Skip to content

Commit 24d4b5b

Browse files
committed
support setting ssl_version = "TLSv1_1" (or "TLSv1_2") just like MRI 2.x does
closing jruby/jruby#1735
1 parent 781b155 commit 24d4b5b

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public class SSLContext extends RubyObject {
9898
private static final Map<String, String[]> ENABLED_PROTOCOLS;
9999

100100
static {
101-
SSL_VERSION_OSSL2JSSE = new LinkedHashMap<String, String>(16);
101+
SSL_VERSION_OSSL2JSSE = new LinkedHashMap<String, String>(20, 1);
102102
ENABLED_PROTOCOLS = new HashMap<String, String[]>(8, 1);
103103

104104
SSL_VERSION_OSSL2JSSE.put("TLSv1", "TLSv1");
@@ -121,13 +121,20 @@ public class SSLContext extends RubyObject {
121121
SSL_VERSION_OSSL2JSSE.put("SSLv23_client", "SSL");
122122
ENABLED_PROTOCOLS.put("SSL", new String[] { "SSLv2", "SSLv3", "TLSv1" });
123123

124-
// Followings(TLS, TLSv1.1) are JSSE only methods at present. Let's allow user to use it.
124+
// Historically we were ahead of MRI to support TLS
125+
// ... thus the non-standard names version names :
125126

126127
SSL_VERSION_OSSL2JSSE.put("TLS", "TLS");
127128
ENABLED_PROTOCOLS.put("TLS", new String[] { "TLSv1", "TLSv1.1" });
128129

129130
SSL_VERSION_OSSL2JSSE.put("TLSv1.1", "TLSv1.1");
130131
ENABLED_PROTOCOLS.put("TLSv1.1", new String[] { "TLSv1.1" });
132+
133+
SSL_VERSION_OSSL2JSSE.put("TLSv1_1", "TLSv1.1"); // supported on MRI 2.x
134+
SSL_VERSION_OSSL2JSSE.put("TLSv1_2", "TLSv1.2"); // supported on MRI 2.x
135+
ENABLED_PROTOCOLS.put("TLSv1.2", new String[] { "TLSv1.2" });
136+
137+
SSL_VERSION_OSSL2JSSE.put("TLSv1.2", "TLSv1.2"); // just for completeness
131138
}
132139

133140
private static ObjectAllocator SSLCONTEXT_ALLOCATOR = new ObjectAllocator() {
@@ -269,7 +276,7 @@ public IRubyObject setup(final ThreadContext context) {
269276
internalContext = new InternalContext();
270277

271278
// TODO: handle tmp_dh_callback :
272-
279+
273280
// #if !defined(OPENSSL_NO_DH)
274281
// if (RTEST(ossl_sslctx_get_tmp_dh_cb(self))){
275282
// SSL_CTX_set_tmp_dh_callback(ctx, ossl_tmp_dh_callback);

src/test/ruby/ssl/test_context.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# coding: US-ASCII
2+
require File.expand_path('test_helper', File.dirname(__FILE__))
3+
4+
class TestSSLContext < TestCase
5+
#include SSLTestHelper
6+
7+
def test_context_set_ssl_version
8+
context = OpenSSL::SSL::SSLContext.new
9+
context.ssl_version = :"TLSv1_1"
10+
#assert_equal :TLSv1_1, context.ssl_version
11+
12+
context = OpenSSL::SSL::SSLContext.new
13+
context.ssl_version = "TLSv1_1"
14+
15+
context = OpenSSL::SSL::SSLContext.new
16+
context.ssl_version = "TLSv1.1" if defined? JRUBY_VERSION
17+
18+
context = OpenSSL::SSL::SSLContext.new
19+
context.ssl_version = :TLSv1_2
20+
21+
context = OpenSSL::SSL::SSLContext.new
22+
context.ssl_version = "TLSv1.2" if defined? JRUBY_VERSION
23+
end
24+
25+
end

0 commit comments

Comments
 (0)