From 8f4d78910c8bba1748751be63b44c0ae07d5546d Mon Sep 17 00:00:00 2001 From: Vadim Lomovtsev Date: Wed, 17 Apr 2024 15:33:35 +0300 Subject: [PATCH] OpenGPG plugin : Fixed don't list expired/revoked GPG key (#57) This commit is to implement follwoing changes: - closes #91; - Mention that GPG key may be expired or revoked: in the account dialog if the number of OpenPGP keys found is 0, the label also notes that a key may have been revoked or expired; - blocks input in chat box if key is use is revoked or expired; (cherry picked from commit 2f3ddad1e87f99cdda9d42dbabc528c2b29c0476) Signed-off-by: Vadim Lomovtsev --- plugins/openpgp/po/en.po | 2 +- plugins/openpgp/po/ru.po | 2 +- plugins/openpgp/src/account_settings_entry.vala | 2 +- plugins/openpgp/src/encryption_list_entry.vala | 10 ++++++++++ plugins/openpgp/src/gpgme_helper.vala | 7 ++++++- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/plugins/openpgp/po/en.po b/plugins/openpgp/po/en.po index 2a2a9aaa..4a545bc3 100644 --- a/plugins/openpgp/po/en.po +++ b/plugins/openpgp/po/en.po @@ -20,7 +20,7 @@ msgstr "" #: plugins/openpgp/src/account_settings_entry.vala:72 msgid "No keys available. Generate one!" -msgstr "" +msgstr "No keys available. Generate one or check if your keys aren't expired or revoked!" #: plugins/openpgp/src/account_settings_entry.vala:101 msgid "Select key" diff --git a/plugins/openpgp/po/ru.po b/plugins/openpgp/po/ru.po index f3628e57..b2f2e4e3 100644 --- a/plugins/openpgp/po/ru.po +++ b/plugins/openpgp/po/ru.po @@ -31,7 +31,7 @@ msgstr "Ошибка в GnuPG" #: plugins/openpgp/src/account_settings_entry.vala:72 msgid "No keys available. Generate one!" -msgstr "Нет доступных ключей. Стоило бы сгенерировать один!" +msgstr "Нет доступных ключей. Создайте как минимум один, либо проверьте что уже существующие (ранее созданные) ключи не были отозваны или срок их действия не закончился!" #: plugins/openpgp/src/account_settings_entry.vala:101 msgid "Select key" diff --git a/plugins/openpgp/src/account_settings_entry.vala b/plugins/openpgp/src/account_settings_entry.vala index 7c99942f..366718c3 100644 --- a/plugins/openpgp/src/account_settings_entry.vala +++ b/plugins/openpgp/src/account_settings_entry.vala @@ -160,4 +160,4 @@ public class AccountSettingsEntry : Plugins.AccountSettingsEntry { return stack; } } -} \ No newline at end of file +} diff --git a/plugins/openpgp/src/encryption_list_entry.vala b/plugins/openpgp/src/encryption_list_entry.vala index 68a31f38..2ac3460a 100644 --- a/plugins/openpgp/src/encryption_list_entry.vala +++ b/plugins/openpgp/src/encryption_list_entry.vala @@ -40,6 +40,16 @@ private class EncryptionListEntry : Plugins.EncryptionListEntry, Object { return; } + GPG.Key key_check = GPGHelper.get_public_key(db.get_account_key(conversation.account)); + if (key_check.expired || key_check.revoked) { + string status_str = key_check.expired ? " has expired." : " has been revoked."; + debug("GPG public key %s is NOT fine for encryption: it %s.\n", key_check.fpr, status_str); + input_status_callback(new Plugins.InputFieldStatus("Your GPG key " + key_check.fpr + status_str, + Plugins.InputFieldStatus.MessageType.ERROR, + Plugins.InputFieldStatus.InputState.NO_SEND)); + return; + } + if (conversation.type_ == Conversation.Type.CHAT) { string? key_id = stream_interactor.get_module(Manager.IDENTITY).get_key_id(conversation.account, conversation.counterpart); if (key_id == null) { diff --git a/plugins/openpgp/src/gpgme_helper.vala b/plugins/openpgp/src/gpgme_helper.vala index 956ea1c8..8fda3e07 100644 --- a/plugins/openpgp/src/gpgme_helper.vala +++ b/plugins/openpgp/src/gpgme_helper.vala @@ -112,7 +112,12 @@ public static Gee.List get_keylist(string? pattern = null, bool secret_only try { while (true) { Key key = context.op_keylist_next(); - keys.add(key); + if (!key.expired && !key.revoked) { + debug("PGP Key " + key.fpr + " is valid!"); + keys.add(key); + } else { + debug("PGP Key " + key.fpr + " is either expired or revoked!"); + } } } catch (Error e) { if (e.code != GPGError.ErrorCode.EOF) throw e;