From dddc1ec112713b22196ac99981a4a1f5b8a9fdf6 Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 21 Jun 2018 08:12:55 -0400 Subject: [PATCH] Fix a bug where an incoming SSL client connection was being treated as a plain-text connection. --- Source/MQTTnet/Implementations/MqttTcpServerListener.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/MQTTnet/Implementations/MqttTcpServerListener.cs b/Source/MQTTnet/Implementations/MqttTcpServerListener.cs index fccd77f..f8a90b5 100644 --- a/Source/MQTTnet/Implementations/MqttTcpServerListener.cs +++ b/Source/MQTTnet/Implementations/MqttTcpServerListener.cs @@ -70,15 +70,17 @@ namespace MQTTnet.Implementations #endif clientSocket.NoDelay = true; + SslStream sslStream = null; + if (_tlsCertificate != null) { - var sslStream = new SslStream(new NetworkStream(clientSocket), false); + sslStream = new SslStream(new NetworkStream(clientSocket), false); await sslStream.AuthenticateAsServerAsync(_tlsCertificate, false, SslProtocols.Tls12, false).ConfigureAwait(false); } _logger.Verbose($"Client '{clientSocket.RemoteEndPoint}' accepted by TCP listener '{_socket.LocalEndPoint}, {_addressFamily}'."); - var clientAdapter = new MqttChannelAdapter(new MqttTcpChannel(clientSocket, null), new MqttPacketSerializer(), _logger); + var clientAdapter = new MqttChannelAdapter(new MqttTcpChannel(clientSocket, sslStream), new MqttPacketSerializer(), _logger); ClientAccepted?.Invoke(this, new MqttServerAdapterClientAcceptedEventArgs(clientAdapter)); } catch (ObjectDisposedException)