mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/openssl] 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.
867e5c021b
This commit is contained in:
parent
c157f6e787
commit
efad0166c6
Notes:
git
2021-03-16 20:38:54 +09:00
3 changed files with 5 additions and 3 deletions
|
@ -178,6 +178,9 @@ ossl_pkey_new_from_data(int argc, VALUE *argv, VALUE self)
|
||||||
OSSL_BIO_reset(bio);
|
OSSL_BIO_reset(bio);
|
||||||
if ((pkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL)))
|
if ((pkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL)))
|
||||||
goto ok;
|
goto ok;
|
||||||
|
OSSL_BIO_reset(bio);
|
||||||
|
if ((pkey = PEM_read_bio_Parameters(bio, NULL)))
|
||||||
|
goto ok;
|
||||||
|
|
||||||
BIO_free(bio);
|
BIO_free(bio);
|
||||||
ossl_raise(ePKeyError, "Could not parse PKey");
|
ossl_raise(ePKeyError, "Could not parse PKey");
|
||||||
|
|
|
@ -36,6 +36,8 @@ class OpenSSL::TestPKeyDH < OpenSSL::PKeyTestCase
|
||||||
EOF
|
EOF
|
||||||
key = OpenSSL::PKey::DH.new(pem)
|
key = OpenSSL::PKey::DH.new(pem)
|
||||||
assert_same_dh dup_public(dh1024), key
|
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 asn1.to_der, dh1024.to_der
|
||||||
assert_equal pem, dh1024.export
|
assert_equal pem, dh1024.export
|
||||||
|
|
|
@ -42,9 +42,6 @@ module OpenSSL::TestUtils
|
||||||
|
|
||||||
def pkey(name)
|
def pkey(name)
|
||||||
OpenSSL::PKey.read(read_file("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
|
end
|
||||||
|
|
||||||
def read_file(category, name)
|
def read_file(category, name)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue