【问题标题】:Facing Error while using TLS with mosquitto将 TLS 与 mosquitto 一起使用时遇到错误
【发布时间】:2019-02-25 09:50:05
【问题描述】:

我正在尝试使用 TLS 通过 mqtt 进行通信。我的系统中安装了 ubuntu。对于使用 TLS,我使用以下链接创建了证书:

http://www.embedded101.com/Blogs/PaoloPatierno/entryid/366/mqtt-over-ssl-tls-with-the-m2mqtt-library-and-the-mosquitto-broker

我能够创建证书。但是,当我在 mosquitto_m2mqtt.conf 文件中为 bind_address 属性赋值并使用命令 mosquitto -c mosquitto_m2mqtt.conf 启动 mosquitto 时,我得到了问题主题中给出的错误;即Error: cannot assign requested address。请告诉我如何解决此问题。

下面是配置文件的内容:

port 8883
bind_address iothdp02
cafile /etc/mosquitto/m2mqtt_ca.crt
certfile /etc/mosquitto/m2mqtt_srv.crt
keyfile /etc/mosquitto/m2mqtt_srv.key
tls_version tlsv1

当我运行命令mosquitto -c mosquitto_m2mqtt.conf -v 时,我得到的错误如下:

1551089294: mosquitto version 1.4.8 (build date 2016-09-21 11:21:45+0530) starting
1551089294: Config loaded from mosquitto_m2mqtt.conf.
1551089294: Opening ipv4 listen socket on port 8883.
1551089294: Error: Cannot assign requested address

编辑 1:

我已从配置文件中删除 bind_address,并使用带有“mosquitto -c mosquitto_m2mqtt.conf -v”的新配置文件启动 mosquitto。 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.).

【问题讨论】:

  • iothdp02 解析为什么?如果你运行nslookup iothdp02 会发生什么?这很可能不是解析为地址
  • nslookup iothdp02 的输出:Server: 127.0.1.1 Address: 127.0.1.1#53 ** server can't find iothdp02: NXDOMAIN
  • 我运行了命令hostname 并得到了iothdp02 的输出,因此在生成证书时给出了与Common Name 相同的名称,并且在配置文件中也给出了bind_address。
  • 编辑现在是一个完全不同的问题。问一个新问题。
  • 我在以下位置提出了一个新问题:stackoverflow.com/questions/54899215/…

标签: ssl mqtt tls1.2 mosquitto


【解决方案1】:

如果您将主机名传递给 bind_address 参数,它必须解析为有效的 IP 地址,这不一定与 hostname 的输出相同。

这与 TLS/证书设置无关,它纯粹是 mosquitto 识别要绑定到哪个地址的方式。

关于如何解决这个问题,您有几种选择:

  1. 删除bind_address 行,这将导致mosquitto 监听所有可用地址
  2. 确保您在bind_address 字段中使用的任何内容都解析为绑定到代理正在运行的机器上的接口的IP 地址。这可能意味着使用完全限定域名(您可能也应该在代理的证书 CN 中使用它)
  3. 将主机名替换为您希望 mosquitto 监听的接口的 IP 地址。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-24
    • 1970-01-01
    • 2010-09-29
    • 2013-03-20
    • 2021-07-15
    • 2013-06-19
    • 2014-01-29
    • 1970-01-01
    相关资源
    最近更新 更多