Skip to content

Commit a9954ba

Browse files
committed
test: adjust test cases for LibreSSL 3.2.4
LibreSSL 3.2.4 made the certificate verification logic back closer to pre-3.2.2 one, which is more compatible with OpenSSL. Part of the fixes added by commit a0e98d4 ("Enhance TLS 1.3 support on LibreSSL 3.2/3.3", 2020-12-03) is required for 3.2.2 and 3.2.3 only (and ~3.3.1, however 3.3 does not have a stable release yet). Since both releases are security fix, it should be safe to remove those special treatment from our test suite. While we are at it, TestSSL#test_ecdh_curves is split into TLS 1.2 and TLS 1.3 variants for clarity.
1 parent cde6e4a commit a9954ba

File tree

5 files changed

+52
-41
lines changed

5 files changed

+52
-41
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
- openssl-1.1.1j
7878
- libressl-2.9.2 # EOL
7979
- libressl-3.1.5
80-
- libressl-3.2.0
80+
- libressl-3.2.4
8181
steps:
8282
- name: repo checkout
8383
uses: actions/checkout@v2

test/openssl/test_ssl.rb

+28-16
Original file line numberDiff line numberDiff line change
@@ -458,11 +458,7 @@ def test_verify_result
458458
ssl.sync_close = true
459459
begin
460460
assert_raise(OpenSSL::SSL::SSLError){ ssl.connect }
461-
assert_include(
462-
[
463-
OpenSSL::X509::V_ERR_SELF_SIGNED_CERT_IN_CHAIN,
464-
OpenSSL::X509::V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY
465-
], ssl.verify_result)
461+
assert_equal(OpenSSL::X509::V_ERR_SELF_SIGNED_CERT_IN_CHAIN, ssl.verify_result)
466462
ensure
467463
ssl.close
468464
end
@@ -930,7 +926,7 @@ def test_verify_hostname_on_connect
930926
["keyUsage", "keyEncipherment,digitalSignature", true],
931927
["subjectAltName", san],
932928
]
933-
929+
934930
ctx.cert = issue_cert(@svr, @svr_key, 4, exts, @ca_cert, @ca_key)
935931
ctx.key = @svr_key
936932
}
@@ -1015,7 +1011,7 @@ def test_connect_certificate_verify_failed_exception_message
10151011
start_server(ignore_listener_error: true) { |port|
10161012
ctx = OpenSSL::SSL::SSLContext.new
10171013
ctx.set_params
1018-
assert_raise_with_message(OpenSSL::SSL::SSLError, /self signed|unable to get local issuer certificate/) {
1014+
assert_raise_with_message(OpenSSL::SSL::SSLError, /self signed/) {
10191015
server_connect(port, ctx)
10201016
}
10211017
}
@@ -1617,13 +1613,13 @@ def test_connect_works_when_setting_dh_callback_to_nil
16171613
end
16181614
end
16191615

1620-
def test_ecdh_curves
1616+
def test_ecdh_curves_tls12
16211617
pend "EC is disabled" unless defined?(OpenSSL::PKey::EC)
16221618

16231619
ctx_proc = -> ctx {
16241620
# Enable both ECDHE (~ TLS 1.2) cipher suites and TLS 1.3
1625-
ctx.ciphers = "DEFAULT:!kRSA:!kEDH"
1626-
ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION if libressl?(3, 2, 0)
1621+
ctx.max_version = OpenSSL::SSL::TLS1_2_VERSION
1622+
ctx.ciphers = "kEECDH"
16271623
ctx.ecdh_curves = "P-384:P-521"
16281624
}
16291625
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) do |port|
@@ -1632,13 +1628,9 @@ def test_ecdh_curves
16321628

16331629
server_connect(port, ctx) { |ssl|
16341630
cs = ssl.cipher[0]
1635-
if /\ATLS/ =~ cs # Is TLS 1.3 is used?
1631+
assert_match (/\AECDH/), cs
1632+
if ssl.respond_to?(:tmp_key)
16361633
assert_equal "secp384r1", ssl.tmp_key.group.curve_name
1637-
else
1638-
assert_match (/\AECDH/), cs
1639-
if ssl.respond_to?(:tmp_key)
1640-
assert_equal "secp384r1", ssl.tmp_key.group.curve_name
1641-
end
16421634
end
16431635
ssl.puts "abc"; assert_equal "abc\n", ssl.gets
16441636
}
@@ -1662,6 +1654,26 @@ def test_ecdh_curves
16621654
end
16631655
end
16641656

1657+
def test_ecdh_curves_tls13
1658+
pend "EC is disabled" unless defined?(OpenSSL::PKey::EC)
1659+
pend "TLS 1.3 not supported" unless tls13_supported?
1660+
1661+
ctx_proc = -> ctx {
1662+
# Assume TLS 1.3 is enabled and chosen by default
1663+
ctx.ecdh_curves = "P-384:P-521"
1664+
}
1665+
start_server(ctx_proc: ctx_proc, ignore_listener_error: true) do |port|
1666+
ctx = OpenSSL::SSL::SSLContext.new
1667+
ctx.ecdh_curves = "P-256:P-384" # disable P-521
1668+
1669+
server_connect(port, ctx) { |ssl|
1670+
assert_equal "TLSv1.3", ssl.ssl_version
1671+
assert_equal "secp384r1", ssl.tmp_key.group.curve_name
1672+
ssl.puts "abc"; assert_equal "abc\n", ssl.gets
1673+
}
1674+
end
1675+
end
1676+
16651677
def test_security_level
16661678
ctx = OpenSSL::SSL::SSLContext.new
16671679
begin

test/openssl/test_ts.rb

