Skip to content

Commit ecc4d7f

Browse files
committed
test_pkey.rb: Refactor the test_ed25519 in FIPS.
* Split the test in the FIPS case as another test. * test/openssl/utils.rb: Add omit_on_fips method.
1 parent 2fe3438 commit ecc4d7f

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

test/openssl/test_pkey.rb

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

8484
def test_ed25519
85+
# Ed25519 is not FIPS-approved in OpenSSL 3.0 security policy documents.
86+
# However, it's technically allowed in the OpenSSL 3.0 code.
87+
#
88+
# See OpenSSL providers/fips/fipsprov.c PROV_NAMES_ED25519 entries with
89+
# FIPS_DEFAULT_PROPERTIES in OpenSSL 3.0 (openssl-3.0 branch) and
90+
# FIPS_UNAPPROVED_PROPERTIES in OpenSSL 3.1 (openssl-3.1 branch).
91+
#
92+
# See https://github.com/openssl/openssl/issues/20758#issuecomment-1639658102
93+
# for details.
94+
omit_on_fips { openssl?(3, 1, 0, 0) }
95+
8596
# Test vector from RFC 8032 Section 7.1 TEST 2
8697
priv_pem = <<~EOF
8798
-----BEGIN PRIVATE KEY-----
@@ -96,15 +107,11 @@ def test_ed25519
96107
begin
97108
priv = OpenSSL::PKey.read(priv_pem)
98109
pub = OpenSSL::PKey.read(pub_pem)
99-
rescue OpenSSL::PKey::PKeyError
110+
rescue OpenSSL::PKey::PKeyError => e
100111
# 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
112+
pend "Ed25519 is not implemented" unless openssl?(1, 1, 1)
113+
114+
raise e
108115
end
109116
assert_instance_of OpenSSL::PKey::PKey, priv
110117
assert_instance_of OpenSSL::PKey::PKey, pub
@@ -145,6 +152,21 @@ def test_ed25519
145152
assert_raise(OpenSSL::PKey::PKeyError) { priv.derive(pub) }
146153
end
147154

155+
def test_ed25519_not_approved_on_fips
156+
unless OpenSSL.fips_mode && openssl?(3, 1, 0, 0)
157+
omit "Only for OpenSSL 3.1+ FIPS"
158+
end
159+
160+
priv_pem = <<~EOF
161+
-----BEGIN PRIVATE KEY-----
162+
MC4CAQAwBQYDK2VwBCIEIEzNCJso/5banbbDRuwRTg9bijGfNaumJNqM9u1PuKb7
163+
-----END PRIVATE KEY-----
164+
EOF
165+
assert_raise(OpenSSL::PKey::PKeyError) do
166+
OpenSSL::PKey.read(priv_pem)
167+
end
168+
end
169+
148170
def test_x25519
149171
# Test vector from RFC 7748 Section 6.1
150172
alice_pem = <<~EOF

test/openssl/utils.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,22 @@ 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(&filter_block)
152+
filter_block ||= proc { true }
153+
154+
return unless OpenSSL.fips_mode && filter_block.call
155+
156+
omit 'An encryption used in the test is not FIPS-approved'
157+
end
142158
end
143159

144160
class OpenSSL::SSLTestCase < OpenSSL::TestCase

0 commit comments

Comments
 (0)