1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/openssl] test/openssl/test_pkey: use EC keys for PKey.generate_parameters tests

OpenSSL 3.0 refuses to generate DSA parameters shorter than 2048 bits,
but generating 2048 bits parameters takes very long time. Let's use EC
in these test cases instead.

https://github.com/ruby/openssl/commit/c732387ee5
This commit is contained in:
Kazuki Yamaguchi 2020-05-18 02:35:35 +09:00
parent d67fe1e9de
commit 95044fa13b

View file

@ -27,20 +27,16 @@ class OpenSSL::TestPKey < OpenSSL::PKeyTestCase
end end
def test_s_generate_parameters def test_s_generate_parameters
# 512 is non-default; 1024 is used if 'dsa_paramgen_bits' is not specified pkey = OpenSSL::PKey.generate_parameters("EC", {
# with OpenSSL 1.1.0. "ec_paramgen_curve" => "secp384r1",
pkey = OpenSSL::PKey.generate_parameters("DSA", {
"dsa_paramgen_bits" => 512,
"dsa_paramgen_q_bits" => 256,
}) })
assert_instance_of OpenSSL::PKey::DSA, pkey assert_instance_of OpenSSL::PKey::EC, pkey
assert_equal 512, pkey.p.num_bits assert_equal "secp384r1", pkey.group.curve_name
assert_equal 256, pkey.q.num_bits assert_equal nil, pkey.private_key
assert_equal nil, pkey.priv_key
# Invalid options are checked # Invalid options are checked
assert_raise(OpenSSL::PKey::PKeyError) { assert_raise(OpenSSL::PKey::PKeyError) {
OpenSSL::PKey.generate_parameters("DSA", "invalid" => "option") OpenSSL::PKey.generate_parameters("EC", "invalid" => "option")
} }
# Parameter generation callback is called # Parameter generation callback is called
@ -59,14 +55,13 @@ class OpenSSL::TestPKey < OpenSSL::PKeyTestCase
# DSA key pair cannot be generated without parameters # DSA key pair cannot be generated without parameters
OpenSSL::PKey.generate_key("DSA") OpenSSL::PKey.generate_key("DSA")
} }
pkey_params = OpenSSL::PKey.generate_parameters("DSA", { pkey_params = OpenSSL::PKey.generate_parameters("EC", {
"dsa_paramgen_bits" => 512, "ec_paramgen_curve" => "secp384r1",
"dsa_paramgen_q_bits" => 256,
}) })
pkey = OpenSSL::PKey.generate_key(pkey_params) pkey = OpenSSL::PKey.generate_key(pkey_params)
assert_instance_of OpenSSL::PKey::DSA, pkey assert_instance_of OpenSSL::PKey::EC, pkey
assert_equal 512, pkey.p.num_bits assert_equal "secp384r1", pkey.group.curve_name
assert_not_equal nil, pkey.priv_key assert_not_equal nil, pkey.private_key
end end
def test_hmac_sign_verify def test_hmac_sign_verify