Filter results by

Azure IoT – Enrollment by X.509 Certificate

Enrolling with the Azure IoT Hub by X.509 certificate provides the base credentials for determining whether a device should be allowed to connect. It involves generation of keys and certificates that are then enrolled with the hub.

In this article, we demonstrate key/certificate generation through a C application supplied in the Azure IoT C SDK. We'll show you two different ways to enroll.

  • Individual

  • Group

The group method is likely the one you'll use in production, but you may want to use the individual method for testing.

Enrollment Models


For a production device, there will be two possibilities for provisioning the device with keys and certificates.

On the factory floor. In one manufacturing scenario, key and certificate generation and management would be done on a secure system on the factory floor, using scripts and possibly a Hardware Security Module (HSM). This facility programs a device key into the ARTIK module Secure Storage and copies the corresponding certificate onto the board. This method allows the certificates to be "white listed" ahead of time.

In this scenario, no key generation software needs to be present on the module itself. A form of the C application code demonstrated here would be present on the factory floor equipment that pre-provisions the modules.

On the device. ARTIK modules provide a means of generating keys and certificates securely, making them ideal for such an application. No "white listing" is used; instead, an enrolled certificate can be revoked and any chip identifiers (such as MAC address) can be kept to prevent future connection.

In this scenario, a form of the C application code demonstrated here would be installed on each module. At connect time, the module software would be used to generate a key and certificate at the moment it is needed and utilized by the C application to perform the enrollment.


Because we need to install and use the SDK on your ARTIK board for other tutorials anyway, we can use that same board as a generic Linux environment to emulate the factory floor equipment. As a result, we will discuss just a single approach of generating all certificates from the ARTIK board demo application. Adjust the model as needed to meet your needs.

Installing C SDK

To enroll a device or group of devices that are to be authenticated using an X.509 certificate (refer to X.509 CA certificate security concepts), we make use of Azure’s sample certificate generator application included with the Azure IoT C SDK.


Set up the Azure

  • IoT Hub
  • Device Provisioning Service

Refer to the introductory article for links and ARTIK-specific information.

Install dependencies

apt update
apt install git
apt install build-essential
apt install cmake
apt install uuid-dev
apt install libssl-dev
apt install curl libcurl4-openssl-dev

Clone the Azure IoT C SDK

git clone --recursive

Build the C SDK

cd azure-iot-sdk-c

mkdir cmake

cd cmake

cmake -Duse_prov_client:BOOL=ON ..


Look for the dice_device_enrollment application under the directory


Hereafter, we'll refer to it simply as the "enrollment application".

Individual Enrollment

For individual enrollment, each of the devices is signed into a certificate chain of trust by the X.509 CA – in our demonstration case, the device itself acts as CA. Refer to the X.509 CA certificate security overview.

  1. Run the enrollment application and select Individual enrollment to obtain the device certificates (primary and secondary).


    Would you like to do Individual (i) or Group (g) enrollments: i
    Device certificate:
    -----END CERTIFICATE-----
    -----END CERTIFICATE-----
    Press any key to continue:
  2. Copy the contents from
    -----END CERTIFICATE-----
    and store it in files called certificate.pem and certificate_2.pem.

  3. Enroll an IoT device.
    1. Select the “Device Provisioning Service” resource that you created here and choose “Manage enrollments”.
    2. Click on “Add individual enrollment”
      • Choose the mechanism as “X.509”
      • Upload the device certificate
      • Type the device id for the new IoT device
      • Make sure that the DPS is linked to the right Azure IoT hub resource
      then click “Save”.

    3. Under “Individual enrollment”, locate the REGISTRATION ID.

Group Enrollment

With group enrollment of a device type, all of the device entries are associated with a specific intermediate or root CA certificate. These entries control enrollments for all devices that have that intermediate or root certificate in their certificate chain.

  1. Run the enrollment application and select Group enrollment to obtain the root certificate.


    Would you like to do Individual (i) or Group (g) enrollments: g
    root cert:
    -----END CERTIFICATE-----
    Enter the Validation Code (Press enter when finished):
  2. Copy the contents from “-----BEGIN CERTIFICATE-----“ to “-----END CERTIFICATE-----“ and store it in a file called root.pem.
  3. In order to generate the leaf device certificate, we need to get the validation code for the root certificate and supply the same to the currently running enrollment application.
    1. Go to the Device Provisioning Service, choose “Certificates”, and click “Add”. Provide the Certificate Name as “root” and upload the root.pem file.
    2. On clicking “Save”, the status will be “Unverified”.
    3. The certificate needs to be verified. Click the certificate name and then click “Generate Verification code” to generate the validation code.

    4. Copy the code and provide the same as the validation code to the enrollment application. Then copy the generated leaf certificate and save it in a file named leaf.pem.

      Enter the Validation Code (Press enter when finished): F7C61676413D37CC0B84872AC0AAD9DBBBC63946C4545ED4

      Leaf Certificate:
       -----BEGIN CERTIFICATE-----
       -----END CERTIFICATE-----
      Press any key to continue:
  4. Upload the leaf.pem file under “Verification certificate” to update the status as “Verified”
  5. Once the root certificate is verified, the same needs to be listed in the Group enrollment in the Device Provisioning Service.
    1. Go to “Manage enrollments” and click on “Add Enrollment Group”.
    2. Provide a name for the group and select the verified certificate as the primary certificate. Click on “Save”.

Security Credentials

You can now click on the device created to gain access to the security credentials. Keep the key and connection strings available for reference so that you can install the credentials on your ARTIK board in the upcoming tutorial.

Last updated on: