From 4b1c7cf772fc98df36cf940eceb93ca0d91ba5e0 Mon Sep 17 00:00:00 2001 From: Torstein Lundervold Nesheim <57716654+GodVenn@users.noreply.github.com> Date: Fri, 1 Jul 2022 17:00:13 +0200 Subject: [PATCH] Use IgnoreCertificateChainErrors option in TcpChannel (#1447) --- Source/MQTTnet/Implementations/MqttTcpChannel.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Source/MQTTnet/Implementations/MqttTcpChannel.cs b/Source/MQTTnet/Implementations/MqttTcpChannel.cs index 5dbfd8dd..3c173947 100644 --- a/Source/MQTTnet/Implementations/MqttTcpChannel.cs +++ b/Source/MQTTnet/Implementations/MqttTcpChannel.cs @@ -3,6 +3,9 @@ // See the LICENSE file in the project root for more information. #if !WINDOWS_UWP +using MQTTnet.Channel; +using MQTTnet.Client; +using MQTTnet.Exceptions; using System; using System.IO; using System.Net.Security; @@ -11,9 +14,6 @@ using System.Runtime.ExceptionServices; using System.Security.Cryptography.X509Certificates; using System.Threading; using System.Threading.Tasks; -using MQTTnet.Channel; -using MQTTnet.Client; -using MQTTnet.Exceptions; namespace MQTTnet.Implementations { @@ -274,6 +274,9 @@ namespace MQTTnet.Implementations return certificateValidationHandler(eventArgs); } + if (_tcpOptions?.TlsOptions?.IgnoreCertificateChainErrors ?? false) + sslPolicyErrors &= ~SslPolicyErrors.RemoteCertificateChainErrors; + return sslPolicyErrors == SslPolicyErrors.None; }