This is a quick tutorial with the steps to create, update, get, and delete an Individual Enrollment on the Microsoft Azure IoT Hub Device Provisioning Service using the C SDK.
- Clone the C SDK repository
- Compile the C SDK as shown here, using the
-Duse_prov_client=ON
flag. - Edit
provisioning_individual_enrollment_sample.c
to add your provisioning service information:-
Replace the
[Connection String]
with the Provisioning Connection String copied from your Device Provisiong Service on the Portal.const char* connectionString = "[Connection String]";
-
For a TPM Attestation (as shown in the sample):
-
From the device that you have, you must copy the Registration ID and Endorsement Key. If you do not have a physical device with a TPM, you can create a Registration ID yourself, and use the following endorsement key for testing purposes:
AToAAQALAAMAsgAgg3GXZ0SEs/gakMyNRqXXJP1S124GUgtk8qHaGzMUaaoABgCAAEMAEAgAAAAAAAEAxsj2gUScTk1UjuioeTlfGYZrrimExB+bScH75adUMRIi2UOMxG1kw4y+9RW/IVoMl4e620VxZad0ARX2gUqVjYO7KPVt3dyKhZS3dkcvfBisBhP1XH9B33VqHG9SHnbnQXdBUaCgKAfxome8UmBKfe+naTsE5fkvjb/do3/dD6l4sGBwFCnKRdln4XpM03zLpoHFao8zOwt8l/uP3qUIxmCYv9A7m69Ms+5/pCkTu/rK4mRDsfhZ0QLfbzVI6zQFOKF/rwsfBtFeWlWtcuJMKlXdD8TXWElTzgh7JS4qhFzreL0c1mI0GCj+Aws0usZh7dLIVPnlgZcBhgy1SSDQMQ==
-
Replace the
[Registration Id]
with the Reigstration ID, and[Endorsement Key]
with the Endorsement Key.const char* registrationId = "[Registration Id]"; const char* endorsementKey = "[Endorsement Key]";
-
Optionally, Replace the
[Device Id]
with a Device ID.const char* deviceId = "[Device Id]";
-
-
For a X509 Attestation (not shown in this sample):
-
From the device that you have, you must copy the Registration ID and the Client Certificate. You can use a physical device with DICE, or use a certificate you generate yourself. One possible way to do this is to use the included CA Certificates Tool.
-
Replace the
[Registration Id]
with the Registration ID, and define a variableclientCertificate
containing your Client Certificateconst char* registrationId = "[Registration Id]"; const char* clientCertificate = "[Client Certificate]";
Note that a certificate format can be just the Base 64 encoding, or can include the
-----BEGIN CERTIFICATE-----
and-----END CERTIFICATE-----
tags, either works. -
Replace the TPM Attestation Mechanism in the sample with an X509 Attestation Mechanism.
Replace
if ((am_handle = attestationMechanism_createWithTpm(endorsementKey)) == NULL) { printf("Failed calling attestationMechanism_createWithTpm\n"); result = MU_FAILURE; }
With
if ((am_handle = attestationMechanism_createWithX509ClientCert(clientCertificate, NULL)) == NULL) { printf("Failed calling attestationMechanism_createWithX509ClientCert\n"); result = MU_FAILURE; }
-
-
- Build as shown here and run the sample.