[英]"certificate verify failed" when bridging AWS IoT with local Mosquitto MQTT
我在本地樹莓派上安裝了一個 mosquitto MQTT,它的工作非常迷人。 我在 AWS IoT 上創建了一個同樣有效的 MQTT 代理。
在我的樹莓派上,我可以使用 mosquitto_pub 和 mosquitto_sub 命令“手動”連接、發布和訂閱 AWS 代理。 當我手動執行此操作時,我使用所有證書和內容。 我使用的命令是:
mosquitto_pub --cafile amazonCA1.pem --cert certificate.cert --key private.key -h XXXXXXXXXXXXXXXXXX.amazonaws.com -p 8883 -q 1 -d -t "iot/test" -m "testing message"
所以,我認為問題不在於證書。
問題是當我更改配置以使用“橋接模式”時,我在 mosquitto 日志中收到以下消息:
1584371971: Connecting bridge (step 1) awsiot (XXXXXXXXXXXXXXXXXXXXX.amazonaws.com:8883)
1584371972: Connecting bridge (step 2) awsiot (XXXXXXXXXXXXXXXXXXXXX.amazonaws.com:8883)
1584371972: Bridge bridgeawsiot sending CONNECT
1584371972: OpenSSL Error: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
1584371972: Socket error on client local.bridgeawsiot, disconnecting.
1584371977: Bridge local.bridgeawsiot doing local SUBSCRIBE on topic #
這是我的 mosquitto.conf:
pid_file /var/run/mosquitto.pid
persistence true persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log log_type all
#log_dest topic
log_type error log_type warning log_type notice log_type information
connection_messages true log_timestamp true
include_dir /etc/mosquitto/conf.d
password_file /etc/mosquitto/passwordfile allow_anonymous false
這是我的 /etc/mosquitto/conf.d/bridge.conf
connection awsiot
address XXXXXXXXXXXXXXXXXXXX.amazonaws.com:8883
# Specifying which topics are bridged
topic # both 1
# Setting protocol version explicitly
bridge_protocol_version mqttv311
bridge_insecure false
# Bridge connection name and MQTT client Id,
# enabling the connection automatically when the broker starts.
cleansession true
clientid bridgeawsiot
start_type automatic
notifications false
log_type all
# =================================================================
# Certificate based SSL/TLS support
# -----------------------------------------------------------------
#Path to the rootCA
bridge_cafile /home/pi/certs/amazonCA1.pem
# Path to the PEM encoded client certificate
bridge_certfile /home/pi/certs/certificate.cert
# Path to the PEM encoded client private key
bridge_keyfile /home/pi/certs/private.key
所以,總的來說問題是:當我手動連接/發布/訂閱時,一切正常......但是當我使用橋配置文件時,我收到錯誤:
OpenSSL Error: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed
有什么建議? 在我的本地代理(樹莓派)上使用帶有用戶名/密碼的身份驗證方法和在 AWS 上使用證書身份驗證有什么問題嗎??
謝謝
好吧,我不知道我做了什么,我只知道它解決了問題。
起初,我在我擁有的 Ubuntu VM 上全新安裝了 mosquitto,一切正常。
然后我從我的樹莓派上卸載了 Mosquitto 並重新安裝了它。 按照我配置 Ubuntu VM 的方式配置它,但仍然沒有運氣。 我開始認為問題出在我的 raspbian 映像上……但是在對配置稍加擺弄之后,將證書文件從一個目錄移動到另一個目錄,更改它們的權限,更改 bridge.conf 文件目錄等等……它開始工作,現在好了。
因此,如果您將來遇到此問題:可能只是文件或目錄的權限。
編輯(一天后) :當我試圖在另一個代理上復制相同的東西時,我做了同樣的事情,但是一旦我的本地代理與 AWS IoT 橋建立了連接,連接就丟失了(下面的消息。沒有證書錯誤時間):
1584456917: Bridge local.bridgeawsiot doing local SUBSCRIBE on topic #
1584456917: Connecting bridge (step 1) awsiot (XXXXXXXXXXXXXXX.amazonaws.com:8883)
1584456918: Connecting bridge (step 2) awsiot (XXXXXXXXXXXXXXX.amazonaws.com:8883)
1584456918: Bridge bridgeawsiot sending CONNECT
1584456918: Received CONNACK on connection local.bridgeawsiot.
1584456918: Bridge local.bridgeawsiot sending SUBSCRIBE (Mid: 2, Topic: #, QoS: 0, Options: 0x00)
1584456918: Sending PUBLISH to local.bridgeawsiot (d0, q0, r1, m0, 'XXXXX/XXXXX/XXXXX', ... (6 bytes))
1584456918: Sending PUBLISH to local.bridgeawsiot (d0, q0, r1, m0, 'XXXXX/XXXXX/XXXXX/LWT', ... (6 bytes))
1584456918: Sending PUBLISH to local.bridgeawsiot (d0, q0, r1, m0, 'XXXXX/XXXXX/XXXXX/LWT', ... (6 bytes))
1584456918: Sending PUBLISH to local.bridgeawsiot (d0, q0, r1, m0, 'XXXXX/XXXXX/XXXXX/LWT', ... (6 bytes))
1584456918: Sending PUBLISH to local.bridgeawsiot (d0, q0, r1, m0, 'XXXXX/XXXXX/XXXXX/LWT', ... (6 bytes))
1584456918: Sending PUBLISH to local.bridgeawsiot (d0, q0, r1, m0, 'XXXXX/XXXXX/XXXXX/LWT', ... (6 bytes))
1584456918: Received SUBACK from local.bridgeawsiot
1584456919: Socket error on client local.bridgeawsiot, disconnecting.
我正在使用所有主題的橋梁:
topic # both 1
我馬上想隨着我與橋相連的許多設備發布了很多信息和連接斷開。 所以在我改變了橋接主題之后,一切都是正確的
topic iot/test both 1
[另一個編輯:3 天后]我找到了為什么當我使用“topic # both 1”時它斷開連接:因為我的一個設備正在發送一條消息,其中 RETAIN 標志設置為 TRUE。
AWS IoT 的文檔說它不支持 RETAIN TRUE 並且如果以這種方式發送任何消息 AWS IoT Broker 斷開連接。
rootCA.pem 無效。 按照how-to-bridge-mosquitto-mqtt-broker-to-aws-iot ,他們引用AmazonRootCA1.pem作為 rootCA.pem 文件。 但是,使用 openssl 進行驗證時會出現錯誤:
openssl s_client -connect <endpoint>.iot.us-east-1.amazonaws.com:8443 -CAfile rootCA.pem -cert cert.crt -key private.key
...
verify error:num=20:unable to get local issuer certificate
在OpenSSL Verify return code: 20 (unable to get local issuer certificate) 中,有一些關於 openssl 錯誤的線索,其中強調了 CAfile 路徑。
在另一個配置網橋的教程中: Arduino-AWS-IOT-Bridge ,rootCA.pem 文件有不同的參考: Public-Primary-Certification-Authority-G5.pem 。 最后,使用新的 rootCA.pem 嘗試openssl s_client
命令返回:
verify return:1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.