about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-08-25 21:58:24 +0100
committerJames Booth <boothj5@gmail.com>2015-08-25 21:58:24 +0100
commit592a3695a573ca5e0a1fa45b79b8a0e64225f1d9 (patch)
tree1058c6e1d2ba5e116c4c3773ae38cb563b4cbfbd
parent872ab8e5297342c22cf45f86754f0958ca2a0617 (diff)
downloadprofani-tty-592a3695a573ca5e0a1fa45b79b8a0e64225f1d9.tar.gz
PGP: Do not save contact's fingerprint when no key found
-rw-r--r--src/pgp/gpg.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/pgp/gpg.c b/src/pgp/gpg.c
index 9d594be4..3067f81d 100644
--- a/src/pgp/gpg.c
+++ b/src/pgp/gpg.c
@@ -196,7 +196,7 @@ p_gpg_addkey(const char * const jid, const char * const keyid)
     }
 
     gpgme_key_t key = NULL;
-    error = gpgme_get_key(ctx, keyid, &key, 1);
+    error = gpgme_get_key(ctx, keyid, &key, 0);
     gpgme_release(ctx);
 
     if (error || key == NULL) {
@@ -406,8 +406,16 @@ p_gpg_verify(const char * const barejid, const char *const sign)
     gpgme_verify_result_t result = gpgme_op_verify_result(ctx);
     if (result) {
         if (result->signatures) {
-            log_debug("Fingerprint found for %s: %s ", barejid, result->signatures->fpr);
-            g_hash_table_replace(fingerprints, strdup(barejid), strdup(result->signatures->fpr));
+            gpgme_key_t key = NULL;
+            error = gpgme_get_key(ctx, result->signatures->fpr, &key, 0);
+            if (error) {
+                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(fingerprints, strdup(barejid), strdup(key->subkeys->fpr));
+            }
+
+            gpgme_key_unref(key);
         }
     }