[git] GPGME - branch, master, updated. gpgme-1.9.0-51-g46d2e48

by Werner Koch cvs at cvs.gnupg.org
Wed Jul 12 18:38:26 CEST 2017


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  46d2e48105e0929ec38dd4106004dd60d941df9a (commit)
       via  ad0c5ab4cd8d3a1b11b37dc137b75a67aa26da37 (commit)
       via  d37bc7e025cdc6228da45b2b527e9f3bfef71c71 (commit)
       via  87703dbb86ac8fd8abd23170f8038ea6e3dbde28 (commit)
      from  111cd562d8eb11546bbd2d3bd11da4e952d4e504 (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 46d2e48105e0929ec38dd4106004dd60d941df9a
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Jul 12 18:32:50 2017 +0200

    tests: Fix printf compiler warning for an error case.
    
    * tests/gpg/t-keylist.c (main): Cast DIM to int.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/tests/gpg/t-keylist.c b/tests/gpg/t-keylist.c
index 8a32f9b..0417011 100644
--- a/tests/gpg/t-keylist.c
+++ b/tests/gpg/t-keylist.c
@@ -569,7 +569,7 @@ main (int argc, char **argv)
   if (keys[i].fpr)
     {
       fprintf (stderr, "Less keys (%d) returned than expected (%d)\n",
-	       i, DIM (keys) - 1);
+	       i, (int)(DIM (keys) - 1));
       exit (1);
     }
 

commit ad0c5ab4cd8d3a1b11b37dc137b75a67aa26da37
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Jul 12 18:30:49 2017 +0200

    core: Return NO_SECKEY error code on decryption
    
    * src/decrypt.c (op_data_t): Add flag any_no_seckey.
    (_gpgme_decrypt_status_handler): Consult that flag.
    (_gpgme_decrypt_status_handler): Set that flag.
    --
    
    The NO_SECKEY is emitted instead of an "S ERROR pkdecrypt_failed" if
    gpg knowns that a key has been encrypted to that key (cf. "S ENC_TO").
    it is not fool proffof but in the majority of cases we can provide a
    better error message than just DECRYPTION_FAILED.
    
    GnuPG-bug-id: 3270
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/doc/gpgme.texi b/doc/gpgme.texi
index bc40430..31929d3 100644
--- a/doc/gpgme.texi
+++ b/doc/gpgme.texi
@@ -4893,7 +4893,7 @@ if @var{ctx}, @var{cipher} or @var{plain} is not a valid pointer,
 @code{GPG_ERR_NO_DATA} if @var{cipher} does not contain any data to
 decrypt, @code{GPG_ERR_DECRYPT_FAILED} if @var{cipher} is not a valid
 cipher text, @code{GPG_ERR_BAD_PASSPHRASE} if the passphrase for the
-secret key could not be retrieved, and passes through any errors that
+secret key could not be retrieved, and passes through some errors that
 are reported by the crypto engine support routines.
 @end deftypefun
 
diff --git a/src/decrypt.c b/src/decrypt.c
index 1d8412a..aa17771 100644
--- a/src/decrypt.c
+++ b/src/decrypt.c
@@ -1,6 +1,6 @@
 /* decrypt.c - Decrypt function.
    Copyright (C) 2000 Werner Koch (dd9jn)
-   Copyright (C) 2001, 2002, 2003, 2004 g10 Code GmbH
+   Copyright (C) 2001, 2002, 2003, 2004, 2017 g10 Code GmbH
 
    This file is part of GPGME.
 
@@ -49,6 +49,13 @@ typedef struct
   int failed;
   gpg_error_t pkdecrypt_failed;
 
+  /* At least one secret key is not available.  gpg issues NO_SECKEY
+   * status lines for each key the message has been encrypted to but
+   * that secret key is not available.  This can't be done for hidden
+   * recipients, though.  We track it here to allow for a better error
+   * message that the general DECRYPTION_FAILED. */
+  int any_no_seckey;
+
   /* A pointer to the next pointer of the last recipient in the list.
      This makes appending new invalid signers painless while
      preserving the order.  */
