ssl - 当我在运行 Mosquitto 的服务器上使用 SSL 时收到错误消息?

标签 ssl openssl mqtt mosquitto paho

我已经在端口 8883 和端口 1883 上为 ubuntu 实现了 mosquitto 代理,但无法弄清楚为什么我不断收到如下所示的与 CA 相关的错误。

当我在服务器本地使用 mosquitto_pub 测试它时,以及当我在我的 MacBook 上使用 Paho/Python 脚本作为客户端时,就会发生这种情况。我的 mosquitto.config 文件、mosquitto_pub 命令和我的 mosquitto 日志消息如下所示。我还包含了我的 openssl 证书创建命令,以防我做错了什么。

这是我的 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/

#log_dest file /var/log/mosquitto/mosquitto.log
log_dest stdout

include_dir /etc/mosquitto/conf.d

log_type all

#-----------------------------------------------
#Default Listener
#-----------------------------------------------

port 8883

#------------------------------------------------
#Certificate Based SSL/TLS Support
#------------------------------------------------

cafile /../etc/mosquitto/ca_certificates/ca.crt
keyfile /../etc/mosquitto/certs/server.key
certfile /../etc/mosquitto/certs/server.crt

listener 1883

这是我用来测试它的 mosquitto_pub 命令。

sudo mosquitto_pub -h 305.875.987.34 -t test -m "Typing this" -p 8883 --cafile /../etc/mosquitto/ca_certificates/ca.crt

这就是我运行时 mosquitto 日志所说的内容。

1546507891: mosquitto version 1.5.5 starting
1546507891: Config loaded from /../etc/mosquitto/mosquitto.conf.
1546507891: Opening ipv4 listen socket on port 1883.
1546507891: Opening ipv6 listen socket on port 1883.
1546507891: Opening ipv4 listen socket on port 8883.
1546507891: Opening ipv6 listen socket on port 8883.
1546507929: New connection from 305.875.987.34 on port 8883.
1546507929: OpenSSL Error: error:14094418:SSL routines:ssl3_read_bytes:tlsv1 alert unknown ca
1546507929: Socket error on client <unknown>, disconnecting.

这些是我用来创建 ca.crt、server.crt 和 server.key 的 openssl 命令。我在名为 certs 的文件夹中创建了它们。

openssl genrsa -des3 -out ca.key 2048
openssl req -new -x509 -days 1826 -key ca.key -out ca.crt
openssl genrsa -out server.key 2048
openssl req -new -out server.csr -key server.key
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 360

在删除我试图解决问题的旧 ca.crt 之后,我将 ca.crt 移至/../etc/mosquitto/ca_certifications。我使用以下两个命令完成了此操作。

sudo rm /../etc/mosquitto/ca_certifications/ca.crt
sudo mv ca.crt /../etc/mosquitto/ca_certifications

我对 server.crt 和 server.key 做了同样的事情,除了我把它们放在/../etc/mosquitto/certs 中。

经纪人似乎在端口 1883 上工作正常。

如果您需要更多信息,请告诉我。

最佳答案

首先,我会重新安排您的 mosquitto.conf 以使链接更清楚,并删除您的证书/ key 文件的相对路径,如下所示:

# 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/

#log_dest file /var/log/mosquitto/mosquitto.log
log_dest stdout

include_dir /etc/mosquitto/conf.d

log_type all

#-----------------------------------------------
#Default Listener
#-----------------------------------------------

port 1883

#------------------------------------------------
#Certificate Based SSL/TLS Support
#------------------------------------------------
listener 8883
cafile /etc/mosquitto/ca_certificates/ca.crt
keyfile /etc/mosquitto/certs/server.key
certfile /etc/mosquitto/certs/server.crt

我交换了端口/监听器条目,以明确 SSL 设置绑定(bind)到端口 8883 监听器。我还从路径的开头删除了/../,因为这是没有意义的,因为不可能从/“root”“向上”一个目录。

同样,您应该为 mosquitto_pub 命令使用直接路径。

此外,当您以 root 身份(使用 sudo)复制文件时,请确保 mosquitto 用户可以读取证书/ key 文件。

关于ssl - 当我在运行 Mosquitto 的服务器上使用 SSL 时收到错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54020103/

相关文章:

ruby-on-rails - OpenSSL 导致 Windows 上的 Rails 启动时间非常慢

openssl - 使用 .start_tls_s() 时如何强制 Python LDAP 验证/验证 SSL 证书

java - 连接到 MQTT 代理

python - 使用 python paho.mqtt 从 docker 容器通过 ssh 发送数据

python-3.x - 在 VSCode 虚拟环境中安装 numpy 时,pip 配置了需要 TLS/SSL 的位置

php "All authentication must be done over SSL"使用 SOAP

java - 无法将 chrome 连接到 HttpsServer

c++ - 为什么我的 OpenSSL/libcrypto 签名不正确?

ssl - 物联网无法连接到使用 MQTT+TLS 的服务器

iOS FlickrKit : err code ="95" msg ="SSL is required"