Skip to content

Commit c53cbab

Browse files
committed
test/openssl/test_pkey_ec.rb: refactor tests for EC.builtin_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. #671 found that the list may include unapproved (and thus unusable) curves when the FIPS module is loaded.
1 parent 7c34a43 commit c53cbab

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

test/openssl/test_pkey_ec.rb

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,6 @@
55

66
class OpenSSL::TestEC < OpenSSL::PKeyTestCase
77
def test_ec_key
8-
builtin_curves = OpenSSL::PKey::EC.builtin_curves
9-
assert_not_empty builtin_curves
10-
11-
builtin_curves.each do |curve_name, comment|
12-
# Oakley curves and X25519 are not suitable for signing and causes
13-
# FIPS-selftest failure on some environment, so skip for now.
14-
next if ["Oakley", "X25519"].any? { |n| curve_name.start_with?(n) }
15-
16-
key = OpenSSL::PKey::EC.generate(curve_name)
17-
assert_predicate key, :private?
18-
assert_predicate key, :public?
19-
assert_nothing_raised { key.check_key }
20-
end
21-
228
key1 = OpenSSL::PKey::EC.generate("prime256v1")
239

2410
# PKey is immutable in OpenSSL >= 3.0; constructing an empty EC object is
@@ -49,6 +35,17 @@ def test_ec_key
4935
end
5036
end
5137

38+
def test_builtin_curves
39+
builtin_curves = OpenSSL::PKey::EC.builtin_curves
40+
assert_not_empty builtin_curves
41+
assert_equal 2, builtin_curves[0].size
42+
assert_kind_of String, builtin_curves[0][0]
43+
assert_kind_of String, builtin_curves[0][1]
44+
45+
builtin_curve_names = builtin_curves.map { |name, comment| name }
46+
assert_include builtin_curve_names, "prime256v1"
47+
end
48+
5249
def test_generate
5350
assert_raise(OpenSSL::PKey::ECError) { OpenSSL::PKey::EC.generate("non-existent") }
5451
g = OpenSSL::PKey::EC::Group.new("prime256v1")

0 commit comments

Comments
 (0)