dotnet / dotnet/MQTTnet

Connect to broker using CA Cert ClientCert and Key

Open
#1,522 2 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
C#
Stars
5.1k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

I am using MQTTNet with .Net 6 . My MQTT Broker provides 3 certificates as follows
-CA Cert
-Client Cert
-Client Key

These certificates are valid and work if i use them with a software like MQTTExplorer.

Now I am trying to use MqttNet (latest version) to connect to the broker. I have read the documentation and accordingly tried by converting clientCert and Key to pfx file using following command.

` openssl pkcs12 -export -out certificate.pfx -inkey clientkey.pem -in clientCert.crt`

Now I have two certificates
-certificate.pfx (with password)
- ca cert
I am trying to use MQTTNet as follows in console app:

```
var factory = new MqttFactory();
var mqttClient = factory.CreateMqttClient();

var caCert = X509Certificate.CreateFromCertFile(@"certificates\cacert.cer");

var clientCert = new X509Certificate2(@"certificates\mycertificate.pfx", "mypassword");

var options = new MqttClientOptionsBuilder()
.WithClientId(clientId)
.WithTcpServer(mqttUri, mqttPort)
.WithTls(new MqttClientOptionsBuilderTlsParameters
{
UseTls = true,
SslProtocol = System.Security.Authentication.SslProtocols.Tls12,
Certificates = new List()
{
caCert,clientCert
}
}).Build();

await mqttClient.ConnectAsync(options, CancellationToken.None);

```
On connectAsync I get an error, "Unknown error occured while processing certificates. Not sure what is wrong here ? I have tried to follow the documentation as well

https://github.com/dotnet/MQTTnet/wiki/Client#certificate-based-authentication -- TLS using client Certificate

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the certificate-based authentication section linked in the issue, then inspect the shown console-app configuration and the CA, client certificate, and client key inputs. Done means identifying why ConnectAsync rejects the certificate collection and achieving a successful TLS connection to the broker.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
networking, security
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.