mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-20 19:58:57 +08:00
Expose server certificate password and client certificate options to MqttServerOptionsBuilder
This commit is contained in:
@@ -139,6 +139,13 @@ namespace MQTTnet.Client.Options
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MqttClientOptionsBuilder WithCredentials(IMqttClientCredentials credentials)
|
||||||
|
{
|
||||||
|
_options.Credentials = credentials;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public MqttClientOptionsBuilder WithExtendedAuthenticationExchangeHandler(IMqttExtendedAuthenticationExchangeHandler handler)
|
public MqttClientOptionsBuilder WithExtendedAuthenticationExchangeHandler(IMqttExtendedAuthenticationExchangeHandler handler)
|
||||||
{
|
{
|
||||||
_options.ExtendedAuthenticationExchangeHandler = handler;
|
_options.ExtendedAuthenticationExchangeHandler = handler;
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace MQTTnet.Implementations
|
|||||||
throw new ArgumentException("TLS certificate is not set.");
|
throw new ArgumentException("TLS certificate is not set.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var tlsCertificate = new X509Certificate2(options.TlsEndpointOptions.Certificate);
|
var tlsCertificate = new X509Certificate2(options.TlsEndpointOptions.Certificate, options.TlsEndpointOptions.Password.Password);
|
||||||
if (!tlsCertificate.HasPrivateKey)
|
if (!tlsCertificate.HasPrivateKey)
|
||||||
{
|
{
|
||||||
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.");
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
public interface IMqttServerCredentials
|
||||||
|
{
|
||||||
|
String Password { get; }
|
||||||
|
}
|
||||||
@@ -82,9 +82,10 @@ namespace MQTTnet.Server
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public MqttServerOptionsBuilder WithEncryptionCertificate(byte[] value)
|
public MqttServerOptionsBuilder WithEncryptionCertificate(byte[] value, IMqttServerCredentials password = null)
|
||||||
{
|
{
|
||||||
_options.TlsEndpointOptions.Certificate = value;
|
_options.TlsEndpointOptions.Certificate = value;
|
||||||
|
_options.TlsEndpointOptions.Password = password;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,6 +95,14 @@ namespace MQTTnet.Server
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MqttServerOptionsBuilder WithClientCertificate(RemoteCertificateValidationCallback validationCallback = null, bool checkCertificateRevocation = false)
|
||||||
|
{
|
||||||
|
_options.TlsEndpointOptions.ClientCertificateRequired = true;
|
||||||
|
_options.TlsEndpointOptions.CheckCertificateRevocation = checkCertificateRevocation;
|
||||||
|
_options.TlsEndpointOptions.CertificateValidationCallback = validationCallback;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public MqttServerOptionsBuilder WithoutEncryptedEndpoint()
|
public MqttServerOptionsBuilder WithoutEncryptedEndpoint()
|
||||||
{
|
{
|
||||||
_options.TlsEndpointOptions.IsEnabled = false;
|
_options.TlsEndpointOptions.IsEnabled = false;
|
||||||
@@ -107,7 +116,7 @@ namespace MQTTnet.Server
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public MqttServerOptionsBuilder WithStorage(IMqttServerStorage value)
|
public MqttServerOptionsBuilder WithStorage(IMqttServerStorage value)
|
||||||
{
|
{
|
||||||
_options.Storage = value;
|
_options.Storage = value;
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ namespace MQTTnet.Server
|
|||||||
|
|
||||||
public byte[] Certificate { get; set; }
|
public byte[] Certificate { get; set; }
|
||||||
|
|
||||||
|
public IMqttServerCredentials Password { get; set; }
|
||||||
|
|
||||||
public bool ClientCertificateRequired { get; set; }
|
public bool ClientCertificateRequired { get; set; }
|
||||||
|
|
||||||
public bool CheckCertificateRevocation { get; set; }
|
public bool CheckCertificateRevocation { get; set; }
|
||||||
|
|||||||
Reference in New Issue
Block a user