You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is a script to generate elliptic curve private keys, create a
certificate signing request for a private key, create root CA and
subordinate CA certificates and sign a certificate signing request
with a CA.
The keys are not encrypted with a password or any other protection. It
is strictly for testing and evaluation purposes.
It is only tested with Azure IoT Hub and Azure DPS, but doesn't include
anything specific for Azure, so in theory it should work with other
cloud vendors.
usage: cert_tool.py [-h] {client_key,root_ca,sub_ca,csr,sign,sign_root}
All file-related arguments have default values. Client key/csr/cert is
stored in ./certs folder and CA keys/certs are stored in ./ca.
Signed-off-by: Gregers Gram Rygg <[email protected]>
The connection to Azure IoT Hub with MQTT is secured using TLS.
108
+
To creat the device certificate you'll need a Certificate Authority (CA) certificate and private key that is used to sign all of your client certificates.
109
+
The CA certificate is uploaded to Azure IoT Hub, so Azure can verify that the device certificate is signed by your CA.
110
+
If you do not have a CA certificate, you can purchase one or make a self-signed test CA certificate for testing purposes.
111
+
112
+
To help generate test CA certificates and handling the device keys and certificates, we've provided a Python script.
113
+
You can find this script here: :file:`nrf/scripts/cert_tool.py`.
114
+
Either call the script relative from the current working directory, or add it to PATH.
115
+
For the rest of this document we'll refer to this script as ``cert_tool.py`` without using the directory name.
116
+
117
+
.. note::
118
+
All of the actions for ``cert_tool.py`` have default values for the input and output file names to make this simple.
119
+
See what arguments are available by running adding the ``--help`` argument to the script.
120
+
121
+
Generate test CA certificates
122
+
+++++++++++++++++++++++++++++
123
+
124
+
* To generate the root CA certificate, use the following command:
125
+
126
+
.. code-block:: console
127
+
128
+
cert_tool.py root_ca
129
+
130
+
This command generates a self-signed root CA certificate and private key and saves them to the files :file:`ca/root-ca-cert.pem` and :file:`ca/root-ca-key.pem`.
131
+
132
+
* To generate the subordinate CA certificate, use the following command:
133
+
134
+
.. code-block:: console
135
+
136
+
cert_tool.py sub_ca
137
+
138
+
This command generates a subordinate CA certificate (signed by the root CA) and private key and saves them to the files :file:`ca/sub-ca-cert.pem` and :file:`ca/sub-ca-key.pem`.
139
+
140
+
Upload and verify the root CA certificate
141
+
+++++++++++++++++++++++++++++++++++++++++
142
+
143
+
To perform proof of possession of the root CA key, you can verify the root CA certificate using the following set of commands:
When generating the private key on your computer, make sure to keep it secure and not to share it with anyone.
326
+
If the private key is compromised, the security of the device is compromised.
327
+
328
+
To obtain a key and certificate generated using ``cert_tool.py``, complete the following steps:
329
+
330
+
1. Generate the key and certificate using the following commands:
331
+
332
+
.. code-block:: console
333
+
334
+
cert_tool.py client_key
335
+
cert_tool.py csr --common-name <device_id>
336
+
cert_tool.py sign
337
+
338
+
#. Provision the certificates and private key at runtime to the Mbed TLS stack.
339
+
This is achieved by placing the PEM files into a :file:`certs/` subdirectory and ensuring the :kconfig:option:`CONFIG_MQTT_HELPER_PROVISION_CERTIFICATES` Kconfig option is enabled.
340
+
For more information, refer to the :ref:`azure_iot_hub` sample as well as the :kconfig:option:`CONFIG_MQTT_HELPER_CERTIFICATES_FILE` Kconfig option.
341
+
342
+
.. rst-class:: numbered-step
343
+
101
344
.. _azure_create_device:
102
345
103
346
Register a device in Azure IoT Hub
@@ -122,46 +365,26 @@ You can list your devices in Azure IoT Hub using the following command:
The connection to Azure IoT Hub with MQTT is secured using TLS.
132
-
For testing purposes, see `Creating Azure IoT Hub certificates`_ for the steps to create certificates and a private key for the leaf device, and to register the generated test root certificate to be used with an IoT Hub.
370
+
Provisioning certificates
371
+
=========================
133
372
134
373
The Azure IoT Hub library requires provisioning of the following certificates and a private key for a successful TLS connection:
135
374
136
-
1. `DigiCert Global Root G2`_ - Server certificate, used to verify the server's certificate chain while connecting.
137
-
#. Public device certificate - generated by the procedures described in `Creating Azure IoT Hub certificates`_ , used by Azure IoT Hub to authenticate the device.
375
+
1. `DigiCert Global Root G2`_ - The root CA certificate, used to verify the server's certificate chain while connecting.
376
+
#. `Baltimore CyberTrust Root Certificate`_ - Azures legacy root CA certificate, needed to verify the Azure server's that haven't migrated to `DigiCert Global Root G2`_ yet.
377
+
#. Public device certificate - generated by the procedures described in REMOVED , used by Azure IoT Hub to authenticate the device.
138
378
#. Private key of the device.
139
379
140
380
.. important::
141
381
Azure has started the process of migrating their DPS server certificates from `Baltimore CyberTrust Root Certificate`_ to `DigiCert Global Root G2`_.
142
382
Azure IoT Hub servers have finished this transition, and only DigiCert Global Root G2 is used now for those connections.
143
383
Azure advises to have both Baltimore CyberTrust Root and DigiCert Global Root G2 certificates for all devices to avoid disruption of service during the transition.
144
384
Refer to `Azure IoT TLS: Critical changes`_ for updated information and timeline.
145
-
Due to this, it is recommended to provision the DigiCert Baltimore CyberTrust Root Certificate to a secondary security tag set by the :kconfig:option:`CONFIG_MQTT_HELPER_SECONDARY_SEC_TAG` option.
385
+
Due to this, it is recommended to provision the Baltimore CyberTrust Root Certificate to a secondary security tag set by the :kconfig:option:`CONFIG_MQTT_HELPER_SECONDARY_SEC_TAG` option.
146
386
This ensures that the device can also connect after the transition.
147
387
148
-
The location and name of the generated public device certificate and private key files vary depending on the method you use for the credential generation as follows:
149
-
150
-
* For PowerShell scripts, the device certificate is called :file:`<mydevice>-public.pem` and the private key is :file:`<mydevice>-private.pem`.
151
-
These files are located in the working directory with the other generated files.
152
-
153
-
* For bash scripts, the public device certificate is called :file:`<mydevice>.cert.pem` and is located in a directory called :file:`certs` within the :file:`script` directory.
154
-
The private key is called :file:`<mydevice>.key.pem` and located in a directory called :file:`private` within the :file:`script` directory.
155
-
156
-
The file and directory names may change if Azure changes their scripts.
157
-
158
-
.. rst-class:: numbered-step
159
-
160
-
.. _azure_iot_hub_flash_certs:
161
-
162
-
Provisioning certificates
163
-
=========================
164
-
165
388
To provision the certificates, use any of the following methods, depending on the DK you are using.
166
389
167
390
.. tabs::
@@ -183,13 +406,13 @@ To provision the certificates, use any of the following methods, depending on th
#. Provison the server certificates, which you downloaded previously, by running the following commands:
195
418
@@ -210,7 +433,8 @@ To provision the certificates, use any of the following methods, depending on th
210
433
211
434
Provision the certificates and private key at runtime to the MbedTLS stack.
212
435
This is achieved by placing the PEM files into a :file:`certs/` subdirectory and ensuring the :kconfig:option:`CONFIG_MQTT_HELPER_PROVISION_CERTIFICATES` Kconfig option is enabled.
213
-
For more information, refer to the :ref:`aws_iot` sample as well as the :kconfig:option:`CONFIG_MQTT_HELPER_CERTIFICATES_FILE` Kconfig option.
436
+
Save DigiCertGlobalRootG2.crt.pem as :file:`certs/ca-cert.pem`, and BaltimoreCyberTrustRoot.crt.pem as :file:`certs/ca-cert-2.pem`.
437
+
For more information, refer to the :ref:`azure_iot_hub` sample as well as the :kconfig:option:`CONFIG_MQTT_HELPER_CERTIFICATES_FILE` Kconfig option.
214
438
215
439
The CA will be provisioned to the security tag set by the :kconfig:option:`CONFIG_MQTT_HELPER_SEC_TAG` Kconfig option.
216
440
@@ -242,7 +466,7 @@ To connect to Azure IoT Hub without using DPS, complete the following minimum re
242
466
The device ID must match with the one used while creating the certificates.
243
467
You can also set the device ID at run time by populating the ``device_id`` member of the :c:struct:`azure_iot_hub_config` structure passed to the :c:func:`azure_iot_hub_connect` function when connecting.
244
468
If the ``device_id.size`` buffer size is zero, the compile-time option :kconfig:option:`CONFIG_AZURE_IOT_HUB_DEVICE_ID` is used.
245
-
#. Make sure that the device is already registered with your Azure IoT Hub, or follow the instructions in `Registering the device with Azure IoT Hub`_.
469
+
#. Make sure that the device is already registered with your Azure IoT Hub, or follow the instructions in :ref:`azure_create_device`.
246
470
#. Set the :kconfig:option:`CONFIG_MQTT_HELPER_SEC_TAG` Kconfig option to the security tag used in :ref:`azure_iot_hub_flash_certs`.
247
471
248
472
Optionally, set the :kconfig:option:`CONFIG_MQTT_HELPER_SECONDARY_SEC_TAG` Kconfig option if multiple server certificates are provisioned.
@@ -254,14 +478,15 @@ Configuration using DPS
254
478
255
479
To connect to Azure IoT Hub using DPS, complete the following steps:
256
480
257
-
1. `Set up an Azure IoT Hub Device Provisioning Service (DPS) instance`_ and obtain the ID scope.
258
-
#. `Add certificates to the DPS instance`_.
259
-
#. Create an *enrollment group* as described in `Device enrollments with Azure Portal`_ and link it to your IoT hub. Select the certificate added in the previous step as the *Primary certificate*.
260
-
#. Enable the :kconfig:option:`CONFIG_AZURE_IOT_HUB_DPS` Kconfig option.
261
-
#. In the `Azure Portal`_, click :guilabel:`Device Provisioning Services` and select the DPS instance to use.
262
-
#. In the overview page, locate and copy the ``ID Scope`` and set the :kconfig:option:`CONFIG_AZURE_IOT_HUB_DPS_ID_SCOPE` Kconfig option to this string.
481
+
1. `Set up an Azure IoT Hub Device Provisioning Service (DPS) instance`_ if you haven't done this already.
482
+
#. Set the :kconfig:option:`CONFIG_AZURE_IOT_HUB_DPS_ID_SCOPE` Kconfig option to the ``ID Scope`` for your DPS instance:
483
+
484
+
.. code-block:: console
485
+
486
+
az iot dps show --name <dps_name> --query "properties.idScope"
263
487
264
488
Alternatively, you can set the registration ID at run time.
489
+
265
490
#. Set the :kconfig:option:`CONFIG_AZURE_IOT_HUB_DPS_REG_ID` Kconfig option to the registration ID.
0 commit comments