mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 03:24:33 +08:00
Fix TLS certificate loading.
This commit is contained in:
@@ -65,11 +65,6 @@ namespace MQTTnet.Adapter
|
|||||||
|
|
||||||
foreach (var packet in packets)
|
foreach (var packet in packets)
|
||||||
{
|
{
|
||||||
if (packet == null)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
await SendPacketAsync(timeout, cancellationToken, packet).ConfigureAwait(false);
|
await SendPacketAsync(timeout, cancellationToken, packet).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ namespace MQTTnet.Implementations
|
|||||||
{
|
{
|
||||||
private readonly List<MqttTcpServerListener> _listeners = new List<MqttTcpServerListener>();
|
private readonly List<MqttTcpServerListener> _listeners = new List<MqttTcpServerListener>();
|
||||||
private readonly IMqttNetChildLogger _logger;
|
private readonly IMqttNetChildLogger _logger;
|
||||||
|
|
||||||
private CancellationTokenSource _cancellationTokenSource;
|
private CancellationTokenSource _cancellationTokenSource;
|
||||||
|
|
||||||
public MqttTcpServerAdapter(IMqttNetChildLogger logger)
|
public MqttTcpServerAdapter(IMqttNetChildLogger logger)
|
||||||
{
|
{
|
||||||
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
if (logger == null) throw new ArgumentNullException(nameof(logger));
|
||||||
@@ -35,7 +35,7 @@ namespace MQTTnet.Implementations
|
|||||||
|
|
||||||
if (options.DefaultEndpointOptions.IsEnabled)
|
if (options.DefaultEndpointOptions.IsEnabled)
|
||||||
{
|
{
|
||||||
RegisterListeners(options.DefaultEndpointOptions);
|
RegisterListeners(options.DefaultEndpointOptions, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.TlsEndpointOptions.IsEnabled)
|
if (options.TlsEndpointOptions.IsEnabled)
|
||||||
@@ -51,7 +51,7 @@ namespace MQTTnet.Implementations
|
|||||||
throw new InvalidOperationException("The certificate for TLS encryption must contain the private key.");
|
throw new InvalidOperationException("The certificate for TLS encryption must contain the private key.");
|
||||||
}
|
}
|
||||||
|
|
||||||
RegisterListeners(options.TlsEndpointOptions);
|
RegisterListeners(options.TlsEndpointOptions, tlsCertificate);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.FromResult(0);
|
return Task.FromResult(0);
|
||||||
@@ -77,16 +77,8 @@ namespace MQTTnet.Implementations
|
|||||||
_listeners.Clear();
|
_listeners.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RegisterListeners(MqttServerTcpEndpointBaseOptions options)
|
private void RegisterListeners(MqttServerTcpEndpointBaseOptions options, X509Certificate2 tlsCertificate)
|
||||||
{
|
{
|
||||||
var tlsOptions = options as MqttServerTlsTcpEndpointOptions;
|
|
||||||
|
|
||||||
X509Certificate2 tlsCertificate = null;
|
|
||||||
if (tlsOptions != null)
|
|
||||||
{
|
|
||||||
tlsCertificate = new X509Certificate2(tlsOptions.Certificate);
|
|
||||||
}
|
|
||||||
|
|
||||||
var listenerV4 = new MqttTcpServerListener(
|
var listenerV4 = new MqttTcpServerListener(
|
||||||
AddressFamily.InterNetwork,
|
AddressFamily.InterNetwork,
|
||||||
options,
|
options,
|
||||||
@@ -97,7 +89,7 @@ namespace MQTTnet.Implementations
|
|||||||
listenerV4.ClientAccepted += OnClientAccepted;
|
listenerV4.ClientAccepted += OnClientAccepted;
|
||||||
listenerV4.Start();
|
listenerV4.Start();
|
||||||
_listeners.Add(listenerV4);
|
_listeners.Add(listenerV4);
|
||||||
|
|
||||||
var listenerV6 = new MqttTcpServerListener(
|
var listenerV6 = new MqttTcpServerListener(
|
||||||
AddressFamily.InterNetworkV6,
|
AddressFamily.InterNetworkV6,
|
||||||
options,
|
options,
|
||||||
|
|||||||
Reference in New Issue
Block a user