diff --git a/Source/MQTTnet.Extensions.WebSocket4Net/WebSocket4NetMqttChannel.cs b/Source/MQTTnet.Extensions.WebSocket4Net/WebSocket4NetMqttChannel.cs index 1bbc65c..47d9682 100644 --- a/Source/MQTTnet.Extensions.WebSocket4Net/WebSocket4NetMqttChannel.cs +++ b/Source/MQTTnet.Extensions.WebSocket4Net/WebSocket4NetMqttChannel.cs @@ -85,7 +85,12 @@ namespace MQTTnet.Extensions.WebSocket4Net { foreach (var certificate in _webSocketOptions.TlsOptions.Certificates) { +#if WINDOWS_UWP + certificates.Add(new X509Certificate(certificate)); +#else certificates.Add(certificate); +#endif + } } diff --git a/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs b/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs index e9ab3df..4fd0ccf 100644 --- a/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs +++ b/Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs @@ -256,7 +256,11 @@ namespace MQTTnet.Client.Options UseTls = true, SslProtocol = _tlsParameters.SslProtocol, AllowUntrustedCertificates = _tlsParameters.AllowUntrustedCertificates, +#if WINDOWS_UWP + Certificates = _tlsParameters.Certificates?.Select(c => c.ToArray()).ToList(), +#else Certificates = _tlsParameters.Certificates?.ToList(), +#endif 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..d1854ff 100644 --- a/Source/MQTTnet/Client/Options/MqttClientOptionsBuilderTlsParameters.cs +++ b/Source/MQTTnet/Client/Options/MqttClientOptionsBuilderTlsParameters.cs @@ -18,7 +18,12 @@ namespace MQTTnet.Client.Options public SslProtocols SslProtocol { get; set; } = SslProtocols.Tls12; +#if WINDOWS_UWP + public IEnumerable> Certificates { get; set; } +#else public IEnumerable Certificates { get; set; } +#endif + public bool AllowUntrustedCertificates { get; set; } diff --git a/Source/MQTTnet/Client/Options/MqttClientTlsOptions.cs b/Source/MQTTnet/Client/Options/MqttClientTlsOptions.cs index cf04646..0d1a3a5 100644 --- a/Source/MQTTnet/Client/Options/MqttClientTlsOptions.cs +++ b/Source/MQTTnet/Client/Options/MqttClientTlsOptions.cs @@ -15,8 +15,11 @@ namespace MQTTnet.Client.Options public bool IgnoreCertificateChainErrors { get; set; } public bool AllowUntrustedCertificates { get; set; } - +#if WINDOWS_UWP + public List Certificates { get; set; } +#else public List Certificates { get; set; } +#endif 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/MqttWebSocketChannel.cs b/Source/MQTTnet/Implementations/MqttWebSocketChannel.cs index c53a131..db53936 100644 --- a/Source/MQTTnet/Implementations/MqttWebSocketChannel.cs +++ b/Source/MQTTnet/Implementations/MqttWebSocketChannel.cs @@ -84,7 +84,12 @@ namespace MQTTnet.Implementations clientWebSocket.Options.ClientCertificates = new X509CertificateCollection(); foreach (var certificate in _options.TlsOptions.Certificates) { +#if WINDOWS_UWP + clientWebSocket.Options.ClientCertificates.Add(new X509Certificate(certificate)); +#else clientWebSocket.Options.ClientCertificates.Add(certificate); +#endif + } }