diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/keytrans/pem2openpgp | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/src/keytrans/pem2openpgp b/src/keytrans/pem2openpgp index 4e6ebe7..4dda6ca 100755 --- a/src/keytrans/pem2openpgp +++ b/src/keytrans/pem2openpgp @@ -23,6 +23,7 @@ use strict; use warnings; +use File::Basename; use Crypt::OpenSSL::RSA; use Crypt::OpenSSL::Bignum; use Crypt::OpenSSL::Bignum::CTX; @@ -508,29 +509,41 @@ sub pem2openpgp { } -my $rsa; -my $stdin; -if (defined $ENV{PEM2OPENPGP_NEWKEY}) { - $rsa = Crypt::OpenSSL::RSA->generate_key($ENV{PEM2OPENPGP_NEWKEY}); -} else { - $stdin = do { - local $/; # slurp! - <STDIN>; - }; +for (basename($0)) { + if (/^pem2openpgp$/) { - $rsa = Crypt::OpenSSL::RSA->new_private_key($stdin); -} + my $rsa; + my $stdin; + if (defined $ENV{PEM2OPENPGP_NEWKEY}) { + $rsa = Crypt::OpenSSL::RSA->generate_key($ENV{PEM2OPENPGP_NEWKEY}); + } else { + $stdin = do { + local $/; # slurp! + <STDIN>; + }; + + $rsa = Crypt::OpenSSL::RSA->new_private_key($stdin); + } -my $uid = shift; + my $uid = shift; -# FIXME: fail if there is no given user ID; or should we default to -# hostname_long() from Sys::Hostname::Long ? + # FIXME: fail if there is no given user ID; or should we default to + # hostname_long() from Sys::Hostname::Long ? -print pem2openpgp($rsa, - $uid, - { timestamp => $ENV{PEM2OPENPGP_TIMESTAMP}, - expiration => $ENV{PEM2OPENPGP_EXPIRATION}, - usage_flags => $ENV{PEM2OPENPGP_USAGE_FLAGS}, - } - ); + print pem2openpgp($rsa, + $uid, + { timestamp => $ENV{PEM2OPENPGP_TIMESTAMP}, + expiration => $ENV{PEM2OPENPGP_EXPIRATION}, + usage_flags => $ENV{PEM2OPENPGP_USAGE_FLAGS}, + } + ); + } + elsif (/^openpgp2ssh$/) { + print STDERR "woo\n"; + } + else { + print STDERR "Unrecognized keytrans call.\n"; + die 1; + } +} |