3 # gpg-key2ps: convert a PGP/GnuPG key into paper slips.
4 # Copyright (C) 2001-2005 Simon Richter
5 # Copyright (C) 2005-2006 Thijs Kinkhorst
6 # Copyright (C) 2005-2006 Christoph Berg <cb@df7cb.de>
7 # Licenced under the GNU General Public License,
15 my $version = '$Rev$';
16 $version =~ s/\$Rev:\s*(\d+)\s*\$/$1/;
17 my $revokestyle = "hide";
18 my $creationdate = scalar(localtime);
22 print $fd "gpg-key2ps $version - (c) 2001-2006 Simon Richter, Thijs Kinkhorst, Christoph Berg\n";
26 my ($fd, $exitcode) = @_;
29 Usage: $0 [-p papersize] [-r revoked-style] keyid-or-name ...
33 hide - Don't show revoked uids (default)
34 grey - Print text in grey
35 note - Add "[revoked]"
36 show - List revoked uids normally
37 strike - Strike through lines
44 # fetch command line parameters
46 Getopt
::Long
::config
('bundling');
48 '-h' => \
$opts->{help
},
49 '--help' => \
$opts->{help
},
50 '-v' => \
$opts->{version
},
51 '--version' => \
$opts->{version
},
52 '-p=s' => \
$opts->{papersize
},
53 '--paper-size=s' => \
$opts->{papersize
},
54 '-r=s' => \
$opts->{revokestyle
},
55 '--revoked-style=s' => \
$opts->{revokestyle
},
64 if ($opts->{version
}) {
69 if ( $opts->{revokestyle
} ) { $revokestyle = $opts->{revokestyle
}; }
70 if ( $opts->{papersize
} ) { $ENV{'PAPERSIZE'} = $opts->{papersize
}; }
72 if ( $revokestyle !~ /^(grey|hide|note|show|strike)$/ ) {
73 print STDERR
"Unknown revoked-style \"$revokestyle\".\n";
77 usage
(\
*STDERR
, 1) unless scalar @ARGV >= 1;
79 # determine the paper size through the paperconf tool
81 if ( `which paperconf` && $?
== 0 ) {
88 print STDERR
"Warning: libpaper-utils is not installed, defaulting to A4.\n";
93 # open a gpg process we'll be reading from below
94 map { s/'/'\\''/g; } @ARGV; # quote single quotes
95 # --list-key due to #382794
96 open(GPG
, "gpg --list-key --with-fingerprint --with-colons '". (join "' '", @ARGV) ."' |");
98 sub start_postscript
{
99 # start the PostScript output
102 %%BoundingBox: 0 0 $w $h
104 %%Creator: gpg-key2ps $version
105 %%CreationDate: $creationdate
114 /Times-Roman findfont 9 scalefont setfont
122 w 2 div 30 sub y 3 add lineto stroke
127 /condhline { hline } def
135 << 1 (R) 2 (r) 3 (s) 16 (g) 20 (G) 17 (D) >> exch get
141 50 y moveto (pub) show
142 70 y moveto show showAlgorithm (/) show show
150 70 y moveto (Key fingerprint = ) show show
155 50 y moveto (uid) show
162 # output the desired display for revoked uids
163 if ( $revokestyle eq "grey" ) {
165 print " .5 setgray\n";
167 print " 0 setgray\n";
169 } elsif ( $revokestyle eq "note" ) {
171 print " 50 y moveto (uid) show\n";
172 print " 200 y moveto show ( [revoked]) show\n";
175 } elsif ( $revokestyle eq "show" ) {
176 print "/revuid { uid } def\n";
177 } elsif ( $revokestyle eq "strike" ) {
180 print " 45 y 9 add moveto h 2 div 45 sub y 18 add lineto stroke\n";
187 50 y moveto (sub) show
188 70 y moveto show showAlgorithm (/) show show
196 } # sub start_postscript
198 # walk the output of gpg line by line
199 # $numlines has the total number of lines so we'll know how many to put on page
204 if ( /^(tru|uat):/ ) { next; }
205 # every primary uid causes an extra line because of the separator
207 start_postscript
() unless $started;
212 s/^pub:[^:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:([^:]*):[^:]*:[^:]*:.*/ ($5) ($4) ($3) $2 ($1) pub/;
213 # fingerprint, format it nicely with spaces
214 if ( /^fpr:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ) {
217 $fpr =~ s/(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})/$1 $2 $3 $4 $5 $6 $7 $8 $9 $10/;
219 $fpr =~ s/(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})/$1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12 $13 $14 $15 $16/g;
220 $_ = " ($fpr) fpr\n";
223 s/^uid:[^:r]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ($1) uid/;
225 if (s/^uid:r[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ($1) revuid/) {
226 next if $revokestyle eq "hide";
229 s/^sub:[^:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:.*/ ($4) ($3) $2 ($1) sbk/;
237 print STDERR
"No public key found.\n";
241 # output the remaining postscript
245 /numlines $numlines def
246 /num w 16 sub 10 div numlines div def
252 0 0 h 2 div w rectclip
257 0 upper h 2 div upper h 2 div lower 0 lower 0 upper moveto lineto lineto lineto lineto stroke
282 B<gpg-key2ps> - generates a PS file from a GnuPG keyring
286 B<gpg-key2ps> [B<-r> I<revoked-style>] [B<-p> I<papersize>] I<keyid-or-name> [ I<...> ]
290 gpg-key2ps generates a PostScript file with your OpenPGP key fingerprint (repeated
291 as often as it fits) useful for keysigning parties. The only argument is the same
292 as you would pass to GPG's list-keys command, either a key-id or a (partial) name.
293 The PS data is written to stdout.
299 =item B<-p> B<--paper-size> I<paper-size>
301 Select the output paper size. Default is to look into /etc/papersize or A4 if
302 libpaper isn't installed.
304 =item B<-r> B<--revoked-style> I<revoked-style>
306 Select how to mark revoked UIDs. Five styles are available:
307 B<hide> don't show at all (default),
308 B<show> show normally,
309 B<grey> display in 50% grey,
310 B<note> add "[revoked]", and
311 B<strike> strike through.
315 Keyids to print. Multiple can be separated by spaces.
317 =item B<-h> B<--help>
319 Print usage and exit.
321 =item B<-v> B<--version>
323 Print version and exit.
332 http://pgp-tools.alioth.debian.org/
334 =head1 AUTHORS AND COPYRIGHT
336 (c) 2001 - 2005 Simon Richter <sjr@debian.org>
338 (c) 2005 Thijs Kinkhorst <thijs@kinkhorst.com>
340 (c) 2005 Christoph Berg <cb@df7cb.de>