Skip to content

Commit

Permalink
Adds a fix for an MQTTNet bug on cert verifications
Browse files Browse the repository at this point in the history
  • Loading branch information
i8beef committed Dec 26, 2022
1 parent 1c97d06 commit fa290d8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/HomeAutio.Mqtt.Core/ServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,18 @@ public async Task StartAsync(CancellationToken cancellationToken = default)
throw new ArgumentException($"BrokerSettings {nameof(_brokerSettings.BrokerTlsSettings)} cannot be null when {nameof(_brokerSettings.BrokerUseTls)} is true");
}

// Temporary fix for https://github.com/dotnet/MQTTnet/issues/1547
var certificateValidationHandler = MqttClientDefaultCertificateValidationHandler.Handle;

var tlsOptions = new MqttClientOptionsBuilderTlsParameters
{
UseTls = _brokerSettings.BrokerUseTls,
AllowUntrustedCertificates = _brokerSettings.BrokerTlsSettings.AllowUntrustedCertificates,
IgnoreCertificateChainErrors = _brokerSettings.BrokerTlsSettings.IgnoreCertificateChainErrors,
IgnoreCertificateRevocationErrors = _brokerSettings.BrokerTlsSettings.IgnoreCertificateRevocationErrors,
SslProtocol = _brokerSettings.BrokerTlsSettings.SslProtocol,
Certificates = _brokerSettings.BrokerTlsSettings.Certificates
Certificates = _brokerSettings.BrokerTlsSettings.Certificates,
CertificateValidationHandler = certificateValidationHandler
};

optionsBuilder.WithTls(tlsOptions);
Expand Down

0 comments on commit fa290d8

Please sign in to comment.