Skip to content

Commit aa7f03e

Browse files
committedFeb 27, 2025·
ssl: refactor check_supported_protocol_versions
As reported in <ruby/ruby#12823>, check_supported_protocol_versions is unstable and occasionally fails with Errno::ECONNABORTED during SSLSocket#connect on Windows. When the server-side SSLContext specifies an unsupported SSL/TLS protocol version, start_server accepts a TCP connection but closes it without reading ClientHello, as SSLSocket#accept immediately raises an exception. With Winsock, this can cause the client-side SSLSocket#connect to raise Errno::ECONNABORTED. While the simplest fix is to add rescue Errno::ECONNABORTED, this method can be simplified. Instead, let's set up a server that accepts all protocol versions and test client connections with different settings.
1 parent d725783 commit aa7f03e

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed
 

‎test/openssl/test_ssl.rb

+18-22
Original file line numberDiff line numberDiff line change
@@ -1243,32 +1243,28 @@ def check_supported_protocol_versions
12431243
OpenSSL::SSL::TLS1_1_VERSION,
12441244
OpenSSL::SSL::TLS1_2_VERSION,
12451245
OpenSSL::SSL::TLS1_3_VERSION,
1246-
].compact
1246+
]
12471247

1248-
# Prepare for testing & do sanity check
12491248
supported = []
1250-
possible_versions.each do |ver|
1251-
catch(:unsupported) {
1252-
ctx_proc = proc { |ctx|
1253-
begin
1254-
ctx.min_version = ctx.max_version = ver
1255-
rescue ArgumentError, OpenSSL::SSL::SSLError
1256-
throw :unsupported
1257-
end
1249+
ctx_proc = proc { |ctx|
1250+
# Explicitly reset them to avoid influenced by OPENSSL_CONF
1251+
ctx.min_version = ctx.max_version = nil
1252+
}
1253+
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) do |port|
1254+
possible_versions.each do |ver|
1255+
ctx = OpenSSL::SSL::SSLContext.new
1256+
ctx.min_version = ctx.max_version = ver
1257+
server_connect(port, ctx) { |ssl|
1258+
ssl.puts "abc"; assert_equal "abc\n", ssl.gets
12581259
}
1259-
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) do |port|
1260-
begin
1261-
server_connect(port) { |ssl|
1262-
ssl.puts "abc"; assert_equal "abc\n", ssl.gets
1263-
}
1264-
rescue OpenSSL::SSL::SSLError, Errno::ECONNRESET
1265-
else
1266-
supported << ver
1267-
end
1268-
end
1269-
}
1260+
supported << ver
1261+
rescue OpenSSL::SSL::SSLError, Errno::ECONNRESET
1262+
end
12701263
end
1271-
assert_not_empty supported
1264+
1265+
# Sanity check: in our test suite we assume these are always supported
1266+
assert_include(supported, OpenSSL::SSL::TLS1_2_VERSION)
1267+
assert_include(supported, OpenSSL::SSL::TLS1_3_VERSION)
12721268

12731269
supported
12741270
end

0 commit comments

Comments
 (0)
Please sign in to comment.