dotnet / dotnet/MQTTnet

Can't connect to a MQTT Server with supplied certificates

Open
#1,863 6 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

Hi there,
I am sorry if this is the wrong place to ask this, but I have been trying for the last weeks to connect to a MQTT Server for an application I am working on.

From this Server I got 3 files used as certificates:
- ca.pem
- mqtt.pem
- mqtt.key
Both pem files start with -----BEGIN CERTIFICATE-----
The .key file starts with -----BEGIN RSA PRIVATE KEY-----

My issue is that I can't seem to figure out how to connect to the Server with those certificates.

I did get an example from the Devs that made the Server, but it is in JavaScript:
```
var fs = require('fs');
const mqtt = require('mqtt')

console.log('mqtt test started...');

var KEY = fs.readFileSync('./cert/mqtt.key')
var CERT = fs.readFileSync('./cert/mqtt.pem')
var TRUSTED_CA_LIST = fs.readFileSync('./cert/ca.pem')

var PORT = 1883; // mqtt port
var HOST = '127.0.0.1'; // mqtt server

var options = {
port: PORT,
host: HOST,
key: KEY,
cert: CERT,
rejectUnauthorized: false,
ca: TRUSTED_CA_LIST,
protocol: 'mqtts'
}

console.log('try to connect....');

const client = mqtt.connect(options)
```

The example I got works perfectly, but since my project is in C# I can't use the one they provided.

Am I just getting stuck with a somewhat simple issue or is this something else?
I'd love to know how I should use those files in MQTTnet since everything I tried leads me to the error
`The remote certificate was rejected` and I even tried the mqttMultimeter, but I get the same error.
I even tried to convert the mqtt.pem and the mqtt.key to a .pfx file with openssl, but it still gets rejected.

### Which project is your question related to?
- Client

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the MQTTnet client certificate configuration and compare it with the supplied JavaScript example, including ca.pem, mqtt.pem, and mqtt.key. Reproduce the rejected-certificate error in the mqttMultimeter and C# client using the reported settings; done means the client connects successfully to the MQTT server with the supplied certificates.

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
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.