mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 00:15:15 +08:00
Added certificate validation callback for .NET framework 4.x (#1806)
* Added certificate validation callback for .NET framework 4.x * Update ReleaseNotes.md * Also expose sender to event arguments --------- Co-authored-by: Christian <6939810+chkr1011@users.noreply.github.com>
This commit is contained in:
@@ -14,8 +14,14 @@ namespace MQTTnet.Client
|
||||
|
||||
public X509Chain Chain { get; set; }
|
||||
|
||||
public SslPolicyErrors SslPolicyErrors { get; set; }
|
||||
|
||||
public IMqttClientChannelOptions ClientOptions { get; set; }
|
||||
#if NET452 || NET461 || NET48
|
||||
/// <summary>
|
||||
/// Can be a host string name or an object derived from WebRequest.
|
||||
/// </summary>
|
||||
public object Sender { get; set; }
|
||||
#endif
|
||||
|
||||
public SslPolicyErrors SslPolicyErrors { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -248,12 +248,20 @@ namespace MQTTnet.Implementations
|
||||
throw new NotSupportedException("Remote certificate validation callback is not supported when using 'netstandard2.0'.");
|
||||
#elif WINDOWS_UWP
|
||||
throw new NotSupportedException("Remote certificate validation callback is not supported when using 'uap10.0'.");
|
||||
#elif NET452
|
||||
throw new NotSupportedException("Remote certificate validation callback is not supported when using 'net452'.");
|
||||
#elif NET461
|
||||
throw new NotSupportedException("Remote certificate validation callback is not supported when using 'net461'.");
|
||||
#elif NET48
|
||||
throw new NotSupportedException("Remote certificate validation callback is not supported when using 'net48'.");
|
||||
#elif NET452 || NET461 || NET48
|
||||
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) =>
|
||||
{
|
||||
var context = new MqttClientCertificateValidationEventArgs
|
||||
{
|
||||
Sender = sender,
|
||||
Certificate = certificate,
|
||||
Chain = chain,
|
||||
SslPolicyErrors = sslPolicyErrors,
|
||||
ClientOptions = _options
|
||||
};
|
||||
|
||||
return certificateValidationHandler(context);
|
||||
};
|
||||
#else
|
||||
clientWebSocket.Options.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
|
||||
{
|
||||
@@ -272,4 +280,4 @@ namespace MQTTnet.Implementations
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user