mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 01:03:01 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -44,13 +44,21 @@ namespace MQTTnet.Implementations
|
||||
|
||||
if (options.TlsEndpointOptions?.IsEnabled == true)
|
||||
{
|
||||
if (options.TlsEndpointOptions.Certificate == null)
|
||||
if (options.TlsEndpointOptions.Certificate == null && options.TlsEndpointOptions.X509Certificate == null)
|
||||
{
|
||||
throw new ArgumentException("TLS certificate is not set.");
|
||||
}
|
||||
else if (options.TlsEndpointOptions.Certificate != null && options.TlsEndpointOptions.X509Certificate != null)
|
||||
{
|
||||
throw new ArgumentException($"{nameof(MqttServerTlsTcpEndpointOptions.Certificate)} and {nameof(MqttServerTlsTcpEndpointOptions.X509Certificate)} cannot both be set");
|
||||
}
|
||||
|
||||
X509Certificate2 tlsCertificate;
|
||||
if (string.IsNullOrEmpty(options.TlsEndpointOptions.CertificateCredentials?.Password))
|
||||
if (options.TlsEndpointOptions.X509Certificate != null)
|
||||
{
|
||||
tlsCertificate = options.TlsEndpointOptions.X509Certificate;
|
||||
}
|
||||
else if (string.IsNullOrEmpty(options.TlsEndpointOptions.CertificateCredentials?.Password))
|
||||
{
|
||||
// Use a different overload when no password is specified. Otherwise the constructor will fail.
|
||||
tlsCertificate = new X509Certificate2(options.TlsEndpointOptions.Certificate);
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Security.Authentication;
|
||||
#if !WINDOWS_UWP
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
#endif
|
||||
|
||||
namespace MQTTnet.Server
|
||||
{
|
||||
@@ -89,6 +92,14 @@ namespace MQTTnet.Server
|
||||
return this;
|
||||
}
|
||||
|
||||
#if !WINDOWS_UWP
|
||||
public MqttServerOptionsBuilder WithEncryptionCertificate(X509Certificate2 certificate)
|
||||
{
|
||||
_options.TlsEndpointOptions.X509Certificate = certificate;
|
||||
return this;
|
||||
}
|
||||
#endif
|
||||
|
||||
public MqttServerOptionsBuilder WithEncryptionSslProtocol(SslProtocols value)
|
||||
{
|
||||
_options.TlsEndpointOptions.SslProtocol = value;
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using System.Net.Security;
|
||||
using System.Security.Authentication;
|
||||
#if !WINDOWS_UWP
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
#endif
|
||||
|
||||
namespace MQTTnet.Server
|
||||
{
|
||||
@@ -12,6 +15,10 @@ namespace MQTTnet.Server
|
||||
|
||||
public byte[] Certificate { get; set; }
|
||||
|
||||
#if !WINDOWS_UWP
|
||||
public X509Certificate2 X509Certificate { get; set; }
|
||||
#endif
|
||||
|
||||
public IMqttServerCertificateCredentials CertificateCredentials { get; set; }
|
||||
|
||||
public bool ClientCertificateRequired { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user