about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-09-01 19:24:56 +0100
committerJames Booth <boothj5@gmail.com>2015-09-01 19:24:56 +0100
commitdd346eefc4f633db2047694ce49ef91314e5a5b4 (patch)
tree6eed5e798f725418dfe56c9556d2c0155ac5f703 /src
parent508f858b0b7f511d48ecba69e29610c6acc39ed2 (diff)
downloadprofani-tty-dd346eefc4f633db2047694ce49ef91314e5a5b4.tar.gz
Added PGP passphrase callback
Diffstat (limited to 'src')
-rw-r--r--src/pgp/gpg.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/pgp/gpg.c b/src/pgp/gpg.c
index cda77e13..aeb88e5a 100644
--- a/src/pgp/gpg.c
+++ b/src/pgp/gpg.c
@@ -48,6 +48,7 @@
 #include "log.h"
 #include "common.h"
 #include "tools/autocomplete.h"
+#include "ui/ui.h"
 
 #define PGP_SIGNATURE_HEADER "-----BEGIN PGP SIGNATURE-----"
 #define PGP_SIGNATURE_FOOTER "-----END PGP SIGNATURE-----"
@@ -75,6 +76,23 @@ _p_gpg_free_pubkeyid(ProfPGPPubKeyId *pubkeyid)
     free(pubkeyid);
 }
 
+static gpgme_error_t *
+_p_gpg_passphrase_cb(void *hook, const char *uid_hint, const char *passphrase_info, int prev_was_bad, int fd)
+{
+    cons_show("Passphrase callback");
+    if (uid_hint) {
+        cons_show("  uid_hind: %s", uid_hint);
+    }
+    if (passphrase_info) {
+        cons_show("  passphrase_info: %s", passphrase_info);
+    }
+    if (prev_was_bad) {
+        cons_show("  prev_was_bad");
+    }
+    gpgme_io_writen(fd, "password\n", strlen("password\n"));
+    return 0;
+}
+
 void
 p_gpg_init(void)
 {
@@ -158,6 +176,8 @@ p_gpg_on_connect(const char * const barejid)
         return;
     }
 
+    gpgme_set_passphrase_cb(ctx, (gpgme_passphrase_cb_t)_p_gpg_passphrase_cb, NULL);
+
     int i = 0;
     for (i = 0; i < len; i++) {
         GError *gerr = NULL;
@@ -217,6 +237,8 @@ p_gpg_addkey(const char * const jid, const char * const keyid)
         return FALSE;
     }
 
+    gpgme_set_passphrase_cb(ctx, (gpgme_passphrase_cb_t)_p_gpg_passphrase_cb, NULL);
+
     gpgme_key_t key = NULL;
     error = gpgme_get_key(ctx, keyid, &key, 0);
     gpgme_release(ctx);
@@ -281,6 +303,8 @@ p_gpg_list_keys(void)
         return NULL;
     }
 
+    gpgme_set_passphrase_cb(ctx, (gpgme_passphrase_cb_t)_p_gpg_passphrase_cb, NULL);
+
     error = gpgme_op_keylist_start(ctx, NULL, 0);
     if (error == GPG_ERR_NO_ERROR) {
         gpgme_key_t key;
@@ -379,6 +403,8 @@ p_gpg_valid_key(const char * const keyid)
         return FALSE;
     }
 
+    gpgme_set_passphrase_cb(ctx, (gpgme_passphrase_cb_t)_p_gpg_passphrase_cb, NULL);
+
     gpgme_key_t key = NULL;
     error = gpgme_get_key(ctx, keyid, &key, 1);
 
@@ -420,6 +446,8 @@ p_gpg_verify(const char * const barejid, const char *const sign)
         return;
     }
 
+    gpgme_set_passphrase_cb(ctx, (gpgme_passphrase_cb_t)_p_gpg_passphrase_cb, NULL);
+
     char *sign_with_header_footer = _add_header_footer(sign, PGP_SIGNATURE_HEADER, PGP_SIGNATURE_FOOTER);
     gpgme_data_t sign_data;
     gpgme_data_new_from_mem(&sign_data, sign_with_header_footer, strlen(sign_with_header_footer), 1);
@@ -470,6 +498,8 @@ p_gpg_sign(const char * const str, const char * const fp)
         return NULL;
     }
 
+    gpgme_set_passphrase_cb(ctx, (gpgme_passphrase_cb_t)_p_gpg_passphrase_cb, NULL);
+
     gpgme_key_t key = NULL;
     error = gpgme_get_key(ctx, fp, &key, 1);
 
@@ -551,6 +581,8 @@ p_gpg_encrypt(const char * const barejid, const char * const message)
         return NULL;
     }
 
+    gpgme_set_passphrase_cb(ctx, (gpgme_passphrase_cb_t)_p_gpg_passphrase_cb, NULL);
+
     gpgme_key_t key;
     error = gpgme_get_key(ctx, pubkeyid->id, &key, 0);
 
@@ -605,6 +637,8 @@ p_gpg_decrypt(const char * const cipher)
         return NULL;
     }
 
+    gpgme_set_passphrase_cb(ctx, (gpgme_passphrase_cb_t)_p_gpg_passphrase_cb, NULL);
+
     char *cipher_with_headers = _add_header_footer(cipher, PGP_MESSAGE_HEADER, PGP_MESSAGE_FOOTER);
     gpgme_data_t cipher_data;
     gpgme_data_new_from_mem(&cipher_data, cipher_with_headers, strlen(cipher_with_headers), 1);