[git] GPGME - branch, master, updated. gpgme-1.11.1-33-ga1bbe74

by Andre Heinecke cvs at cvs.gnupg.org
Fri May 25 14:53:46 CEST 2018


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 "GnuPG Made Easy".

The branch, master has been updated
       via  a1bbe7473a4d0f31d471d6cceb2f7e1382860194 (commit)
       via  897522527d493307d15809a41496f8b76ec4edfe (commit)
       via  10683b1a913c39238c9871f5aa607334f32467f7 (commit)
      from  1ff16dad595946af140b324fad2bceca7ddbc378 (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 a1bbe7473a4d0f31d471d6cceb2f7e1382860194
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Fri May 25 14:52:51 2018 +0200

    json: Implement op_export
    
    * src/gpgme-json.c (op_export): New.
    (hlp_getmore, process_request): Add it.
    
    --
    Secret key export does not work with request-origin browser.

diff --git a/src/gpgme-json.c b/src/gpgme-json.c
index ca8c41c..7e0e637 100644
--- a/src/gpgme-json.c
+++ b/src/gpgme-json.c
@@ -2072,6 +2072,114 @@ op_import (cjson_t request, cjson_t result)
   gpgme_data_release (input);
   return err;
 }
+
+
+static const char hlp_export[] =
+  "op:     \"export\"\n"
+  "\n"
+  "Optional parameters:\n"
+  "keys:          Array of strings or fingerprints to lookup\n"
+  "               For a single key a String may be used instead of an array.\n"
+  "               default exports all keys.\n"
+  "protocol:      Either \"openpgp\" (default) or \"cms\".\n"
+  "chunksize:     Max number of bytes in the resulting \"data\".\n"
+  "\n"
+  "Optional boolean flags (default is false):\n"
+  "armor:         Request output in armored format.\n"
+  "extern:        Add EXPORT_MODE_EXTERN.\n"
+  "minimal:       Add EXPORT_MODE_MINIMAL.\n"
+  "secret:        Add EXPORT_MODE_SECRET. (not implemented)\n"
+  "raw:           Add EXPORT_MODE_RAW.\n"
+  "pkcs12:        Add EXPORT_MODE_PKCS12.\n"
+  "\n"
+  "Response on success:\n"
+  "type:   \"keys\"\n"
+  "data:   Unless armor mode is used a Base64 encoded binary.\n"
+  "        In armor mode a string with an armored\n"
+  "        OpenPGP or a PEM / PKCS12 key.\n"
+  "base64: Boolean indicating whether data is base64 encoded.\n"
+  "more:   Optional boolean indicating that \"getmore\" is required.";
+static gpg_error_t
+op_export (cjson_t request, cjson_t result)
+{
+  gpg_error_t err;
+  gpgme_ctx_t ctx = NULL;
+  gpgme_protocol_t protocol;
+  size_t chunksize;
+  char **patterns = NULL;
+  int abool;
+  gpgme_export_mode_t mode = 0;
+  gpgme_data_t output = NULL;
+
+  if ((err = get_protocol (request, &protocol)))
+    goto leave;
+  ctx = get_context (protocol);
+  if ((err = get_chunksize (request, &chunksize)))
+    goto leave;
+
+  if ((err = get_boolean_flag (request, "armor", 0, &abool)))
+    goto leave;
+  gpgme_set_armor (ctx, abool);
+
+  /* Handle the various export mode bools. */
+  if ((err = get_boolean_flag (request, "secret", 0, &abool)))
+    goto leave;
+  if (abool)
+    mode |= GPGME_EXPORT_MODE_SECRET;
+
+  if ((err = get_boolean_flag (request, "extern", 0, &abool)))
+    goto leave;
+  if (abool)
+    mode |= GPGME_EXPORT_MODE_EXTERN;
+
+  if ((err = get_boolean_flag (request, "minimal", 0, &abool)))
+    goto leave;
+  if (abool)
+    mode |= GPGME_EXPORT_MODE_MINIMAL;
+
+  if ((err = get_boolean_flag (request, "raw", 0, &abool)))
+    goto leave;
+  if (abool)
+    mode |= GPGME_EXPORT_MODE_RAW;
+
+  if ((err = get_boolean_flag (request, "pkcs12", 0, &abool)))
+    goto leave;
+  if (abool)
+    mode |= GPGME_EXPORT_MODE_PKCS12;
+
+  /* Get the export patterns.  */
+  patterns = create_keylist_patterns (request);
+
+  /* Create an output data object.  */
+  err = gpgme_data_new (&output);
+  if (err)
+    {
+      gpg_error_object (result, err, "Error creating output data object: %s",
+                        gpg_strerror (err));
+      goto leave;
+    }
+
+  err = gpgme_op_export_ext (ctx, (const char **) patterns,
+                             mode, output);
+  if (err)
+    {
+      gpg_error_object (result, err, "Error exporting keys: %s",
+                        gpg_strerror (err));
+      goto leave;
+    }
+
+  /* We need to base64 if armoring has not been requested.  */
+  err = make_data_object (result, output, chunksize,
+                          "keys", !gpgme_get_armor (ctx));
+  output = NULL;
+
+leave:
+  xfree_array (patterns);
+  release_context (ctx);
+  gpgme_data_release (output);
+
+  return err;
+}
 

 static const char hlp_getmore[] =
   "op:     \"getmore\"\n"
