Browse Source

added support for Tls1.3 protocol

release/3.x.x
Piotr Łobacz 4 years ago
parent
commit
7274f4390c
5 changed files with 34 additions and 0 deletions
  1. +4
    -0
      Source/MQTTnet.Extensions.Wrappers.WebSocket4Net/WebSocket4NetMqttClientAdapterFactory.cs
  2. +6
    -0
      Source/MQTTnet.Server/Mqtt/MqttServerService.cs
  3. +4
    -0
      Source/MQTTnet/Client/Options/MqttClientOptionsBuilderTlsParameters.cs
  4. +4
    -0
      Source/MQTTnet/Client/Options/MqttClientTlsOptions.cs
  5. +16
    -0
      Source/MQTTnet/Implementations/MqttTcpChannel.Uwp.cs

+ 4
- 0
Source/MQTTnet.Extensions.Wrappers.WebSocket4Net/WebSocket4NetMqttClientAdapterFactory.cs View File

@@ -52,7 +52,11 @@ namespace MQTTnet.TestApp.NetCore
if (channelOptions.TlsOptions.UseTls)
{
uri = "wss://" + channelOptions.Uri;
#if NETCOREAPP3_0 || NET5_0
sslProtocols = SslProtocols.Tls13;
#else
sslProtocols = SslProtocols.Tls12;
#endif
}

var subProtocol = channelOptions.SubProtocols.FirstOrDefault() ?? string.Empty;


+ 6
- 0
Source/MQTTnet.Server/Mqtt/MqttServerService.cs View File

@@ -212,9 +212,15 @@ namespace MQTTnet.Server.Mqtt
// Configure encrypted connections
if (_settings.EncryptedTcpEndPoint.Enabled)
{
#if NETCOREAPP3_0 || NET5_0
options
.WithEncryptedEndpoint()
.WithEncryptionSslProtocol(SslProtocols.Tls13);
#else
options
.WithEncryptedEndpoint()
.WithEncryptionSslProtocol(SslProtocols.Tls12);
#endif

if (!string.IsNullOrEmpty(_settings.EncryptedTcpEndPoint?.Certificate?.Path))
{


+ 4
- 0
Source/MQTTnet/Client/Options/MqttClientOptionsBuilderTlsParameters.cs View File

@@ -19,7 +19,11 @@ namespace MQTTnet.Client.Options

public Func<MqttClientCertificateValidationCallbackContext, bool> CertificateValidationHandler { get; set; }

#if NETCOREAPP3_0 || NET5_0
public SslProtocols SslProtocol { get; set; } = SslProtocols.Tls13;
#else
public SslProtocols SslProtocol { get; set; } = SslProtocols.Tls12;
#endif

#if WINDOWS_UWP
public IEnumerable<IEnumerable<byte>> Certificates { get; set; }


+ 4
- 0
Source/MQTTnet/Client/Options/MqttClientTlsOptions.cs View File

@@ -26,7 +26,11 @@ namespace MQTTnet.Client.Options
public List<SslApplicationProtocol> ApplicationProtocols { get; set; }
#endif

#if NETCOREAPP3_0 || NET5_0
public SslProtocols SslProtocol { get; set; } = SslProtocols.Tls13;
#else
public SslProtocols SslProtocol { get; set; } = SslProtocols.Tls12;
#endif

[Obsolete("This property will be removed soon. Use CertificateValidationHandler instead.")]
public Func<X509Certificate, X509Chain, SslPolicyErrors, IMqttClientOptions, bool> CertificateValidationCallback { get; set; }


+ 16
- 0
Source/MQTTnet/Implementations/MqttTcpChannel.Uwp.cs View File

@@ -39,7 +39,11 @@ 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;
@@ -75,11 +79,23 @@ namespace MQTTnet.Implementations
_socket.Control.IgnorableServerCertificateErrors.Add(ignorableChainValidationResult);
}

#if NETCOREAPP3_0 || NET5_0
var socketProtectionLevel = SocketProtectionLevel.Tls13;
if (_options.TlsOptions.SslProtocol == SslProtocols.Tls12)
{
socketProtectionLevel = SocketProtectionLevel.Tls12;
}
else if (_options.TlsOptions.SslProtocol == SslProtocols.Tls11)
{
socketProtectionLevel = SocketProtectionLevel.Tls11;
}
#else
var socketProtectionLevel = SocketProtectionLevel.Tls12;
if (_options.TlsOptions.SslProtocol == SslProtocols.Tls11)
{
socketProtectionLevel = SocketProtectionLevel.Tls11;
}
#endif
else if (_options.TlsOptions.SslProtocol == SslProtocols.Tls)
{
socketProtectionLevel = SocketProtectionLevel.Tls10;


Loading…
Cancel
Save