1 Return-Path: <jani@nikula.org>
\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 CCAF8431FAF
\r
6 for <notmuch@notmuchmail.org>; Tue, 22 May 2012 23:00:03 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5
\r
12 tests=[HTML_MESSAGE=0.001, 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 L8ri6PGhDFiS for <notmuch@notmuchmail.org>;
\r
16 Tue, 22 May 2012 23:00:01 -0700 (PDT)
\r
17 Received: from mail-ob0-f181.google.com (mail-ob0-f181.google.com
\r
18 [209.85.214.181]) (using TLSv1 with cipher RC4-MD5 (128/128 bits))
\r
19 (No client certificate requested)
\r
20 by olra.theworths.org (Postfix) with ESMTPS id 990EB431FBD
\r
21 for <notmuch@notmuchmail.org>; Tue, 22 May 2012 23:00:01 -0700 (PDT)
\r
22 Received: by obbuo19 with SMTP id uo19so12399326obb.26
\r
23 for <notmuch@notmuchmail.org>; Tue, 22 May 2012 23:00:00 -0700 (PDT)
\r
24 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
\r
25 d=google.com; s=20120113;
\r
26 h=mime-version:in-reply-to:references:date:message-id:subject:from:to
\r
27 :cc:content-type:x-gm-message-state;
\r
28 bh=oXwxC2xxA729NWM0BOEO0mTxIoVTBDumKLMg9DyVGVs=;
\r
29 b=abz+jm3wKi7j72VAbUOKQt+0n2PiywCN478fhMGhCx6A+6D+vSlnf06pAu8ZUYiqn3
\r
30 MFJ7PhQsEni5kLL3iorEb/ePRh/3xm4c6JxXMH6w26olsaojuFfu8eKYRFaGHx+df7km
\r
31 zfo/F4ZjGqi7gMqYFv3d6To4toRAwEtfLsKN7MZYi8G0M8fsVhxZ79cKS4xZwmMmRXeY
\r
32 Xk8UZOq0g205d0ZVOvBwe6KkoszWakiKjca+jF7cvOXAk6g7AhdmhxclVhFqPgKYrHsQ
\r
33 dCyJFzIOoS/n9FBAobwknDqeASpmzal5BYuzwEOXzelurNTXyKKO2xoFZgrV88XWtNgn
\r
36 Received: by 10.60.3.40 with SMTP id 8mr644771oez.31.1337752799886; Tue, 22
\r
37 May 2012 22:59:59 -0700 (PDT)
\r
38 Received: by 10.76.173.136 with HTTP; Tue, 22 May 2012 22:59:59 -0700 (PDT)
\r
39 Received: by 10.76.173.136 with HTTP; Tue, 22 May 2012 22:59:59 -0700 (PDT)
\r
40 In-Reply-To: <1337737430-21160-2-git-send-email-jrollins@finestructure.net>
\r
41 References: <1337737430-21160-1-git-send-email-jrollins@finestructure.net>
\r
42 <1337737430-21160-2-git-send-email-jrollins@finestructure.net>
\r
43 Date: Wed, 23 May 2012 08:59:59 +0300
\r
45 <CAB+hUn_eapb9nxC2rnyRX7czoXELX-8KeWOCFe-eDtRw0OifOw@mail.gmail.com>
\r
46 Subject: Re: [PATCH v3 1/6] cli: new crypto structure to store crypto contexts
\r
47 and parameters, and functions to support it
\r
48 From: Jani Nikula <jani@nikula.org>
\r
49 To: Jameson Graef Rollins <jrollins@finestructure.net>
\r
50 Content-Type: multipart/alternative; boundary=e89a8f83a3456f3bdb04c0add800
\r
52 ALoCoQmFHnzbqVzpgQ/ZrF8juX6v4MfDcsLCOGMjS/wFXprLNZhMomdyZHyhYy1Czqz/n+stjdlf
\r
53 Cc: Notmuch Mail <notmuch@notmuchmail.org>
\r
54 X-BeenThere: notmuch@notmuchmail.org
\r
55 X-Mailman-Version: 2.1.13
\r
57 List-Id: "Use and development of the notmuch mail system."
\r
58 <notmuch.notmuchmail.org>
\r
59 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
60 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
61 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
62 List-Post: <mailto:notmuch@notmuchmail.org>
\r
63 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
64 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
65 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
66 X-List-Received-Date: Wed, 23 May 2012 06:00:04 -0000
\r
68 --e89a8f83a3456f3bdb04c0add800
\r
69 Content-Type: text/plain; charset=UTF-8
\r
70 Content-Transfer-Encoding: quoted-printable
\r
72 On May 23, 2012 4:44 AM, "Jameson Graef Rollins" <jrollins@finestructure.ne=
\r
76 > This new structure, notmuch_crypto_t, keeps all relevant crypto
\r
77 > contexts and parameters together, and will make it easier to pass the
\r
78 > stuff around and clean it up. The name of the crypto context inside
\r
79 > this new struct will change, to reflect that it is actually a GPG
\r
80 > context, which is a sub type of Crypto context. There are other types
\r
81 > of Crypto contexts (Pkcs7 in particular, which we hope to support) so
\r
82 > we want to be clear.
\r
84 > The new crypto.c contains functions to return the proper context from
\r
85 > the struct for a given protocol (and initialize it if needed), and to
\r
86 > cleanup a struct by releasing the crypto contexts.
\r
88 > Makefile.local | 1 +
\r
90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
91 > notmuch-client.h | 15 +++++++++++++
\r
92 > 3 files changed, 81 insertions(+)
\r
93 > create mode 100644 crypto.c
\r
95 > diff --git a/Makefile.local b/Makefile.local
\r
96 > index 53b4a0d..a890df2 100644
\r
97 > --- a/Makefile.local
\r
98 > +++ b/Makefile.local
\r
99 > @@ -292,6 +292,7 @@ notmuch_client_srcs =3D \
\r
106 > notmuch_client_modules =3D $(notmuch_client_srcs:.c=3D.o)
\r
107 > diff --git a/crypto.c b/crypto.c
\r
108 > new file mode 100644
\r
109 > index 0000000..c346999
\r
113 > +/* notmuch - Not much of an email program, (just index and search)
\r
115 > + * Copyright =C2=A9 2012 Jameson Rollins
\r
117 > + * This program is free software: you can redistribute it and/or modify
\r
118 > + * it under the terms of the GNU General Public License as published by
\r
119 > + * the Free Software Foundation, either version 3 of the License, or
\r
120 > + * (at your option) any later version.
\r
122 > + * This program is distributed in the hope that it will be useful,
\r
123 > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
124 > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
125 > + * GNU General Public License for more details.
\r
127 > + * You should have received a copy of the GNU General Public License
\r
128 > + * along with this program. If not, see http://www.gnu.org/licenses/ .
\r
130 > + * Authors: Jameson Rollins <jrollins@finestructure.net>
\r
133 > +#include "notmuch-client.h"
\r
135 > +/* for the specified protocol return the context pointer (initializing
\r
136 > + * if needed) */
\r
137 > +GMimeCryptoContext *
\r
138 > +notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char
\r
141 > + GMimeCryptoContext *cryptoctx =3D NULL;
\r
143 Isn't GMimeCryptoContext gmime 2.6 specific? It's #ifdeffed elsewhere at
\r
144 least. Also affects the return type.
\r
147 > + if ((strcmp (protocol, "application/pgp-signature") =3D=3D 0)
\r
148 > + || (strcmp (protocol, "application/pgp-encrypted") =3D=3D 0)) {
\r
150 Is protocol guaranteed to be lower case?
\r
152 > + if (!crypto->gpgctx) {
\r
153 > +#ifdef GMIME_ATLEAST_26
\r
154 > + /* TODO: GMimePasswordRequestFunc */
\r
155 > + crypto->gpgctx =3D g_mime_gpg_context_new (NULL, "gpg");
\r
157 > + GMimeSession* session =3D g_object_new
\r
158 (g_mime_session_get_type(), NULL);
\r
159 > + crypto->gpgctx =3D g_mime_gpg_context_new (session, "gpg");
\r
160 > + g_object_unref (session);
\r
162 > + if (crypto->gpgctx) {
\r
163 > + g_mime_gpg_context_set_always_trust ((GMimeGpgContext*)
\r
164 crypto->gpgctx, FALSE);
\r
166 > + fprintf (stderr, "Failed to construct gpg context.\n");
\r
169 > + cryptoctx =3D crypto->gpgctx;
\r
172 > + fprintf (stderr, "Unknown or unsupported cryptographic
\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
184 > + crypto->gpgctx =3D NULL;
\r
189 > diff --git a/notmuch-client.h b/notmuch-client.h
\r
190 > index 19b7f01..14d1e2f 100644
\r
191 > --- a/notmuch-client.h
\r
192 > +++ b/notmuch-client.h
\r
193 > @@ -74,6 +74,15 @@ typedef struct notmuch_show_format {
\r
194 > const char *message_set_end;
\r
195 > } notmuch_show_format_t;
\r
197 > +typedef struct notmuch_crypto {
\r
198 > +#ifdef GMIME_ATLEAST_26
\r
199 > + GMimeCryptoContext* gpgctx;
\r
201 > + GMimeCipherContext* gpgctx;
\r
203 > + notmuch_bool_t decrypt;
\r
204 > +} notmuch_crypto_t;
\r
206 > typedef struct notmuch_show_params {
\r
207 > notmuch_bool_t entire_thread;
\r
208 > notmuch_bool_t omit_excluded;
\r
209 > @@ -113,6 +122,12 @@ chomp_newline (char *str)
\r
210 > str[strlen(str)-1] =3D '\0';
\r
213 > +GMimeCryptoContext *
\r
214 > +notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char
\r
218 > +notmuch_crypto_cleanup (notmuch_crypto_t *crypto);
\r
221 > notmuch_count_command (void *ctx, int argc, char *argv[]);
\r
226 > _______________________________________________
\r
227 > notmuch mailing list
\r
228 > notmuch@notmuchmail.org
\r
229 > http://notmuchmail.org/mailman/listinfo/notmuch
\r
231 --e89a8f83a3456f3bdb04c0add800
\r
232 Content-Type: text/html; charset=UTF-8
\r
233 Content-Transfer-Encoding: quoted-printable
\r
236 On May 23, 2012 4:44 AM, "Jameson Graef Rollins" <<a href=3D"m=
\r
237 ailto:jrollins@finestructure.net">jrollins@finestructure.net</a>> wrote:=
\r
240 > This new structure, notmuch_crypto_t, keeps all relevant crypto<br>
\r
241 > contexts and parameters together, and will make it easier to pass the<=
\r
243 > stuff around and clean it up. =C2=A0The name of the crypto context ins=
\r
245 > this new struct will change, to reflect that it is actually a GPG<br>
\r
246 > context, which is a sub type of Crypto context. =C2=A0There are other =
\r
248 > of Crypto contexts (Pkcs7 in particular, which we hope to support) so<=
\r
250 > we want to be clear.<br>
\r
252 > The new crypto.c contains functions to return the proper context from<=
\r
254 > the struct for a given protocol (and initialize it if needed), and to<=
\r
256 > cleanup a struct by releasing the crypto contexts.<br>
\r
258 > =C2=A0Makefile.local =C2=A0 | =C2=A0 =C2=A01 +<br>
\r
259 > =C2=A0crypto.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 65 +++++++++++++++=
\r
260 +++++++++++++++++++++++++++++++++++++++<br>
\r
261 > =C2=A0notmuch-client.h | =C2=A0 15 +++++++++++++<br>
\r
262 > =C2=A03 files changed, 81 insertions(+)<br>
\r
263 > =C2=A0create mode 100644 crypto.c<br>
\r
265 > diff --git a/Makefile.local b/Makefile.local<br>
\r
266 > index 53b4a0d..a890df2 100644<br>
\r
267 > --- a/Makefile.local<br>
\r
268 > +++ b/Makefile.local<br>
\r
269 > @@ -292,6 +292,7 @@ notmuch_client_srcs =3D =C2=A0 =C2=A0 =C2=A0 =C2=
\r
270 =A0 =C2=A0 =C2=A0 =C2=A0 \<br>
\r
271 > =C2=A0 =C2=A0 =C2=A0 =C2=A0notmuch-time.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
\r
273 > =C2=A0 =C2=A0 =C2=A0 =C2=A0query-string.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
\r
275 > =C2=A0 =C2=A0 =C2=A0 =C2=A0mime-node.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
\r
277 > + =C2=A0 =C2=A0 =C2=A0 crypto.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
\r
278 =A0 =C2=A0 =C2=A0\<br>
\r
279 > =C2=A0 =C2=A0 =C2=A0 =C2=A0json.c<br>
\r
281 > =C2=A0notmuch_client_modules =3D $(notmuch_client_srcs:.c=3D.o)<br>
\r
282 > diff --git a/crypto.c b/crypto.c<br>
\r
283 > new file mode 100644<br>
\r
284 > index 0000000..c346999<br>
\r
285 > --- /dev/null<br>
\r
286 > +++ b/crypto.c<br>
\r
287 > @@ -0,0 +1,65 @@<br>
\r
288 > +/* notmuch - Not much of an email program, (just index and search)<br=
\r
291 > + * Copyright =C2=A9 2012 Jameson Rollins<br>
\r
293 > + * This program is free software: you can redistribute it and/or modi=
\r
295 > + * it under the terms of the GNU General Public License as published =
\r
297 > + * the Free Software Foundation, either version 3 of the License, or<=
\r
299 > + * (at your option) any later version.<br>
\r
301 > + * This program is distributed in the hope that it will be useful,<br=
\r
303 > + * but WITHOUT ANY WARRANTY; without even the implied warranty of<br>
\r
304 > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. =C2=A0See the=
\r
306 > + * GNU General Public License for more details.<br>
\r
308 > + * You should have received a copy of the GNU General Public License<=
\r
310 > + * along with this program. =C2=A0If not, see <a href=3D"http://www.g=
\r
311 nu.org/licenses/">http://www.gnu.org/licenses/</a> .<br>
\r
313 > + * Authors: Jameson Rollins <<a href=3D"mailto:jrollins@finestruct=
\r
314 ure.net">jrollins@finestructure.net</a>><br>
\r
317 > +#include "notmuch-client.h"<br>
\r
319 > +/* for the specified protocol return the context pointer (initializin=
\r
321 > + * if needed) */<br>
\r
322 > +GMimeCryptoContext *<br>
\r
323 > +notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *pro=
\r
326 > + =C2=A0 =C2=A0GMimeCryptoContext *cryptoctx =3D NULL;</p>
\r
327 <p>Isn't GMimeCryptoContext gmime 2.6 specific? It's #ifdeffed else=
\r
328 where at least. Also affects the return type.</p>
\r
330 > + =C2=A0 =C2=A0if ((strcmp (protocol, "application/pgp-signature&=
\r
331 quot;) =3D=3D 0)<br>
\r
332 > + =C2=A0 =C2=A0 =C2=A0 || (strcmp (protocol, "application/pgp-enc=
\r
333 rypted") =3D=3D 0)) {</p>
\r
334 <p>Is protocol guaranteed to be lower case?<br></p>
\r
335 <p>> + =C2=A0 =C2=A0 =C2=A0 if (!crypto->gpgctx) {<br>
\r
336 > +#ifdef GMIME_ATLEAST_26<br>
\r
337 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* TODO: GMimePasswordRequestFunc=
\r
339 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 crypto->gpgctx =3D g_mime_gpg_=
\r
340 context_new (NULL, "gpg");<br>
\r
342 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 GMimeSession* session =3D g_objec=
\r
343 t_new (g_mime_session_get_type(), NULL);<br>
\r
344 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 crypto->gpgctx =3D g_mime_gpg_=
\r
345 context_new (session, "gpg");<br>
\r
346 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 g_object_unref (session);<br>
\r
348 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (crypto->gpgctx) {<br>
\r
349 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 g_mime_gpg_context_=
\r
350 set_always_trust ((GMimeGpgContext*) crypto->gpgctx, FALSE);<br>
\r
351 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } else {<br>
\r
352 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf (stderr, &q=
\r
353 uot;Failed to construct gpg context.\n");<br>
\r
354 > + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }<br>
\r
355 > + =C2=A0 =C2=A0 =C2=A0 }<br>
\r
356 > + =C2=A0 =C2=A0 =C2=A0 cryptoctx =3D crypto->gpgctx;<br>
\r
358 > + =C2=A0 =C2=A0} else {<br>
\r
359 > + =C2=A0 =C2=A0 =C2=A0 fprintf (stderr, "Unknown or unsupported c=
\r
360 ryptographic protocol.\n");<br>
\r
361 > + =C2=A0 =C2=A0}<br>
\r
363 > + =C2=A0 =C2=A0return cryptoctx;<br>
\r
367 > +notmuch_crypto_cleanup (notmuch_crypto_t *crypto)<br>
\r
369 > + =C2=A0 =C2=A0if (crypto->gpgctx) {<br>
\r
370 > + =C2=A0 =C2=A0 =C2=A0 g_object_unref(crypto->gpgctx);<br>
\r
371 > + =C2=A0 =C2=A0 =C2=A0 crypto->gpgctx =3D NULL;<br>
\r
372 > + =C2=A0 =C2=A0}<br>
\r
374 > + =C2=A0 =C2=A0return 0;<br>
\r
376 > diff --git a/notmuch-client.h b/notmuch-client.h<br>
\r
377 > index 19b7f01..14d1e2f 100644<br>
\r
378 > --- a/notmuch-client.h<br>
\r
379 > +++ b/notmuch-client.h<br>
\r
380 > @@ -74,6 +74,15 @@ typedef struct notmuch_show_format {<br>
\r
381 > =C2=A0 =C2=A0 const char *message_set_end;<br>
\r
382 > =C2=A0} notmuch_show_format_t;<br>
\r
384 > +typedef struct notmuch_crypto {<br>
\r
385 > +#ifdef GMIME_ATLEAST_26<br>
\r
386 > + =C2=A0 =C2=A0GMimeCryptoContext* gpgctx;<br>
\r
388 > + =C2=A0 =C2=A0GMimeCipherContext* gpgctx;<br>
\r
390 > + =C2=A0 =C2=A0notmuch_bool_t decrypt;<br>
\r
391 > +} notmuch_crypto_t;<br>
\r
393 > =C2=A0typedef struct notmuch_show_params {<br>
\r
394 > =C2=A0 =C2=A0 notmuch_bool_t entire_thread;<br>
\r
395 > =C2=A0 =C2=A0 notmuch_bool_t omit_excluded;<br>
\r
396 > @@ -113,6 +122,12 @@ chomp_newline (char *str)<br>
\r
397 > =C2=A0 =C2=A0 =C2=A0 =C2=A0str[strlen(str)-1] =3D '\0';<br>
\r
400 > +GMimeCryptoContext *<br>
\r
401 > +notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *pro=
\r
405 > +notmuch_crypto_cleanup (notmuch_crypto_t *crypto);<br>
\r
408 > =C2=A0notmuch_count_command (void *ctx, int argc, char *argv[]);<br>
\r
413 > _______________________________________________<br>
\r
414 > notmuch mailing list<br>
\r
415 > <a href=3D"mailto:notmuch@notmuchmail.org">notmuch@notmuchmail.org</a>=
\r
417 > <a href=3D"http://notmuchmail.org/mailman/listinfo/notmuch">http://not=
\r
418 muchmail.org/mailman/listinfo/notmuch</a><br>
\r
421 --e89a8f83a3456f3bdb04c0add800--
\r