[git] GpgOL - branch, async-enc, updated. gpgol-2.0.6-25-g3e1974e

by Andre Heinecke cvs at cvs.gnupg.org
Wed Feb 14 11:22:10 CET 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 extension for MS Outlook".

The branch, async-enc has been updated
       via  3e1974e6ee4fa457c0953faf5d4770338f8c999a (commit)
       via  6b5f7b1fb392fce7b87aa7aa2bdf329b2ffc3c1f (commit)
       via  be3109df4ca2f3374658c05e40fe34a9a23c7612 (commit)
       via  d66b17083386f8be9fe190814abbc41cf85e1290 (commit)
       via  31b54cd71c4ff798b04b129f1739852f93a72167 (commit)
      from  65599bb918388d537c29a3d29b4263497eb261de (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 3e1974e6ee4fa457c0953faf5d4770338f8c999a
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Feb 14 11:18:37 2018 +0100

    Start fixing S/MIME
    
    * src/cryptcontroller.h (m_bodyInput): Place to cache
    the plain text body.
    * src/cryptcontroller.cpp (CryptController::collect_data):
    Collect body into special data variable.
    (CryptController::lookup_fingerprints),
    (CryptController::parse_output),
    (CryptController::resolve_keys): Basically handle S/MIME.
    
    --
    We now collect the body of a mail twice because when we
    do the protocol selection later we do not know if
    we can do inline (S/MIME inline is not supported by us).

diff --git a/src/cryptcontroller.cpp b/src/cryptcontroller.cpp
index 6f164fa..733389f 100644
--- a/src/cryptcontroller.cpp
+++ b/src/cryptcontroller.cpp
@@ -120,14 +120,14 @@ CryptController::collect_data ()
     }
   else if (m_inline)
     {
-      // Inline. Use Body as input and be done.
-      m_input.write (body, strlen (body));
-      log_debug ("%s:%s: PGP Inline. Using cached body as input.",
+      /* Inline. Use Body as input.
+        We need to collect also our mime structure for S/MIME
+        as we don't know yet if we are S/MIME or OpenPGP */
+      m_bodyInput.write (body, strlen (body));
+      log_debug ("%s:%s: Inline. Caching body.",
                  SRCNAME, __func__);
-      gpgol_release (message);
       /* Set the input buffer to start. */
-      m_input.seek (0, SEEK_SET);
-      return 0;
+      m_bodyInput.seek (0, SEEK_SET);
     }
 
   /* Set up the sink object to collect the mime structure */
@@ -177,23 +177,35 @@ rtrim(std::string &s) {
 
 int
 CryptController::lookup_fingerprints (const std::string &sigFpr,
-                                      const std::vector<std::string> recpFprs,
-                                      GpgME::Protocol proto)
+                                      const std::vector<std::string> recpFprs)
 {
-  auto ctx = std::shared_ptr<GpgME::Context> (GpgME::Context::createForProtocol (proto));
+  auto ctx = std::shared_ptr<GpgME::Context> (GpgME::Context::createForProtocol (m_proto));
+
+  if (!ctx)
+    {
+      log_error ("%s:%s: failed to create context with protocol '%s'",
+                 SRCNAME, __func__,
+                 m_proto == GpgME::CMS ? "smime" :
+                 m_proto == GpgME::OpenPGP ? "openpgp" :
+                 "unknown");
+      return -1;
+    }
 
   ctx->setKeyListMode (GpgME::Local);
   GpgME::Error err;
 
   if (!sigFpr.empty()) {
       m_signer_key = ctx->key (sigFpr.c_str (), err, true);
-      if (err || m_signer_key.isNull () ) {
-          log_error ("%s:%s: failed to lookup key for '%s'",
-                     SRCNAME, __func__, sigFpr.c_str ());
+      if (err || m_signer_key.isNull ()) {
+          log_error ("%s:%s: failed to lookup key for '%s' with protocol '%s'",
+                     SRCNAME, __func__, sigFpr.c_str (),
+                     m_proto == GpgME::CMS ? "smime" :
+                     m_proto == GpgME::OpenPGP ? "openpgp" :
+                     "unknown");
           return -1;
       }
       // reset context
-      ctx = std::shared_ptr<GpgME::Context> (GpgME::Context::createForProtocol (proto));
+      ctx = std::shared_ptr<GpgME::Context> (GpgME::Context::createForProtocol (m_proto));
       ctx->setKeyListMode (GpgME::Local);
   }
 
@@ -236,8 +248,6 @@ CryptController::parse_output (GpgME::Data &resolverOutput)
   std::istringstream ss(resolverOutput.toString());
   std::string line;
 
-  GpgME::Protocol proto = GpgME::UnknownProtocol;
-
   std::string sigFpr;
   std::vector<std::string> recpFprs;
   while (std::getline (ss, line))
@@ -266,9 +276,9 @@ CryptController::parse_output (GpgME::Data &resolverOutput)
       std::getline (lss, how, ':');
       std::getline (lss, fingerprint, ':');
 
-      if (proto == GpgME::UnknownProtocol)
+      if (m_proto == GpgME::UnknownProtocol)
         {
-          proto = (how == "smime") ? GpgME::CMS : GpgME::OpenPGP;
+          m_proto = (how == "smime") ? GpgME::CMS : GpgME::OpenPGP;
         }
 
       if (what == "sig")
@@ -301,7 +311,7 @@ CryptController::parse_output (GpgME::Data &resolverOutput)
       return -1;
     }
 
-  return lookup_fingerprints (sigFpr, recpFprs, proto);
+  return lookup_fingerprints (sigFpr, recpFprs);
 }
 
 int
@@ -363,24 +373,24 @@ CryptController::resolve_keys ()
       args.push_back (cached_sender);
     }
 
