summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>2009-02-28 14:22:22 -0500
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>2009-02-28 14:22:22 -0500
commit3cc809546f716f93be416f2f3edd9e06ea17a547 (patch)
tree3c208e4c873d50c4a5e47f50f3ff3eeb5eb45b4a /src
parentb08a2e207f22000b494fc1aabe413bea5eb8f7d5 (diff)
make pem2openpgp closer to a generic keytrans so that we can reuse it for the openpgp2ssh replacement.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/keytrans/pem2openpgp55
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;
+ }
+}