[Pkg-gnupg-commit] [gpgme] 183/412: core: Add closer inspection of "PGP MESSAGE".

Daniel Kahn Gillmor dkg at fifthhorseman.net
Thu Sep 22 21:26:43 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gpgme.

commit cf37a57d28c43ec36277e84ca44458b7287b940b
Author: Werner Koch <wk at gnupg.org>
Date:   Thu Jun 23 10:14:57 2016 +0200

    core: Add closer inspection of "PGP MESSAGE".
    
    * src/data-identify.c (inspect_pgp_message): New.
    (basic_detection): Un-const arg DATA. Call inspect_pgp_message.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>
---
 src/data-identify.c | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/src/data-identify.c b/src/data-identify.c
index ae31117..1cfccd7 100644
--- a/src/data-identify.c
+++ b/src/data-identify.c
@@ -271,12 +271,36 @@ pgp_binary_detection (const void *image_arg, size_t imagelen)
 }
 
 
+/* This is probably an armored "PGP MESSAGE" which can encode
+ * different PGP data types.  STRING is modified after a call to this
+ * fucntion. */
+static gpgme_data_type_t
+inspect_pgp_message (char *string)
+{
+  struct b64state state;
+  size_t nbytes;
+
+  if (_gpgme_b64dec_start (&state, ""))
+    return GPGME_DATA_TYPE_INVALID; /* oops */
+
+  if (_gpgme_b64dec_proc (&state, string, strlen (string), &nbytes))
+    {
+      _gpgme_b64dec_finish (&state);
+      return GPGME_DATA_TYPE_UNKNOWN; /* bad encoding etc. */
+    }
+  _gpgme_b64dec_finish (&state);
+  string[nbytes] = 0; /* Better append a Nul. */
+
+  return pgp_binary_detection (string, nbytes);
+}
+
+
 /* Note that DATA may be binary but a final nul is required so that
    string operations will find a terminator.
 
    Returns: GPGME_DATA_TYPE_xxxx */
 static gpgme_data_type_t
-basic_detection (const char *data, size_t datalen)
+basic_detection (char *data, size_t datalen)
 {
   tlvinfo_t ti;
   const char *s;
@@ -430,7 +454,8 @@ basic_detection (const char *data, size_t datalen)
                 return GPGME_DATA_TYPE_PGP_KEY;
               if (!strncmp (s+15, "ARMORED FILE", 12))
                 return GPGME_DATA_TYPE_UNKNOWN;
-              return GPGME_DATA_TYPE_PGP_OTHER; /* PGP MESSAGE */
+
+              return inspect_pgp_message (data);
             }
           if (!strncmp (s+11, "CERTIFICATE", 11))
             return GPGME_DATA_TYPE_X509_CERT;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gpgme.git



More information about the Pkg-gnupg-commit mailing list