summaryrefslogtreecommitdiff
path: root/src/keytrans
diff options
context:
space:
mode:
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>2009-02-28 15:55:10 -0500
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>2009-02-28 15:55:10 -0500
commit375c864f9b89cb8f8923dfcb7a9ba2e783a244da (patch)
tree44f669465f014aa65de549b9a129b86a0e68e63c /src/keytrans
parent3cc809546f716f93be416f2f3edd9e06ea17a547 (diff)
start to make an openpgp2ssh implementation within pem2openpgp.
Diffstat (limited to 'src/keytrans')
-rwxr-xr-xsrc/keytrans/pem2openpgp45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/keytrans/pem2openpgp b/src/keytrans/pem2openpgp
index 4dda6ca..9b7d8f6 100755
--- a/src/keytrans/pem2openpgp
+++ b/src/keytrans/pem2openpgp
@@ -509,6 +509,45 @@ sub pem2openpgp {
}
+
+
+sub openpgp2ssh {
+ my $instr = shift;
+ my $fpr = shift;
+
+ my $packettag;
+ read($instr, $packettag, 1);
+ $packettag = ord($packettag);
+
+ my $packetlen;
+ if ( ! (0x80 & $packettag)) {
+ print STDERR "This is not an OpenPGP packet";
+ exit 1;
+ }
+ if (0x40 & $packettag) {
+ print STDERR "This is a new-style packet header";
+ $tag = (0x3f & $packettag);
+ } else {
+ print STDERR "This is an old-style packet header";
+ $lentype = 0x03 & $packettag;
+ $tag = (0x3c & $packettag ) >> 2;
+ if ($lentype == 0) {
+ read($instr, $packetlen, 1);
+ $packetlen = unpack('%C', $packetlen);
+ } elsif ($lentype == 1) {
+ read($instr, $packetlen, 2);
+ $packetlen = unpack('%S', $packetlen);
+ } elsif ($lentype == 2) {
+ read($instr, $packetlen, 4);
+ $packetlen = unpack('%L', $packetlen);
+ }
+ }
+ printf(STDERR, "Packet is %d long\n", $packetlen);
+
+ print $packettag;
+}
+
+
for (basename($0)) {
if (/^pem2openpgp$/) {
@@ -539,7 +578,11 @@ for (basename($0)) {
);
}
elsif (/^openpgp2ssh$/) {
- print STDERR "woo\n";
+ my $fpr = shift;
+ my $instream;
+ open($instream,'-');
+ binmode($instream, ":bytes");
+ openpgp2ssh($instream, $fpr);
}
else {
print STDERR "Unrecognized keytrans call.\n";