我正在尝试使用下游设备的透明网关用例。我正在关注Microsoft提供的文档how-to-create-transparent-gateway。我已经在Ubuntu 18.04虚拟机上安装了Azure IoT Edge Runtime。IoT Edge运行时可通过一个自定义Java模块完美运行。
我已经使用对称密钥在Azure门户上创建了IoT设备。我已将IoT Edge设备作为父级添加到此IoT设备。我正在使用Java示例send-event将消息发送到IoT Edge设备。
我已经从azure门户复制了IoT设备连接字符串,并根据文档“ 检索和修改连接字符串”对其进行了修改。我的IoT设备连接字符串如下所示 HostName=myGatewayDevice;DeviceId=myDownstreamDevice;SharedAccessKey=xxxyyyzzz 上面的连接字符串中myGatewayDevice是hostname托管IoT Edge运行时的ubuntu虚拟机的名称。当我运行此示例时,出现以下异常
HostName=myGatewayDevice;DeviceId=myDownstreamDevice;SharedAccessKey=xxxyyyzzz
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)
当我像这样修改IoT设备连接字符串时 HostName=myiothub.azure-devices.net;DeviceId=myDownstreamDevice;SharedAccessKey=xxxyyyzzz;GatewayHostName=myGatewayDevice 我低于错误
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为我指出正确的方向。我需要azure-iot-test-only.root.ca.cert.pem.crt在我的Java代码中添加路径。对于具有对称密钥证明的设备,他们需要出示root ca证书来验证网关设备。与用于对称设备的Azure IoT中心直接通信不需要此证书。