From ad71c7ffaeb96107ad3dfa59af2b93da248fb257 Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Tue, 31 Mar 2015 19:41:19 -0700 Subject: [PATCH] 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. --- gpg.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gpg.cpp b/gpg.cpp index 4813b35..2cbb06a 100644 --- a/gpg.cpp +++ b/gpg.cpp @@ -102,10 +102,15 @@ std::vector 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));