mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
PGP: Display whether contact public key was received or manually set
This commit is contained in:
parent
fc1ee79190
commit
55c2d1cc21
@ -1157,8 +1157,8 @@ static struct cmd_t command_defs[] =
|
||||
CMD_ARGS(
|
||||
{ "libver", "Show which version of the libgpgme library is being used." },
|
||||
{ "keys", "List all keys known to the system." },
|
||||
{ "contacts", "Show contacts with assigned public keys." },
|
||||
{ "setkey <contact> <keyid>", "Manually associate a key ID with a JID." },
|
||||
{ "contacts", "Show contacts with assigned public keys." },
|
||||
{ "setkey <contact> <keyid>", "Manually associate a contact with a public key." },
|
||||
{ "start [<contact>]", "Start PGP encrypted chat, current contact will be used if not specified." },
|
||||
{ "end", "End PGP encrypted chat with the current recipient." },
|
||||
{ "log on|off", "Enable or disable plaintext logging of PGP encrypted messages." },
|
||||
|
@ -4287,8 +4287,12 @@ cmd_pgp(ProfWin *window, const char * const command, gchar **args)
|
||||
GList *curr = jids;
|
||||
while (curr) {
|
||||
char *jid = curr->data;
|
||||
char *pubkey = g_hash_table_lookup(pubkeys, jid);
|
||||
cons_show(" %s: %s", jid, pubkey);
|
||||
ProfPGPPubKeyId *pubkeyid = g_hash_table_lookup(pubkeys, jid);
|
||||
if (pubkeyid->received) {
|
||||
cons_show(" %s: %s (received)", jid, pubkeyid->id);
|
||||
} else {
|
||||
cons_show(" %s: %s (stored)", jid, pubkeyid->id);
|
||||
}
|
||||
curr = g_list_next(curr);
|
||||
}
|
||||
g_list_free(jids);
|
||||
|
@ -63,6 +63,15 @@ static char* _remove_header_footer(char *str, const char * const footer);
|
||||
static char* _add_header_footer(const char * const str, const char * const header, const char * const footer);
|
||||
static void _save_pubkeys(void);
|
||||
|
||||
void
|
||||
_p_gpg_free_pubkeyid(ProfPGPPubKeyId *pubkeyid)
|
||||
{
|
||||
if (pubkeyid) {
|
||||
free(pubkeyid->id);
|
||||
}
|
||||
free(pubkeyid);
|
||||
}
|
||||
|
||||
void
|
||||
p_gpg_init(void)
|
||||
{
|
||||
@ -70,7 +79,7 @@ p_gpg_init(void)
|
||||
log_debug("GPG: Found gpgme version: %s", libversion);
|
||||
gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
|
||||
|
||||
pubkeys = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
||||
pubkeys = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_p_gpg_free_pubkeyid);
|
||||
}
|
||||
|
||||
void
|
||||
@ -156,7 +165,10 @@ p_gpg_on_connect(const char * const barejid)
|
||||
continue;
|
||||
}
|
||||
|
||||
g_hash_table_replace(pubkeys, strdup(jid), strdup(keyid));
|
||||
ProfPGPPubKeyId *pubkeyid = malloc(sizeof(ProfPGPPubKeyId));
|
||||
pubkeyid->id = strdup(keyid);
|
||||
pubkeyid->received = FALSE;
|
||||
g_hash_table_replace(pubkeys, strdup(jid), pubkeyid);
|
||||
g_free(keyid);
|
||||
gpgme_key_unref(key);
|
||||
}
|
||||
@ -173,7 +185,7 @@ p_gpg_on_disconnect(void)
|
||||
{
|
||||
if (pubkeys) {
|
||||
g_hash_table_destroy(pubkeys);
|
||||
pubkeys = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
||||
pubkeys = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_p_gpg_free_pubkeyid);
|
||||
}
|
||||
|
||||
if (pubkeyfile) {
|
||||
@ -209,7 +221,10 @@ p_gpg_addkey(const char * const jid, const char * const keyid)
|
||||
_save_pubkeys();
|
||||
|
||||
// update in memory pubkeys list
|
||||
g_hash_table_replace(pubkeys, strdup(jid), strdup(keyid));
|
||||
ProfPGPPubKeyId *pubkeyid = malloc(sizeof(ProfPGPPubKeyId));
|
||||
pubkeyid->id = strdup(keyid);
|
||||
pubkeyid->received = FALSE;
|
||||
g_hash_table_replace(pubkeys, strdup(jid), pubkeyid);
|
||||
gpgme_key_unref(key);
|
||||
|
||||
return TRUE;
|
||||
@ -412,7 +427,10 @@ p_gpg_verify(const char * const barejid, const char *const sign)
|
||||
log_debug("Could not find PGP key with ID %s for %s", result->signatures->fpr, barejid);
|
||||
} else {
|
||||
log_debug("Fingerprint found for %s: %s ", barejid, key->subkeys->fpr);
|
||||
g_hash_table_replace(pubkeys, strdup(barejid), strdup(key->subkeys->keyid));
|
||||
ProfPGPPubKeyId *pubkeyid = malloc(sizeof(ProfPGPPubKeyId));
|
||||
pubkeyid->id = strdup(key->subkeys->keyid);
|
||||
pubkeyid->received = TRUE;
|
||||
g_hash_table_replace(pubkeys, strdup(barejid), pubkeyid);
|
||||
}
|
||||
|
||||
gpgme_key_unref(key);
|
||||
@ -493,9 +511,11 @@ p_gpg_sign(const char * const str, const char * const fp)
|
||||
char *
|
||||
p_gpg_encrypt(const char * const barejid, const char * const message)
|
||||
{
|
||||
char *keyid = g_hash_table_lookup(pubkeys, barejid);
|
||||
|
||||
if (!keyid) {
|
||||
ProfPGPPubKeyId *pubkeyid = g_hash_table_lookup(pubkeys, barejid);
|
||||
if (!pubkeyid) {
|
||||
return NULL;
|
||||
}
|
||||
if (!pubkeyid->id) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -512,7 +532,7 @@ p_gpg_encrypt(const char * const barejid, const char * const message)
|
||||
}
|
||||
|
||||
gpgme_key_t key;
|
||||
error = gpgme_get_key(ctx, keyid, &key, 0);
|
||||
error = gpgme_get_key(ctx, pubkeyid->id, &key, 0);
|
||||
|
||||
if (error || key == NULL) {
|
||||
log_error("GPG: Failed to get key. %s %s", gpgme_strsource(error), gpgme_strerror(error));
|
||||
|
@ -46,6 +46,11 @@ typedef struct pgp_key_t {
|
||||
gboolean secret;
|
||||
} ProfPGPKey;
|
||||
|
||||
typedef struct pgp_pubkeyid_t {
|
||||
char *id;
|
||||
gboolean received;
|
||||
} ProfPGPPubKeyId;
|
||||
|
||||
void p_gpg_init(void);
|
||||
void p_gpg_close(void);
|
||||
void p_gpg_on_connect(const char * const barejid);
|
||||
|
Loading…
Reference in New Issue
Block a user