Skip to content

Commit e9ae6a3

Browse files
committed
test_pkey_ec.rb: Fix the test in FIPS case, adding the file to CI.
Fix the test_ECPrivateKey_encrypted test in OpenSSL FIPS case. The password based encryption used in the PEM format uses MD5 for deriving the encryption key from the password, and MD5 is not FIPS-approved.
1 parent 40775db commit e9ae6a3

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,5 +182,5 @@ jobs:
182182
run: |
183183
bundle exec rake debug &&
184184
ruby -I./lib -ropenssl \
185-
-e 'Dir.glob "./test/openssl/{test_fips.rb,test_pkey.rb}", &method(:require)'
185+
-e 'Dir.glob "./test/openssl/{test_fips.rb,test_pkey.rb,test_pkey_ec.rb}", &method(:require)'
186186
if: matrix.fips-enabled

test/openssl/test_pkey_ec.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,23 @@ def test_ECPrivateKey_encrypted
241241
0/dGSU5SzFG+iT9iFXCwCvv+bxyegkBOyALFje1NAsM=
242242
-----END EC PRIVATE KEY-----
243243
EOF
244-
key = OpenSSL::PKey::EC.new(pem, "abcdef")
244+
begin
245+
key = OpenSSL::PKey::EC.new(pem, "abcdef")
246+
rescue OpenSSL::PKey::ECError => e
247+
raise e unless OpenSSL.fips_mode
248+
249+
# The password based encryption used in the PEM format uses MD5 for
250+
# deriving the encryption key from the password, and MD5 is not
251+
# FIPS-approved.
252+
#
253+
# See https://github.com/openssl/openssl/discussions/21830#discussioncomment-6865636
254+
# for details.
255+
#
256+
# The error message is not the best. But it is expected.
257+
assert_equal "OpenSSL::PKey::ECError", e.class.name
258+
assert_equal "invalid curve name", e.message
259+
return
260+
end
245261
assert_same_ec p256, key
246262
key = OpenSSL::PKey::EC.new(pem) { "abcdef" }
247263
assert_same_ec p256, key

0 commit comments

Comments
 (0)