Skip to content

Commit

Permalink
OPENPGP PLUGIN: Don't list expired/revoked GPG key
Browse files Browse the repository at this point in the history
	- 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
  • Loading branch information
eerielili committed Apr 16, 2024
1 parent 7e3ceda commit 2f3ddad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions plugins/openpgp/src/account_settings_entry.vala
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class AccountSettingsEntry : Plugins.AccountSettingsEntry {
return;
}
if (keys.size == 0) {
label.set_markup(build_markup_string(_("Key publishing disabled"), _("No keys available. Generate one!")));
label.set_markup(build_markup_string(_("Key publishing disabled"), _("No keys available. Generate one or check if your keys aren't expired or revoked!")));
return;
}

Expand Down Expand Up @@ -160,4 +160,4 @@ public class AccountSettingsEntry : Plugins.AccountSettingsEntry {
return stack;
}
}
}
}
9 changes: 9 additions & 0 deletions plugins/openpgp/src/encryption_list_entry.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ private class EncryptionListEntry : Plugins.EncryptionListEntry, Object {
return null;
}


public void encryption_activated(Entities.Conversation conversation, Plugins.SetInputFieldStatus input_status_callback) {
try {
GPGHelper.get_public_key(db.get_account_key(conversation.account) ?? "");
Expand All @@ -40,6 +41,14 @@ 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) {
Expand Down
8 changes: 7 additions & 1 deletion plugins/openpgp/src/gpgme_helper.vala
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ public static Gee.List<Key> 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;
Expand Down

0 comments on commit 2f3ddad

Please sign in to comment.