[svn] GpgOL - r218 - in trunk: doc po src

svn author wk cvs at cvs.gnupg.org
Fri Feb 8 13:11:59 CET 2008


Author: wk
Date: 2008-02-08 13:11:57 +0100 (Fri, 08 Feb 2008)
New Revision: 218

Modified:
   trunk/doc/gpgol.texi
   trunk/po/de.po
   trunk/po/sv.po
   trunk/src/ChangeLog
   trunk/src/common.h
   trunk/src/engine-assuan.c
   trunk/src/engine-assuan.h
   trunk/src/engine.c
   trunk/src/ext-commands.cpp
   trunk/src/item-events.cpp
   trunk/src/main.c
   trunk/src/mapihelp.cpp
   trunk/src/message-events.cpp
   trunk/src/message.cpp
   trunk/src/mimeparser.c
   trunk/src/mimeparser.h
   trunk/src/ol-ext-callback.cpp
   trunk/src/olflange.cpp
   trunk/src/session-events.cpp
   trunk/src/user-events.cpp
Log:
Finer grained debug control.
Fixes for CryptoEx.


[The diff below has been truncated]

Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2008-02-07 11:46:47 UTC (rev 217)
+++ trunk/src/ChangeLog	2008-02-08 12:11:57 UTC (rev 218)
@@ -1,5 +1,18 @@
+2008-02-08  Werner Koch  <wk at g10code.com>
+
+	* mapihelp.cpp (mapi_change_message_class): Improve detecion of
+	CryptoEx messages.
+
 2008-02-07  Werner Koch  <wk at g10code.com>
 
+	* engine.c (engine_verify_start): Enable opaque signature for the
+	assuan backend.
+	* engine-assuan.c (op_assuan_verify): New arg OUTDATA.  Add
+	support for opaque signatures.
+
+	* mimeparser.c (mime_verify_opaque): New.
+	* message.cpp (message_verify): Handle opaque signed S/MIME.
+
 	* message.cpp (message_wipe_body_cruft): Delete only encrypted
 	messages.
 

Modified: trunk/doc/gpgol.texi
===================================================================
--- trunk/doc/gpgol.texi	2008-02-07 11:46:47 UTC (rev 217)
+++ trunk/doc/gpgol.texi	2008-02-08 12:11:57 UTC (rev 218)
@@ -647,18 +647,20 @@
 make the log file output more verbose; these are actually bit flags
 according to the following table (which may change with any release):
 @table @code
- at item 2
+ at item 2  (0x0002)
 Tell what the Assuan I/O scheduler is doing.
- at item 4 
+ at item 4  (0x0004)
 Even more verbose Assuan I/O scheduler reporting. 
- at item 8
+ at item 8  (0x0008)
 Tell what the filter I/O system is doing.
- at item 16 
+ at item 16 (0x0010)
 Tell how the filter I/O locks the resources.
+ at item 32 (0x0020)
+Tell about resource allocation.
 @end table
+You may use the regular C-syntax for entering the value.
 
 
-
 @itemx HKCU\Software\GNU\GpgOL:logFile
 If the value is not empty, GpgOL takes this as a log file and appends
 debug information to this file.  The file may get very large.

Modified: trunk/po/de.po  [not shown]
Modified: trunk/po/sv.po  [not shown]
Modified: trunk/src/common.h
===================================================================
--- trunk/src/common.h	2008-02-07 11:46:47 UTC (rev 217)
+++ trunk/src/common.h	2008-02-08 12:11:57 UTC (rev 218)
@@ -149,6 +149,7 @@
 #define DBG_IOWORKER_EXTRA  4
 #define DBG_FILTER          8
 #define DBG_FILTER_EXTRA   16 
+#define DBG_MEMORY         32
 
 /*-- common.c --*/
 void set_global_hinstance (HINSTANCE hinst);

Modified: trunk/src/engine-assuan.c
===================================================================
--- trunk/src/engine-assuan.c	2008-02-07 11:46:47 UTC (rev 217)
+++ trunk/src/engine-assuan.c	2008-02-08 12:11:57 UTC (rev 218)
@@ -1680,43 +1680,76 @@
 }
 
 
