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: docs/wolfHSM.md
+96-31Lines changed: 96 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,11 @@
1
1
2
-
# wolfHSM Client Integration with wolfBoot
2
+
# wolfHSM Integration with wolfBoot
3
3
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.
5
9
6
10
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).
7
11
@@ -20,9 +24,9 @@ wolfBoot supports using wolfHSM on the following platforms:
20
24
21
25
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.
22
26
23
-
## Algorithm Support
27
+
## Client Algorithm Support
24
28
25
-
wolfBoot supports using wolfHSM for the following algorithms:
29
+
wolfBoot supports using wolfHSM to offlad the following algorithms to the HSM server:
26
30
27
31
- RSA with 2048, 3072, and 4096-bit keys for image signature verification
28
32
- 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:
47
51
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.
48
52
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.
49
53
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
51
55
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
52
56
53
57
To use certificate verification with wolfHSM:
54
58
55
59
1. Enable `WOLFBOOT_CERT_CHAIN_VERIFY` in your wolfBoot configuration
56
60
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`
58
62
4. Sign firmware images with the `--cert-chain` option, providing a DER-encoded certificate chain
59
63
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)
61
68
62
69
## Configuration Options
63
70
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.
65
72
66
73
### `WOLFBOOT_ENABLE_WOLFHSM_CLIENT`
67
74
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`.
69
80
70
81
### `WOLFBOOT_USE_WOLFHSM_PUBKEY_ID`
71
82
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.
73
84
74
85
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.
75
86
@@ -79,52 +90,91 @@ In addition to the standard wolfBoot HAL functions, wolfHSM-enabled platforms mu
79
90
80
91
### HAL Global Variables
81
92
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`
86
95
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
88
101
89
102
-`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.
90
103
-`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.
91
104
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
+
92
110
## wolfBoot Simulator and wolfHSM
93
111
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.
95
121
96
122
### Building the simulator with wolfHSM support
97
123
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.
# 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
105
135
make
106
136
107
137
# Build and sign the test applications used in the simulated update
108
138
make test-sim-internal-flash-with-update
109
139
110
140
# 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
112
142
# in the next section
113
143
```
114
144
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)
# 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
116
164
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)
118
168
119
169
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`)
120
170
121
171
```sh
122
172
# Build the example server
123
-
cd wolfHSM-examples/posix/tcp/wh_server_tcp
124
-
make WOLFHSM_DIR=/path/to/wolfHSM/install
173
+
cdlib/wolfHSM/examples/posix/tcp/wh_server_tcp
174
+
make WOLFSSL_DIR=../../../../../wolfssl
125
175
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`)
# In the wolfBoot terminal window, run the following to update the image and confirm the update
156
203
./wolfboot.elf success get_version
157
204
@@ -173,3 +220,21 @@ Simulator assigned ./internal_flash.dd to base 0x7fe902d2e000
173
220
2
174
221
```
175
222
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
# 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.
0 commit comments