Creating SSL Certificates for Secure MQTT communication By Ranjith kumar DSM April 12, 2017 SSL Certificates play a major role enabling the security. Hence we enable TLS/SSL mode of data transfer secure MQTT Communication.SSL certificates are files that has digital data of encryption key to encrypt data for security. Hence, You can use the certificates to make sure the data encryption in the tunnel and cannot be tampered. There is a need of key for decoding the data at the other end.Must Read Other Related PostMQTT Broker integration using REST APIMQTT Broker Comparison – MQTTRoute vs MosquittoDocker MQTT Broker for easy service manageabilityChoosing Best MQTT Broker for your IoT Implementation Lower Power consumptionMQTT vs REST from IoT Implementation perspectiveThis blog provides a detailed and a quick guide to create a self signed certificate using the openssl installed in ubuntu.Create Root CertificateThe following command creates the private key file.openssl genrsa -out root.key 2048To create a password protected key by adding -des3.openssl genrsa -des3 -out root.key 2048The above command will create a root.key In the current folder. our next step is to generate Certificate signing request file using above generated RSA private Key. Besides that, It contains encrypted personal details of the Host ie. country, state, organization, common Name, email address, and public key.openssl req -new -key root.key -out root.csrThe above command will prompt for the following details.Country Name : State or Province Name : Locality Name : Organization Name : Organizational Unit Name : Common Name (e.g. server FQDN or YOUR name): Email Address : A challenge password :(optional) An optional company name :(optional)You can use the above two files to sign the certificate.openssl x509 -req -days 365 -sha1 -extensions v3_ca -signkey root.key -in root.csr -out root.crtThe above command creates the X509 based root certificate which is considered as CA Root Certificate The above command generated a root certificate root.crt which is valid for 365 days.Creating a MQTT Server certificateYou need to create the server key file using the following command.openssl genrsa -out server.key 2048Create a Server csr file that holds the complete server details of the host. The following command will prompt for the company details.openssl req -new -key server.key -out server.csrUse the following command to create the Server certificate . The root certificate will be used for creating the server certificate.openssl x509 -req -days 365 -sha1 -extensions v3_req -CA root.crt -CAkey root.key -CAcreateserial -in server.csr -out server.crtCreating MQTT Client certificateThe above procedure followed for the server certificate can be used to create the client certificates. Please use appropriate name for the files.The above certificates are also valid for 365 days. Same Certificate Authority is used for generating both the client and Server certificate.Secure MQTT Communication in MQTT BrokerThe root certificate, server certificate and server private key needs to be placed on the server side and the root certificate, client certificate and the client private key needs to be placed in the client side.We can either have a common client certificate or individual certificate for each client. You can issue a certificate to client using your own root.key and root.crt. MqttRoute / MQTT Server verify the common name and the client IP during the connection process. If both are same then only broker allows the client to connect otherwise reject the client’s connection request.Follow the steps to run the MQTT Broker and the MQTT client in the MQTT Broker.Broker certificate and Key file MUST be present in ./Certificate/server folder.Client certificate and Key file MUST be present in ./Certificate/client folder.CA Certificate MUST present in ./Certificate/root folder.Broker and Client certificates MUST be signed by same CA.Download the makefile and follow the above procedure to secure MQTT communication in minutes. Please make sure the necessary information is provided during the prompt. You can download the FREE MQTT Broker now.Write to support for any assistance regarding MQTT Security.Leave a Reply Cancel replyYour email address will not be published. Required fields are marked *CommentName * Email * Website Save my name, email, and website in this browser for the next time I comment.