2012-05-26 20:45:41 +02:00
|
|
|
/* notmuch - Not much of an email program, (just index and search)
|
|
|
|
*
|
|
|
|
* Copyright © 2012 Jameson Rollins
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2016-06-02 18:26:14 +02:00
|
|
|
* along with this program. If not, see https://www.gnu.org/licenses/ .
|
2012-05-26 20:45:41 +02:00
|
|
|
*
|
|
|
|
* Authors: Jameson Rollins <jrollins@finestructure.net>
|
|
|
|
*/
|
|
|
|
|
2017-10-17 21:09:55 +02:00
|
|
|
#include "crypto.h"
|
|
|
|
#include <strings.h>
|
|
|
|
#define unused(x) x __attribute__ ((unused))
|
|
|
|
|
|
|
|
#define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))
|
|
|
|
|
2017-10-10 07:49:04 +02:00
|
|
|
void _notmuch_crypto_cleanup (unused(_notmuch_crypto_t *crypto))
|
2017-07-16 01:01:45 +02:00
|
|
|
{
|
|
|
|
}
|
2017-11-30 09:59:27 +01:00
|
|
|
|
|
|
|
GMimeObject *
|
2017-12-08 07:23:58 +01:00
|
|
|
_notmuch_crypto_decrypt (bool *attempted,
|
|
|
|
notmuch_decryption_policy_t decrypt,
|
2017-12-08 07:23:53 +01:00
|
|
|
notmuch_message_t *message,
|
2017-11-30 09:59:27 +01:00
|
|
|
GMimeMultipartEncrypted *part,
|
|
|
|
GMimeDecryptResult **decrypt_result,
|
|
|
|
GError **err)
|
|
|
|
{
|
|
|
|
GMimeObject *ret = NULL;
|
2017-12-08 07:23:53 +01:00
|
|
|
if (decrypt == NOTMUCH_DECRYPT_FALSE)
|
|
|
|
return NULL;
|
2017-11-30 09:59:27 +01:00
|
|
|
|
2017-11-30 09:59:29 +01:00
|
|
|
/* the versions of notmuch that can support session key decryption */
|
|
|
|
if (message) {
|
|
|
|
notmuch_message_properties_t *list = NULL;
|
|
|
|
|
|
|
|
for (list = notmuch_message_get_properties (message, "session-key", TRUE);
|
|
|
|
notmuch_message_properties_valid (list); notmuch_message_properties_move_to_next (list)) {
|
|
|
|
if (err && *err) {
|
|
|
|
g_error_free (*err);
|
|
|
|
*err = NULL;
|
|
|
|
}
|
2017-12-08 07:23:58 +01:00
|
|
|
if (attempted)
|
|
|
|
*attempted = true;
|
2017-11-30 09:59:29 +01:00
|
|
|
ret = g_mime_multipart_encrypted_decrypt (part,
|
|
|
|
GMIME_DECRYPT_NONE,
|
|
|
|
notmuch_message_properties_value (list),
|
|
|
|
decrypt_result, err);
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (list)
|
|
|
|
notmuch_message_properties_destroy (list);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err && *err) {
|
|
|
|
g_error_free (*err);
|
|
|
|
*err = NULL;
|
|
|
|
}
|
2017-12-08 07:23:53 +01:00
|
|
|
|
|
|
|
if (decrypt == NOTMUCH_DECRYPT_AUTO)
|
|
|
|
return ret;
|
|
|
|
|
2017-12-08 07:23:58 +01:00
|
|
|
if (attempted)
|
|
|
|
*attempted = true;
|
2017-12-08 07:24:01 +01:00
|
|
|
GMimeDecryptFlags flags = GMIME_DECRYPT_NONE;
|
2017-12-08 07:24:02 +01:00
|
|
|
if (decrypt == NOTMUCH_DECRYPT_TRUE && decrypt_result)
|
2017-12-08 07:24:01 +01:00
|
|
|
flags |= GMIME_DECRYPT_EXPORT_SESSION_KEY;
|
|
|
|
ret = g_mime_multipart_encrypted_decrypt(part, flags, NULL,
|
2017-11-30 09:59:27 +01:00
|
|
|
decrypt_result, err);
|
|
|
|
return ret;
|
|
|
|
}
|