Skip to content

Commit c48bb75

Browse files
authored
Merge pull request #847 from rhenium/ky/pkey-export-check-public
pkey: avoid calling i2d_PUBKEY family on an incomplete key
2 parents 7edb8b3 + 5aeed93 commit c48bb75

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

ext/openssl/ossl_pkey.c

+1
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,7 @@ ossl_pkey_export_spki(VALUE self, int to_der)
807807
BIO *bio;
808808

809809
GetPKey(self, pkey);
810+
ossl_pkey_check_public_key(pkey);
810811
bio = BIO_new(BIO_s_mem());
811812
if (!bio)
812813
ossl_raise(ePKeyError, "BIO_new");

test/openssl/test_pkey_dsa.rb

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ def test_new_break
2828
end
2929
end
3030

31+
def test_new_empty
32+
key = OpenSSL::PKey::DSA.new
33+
assert_nil(key.p)
34+
assert_raise(OpenSSL::PKey::PKeyError) { key.to_der }
35+
end
36+
3137
def test_generate
3238
# DSA.generate used to call DSA_generate_parameters_ex(), which adjusts the
3339
# size of q according to the size of p

0 commit comments

Comments
 (0)