From: weasel Date: Tue, 28 Jun 2005 12:59:41 +0000 (+0000) Subject: Allow entire FPRs on the command line X-Git-Url: https://git.sthu.org/?a=commitdiff_plain;h=7ba830ca9f320d4cfd115d350675078f15a2bbac;p=pgp-tools.git Allow entire FPRs on the command line git-svn-id: svn://svn.debian.org/pgp-tools/trunk@89 b513b33f-fedd-0310-b452-c3deb5f4c849 --- diff --git a/caff/caff b/caff/caff index 9760470..4bbab0a 100755 --- a/caff/caff +++ b/caff/caff @@ -510,7 +510,7 @@ if ($opt{u}) { }; for my $keyid (@ARGV) { $keyid =~ s/^0x//i; - unless ($keyid =~ /^[A-Za-z0-9]{8}([A-Za-z0-9]{8})?$/) { + unless ($keyid =~ /^[A-Za-z0-9]{8}([A-Za-z0-9]{8}|[A-Za-z0-9]{32})?$/) { print STDERR "$keyid is not a keyid.\n"; usage(); }; @@ -573,19 +573,29 @@ if ($CONFIG{'no-download'} or $opt{R}) { # [GNUPG:] IMPORT_OK 0 25FC1614B8F87B52FF2F99B962AF4031C82E0039 my $handled = 0; for my $line (split /\n/, $status) { - if ($line =~ /^\[GNUPG:\] IMPORT_OK/) { - push @keyids_ok, shift @KEYIDS; + if ($line =~ /^\[GNUPG:\] IMPORT_OK \d+ ([0-9A-F]{40})/) { + my $imported_key = $1; + if ($keyid ne $imported_key && + $keyid ne substr($imported_key, -16) && + $keyid ne substr($imported_key, -8)) { + warn("Imported unexpected key. expected: $keyid; got: $imported_key.\n"); + next; + }; + push @keyids_ok, $keyid; + shift @KEYIDS; $handled = 1; last; } elsif ($line =~ /^\[GNUPG:\] NODATA/) { - push @keyids_failed, shift @KEYIDS; + push @keyids_failed, $keyid; + shift @KEYIDS; $handled = 1; last; }; }; unless ($handled) { notice ("Huh, what's up with $keyid?"); - push @keyids_failed, shift @KEYIDS; + push @keyids_failed, $keyid; + shift @KEYIDS; }; }; die ("Still keys in \@KEYIDS. This should not happen.") if scalar @KEYIDS; @@ -630,14 +640,21 @@ for my $keyid (@keyids_ok) { warn ("No data from gpg for list-key $keyid\n"); next; }; - my $keyinfo = $stdout; my @publine = grep { /^pub/ } (split /\n/, $stdout); my (undef, undef, undef, undef, $longkeyid, undef, undef, undef, undef, undef, undef, $flags) = split /:/, pop @publine; - my $can_encrypt = $flags =~ /E/; + if (scalar @publine > 0) { + warn ("More than one key matched $keyid. Try to specify the long keyid or fingerprint\n"); + next; + }; unless (defined $longkeyid) { - warn ("Didn't find public keyid in edit dialog of key $keyid.\n"); + warn ("Didn't find public keyid in --list-key of key $keyid.\n"); next; }; + unless (defined $flags) { + warn ("Didn't find flags in --list-key of key $keyid.\n"); + next; + }; + my $can_encrypt = $flags =~ /E/; # export the key ################ @@ -778,9 +795,9 @@ for my $keyid (@keyids_ok) { readwrite_gpg("save\n", $inputfd, $stdoutfd, $stderrfd, $statusfd); waitpid $pid, 0; - my $asciikey = export_key($tempdir, $longkeyid); + my $asciikey = export_key($tempdir, $keyid); if ($asciikey eq '') { - warn ("No data from gpg for export $longkeyid\n"); + warn ("No data from gpg for export $keyid\n"); next; };