diff options
author | Daniel Kahn Gillmor <dkg@fifthhorseman.net> | 2018-05-11 02:57:56 -0400 |
---|---|---|
committer | David Bremner <david@tethera.net> | 2018-05-26 07:33:01 -0700 |
commit | bc842bfff12998a9b1a30b880cf8c6612f727d45 (patch) | |
tree | 812d3a5bfb58a5bb39b14a4a216f2046be2504d4 /mime-node.c | |
parent | f32e52448b8665dbf335fd97a21b49108e05a6c0 (diff) |
cli: write session keys to database, if asked to do so
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.
Diffstat (limited to 'mime-node.c')
-rw-r--r-- | mime-node.c | 22 |
1 files 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); } |