[git] GPGME - branch, master, updated. gpgme-1.10.0-201-ge5273fc

by Werner Koch cvs at cvs.gnupg.org
Wed Apr 18 15:32:40 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  e5273fc4431dfb597a2d9cf4af5172572476a2de (commit)
       via  65479fe7b871ad6237d5a8959b73afcc7db784da (commit)
       via  23177e4410d05d590c0f2e1675dc645bbb4ad62c (commit)
      from  49a617f8bbff116884ca5c7238c2e0ea4e26ce59 (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 e5273fc4431dfb597a2d9cf4af5172572476a2de
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Apr 18 15:24:42 2018 +0200

    json: Add command "decrypt" to gpgme-json.
    
    * src/gpgme-json.c (make_data_object): Enable auto-detection of
    base-64.
    (op_encrypt): Support a 'mime' flag.
    (op_decrypt): New.
    (process_request): Add command "encrypt".
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/src/gpgme-json.c b/src/gpgme-json.c
index f63f196..e7aa228 100644
--- a/src/gpgme-json.c
+++ b/src/gpgme-json.c
@@ -587,7 +587,9 @@ data_from_base64_string (gpgme_data_t *r_data, cjson_t json)
 /* Create a "data" object and the "type", "base64" and "more" flags
  * from DATA and append them to RESULT.  Ownership if DATA is
  * transferred to this function.  TYPE must be a fixed string.
- * CHUNKSIZE is the chunksize requested from the caller.  Note that
+ * CHUNKSIZE is the chunksize requested from the caller.  If BASE64 is
+ * -1 the need for base64 encoding is determined by the content of
+ * DATA, all other values are take as rtue or false.  Note that
  * op_getmore has similar code but works on PENDING_DATA which is set
  * here.  */
 static gpg_error_t
@@ -599,11 +601,7 @@ make_data_object (cjson_t result, gpgme_data_t data, size_t chunksize,
   size_t buflen;
   int c;
 
-  /* Adjust the chunksize if we need to do base64 conversion.  */
-  if (base64)
-    chunksize = (chunksize / 4) * 3;
-
-  if (!base64) /* Make sure that we really have a string.  */
+  if (!base64 || base64 == -1) /* Make sure that we really have a string.  */
     gpgme_data_write (data, "", 1);
 
   buffer = gpgme_data_release_and_get_mem (data, &buflen);
@@ -614,6 +612,23 @@ make_data_object (cjson_t result, gpgme_data_t data, size_t chunksize,
       goto leave;
     }
 
+  if (base64 == -1)
+    {
+      base64 = 0;
+      if (!buflen)
+        log_fatal ("Appended Nul byte got lost\n");
+      if (memchr (buffer, 0, buflen-1))
+        {
+          buflen--; /* Adjust for the extra nul byte.  */
+          base64 = 1;
+        }
+      /* Fixme: We might want to do more advanced heuristics than to
+       * only look for a Nul.  */
+    }
+
+  /* Adjust the chunksize if we need to do base64 conversion.  */
+  if (base64)
+    chunksize = (chunksize / 4) * 3;
 
   xjson_AddStringToObject (result, "type", type);
   xjson_AddBoolToObject (result, "base64", base64);
@@ -667,6 +682,7 @@ static const char hlp_encrypt[] =
   "\n"
   "Optional boolean flags (default is false):\n"
   "base64:        Input data is base64 encoded.\n"
+  "mime:          Indicate that data is a MIME object.\n"
   "armor:         Request output in armored format.\n"
   "always-trust:  Request --always-trust option.\n"
   "no-encrypt-to: Do not use a default recipient.\n"
@@ -690,6 +706,7 @@ op_encrypt (cjson_t request, cjson_t result)
   gpgme_protocol_t protocol;
   size_t chunksize;
   int opt_base64;
+  int opt_mime;
   char *keystring = NULL;
   cjson_t j_input;
   gpgme_data_t input = NULL;
@@ -705,6 +722,8 @@ op_encrypt (cjson_t request, cjson_t result)
 
   if ((err = get_boolean_flag (request, "base64", 0, &opt_base64)))
     goto leave;
+  if ((err = get_boolean_flag (request, "mime", 0, &opt_mime)))
+    goto leave;
 
   if ((err = get_boolean_flag (request, "armor", 0, &abool)))
     goto leave;
@@ -777,6 +796,9 @@ op_encrypt (cjson_t request, cjson_t result)
           goto leave;
         }
     }
