Skip to content

Commit 5ee118c

Browse files
authoredFeb 28, 2025··
Merge pull request #867 from rhenium/ky/ssl-fix-flaky-tests
ssl: fix tests using TLS 1.1 or older
2 parents 8c49897 + 6d0ea81 commit 5ee118c

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed
 

‎test/openssl/test_ssl.rb

+38-7
Original file line numberDiff line numberDiff line change
@@ -1248,12 +1248,16 @@ def check_supported_protocol_versions
12481248

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

13051309
# Server enables a single version
13061310
supported.each do |ver|
1307-
ctx_proc = proc { |ctx| ctx.min_version = ctx.max_version = ver }
1311+
ctx_proc = proc { |ctx|
1312+
ctx.security_level = 0
1313+
ctx.min_version = ctx.max_version = ver
1314+
}
13081315
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) { |port|
13091316
supported.each do |cver|
13101317
# Client enables a single version
13111318
ctx1 = OpenSSL::SSL::SSLContext.new
1319+
ctx1.security_level = 0
13121320
ctx1.min_version = ctx1.max_version = cver
13131321
if ver == cver
13141322
server_connect(port, ctx1) { |ssl|
@@ -1323,6 +1331,7 @@ def test_minmax_version
13231331
if cver <= OpenSSL::SSL::TLS1_2_VERSION
13241332
# Client enables a single version using #ssl_version=
13251333
ctx2 = OpenSSL::SSL::SSLContext.new
1334+
ctx2.security_level = 0
13261335
ctx2.ssl_version = vmap[cver][:method]
13271336
if ver == cver
13281337
server_connect(port, ctx2) { |ssl|
@@ -1337,6 +1346,7 @@ def test_minmax_version
13371346

13381347
# Client enables all supported versions
13391348
ctx3 = OpenSSL::SSL::SSLContext.new
1349+
ctx3.security_level = 0
13401350
ctx3.min_version = ctx3.max_version = nil
13411351
server_connect(port, ctx3) { |ssl|
13421352
assert_equal vmap[ver][:name], ssl.ssl_version
@@ -1351,19 +1361,26 @@ def test_minmax_version
13511361

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

13651380
# Client sets max_version
13661381
ctx2 = OpenSSL::SSL::SSLContext.new
1382+
ctx2.security_level = 0
1383+
ctx2.min_version = 0
13671384
ctx2.max_version = cver
13681385
if cver >= sver
13691386
server_connect(port, ctx2) { |ssl|
@@ -1378,7 +1395,11 @@ def test_minmax_version
13781395

13791396
# Server sets max_version (latest is disabled)
13801397
sver = supported[-2]
1381-
ctx_proc = proc { |ctx| ctx.max_version = sver }
1398+
ctx_proc = proc { |ctx|
1399+
ctx.security_level = 0
1400+
ctx.min_version = 0
1401+
ctx.max_version = sver
1402+
}
13821403
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) { |port|
13831404
supported.each do |cver|
13841405
# Client sets min_version
@@ -1395,6 +1416,8 @@ def test_minmax_version
13951416

13961417
# Client sets max_version
13971418
ctx2 = OpenSSL::SSL::SSLContext.new
1419+
ctx2.security_level = 0
1420+
ctx2.min_version = 0
13981421
ctx2.max_version = cver
13991422
server_connect(port, ctx2) { |ssl|
14001423
if cver >= sver
@@ -1771,11 +1794,11 @@ def test_get_ephemeral_key
17711794

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

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

17801803
start_server do |port|
17811804
ctx = OpenSSL::SSL::SSLContext.new
@@ -1786,11 +1809,15 @@ def test_fallback_scsv
17861809
end
17871810

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.