Azure / azure-sdk-for-c

This repository is for active development of the Azure SDK for Embedded C. For consumers of the SDK we recommend visiting our versioned developer docs at https://azure.github.io/azure-sdk-for-c.
MIT License
224 stars 120 forks source link

[Azure_IoT_Central_ESP32] Failed decoding SAS key #2352

Closed matsujirushi closed 2 years ago

matsujirushi commented 2 years ago

Describe the bug "Failed decoding SAS key" occurs when trying individual enrollments of SAS with sample code Azure_IoT_Central_ESP32.

To Reproduce

  1. Generate SAS Key with openssl rand -base64 64 command.
  2. Set SAS Key to IOT_CONFIG_DEVICE_KEY

Expected behavior The SAS Key generation command openssl rand -base64 64 uses what is written in the Azure IoT Central document. I am generating a 64 byte key, but it seems that Azure_IoT_Central_ESP32 only supports up to 32 bytes.

I think you should increase ECODED_SAS_KEY_BUFFER_SIZE in the sample code to 64 or change the Azure IoT Central documentation.

Screenshots

Generate SAS key:

$ openssl rand -base64 64
JX5MSR2bjrEpY3siZjcMxaTDcZ//7OPjdmER024lETmj8mZVXHVMvHE/9ELwqomI
tb3TRkmTzdbHbe1ASsR6Lg==

Log:

1970/1/1 00:00:00 [INFO] Connecting to WIFI wifi_ssid seeed2g
..
1970/1/1 00:00:01 [INFO] WiFi connected, IP address: 192.168.1.106
1970/1/1 00:00:01 [INFO] Setting time using SNTP
......
2022/9/28 11:48:07 [INFO] Time initialized!
2022/9/28 11:48:07 [INFO] Azure IoT client initialized (state=2)
2022/9/28 11:48:07 [ERROR] Failed decoding SAS key.
2022/9/28 11:48:07 [ERROR] Failed creating mqtt password for DPS connection.
2022/9/28 11:48:07 [ERROR] Failed initializing MQTT client.
2022/9/28 11:48:07 [ERROR] Azure IoT client is in error state.
ericwolz commented 2 years ago

Yes, the default autogenerated keysize in IoT Central is 32 bytes, but also supports (and DPS) 64 byte device keys. Will update the sample with longer 64 byte key.

matsujirushi commented 2 years ago

https://github.com/Azure/azure-sdk-for-c-arduino/pull/30

ericwolz commented 2 years ago

Issue resolved with https://github.com/Azure/azure-sdk-for-c-arduino/pull/30