[git] GnuPG - branch, master, updated. gnupg-2.1.16-73-ga75790b

by Werner Koch cvs at cvs.gnupg.org
Thu Dec 8 17:07:08 CET 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, master has been updated
       via  a75790b74095828f967c012eff7033f570d93077 (commit)
       via  d8c5e8ccfdb53cc327f7520fc7badc31d0c9c666 (commit)
       via  c3138decd77d788906885b638b344d0d1faf32c0 (commit)
      from  a2bedc8ac6fcdcd1de0a9fa3d540006481387dff (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit a75790b74095828f967c012eff7033f570d93077
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Dec 8 17:03:26 2016 +0100

    gpg: Fix the fix out-of-bounds access.
    
    * g10/tofu.c (build_conflict_set): Revert to int* and fix calloc.
    --
    
    The original code used an int array and thus better keep that and do
    not limit it to 128 entries.
    
    Fixes-commit: c3008bffac68b6f31e9ae9bad837cdce5de7c0db
    Fixes-commit: 3b5b94ceab7c0ed9501c5cf54b4efa17fcd7300a
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/g10/tofu.c b/g10/tofu.c
index abf1ab4..d15b25f 100644
--- a/g10/tofu.c
+++ b/g10/tofu.c
@@ -2227,10 +2227,10 @@ build_conflict_set (tofu_dbs_t dbs,
     int j;
     strlist_t *prevp;
     strlist_t iter_next;
-    char *die;
+    int *die;
 
     log_assert (conflict_set_count > 0);
-    die = xtrycalloc (1, conflict_set_count);
+    die = xtrycalloc (conflict_set_count, sizeof *die);
     if (!die)
       {
         /*err = gpg_error_from_syserror ();*/

commit d8c5e8ccfdb53cc327f7520fc7badc31d0c9c666
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Dec 8 16:57:21 2016 +0100

    wks: New option --check for gpg-wks-client.
    
    * tools/call-dirmngr.c (wkd_get_key): New.
    * tools/gpg-wks-client.c (aCheck): New constant.
    (opts): New option "--check".
    (main): Call command_check.
    (command_check): New.
    --
    
    GnuPG-bug-id: 2866
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/tools/call-dirmngr.c b/tools/call-dirmngr.c
index c5ee244..51f1fa1 100644
--- a/tools/call-dirmngr.c
+++ b/tools/call-dirmngr.c
@@ -258,3 +258,55 @@ wkd_get_policy_flags (const char *addrspec, estream_t *r_buffer)
   assuan_release (ctx);
   return err;
 }
+
+
+/* Ask the dirmngr for the key for ADDRSPEC.  On success a stream with
+ * the key is stored at R_KEY.  */
+gpg_error_t
+wkd_get_key (const char *addrspec, estream_t *r_key)
+{
+  gpg_error_t err;
+  assuan_context_t ctx;
+  struct wkd_get_parm_s parm;
+  char *line = NULL;
+
+  memset (&parm, 0, sizeof parm);
+  *r_key = NULL;
+
+  err = connect_dirmngr (&ctx);
+  if (err)
+    return err;
+
+  line = es_bsprintf ("WKD_GET -- %s", addrspec);
+  if (!line)
+    {
+      err = gpg_error_from_syserror ();
+      goto leave;
+    }
+  if (strlen (line) + 2 >= ASSUAN_LINELENGTH)
+    {
+      err = gpg_error (GPG_ERR_TOO_LARGE);
+      goto leave;
+    }
+
+  parm.memfp = es_fopenmem (0, "rwb");
+  if (!parm.memfp)
+    {
+      err = gpg_error_from_syserror ();
+      goto leave;
+    }
+  err = assuan_transact (ctx, line, wkd_get_data_cb, &parm,
+                         NULL, NULL, wkd_get_status_cb, &parm);
+  if (err)
+    goto leave;
+
+  es_rewind (parm.memfp);
+  *r_key = parm.memfp;
+  parm.memfp = NULL;
+
+ leave:
+  es_fclose (parm.memfp);
+  xfree (line);
+  assuan_release (ctx);
+  return err;
+}
diff --git a/tools/call-dirmngr.h b/tools/call-dirmngr.h
index 83ebd2c..32486b1 100644
--- a/tools/call-dirmngr.h
+++ b/tools/call-dirmngr.h
@@ -25,5 +25,7 @@ gpg_error_t wkd_get_submission_address (const char *addrspec,
                                         char **r_addrspec);
 gpg_error_t wkd_get_policy_flags (const char *addrspec, estream_t *r_buffer);
 
+gpg_error_t wkd_get_key (const char *addrspec, estream_t *r_key);
+
 
 #endif /*GNUPG_TOOLS_CALL_DIRMNGR_H*/
diff --git a/tools/gpg-wks-client.c b/tools/gpg-wks-client.c
index 9bf5403..1a53f39 100644
--- a/tools/gpg-wks-client.c
+++ b/tools/gpg-wks-client.c
@@ -50,6 +50,7 @@ enum cmd_and_opt_values
     oDebug      = 500,
 
     aSupported,
+    aCheck,
     aCreate,
     aReceive,
     aRead,
@@ -68,6 +69,8 @@ static ARGPARSE_OPTS opts[] = {
 
   ARGPARSE_c (aSupported, "supported",
               ("check whether provider supports WKS")),
+  ARGPARSE_c (aCheck, "check",
+              ("check whether a key is available")),
   ARGPARSE_c (aCreate,   "create",
               ("create a publication request")),
   ARGPARSE_c (aReceive,   "receive",
@@ -111,6 +114,7 @@ const char *fake_submission_addr;
 
 static void wrong_args (const char *text) GPGRT_ATTR_NORETURN;
 static gpg_error_t command_supported (char *userid);
+static gpg_error_t command_check (char *userid);
 static gpg_error_t command_send (const char *fingerprint, char *userid);
 static gpg_error_t encrypt_response (estream_t *r_output, estream_t input,
                                      const char *addrspec,
@@ -198,6 +202,7 @@ parse_arguments (ARGPARSE_ARGS *pargs, ARGPARSE_OPTS *popts)
 	case aCreate:
 	case aReceive:
 	case aRead:
+        case aCheck:
           cmd = pargs->r_opt;
           break;
 
@@ -290,6 +295,12 @@ main (int argc, char **argv)
         log_error ("processing mail failed: %s\n", gpg_strerror (err));
       break;
 
+    case aCheck:
+      if (argc != 1)
+        wrong_args ("--check USER-ID");
+      command_check (argv[0]);
+      break;
+
     default:
       usage (1);
       break;
@@ -532,6 +543,96 @@ command_supported (char *userid)
 
 
 

+/* Check whether the key for USERID is available in the WKD.  */
+static gpg_error_t
+command_check (char *userid)
+{
+  gpg_error_t err;
+  char *addrspec = NULL;
+  estream_t key = NULL;
+  char *fpr = NULL;
+  strlist_t mboxes = NULL;
+  strlist_t sl;
+  int found = 0;
+
+  addrspec = mailbox_from_userid (userid);
+  if (!addrspec)
+    {
+      log_error (_("\"%s\" is not a proper mail address\n"), userid);
+      err = gpg_error (GPG_ERR_INV_USER_ID);
+      goto leave;
+    }
+
+  /* Get the submission address.  */
+  err = wkd_get_key (addrspec, &key);
+  switch (gpg_err_code (err))
+    {
+    case 0:
+      if (opt.verbose)
+        log_info ("public key for '%s' found via WKD\n", addrspec);
+      /* Fixme: Check that the key contains the user id.  */
+      break;
+
+    case GPG_ERR_NO_DATA: /* No such key.  */
+      if (opt.verbose)
+        log_info ("public key for '%s' NOT found via WKD\n", addrspec);
+      err = gpg_error (GPG_ERR_NO_PUBKEY);
+      log_inc_errorcount ();
+      break;
+
+    case GPG_ERR_UNKNOWN_HOST:
+      if (opt.verbose)
+        log_info ("error looking up '%s' via WKD: %s\n",
+                  addrspec, gpg_strerror (err));
+      err = gpg_error (GPG_ERR_NOT_SUPPORTED);
+      break;
+
+    default:
+      log_error ("error looking up '%s' via WKD: %s\n",
+                 addrspec, gpg_strerror (err));
+      break;
+    }
+
+  if (err)
+    goto leave;
+
+  /* Look closer at the key.  */
+  err = wks_list_key (key, &fpr, &mboxes);
+  if (err || !fpr)
+    {
+      log_error ("error parsing key: %s\n",
+                 err? gpg_strerror (err) : "no fingerprint found");
+      err = gpg_error (GPG_ERR_NO_PUBKEY);
+      goto leave;
+    }
+
+  if (opt.verbose)
+    log_info ("fingerprint: %s\n", fpr);
+
+  for (sl = mboxes; sl; sl = sl->next)
+    {
+      if (!strcmp (sl->d, addrspec))
+        found = 1;
+      if (opt.verbose)
+        log_info ("  addr-spec: %s\n", sl->d);
+    }
+  if (!found)
+    {
+      log_error ("public key for '%s' has no user id with the mail address\n",
+                 addrspec);
+      err = gpg_error (GPG_ERR_CERT_REVOKED);
+    }
+
+ leave:
+  xfree (fpr);
+  free_strlist (mboxes);
+  es_fclose (key);
+  xfree (addrspec);
+  return err;
+}
+
+
+

 /* Locate the key by fingerprint and userid and send a publication
  * request.  */
 static gpg_error_t

commit c3138decd77d788906885b638b344d0d1faf32c0
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Dec 8 16:11:42 2016 +0100

    tools: Move a function from gpg-wks-server to wks-util.c.
    
    * tools/gpg-wks-server.c (list_key_status_cb): Remove.
    (list_key): Move to ...
    * tools/wks-util.c (wks_list_key): here and rename.  Add new args
    R_FPR and R_MBOXES and remove the CTX.
    (list_key_status_cb): New.
    * tools/wks-util.c: Include ccparray.h, exectool.h, and mbox-util.h.
    * tools/gpg-wks-server.c (process_new_key): Replace list_key by
    wks_list_key.
    (check_and_publish): Ditto.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/tools/gpg-wks-server.c b/tools/gpg-wks-server.c
index fd65b40..1a91858 100644
--- a/tools/gpg-wks-server.c
+++ b/tools/gpg-wks-server.c
@@ -348,168 +348,6 @@ main (int argc, char **argv)
 }
 
 
-

-static void
-list_key_status_cb (void *opaque, const char *keyword, char *args)
-{
-  server_ctx_t ctx = opaque;
-  (void)ctx;
-  if (DBG_CRYPTO)
-    log_debug ("gpg status: %s %s\n", keyword, args);
-}
-
-
-static gpg_error_t
-list_key (server_ctx_t ctx, estream_t key)
-{
-  gpg_error_t err;
-  ccparray_t ccp;
-  const char **argv;
-  estream_t listing;
-  char *line = NULL;
-  size_t length_of_line = 0;
-  size_t  maxlen;
-  ssize_t len;
-  char **fields = NULL;
-  int nfields;
-  int lnr;
-  char *mbox = NULL;
-
-  /* We store our results in the context - clear it first.  */
-  xfree (ctx->fpr);
-  ctx->fpr = NULL;
-  free_strlist (ctx->mboxes);
-  ctx->mboxes = NULL;
-
-  /* Open a memory stream.  */
-  listing = es_fopenmem (0, "w+b");
-  if (!listing)
-    {
-      err = gpg_error_from_syserror ();
-      log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
-      return err;
-    }
-
-  ccparray_init (&ccp, 0);
-
-  ccparray_put (&ccp, "--no-options");
-  if (!opt.verbose)
-    ccparray_put (&ccp, "--quiet");
-  else if (opt.verbose > 1)
-    ccparray_put (&ccp, "--verbose");
-  ccparray_put (&ccp, "--batch");
-  ccparray_put (&ccp, "--status-fd=2");
-  ccparray_put (&ccp, "--always-trust");
-  ccparray_put (&ccp, "--with-colons");
-  ccparray_put (&ccp, "--dry-run");
-  ccparray_put (&ccp, "--import-options=import-minimal,import-show");
-  ccparray_put (&ccp, "--import");
-
-  ccparray_put (&ccp, NULL);
-  argv = ccparray_get (&ccp, NULL);
-  if (!argv)
-    {
-      err = gpg_error_from_syserror ();
-      goto leave;
-    }
-  err = gnupg_exec_tool_stream (opt.gpg_program, argv, key,
-                                NULL, listing,
-                                list_key_status_cb, ctx);
-  if (err)
-    {
-      log_error ("import failed: %s\n", gpg_strerror (err));
-      goto leave;
-    }
-
-  es_rewind (listing);
-  lnr = 0;
-  maxlen = 2048; /* Set limit.  */
-  while ((len = es_read_line (listing, &line, &length_of_line, &maxlen)) > 0)
-    {
-      lnr++;
-      if (!maxlen)
-        {
-          log_error ("received line too long\n");
-          err = gpg_error (GPG_ERR_LINE_TOO_LONG);
-          goto leave;
-        }
-      /* Strip newline and carriage return, if present.  */
-      while (len > 0
-	     && (line[len - 1] == '\n' || line[len - 1] == '\r'))
-	line[--len] = '\0';
-      /* log_debug ("line '%s'\n", line); */
-
-      xfree (fields);
-      fields = strtokenize (line, ":");
-      if (!fields)
-        {
-          err = gpg_error_from_syserror ();
-          log_error ("strtokenize failed: %s\n", gpg_strerror (err));
-          goto leave;
-        }
-      for (nfields = 0; fields[nfields]; nfields++)
-        ;
-      if (!nfields)
-        {
-          err = gpg_error (GPG_ERR_INV_ENGINE);
-          goto leave;
-        }
-      if (!strcmp (fields[0], "sec"))
-        {
-          /* gpg may return "sec" as the first record - but we do not
-           * accept secret keys.  */
-          err = gpg_error (GPG_ERR_NO_PUBKEY);
-          goto leave;
-        }
-      if (lnr == 1 && strcmp (fields[0], "pub"))
-        {
-          /* First record is not a public key.  */
-          err = gpg_error (GPG_ERR_INV_ENGINE);
-          goto leave;
-        }
-      if (lnr > 1 && !strcmp (fields[0], "pub"))
-        {
-          /* More than one public key.  */
-          err = gpg_error (GPG_ERR_TOO_MANY);
-          goto leave;
-        }
-      if (!strcmp (fields[0], "sub") || !strcmp (fields[0], "ssb"))
-        break; /* We can stop parsing here.  */
-
-      if (!strcmp (fields[0], "fpr") && nfields > 9 && !ctx->fpr)
-        {
-          ctx->fpr = xtrystrdup (fields[9]);
-          if (!ctx->fpr)
-            {
-              err = gpg_error_from_syserror ();
-              goto leave;
-            }
-        }
-      else if (!strcmp (fields[0], "uid") && nfields > 9)
-        {
-          /* Fixme: Unescape fields[9] */
-          xfree (mbox);
-          mbox = mailbox_from_userid (fields[9]);
-          if (mbox && !append_to_strlist_try (&ctx->mboxes, mbox))
-            {
-              err = gpg_error_from_syserror ();
-              goto leave;
-            }
-        }
-    }
-  if (len < 0 || es_ferror (listing))
-    log_error ("error reading memory stream\n");
-
- leave:
-  xfree (mbox);
-  xfree (fields);
-  es_free (line);
-  xfree (argv);
-  es_fclose (listing);
-  return err;
-}
-
-
 /* Take the key in KEYFILE and write it to OUTFILE in binary encoding.
  * If ADDRSPEC is given only matching user IDs are included in the
  * output.  */
@@ -1216,7 +1054,9 @@ process_new_key (server_ctx_t ctx, estream_t key)
   struct policy_flags_s policybuf;
 
   /* First figure out the user id from the key.  */
-  err = list_key (ctx, key);
+  xfree (ctx->fpr);
+  free_strlist (ctx->mboxes);
+  err = wks_list_key (key, &ctx->fpr, &ctx->mboxes);
   if (err)
     goto leave;
   if (!ctx->fpr)
@@ -1457,7 +1297,9 @@ check_and_publish (server_ctx_t ctx, const char *address, const char *nonce)
     }
 
   /* We need to get the fingerprint from the key.  */
-  err = list_key (ctx, key);
+  xfree (ctx->fpr);
+  free_strlist (ctx->mboxes);
+  err = wks_list_key (key, &ctx->fpr, &ctx->mboxes);
   if (err)
     goto leave;
   if (!ctx->fpr)
diff --git a/tools/gpg-wks.h b/tools/gpg-wks.h
index f7cccb3..7f347eb 100644
--- a/tools/gpg-wks.h
+++ b/tools/gpg-wks.h
@@ -65,6 +65,7 @@ typedef struct policy_flags_s *policy_flags_t;
 
 
 /*-- wks-util.c --*/
+gpg_error_t wks_list_key (estream_t key, char **r_fpr, strlist_t *r_mboxes);
 gpg_error_t wks_send_mime (mime_maker_t mime);
 gpg_error_t wks_parse_policy (policy_flags_t flags, estream_t stream,
                               int ignore_unknown);
diff --git a/tools/wks-util.c b/tools/wks-util.c
index 1b47612..f4f44f6 100644
--- a/tools/wks-util.c
+++ b/tools/wks-util.c
@@ -23,11 +23,190 @@
 #include <string.h>
 
 #include "util.h"
+#include "ccparray.h"
+#include "exectool.h"
+#include "mbox-util.h"
 #include "mime-maker.h"
 #include "send-mail.h"
 #include "gpg-wks.h"
 
 
+

+/* Helper for wks_list_key.  */
+static void
+list_key_status_cb (void *opaque, const char *keyword, char *args)
+{
+  (void)opaque;
+
+  if (DBG_CRYPTO)
+    log_debug ("gpg status: %s %s\n", keyword, args);
+}
+
+
+/* Run gpg on KEY and store the primary fingerprint at R_FPR and the
+ * list of mailboxes at R_MBOXES.  Returns 0 on success; on error NULL
+ * is stored at R_FPR and R_MBOXES and an error code is returned.  */
+gpg_error_t
+wks_list_key (estream_t key, char **r_fpr, strlist_t *r_mboxes)
+{
+  gpg_error_t err;
+  ccparray_t ccp;
+  const char **argv;
+  estream_t listing;
+  char *line = NULL;
+  size_t length_of_line = 0;
+  size_t  maxlen;
+  ssize_t len;
+  char **fields = NULL;
+  int nfields;
+  int lnr;
+  char *mbox = NULL;
+  char *fpr = NULL;
+  strlist_t mboxes = NULL;
+
+  *r_fpr = NULL;
+  *r_mboxes = NULL;
+
+  /* Open a memory stream.  */
+  listing = es_fopenmem (0, "w+b");
+  if (!listing)
+    {
+      err = gpg_error_from_syserror ();
+      log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
+      return err;
+    }
+
+  ccparray_init (&ccp, 0);
+
+  ccparray_put (&ccp, "--no-options");
+  if (!opt.verbose)
+    ccparray_put (&ccp, "--quiet");
+  else if (opt.verbose > 1)
+    ccparray_put (&ccp, "--verbose");
+  ccparray_put (&ccp, "--batch");
+  ccparray_put (&ccp, "--status-fd=2");
+  ccparray_put (&ccp, "--always-trust");
+  ccparray_put (&ccp, "--with-colons");
+  ccparray_put (&ccp, "--dry-run");
+  ccparray_put (&ccp, "--import-options=import-minimal,import-show");
+  ccparray_put (&ccp, "--import");
+
+  ccparray_put (&ccp, NULL);
+  argv = ccparray_get (&ccp, NULL);
+  if (!argv)
+    {
+      err = gpg_error_from_syserror ();
+      goto leave;
+    }
+  err = gnupg_exec_tool_stream (opt.gpg_program, argv, key,
+                                NULL, listing,
+                                list_key_status_cb, NULL);
+  if (err)
+    {
+      log_error ("import failed: %s\n", gpg_strerror (err));
+      goto leave;
+    }
+
+  es_rewind (listing);
+  lnr = 0;
+  maxlen = 2048; /* Set limit.  */
+  while ((len = es_read_line (listing, &line, &length_of_line, &maxlen)) > 0)
+    {
+      lnr++;
+      if (!maxlen)
+        {
+          log_error ("received line too long\n");
+          err = gpg_error (GPG_ERR_LINE_TOO_LONG);
+          goto leave;
+        }
+      /* Strip newline and carriage return, if present.  */
+      while (len > 0
+	     && (line[len - 1] == '\n' || line[len - 1] == '\r'))
+	line[--len] = '\0';
+      /* log_debug ("line '%s'\n", line); */
+
+      xfree (fields);
+      fields = strtokenize (line, ":");
+      if (!fields)
+        {
+          err = gpg_error_from_syserror ();
+          log_error ("strtokenize failed: %s\n", gpg_strerror (err));
+          goto leave;
+        }
+      for (nfields = 0; fields[nfields]; nfields++)
+        ;
+      if (!nfields)
+        {
+          err = gpg_error (GPG_ERR_INV_ENGINE);
+          goto leave;
+        }
+      if (!strcmp (fields[0], "sec"))
+        {
+          /* gpg may return "sec" as the first record - but we do not
+           * accept secret keys.  */
+          err = gpg_error (GPG_ERR_NO_PUBKEY);
+          goto leave;
+        }
+      if (lnr == 1 && strcmp (fields[0], "pub"))
+        {
+          /* First record is not a public key.  */
+          err = gpg_error (GPG_ERR_INV_ENGINE);
+          goto leave;
+        }
+      if (lnr > 1 && !strcmp (fields[0], "pub"))
+        {
+          /* More than one public key.  */
+          err = gpg_error (GPG_ERR_TOO_MANY);
+          goto leave;
+        }
+      if (!strcmp (fields[0], "sub") || !strcmp (fields[0], "ssb"))
+        break; /* We can stop parsing here.  */
+
+      if (!strcmp (fields[0], "fpr") && nfields > 9 && !fpr)
+        {
+          fpr = xtrystrdup (fields[9]);
+          if (!fpr)
+            {
+              err = gpg_error_from_syserror ();
+              goto leave;
+            }
+        }
+      else if (!strcmp (fields[0], "uid") && nfields > 9)
+        {
+          /* Fixme: Unescape fields[9] */
+          xfree (mbox);
+          mbox = mailbox_from_userid (fields[9]);
+          if (mbox && !append_to_strlist_try (&mboxes, mbox))
+            {
+              err = gpg_error_from_syserror ();
+              goto leave;
+            }
+        }
+    }
+  if (len < 0 || es_ferror (listing))
+    {
+      err = gpg_error_from_syserror ();
+      log_error ("error reading memory stream\n");
+      goto leave;
+    }
+
+  *r_fpr = fpr;
+  fpr = NULL;
+  *r_mboxes = mboxes;
+  mboxes = NULL;
+
+ leave:
+  xfree (fpr);
+  xfree (mboxes);
+  xfree (mbox);
+  xfree (fields);
+  es_free (line);
+  xfree (argv);
+  es_fclose (listing);
+  return err;
+}
+
+
 /* Helper to write mail to the output(s).  */
 gpg_error_t
 wks_send_mime (mime_maker_t mime)

-----------------------------------------------------------------------

Summary of changes:
 g10/tofu.c             |   4 +-
 tools/call-dirmngr.c   |  52 ++++++++++++++
 tools/call-dirmngr.h   |   2 +
 tools/gpg-wks-client.c | 101 ++++++++++++++++++++++++++++
 tools/gpg-wks-server.c | 170 ++--------------------------------------------
 tools/gpg-wks.h        |   1 +
 tools/wks-util.c       | 179 +++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 343 insertions(+), 166 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list