3 # caff -- CA - Fire and Forget
6 # Copyright (c) 2004 Peter Palfrader <peter@palfrader.org>
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
13 # 1. Redistributions of source code must retain the above copyright
14 # notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 # notice, this list of conditions and the following disclaimer in the
17 # documentation and/or other materials provided with the distribution.
18 # 3. The name of the author may not be used to endorse or promote products
19 # derived from this software without specific prior written permission.
21 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 caff -- CA - Fire and Forget
42 =item B<caff> [-u I<yourkeyid>] I<keyid> [I<keyid> ..]
48 CA Fire and Forget is a script that helps you in keysigning. It takes a list
49 of keyids on the command line, fetches them from a keyserver and calls GnuPG so
50 that you can sign it. It then mails each key to all its email addresses - only
51 including the one UID that we send to in each mail, pruned from all but self
52 sigs and sigs done by you.
58 =item B<-u> I<yourkeyid>
60 Select the key that is used for signing, in case you have more than one key.
68 =item $HOME/.caffrc - configuration file
72 =head1 CONFIGURATION FILE OPTIONS
74 The configuration file is a perl script that sets values in the hash B<%CONFIG>.
78 $CONFIG{'owner'} = 'Peter Palfrader';
79 $CONFIG{'email'} = 'peter@palfrader.org';
85 =item B<caffhome> [string]
87 Base directory for the files caff stores. Default: B<$HOME/.caff/>.
89 =item B<owner> [string]
91 Your name. B<REQUIRED>.
93 =item B<email> [string]
95 Your email address, used in From: lines. B<REQUIRED>.
97 =item B<keyid> [list of keyids]
99 A list of your keys. This is used to determine which signatures to keep
100 in the pruning step. If you select a key using B<-u> it has to be in
101 this list. B<REQUIRED>.
103 =item B<export-sig-age> [seconds]
105 Don't export UIDs by default, on which your latest signature is older
106 than this age. Default: B<24*60*60> (i.e. one day).
108 =item B<keyserver> [string]
110 Keyserver to download keys from. Default: B<subkeys.pgp.net>.
112 =item B<gpg> [string]
114 Path to the GnuPG binary. Default: B<gpg>.
116 =item B<gpg-sign> [string]
118 Path to the GnuPG binary which is used to sign keys. Default: what
121 =item B<gpg-sdelsig> [string]
123 Path to the GnuPG binary which is used to split off signatures. This is
124 needed while the upstream GnuPG is not fixed (there are 2 bugs in the
125 Debian Bug Tracking System). Default: what B<gpg> is set to.
127 =item B<secret-keyring> [string]
129 Path to your secret keyring. Default: B<$HOME/.gnupg/secring.gpg>.
135 Peter Palfrader <peter@palfrader.org>
143 use File
::Temp
qw{tempdir
};
147 use GnuPG
::Interface
;
150 my $REVISION = '$Rev$';
151 my ($REVISION_NUMER) = $REVISION =~ /(\d+)/;
152 my $VERSION = "0.0.0.$REVISION_NUMER";
155 my $config = $ENV{'HOME'} . '/.caffrc';
156 -f
$config or die "No file $config present. See caffrc(5).\n";
157 unless (scalar eval `cat $config`) {
158 die "Couldn't parse $config: $EVAL_ERROR\n" if $EVAL_ERROR;
161 $CONFIG{'caffhome'}=$ENV{'HOME'}.'/.caff' unless defined $CONFIG{'caffhome'};
162 die ("owner is not defined.\n") unless defined $CONFIG{'owner'};
163 die ("email is not defined.\n") unless defined $CONFIG{'email'};
164 die ("keyid is not defined.\n") unless defined $CONFIG{'keyid'};
165 die ("keyid is not an array ref\n") unless (ref $CONFIG{'keyid'} eq 'ARRAY');
166 for my $keyid (@
{$CONFIG{'keyid'}}) {
167 $keyid =~ /^[A-Fa-z0-9]{16}$/ or die ("key $keyid is not a long (16 digit) keyid.\n");
169 @
{$CONFIG{'keyid'}} = map { uc } @
{$CONFIG{'keyid'}};
170 $CONFIG{'export-sig-age'}= 24*60*60 unless defined $CONFIG{'export-sig-age'};
171 $CONFIG{'keyserver'} = 'subkeys.pgp.net' unless defined $CONFIG{'keyserver'};
172 $CONFIG{'gpg'} = 'gpg' unless defined $CONFIG{'gpg'};
173 $CONFIG{'gpg-sign'} = $CONFIG{'gpg'} unless defined $CONFIG{'gpg-sign'};
174 $CONFIG{'gpg-delsig'} = $CONFIG{'gpg'} unless defined $CONFIG{'gpg-delsig'};
175 $CONFIG{'secret-keyring'} = $ENV{'HOME'}.'/.gnupg/secring.gpg' unless defined $CONFIG{'secret-keyring'};
180 print "[NOTICE] $line\n";
184 print "[INFO] $line\n";
188 #print "[DEBUG] $line\n";
192 #print "[trace] $line\n";
196 #print "[trace2] $line\n";
201 stdin
=> IO
::Handle
->new(),
202 stdout
=> IO
::Handle
->new(),
203 stderr
=> IO
::Handle
->new(),
204 status
=> IO
::Handle
->new() );
205 my $handles = GnuPG
::Handles
->new( %fds );
206 return ($fds{'stdin'}, $fds{'stdout'}, $fds{'stderr'}, $fds{'status'}, $handles);
209 sub readwrite_gpg
($$$$$%) {
210 my ($in, $inputfd, $stdoutfd, $stderrfd, $statusfd, %options) = @_;
212 trace
("Entering readwrite_gpg.");
214 my ($first_line, $dummy) = split /\n/, $in;
215 debug
("readwrite_gpg sends ".(defined $first_line ?
$first_line : "<nothing>"));
217 local $INPUT_RECORD_SEPARATOR = undef;
218 my $sout = IO
::Select
->new();
219 my $sin = IO
::Select
->new();
222 trace
("input is $inputfd; output is $stdoutfd; err is $stderrfd; status is ".(defined $statusfd ?
$statusfd : 'undef').".");
224 $inputfd->blocking(0);
225 $stdoutfd->blocking(0);
226 $statusfd->blocking(0) if defined $statusfd;
227 $stderrfd->blocking(0);
228 $sout->add($stdoutfd);
229 $sout->add($stderrfd);
230 $sout->add($statusfd) if defined $statusfd;
233 my ($stdout, $stderr, $status) = ("", "", "");
234 my $exitwhenstatusmatches = $options{'exitwhenstatusmatches'};
235 trace
("doign stuff until we find $exitwhenstatusmatches") if defined $exitwhenstatusmatches;
237 my ($readyr, $readyw, $written);
238 while ($sout->count() > 0 || (defined($sin) && ($sin->count() > 0))) {
239 if (defined $exitwhenstatusmatches) {
240 if ($status =~ /$exitwhenstatusmatches/m) {
241 trace
("readwrite_gpg found match on $exitwhenstatusmatches");
246 trace
("select waiting for ".($sout->count())." fds.");
247 ($readyr, $readyw, undef) = IO
::Select
::select($sout, $sin, undef, 1);
248 trace
("ready: write: ".(defined $readyw ?
scalar @
$readyw : 0 )."; read: ".(defined $readyr ?
scalar @
$readyr : 0));
249 for my $wfd (@
$readyw) {
250 if (length($in) != $offset) {
251 trace
("writing to $wfd.");
252 $written = $wfd->syswrite($in, length($in) - $offset, $offset);
255 if ($offset == length($in)) {
256 trace
("writing to $wfd done.");
257 unless ($options{'nocloseinput'}) {
259 trace
("$wfd closed.");
266 next unless (defined(@
$readyr)); # Wait some more.
268 for my $rfd (@
$readyr) {
270 trace
("reading from $rfd done.");
275 trace
("reading from $rfd.");
276 if ($rfd == $stdoutfd) {
278 trace2
("stdout is now $stdout\n================");
281 if (defined $statusfd && $rfd == $statusfd) {
283 trace2
("status is now $status\n================");
286 if ($rfd == $stderrfd) {
288 trace2
("stderr is now $stderr\n================");
293 trace
("readwrite_gpg done.");
294 return ($stdout, $stderr, $status);
298 my ($question, $default) = @_;
301 print $question,' ',($default ?
'[Y/n]' : '[y/N]'), ' ';
304 last if ((defined $answer) && (length $answer <= 1));
308 my $result = $default;
309 $result = 1 if $answer =~ /y/i;
310 $result = 0 if $answer =~ /n/i;
318 my $KEYEDIT_PROMPT = '^\[GNUPG:\] GET_LINE keyedit.prompt';
319 my $KEYEDIT_DELUID_PROMPT = '^\[GNUPG:\] GET_BOOL keyedit.remove.uid.okay';
320 my $KEYEDIT_DELSIG_PROMPT = '^\[GNUPG:\] GET_BOOL keyedit.delsig';
321 my $KEYEDIT_KEYEDIT_OR_DELSIG_PROMPT = '^\[GNUPG:\] (GET_BOOL keyedit.delsig|GET_LINE keyedit.prompt)';
322 my $KEYEDIT_DELSUBKEY_PROMPT = '^\[GNUPG:\] GET_BOOL keyedit.remove.subkey';
325 my $USER_AGENT = "caff $VERSION - (c) 2004 Peter Palfrader";
327 my $KEYSBASE = $CONFIG{'caffhome'}.'/keys';
328 my $GNUPGHOME = $CONFIG{'caffhome'}.'/gnupghome';
330 -d
$KEYSBASE || mkpath
($KEYSBASE , 0, 0700) or die ("Cannot create $KEYSBASE: $!\n");
331 -d
$GNUPGHOME || mkpath
($GNUPGHOME, 0, 0700) or die ("Cannot create $GNUPGHOME: $!\n");
334 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($NOW);
335 my $DATE_STRING = sprintf("%04d-%02d-%02d", $year+1900, $mon+1, $mday);
339 print STDERR
"caff $VERSION - (c) 2004 Peter Palfrader\n";
340 print STDERR
"Usage: $PROGRAM_NAME [-u <yourkeyid] <keyid> [<keyid> ...]\n";
345 my ($gnupghome, $keyid) = @_;
347 my $gpg = GnuPG
::Interface
->new();
348 $gpg->call( $CONFIG{'gpg'} );
349 $gpg->options->hash_init(
350 'homedir' => $gnupghome,
352 $gpg->options->meta_interactive( 0 );
353 my ($inputfd, $stdoutfd, $stderrfd, $statusfd, $handles) = make_gpg_fds
();
354 my $pid = $gpg->export_keys(handles
=> $handles, command_args
=> [ $keyid ]);
355 my ($stdout, $stderr, $status) = readwrite_gpg
('', $inputfd, $stdoutfd, $stderrfd, $statusfd);
361 #send_mail($address, $can_encrypt, $longkeyid, $uid, @attached);
362 sub send_mail
($$$@
) {
363 my ($address, $can_encrypt, $key_id, @keys) = @_;
365 my $message = "Hi,\n\n";
367 $message .= 'please find attached the user id'.(scalar @keys >= 2 ?
's' : '')."\n";
368 for my $key (@keys) {
369 $message .= "\t".$key->{'text'}."\n";
371 $message .= qq{of your key
$key_id signed by me
.
373 Note that I did
not upload your key to any keyservers
. If you want this
374 new signature to be available to others
, please upload it yourself
.
375 With GnuPG this can be done using
376 gpg
--keyserver subkeys
.pgp
.net
--send-key
$key_id
378 If you have any questions
, don
't hesitate to ask.
383 my $message_entity = MIME::Entity->build(
384 Type => "text/plain",
386 Disposition => 'inline
',
390 for my $key (@keys) {
391 $message_entity->attach(
392 Type => "application/pgp-keys",
393 Disposition => 'attachment
',
395 Description => "PGP Key 0x$key_id, uid ".($key->{'text
'}).' ('.($key->{'serial
'}).')',
396 Data => $key->{'key
'},
397 Filename => "0x$key_id.".$key->{'serial
'}.".asc");
401 my $message = $message_entity->stringify();
403 my $gpg = GnuPG::Interface->new();
404 $gpg->call( $CONFIG{'gpg
'} );
405 $gpg->options->hash_init( 'homedir
' => $GNUPGHOME,
406 'extra_args
' => '--always
-trust
',
408 $gpg->options->meta_interactive( 0 );
409 my ($inputfd, $stdoutfd, $stderrfd, $statusfd, $handles) = make_gpg_fds();
410 $gpg->options->push_recipients( $key_id );
411 $gpg->options->push_recipients( $CONFIG{'also
-encrypt
-to
'} ) if defined $CONFIG{'also
-encrypt
-to
'};
412 my $pid = $gpg->encrypt(handles => $handles);
413 my ($stdout, $stderr, $status) = readwrite_gpg($message, $inputfd, $stdoutfd, $stderrfd, $statusfd);
416 warn ("No data from gpg for list-key $key_id\n");
421 $message_entity = MIME::Entity->build(
422 Type => 'multipart
/encrypted; protocol="application/pgp-encrypted
"');
424 $message_entity->attach(
425 Type => "application
/pgp
-encrypted
",
426 Disposition => 'attachment',
428 Data => "Version
: 1\n");
430 $message_entity->attach(
431 Type => "application
/octet
-stream
",
432 Filename => 'msg.asc',
433 Disposition => 'inline',
438 $message_entity->head->add("Subject
", "Your signed PGP key
0x
$key_id");
439 $message_entity->head->add("To
", $address);
440 $message_entity->head->add("From
", $CONFIG{'owner'}.' <'.$CONFIG{'email'}.'>');
441 $message_entity->head->add("User
-Agent
", $USER_AGENT);
442 $message_entity->send();
443 $message_entity->stringify();
449 usage() unless scalar @ARGV >= 1;
450 if ($ARGV[0] eq '-u') {
451 usage() unless scalar @ARGV >= 3;
454 unless ($USER =~ /^[A-Za-z0-9]{8,8}([A-Za-z0-9]{8})?$/) {
455 print STDERR "-u
$USER is
not a keyid
.\n";
460 for my $keyid (@ARGV) {
461 unless ($keyid =~ /^[A-Za-z0-9]{8}([A-Za-z0-9]{8})?$/) {
462 print STDERR "$keyid is
not a keyid
.\n";
465 push @KEYIDS, uc($keyid);
469 #############################
470 # receive keys from keyserver
471 #############################
472 my $gpg = GnuPG::Interface->new();
473 $gpg->call( $CONFIG{'gpg'} );
474 $gpg->options->hash_init(
475 'homedir' => $GNUPGHOME,
476 'extra_args' => '--keyserver='.$CONFIG{'keyserver'} );
477 $gpg->options->meta_interactive( 0 );
478 my ($inputfd, $stdoutfd, $stderrfd, $statusfd, $handles) = make_gpg_fds();
479 my $pid = $gpg->recv_keys(handles => $handles, command_args => [ @KEYIDS ]);
480 my ($stdout, $stderr, $status) = readwrite_gpg('', $inputfd, $stdoutfd, $stderrfd, $statusfd);
485 # [GNUPG:] IMPORT_OK 0 5B00C96D5D54AEE1206BAF84DE7AAF6E94C09C7F
488 # [GNUPG:] IMPORT_OK 0 25FC1614B8F87B52FF2F99B962AF4031C82E0039
489 for my $line (split /\n/, $status) {
490 if ($line =~ /^\[GNUPG:\] IMPORT_OK/) {
491 push @keyids_ok, shift @KEYIDS;
492 } elsif ($line =~ /^\[GNUPG:\] NODATA/) {
493 push @keyids_failed, shift @KEYIDS;
496 die ("Still
keys in \
@KEYIDS. This should
not happen
.") if scalar @KEYIDS;
497 notice ("Import failed
for: ". (join ' ', @keyids_failed).".") if scalar @keyids_failed;
502 info("Sign the following
keys according to your policy
...");
503 for my $keyid (@keyids_ok) {
505 push @command, $CONFIG{'gpg-sign'};
506 push @command, '--local-user', $USER if (defined $USER);
507 push @command, "--homedir
=$GNUPGHOME";
508 push @command, '--secret-keyring', $CONFIG{'secret-keyring'};
509 push @command, '--sign-key', $keyid;
510 print join(' ', @command),"\n";
518 for my $keyid (@keyids_ok) {
521 $gpg = GnuPG::Interface->new();
522 $gpg->call( $CONFIG{'gpg'} );
523 $gpg->options->hash_init( 'homedir' => $GNUPGHOME );
524 $gpg->options->meta_interactive( 0 );
525 ($inputfd, $stdoutfd, $stderrfd, $statusfd, $handles) = make_gpg_fds();
526 $gpg->options->hash_init( 'extra_args' => [ '--with-colons', '--fixed-list-mode' ] );
527 $pid = $gpg->list_public_keys(handles => $handles, command_args => [ $keyid ]);
528 ($stdout, $stderr, $status) = readwrite_gpg('', $inputfd, $stdoutfd, $stderrfd, $statusfd);
531 warn ("No data from gpg
for list
-key
$keyid\n");
534 my $keyinfo = $stdout;
535 my @publine = grep { /^pub/ } (split /\n/, $stdout);
536 my ($dummy1, $dummy2, $dummy3, $dummy4, $longkeyid, $dummy6, $dummy7, $dummy8, $dummy9, $dummy10, $dummy11, $flags) = split /:/, pop @publine;
537 my $can_encrypt = $flags =~ /E/;
538 unless (defined $longkeyid) {
539 warn ("Didn
't find public keyid in edit dialog of key $keyid.\n");
545 my $asciikey = export_key($GNUPGHOME, $keyid);
546 if ($asciikey eq '') {
547 warn ("No data from gpg for export $keyid\n");
554 my $this_uid_text = '';
556 info("Doing key $keyid, uid $uid_number");
558 # import into temporary gpghome
559 ###############################
560 my $tempdir = tempdir( "caff-$keyid-XXXXX", DIR => '/tmp/', CLEANUP => 1);
561 my $gpg = GnuPG::Interface->new();
562 $gpg->call( $CONFIG{'gpg
'} );
563 $gpg->options->hash_init( 'homedir
' => $tempdir );
564 $gpg->options->meta_interactive( 0 );
565 my ($inputfd, $stdoutfd, $stderrfd, $statusfd, $handles) = make_gpg_fds();
566 my $pid = $gpg->import_keys(handles => $handles);
567 my ($stdout, $stderr, $status) = readwrite_gpg($asciikey, $inputfd, $stdoutfd, $stderrfd, $statusfd);
570 if ($status !~ /^\[GNUPG:\] IMPORT_OK/m) {
571 warn ("Could not import $keyid into temporary gnupg.\n");
577 $gpg = GnuPG::Interface->new();
578 $gpg->call( $CONFIG{'gpg
-delsig
'} );
579 $gpg->options->hash_init(
580 'homedir
' => $tempdir,
581 'extra_args
' => [ '--with
-colons
', '--fixed
-list
-mode
', '--command
-fd
=0', '--no-tty
' ] );
582 ($inputfd, $stdoutfd, $stderrfd, $statusfd, $handles) = make_gpg_fds();
583 $pid = $gpg->wrap_call(
584 commands => [ '--edit
' ],
585 command_args => [ $keyid ],
586 handles => $handles );
588 debug("Starting edit session");
589 ($stdout, $stderr, $status) = readwrite_gpg('', $inputfd, $stdoutfd, $stderrfd, $statusfd, exitwhenstatusmatches => $KEYEDIT_PROMPT, nocloseinput => 1);
593 my $number_of_subkeys = 0;
598 debug("Parsing stdout output.");
599 for my $line (split /\n/, $stdout) {
600 debug("Checking line $line");
601 my ($type, $dummy2, $dummy3, $dummy4, $dummy5, $dummy6, $dummy7, $dummy8, $dummy9, $uidtext) = split /:/, $line;
602 if ($type eq 'sub') {
603 $number_of_subkeys++;
605 next unless ($type eq 'uid
' || $type eq 'uat
');
606 debug("line is interesting.");
607 if ($uid_number != $i) {
608 debug("mark for deletion.");
609 readwrite_gpg("$i\n", $inputfd, $stdoutfd, $stderrfd, $statusfd, exitwhenstatusmatches => $KEYEDIT_PROMPT, nocloseinput => 1);
614 $this_uid_text = ($type eq 'uid
') ? $uidtext : 'attribute
';
615 $is_uat = $type eq 'uat
';
619 debug("Parsing stdout output done.");
621 notice("Can't handle attribute userid of key
$keyid.");
625 info("key
$keyid done
.");
629 debug("need to
delete a few uids
.");
630 readwrite_gpg("deluid
\n", $inputfd, $stdoutfd, $stderrfd, $statusfd, exitwhenstatusmatches => $KEYEDIT_DELUID_PROMPT, nocloseinput => 1);
631 readwrite_gpg("yes
\n", $inputfd, $stdoutfd, $stderrfd, $statusfd, exitwhenstatusmatches => $KEYEDIT_PROMPT, nocloseinput => 1);
636 if ($number_of_subkeys > 0) {
637 for (my $i=1; $i<=$number_of_subkeys; $i++) {
638 readwrite_gpg("key
$i\n", $inputfd, $stdoutfd, $stderrfd, $statusfd, exitwhenstatusmatches => $KEYEDIT_PROMPT, nocloseinput => 1);
640 readwrite_gpg("delkey
\n", $inputfd, $stdoutfd, $stderrfd, $statusfd, exitwhenstatusmatches => $KEYEDIT_DELSUBKEY_PROMPT, nocloseinput => 1);
641 readwrite_gpg("yes
\n", $inputfd, $stdoutfd, $stderrfd, $statusfd, exitwhenstatusmatches => $KEYEDIT_PROMPT, nocloseinput => 1);
646 my $signed_by_me = 0;
647 readwrite_gpg("1\n", $inputfd, $stdoutfd, $stderrfd, $statusfd, exitwhenstatusmatches => $KEYEDIT_PROMPT, nocloseinput => 1);
648 ($stdout, $stderr, $status) =
649 readwrite_gpg("delsig
\n", $inputfd, $stdoutfd, $stderrfd, $statusfd, exitwhenstatusmatches => $KEYEDIT_DELSIG_PROMPT, nocloseinput => 1);
651 while($status =~ /$KEYEDIT_DELSIG_PROMPT/m) {
652 # sig:?::17:EA2199412477CAF8:1058095214:::::13x:
653 my @sigline = grep { /^sig/ } (split /\n/, $stdout);
654 my $line = pop @sigline;
656 if (defined $line) { # only if we found a sig here - we never remove revocation packets for instance
657 my ($dummy1, $dummy2, $dummy3, $dummy4, $signer, $created, $dummy7, $dummy8, $dummy9) = split /:/, $line;
658 if ($signer eq $longkeyid) {
660 } elsif (grep { $signer eq $_ } @{$CONFIG{'keyid'}}) {
662 $signed_by_me = $signed_by_me > $created ? $signed_by_me : $created;
667 ($stdout, $stderr, $status) =
668 readwrite_gpg($answer."\n", $inputfd, $stdoutfd, $stderrfd, $statusfd, exitwhenstatusmatches => $KEYEDIT_KEYEDIT_OR_DELSIG_PROMPT, nocloseinput => 1);
670 readwrite_gpg("save
\n", $inputfd, $stdoutfd, $stderrfd, $statusfd);
673 my $asciikey = export_key($tempdir, $longkeyid);
674 if ($asciikey eq '') {
675 warn ("No data from gpg
for export
$longkeyid\n");
680 if ($NOW - $signed_by_me > $CONFIG{'export-sig-age'} ) {
681 my $write = ask("Signature on
$this_uid_text is old
. Export?
", 0);
684 my $keydir = "$KEYSBASE/$DATE_STRING";
685 -d $keydir || mkpath($keydir , 0, 0700) or die ("Cannot create
$keydir $!\n");
687 my $keyfile = "$keydir/$longkeyid.key
.$uid_number.$this_uid_text.asc
";
688 open (KEY, ">$keyfile") or die ("Cannot
open $keyfile\n");
692 push @UIDS, { text => $this_uid_text, key => $asciikey, serial => $uid_number };
694 info("$longkeyid $uid_number $this_uid_text done
.");
696 info("$longkeyid $uid_number $this_uid_text is
not signed by me
, not writing
.");
700 if (scalar @UIDS == 0) {
701 info("found
no signed uids
for $keyid");
704 for my $uid (@UIDS) {
705 unless ($uid->{'text'} =~ /@/) {
706 my $attach = ask("UID
$uid->{'text'} is
no email address
, attach it to every email sent?
", 1);
707 push @attached, $uid;
711 notice("Key has
no encryption capabilities
, mail will be sent unencrypted
") unless $can_encrypt;
712 for my $uid (@UIDS) {
713 if ($uid->{'text'} =~ /@/) {
714 my $address = $uid->{'text'};
715 $address =~ s/.*<(.*)>.*/$1/;
716 my $send = ask("Send mail to
'$address' for $uid->{'text'}?
", 1);
718 my $mail = send_mail($address, $can_encrypt, $longkeyid, $uid, @attached);
720 my $keydir = "$KEYSBASE/$DATE_STRING";
721 my $mailfile = "$keydir/$longkeyid.mail
.".$uid->{'serial'}.".".$uid->{'text'};
722 open (KEY, ">$mailfile") or die ("Cannot
open $mailfile\n");
735 ###############################################################3
736 #### old fork gpg --edit
738 my ($stdin_read, $stdin_write);
739 my ($stdout_read, $stdout_write);
740 my ($stderr_read, $stderr_write);
741 my ($status_read, $status_write);
742 pipe $stdin_read, $stdin_write;
743 pipe $stdout_read, $stdout_write;
744 pipe $stderr_read, $stderr_write;
745 pipe $status_read, $status_write;
748 unless ($pid) { # child
755 push @call, $CONFIG{'gpg-delsig'};
756 push @call, "--homedir
=$tempdir";
757 push @call, '--with-colons';
758 push @call, '--fixed-list-mode';
759 push @call, '--command-fd=0';
760 push @call, "--status
-fd
=".fileno($status_write);
761 push @call, "--no-tty
";
762 push @call, "--edit
";
768 open (STDIN, "<&".fileno($stdin_read)) or die ("Cannot reopen stdin
: $!\n");
769 open (STDOUT, ">&".fileno($stdout_write)) or die ("Cannot reopen stdout
: $!\n");
770 open (STDERR, ">&".fileno($stderr_write)) or die ("Cannot reopen stderr
: $!\n");
772 fcntl $status_write, F_SETFD, 0;
782 $inputfd = $stdin_write;
783 $stdoutfd = $stdout_read;
784 $stderrfd = $stderr_read;
785 $statusfd = $status_read;