I am trying to automate the creation of certificates, using the steps from a StackOverflow answer here.
These are the commands I'm trying:
openssl genrsa -des3 -out ca.key 2048openssl req -new -key ca.key -out ca-cert-request.csr -sha256openssl x509 -req -in ca-cert-request.csr -signkey ca.key -out ca-root-cert.crt -days 365 -sha256openssl genrsa -out server.key 2048openssl req -new -key server.key -out server-cert-request.csr -sha256openssl x509 -req -in server-cert-request.csr -CA ca-root-cert.crt -CAkey ca.key -CAcreateserial -out server.crt -days 360
In step 2, I am leaving the Common Name blank. In step 5 I have tried localhost and the actual hostname for the Common Name.
When I run mosquitto_pub -h localhost -t mqttsTest42 -p 8883 -m testMessage --cafile "C:\Certificates\ca-root-cert.crt" --cert "C:\Certificates\server.crt" --key "C:\Certificates\server.key" it outputs this:
Connection error: Connection Refused: not authorised.
Error: The connection was refused.
If I run Mosquitto manually, it gives this:
C:\Program Files\mosquitto>mosquitto -c mosquitto.conf -v
1669685112: mosquitto version 2.0.14 starting
1669685112: Config loaded from mosquitto.conf.
1669685112: Opening ipv6 listen socket on port 8883.
1669685112: Opening ipv4 listen socket on port 8883.
1669685112: mosquitto version 2.0.14 running
1669685121: New connection from ::1:49375 on port 8883.
1669685121: Sending CONNACK to auto-7484C261-71E1-F653-3807-74471901380A (0, 5)
1669685121: Client auto-7484C261-71E1-F653-3807-74471901380A disconnected, not authorised.
I had this working with Mosquitto and another broker at one point. In my effort to automate this, I have changed too many things, and now cannot even get the original six steps above to work for me anymore.
I am currently using mosquitto version 2.0.14 and OpenSSL version 3.0.7 1 Nov 2022 (Library: OpenSSL 3.0.7 1 Nov 2022). I have tried one other version of Mosquitto, and one other version of OpenSSL.
The batch file I created is here.
My openssl.cnf is here.
My mosquitto.conf contains these lines:
listener 8883
certfile C:\Certificates\server.crt
keyfile C:\Certificates\server.key
cafile C:\Certificates\ca-root-cert.crt
What should I try next?