I am trying to support DPS for my ESP32 firmware through HTTPS REST API using SAS.
My device registration ID is: xx-xx-8c4b14149ff4
I took the group enrollment from DPS primary key to generate the symmetric key from the registration ID.
I created the related SAS from that and forged the request, but the server returns "Unauthorized" with error code being 401002.
Here is my request (a curl version is provided for handiness ):
curl -L -i -X PUT \
-H 'Content-Type: application/json' \
-H 'Content-Encoding: utf-8' \
-H 'Authorization: SharedAccessSignature sr=0neXXXXXX22%2Fregistrations%xx-xx-8c4b14149ff4&sig=XXXXXXXXXXXXXXXXXXX%3D&skn=registration&se=1651482003' \
-d '{"registrationId": "xx-xx-8c4b14149ff4"}' \
https://global.azure-devices-provisioning.net/0neXXXXXX22/registrations/xx-xx-8c4b14149ff4/register?api-version=2021-06-01
Note that I replaced secret information with "xx".
The response body is as follows:
{
"errorCode": 401002,
"trackingId": "9fecada7-4e51-455e-9392-68522654a64a",
"message": "Unauthorized",
"timestampUtc": "2022-05-02T08:04:03.5761437Z"
}
Is there anything I must tweak to use the HTTPS REST API from the portal?
What should I look at beside the information themselves (which I already double-checked)?
References:
Actually my signature code had a small bug. I fixed it and now it works.
Here is the (working) code for signing:
See it there: How to generate a symmetric key in C or C++ the same way this script does?