Skip to content

Commit 882e33a

Browse files
[fix] SSL session resumption failure due to BC classloader mismatch (#369)
1 parent f52e9f0 commit 882e33a

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/main/java/org/jruby/ext/openssl/BCSSLSupport.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ static SSLSession getBCSession(final SSLEngine engine) {
4646

4747
static boolean setBCSessionToResume(final SSLEngine engine, final SSLSession session) {
4848
if (engine instanceof BCSSLEngine && session instanceof BCExtendedSSLSession) {
49-
((BCSSLEngine) engine).setBCSessionToResume((BCExtendedSSLSession) session);
50-
return true;
49+
try {
50+
((BCSSLEngine) engine).setBCSessionToResume((BCExtendedSSLSession) session);
51+
return true;
52+
} catch (IllegalArgumentException e) {
53+
// This can happen when a Java gem's post-install hook (e.g. fast-rsa-engine)
54+
// downloads BC JARs via Maven and loads them under a new classloader. At that
55+
// point there are two copies of BC in the JVM, and ProvSSLEngine rejects the
56+
// stored session because it came from a different classloader context.
57+
// Just fall through and let the caller do a fresh handshake.
58+
}
5159
}
5260
return false;
5361
}

src/main/java/org/jruby/ext/openssl/SSLSocket.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,10 +1356,12 @@ private void tryResumeSessionIfSet(final ThreadContext context) {
13561356

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

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

0 commit comments

Comments
 (0)