Skip to content
Closed
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
3 changes: 2 additions & 1 deletion RSA.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ sub new_private_key {
return $proto->_new_private_key_pem($p_key_string, @rest);
}
elsif ( substr($p_key_string, 0, 1) eq "\x30" ) {
# ASN.1 SEQUENCE tag detected — likely DER-encoded private key.
croak "passphrase argument not supported for DER-encoded keys"
if @rest;
return $proto->_new_private_key_der($p_key_string);
}
else {
Expand Down
7 changes: 6 additions & 1 deletion t/der.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Test::More;
use MIME::Base64;
use Crypt::OpenSSL::RSA;

BEGIN { plan tests => 22 }
BEGIN { plan tests => 23 }

# --- Generate a key pair for testing ---

Expand Down Expand Up @@ -93,6 +93,11 @@ my $sig2 = $priv_from_der->sign($plaintext);
ok( $pub_from_x509_der->verify($plaintext, $sig2),
"signature from DER-loaded private key verifies" );

# Error: passphrase with DER key
eval { Crypt::OpenSSL::RSA->new_private_key($priv_der, "secret") };
like( $@, qr/passphrase.*not supported.*DER/,
"new_private_key croaks when passphrase given with DER key" );

# Error: DER-like data for private key
eval { Crypt::OpenSSL::RSA->new_private_key("\x30\x00") };
ok( $@, "new_private_key croaks on truncated DER data" );
Expand Down
Loading