]>
git.sthu.org Git - pgp-tools.git/blob - gpg-key2ps/gpg-key2ps
3 # gpg-key2ps: convert a PGP/GnuPG key into paper slips.
4 # Copyright (C) 2001-2005 Simon Richter
5 # Copyright (C) 2005-2008 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/;
18 my $revokestyle = "hide";
20 my $creationdate = scalar(localtime);
24 print $fd "gpg-key2ps $version - (c) 2001-2008 Simon Richter, Thijs Kinkhorst, Christoph Berg\n";
28 my ($fd, $exitcode) = @_;
31 Usage: $0 [-p papersize] [-r revoked-style] [-1] [-s] keyid-or-name ...
36 hide - Don't show revoked uids and subkeys (default)
37 grey - Print text in grey
38 note - Add "[revoked]"
39 show - List revoked uids normally
40 strike - Strike through lines
41 -1 Only print one column, for extra wide keys
48 # fetch command line parameters
50 Getopt
::Long
::config
('bundling');
52 '-h' => \
$opts->{help
},
53 '--help' => \
$opts->{help
},
54 '-v' => \
$opts->{version
},
55 '--version' => \
$opts->{version
},
56 '-s' => \
$opts->{showsubkeys
},
57 '--show-subkeys' => \
$opts->{showsubkeys
},
58 '-p=s' => \
$opts->{papersize
},
59 '--paper-size=s' => \
$opts->{papersize
},
60 '-r=s' => \
$opts->{revokestyle
},
61 '--revoked-style=s' => \
$opts->{revokestyle
},
71 if ($opts->{version
}) {
76 if ( $opts->{papersize
} ) { $ENV{'PAPERSIZE'} = $opts->{papersize
}; }
77 if ( $opts->{showsubkeys
} ) { $showsubkeys = 1; }
78 if ( $opts->{revokestyle
} ) { $revokestyle = $opts->{revokestyle
}; }
80 if ( $revokestyle !~ /^(grey|hide|note|show|strike)$/ ) {
81 print STDERR
"Unknown revoked-style \"$revokestyle\".\n";
85 if ( $opts->{1} ) { $columns = 1; }
87 usage
(\
*STDERR
, 1) unless scalar @ARGV >= 1;
89 # determine the paper size through the paperconf tool
91 if ( `which paperconf` && $?
== 0 ) {
98 print STDERR
"Warning: libpaper-utils is not installed, defaulting to A4.\n";
103 # open a gpg process we'll be reading from below
104 map { s/'/'\\''/g; } @ARGV; # quote single quotes
105 # --list-key due to #382794
106 open(GPG
, "gpg --list-key --with-fingerprint --with-colons '". (join "' '", @ARGV) ."' |");
108 sub start_postscript
{
109 # start the PostScript output
112 %%BoundingBox: 0 0 $w $h
114 %%Creator: gpg-key2ps $version
115 %%CreationDate: $creationdate
124 /Times-Roman findfont 9 scalefont setfont
132 w $columns div 30 sub y 3 add lineto stroke
137 /condhline { hline } def
145 << 1 (R) 2 (r) 3 (s) 16 (g) 20 (G) 17 (D) >> exch get
151 50 y moveto (pub) show
152 70 y moveto show showAlgorithm (/) show show
160 70 y moveto (Key fingerprint = ) show show
165 50 y moveto (uid) show
171 50 y moveto (sub) show
172 70 y moveto show showAlgorithm (/) show show
179 # output the desired display for revoked uids
180 if ( $revokestyle eq "grey" ) {
193 } elsif ( $revokestyle eq "note" ) {
196 50 y moveto (uid) show
197 200 y moveto show ( [revoked]) show
205 } elsif ( $revokestyle eq "show" ) {
210 } elsif ( $revokestyle eq "strike" ) {
214 45 y 9 add moveto h 2 div 45 sub y 18 add lineto stroke
218 45 y 9 add moveto h 2 div 45 sub y 18 add lineto stroke
228 } # sub start_postscript
230 # walk the output of gpg line by line
231 # $numlines has the total number of lines so we'll know how many to put on page
236 if ( /^(tru|uat):/ ) { next; }
237 # every primary uid causes an extra line because of the separator
239 start_postscript
() unless $started;
244 s/^pub:[^:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:([^:]*):[^:]*:[^:]*:.*/ ($5) ($4) ($3) $2 ($1) pub/;
245 # fingerprint, format it nicely with spaces
246 if ( /^fpr:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ) {
249 $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/;
251 $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;
252 $_ = " ($fpr) fpr\n";
255 s/\\x([0-9a-f][0-9a-f])/ chr(hex($1)) /gie;
256 $_ = `echo "$_" | iconv -ct latin1`;
257 s/^uid:[^:r]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ($1) uid/;
259 if (s/^uid:r[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ($1) revuid/) {
260 next if $revokestyle eq "hide";
263 if (s/^sub:[^r:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:.*/ ($4) ($3) $2 ($1) sbk/) {
264 next if ! $showsubkeys;
266 if (s/^sub:r[^:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:.*/ ($4) ($3) $2 ($1) revsbk/) {
267 next if (!$showsubkeys) || $revokestyle eq "hide";
276 print STDERR
"No public key found.\n";
280 # output the remaining postscript
284 /numlines $numlines def
285 /num w 16 sub 10 div numlines div def
291 0 0 h $columns div w rectclip
296 0 upper h $columns div upper h $columns div lower 0 lower 0 upper moveto lineto lineto lineto lineto stroke
306 if ( $columns == 2 ) {
308 h $columns div 0 translate
329 B<gpg-key2ps> - generates a PS file from a GnuPG keyring
333 B<gpg-key2ps> [B<-r> I<revoked-style>] [B<-p> I<papersize>] [B<-1>] [B<-s>] I<keyid-or-name> [ I<...> ]
337 gpg-key2ps generates a PostScript file with your OpenPGP key fingerprint (repeated
338 as often as it fits) useful for keysigning parties. The only argument is the same
339 as you would pass to GPG's list-keys command, either a key-id or a (partial) name.
340 The PS data is written to stdout.
346 =item B<-p> B<--paper-size> I<paper-size>
348 Select the output paper size. Default is to look into /etc/papersize or A4 if
349 libpaper isn't installed.
351 =item B<-s> B<--show-subkeys>
353 Enable subkey information to be printed on the slips. Subkey information is
354 normally not relevant to the key signing process.
356 =item B<-r> B<--revoked-style> I<revoked-style>
358 Select how to mark revoked UIDs and subkeys. Five styles are available:
359 B<hide> don't show at all (default),
360 B<show> show normally,
361 B<grey> display in 50% grey,
362 B<note> add "[revoked]", and
363 B<strike> strike through.
367 Print only one column of paper slips instead of the default two. Useful for keys
368 with long UIDs that otherwise won't fit.
372 Keyids to print. Multiple can be separated by spaces.
374 =item B<-h> B<--help>
376 Print usage and exit.
378 =item B<-v> B<--version>
380 Print version and exit.
392 =item http://pgp-tools.alioth.debian.org/
394 The homepage of B<gpg-key2ps> and the other tools bundled in B<signing-party>.
396 =item http://www.debian.org/events/materials/business-cards/
398 B<gpg-key2ps> prints plain fingerprint slips. If you are looking for something
399 more stylish, look at these latex templates for business cards that also
400 include fingerprints.
404 =head1 AUTHORS AND COPYRIGHT
408 =item (c) 2001-2005 Simon Richter <sjr@debian.org>
410 =item (c) 2005-2008 Thijs Kinkhorst <thijs@kinkhorst.com>
412 =item (c) 2005-2008 Christoph Berg <cb@df7cb.de>