首页 > 解决方案 > Paho javascript 客户端 + mosquitto Websockets + Tls

问题描述

一段时间以来,我一直在尝试为 mosquitto 代理添加安全层,我需要一些帮助。

我用这个配置配置了我的代理:

...
#logs


#authentication

password_file /etc/mosquitto/passwd
allow_anonymous false

#user
user mosquitto

#broker settings
require_certificate false
listener 8081
protocol websockets
http_dir /var/www/html
keyfile /etc/mosquitto/certs/mqtt-server.key
certfile /etc/mosquitto/certs/mqtt-server.crt
cafile /etc/mosquitto/ca_certificates/mosquitto-certificate-authority.crt

这是日志输出的内容:

1631281308: mosquitto version 2.0.12 starting
1631281308: Config loaded from /etc/mosquitto/mosquitto.conf.
1631281308: Opening websockets listen socket on port 8081.
1631281308: mosquitto version 2.0.12 running

我根据此站点生成了我的证书:https ://www.raspberrypi.org/forums/viewtopic.php?t=287326 。我相信证书没有问题,因为在使用 mosquitto-clients 进行测试时一切正常(在 .conf 文件上评论协议 websockets)。

我从这个站点https://jpmens.net/2014/07/03/the-mosquitto-mqtt-broker-gets-websockets-support/在我的 nginx 服务上上传了一个测试代码,以测试与安全 websockets 的连接,但所有这些给我的是“连接失败:AMQJS0007E 套接字错误:undefined.Retrying”。

你们能帮帮我吗?

标签: sslwebsocketmosquitto

解决方案


如果您生成了自己的证书,则需要将 CA 证书导入浏览器,以便它知道信任它来签署代理证书。

与网页不同,当连接由 JavaScript 触发时,浏览器不会提示您信任证书,您需要在尝试连接之前手动执行此操作。


推荐阅读