mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 08:33:01 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
83b85b8059 | ||
|
|
e88b280eb0 | ||
|
|
db2c164dbf | ||
|
|
30426e5e1e |
@@ -1,8 +1 @@
|
||||
* [Core] Fixed several dead locks by implementing a new async signal (#1552)
|
||||
* [Client] All waiting tasks will now fail when the client connection gets closed. This fixes several freezes (#1561)
|
||||
* [ManagedClient] The topic is no longer declared as invalid if a topic alias is used (#1395)
|
||||
* [Server] Fixed duplicated invocation of the event _ClientAcknowledgedPublishPacketAsync_ for QoS level 2 (#1550)
|
||||
* [Server] Fixed issue in upgrading and downgrading of QoS levels for subscriptions and retained messages (#1560)
|
||||
* [Server] Fixed memory leak when old sessions are discarded (#1553)
|
||||
* [Server] When using MQTTv5 the reason code _NoMatchingSubscribers_ is returned when no client is subscribed to a published topic (#802)
|
||||
* [Server] Fix sending of duplicate messages with QoS > 0 when session is recovered and session is reused (#1546)
|
||||
|
||||
|
||||
@@ -10,12 +10,20 @@ namespace MQTTnet.Client
|
||||
{
|
||||
public sealed class MqttClientCertificateValidationEventArgs : EventArgs
|
||||
{
|
||||
public X509Certificate Certificate { get; set; }
|
||||
public MqttClientCertificateValidationEventArgs(X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors, IMqttClientChannelOptions clientOptions)
|
||||
{
|
||||
Certificate = certificate ?? throw new ArgumentNullException(nameof(certificate));
|
||||
Chain = chain ?? throw new ArgumentNullException(nameof(chain));
|
||||
SslPolicyErrors = sslPolicyErrors;
|
||||
ClientOptions = clientOptions ?? throw new ArgumentNullException(nameof(clientOptions));
|
||||
}
|
||||
|
||||
public X509Chain Chain { get; set; }
|
||||
public X509Certificate Certificate { get; }
|
||||
|
||||
public SslPolicyErrors SslPolicyErrors { get; set; }
|
||||
public X509Chain Chain { get; }
|
||||
|
||||
public IMqttClientChannelOptions ClientOptions { get; set; }
|
||||
public IMqttClientChannelOptions ClientOptions { get; }
|
||||
|
||||
public SslPolicyErrors SslPolicyErrors { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,18 @@ namespace MQTTnet.Client
|
||||
{
|
||||
public static bool Handle(MqttClientCertificateValidationEventArgs eventArgs)
|
||||
{
|
||||
if (eventArgs.SslPolicyErrors == SslPolicyErrors.None)
|
||||
var sslPolicyErrors = eventArgs.SslPolicyErrors;
|
||||
|
||||
if (eventArgs.ClientOptions?.TlsOptions?.IgnoreCertificateChainErrors ?? false)
|
||||
{
|
||||
sslPolicyErrors &= ~SslPolicyErrors.RemoteCertificateChainErrors;
|
||||
}
|
||||
|
||||
if (sslPolicyErrors == SslPolicyErrors.None)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
if (eventArgs.Chain.ChainStatus.Any(c =>
|
||||
c.Status == X509ChainStatusFlags.RevocationStatusUnknown || c.Status == X509ChainStatusFlags.Revoked || c.Status == X509ChainStatusFlags.OfflineRevocation))
|
||||
{
|
||||
|
||||
@@ -13,8 +13,8 @@ namespace MQTTnet.Client
|
||||
public sealed class MqttClientOptionsBuilderTlsParameters
|
||||
{
|
||||
public bool UseTls { get; set; }
|
||||
|
||||
public Func<MqttClientCertificateValidationEventArgs, bool> CertificateValidationHandler { get; set; }
|
||||
|
||||
public Func<MqttClientCertificateValidationEventArgs, bool> CertificateValidationHandler { get; set; } = MqttClientDefaultCertificateValidationHandler.Handle;
|
||||
|
||||
#if NET48 || NETCOREAPP3_1 || NET5 || NET6
|
||||
public SslProtocols SslProtocol { get; set; } = SslProtocols.Tls12 | SslProtocols.Tls13;
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace MQTTnet.Client
|
||||
{
|
||||
public sealed class MqttClientTlsOptions
|
||||
{
|
||||
public Func<MqttClientCertificateValidationEventArgs, bool> CertificateValidationHandler { get; set; }
|
||||
public Func<MqttClientCertificateValidationEventArgs, bool> CertificateValidationHandler { get; set; } = MqttClientDefaultCertificateValidationHandler.Handle;
|
||||
|
||||
public bool UseTls { get; set; }
|
||||
|
||||
|
||||
@@ -264,27 +264,15 @@ namespace MQTTnet.Implementations
|
||||
}
|
||||
}
|
||||
|
||||
bool InternalUserCertificateValidationCallback(object sender, X509Certificate x509Certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
bool InternalUserCertificateValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
{
|
||||
var certificateValidationHandler = _tcpOptions?.TlsOptions?.CertificateValidationHandler;
|
||||
if (certificateValidationHandler != null)
|
||||
{
|
||||
var eventArgs = new MqttClientCertificateValidationEventArgs
|
||||
{
|
||||
Certificate = x509Certificate,
|
||||
Chain = chain,
|
||||
SslPolicyErrors = sslPolicyErrors,
|
||||
ClientOptions = _tcpOptions
|
||||
};
|
||||
|
||||
var eventArgs = new MqttClientCertificateValidationEventArgs(certificate, chain, sslPolicyErrors, _tcpOptions);
|
||||
return certificateValidationHandler(eventArgs);
|
||||
}
|
||||
|
||||
if (_tcpOptions?.TlsOptions?.IgnoreCertificateChainErrors ?? false)
|
||||
{
|
||||
sslPolicyErrors &= ~SslPolicyErrors.RemoteCertificateChainErrors;
|
||||
}
|
||||
|
||||
return sslPolicyErrors == SslPolicyErrors.None;
|
||||
}
|
||||
|
||||
|
||||
@@ -224,14 +224,7 @@ namespace MQTTnet.Implementations
|
||||
clientWebSocket.Options.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) =>
|
||||
{
|
||||
// TODO: Find a way to add client options to same callback. Problem is that they have a different type.
|
||||
var context = new MqttClientCertificateValidationEventArgs
|
||||
{
|
||||
Certificate = certificate,
|
||||
Chain = chain,
|
||||
SslPolicyErrors = sslPolicyErrors,
|
||||
ClientOptions = _options
|
||||
};
|
||||
|
||||
var context = new MqttClientCertificateValidationEventArgs(certificate, chain, sslPolicyErrors, _options);
|
||||
return certificateValidationHandler(context);
|
||||
};
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user