[git] GnuPG - branch, master, updated. gnupg-2.1.13-134-g5de41c4

by Werner Koch cvs at cvs.gnupg.org
Tue Jul 12 18:20:58 CEST 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  5de41c4ecef32add89044b8a550a47cce8c6d61e (commit)
       via  d3837e0435921bfa5587a50738f5924a5fdf976a (commit)
       via  6cb373f37b21505562665408c15210c5d42bed9d (commit)
      from  9b075575cdc5851b019aed5ca5d5e18416beec8e (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 5de41c4ecef32add89044b8a550a47cce8c6d61e
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Jul 12 17:27:15 2016 +0200

    wks: Try to send an encrypted confirmation back.
    
    * tools/gpg-wks-client.c (encrypt_response_status_cb): New.
    (encrypt_response): New.
    (send_confirmation_response): Encrypt the response.
    
    * tools/gpg-wks-server.c (send_confirmation_request): Use freeing of
    BODY and BODYENC.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/tools/gpg-wks-client.c b/tools/gpg-wks-client.c
index 20dfa29..ca7ec70 100644
--- a/tools/gpg-wks-client.c
+++ b/tools/gpg-wks-client.c
@@ -452,14 +452,104 @@ command_send (const char *fingerprint, char *userid)
 
 
 

+static void
+encrypt_response_status_cb (void *opaque, const char *keyword, char *args)
+{
+  gpg_error_t *failure = opaque;
+  char *fields[2];
+
+  if (opt.debug)
+    log_debug ("%s: %s\n", keyword, args);
+
+  if (!strcmp (keyword, "FAILURE"))
+    {
+      if (split_fields (args, fields, DIM (fields)) >= 2
+          && !strcmp (fields[0], "encrypt"))
+        *failure = strtoul (fields[1], NULL, 10);
+    }
+
+}
+
+
+/* Encrypt the INPUT stream to a new stream which is stored at success
+ * at R_OUTPUT.  Encryption is done for ADDRSPEC.  We currently
+ * retrieve that key from the WKD, DANE, or from "local".  "local" is
+ * last to prefer the latest key version but use a local copy in case
+ * we are working offline.  It might be useful for the server to send
+ * the fingerprint of its encryption key - or even the entire key
+ * back.  */
+static gpg_error_t
+encrypt_response (estream_t *r_output, estream_t input, const char *addrspec)
+{
+  gpg_error_t err;
+  ccparray_t ccp;
+  const char **argv;
+  estream_t output;
+  gpg_error_t gpg_err = 0;
+
+  *r_output = NULL;
+
+  output = es_fopenmem (0, "w+b");
+  if (!output)
+    {
+      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, "--armor");
+  ccparray_put (&ccp, "--auto-key-locate=clear,wkd,dane,local");
+  ccparray_put (&ccp, "--recipient");
+  ccparray_put (&ccp, addrspec);
+  ccparray_put (&ccp, "--encrypt");
+  ccparray_put (&ccp, "--");
+
+  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, input,
+                                NULL, output,
+                                encrypt_response_status_cb, &gpg_err);
+  if (err)
+    {
+      if (gpg_err)
+        err = gpg_err;
+      log_error ("encryption failed: %s\n", gpg_strerror (err));
+      goto leave;
+    }
+
+  es_rewind (output);
+  *r_output = output;
+  output = NULL;
+
+ leave:
+  es_fclose (output);
+  xfree (argv);
+  return err;
+}
+
+
 static gpg_error_t
 send_confirmation_response (const char *sender, const char *address,
-                            const char *nonce)
+                            const char *nonce, int encrypt)
 {
   gpg_error_t err;
   estream_t body = NULL;
-  /* FIXME: Encrypt and sign the response.  */
-  /* estream_t bodyenc = NULL; */
+  estream_t bodyenc = NULL;
   mime_maker_t mime = NULL;
 
   body = es_fopenmem (0, "w+b");
@@ -469,12 +559,16 @@ send_confirmation_response (const char *sender, const char *address,
       log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
       return err;
     }
-  /* It is fine to use 8 bit encosind because that is encrypted and
+
+  /* It is fine to use 8 bit encoding because that is encrypted and
    * only our client will see it.  */
-  /* es_fputs ("Content-Type: application/vnd.gnupg.wks\n" */
-  /*           "Content-Transfer-Encoding: 8bit\n" */
-  /*           "\n", */
-  /*           body); */
+  if (encrypt)
+    {
+      es_fputs ("Content-Type: application/vnd.gnupg.wks\n"
+                "Content-Transfer-Encoding: 8bit\n"
+                "\n",
+                body);
+    }
 
   es_fprintf (body, ("type: confirmation-response\n"
                      "sender: %s\n"
@@ -485,12 +579,14 @@ send_confirmation_response (const char *sender, const char *address,
               nonce);
 
   es_rewind (body);
-  /* err = encrypt_stream (&bodyenc, body, ctx->fpr); */
-  /* if (err) */
-  /*   goto leave; */
-  /* es_fclose (body); */
-  /* body = NULL; */
-
+  if (encrypt)
+    {
+      err = encrypt_response (&bodyenc, body, address);
+      if (err)
+        goto leave;
+      es_fclose (body);
+      body = NULL;
+    }
 
   err = mime_maker_new (&mime, NULL);
   if (err)
@@ -505,42 +601,50 @@ send_confirmation_response (const char *sender, const char *address,
   if (err)
     goto leave;
 
-  /* err = mime_maker_add_header (mime, "Content-Type", */
-  /*                              "multipart/encrypted; " */
-  /*                              "protocol=\"application/pgp-encrypted\""); */
-  /* if (err) */
-  /*   goto leave; */
-  /* err = mime_maker_add_container (mime, "multipart/encrypted"); */
-  /* if (err) */
-  /*   goto leave; */
-
-  /* err = mime_maker_add_header (mime, "Content-Type", */
-  /*                              "application/pgp-encrypted"); */
-  /* if (err) */
-  /*   goto leave; */
-  /* err = mime_maker_add_body (mime, "Version: 1\n"); */
-  /* if (err) */
-  /*   goto leave; */
-  /* err = mime_maker_add_header (mime, "Content-Type", */
-  /*                              "application/octet-stream"); */
-  /* if (err) */
-  /*   goto leave; */
-
-  err = mime_maker_add_header (mime, "Content-Type",
-                               "application/vnd.gnupg.wks");
-  if (err)
-    goto leave;
+  if (encrypt)
+    {
+      err = mime_maker_add_header (mime, "Content-Type",
+                                   "multipart/encrypted; "
+                                   "protocol=\"application/pgp-encrypted\"");
+      if (err)
+        goto leave;
+      err = mime_maker_add_container (mime, "multipart/encrypted");
+      if (err)
+        goto leave;
 
-  err = mime_maker_add_stream (mime, &body);
-  if (err)
-    goto leave;
+      err = mime_maker_add_header (mime, "Content-Type",
+                                   "application/pgp-encrypted");
+      if (err)
+        goto leave;
+      err = mime_maker_add_body (mime, "Version: 1\n");
+      if (err)
+        goto leave;
+      err = mime_maker_add_header (mime, "Content-Type",
+                                   "application/octet-stream");
+      if (err)
+        goto leave;
+
+      err = mime_maker_add_stream (mime, &bodyenc);
+      if (err)
+        goto leave;
+    }
+  else
+    {
+      err = mime_maker_add_header (mime, "Content-Type",
+                                   "application/vnd.gnupg.wks");
+      if (err)
+        goto leave;
+      err = mime_maker_add_stream (mime, &body);
+      if (err)
+        goto leave;
+    }
 
   err = wks_send_mime (mime);
 
  leave:
   mime_maker_release (mime);
-  /* xfree (bodyenc); */
-  xfree (body);
+  es_fclose (bodyenc);
+  es_fclose (body);
   return err;
 }
 
@@ -619,8 +723,14 @@ process_confirmation_request (estream_t msg)
     }
   nonce = value;
 
-  err = send_confirmation_response (sender, address, nonce);
-
+  /* Send the confirmation.  If no key was found, try again without
+   * encryption.  */
+  err = send_confirmation_response (sender, address, nonce, 1);
+  if (gpg_err_code (err) == GPG_ERR_NO_PUBKEY)
+    {
+      log_info ("no encryption key found - sending response in the clear\n");
+      err = send_confirmation_response (sender, address, nonce, 0);
+    }
 
  leave:
   nvc_release (nvc);
diff --git a/tools/gpg-wks-server.c b/tools/gpg-wks-server.c
index 88313ec..de1be6a 100644
--- a/tools/gpg-wks-server.c
+++ b/tools/gpg-wks-server.c
@@ -904,8 +904,8 @@ send_confirmation_request (server_ctx_t ctx,
 
  leave:
   mime_maker_release (mime);
-  xfree (bodyenc);
-  xfree (body);
+  es_fclose (bodyenc);
+  es_fclose (body);
   xfree (from_buffer);
   return err;
 }

commit d3837e0435921bfa5587a50738f5924a5fdf976a
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Jul 12 16:54:55 2016 +0200

    wks: Also create DANE record.
    
    * tools/gpg-wks-server.c (copy_key_as_dane): New.
    (check_and_publish): Also publish as DANE record.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/tools/gpg-wks-server.c b/tools/gpg-wks-server.c
index e46eafa..88313ec 100644
--- a/tools/gpg-wks-server.c
+++ b/tools/gpg-wks-server.c
@@ -489,6 +489,55 @@ list_key (server_ctx_t ctx, estream_t key)
 }
 
 
+/* Take the key in KEYFILE and write it to DANEFILE using the DANE
+ * output format. */
+static gpg_error_t
+copy_key_as_dane (const char *keyfile, const char *danefile)
+{
+  gpg_error_t err;
+  ccparray_t ccp;
+  const char **argv;
+
+  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, "--yes");
+  ccparray_put (&ccp, "--always-trust");
+  ccparray_put (&ccp, "--no-keyring");
+  ccparray_put (&ccp, "--output");
+  ccparray_put (&ccp, danefile);
+  ccparray_put (&ccp, "--export-options=export-dane");
+  ccparray_put (&ccp, "--import-options=import-export");
+  ccparray_put (&ccp, "--import");
+  ccparray_put (&ccp, "--");
+  ccparray_put (&ccp, keyfile);
+
+  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, NULL,
+                                NULL, NULL, NULL, NULL);
+  if (err)
+    {
+      log_error ("%s failed: %s\n", __func__, gpg_strerror (err));
+      goto leave;
+    }
+
+ leave:
+  xfree (argv);
+  return err;
+}
+
+
 static void
 encrypt_stream_status_cb (void *opaque, const char *keyword, char *args)
 {
@@ -782,7 +831,7 @@ send_confirmation_request (server_ctx_t ctx,
       log_error ("error allocating memory buffer: %s\n", gpg_strerror (err));
       goto leave;
     }
-  /* It is fine to use 8 bit encosind because that is encrypted and
+  /* It is fine to use 8 bit encoding because that is encrypted and
    * only our client will see it.  */
   es_fputs ("Content-Type: application/vnd.gnupg.wks\n"
             "Content-Transfer-Encoding: 8bit\n"
@@ -945,6 +994,7 @@ check_and_publish (server_ctx_t ctx, const char *address, const char *nonce)
   const char *domain;
   const char *s;
   strlist_t sl;
+  char shaxbuf[32]; /* Used for SHA-1 and SHA-256 */
 
   /* FIXME: There is a bug in name-value.c which adds white space for
    * the last pair and thus we strip the nonce here until this has
@@ -1011,11 +1061,8 @@ check_and_publish (server_ctx_t ctx, const char *address, const char *nonce)
   /* Hash user ID and create filename.  */
   s = strchr (address, '@');
   log_assert (s);
-  {
-    char sha1buf[20];
-    gcry_md_hash_buffer (GCRY_MD_SHA1, sha1buf, address, s - address);
-    hash = zb32_encode (sha1buf, 8*20);
-  }
+  gcry_md_hash_buffer (GCRY_MD_SHA1, shaxbuf, address, s - address);
+  hash = zb32_encode (shaxbuf, 8*20);
   if (!hash)
     {
       err = gpg_error_from_syserror ();
@@ -1032,7 +1079,7 @@ check_and_publish (server_ctx_t ctx, const char *address, const char *nonce)
         goto leave;
     }
     if (!gnupg_mkdir (fnewname, "-rwxr-xr-x"))
-      log_info ("directory '%s' created\n", fname);
+      log_info ("directory '%s' created\n", fnewname);
     xfree (fnewname);
   }
   fnewname = make_filename_try (opt.directory, domain, "hu", hash, NULL);
@@ -1053,6 +1100,43 @@ check_and_publish (server_ctx_t ctx, const char *address, const char *nonce)
 
   log_info ("key %s published for '%s'\n", ctx->fpr, address);
 
+
+  /* Try to publish as DANE record if the DANE directory exists.  */
+  xfree (fname);
+  fname = fnewname;
+  fnewname = make_filename_try (opt.directory, domain, "dane", NULL);
+  if (!fnewname)
+    {
+      err = gpg_error_from_syserror ();
+      goto leave;
+    }
+  if (!access (fnewname, W_OK))
+    {
+      /* Yes, we have a dane directory.  */
+      s = strchr (address, '@');
+      log_assert (s);
+      gcry_md_hash_buffer (GCRY_MD_SHA256, shaxbuf, address, s - address);
+      xfree (hash);
+      hash = bin2hex (shaxbuf, 28, NULL);
+      if (!hash)
+        {
+          err = gpg_error_from_syserror ();
+          goto leave;
+        }
+      xfree (fnewname);
+      fnewname = make_filename_try (opt.directory, domain, "dane", hash, NULL);
+      if (!fnewname)
+        {
+          err = gpg_error_from_syserror ();
+          goto leave;
+        }
+      err = copy_key_as_dane (fname, fnewname);
+      if (err)
+        goto leave;
+      log_info ("key %s published for '%s' (DANE record)\n", ctx->fpr, address);
+    }
+
+
  leave:
   es_fclose (key);
   xfree (hash);

commit 6cb373f37b21505562665408c15210c5d42bed9d
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Jul 12 16:11:20 2016 +0200

    doc: Update import-export description.
    
    --

diff --git a/doc/gpg.texi b/doc/gpg.texi
index ae860d7..db11061 100644
--- a/doc/gpg.texi
+++ b/doc/gpg.texi
@@ -2211,8 +2211,10 @@ opposite meaning. The options are:
 
   @item import-export
   Run the entire import code but instead of storing the key to the
-  local keyring write it to the output.  This option can be used to
-  remove all invalid parts from a key without the need to store it.
+  local keyring write it to the output.  The export options
+  @option{export-pka} and @option{export-dane} affect the output.  This
+  option can be used to remove all invalid parts from a key without the
+  need to store it.
 
   @item merge-only
   During import, allow key updates to existing keys, but do not allow

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

Summary of changes:
 doc/gpg.texi           |   6 +-
 tools/gpg-wks-client.c | 202 ++++++++++++++++++++++++++++++++++++++-----------
 tools/gpg-wks-server.c | 102 ++++++++++++++++++++++---
 3 files changed, 253 insertions(+), 57 deletions(-)


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




More information about the Gnupg-commits mailing list