Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions RSA.xs
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,10 @@ get_private_key_pkcs8_string(p_rsa, passphrase_SV=&PL_sv_undef, cipher_name_SV=&
char* cipher_name;
const EVP_CIPHER* enc = NULL;
CODE:
if (!_is_private(p_rsa))
{
croak("Public keys cannot export private key strings");
}
if (SvPOK(cipher_name_SV) && !SvPOK(passphrase_SV)) {
croak("Passphrase is required for cipher");
}
Expand Down
6 changes: 5 additions & 1 deletion t/format.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use Crypt::OpenSSL::Guess qw(openssl_version);

my ($major, $minor, $patch) = openssl_version();

BEGIN { plan tests => 56 }
BEGIN { plan tests => 57 }

my $PRIVATE_KEY_STRING = <<EOF;
-----BEGIN RSA PRIVATE KEY-----
Expand Down Expand Up @@ -130,6 +130,10 @@ eval { $pub_only->get_private_key_string() };
like($@, qr/Public keys cannot export private key strings/,
"get_private_key_string croaks on public-only key");

eval { $pub_only->get_private_key_pkcs8_string() };
like($@, qr/Public keys cannot export private key strings/,
"get_private_key_pkcs8_string croaks on public-only key");

# --- Error: wrong passphrase on re-import ---

my $encrypted_pem = $private_key->get_private_key_string($passphrase, 'aes-128-cbc');
Expand Down
Loading