Skip to content

Commit ed95b2c

Browse files
committed
SSLSocket.session= needs to delay session initialization after the engine is setup
... hopefully the now removed `session=` warning won't confuse users as we do not do much except for copy-ing the timeout - although the underlying engine should now have an explicit hint not to create new sessions! resolves cases such as jruby/jruby#3765
1 parent f12aab2 commit ed95b2c

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ private SSLEngine ossl_ssl_setup(final ThreadContext context)
191191
peerAppData.limit(0);
192192
netData.limit(0);
193193
dummy = ByteBuffer.allocate(0);
194-
return this.engine = engine;
194+
this.engine = engine;
195+
copySessionSetupIfSet();
196+
return engine;
195197
}
196198

197199
@JRubyMethod(name = "io", alias = "to_io")
@@ -1054,23 +1056,31 @@ private SSLSession getSession(final ThreadContext context) {
10541056
return session;
10551057
}
10561058

1059+
private transient SSLSession setSession = null;
1060+
10571061
@JRubyMethod(name = "session=")
10581062
public IRubyObject set_session(IRubyObject session) {
10591063
final ThreadContext context = getRuntime().getCurrentContext();
10601064
// NOTE: we can not fully support this without the SSL provider internals
10611065
// but we can assume setting a session= is meant as a forced session re-use
1062-
if ( reusableSSLEngine() ) {
1063-
engine.setEnableSessionCreation(false);
1064-
if ( session instanceof SSLSession ) {
1065-
final SSLSession theSession = (SSLSession) session;
1066-
if ( ! theSession.equals( getSession(context) ) ) {
1067-
getSession(context).set_timeout(context, theSession.timeout(context));
1066+
if ( session instanceof SSLSession ) {
1067+
setSession = (SSLSession) session;
1068+
if ( engine != null ) copySessionSetupIfSet();
1069+
}
1070+
//warn(context, "WARNING: SSLSocket#session= has not effect");
1071+
return context.nil;
1072+
}
1073+
1074+
private void copySessionSetupIfSet() {
1075+
if ( setSession != null ) {
1076+
if ( reusableSSLEngine() ) {
1077+
engine.setEnableSessionCreation(false);
1078+
final ThreadContext context = getRuntime().getCurrentContext();
1079+
if ( ! setSession.equals( getSession(context) ) ) {
1080+
getSession(context).set_timeout(context, setSession.timeout(context));
10681081
}
10691082
}
1070-
return getSession(context);
10711083
}
1072-
warn(context, "WARNING: SSLSocket#session= has not effect");
1073-
return context.nil;
10741084
}
10751085

10761086
@JRubyMethod

0 commit comments

Comments
 (0)