Skip to content

Commit 57796c2

Browse files
committed
Added documentation for signing with Azure Key Vault
1 parent 918fdc5 commit 57796c2

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

docs/azure_keyvault.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
## Signing firmware using Microsoft Azure Keyvault
2+
3+
Microsoft offer secure key management and provisioning tools, using keys stored
4+
in HSMs. This mechanisms helps to centralize key management for several purposes,
5+
including the support for signing payloads using the managed keys, which can be
6+
used in combination with wolfBoot for provisioning public keys in a fleet of
7+
devices.
8+
9+
10+
### Preparing the keystore
11+
12+
wolfBoot can import public keys in the keystore using the `keygen` command line
13+
tool provided. `keygen` supports both raw ECC keys and ASN.1 format (.der).
14+
15+
Azure allows to download the public keys in ASN.1 format to provision the device.
16+
To retrieve each pukey to use for firmware authentication in wolfBoot, use:
17+
18+
```
19+
az keyvault key download --vault-name <vault-name> -n test-signing-key-1 -e DER -f public-key-1.der
20+
```
21+
22+
A keystore can now be created importing the public keys and with `keygen`'s `-i`
23+
(import) option. The option may be repeated multiple times to add more keys to
24+
the keystore.
25+
26+
```
27+
tools/keytools/keygen --ecc256 -i public-key-1.der [-i public-key-2.der ...]
28+
```
29+
30+
### Signing the firmware image for wolfBoot
31+
32+
The signing operation using any external HSM is performed through three-steps,
33+
as described in the relevant section in [Signing.md](signing.md).
34+
In this section we describe the procedure to sign the firmware image using Azure key vault.
35+
36+
37+
#### Obtaining the SHA256 digest
38+
39+
Step 1 consists in calling the `./sign` tool with the extra `--sha-only` argument,
40+
to generate the digest to sign. The public key associated to the selected signing
41+
key in the vault needs to be provided:
42+
43+
```
44+
./sign --ecc256 --sha-only --sha256 test-app/image.bin public-keyi-1.der 1
45+
```
46+
47+
To fit in a https REST request, the digest obtained must be encoded using base64:
48+
49+
```
50+
DIGEST=$(cat test-app/image_v1_digest.bin | base64url_encode)
51+
52+
```
53+
54+
The variable `DIGEST` now contains a printable encoding of the key, which can be
55+
attached to the request.
56+
57+
#### HTTPS request for signing the digest with the Key Vault
58+
59+
60+
To prepare the request, first get an access token from the vault and store it in a variable:
61+
62+
```
63+
ACCESS_TOKEN=$(az account get-access-token --resource "https://vault.azure.net" --query "accessToken" -o tsv)
64+
```
65+
66+
Use the URL associated to the selected key vault:
67+
68+
```
69+
KEY_IDENTIFIER="https://<vault-name>.vault.azure.net/keys/test-signing-key"
70+
```
71+
72+
Perform the request using cURL, and store the result in a variable:
73+
74+
```
75+
SIGNING_RESULT=$(curl -X POST \
76+
-s "${KEY_IDENTIFIER}/sign?api-version=7.4" \
77+
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
78+
-H "Content-Type:application/json" \
79+
-H "Accept:application/json" \
80+
-d "{\"alg\":\"ES256\",\"value\":\"${DIGEST}\"}")
81+
echo $SIGNING_RESULT
82+
```
83+
84+
The field `.value` in the result contains the (base64 encoded) signature.
85+
To extract the signature from the response, you can use a JSON parser:
86+
87+
```
88+
SIGNATURE=$(jq -jn "$SIGNING_RESULT|.value")
89+
```
90+
91+
The signature can now be decoded from base64 into a binary, so the
92+
`sign` tool can incorporate the signature into the manifest header.
93+
94+
```
95+
echo $SIGNATURE| base64url_decode > test-app/image_v1_digest.sig
96+
```
97+
98+
#### Final step: create the signed firmware image
99+
100+
The 'third step' in the HSM three-steps procedure requires the `--manual-sign` option and the
101+
signature obtained through the Azure REST API.
102+
103+
104+
```
105+
./sign --ecc256 --sha256 --manual-sign test-app/image.bin test-signin-key_pub.der 1 test-app/image_v1_digest.sig
106+
```
107+
108+
The resulting binary file `image_v1_signed.bin` will now contain a signed firmware
109+
image that can be authenticated and staged by wolfBoot.
110+

0 commit comments

Comments
 (0)