Re: [PATCH v4 2/7] cli: new crypto structure to store crypto contexts and parameters...
authorAustin Clements <amdragon@MIT.EDU>
Fri, 25 May 2012 14:42:08 +0000 (10:42 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:47:23 +0000 (09:47 -0800)
47/ebd1372cf28ee4a8e390e6e44841f497d6d422 [new file with mode: 0644]

diff --git a/47/ebd1372cf28ee4a8e390e6e44841f497d6d422 b/47/ebd1372cf28ee4a8e390e6e44841f497d6d422
new file mode 100644 (file)
index 0000000..b2e3bbd
--- /dev/null
@@ -0,0 +1,220 @@
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id A98E6431FBC\r
+       for <notmuch@notmuchmail.org>; Fri, 25 May 2012 07:42:11 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id C+MZ+7of9y2d for <notmuch@notmuchmail.org>;\r
+       Fri, 25 May 2012 07:42:11 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU\r
+       [18.7.68.37])\r
+       by olra.theworths.org (Postfix) with ESMTP id E08C0431FB6\r
+       for <notmuch@notmuchmail.org>; Fri, 25 May 2012 07:42:10 -0700 (PDT)\r
+X-AuditID: 12074425-b7f966d0000008b6-22-4fbf9a4118af\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+       by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id 7D.B5.02230.14A9FBF4; Fri, 25 May 2012 10:42:09 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q4PEg9un008373; \r
+       Fri, 25 May 2012 10:42:09 -0400\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q4PEg8Ia007537\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Fri, 25 May 2012 10:42:09 -0400 (EDT)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1SXviS-0000dh-91; Fri, 25 May 2012 10:42:08 -0400\r
+Date: Fri, 25 May 2012 10:42:08 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Jameson Graef Rollins <jrollins@finestructure.net>\r
+Subject: Re: [PATCH v4 2/7] cli: new crypto structure to store crypto\r
+       contexts and parameters, and functions to support it\r
+Message-ID: <20120525144208.GC11804@mit.edu>\r
+References: <1337812843-14986-1-git-send-email-jrollins@finestructure.net>\r
+       <1337812843-14986-2-git-send-email-jrollins@finestructure.net>\r
+       <1337812843-14986-3-git-send-email-jrollins@finestructure.net>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=iso-8859-1\r
+Content-Disposition: inline\r
+Content-Transfer-Encoding: 8bit\r
+In-Reply-To: <1337812843-14986-3-git-send-email-jrollins@finestructure.net>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFlrGKsWRmVeSWpSXmKPExsUixCmqres4a7+/wZo7qhZ79nlZXL85k9mB\r
+       yePuaS6PZ6tuMQcwRXHZpKTmZJalFunbJXBlzFpzlrHguVrF5xt9rA2M6+S6GDk5JARMJBaf\r
+       +MoCYYtJXLi3nq2LkYtDSGAfo8SKJytZIZwNjBK9SxczQTgnmSRmPL7JDOEsYZRoP7GcHaSf\r
+       RUBV4sjSrWCz2AQ0JLbtX84IYosImEn0fPkDZjMLaEls3fgBzBYWqJFYefI9WD2vgI7E6ZY3\r
+       UBvOMEqcXH6JHSIhKHFy5hMWiGYdiZ1b7wAdyAFkS0ss/8cBEZaXaN46mxkkzCngLbHqvjNI\r
+       WFRARWLKyW1sExiFZyEZNAvJoFkIg2YhGbSAkWUVo2xKbpVubmJmTnFqsm5xcmJeXmqRroVe\r
+       bmaJXmpK6SZGUBSwu6juYJxwSOkQowAHoxIPL1P0Pn8h1sSy4srcQ4ySHExKorwhM/f7C/El\r
+       5adUZiQWZ8QXleakFh9ilOBgVhLhZUkDyvGmJFZWpRblw6SkOViUxHnXae72FxJITyxJzU5N\r
+       LUgtgsnKcHAoSfBOAhkqWJSanlqRlplTgpBm4uAEGc4DNHwqSA1vcUFibnFmOkT+FKMux/4f\r
+       E68zCrHk5eelSonzhoIUCYAUZZTmwc2BJa9XjOJAbwnzRoFU8QATH9ykV0BLmICWbHm8F2RJ\r
+       SSJCSqqB0W/F0tNJr8uiJ61mPvLz3dP3/l/b7e68+OrfKLLSv/nRXE8epvQVn1K03a/HRD10\r
+       ncXFvJLnTd1XuZ8vGe/3W0lkxC/6aX6uUlZXf6PiJH+FNQs8D6+S41rGraircNT+rU7XdbXb\r
+       Ba5v9JmNNi1YZXLSXMDzF2/1HclZzIt50+2c9D6rXj/2W4mlOCPRUIu5qDgRAEM36KQ5AwAA\r
+Cc: Notmuch Mail <notmuch@notmuchmail.org>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 25 May 2012 14:42:11 -0000\r
+\r
+Quoth Jameson Graef Rollins on May 23 at  3:40 pm:\r
+> This new structure, notmuch_crypto_t, keeps all relevant crypto\r
+> contexts and parameters together, and will make it easier to pass the\r
+> stuff around and clean it up.  The name of the crypto context inside\r
+> this new struct will change, to reflect that it is actually a GPG\r
+> context, which is a sub type of Crypto context.  There are other types\r
+> of Crypto contexts (Pkcs7 in particular, which we hope to support) so\r
+> we want to be clear.\r
+> \r
+> The new crypto.c contains functions to return the proper context from\r
+> the struct for a given protocol (and initialize it if needed), and to\r
+> cleanup a struct by releasing the crypto contexts.\r
+> ---\r
+>  Makefile.local   |    1 +\r
+>  crypto.c         |   71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+>  notmuch-client.h |   11 +++++++++\r
+>  3 files changed, 83 insertions(+)\r
+>  create mode 100644 crypto.c\r
+> \r
+> diff --git a/Makefile.local b/Makefile.local\r
+> index 53b4a0d..a890df2 100644\r
+> --- a/Makefile.local\r
+> +++ b/Makefile.local\r
+> @@ -292,6 +292,7 @@ notmuch_client_srcs =            \\r
+>      notmuch-time.c          \\r
+>      query-string.c          \\r
+>      mime-node.c             \\r
+> +    crypto.c                \\r
+>      json.c\r
+>  \r
+>  notmuch_client_modules = $(notmuch_client_srcs:.c=.o)\r
+> diff --git a/crypto.c b/crypto.c\r
+> new file mode 100644\r
+> index 0000000..25c2d10\r
+> --- /dev/null\r
+> +++ b/crypto.c\r
+> @@ -0,0 +1,71 @@\r
+> +/* notmuch - Not much of an email program, (just index and search)\r
+> + *\r
+> + * Copyright © 2012 Jameson Rollins\r
+> + *\r
+> + * This program is free software: you can redistribute it and/or modify\r
+> + * it under the terms of the GNU General Public License as published by\r
+> + * the Free Software Foundation, either version 3 of the License, or\r
+> + * (at your option) any later version.\r
+> + *\r
+> + * This program is distributed in the hope that it will be useful,\r
+> + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+> + * GNU General Public License for more details.\r
+> + *\r
+> + * You should have received a copy of the GNU General Public License\r
+> + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
+> + *\r
+> + * Authors: Jameson Rollins <jrollins@finestructure.net>\r
+> + */\r
+> +\r
+> +#include "notmuch-client.h"\r
+> +\r
+> +/* for the specified protocol return the context pointer (initializing\r
+> + * if needed) */\r
+> +GMimeCryptoContext *\r
+> +notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol)\r
+> +{\r
+> +    GMimeCryptoContext *cryptoctx = NULL;\r
+> +\r
+> +    /* As per RFC 1847 section 2.1: "the [protocol] value token is\r
+> +     * comprised of the type and sub-type tokens of the Content-Type".\r
+> +     * As per RFC 1521 section 2: "Content-Type values, subtypes, and\r
+> +     * parameter names as defined in this document are\r
+> +     * case-insensitive."  Thus, we use strcasecmp for the protocol.\r
+> +     */\r
+> +    if ((strcasecmp (protocol, "application/pgp-signature") == 0)\r
+> +    || (strcasecmp (protocol, "application/pgp-encrypted") == 0)) {\r
+> +    if (!crypto->gpgctx) {\r
+> +#ifdef GMIME_ATLEAST_26\r
+> +        /* TODO: GMimePasswordRequestFunc */\r
+> +        crypto->gpgctx = g_mime_gpg_context_new (NULL, "gpg");\r
+> +#else\r
+> +        GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);\r
+> +        crypto->gpgctx = g_mime_gpg_context_new (session, "gpg");\r
+> +        g_object_unref (session);\r
+> +#endif\r
+> +        if (crypto->gpgctx) {\r
+> +            g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) crypto->gpgctx, FALSE);\r
+> +        } else {\r
+> +            fprintf (stderr, "Failed to construct gpg context.\n");\r
+> +        }\r
+> +    }\r
+> +    cryptoctx = crypto->gpgctx;\r
+> +\r
+> +    } else {\r
+> +    fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n");\r
+> +    }\r
+> +\r
+> +    return cryptoctx;\r
+> +}\r
+> +\r
+> +int\r
+> +notmuch_crypto_cleanup (notmuch_crypto_t *crypto)\r
+> +{\r
+> +    if (crypto->gpgctx) {\r
+> +    g_object_unref(crypto->gpgctx);\r
+\r
+Missing space.\r
+\r
+> +    crypto->gpgctx = NULL;\r
+> +    }\r
+> +\r
+> +    return 0;\r
+> +}\r
+> diff --git a/notmuch-client.h b/notmuch-client.h\r
+> index 337409f..a8b00ab 100644\r
+> --- a/notmuch-client.h\r
+> +++ b/notmuch-client.h\r
+> @@ -76,6 +76,11 @@ typedef struct notmuch_show_format {\r
+>      const char *message_set_end;\r
+>  } notmuch_show_format_t;\r
+>  \r
+> +typedef struct notmuch_crypto {\r
+> +    GMimeCryptoContext* gpgctx;\r
+> +    notmuch_bool_t decrypt;\r
+> +} notmuch_crypto_t;\r
+> +\r
+>  typedef struct notmuch_show_params {\r
+>      notmuch_bool_t entire_thread;\r
+>      notmuch_bool_t omit_excluded;\r
+> @@ -111,6 +116,12 @@ chomp_newline (char *str)\r
+>      str[strlen(str)-1] = '\0';\r
+>  }\r
+>  \r
+> +GMimeCryptoContext *\r
+> +notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol);\r
+> +\r
+> +int\r
+> +notmuch_crypto_cleanup (notmuch_crypto_t *crypto);\r
+> +\r
+>  int\r
+>  notmuch_count_command (void *ctx, int argc, char *argv[]);\r
+>  \r