crypto: record whether an actual decryption attempt happened
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Fri, 8 Dec 2017 06:23:58 +0000 (01:23 -0500)
committerDavid Bremner <david@tethera.net>
Fri, 8 Dec 2017 12:08:46 +0000 (08:08 -0400)
In our consolidation of _notmuch_crypto_decrypt, the callers lost
track a little bit of whether any actual decryption was attempted.

Now that we have the more-subtle "auto" policy, it's possible that
_notmuch_crypto_decrypt could be called without having any actual
decryption take place.

This change lets the callers be a little bit smarter about whether or
not any decryption was actually attempted.

lib/index.cc
mime-node.c
util/crypto.c
util/crypto.h

index af999bd306cf4def9121c39fb83b18d5c60a718d..3914012afddc1a25832e180ec6e3cae2be467483 100644 (file)
@@ -548,12 +548,19 @@ _index_encrypted_mime_part (notmuch_message_t *message,
        }
     }
 #endif
-    clear = _notmuch_crypto_decrypt (notmuch_indexopts_get_decrypt_policy (indexopts),
+    bool attempted = false;
+    clear = _notmuch_crypto_decrypt (&attempted, notmuch_indexopts_get_decrypt_policy (indexopts),
                                     message, crypto_ctx, encrypted_data, NULL, &err);
-    if (err) {
-       _notmuch_database_log (notmuch, "Failed to decrypt during indexing. (%d:%d) [%s]\n",
-                              err->domain, err->code, err->message);
-       g_error_free(err);
+    if (!attempted)
+       return;
+    if (err || !clear) {
+       if (err) {
+           _notmuch_database_log (notmuch, "Failed to decrypt during indexing. (%d:%d) [%s]\n",
+                                  err->domain, err->code, err->message);
+           g_error_free(err);
+       } else {
+           _notmuch_database_log (notmuch, "Failed to decrypt during indexing. (unknown error)\n");
+       }
        /* Indicate that we failed to decrypt during indexing */
        status = notmuch_message_add_property (message, "index.decryption", "failure");
        if (status)
index 49d668fee812272a96f1152753b4db6b249188b0..11df082b86cd03520d17fbf5ff9ae5e547878af5 100644 (file)
@@ -204,8 +204,8 @@ node_decrypt_and_verify (mime_node_t *node, GMimeObject *part,
            if (parent->envelope_file)
                break;
 
-       node->decrypt_attempted = true;
-       node->decrypted_child = _notmuch_crypto_decrypt (node->ctx->crypto->decrypt,
+       node->decrypted_child = _notmuch_crypto_decrypt (&node->decrypt_attempted,
+                                                        node->ctx->crypto->decrypt,
                                                         parent ? parent->envelope_file : NULL,
                                                         cryptoctx, encrypteddata, &decrypt_result, &err);
     }
index bb587571879320f6370b320cf6e2083e2187503c..338f1d5d85e5a4b9b273488dcac4b1770c301749 100644 (file)
@@ -140,7 +140,8 @@ void _notmuch_crypto_cleanup (unused(_notmuch_crypto_t *crypto))
 #endif
 
 GMimeObject *
-_notmuch_crypto_decrypt (notmuch_decryption_policy_t decrypt,
+_notmuch_crypto_decrypt (bool *attempted,
+                        notmuch_decryption_policy_t decrypt,
                         notmuch_message_t *message,
                         g_mime_3_unused(GMimeCryptoContext* crypto_ctx),
                         GMimeMultipartEncrypted *part,
@@ -162,6 +163,8 @@ _notmuch_crypto_decrypt (notmuch_decryption_policy_t decrypt,
                g_error_free (*err);
                *err = NULL;
            }
+           if (attempted)
+               *attempted = true;
 #if (GMIME_MAJOR_VERSION < 3)
            ret = g_mime_multipart_encrypted_decrypt_session (part,
                                                              crypto_ctx,
@@ -191,6 +194,8 @@ _notmuch_crypto_decrypt (notmuch_decryption_policy_t decrypt,
     if (decrypt == NOTMUCH_DECRYPT_AUTO)
        return ret;
 
+    if (attempted)
+       *attempted = true;
 #if (GMIME_MAJOR_VERSION < 3)
     ret = g_mime_multipart_encrypted_decrypt(part, crypto_ctx,
                                             decrypt_result, err);
index dc95b4cadda7329d0d4041820a11af3ffd3a44e4..c384601c11d35772a727c55996f4c3180076481e 100644 (file)
@@ -16,7 +16,8 @@ typedef struct _notmuch_crypto {
 } _notmuch_crypto_t;
 
 GMimeObject *
-_notmuch_crypto_decrypt (notmuch_decryption_policy_t decrypt,
+_notmuch_crypto_decrypt (bool *attempted,
+                        notmuch_decryption_policy_t decrypt,
                         notmuch_message_t *message,
                         GMimeCryptoContext* crypto_ctx,
                         GMimeMultipartEncrypted *part,