Skip to content

Commit 0bf65fa

Browse files
authored
Merge pull request #574 from bigbrett/wolfhsm-cert-verify
Add cert chain verification via wolfHSM on sim and TC3xx
2 parents 2b996f8 + 6abf550 commit 0bf65fa

File tree

25 files changed

+967
-127
lines changed

25 files changed

+967
-127
lines changed

.github/workflows/test-wolfhsm-simulator.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ jobs:
1818
file: "config/examples/sim-wolfHSM.config"
1919
- name: "wolfHSM ML-DSA"
2020
file: "config/examples/sim-wolfHSM-mldsa.config"
21+
- name: "wolfHSM cert chain verify"
22+
file: "config/examples/sim-wolfHSM-certchain.config"
2123
fail-fast: false
2224

2325
runs-on: ubuntu-latest
@@ -54,8 +56,7 @@ jobs:
5456
with:
5557
repository: wolfssl/wolfHSM-examples
5658
# Make sure to update this when the wolfHSM submodule is updated!
57-
#ref: wolfHSM-v1.1.0
58-
ref: 3e03bd4d4a8439ed4a8a9577823c89e4c37eb9be
59+
ref: wolfHSM-examples-v1.2.0
5960
path: wolfHSM-examples
6061

6162
- name: Build example POSIX TCP server
@@ -65,7 +66,13 @@ jobs:
6566
- name: Run POSIX TCP server
6667
run: |
6768
cd wolfHSM-examples/posix/tcp/wh_server_tcp
68-
./Build/wh_server_tcp.elf --client 12 --id 255 --key ../../../../wolfboot_signing_private_key_pub.der &
69+
if [ "${{ matrix.config.name }}" = "wolfHSM cert chain verify" ]; then
70+
tmpfile=$(mktemp)
71+
echo "obj 1 0xFFFF 0x0000 \"cert CA\" ../../../../test-dummy-ca/root-cert.der" >> $tmpfile
72+
./Build/wh_server_tcp.elf --nvminit $tmpfile &
73+
else
74+
./Build/wh_server_tcp.elf --client 12 --id 255 --key ../../../../wolfboot_signing_private_key_pub.der &
75+
fi
6976
TCP_SERVER_PID=$!
7077
echo "TCP_SERVER_PID=$TCP_SERVER_PID" >> $GITHUB_ENV
7178

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ include/target.h
9999
.wolfboot-partition-size
100100
.bootloader-partition-size
101101
MPLabX/wolfBoot-SAME51.X/.generated_files/
102+
test-dummy-ca/**
102103

103104
# Test tools
104105
tools/check_config/check_config

IDE/AURIX/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This example demonstrates using wolfBoot on the Infineon AURIX TC3xx family of m
1010
- [Flash Partitioning](#flash-partitioning)
1111
- [Standard wolfBoot images](#standard-wolfboot-images)
1212
- [ELF files](#elf-files)
13+
- [Cert Chain Verification](#cert-chain-verification)
1314
- [Configuration and the wolfBoot AURIX tool (wbaurixtool.sh)](#configuration-and-the-wolfboot-aurix-tool-wbaurixtoolsh)
1415
- [Building and running the wolfBoot demo](#building-and-running-the-wolfboot-demo)
1516
- [Prerequisites](#prerequisites)
@@ -23,6 +24,9 @@ This example demonstrates using wolfBoot on the Infineon AURIX TC3xx family of m
2324
- [Load and run the wolfBoot demo in TRACE32](#load-and-run-the-wolfboot-demo-in-trace32)
2425
- [wolfHSM Compatibility](#wolfhsm-compatibility)
2526
- [Building wolfBoot with wolfHSM](#building-wolfboot-with-wolfhsm)
27+
- [Building wolfBoot with wolfHSM and cert chain verification](#building-wolfboot-with-wolfhsm-and-cert-chain-verification)
28+
- [Custom Certificate Chain](#custom-certificate-chain)
29+
- [Dummy Certificate Chain](#dummy-certificate-chain)
2630
- [Building: Command Sequence](#building-command-sequence)
2731
- [Troubleshooting](#troubleshooting)
2832
- [WSL "bad interpreter" error](#wsl-bad-interpreter-error)
@@ -95,6 +99,10 @@ Different linker script templates are used to configure the memory layout via `w
9599
- [test-app (standard wolfBoot images)](test-app/Lcf_Gnu_Tricore_Tc.lsl.in)
96100
- [test-app (ELF files)](test-app/Lcf_Gnu_Tricore_elf.lsl.in)
97101

102+
### Cert Chain Verification
103+
104+
wolfBoot on AURIX supports verifying firmware images using certificate chains. For more information on how this wolfBoot feature works, refer to [Signing.md](../../docs/Signing.md), [firmware_update.md](../docs/firmware_update.md), and [wolfBoot-wolfHSM](../../IDE/AURIX/wolfBoot-wolfHSM). Currently this feature can only be used in conjunction with wolfHSM. Instructions for using this feature are detailed below in the [Building wolfBoot with wolfHSM](#building-wolfboot-with-wolfhsm) section.
105+
98106
## Configuration and the wolfBoot AURIX tool (wbaurixtool.sh)
99107

100108
wolfBoot relies extensively on its build system in order to properly set configuration macros, linker addresses, and other target-specific items. Because wolfBoot on AURIX uses the AURIX studio IDE to build, changing things like the signature algorithm would require manually editing IDE settings, linker scripts, etc. which is error prone and tedious. The `wbaurixtool.sh` script provides a single tool that automates the generation of all configurable items required for building wolfBoot and the test application on AURIX given the chosen signature and hashing algorithms, including managing all configuration macros, linker scripts, as well as handling the actual key generation and image signing process. `wbaurixtool.sh` can also generate wolfHSM NVM images containing the generated image signing key when used in conjunction with wolfHSM.
@@ -320,6 +328,27 @@ IDE/AURIX/wolfHSM-infineon-tc3xx/
320328
3. Provide the `--hsm` global option to the `wbaurixtool.sh` script when invoking it so that the wolfHSM projects are used instead of the standard wolfBoot projects
321329
4. If using the default build options in [wolfBoot-tc3xx-wolfHSM](./wolfBoot-tc3xx-wolfHSM/), wolfBoot will expect the public key for image verification to be stored at a specific keyId for the wolfBoot client ID. You can use [whnvmtool](https://github.com/wolfSSL/wolfHSM/tree/main/tools/whnvmtool) to generate a loadable NVM image that contains the required keys automatically via `wbaurixtool.sh` through the `nvm` subcommand. This generates an NVM image containing the generated image signing key based on the [wolfBoot-wolfHSM-keys.nvminit](../../tools/scripts/tc3xx/wolfBoot-wolfHSM-keys.nvminit) configuration file, which can then be loaded to the device via a flash programming tool. Before using the `nvm` subcommand of `wbaurixtool.sh`, first compile `whnvmtool` by running `make` in the `lib/wolfHSM/tools/whnvmtool` directory. See the `whnvmtool` documentation and the documentation included in your wolfHSM AURIX release for more details. Note: if you want to use the standard wolfBoot keystore functionality in conjunction with wolfHSM for testing purposes (doesn't require pre-loading keys on the HSM) you can configure wolfBoot to send the keys to the HSM on-the-fly as ephemeral keys. To do this, ensure `WOLFBOOT_USE_WOLFHSM_PUBKEY_ID` is **NOT** defined, and add the `--localkeys` argument to then `./wbaurixtool.sh keygen` command, which invokes the `keygen` tool without the default `--nolocalkeys` option.
322330

331+
### Building wolfBoot with wolfHSM and cert chain verification
332+
333+
wolfBoot with wolfHSM supports certificate chain verification for firmware images. This feature allows wolfBoot to verify that firmware images are signed with certificates that can be traced back to a trusted root certificate authority through a certificate chain.
334+
335+
The `wbaurixtool.sh` script provides two options for applicable commands that enable automation of configuring the build for certificate chain verification:
336+
337+
- `--certchain <file>`: Use a user-provided certificate chain file
338+
- `--dummy-certchain`: Use a "dummy" certificate chain that is created from the key pair generated by the wolfBoot keytools for development/testing purposes.
339+
340+
Both options require the `--hsm` global option and can be used with the `keygen`, `sign`, `macros`, `lcf`, and `nvm` subcommands.
341+
342+
### Custom Certificate Chain
343+
344+
If you want to use a custom certificate chain for verification, you can provide the `--certchain <certchain file>` option to the `macros`, `lcf`, and `sign` subcommands. This ensures that your certificate chain will be included in the generated firmware image and that wolfBoot will verify the chain on boot, then verify the signature of the firmware image using the public key corresponding to the leaf certificate in the chain. Note that the user is responsible for properly constructing the certificate chain and ensuring that the leaf certificate is bound to the firmware signing key pair, as well as properly provisioning the HSM with the root CA certificate at the expected NVM object ID specified by the HAL.
345+
346+
### Dummy Certificate Chain
347+
348+
If you just want to test out the certificate verifcation functionality, `wbaurixtool.sh` can generate and use a dummy certificate chain by providing the `--dummy-certchain` option to the `keygen`, `sign`, `macros`, `lcf`, and `nvm` subcommands. This will cause the keygen step to generate a dummy root CA at `test-dummy-ca/root-ca.der`, well as a dummy certificate chain at `test-dummy-ca/raw-chain.der` using the specified algorithm. The generated chain consists of a single intermediate as well as a leaf (signing) certificate whose identity is bound to the generated firmware signing key pair. The subsequent commands will then ensure this generated chain is used by wolfBoot. Additionally, the `nvm` subcommand will create an NVM image containing the generated root CA that can be loaded into HSM NVM.
349+
350+
**Note: The `--dummy-certchain` option is intended for development and testing. For production use, generate and use your own certificate chain.**
351+
323352
## Building: Command Sequence
324353

325354
The following pseudo command sequence shows a brief overview of the commands needed to build wolfBoot on AURIX (optionally with wolfHSM). The signature and hashing algorithms used in the example are ECC 256 and SHA 256 and specified explicitly for clarity. Note that these algorithms are the default, so do not need to be explicitly specified. Optional arguments are shown in square brackets (e.g. if targeting wolfHSM, the `--hsm` option must be provided as a global option to `wbaurixtool.sh`).

IDE/AURIX/wolfBoot-tc3xx-wolfHSM/.cproject

Lines changed: 4 additions & 4 deletions
Large diffs are not rendered by default.

IDE/AURIX/wolfBoot-tc3xx-wolfHSM/wolfBoot_macros.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
@ML_DSA_LEVEL@
88
@ML_DSA_IMAGE_SIGNATURE_SIZE@
99
@WOLFBOOT_ELF@
10-
@WOLFBOOT_ELF_FLASH_SCATTER@
10+
@WOLFBOOT_ELF_FLASH_SCATTER@
11+
@WOLFBOOT_CERT_CHAIN_VERIFY@

IDE/AURIX/wolfBoot-tc3xx-wolfHSM/wolfhsm_cfg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@
2626
#define WOLFHSM_CFG_H_
2727

2828
#define WOLFHSM_CFG_DMA
29+
#define WOLFHSM_CFG_CERTIFICATE_MANAGER
2930

3031
#endif /* WOLFHSM_CFG_H_ */

0 commit comments

Comments
 (0)