From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 573616DE0C45 for ; Tue, 24 Oct 2017 23:52:23 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.037 X-Spam-Level: X-Spam-Status: No, score=-0.037 tagged_above=-999 required=5 tests=[AWL=-0.037] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3Q4sjmtIRWVa for ; Tue, 24 Oct 2017 23:52:21 -0700 (PDT) Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118]) by arlo.cworth.org (Postfix) with ESMTP id 444816DE0C97 for ; Tue, 24 Oct 2017 23:52:13 -0700 (PDT) Received: from fifthhorseman.net (unknown [38.109.115.130]) by che.mayfirst.org (Postfix) with ESMTPSA id 8140FF9A8 for ; Wed, 25 Oct 2017 02:52:12 -0400 (EDT) Received: by fifthhorseman.net (Postfix, from userid 1000) id F2EFF2160B; Wed, 25 Oct 2017 02:52:06 -0400 (EDT) From: Daniel Kahn Gillmor To: Notmuch Mail Subject: [PATCH 12/18] crypto: record whether an actual decryption attempt happened Date: Wed, 25 Oct 2017 02:51:57 -0400 Message-Id: <20171025065203.24403-13-dkg@fifthhorseman.net> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171025065203.24403-1-dkg@fifthhorseman.net> References: <20171025065203.24403-1-dkg@fifthhorseman.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 25 Oct 2017 06:52:23 -0000 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 | 17 ++++++++++++----- mime-node.c | 4 ++-- util/crypto.c | 7 ++++++- util/crypto.h | 3 ++- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/lib/index.cc b/lib/index.cc index d9a0018c..e2701755 100644 --- a/lib/index.cc +++ b/lib/index.cc @@ -548,12 +548,19 @@ _index_encrypted_mime_part (notmuch_message_t *message, } } #endif - clear = _notmuch_crypto_decrypt (notmuch_indexopts_get_try_decrypt (indexopts), + bool attempted = false; + clear = _notmuch_crypto_decrypt (&attempted, notmuch_indexopts_get_try_decrypt (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) diff --git a/mime-node.c b/mime-node.c index 815c1787..6d3d5f69 100644 --- a/mime-node.c +++ b/mime-node.c @@ -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); } diff --git a/util/crypto.c b/util/crypto.c index 9789f203..ae6b94be 100644 --- a/util/crypto.c +++ b/util/crypto.c @@ -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, @@ -158,6 +159,8 @@ _notmuch_crypto_decrypt (notmuch_decryption_policy_t decrypt, for (list = notmuch_message_get_properties (message, "session-key", TRUE); notmuch_message_properties_valid (list); notmuch_message_properties_move_to_next (list)) { + if (attempted) + *attempted = true; #if (GMIME_MAJOR_VERSION < 3) ret = g_mime_multipart_encrypted_decrypt_session (part, crypto_ctx, @@ -182,6 +185,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); diff --git a/util/crypto.h b/util/crypto.h index dc95b4ca..c384601c 100644 --- a/util/crypto.h +++ b/util/crypto.h @@ -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, -- 2.14.2