Skip to content

Removes all hard dependencies on bcprov-specific#85

Open
strehle wants to merge 3 commits into
vt-middleware:mainfrom
sap-contributions:fix-issue-43
Open

Removes all hard dependencies on bcprov-specific#85
strehle wants to merge 3 commits into
vt-middleware:mainfrom
sap-contributions:fix-issue-43

Conversation

@strehle
Copy link
Copy Markdown

@strehle strehle commented May 4, 2026

Removes all hard dependencies on bcprov-specific internal classes so the library works transparently with either BouncyCastleProvider (BC) or BouncyCastleFipsProvider (BCFIPS), whichever is registered at runtime

Solution for issue #43

This PR was generate with help of AI but manually verified

strehle added 3 commits May 4, 2026 17:04
## Summary

  Removes all hard dependencies on bcprov-specific internal classes so the library works transparently with either BouncyCastleProvider (BC) or BouncyCastleFipsProvider (BCFIPS), whichever is registered at runtime.

  Root cause: Several classes bypassed the JCA provider abstraction by instantiating BC internal SPI and utility classes directly. These classes do not exist in bc-fips, causing ClassNotFoundException at runtime when the FIPS provider is used.

  Changes per file:

  - CertUtil — Adds a public bouncyCastleProvider() utility method that resolves the active BC provider at runtime: prefers BCFIPS if registered, falls back to BC, and finally instantiates BouncyCastleProvider reflectively if neither is registered. Both JcaContentSignerBuilder and
  JcaX509CertificateConverter now use this provider explicitly.
  - CsrUtil — Passes bouncyCastleProvider() to JcaContentSignerBuilder.setProvider() so CSR signing routes through whichever BC provider is active.
  - KeyPairGenerator — Replaces direct instantiation of bcprov internal *KeyPairGeneratorSpi classes (DSA, RSA, EC) with java.security.KeyPairGenerator.getInstance(algo, provider) — the standard JCA pattern, compatible with both BC and BCFIPS.
  - KeyPairUtil — Replaces ECUtil.generatePrivateKeyParameter / generatePublicKeyParameter (bcprov-only) with PrivateKeyFactory.createKey(PrivateKeyInfo.getInstance(...)) and PublicKeyFactory.createKey(SubjectPublicKeyInfo.getInstance(...)), which are available in both BC and BCFIPS via the shared bcpkix
   layer.
  - OpenSSLPrivateKeyDecoder — Replaces ECUtil.getNamedCurveByOid (bcprov-only) with ECNamedCurveTable.getByOID from org.bouncycastle.asn1.x9, which is present in both bcprov and bc-fips.
  - AbstractWrappedECKey — Replaces EC5Util.convertCurve (bcprov-only) with an inline conversion using standard java.security.spec.ECFieldFp / ECFieldF2m — no BC provider dependency at all.

  ## Test plan

  - All 359 existing tests pass unchanged (mvn test)
  - CertUtil.bouncyCastleProvider() returns BCFIPS when that provider is registered, BC otherwise
  - generateX509Certificate and generateCsr complete successfully with an explicitly registered BouncyCastleProvider
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.

1 participant