mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-18 18:43:10 +08:00
Add support for ignored certificate chain errors (Self signed)
This commit is contained in:
@@ -51,7 +51,7 @@ namespace MQTTnet.Implementations
|
||||
|
||||
if (_options.TlsOptions.UseTls)
|
||||
{
|
||||
_sslStream = new SslStream(new NetworkStream(_socket, true));
|
||||
_sslStream = new SslStream(new NetworkStream(_socket, true), false, UserCertificateValidationCallback);
|
||||
ReceiveStream = _sslStream;
|
||||
await _sslStream.AuthenticateAsClientAsync(_options.Server, LoadCertificates(_options), SslProtocols.Tls12, _options.TlsOptions.CheckCertificateRevocation).ConfigureAwait(false);
|
||||
}
|
||||
@@ -76,6 +76,16 @@ namespace MQTTnet.Implementations
|
||||
_sslStream = null;
|
||||
}
|
||||
|
||||
private bool UserCertificateValidationCallback(object sender, X509Certificate x509Certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
{
|
||||
if ((sslPolicyErrors & SslPolicyErrors.RemoteCertificateChainErrors) != 0)
|
||||
{
|
||||
return _options.TlsOptions.IgnoreCertificateChainErrors;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static X509CertificateCollection LoadCertificates(MqttClientOptions options)
|
||||
{
|
||||
var certificates = new X509CertificateCollection();
|
||||
|
||||
Reference in New Issue
Block a user