Hi,
It’s a pretty good overview on that page. I’ve just tested this myself and it worked exactly as I expected, so let me explain what I did so we can find out what is different.
I’m using mosquitto 2.0.11, and I’m using certificates that are in the mosquitto repository so I don’t need to worry about generating them myself. The certificates are only useful when working on a single computer, but that’s fine here.
My configuration file is:
listener 8883
cafile test/ssl/all-ca.crt
certfile test/ssl/server.crt
keyfile test/ssl/server.key
require_certificate true
# To make testing a little simpler:
allow_anonymous true
The certificates are in the test/ssl
directory of the mosquitto source, I’m going to be running mosquitto from the root directory of the mosquitto source:
cd /path/to/source
mosquitto -c test.conf -v
Now I’ll try to connect with mosquitto_sub. First without specifying our CA certificate (because we’re using port 8883, mosquitto_sub will default to using TLS in version 2.0 and later, in earlier versions it would not use TLS unless explicitly told to).
$ mosquitto_sub -p 8883 -t topic -d
Client (null) sending CONNECT
OpenSSL Error[0]: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
Error: A TLS error occurred.
As expected, the client rejected our custom certificate.
Now trying with the CA certificate (which is at test/ssl/all-ca.crt
):
$ mosquitto_sub -p 8883 -t asdf -d --cafile test/ssl/all-ca.crt
Client (null) sending CONNECT
OpenSSL Error[0]: error:1409445C:SSL routines:ssl3_read_bytes:tlsv13 alert certificate required
Error: The connection was lost.
This gives the error I’d expect - the server is rejecting the connection because the client isn’t providing a certificate.
Now trying with a certificate:
$ mosquitto_sub -p 8883 -t asdf -d --cafile test/ssl/all-ca.crt --cert test/ssl/client.crt --key test/ssl/client.key
Client (null) sending CONNECT
Client (null) received CONNACK (0)
Client (null) sending SUBSCRIBE (Mid: 1, Topic: asdf, QoS: 0, Options: 0x00)
Client (null) received SUBACK
Subscribed (mid: 1): 0
And it succeeds.
Please take a look and see where your configuration differs. If there’s something that doesn’t make sense I’d be happy to hear about it so we can improve things for other people.
Regards,
Roger