feat(vault): decompose Vault into HSM capability interfaces#12
Closed
canaan5 wants to merge 3 commits into
Closed
Conversation
Make the key-management façade HSM-adapter-ready by splitting it into small capability interfaces, so an adapter implements exactly what its device supports. - Add PINEncryptor, PINTranslator, and Macer. Vault is now their composition, so it keeps the same method set — source-compatible; SoftVault and SealedVault still satisfy Vault unchanged. - PINTranslator documents the PCI PIN Security contract: a conforming hardware implementation must re-encipher the PIN block atomically inside the device so the clear PIN never leaves it; an adapter that cannot (e.g. stock PKCS#11) must not implement the interface, since callers rely on its presence to mean the operation is PIN-secure. - A general-purpose PKCS#11 HSM provides Macer (and possibly PINEncryptor); a payment HSM (Thales payShield, Futurex) additionally provides PINTranslator. Callers type-assert for the narrowest capability they need. Adds capability-detection tests. gofmt/vet clean; ./... builds, vault/flow/gateway pass under -race.
…aces # Conflicts: # CHANGELOG.md
canaan5
added a commit
that referenced
this pull request
Jun 4, 2026
This was referenced Jun 4, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The core interface-design step toward HSM support — making the
vaultfaçade ready for any HSM adapter to implement out of the box. Source-compatible (no method-set change), so it's safe to land before the v1vaultfreeze.What changed
vault.Vaultis now the composition of three small capability interfaces:So an adapter implements exactly what its hardware supports:
Macer(and possiblyPINEncryptor)PINTranslatorCallers type-assert for the narrowest capability they need:
The PIN-security contract, encoded in the type system
PINTranslator's doc makes the rule explicit: a conforming hardware implementation must re-encipher atomically inside the device so the clear PIN never leaves it (PCI PIN Security). An adapter that can't (e.g. stock PKCS#11, which has no atomic-translate mechanism) must not implement the interface — its absence is the signal that PIN translation isn't available. This resolves the finding from #11.Verification
Vaultmethod set unchanged →SoftVault/SealedVaultstill satisfy it (compile-time assertions added for each capability).TestCapabilityDetectionshows a MAC-only adapter is correctly not usable as aPINTranslator.gofmt/vetclean;./...builds;vault/flow/gatewaypass under-race.Next (separate PRs)
adapters/pkcs11(feat(adapters/pkcs11): HSM-backed MAC (vault.Macer) verified against SoftHSM2 #11) to implementMaceragainst SoftHSM2 in CI; keepTranslatePINunimplemented (correct per the contract).adapters/payshield(PINTranslator+Macer) against a payShield simulator.