Getting error while establishing connection with MQTT on Azure Container :tlsv13 alert certificate required but it is working on the local windows machine
public MQTTClient(MQTTClientOptions clientOptions, IOSPLogger logger)
{
try
{
certificateProvider = new KeyVaultCertificatesProvider(clientOptions.DeviceCertificateName, new Uri(clientOptions.KeyVaultUri), logger);
_clientOptions = new MqttClientOptionsBuilder()
.WithTcpServer(clientOptions.Host, clientOptions.Port)
.WithProtocolVersion(MQTTnet.Formatter.MqttProtocolVersion.V500)
.WithWillQualityOfServiceLevel(MqttQualityOfServiceLevel.AtLeastOnce)
.WithClientId(Guid.NewGuid().ToString())
.WithWillRetain(true)
.WithTlsOptions(new MqttClientTlsOptions
{
UseTls = clientOptions.UseTLS,
ClientCertificatesProvider = certificateProvider,
IgnoreCertificateRevocationErrors = true,
AllowUntrustedCertificates = true,
IgnoreCertificateChainErrors = true
})
.WithCleanStart(clientOptions.CleanStart)
.WithKeepAlivePeriod(TimeSpan.FromSeconds(clientOptions.KeepAlive))
.Build();
_automaticReconnect = clientOptions.AutomaticReconnect;
_client = new MqttFactory().CreateMqttClient();
_logger = logger;
JsonSerializerOptions option = new JsonSerializerOptions()
{
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull
};
}
catch (Exception e)
{
throw new MQTTClientInitializationException(e.Message);
}
}
MQTTnet.Adapter.MqttConnectingFailedException: Error while authenticating. The decryption operation failed, see inner exception. —> MQTTnet.Exceptions.MqttCommunicationException: The decryption operation failed, see inner exception. —> System.IO.IOException: The decryption operation failed, see inner exception. —> Interop+OpenSsl+SslException: Decrypt failed with OpenSSL error - SSL_ERROR_SSL. —> Interop+Crypto+OpenSslCryptographicException: error:0A00045C:SSL routines::tlsv13 alert certificate required — End of inner exception stack trace — at Interop.OpenSsl.Decrypt(SafeSslHandle context, Span1 buffer, SslErrorCode& errorCode) at System.Net.Security.SslStreamPal.DecryptMessage(SafeDeleteSslContext securityContext, Span
1 buffer, Int32& offset, Int32& count) — End of inner exception stack trace — at System.Net.Security.SslStream.ReadAsyncInternal[TIOAdapter](Memory1 buffer, CancellationToken cancellationToken) at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder
1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at MQTTnet.Implementations.MqttTcpChannel.ReadAsync(Byte buffer, Int32 offset, Int32 count, CancellationToken cancellationToken) at MQTTnet.Adapter.MqttChannelAdapter.ReadFixedHeaderAsync(CancellationToken cancellationToken) at MQTTnet.Adapter.MqttChannelAdapter.ReceiveAsync(CancellationToken cancellationToken) at MQTTnet.Adapter.MqttChannelAdapter.ReceivePacketAsync(CancellationToken cancellationToken) — End of inner exception stack trace — at MQTTnet.Adapter.MqttChannelAdapter.WrapAndThrowException(Exception exception) at MQTTnet.Adapter.MqttChannelAdapter.ReceivePacketAsync(CancellationToken cancellationToken) at MQTTnet.Client.MqttClient.Receive(CancellationToken cancellationToken) at MQTTnet.Client.MqttClient.Authenticate(IMqttChannelAdapter channelAdapter, MqttClientOptions options, CancellationToken cancellationToken) — End of inner exception stack trace — at MQTTnet.Client.MqttClient.Authenticate(IMqttChannelAdapter channelAdapter, MqttClientOptions options, CancellationToken cancellationToken) at MQTTnet.Client.MqttClient.ConnectInternal(IMqttChannelAdapter channelAdapter, CancellationToken cancellationToken) at MQTTnet.Client.MqttClient.ConnectAsync(MqttClientOptions options, CancellationToken cancellationToken) at MQTTnet.Client.MqttClient.ConnectAsync(MqttClientOptions options, CancellationToken cancellationToken)