Skip to content

Commit 3d2f7bb

Browse files
committed
Support negotiating up to TLS1_1 and TLS1_2 when the server supports these ssl_versions
1 parent d030e6d commit 3d2f7bb

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,18 @@ public class SSLContext extends RubyObject {
122122
SSL_VERSION_OSSL2JSSE.put("SSLv23", "SSL");
123123
SSL_VERSION_OSSL2JSSE.put("SSLv23_server", "SSL");
124124
SSL_VERSION_OSSL2JSSE.put("SSLv23_client", "SSL");
125-
ENABLED_PROTOCOLS.put("SSL", new String[] { "SSLv2", "SSLv3", "TLSv1" });
125+
126+
if ( OpenSSL.javaVersion7(true) ) { // >= 1.7
127+
ENABLED_PROTOCOLS.put("SSL", new String[] { "SSLv2", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2" });
128+
} else {
129+
ENABLED_PROTOCOLS.put("SSL", new String[] { "SSLv2", "SSLv3", "TLSv1" });
130+
}
126131

127132
// Historically we were ahead of MRI to support TLS
128133
// ... thus the non-standard names version names :
129134

130135
SSL_VERSION_OSSL2JSSE.put("TLS", "TLS");
131-
ENABLED_PROTOCOLS.put("TLS", new String[] { "TLSv1", "TLSv1.1" });
136+
ENABLED_PROTOCOLS.put("TLS", new String[] { "TLSv1", "TLSv1.1", "TLSv1.2" });
132137

133138
SSL_VERSION_OSSL2JSSE.put("TLSv1.1", "TLSv1.1");
134139
ENABLED_PROTOCOLS.put("TLSv1.1", new String[] { "TLSv1.1" });

src/test/ruby/ssl/test_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ def readwrite_loop(context, ssl)
147147
ssl.close rescue nil
148148
end
149149

150+
def java_version
151+
java.lang.System.get_property('java.version')[2].to_i
152+
end
153+
150154
TEST_KEY_RSA1024 = <<-_end_of_pem_
151155
-----BEGIN RSA PRIVATE KEY-----
152156
MIICXgIBAAKBgQDLwsSw1ECnPtT+PkOgHhcGA71nwC2/nL85VBGnRqDxOqjVh7Cx

src/test/ruby/ssl/test_ssl.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,33 @@ def test_ssl_version_tlsv1
9595
end
9696
end
9797

98+
def test_ssl_version_tlsv1_1
99+
return if java_version < 7 # TLS1_1 is not supported by JDK 6
100+
101+
ctx_proc = Proc.new do |ctx|
102+
ctx.ssl_version = "TLSv1_1"
103+
end
104+
start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true, :ctx_proc => ctx_proc) do |server, port|
105+
sock = TCPSocket.new("127.0.0.1", port)
106+
ssl = OpenSSL::SSL::SSLSocket.new(sock)
107+
ssl.connect
108+
assert_equal("TLSv1.1", ssl.ssl_version)
109+
ssl.close
110+
end
111+
end
112+
113+
def test_ssl_version_tlsv1_2
114+
return if java_version < 7 # TLS1_2 is not supported by JDK 6
115+
116+
ctx_proc = Proc.new do |ctx|
117+
ctx.ssl_version = "TLSv1_2"
118+
end
119+
start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true, :ctx_proc => ctx_proc) do |server, port|
120+
sock = TCPSocket.new("127.0.0.1", port)
121+
ssl = OpenSSL::SSL::SSLSocket.new(sock)
122+
ssl.connect
123+
assert_equal("TLSv1.2", ssl.ssl_version)
124+
ssl.close
125+
end
126+
end
98127
end

0 commit comments

Comments
 (0)