3 # Copyright (c) 2004 Uli Martens <uli@youam.net>
4 # Copyright (c) 2004 Peter Palfrader <peter@palfrader.org>
5 # Copyright (c) 2004 Christoph Berg <cb@df7cb.de>
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
12 # 1. Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # 2. Redistributions in binary form must reproduce the above copyright
15 # notice, this list of conditions and the following disclaimer in the
16 # documentation and/or other materials provided with the distribution.
17 # 3. The name of the author may not be used to endorse or promote products
18 # derived from this software without specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 # libintl-perl (Locale::Recode)
35 # OR libtext-iconv-perl (Text::Iconv),
36 # OR the "recode" binary
41 use File
::Temp
qw{tempdir
};
47 if (eval "require Locale::Recode") {
48 $r = Locale
::Recode
->new (from
=> 'UTF-8',
50 } elsif (eval "require Text::Iconv") {
51 $i = Text
::Iconv
->new("UTF-8", "ISO-8859-1");
59 #printf STDERR "perl: $orig to $text\n";
61 } elsif (defined $i) {
62 $text = $i->convert($text);
64 my $pid = open3
(\
*WTRFH
, \
*RDRFH
, \
*ERRFH
, 'recode', 'utf8..iso8859-1');
73 die ("'recode' failed, is it installed?\n") unless defined $result;
74 #printf STDERR "manual: $text to $result\n";
80 my $EXPECTED_MD5 = '90 43 B8 1B';
82 my $mykey = uc(shift @ARGV);
83 my $keyring = shift @ARGV;
84 my $keytxt = shift @ARGV;
85 my $outfile = shift @ARGV;
87 $keyring = 'ksp-lt2k4.asc' unless defined $keyring;
88 $keytxt = 'ksp-lt2k4.txt' unless defined $keytxt;
89 $outfile = 'ksp-lt2k4-annotated.txt' unless defined $outfile;
91 if (!defined $mykey || scalar @ARGV || ($mykey !~ /^[0-9A-F]{16,16}$/ && $mykey !~ /^[0-9A-F]{8,8}$/)) {
92 print STDERR
"Usage: $PROGRAM_NAME keyid [<keyring> [<keytxt> [<outfile]]]\n";
94 print STDERR
"keyid is a long or short keyid (e.g. DE7AAF6E94C09C7F or 94C09C7F\n";
98 -r
$keyring or die ("$keyring does not exist\n");
99 -r
$keytxt or die ("$keytxt does not exist\n");
105 my $tempdir = tempdir
( "gpgsigs-XXXXX", DIR
=> '/tmp/', CLEANUP
=> 1);
106 $ENV{'GNUPGHOME'} = $tempdir;
107 print STDERR
"Creating a temporary gnupghome and importing keys\n";
108 system(qw{gpg
--import
}, $keyring);
110 print STDERR
"Running --list-sigs, this will take a while\n";
111 open SIGS
, "gpg --fixed-list-mode --with-colons --list-sigs 2>/dev/null |"
112 or die "can't get gpg listing";
117 if ( m/^pub:(?:.*?:){3,3}([0-9A-F]{16,16}):/ ) {
121 if ( m/^uid:(?:.*?:){8,8}(.*):/ ) {
123 $uid = myrecode
($uid);
126 if ( m/^sig:(?:.*?:){3,3}([0-9A-F]{8})([0-9A-F]{8}):(?:.*?:){3,3}(.*):.*?:/ ) {
127 $sigs->{$key}->{$uid}->{$1.$2} = $3;
128 $sigs->{$key}->{$uid}->{$2} = $3;
135 next if ( m/^(rev|sub|tru):/ );
136 warn "unknown value: '$_', key: ".(defined $key ?
$key :'none')."\n";
140 for my $k ( keys %{$sigs} ) {
141 if ( $k =~ m/^[0-9A-F]{8}([0-9A-F]{8})$/ ) {
142 $sigs->{$1} = $sigs->{$k};
147 open MD
, "gpg --print-md md5 $keytxt|" or warn "can't get gpg md5";
150 open MD
, "gpg --print-md sha1 $keytxt|" or warn "can't get gpg sha1";
156 my $metatxt = quotemeta($keytxt);
157 $MD5 =~ s/^$metatxt:\s*//;
158 $SHA1 =~ s/^$metatxt:\s*//;
161 warn ("md5 of $keytxt does not begin with $EXPECTED_MD5") unless ($MD5 =~ /^$EXPECTED_MD5/);
164 print STDERR
"Annotating $keytxt, writing into $outfile\n";
165 open (TXT
, $keytxt) or die ("Cannot open $keytxt\n");
166 open (WRITE
, '>'.$outfile) or die ("Cannot open $outfile for writing\n");
168 if (/^MD5 Checksum: __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __/ && defined $MD5) {
169 print WRITE
"MD5 Checksum: $MD5 [ ]\n";
171 elsif (/^SHA1 Checksum: ____ ____ ____ ____ ____ ____ ____ ____ ____ ____/ && defined $SHA1) {
172 print WRITE
"SHA1 Checksum: $SHA1 [ ]\n";
176 if ( m/^([0-9]{3}) \[ \] Fingerprint OK \[ \] ID OK$/ ) {
178 if ( m/^pub ( 768|1024|2048|4096)[DR]\/([0-9A
-F
]{8}) [0-9]{4}-[0-9]{2}-[0-9]{2} (.*)/ ) {
182 if ( ! defined $sigs->{$keyid}->{$uid} ) {
183 warn "uid '$uid' not found on key $keyid";
185 print WRITE
( defined $sigs->{$keyid}->{$uid}->{$mykey} ?
"(S)" : "( )" );
191 if ( m/^uid (.*)$/ ) {
192 print WRITE
defined $sigs->{$keyid}->{$1}
193 ?
( defined $sigs->{$keyid}->{$1}->{$mykey} ?
"(S)" : "( )" )