X-Git-Url: http://git.sthu.org/?a=blobdiff_plain;f=caff%2Fcaff;h=866af1919956fc271ddb86dc45418e4089aaef92;hb=19c5ad0c18bc815c0507ae0f83eb33c7798db932;hp=dd74de713e7d963d779e02de22bdaf3ea679bef3;hpb=bc522ce016d83a0211b2cdcc6a0892a81584f7f5;p=pgp-tools.git diff --git a/caff/caff b/caff/caff index dd74de7..866af19 100755 --- a/caff/caff +++ b/caff/caff @@ -85,6 +85,10 @@ Do not sign the keys. Select the key that is used for signing, in case you have more than one key. +=item B<--key-file> I + +Import keys from file. Can be supplied more than once. + =back =head1 FILES @@ -169,6 +173,10 @@ Keyserver to download keys from. Default: B. If true, then skip the step of fetching keys from the keyserver. Default: B<0>. +=item B [list of files] + +A list of files containing keys to be imported. + =head2 Signing settings =item B [boolean] @@ -282,6 +290,7 @@ sub load_config() { $CONFIG{'secret-keyring'} = $ENV{'HOME'}.'/.gnupg/secring.gpg' unless defined $CONFIG{'secret-keyring'}; $CONFIG{'no-download'} = 0 unless defined $CONFIG{'no-download'}; $CONFIG{'no-sign'} = 0 unless defined $CONFIG{'no-sign'}; + $CONFIG{'key-files'} = () unless defined $CONFIG{'key-files'}; $CONFIG{'mail-template'} = <<'EOM' unless defined $CONFIG{'mail-template'}; Hi, @@ -439,8 +448,9 @@ sub readwrite_gpg($$$$$%) { sub ask($$;$$) { my ($question, $default, $forceyes, $forceno) = @_; my $answer; + my $yn = $default ? '[Y/n]' : '[y/N]'; while (1) { - print $question,' ',($default ? '[Y/n]' : '[y/N]'), ' '; + print $question,' ',$yn, ' '; if ($forceyes && $forceno) { print "$default (from config/command line)\n"; return $default; @@ -455,9 +465,17 @@ sub ask($$;$$) { }; $answer = ; + if (!defined $answer) { + $OUTPUT_AUTOFLUSH = 1; + die "\n\n". + "End of STDIN reached. Are you using xargs? Caff wants to read from STDIN,\n". + "so you can't really use it with xargs. A patch against caff to read from\n". + "the terminal would be apprechiated.\n". + "For now instead of cat keys | xargs caff do caff `cat keys`\n"; + }; chomp $answer; - last if ((defined $answer) && (length $answer <= 1)); - print "grrrrrr.\n"; + last if ((length $answer == 0) || ($answer =~ m/^[yYnN]$/) ); + print "What about $yn is so hard to understand?\nAnswer with either 'n' or 'y' or just press enter for the default.\n"; sleep 1; }; my $result = $default; @@ -588,9 +606,9 @@ sub send_mail($$$@) { Type => "application/pgp-keys", Disposition => 'attachment', Encoding => "7bit", - Description => "PGP Key 0x$key_id, uid ".($key->{'text'}).' ('.($key->{'serial'}).')', + Description => "PGP Key 0x$key_id, uid ".($key->{'text'}).' ('.($key->{'serial'}).'), signed by 0x'.$CONFIG{'keyid'}[0], Data => $key->{'key'}, - Filename => "0x$key_id.".$key->{'serial'}.".asc"); + Filename => "0x$key_id.".$key->{'serial'}.".signed-by-0x".$CONFIG{'keyid'}[0].".asc"); }; if ($can_encrypt) { @@ -717,6 +735,7 @@ if (!GetOptions ( '--no-download' => \$params->{'no-download'}, '-S' => \$params->{'no-sign'}, '--no-sign' => \$params->{'no-sign'}, + '--key-file=s@' => \$params->{'key-files'}, )) { usage(\*STDERR, 1); }; @@ -758,6 +777,7 @@ $CONFIG{'no-download'} = $params->{'no-download'} if defined $params->{'no-downl $CONFIG{'no-mail'} = $params->{'no-mail'} if defined $params->{'no-mail'}; $CONFIG{'mail'} = $params->{'mail'} if defined $params->{'mail'}; $CONFIG{'no-sign'} = $params->{'no-sign'} if defined $params->{'no-sign'}; +push @{$CONFIG{'key-files'}}, @{$params->{'key-files'}} if defined $params->{'key-files'}; ################# @@ -793,6 +813,24 @@ for my $keyid (@{$CONFIG{'keyid'}}) { } } +######################## +# import keys from files +######################## +foreach my $keyfile (@{$CONFIG{'key-files'}}) { + my $gpg = GnuPG::Interface->new(); + $gpg->call( $CONFIG{'gpg'} ); + $gpg->options->hash_init('homedir' => $GNUPGHOME); + $gpg->options->meta_interactive( 0 ); + my ($inputfd, $stdoutfd, $stderrfd, $statusfd, $handles) = make_gpg_fds(); + my $pid = $gpg->import_keys(handles => $handles, command_args => $keyfile); + my ($stdout, $stderr, $status) = readwrite_gpg('', $inputfd, $stdoutfd, $stderrfd, $statusfd); + info ("Importing keys from $keyfile"); + waitpid $pid, 0; + if ($status !~ /^\[GNUPG:\] IMPORT_OK/m) { + warn $stderr; + } +} + ############################# # receive keys from keyserver #############################