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 9E6B56DE0AD0 for ; Thu, 10 May 2018 23:58:12 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.018 X-Spam-Level: X-Spam-Status: No, score=-0.018 tagged_above=-999 required=5 tests=[AWL=-0.018, RCVD_IN_DNSWL_NONE=-0.0001] 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 HIo3wVIKbGk3 for ; Thu, 10 May 2018 23:58:12 -0700 (PDT) Received: from che.mayfirst.org (che.mayfirst.org [162.247.75.118]) by arlo.cworth.org (Postfix) with ESMTPS id 44D686DE023C for ; Thu, 10 May 2018 23:58:10 -0700 (PDT) Received: from fifthhorseman.net (unknown [38.109.115.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by che.mayfirst.org (Postfix) with ESMTPSA id 7BF4FF99F for ; Fri, 11 May 2018 02:58:08 -0400 (EDT) Received: by fifthhorseman.net (Postfix, from userid 1000) id 70A9220EE6; Fri, 11 May 2018 02:58:03 -0400 (EDT) From: Daniel Kahn Gillmor To: Notmuch Mail Subject: [PATCH v3 5/8] cli: write session keys to database, if asked to do so Date: Fri, 11 May 2018 02:57:56 -0400 Message-Id: <20180511065759.8556-6-dkg@fifthhorseman.net> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180511065759.8556-1-dkg@fifthhorseman.net> References: <20180511065759.8556-1-dkg@fifthhorseman.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.26 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: Fri, 11 May 2018 06:58:12 -0000 If the decryption policy is NOTMUCH_DECRYPT_TRUE, that means we want to stash session keys in the database. Note that there is currently no way from the command line to set it this way, though, so it is not yet included in the test suite. --- mime-node.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/mime-node.c b/mime-node.c index 11df082b..2a24e537 100644 --- a/mime-node.c +++ b/mime-node.c @@ -197,16 +197,18 @@ node_decrypt_and_verify (mime_node_t *node, GMimeObject *part, GError *err = NULL; GMimeDecryptResult *decrypt_result = NULL; GMimeMultipartEncrypted *encrypteddata = GMIME_MULTIPART_ENCRYPTED (part); + notmuch_message_t *message = NULL; if (! node->decrypted_child) { - mime_node_t *parent; - for (parent = node; parent; parent = parent->parent) - if (parent->envelope_file) + for (mime_node_t *parent = node; parent; parent = parent->parent) + if (parent->envelope_file) { + message = parent->envelope_file; break; + } node->decrypted_child = _notmuch_crypto_decrypt (&node->decrypt_attempted, node->ctx->crypto->decrypt, - parent ? parent->envelope_file : NULL, + message, cryptoctx, encrypteddata, &decrypt_result, &err); } if (! node->decrypted_child) { @@ -225,6 +227,18 @@ node_decrypt_and_verify (mime_node_t *node, GMimeObject *part, g_object_ref (node->sig_list); set_signature_list_destructor (node); } + +#if HAVE_GMIME_SESSION_KEYS + if (node->ctx->crypto->decrypt == NOTMUCH_DECRYPT_TRUE && message) { + notmuch_database_t *db = notmuch_message_get_database (message); + const char *session_key = g_mime_decrypt_result_get_session_key (decrypt_result); + if (db && session_key) + print_status_message ("Failed to stash session key in the database", + message, + notmuch_message_add_property (message, "session-key", + session_key)); + } +#endif g_object_unref (decrypt_result); } -- 2.17.0