Add optional pgp public key autoimport

Refactor `p_gpg_list_keys`
Add `/pgp autoimport` command,
it's not described in XEP-0027, but used in some clients,
such as PSI, Pidgin. It will autoimport keys received with
`/pgp sendpub`, in plain text as a message, or using features,
provided in other clients. It doesn't autoassign them, but shows
command to assign, letting user to decide.
Improve documentation for some preexisting functions
Add contact argument to `/pgp sendpub`
This commit is contained in:
John Hernandez
2023-06-30 14:33:17 +02:00
parent 349e4cb322
commit 36784738fc
10 changed files with 269 additions and 52 deletions

View File

@@ -53,6 +53,9 @@
#ifdef HAVE_LIBOTR
#include "otr/otr.h"
#endif
#ifdef HAVE_LIBGPGME
#include "pgp/gpg.h"
#endif
#ifdef HAVE_OMEMO
#include "omemo/omemo.h"
#endif
@@ -320,6 +323,7 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr
char* old_plain = message->plain;
message->plain = plugins_pre_chat_message_display(message->from_jid->barejid, message->from_jid->resourcepart, message->plain);
gboolean show_message = true;
ProfWin* window = (ProfWin*)chatwin;
int num = wins_get_num(window);
@@ -333,12 +337,29 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr
}
free(mybarejid);
#ifdef HAVE_LIBGPGME
if (prefs_get_boolean(PREF_PGP_PUBKEY_AUTOIMPORT)) {
if (p_gpg_is_public_key_format(message->plain)) {
ProfPGPKey* key = p_gpg_import_pubkey(message->plain);
if (key != NULL) {
show_message = false;
win_println(window, THEME_DEFAULT, "-", "Received and imported PGP key %s: \"%s\". To assign it to the correspondent using /pgp setkey %s %s", key->fp, key->name, display_name, key->id);
p_gpg_free_key(key);
} else {
win_println(window, THEME_DEFAULT, "-", "Received PGP key, but couldn't import PGP key above.");
}
}
}
#endif
gboolean is_current = wins_is_current(window);
gboolean notify = prefs_do_chat_notify(is_current) && !message->is_mam;
// currently viewing chat window with sender
if (wins_is_current(window)) {
win_print_incoming(window, display_name, message);
if (show_message) {
win_print_incoming(window, display_name, message);
}
title_bar_set_typing(FALSE);
status_bar_active(num, WIN_CHAT, chatwin->barejid);
@@ -377,7 +398,9 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr
}
win_insert_last_read_position_marker((ProfWin*)chatwin, chatwin->barejid);
win_print_incoming(window, display_name, message);
if (show_message) {
win_print_incoming(window, display_name, message);
}
}
if (!message->is_mam) {