Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/main/java/org/jruby/ext/openssl/BCSSLSupport.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,16 @@ static SSLSession getBCSession(final SSLEngine engine) {

static boolean setBCSessionToResume(final SSLEngine engine, final SSLSession session) {
if (engine instanceof BCSSLEngine && session instanceof BCExtendedSSLSession) {
((BCSSLEngine) engine).setBCSessionToResume((BCExtendedSSLSession) session);
return true;
try {
((BCSSLEngine) engine).setBCSessionToResume((BCExtendedSSLSession) session);
return true;
} catch (IllegalArgumentException e) {
// This can happen when a Java gem's post-install hook (e.g. fast-rsa-engine)
// downloads BC JARs via Maven and loads them under a new classloader. At that
// point there are two copies of BC in the JVM, and ProvSSLEngine rejects the
// stored session because it came from a different classloader context.
// Just fall through and let the caller do a fresh handshake.
}
}
return false;
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/org/jruby/ext/openssl/SSLSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -1356,10 +1356,12 @@ private void tryResumeSessionIfSet(final ThreadContext context) {

if (BCSSLSupport.setBCSessionToResume(engine, setSession.sslSession())) return;

// can not support this without the (BC) SSL provider internals (e.g. on SunJSSE)
// but we can assume setting a session= is meant to be a *forced* session re-use:
// Without BC internals (e.g. on SunJSSE) we can't force session re-use.
// We used to call setEnableSessionCreation(false) here to signal that intent,
// but that backfires: if the stored session can't be resumed for any reason
// (including the BC classloader mismatch above), BC-JSSE throws instead of
// falling back to a fresh handshake. Leave session creation enabled.
if (reusableSSLEngine()) {
engine.setEnableSessionCreation(false);
final SSLSession session = getSession(context.runtime);
if (!setSession.equals(session)) {
session.set_timeout(context, setSession.timeout(context));
Expand Down