Skip to content

Commit 4d64c38

Browse files
committed
test_pkey.rb: Refactor the test_ed25519 on FIPS.
* Split the test in the FIPS case as another test. * test/openssl/utils.rb: Add omit_on_fips and omit_on_non_fips methods.
1 parent 2fe3438 commit 4d64c38

File tree

2 files changed

+53
-8
lines changed

2 files changed

+53
-8
lines changed

test/openssl/test_pkey.rb

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ def test_hmac_sign_verify
8282
end
8383

8484
def test_ed25519
85+
# Ed25519 is not FIPS-approved.
86+
omit_on_fips
87+
8588
# Test vector from RFC 8032 Section 7.1 TEST 2
8689
priv_pem = <<~EOF
8790
-----BEGIN PRIVATE KEY-----
@@ -96,15 +99,11 @@ def test_ed25519
9699
begin
97100
priv = OpenSSL::PKey.read(priv_pem)
98101
pub = OpenSSL::PKey.read(pub_pem)
99-
rescue OpenSSL::PKey::PKeyError
102+
rescue OpenSSL::PKey::PKeyError => e
100103
# OpenSSL < 1.1.1
101-
if !openssl?(1, 1, 1)
102-
pend "Ed25519 is not implemented"
103-
elsif OpenSSL.fips_mode && openssl?(3, 1, 0, 0)
104-
# See OpenSSL providers/fips/fipsprov.c PROV_NAMES_ED25519 entries
105-
# with FIPS_UNAPPROVED_PROPERTIES in OpenSSL 3.1+.
106-
pend "Ed25519 is not approved in OpenSSL 3.1+ FIPS code"
107-
end
104+
pend "Ed25519 is not implemented" unless openssl?(1, 1, 1)
105+
106+
raise e
108107
end
109108
assert_instance_of OpenSSL::PKey::PKey, priv
110109
assert_instance_of OpenSSL::PKey::PKey, pub
@@ -145,6 +144,32 @@ def test_ed25519
145144
assert_raise(OpenSSL::PKey::PKeyError) { priv.derive(pub) }
146145
end
147146

147+
def test_ed25519_not_approved_on_fips
148+
omit_on_non_fips
149+
# Ed25519 is technically allowed in the OpenSSL 3.0 code as a kind of bug.
150+
# So, we need to omit OpenSSL 3.0.
151+
#
152+
# See OpenSSL providers/fips/fipsprov.c PROV_NAMES_ED25519 entries with
153+
# FIPS_DEFAULT_PROPERTIES on openssl-3.0 branch and
154+
# FIPS_UNAPPROVED_PROPERTIES on openssl-3.1 branch.
155+
#
156+
# See also
157+
# https://github.com/openssl/openssl/issues/20758#issuecomment-1639658102
158+
# for details.
159+
unless openssl?(3, 1, 0, 0)
160+
omit 'Ed25519 is allowed in the OpenSSL 3.0 FIPS code as a kind of bug'
161+
end
162+
163+
priv_pem = <<~EOF
164+
-----BEGIN PRIVATE KEY-----
165+
MC4CAQAwBQYDK2VwBCIEIEzNCJso/5banbbDRuwRTg9bijGfNaumJNqM9u1PuKb7
166+
-----END PRIVATE KEY-----
167+
EOF
168+
assert_raise(OpenSSL::PKey::PKeyError) do
169+
OpenSSL::PKey.read(priv_pem)
170+
end
171+
end
172+
148173
def test_x25519
149174
# Test vector from RFC 7748 Section 6.1
150175
alice_pem = <<~EOF

test/openssl/utils.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,26 @@ def teardown
139139
# OpenSSL error stack must be empty
140140
assert_equal([], OpenSSL.errors)
141141
end
142+
143+
# Omit the tests in FIPS.
144+
#
145+
# For example, the password based encryption used in the PEM format uses MD5
146+
# for deriving the encryption key from the password, and MD5 is not
147+
# FIPS-approved.
148+
#
149+
# See https://github.com/openssl/openssl/discussions/21830#discussioncomment-6865636
150+
# for details.
151+
def omit_on_fips
152+
return unless OpenSSL.fips_mode
153+
154+
omit 'An encryption used in the test is not FIPS-approved'
155+
end
156+
157+
def omit_on_non_fips
158+
return if OpenSSL.fips_mode
159+
160+
omit "Only for OpenSSL FIPS"
161+
end
142162
end
143163

144164
class OpenSSL::SSLTestCase < OpenSSL::TestCase

0 commit comments

Comments
 (0)