Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 9DAD2431FD6 for ; Fri, 29 Jun 2012 11:38:30 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.3 X-Spam-Level: X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_MED=-2.3] 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 4szEgKtnTe2V for ; Fri, 29 Jun 2012 11:38:30 -0700 (PDT) Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu [131.215.239.19]) by olra.theworths.org (Postfix) with ESMTP id 0DFAE431FCF for ; Fri, 29 Jun 2012 11:38:30 -0700 (PDT) Received: from earth-doxen.imss.caltech.edu (localhost [127.0.0.1]) by earth-doxen-postvirus (Postfix) with ESMTP id C1FB866E030A for ; Fri, 29 Jun 2012 11:38:27 -0700 (PDT) X-Spam-Scanned: at Caltech-IMSS on earth-doxen by amavisd-new Received: from finestructure.net (gwave-70.ligo.caltech.edu [131.215.114.70]) (Authenticated sender: jrollins) by earth-doxen-submit (Postfix) with ESMTP id F1E4466E0306 for ; Fri, 29 Jun 2012 11:38:25 -0700 (PDT) Received: by finestructure.net (Postfix, from userid 1000) id D50D62E97; Fri, 29 Jun 2012 11:38:25 -0700 (PDT) From: Jameson Graef Rollins To: Notmuch Mail Subject: [PATCH 1/2] cli: S/MIME verification/decryption support Date: Fri, 29 Jun 2012 11:38:20 -0700 Message-Id: <1340995101-9616-2-git-send-email-jrollins@finestructure.net> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1340995101-9616-1-git-send-email-jrollins@finestructure.net> References: <1340995101-9616-1-git-send-email-jrollins@finestructure.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: Fri, 29 Jun 2012 18:38:31 -0000 The notmuch-show flags --decrypt and --verify will now also process S/MIME multiparts if encountered. Requires gmime-2.6 and gpgsm. --- crypto.c | 21 +++++++++++++++++++++ notmuch-client.h | 5 +++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/crypto.c b/crypto.c index fbe5aeb..551ffc5 100644 --- a/crypto.c +++ b/crypto.c @@ -52,6 +52,22 @@ notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol) } 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"); } @@ -67,5 +83,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 9b63eae..72edd50 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -79,6 +79,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; @@ -353,8 +354,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: * -- 1.7.10