]> granicus.if.org Git - neomutt/commitdiff
Disable message security if the backend is not available.
authorKevin McCarthy <kevin@8t8.us>
Sun, 31 Dec 2017 03:10:16 +0000 (19:10 -0800)
committerRichard Russon <rich@flatcap.org>
Fri, 5 Jan 2018 00:43:41 +0000 (00:43 +0000)
Gitlab issue #3 exposed an awkward corner case: if mutt is configured
without PGP or S/MIME, and with GPGME, but $crypt_use_gpgme is unset.
In this case, no backend will be available, but WithCrypto will be set
with both APPLICATION_PGP and APPLICATION_SMIME bits.

That will allow various config vars to enable encryption or signing,
even though there will be no backend available to perform them.  The
message security flag might then be set, but when the user hits send,
will end up back at the compose menu due to the error.

The pgp or smime menu might not even be available to clear the
security setting!

Add a check in send.c before the compose menu is invoked, and give a
warning message for the menu ops inside the compose menu.

I believe this should prevent the issue.  However this is a corner
case combined with user misconfiguration, so I don't believe is worth
a large effort to completely eradicate.

compose.c
ncrypt/cryptglue.c
ncrypt/ncrypt.h
send.c

index 3f0ae74ce0fb4c6a7bc19309f90363b284f711aa..d113791aa6b19f0b9c3b7355c20d28164c0e7e40 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -1604,6 +1604,11 @@ int mutt_compose_menu(struct Header *msg, /* structure for new message */
       case OP_COMPOSE_PGP_MENU:
         if (!(WithCrypto & APPLICATION_PGP))
           break;
+        if (!crypt_has_module_backend(APPLICATION_PGP))
+        {
+          mutt_error(_("No PGP backend configured"));
+          break;
+        }
         if ((WithCrypto & APPLICATION_SMIME) && (msg->security & APPLICATION_SMIME))
         {
           if (msg->security & (ENCRYPT | SIGN))
@@ -1633,6 +1638,11 @@ int mutt_compose_menu(struct Header *msg, /* structure for new message */
       case OP_COMPOSE_SMIME_MENU:
         if (!(WithCrypto & APPLICATION_SMIME))
           break;
+        if (!crypt_has_module_backend(APPLICATION_SMIME))
+        {
+          mutt_error(_("No S/MIME backend configured"));
+          break;
+        }
 
         if ((WithCrypto & APPLICATION_PGP) && (msg->security & APPLICATION_PGP))
         {
index 854c64fc8be6d0d634a22a5129c52285abc57988..caab8414400d847c595802ba54afeea2be8ddb0d 100644 (file)
@@ -126,6 +126,24 @@ void crypt_invoke_message(int type)
     mutt_message(_("Invoking S/MIME..."));
 }
 
+/* Returns 1 if a module backend is registered for the type */
+int crypt_has_module_backend(int type)
+{
+  if ((WithCrypto & APPLICATION_PGP) && (type & APPLICATION_PGP) &&
+      crypto_module_lookup(APPLICATION_PGP))
+  {
+    return 1;
+  }
+
+  if ((WithCrypto & APPLICATION_SMIME) && (type & APPLICATION_SMIME) &&
+      crypto_module_lookup(APPLICATION_SMIME))
+  {
+    return 1;
+  }
+
+  return 0;
+}
+
 /*
  * PGP
  */
index 2815811af82ca9521ad61f89885f9e2daff24d13..d30a90445b8769c8c7c04ec89bc6aa87c7643fd6 100644 (file)
@@ -137,4 +137,7 @@ int crypt_smime_verify_sender(struct Header *h);
 int crypt_smime_send_menu(struct Header *msg);
 void crypt_init(void);
 
+/* Returns 1 if a module backend is registered for the type */
+int crypt_has_module_backend(int type);
+
 #endif /* _NCRYPT_NCRYPT_H */
diff --git a/send.c b/send.c
index dd66c73328e03fbe2a80d9654815cdc5521ca24c..0e09eaaf4083fa16ffd38cae5cf06589f7bf4775 100644 (file)
--- a/send.c
+++ b/send.c
@@ -1771,6 +1771,18 @@ int ci_send_message(int flags, struct Header *msg, char *tempfile,
       msg->security = 0;
   }
 
+  /* Deal with the corner case where the crypto module backend is not available.
+   * This can happen if configured without pgp/smime and with gpgme, but
+   * $crypt_use_gpgme is unset.
+   */
+  if (msg->security && !crypt_has_module_backend(msg->security))
+  {
+    mutt_error(_(
+        "No crypto backend configured.  Disabling message security setting."));
+    mutt_sleep(1);
+    msg->security = 0;
+  }
+
   /* specify a default fcc.  if we are in batchmode, only save a copy of
    * the message if the value of $copy is yes or ask-yes */