-  if (m_encrypt)
-    {
-      args.push_back (std::string ("--encrypt"));
-    }
-
   if (!opt.autoresolve)
     {
       args.push_back (std::string ("--alwaysShow"));
     }
 
-  // Get the recipients that are cached from OOM
-  char **recipients = m_mail->take_cached_recipients ();
-  for (size_t i = 0; recipients && recipients[i]; i++)
+
+  if (m_encrypt)
     {
-      args.push_back (GpgME::UserID::addrSpecFromString (recipients[i]));
-    }
+      args.push_back (std::string ("--encrypt"));
+      // Get the recipients that are cached from OOM
+      char **recipients = m_mail->take_cached_recipients ();
+      for (size_t i = 0; recipients && recipients[i]; i++)
+        {
+          args.push_back (GpgME::UserID::addrSpecFromString (recipients[i]));
+        }
 
-  release_carray (recipients);
+      release_carray (recipients);
+    }
 
   // Convert our collected vector to c strings
   // It's a bit overhead but should be quick for such small
@@ -460,7 +470,15 @@ CryptController::do_crypto ()
       return -2;
     }
 
-  auto ctx = std::shared_ptr<GpgME::Context> (GpgME::Context::createForProtocol(GpgME::OpenPGP));
+  if (m_proto == GpgME::CMS && m_inline)
+    {
+      log_debug ("%s:%s: Inline for S/MIME not supported. Switching to mime.",
+                 SRCNAME, __func__);
+      m_inline = false;
+      m_bodyInput = GpgME::Data(GpgME::Data::null);
+    }
+
+  auto ctx = std::shared_ptr<GpgME::Context> (GpgME::Context::createForProtocol(m_proto));
 
   if (!ctx)
     {
@@ -479,7 +497,7 @@ CryptController::do_crypto ()
   if (m_encrypt && m_sign)
     {
       const auto result_pair = ctx->signAndEncrypt (m_recipients,
-                                                    m_input,
+                                                    m_inline ? m_bodyInput : m_input,
                                                     m_output,
                                                     GpgME::Context::AlwaysTrust);
 
@@ -500,7 +518,7 @@ CryptController::do_crypto ()
     }
   else if (m_encrypt)
     {
-      const auto result = ctx->encrypt (m_recipients, m_input,
+      const auto result = ctx->encrypt (m_recipients, m_inline ? m_bodyInput : m_input,
                                         m_output,
                                         GpgME::Context::AlwaysTrust);
       if (result.error())
@@ -518,7 +536,7 @@ CryptController::do_crypto ()
     }
   else if (m_sign)
     {
-      const auto result = ctx->sign (m_input, m_output,
+      const auto result = ctx->sign (m_inline ? m_bodyInput : m_input, m_output,
                                      m_inline ? GpgME::Clearsigned :
                                      GpgME::Detached);
       if (result.error())
diff --git a/src/cryptcontroller.h b/src/cryptcontroller.h
index 416a918..c6d0cbd 100644
--- a/src/cryptcontroller.h
+++ b/src/cryptcontroller.h
@@ -62,12 +62,11 @@ private:
   int resolve_keys ();
   int parse_output (GpgME::Data &resolverOutput);
   int lookup_fingerprints (const std::string &sigFpr,
-                           const std::vector<std::string> recpFprs,
-                           GpgME::Protocol proto);
+                           const std::vector<std::string> recpFprs);
 
 private:
   Mail *m_mail;
-  GpgME::Data m_input, m_output;
+  GpgME::Data m_input, m_bodyInput, m_smime_intermediate, m_output;
   bool m_encrypt, m_sign, m_inline, m_crypto_success;
   GpgME::Protocol m_proto;
   GpgME::Key m_signer_key;

commit 6b5f7b1fb392fce7b87aa7aa2bdf329b2ffc3c1f
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Feb 14 08:29:37 2018 +0100

    Revert "Launch Kleo/GPA in the background on start"
    
    This reverts commit 13950a98522818b27b3048617acb0282b65b54b3.
    
    --
    For the async-enc branch this is no longer needed.

diff --git a/src/engine-assuan.c b/src/engine-assuan.c
index 95eee5f..8907c18 100644
--- a/src/engine-assuan.c
+++ b/src/engine-assuan.c
@@ -559,53 +559,16 @@ op_assuan_deinit (void)
   cleanup ();
 }
 
-/* Code for a thread in the background */
-static DWORD WINAPI
-spawn_background (LPVOID arg)
-{
-  gpgme_error_t err;
-  assuan_context_t ctx;
-  pid_t pid;
-  ULONG cmdid;
-
-  (void) arg;
-
-  /* Run a test connection to see whether the UI server is available.  */
-  log_debug ("%s:%s: Initial uiserver connect", SRCNAME, __func__);
-  err = connect_uiserver (&ctx, &pid, &cmdid, NULL);
-  if (!err)
-    {
-      log_debug ("%s:%s: Sending noop", SRCNAME, __func__);
-      err = assuan_transact (ctx, "NOP", NULL, NULL, NULL, NULL, NULL, NULL);
-      assuan_release (ctx);
-    }
-  if (err)
-    log_debug ("%s:%s: Failed code: %i", SRCNAME, __func__, err);
-
-  return 0;
-}
 
 /* Initialize this system. */
 int
 op_assuan_init (void)
 {
   static int init_done;
-  HANDLE thread;
 
   if (init_done)
     return 0;
 
-  /* Connect to UiServer in the background */
-
-  /* XXX This should not really be necessary but
-     it was often reported that the spawn and connect
-     did not work. Also it is much faster to access
-     Kleopatra when it's already running so spawning
-     it as lookahead probably makes sense. */
-  thread = CreateThread (NULL, 0, spawn_background,
-                         NULL, 0, NULL);
-  CloseHandle(thread);
-
   /* Fire up the pipe worker thread. */
   {
     HANDLE th;

commit be3109df4ca2f3374658c05e40fe34a9a23c7612
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Feb 14 08:15:34 2018 +0100

    Minor cleanup
    
    --

diff --git a/src/cryptcontroller.cpp b/src/cryptcontroller.cpp
index e24f8fb..6f164fa 100644
--- a/src/cryptcontroller.cpp
+++ b/src/cryptcontroller.cpp
@@ -450,18 +450,8 @@ CryptController::resolve_keys ()
 int
 CryptController::do_crypto ()
 {
-  // TODO get recipients and sender and protocol.
-
-  log_debug ("%s:%s:",
+  log_debug ("%s:%s",
              SRCNAME, __func__);
-  auto ctx = std::shared_ptr<GpgME::Context> (GpgME::Context::createForProtocol(GpgME::OpenPGP));
-
-  if (!ctx)
-    {
-      log_error ("%s:%s: Failure to create context.",
-                 SRCNAME, __func__);
-      return -1;
-    }
 
   if (resolve_keys ())
     {
@@ -470,6 +460,14 @@ CryptController::do_crypto ()
       return -2;
     }
 
+  auto ctx = std::shared_ptr<GpgME::Context> (GpgME::Context::createForProtocol(GpgME::OpenPGP));
+
+  if (!ctx)
+    {
+      log_error ("%s:%s: Failure to create context.",
+                 SRCNAME, __func__);
+      return -1;
+    }
   if (!m_signer_key.isNull())
     {
       ctx->addSigningKey (m_signer_key);

commit d66b17083386f8be9fe190814abbc41cf85e1290
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Feb 14 08:12:46 2018 +0100

    Fix parsing of command lines
    
    * src/cryptcontroller.cpp (CryptController::parse_output):
    rtrim parsed lines.
    
    --
    This fixes cancel.

diff --git a/src/cryptcontroller.cpp b/src/cryptcontroller.cpp
index 389d307..e24f8fb 100644
--- a/src/cryptcontroller.cpp
+++ b/src/cryptcontroller.cpp
@@ -242,6 +242,7 @@ CryptController::parse_output (GpgME::Data &resolverOutput)
   std::vector<std::string> recpFprs;
   while (std::getline (ss, line))
     {
+      rtrim (line);
       if (line == "cancel")
         {
           log_debug ("%s:%s: resolver canceled",
@@ -265,9 +266,6 @@ CryptController::parse_output (GpgME::Data &resolverOutput)
       std::getline (lss, how, ':');
       std::getline (lss, fingerprint, ':');
 
-      // Remove possible trailing newline / cr
-      rtrim (fingerprint);
-
       if (proto == GpgME::UnknownProtocol)
         {
           proto = (how == "smime") ? GpgME::CMS : GpgME::OpenPGP;

commit 31b54cd71c4ff798b04b129f1739852f93a72167
Author: Andre Heinecke <aheinecke at intevation.de>
Date:   Wed Feb 14 08:09:41 2018 +0100

    Bring mail window to front after keyresolution
    
    * src/common.c, src/common.h (bring_to_front): New.
    * src/cryptcontroller.cpp (CryptController::resolve_keys): Use it.
    
    --
    Somehow when the Qt modal window is closed it brings the wrong
    window back. This fix does not prevent that but at least returns
    the previous active window to the front.
    
    GnuPG-Bug-Id: T3732

diff --git a/src/common.c b/src/common.c
index f2bfc86..5d4c6fb 100644
--- a/src/common.c
+++ b/src/common.c
@@ -242,6 +242,23 @@ get_save_filename (HWND root, const char *srcname)
   return NULL;
 }
 
+void
+bring_to_front (HWND wid)
+{
+  if (wid)
+    {
+      if (!SetForegroundWindow (wid))
+        {
+          log_debug ("%s:%s: SetForegroundWindow failed", SRCNAME, __func__);
+          /* Yet another fallback which will not work on some
+           * versions and is not recommended by msdn */
+          if (!ShowWindow (wid, SW_SHOWNORMAL))
+            {
+              log_debug ("%s:%s: ShowWindow failed.", SRCNAME, __func__);
+            }
+        }
+    }
+}
 
 void
 fatal_error (const char *format, ...)
diff --git a/src/common.h b/src/common.h
index 09c6072..d306d16 100644
--- a/src/common.h
+++ b/src/common.h
@@ -140,6 +140,7 @@ extern int g_ol_version_major;
 void log_window_hierarchy (HWND window, const char *fmt,
                            ...) __attribute__ ((format (printf,2,3)));
 
+void bring_to_front (HWND wid);
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/cryptcontroller.cpp b/src/cryptcontroller.cpp
index 9f6cdbf..389d307 100644
--- a/src/cryptcontroller.cpp
+++ b/src/cryptcontroller.cpp
@@ -329,10 +329,14 @@ CryptController::resolve_keys ()
   // We want debug output as OutputDebugString
   args.push_back (std::string ("--debug"));
 
-  // Pass the handle of the active window for raise / overlay.
-  args.push_back (std::string ("--hwnd"));
   // Yes passing it as int is ok.
-  args.push_back (std::to_string ((int) m_mail->get_window ()));
+  auto wnd = m_mail->get_window ();
+  if (wnd)
+    {
+      // Pass the handle of the active window for raise / overlay.
+      args.push_back (std::string ("--hwnd"));
+      args.push_back (std::to_string ((int) wnd));
+    }
 
   // Set the overlay caption
   args.push_back (std::string ("--overlayText"));
@@ -416,6 +420,9 @@ CryptController::resolve_keys ()
                                  (GpgME::Context::SpawnFlags) (
                                   GpgME::Context::SpawnAllowSetFg |
                                   GpgME::Context::SpawnShowWindow));
+  // Somehow Qt messes up which window to bring back to front.
+  // So we do it manually.
+  bring_to_front (wnd);
 
 #ifdef DEBUG_RESOLVER
   log_debug ("Resolver stdout:\n'%s'", mystdout.toString ().c_str ());

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

Summary of changes:
 src/common.c            |  17 +++++++
 src/common.h            |   1 +
 src/cryptcontroller.cpp | 117 ++++++++++++++++++++++++++++--------------------
 src/cryptcontroller.h   |   5 +--
 src/engine-assuan.c     |  37 ---------------
 5 files changed, 89 insertions(+), 88 deletions(-)


hooks/post-receive
-- 
GnuPG extension for MS Outlook
http://git.gnupg.org




More information about the Gnupg-commits mailing list