您尚未登录。

楼主 # 2024-04-05 14:14:57

memory
会员
注册时间: 2021-08-11
已发帖子: 240
积分: 214

用阿里云免费的SSL证书搭建 WebSocket MQTT 平台

QQ截图20240407132334.png

三个月有效期的 DigiCert 免费SSL证书。


参考:

https://blog.csdn.net/mgledu/article/details/118573075

https://blog.csdn.net/qq_43547555/article/details/106628783

下载 Nginx PEM/KEY 证书和 根证书


修改:
/etc/mosquitto/mosquitto.conf

增加:

listener 1883 0.0.0.0
listener 8883 0.0.0.0
listener 8884 0.0.0.0

protocol websockets

cafile /etc/mosquitto/ssl/Digicert-OV-DV-root.cer
keyfile /etc/mosquitto/ssl/mqtt1.test.com.key
certfile /etc/mosquitto/ssl/mqtt1.test.com.pem

离线

楼主 #1 2024-04-05 17:59:22

memory
会员
注册时间: 2021-08-11
已发帖子: 240
积分: 214

Re: 用阿里云免费的SSL证书搭建 WebSocket MQTT 平台

_20240405175535.jpg

QQ截图20240405175825.png

离线

楼主 #2 2024-04-05 18:01:19

memory
会员
注册时间: 2021-08-11
已发帖子: 240
积分: 214

Re: 用阿里云免费的SSL证书搭建 WebSocket MQTT 平台

QQ截图20240405180101.png

离线

楼主 #3 2024-04-05 18:15:07

memory
会员
注册时间: 2021-08-11
已发帖子: 240
积分: 214

Re: 用阿里云免费的SSL证书搭建 WebSocket MQTT 平台

QQ截图20240405181443.png

离线

楼主 #4 2024-04-05 18:25:05

memory
会员
注册时间: 2021-08-11
已发帖子: 240
积分: 214

Re: 用阿里云免费的SSL证书搭建 WebSocket MQTT 平台

/etc/mosquitto/mosquitto.conf 这个配置

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

listener 1883 0.0.0.0

listener 8883 0.0.0.0
cafile /etc/mosquitto/ssl/Digicert-OV-DV-root.cer
certfile /etc/mosquitto/ssl/mqtt1.xxx.com.pem
keyfile /etc/mosquitto/ssl/mqtt1.xxx.com.key
protocol mqtt



listener 8884 0.0.0.0
cafile /etc/mosquitto/ssl/Digicert-OV-DV-root.cer
keyfile /etc/mosquitto/ssl/mqtt1.xxx.com.key
certfile /etc/mosquitto/ssl/mqtt1.xxx.com.pem
protocol websockets



log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

这个配置 MQTT, MQTTS, WSS 用MQTTX软件测试均正常了,但是MQTTS用mosquitto_sub测试未成功。

离线

楼主 #5 2024-04-05 19:44:19

memory
会员
注册时间: 2021-08-11
已发帖子: 240
积分: 214

Re: 用阿里云免费的SSL证书搭建 WebSocket MQTT 平台

openssl verify  Digicert-OV-DV-root.cer
Digicert-OV-DV-root.cer: OK

离线

楼主 #8 2024-04-07 11:52:37

memory
会员
注册时间: 2021-08-11
已发帖子: 240
积分: 214

Re: 用阿里云免费的SSL证书搭建 WebSocket MQTT 平台

创建用户名test的密码文件:

mosquitto_passwd -c /etc/mosquitto/passwd test

强制密码登录:

/etc/mosquitto/mosquitto.conf
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /var/run/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

allow_anonymous false
password_file  /etc/mosquitto/passwd
listener 1883 0.0.0.0

listener 8883 0.0.0.0
cafile /etc/mosquitto/ssl/Digicert-OV-DV-root.cer
certfile /etc/mosquitto/ssl/mqtt1.test.com.pem
keyfile /etc/mosquitto/ssl/mqtt1.test.com.key
protocol mqtt



listener 8884 0.0.0.0
cafile /etc/mosquitto/ssl/Digicert-OV-DV-root.cer
keyfile /etc/mosquitto/ssl/mqtt1.test.com.key
certfile /etc/mosquitto/ssl/mqtt1.test.com.pem
protocol websockets



log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

这个配置 MQTT, MQTTS, WSS 用MQTTX软件测试均正常,强制账号密码登录,但是MQTTS用mosquitto_sub测试未成功。

离线

楼主 #9 2024-04-07 11:52:49

memory
会员
注册时间: 2021-08-11
已发帖子: 240
积分: 214

Re: 用阿里云免费的SSL证书搭建 WebSocket MQTT 平台

QQ截图20240407115024.png

搞定了,得用Ubuntu22.04

离线

楼主 #10 2024-04-07 11:55:49

memory
会员
注册时间: 2021-08-11
已发帖子: 240
积分: 214

Re: 用阿里云免费的SSL证书搭建 WebSocket MQTT 平台

应该是前面用Ubuntu18.04 的openssl 版本问题,怪不得在google play下载一堆MQTT app都能正常连接到8883端口MQTTS。

离线

楼主 #11 2024-04-07 13:11:07

memory
会员
注册时间: 2021-08-11
已发帖子: 240
积分: 214

Re: 用阿里云免费的SSL证书搭建 WebSocket MQTT 平台

memory 说:

应该是前面用Ubuntu18.04 的openssl 版本问题,怪不得在google play下载一堆MQTT app都能正常连接到8883端口MQTTS。

到此为止,MQTT,MQTTS,WSS 三种协议完全打通,并且可以互通。

离线

楼主 #12 2024-04-07 17:46:09

memory
会员
注册时间: 2021-08-11
已发帖子: 240
积分: 214

Re: 用阿里云免费的SSL证书搭建 WebSocket MQTT 平台

buildroot 2024.02 版本编译出来的,发现嵌入式系统跑不了,也是出错:

# mosquitto_sub -h mqtt2.test.com -t "/control/#" -p 8883 -u test-P test-os.com -d
Client null sending CONNECT
OpenSSL Error[0]: error:0A000086:SSL routines::certificate verify failed
Error: Protocol error

然后一顿骚操作,升级了openssl版本,仍然没有解决,继续跟踪openssl源码,发现需要去找 /etc/ssl 目录

然后把ubuntu 的 /etc/ssl 目录备份解压到 buildroot,OK!

tar cvf /mnt/hgfs/D/s.tar /etc/ssl/ /usr/share/ca-certificates/

离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn