I'm using dotnet core to develop an application that will be sending messages to an IoT Hub. This application will be running under Unix. To do so I've used X509 certificate authentication as explained in the following link:
https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-security-x509-get-started
If I run the application using Visual Studio 2019 on debug mode the application runs perfectly. On The other hand, while running under unix it always throws a "TLS authentication error." exception.
Stack trace: " at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.ExecuteWithErrorHandlingAsync[T](Func`1 asyncOperation) at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.<>c__DisplayClass33_0.<b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.EnsureOpenedAsync(CancellationToken cancellationToken) at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.<>c__DisplayClass14_0.<b__0>d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.SendEventAsync(Message message, CancellationToken cancellationToken) at Venom.IoT.IoTDeviceClient.SendEventAsync(Message message, CancellationToken cancellationToken) in C:\SBNRepo\Venom\VenomIoT\IoT\IoTDeviceClient.cs:line 43 at Venom.IoT.VenomIoTDevice.SendVenomIoTMessage(VenomIoTMessage venomIoTMessage, CancellationToken cancellationToken) in C:\SBNRepo\Venom\VenomIoT\VenomIoTDevice.cs:line 41 at Venom.IoT.VenomIoTDevice.Start(CancellationToken cancellationToken) in C:\SBNRepo\Venom\VenomIoT\VenomIoTDevice.cs:line 58"
I've captured the inner exception and it's the following: Inner Exception: System.Security.Authentication.AuthenticationException - The remote certificate is invalid according to the validation procedure.
Seems that certificates not match...but why do they unde Windows?
This is how I'm creating my device instace:
var cert = new X509Certificate2(certPath, certPwd);
var auth = new DeviceAuthenticationWithX509Certificate(deviceId, cert);
_deviceClient = DeviceClient.Create(iotHubUri, auth, TransportType.Mqtt);
and this is how I'm sending the d2c message:
var messageString = JsonConvert.SerializeObject(myMessage);
var message = new Message(Encoding.ASCII.GetBytes(messageString));
await _deviceClient.SendEventAsync(message, cancellationToken);
I've been struggling with this for the last couple of days, really trying to figure it out... any suggestions? They'll be very much appreciated.
Thanks in advance!