I’m trying to use Device Certificates with the MQTT interface to Cumulocity. I have things working with a TLS secured connection using password authentication. But when I try to use Device Certificates, my client (the ESP32 SDK version 5.1.4) returns unauthorized. I also tried to use the same certificates and connect using MQTTX, which also returned “unauthorized”
This is the process I use. First I generate the root certificate that I’ll be putting in the “trusted certificates” section of my cumulocity instance;
openssl genrsa -out autodoser-private-key.pem 2048
Then the sign request;
openssl req -new -key autodoser-private-key.pem -out autodoser-cert-sign-request.pem -extensions v3_req -subj "/C=US/ST=Delaware/L=Wilmington/O=Solenis/CN=*.solenis.com"
Then I create and sign the public key;
openssl x509 -in autodoser-cert-sign-request.pem -out autodoser-cert.pem -req -signkey autodoser-private-key.pem -extensions v3_req -extfile intermediate-config.cnf -days 3650
intermediate-config.cnf.txt (115 Bytes)
I put the autodoser-cert.pem in the trusted certificates, enable it and then take the verification text from the page and put it into the file verification.txt
openssl dgst -sha256 -sign autodoser-private-key.pem verification_code.txt | openssl base64 -A
I take the code generated from this and put it into the verification to confirm ownership of the key. The trusted certificate entry acknowledges this.
DEVICE_ID represents the ID of the device I’m trying to generate cert/key pair for;
openssl genrsa -out DEVICE_ID-private-key.pem 2048
openssl req -new -key DEVICE_ID-private-key.pem -out DEVICE_ID-cert-sign-request.pem -extensions v3_req -subj "/C=US/ST=Delaware/L=Wilmington/O=device/CN=DEVICE_ID"
openssl x509 -req -CA autodoser-cert.pem -CAkey autodoser-private-key.pem -in DEVICE_ID-cert-sign-request.pem -out DEVICE_ID-cert.pem -days 730 -extensions v3_req -extfile "end-user-config.cnf" -CAcreateserial
end-user-config.cnf.txt (103 Bytes)
I then use the values from DEVICE_ID-cert.pem and DEVICE_ID-private-key.pem in the authentication structures of the mqtt client library. Can you see anything wrong with my key generation?