SSL Handshake Certificate creation
I am using a Gateway that supports MQTT over SSL only. But the manufacturers have not provided any certificate necessary for the handshake. I have been following the procedures mentioned on the net to create these certificates on my own wherein i will will be the signing authority but have not succeeded yet. i needed some detailed guidance.
Saravanan GanesanPosted Aug 4, 2023, 7:22 PM
Hi Harsh Pandit , check the below answer .
Creating SSL certificates and setting up MQTT over SSL can be a complex process, especially when you need to act as your own certificate authority. Here's a detailed step-by-step guide to help you generate SSL certificates and set up MQTT over SSL on your gateway:
1. Prerequisites:
Ensure you have OpenSSL installed on your system. If you don't have it, you can install it on Linux using the package manager or download it for Windows from the official OpenSSL website.
2. Generate Root Certificate:
Create a root certificate that will act as the signing authority for your SSL certificates.
openssl genrsa -out rootCA.key 2048
openssl req -x509 -new -nodes -key rootCA.key -sha256 -days 3650 -out rootCA.crt
3. Generate Certificate Signing Request (CSR) for Your Gateway:
Create a CSR for your gateway, which will be used to obtain a certificate signed by your root certificate.
openssl genrsa -out gateway.key 2048
openssl req -new -key gateway.key -out gateway.csr
4. Sign the CSR with Your Root Certificate:
Use your root certificate to sign the gateway's CSR and generate the gateway certificate.
openssl x509 -req -in gateway.csr -CA rootCA.crt -CAkey rootCA.key -CAcreateserial -out gateway.crt -days 365
5. Combine the Certificate and Private Key:
To use the certificate with your gateway, you'll need to combine the gateway certificate and private key into a single PEM file.
cat gateway.crt gateway.key > gateway.pem
6. Enable MQTT over SSL on the Gateway:
Consult your gateway's documentation to enable MQTT over SSL and provide the generated gateway.pem file as the SSL certificate.
7. MQTT Broker Configuration:
Ensure that your MQTT broker (e.g., Mosquitto) is configured to accept SSL connections. Generate the broker's SSL certificate and key in a similar manner as the gateway.
8. Testing:
Test the SSL connection from your gateway to the MQTT broker using the following command:
openssl s_client -connect
Make sure to replace and with your MQTT broker's address and port.
By following these steps, you should be able to generate SSL certificates and set up MQTT over SSL on your gateway. Please note that SSL certificate generation can be tricky, and any misconfiguration could result in connection failures. Double-check all configurations and ensure the necessary files are in the correct locations on your gateway.
Sachin SinghPosted Jan 22, 2021, 10:24 AM