+  if (opt_mime)
+    gpgme_data_set_encoding (input, GPGME_DATA_ENCODING_MIME);
+
 
   /* Create an output data object.  */
   err = gpgme_data_new (&output);
@@ -814,6 +836,116 @@ op_encrypt (cjson_t request, cjson_t result)
 
 
 

+static const char hlp_decrypt[] =
+  "op:     \"decrypt\"\n"
+  "data:   The encrypted data.\n"
+  "\n"
+  "Optional parameters:\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"
+  "base64:        Input data is base64 encoded.\n"
+  "\n"
+  "Response on success:\n"
+  "type:   \"plaintext\"\n"
+  "data:   The decrypted data.  This may be base64 encoded.\n"
+  "base64: Boolean indicating whether data is base64 encoded.\n"
+  "mime:   A Boolean indicating whether the data is a MIME object.\n"
+  "info:   An optional object with extra information.\n"
+  "more:   Optional boolean indicating that \"getmore\" is required.";
+static gpg_error_t
+op_decrypt (cjson_t request, cjson_t result)
+{
+  gpg_error_t err;
+  gpgme_ctx_t ctx = NULL;
+  gpgme_protocol_t protocol;
+  size_t chunksize;
+  int opt_base64;
+  cjson_t j_input;
+  gpgme_data_t input = NULL;
+  gpgme_data_t output = NULL;
+  gpgme_decrypt_result_t decrypt_result;
+
+  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, "base64", 0, &opt_base64)))
+    goto leave;
+
+  /* Get the data.  Note that INPUT is a shallow data object with the
+   * storage hold in REQUEST.  */
+  j_input = cJSON_GetObjectItem (request, "data");
+  if (!j_input)
+    {
+      err = gpg_error (GPG_ERR_NO_DATA);
+      goto leave;
+    }
+  if (!cjson_is_string (j_input))
+    {
+      err = gpg_error (GPG_ERR_INV_VALUE);
+      goto leave;
+    }
+  if (opt_base64)
+    {
+      err = data_from_base64_string (&input, j_input);
+      if (err)
+        {
+          error_object (result, "Error decoding Base-64 encoded 'data': %s",
+                        gpg_strerror (err));
+          goto leave;
+        }
+    }
+  else
+    {
+      err = gpgme_data_new_from_mem (&input, j_input->valuestring,
+                                     strlen (j_input->valuestring), 0);
+      if (err)
+        {
+          error_object (result, "Error getting 'data': %s", gpg_strerror (err));
+          goto leave;
+        }
+    }
+
+  /* Create an output data object.  */
+  err = gpgme_data_new (&output);
+  if (err)
+    {
+      error_object (result, "Error creating output data object: %s",
+                    gpg_strerror (err));
+      goto leave;
+    }
+
+  /* Decrypt.  */
+  err = gpgme_op_decrypt_ext (ctx, GPGME_DECRYPT_VERIFY,
+                              input, output);
+  decrypt_result = gpgme_op_decrypt_result (ctx);
+  if (err)
+    {
+      error_object (result, "Decryption failed: %s", gpg_strerror (err));
+      goto leave;
+    }
+  gpgme_data_release (input);
+  input = NULL;
+
+  if (decrypt_result->is_mime)
+    xjson_AddBoolToObject (result, "mime", 1);
+
+  err = make_data_object (result, output, chunksize, "plaintext", -1);
+  output = NULL;
+
+ leave:
+  release_context (ctx);
+  gpgme_data_release (input);
+  gpgme_data_release (output);
+  return err;
+}
+
+
+

 static const char hlp_getmore[] =
   "op:     \"getmore\"\n"
   "\n"
