mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-19 19:13:11 +08:00
Add abstraction layer for server certificate.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Security.Authentication;
|
||||
using MQTTnet.Certificates;
|
||||
|
||||
#if !WINDOWS_UWP
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
#endif
|
||||
@@ -10,7 +12,7 @@ namespace MQTTnet.Server
|
||||
{
|
||||
public class MqttServerOptionsBuilder
|
||||
{
|
||||
private readonly MqttServerOptions _options = new MqttServerOptions();
|
||||
readonly MqttServerOptions _options = new MqttServerOptions();
|
||||
|
||||
public MqttServerOptionsBuilder WithConnectionBacklog(int value)
|
||||
{
|
||||
@@ -85,17 +87,24 @@ namespace MQTTnet.Server
|
||||
return this;
|
||||
}
|
||||
|
||||
#if !WINDOWS_UWP
|
||||
public MqttServerOptionsBuilder WithEncryptionCertificate(byte[] value, IMqttServerCertificateCredentials credentials = null)
|
||||
{
|
||||
_options.TlsEndpointOptions.Certificate = value;
|
||||
_options.TlsEndpointOptions.CertificateCredentials = credentials;
|
||||
if (value == null) throw new ArgumentNullException(nameof(value));
|
||||
|
||||
_options.TlsEndpointOptions.CertificateProvider = new BlobCertificateProvider(value)
|
||||
{
|
||||
Password = credentials?.Password
|
||||
};
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
#if !WINDOWS_UWP
|
||||
public MqttServerOptionsBuilder WithEncryptionCertificate(X509Certificate2 certificate)
|
||||
{
|
||||
_options.TlsEndpointOptions.X509Certificate = certificate;
|
||||
if (certificate == null) throw new ArgumentNullException(nameof(certificate));
|
||||
|
||||
_options.TlsEndpointOptions.CertificateProvider = new X509CertificateProvider(certificate);
|
||||
return this;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user