amazon-web-services - 将 AWS IoT 与本地 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 天后] 我发现为什么当我使用“主题#都 1”时它会断开连接:因为我的一个设备正在发送一条将 RETAIN 标志设置为 TRUE 的消息。
AWS IoT 的文档说它不支持 RETAIN TRUE,如果以这种方式发送任何消息,AWS IoT Broker 就会断开连接。
推荐阅读
- intellij-idea - Intellij IDEA脚本错误:系统找不到指定的路径
- vba - 使用拆分和替换 - VBA
- wget - 如果已经存在,则让 wget 覆盖文件并每次下载它,无论它在远程服务器上被更改
- python-3.x - 如何通过检查 html 源来下载这个声音图标?
- monetdb - 将 COPY INTO 与包含时间戳列的 CSV 文件一起使用
- python - 程序完成后的事件循环异常
- python - 更改表单中的操作后 Django 中的 KeyError
- python - Azure Python 函数应用执行时间真的很慢
- maven - 如何将依赖项的唯一快照版本解析为 Maven 中的变量?
- ios - Xcode 11.1如何安装iOS14模拟器?