@@ -273,6 +280,8 @@ _gpgme_decrypt_status_handler (void *priv, gpgme_status_code_t code,
 	 the underlying crypto engine (as error source).  */
       if (opd->failed && opd->pkdecrypt_failed)
         return opd->pkdecrypt_failed;
+      else if (opd->failed && opd->any_no_seckey)
+	return gpg_error (GPG_ERR_NO_SECKEY);
       else if (opd->failed)
 	return gpg_error (GPG_ERR_DECRYPT_FAILED);
       else if (!opd->okay)
@@ -319,7 +328,6 @@ _gpgme_decrypt_status_handler (void *priv, gpgme_status_code_t code,
     case GPGME_STATUS_NO_SECKEY:
       {
 	gpgme_recipient_t rec = opd->result.recipients;
-
 	while (rec)
 	  {
 	    if (!strcmp (rec->keyid, args))
@@ -332,6 +340,7 @@ _gpgme_decrypt_status_handler (void *priv, gpgme_status_code_t code,
 	/* FIXME: Is this ok?  */
 	if (!rec)
 	  return trace_gpg_error (GPG_ERR_INV_ENGINE);
+        opd->any_no_seckey = 1;
       }
       break;
 

commit d37bc7e025cdc6228da45b2b527e9f3bfef71c71
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Jul 12 17:55:43 2017 +0200

    core: Return CANCELED and BAD_PASSPHRASE error code on decryption.
    
    * src/decrypt.c (op_data_t): Add field pkdecrypt_failed.
    (_gpgme_decrypt_status_handler): Consult new field.
    (parse_status_error): Handle some error codes.
    --
    
    The idea is to return only a limited set of error codes because a user
    won't be able to understand the more esoteric codes.
    
    GnuPG-bug-id: 3270
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/src/decrypt.c b/src/decrypt.c
index 91a32ae..1d8412a 100644
--- a/src/decrypt.c
+++ b/src/decrypt.c
@@ -43,7 +43,11 @@ typedef struct
   gpg_error_t failure_code;
 
   int okay;
+
+  /* A flag telling that the a decryption failed and an optional error
+   * code to further specify the failure.  */
   int failed;
+  gpg_error_t pkdecrypt_failed;
 
   /* A pointer to the next pointer of the last recipient in the list.
      This makes appending new invalid signers painless while
@@ -156,6 +160,31 @@ parse_status_error (char *args, op_data_t opd)
       if (gpg_err_code (err) == GPG_ERR_WRONG_KEY_USAGE)
         opd->result.wrong_key_usage = 1;
     }
+  else if (!strcmp (field[0], "pkdecrypt_failed"))
+    {
+      switch (gpg_err_code (err))
+        {
+        case GPG_ERR_CANCELED:
+        case GPG_ERR_FULLY_CANCELED:
+          /* It is better to return with a cancel error code than the
+           * general decryption failed error code.  */
+          opd->pkdecrypt_failed = gpg_err_make (gpg_err_source (err),
+                                                GPG_ERR_CANCELED);
+          break;
+
+        case GPG_ERR_BAD_PASSPHRASE:
+          /* A bad passphrase is severe enough that we return this
+           * error code.  */
+          opd->pkdecrypt_failed = err;
+          break;
+
+        default:
+          /* For now all other error codes are ignored and the
+           * standard DECRYPT_FAILED is returned.  */
+          break;
+        }
+    }
+
 
   return 0;
 }
@@ -242,7 +271,9 @@ _gpgme_decrypt_status_handler (void *priv, gpgme_status_code_t code,
     case GPGME_STATUS_EOF:
       /* FIXME: These error values should probably be attributed to
 	 the underlying crypto engine (as error source).  */
-      if (opd->failed)
+      if (opd->failed && opd->pkdecrypt_failed)
+        return opd->pkdecrypt_failed;
+      else if (opd->failed)
 	return gpg_error (GPG_ERR_DECRYPT_FAILED);
       else if (!opd->okay)
 	return gpg_error (GPG_ERR_NO_DATA);

commit 87703dbb86ac8fd8abd23170f8038ea6e3dbde28
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Jul 12 15:59:12 2017 +0200

    core: Simplify parsing of STATUS_ERROR in decrypt.c
    
    * src/decrypt.c (_gpgme_decrypt_status_handler): Factor some code out
    to ...
    (parse_status_error): new.  Modernize parsing.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/src/conversion.c b/src/conversion.c
index 92dd214..5b84f67 100644
--- a/src/conversion.c
+++ b/src/conversion.c
@@ -374,7 +374,7 @@ _gpgme_encode_percent_string (const char *src, char **destp, size_t len)
 
 
 /* Split a string into space delimited fields and remove leading and
- * trailing spaces from each field.  A pointer to the each field is
+ * trailing spaces from each field.  A pointer to each field is
  * stored in ARRAY.  Stop splitting at ARRAYSIZE fields.  The function
  * modifies STRING.  The number of parsed fields is returned.
  */
diff --git a/src/decrypt.c b/src/decrypt.c
index 3b18909..91a32ae 100644
--- a/src/decrypt.c
+++ b/src/decrypt.c
@@ -124,7 +124,43 @@ gpgme_op_decrypt_result (gpgme_ctx_t ctx)
   return &opd->result;
 }
 
+
 

+/* Parse the ARGS of an error status line and record some error
+ * conditions at OPD.  Returns 0 on success.  */
+static gpgme_error_t
+parse_status_error (char *args, op_data_t opd)
+{
+  gpgme_error_t err;
+  char *field[3];
+  int nfields;
+
+  nfields = _gpgme_split_fields (args, field, DIM (field));
+  if (nfields < 1)
+    return trace_gpg_error (GPG_ERR_INV_ENGINE); /* Required arg missing.  */
+  err = nfields < 2 ? 0 : atoi (field[1]);
+
+  if (!strcmp (field[0], "decrypt.algorithm"))
+    {
+      if (gpg_err_code (err) == GPG_ERR_UNSUPPORTED_ALGORITHM
+          && nfields > 2
+          && strcmp (field[2], "?"))
+        {
+          opd->result.unsupported_algorithm = strdup (field[2]);
+          if (!opd->result.unsupported_algorithm)
+            return gpg_error_from_syserror ();
+        }
+    }
+  else if (!strcmp (field[0], "decrypt.keyusage"))
+    {
+      if (gpg_err_code (err) == GPG_ERR_WRONG_KEY_USAGE)
+        opd->result.wrong_key_usage = 1;
+    }
+
+  return 0;
+}
+
+
 static gpgme_error_t
 parse_enc_to (char *args, gpgme_recipient_t *recp, gpgme_protocol_t protocol)
 {
@@ -230,47 +266,9 @@ _gpgme_decrypt_status_handler (void *priv, gpgme_status_code_t code,
       /* Note that this is an informational status code which should
          not lead to an error return unless it is something not
          related to the backend.  */
-      {
-	const char d_alg[] = "decrypt.algorithm";
-	const char k_alg[] = "decrypt.keyusage";
-
-	if (!strncmp (args, d_alg, sizeof (d_alg) - 1))
-	  {
-	    args += sizeof (d_alg) - 1;
-	    while (*args == ' ')
-	      args++;
-
-	    if (gpg_err_code (atoi (args)) == GPG_ERR_UNSUPPORTED_ALGORITHM)
-	      {
-		char *end;
-
-		while (*args && *args != ' ')
-		  args++;
-		while (*args == ' ')
-		  args++;
-
-		end = strchr (args, ' ');
-		if (end)
-		  *end = '\0';
-
-		if (!(*args == '?' && *(args + 1) == '\0'))
-		  {
-		    opd->result.unsupported_algorithm = strdup (args);
-		    if (!opd->result.unsupported_algorithm)
-		      return gpg_error_from_syserror ();
-		  }
-	      }
-	  }
-	else if (!strncmp (args, k_alg, sizeof (k_alg) - 1))
-	  {
-	    args += sizeof (k_alg) - 1;
-	    while (*args == ' ')
-	      args++;
-
-	    if (gpg_err_code (atoi (args)) == GPG_ERR_WRONG_KEY_USAGE)
-	      opd->result.wrong_key_usage = 1;
-	  }
-      }
+      err = parse_status_error (args, opd);
+      if (err)
+        return err;
       break;
 
     case GPGME_STATUS_ENC_TO:

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

Summary of changes:
 doc/gpgme.texi        |   2 +-
 src/conversion.c      |   2 +-
 src/decrypt.c         | 126 ++++++++++++++++++++++++++++++++------------------
 tests/gpg/t-keylist.c |   2 +-
 4 files changed, 85 insertions(+), 47 deletions(-)


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




More information about the Gnupg-commits mailing list