Skip to content

Commit

Permalink
pkey: have PKey.read parse PEM-encoded DHParameter
Browse files Browse the repository at this point in the history
Try PEM_read_bio_Parameters(). Only PEM format is supported at the
moment since corresponding d2i_* functions are not provided by OpenSSL.
  • Loading branch information
rhenium committed May 13, 2020
1 parent 1eb1366 commit 867e5c0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ext/openssl/ossl_pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions test/openssl/test_pkey_dh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def test_DHparams
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
Expand Down
3 changes: 0 additions & 3 deletions test/openssl/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ module Fixtures

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)
Expand Down

0 comments on commit 867e5c0

Please sign in to comment.