-2
Original file line numberDiff line numberDiff line change
@@ -387,15 +387,13 @@ def test_verify_ee_no_store
387387
end
388388

389389
def test_verify_ee_wrong_root_no_intermediate
390-
pend "LibreSSL 3.2.2 Timestamp Issue" if libressl?(3, 2, 2)
391390
assert_raise(OpenSSL::Timestamp::TimestampError) do
392391
ts, req = timestamp_ee
393392
ts.verify(req, intermediate_store)
394393
end
395394
end
396395

397396
def test_verify_ee_wrong_root_wrong_intermediate
398-
pend "LibreSSL 3.2.2 Timestamp Issue" if libressl?(3, 2, 2)
399397
assert_raise(OpenSSL::Timestamp::TimestampError) do
400398
ts, req = timestamp_ee
401399
ts.verify(req, intermediate_store, [ca_cert])

test/openssl/test_x509store.rb

+15-22
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,15 @@ def test_add_file_path
3232
assert_equal true, store.verify(cert1)
3333
assert_equal true, store.verify(cert2)
3434

35-
unless libressl?(3, 2, 2)
36-
# X509::Store#add_path
37-
Dir.mktmpdir do |dir|
38-
hash1 = "%08x.%d" % [cert1_subj.hash, 0]
39-
File.write(File.join(dir, hash1), cert1.to_pem)
40-
store = OpenSSL::X509::Store.new
41-
store.add_path(dir)
42-
43-
assert_equal true, store.verify(cert1)
44-
assert_equal false, store.verify(cert2)
45-
end
35+
# X509::Store#add_path
36+
Dir.mktmpdir do |dir|
37+
hash1 = "%08x.%d" % [cert1_subj.hash, 0]
38+
File.write(File.join(dir, hash1), cert1.to_pem)
39+
store = OpenSSL::X509::Store.new
40+
store.add_path(dir)
41+
42+
assert_equal true, store.verify(cert1)
43+
assert_equal false, store.verify(cert2)
4644
end
4745

4846
# OpenSSL < 1.1.1 leaks an error on a duplicate certificate
@@ -77,8 +75,8 @@ def test_verify_simple
7775
# Nothing trusted
7876
store = OpenSSL::X509::Store.new
7977
assert_equal(false, store.verify(ee1_cert, [ca2_cert, ca1_cert]))
80-
assert_include([OpenSSL::X509::V_ERR_SELF_SIGNED_CERT_IN_CHAIN, OpenSSL::X509::V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY], store.error)
81-
assert_match(/self.signed|unable to get local issuer certificate/i, store.error_string)
78+
assert_equal(OpenSSL::X509::V_ERR_SELF_SIGNED_CERT_IN_CHAIN, store.error)
79+
assert_match(/self.signed/i, store.error_string)
8280

8381
# CA1 trusted, CA2 missing
8482
store = OpenSSL::X509::Store.new
@@ -188,7 +186,7 @@ def test_verify_purpose
188186
store.purpose = OpenSSL::X509::PURPOSE_CRL_SIGN
189187
store.add_cert(ca1_cert)
190188
assert_equal(true, store.verify(ca1_cert))
191-
assert_equal(libressl?(3, 2, 2), store.verify(ee1_cert))
189+
assert_equal(false, store.verify(ee1_cert))
192190
end
193191

194192
def test_verify_validity_period
@@ -284,7 +282,7 @@ def test_verify_with_crl
284282
store.flags = OpenSSL::X509::V_FLAG_CRL_CHECK
285283
store.add_cert(ca1_cert)
286284
assert_equal(false, store.verify(ca2_cert))
287-
assert_include([OpenSSL::X509::V_ERR_UNABLE_TO_GET_CRL, OpenSSL::X509::V_ERR_UNSPECIFIED], store.error)
285+
assert_equal(OpenSSL::X509::V_ERR_UNABLE_TO_GET_CRL, store.error)
288286

289287
# Intermediate CA revoked EE2
290288
store = OpenSSL::X509::Store.new
@@ -324,14 +322,9 @@ def test_verify_with_crl
324322
store.add_cert(ca2_cert)
325323
store.add_crl(ca1_crl1)
326324
store.add_crl(ca2_crl2) # issued by ca2 but expired
327-
if libressl?(3, 2, 2)
328-
assert_equal(false, store.verify(ca2_cert))
329-
assert_include([OpenSSL::X509::V_ERR_CRL_SIGNATURE_FAILURE, OpenSSL::X509::V_ERR_UNSPECIFIED], store.error)
330-
else
331-
assert_equal(true, store.verify(ca2_cert))
332-
end
325+
assert_equal(true, store.verify(ca2_cert))
333326
assert_equal(false, store.verify(ee1_cert))
334-
assert_include([OpenSSL::X509::V_ERR_CRL_HAS_EXPIRED, OpenSSL::X509::V_ERR_UNSPECIFIED], store.error)
327+
assert_equal(OpenSSL::X509::V_ERR_CRL_HAS_EXPIRED, store.error)
335328
assert_equal(false, store.verify(ee2_cert))
336329
end
337330

test/openssl/utils.rb

+8
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ def tls12_supported?
196196
rescue
197197
end
198198

199+
def tls13_supported?
200+
return false unless defined?(OpenSSL::SSL::TLS1_3_VERSION)
201+
ctx = OpenSSL::SSL::SSLContext.new
202+
ctx.min_version = ctx.max_version = OpenSSL::SSL::TLS1_3_VERSION
203+
true
204+
rescue
205+
end
206+
199207
def readwrite_loop(ctx, ssl)
200208
while line = ssl.gets
201209
ssl.write(line)

0 commit comments

Comments
 (0)