Skip to content

Commit 6886484

Browse files
driskellkares
authored andcommitted
Add SSLSocket ssl_version property like MRI has
1 parent cb684d7 commit 6886484

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,12 @@ public IRubyObject set_session(IRubyObject session) {
858858
return getRuntime().getNil(); // throw new UnsupportedOperationException();
859859
}
860860

861+
@JRubyMethod
862+
public IRubyObject ssl_version() {
863+
if ( engine == null ) return getRuntime().getNil();
864+
return getRuntime().newString( engine.getSession().getProtocol() );
865+
}
866+
861867
private SocketChannel getSocketChannel() {
862868
return (SocketChannel) io.getChannel();
863869
}

src/test/ruby/ssl/test_ssl.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,30 @@ def test_post_connection_check
8282
end
8383
end
8484

85-
end
85+
def test_ssl_version_sslv3
86+
ctx_proc = Proc.new do |ctx|
87+
ctx.ssl_version = "SSLv3"
88+
end
89+
start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true, :ctx_proc => ctx_proc) do |server, port|
90+
sock = TCPSocket.new("127.0.0.1", port)
91+
ssl = OpenSSL::SSL::SSLSocket.new(sock)
92+
ssl.connect
93+
assert_equal("SSLv3", ssl.ssl_version)
94+
ssl.close
95+
end
96+
end
97+
98+
def test_ssl_version_tlsv1
99+
ctx_proc = Proc.new do |ctx|
100+
ctx.ssl_version = "TLSv1"
101+
end
102+
start_server(PORT, OpenSSL::SSL::VERIFY_NONE, true, :ctx_proc => ctx_proc) do |server, port|
103+
sock = TCPSocket.new("127.0.0.1", port)
104+
ssl = OpenSSL::SSL::SSLSocket.new(sock)
105+
ssl.connect
106+
assert_equal("TLSv1", ssl.ssl_version)
107+
ssl.close
108+
end
109+
end
110+
111+
end

0 commit comments

Comments
 (0)