Load openssl when BouncyCastle FIPS jars are on the classpath#365
Open
tehbooom wants to merge 3 commits into
Open
Load openssl when BouncyCastle FIPS jars are on the classpath#365tehbooom wants to merge 3 commits into
openssl when BouncyCastle FIPS jars are on the classpath#365tehbooom wants to merge 3 commits into
Conversation
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.
Summary
require "openssl"crashes when BouncyCastle FIPS jars (bc-fips, bcpkix-fips, bctls-fips, bcutil-fips) are on the classpath in place of non-FIPS BouncyCastle. Several classes reference bc-internal types underorg.bouncycastle.jce.provider.*andorg.bouncycastle.jcajce.provider.asymmetric.util.*that don't exist in the FIPS distribution, so the class-load hitsNoClassDefFoundErrorbeforeopensslcan initialize.This PR makes jruby-openssl load under either BouncyCastle distribution. It is a compatibility fix, not a feature. It does not add FIPS enforcement and does not change which provider is selected.
Approach
Every code path that references a bc-internal type absent from the FIPS jars is moved verbatim into a lazily-loaded
BCInternalnested class, and the outer method delegates to it. Because inner classes compile to separate class files and the verifier resolves referenced types per-class, the outer classes no longer carry any load-time reference to the absent types, so the class loads regardless of which BC distribution is present. Code paths that genuinely require the absent classes fail at call time (only if invoked), not at load time.The non-FIPS path is unchanged. The moved method bodies are byte-identical, and delegation only changes where the code lives, not what it does.
Changes
Isolation into
BCInternalnested classes (verbatim extraction, delegated):SecurityHelper,PKeyEC,PKeyRSA,PKCS5,X509Name,PEMInputOutput,x509store/Name,x509store/X509AuxCertificate,impl/PKey.DN comparison: removes the
X509CertificateObjectinstanceof fast-path (that class is bc-internal and absent from FIPS jars) and usesX500Principalcomparison, which is RFC-4514 normalized and encoding-tolerant (verified to treat PrintableString and UTF8String of the same subject as equal).EC
dsa_verifyerror message: a non-sequence signature previously produced a double-prefixed message (invalid signature: invalid signature (not a sequence)); this restores the single, correct message.Behavior-change note
Removing the
X509CertificateObjectDN fast-path is correctness-preserving but a minor performance regression for non-FIPS users doing heavy certificate-chain and CRL verification, where the old O(1) fast-path is no longer taken. The fast-path was already unavailable under FIPS (the class is absent), so this affects only the non-FIPS path, and only performance, not results.Testing
Full existing suite passes unchanged (no behavior change on the non-FIPS path).
New regression test for the EC
dsa_verifymessage, verified to fail on the pre-fix double-prefix behavior and pass on the fix.New test confirming DN comparison matches subjects encoded as PrintableString versus UTF8String.
Verified
require "openssl"loads clean with only bc-fips jars on the classpath (non-FIPS BC absent), and that operations depending on absent bc-internal classes fail at call time rather than at load time.