Merge pull request #895 from borigas/x509Cert

Add an x509 certificate parameter
This commit is contained in:
Christian
2020-05-26 23:14:23 +02:00
committed by GitHub
3 changed files with 28 additions and 2 deletions
@@ -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);