Add ExternalKeyProvider SPI for HSM-backed EBICS keys#48
Open
florianpollstaetter-dot wants to merge 1 commit into
Open
Add ExternalKeyProvider SPI for HSM-backed EBICS keys#48florianpollstaetter-dot wants to merge 1 commit into
florianpollstaetter-dot wants to merge 1 commit into
Conversation
…002 keys
Closes the gap that forces in-process generation of EBICS subscriber RSA key
pairs. Callers that hold the private keys in an HSM, smartcard, or any other
PKCS#11 token can now pass an ExternalKeyProvider; the library installs the
supplied (PrivateKey, X509Certificate) triples on the User and skips
KeyUtil.makeKeyPair(...) for that subscriber. No PKCS#12 is written for an
externally-keyed user, so the heap-key duplicate path stays cold.
The change is additive and non-breaking: existing createUser(...) callers see
no behaviour change.
Surface:
* New interface org.kopi.ebics.client.ExternalKeyProvider with the
KeyMaterial(PrivateKey, X509Certificate) record. Compact constructor
rejects null components at the boundary.
* New User constructor accepting an ExternalKeyProvider; bypasses
CertificateManager.create().
* New EbicsClient.createUser(..., ExternalKeyProvider) overload that
produces the user, persists bank/partner/user, and writes the
INI/HIA letters (public-key bytes only) without writing PKCS#12.
JUnit coverage:
* UserExternalKeysTest#constructorAssignsExternalKeysVerbatim verifies the
supplied PrivateKey instances reach the User unchanged (no internal
KeyPair generation overwrites them) and that the public keys returned by
the User match the supplied certificates for all three roles.
* UserExternalKeysTest#nullProviderRejected and #partialProviderRejected
cover the boundary checks; partial errors name the offending role.
* UserExternalKeysTest#keyMaterialRecordRejects{Null,Null}* verify the
record-level null guards.
Motivated by DSGVO + ISO 27001 commitments under which EBICS subscriber
A005/X002 private keys must never reside outside their hardware token.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add
ExternalKeyProviderSPI for HSM-backed EBICS keysThis PR adds a small, additive and non-breaking SPI so callers can supply A005/X002/E002 key material from outside the JVM (HSM, smartcard, any PKCS#11 token) instead of having the library generate keys via
KeyUtil.makeKeyPair(...).Motivation: production EBICS use cases that must keep private keys in tamper-resistant hardware (regulatory requirements, DSGVO-Schutzbedarf-Hoch in our case). Today
EbicsClient.createUser(...)generates the keys internally and persists them as PKCS#12 — no public seam to inject an externally-suppliedPrivateKey.Design
New interface
org.kopi.ebics.client.ExternalKeyProvidera005(),x002(),e002()KeyMaterial(PrivateKey, X509Certificate)recordNew
User(...)constructor overload acceptingExternalKeyProviderUserCertificateManager.create()(no internalKeyUtil.makeKeyPair)New
EbicsClient.createUser(...)overload acceptingExternalKeyProviderGoals
CertificateManager, no breaking change toUserjava.security.PrivateKey. SunPKCS11, BouncyCastleFipsProvider, JCE software — library is unawareKeyUtil.makeKeyPair(...)for the same role (no double-generation leak)Tests (committed in this branch)
UserExternalKeysTest#constructorAssignsExternalKeysVerbatim— suppliedPrivateKeyinstances arrive onUserunchanged; public keys match supplied certsUserExternalKeysTest#nullProviderRejected— nullExternalKeyProvider→IllegalArgumentExceptionUserExternalKeysTest#partialProviderRejected— provider returningnullforx002()→IllegalArgumentExceptionnaming the offending roleUserExternalKeysTest#keyMaterialRecordRejectsNullPrivateKey/…NullCertificate— record-level null guardsContext
This SPI closes the HSM integration gap documented at https://github.com/florianpollstaetter-dot/rechnungstool (treasury sidecar). We've shipped the PKCS#11 plumbing on our side (
Pkcs11A005Signer, smartcard + AWS CloudHSM locators), and would prefer to drop our local wrapper in favor of an upstream SPI if accepted.Happy to iterate on naming, scope, or testing approach. Reach out anytime — we're committed to maintaining this if accepted.