Engineer999
Engineer999

Reputation: 3955

Azure IoT SDK - connection not accepted problem

I am using the Azure IoT SDK for C to try and provision a device on my hub on the Azure IoT Portal.

I have followed the instructions in order to generate signed certificates and add them to the portal as stated here https://github.com/Azure/azure-iot-sdk-c/blob/master/tools/CACertificates/CACertificateOverview.md

and also here in this tutorial https://kevinsaye.wordpress.com/2020/04/14/using-a-real-certificate-with-the-azure-iot-client-c-sdk-and-the-provisioning-service/ .

When I run the sample code prov_dev_client_ll_sample.c with all my changes, I am continuously getting the below authorization error. I have built and run code this for an X86-64 chip running Debian, and also cross-compiled for an ARM chip, both yielding the same error.

On the Azure Portal, I have tried to create an enrollment group associating the certificates, and also tried to create an individual enrollment, explicitly adding the certificates. Nothing works. People have suggested that my clock might be out of date. However, it looks fine when I run date .

Any help would be greatly appreciated. I am more than two days trying to solve this issue now.

Running provisioning appplication..
Provisioning API Version : 1.3.8
Iothub API Version: 1.3.8
Device Certificate Name File: Device_identity.txt
Device Certificate PEM File : Device_cert.pem
Device Private Key PEM File : Device_key.pem
Error: Time:Fri Jun 19 12:02:42 2020 File:/home/azure-iot-sdk- 
c/provisioning_client/src/prov_transport_mqtt_common.c Func:mqtt_operation_complete_callback Line:208 
Connection Not Accepted: 0x5: Not Authorized
Error: Time:Fri Jun 19 12:02:42 2020 File:/home/azure-iot-sdk- 
c/provisioning_client/src/prov_transport_mqtt_common.c Func:mqtt_error_callback Line:139 MQTT 
communication error
Error: Time:Fri Jun 19 12:02:42 2020 File:/home/azure-iot-sdk-
c/provisioning_client/src/prov_device_ll_client.c Func:on_transport_registration_data Line:771 
Failure 
retrieving data from the provisioning service
Failure encountered on registration PROV_DEVICE_RESULT_DEV_AUTH_ERROR
registration failed!
Press any enter to continue:

Upvotes: 0

Views: 1090

Answers (1)

Dominic Betts
Dominic Betts

Reputation: 2331

There are two distinct scenarios for using an X.509 cert to connect a device to an Azure IoT hub:

  • Register and connect the device directly with your IoT hub
  • Use the Device Provisioning Service to assign and register your device to an IoT hub so that it can connect.

This sample shows you how to connect a device directly to IoT Hub without using DPS: https://github.com/Azure/azure-iot-sdk-c/tree/master/iothub_client/samples/iothub_ll_client_x509_sample. The sample assumes you're using the scripts described in https://github.com/Azure/azure-iot-sdk-c/blob/master/tools/CACertificates/CACertificateOverview.md to generate your keys and certs. For more information, see: https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-x509ca-overview.

This sample (the one you're trying to run) shows you how to use DPS to register your device with IoT Hub: https://github.com/Azure/azure-iot-sdk-c/tree/master/provisioning_client/samples/prov_dev_client_sample. The sample uses a simulated Hardware Security Module (HSM) to generate the keys and certs (not the scripts). For more information about how to run this sample, see https://learn.microsoft.com/azure/iot-dps/quick-create-simulated-device-x509.

Upvotes: 0

Related Questions