Skip to content

Commit c512146

Browse files
committed
edits and acrolinx
1 parent d1475ec commit c512146

File tree

1 file changed

+29
-95
lines changed

1 file changed

+29
-95
lines changed

articles/iot-dps/tutorial-custom-allocation-policies.md

Lines changed: 29 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This tutorial demonstrates a custom allocation policy using an Azure Function wr
1919
* **-contoso-tstrsd-007** for the Contoso Toasters Division
2020
* **-contoso-hpsd-088** for the Contoso Heat Pumps Division
2121

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).
2323

2424
In this tutorial, you'll do the following:
2525

@@ -81,41 +81,41 @@ In this section, you use the Azure Cloud Shell to create a provisioning service
8181
```azurecli-interactive
8282
az group create --name $RESOURCE_GROUP --location $LOCATION
8383
```
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*.
8686

8787
```azurecli-interactive
8888
az iot dps create --name $DPS --resource-group $RESOURCE_GROUP --location $LOCATION
8989
```
9090
9191
This command might take a few minutes to complete.
9292
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*.
9494
9595
```azurecli-interactive
9696
az iot hub create --name $TOASTER_HUB --resource-group $RESOURCE_GROUP --location $LOCATION --sku S1
9797
```
9898
99-
This command may take a few minutes to complete.
99+
This command might take a few minutes to complete.
100100
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*.
102102
103103
```azurecli-interactive
104-
az iot hub create --name HEATPUMP_HUB --resource-group $RESOURCE_GROUP --location $LOCATION --sku S1
104+
az iot hub create --name $HEATPUMP_HUB --resource-group $RESOURCE_GROUP --location $LOCATION --sku S1
105105
```
106106
107-
This command may take a few minutes to complete.
107+
This command might take a few minutes to complete.
108108
109-
5. Run the following two commands to get the connection strings for the hubs you created.
109+
1. Run the following two commands to get the connection strings for the hubs you created.
110110
111-
```azurecli-interactive
111+
```azurecli-interactive
112112
az iot hub connection-string show --hub-name $TOASTER_HUB --key primary --query connectionString -o tsv
113113
az iot hub connection-string show --hub-name $HEATPUMP_HUB --key primary --query connectionString -o tsv
114114
```
115115
116-
6. Run the following commands to link the hubs to the DPS resource. Replace the placeholders with the hub connection strings from the previous step.
116+
1. Run the following commands to link the hubs to the DPS resource. Replace the placeholders with the hub connection strings from the previous step.
117117
118-
```azurecli-interactive
118+
```azurecli-interactive
119119
az iot dps linked-hub create --dps-name $DPS --resource-group $RESOURCE_GROUP --location $LOCATION --connection-string <toaster_hub_connection_string>
120120
az iot dps linked-hub create --dps-name $DPS --resource-group $RESOURCE_GROUP --location $LOCATION --connection-string <heatpump_hub_connection_string>
121121
```
@@ -149,7 +149,7 @@ In this section, you create an Azure function that implements your custom alloca
149149
150150
1. On the **Review + create** tab, select **Create** to create the function app.
151151
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**.
153153
154154
1. On the left pane of the function app **Overview** page, select **Create function**.
155155
@@ -184,7 +184,7 @@ In this section, you create an Azure function that implements your custom alloca
184184
185185
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.
186186
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.)
188188
189189
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**:
190190
@@ -327,7 +327,7 @@ In this section, you create an Azure function that implements your custom alloca
327327
328328
## Create the enrollment
329329
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.
331331
332332
1. Sign in to the [Azure portal](https://portal.azure.com) and navigate to your Device Provisioning Service instance.
333333
@@ -357,35 +357,29 @@ In this section, you'll create a new enrollment group that uses the custom alloc
357357
358358
1. On the **Review + create** tab, verify all of your values then select **Create**.
359359
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.
361361
362362
## Derive unique device keys
363363
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.
365365
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).
367367
368368
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:
369369
370370
* **breakroom499-contoso-tstrsd-007**
371371
* **mainbuilding167-contoso-hpsd-088**
372372
373-
# [Azure CLI](#tab/azure-cli)
374-
375373
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.
376374
377375
Replace the value of `--key` argument with the **Primary Key** from your enrollment group.
378376
379377
```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
383379
```
384380

385381
```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
389383
```
390384

