Skip to content

Global SHE keys#478

Draft
bigbrett wants to merge 1 commit into
wolfSSL:mainfrom
bigbrett:she-global
Draft

Global SHE keys#478
bigbrett wants to merge 1 commit into
wolfSSL:mainfrom
bigbrett:she-global

Conversation

@bigbrett

Copy link
Copy Markdown
Contributor

Adds support for global SHE keys

Other fixes:

  • change whnvmtool to fail-fast when an image generation error occurs
  • Enhance whnvmtool test coverage
  • Small code hygene fixes

Copilot AI review requested due to automatic review settings July 22, 2026 16:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a build-time option to place all AUTOSAR SHE key slots in the global-keys namespace so all clients share a single SHE device view, and updates keystore/keywrap behavior plus tests and documentation accordingly. It also hardens whnvmtool by adding SHE entry support, stricter bounds checking, fail-fast behavior, and expanded negative test coverage.

Changes:

  • Add WOLFHSM_CFG_SHE_GLOBAL_KEYS and route SHE slot key IDs through the global namespace when enabled.
  • Extend whnvmtool config format to support she ... entries, add fail-fast behavior, and add negative tests.
  • Add/extend multiclient + interop tests and update docs/CI workflows to cover the new configuration.

Reviewed changes

Copilot reviewed 28 out of 29 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
wolfhsm/wh_she_common.h Introduces WH_SHE_MAKE_KEYID() / global-user selection for SHE slot key IDs.
wolfhsm/wh_settings.h Documents and enforces compile-time dependencies for WOLFHSM_CFG_SHE_GLOBAL_KEYS.
wolfhsm/wh_client_she.h Updates API docstring to reflect optional global SHE slot namespace.
tools/whnvmtool/whnvmtool.c Adds she entries, stronger parse-time bounds, and fail-fast entry processing.
tools/whnvmtool/test/test_invalid_input.sh Adds negative test script ensuring invalid configs/files fail with nonzero exit.
tools/whnvmtool/test/nvminit/test.nvminit Updates test init config with a global key and example SHE entries.
tools/whnvmtool/test/data/she2.bin Adds binary test fixture data for SHE provisioning tests.
tools/whnvmtool/README.md Documents new bounds, global namespace semantics, and she entry format.
tools/whnvmtool/Makefile Runs new negative tests as part of the test target.
tools/whnvmtool/.gitignore Ensures test binary fixtures under test/data/*.bin are not ignored.
test/wh_test_she.c Updates SHE key ID construction and adds global/per-client blob interop assertions.
test/wh_test_she_no_nvm.c Updates SHE key ID construction to use WH_SHE_MAKE_KEYID().
test/wh_test_multiclient.c Adds a global-SHE multiclient test suite and wires in server SHE contexts.
test/Makefile Adds SHE_GLOBAL build option for tests.
test-refactor/server/wh_test_she_server.c Updates SHE key ID construction to use WH_SHE_MAKE_KEYID().
test-refactor/server/wh_test_nvm_optional.c Updates SHE key ID construction to use WH_SHE_MAKE_KEYID().
test-refactor/posix/Makefile Adds SHE_GLOBAL build option for refactor posix tests.
test-refactor/misc/wh_test_she_no_nvm.c Updates SHE key ID construction to use WH_SHE_MAKE_KEYID().
test-refactor/misc/wh_test_she_keywrap.c Adds global/per-client blob interop assertions and updates key ID construction.
test-refactor/misc/wh_test_multiclient.c Adds a global-SHE multiclient test suite and wires in server SHE contexts.
test-refactor/client-server/wh_test_she.c Updates SHE key ID construction to use WH_SHE_MAKE_KEYID().
src/wh_server_she.c Routes SHE slot lookups through WH_SHE_MAKE_KEYID() so slot IDs resolve correctly under global mode.
src/wh_server_keystore.c Normalizes wrap-export and unwrap-and-cache behavior for global SHE slot IDs (and rejects global-id blobs in per-client mode).
src/wh_client_she.c Updates provisioning to use WH_SHE_MAKE_KEYID() for correct slot ID resolution.
docs/src/9-Configuration.md Documents WOLFHSM_CFG_SHE_GLOBAL_KEYS in the configuration reference.
docs/src/5-Features.md Adds “Global SHE Keys” feature documentation and updates SHE/global-keys discussion.
.github/workflows/build-and-test.yml Adds CI jobs to build/test with SHE_GLOBAL=1.
.github/workflows/build-and-test-refactor.yml Adds CI jobs to build/test refactor suite with SHE_GLOBAL=1.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tools/whnvmtool/whnvmtool.c
Comment thread tools/whnvmtool/README.md Outdated

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #478

⚠️ An internal error occurred during the automated review. This error has been logged. Please contact the Fenrir team if you need assistance.

Error: UnicodeDecodeError

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #478

⚠️ An internal error occurred during the automated review. This error has been logged. Please contact the Fenrir team if you need assistance.

Error: UnicodeDecodeError

@bigbrett
bigbrett force-pushed the she-global branch 2 times, most recently from 8afec1b to 995fc9b Compare July 22, 2026 23:20

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #478

Scan targets checked: wolfhsm-core-bugs, wolfhsm-crypto-bugs, wolfhsm-src

No new issues found in the changed files. ✅

- change whnvmtool to fail-fast when an image generation error occurs
- Enhance whnvmtool test coverage
- Small code hygene fixes
Comment thread wolfhsm/wh_she_common.h
* otherwise each client gets its own slots. The global form still evaluates
* _clientId (times zero) so call sites don't trip unused warnings. */
#ifdef WOLFHSM_CFG_SHE_GLOBAL_KEYS
#define WH_SHE_KEY_USER(_clientId) ((_clientId) * 0 + WH_KEYUSER_GLOBAL)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why can't it just be WH_KEYUSER_GLOBAL?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we want to track these?

