java - 具有与 IoT Edge 设备的对称密钥连接的 IoT 设备
问题描述
我正在尝试使用下游设备的透明网关用例。我正在关注microsoft 提供的文档how-to-create-transparent-gateway 。我已经在 Ubuntu 18.04 虚拟机上安装了 azure IoT Edge Runtime。物联网边缘运行时与一个自定义 java 模块完美运行。
我在 Azure 门户上使用对称密钥创建了一个 IoT 设备。我已将我的 IoT Edge 设备作为父级添加到此 IoT 设备。我正在使用 java 示例发送事件向 IoT Edge 设备发送消息。
我已经从 azure 门户复制了 IoT 设备连接字符串,并根据文档Retrieve and modify connection string对其进行了修改。我的物联网设备连接字符串看起来像HostName=myGatewayDevice;DeviceId=myDownstreamDevice;SharedAccessKey=xxxyyyzzz
上面的连接字符串myGatewayDevice
是hostname
托管 IoT Edge 运行时的 ubuntu 虚拟机。当我运行这个例子时,我得到了以下异常
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 为我指明了正确的方向。我需要azure-iot-test-only.root.ca.cert.pem.crt
在我的 java 代码中添加路径。对于具有对称密钥证明的设备,他们需要提供根 ca 证书来验证网关设备。与对称设备的 Azure IoT 中心直接通信不需要此证书。
解决方案
IoT Edge(默认情况下)使用自签名证书进行传入连接。您需要让下游设备信任该证书。有关如何进行此操作的详细信息,请参见此处:
https://docs.microsoft.com/en-us/azure/iot-edge/how-to-connect-downstream-device
推荐阅读
- javascript - 无法在上下文中更新状态
- javascript - npm 安装错误:完整性检查失败
- sql - 通过一次调用 SaveChanges() 进行多个 Dbset/实体修改
- google-cast - Chromecast 自定义接收器不同步音频/视频 HLS 格式
- concurrency - 如何进行比较和添加 AtomicInteger
- angularjs - 包含 $state.includes() 的单元测试控制器
- javascript - 打字稿:如何将类型定义为枚举的任何部分?
- javascript - 为什么我的程序没有进入我的 switch case "deleteRegistro" 发送和获取 PHP 中的 $_POST?
- flutter - 如何摆脱卡周围的闪烁框?
- json - 难以理解包含 [?] 的 JSONPath