mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-29 21:46:22 +00:00
PGP: Display whether contact public key was received or manually set
This commit is contained in:
@@ -1157,8 +1157,8 @@ static struct cmd_t command_defs[] =
|
|||||||
CMD_ARGS(
|
CMD_ARGS(
|
||||||
{ "libver", "Show which version of the libgpgme library is being used." },
|
{ "libver", "Show which version of the libgpgme library is being used." },
|
||||||
{ "keys", "List all keys known to the system." },
|
{ "keys", "List all keys known to the system." },
|
||||||
{ "contacts", "Show contacts with assigned public keys." },
|
{ "contacts", "Show contacts with assigned public keys." },
|
||||||
{ "setkey <contact> <keyid>", "Manually associate a key ID with a JID." },
|
{ "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." },
|
{ "start [<contact>]", "Start PGP encrypted chat, current contact will be used if not specified." },
|
||||||
{ "end", "End PGP encrypted chat with the current recipient." },
|
{ "end", "End PGP encrypted chat with the current recipient." },
|
||||||
{ "log on|off", "Enable or disable plaintext logging of PGP encrypted messages." },
|
{ "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;
|
GList *curr = jids;
|
||||||
while (curr) {
|
while (curr) {
|
||||||
char *jid = curr->data;
|
char *jid = curr->data;
|
||||||
char *pubkey = g_hash_table_lookup(pubkeys, jid);
|
ProfPGPPubKeyId *pubkeyid = g_hash_table_lookup(pubkeys, jid);
|
||||||
cons_show(" %s: %s", jid, pubkey);
|
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);
|
curr = g_list_next(curr);
|
||||||
}
|
}
|
||||||
g_list_free(jids);
|
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 char* _add_header_footer(const char * const str, const char * const header, const char * const footer);
|
||||||
static void _save_pubkeys(void);
|
static void _save_pubkeys(void);
|
||||||
|
|
||||||
|
void
|
||||||
|
_p_gpg_free_pubkeyid(ProfPGPPubKeyId *pubkeyid)
|
||||||
|
{
|
||||||
|
if (pubkeyid) {
|
||||||
|
free(pubkeyid->id);
|
||||||
|
}
|
||||||
|
free(pubkeyid);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
p_gpg_init(void)
|
p_gpg_init(void)
|
||||||
{
|
{
|
||||||
@@ -70,7 +79,7 @@ p_gpg_init(void)
|
|||||||
log_debug("GPG: Found gpgme version: %s", libversion);
|
log_debug("GPG: Found gpgme version: %s", libversion);
|
||||||
gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
|
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
|
void
|
||||||
@@ -156,7 +165,10 @@ p_gpg_on_connect(const char * const barejid)
|
|||||||
continue;
|
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);
|
g_free(keyid);
|
||||||
gpgme_key_unref(key);
|
gpgme_key_unref(key);
|
||||||
}
|
}
|
||||||
@@ -173,7 +185,7 @@ p_gpg_on_disconnect(void)
|
|||||||
{
|
{
|
||||||
if (pubkeys) {
|
if (pubkeys) {
|
||||||
g_hash_table_destroy(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) {
|
if (pubkeyfile) {
|
||||||
@@ -209,7 +221,10 @@ p_gpg_addkey(const char * const jid, const char * const keyid)
|
|||||||
_save_pubkeys();
|
_save_pubkeys();
|
||||||
|
|
||||||
// update in memory pubkeys list
|
// 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);
|
gpgme_key_unref(key);
|
||||||
|
|
||||||
return TRUE;
|
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);
|
log_debug("Could not find PGP key with ID %s for %s", result->signatures->fpr, barejid);
|
||||||
} else {
|
} else {
|
||||||
log_debug("Fingerprint found for %s: %s ", barejid, key->subkeys->fpr);
|
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);
|
gpgme_key_unref(key);
|
||||||
@@ -493,9 +511,11 @@ p_gpg_sign(const char * const str, const char * const fp)
|
|||||||
char *
|
char *
|
||||||
p_gpg_encrypt(const char * const barejid, const char * const message)
|
p_gpg_encrypt(const char * const barejid, const char * const message)
|
||||||
{
|
{
|
||||||
char *keyid = g_hash_table_lookup(pubkeys, barejid);
|
ProfPGPPubKeyId *pubkeyid = g_hash_table_lookup(pubkeys, barejid);
|
||||||
|
if (!pubkeyid) {
|
||||||
if (!keyid) {
|
return NULL;
|
||||||
|
}
|
||||||
|
if (!pubkeyid->id) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,7 +532,7 @@ p_gpg_encrypt(const char * const barejid, const char * const message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gpgme_key_t key;
|
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) {
|
if (error || key == NULL) {
|
||||||
log_error("GPG: Failed to get key. %s %s", gpgme_strsource(error), gpgme_strerror(error));
|
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;
|
gboolean secret;
|
||||||
} ProfPGPKey;
|
} ProfPGPKey;
|
||||||
|
|
||||||
|
typedef struct pgp_pubkeyid_t {
|
||||||
|
char *id;
|
||||||
|
gboolean received;
|
||||||
|
} ProfPGPPubKeyId;
|
||||||
|
|
||||||
void p_gpg_init(void);
|
void p_gpg_init(void);
|
||||||
void p_gpg_close(void);
|
void p_gpg_close(void);
|
||||||
void p_gpg_on_connect(const char * const barejid);
|
void p_gpg_on_connect(const char * const barejid);
|
||||||
|
|||||||
Reference in New Issue
Block a user