Skip to content

Commit febe50b

Browse files
pkey: AWS-LC disallows parsing of invalid keys and params
OpenSSL allows invalid EC keys or DH params to be parsed. The consuming application can then run parameter/key checks to check the validity of the parameters. We happen to run tests to verify that this behaves as expected. AWS-LC on the other hand, directly raises an error and disallows the invalid state to be parsed, rather than making it parsable and checking the validity later. Relevant tests have been adjusted accordingly to reflect this.
1 parent 78c585a commit febe50b

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

test/openssl/test_pkey_dh.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,22 @@ def test_params_ok?
123123
]))
124124
assert_equal(true, dh1.params_ok?)
125125

126-
dh2 = OpenSSL::PKey::DH.new(OpenSSL::ASN1::Sequence([
127-
OpenSSL::ASN1::Integer(dh0.p + 1),
128-
OpenSSL::ASN1::Integer(dh0.g)
129-
]))
130-
assert_equal(false, dh2.params_ok?)
126+
# AWS-LC automatically does parameter checks on the parsed params.
127+
if aws_lc?
128+
assert_raise(OpenSSL::PKey::DHError) {
129+
OpenSSL::PKey::DH.new(OpenSSL::ASN1::Sequence([
130+
OpenSSL::ASN1::Integer(dh0.p + 1),
131+
OpenSSL::ASN1::Integer(dh0.g)
132+
]))
133+
}
134+
else
135+
dh2 = OpenSSL::PKey::DH.new(OpenSSL::ASN1::Sequence([
136+
OpenSSL::ASN1::Integer(dh0.p + 1),
137+
OpenSSL::ASN1::Integer(dh0.g)
138+
]))
139+
assert_equal(false, dh2.params_ok?)
140+
end
141+
131142
end
132143

133144
def test_params

test/openssl/test_pkey_ec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,19 @@ def test_check_key
8989

9090
# Behavior of EVP_PKEY_public_check changes between OpenSSL 1.1.1 and 3.0
9191
# The public key does not match the private key
92-
key4 = OpenSSL::PKey.read(<<~EOF)
92+
ec_key_data = <<~EOF
9393
-----BEGIN EC PRIVATE KEY-----
9494
MHcCAQEEIP+TT0V8Fndsnacji9tyf6hmhHywcOWTee9XkiBeJoVloAoGCCqGSM49
9595
AwEHoUQDQgAEBkhhJIU/2/YdPSlY2I1k25xjK4trr5OXSgXvBC21PtY0HQ7lor7A
9696
jzT0giJITqmcd81fwGw5+96zLcdxTF1hVQ==
9797
-----END EC PRIVATE KEY-----
9898
EOF
99-
assert_raise(OpenSSL::PKey::ECError) { key4.check_key }
99+
if aws_lc? # AWS-LC automatically does key checks on the parsed key.
100+
assert_raise(OpenSSL::PKey::PKeyError) { OpenSSL::PKey.read(ec_key_data) }
101+
else
102+
key4 = OpenSSL::PKey.read(ec_key_data)
103+
assert_raise(OpenSSL::PKey::ECError) { key4.check_key }
104+
end
100105

101106
# EC#private_key= is deprecated in 3.0 and won't work on OpenSSL 3.0
102107
if !openssl?(3, 0, 0)

0 commit comments

Comments
 (0)