尝试使用自己的 x509 证书运行 azure-iot-sdk-java provisioning-x509-sample

Posted

技术标签:

【中文标题】尝试使用自己的 x509 证书运行 azure-iot-sdk-java provisioning-x509-sample【英文标题】:Try to run the azure-iot-sdk-java provisioning-x509-sample with an own x509-certificate 【发布时间】:2018-10-31 09:23:51 【问题描述】:

我正在尝试运行 azure-iot-sdk-java provisioning-X509-sample。

我所做的是,我用 openssl 创建了一个证书链并生成了一个 X509 证书。我将此证书上传到 azure DPS。 我检查了上传证书的指纹,一切正常。

在下一步中,我将配置 ProvisioningX509Sample.java。输入 idScope、globalEndpoint 和作为 leafPublicPem 我输入 Base64 字符串

"-----BEGIN CERTIFICATE-----" + "\n" +
************ + "\n" +
"-----END CERTIFICATE-----"

作为leafPrivateKey,我输入了我的中间CA的私钥,它创建/签署了我的X509-Device-certifivate

"-----BEGIN RSA PRIVATE KEY-----" + "\n" +
************+ "\n" +
"-----END RSA PRIVATE KEY-----";

作为传输协议,我将使用 MQTT

如果我运行此示例,我会收到以下错误

Starting...
Beginning setup.
Waiting for Provisioning Service to register
com.microsoft.azure.sdk.iot.provisioning.device.internal.exceptions.ProvisioningDeviceConnectionException: Exception opening connection amqp
        at com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.mqtt.ContractAPIMqtt.open(ContractAPIMqtt.java:142)
        at com.microsoft.azure.sdk.iot.provisioning.device.internal.task.ProvisioningTask.call(ProvisioningTask.java:267)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.io.IOException: Unable to connect to mqtt service
        at com.microsoft.azure.sdk.iot.deps.transport.mqtt.MqttConnection.connect(MqttConnection.java:151)
        at com.microsoft.azure.sdk.iot.provisioning.device.internal.contract.mqtt.ContractAPIMqtt.open(ContractAPIMqtt.java:135)
        ... 5 more
Caused by: MqttException (0) - javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
        at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:715)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        ... 3 more
Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1002)
        at sun.security.ssl.SSLSocketImpl.waitForClose(SSLSocketImpl.java:1779)
        at sun.security.ssl.HandshakeOutStream.flush(HandshakeOutStream.java:124)
        at sun.security.ssl.Handshaker.sendChangeCipherSpec(Handshaker.java:1156)
        at sun.security.ssl.ClientHandshaker.sendChangeCipherAndFinish(ClientHandshaker.java:1267)
        at sun.security.ssl.ClientHandshaker.serverHelloDone(ClientHandshaker.java:1179)
        at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:348)
        at sun.security.ssl.Handshaker.processLoop(Handshaker.java:1052)
        at sun.security.ssl.Handshaker.process_record(Handshaker.java:987)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1072)
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1385)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1413)
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1397)
        at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:108)
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:701)
        ... 7 more
Caused by: java.io.EOFException: SSL peer shut down incorrectly
        at sun.security.ssl.InputRecord.read(InputRecord.java:505)
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:983)
        ... 21 more
Registration error, bailing out
Press any key to exit...

我不明白这个错误。是不是少了一个步骤?

感谢您的帮助和问候

JensV

【问题讨论】:

【参考方案1】:

DPS 仅支持 TLS 1.2。旧版本的 TLS 连接将被拒绝。

【讨论】:

以上是关于尝试使用自己的 x509 证书运行 azure-iot-sdk-java provisioning-x509-sample的主要内容,如果未能解决你的问题,请参考以下文章

Helm 从 pod 内部使用“x509:由未知机构签名的证书”获取错误

是否可以仅使用 C# 以编程方式生成 X509 证书?

请教使用OpenSSL读写X509数字证书,有代码

使用 X509 证书进行消息签名

x509:由未知权威 CMD K6.io 签署的证书

Java X509 证书解析和验证