@@ -947,7 +1079,7 @@ process_request (const char *request)
     const char * const helpstr;
   } optbl[] = {
     { "encrypt", op_encrypt, hlp_encrypt },
-
+    { "decrypt", op_decrypt, hlp_decrypt },
     { "getmore", op_getmore, hlp_getmore },
     { "help",    op_help,    hlp_help },
     { NULL }

commit 65479fe7b871ad6237d5a8959b73afcc7db784da
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Apr 18 15:20:35 2018 +0200

    core: Add 'is_mime' flags to the verify and decrypt results.
    
    * src/op-support.c (_gpgme_parse_plaintext): Add arg r_mime.
    * src/decrypt.c (_gpgme_decrypt_status_handler): Ser mime flag.
    * src/verify.c (_gpgme_verify_status_handler): Ditto.
    * src/gpgme.h.in (gpgme_op_verify_result_t): Append fields 'is_mime'
    and '_unused'.
    (gpgme_op_decrypt_result_t): New field 'is_mime'.  Shrink '_unused'.
    
    * tests/run-decrypt.c (print_result): Print MIME flag.
    * tests/run-verify.c (print_result): Ditto.
    --
    
    Note that this flag (Liternal Data packet's 'm' mode) is only
    specified in RFC-4880bis.  To use it you currently need to add
    "rfc4880bis" to the the gpg.conf.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/NEWS b/NEWS
index 92a9673..be3111c 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,8 @@ Noteworthy changes in version 1.10.1 (unreleased)
  GPGME_ENCRYPT_WANT_ADDRESS       NEW.
  gpgme_import_result_t            EXTENDED: New field 'skipped_v3_keys'.
  gpgme_decrypt_result_t           EXTENDED: New field 'symkey_algo'.
+ gpgme_decrypt_result_t           EXTENDED: New field 'is_mime'.
+ gpgme_verify_result_t            EXTENDED: New field 'is_mime'.
  cpp: Key::locate                 NEW.
  cpp: Data::toString              NEW.
  cpp: ImportResult::numV3KeysSkipped  NEW.
diff --git a/doc/gpgme.texi b/doc/gpgme.texi
index 5a09ea0..83348dd 100644
--- a/doc/gpgme.texi
+++ b/doc/gpgme.texi
@@ -5284,7 +5284,7 @@ if @var{cipher} or @var{plain} is not a valid pointer.
 @since{1.8.0}
 
 The function @code{gpgme_op_decrypt_ext} is the same as
- at code{gpgme_op_decrypt_ext} but has an additional argument
+ at code{gpgme_op_decrypt} but has an additional argument
 @var{flags}.  If @var{flags} is 0 both function behave identically.
 
 The value in @var{flags} is a bitwise-or combination of one or
diff --git a/src/decrypt.c b/src/decrypt.c
index e4de6e4..155e18e 100644
--- a/src/decrypt.c
+++ b/src/decrypt.c
@@ -409,9 +409,14 @@ _gpgme_decrypt_status_handler (void *priv, gpgme_status_code_t code,
       break;
 
     case GPGME_STATUS_PLAINTEXT:
-      err = _gpgme_parse_plaintext (args, &opd->result.file_name);
-      if (err)
-	return err;
+      {
+        int mime = 0;
+        err = _gpgme_parse_plaintext (args, &opd->result.file_name, &mime);
+        if (err)
+          return err;
+        gpgrt_log_debug ("decrypt.c setting mime to %d\n", mime);
+        opd->result.is_mime = !!mime;
+      }
       break;
 
     case GPGME_STATUS_INQUIRE_MAXLEN:
diff --git a/src/gpgme.h.in b/src/gpgme.h.in
index 202859c..c81e882 100644
--- a/src/gpgme.h.in
+++ b/src/gpgme.h.in
@@ -1356,8 +1356,11 @@ struct _gpgme_op_decrypt_result
    * mode.  */
   unsigned int is_de_vs : 1;
 
+  /* The message claims that the content is a MIME object.  */
+  unsigned int is_mime : 1;
+
   /* Internal to GPGME, do not use.  */
-  int _unused : 30;
+  int _unused : 29;
 
   gpgme_recipient_t recipients;
 
@@ -1572,6 +1575,12 @@ struct _gpgme_op_verify_result
   /* The original file name of the plaintext message, if
      available.  */
   char *file_name;
+
+  /* The message claims that the content is a MIME object.  */
+  unsigned int is_mime : 1;
+
+  /* Internal to GPGME; do not use.  */
+  unsigned int _unused : 31;
 };
 typedef struct _gpgme_op_verify_result *gpgme_verify_result_t;
 
diff --git a/src/op-support.c b/src/op-support.c
index e55875f..03f274c 100644
--- a/src/op-support.c
+++ b/src/op-support.c
@@ -358,7 +358,7 @@ _gpgme_parse_key_considered (const char *args,
 /* Parse the PLAINTEXT status line in ARGS and return the result in
    FILENAMEP.  */
 gpgme_error_t
-_gpgme_parse_plaintext (char *args, char **filenamep)
+_gpgme_parse_plaintext (char *args, char **filenamep, int *r_mime)
 {
   char *tail;
 
@@ -367,7 +367,9 @@ _gpgme_parse_plaintext (char *args, char **filenamep)
   if (*args == '\0')
     return 0;
 
-  /* First argument is file type.  */
+  /* First argument is file type (a one byte uppercase hex value).  */
+  if (args[0] == '6' && args[1] == 'D')
+    *r_mime = 1;
   while (*args != ' ' && *args != '\0')
     args++;
   while (*args == ' ')
diff --git a/src/ops.h b/src/ops.h
index cc61dc4..5955454 100644
--- a/src/ops.h
+++ b/src/ops.h
@@ -68,8 +68,8 @@ gpgme_error_t _gpgme_parse_inv_recp (char *args, int for_signing,
                                      gpgme_invalid_key_t *key);
 
 /* Parse the PLAINTEXT status line in ARGS and return the result in
-   FILENAMEP.  */
-gpgme_error_t _gpgme_parse_plaintext (char *args, char **filenamep);
+   FILENAMEP and R_MIME.  */
+gpgme_error_t _gpgme_parse_plaintext (char *args, char **filenamep,int *r_mime);
 
 /* Parse a FAILURE status line and return the error code.  ARGS is
    modified to contain the location part.  */
diff --git a/src/verify.c b/src/verify.c
index c3afdef..bd437c9 100644
--- a/src/verify.c
+++ b/src/verify.c
@@ -1091,9 +1091,14 @@ _gpgme_verify_status_handler (void *priv, gpgme_status_code_t code, char *args)
     case GPGME_STATUS_PLAINTEXT:
       if (++opd->plaintext_seen > 1)
         return gpg_error (GPG_ERR_BAD_DATA);
-      err = _gpgme_parse_plaintext (args, &opd->result.file_name);
-      if (err)
-	return err;
+      {
+        int mime = 0;
+        err = _gpgme_parse_plaintext (args, &opd->result.file_name, &mime);
+        if (err)
+          return err;
+        gpgrt_log_debug ("verify.c: setting mime to %d\n", mime);
+        opd->result.is_mime = !!mime;
+      }
       break;
 
     case GPGME_STATUS_VERIFICATION_COMPLIANCE_MODE:
diff --git a/tests/run-decrypt.c b/tests/run-decrypt.c
index 8eb6ba0..69de139 100644
--- a/tests/run-decrypt.c
+++ b/tests/run-decrypt.c
@@ -53,20 +53,21 @@ print_result (gpgme_decrypt_result_t result)
   gpgme_recipient_t recp;
   int count = 0;
 
-  printf ("Original file name: %s\n", nonnull(result->file_name));
-  printf ("Wrong key usage: %i\n", result->wrong_key_usage);
-  printf ("Unsupported algorithm: %s\n",
-          nonnull(result->unsupported_algorithm));
-  if (result->session_key)
-    printf ("Session key: %s\n", result->session_key);
-  printf ("Symmetric algorithm: %s\n", result->symkey_algo);
+  printf ("Original file name .: %s\n", nonnull(result->file_name));
+  printf ("Wrong key usage ....: %s\n", result->wrong_key_usage? "yes":"no");
+  printf ("Compliance de-vs ...: %s\n", result->is_de_vs? "yes":"no");
+  printf ("MIME flag ..........: %s\n", result->is_mime? "yes":"no");
+  printf ("Unsupported algo ...: %s\n", nonnull(result->unsupported_algorithm));
+  printf ("Session key ........: %s\n", nonnull (result->session_key));
+  printf ("Symmetric algorithm : %s\n", result->symkey_algo);
 
   for (recp = result->recipients; recp && recp->next; recp = recp->next)
     {
-      printf ("recipient %d\n", count++);
+      printf ("Recipient ...: %d\n", count++);
       printf ("  status ....: %s\n", gpgme_strerror (recp->status));
-      printf ("  keyid: %s\n", nonnull (recp->keyid));
-      printf ("  algo ...: %s\n", gpgme_pubkey_algo_name (recp->pubkey_algo));
+      printf ("  keyid .....: %s\n", nonnull (recp->keyid));
+      printf ("  algo ......: %s\n",
+              gpgme_pubkey_algo_name (recp->pubkey_algo));
     }
 }
 
diff --git a/tests/run-verify.c b/tests/run-verify.c
index 699bfd1..4a6c960 100644
--- a/tests/run-verify.c
+++ b/tests/run-verify.c
@@ -136,10 +136,11 @@ print_result (gpgme_verify_result_t result)
   gpgme_tofu_info_t ti;
   int count = 0;
 
-  printf ("Original file name: %s\n", nonnull(result->file_name));
+  printf ("Original file name .: %s\n", nonnull(result->file_name));
+  printf ("MIME flag ..........: %s\n", result->is_mime? "yes":"no");
   for (sig = result->signatures; sig; sig = sig->next)
     {
-      printf ("Signature %d\n", count++);
+      printf ("Signature ...: %d\n", count++);
       printf ("  status ....: %s\n", gpgme_strerror (sig->status));
       printf ("  summary ...:"); print_summary (sig->summary); putchar ('\n');
       printf ("  fingerprint: %s\n", nonnull (sig->fpr));
@@ -167,7 +168,7 @@ print_result (gpgme_verify_result_t result)
             {
               printf ("  notation ..: '%s'\n", nt->name);
               if (strlen (nt->name) != nt->name_len)
-                printf ("    warning : name larger (%d)\n", nt->name_len);
+                printf ("    warning .: name larger (%d)\n", nt->name_len);
               printf ("    flags ...:%s%s (0x%02x)\n",
                       nt->critical? " critical":"",
                       nt->human_readable? " human":"",
@@ -180,7 +181,7 @@ print_result (gpgme_verify_result_t result)
               printf ("  policy ....: '%s'\n", nt->value);
             }
           if ((nt->value?strlen (nt->value):0) != nt->value_len)
-            printf ("    warning : value larger (%d)\n", nt->value_len);
+            printf ("    warning .: value larger (%d)\n", nt->value_len);
         }
       if (sig->key)
         {

commit 23177e4410d05d590c0f2e1675dc645bbb4ad62c
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Apr 18 14:41:50 2018 +0200

    core: Fix possible compliance mode detection error.
    
    * src/verify.c (_gpgme_verify_status_handler): Insert missing break.
    --
    
    Before the insertion of the compliance status checking the break in
    the default clause was used by the STATUS_PLAINTEXT code.  That got
    lost.  I don't see any actual harm due to different values currently
    in use for the compliance status.
    
    Fixes-commit: 05fa2a9c7764b28fdac35eb72631439df948ca0e
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/src/verify.c b/src/verify.c
index 4eab902..c3afdef 100644
--- a/src/verify.c
+++ b/src/verify.c
@@ -1094,6 +1094,7 @@ _gpgme_verify_status_handler (void *priv, gpgme_status_code_t code, char *args)
       err = _gpgme_parse_plaintext (args, &opd->result.file_name);
       if (err)
 	return err;
+      break;
 
     case GPGME_STATUS_VERIFICATION_COMPLIANCE_MODE:
       PARSE_COMPLIANCE_FLAGS (args, opd->current_sig);

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

Summary of changes:
 NEWS                |   2 +
 doc/gpgme.texi      |   2 +-
 src/decrypt.c       |  11 ++--
 src/gpgme-json.c    | 146 +++++++++++++++++++++++++++++++++++++++++++++++++---
 src/gpgme.h.in      |  11 +++-
 src/op-support.c    |   6 ++-
 src/ops.h           |   4 +-
 src/verify.c        |  12 +++--
 tests/run-decrypt.c |  21 ++++----
 tests/run-verify.c  |   9 ++--
 10 files changed, 191 insertions(+), 33 deletions(-)


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




More information about the Gnupg-commits mailing list