diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec index c15d5321..42042a0e 100644 --- a/Build/MQTTnet.nuspec +++ b/Build/MQTTnet.nuspec @@ -12,7 +12,7 @@ true MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker) and supports v3.1.0, v3.1.1 and v5.0.0 of the MQTT protocol. -* [Server] .. +* [Core] Added support for TLS 1.3 (requires .NET Core 3.1+) (thanks to @Dvergatal). Copyright Christian Kratky 2016-2020 MQTT Message Queue Telemetry Transport MQTTClient MQTTServer Server MQTTBroker Broker NETStandard IoT InternetOfThings Messaging Hardware Arduino Sensor Actuator M2M ESP Smart Home Cities Automation Xamarin Blazor diff --git a/Source/MQTTnet.Extensions.WebSocket4Net/WebSocket4NetMqttChannel.cs b/Source/MQTTnet.Extensions.WebSocket4Net/WebSocket4NetMqttChannel.cs index 47d96821..120e6c36 100644 --- a/Source/MQTTnet.Extensions.WebSocket4Net/WebSocket4NetMqttChannel.cs +++ b/Source/MQTTnet.Extensions.WebSocket4Net/WebSocket4NetMqttChannel.cs @@ -16,14 +16,14 @@ using WebSocket4Net; namespace MQTTnet.Extensions.WebSocket4Net { - public class WebSocket4NetMqttChannel : IMqttChannel + public sealed class WebSocket4NetMqttChannel : IMqttChannel { - private readonly BlockingCollection _receiveBuffer = new BlockingCollection(); + readonly BlockingCollection _receiveBuffer = new BlockingCollection(); - private readonly IMqttClientOptions _clientOptions; - private readonly MqttClientWebSocketOptions _webSocketOptions; + readonly IMqttClientOptions _clientOptions; + readonly MqttClientWebSocketOptions _webSocketOptions; - private WebSocket _webSocket; + WebSocket _webSocket; public WebSocket4NetMqttChannel(IMqttClientOptions clientOptions, MqttClientWebSocketOptions webSocketOptions) { @@ -166,12 +166,12 @@ namespace MQTTnet.Extensions.WebSocket4Net _webSocket = null; } - private void OnError(object sender, ErrorEventArgs e) + static void OnError(object sender, ErrorEventArgs e) { System.Diagnostics.Debug.Write(e.Exception.ToString()); } - private void OnDataReceived(object sender, DataReceivedEventArgs e) + void OnDataReceived(object sender, DataReceivedEventArgs e) { foreach (var @byte in e.Data) { @@ -179,7 +179,7 @@ namespace MQTTnet.Extensions.WebSocket4Net } } - private async Task ConnectInternalAsync(CancellationToken cancellationToken) + async Task ConnectInternalAsync(CancellationToken cancellationToken) { _webSocket.Error += OnError; _webSocket.DataReceived += OnDataReceived; diff --git a/Source/MQTTnet.Server/Mqtt/MqttServerService.cs b/Source/MQTTnet.Server/Mqtt/MqttServerService.cs index ac11aa44..bdb57624 100644 --- a/Source/MQTTnet.Server/Mqtt/MqttServerService.cs +++ b/Source/MQTTnet.Server/Mqtt/MqttServerService.cs @@ -212,7 +212,7 @@ namespace MQTTnet.Server.Mqtt // Configure encrypted connections if (_settings.EncryptedTcpEndPoint.Enabled) { -#if NETCOREAPP3_0 || NET5_0 +#if NETCOREAPP3_1 || NET5_0 options .WithEncryptedEndpoint() .WithEncryptionSslProtocol(SslProtocols.Tls13); diff --git a/Source/MQTTnet/Client/Options/MqttClientOptionsBuilderTlsParameters.cs b/Source/MQTTnet/Client/Options/MqttClientOptionsBuilderTlsParameters.cs index 8f6abcc8..f73ab3b7 100644 --- a/Source/MQTTnet/Client/Options/MqttClientOptionsBuilderTlsParameters.cs +++ b/Source/MQTTnet/Client/Options/MqttClientOptionsBuilderTlsParameters.cs @@ -19,7 +19,7 @@ namespace MQTTnet.Client.Options public Func CertificateValidationHandler { get; set; } -#if NETCOREAPP3_0 || NET5_0 +#if NETCOREAPP3_1 || NET5_0 public SslProtocols SslProtocol { get; set; } = SslProtocols.Tls13; #else public SslProtocols SslProtocol { get; set; } = SslProtocols.Tls12; diff --git a/Source/MQTTnet/Client/Options/MqttClientTlsOptions.cs b/Source/MQTTnet/Client/Options/MqttClientTlsOptions.cs index da926abd..b5e2c261 100644 --- a/Source/MQTTnet/Client/Options/MqttClientTlsOptions.cs +++ b/Source/MQTTnet/Client/Options/MqttClientTlsOptions.cs @@ -26,7 +26,7 @@ namespace MQTTnet.Client.Options public List ApplicationProtocols { get; set; } #endif -#if NETCOREAPP3_0 || NET5_0 +#if NETCOREAPP3_1 || NET5_0 public SslProtocols SslProtocol { get; set; } = SslProtocols.Tls13; #else public SslProtocols SslProtocol { get; set; } = SslProtocols.Tls12; diff --git a/Source/MQTTnet/Implementations/MqttTcpChannel.Uwp.cs b/Source/MQTTnet/Implementations/MqttTcpChannel.Uwp.cs index 20b798df..7d5706dd 100644 --- a/Source/MQTTnet/Implementations/MqttTcpChannel.Uwp.cs +++ b/Source/MQTTnet/Implementations/MqttTcpChannel.Uwp.cs @@ -39,11 +39,7 @@ namespace MQTTnet.Implementations CreateStreams(); -#if NETCOREAPP3_0 || NET5_0 - IsSecureConnection = socket.Information.ProtectionLevel >= SocketProtectionLevel.Tls13; -#else IsSecureConnection = socket.Information.ProtectionLevel >= SocketProtectionLevel.Tls12; -#endif ClientCertificate = clientCertificate; Endpoint = _socket.Information.RemoteAddress + ":" + _socket.Information.RemotePort; @@ -79,7 +75,7 @@ namespace MQTTnet.Implementations _socket.Control.IgnorableServerCertificateErrors.Add(ignorableChainValidationResult); } -#if NETCOREAPP3_0 || NET5_0 +#if NETCOREAPP3_1 || NET5_0 var socketProtectionLevel = SocketProtectionLevel.Tls13; if (_options.TlsOptions.SslProtocol == SslProtocols.Tls12) { @@ -89,7 +85,7 @@ namespace MQTTnet.Implementations { socketProtectionLevel = SocketProtectionLevel.Tls11; } -#else +#else var socketProtectionLevel = SocketProtectionLevel.Tls12; if (_options.TlsOptions.SslProtocol == SslProtocols.Tls11) {