Add a changelog
[pgp-tools.git] / gpglist / gpglist
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # small script to show in an intuitive way who signed which of your user ids
6 #
7 # Copyright (c) 2004 Uli Martens <uli@youam.net>
8 # Copyright (c) 2005 Peter Palfrader <peter@palfrader.org>
9 # All rights reserved.
10 #
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
13 # are met:
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
19 # 3. The name of the author may not be used to endorse or promote products
20 # derived from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 =pod
34
35 =head1 NAME
36
37 gpglist -- show who signed which of your UIDs
38
39 =head1 SYNOPSIS
40
41 =over
42
43 =item B<gpglist> I<keyid>
44
45 =back
46
47 =head1 DESCRIPTION
48
49 B<gpglist> takes a keyid and creates a listing showing who signed your user IDs.
50
51 $ gpglist 6D8ABE71
52 +----- 1 Christoph Berg <cb@df7cb.de>
53 | +-- 2 Christoph Berg <cb@cs.uni-sb.de>
54 1 2
55 x 7929AB90F7AC3AF0 Martin Helas <mhelas@helas.net>
56 x x 29BE5D2268FD549F Martin Michlmayr <tbm@cyrius.com>
57 x 7DDB2B8DB4B462C5 Martin Wanke <mawan@mawan.de>
58
59 =head1 AUTHORS
60
61 =over
62
63 =item Uli Martens <uli@youam.net>
64
65 =item Peter Palfrader <peter@palfrader.org>
66
67 =back
68
69 =head1 WEBSITE
70
71 http://pgp-tools.alioth.debian.org/
72
73 =head1 SEE ALSO
74
75 gpgsigs(1), gpg(1), caff(1).
76
77 =cut
78
79 use strict;
80 use warnings;
81 use English;
82
83 my $key=shift @ARGV;
84 unless (defined $key) {
85 die "Usage: $PROGRAM_NAME <keyid>\n";
86 }
87
88 open SIGS, "gpg --fixed-list-mode --with-colons --list-sigs $key 2>/dev/null |"
89 or die "can't get gpg listing";
90
91 my $uid = "";
92 my @uids;
93 my %sigs;
94 my %rev;
95 my %ids;
96 my $longkey;
97 while (<SIGS>) {
98 if ( m/^uid:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):/ ) {
99 $uid = $1;
100 push @uids, $1;
101 next;
102 }
103 if ( m/^sig:[^:]*:[^:]*:[^:]*:([0-9A-F]*):[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):/ ) {
104 $ids{$1} = $2;
105 $sigs{$1}->{$uid} = "x" unless defined $sigs{$1}->{$uid};
106 next;
107 }
108 if ( m/^rev:[^:]*:[^:]*:[^:]*:([0-9A-F]*):/ ) {
109 $rev{$uid} = "x" if ($longkey eq $1);
110 $sigs{$1}->{$uid} = "R";
111 next;
112 }
113 if ( m/^uat:.:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):/ ) {
114 $uid = "Photo ID";
115 push @uids, $uid;
116 next;
117 }
118 if ( m/^pub:[^:]*:[^:]*:[^:]*:([^:]*):/ ) {
119 $longkey = $1;
120 next;
121 }
122 last if ( m/^(sub):/ );
123 next if ( m/^(fpr|tru|rvk):/ );
124 print STDERR "hi, i'm a bug. please report me to my owner\n";
125 die "input: $_, key: $key";
126 }
127 close SIGS;
128
129 # XXX: Add an option for this
130 my $c = 0;
131 @uids = grep { ! defined $rev{$uids[$c++]} } @uids;
132
133 my $n = scalar @uids -1;
134 for ( my $a=0; $a <= $n; $a++ ) {
135 printf "| " x ($a)
136 . "+--"
137 . "---" x ($n-$a)
138 . (defined $rev{$uids[$a]} ? "R" : " ")
139 . "%2i $uids[$a]\n", $a+1;
140 }
141
142 for ( my $a=0; $a <= $n; $a++ ) {
143 printf "%-2i ", $a+1;
144 }
145 print "\n";
146
147 for my $id (sort {$ids{$a} cmp $ids{$b}} keys %ids) {
148 print((defined $sigs{$id}->{$_} ? $sigs{$id}->{$_} : " ") . " ") for (@uids);
149 print $id." $ids{$id}\n";
150 }