I spent hours to to setup the TSL connection for my mosquitto broker in my raspberry. Now I can publish and subscribe topics in a client (on raspberry) using client certificate, client private key and ca certificate. It works correctly.
Now I want to create the client in the ESP32 (IDF platform). I started from the example called ssl_mutual_auth. Unfortunatly in the example is used the client certificate, client private key and a server certificate not the ca certificate. So.. I'm confused and I don't know how to manage the ca.crt file in esp32 client (or Mosquitto client). Do I need to change my certificates or my mosquittos configuration? I used this guide to configure my mosquitto broker : https://medium.com/himinds/mqtt-broker-with-secure-tls-communication-on-ubuntu-18-04-lts-and-an-esp32-mqtt-client-5c25fd7afe67
Here the Mosquitto.conf details where I set the path of certificates:
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
allow_anonymous false
password_file /etc/mosquitto/passwords
include_dir /etc/mosquitto/conf.d
cafile /etc/mosquitto/certs/ca.crt
certfile /etc/mosquitto/certs/server.crt
keyfile /etc/mosquitto/certs/server.key
require_certificate true
use_identity_as_username true
Here what I did:
1-Create the CA Authority (for self signed certificates)
2-Create a Server Key, Servers csr and then server.crt (signed with ca.crt)
3-Create a Client Key, Client csr and then client.crt (signed with ca.crt)
In raspberry client, I use this to publish:
mosquitto_pub -t "test" -m "hello" -d --cert client.crt --key client.key --cafile ca.crt --insecure
And I use this to subscribe:
mosquitto_sub --cafile ca.crt -t "#" -d --cert client.crt --key client.key