Skip to content

Commit 9994a95

Browse files
rheniummatzbot
authored andcommitted
[ruby/openssl] ssl: manually craft invalid SAN extensions in tests
Starting with LibreSSL 3.5, OpenSSL::X509::ExtensionFactory refuses to create SAN extensions that are not valid according to RFC 6125. While this behavior makes sense, we need such invalid extensions to test our own validation routine. Let's construct SAN extensions manually instead. ruby/openssl@b420d6d739
1 parent 244363b commit 9994a95

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

test/openssl/test_ssl.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -835,11 +835,6 @@ def test_post_connection_check_wildcard_san
835835
# buzz.example.net, respectively). ...
836836
assert_equal(true, OpenSSL::SSL.verify_certificate_identity(
837837
create_cert_with_san('DNS:baz*.example.com'), 'baz1.example.com'))
838-
839-
# LibreSSL 3.5.0+ doesn't support other wildcard certificates
840-
# (it isn't required to, as RFC states MAY, not MUST)
841-
return if libressl?
842-
843838
assert_equal(true, OpenSSL::SSL.verify_certificate_identity(
844839
create_cert_with_san('DNS:*baz.example.com'), 'foobaz.example.com'))
845840
assert_equal(true, OpenSSL::SSL.verify_certificate_identity(
@@ -923,11 +918,17 @@ def test_post_connection_check_wildcard_cn
923918
end
924919

925920
def create_cert_with_san(san)
926-
ef = OpenSSL::X509::ExtensionFactory.new
927921
cert = OpenSSL::X509::Certificate.new
928922
cert.subject = OpenSSL::X509::Name.parse("/DC=some/DC=site/CN=Some Site")
929-
ext = ef.create_ext('subjectAltName', san)
930-
cert.add_extension(ext)
923+
v = OpenSSL::ASN1::Sequence(san.split(",").map { |item|
924+
type, value = item.split(":", 2)
925+
case type
926+
when "DNS" then OpenSSL::ASN1::IA5String(value, 2, :IMPLICIT)
927+
when "IP" then OpenSSL::ASN1::OctetString(IPAddr.new(value).hton, 7, :IMPLICIT)
928+
else raise "unsupported"
929+
end
930+
})
931+
cert.add_extension(OpenSSL::X509::Extension.new("subjectAltName", v))
931932
cert
932933
end
933934

0 commit comments

Comments
 (0)