From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id D4488429E35 for ; Sat, 17 Jan 2015 02:52:38 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 2.438 X-Spam-Level: ** X-Spam-Status: No, score=2.438 tagged_above=-999 required=5 tests=[DNS_FROM_AHBL_RHSBL=2.438] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id x1WBvNBePwsv for ; Sat, 17 Jan 2015 02:52:36 -0800 (PST) Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id A939B429E37 for ; Sat, 17 Jan 2015 02:52:21 -0800 (PST) Received: from remotemail by yantan.tethera.net with local (Exim 4.80) (envelope-from ) id 1YCQzN-0006C9-8y; Sat, 17 Jan 2015 06:52:21 -0400 Received: (nullmailer pid 14752 invoked by uid 1000); Sat, 17 Jan 2015 10:51:54 -0000 From: David Bremner To: Jameson Graef Rollins , Notmuch Mail Subject: [PATCH 2/4] cli: S/MIME verification/decryption support Date: Sat, 17 Jan 2015 11:51:44 +0100 Message-Id: <1421491906-14542-3-git-send-email-david@tethera.net> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1421491906-14542-1-git-send-email-david@tethera.net> References: <1395031944-15557-1-git-send-email-jrollins@finestructure.net> <1421491906-14542-1-git-send-email-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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: Sat, 17 Jan 2015 10:52:39 -0000 From: Jameson Graef Rollins The notmuch-show flags --decrypt and --verify will now also process S/MIME multiparts if encountered. Requires gmime-2.6 and gpgsm. --- crypto.c | 20 ++++++++++++++++++++ notmuch-client.h | 5 +++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/crypto.c b/crypto.c index 6f4a6db..d66aa66 100644 --- a/crypto.c +++ b/crypto.c @@ -88,6 +88,21 @@ notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol) fprintf (stderr, "Failed to construct gpg context.\n"); } cryptoctx = crypto->gpgctx; +#ifdef GMIME_ATLEAST_26 + } else if ((strcasecmp (protocol, "application/pkcs7-signature") == 0) + || (strcasecmp (protocol, "application/x-pkcs7-signature") == 0) + || (strcasecmp (protocol, "application/pkcs7-encrypted") == 0)) { + if (! crypto->pkcs7ctx) { + /* TODO: GMimePasswordRequestFunc */ + crypto->pkcs7ctx = g_mime_pkcs7_context_new (NULL); + if (crypto->pkcs7ctx) { + g_mime_pkcs7_context_set_always_trust ((GMimePkcs7Context*) crypto->pkcs7ctx, FALSE); + } else { + fprintf (stderr, "Failed to construct pkcs7 context.\n"); + } + } + cryptoctx = crypto->pkcs7ctx; +#endif } else { fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n"); } @@ -103,5 +118,10 @@ notmuch_crypto_cleanup (notmuch_crypto_t *crypto) crypto->gpgctx = NULL; } + if (crypto->pkcs7ctx) { + g_object_unref (crypto->pkcs7ctx); + crypto->pkcs7ctx = NULL; + } + return 0; } diff --git a/notmuch-client.h b/notmuch-client.h index 5e0d475..986f6cd 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -78,6 +78,7 @@ typedef struct notmuch_show_format { typedef struct notmuch_crypto { notmuch_crypto_context_t* gpgctx; + notmuch_crypto_context_t* pkcs7ctx; notmuch_bool_t verify; notmuch_bool_t decrypt; } notmuch_crypto_t; @@ -414,8 +415,8 @@ struct mime_node { /* Construct a new MIME node pointing to the root message part of * message. If crypto->verify is true, signed child parts will be * verified. If crypto->decrypt is true, encrypted child parts will be - * decrypted. If crypto->gpgctx is NULL, it will be lazily - * initialized. + * decrypted. If the crypto contexts (crypto->gpgctx or + * crypto->pkcs7) are NULL, they will be lazily initialized. * * Return value: * -- 2.1.4