]>
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
132 /Encoding ISOLatin1Encoding def
138 /Times-Roman /trlatin1 reencode 9 scalefont setfont
146 w $columns div 30 sub y 3 add lineto stroke
151 /condhline { hline } def
159 << 1 (R) 2 (r) 3 (s) 16 (g) 20 (G) 17 (D) >> exch get
165 50 y moveto (pub) show
166 70 y moveto show showAlgorithm (/) show show
174 70 y moveto (Key fingerprint = ) show show
179 50 y moveto (uid) show
185 50 y moveto (sub) show
186 70 y moveto show showAlgorithm (/) show show
193 # output the desired display for revoked uids
194 if ( $revokestyle eq "grey" ) {
207 } elsif ( $revokestyle eq "note" ) {
210 50 y moveto (uid) show
211 200 y moveto show ( [revoked]) show
219 } elsif ( $revokestyle eq "show" ) {
224 } elsif ( $revokestyle eq "strike" ) {
228 45 y 9 add moveto h 2 div 45 sub y 18 add lineto stroke
232 45 y 9 add moveto h 2 div 45 sub y 18 add lineto stroke
242 } # sub start_postscript
244 # walk the output of gpg line by line
245 # $numlines has the total number of lines so we'll know how many to put on page
250 if ( /^(tru|uat):/ ) { next; }
251 # every primary uid causes an extra line because of the separator
253 start_postscript
() unless $started;
258 s/^pub:[^:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:([^:]*):[^:]*:[^:]*:.*/ ($5) ($4) ($3) $2 ($1) pub/;
259 # fingerprint, format it nicely with spaces
260 if ( /^fpr:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ) {
263 $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/;
265 $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;
266 $_ = " ($fpr) fpr\n";
269 s/\\x([0-9a-f][0-9a-f])/ chr(hex($1)) /gie;
270 $_ = `echo "$_" | iconv -c -f utf-8 -t latin1`;
271 s/^uid:[^:r]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ($1) uid/;
273 if (s/^uid:r[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ($1) revuid/) {
274 next if $revokestyle eq "hide";
277 if (s/^sub:[^r:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:.*/ ($4) ($3) $2 ($1) sbk/) {
278 next if ! $showsubkeys;
280 if (s/^sub:r[^:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:.*/ ($4) ($3) $2 ($1) revsbk/) {
281 next if (!$showsubkeys) || $revokestyle eq "hide";
290 print STDERR
"No public key found.\n";
294 # output the remaining postscript
298 /numlines $numlines def
299 /num w 16 sub 10 div numlines div def
305 0 0 h $columns div w rectclip
310 0 upper h $columns div upper h $columns div lower 0 lower 0 upper moveto lineto lineto lineto lineto stroke
320 if ( $columns == 2 ) {
322 h $columns div 0 translate
343 B<gpg-key2ps> - generates a PS file from a GnuPG keyring
347 B<gpg-key2ps> [B<-r> I<revoked-style>] [B<-p> I<papersize>] [B<-1>] [B<-s>] I<keyid-or-name> [ I<...> ]
351 gpg-key2ps generates a PostScript file with your OpenPGP key fingerprint (repeated
352 as often as it fits) useful for keysigning parties. The only argument is the same
353 as you would pass to GPG's list-keys command, either a key-id or a (partial) name.
354 The PS data is written to stdout.
360 =item B<-p> B<--paper-size> I<paper-size>
362 Select the output paper size. Default is to look into /etc/papersize or A4 if
363 libpaper isn't installed.
365 =item B<-s> B<--show-subkeys>
367 Enable subkey information to be printed on the slips. Subkey information is
368 normally not relevant to the key signing process.
370 =item B<-r> B<--revoked-style> I<revoked-style>
372 Select how to mark revoked UIDs and subkeys. Five styles are available:
373 B<hide> don't show at all (default),
374 B<show> show normally,
375 B<grey> display in 50% grey,
376 B<note> add "[revoked]", and
377 B<strike> strike through.
381 Print only one column of paper slips instead of the default two. Useful for keys
382 with long UIDs that otherwise won't fit.
386 Keyids to print. Multiple can be separated by spaces.
388 =item B<-h> B<--help>
390 Print usage and exit.
392 =item B<-v> B<--version>
394 Print version and exit.
406 =item http://pgp-tools.alioth.debian.org/
408 The homepage of B<gpg-key2ps> and the other tools bundled in B<signing-party>.
410 =item http://www.debian.org/events/materials/business-cards/
412 B<gpg-key2ps> prints plain fingerprint slips. If you are looking for something
413 more stylish, look at these latex templates for business cards that also
414 include fingerprints.
418 =head1 AUTHORS AND COPYRIGHT
422 =item (c) 2001-2005 Simon Richter <sjr@debian.org>
424 =item (c) 2005-2008 Thijs Kinkhorst <thijs@kinkhorst.com>
426 =item (c) 2005-2008 Christoph Berg <cb@df7cb.de>