]>
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 Thijs Kinkhorst
6 # Copyright (C) 2005 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-2005 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 ( -x
"/usr/bin/paperconf" ) {
92 # open a gpg process we'll be reading from below
93 map { s/'/'\\''/g; } @ARGV; # quote single quotes
94 open(GPG
, "gpg --fingerprint --with-colons '". (join "' '", @ARGV) ."' |");
96 sub start_postscript
{
97 # start the PostScript output
100 %%BoundingBox: 0 0 $w $h
102 %%Creator: gpg-key2ps $version
103 %%CreationDate: $creationdate
112 /Times-Roman findfont 9 scalefont setfont
120 w 2 div 30 sub y 3 add lineto stroke
125 /condhline { hline } def
133 << 1 (R) 2 (r) 3 (s) 16 (g) 20 (G) 17 (D) >> exch get
139 50 y moveto (pub) show
140 70 y moveto show showAlgorithm (/) show show
148 70 y moveto (Key fingerprint = ) show show
153 50 y moveto (uid) show
160 # output the desired display for revoked uids
161 if ( $revokestyle eq "grey" ) {
163 print " .5 setgray\n";
165 print " 0 setgray\n";
167 } elsif ( $revokestyle eq "hide" ) {
168 print "/revuid {} def\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 s/^uid:r[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ($1) revuid/;
227 s/^sub:[^:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:.*/ ($4) ($3) $2 ($1) sbk/;
235 print STDERR
"No public key found.\n";
239 # output the remaining postscript
243 /numlines $numlines def
244 /num w 16 sub 10 div numlines div def
250 0 0 h 2 div w rectclip
255 0 upper h 2 div upper h 2 div lower 0 lower 0 upper moveto lineto lineto lineto lineto stroke
280 B<gpg-key2ps> - generates a PS file from a GnuPG keyring
284 B<gpg-key2ps> [B<-r> I<revoked-style>] [B<-p> I<papersize>] I<keyid-or-name> [ I<...> ]
288 gpg-key2ps generates a PostScript file with your OpenPGP key fingerprint (repeated
289 as often as it fits) useful for keysigning parties. The only argument is the same
290 as you would pass to GPG's list-keys command, either a key-id or a (partial) name.
291 The PS data is written to stdout.
297 =item B<-p> B<--paper-size> I<paper-size>
299 Select the output paper size. Default is to look into /etc/papersize or A4 if
300 libpaper isn't installed.
302 =item B<-r> B<--revoked-style> I<revoked-style>
304 Select how to mark revoked UIDs. Five styles are available:
305 B<hide> don't show at all (default),
306 B<show> show normally,
307 B<grey> display in 50% grey,
308 B<note> add "[revoked]", and
309 B<strike> strike through.
313 Keyids to print. Multiple can be separated by spaces.
315 =item B<-h> B<--help>
317 Print usage and exit.
319 =item B<-v> B<--version>
321 Print version and exit.
330 http://pgp-tools.alioth.debian.org/
332 =head1 AUTHORS AND COPYRIGHT
334 (c) 2001 - 2005 Simon Richter <sjr@debian.org>
336 (c) 2005 Thijs Kinkhorst <thijs@kinkhorst.com>
338 (c) 2005 Christoph Berg <cb@df7cb.de>