During bundle install on a long-lived JVM, any Java gem with a post-install hook
(e.g. fast-rsa-engine, digest-crc, psych) can load BouncyCastle JARs via Maven
under a new classloader. Once that happens there are two copies of BC in the same JVM,
and two bugs combine to make every subsequent HTTPS connection fatal.
Issue 1 — BCSSLSupport
ProvSSLEngine.setBCSessionToResume throws IllegalArgumentException because the stored
BCExtendedSSLSession came from a different classloader than the current engine. That
exception was uncaught and propagated as an SSLError.
Issue 2 — SSLSocket
When setBCSessionToResume returned false, we called engine.setEnableSessionCreation(false).
If the stored session then couldn't be resumed for any reason, BC-JSSE threw instead of falling
back to a fresh handshake — which is the error users see:
OpenSSL::SSL::SSLError: No new session is allowed and no existing session can be resumed
Neither bug alone explains the full failure — both need to be fixed together.
The fix
File
Change
BCSSLSupport.java
Catch IllegalArgumentException from setBCSessionToResume and return false so the caller falls back to a fresh handshake
SSLSocket.java
Remove setEnableSessionCreation(false) — it was intended to enforce session reuse but makes any resumption failure unrecoverable
Testing
Tested locally on macOS with JRuby 9.4.13.0 and a Gemfile that pulls in fast-rsa-engine,
digest-crc, ruby-maven-libs, and psych — all gems that trigger JAR classloading via
post-install hooks.
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
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.
Fixes #369.
What breaks and why
During bundle install on a long-lived JVM, any Java gem with a post-install hook
(e.g. fast-rsa-engine, digest-crc, psych) can load BouncyCastle JARs via Maven
under a new classloader. Once that happens there are two copies of BC in the same JVM,
and two bugs combine to make every subsequent HTTPS connection fatal.
Issue 1 — BCSSLSupport
ProvSSLEngine.setBCSessionToResume throws IllegalArgumentException because the stored
BCExtendedSSLSession came from a different classloader than the current engine. That
exception was uncaught and propagated as an SSLError.
Issue 2 — SSLSocket
When setBCSessionToResume returned false, we called engine.setEnableSessionCreation(false).
If the stored session then couldn't be resumed for any reason, BC-JSSE threw instead of falling
back to a fresh handshake — which is the error users see:
OpenSSL::SSL::SSLError: No new session is allowed and no existing session can be resumed
Neither bug alone explains the full failure — both need to be fixed together.
The fix
Testing
Tested locally on macOS with JRuby 9.4.13.0 and a Gemfile that pulls in fast-rsa-engine,
digest-crc, ruby-maven-libs, and psych — all gems that trigger JAR classloading via
post-install hooks.