-/* Verify a detached message where the data is in the gpgme object
-   MSGDATA and the signature given as the string SIGNATURE. */
+/* With MSGDATA, SIGNATURE and SIGLEN given: 
+
+      Verify a detached message where the data is in the gpgme object
+      MSGDATA and the signature given as the string SIGNATURE. 
+
+   With MSGDATA and OUTDATA given:
+
+      Verify an opaque signature from MSGDATA and write the decoded
+      plaintext to OUTDATA.
+
+*/
 int 
 op_assuan_verify (gpgme_protocol_t protocol, 
                   gpgme_data_t msgdata, const char *signature, size_t sig_len,
+                  gpgme_data_t outdata,
                   engine_filter_t filter, void *hwnd)
 {
   gpg_error_t err;
   closure_data_t cld = NULL;
   assuan_context_t ctx;
   char line[1024];
-  HANDLE msgpipe[2], sigpipe[2];
+  HANDLE msgpipe[2], sigpipe[2], outpipe[2];
   ULONG cmdid;
   pid_t pid;
   gpgme_data_t sigdata = NULL;
   const char *protocol_name;
+  int opaque_mode;
 
   msgpipe[0] = INVALID_HANDLE_VALUE;
   msgpipe[1] = INVALID_HANDLE_VALUE;
   sigpipe[0] = INVALID_HANDLE_VALUE;
   sigpipe[1] = INVALID_HANDLE_VALUE;
+  outpipe[0] = INVALID_HANDLE_VALUE;
+  outpipe[1] = INVALID_HANDLE_VALUE;
 
   if (!(protocol_name = get_protocol_name (protocol)))
     return gpg_error(GPG_ERR_INV_VALUE);
 
-  err = gpgme_data_new_from_mem (&sigdata, signature, sig_len, 0);
-  if (err)
-    goto leave;
+  if (signature && sig_len && !outdata)
+    opaque_mode = 0;
+  else if (!signature && !sig_len && outdata)
+    opaque_mode = 1;
+  else
+    return gpg_error(GPG_ERR_INV_VALUE);
 
+  if (!opaque_mode)
+    {
+      err = gpgme_data_new_from_mem (&sigdata, signature, sig_len, 0);
+      if (err)
+        goto leave;
+    }
+
   err = connect_uiserver (&ctx, &pid, &cmdid, hwnd);
   if (err)
     goto leave;
 
-  if ((err = create_io_pipe (msgpipe, pid, 1)))
-    goto leave;
-  if ((err = create_io_pipe (sigpipe, pid, 1)))
-    goto leave;
+  if (!opaque_mode)
+    {
+      if ((err = create_io_pipe (msgpipe, pid, 1)))
+        goto leave;
+      if ((err = create_io_pipe (sigpipe, pid, 1)))
+        goto leave;
+    }
+  else
+    {
+      if ((err = create_io_pipe (msgpipe, pid, 1)))
+        goto leave;
+      if ((err = create_io_pipe (outpipe, pid, 0)))
+        goto leave;
+    }
 
   cld = xcalloc (1, sizeof *cld);
   cld->closure = verify_closure;
@@ -1727,20 +1760,41 @@
   if (err)
     goto leave;
 
-  snprintf (line, sizeof line, "MESSAGE FD=%ld",(unsigned long int)msgpipe[0]);
-  err = assuan_transact (ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
-  if (err)
-    goto leave;
-  snprintf (line, sizeof line, "INPUT FD=%ld", (unsigned long int)sigpipe[0]);
-  err = assuan_transact (ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
-  if (err)
-    goto leave;
+  if (!opaque_mode)
+    {
+      snprintf (line, sizeof line, "MESSAGE FD=%ld",
+                (unsigned long int)msgpipe[0]);
+      err = assuan_transact (ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
+      if (err)
+        goto leave;
+      snprintf (line, sizeof line, "INPUT FD=%ld",
+                (unsigned long int)sigpipe[0]);
+      err = assuan_transact (ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
+      if (err)
+        goto leave;
+      enqueue_callback ("   msg", ctx, msgdata, msgpipe[1], 1,
+                        finalize_handler, cmdid, NULL, 0); 
+      enqueue_callback ("   sig", ctx, sigdata, sigpipe[1], 1, 
+                        finalize_handler, cmdid, NULL, 0); 
+    }
+  else 
+    {
+      snprintf (line, sizeof line, "INPUT FD=%ld",
+                (unsigned long int)msgpipe[0]);
+      err = assuan_transact (ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
+      if (err)
+        goto leave;
+      snprintf (line, sizeof line, "OUTPUT FD=%ld",
+                (unsigned long int)outpipe[1]);
+      err = assuan_transact (ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
+      if (err)
+        goto leave;
+      enqueue_callback ("   msg", ctx, msgdata, msgpipe[1], 1,
+                        finalize_handler, cmdid, NULL, 0); 
+      enqueue_callback ("   out", ctx, outdata, outpipe[0], 0,
+                        finalize_handler, cmdid, NULL, 1); 
+    }
 
-  enqueue_callback ("   msg", ctx, msgdata, msgpipe[1], 1, finalize_handler,
-                    cmdid, NULL, 0); 
-  enqueue_callback ("   sig", ctx, sigdata, sigpipe[1], 1, finalize_handler, 
-                    cmdid, NULL, 0); 
-
   snprintf (line, sizeof line, "VERIFY --protocol=%s",  protocol_name);
   err = start_command (ctx, cld, cmdid, line);
   cld = NULL;     /* Now owned by start_command.  */
@@ -1755,6 +1809,7 @@
       /* Fixme: Cancel stuff in the work_queue. */
       close_pipe (msgpipe);
       close_pipe (sigpipe);
+      close_pipe (outpipe);
       gpgme_data_release (sigdata);
       xfree (cld);
       assuan_disconnect (ctx);

Modified: trunk/src/engine-assuan.h
===================================================================
--- trunk/src/engine-assuan.h	2008-02-07 11:46:47 UTC (rev 217)
+++ trunk/src/engine-assuan.h	2008-02-08 12:11:57 UTC (rev 218)
@@ -48,6 +48,7 @@
                        int with_verify);
 int op_assuan_verify (gpgme_protocol_t protocol, 
                       gpgme_data_t data, const char *signature, size_t sig_len,
+                      gpgme_data_t outdata,
                       engine_filter_t filter, void *hwnd);
 
 int op_assuan_start_keymanager (void *hwnd);

Modified: trunk/src/engine.c
===================================================================
--- trunk/src/engine.c	2008-02-07 11:46:47 UTC (rev 217)
+++ trunk/src/engine.c	2008-02-08 12:11:57 UTC (rev 218)
@@ -742,19 +742,23 @@
 {
   gpg_error_t err;
 
-  if (!signature)
+  if (!signature && !filter->use_assuan)
     {
-      log_error ("%s:%s: opaque signature are not yet supported\n",
+      log_error ("%s:%s: opaque signatures are not supported "
+                 "by the internal backend\n",
                  SRCNAME, __func__);
       return gpg_error (GPG_ERR_NOT_SUPPORTED);
     }
 
-  if (filter->use_assuan)
-    err = op_assuan_verify (protocol, filter->indata, signature,
-			    sig_len, filter, hwnd);
+  if (filter->use_assuan && !signature)
+    err = op_assuan_verify (protocol, filter->indata, NULL, 0,
+			    filter->outdata, filter, hwnd);
+  else if (filter->use_assuan)
+    err = op_assuan_verify (protocol, filter->indata, signature, sig_len,
+			    NULL, filter, hwnd);
   else
-    err = op_gpgme_verify (protocol, filter->indata, signature,
-			   sig_len, filter, hwnd);
+    err = op_gpgme_verify (protocol, filter->indata, signature, sig_len,
+                           filter, hwnd);
   return err;
 }
 

Modified: trunk/src/ext-commands.cpp
===================================================================
--- trunk/src/ext-commands.cpp	2008-02-07 11:46:47 UTC (rev 217)
+++ trunk/src/ext-commands.cpp	2008-02-08 12:11:57 UTC (rev 218)
@@ -83,8 +83,9 @@
   if (!punk)
     return;
   res = UlRelease (punk);
-  log_debug ("%s:%s:%d: UlRelease(%p) had %lu references\n", 
-             SRCNAME, func, lnr, punk, res);
+  if (opt.enable_debug & DBG_MEMORY)
+    log_debug ("%s:%s:%d: UlRelease(%p) had %lu references\n", 
+               SRCNAME, func, lnr, punk, res);
 }
 
 

Modified: trunk/src/item-events.cpp
===================================================================
--- trunk/src/item-events.cpp	2008-02-07 11:46:47 UTC (rev 217)
+++ trunk/src/item-events.cpp	2008-02-08 12:11:57 UTC (rev 218)
@@ -50,7 +50,8 @@
   if (!punk)
     return;
   res = UlRelease (punk);
-//   log_debug ("%s UlRelease(%p) had %lu references\n", __func__, punk, res);
+  if (opt.enable_debug & DBG_MEMORY)
+    log_debug ("%s UlRelease(%p) had %lu references\n", __func__, punk, res);
 }
 
 

Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c	2008-02-07 11:46:47 UTC (rev 217)
+++ trunk/src/main.c	2008-02-08 12:11:57 UTC (rev 218)
@@ -509,7 +509,7 @@
   char *val = NULL;
  
   load_extension_value ("enableDebug", &val);
-  opt.enable_debug = val? atoi (val) : 0;
+  opt.enable_debug = val? strtoul (val, NULL, 0) : 0;
   xfree (val); val = NULL;
 
   load_extension_value ("enableSmime", &val);

Modified: trunk/src/mapihelp.cpp
===================================================================
--- trunk/src/mapihelp.cpp	2008-02-07 11:46:47 UTC (rev 217)
+++ trunk/src/mapihelp.cpp	2008-02-08 12:11:57 UTC (rev 218)
@@ -526,7 +526,10 @@
   if ( PROP_TYPE (propval->ulPropTag) == PT_STRING8 )
     {
       const char *s = propval->Value.lpszA;
-
+      int cexenc = 0;
+      
+      log_debug ("%s:%s: checking message class `%s'", 
+                       SRCNAME, __func__, s);
       if (!strcmp (s, "IPM.Note"))
         {
           /* Most message today are of this type.  However a PGP/MIME
@@ -631,24 +634,33 @@
             newvalue = (char*)xstrdup (s);
           MAPIFreeBuffer (propval2);
         }
-      else if (opt.enable_smime && !strcmp (s, "IPM.Note.Secure.CexSig"))
+      else if (opt.enable_smime 
+               && (!strcmp (s, "IPM.Note.Secure.CexSig")
+                   || (cexenc = !strcmp (s, "IPM.Note.Secure.CexEnc"))))
         {
-          /* This is a CryptoEx generated signature. */
-          char *ct, *smtype;
+          /* This is a CryptoEx generated signature or encrypted data. */
+          char *ct, *smtype, *proto;
 
-          ct = mapi_get_message_content_type (message, NULL, &smtype);
+          ct = mapi_get_message_content_type (message, &proto, &smtype);
           if (!ct)
-            log_debug ("%s:%s: message has no content type", 
-                       SRCNAME, __func__);
+            {
+              log_debug ("%s:%s: message has no content type", 
+                         SRCNAME, __func__);
+              if (cexenc)
+                newvalue = xstrdup ("IPM.Note.GpgOL.OpaqueEncrypted");
+            }
           else
             {
               log_debug ("%s:%s: content type is '%s'", 
                          SRCNAME, __func__, ct);
               if (smtype)
+               log_debug ("%s:%s:   smime-type is '%s'", 
+                           SRCNAME, __func__, smtype);
+              if (proto)
+                log_debug ("%s:%s:     protocol is '%s'", 
+                           SRCNAME, __func__, proto);
+              if (smtype)
                 {
-                  log_debug ("%s:%s:   smime-type is '%s'", 
-                             SRCNAME, __func__, smtype);
-              
                   if (!strcmp (ct, "application/pkcs7-mime")
                       || !strcmp (ct, "application/x-pkcs7-mime"))
                     {
@@ -657,12 +669,29 @@
                       else if (!strcmp (smtype, "enveloped-data"))
                         newvalue = xstrdup ("IPM.Note.GpgOL.OpaqueEncrypted");
                     }
-                  else if (!strcmp (ct, "application/pkcs7-signature"))
-                    {
-                      newvalue = xstrdup ("IPM.Note.GpgOL.MultipartSigned");
-                    }
-                  xfree (smtype);
                 }
+
+              if (!newvalue && proto)
+                {
+                  if (!strcmp (ct, "multipart/signed")
+                      && (!strcmp (proto, "application/pkcs7-signature")
+                          || !strcmp (proto, "application/x-pkcs7-signature")))
+                    newvalue = xstrdup ("IPM.Note.GpgOL.MultipartSigned");
+                  else if (!strcmp (ct, "multipart/signed")
+                           && (!strcmp (proto, "application/pgp-signature")))
+                    newvalue = xstrdup ("IPM.Note.GpgOL.MultipartSigned");
+                }
+
+              if (!newvalue && !strcmp (ct, "text/plain"))
+                {
+                  newvalue = get_msgcls_from_pgp_lines (message);
+                }
+
+              if (!newvalue && cexenc)
+                newvalue = xstrdup ("IPM.Note.GpgOL.OpaqueEncrypted");
+
+              xfree (smtype);
+              xfree (proto);
               xfree (ct);
             }
           if (!newvalue)
@@ -1654,7 +1683,7 @@
 {
   if (event == RFC822PARSE_T2BODY)
     return 42; /* Hack to stop the parsing after having read the
-                  outher headers. */
+                  outer headers. */
   return 0;
 }
 

Modified: trunk/src/message-events.cpp
===================================================================
--- trunk/src/message-events.cpp	2008-02-07 11:46:47 UTC (rev 217)
+++ trunk/src/message-events.cpp	2008-02-08 12:11:57 UTC (rev 218)
@@ -54,8 +54,9 @@
   if (!punk)
     return;
   res = UlRelease (punk);
-  log_debug ("%s:%s:%d: UlRelease(%p) had %lu references\n", 
-             SRCNAME, func, lnr, punk, res);
+  if (opt.enable_debug & DBG_MEMORY)
+    log_debug ("%s:%s:%d: UlRelease(%p) had %lu references\n", 
+               SRCNAME, func, lnr, punk, res);
 }
 
 

Modified: trunk/src/message.cpp
===================================================================
--- trunk/src/message.cpp	2008-02-07 11:46:47 UTC (rev 217)
+++ trunk/src/message.cpp	2008-02-08 12:11:57 UTC (rev 218)
@@ -45,8 +45,9 @@
   if (!punk)
     return;
   res = UlRelease (punk);
-  log_debug ("%s:%s: UlRelease(%p) had %lu references\n", 
-             SRCNAME, func, punk, res);
+  if (opt.enable_debug & DBG_MEMORY)
+    log_debug ("%s:%s: UlRelease(%p) had %lu references\n", 
+               SRCNAME, func, punk, res);
 }
 
 
@@ -286,7 +287,7 @@
 
 
 
-/* Convert the clear signed message from INPUT into a PS?MIME signed
+/* Convert the clear signed message from INPUT into a PGP/MIME signed
    message and return it in a new allocated buffer.  OUTPUTLEN
    received the valid length of that buffer; the buffer is guarnateed
    to be Nul terminated.  */
@@ -474,20 +475,18 @@
 {
   HRESULT hr;
   mapi_attach_item_t *table = NULL;
+  LPSTREAM opaquestream = NULL;
   int moss_idx = -1;
   int i;
-  char *inbuf;
-  size_t inbuflen;
+  char *inbuf = NULL;
+  size_t inbuflen = 0;
   protocol_t protocol = PROTOCOL_UNKNOWN;
   int err;
 
   switch (msgtype)
     {
     case MSGTYPE_GPGOL_MULTIPART_SIGNED:
-      break;
     case MSGTYPE_GPGOL_OPAQUE_SIGNED:
-      log_debug ("Opaque signed message are not yet supported!");
-      return 0;
     case MSGTYPE_GPGOL_CLEAR_SIGNED:
       break;
     case MSGTYPE_GPGOL_MULTIPART_ENCRYPTED:
@@ -533,6 +532,38 @@
         return -1;
       protocol = PROTOCOL_OPENPGP;
     }
+  else if (msgtype == MSGTYPE_GPGOL_OPAQUE_SIGNED)
+    {
+      /* S/MIME opaque signed message: The data is expected to be in
+         an attachment.  */
+      table = mapi_create_attach_table (message, 0);
+      if (!table)
+        return -1; /* No attachment - this should not happen.  */
+
+      for (i=0; !table[i].end_of_table; i++)
+        if (table[i].content_type               
+            && (!strcmp (table[i].content_type, "application/pkcs7-mime")
+                || !strcmp (table[i].content_type,
+                            "application/x-pkcs7-mime"))
+            && table[i].filename
+            && !strcmp (table[i].filename, "smime.p7m"))
+          break;
+      if (table[i].end_of_table)
+        {
+          log_debug ("%s:%s: attachment for opaque signed S/MIME not found",
+                     SRCNAME, __func__);
+          mapi_release_attach_table (table);
+          return -1;
+        }
+
+      opaquestream = mapi_get_attach_as_stream (message, table+i, NULL);
+      if (!opaquestream)
+        {
+          mapi_release_attach_table (table);
+          return -1; /* Problem getting the attachment.  */
+        }




More information about the Gnupg-commits mailing list