Skip to content

Report token store failures and keep stored state consistent - #232

Merged
Frauschi merged 73 commits into
wolfSSL:masterfrom
aidangarske:fenrir-fixes-10378-10379
Oct 15, 2026
Merged

Frauschi merged 73 commits into
wolfSSL:masterfrom
aidangarske:fenrir-fixes-10378-10379

Conversation

@aidangarske

@aidangarske aidangarske commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

F-10378 - 325fa7a - wolfPKCS11_Store_Name now declares its string unconditionally and guards the HOME and APPDIR lookup with WOLFPKCS11_NO_ENV, and a no_env CI job is added.

F-10379 - 5d0def0 - wp11_Token_Store no longer changes the token object count on a failed store or turns a TPM NV_SPACE error into success, and C_DeriveKey frees the derived object when AddObject fails.

F-10386 - b0ed4a4 - Store commit failures are now reported: a new wolfPKCS11_Store_CloseCommit returns rename and close errors and discards a failed write, and the user PIN, SO PIN and token reset paths restore their previous state when the store fails.

F-10384 - 617f7b4 - For the file backend, wp11_Token_Store no longer replaces the token record with an empty temporary file before the objects are written.

F-11505 - c79ea02 - WP11_Library_Final now returns the first slot store error after finishing cleanup, and C_Finalize maps it to CKR_FUNCTION_FAILED.

F-8645 - 5bb3614 - WP11_Library_Init now tracks the global lock, wolfCrypt, the global RNG and initialized slots and unwinds them when initialization fails.

F-10385 - 844537c - wp11_Object_New now frees only a non-NULL object, and WP11_Object_Free(NULL) does nothing.

F-13243 - fe5d444 - Destroying a token object now reports the first unstore error, ignoring NOT_AVAILABLE_E, and the file backend treats a missing file as success on remove.

F-2791 - ca3304f - wp11_Token_Final now clears the token with wc_ForceZero instead of XMEMSET.

F-11502 - 97b89ab - wp11_Token_Load now reads nextObjId only when the token flags read succeeded, and falls back only on BUFFER_E or a successful read of 0, so other errors fail the load.

F-10380 - 2711d6d - The TPM store now sizes ML-DSA, ML-KEM, HSS and XMSS records, and the handle type mask is widened from 0x0F to 0x1F so these types get distinct handles. Existing handles below 0x10 are unchanged.

@aidangarske aidangarske self-assigned this Oct 8, 2026
Copilot AI balanced review requested due to automatic review settings October 8, 2026 22:07

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.

🟡 Changes recommended

A failed user-PIN change can leave committed object records encrypted under a discarded key, making them unreadable after restart.

3 open findings
What changed in this PR

Hardens token persistence, lifecycle cleanup, stored-object validation, and PKCS#11 operation handling.

Changes:

  • Propagates storage failures and improves rollback/cleanup behavior.
  • Strengthens stored-object decoding, policy integrity, and session lifecycle handling.
  • Adds targeted tests and a no-environment CI configuration.
File Description
.github/​workflows/​unit-test.yml Adds no-environment CI coverage.
src/​crypto.c Improves operation cleanup and object failure handling.
src/​internal.c Implements persistence, rollback, loading, and lifecycle changes.
src/​slot.c Corrects token information and mechanism metadata.
src/​wolfpkcs11.c Propagates finalization errors and pads information fields.
tests/​include.am Registers the new test programs.
tests/​info_mech_table_test.c Tests information and mechanism contracts.
tests/​login_pin_state_test.c Tests PIN, login, and concurrency invariants.
tests/​object_policy_integrity_test.c Tests persisted key-policy integrity.
tests/​object_store_decode_test.c Tests malformed stored-record handling.
tests/​pkcs11mtt.c Updates PKCS#11 v3 cancellation expectations.
tests/​pkcs11test.c Updates clock and cancellation tests.
tests/​session_op_lifecycle_test.c Tests operation cleanup and cancellation.
tests/​token_store_test.c Tests storage failures and recovery.
wolfpkcs11/​internal.h Adds internal limits and lifecycle APIs.
wolfpkcs11/​pkcs11.h Defines the cancellation failure result code.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/internal.c
Comment thread tests/object_policy_integrity_test.c Outdated
Comment thread tests/object_store_decode_test.c Outdated
@aidangarske
aidangarske force-pushed the fenrir-fixes-10378-10379 branch 2 times, most recently from 2711d6d to ea58fe1 Compare October 10, 2026 03:20

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A few comments, inline.

Comment thread src/internal.c
Comment thread tests/token_store_test.c
Comment thread src/wolfpkcs11.c
@aidangarske
aidangarske force-pushed the fenrir-fixes-10378-10379 branch from ea58fe1 to eafe9ba Compare October 13, 2026 22:19
@aidangarske
aidangarske requested a review from Frauschi October 13, 2026 22:24
@aidangarske
aidangarske force-pushed the fenrir-fixes-10378-10379 branch 3 times, most recently from 03f5514 to 036219e Compare October 13, 2026 23:43
Frauschi
Frauschi previously approved these changes Oct 14, 2026

@Frauschi Frauschi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, all addressed. The TPM half of my first comment (the positive RC from wolfPKCS11_Store_Remove) landed in #244 rather than here, which is fine as long as they merge in order. nss-test is only red here because of the #231 issue.

Frauschi
Frauschi previously approved these changes Oct 15, 2026
@aidangarske
aidangarske dismissed Frauschi’s stale review October 15, 2026 20:36

The merge-base changed after approval.

@aidangarske
aidangarske force-pushed the fenrir-fixes-10378-10379 branch from 456266a to cc1d926 Compare October 15, 2026 21:00
@Frauschi
Frauschi merged commit cc1d926 into wolfSSL:master Oct 15, 2026
90 checks passed
@aidangarske
aidangarske deleted the fenrir-fixes-10378-10379 branch October 15, 2026 21:41
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.

4 participants