Ignore revoked UIDs
[pgp-tools.git] / gpglist / gpglist
1 #!/usr/bin/perl
2
3 # small script to show in an intuitive way who signed which of your user ids
4 #
5 # Copyright (c) 2004 Uli Martens <uli@youam.net>
6 # Copyright (c) 2005 Peter Palfrader <peter@palfrader.org>
7 # All rights reserved.
8 #
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
11 # are met:
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.
19 #
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.
30
31 use strict;
32 use warnings;
33
34 my $key=shift @ARGV;
35 if ( $key eq "" ) {
36 die
37 }
38
39 open SIGS, "gpg --fixed-list-mode --with-colons --list-sigs $key 2>/dev/null |"
40 or die "can't get gpg listing";
41
42 my $uid = "";
43 my @uids;
44 my %sigs;
45 my %rev;
46 my %ids;
47 my %unknownID;
48 my $longkey;
49 while (<SIGS>) {
50 if ( m/^uid:.:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:(.*):$/ ) {
51 $uid = $1;
52 push @uids, $1;
53 next;
54 }
55 if ( m/^sig:[^:]*:[^:]*:[^:]*:([0-9A-F]*):[^:]*:[^:]*:[^:]*:[^:]*:(.*):[^:]*:$/ ) {
56 $2 eq "[User id not found]" ? $unknownID{$1} = $1 : $ids{$2} = $1;
57 $sigs{$1}->{$uid} = "x" unless defined $sigs{$1}->{$uid};
58 next;
59 }
60 if ( m/^rev:[^:]*:[^:]*:[^:]*:([0-9A-F]*):[^:]*:[^:]*:[^:]*:[^:]*:(.*):[^:]*:$/ ) {
61 $rev{$uid} = "x" if ($longkey eq $1);
62 $sigs{$1}->{$uid} = "R";
63 next;
64 }
65 if ( m/^uat:.:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:(.*):$/ ) {
66 $uid = "Photo ID";
67 push @uids, $uid;
68 next;
69 }
70 if ( m/^pub:[^:]*:[^:]*:[^:]*:([^:]*):[^:]*:[^:]*:[^:]*:[^:]*:(.*):$/ ) {
71 $longkey = $1;
72 next;
73 }
74 last if ( m/^(sub):/ );
75 next if ( m/^(tru):/ );
76 print STDERR "hi, i'm a bug. please report me to my owner";
77 die "input: $_, key: $key";
78 }
79 close SIGS;
80
81 # XXX: Add an option for this
82 my $c = 0;
83 @uids = grep { ! defined $rev{$uids[$c++]} } @uids;
84
85 my $n = scalar @uids -1;
86 for ( my $a=0; $a <= $n; $a++ ) {
87 printf "| " x ($a)
88 . "+--"
89 . "---" x ($n-$a)
90 . (defined $rev{$uids[$a]} ? "R" : " ")
91 . "%2i $uids[$a]\n", $a+1;
92 }
93
94 for ( my $a=0; $a <= $n; $a++ ) {
95 printf "%-2i ", $a+1;
96 }
97 print "\n";
98
99 for my $id (sort keys %ids) {
100 print((defined $sigs{$ids{$id}}->{$_} ? $sigs{$ids{$id}}->{$_} : " ") . " ") for (@uids);
101 print $ids{$id}." $id\n";
102 }
103 for my $id (sort keys %unknownID) {
104 print((defined $sigs{$id}->{$_} ? $sigs{$id}->{$_} : " ") . " ") for (@uids);
105 print "$id [User id not found]\n";
106 }