1 Return-Path: <amdragon@mit.edu>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id A98E6431FBC
\r
6 for <notmuch@notmuchmail.org>; Fri, 25 May 2012 07:42:11 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id C+MZ+7of9y2d for <notmuch@notmuchmail.org>;
\r
16 Fri, 25 May 2012 07:42:11 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id E08C0431FB6
\r
20 for <notmuch@notmuchmail.org>; Fri, 25 May 2012 07:42:10 -0700 (PDT)
\r
21 X-AuditID: 12074425-b7f966d0000008b6-22-4fbf9a4118af
\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])
\r
23 by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 7D.B5.02230.14A9FBF4; Fri, 25 May 2012 10:42:09 -0400 (EDT)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q4PEg9un008373;
\r
27 Fri, 25 May 2012 10:42:09 -0400
\r
28 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])
\r
29 (authenticated bits=0)
\r
30 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
31 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q4PEg8Ia007537
\r
32 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
33 Fri, 25 May 2012 10:42:09 -0400 (EDT)
\r
34 Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)
\r
35 (envelope-from <amdragon@mit.edu>)
\r
36 id 1SXviS-0000dh-91; Fri, 25 May 2012 10:42:08 -0400
\r
37 Date: Fri, 25 May 2012 10:42:08 -0400
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: Jameson Graef Rollins <jrollins@finestructure.net>
\r
40 Subject: Re: [PATCH v4 2/7] cli: new crypto structure to store crypto
\r
41 contexts and parameters, and functions to support it
\r
42 Message-ID: <20120525144208.GC11804@mit.edu>
\r
43 References: <1337812843-14986-1-git-send-email-jrollins@finestructure.net>
\r
44 <1337812843-14986-2-git-send-email-jrollins@finestructure.net>
\r
45 <1337812843-14986-3-git-send-email-jrollins@finestructure.net>
\r
47 Content-Type: text/plain; charset=iso-8859-1
\r
48 Content-Disposition: inline
\r
49 Content-Transfer-Encoding: 8bit
\r
50 In-Reply-To: <1337812843-14986-3-git-send-email-jrollins@finestructure.net>
\r
51 User-Agent: Mutt/1.5.21 (2010-09-15)
\r
52 X-Brightmail-Tracker:
\r
53 H4sIAAAAAAAAA+NgFlrGKsWRmVeSWpSXmKPExsUixCmqres4a7+/wZo7qhZ79nlZXL85k9mB
\r
54 yePuaS6PZ6tuMQcwRXHZpKTmZJalFunbJXBlzFpzlrHguVrF5xt9rA2M6+S6GDk5JARMJBaf
\r
55 +MoCYYtJXLi3nq2LkYtDSGAfo8SKJytZIZwNjBK9SxczQTgnmSRmPL7JDOEsYZRoP7GcHaSf
\r
56 RUBV4sjSrWCz2AQ0JLbtX84IYosImEn0fPkDZjMLaEls3fgBzBYWqJFYefI9WD2vgI7E6ZY3
\r
57 UBvOMEqcXH6JHSIhKHFy5hMWiGYdiZ1b7wAdyAFkS0ss/8cBEZaXaN46mxkkzCngLbHqvjNI
\r
58 WFRARWLKyW1sExiFZyEZNAvJoFkIg2YhGbSAkWUVo2xKbpVubmJmTnFqsm5xcmJeXmqRroVe
\r
59 bmaJXmpK6SZGUBSwu6juYJxwSOkQowAHoxIPL1P0Pn8h1sSy4srcQ4ySHExKorwhM/f7C/El
\r
60 5adUZiQWZ8QXleakFh9ilOBgVhLhZUkDyvGmJFZWpRblw6SkOViUxHnXae72FxJITyxJzU5N
\r
61 LUgtgsnKcHAoSfBOAhkqWJSanlqRlplTgpBm4uAEGc4DNHwqSA1vcUFibnFmOkT+FKMux/4f
\r
62 E68zCrHk5eelSonzhoIUCYAUZZTmwc2BJa9XjOJAbwnzRoFU8QATH9ykV0BLmICWbHm8F2RJ
\r
63 SSJCSqqB0W/F0tNJr8uiJ61mPvLz3dP3/l/b7e68+OrfKLLSv/nRXE8epvQVn1K03a/HRD10
\r
64 ncXFvJLnTd1XuZ8vGe/3W0lkxC/6aX6uUlZXf6PiJH+FNQs8D6+S41rGraircNT+rU7XdbXb
\r
65 Ba5v9JmNNi1YZXLSXMDzF2/1HclZzIt50+2c9D6rXj/2W4mlOCPRUIu5qDgRAEM36KQ5AwAA
\r
66 Cc: Notmuch Mail <notmuch@notmuchmail.org>
\r
67 X-BeenThere: notmuch@notmuchmail.org
\r
68 X-Mailman-Version: 2.1.13
\r
70 List-Id: "Use and development of the notmuch mail system."
\r
71 <notmuch.notmuchmail.org>
\r
72 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
73 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
74 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
75 List-Post: <mailto:notmuch@notmuchmail.org>
\r
76 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
77 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
78 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
79 X-List-Received-Date: Fri, 25 May 2012 14:42:11 -0000
\r
81 Quoth Jameson Graef Rollins on May 23 at 3:40 pm:
\r
82 > This new structure, notmuch_crypto_t, keeps all relevant crypto
\r
83 > contexts and parameters together, and will make it easier to pass the
\r
84 > stuff around and clean it up. The name of the crypto context inside
\r
85 > this new struct will change, to reflect that it is actually a GPG
\r
86 > context, which is a sub type of Crypto context. There are other types
\r
87 > of Crypto contexts (Pkcs7 in particular, which we hope to support) so
\r
88 > we want to be clear.
\r
90 > The new crypto.c contains functions to return the proper context from
\r
91 > the struct for a given protocol (and initialize it if needed), and to
\r
92 > cleanup a struct by releasing the crypto contexts.
\r
94 > Makefile.local | 1 +
\r
95 > crypto.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
96 > notmuch-client.h | 11 +++++++++
\r
97 > 3 files changed, 83 insertions(+)
\r
98 > create mode 100644 crypto.c
\r
100 > diff --git a/Makefile.local b/Makefile.local
\r
101 > index 53b4a0d..a890df2 100644
\r
102 > --- a/Makefile.local
\r
103 > +++ b/Makefile.local
\r
104 > @@ -292,6 +292,7 @@ notmuch_client_srcs = \
\r
111 > notmuch_client_modules = $(notmuch_client_srcs:.c=.o)
\r
112 > diff --git a/crypto.c b/crypto.c
\r
113 > new file mode 100644
\r
114 > index 0000000..25c2d10
\r
118 > +/* notmuch - Not much of an email program, (just index and search)
\r
120 > + * Copyright © 2012 Jameson Rollins
\r
122 > + * This program is free software: you can redistribute it and/or modify
\r
123 > + * it under the terms of the GNU General Public License as published by
\r
124 > + * the Free Software Foundation, either version 3 of the License, or
\r
125 > + * (at your option) any later version.
\r
127 > + * This program is distributed in the hope that it will be useful,
\r
128 > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
129 > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
130 > + * GNU General Public License for more details.
\r
132 > + * You should have received a copy of the GNU General Public License
\r
133 > + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
135 > + * Authors: Jameson Rollins <jrollins@finestructure.net>
\r
138 > +#include "notmuch-client.h"
\r
140 > +/* for the specified protocol return the context pointer (initializing
\r
141 > + * if needed) */
\r
142 > +GMimeCryptoContext *
\r
143 > +notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol)
\r
145 > + GMimeCryptoContext *cryptoctx = NULL;
\r
147 > + /* As per RFC 1847 section 2.1: "the [protocol] value token is
\r
148 > + * comprised of the type and sub-type tokens of the Content-Type".
\r
149 > + * As per RFC 1521 section 2: "Content-Type values, subtypes, and
\r
150 > + * parameter names as defined in this document are
\r
151 > + * case-insensitive." Thus, we use strcasecmp for the protocol.
\r
153 > + if ((strcasecmp (protocol, "application/pgp-signature") == 0)
\r
154 > + || (strcasecmp (protocol, "application/pgp-encrypted") == 0)) {
\r
155 > + if (!crypto->gpgctx) {
\r
156 > +#ifdef GMIME_ATLEAST_26
\r
157 > + /* TODO: GMimePasswordRequestFunc */
\r
158 > + crypto->gpgctx = g_mime_gpg_context_new (NULL, "gpg");
\r
160 > + GMimeSession* session = g_object_new (g_mime_session_get_type(), NULL);
\r
161 > + crypto->gpgctx = g_mime_gpg_context_new (session, "gpg");
\r
162 > + g_object_unref (session);
\r
164 > + if (crypto->gpgctx) {
\r
165 > + g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) crypto->gpgctx, FALSE);
\r
167 > + fprintf (stderr, "Failed to construct gpg context.\n");
\r
170 > + cryptoctx = crypto->gpgctx;
\r
173 > + fprintf (stderr, "Unknown or unsupported cryptographic protocol.\n");
\r
176 > + return cryptoctx;
\r
180 > +notmuch_crypto_cleanup (notmuch_crypto_t *crypto)
\r
182 > + if (crypto->gpgctx) {
\r
183 > + g_object_unref(crypto->gpgctx);
\r
187 > + crypto->gpgctx = NULL;
\r
192 > diff --git a/notmuch-client.h b/notmuch-client.h
\r
193 > index 337409f..a8b00ab 100644
\r
194 > --- a/notmuch-client.h
\r
195 > +++ b/notmuch-client.h
\r
196 > @@ -76,6 +76,11 @@ typedef struct notmuch_show_format {
\r
197 > const char *message_set_end;
\r
198 > } notmuch_show_format_t;
\r
200 > +typedef struct notmuch_crypto {
\r
201 > + GMimeCryptoContext* gpgctx;
\r
202 > + notmuch_bool_t decrypt;
\r
203 > +} notmuch_crypto_t;
\r
205 > typedef struct notmuch_show_params {
\r
206 > notmuch_bool_t entire_thread;
\r
207 > notmuch_bool_t omit_excluded;
\r
208 > @@ -111,6 +116,12 @@ chomp_newline (char *str)
\r
209 > str[strlen(str)-1] = '\0';
\r
212 > +GMimeCryptoContext *
\r
213 > +notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *protocol);
\r
216 > +notmuch_crypto_cleanup (notmuch_crypto_t *crypto);
\r
219 > notmuch_count_command (void *ctx, int argc, char *argv[]);
\r