]>
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" ) {
88 print STDERR
"Warning: libpaper-utils is not installed, defaulting to A4.\n";
93 # open a gpg process we'll be reading from below
94 map { s/'/'\\''/g; } @ARGV; # quote single quotes
95 open(GPG
, "gpg --fingerprint --with-colons '". (join "' '", @ARGV) ."' |");
97 sub start_postscript
{
98 # start the PostScript output
101 %%BoundingBox: 0 0 $w $h
103 %%Creator: gpg-key2ps $version
104 %%CreationDate: $creationdate
113 /Times-Roman findfont 9 scalefont setfont
121 w 2 div 30 sub y 3 add lineto stroke
126 /condhline { hline } def
134 << 1 (R) 2 (r) 3 (s) 16 (g) 20 (G) 17 (D) >> exch get
140 50 y moveto (pub) show
141 70 y moveto show showAlgorithm (/) show show
149 70 y moveto (Key fingerprint = ) show show
154 50 y moveto (uid) show
161 # output the desired display for revoked uids
162 if ( $revokestyle eq "grey" ) {
164 print " .5 setgray\n";
166 print " 0 setgray\n";
168 } elsif ( $revokestyle eq "hide" ) {
169 print "/revuid {} def\n";
170 } elsif ( $revokestyle eq "note" ) {
172 print " 50 y moveto (uid) show\n";
173 print " 200 y moveto show ( [revoked]) show\n";
176 } elsif ( $revokestyle eq "show" ) {
177 print "/revuid { uid } def\n";
178 } elsif ( $revokestyle eq "strike" ) {
181 print " 45 y 9 add moveto h 2 div 45 sub y 18 add lineto stroke\n";
188 50 y moveto (sub) show
189 70 y moveto show showAlgorithm (/) show show
197 } # sub start_postscript
199 # walk the output of gpg line by line
200 # $numlines has the total number of lines so we'll know how many to put on page
205 if ( /^(tru|uat):/ ) { next; }
206 # every primary uid causes an extra line because of the separator
208 start_postscript
() unless $started;
213 s/^pub:[^:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:([^:]*):[^:]*:[^:]*:.*/ ($5) ($4) ($3) $2 ($1) pub/;
214 # fingerprint, format it nicely with spaces
215 if ( /^fpr:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ) {
218 $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/;
220 $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;
221 $_ = " ($fpr) fpr\n";
224 s/^uid:[^:r]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ($1) uid/;
226 s/^uid:r[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:([^:]*):.*/ ($1) revuid/;
228 s/^sub:[^:]*:([^:]*):([0-9]*):.{8,8}(.{8,8}):([^:]*):[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:.*/ ($4) ($3) $2 ($1) sbk/;
236 print STDERR
"No public key found.\n";
240 # output the remaining postscript
244 /numlines $numlines def
245 /num w 16 sub 10 div numlines div def
251 0 0 h 2 div w rectclip
256 0 upper h 2 div upper h 2 div lower 0 lower 0 upper moveto lineto lineto lineto lineto stroke
281 B<gpg-key2ps> - generates a PS file from a GnuPG keyring
285 B<gpg-key2ps> [B<-r> I<revoked-style>] [B<-p> I<papersize>] I<keyid-or-name> [ I<...> ]
289 gpg-key2ps generates a PostScript file with your OpenPGP key fingerprint (repeated
290 as often as it fits) useful for keysigning parties. The only argument is the same
291 as you would pass to GPG's list-keys command, either a key-id or a (partial) name.
292 The PS data is written to stdout.
298 =item B<-p> B<--paper-size> I<paper-size>
300 Select the output paper size. Default is to look into /etc/papersize or A4 if
301 libpaper isn't installed.
303 =item B<-r> B<--revoked-style> I<revoked-style>
305 Select how to mark revoked UIDs. Five styles are available:
306 B<hide> don't show at all (default),
307 B<show> show normally,
308 B<grey> display in 50% grey,
309 B<note> add "[revoked]", and
310 B<strike> strike through.
314 Keyids to print. Multiple can be separated by spaces.
316 =item B<-h> B<--help>
318 Print usage and exit.
320 =item B<-v> B<--version>
322 Print version and exit.
331 http://pgp-tools.alioth.debian.org/
333 =head1 AUTHORS AND COPYRIGHT
335 (c) 2001 - 2005 Simon Richter <sjr@debian.org>
337 (c) 2005 Thijs Kinkhorst <thijs@kinkhorst.com>
339 (c) 2005 Christoph Berg <cb@df7cb.de>