mosquitto - 如何正确地将证书传递给 mosquitto_pub 和 mosquitto_sub 以便进行 TLS 通信?
问题描述
我有这个设置
在远程服务器中。我试过了
mosquitto_sub -h 127.0.0.1 -t 'myTopic' -i 'myId'
在我的电脑我试过
mosquitto_pub -h 'remote_ip_here' -t 'myTopic' -m 'the message'
远程服务器能够获取我从我的计算机发布的消息
远程服务器有这些密钥
certificate file = cert.pem
certificate key file = privkey.pem
certification chain file = chain.pem
如果我想在我的计算机和远程计算机之间进行 ssl/tls 通信。
- How do I use those keys ?
- Am I suppose to copy those keys from the remote computer and put them also in my computer ?
- can someone please help what's the proper command to execute in order to have an ssl and tls communication.
在我试过的远程服务器中
mosquitto_sub -h 127.0.0.1 -t 'myTopic' -i 'myId' --capath /etc/myPemPath -p 1883
在我的电脑里,我试过了
mosquitto_pub -h remote_ip -t 'myTopic' -m 'the message' --capath /etc/localPemPath -p 1883
它没有用,那怎么办?
解决方案
您似乎没有理解 MQTT 的工作原理。两者都是mosquitto_sub
与mosquitto_pub
MQTT 代理 ( mosquitto
) 通信的 MQTT 客户端。它不是直接的客户端/服务器关系。
为了获得 TLS 安全的 MQTT 连接,您首先需要配置代理以使用证书来识别它自己,然后配置客户端以验证该证书作为 TLS 握手的一部分。
有关如何配置 TLS 的 mosquitto 文档可在此处获得。您需要在文件中添加一个cafile
或capath
和certfile
和keyfile
选项mosquitto.conf
。请注意,TLS 设置适用于上次listener
配置的设置,因此您可能需要在与 1883 不同的端口上设置新的侦听器。
至于客户端,假设您没有进行相互身份验证的 TLS,那么您只需将-cafile
/-capath
选项传递给mosquitto_pub
并mosquitto_sub
启用 TLS 会话。
推荐阅读
- email - 阅读通过 SMTP 发送的电子邮件的内容?
- javascript - 屏幕大小模式的 JavaScript Window.Open() 方法仍然以最小化模式打开浏览器窗口
- c++ - 当文件描述符变坏时 QSocketNotifier 会发生什么?
- python - 无法计算分割图像的准确性、敏感性和特异性
- java - JavaFX Alert Button Bar sizing
- sql-server - SSIS 可以按照与 TXT 文件中完全相同的顺序导入 TXT 记录吗?如果不是(默认情况下),那怎么办?
- ios - 我的 Answer SDP 有什么问题(WebRTC,iOS 项目)
- mongodb - 操作子文档
- python - python:是否可以使用字符串数据框映射值?
- java - 通过组合实现多重继承