diff --git a/commands.cpp b/commands.cpp index 6b3c498..b9030ba 100644 --- a/commands.cpp +++ b/commands.cpp @@ -689,7 +689,12 @@ static void encrypt_repo_key (const char* key_name, const Key_file::Entry& key, const std::string& fingerprint(collab->first); const bool key_is_trusted(collab->second); std::ostringstream path_builder; - path_builder << keys_path << '/' << (key_name ? key_name : "default") << '/' << key.version << '/' << fingerprint << ".gpg"; + + if (fingerprint.rfind("!") == fingerprint.size() - 1) { + path_builder << keys_path << '/' << (key_name ? key_name : "default") << '/' << key.version << '/' << fingerprint.substr(0, fingerprint.size() - 1) << ".gpg"; + } else { + path_builder << keys_path << '/' << (key_name ? key_name : "default") << '/' << key.version << '/' << fingerprint << ".gpg"; + } std::string path(path_builder.str()); if (access(path.c_str(), F_OK) == 0) { diff --git a/gpg.cpp b/gpg.cpp index 901ffaf..57e254e 100644 --- a/gpg.cpp +++ b/gpg.cpp @@ -32,6 +32,8 @@ #include "util.hpp" #include "commands.hpp" #include +#include +#include static std::string gpg_get_executable() { @@ -105,6 +107,12 @@ std::vector gpg_lookup_key (const std::string& query) command.push_back("--list-keys"); command.push_back(query); std::stringstream command_output; + bool forceSubkey = false; + std::string subkey; + if (query.rfind("!") == query.size() - 1) { + forceSubkey = true; + subkey = query.substr(0, query.size() - 1); + } if (successful_exit(exec_command(command, command_output))) { bool is_pubkey = false; while (command_output.peek() != -1) { @@ -113,10 +121,19 @@ std::vector gpg_lookup_key (const std::string& query) if (line.substr(0, 4) == "pub:") { is_pubkey = true; } else if (line.substr(0, 4) == "sub:") { - is_pubkey = false; + if (!forceSubkey) { + is_pubkey = false; + } } else if (is_pubkey && line.substr(0, 4) == "fpr:") { // fpr:::::::::7A399B2DB06D039020CD1CE1D0F3702D61489532: // want the 9th column (counting from 0) + if (forceSubkey) { + if (gpg_nth_column(line, 9) == subkey) { + fingerprints.push_back(query); + break; + } + continue; + } fingerprints.push_back(gpg_nth_column(line, 9)); } }