Skip to content

Commit

Permalink
Merge pull request #847 from rhenium/ky/pkey-export-check-public
Browse files Browse the repository at this point in the history
pkey: avoid calling i2d_PUBKEY family on an incomplete key
  • Loading branch information
rhenium authored Jan 29, 2025
2 parents 7edb8b3 + 5aeed93 commit c48bb75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions ext/openssl/ossl_pkey.c
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ ossl_pkey_export_spki(VALUE self, int to_der)
BIO *bio;

GetPKey(self, pkey);
ossl_pkey_check_public_key(pkey);
bio = BIO_new(BIO_s_mem());
if (!bio)
ossl_raise(ePKeyError, "BIO_new");
Expand Down
6 changes: 6 additions & 0 deletions test/openssl/test_pkey_dsa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def test_new_break
end
end

def test_new_empty
key = OpenSSL::PKey::DSA.new
assert_nil(key.p)
assert_raise(OpenSSL::PKey::PKeyError) { key.to_der }
end

def test_generate
# DSA.generate used to call DSA_generate_parameters_ex(), which adjusts the
# size of q according to the size of p
Expand Down

0 comments on commit c48bb75

Please sign in to comment.