Browse Source

Merge pull request #321 from asthomas/develop

Fix for incoming SSL connections
release/3.x.x
Christian 6 years ago
committed by GitHub
parent
commit
2a03c1f1f4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions
  1. +4
    -2
      Source/MQTTnet/Implementations/MqttTcpServerListener.cs

+ 4
- 2
Source/MQTTnet/Implementations/MqttTcpServerListener.cs View File

@@ -70,16 +70,18 @@ namespace MQTTnet.Implementations
#endif #endif
clientSocket.NoDelay = true; clientSocket.NoDelay = true;


SslStream sslStream = null;

if (_tlsCertificate != 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); await sslStream.AuthenticateAsServerAsync(_tlsCertificate, false, SslProtocols.Tls12, false).ConfigureAwait(false);
} }


var protocol = _addressFamily == AddressFamily.InterNetwork ? "ipv4" : "ipv6"; var protocol = _addressFamily == AddressFamily.InterNetwork ? "ipv4" : "ipv6";
_logger.Verbose($"Client '{clientSocket.RemoteEndPoint}' accepted by TCP listener '{_socket.LocalEndPoint}, {protocol}'."); _logger.Verbose($"Client '{clientSocket.RemoteEndPoint}' accepted by TCP listener '{_socket.LocalEndPoint}, {protocol}'.");


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)); ClientAccepted?.Invoke(this, new MqttServerAdapterClientAcceptedEventArgs(clientAdapter));
} }
catch (ObjectDisposedException) catch (ObjectDisposedException)


Loading…
Cancel
Save