-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_pkey_ec.rb test failures in OpenSSL FIPS #671
Comments
For the error above, where does the openssl/test/lib/core_assertions.rb Lines 185 to 190 in f4b8dac
|
The And I am seeing the same name method |
secp112r1 isn't allowed in FIPS 140. |
First, we should switch to using https://github.com/ruby/test-unit-ruby-core instead of embedding core_assertions.rb. This is just not yet worked on. The same issue is in ruby/test-unit-ruby-core. |
ruby/test-unit-ruby-core#2 (comment) is helpful for openssl? |
Yes, test-unit-ruby-core 1.0.2 fixed |
@hsbt @rhenium thanks! On the latest ruby/opessl including the #673, the
|
How did you know that? Could you share a document link that you checked for that? |
Is it https://www.openssl.org/source/ - The OpenSSL 3.0.0 or 3.0.8 security policy document? |
secp112r1, defined on a 112-bit finite field, would provide at most 56 bits of security. I don't know how to cite the specifications for FIPS 140, but it must definitely be prohibited for any use. The test case in question is about OpenSSL::PKey::EC.builtin_curves. I don't think the current assertions make much sense anyway. I think it can use something like: diff --git a/test/openssl/test_pkey_ec.rb b/test/openssl/test_pkey_ec.rb
index e5fef940a6c3..ab777a8b48a4 100644
--- a/test/openssl/test_pkey_ec.rb
+++ b/test/openssl/test_pkey_ec.rb
@@ -5,20 +5,6 @@
class OpenSSL::TestEC < OpenSSL::PKeyTestCase
def test_ec_key
- builtin_curves = OpenSSL::PKey::EC.builtin_curves
- assert_not_empty builtin_curves
-
- builtin_curves.each do |curve_name, comment|
- # Oakley curves and X25519 are not suitable for signing and causes
- # FIPS-selftest failure on some environment, so skip for now.
- next if ["Oakley", "X25519"].any? { |n| curve_name.start_with?(n) }
-
- key = OpenSSL::PKey::EC.generate(curve_name)
- assert_predicate key, :private?
- assert_predicate key, :public?
- assert_nothing_raised { key.check_key }
- end
-
key1 = OpenSSL::PKey::EC.generate("prime256v1")
# PKey is immutable in OpenSSL >= 3.0; constructing an empty EC object is
@@ -49,6 +35,17 @@ def test_ec_key
end
end
+ def test_builtin_curves
+ builtin_curves = OpenSSL::PKey::EC.builtin_curves
+ assert_not_empty builtin_curves
+ assert_equal 2, builtin_curves[0].size
+ assert_kind_of String, builtin_curves[0][0]
+ assert_kind_of String, builtin_curves[0][1]
+
+ builtin_curve_names = builtin_curves.map { |name, comment| name }
+ assert_include builtin_curve_names, "prime256v1"
+ end
+
def test_generate
assert_raise(OpenSSL::PKey::ECError) { OpenSSL::PKey::EC.generate("non-existent") }
g = OpenSSL::PKey::EC::Group.new("prime256v1") |
Check that OpenSSL::PKey::EC.builtin_curves returns an array in the expected format. Similarly to OpenSSL::Cipher.ciphers, OpenSSL::PKey::EC.builtin_curves returns a list of known named curves rather than actually usable ones. ruby#671 found that the list may include unapproved (and thus unusable) curves when the FIPS module is loaded.
I see. The solution looks okay to me. I may notice that one issue related to the FIPS
Non-FIPS
This is weird to me. Because the And it seems that the |
The EC_get_builtin_curves() called from ruby/openssl would be the one in libcrypto.so. Since this function isn't provider-aware (rather, crypto/ec is the backend used by the default/fips providers), and considering it's possible to use FIPS module and non-FIPS module at the same time with custom property query string (which is however not currently supported in ruby/openssl - https://www.openssl.org/docs/man3.0/man7/fips_module.html), I don't think this is fixable. The commit that introduced the |
Thanks for the investigation. I found the issue ticket, openssl/openssl#18273 (comment) related to this topic, and commented there. It seems that the |
A minimal reproducerFor the test failure above, below is a minimal reproducer. Does the "AES-128-CBC" mean MD5? And it is not allowed in FIPS 140? I found the AES's Wikipedia page including the FIPS 140 things.
I referred to the following code. openssl/test/openssl/test_pkey_ec.rb Lines 237 to 247 in 7c34a43
Debug with GDBFIPS case
The error happens in the openssl/ext/openssl/ossl_pkey_ec.c Lines 166 to 172 in 7c34a43
The error happens in the openssl/ext/openssl/ossl_pkey_ec.c Line 85 in 7c34a43
Non-FIPS caseIn the non-FIPS case, the
So, in the code below, after openssl/ext/openssl/ossl_pkey_ec.c Lines 166 to 172 in 7c34a43
|
By the way, I was discussing how we can know a key or key name is allowed or not allowed in OpenSSL FIPS at openssl/openssl#21830. Unfortunately I don't find a clear way to know it. But I think if |
The "-----BEGIN EC PRIVATE KEY-----" PEM can't be decoded in FIPS 140-compliant systems because it uses MD5 to derive encryption keys from passwords (#643, #645). I don't think AES-128-CBC is the issue here. The error message is unfortunate. As you analyzed it, unlike other PKey types, The test case (and also corresponding ones in other |
…iltin_curves Check that OpenSSL::PKey::EC.builtin_curves returns an array in the expected format. Similarly to OpenSSL::Cipher.ciphers, OpenSSL::PKey::EC.builtin_curves returns a list of known named curves rather than actually usable ones. ruby/openssl#671 found that the list may include unapproved (and thus unusable) curves when the FIPS module is loaded. ruby/openssl@c53cbabe00
All right. I sent the PR to #681 fix the |
Check that OpenSSL::PKey::EC.builtin_curves returns an array in the expected format. Similarly to OpenSSL::Cipher.ciphers, OpenSSL::PKey::EC.builtin_curves returns a list of known named curves rather than actually usable ones. ruby#671 found that the list may include unapproved (and thus unusable) curves when the FIPS module is loaded.
I am trying to fix the test failures in
test/openssl/test_pkey_ec.rb
now in OpenSSL FIPS on the ruby/openssl latest master branchf4b8dacc75d61142b7b4e0142898b2fecbb131b9
, and openssl/openssl latest master branchcf712830b7b5a20a768a1fc5f78dc48841b7617f
.Test failures
A minimal reproducer
For the
test/openssl/test_pkey_ec.rb:19
, below is a minimal reproducer.Debug with GDB
The
EVP_PKEY_check(pctx)
returns0
in the line below. And it seems that causes theEVP_PKEY_check: initialization error (OpenSSL::PKey::ECError)
. Do you know why this happens?openssl/ext/openssl/ossl_pkey_ec.c
Lines 551 to 554 in f4b8dac
The text was updated successfully, but these errors were encountered: