【问题标题】:Getting error message when I use SSL on my server running Mosquitto?当我在运行 Mosquitto 的服务器上使用 SSL 时收到错误消息?
【发布时间】:2019-05-29 21:55:33
【问题描述】:

我已经在端口 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 端口上运行良好。

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

【问题讨论】:

  • 自创证书 -> 没有已知的 CA。这个错误对我来说似乎是合乎逻辑的。不知道是否可以将蚊子配置为忽略 CA 验证或承认自签名证书。

标签: ssl openssl mqtt mosquitto paho


【解决方案1】:

首先,我会重新排列您的 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 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 设置绑定到端口 8883 侦听器。我还从路径的开头删除了 /../,因为这是没有意义的,因为不可能从 /“root”“向上”一个目录。

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

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

【讨论】:

    猜你喜欢
    • 2020-01-05
    • 2021-02-22
    • 2021-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-29
    相关资源
    最近更新 更多