#!/usr/bin/perl -w # $Id: pks-list-fingerprints,v 1.3 2002/05/21 23:49:58 jason Exp jason $ # This takes pksclient index -f, gpg --with-fingerprint, or pgpring -f # input on stdin and prints keyids and fingerprints on stdout. # NB: gpg --with-fingerprint only displays fingerprints for revoked keys # (version 1.0.6, anyway) with my patch. (Of course, I had to patch # pgpring to make it print _any_ fingerprints.) Unpatched pks servers # may get some fingerprints and keyids wrong. # FUTURE: extract subkey fingerprints from pgpring -f listings? require "flush.pl"; $line = 0; # input line # $count = 0; # # of pub keys processed $fp_count = 0; # # of pub key fingerprints found $in_pub = 0; # already inside a pubkey? $last_line = ""; # copy of overshot ^pub line @lines = (); # stored input while () { $line++; next if (/^$/); # $/ (record separator) doesn't allow for REs (not even ^), so we # have to do this the hard way... if (/^pub/) { if (!$in_pub) { $in_pub = 1; push @lines, $_; } else { $last_line = $_; process(); @lines = (); push @lines, $last_line; $in_pub = 1; } } else { push @lines, $_; } } # while process(); # do final key flush (STDOUT); print STDERR "\n"; print STDERR "info: found $count key(s), $fp_count fingerprint(s)\n"; $runtime = time() - $^T; print STDERR "info: completed in $runtime second(s)\n\n"; # try to print some process status information... times() isn't enough. # for more data, use time(1) from the shell. # FIXME: make this optional and/or work on systems with different ps args? if (open (PS, "ps -uxwp $$|")) { while () { print STDERR "info: ps: $_"; } print STDERR "\n"; } ############################################################################### sub process { local $_; local ($keyid, $fp); # fingerprints may be unavailable... $fp = "unavailable"; $_ = $lines[0]; if (/^pub\s+(\w+)\/(\w+)/) { # pks/gpg output $keyid = $2; # short keyid $count++; } elsif (/^pub:(\w+):(\w+):(\w+):(\w+)/) { # pgpring/gpg --with-colons $keyid = $4; # long keyid $count++; } $_ = $lines[1]; if (/^ Key fingerprint = (.*)/) { # pks/gpg output $fp = $1; $fp_count++; $fp =~ s/ //g; # remove spaces } elsif (/^fpr:::::::::(\w+):/) { # pgpring/gpg --with-colons $fp = $1; $fp_count++; } print "$fp\t$keyid\n"; } # process() ###############################################################################