1

I am new to Azure MQTT server. I have created account in Azure and Device is registered. I received Hostname, DeviceID and shared access key.

I am using an embedded device working on C. Previously I connected with another MQTT Broker.

How to get the password for theMQTT broker from the Azure? enter image description here

what is {signature-string}, {expiry} and {URL-encoded-resourceURI}? where do i get all theses information, if to encode how to encode in C?

  • https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-security#security-token-structure – Daniel Björk Aug 05 '20 at 07:32
  • @DanielBjörk, Thanks for the reply. How to encode these parameters, like ```{URL-encoded-resourceURI} Lower case URL-encoding of the lower case resource URI ``` ? For example, consider this iot connection string(Changed for security reasons): HostName=rd-test-hub.azure-devices.net;DeviceId=DFG87F5SK8;SharedAccessKey=07sX9LF4PGWTmbpltQFybluKi123C2uBrWcNX+i6kyQ= How can i parse the required parameters? – ATHMESH ANDROID Aug 05 '20 at 07:55
  • Thats whats the documentation describes. – Daniel Björk Aug 05 '20 at 08:04
  • Hi, did any of the answers help you? If so, could you mark them as accepted? Otherwise, please let us know if we can help. – Matthijs van der Veer Aug 10 '20 at 19:31

2 Answers2

2

{signature-string}: This is a HMAC-SHA256 signature string the following format: {URL-encoded-resourceURI} + "\n" + expiry

{expiry}: This is when the credentials will expire. The notation is number of seconds since 00:00:00 UTC on 1 January 1970.

{URL-encoded-resourceURI}: Lower case URL encoding of the resource URI. Your resource ID is rd-test-hub.azure-devices.net/devices/DFG87F5SK8. Encoded and lowercase that would make rd-test-hub.azure-devices.net%2Fdevices%2fdfg87f5sk8

This page does an excellent job of explaining the fields. If you want to find out how to implement this all in C, you can take some inspiration from the C SDK for IoT Hub This might be where the magic happens, but my C is a bit rusty.

Matthijs van der Veer
  • 3,865
  • 2
  • 12
  • 22
0

I have a sample of generating a SAS token from a connection string on my GitHub account. You can find it here: https://github.com/markrad/IoTSASTokenGenerate. Versions in both C and C++. It uses Visual Studio to build but the code should build on Linux too. It has no dependencies in that it implements HMAC SHA256 algorithm, URL encode and decode and Base64 encode and decode. You can likely substitute some of those since your platform may already provide that functionality.

Mark Radbourne
  • 528
  • 3
  • 12