3 # gpg-key2ps: convert a PGP/GnuPG key into paper slips.
4 # Copyright (C) 2001-2005 Simon Richter and Thijs Kinkhorst
5 # Licenced under the GNU General Public License,
13 my $version = '$Rev$';
14 $version =~ s/\$Rev:\s*(\d+)\s*\$/$1/;
15 my $usage = "Usage: $0 [-p papersize] [-r revoked-style] keyid-or-name\n";
17 my $revokestyle="hide";
24 # fetch command line parameters
27 if ( $opts{r
} ) { $revokestyle = $opts{'r'}; }
28 if ( $opts{p
} ) { $ENV{'PAPERSIZE'} = $opts{'p'}; }
29 foreach (@ARGV) { $keyids .= $_ . " "; }
31 if ( $revokestyle !~ /^(grey|hide|note|show|strike)$/ ) {
32 print STDERR
"Unknown style \"$revokestyle\". Please use one of\n";
33 print STDERR
" grey - Print text in grey\n";
34 print STDERR
" hide - Don't show revoked uids\n";
35 print STDERR
" note - Add \"(revoked)\"\n";
36 print STDERR
" show - List revoked uids normally\n";
37 print STDERR
" strike - Strike through lines\n";
41 # determine default papersize through the paperconf tool
43 if ( -x
"/usr/bin/paperconf" ) {
55 # can't check that accurately through the 'open' call below
56 # so have to run gpg twice). Please supply a better way.
57 if ( system( "gpg --fingerprint $keyids >/dev/null" ) != 0 ) {
58 print STDERR
"Key not found. Try 'gpg --list-keys'\n";
62 # open a gpg process we'll be reading from below
63 open(GPG
, "gpg --fingerprint --with-colons $keyids |");
65 # start the PostScript output
68 %%BoundingBox: 0 0 $w $h
70 %%Creator: gpg-key2ps $version
72 print "%%CreationDate: " . scalar(localtime) . "\n";
82 /Times-Roman findfont 9 scalefont setfont
90 w 2 div 30 sub y 3 add lineto stroke
95 /condhline { hline } def
103 << 1 (R) 2 (r) 3 (s) 16 (g) 20 (G) 17 (D) >> exch get
109 50 y moveto (pub) show
110 70 y moveto show showAlgorithm (/) show show
118 70 y moveto (Key fingerprint = ) show show
123 50 y moveto (uid) show
130 # output the desired display for revoked uids
131 if ( $revokestyle eq "grey" ) {
133 print " .5 setgray\n";
135 print " 0 setgray\n";
137 } elsif ( $revokestyle eq "hide" ) {
138 print "/revuid {} def\n";
139 } elsif ( $revokestyle eq "note" ) {
141 print " 50 y moveto (uid) show\n";
142 print " 200 y moveto show ([revoked]) show\n";
145 } elsif ( $revokestyle eq "show" ) {
146 print "/revuid { uid } def\n";
147 } elsif ( $revokestyle eq "strike" ) {
150 print " 45 y 9 add moveto h 2 div 45 sub y 18 add lineto stroke\n";
157 50 y moveto (sub) show
158 70 y moveto show showAlgorithm (/) show show
167 # walk the output of gpg line by line
168 # $numlines has the total number of lines so we'll know how many to put on page
172 if ( /^(tru|uat):/ ) { next; }
173 # every primary uid causes an extra line because of the separator
174 if ( /^pub:/ ) { $numlines++; }
176 s/^pub:[^:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:([^:]*):[^:]*:[^:]*:.*/ ($5) ($4) ($3) $2 ($1) pub/;
177 # fingerprint, format it nicely with spaces
178 if ( /^fpr:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ) {
181 $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/;
183 $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;
184 $_ = " ($fpr) fpr\n";
187 s/^uid:[^:r]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ($1) uid/;
188 s/^uid:[^:r]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ($1) uid/;
190 s/^uid:r[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ($1) revuid/;
192 s/^sub:[^:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:.*/ ($4) ($3) $2 ($1) sbk/;
199 # output the remaining postscript
204 print "/numlines $numlines def\n";
206 /num w 16 sub 10 div numlines div def
212 0 0 h 2 div w rectclip
217 0 upper h 2 div upper h 2 div lower 0 lower 0 upper moveto lineto lineto lineto lineto stroke
242 B<gpg-key2ps> - generates a PS file from a GnuPG keyring
246 B<gpg-key2ps> [-r I<revoked-style>] [-p I<papersize>] I<keyid>I<[> I<keyidI<[> I<...>I<]>>I<]>
250 gpg-key2ps generates a PostScript file with your OpenPGP key fingerprint (repeated
251 as often as it fits) useful for keysigning parties. The only argument is the same
252 as you would pass to GPG's list-keys command, either a key-id or a (partial) name.
253 The PS data is written to stdout.
259 =item -p I<paper-size>
261 Select the output paper size. Default is to look into /etc/papersize or A4 if
262 libpaper isn't installed.
264 =item -r I<revoked-style>
266 Select how to mark revoked UIDs. Five styles are available:
267 B<hide> (don't show at all),
268 B<show> (show normally),
269 B<grey> (display in 50% grey),
270 B<note> (add a note), and
271 B<strike> (strike through).
275 Keyid's to print. Multiple can be separated by spaces.
285 http://pgp-tools.alioth.debian.org/
287 =head1 AUTHORS AND COPYRIGHT
289 (c) 2001 - 2005 Simon Richter <sjr@debian.org>
291 (c) 2005 Thijs Kinkhorst <thijs@kinkhorst.com>