Azure / azure-iot-sdk-c

A C99 SDK for connecting devices to Microsoft Azure IoT services
https://azure.github.io/azure-iot-sdk-c
Other
588 stars 740 forks source link

@azure-iot-sdk-c : Device provisioning getting failed with the error PROV_DEVICE_RESULT_DEV_AUTH_ERROR. #1653

Closed neethuantony42 closed 4 years ago

neethuantony42 commented 4 years ago

We are using the azure-iot-sdk -c 1.3.8 version. Device provisioning is getting failed after passing correct key. We are using MQTT. The keys used for Device provisioning

  1. Global device endpoint(Device Provisioning Endpoint)
  2. ID Scope
  3. Symmetric Key (Primary Key) And we using group-enrollment method.

This was working earlier. But now Device Provisioning is getting failed with PROV_DEVICE_RESULT_DEV_AUTH_ERROR.

Please find the trace log:

PROV_DEVICE_RESULT :0 Error: Time:Mon Sep 14 08:03:07 2020 File:/home/siemensvm/Workspace/Neethu/AzureSDK/azure-iot-sdk-c/provisioning_client/src/prov_device_ll_client.c Func:prov_transport_process_json_reply Line:670 Unsuccessful json encountered: {"errorCode":400004,"trackingId":"","message":"BadRequest","timestampUtc":"2020-09-14T08:03:07.2178423Z"} Error: Time:Mon Sep 14 08:03:07 2020 File:/home/siemensvm/Workspace/Neethu/AzureSDK/azure-iot-sdk-c/provisioning_client/src/prov_transport_mqtt_common.c Func:prov_transport_common_mqtt_dowork Line:1014 Unable to process registration reply. Error: Time:Mon Sep 14 08:03:07 2020 File:/home/siemensvm/Workspace/Neethu/AzureSDK/azure-iot-sdk-c/provisioning_client/src/prov_device_ll_client.c Func:on_transport_registration_data Line:770 Failure retrieving data from the provisioning service

Could you please tell us why this error is coming.

Thanks, Neethu

danewalton commented 4 years ago

Hi @neethuantony42 Are you able to double check a couple things for me first?

  1. The section here should be changed so that Symmetric Key auth is used instead. Comment out the x509 part and instead use symmetric key.
  2. The symmetric key should be set here.

Once you verify both of those are in working order and you are still having issues we can move forward with some other things.

neethuantony42 commented 4 years ago

Hi @danewalton , Thank you for the reply. But one think to update that we are not using the samples in the SDK. We are using the SDK in another QT application. Our Device provisioning in our application was working properly. And it is working while we are running in the desktop version. We are getting the error in the our embedded version. (Also in the embedded version it was working earlier).

Please find the code in our used on Device provisioning initialization :

/// Initialization _SECURE_DEVICE_TYPE eHSMType(SECURE_DEVICE_TYPE_SYMMETRIC_KEY); prov_dev_security_init(eHSMType); IoTHubInit();

string strGroupSymmetricKey;
if(bGroupEnrollment)
{
    /// Group enrollment has been selected
    if(false == constructSymmetricKey(strSymmetricKey, strSerialNumber, strGroupSymmetricKey))
    {
        prov_dev_security_deinit();
        IoTHub_Deinit();

        eResult = AICL_RESULT_ERROR_SYMMERTIC_KEY_GENERATION_FAILED;
        return eResult;
    }
}
else
{
    /// Individual enrollment has been selected
    strGroupSymmetricKey = strSymmetricKey;
}

/// set key
if(0 != prov_dev_set_symmetric_key_info(strSerialNumber.c_str(), strGroupSymmetricKey.c_str()))
{
    prov_dev_security_deinit();
    IoTHub_Deinit();

    eResult = AICL_RESULT_ERROR_SETTING_KEY;
}

Thanks, Neethu.

danewalton commented 4 years ago

At least one thing I can think of.

Call me crazy but we've seen it happen many times before. Make sure the clock is getting set correctly on the device. A clock that is out of sync will cause connection issues.

Also if you could post the full logs of the application running that would be great:

bool traceOn = true;
Prov_Device_SetOption(prov_device_handle, PROV_OPTION_LOG_TRACE, &traceOn);
neethuantony42 commented 4 years ago

Hi @danewalton, Thank you for the explanation. We are getting this error only continuously running the application for 4 days. We will collect the log and share once the issue is reproduced.

Thanks, Neethu

danewalton commented 4 years ago

I'm going to go ahead and close this for now but please leave a comment if you would like this reopened. Possibly when you have the logs.

az-iot-builder-01 commented 4 years ago

@danewalton, @neethuantony42, thank you for your contribution to our open-sourced project! Please help us improve by filling out this 2-minute customer satisfaction survey