Azure 物联网中心证书

Azure IoT Hub Certificate

我正在尝试使用 Mqtt 在 Azure IoT 中心发布一些数据。 我已经使用 SAS 令牌成功发布了一些数据。

但我的客户想要一个 x509 自生成和自签名证书。 Azure 对此提供支持,但并未提供太多相关信息。 (https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-security#supported-x509-certificates)

A self-generated and self-signed X-509 certificate. A device manufacturer or in-house deployer can generate these certificates and store the corresponding private key (and certificate) on the device. You can use tools such as OpenSSL and Windows SelfSignedCertificate utility for this purpose.

Note IoT Hub does not require or store the entire X.509 certificate, only the thumbprint.

我所做的是创建 CA 证书和密钥。

$openssl req -newkey rsa:2048 -x509 -nodes -sha256 -days 365 -extensions v3_ca -keyout ca.key -out ca.crt

创建了客户端密钥和签名请求

$openssl genrsa -out client.key 2048

$openssl req -new -sha256 -out client.csr -key client.key

签署请求并创建证书

$openssl x509 -req -sha256 -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -CAserial ca.srl -out client.crt -days 365

我已将客户端密钥和证书上传到调制解调器。 并插入客户端证书的指纹。

我的调制解调器可以成功连接到 myhub.azure-devices.net/deviceId (port 8883) 但是当新数据到达时它无法对其进行解码。

从这一点开始我有点卡住了。我试过使用 MqttFx,但没有成功。

有人可以把我推向正确的方向吗?

我已经解决了这个问题:

配置的CA证书必须是Azure证书:CA Root Certificate Azure SDK。我使用了巴尔的摩根证书。

客户端证书和密钥正确。客户端证书的 SHA1 指纹必须传送到 Azure IoT 中心。

我使用 Paho 作为 Mqtt 客户端。

最后,我在连接到服务器时遇到调制解调器错误。 modem里面的时间显然还是默认的(1-1-2004),modem用当前时间(1-1-2004)检查证书的时间,无效,所以连接不上。

对于那些想要使用 Azure IoT C# SDK 的用户,我创建了一个基于 C# 的代码示例,向您展示了如何将 OpenSSL 自签名和自生成的 X509 证书与在 Azure 中注册的设备相关联IoT 中心,然后在后续运行时操作中使用证书(主要或次要)——特别是发送遥测消息。

您可以选择使用 MQTT 或 HTTPS 作为传输层。

https://github.com/tamhinsf/SimpleAzureIoTCerts/