From b89e704fdf28cdd02bea0b4cd12333bd99c0f3b5 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 30 Nov 2022 01:07:42 +0100 Subject: Matrix: ignore gpg keys with expired/revoked subkey as well --- src/plugins/Matrix.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/Matrix.cpp b/src/plugins/Matrix.cpp index 38ab6d0..2452548 100644 --- a/src/plugins/Matrix.cpp +++ b/src/plugins/Matrix.cpp @@ -80,6 +80,7 @@ namespace QuickMedia { enum class GpgLineType { UID, FPR, + SUB, UNKNOWN }; @@ -120,6 +121,7 @@ namespace QuickMedia { } std::string_view fpr; + std::string_view name_and_email; string_split(output, '\n', [&](const char *str, size_t size) { GpgLineType line_type = GpgLineType::UNKNOWN; int column = 0; @@ -132,20 +134,24 @@ namespace QuickMedia { line_type = GpgLineType::UID; else if(section == "fpr") line_type = GpgLineType::FPR; + else if(section == "sub") + line_type = GpgLineType::SUB; } else if(column == 1) { - if(line_type == GpgLineType::UID) - invalid_signature = (section == "e" || section == "r"); // Expired or revoked - } else if(column == 9) { - if(line_type == GpgLineType::UID && !invalid_signature) { - // Assumes that each uid is preceeded with fpr - const std::string user_email = std::string(gpg_display_name_extract_email(section)); + if(line_type == GpgLineType::UID || line_type == GpgLineType::SUB) + invalid_signature |= (section == "e" || section == "r"); // Expired or revoked + + if(line_type == GpgLineType::SUB && !invalid_signature) { + const std::string user_email = std::string(gpg_display_name_extract_email(name_and_email)); if(!user_email.empty() && users_by_email.find(user_email) != users_by_email.end()) { fprintf(stderr, "found public key %.*s for user %s\n", (int)fpr.size(), fpr.data(), user_email.c_str()); callback(fpr); } - } else if(line_type == GpgLineType::FPR) { - fpr = section; } + } else if(column == 9) { + if(line_type == GpgLineType::UID) + name_and_email = section; + else if(line_type == GpgLineType::FPR) + fpr = section; } ++column; -- cgit v1.2.3