about summary refs log tree commit diff stats
path: root/src/pgp
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-08-23 22:18:54 +0100
committerJames Booth <boothj5@gmail.com>2015-08-23 22:18:54 +0100
commitc07638746a37c333dc15d7b8597d0e310fe5286c (patch)
tree9b7bacd040317ecb7dac28c238042396c1b0d817 /src/pgp
parentd791e4dd597ecaacf3864e4af4f60953ba24467f (diff)
downloadprofani-tty-c07638746a37c333dc15d7b8597d0e310fe5286c.tar.gz
Log recipient used for PGP decryption
Diffstat (limited to 'src/pgp')
-rw-r--r--src/pgp/gpg.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/pgp/gpg.c b/src/pgp/gpg.c
index 39e743eb..3e2cfe67 100644
--- a/src/pgp/gpg.c
+++ b/src/pgp/gpg.c
@@ -484,14 +484,32 @@ p_gpg_decrypt(const char * const barejid, const char * const cipher)
 
     error = gpgme_op_decrypt(ctx, cipher_data, plain_data);
     gpgme_data_release(cipher_data);
-    gpgme_release(ctx);
 
     if (error) {
         log_error("GPG: Failed to encrypt message. %s %s", gpgme_strsource(error), gpgme_strerror(error));
         gpgme_data_release(plain_data);
+        gpgme_release(ctx);
         return NULL;
     }
 
+    gpgme_decrypt_result_t res = gpgme_op_decrypt_result(ctx);
+    if (res) {
+        gpgme_recipient_t recipient = res->recipients;
+        if (recipient) {
+            gpgme_key_t key;
+            error = gpgme_get_key(ctx, recipient->keyid, &key, 0);
+
+            if (!error && key) {
+                const char *addr = gpgme_key_get_string_attr(key, GPGME_ATTR_EMAIL, NULL, 0);
+                if (addr) {
+                    log_debug("GPG: Decrypted message for recipient: %s", addr);
+                }
+                gpgme_key_unref(key);
+            }
+        }
+    }
+    gpgme_release(ctx);
+
     size_t len = 0;
     char *plain_str = gpgme_data_release_and_get_mem(plain_data, &len);
     char *result = NULL;