[git] GpgOL - branch, master, updated. gpgol-2.2.0-140-gb5e68fc
by Andre Heinecke
cvs at cvs.gnupg.org
Wed Aug 22 10:21:53 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 extension for MS Outlook".
The branch, master has been updated
via b5e68fc000add09200045df885479864bc325445 (commit)
via 2767b0a794ae2b77331fc4305f91b767f9b4862d (commit)
via cebe6484acaa250858affa3d854ef2b25cecd59f (commit)
via 75659ee29c72c78a4c44ba87ea168f06813f84cd (commit)
from 29f3ba005571b7a145f18240598d9f87f2ba9bca (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 b5e68fc000add09200045df885479864bc325445
Author: Andre Heinecke <aheinecke at intevation.de>
Date: Wed Aug 22 10:20:20 2018 +0200
Rewrite cached key resolution
* src/cryptcontroller.cpp (resolve_through_protocol): New.
(resolve_keys_cached): Use new helper function.
--
The old code was too much spaghetti and several issues. E.g.
it could select a CMS Signing key with OpenPGP Encryption
keys. Or would not support fallback to S/MIME if OpenPGP
encryption was possible but only an S/MIME signing key available.
diff --git a/src/cryptcontroller.cpp b/src/cryptcontroller.cpp
index f6f1542..afeb24d 100644
--- a/src/cryptcontroller.cpp
+++ b/src/cryptcontroller.cpp
@@ -312,86 +312,105 @@ CryptController::parse_output (GpgME::Data &resolverOutput)
return lookup_fingerprints (sigFpr, recpFprs);
}
-int
-CryptController::resolve_keys_cached()
+static bool
+resolve_through_protocol (const GpgME::Protocol &proto, bool sign,
+ bool encrypt, const std::string &sender,
+ const std::vector<std::string> &recps,
+ std::vector<GpgME::Key> &r_keys,
+ GpgME::Key &r_sig)
{
+ bool sig_ok = true;
+ bool enc_ok = true;
+
const auto cache = KeyCache::instance();
- bool fallbackToSMIME = false;
+ if (encrypt)
+ {
+ r_keys = cache->getEncryptionKeys(recps, proto);
+ enc_ok = !r_keys.empty();
+ }
+ if (sign && enc_ok)
+ {
+ r_sig = cache->getSigningKey (sender.c_str (), proto);
+ sig_ok = !r_sig.isNull();
+ }
+ return sig_ok && enc_ok;
+}
+
+int
+CryptController::resolve_keys_cached()
+{
+ // Prepare variables
+ const auto cached_sender = m_mail->getSender ();
+ auto recps = m_recipient_addrs;
if (m_encrypt)
{
- const auto cached_sender = m_mail->getSender ();
- auto recps = m_recipient_addrs;
recps.push_back (cached_sender);
+ }
- m_recipients.clear();
- if (opt.enable_smime && opt.prefer_smime)
- {
- m_recipients = cache->getEncryptionKeys(recps, GpgME::CMS);
- if (!m_recipients.empty())
- {
- fallbackToSMIME = true;
- m_proto = GpgME::CMS;
- }
- }
-
- if (m_recipients.empty())
- {
- m_recipients = cache->getEncryptionKeys(recps, GpgME::OpenPGP);
- m_proto = GpgME::OpenPGP;
- }
-
- if (m_recipients.empty() && (opt.enable_smime && !opt.prefer_smime))
- {
- m_recipients = cache->getEncryptionKeys(recps, GpgME::CMS);
- fallbackToSMIME = true;
- m_proto = GpgME::CMS;
- }
-
- if (m_recipients.empty())
+ bool resolved = false;
+ if (opt.enable_smime && opt.prefer_smime)
+ {
+ resolved = resolve_through_protocol (GpgME::CMS, m_sign, m_encrypt,
+ cached_sender, recps, m_recipients,
+ m_signer_key);
+ if (resolved)
{
- log_debug ("%s:%s: Failed to resolve keys through cache",
+ log_debug ("%s:%s: Resolved with CMS due to preference.",
SRCNAME, __func__);
- m_proto = GpgME::UnknownProtocol;
- return 1;
+ m_proto = GpgME::CMS;
}
}
-
- if (m_sign)
+ if (!resolved)
{
- if (!fallbackToSMIME)
+ resolved = resolve_through_protocol (GpgME::OpenPGP, m_sign, m_encrypt,
+ cached_sender, recps, m_recipients,
+ m_signer_key);
+ if (resolved)
{
- m_signer_key = cache->getSigningKey (m_mail->getSender ().c_str (),
- GpgME::OpenPGP);
+ log_debug ("%s:%s: Resolved with OpenPGP.",
+ SRCNAME, __func__);
m_proto = GpgME::OpenPGP;
}
- if (m_signer_key.isNull() && opt.enable_smime)
- {
- m_signer_key = cache->getSigningKey (m_mail->getSender ().c_str (),
- GpgME::CMS);
- m_proto = GpgME::CMS;
- }
- if (m_signer_key.isNull())
+ }
+ if (!resolved && (opt.enable_smime && !opt.prefer_smime))
+ {
+ resolved = resolve_through_protocol (GpgME::CMS, m_sign, m_encrypt,
+ cached_sender, recps, m_recipients,
+ m_signer_key);
+ if (resolved)
{
- log_debug ("%s:%s: Failed to resolve signer key through cache",
+ log_debug ("%s:%s: Resolved with CMS as fallback.",
SRCNAME, __func__);
- m_recipients.clear();
- m_proto = GpgME::UnknownProtocol;
- return 1;
+ m_proto = GpgME::CMS;
}
}
- log_debug ("%s:%s: Encrypting to:",
- SRCNAME, __func__);
+ if (!resolved)
+ {
+ log_debug ("%s:%s: Failed to resolve through cache",
+ SRCNAME, __func__);
+ m_recipients.clear();
+ m_signer_key = GpgME::Key();
+ m_proto = GpgME::UnknownProtocol;
+ return 1;
+ }
+
+ if (!m_recipients.empty())
+ {
+ log_debug ("%s:%s: Encrypting with protocol %s to:",
+ SRCNAME, __func__, to_cstr (m_proto));
+ }
for (const auto &key: m_recipients)
{
- log_debug ("%s", key.primaryFingerprint());
+ log_debug ("%s", key.primaryFingerprint ());
}
if (!m_signer_key.isNull())
{
- log_debug ("%s:%s: Signing key: %s",
- SRCNAME, __func__, m_signer_key.primaryFingerprint());
+ log_debug ("%s:%s: Signing key: %s:%s",
+ SRCNAME, __func__, m_signer_key.primaryFingerprint (),
+ to_cstr (m_signer_key.protocol()));
}
return 0;
}
commit 2767b0a794ae2b77331fc4305f91b767f9b4862d
Author: Andre Heinecke <aheinecke at intevation.de>
Date: Wed Aug 22 10:19:27 2018 +0200
Add helper to print out protocol
* src/cpphelp.cpp, src/cpphelp.h (to_string): New.
--
It's in cpphelp as I plan to have some more overloads of
this.
diff --git a/src/cpphelp.cpp b/src/cpphelp.cpp
index a7a57ad..6ed5ad0 100644
--- a/src/cpphelp.cpp
+++ b/src/cpphelp.cpp
@@ -292,3 +292,11 @@ is_binary (const std::string &input)
}
return false;
}
+
+const char *
+to_cstr (const GpgME::Protocol &prot)
+{
+ return prot == GpgME::CMS ? "S/MIME" :
+ prot == GpgME::OpenPGP ? "OpenPGP" :
+ "Unknown Protocol";
+}
diff --git a/src/cpphelp.h b/src/cpphelp.h
index 654ab19..0b905b1 100644
--- a/src/cpphelp.h
+++ b/src/cpphelp.h
@@ -25,6 +25,8 @@
#include <vector>
#include <map>
+#include <gpgme++/global.h>
+
/* Stuff that should be in common but is c++ so it does not fit in there. */
@@ -53,4 +55,7 @@ std::string string_to_hex (const std::string& input);
/* Check if a string contains a char < 32 */
bool is_binary (const std::string &input);
+
+/* Return a string repr of the GpgME Protocol */
+const char *to_cstr (const GpgME::Protocol &prot);
#endif // CPPHELP_H
commit cebe6484acaa250858affa3d854ef2b25cecd59f
Author: Andre Heinecke <aheinecke at intevation.de>
Date: Fri Aug 10 11:38:01 2018 +0200
Fix crash on async send in OL 2013
* src/mail.cpp, src/mail.h (Mail::
diff --git a/src/mail.cpp b/src/mail.cpp
index 4ee4314..0e8a9d2 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -73,6 +73,7 @@ static Mail *s_last_mail;
Mail::Mail (LPDISPATCH mailitem) :
m_mailitem(mailitem),
+ m_currentItemRef(nullptr),
m_processed(false),
m_needs_wipe(false),
m_needs_save(false),
@@ -201,6 +202,8 @@ Mail::~Mail()
SRCNAME, __func__);
m_parser = nullptr;
m_crypter = nullptr;
+
+ releaseCurrentItem();
gpgrt_lock_unlock (&dtor_lock);
log_oom_extra ("%s:%s: returning",
SRCNAME, __func__);
@@ -3454,3 +3457,33 @@ Mail::installFolderEventHandler_o()
/* Folder already registered */
gpgol_release (folder);
}
+
+void
+Mail::refCurrentItem()
+{
+ if (m_currentItemRef)
+ {
+ gpgol_release (m_currentItemRef);
+ }
+ /* This prevents a crash in Outlook 2013 when sending a mail as it
+ * would unload too early.
+ *
+ * As it didn't crash when the mail was opened in Outlook Spy this
+ * mimics that the mail is inspected somewhere else. */
+ m_currentItemRef = get_oom_object (m_mailitem, "GetInspector.CurrentItem");
+}
+
+void
+Mail::releaseCurrentItem()
+{
+ if (!m_currentItemRef)
+ {
+ return;
+ }
+ log_oom_extra ("%s:%s: releasing CurrentItem ref %p",
+ SRCNAME, __func__, m_currentItemRef);
+ LPDISPATCH m_tmp = m_currentItemRef;
+ m_currentItemRef = nullptr;
+ /* This can cause our destruction */
+ gpgol_release (m_tmp);
+}
diff --git a/src/mail.h b/src/mail.h
index cc4a78b..ee7fcac 100644
--- a/src/mail.h
+++ b/src/mail.h
@@ -591,12 +591,18 @@ public:
bool isAboutToBeMoved () { return m_is_about_to_be_moved; }
void setIsAboutToBeMoved (bool value) { m_is_about_to_be_moved = value; }
+ /* Releases the current item ref obtained in update oom data */
+ void releaseCurrentItem ();
+ /* Gets an additional reference for GetInspector.CurrentItem */
+ void refCurrentItem ();
+
private:
void updateCategories_o ();
void updateSigstate ();
LPDISPATCH m_mailitem;
LPDISPATCH m_event_sink;
+ LPDISPATCH m_currentItemRef;
bool m_processed, /* The message has been porcessed by us. */
m_needs_wipe, /* We have added plaintext to the mesage. */
m_needs_save, /* A property was changed but not by us. */
diff --git a/src/mailitem-events.cpp b/src/mailitem-events.cpp
index f93b239..26cbbdd 100644
--- a/src/mailitem-events.cpp
+++ b/src/mailitem-events.cpp
@@ -371,6 +371,16 @@ EVENT_SINK_INVOKE(MailItemEvents)
log_debug ("%s:%s: Send event for crypto mail %p saving and starting.",
SRCNAME, __func__, m_mail);
+ if (!m_mail->isAsyncCryptDisabled())
+ {
+ /* Obtain a reference of the current item. This prevents
+ * an early unload which would crash Outlook 2013
+ *
+ * As it didn't crash when the mail was opened in Outlook Spy this
+ * mimics that the mail is inspected somewhere else. */
+ m_mail->refCurrentItem ();
+ }
+
// First contact with a mail to encrypt update
// state and oom data.
m_mail->updateOOMData_o ();
diff --git a/src/windowmessages.cpp b/src/windowmessages.cpp
index bf252a0..afb8197 100644
--- a/src/windowmessages.cpp
+++ b/src/windowmessages.cpp
@@ -162,6 +162,7 @@ gpgol_window_proc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
invoke_oom_method (mail->item (), "Send", NULL);
log_debug ("%s:%s: Send for %p completed.",
SRCNAME, __func__, mail);
+ mail->releaseCurrentItem();
break;
}
case (BRING_TO_FRONT):
commit 75659ee29c72c78a4c44ba87ea168f06813f84cd
Author: Andre Heinecke <aheinecke at intevation.de>
Date: Fri Aug 10 10:39:02 2018 +0200
Disable super verbose debug output
* src/w32-gettext.h: Disable very verbose debug output.
diff --git a/src/w32-gettext.h b/src/w32-gettext.h
index 7232147..c450b31 100644
--- a/src/w32-gettext.h
+++ b/src/w32-gettext.h
@@ -73,7 +73,7 @@ char *native_to_utf8 (const char *string);
#define utf8_to_wchar(VAR1) ({wchar_t *retval; \
retval = _utf8_to_wchar (VAR1); \
- if ((opt.enable_debug & DBG_OOM_EXTRA)) \
+ if ((opt.enable_debug & DBG_OOM_EXTRA) && 0) \
{ \
log_debug ("%s:%s:%i wchar_t alloc %p:%S", \
SRCNAME, __func__, __LINE__, retval, retval); \
@@ -82,7 +82,7 @@ retval;})
#define wchar_to_utf8(VAR1) ({char *retval; \
retval = _wchar_to_utf8 (VAR1); \
- if ((opt.enable_debug & DBG_OOM_EXTRA)) \
+ if ((opt.enable_debug & DBG_OOM_EXTRA) && 0) \
{ \
log_debug ("%s:%s:%i char utf8 alloc %p:%s", \
SRCNAME, __func__, __LINE__, retval, retval); \
-----------------------------------------------------------------------
Summary of changes:
src/cpphelp.cpp | 8 +++
src/cpphelp.h | 5 ++
src/cryptcontroller.cpp | 127 ++++++++++++++++++++++++++++--------------------
src/mail.cpp | 33 +++++++++++++
src/mail.h | 6 +++
src/mailitem-events.cpp | 10 ++++
src/w32-gettext.h | 4 +-
src/windowmessages.cpp | 1 +
8 files changed, 138 insertions(+), 56 deletions(-)
hooks/post-receive
--
GnuPG extension for MS Outlook
http://git.gnupg.org
More information about the Gnupg-commits
mailing list