391385
> [!NOTE]
@@ -395,60 +389,7 @@ az iot dps compute-device-key --key oiK77Oy7rBw8YB6IS6ukRChAw+Yq6GC61RMrPLSTiOOt
395389
> az iot dps enrollment-group compute-device-key -g contoso-us-resource-group --dps-name contoso-provisioning-service-1098 --enrollment-id contoso-custom-allocated-devices --registration-id breakroom499-contoso-tstrsd-007
396390
> ```
397391
398-
# [PowerShell](#tab/powershell)
399-
400-
If you're using a Windows-based workstation, you can use PowerShell to generate your derived device key as shown in the following example.
401-
402-
Replace the value of **KEY** with the **Primary Key** you noted earlier.
403-
404-
```powershell
405-
$KEY='oiK77Oy7rBw8YB6IS6ukRChAw+Yq6GC61RMrPLSTiOOtdI+XDu0LmLuNm11p+qv2I+adqGUdZHm46zXAQdZoOA=='
406-
407-
$REG_ID1='breakroom499-contoso-tstrsd-007'
408-
$REG_ID2='mainbuilding167-contoso-hpsd-088'
409-
410-
$hmacsha256 = New-Object System.Security.Cryptography.HMACSHA256
411-
$hmacsha256.key = [Convert]::FromBase64String($KEY)
412-
$sig1 = $hmacsha256.ComputeHash([Text.Encoding]::ASCII.GetBytes($REG_ID1))
413-
$sig2 = $hmacsha256.ComputeHash([Text.Encoding]::ASCII.GetBytes($REG_ID2))
414-
$derivedkey1 = [Convert]::ToBase64String($sig1)
415-
$derivedkey2 = [Convert]::ToBase64String($sig2)
416-
417-
echo "`n`n$REG_ID1 : $derivedkey1`n$REG_ID2 : $derivedkey2`n`n"
418-
```
419-
420-
```powershell
421-
breakroom499-contoso-tstrsd-007 : JC8F96eayuQwwz+PkE7IzjH2lIAjCUnAa61tDigBnSs=
422-
mainbuilding167-contoso-hpsd-088 : 6uejA9PfkQgmYylj8Zerp3kcbeVrGZ172YLa7VSnJzg=
423-
```
424-
425-
# [Bash](#tab/bash)
426-
427-
If you're using a Linux workstation, you can use openssl to generate your derived device keys as shown in the following example.
428-
429-
Replace the value of **KEY** with the **Primary Key** you noted earlier.
430-
431-
```bash
432-
KEY=oiK77Oy7rBw8YB6IS6ukRChAw+Yq6GC61RMrPLSTiOOtdI+XDu0LmLuNm11p+qv2I+adqGUdZHm46zXAQdZoOA==
433-
434-
REG_ID1=breakroom499-contoso-tstrsd-007
435-
REG_ID2=mainbuilding167-contoso-hpsd-088
436-
437-
keybytes=$(echo $KEY | base64 --decode | xxd -p -u -c 1000)
438-
devkey1=$(echo -n $REG_ID1 | openssl sha256 -mac HMAC -macopt hexkey:$keybytes -binary | base64)
439-
devkey2=$(echo -n $REG_ID2 | openssl sha256 -mac HMAC -macopt hexkey:$keybytes -binary | base64)
440-
441-
echo -e $"\n\n$REG_ID1 : $devkey1\n$REG_ID2 : $devkey2\n\n"
442-
```
443-
444-
```bash
445-
breakroom499-contoso-tstrsd-007 : JC8F96eayuQwwz+PkE7IzjH2lIAjCUnAa61tDigBnSs=
446-
mainbuilding167-contoso-hpsd-088 : 6uejA9PfkQgmYylj8Zerp3kcbeVrGZ172YLa7VSnJzg=
447-
```
448-
449-
---
450-
451-
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.
452393
453394
## Prepare an Azure IoT C SDK development environment
454395
@@ -487,7 +428,7 @@ This section is oriented toward a Windows-based workstation. For a Linux example
487428
488429
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).
489430
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:
491432
492433
```cmd/sh
493434
$ cmake -Dhsm_type_symm_key:BOOL=ON -Duse_prov_client:BOOL=ON ..
@@ -507,21 +448,17 @@ This section is oriented toward a Windows-based workstation. For a Linux example
507448
508449
In this section, you update a provisioning sample named **prov\_dev\_client\_sample** located in the Azure IoT C SDK you set up previously.
509450
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.
511452
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.
513454
514-
![Extract Device Provisioning Service endpoint information from the portal blade](./media/quick-create-simulated-device-x509/copy-id-scope.png)
455+
![Extract Device Provisioning Service endpoint information from the portal blade](./media/quick-create-simulated-device-x509/copy-id-scope.png)
515456
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`.
521458
522459
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**.
523460
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.
525462
526463
```c
527464
static const char* id_scope = "0ne00002193";
@@ -601,8 +538,6 @@ This sample code simulates a device boot sequence that sends the provisioning re
601538
2022-08-03T20:34:41.399 [Information] Executed 'Functions.HttpTrigger1' (Succeeded, Id=12950752-6d75-4f41-844b-c253a6653d4f, Duration=227ms)
602539
```
603540
604-
605-
606541
### Simulate the Contoso heat pump device
607542
608543
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
632567
Press enter key to exit:
633568
```
634569
635-
## Troubleshooting custom allocation policies
570+
## Troubleshoot custom allocation policies
636571
637572
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.
638573
@@ -653,13 +588,12 @@ The steps here assume you created all resources in this tutorial as instructed i
653588
654589
> [!IMPORTANT]
655590
> 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-
>
657591
658592
To delete the resource group by name:
659593
660594
1. Sign in to the [Azure portal](https://portal.azure.com) and select **Resource groups**.
661595
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**.
663597
664598
3. To the right of your resource group in the result list, select **...** then **Delete resource group**.
665599

0 commit comments

Comments
 (0)