MQTT TLS on ESP8266 on personal server #18339
Replies: 4 comments 26 replies
-
You doesn't use Caddy and Mosquitto as Docker container ? |
Beta Was this translation helpful? Give feedback.
-
Good write up! I have yet to enable TLS on my Tasmota devices because I never could understand how it all worked. I am running my Mosquitto broker on a Raspberry Pi 4. I have a spare Pi - so I may have to give this a go. Thanks for putting this together. |
Beta Was this translation helpful? Give feedback.
-
I am really struggling to put this puzzle together. Using my Raspberry Pi as my "server", I did get Caddy installed and believe I got the needed directories created. Changed users, groups and permissions - that is a whole other can of worms. Added the info to Mosquitto local.conf but when I restart Mosquitto it fails, log says missing CA file. I went to LetsEncrypt and that is where I started being instructed to install Apache2 and Certbot. Am I trying to install too many pieces? |
Beta Was this translation helpful? Give feedback.
-
Not sure if this helps, but I installed acme.sh on my RaspPi and ran comment to get certs for my site. See log file below. Seemed to run without issue until time 09:02:53 "verify error"? nam@GaragePi3B-Plus:/var/lib/caddy $ acme.sh --issue -d xyz.660p.cz -w /var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/xyz.660p.cz --debug |
Beta Was this translation helpful? Give feedback.
-
Looked at documentation and a few discussion threads, and came up with a solution that works for my setup.
Server: Running Ubuntu 22.04 with Caddy managing Let's Encrypt certificates/renewals (for all my services) and Mosquitto as broker.
Install Caddy with the following JSON config. Requires changing the service to load a JSON file vs the default Caddyfile. To do this, edit /lib/systemd/system/caddy.service and change the following lines:
to
or whatever location you want to store your Caddy JSON config.
Need to
sudo systemctl daemon-reload
at this pointCaddy JSON config should have the following to allow it to request the right certs from Let's Encrypt:
Restart caddy service with
sudo systemctl restart caddy
Tasmota can only deal with ECDHE_RSA_WITH_AES_128_GCM_SHA256 cipher by default, and to force Caddy to generate certificates with the smaller 2048-bit RSA, need to specify key_type of rsa2048.
Once certificates are requested, they are stored in
/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/mqtt.example.com/mqtt.example.com.crt
/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/mqtt.example.com/mqtt.example.com.json
/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/mqtt.example.com/mqtt.example.com.key
Up to the user how to access those certificates with Mosquitto. I changed group ownership of the directories and added the mosquitto user to a group with caddy so both services could access the directories/files. Certificates need to have read/execute privileges by mosquitto, and directories need read/write/execute (I think). Could copy the certificates to /etc/mosquitto/certs/ but I think you'd have to do that manually every three months.
Check out caddy cert request logs at
sudo journalctl -xeu caddy.service
Mosquitto config (/etc/mosquitto/conf.d/default.conf) should have the following:
Guide to username/password on Mosquitto.
Note that the R3 Let's Encrypt Certificate Authority hangs out in the default Ubuntu folder above. Need to adjust permissions so mosquitto user has read/execute authority for it. Or just copy the CA file to the mosquitto directory. Can download it from lets-encrypt and rename to
lets-encrypt-r3.crt
.Save and restart mosquitto service
sudo systemctl restart mosquitto
Errors usually have to do with Mosquitto accessing the certificate files.
Once mosquitto is running, check that the ciphers/algorithm are correct by issuing the following command with a computer with nmap installed:
nmap --script ssl-enum-ciphers -p 8883 mqtt.example.com
Should see an entry for
TLS_RSA_WITH_AES_128_GCM_SHA256 (rsa 2048)
which is just what Tasmota wants.Compile tasmota with the following #defines:
Note in documentation, the following statement:
This seems to not be necessary, and introduces compile errors.
Beta Was this translation helpful? Give feedback.
All reactions