Skip to content

Commit 1febfd9

Browse files
bigbrettdanielinux
authored andcommitted
unify global HAL names between server/client, update docs
1 parent c106d92 commit 1febfd9

File tree

6 files changed

+177
-116
lines changed

6 files changed

+177
-116
lines changed

docs/HAL.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,6 @@ implementation in new ports must return immediately without performing any actio
145145
if the content of the bootloader partition in the two banks already match.
146146

147147

148+
### wolfHSM HAL extensions
149+
150+
Refer to [wolfHSM.md](wolfHSM.md) for the wolfHSM-specific HAL functions and an overview of wolfHSM compatibility.

docs/wolfHSM.md

Lines changed: 96 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11

2-
# wolfHSM Client Integration with wolfBoot
2+
# wolfHSM Integration with wolfBoot
33

4-
wolfBoot provides tight integration with wolfHSM when used on a select group of supported platforms. When used in this mode, wolfBoot acts as a wolfHSM client, with all cryptographic operations and key storage offloaded to the wolfHSM server as remote procedure calls (RPCs).
4+
wolfBoot provides tight integration with wolfHSM when used on a select group of supported platforms. wolfBoot can operate in two modes with wolfHSM:
5+
6+
1. **wolfHSM Client Mode**: wolfBoot acts as a wolfHSM client, with all cryptographic operations and key storage offloaded to an external wolfHSM server as remote procedure calls (RPCs).
7+
8+
2. **wolfHSM Server Mode**: wolfBoot runs on the wolfHSM server, directly using the wolfHSM API for operations like secure key storage and certificate chain verification.
59

