一段时间以来,我一直在 debian 8 上使用 mosquitto + websockets,效果很好。现在我想将系统移至试生产阶段,因此我需要开始加密这些通信。
我已尝试按照此博文 (http://embeddedprog.blogspot.pt/2014/05/tlsssl-communication-via-mqtt.html) 中的步骤以及 J-P Mens (https://github.com/owntracks/tools) 中的证书生成脚本手动生成证书
我的“mosquitto.conf”看起来像这样:
allow_anonymous false
allow_duplicate_messages false
autosave_interval 1800
persistence true
persistence_file mosquitto.db
persistence_location /tmp/
connection_messages true
log_timestamp true
#log_dest syslog
#log_type error
#log_type warning
#log_type notice
#log_type information
log_type all
log_type debug
listener 8880
protocol mqtt
listener 8881
protocol websockets
bind_address hi-server
cafile /home/hi/cert/ca.crt
certfile /home/hi/cert/hi.com.crt
keyfile /home/hi/cert/hi.com.key
tls_version tlsv1
#require_certificate false
#
# __ __ ____ ___ _
# | \/ |_ _/ ___| / _ \| |
# | |\/| | | | \___ \| | | | |
# | | | | |_| |___) | |_| | |___
# |_| |_|\__, |____/ \__\_\_____|
# |___/
#
#
#auth_plugin /home/jpm/mosquitto-auth-plug/auth-plug.so
auth_plugin /etc/mosquitto/auth-plug.so
[auth_opt stuff...]
这是 mosquitto 的详细输出:
1448802719: mosquitto version 1.4.2 (build date 2015-11-27 23:40:02+0000) starting
1448802719: Config loaded from /etc/mosquitto/mosquitto.conf.
1448802719: |-- *** auth-plug: startup
1448802719: |-- ** Configured order: mysql
1448802719: |-- }}}} MYSQL
1448802719: Opening ipv4 listen socket on port 8880.
1448802719: Opening ipv6 listen socket on port 8880.
1448802719: Opening websockets listen socket on port 8881.
1448802719: New connection from ****** on port 8880.
1448802719: |-- mosquitto_auth_unpwd_check(******)
1448802719: |-- ** checking backend mysql
1448802719: |-- getuser(******) AUTHENTICATED=1 by mysql
1448802719: New client connected from ****** as ****** (c1, k15, u'******').
1448802719: Sending CONNACK to ****** (0, 0)
每当我尝试连接 HiveMQ Websockets 客户端时,它都会超时...
有人可以告诉我如何实现这一目标吗?非常感谢您的帮助!
谢谢, 佩德罗。
更新:通过导入 CA 证书管理连接
从那以后,我已经成功地使用用于 javascript 的 Paho MQTT 客户端连接到 mosquito!我对 mosquitto.conf 做了一些小改动:
listener 8880
protocol mqtt
listener 8881
protocol websockets
cafile /home/hi/cert/ca.crt
certfile /home/hi/cert/hi.com.crt
keyfile /home/hi/cert/hi.com.key
tls_version tlsv1
#require_certificate false
我现在遇到的问题是,只有当我导入了 hi.com.crt 文件并在钥匙串(keychain) (OS X) 上手动设置为“始终信任”时,我才能连接。由于证书是自签名的,不受 iOS 信任,我无法使用我的 iPhone 登录...
默认的 mosquitto TLS 行为不应该不需要来自客户端的证书吗?
最佳答案
从评论看来,hi-server 解析为 127.0.0.1/localhost。这意味着配置中的行
bind_address hi-server
告诉 mosquitto 只监听本地主机上的 websocket 连接,而不是任何公共(public)接口(interface)。
把这行注释掉再试
关于ssl - Websockets + TLS 的 Mosquitto 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33973212/