#!/usr/bin/perl -w # $Id: pi,v 1.6 2004/02/19 19:39:04 jason Exp jason $ # lookup or get keys via pksclient index/get, putting all flags at # the end of the arg list and all search strings inside quotes, to keep # pksclient happy. also add 0x prefixes to keyids since keyservers and GPG # do not print them, but pksclient requires them. shorten 64b keyids to # 32b, since that's how pks indexes them. sub usage (*); $dbdir = $ENV{'pk'}; # pksclient needs path to key db die ("\$pk not set in envt.") if (!defined ($dbdir)); usage ("no arguments given") if (!defined(@ARGV)); $noconvert = 0; # attempt to convert hex-looking strings to keyids $action = "index"; # what to do with the key(s) while ($#ARGV >= 0) { $_ = shift @ARGV; if (/^-n/) { $noconvert = 1; } elsif (/^-g/) { $action = "get"; } elsif (/^-/) { s/^-//; push @flags, $_; #print "flags now @flags\n"; #debug } else { push @strings, $_; #print "strings now @strings\n"; #debug } } usage("no search strings given") if (!defined(@strings)); # GPG handles hex keyids with or without a 0x prefix, let's try to too... # single string? let the testing begin! multiple strings (for now) imply # name lookups. if (($#strings == 0) && (! $noconvert)) { $_ = $strings[0]; if ((! /^0x/) && ((length == 8) || length == 16) || (length == 40)) { tr/[0-9][A-F][a-f]//d; $strings[0] =~ s/^/0x/ if length == 0; } if (($strings[0] =~ /^0x/) && (length ($strings[0]) == 18)) { # convert (full) 64b keyids to 32b $strings[0] =~ s/^0x......../0x/; } elsif (($strings[0] =~ /^0x/) && (length ($strings[0]) == 42)) { # convert a v4 fingerprint (SHA-1 hash) into a keyid $strings[0] =~ s/^0x................................/0x/; } } $flags = "-" . join ("", @flags); # OK, run it... $cmd = "pksclient $dbdir $action \"@strings\" $flags"; #print "$0: system($cmd)\n"; #debug system ($cmd); ############################################################################### sub usage (*) { local ($msg) = @_; print "usage: $0 [-n] [-g] \n"; print " where: -n == noconvert, don't try to interpret strings as"; print " hex keyids\n"; print " -g == get, perform a 'get' instead of an 'index'\n"; print " error: $msg\n"; exit (1); } # usage() ###############################################################################