MQTT.js
MQTT.js copied to clipboard
Unable to connect over TLS
Hi, I'm trying to connect to a broker over TLS in react-native. Based on the doc I tried this code:
const options = {
port: PORT,
host: HOST,
protocol: 'mqtts',
secureProtocol: 'TLS_method',
username: USERNAME,
password: PASSWORD,
ca: CA_FILE
}
const client = mqtt.connect(options);
client.on('error', (error) => {
console.log("error", error);
});
client.on('connect', () => {
console.log("connected");
});
The options object will be passed through tls.connect()
, so I specified the certificate file.
The connection doesn't return an error, but the client is not connected. What did I do wrong?
Thanks in advance for your help
What is CA_FILE
? It can't be a path to file--you need to load it yourself and pass in the file's content as a Buffer
or string.
Try running with env var DEBUG=mqttjs,mqttjs:*
to see if there is any useful output.
CA_FILE
is the file content as a string, not the path.
The broker log show:
1595238085: OpenSSL Error: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown
1595238085: Socket error on client <unknown>, disconnecting.
I checked, and the cafile in the mosquitto.conf is the same one I use. What could cause this error ?
I think the certificate in mosquitto.conf and the CA file you use with MQTT.js would only be the same if the certificate was self-signed.
Your error message makes me think mosquitto is expecting a client certificate. Are you setting the require_certificate and cafile options in mosquitto.conf? If so, remove those. You should probably only be setting certfile and keyfile. But if you are trying to use client certificates, you need to also set the cert and key options with MQTT.js.
How did you solve it ?
This is an automated message to let you know that this issue has gone 365 days without any activity. In order to ensure that we work on issues that still matter, this issue will be closed in 14 days.
If this issue is still important, you can simply comment with a "bump" to keep it open.
Thank you for your contribution.
This issue was automatically closed due to inactivity.