FIx GPG key lookup with with-fingerprint enabled in gpg.conf

When the with-fingerprint option is enabled, the gpg command invoked by
git-crypt to look up a GPG user ID returns a fingerprint for both primary
keys and sub-keys.  Previously, this misled git-crypt into thinking that
the user ID matched more than one public key.  Now, git-crypt ignores
fingerprints for sub-keys.
This commit is contained in:
Andrew Ayer
2015-03-31 19:41:19 -07:00
parent 3ce5c83b2d
commit ad71c7ffae

View File

@@ -102,10 +102,15 @@ std::vector<std::string> gpg_lookup_key (const std::string& query)
command.push_back(query);
std::stringstream command_output;
if (successful_exit(exec_command(command, command_output))) {
bool is_pubkey = false;
while (command_output.peek() != -1) {
std::string line;
std::getline(command_output, line);
if (line.substr(0, 4) == "fpr:") {
if (line.substr(0, 4) == "pub:") {
is_pubkey = true;
} else if (line.substr(0, 4) == "sub:") {
is_pubkey = false;
} else if (is_pubkey && line.substr(0, 4) == "fpr:") {
// fpr:::::::::7A399B2DB06D039020CD1CE1D0F3702D61489532:
// want the 9th column (counting from 0)
fingerprints.push_back(gpg_nth_column(line, 9));