Skip to content

Commit 867e5c0

Browse files
committed
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.
1 parent 1eb1366 commit 867e5c0

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

ext/openssl/ossl_pkey.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ ossl_pkey_new_from_data(int argc, VALUE *argv, VALUE self)
178178
OSSL_BIO_reset(bio);
179179
if ((pkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL)))
180180
goto ok;
181+
OSSL_BIO_reset(bio);
182+
if ((pkey = PEM_read_bio_Parameters(bio, NULL)))
183+
goto ok;
181184

182185
BIO_free(bio);
183186
ossl_raise(ePKeyError, "Could not parse PKey");

test/openssl/test_pkey_dh.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def test_DHparams
3636
EOF
3737
key = OpenSSL::PKey::DH.new(pem)
3838
assert_same_dh dup_public(dh1024), key
39+
key = OpenSSL::PKey.read(pem)
40+
assert_same_dh dup_public(dh1024), key
3941

4042
assert_equal asn1.to_der, dh1024.to_der
4143
assert_equal pem, dh1024.export

test/openssl/utils.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ module Fixtures
4242

4343
def pkey(name)
4444
OpenSSL::PKey.read(read_file("pkey", name))
45-
rescue OpenSSL::PKey::PKeyError
46-
# TODO: DH parameters can be read by OpenSSL::PKey.read atm
47-
OpenSSL::PKey::DH.new(read_file("pkey", name))
4845
end
4946

5047
def read_file(category, name)

0 commit comments

Comments
 (0)