【问题标题】:mosquitto TLS what certificate to use for remote mosquitto_pubmosquitto TLS 远程 mosquitto_pub 使用什么证书
【发布时间】:2018-03-29 10:32:41
【问题描述】:

我正在尝试使用 TLS1.2 设置 mosquitto MQTT 服务器,并使用 Let 加密证书。

我已经安装了 mosquitto 并设置了让 encrpypt。我的 /etc/mosquitto/conf.d/default.conf 是

listener 1883 localhost

listener 8883
certfile /etc/letsencrypt/live/mqtt.atom.net/cert.pem
cafile /etc/letsencrypt/live/mqtt.atom.net/chain.pem
keyfile /etc/letsencrypt/live/mqtt.atom.net/privkey.pem

在服务器上运行 mosquitto 我可以成功发布和订阅消息

Sub 
mosquitto_sub -h localhost -t test
hello

Pub
mosquitto_pub -h mqtt.atom.net -t test -m "hello" -p 8883 --capath /etc/ssl/certs/

来自 Internet 上的另一个系统(或 ESP32) - 尝试建立 TLS 连接时出现错误

mosquitto_pub -h mqtt.atom.net -t test -m "hello again" -p 8883
Error: The connection was lost.

我需要将什么证书/证书传递给 mosquitto_pub?

【问题讨论】:

    标签: tls1.2 mosquitto


    【解决方案1】:

    要在 mosquitto_pub 中启用 TLS,您需要在命令行中传递 --capath--cafile

    在 linux 系统上,您应该能够传递相同的 --capath /etc/ssl/certs/(假设您使用的发行版将其 CA 证书保存在同一位置)。

    或者您可以将chain.pem 文件从您的代理复制到另一台机器并使用--cafile chain.pem

    对于 ESP32 之类的东西,您需要弄清楚如何在推送到设备的构建中包含 chain.pem。

    【讨论】:

    • 是的,在第二个 Linux 系统上 - 我使用 --capath /etc/ssl/certs/ 让它工作。我认为这证实了我的 mosquitto 服务器已正确构建。但是在第二个 Linux 系统上,如果我复制 chain.pem 并使用 --cafile chain.pem。我收到错误:发生 TLS 错误。在 Wireshark 中,我看到 mosquitto_pub 客户端发送 TLS1.2 警报消息 - 级别致命,描述:未知 CA。复制的 chain.pem 文件是有效的,因为我可以使用 openssl x509 -in chain.pem -noout -text 转储它的内容。
    • 遇到了与--cafile chain.pem 相同的问题。如果您知道造成这种情况的根本原因,请分享。
    • 假设您使用letsencrypt证书,您可能需要fullchain.pem文件的路径
    猜你喜欢
    • 2018-04-05
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 2017-12-16
    • 1970-01-01
    • 2017-12-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多