File tree Expand file tree Collapse file tree
src/main/java/org/jruby/ext/openssl Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 ));
You can’t perform that action at this time.
0 commit comments