我花了幾個小時在我的覆盆子里為我的mosquitto經(jīng)紀(jì)人設(shè)置TSL連接。現(xiàn)在我可以使用客戶機(jī)證書、客戶機(jī)私鑰和ca證書在客戶機(jī)(在raspberry上)中發(fā)布和訂閱主題。它工作正常。
現(xiàn)在我想在ESP32(IDF平臺)中創(chuàng)建客戶機(jī)。我從名為ssl_mutual_auth的示例開始。不幸的是,在這個示例中使用的是客戶機(jī)證書、客戶機(jī)私鑰和服務(wù)器證書,而不是ca證書。所以。。我很困惑,不知道如何管理esp32客戶機(jī)(或Mosquitto客戶機(jī))中的ca.crt文件。我是否需要更改證書或操作系統(tǒng)配置?我使用這個指南來配置我的mosquitto代理:https://medium.com/himinds/mqtt-broker-with-secure-tls-communication-on-ubuntu-18-04-lts-and-an-esp32-mqtt-client-5c25fd7afe67
這里的Mosquitto.conf詳細(xì)說明了我設(shè)置證書路徑的位置:
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
以下是我所做的:
1-CreateCA頒發(fā)機(jī)構(gòu)(用于自簽名證書)
2-Create服務(wù)器密鑰,服務(wù)器csr,然后是server.crt(用ca.crt簽名)
3-Create客戶端密鑰,客戶端csr,然后是client.crt(用ca.crt簽名)
在raspberry客戶端中,我使用以下命令發(fā)布:
mosquitto_pub -t "test" -m "hello" -d --cert client.crt --key client.key --cafile ca.crt --insecure
我用這個來訂閱:
mosquitto_sub --cafile ca.crt -t "#" -d --cert client.crt --key client.key
ESP-IDF文檔在PKI術(shù)語方面有點(diǎn)問題。我很確定,當(dāng)他們說“服務(wù)器證書”時,他們的意思是“鏈中驗(yàn)證服務(wù)器身份的任何證書:CA、intermediate或server cert”。他們在HTTPS客戶端文檔中也犯同樣的錯誤。
不管怎樣,只要將您的CA證書輸入ESP示例項(xiàng)目并嘗試一下。確保它是PEM格式的-檢查這個答案的細(xì)節(jié)。如果需要,使用openssl轉(zhuǎn)換。