【发布时间】:2020-02-12 05:59:46
【问题描述】:
我正在尝试使用下游设备的透明网关用例。我正在关注微软提供的文档how-to-create-transparent-gateway。我已经在 Ubuntu 18.04 虚拟机上安装了 azure IoT Edge Runtime。物联网边缘运行时与一个自定义 java 模块完美运行。
我在 Azure 门户上使用对称密钥创建了一个 IoT 设备。我已将我的 IoT Edge 设备作为父级添加到此 IoT 设备。我正在使用 java 示例 send-event 向 IoT Edge 设备发送消息。
我已从 azure 门户复制 IoT 设备连接字符串,并根据文档 Retrieve and modify connection string 对其进行了修改。我的 IoT 设备连接字符串看起来像 HostName=myGatewayDevice;DeviceId=myDownstreamDevice;SharedAccessKey=xxxyyyzzz
在上面的连接字符串中,myGatewayDevice 是托管 IoT Edge 运行时的 ubuntu 虚拟机的 hostname。当我运行这个例子时,我得到了以下异常
Starting...
Beginning setup.
Successfully read input parameters.
Using communication protocol MQTT.
Exception in thread "main" java.lang.IllegalArgumentException: Provided hostname did not include a valid IoT Hub name as its prefix. An IoT Hub hostname has the following format: [iotHubName].[valid URI chars]
at com.microsoft.azure.sdk.iot.device.IotHubConnectionString.parseHubName(IotHubConnectionString.java:321)
at com.microsoft.azure.sdk.iot.device.IotHubConnectionString.validateTerms(IotHubConnectionString.java:287)
at com.microsoft.azure.sdk.iot.device.IotHubConnectionString.<init>(IotHubConnectionString.java:121)
at com.microsoft.azure.sdk.iot.device.DeviceClient.<init>(DeviceClient.java:176)
at samples.com.microsoft.azure.sdk.iot.SendEvent.main(SendEvent.java:171)
当我像这样修改物联网设备连接字符串时
HostName=myiothub.azure-devices.net;DeviceId=myDownstreamDevice;SharedAccessKey=xxxyyyzzz;GatewayHostName=myGatewayDevice我得到以下错误
Exception encountered while sending MQTT CONNECT packet
MqttException (0) - javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:736)
at java.lang.Thread.run(Thread.java:748)
请帮我解决这个问题。我想让 IoT Edge 设备进行通信。任何帮助将不胜感激。
编辑 1
这是sudo openssl s_client -connect RajUbuntuVM:8883 -CAfile Production/EdgeCerts/RootCACertificate/azure-iot-test-only.root.ca.cert.pem -showcerts的输出
0040 - 95 c4 40 5b f9 a8 0d 3c-62 83 50 05 ea 1f b9 0a ..@[...<b.P.....
0050 - 25 e6 99 8a 27 47 4d 55-25 3d 30 aa 00 94 ea 6a %...'GMU%=0....j
0060 - 89 ad 18 60 8f 6b f6 4d-66 6d 05 29 87 6e b0 38 ...`.k.Mfm.).n.8
0070 - a7 01 38 6f 6e 11 c1 db-62 20 43 de 0d 8d ba 29 ..8on...b C....)
0080 - ca 91 78 ff a7 5a 49 1a-d6 ed ae 1d ac 65 73 b8 ..x..ZI......es.
0090 - e1 08 9e 41 63 59 37 ad-88 f9 bd 29 06 8e ca 14 ...AcY7....)....
Start Time: 1581571257
Timeout : 7200 (sec)
Verify return code: 0 (ok)
Extended master secret: yes
---
我的两个设备 IoT Device 和 IoT Edge Device 都在同一个 Ubuntu 虚拟机上运行。我已经在 Ubuntu 设备中安装了 root ca,如下所示
sudo cp <path>/azure-iot-test-only.root.ca.cert.pem /usr/local/share/ca-certificates/azure-iot-test-only.root.ca.cert.pem.crt
sudo update-ca-certificates
分辨率:
感谢 Silent 为我指明了正确的方向。我需要在我的 java 代码中添加 azure-iot-test-only.root.ca.cert.pem.crt 路径。对于具有对称密钥证明的设备,他们需要提供根 ca 证书来验证网关设备。与对称设备的 Azure IoT 中心直接通信不需要此证书。
【问题讨论】:
标签: java azure azure-iot-edge