最近,Microsoft Azure已在其服务中添加了MQTT后端。 此服务使用TLS对其流量进行加密。 我无法连接Mosquitto和Microsoft Azure Cloud。
我用
下载了服务器证书echo -n | openssl s_client -connect mytarget.azure-devices.net:8883 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/test.cert
然后尝试连接mosquitto_sub
mosquitto_sub -h mytarget.azure-devices.net -p 8883 -d -t devices/Device1/messages/events -i Device1 -u "mytarget.azure-devices.net/Device1" -P "SharedAccessSignature sr=snip&sig=snip&skn=snip" --cafile /tmp/test.pem --insecure
但是,永远不会建立连接。 Mosquitto输出:
客户端Device1发送CONNECT 错误:发生TLS错误。
我之前已成功将ssl上的mosquitto连接到亚马逊云端(虽然我获得了证书和私钥)。 所以我尝试添加客户端证书/密钥,我从AWS获得,希望错误是mosquitto也需要这些文件。
mosquitto_sub -h mytarget.azure-devices.net -p 8883 -d -t devices/Device1/messages/events -i Device1 -u "mytarget.azure-devices.net/Device1" -P "SharedAccessSignature sr=snip&sig=snip&skn=snip" --cafile /tmp/test.pem --cert certificate.pem.crt --key -private.pem.key --insecure --insecure
但是,这没有帮助,也没有更改错误消息。
然后我查看了github上的mosquitto代码,发现错误可能是由SSL_connect引起的on this line,这似乎是一个openssl函数。
有没有人让mosquitto连接到Microsoft Azure云,或者有任何指针可以在哪里查看?
修改:
我似乎能够通过在socat上隧道传输SSL来发布:
socat openssl-connect:mytarget.azure-dices.net:8883,verify=0 tcp-l:8884,reuseaddr,fork
然后连接mosquitto到-h localhost而不是azure让我:
Client Device1 sending CONNECT
Client Device1 received CONNACK
Client Device1 sending PUBLISH (d0, q0, r0, m1, 'devices/Device1/messages/events', ... (4 bytes))
Client Device1 sending DISCONNECT
可能是来自Azure Host的东西正在抛出蚊子。 像蚊子这样的订阅也有效。
这种方法的问题是ssl-connection似乎在第一个(少数)数据包之后被破坏,而socat随后抱怨
E SSL_write(): Broken pipe
答案 0 :(得分:6)
对于其他寻找此事的人。 我们终于设法使用了mosquitto_sub / pub:
@Html.Sitecore().BeginField("Link Field", new { @data_toggle="dropdown" })
和发布:
mosquitto_sub -h mytarget.azure-devices.net -p 8883 -t "devices/Device1/messages/devicebound/#" -i Device1 -u "mytarget.azure-devices.net/Device1" -P "SharedAccessSignature sr=mytarget.azure-devices.net&sig=snip&skn=snip" --capath /etc/ssl/certs/ --tls-version tlsv1 -d -V mqttv311 -q 1
重要您必须发送JSON数据,其他所有内容都会被拒绝(至少在我们的设置中)!
注意请注意,您(貌似)无法直接从一台设备发送到另一台设备。因为这与 Cloud 方式相反。 您必须在云中配置连接