From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
To: Notmuch Mail <notmuch@notmuchmail.org>
Subject: [PATCH 3/5] cli: write session keys to database, if asked to do so
Date: Mon, 11 Dec 2017 21:52:23 -0500 [thread overview]
Message-ID: <20171212025225.11854-4-dkg@fifthhorseman.net> (raw)
In-Reply-To: <20171212025225.11854-1-dkg@fifthhorseman.net>
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 | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/mime-node.c b/mime-node.c
index 11df082b..75b79f98 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,20 @@ 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 *sk = g_mime_decrypt_result_get_session_key (decrypt_result);
+ if (db && sk) {
+ notmuch_status_t status;
+ status = notmuch_message_add_property (message, "session-key", sk);
+ if (status)
+ fprintf (stderr, "Failed to stash session key in the database (%d) %s\n",
+ status, notmuch_status_to_string (status));
+ }
+ }
+#endif
g_object_unref (decrypt_result);
}
--
2.15.1
next prev parent reply other threads:[~2017-12-12 2:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-12 2:52 notmuch show --decrypt=stash Daniel Kahn Gillmor
2017-12-12 2:52 ` [PATCH 1/5] lib: expose notmuch_message_get_database() Daniel Kahn Gillmor
2017-12-12 2:52 ` [PATCH 2/5] properties: add notmuch_message_count_properties Daniel Kahn Gillmor
2017-12-12 4:49 ` [PATCH v2] " Daniel Kahn Gillmor
2017-12-12 2:52 ` Daniel Kahn Gillmor [this message]
2017-12-12 2:52 ` [PATCH 4/5] cli/show: reindex when we learned new session keys about a message Daniel Kahn Gillmor
2017-12-12 2:52 ` [PATCH 5/5] cli/show: enable --decrypt=stash Daniel Kahn Gillmor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171212025225.11854-4-dkg@fifthhorseman.net \
--to=dkg@fifthhorseman.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).