610
For an introduction to wolfHSM, please refer to the [wolfHSM Manual](https://wolfSSL.com/https://www.wolfssl.com/documentation/manuals/wolfhsm/) and [wolfHSM GitHub Repository](https://github.com/wolfssl/wolfHSM.git).
711

@@ -20,9 +24,9 @@ wolfBoot supports using wolfHSM on the following platforms:
2024

2125
Details on configuring wolfBoot to use wolfHSM on each of these platforms can be found in the wolfBoot (and wolfHSM) documentation specific to that target, with the exception of the simulator, which is documented here. The remainder of this document focuses on the generic wolfHSM-related configuration options.
2226

23-
## Algorithm Support
27+
## Client Algorithm Support
2428

25-
wolfBoot supports using wolfHSM for the following algorithms:
29+
wolfBoot supports using wolfHSM to offlad the following algorithms to the HSM server:
2630

2731
- RSA with 2048, 3072, and 4096-bit keys for image signature verification
2832
- ECDSA P-256, P-384, and P-521 for image signature verification
@@ -47,29 +51,36 @@ The certificate verification process with wolfHSM works as follows:
4751
4. A certificate chain is created consisting of the signing identity certificate and an optional number of intermediate certificates, where trust is chained back to the root CA.
4852
5. During the signing process, the image is signed with the signer private key and the certificate chain is embedded in the firmware image header.
4953
6. During boot, wolfBoot extracts the certificate chain from the firmware header
50-
7. wolfBoot uses the wolfHSM server to verify the certificate chain against a pre-provisioned root CA certificate stored on the HSM and caches the public key of the leaf certificate if the chain verifies as trusted
54+
7. wolfBoot uses the wolfHSM server (remotely or directly, depending on configuration) to verify the certificate chain against a pre-provisioned root CA certificate stored on the HSM and caches the public key of the leaf certificate if the chain verifies as trusted
5155
8. If the chain is trusted, wolfBoot uses the cached public key from the leaf certificate to verify the firmware signature on the wolfHSM server
5256

5357
To use certificate verification with wolfHSM:
5458

5559
1. Enable `WOLFBOOT_CERT_CHAIN_VERIFY` in your wolfBoot configuration
5660
2. Ensure the wolfHSM server is configured with certificate manager support (`WOLFHSM_CFG_CERTIFICATE_MANAGER`)
57-
3. Pre-provision the root CA certificate on the wolfHSM server at the NVM ID specified by the HAL `hsmClientNvmIdCertRootCA`
61+
3. Pre-provision the root CA certificate on the wolfHSM server at the NVM ID specified by the HAL `hsmNvmIdCertRootCA`
5862
4. Sign firmware images with the `--cert-chain` option, providing a DER-encoded certificate chain
5963

60-
To build the simulator using wolfHSM for certificate verification, use [config/examples/sim-wolfHSM-certchain.config](config/examples/sim-wolfHSM-certchain.config).
64+
To build the simulator using wolfHSM for certificate verification:
65+
66+
- **Client Mode**: Use [config/examples/sim-wolfHSM-client-certchain.config](config/examples/sim-wolfHSM-client-certchain.config)
67+
- **Server Mode**: Use [config/examples/sim-wolfHSM-server-certchain.config](config/examples/sim-wolfHSM-server-certchain.config)
6168

6269
## Configuration Options
6370

64-
This section describes the configuration options available for wolfHSM client integration. Note that these options should be configured automatically by the build system for each supported platform when wolfHSM support is enabled. Consult the platform-specific documentation for details on enabling wolfHSM support.
71+
This section describes the configuration options available for wolfHSM integration. Note that these options should be configured automatically by the build system for each supported platform when wolfHSM support is enabled. Consult the platform-specific documentation for details on enabling wolfHSM support.
6572

6673
### `WOLFBOOT_ENABLE_WOLFHSM_CLIENT`
6774

68-
This option enables wolfHSM client support in wolfBoot. Without defining this option, support for wolfHSM is not compiled in and the remainder of the options have no effect.
75+
This option enables wolfHSM client support in wolfBoot. Without defining this option, support for wolfHSM client mode is not compiled in.
76+
77+
### `WOLFBOOT_ENABLE_WOLFHSM_SERVER`
78+
79+
This option enables wolfHSM server support in wolfBoot. When defined, wolfBoot includes an embedded wolfHSM server that provides HSM functionality locally within the bootloader. This is mutually exclusive with `WOLFBOOT_ENABLE_WOLFHSM_CLIENT`.
6980

7081
### `WOLFBOOT_USE_WOLFHSM_PUBKEY_ID`
7182

72-
This option enables use of the reserved wolfHSM public key ID for firmware authentication, and is typically the desired behavior for using wolfHSM. When this option is defined, wolfBoot will use the reserved wolfHSM keyId defined by the HAL (`hsmClientKeyIdPubKey`). This option is meant to be used in conjunction with the `--nolocalkeys` keygen option, as the key material in the keystore will not be used.
83+
This option enables use of the reserved wolfHSM public key ID for firmware authentication, and is typically the desired behavior for using wolfHSM. When this option is defined, wolfBoot will use the reserved wolfHSM keyId defined by the HAL (`hsmKeyIdPubKey`). This option is meant to be used in conjunction with the `--nolocalkeys` keygen option, as the key material in the keystore will not be used.
7384

7485
If this option is not defined, cryptographic operations are still performed on the wolfHSM server, but wolfBoot assumes the key material is present in the keystore and NOT stored on the HSM. This means that wolfBoot will first load keys from the keystore, send the key material to the wolfHSM server at the time of use (cached as ephemeral keys), and finally evict the key from the HSM after usage. This behavior is typically only useful for debugging or testing scenarios, where the keys may not be pre-loaded onto the HSM. The keystore for use in this mode should not be generated with the `--nolocalkeys` option.
7586

@@ -79,52 +90,91 @@ In addition to the standard wolfBoot HAL functions, wolfHSM-enabled platforms mu
7990

8091
### HAL Global Variables
8192

82-
- `hsmClientCtx`: A global context for the wolfHSM client. This is initialized by the HAL and passed to wolfBoot, but should not be modified by wolfBoot.
83-
- `hsmClientDevIdHash`: The HSM device ID for hash operations. This is used to identify the HSM device to wolfBoot.
84-
- `hsmClientDevIdPubKey`: The HSM device ID for public key operations. This is used to identify the HSM device to wolfBoot.
85-
- `hsmClientKeyIdPubKey`: The HSM key ID for public key operations. This is used to identify the key to use for public key operations.
93+
- `hsmClientCtx`: A global context for the wolfHSM client. This is initialized by the HAL and passed to wolfBoot, but should not be modified by wolfBoot. Only used when building with `WOLFHSM_ENABLE_WOLFHSM_CLIENT`.
94+
- `hsmServerCtx`: A global context for the wolfHSM server. This is initialized by the HAL and used by wolfBoot for all HSM operations. Only used when building with `WOLFHSM_ENABLE_WOLFHSM_SERVER`
8695

87-
### HAL Functions
96+
- `hsmDevIdHash`: The HSM device ID for hash operations. This is used to identify the HSM device to wolfBoot.
97+
- `hsmDevIdPubKey`: The HSM device ID for public key operations. This is used to identify the HSM device to wolfBoot.
98+
- `hsmKeyIdPubKey`: The HSM key ID for public key operations. This is used to identify the key to use for public key operations.
99+
100+
### Client HAL Functions
88101

89102
- `hal_hsm_init_connect()`: Initializes the connection to the wolfHSM server. This is called by wolfBoot during initialization. This should initialize the HSM client context (`hsmClientCtx`) with a valid configuration and initialize the wolfHSM client API.
90103
- `hal_hsm_disconnect()`: Disconnects from the wolfHSM server. This is called by wolfBoot during shutdown. This should clean up the HSM client context (`hsmClientCtx`) and invoke the wolfHSM client API's cleanup function, freeing any additional allocated resources.
91104

105+
### Server HAL Functions
106+
107+
- `hal_hsm_server_init()`: Initializes the embedded wolfHSM server. This is called by wolfBoot during initialization. This should initialize the HSM server context (`hsmServerCtx`) with a valid configuration, initialize the NVM subsystem, and start the wolfHSM server.
108+
- `hal_hsm_server_cleanup()`: Cleans up the embedded wolfHSM server. This is called by wolfBoot during shutdown. This should clean up the HSM server context and free any allocated resources.
109+
92110
## wolfBoot Simulator and wolfHSM
93111

94-
The wolfBoot simulator supports wolfHSM with the POSIX TCP transport. It expects to communicate with the [wolfHSM example POSIX TCP server](https://github.com/wolfSSL/wolfHSM-examples/tree/main/posix/tcp/wh_server_tcp) at `127.0.0.1:1234`. See the [wolfHSM-examples README](https://github.com/wolfSSL/wolfHSM-examples/blob/main/README.md) for more information on the example POSIX TCP server.
112+
The wolfBoot simulator supports using wolfHSM in both client and server modes:
113+
114+
### wolfHSM Client Mode
115+
116+
The simulator supports wolfHSM client mode with the POSIX TCP transport. It expects to communicate with the [wolfHSM example POSIX TCP server](https://github.com/wolfSSL/wolfHSM-examples/tree/main/posix/tcp/wh_server_tcp) at `127.0.0.1:1234`. See the [wolfHSM-examples README](https://github.com/wolfSSL/wolfHSM-examples/blob/main/README.md) for more information on the example POSIX TCP server.
117+
118+
### wolfHSM Server Mode
119+
120+
The simulator also supports an embedded wolfHSM server mode where wolfBoot includes the complete wolfHSM server functionality. In this mode, no external wolfHSM server is required, and all HSM operations are performed locally within wolfBoot using the file-based NVM simulator for storage.
95121

96122
### Building the simulator with wolfHSM support
97123

98-
The wolfBoot simulator supports using wolfHSM with all algorithms mentioned in [Algorithm Support](#algorithm-support). To build the simulator configured to use wolfHSM,, ensure you build with the `WOLFHSM_CLIENT=1` makefile option. This will automatically define `WOLFBOOT_USE_WOLFHSM_PUBKEY_ID`, and requires the public key corresponding to the private key that signed the image to be pre-loaded into the HSM at the keyId specified by `hsmClientKeyIdPubKey` in the simulator HAL (see the next section for details on loading keys into the HSM example server).
124+
The wolfBoot simulator supports using wolfHSM with all algorithms mentioned in [Algorithm Support](#algorithm-support).
125+
126+
#### wolfHSM Client Mode Build
127+
128+
To build the simulator configured to use wolfHSM client mode, ensure you build with the `WOLFHSM_CLIENT=1` makefile option. This will automatically define `WOLFBOOT_USE_WOLFHSM_PUBKEY_ID`, and requires the public key corresponding to the private key that signed the image to be pre-loaded into the HSM at the keyId specified by `hsmKeyIdPubKey` in the simulator HAL.
99129

100130
```sh
101-
# Grab the HSM simulator configuration
102-
cp config/examples/sim-wolfHSM.config .config
131+
# Grab the HSM client simulator configuration
132+
cp config/examples/sim-wolfHSM-client.config .config
103133

104-
# Build wolfBoot with the simulator HAL configured to use wolfHSM, automatically generating keys
134+
# Build wolfBoot with the simulator HAL configured to use wolfHSM client, automatically generating keys
105135
make
106136

107137
# Build and sign the test applications used in the simulated update
108138
make test-sim-internal-flash-with-update
109139

110140
# The generated wolfBoot public key can be found at `wolfboot_signing_private_key_pub.der`, and
111-
# should be loaded into the HSM at the keyId specified by `hsmClientKeyIdPubKey` as described
141+
# should be loaded into the HSM at the keyId specified by `hsmKeyIdPubKey` as described
112142
# in the next section
113143
```
114144

115-
### Running the simulator against a wolfHSM server
145+
#### wolfHSM Server Mode Build
146+
147+
To build the simulator configured to use embedded wolfHSM server mode, use the `WOLFHSM_SERVER=1` makefile option. In this mode, wolfBoot includes the complete wolfHSM server and no external HSM server is required. Currently the wolfHSM server only supporst the certificate chain verification mode of authentication.
148+
149+
```sh
150+
# Grab the HSM server simulator configuration (with certificate chain verification)
151+
cp config/examples/sim-wolfHSM-server-certchain.config .config
152+
153+
# Build wolfBoot with the embedded wolfHSM server.
154+
make
155+
156+
# Build and sign the test applications used in the simulated update. This generates a dummy CA and certificate chain for your public key.
157+
make test-sim-internal-flash-with-update
158+
159+
```
160+
161+
### Running the simulator with wolfHSM
162+
163+
#### wolfHSM Client Mode
116164

117-
First, build the wolfHSM POSIX TCP server, following the instructions in the [wolfHSM-examples README](https://github.com/wolfSSL/wolfHSM-examples/blob/main/README.md).
165+
When using wolfHSM client mode, you need to run an external wolfHSM server.
166+
167+
First, build the wolfHSM POSIX TCP server, following the instructions in the [wolfHSM example README](github.com/wolfSSL/wolfHSM/blob/main/examples/README.md)
118168

119169
Next, in a new terminal window, run the wolfHSM POSIX TCP server, loading the public key generated by the wolfBoot build process (`wolfboot_signing_private_key_pub.der`)
120170

121171
```sh
122172
# Build the example server
123-
cd wolfHSM-examples/posix/tcp/wh_server_tcp
124-
make WOLFHSM_DIR=/path/to/wolfHSM/install
173+
cd lib/wolfHSM/examples/posix/tcp/wh_server_tcp
174+
make WOLFSSL_DIR=../../../../../wolfssl
125175

126-
# Run the server, loading the wolfBoot public key and using keyId 0xFF (or modify keyId to match value of `hsmClientKeyIdPubKey` in `hal/sim.c`)
127-
./Build/wh_server_tcp.elf --key /path/to/wolfboot_signing_private_key_pub.der --id 0xFF
176+
# Run the server, loading the wolfBoot public key and using the client ID and keyId matching the values declared in `hal/sim.c`)
177+
./Build/wh_server_tcp.elf --client 12 --id 255 --key ../../../../../../wolfboot_signing_private_key_pub.der &
128178

129179
# The server will now be waiting for connections
130180
```
@@ -146,12 +196,9 @@ hal_flash_erase addr 0x7f66658f7000 len 4091
146196
1
147197
```
148198

149-
Restart the wolfHSM server with the same arguments, then rerun the wolfBoot simulator to boot the new firmware and verify the update.
199+
Rerun the wolfBoot simulator to boot the new firmware and verify the update.
150200

151201
```sh
152-
# In the wolfHSM server terminal window
153-
./Build/wh_server_tcp.elf --key /path/to/wolfboot_signing_private_key_pub.der --id 0xFF
154-
155202
# In the wolfBoot terminal window, run the following to update the image and confirm the update
156203
./wolfboot.elf success get_version
157204

@@ -173,3 +220,21 @@ Simulator assigned ./internal_flash.dd to base 0x7fe902d2e000
173220
2
174221
```
175222

223+
#### wolfHSM Server Mode
224+
225+
When using wolfHSM server mode, no external server is required. wolfBoot includes the embedded wolfHSM server functionality. The only requirement is a wolfHSM simulated NVM image must be created that the server can use with the root CA for certificate verification stored at the expected NVM ID.
226+
227+
```sh
228+
# Create a simulated NVM image for the POSIX flash file simulator containing the dummy root CA for cert chain verification.
229+
# You must build whnvmtool first if you haven't already, and ensure the file name matches the simulated NVM image file
230+
# name in hal/sim.c
231+
./lib/wolfHSM/tools/whnvmtool/whnvmtool --image=wolfBoot_wolfHSM_NVM.bin --size 16348 --invert-erased-byte tools/scripts/wolfBoot-wolfHSM-sim-dummy-certchain.nvminit
232+
233+
# Run the wolfBoot simulator with embedded wolfHSM server to stage an update
234+
./wolfboot.elf update_trigger get_version
235+
236+
# Run the simulator again to boot the new firmware and verify the update
237+
./wolfboot.elf success get_version
238+
```
239+
240+
The embedded wolfHSM server will automatically handle all cryptographic operations and key management using the file-based NVM storage(`wolfBoot_wolfHSM_NVM.bin`) that was generated above.

hal/aurix_tc3xx.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -652,21 +652,21 @@ static whTransportClientCb tmcCb[1] = {WH_TRANSPORT_MEM_CLIENT_CB};
652652

653653
/* Globally exported HAL symbols */
654654
whClientContext hsmClientCtx = {0};
655-
const int hsmClientDevIdHash = WH_DEV_ID_DMA;
655+
const int hsmDevIdHash = WH_DEV_ID_DMA;
656656
#ifdef WOLFBOOT_SIGN_ML_DSA
657657
/* Use DMA for massive ML DSA keys/signatures, too big for shm transport */
658-
const int hsmClientDevIdPubKey = WH_DEV_ID_DMA;
658+
const int hsmDevIdPubKey = WH_DEV_ID_DMA;
659659
#else
660-
const int hsmClientDevIdPubKey = WH_DEV_ID;
660+
const int hsmDevIdPubKey = WH_DEV_ID;
661661
#endif
662-
const int hsmClientKeyIdPubKey = 0xFF;
662+
const int hsmKeyIdPubKey = 0xFF;
663663
#ifdef EXT_ENCRYPT
664664
#error "AURIX TC3xx does not support firmware encryption with wolfHSM (yet)"
665-
const int hsmClientDevIdCrypt = WH_DEV_ID;
666-
const int hsmClientKeyIdCrypt = 0xFF;
665+
const int hsmDevIdCrypt = WH_DEV_ID;
666+
const int hsmKeyIdCrypt = 0xFF;
667667
#endif
668668
#ifdef WOLFBOOT_CERT_CHAIN_VERIFY
669-
const whNvmId hsmClientNvmIdCertRootCA = 1;
669+
const whNvmId hsmNvmIdCertRootCA = 1;
670670
#endif
671671

672672

0 commit comments

Comments
 (0)