]>
git.sthu.org Git - pgp-tools.git/blob - gpgsigs/gpgsigs
5 # See the pod documentation at the end of this file for author,
6 # copyright, and licence information.
9 # libintl-perl (Locale::Recode)
10 # OR libtext-iconv-perl (Text::Iconv),
11 # OR the "recode" binary
16 # * use the user's normal keyring to find signatures
17 # * support for multiple user keys
18 # * better charset conversion
21 my $VERSION = qq$Rev$;
35 gpgsigs $VERSION- http://pgp-tools.alioth.debian.org/
36 (c) 2004 Uli Martens <uli\@youam.net>
37 (c) 2004, 2005 Peter Palfrader <peter\@palfrader.org>
38 (c) 2004, 2005 Christoph Berg <cb\@df7cb.de>
44 my ($fd, $error) = @_;
49 Usage: $PROGRAM_NAME [-r] [-t <charset>] <keyid> <keytxt> [<outfile>]
51 keyid is a long or short keyid (e.g. DE7AAF6E94C09C7F or 94C09C7F)
52 separate multiple keyids with ','
53 -r call gpg --recv-keys before proceeding
54 -f <charset> convert <keytxt> from charset
55 -t <charset> convert UIDs to charset in output
61 my ($fromcharset, $charset, $recv_keys);
66 help
=> sub { usage
(*STDOUT
, 0); },
67 version
=> sub { version
(*STDOUT
); exit 0;},
68 ) or usage
(*STDERR
, 1);
72 $fromcharset ||= "ISO-8859-1";
73 $charset ||= $ENV{LC_ALL
} || $ENV{LC_CTYPE
} || $ENV{LANG
} || "ISO-8859-1";
74 $charset = "ISO-8859-1" unless $charset =~ /[\.-]/;
78 my ($rf, $rt, $if, $it);
79 if (eval "require Locale::Recode") {
80 $rf = Locale
::Recode
->new (from
=> $fromcharset, to
=> $charset) if $fromcharset;
81 $rt = Locale
::Recode
->new (from
=> 'UTF-8', to
=> $charset);
82 } elsif (eval "require Text::Iconv") {
83 $if = Text
::Iconv
->new($fromcharset, $charset) if $fromcharset;
84 $it = Text
::Iconv
->new("UTF-8", $charset);
93 } elsif (defined $if) {
94 return $if->convert($text);
96 my $pid = open3
(\
*WTRFH
, \
*RDRFH
, \
*ERRFH
, 'recode', "$fromcharset..$charset");
100 my $result = <RDRFH
>;
104 die ("'recode' failed, is it installed?\n") unless defined $result;
115 } elsif (defined $it) {
116 my $result = $it->convert($text);
117 warn ("Could not convert '$text'\n") unless defined $result;
118 return (defined $result) ?
$result : $text
120 my $pid = open3
(\
*WTRFH
, \
*RDRFH
, \
*ERRFH
, 'recode', "utf8..$charset");
124 my $result = <RDRFH
>;
128 warn ("'recode' failed, is it installed?\n") unless defined $result;
129 return (defined $result) ?
$result : $text
135 my $mykey = uc(shift @ARGV);
136 my $keytxt = (shift @ARGV) || usage
(*STDERR
, 1);
137 my $outfile = (shift @ARGV) || '-';
139 my @mykeys = split /,/, $mykey;
140 map { s/^0x//i; } @mykeys;
142 if (!@mykeys || scalar @ARGV) {
145 if (!grep { /^([0-9A-F]{16,16}|[0-9A-F]{8,8})$/ } @mykeys) {
146 print STDERR
"Invalid keyid given\n";
150 -r
$keytxt or die ("$keytxt does not exist\n");
153 # get list of keys in file
155 open (TXT
, $keytxt) or die ("Cannot open $keytxt\n");
157 if ( m/^pub +(?:\d+)[DR]\/([0-9A
-F
]{8}) [0-9]{4}-[0-9]{2}-[0-9]{2} *(.*)/ ) {
164 # get all known signatures
166 print STDERR
"Requesting keys from keyserver\n";
167 system "gpg --recv-keys @keys";
170 print STDERR
"Running --list-sigs, this will take a while ";
171 open SIGS
, "gpg --fixed-list-mode --with-colons --list-sigs @keys 2>/dev/null |"
172 or die "can't get gpg listing";
174 my ($key, $uid, $sigs);
176 if ( m/^pub:(?:.*?:){3,3}([0-9A-F]{16,16}):/ ) {
181 if ( m/^uid:(?:.*?:){8,8}(.*):/s ) {
185 if ( m/^sig:(?:.*?:){3,3}([0-9A-F]{8})([0-9A-F]{8}):(?:.*?:){3,3}(.*):.*?:/ ) {
186 $sigs->{$key}->{$uid}->{$1.$2} = $3;
187 $sigs->{$key}->{$uid}->{$2} = $3;
194 next if ( m/^(rev|sub|tru):/ );
195 warn "unknown value: '$_', key: ".(defined $key ?
$key :'none')."\n";
200 for my $k ( keys %{$sigs} ) {
201 if ( $k =~ m/^[0-9A-F]{8}([0-9A-F]{8})$/ ) {
202 $sigs->{$1} = $sigs->{$k};
208 open MD
, "gpg --print-md md5 $keytxt|" or warn "can't get gpg md5\n";
211 open MD
, "gpg --print-md sha1 $keytxt|" or warn "can't get gpg sha1\n";
217 my $metatxt = quotemeta($keytxt);
218 $MD5 =~ s/^$metatxt:\s*//;
219 $SHA1 =~ s/^$metatxt:\s*//;
225 my ($key, $uid) = @_;
226 if (! defined $sigs->{$key}->{$uid}) {
227 warn "uid '$uid' not found on key $key\n";
228 return '(' . (' ' x
@mykeys) . ')';
231 foreach my $mykey (@mykeys) {
232 $r .= defined $sigs->{$key}->{$uid}->{$mykey} ?
"S" : " ";
238 print STDERR
"Annotating $keytxt, writing into $outfile\n";
239 open (TXT
, $keytxt) or die ("Cannot open $keytxt\n");
240 open (WRITE
, '>'.$outfile) or die ("Cannot open $outfile for writing\n");
242 $_ = myfromrecode
($_);
243 if (/^MD5 Checksum:/ && defined $MD5) {
244 s/[_[:xdigit:]][_ [:xdigit:]]+_/$MD5/;
246 if (/^SHA1 Checksum:/ && defined $SHA1) {
247 s/[_[:xdigit:]][_ [:xdigit:]]+_/$SHA1/;
249 if ( m/^pub +(?:\d+)[DR]\/([0-9A
-F
]{8}) [0-9]{4}-[0-9]{2}-[0-9]{2} *(.*)/ ) {
252 #if ($uid) { # in gpg 1.2, the first uid is here
253 # print WRITE print_tag($key, $uid) . " $_";
257 if ( m/^uid +(.*)$/ ) {
259 die "key is undefined" unless defined $key;
260 die "uid is undefined, key $key" unless defined $uid;
261 die "bad tag from $key | $uid" unless defined (print_tag
($key, $uid));
262 print WRITE print_tag
($key, $uid) . " $_";
268 print WRITE
"Legend:\n";
269 foreach my $i (0 .. @mykeys - 1) {
270 print WRITE
'('. ' 'x
$i . 'S' . ' 'x
(@mykeys-$i-1) . ") signed with $mykeys[$i]\n";
278 B<gpgsigs> - annotate list of GnuPG keys with already done signatures
282 B<gpgsigs> [-r] [-f I<charset>] [-t I<charset>] I<keyid>I<[>B<,>I<keyidI<[>B<,>I<...>I<]>>I<]> F<keytxt> [F<outfile>]
286 B<gpgsigs> was written to assist the user in signing keys during a keysigning
287 party. It takes as input a file containing keys in C<gpg --list-keys> format
288 and prepends every line with a tag indicating if the user has already signed
289 that uid. When the file contains C<MD5 Checksum:> or C<SHA1 Checksum:> lines
290 and placeholders (C<__ __>), the checksum is inserted.
298 Call I<gpg --recv-keys> before creating the output.
302 Convert F<keytxt> from I<charset>. The default is ISO-8859-1.
306 Convert UIDs to I<charset>. The default is derived from LC_ALL, LC_CTYPE, and
307 LANG, and if all these are unset, the default is ISO-8859-1.
311 Use this keyid (8 or 16 byte) for annotation. Multiple keyids can be separated
316 Read input from F<keytxt>.
320 Write output to F<outfile>. Default is stdout.
326 The following key signing parties are using B<gpgsigs>:
328 http://www.palfrader.org/ksp-lt2k4.html
330 http://www.palfrader.org/ksp-lt2k5.html
334 B<GnuPG> is known to change its output format quite often. This version has
335 been tested with gpg 1.2.5 and gpg 1.4.1. YMMV.
341 http://pgp-tools.alioth.debian.org/
343 =head1 AUTHORS AND COPYRIGHT
345 (c) 2004 Uli Martens <uli@youam.net>
347 (c) 2004, 2005 Peter Palfrader <peter@palfrader.org>
349 (c) 2004, 2005 Christoph Berg <cb@df7cb.de>
355 Redistribution and use in source and binary forms, with or without
356 modification, are permitted provided that the following conditions
359 1. Redistributions of source code must retain the above copyright
360 notice, this list of conditions and the following disclaimer.
362 2. Redistributions in binary form must reproduce the above copyright
363 notice, this list of conditions and the following disclaimer in the
364 documentation and/or other materials provided with the distribution.
366 3. The name of the author may not be used to endorse or promote products
367 derived from this software without specific prior written permission.
369 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
370 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
371 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
372 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
373 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
374 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
375 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
376 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
377 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
378 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.