我正在尝试使用TLS通过mqtt进行通信。我的系统中安装了ubuntu。为了使用TLS,我使用以下链接创建了证书:
我能够创建证书。我已经从配置文件中删除了bind_address
。我正在使用mosquitto -c mosquitto_m2mqtt.conf -v
的新配置文件来启动mosquitto。蚊子启动,但是当我运行mosquitto_sub
命令时,出现以下错误:
mosquitto -c mosquitto_m2mqtt.conf -v
1551172930: mosquitto version 1.4.8 (build date 2016-09-21 11:21:45+0530) starting
1551172930: Config loaded from mosquitto_m2mqtt.conf.
1551172930: Opening ipv4 listen socket on port 8883.
1551172930: Opening ipv6 listen socket on port 8883.
Enter PEM pass phrase:
1551172960: New connection from 127.0.0.1 on port 8883.
1551172960: OpenSSL Error: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown
1551172960: OpenSSL Error: error:140940E5:SSL routines:ssl3_read_bytes:ssl handshake failure
1551172960: Socket error on client <unknown>, disconnecting.
在我订阅的窗口中,出现如下错误:
mosquitto_sub -p 8883 -q 1 -t sensor/temp --cafile /etc/mosquitto/m2mqtt_srv.crt --tls-version tlsv1 -d
Unable to connect (A TLS error occurred.).
下面是在配置文件中添加的参数。
port 8883
cafile /etc/mosquitto/m2mqtt_ca.crt
certfile /etc/mosquitto/m2mqtt_srv.crt
keyfile /etc/mosquitto/m2mqtt_srv.key
tls_version tlsv1
答案 0 :(得分:0)
mosquitto_sub和pub需要一个主机地址或ip。例如,我在本地使用test.mosquitto.org,从该站点下载pem格式的证书文件,并将此证书作为“ cafile”添加到conf文件中。这是我的命令:
mosquitto_sub -h test.mosquitto.org -t "test" -p 8883 --cafile "<pem formatted crt file path (downloaded from test.mosquitto.org)>"