You can find my video covering the steps described below on my YT channel:
This is a deep dive into x509 certificates and how they are used in IoT.
We are going to build a complete IoT system:
- two IoT Devices
- MQTT Broker
- Private CA
and establish trust between devices:
We will configure the Private CA from scratch and use it to sign x509 certificates for our devices.
Device certificates are used to:
- confirm device identity (this device is the actual devices it claims to be, not some rogue device that tries to access our system)
- enable TLS encryption for communication between devices (so messages can not be read or modified by a potential attacker)
I am using Docker and Docker-Compose to create the environment used in this deep dive but docker knowledge is not needed to follow me.
If you want to replicate this setup on your system you need to install those tools. The installation is easy for all systems (Windows, Mac, Linux) and is described in the official documentation:
https://docs.docker.com/get-docker/
https://docs.docker.com/compose/install/
Once you clone or download this repository you need to execute the following command:
docker-compose up --build
It will create four containers:
- my_private_ca
- mq_broker
- client_a
- client_b
These containers are emulating real devices in our system.
Once we have containers running our setup will proceed as follows:
- attach to the
my_private_ca
container- generate the Private Key
- generate the self-signed CA Certificate
- attach to the
mq_broker
container- generate the Private Key
- generate the CSR (Certificate Sign Request)
- attach to the
my_private_ca
container- sign the CSR from MQTT Broker to create the MQTT Broker certificate
- attach to the
mq_broker
container- move the certificate to the proper directory
- attach to the
client_a
container- generate the Private Key
- generate the CSR
- attach to the
client_b
container- check if the Private Key and CSR were created for you (I used a bit of Docker magic here, check the Dockerfile-client_b for details)
- attach to the
my_private_ca
container- sign CSR from Client A to create the certificate for that device
- sign CSR from Client B to create the certificate for that device
- attach to the
mq_broker
container- start the MQTT sever and leave it running
- attach to the
client_a
container- subscribe to the test topic at MQTT Broker
- attach to the
client_b
container- publish the MQTT message to the test topic at MQTT Broker
The above process looks complex and needs many manual (error-prone) actions. In the real-world solution all of those tasks should be automated.
I decided to use the manual approach in order to guide you through the end-to-end process of system configuration. I hope that it was useful.
Let me know in case of any questions or comments!
https://www.facebook.com/lmtx.iot.7 https://twitter.com/lmtx1 https://t.me/lmtxdev