我正在尝试使用TLS通过mqtt进行通信。我在我的系统中安装了ubuntu。为了使用TLS,我使用以下链接创建了证书:
我可以创建证书。但是当我给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.).
如果将主机名传递给bind_address
参数,它必须解析为有效的IP地址,这不一定与hostname
的输出相同。
这与TLS /证书设置无关,纯粹是mosquitto如何识别要绑定的地址。
你有几个选择如何解决这个问题:
bind_address
线,这将导致mosquitto收听所有可用的地址bind_address
字段中使用的内容解析为绑定到代理运行的计算机上的接口的IP地址。这可能意味着使用完全限定的域名(您可能应该在经纪人的证书CN中使用它)