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
Copy file name to clipboardExpand all lines: articles/iot-dps/tutorial-custom-allocation-policies.md
+29-95Lines changed: 29 additions & 95 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ This tutorial demonstrates a custom allocation policy using an Azure Function wr
19
19
***-contoso-tstrsd-007** for the Contoso Toasters Division
20
20
***-contoso-hpsd-088** for the Contoso Heat Pumps Division
21
21
22
-
Devices will be simulated using a provisioning sample included in the [Azure IoT C SDK](https://github.com/Azure/azure-iot-sdk-c).
22
+
Devices are simulated using a provisioning sample included in the [Azure IoT C SDK](https://github.com/Azure/azure-iot-sdk-c).
23
23
24
24
In this tutorial, you'll do the following:
25
25
@@ -81,41 +81,41 @@ In this section, you use the Azure Cloud Shell to create a provisioning service
81
81
```azurecli-interactive
82
82
az group create --name $RESOURCE_GROUP --location $LOCATION
83
83
```
84
-
85
-
2. Use the [az iot dps create](/cli/azure/iot/dps#az-iot-dps-create) command to create an instance of the Device Provisioning Service (DPS). The provisioning service is added to *contoso-us-resource-group*.
84
+
85
+
1. Use the [az iot dps create](/cli/azure/iot/dps#az-iot-dps-create) command to create an instance of the Device Provisioning Service (DPS). The provisioning service is added to *contoso-us-resource-group*.
86
86
87
87
```azurecli-interactive
88
88
az iot dps create --name $DPS --resource-group $RESOURCE_GROUP --location $LOCATION
89
89
```
90
90
91
91
This command might take a few minutes to complete.
92
92
93
-
3. Use the [az iot hub create](/cli/azure/iot/hub#az-iot-hub-create) command to create the **Contoso Toasters Division** IoT hub. The IoT hub is added to *contoso-us-resource-group*.
93
+
1. Use the [az iot hub create](/cli/azure/iot/hub#az-iot-hub-create) command to create the **Contoso Toasters Division** IoT hub. The IoT hub is added to *contoso-us-resource-group*.
This command might take a few minutes to complete.
100
100
101
-
4. Use the [az iot hub create](/cli/azure/iot/hub#az-iot-hub-create) command to create the **Contoso Heat Pumps Division** IoT hub. This IoT hub also is added to *contoso-us-resource-group*.
101
+
1. Use the [az iot hub create](/cli/azure/iot/hub#az-iot-hub-create) command to create the **Contoso Heat Pumps Division** IoT hub. This IoT hub also is added to *contoso-us-resource-group*.
@@ -149,7 +149,7 @@ In this section, you create an Azure function that implements your custom alloca
149
149
150
150
1. On the **Review + create** tab, select **Create** to create the function app.
151
151
152
-
1. Deployment may take several minutes. When it completes, select **Go to resource**.
152
+
1. Deployment might take several minutes. When it completes, select **Go to resource**.
153
153
154
154
1. On the left pane of the function app **Overview** page, select **Create function**.
155
155
@@ -184,7 +184,7 @@ In this section, you create an Azure function that implements your custom alloca
184
184
185
185
1. Select the **Upload** button located above the code editor to upload your *function.proj* file. After uploading, select the file in the code editor using the drop-down box to verify the contents.
186
186
187
-
1. Select the *function.proj* file in the code editor and verify its contents. If the *function.proj* file is empty copy the lines above into the file and save it. (Sometimes the upload will create the file without uploading the contents.)
187
+
1. Select the *function.proj* file in the code editor and verify its contents. If the *function.proj* file is empty copy the lines above into the file and save it. (Sometimes the upload creates the file without uploading the contents.)
188
188
189
189
1. Make sure *run.csx* for **HttpTrigger1** is selected in the code editor. Replace the code for the **HttpTrigger1** function with the following code and select **Save**:
190
190
@@ -327,7 +327,7 @@ In this section, you create an Azure function that implements your custom alloca
327
327
328
328
## Create the enrollment
329
329
330
-
In this section, you'll create a new enrollment group that uses the custom allocation policy. For simplicity, this tutorial uses [Symmetric key attestation](concepts-symmetric-key-attestation.md) with the enrollment. For a more secure solution, consider using [X.509 certificate attestation](concepts-x509-attestation.md) with a chain of trust.
330
+
In this section, you create a new enrollment group that uses the custom allocation policy. For simplicity, this tutorial uses [Symmetric key attestation](concepts-symmetric-key-attestation.md) with the enrollment. For a more secure solution, consider using [X.509 certificate attestation](concepts-x509-attestation.md) with a chain of trust.
331
331
332
332
1. Sign in to the [Azure portal](https://portal.azure.com) and navigate to your Device Provisioning Service instance.
333
333
@@ -357,35 +357,29 @@ In this section, you'll create a new enrollment group that uses the custom alloc
357
357
358
358
1. On the **Review + create** tab, verify all of your values then select **Create**.
359
359
360
-
After saving the enrollment, reopen it and make a note of the **Primary key**. You must save the enrollment first to have the keys generated. This key will be used to generate unique device keys for simulated devices later.
360
+
After saving the enrollment, reopen it and make a note of the **Primary key**. You must save the enrollment first to have the keys generated. This key is used to generate unique device keys for simulated devices in the next section.
361
361
362
362
## Derive unique device keys
363
363
364
-
Devices don't use the enrollment group's primary symmetric key directly. Instead, you use the primary key to derive a device key for each device. In this section, you create two unique device keys. One key will be used for a simulated toaster device. The other key will be used for a simulated heat pump device.
364
+
Devices don't use the enrollment group's primary symmetric key directly. Instead, you use the primary key to derive a device key for each device. In this section, you create two unique device keys. One key is used for a simulated toaster device. The other key is used for a simulated heat pump device.
365
365
366
-
To derive the device key, you use the enrollment group **Primary Key** you noted earlier to compute the [HMAC-SHA256](https://wikipedia.org/wiki/HMAC) of the device registration ID for each device and convert the result into Base64 format. For more information on creating derived device keys with enrollment groups, see the group enrollments section of [Symmetric key attestation](concepts-symmetric-key-attestation.md).
366
+
To derive the device key, you use the enrollment group **Primary Key** you noted earlier to compute the [HMAC-SHA256](https://wikipedia.org/wiki/HMAC) of the device registration ID for each device and convert the result into Base 64 format. For more information on creating derived device keys with enrollment groups, see the group enrollments section of [Symmetric key attestation](concepts-symmetric-key-attestation.md).
367
367
368
368
For the example in this tutorial, use the following two device registration IDs and compute a device key for both devices. Both registration IDs have a valid suffix to work with the example code for the custom allocation policy:
369
369
370
370
* **breakroom499-contoso-tstrsd-007**
371
371
* **mainbuilding167-contoso-hpsd-088**
372
372
373
-
# [Azure CLI](#tab/azure-cli)
374
-
375
373
The IoT extension for the Azure CLI provides the [`iot dps enrollment-group compute-device-key`](/cli/azure/iot/dps/enrollment-group#az-iot-dps-enrollment-group-compute-device-key) command for generating derived device keys. This command can be used on Windows-based or Linux systems, from PowerShell or a Bash shell.
376
374
377
375
Replace the value of `--key` argument with the **Primary Key** from your enrollment group.
378
376
379
377
```azurecli
380
-
az iot dps enrollment-group compute-device-key --key oiK77Oy7rBw8YB6IS6ukRChAw+Yq6GC61RMrPLSTiOOtdI+XDu0LmLuNm11p+qv2I+adqGUdZHm46zXAQdZoOA== --registration-id breakroom499-contoso-tstrsd-007
381
-
382
-
"JC8F96eayuQwwz+PkE7IzjH2lIAjCUnAa61tDigBnSs="
378
+
az iot dps enrollment-group compute-device-key --key <ENROLLMENT_GROUP_KEY> --registration-id breakroom499-contoso-tstrsd-007
383
379
```
384
380
385
381
```azurecli
386
-
az iot dps compute-device-key --key oiK77Oy7rBw8YB6IS6ukRChAw+Yq6GC61RMrPLSTiOOtdI+XDu0LmLuNm11p+qv2I+adqGUdZHm46zXAQdZoOA== --registration-id mainbuilding167-contoso-hpsd-088
387
-
388
-
"6uejA9PfkQgmYylj8Zerp3kcbeVrGZ172YLa7VSnJzg="
382
+
az iot dps compute-device-key --key <ENROLLMENT_GROUP_KEY> --registration-id mainbuilding167-contoso-hpsd-088
389
383
```
390
384
391
385
> [!NOTE]
@@ -395,60 +389,7 @@ az iot dps compute-device-key --key oiK77Oy7rBw8YB6IS6ukRChAw+Yq6GC61RMrPLSTiOOt
The simulated devices will use the derived device keys with each registration ID to perform symmetric key attestation.
392
+
The simulated devices use the derived device keys with each registration ID to perform symmetric key attestation.
452
393
453
394
## Prepare an Azure IoT C SDK development environment
454
395
@@ -487,7 +428,7 @@ This section is oriented toward a Windows-based workstation. For a Linux example
487
428
488
429
If `cmake` doesn't find your C++ compiler, you might see build errors while running the command. If that happens, try running the command in the [Visual Studio command prompt](/dotnet/framework/tools/developer-command-prompt-for-vs).
489
430
490
-
Once the build succeeds, the last few output lines will look similar to the following output:
431
+
Once the build succeeds, the last few output lines look similar to the following output:
@@ -507,21 +448,17 @@ This section is oriented toward a Windows-based workstation. For a Linux example
507
448
508
449
In this section, you update a provisioning sample named **prov\_dev\_client\_sample** located in the Azure IoT C SDK you set up previously.
509
450
510
-
This sample code simulates a device boot sequence that sends the provisioning request to your Device Provisioning Service instance. The boot sequence will cause the toaster device to be recognized and assigned to the IoT hub using the custom allocation policy.
451
+
This sample code simulates a device boot sequence that sends the provisioning request to your Device Provisioning Service instance. The boot sequence causes the toaster device to be recognized and assigned to the IoT hub using the custom allocation policy.
511
452
512
-
1. In the Azure portal, select the **Overview** tab for your Device Provisioning Service and note down the **_ID Scope_** value.
453
+
1. In the Azure portal, select the **Overview** tab for your Device Provisioning Service and note down the **ID Scope** value.
513
454
514
-

455
+

515
456
516
-
2. In Visual Studio, open the **azure_iot_sdks.sln** solution file that was generated by running CMake earlier. The solution file should be in the following location:
517
-
518
-
```
519
-
azure-iot-sdk-c\cmake\azure_iot_sdks.sln
520
-
```
457
+
2. In Visual Studio, open the **azure_iot_sdks.sln** solution file that was generated by running CMake earlier. The solution file should be in the following location: `azure-iot-sdk-c\cmake\azure_iot_sdks.sln`.
521
458
522
459
3. In Visual Studio's *Solution Explorer* window, navigate to the **Provision\_Samples** folder. Expand the sample project named **prov\_dev\_client\_sample**. Expand **Source Files**, and open **prov\_dev\_client\_sample.c**.
523
460
524
-
4. Find the `id_scope` constant, and replace the value with your **ID Scope** value that you copied earlier.
461
+
4. Find the `id_scope` constant, and replace the value with your **ID Scope** value that you copied earlier.
525
462
526
463
```c
527
464
static const char* id_scope = "0ne00002193";
@@ -601,8 +538,6 @@ This sample code simulates a device boot sequence that sends the provisioning re
1. To simulate the heat pump device, update the call to `prov_dev_set_symmetric_key_info()` in **prov\_dev\_client\_sample.c** again with the heat pump registration ID and derived device key you generated earlier. The key value **6uejA9PfkQgmYylj8Zerp3kcbeVrGZ172YLa7VSnJzg=** shown below is also only given as an example.
@@ -632,7 +567,7 @@ This sample code simulates a device boot sequence that sends the provisioning re
632
567
Press enter key to exit:
633
568
```
634
569
635
-
## Troubleshooting custom allocation policies
570
+
## Troubleshoot custom allocation policies
636
571
637
572
The following table shows expected scenarios and the results error codes you might receive. Use this table to help troubleshoot custom allocation policy failures with your Azure Functions.
638
573
@@ -653,13 +588,12 @@ The steps here assume you created all resources in this tutorial as instructed i
653
588
654
589
> [!IMPORTANT]
655
590
> Deleting a resource group is irreversible. The resource group and all the resources contained in it are permanently deleted. Make sure that you don't accidentally delete the wrong resource group or resources. If you created the IoT Hub inside an existing resource group that contains resources you want to keep, only delete the IoT Hub resource itself instead of deleting the resource group.
656
-
>
657
591
658
592
To delete the resource group by name:
659
593
660
594
1. Sign in to the [Azure portal](https://portal.azure.com) and select **Resource groups**.
661
595
662
-
2. In the **Filter by name...** textbox, type the name of the resource group containing your resources, **contoso-us-resource-group**.
596
+
2. In the **Filter by name...** textbox, type the name of the resource group containing your resources, **contoso-us-resource-group**.
663
597
664
598
3. To the right of your resource group in the result list, select **...** then **Delete resource group**.
0 commit comments