Skip to content

Commit 6d0ea81

Browse files
committed
ssl: fix tests using TLS 1.1 or older
Commit aa7f03e broke test_minmax_version and test_fallback_scsv on systems using OpenSSL 1.1.1 with a system-wide configuration file that specifies MinProtocol=TLSv1.2. http://rubyci.s3.amazonaws.com/debian11/ruby-master/log/20250228T003003Z.fail.html.gz http://rubyci.s3.amazonaws.com/rhel8/ruby-master/log/20250228T003003Z.fail.html.gz These test cases were already broken before the commit, but they were being skipped because check_supported_protocol_versions failed to detect TLS 1.1 support. To avoid affected by the configuration file, explicitly reset SSLContext#min_version when TLS 1.1 or older is required. The test cases are also broken with OpenSSL 3.0 or later, but this is not currently visible because it still fails to detect TLS 1.1 support. This is caused by the default SSLContext#security_level value, as OpenSSL 3.0 changed TLS 1.1 to be disabled at level 1.
1 parent aa7f03e commit 6d0ea81

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

test/openssl/test_ssl.rb

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,12 +1247,16 @@ def check_supported_protocol_versions
12471247

12481248
supported = []
12491249
ctx_proc = proc { |ctx|
1250+
# The default security level is 1 in OpenSSL <= 3.1, 2 in OpenSSL >= 3.2
1251+
# In OpenSSL >= 3.0, TLS 1.1 or older is disabled at level 1
1252+
ctx.security_level = 0
12501253
# Explicitly reset them to avoid influenced by OPENSSL_CONF
12511254
ctx.min_version = ctx.max_version = nil
12521255
}
12531256
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) do |port|
12541257
possible_versions.each do |ver|
12551258
ctx = OpenSSL::SSL::SSLContext.new
1259+
ctx.security_level = 0
12561260
ctx.min_version = ctx.max_version = ver
12571261
server_connect(port, ctx) { |ssl|
12581262
ssl.puts "abc"; assert_equal "abc\n", ssl.gets
@@ -1303,11 +1307,15 @@ def test_minmax_version
13031307

13041308
# Server enables a single version
13051309
supported.each do |ver|
1306-
ctx_proc = proc { |ctx| ctx.min_version = ctx.max_version = ver }
1310+
ctx_proc = proc { |ctx|
1311+
ctx.security_level = 0
1312+
ctx.min_version = ctx.max_version = ver
1313+
}
13071314
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) { |port|
13081315
supported.each do |cver|
13091316
# Client enables a single version
13101317
ctx1 = OpenSSL::SSL::SSLContext.new
1318+
ctx1.security_level = 0
13111319
ctx1.min_version = ctx1.max_version = cver
13121320
if ver == cver
13131321
server_connect(port, ctx1) { |ssl|
@@ -1322,6 +1330,7 @@ def test_minmax_version
13221330
if cver <= OpenSSL::SSL::TLS1_2_VERSION
13231331
# Client enables a single version using #ssl_version=
13241332
ctx2 = OpenSSL::SSL::SSLContext.new
1333+
ctx2.security_level = 0
13251334
ctx2.ssl_version = vmap[cver][:method]
13261335
if ver == cver
13271336
server_connect(port, ctx2) { |ssl|
@@ -1336,6 +1345,7 @@ def test_minmax_version
13361345

13371346
# Client enables all supported versions
13381347
ctx3 = OpenSSL::SSL::SSLContext.new
1348+
ctx3.security_level = 0
13391349
ctx3.min_version = ctx3.max_version = nil
13401350
server_connect(port, ctx3) { |ssl|
13411351
assert_equal vmap[ver][:name], ssl.ssl_version
@@ -1350,19 +1360,26 @@ def test_minmax_version
13501360

13511361
# Server sets min_version (earliest is disabled)
13521362
sver = supported[1]
1353-
ctx_proc = proc { |ctx| ctx.min_version = sver }
1363+
ctx_proc = proc { |ctx|
1364+
ctx.security_level = 0
1365+
ctx.min_version = sver
1366+
}
13541367
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) { |port|
13551368
supported.each do |cver|
13561369
# Client sets min_version
13571370
ctx1 = OpenSSL::SSL::SSLContext.new
1371+
ctx1.security_level = 0
13581372
ctx1.min_version = cver
1373+
ctx1.max_version = 0
13591374
server_connect(port, ctx1) { |ssl|
13601375
assert_equal vmap[supported.last][:name], ssl.ssl_version
13611376
ssl.puts "abc"; assert_equal "abc\n", ssl.gets
13621377
}
13631378

13641379
# Client sets max_version
13651380
ctx2 = OpenSSL::SSL::SSLContext.new
1381+
ctx2.security_level = 0
1382+
ctx2.min_version = 0
13661383
ctx2.max_version = cver
13671384
if cver >= sver
13681385
server_connect(port, ctx2) { |ssl|
@@ -1377,7 +1394,11 @@ def test_minmax_version
13771394

13781395
# Server sets max_version (latest is disabled)
13791396
sver = supported[-2]
1380-
ctx_proc = proc { |ctx| ctx.max_version = sver }
1397+
ctx_proc = proc { |ctx|
1398+
ctx.security_level = 0
1399+
ctx.min_version = 0
1400+
ctx.max_version = sver
1401+
}
13811402
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) { |port|
13821403
supported.each do |cver|
13831404
# Client sets min_version
@@ -1394,6 +1415,8 @@ def test_minmax_version
13941415

13951416
# Client sets max_version
13961417
ctx2 = OpenSSL::SSL::SSLContext.new
1418+
ctx2.security_level = 0
1419+
ctx2.min_version = 0
13971420
ctx2.max_version = cver
13981421
server_connect(port, ctx2) { |ssl|
13991422
if cver >= sver
@@ -1770,11 +1793,11 @@ def test_get_ephemeral_key
17701793

17711794
def test_fallback_scsv
17721795
supported = check_supported_protocol_versions
1773-
return unless supported.include?(OpenSSL::SSL::TLS1_1_VERSION) &&
1774-
supported.include?(OpenSSL::SSL::TLS1_2_VERSION)
1796+
unless supported.include?(OpenSSL::SSL::TLS1_1_VERSION)
1797+
omit "TLS 1.1 support is required to run this test case"
1798+
end
17751799

1776-
pend "Fallback SCSV is not supported" unless \
1777-
OpenSSL::SSL::SSLContext.method_defined?(:enable_fallback_scsv)
1800+
omit "Fallback SCSV is not supported" if libressl?
17781801

17791802
start_server do |port|
17801803
ctx = OpenSSL::SSL::SSLContext.new
@@ -1785,11 +1808,15 @@ def test_fallback_scsv
17851808
end
17861809

17871810
ctx_proc = proc { |ctx|
1811+
ctx.security_level = 0
1812+
ctx.min_version = 0
17881813
ctx.max_version = OpenSSL::SSL::TLS1_1_VERSION
17891814
}
17901815
start_server(ctx_proc: ctx_proc) do |port|
17911816
ctx = OpenSSL::SSL::SSLContext.new
17921817
ctx.enable_fallback_scsv
1818+
ctx.security_level = 0
1819+
ctx.min_version = 0
17931820
ctx.max_version = OpenSSL::SSL::TLS1_1_VERSION
17941821
# Here is OK too
17951822
# TLS1.2 not supported, fallback to TLS1.1 and signaling the fallback
@@ -1807,11 +1834,15 @@ def test_fallback_scsv
18071834
# Otherwise, this test fails when using openssl 1.1.1 (or later) that supports TLS1.3.
18081835
# TODO: We may need another test for TLS1.3 because it seems to have a different mechanism.
18091836
ctx1 = OpenSSL::SSL::SSLContext.new
1837+
ctx1.security_level = 0
1838+
ctx1.min_version = 0
18101839
ctx1.max_version = OpenSSL::SSL::TLS1_2_VERSION
18111840
s1 = OpenSSL::SSL::SSLSocket.new(sock1, ctx1)
18121841

18131842
ctx2 = OpenSSL::SSL::SSLContext.new
18141843
ctx2.enable_fallback_scsv
1844+
ctx2.security_level = 0
1845+
ctx2.min_version = 0
18151846
ctx2.max_version = OpenSSL::SSL::TLS1_1_VERSION
18161847
s2 = OpenSSL::SSL::SSLSocket.new(sock2, ctx2)
18171848
# AWS-LC has slightly different error messages in all-caps.

0 commit comments

Comments
 (0)