diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2022-09-08 15:37:07 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-08 15:37:07 +0900 |
commit | 9302d4863d9762c3196b724f605dcd5c7ca84a8b (patch) | |
tree | a953a0596c120dedaab4fce5a4a019c10ffd716a /test | |
parent | 9247cf812bce252f1de0bb183ce77b62abb7562c (diff) | |
parent | d486c82833cb5411f2ceae955a6556e976a90296 (diff) | |
download | ruby-openssl-9302d4863d9762c3196b724f605dcd5c7ca84a8b.tar.gz |
Merge pull request #540 from rhenium/ky/pkey-read-prefer-keys
pkey: restore support for decoding "openssl ecparam -genkey" output
Diffstat (limited to 'test')
-rw-r--r-- | test/openssl/test_pkey_ec.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/openssl/test_pkey_ec.rb b/test/openssl/test_pkey_ec.rb index ffe5a94e..23c6c4d4 100644 --- a/test/openssl/test_pkey_ec.rb +++ b/test/openssl/test_pkey_ec.rb @@ -199,6 +199,29 @@ class OpenSSL::TestEC < OpenSSL::PKeyTestCase assert_equal pem, p256.export end + def test_ECPrivateKey_with_parameters + p256 = Fixtures.pkey("p256") + + # The format used by "openssl ecparam -name prime256v1 -genkey -outform PEM" + # + # "EC PARAMETERS" block should be ignored if it is followed by an + # "EC PRIVATE KEY" block + in_pem = <<~EOF + -----BEGIN EC PARAMETERS----- + BggqhkjOPQMBBw== + -----END EC PARAMETERS----- + -----BEGIN EC PRIVATE KEY----- + MHcCAQEEIID49FDqcf1O1eO8saTgG70UbXQw9Fqwseliit2aWhH1oAoGCCqGSM49 + AwEHoUQDQgAEFglk2c+oVUIKQ64eZG9bhLNPWB7lSZ/ArK41eGy5wAzU/0G51Xtt + CeBUl+MahZtn9fO1JKdF4qJmS39dXnpENg== + -----END EC PRIVATE KEY----- + EOF + + key = OpenSSL::PKey::EC.new(in_pem) + assert_same_ec p256, key + assert_equal p256.to_der, key.to_der + end + def test_ECPrivateKey_encrypted p256 = Fixtures.pkey("p256") # key = abcdef |