From 70cccaf58ccb2b541716c933e86f886ec615ebfd Mon Sep 17 00:00:00 2001 From: Terra Date: Sun, 3 Jun 2018 18:36:33 -0400 Subject: [PATCH] gnupg.c: fix gnupg_adddecryptkey() passphrase handling This corrects an issue where the given passphrase was not being respected and pinentry was being called regardless. This fix will set the pinentry_mode to loopback mode so that our custom passphrase_decrypt_cb() function will be called. --- gnupg.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gnupg.c b/gnupg.c index b438d6e..559cf35 100644 --- a/gnupg.c +++ b/gnupg.c @@ -1048,6 +1048,7 @@ PHP_FUNCTION(gnupg_adddecryptkey) phpc_str_size_t passphrase_len; gpgme_key_t gpgme_key; gpgme_subkey_t gpgme_subkey; + int loopback_set = 0; GNUPG_GETOBJ(); @@ -1073,6 +1074,10 @@ PHP_FUNCTION(gnupg_adddecryptkey) PHPC_HASH_CSTR_ADD_PTR( PHPC_THIS->decryptkeys, gpgme_subkey->keyid, passphrase, passphrase_len + 1); + if (!loopback_set && passphrase && passphrase_len > 0) { + gpgme_set_pinentry_mode(PHPC_THIS->ctx, GPGME_PINENTRY_MODE_LOOPBACK); + loopback_set = 1; + } } gpgme_subkey = gpgme_subkey->next; }