Skip to content

Support negotiating up to TLS1_1 and TLS1_2 when the server supports these ssl_versions #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/main/java/org/jruby/ext/openssl/SSLContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,18 @@ public class SSLContext extends RubyObject {
SSL_VERSION_OSSL2JSSE.put("SSLv23", "SSL");
SSL_VERSION_OSSL2JSSE.put("SSLv23_server", "SSL");
SSL_VERSION_OSSL2JSSE.put("SSLv23_client", "SSL");
ENABLED_PROTOCOLS.put("SSL", new String[] { "SSLv2", "SSLv3", "TLSv1" });

if ( OpenSSL.javaVersion7(true) ) { // >= 1.7
ENABLED_PROTOCOLS.put("SSL", new String[] { "SSLv2", "SSLv3", "TLSv1", "TLSv1.1", "TLSv1.2" });
} else {
ENABLED_PROTOCOLS.put("SSL", new String[] { "SSLv2", "SSLv3", "TLSv1" });
}

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

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

SSL_VERSION_OSSL2JSSE.put("TLSv1.1", "TLSv1.1");
ENABLED_PROTOCOLS.put("TLSv1.1", new String[] { "TLSv1.1" });
Expand Down
4 changes: 4 additions & 0 deletions src/test/ruby/ssl/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ def readwrite_loop(context, ssl)
ssl.close rescue nil
end

def java_version
java.lang.System.get_property('java.version')[2].to_i
end

TEST_KEY_RSA1024 = <<-_end_of_pem_
-----BEGIN RSA PRIVATE KEY-----
MIICXgIBAAKBgQDLwsSw1ECnPtT+PkOgHhcGA71nwC2/nL85VBGnRqDxOqjVh7Cx
Expand Down
29 changes: 29 additions & 0 deletions src/test/ruby/ssl/test_ssl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,33 @@ def test_ssl_version_tlsv1
end
end

def test_ssl_version_tlsv1_1
return if java_version < 7 # TLS1_1 is not supported by JDK 6

ctx_proc = Proc.new do |ctx|
ctx.ssl_version = "TLSv1_1"
end
start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true, :ctx_proc => ctx_proc) do |server, port|
sock = TCPSocket.new("127.0.0.1", port)
ssl = OpenSSL::SSL::SSLSocket.new(sock)
ssl.connect
assert_equal("TLSv1.1", ssl.ssl_version)
ssl.close
end
end

def test_ssl_version_tlsv1_2
return if java_version < 7 # TLS1_2 is not supported by JDK 6

ctx_proc = Proc.new do |ctx|
ctx.ssl_version = "TLSv1_2"
end
start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true, :ctx_proc => ctx_proc) do |server, port|
sock = TCPSocket.new("127.0.0.1", port)
ssl = OpenSSL::SSL::SSLSocket.new(sock)
ssl.connect
assert_equal("TLSv1.2", ssl.ssl_version)
ssl.close
end
end
end