diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2017-03-18 17:26:33 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2020-05-13 16:14:06 +0900 |
commit | 867e5c021b7308fe35612510c619b2bba424c184 (patch) | |
tree | c9f4f80c7eefc2e4c5fe96c70c6d4542d270a683 | |
parent | 1eb1366615ec97a75d97c4b35cb20adfca175feb (diff) | |
download | ruby-openssl-867e5c021b7308fe35612510c619b2bba424c184.tar.gz |
pkey: have PKey.read parse PEM-encoded DHParameter
Try PEM_read_bio_Parameters(). Only PEM format is supported at the
moment since corresponding d2i_* functions are not provided by OpenSSL.
-rw-r--r-- | ext/openssl/ossl_pkey.c | 3 | ||||
-rw-r--r-- | test/openssl/test_pkey_dh.rb | 2 | ||||
-rw-r--r-- | test/openssl/utils.rb | 3 |
3 files changed, 5 insertions, 3 deletions
diff --git a/ext/openssl/ossl_pkey.c b/ext/openssl/ossl_pkey.c index c6dbf572..a00d66aa 100644 --- a/ext/openssl/ossl_pkey.c +++ b/ext/openssl/ossl_pkey.c @@ -178,6 +178,9 @@ ossl_pkey_new_from_data(int argc, VALUE *argv, VALUE self) OSSL_BIO_reset(bio); if ((pkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL))) goto ok; + OSSL_BIO_reset(bio); + if ((pkey = PEM_read_bio_Parameters(bio, NULL))) + goto ok; BIO_free(bio); ossl_raise(ePKeyError, "Could not parse PKey"); diff --git a/test/openssl/test_pkey_dh.rb b/test/openssl/test_pkey_dh.rb index fd2c7a66..4a05626a 100644 --- a/test/openssl/test_pkey_dh.rb +++ b/test/openssl/test_pkey_dh.rb @@ -36,6 +36,8 @@ class OpenSSL::TestPKeyDH < OpenSSL::PKeyTestCase EOF key = OpenSSL::PKey::DH.new(pem) assert_same_dh dup_public(dh1024), key + key = OpenSSL::PKey.read(pem) + assert_same_dh dup_public(dh1024), key assert_equal asn1.to_der, dh1024.to_der assert_equal pem, dh1024.export diff --git a/test/openssl/utils.rb b/test/openssl/utils.rb index 3776fbac..c1d737b2 100644 --- a/test/openssl/utils.rb +++ b/test/openssl/utils.rb @@ -42,9 +42,6 @@ module OpenSSL::TestUtils def pkey(name) OpenSSL::PKey.read(read_file("pkey", name)) - rescue OpenSSL::PKey::PKeyError - # TODO: DH parameters can be read by OpenSSL::PKey.read atm - OpenSSL::PKey::DH.new(read_file("pkey", name)) end def read_file(category, name) |