Comment thread src/wh_server_keystore.c
* the same way the SHE commands do, whether or not the client passed the
* global flag. */
if (targetKeyType == WH_KEYTYPE_SHE) {
targetKeyId = WH_MAKE_KEYID(WH_KEYTYPE_SHE, WH_KEYUSER_GLOBAL,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why would we not include this in the above swtich statement?

Comment thread src/wh_server_keystore.c
Comment on lines +2270 to +2273
/* Move the blob's id to the global namespace where the SHE commands look;
* blobs minted by per-client builds would otherwise cache under an id no
* SHE command uses and no client request can evict. Do this before the
* in-cache check and counter guard below so both see the final id. */

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is all jargon and unintelligible. Simplify into something human readible.

Comment thread src/wh_server_keystore.c
Comment on lines +2279 to +2281
/* SHE slots are per-client on this build, so a blob minted by a global-SHE
* build would cache under an id no SHE command reads and no client request
* can evict, pinning the cache slot until reboot. Reject it instead. */

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jargon, unintelligible. Simplify and make human readible

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 29 out of 30 changed files in this pull request and generated 3 comments.

Comment on lines +1877 to +1881
for (i = 0; i < (int)sizeof(evictSlots); i++) {
ret = wh_Server_KeystoreEvictKey(
server1,
WH_SHE_MAKE_KEYID(client1->comm->client_id, evictSlots[i]));
if (ret != 0 && ret != WH_ERROR_NOTFOUND) {
Comment on lines +1806 to +1810
for (i = 0; i < (int)sizeof(evictSlots); i++) {
ret = wh_Server_KeystoreEvictKey(
server1,
WH_SHE_MAKE_KEYID(client1->comm->client_id, evictSlots[i]));
if (ret != 0 && ret != WH_ERROR_NOTFOUND) {
Comment on lines 199 to 205
@@ -161,55 +204,93 @@ static void processEntry(Entry* entry, int isKey, whNvmContext* nvmContext)
fprintf(stderr, "Error: Failed to read entire file %s\n",
entry->filePath);

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #478

Scan targets checked: wolfhsm-core-bugs, wolfhsm-crypto-bugs, wolfhsm-src

No new issues found in the changed files. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants