Skip to content

Bind stored object policy to the encrypted key data - #229

Merged
Frauschi merged 28 commits into
wolfSSL:masterfrom
aidangarske:fenrir-fixes-10400
Oct 15, 2026
Merged

Frauschi merged 28 commits into
wolfSSL:masterfrom
aidangarske:fenrir-fixes-10400

Conversation

@aidangarske

@aidangarske aidangarske commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

F-10400 - 957fa22 - Key encryption and decryption now take additional authenticated data built from the object policy (version, class, key type, keygen mechanism, local flag and operation flags). Records stored in the older format still load and are re-encrypted with the policy data on the next store or logout.

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

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

Object lifetime and persistence paths currently permit use-after-free, unbounded secret retention, and inconsistent policy/ciphertext records.

6 open findings
What changed in this PR

Binds encrypted token keys to their stored policy and strengthens storage decoding, login, logout, and PIN-state handling.

Changes:

  • Adds policy AAD to stored-key encryption with legacy-format migration.
  • Hardens decoding, object cleanup, locking, and PIN lockout behavior.
  • Adds storage integrity and concurrency regression tests.
File Description
wolfpkcs11/​internal.h Declares new lockout and debug helpers.
src/​internal.c Implements policy binding, decoding safeguards, and lifecycle changes.
src/​crypto.c Maps rejected policy updates to PKCS#11 errors.
src/​slot.c Applies lockout accounting to PIN changes.
tests/​login_pin_state_test.c Tests login, logout, PIN, and concurrency invariants.
tests/​object_store_decode_test.c Tests malformed stored-record handling.
tests/​object_policy_integrity_test.c Tests authenticated policy and legacy migration.
tests/​include.am Registers the new test programs.

🧠 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 Resolved
Comment thread src/internal.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/internal.c Resolved
Comment thread tests/object_policy_integrity_test.c Resolved
Comment thread tests/object_store_decode_test.c Resolved
LinuxJedi
LinuxJedi previously approved these changes Oct 9, 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.

One blocker: the store-failure rollback in WP11_Slot_SetUserPin re-encrypts objects that were never decoded and destroys their stored key data. There's also a deadlock in the store batch locking, plus some locking and durability issues, inline.

Comment thread src/internal.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/internal.c Resolved
Comment thread src/internal.c Resolved
Comment thread tests/object_policy_integrity_test.c Resolved
Comment thread src/internal.c Resolved

@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, the blocker is fixed: undecoded records are left alone in both the forward pass and the rollback, and the new public-session and SO tests fail on the previous head. The rest of the comments are addressed too. One locking gap left inline.

Not from this PR, since master does the same, but worth a follow-up issue: a successful C_SetPIN from an RW public session still loses every stored key that wasn't decoded yet. Those records keep their old-key ciphertext and get stored next to the new seed, so after logging in with the new PIN they can't be found. C_SetPIN has the old PIN, so it could decode them first.

Comment thread src/internal.c Resolved

@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.

@aidangarske please fix merge conflicts after #226.

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.

@Frauschi
Frauschi merged commit c988a2f into wolfSSL:master Oct 15, 2026
88 checks passed
@aidangarske
aidangarske deleted the fenrir-fixes-10400 branch October 15, 2026 21:42
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