@@ -2167,8 +2275,9 @@ static const char hlp_help[] =
   "operation is not performned but a string with the documentation\n"
   "returned.  To list all operations it is allowed to leave out \"op\" in\n"
   "help mode.  Supported values for \"op\" are:\n\n"
-  "  encrypt     Encrypt data.\n"
   "  decrypt     Decrypt data.\n"
+  "  encrypt     Encrypt data.\n"
+  "  export      Export keys.\n"
   "  import      Import data.\n"
   "  keylist     List keys.\n"
   "  sign        Sign data.\n"
@@ -2213,6 +2322,7 @@ process_request (const char *request)
     const char * const helpstr;
   } optbl[] = {
     { "encrypt", op_encrypt, hlp_encrypt },
+    { "export",  op_export,  hlp_export },
     { "decrypt", op_decrypt, hlp_decrypt },
     { "keylist", op_keylist, hlp_keylist },
     { "import",  op_import,  hlp_import },

commit 897522527d493307d15809a41496f8b76ec4edfe
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Fri May 25 14:50:59 2018 +0200

    json: Fix double ctx alloc
    
    * src/gpgme-json.c (op_keylist): Only get one ctx.

diff --git a/src/gpgme-json.c b/src/gpgme-json.c
index 3cdd744..ca8c41c 100644
--- a/src/gpgme-json.c
+++ b/src/gpgme-json.c
@@ -1966,9 +1966,6 @@ op_keylist (cjson_t request, cjson_t result)
   patterns = create_keylist_patterns (request);
 
   /* Do a keylisting and add the keys */
-  if ((err = gpgme_new (&ctx)))
-    goto leave;
-  gpgme_set_protocol (ctx, protocol);
   gpgme_set_keylist_mode (ctx, mode);
 
   err = gpgme_op_keylist_ext_start (ctx, (const char **) patterns,

commit 10683b1a913c39238c9871f5aa607334f32467f7
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Fri May 25 14:50:20 2018 +0200

    json: Add guard in create_keylist_patterns
    
    * src/gpgme-json.c (create_keylist_patterns): Guard against
    a string ending with a linbreak.

diff --git a/src/gpgme-json.c b/src/gpgme-json.c
index eb5edf4..3cdd744 100644
--- a/src/gpgme-json.c
+++ b/src/gpgme-json.c
@@ -691,7 +691,7 @@ create_keylist_patterns (cjson_t request)
       tmp = p + 1;
     }
   /* The last key is not newline delimted. */
-  ret[i++] = xstrdup (tmp);
+  ret[i++] = *tmp ? xstrdup (tmp) : NULL;
   ret[i] = NULL;
 
   xfree (keystring);

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

Summary of changes:
 src/gpgme-json.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 112 insertions(+), 5 deletions(-)


hooks/post-receive
-- 
GnuPG Made Easy
http://git.gnupg.org




More information about the Gnupg-commits mailing list