API registration of certification for Azure IoT Hub / DPS

I am trying to connect a custom device to the Azure IoT Hub using DPS service. Because I am using a custom board I am trying to write certificates to the modem using api calls to the modem_key_mgmg functions. Theses functions have a tag and a credential type.

But trying to get around the different certificates in use.and what tags and credential types i should use when writing the certificates.

I have registered Baltimore and DigiCert root CA certificates using the tag CONFIG_MQTT_HELPER_SEC_TAG and CONFIG_MQTT_HELPER_SECONDARY_SEC_TAG and both of them with credential type set to MODEM_KEY_MGMT_CRED_TYPE_PUBLIC_CERT.

For the device certificate I am not really sure what the tag should be, so just set it to 12 for both types.

Then the private certificate is registered with type MODEM_KEY_MGMT_CRED_TYPE_PRIVATE_CERT.

But what about the public part? Should it be MODEM_KEY_MGMT_CRED_TYPE_PUBLIC_CERT?

Is the above at all correct? I am wondering about the tag field since I find no description except a reserrved tag for nRFCloud. Is it used somewhere in the Nordic libraries for Azure and has to have a specific value?

I am getting mqtt_helper, mqtt_connect, error: -111 when trying to connect.

  • I was wondering if the two root CA's should be saved as MODEM_KEY_MGMT_CRED_TYPE_CA_CHAIN instead, but it does not seem to make a difference.

  • Hi Thomas,

    Thanks for checking with us. The error is also reported in the following case. Have you read through it before to find some hint?

    (+) Sample Azure IoT Hub (Thingy9.1) - Nordic Q&A - Nordic DevZone - Nordic DevZone (nordicsemi.com)

    Best regards,

    Charlie

  • Thanks a lot I did not find the other case when searching, so I will look on that and check the details.

  • It seems to be exactly what I have done.

    I have created my own Root CA and uploaded it to the DPS and trusted it during updload.

    Following the recommended guide (https://learn.microsoft.com/en-us/azure/iot-hub/tutorial-x509-test-certs?tabs=linux), I have also created a subordinate CA and based on this created certificate files for the device.

    In the device I am registering certificates with: modem_key_mgmt 

    Since it is not working I am worried that the parameters for the modem_key_mgmt is wrong:

    Removin some code checks and certificates I have the following:

    const char* const digicert =
    "-----BEGIN CERTIFICATE-----\n"
    "MIIDjjCCAnagAwIBAgIQAzrx5qcRqaC7KGSxHQn65TANBgkqhkiG9w0BAQsFADBh\n"
    "MQswCQYDV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KNhJ7jitralj41E6Vf8PlwUHBHQRFXGU7Aj64GxJUTFy8bJZ91\n"
    "8rGOmaFvE7FBcf6IKshPECBV1/MUReXgRPTqh5Uykw7+U0b6LJ3/iyK5S9kJRaTe\n"
    "pLiaWN0bfVKfjllDiIGknibVb63dDcY3fe0Dkhvld1927jyNxF1WW6LZZm6zNTfl\n"
    "MrY=\n"
    "-----END CERTIFICATE-----";

    modem_key_mgmt_write(CONFIG_MQTT_HELPER_SEC_TAG, MODEM_KEY_MGMT_CRED_TYPE_CA_CHAIN,  digicert, sizeof(digicert));
    modem_key_mgmt_write(CONFIG_MQTT_HELPER_SECONDARY_SEC_TAG, MODEM_KEY_MGMT_CRED_TYPE_CA_CHAIN, baltimore, sizeof(baltimore))
    modem_key_mgmt_write(CONFIG_MQTT_HELPER_SEC_TAG, MODEM_KEY_MGMT_CRED_TYPE_PUBLIC_CERT, devicecert, sizeof(devicecert))
    modem_key_mgmt_write(CONFIG_MQTT_HELPER_SEC_TAG, MODEM_KEY_MGMT_CRED_TYPE_PRIVATE_CERT, devicecertpriv, sizeof(devicecertpriv))
    Since it is not working I am wondering about the sec_tag parameter CONFIG_MQTT_HELPER_SEC_TAG is this the correct use?
    I have also the Baltimore certificate as you can see and the two device certificates are the content from the PEM files in the "certs" folder and the "private" folder from the example.
    I get the -111 error during MQTT connect. Does this mean that it is only related to the DigiCert/Baltimore or would i fail with the samme error if it was device trust?
  • I have now also tested connecting directly to the IoT Hub.

    Following the guide for certificates I have uploadede the generated root CA PEM file to the certificates list in the IoT Hub, then manually added the device and set the Authentification type to "X.509 CA Signed".

    Same result, I still get a -111 error....

Related