From 1c7984f473c33f54a0a776105b012fe121193742 Mon Sep 17 00:00:00 2001 From: Christian <6939810+chkr1011@users.noreply.github.com> Date: Wed, 1 Nov 2023 09:25:53 +0100 Subject: [PATCH] Apply project code style --- .../MQTTnet/Implementations/MqttTcpChannel.cs | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Source/MQTTnet/Implementations/MqttTcpChannel.cs b/Source/MQTTnet/Implementations/MqttTcpChannel.cs index 118611771..f9dadf26d 100644 --- a/Source/MQTTnet/Implementations/MqttTcpChannel.cs +++ b/Source/MQTTnet/Implementations/MqttTcpChannel.cs @@ -115,24 +115,32 @@ public async Task ConnectAsync(CancellationToken cancellationToken) ApplicationProtocols = _tcpOptions.TlsOptions.ApplicationProtocols, ClientCertificates = LoadCertificates(), EnabledSslProtocols = _tcpOptions.TlsOptions.SslProtocol, - CertificateRevocationCheckMode = _tcpOptions.TlsOptions.IgnoreCertificateRevocationErrors ? X509RevocationMode.NoCheck : _tcpOptions.TlsOptions.RevocationMode, + CertificateRevocationCheckMode = _tcpOptions.TlsOptions.IgnoreCertificateRevocationErrors + ? X509RevocationMode.NoCheck + : _tcpOptions.TlsOptions.RevocationMode, TargetHost = targetHost, CipherSuitesPolicy = _tcpOptions.TlsOptions.CipherSuitesPolicy, EncryptionPolicy = _tcpOptions.TlsOptions.EncryptionPolicy, AllowRenegotiation = _tcpOptions.TlsOptions.AllowRenegotiation }; + #if NET7_0_OR_GREATER if (_tcpOptions.TlsOptions.TrustChain?.Count > 0) { - sslOptions.CertificateChainPolicy = new X509ChainPolicy(); - sslOptions.CertificateChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust; - sslOptions.CertificateChainPolicy.VerificationFlags = X509VerificationFlags.IgnoreEndRevocationUnknown; - sslOptions.CertificateChainPolicy.RevocationMode = _tcpOptions.TlsOptions.IgnoreCertificateRevocationErrors ? X509RevocationMode.NoCheck : _tcpOptions.TlsOptions.RevocationMode; + sslOptions.CertificateChainPolicy = new X509ChainPolicy + { + TrustMode = X509ChainTrustMode.CustomRootTrust, + VerificationFlags = X509VerificationFlags.IgnoreEndRevocationUnknown, + RevocationMode = _tcpOptions.TlsOptions.IgnoreCertificateRevocationErrors + ? X509RevocationMode.NoCheck + : _tcpOptions.TlsOptions.RevocationMode + }; + sslOptions.CertificateChainPolicy.CustomTrustStore.AddRange(_tcpOptions.TlsOptions.TrustChain); } #endif - await sslStream.AuthenticateAsClientAsync(sslOptions, cancellationToken).ConfigureAwait(false); + await sslStream.AuthenticateAsClientAsync(sslOptions, cancellationToken).ConfigureAwait(false); #else await sslStream.AuthenticateAsClientAsync( targetHost,