Skip to content

Add mock-based coverage for session reuse, reconnect behavior,#470

Merged
pugsley76 merged 3 commits into
pugsley76:mainfrom
shadrach68:HSMSigning
Jul 1, 2026
Merged

Add mock-based coverage for session reuse, reconnect behavior,#470
pugsley76 merged 3 commits into
pugsley76:mainfrom
shadrach68:HSMSigning

Conversation

@shadrach68

Copy link
Copy Markdown
Contributor

Summary
This PR improves PKCS#11/HSM audit signing by making session handling more robust and predictable. The signer now reuses initialized PKCS#11 sessions and cached key lookups across signing operations, retries once when a cached session becomes stale, and returns clearer validation and runtime error messages for common failure cases.

Changes

  • Persist PKCS#11 module/session/key state for the lifetime of the signer
  • Retry once after stale session errors such as invalid or closed handles
  • Validate invalid PKCS#11 inputs earlier, including slot, algorithm, key ID, and public key PEM
  • Improve diagnostics for module load, token selection, login, key lookup, and signing failures
  • Add signer cleanup support and command-side cleanup handling
  • Expand PKCS#11 mocks and tests to cover session reuse, reconnect behavior, and new validation paths
  • Update README guidance for persistent PKCS#11 session behavior and public key configuration

Validation

  • npm exec -- jest --runInBand tests/pkcs11Signer.test.ts tests/pkcs11Signer.signing.test.ts src/commands/__tests__/audit.sign.spec.ts

All 27 focused tests passed.

and cleanup, and document the updated signer lifecycle
@drips-wave

drips-wave Bot commented Jun 30, 2026

Copy link
Copy Markdown

@shadrach68 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@pugsley76 pugsley76 merged commit 1bceb63 into pugsley76:main Jul 1, 2026
1 check failed
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.

Improve session persistence for HSM signing and PKCS11

2 participants