Re: [gmime-devel] [PATCH v2 1/2] Use pinentry-mode loopback in test suite when using "modern" GnuPG



Committed

On 12/2/2016 1:37 PM, Daniel Kahn Gillmor wrote:
The "Modern" GnuPG suite (2.1.x or higher) defaults to relying on the
gpg-agent for secret key material access, which can prompt the user
for a passphrase.  The test suite uses callbacks to supply the
passphrase, so in these modern versions it should use "pinentry-mode
loopback".

Many users of GMime are likely to avoid using the passphrase callback
and instead to rely on permission from the cryptographic agent
directly.  We do not currently test these scenarios, though we could
do so with a fake pinentry.  If we do that, then those scenarios
should *not* use the loopback pinentry-mode, and we'd need to adjust
this setup.

In the longer term, the right way to resolve all of this would be to
use gpgme directly, instead of having our own wrapper that invokes gpg
manually.
---
  tests/testsuite.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 47 insertions(+)

diff --git a/tests/testsuite.c b/tests/testsuite.c
index fa4fd9c..559d7dc 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -27,6 +27,10 @@
  #ifdef ENABLE_THREADS
  #include <pthread.h>
  #endif
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
#include "testsuite.h" @@ -346,9 +350,40 @@ g_throw (Exception *ex)
        longjmp (env->env, 1);
  }
+static int
+is_gpg_modern()
+{
+       const char vheader[] = "gpg (GnuPG) ";
+       FILE *vpipe;
+       char *vstring;
+       size_t vlen;
+       int ret;
+
+       if ((vpipe = popen ("gpg --version", "r")) == NULL)
+               return 0;
+       vlen = 0;
+       vstring = NULL;
+       if (getline (&vstring, &vlen, vpipe) == -1) {
+               pclose (vpipe);
+               return 0;
+       }
+       pclose (vpipe);
+       if (strncmp (vstring, vheader, sizeof (vheader) - 1))
+               return 0;
+       ret = (vstring[sizeof (vheader) - 1] > '2') ||
+               (vstring[sizeof (vheader) - 1] == '2' &&
+                vstring[sizeof (vheader)] == '.' &&
+                vstring[sizeof (vheader) + 1] >= '1');
+       free (vstring);
+       return ret;
+}
+
  int
  testsuite_setup_gpghome (void)
  {
+       FILE *gpgconf;
+       const char directive[] = "pinentry-mode loopback\n";
+       
        /* reset .gnupg config directory */
        if (system ("/bin/rm -rf ./tmp") != 0)
                return EXIT_FAILURE;
@@ -365,6 +400,18 @@ testsuite_setup_gpghome (void)
        if (system ("gpg --list-keys > /dev/null 2>&1") != 0)
                return EXIT_FAILURE;
        
+       if (is_gpg_modern()) {
+               if ((gpgconf = fopen ("./tmp/.gnupg/gpg.conf", "w")) == NULL)
+                       return EXIT_FAILURE;
+               if (fwrite (directive, sizeof(directive) - 1, 1, gpgconf) != 1) {
+                       fclose (gpgconf);
+                       return EXIT_FAILURE;
+               }
+               if (fclose (gpgconf))
+                       return EXIT_FAILURE;
+       }
+       
+       
        return EXIT_SUCCESS;
  }




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]