3 # gpg-key2ps: convert a PGP/GnuPG key into paper slips.
4 # Copyright (C) 2001-2005 Simon Richter
5 # Copyright (C) 2005-2007 Thijs Kinkhorst
6 # Copyright (C) 2005-2008 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";
19 my $creationdate = scalar(localtime);
23 print $fd "gpg-key2ps $version - (c) 2001-2008 Simon Richter, Thijs Kinkhorst, Christoph Berg\n";
27 my ($fd, $exitcode) = @_;
30 Usage: $0 [-p papersize] [-r revoked-style] [-1] keyid-or-name ...
34 hide - Don't show revoked uids and subkeys (default)
35 grey - Print text in grey
36 note - Add "[revoked]"
37 show - List revoked uids normally
38 strike - Strike through lines
39 -1 Only print one column, for extra wide keys
46 # fetch command line parameters
48 Getopt
::Long
::config
('bundling');
50 '-h' => \
$opts->{help
},
51 '--help' => \
$opts->{help
},
52 '-v' => \
$opts->{version
},
53 '--version' => \
$opts->{version
},
54 '-p=s' => \
$opts->{papersize
},
55 '--paper-size=s' => \
$opts->{papersize
},
56 '-r=s' => \
$opts->{revokestyle
},
57 '--revoked-style=s' => \
$opts->{revokestyle
},
67 if ($opts->{version
}) {
72 if ( $opts->{revokestyle
} ) { $revokestyle = $opts->{revokestyle
}; }
73 if ( $opts->{papersize
} ) { $ENV{'PAPERSIZE'} = $opts->{papersize
}; }
75 if ( $revokestyle !~ /^(grey|hide|note|show|strike)$/ ) {
76 print STDERR
"Unknown revoked-style \"$revokestyle\".\n";
80 if ( $opts->{1} ) { $columns = 1; }
82 usage
(\
*STDERR
, 1) unless scalar @ARGV >= 1;
84 # determine the paper size through the paperconf tool
86 if ( `which paperconf` && $?
== 0 ) {
93 print STDERR
"Warning: libpaper-utils is not installed, defaulting to A4.\n";
98 # open a gpg process we'll be reading from below
99 map { s/'/'\\''/g; } @ARGV; # quote single quotes
100 # --list-key due to #382794
101 open(GPG
, "gpg --list-key --with-fingerprint --with-colons '". (join "' '", @ARGV) ."' |");
103 sub start_postscript
{
104 # start the PostScript output
107 %%BoundingBox: 0 0 $w $h
109 %%Creator: gpg-key2ps $version
110 %%CreationDate: $creationdate
119 /Times-Roman findfont 9 scalefont setfont
127 w $columns div 30 sub y 3 add lineto stroke
132 /condhline { hline } def
140 << 1 (R) 2 (r) 3 (s) 16 (g) 20 (G) 17 (D) >> exch get
146 50 y moveto (pub) show
147 70 y moveto show showAlgorithm (/) show show
155 70 y moveto (Key fingerprint = ) show show
160 50 y moveto (uid) show
166 50 y moveto (sub) show
167 70 y moveto show showAlgorithm (/) show show
174 # output the desired display for revoked uids
175 if ( $revokestyle eq "grey" ) {
188 } elsif ( $revokestyle eq "note" ) {
191 50 y moveto (uid) show
192 200 y moveto show ( [revoked]) show
200 } elsif ( $revokestyle eq "show" ) {
205 } elsif ( $revokestyle eq "strike" ) {
209 45 y 9 add moveto h 2 div 45 sub y 18 add lineto stroke
213 45 y 9 add moveto h 2 div 45 sub y 18 add lineto stroke
223 } # sub start_postscript
225 # walk the output of gpg line by line
226 # $numlines has the total number of lines so we'll know how many to put on page
231 if ( /^(tru|uat):/ ) { next; }
232 # every primary uid causes an extra line because of the separator
234 start_postscript
() unless $started;
239 s/^pub:[^:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:([^:]*):[^:]*:[^:]*:.*/ ($5) ($4) ($3) $2 ($1) pub/;
240 # fingerprint, format it nicely with spaces
241 if ( /^fpr:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ) {
244 $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/;
246 $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;
247 $_ = " ($fpr) fpr\n";
250 s/^uid:[^:r]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ($1) uid/;
252 if (s/^uid:r[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ($1) revuid/) {
253 next if $revokestyle eq "hide";
256 s/^sub:[^r:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:.*/ ($4) ($3) $2 ($1) sbk/;
257 if (s/^sub:r[^:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:.*/ ($4) ($3) $2 ($1) revsbk/) {
258 next if $revokestyle eq "hide";
267 print STDERR
"No public key found.\n";
271 # output the remaining postscript
275 /numlines $numlines def
276 /num w 16 sub 10 div numlines div def
282 0 0 h $columns div w rectclip
287 0 upper h $columns div upper h $columns div lower 0 lower 0 upper moveto lineto lineto lineto lineto stroke
297 if ( $columns == 2 ) {
299 h $columns div 0 translate
320 B<gpg-key2ps> - generates a PS file from a GnuPG keyring
324 B<gpg-key2ps> [B<-r> I<revoked-style>] [B<-p> I<papersize>] I<keyid-or-name> [ I<...> ]
328 gpg-key2ps generates a PostScript file with your OpenPGP key fingerprint (repeated
329 as often as it fits) useful for keysigning parties. The only argument is the same
330 as you would pass to GPG's list-keys command, either a key-id or a (partial) name.
331 The PS data is written to stdout.
337 =item B<-p> B<--paper-size> I<paper-size>
339 Select the output paper size. Default is to look into /etc/papersize or A4 if
340 libpaper isn't installed.
342 =item B<-r> B<--revoked-style> I<revoked-style>
344 Select how to mark revoked UIDs and subkeys. Five styles are available:
345 B<hide> don't show at all (default),
346 B<show> show normally,
347 B<grey> display in 50% grey,
348 B<note> add "[revoked]", and
349 B<strike> strike through.
353 Keyids to print. Multiple can be separated by spaces.
355 =item B<-h> B<--help>
357 Print usage and exit.
359 =item B<-v> B<--version>
361 Print version and exit.
373 =item http://pgp-tools.alioth.debian.org/
375 The homepage of B<gpg-key2ps> and the other tools bundled in B<signing-party>.
377 =item http://www.debian.org/events/materials/business-cards/
379 B<gpg-key2ps> prints plain fingerprint slips. If you are looking for something
380 more stylish, look at these latex templates for business cards that also
381 include fingerprints.
385 =head1 AUTHORS AND COPYRIGHT
389 =item (c) 2001-2005 Simon Richter <sjr@debian.org>
391 =item (c) 2005-2007 Thijs Kinkhorst <thijs@kinkhorst.com>
393 =item (c) 2005-2008 Christoph Berg <cb@df7cb.de>