From 9aaa94e821094d0838f64cabfa822ee699626869 Mon Sep 17 00:00:00 2001 From: Christian Date: Sun, 17 Nov 2019 21:24:30 +0100 Subject: [PATCH] Revert "Replace raw bytes with x509 certificate to allow specify passwords and flags" --- .../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.Uwp.cs | 2 +- Source/MQTTnet/Implementations/MqttTcpChannel.cs | 2 +- Source/MQTTnet/Implementations/MqttWebSocketChannel.cs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Source/MQTTnet.Extensions.WebSocket4Net/WebSocket4NetMqttChannel.cs b/Source/MQTTnet.Extensions.WebSocket4Net/WebSocket4NetMqttChannel.cs index 1bbc65c..68b12ef 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(certificate); + certificates.Add(new X509Certificate(certificate)); } } diff --git a/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs b/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs index e9ab3df..65a1ec9 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?.ToList(), + Certificates = _tlsParameters.Certificates?.Select(c => c.ToArray()).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 79be24a..ea36baa 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 cf04646..db4077d 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.Uwp.cs b/Source/MQTTnet/Implementations/MqttTcpChannel.Uwp.cs index 2b84899..cb0f71c 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().GetRawCertData()); + return new Certificate(options.TlsOptions.Certificates.First().AsBuffer()); } private IEnumerable ResolveIgnorableServerCertificateErrors() diff --git a/Source/MQTTnet/Implementations/MqttTcpChannel.cs b/Source/MQTTnet/Implementations/MqttTcpChannel.cs index 8f012cb..d7943ad 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(certificate); + certificates.Add(new X509Certificate2(certificate)); } return certificates; diff --git a/Source/MQTTnet/Implementations/MqttWebSocketChannel.cs b/Source/MQTTnet/Implementations/MqttWebSocketChannel.cs index c53a131..38e4342 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(certificate); + clientWebSocket.Options.ClientCertificates.Add(new X509Certificate(certificate)); } }