【问题标题】:"certificate verify failed" when bridging AWS IoT with local Mosquitto MQTT将 AWS IoT 与本地 Mosquitto MQTT 桥接时出现“证书验证失败”
【发布时间】:2020-06-27 17:23:40
【问题描述】:

我在本地树莓派上有一个 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 上的证书身份验证是否有任何问题?

谢谢

【问题讨论】:

  • 快速建议,重新排序您的bridge.conflog_type all 移到您的网桥设置之外,因为它是一个全局选项。
  • 尝试从bridge.conf 中删除log_type all,但没有任何改变。第一次尝试时 log_type 不存在,后来我添加了它。谢谢

标签: amazon-web-services mqtt mosquitto bridge broker


【解决方案1】:

好吧,我不知道我做了什么,我只知道它解决了问题。

起初,我在我拥有的 Ubuntu 虚拟机上进行了 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

THINK 连接到网桥后,许多设备发布了很多消息并且连接断开了。 因此,在我更改桥接主题后,一切都是正确的

topic iot/test both 1

[另一个编辑:3 天后] 我发现当我使用“topic # both 1”时它为什么会断开连接:因为我的一个设备正在发送一条将 RETAIN 标志设置为 TRUE 的消息。

AWS IoT 的文档说它不支持 RETAIN TRUE,如果以这种方式发送任何消息,AWS IoT Broker 就会断开连接。

【讨论】:

    【解决方案2】:

    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
    

    【讨论】:

      最近更新 更多