From a38623cb5a7a9bacc751929b162caa9c852901e0 Mon Sep 17 00:00:00 2001 From: Anton Yaroshenko Date: Sun, 17 Nov 2019 19:42:23 +0200 Subject: [PATCH 1/2] replace raw byte with x509 certificate to allow specify passwords --- .../WebSocket4NetMqttChannel.cs | 2 +- Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs | 2 +- .../Client/Options/MqttClientOptionsBuilderTlsParameters.cs | 2 +- Source/MQTTnet/Client/Options/MqttClientTlsOptions.cs | 2 +- Source/MQTTnet/Implementations/MqttTcpChannel.cs | 2 +- Source/MQTTnet/Implementations/MqttWebSocketChannel.cs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Source/MQTTnet.Extensions.WebSocket4Net/WebSocket4NetMqttChannel.cs b/Source/MQTTnet.Extensions.WebSocket4Net/WebSocket4NetMqttChannel.cs index 68b12ef..1bbc65c 100644 --- a/Source/MQTTnet.Extensions.WebSocket4Net/WebSocket4NetMqttChannel.cs +++ b/Source/MQTTnet.Extensions.WebSocket4Net/WebSocket4NetMqttChannel.cs @@ -85,7 +85,7 @@ namespace MQTTnet.Extensions.WebSocket4Net { foreach (var certificate in _webSocketOptions.TlsOptions.Certificates) { - certificates.Add(new X509Certificate(certificate)); + certificates.Add(certificate); } } diff --git a/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs b/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs index 65a1ec9..e9ab3df 100644 --- a/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs +++ b/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs @@ -256,7 +256,7 @@ namespace MQTTnet.Client.Options UseTls = true, SslProtocol = _tlsParameters.SslProtocol, AllowUntrustedCertificates = _tlsParameters.AllowUntrustedCertificates, - Certificates = _tlsParameters.Certificates?.Select(c => c.ToArray()).ToList(), + Certificates = _tlsParameters.Certificates?.ToList(), CertificateValidationCallback = _tlsParameters.CertificateValidationCallback, IgnoreCertificateChainErrors = _tlsParameters.IgnoreCertificateChainErrors, IgnoreCertificateRevocationErrors = _tlsParameters.IgnoreCertificateRevocationErrors diff --git a/Source/MQTTnet/Client/Options/MqttClientOptionsBuilderTlsParameters.cs b/Source/MQTTnet/Client/Options/MqttClientOptionsBuilderTlsParameters.cs index ea36baa..79be24a 100644 --- a/Source/MQTTnet/Client/Options/MqttClientOptionsBuilderTlsParameters.cs +++ b/Source/MQTTnet/Client/Options/MqttClientOptionsBuilderTlsParameters.cs @@ -18,7 +18,7 @@ namespace MQTTnet.Client.Options public SslProtocols SslProtocol { get; set; } = SslProtocols.Tls12; - public IEnumerable> Certificates { get; set; } + public IEnumerable Certificates { get; set; } public bool AllowUntrustedCertificates { get; set; } diff --git a/Source/MQTTnet/Client/Options/MqttClientTlsOptions.cs b/Source/MQTTnet/Client/Options/MqttClientTlsOptions.cs index db4077d..cf04646 100644 --- a/Source/MQTTnet/Client/Options/MqttClientTlsOptions.cs +++ b/Source/MQTTnet/Client/Options/MqttClientTlsOptions.cs @@ -16,7 +16,7 @@ namespace MQTTnet.Client.Options public bool AllowUntrustedCertificates { get; set; } - public List Certificates { get; set; } + public List Certificates { get; set; } public SslProtocols SslProtocol { get; set; } = SslProtocols.Tls12; diff --git a/Source/MQTTnet/Implementations/MqttTcpChannel.cs b/Source/MQTTnet/Implementations/MqttTcpChannel.cs index d7943ad..8f012cb 100644 --- a/Source/MQTTnet/Implementations/MqttTcpChannel.cs +++ b/Source/MQTTnet/Implementations/MqttTcpChannel.cs @@ -214,7 +214,7 @@ namespace MQTTnet.Implementations foreach (var certificate in _options.TlsOptions.Certificates) { - certificates.Add(new X509Certificate2(certificate)); + certificates.Add(certificate); } return certificates; diff --git a/Source/MQTTnet/Implementations/MqttWebSocketChannel.cs b/Source/MQTTnet/Implementations/MqttWebSocketChannel.cs index 38e4342..c53a131 100644 --- a/Source/MQTTnet/Implementations/MqttWebSocketChannel.cs +++ b/Source/MQTTnet/Implementations/MqttWebSocketChannel.cs @@ -84,7 +84,7 @@ namespace MQTTnet.Implementations clientWebSocket.Options.ClientCertificates = new X509CertificateCollection(); foreach (var certificate in _options.TlsOptions.Certificates) { - clientWebSocket.Options.ClientCertificates.Add(new X509Certificate(certificate)); + clientWebSocket.Options.ClientCertificates.Add(certificate); } } From ac326babdf0fecdb8fa1008026b7b1d65434aa36 Mon Sep 17 00:00:00 2001 From: Anton Yaroshenko Date: Sun, 17 Nov 2019 20:12:03 +0200 Subject: [PATCH 2/2] blind uwp fix --- Source/MQTTnet/Implementations/MqttTcpChannel.Uwp.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/MQTTnet/Implementations/MqttTcpChannel.Uwp.cs b/Source/MQTTnet/Implementations/MqttTcpChannel.Uwp.cs index cb0f71c..2b84899 100644 --- a/Source/MQTTnet/Implementations/MqttTcpChannel.Uwp.cs +++ b/Source/MQTTnet/Implementations/MqttTcpChannel.Uwp.cs @@ -132,7 +132,7 @@ namespace MQTTnet.Implementations throw new NotSupportedException("Only one client certificate is supported for UWP."); } - return new Certificate(options.TlsOptions.Certificates.First().AsBuffer()); + return new Certificate(options.TlsOptions.Certificates.First().GetRawCertData()); } private IEnumerable ResolveIgnorableServerCertificateErrors()