From 7b41be5bf5983582d48b6bbc55b46bd12a8deaa8 Mon Sep 17 00:00:00 2001 From: Jani Nikula Date: Wed, 23 May 2012 08:59:59 +0300 Subject: [PATCH] Re: [PATCH v3 1/6] cli: new crypto structure to store crypto contexts and parameters, and functions to support it --- f6/fc9924949dd6f0a26b77f148a2c93edab4a890 | 421 ++++++++++++++++++++++ 1 file changed, 421 insertions(+) create mode 100644 f6/fc9924949dd6f0a26b77f148a2c93edab4a890 diff --git a/f6/fc9924949dd6f0a26b77f148a2c93edab4a890 b/f6/fc9924949dd6f0a26b77f148a2c93edab4a890 new file mode 100644 index 000000000..2b5cdc48a --- /dev/null +++ b/f6/fc9924949dd6f0a26b77f148a2c93edab4a890 @@ -0,0 +1,421 @@ +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 CCAF8431FAF + for ; Tue, 22 May 2012 23:00:03 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.699 +X-Spam-Level: +X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5 + tests=[HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7] 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 L8ri6PGhDFiS for ; + Tue, 22 May 2012 23:00:01 -0700 (PDT) +Received: from mail-ob0-f181.google.com (mail-ob0-f181.google.com + [209.85.214.181]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 990EB431FBD + for ; Tue, 22 May 2012 23:00:01 -0700 (PDT) +Received: by obbuo19 with SMTP id uo19so12399326obb.26 + for ; Tue, 22 May 2012 23:00:00 -0700 (PDT) +X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; + d=google.com; s=20120113; + h=mime-version:in-reply-to:references:date:message-id:subject:from:to + :cc:content-type:x-gm-message-state; + bh=oXwxC2xxA729NWM0BOEO0mTxIoVTBDumKLMg9DyVGVs=; + b=abz+jm3wKi7j72VAbUOKQt+0n2PiywCN478fhMGhCx6A+6D+vSlnf06pAu8ZUYiqn3 + MFJ7PhQsEni5kLL3iorEb/ePRh/3xm4c6JxXMH6w26olsaojuFfu8eKYRFaGHx+df7km + zfo/F4ZjGqi7gMqYFv3d6To4toRAwEtfLsKN7MZYi8G0M8fsVhxZ79cKS4xZwmMmRXeY + Xk8UZOq0g205d0ZVOvBwe6KkoszWakiKjca+jF7cvOXAk6g7AhdmhxclVhFqPgKYrHsQ + dCyJFzIOoS/n9FBAobwknDqeASpmzal5BYuzwEOXzelurNTXyKKO2xoFZgrV88XWtNgn + FQTQ== +MIME-Version: 1.0 +Received: by 10.60.3.40 with SMTP id 8mr644771oez.31.1337752799886; Tue, 22 + May 2012 22:59:59 -0700 (PDT) +Received: by 10.76.173.136 with HTTP; Tue, 22 May 2012 22:59:59 -0700 (PDT) +Received: by 10.76.173.136 with HTTP; Tue, 22 May 2012 22:59:59 -0700 (PDT) +In-Reply-To: <1337737430-21160-2-git-send-email-jrollins@finestructure.net> +References: <1337737430-21160-1-git-send-email-jrollins@finestructure.net> + <1337737430-21160-2-git-send-email-jrollins@finestructure.net> +Date: Wed, 23 May 2012 08:59:59 +0300 +Message-ID: + +Subject: Re: [PATCH v3 1/6] cli: new crypto structure to store crypto contexts + and parameters, and functions to support it +From: Jani Nikula +To: Jameson Graef Rollins +Content-Type: multipart/alternative; boundary=e89a8f83a3456f3bdb04c0add800 +X-Gm-Message-State: + ALoCoQmFHnzbqVzpgQ/ZrF8juX6v4MfDcsLCOGMjS/wFXprLNZhMomdyZHyhYy1Czqz/n+stjdlf +Cc: Notmuch Mail +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: Wed, 23 May 2012 06:00:04 -0000 + +--e89a8f83a3456f3bdb04c0add800 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: quoted-printable + +On May 23, 2012 4:44 AM, "Jameson Graef Rollins" +wrote: +> +> This new structure, notmuch_crypto_t, keeps all relevant crypto +> contexts and parameters together, and will make it easier to pass the +> stuff around and clean it up. The name of the crypto context inside +> this new struct will change, to reflect that it is actually a GPG +> context, which is a sub type of Crypto context. There are other types +> of Crypto contexts (Pkcs7 in particular, which we hope to support) so +> we want to be clear. +> +> The new crypto.c contains functions to return the proper context from +> the struct for a given protocol (and initialize it if needed), and to +> cleanup a struct by releasing the crypto contexts. +> --- +> Makefile.local | 1 + +> crypto.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ +> notmuch-client.h | 15 +++++++++++++ +> 3 files changed, 81 insertions(+) +> create mode 100644 crypto.c +> +> diff --git a/Makefile.local b/Makefile.local +> index 53b4a0d..a890df2 100644 +> --- a/Makefile.local +> +++ b/Makefile.local +> @@ -292,6 +292,7 @@ notmuch_client_srcs =3D \ +> notmuch-time.c \ +> query-string.c \ +> mime-node.c \ +> + crypto.c \ +> json.c +> +> notmuch_client_modules =3D $(notmuch_client_srcs:.c=3D.o) +> diff --git a/crypto.c b/crypto.c +> new file mode 100644 +> index 0000000..c346999 +> --- /dev/null +> +++ b/crypto.c +> @@ -0,0 +1,65 @@ +> +/* notmuch - Not much of an email program, (just index and search) +> + * +> + * Copyright =C2=A9 2012 Jameson Rollins +> + * +> + * This program is free software: you can redistribute it and/or modify +> + * it under the terms of the GNU General Public License as published by +> + * the Free Software Foundation, either version 3 of the License, or +> + * (at your option) any later version. +> + * +> + * This program is distributed in the hope that it will be useful, +> + * but WITHOUT ANY WARRANTY; without even the implied warranty of +> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +> + * GNU General Public License for more details. +> + * +> + * You should have received a copy of the GNU General Public License +> + * along with this program. If not, see http://www.gnu.org/licenses/ . +> + * +> + * Authors: Jameson Rollins +> + */ +> + +> +#include "notmuch-client.h" +> + +> +/* for the specified protocol return the context pointer (initializing +> + * if needed) */ +> +GMimeCryptoContext * +> +notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char +*protocol) +> +{ +> + GMimeCryptoContext *cryptoctx =3D NULL; + +Isn't GMimeCryptoContext gmime 2.6 specific? It's #ifdeffed elsewhere at +least. Also affects the return type. + +> + +> + if ((strcmp (protocol, "application/pgp-signature") =3D=3D 0) +> + || (strcmp (protocol, "application/pgp-encrypted") =3D=3D 0)) { + +Is protocol guaranteed to be lower case? + +> + if (!crypto->gpgctx) { +> +#ifdef GMIME_ATLEAST_26 +> + /* TODO: GMimePasswordRequestFunc */ +> + crypto->gpgctx =3D g_mime_gpg_context_new (NULL, "gpg"); +> +#else +> + GMimeSession* session =3D g_object_new +(g_mime_session_get_type(), NULL); +> + crypto->gpgctx =3D g_mime_gpg_context_new (session, "gpg"); +> + g_object_unref (session); +> +#endif +> + if (crypto->gpgctx) { +> + g_mime_gpg_context_set_always_trust ((GMimeGpgContext*) +crypto->gpgctx, FALSE); +> + } else { +> + fprintf (stderr, "Failed to construct gpg context.\n"); +> + } +> + } +> + cryptoctx =3D crypto->gpgctx; +> + +> + } else { +> + fprintf (stderr, "Unknown or unsupported cryptographic +protocol.\n"); +> + } +> + +> + return cryptoctx; +> +} +> + +> +int +> +notmuch_crypto_cleanup (notmuch_crypto_t *crypto) +> +{ +> + if (crypto->gpgctx) { +> + g_object_unref(crypto->gpgctx); +> + crypto->gpgctx =3D NULL; +> + } +> + +> + return 0; +> +} +> diff --git a/notmuch-client.h b/notmuch-client.h +> index 19b7f01..14d1e2f 100644 +> --- a/notmuch-client.h +> +++ b/notmuch-client.h +> @@ -74,6 +74,15 @@ typedef struct notmuch_show_format { +> const char *message_set_end; +> } notmuch_show_format_t; +> +> +typedef struct notmuch_crypto { +> +#ifdef GMIME_ATLEAST_26 +> + GMimeCryptoContext* gpgctx; +> +#else +> + GMimeCipherContext* gpgctx; +> +#endif +> + notmuch_bool_t decrypt; +> +} notmuch_crypto_t; +> + +> typedef struct notmuch_show_params { +> notmuch_bool_t entire_thread; +> notmuch_bool_t omit_excluded; +> @@ -113,6 +122,12 @@ chomp_newline (char *str) +> str[strlen(str)-1] =3D '\0'; +> } +> +> +GMimeCryptoContext * +> +notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char +*protocol); +> + +> +int +> +notmuch_crypto_cleanup (notmuch_crypto_t *crypto); +> + +> int +> notmuch_count_command (void *ctx, int argc, char *argv[]); +> +> -- +> 1.7.10 +> +> _______________________________________________ +> notmuch mailing list +> notmuch@notmuchmail.org +> http://notmuchmail.org/mailman/listinfo/notmuch + +--e89a8f83a3456f3bdb04c0add800 +Content-Type: text/html; charset=UTF-8 +Content-Transfer-Encoding: quoted-printable + +


+On May 23, 2012 4:44 AM, "Jameson Graef Rollins" <jrollins@finestructure.net> wrote:= +
+>
+> This new structure, notmuch_crypto_t, keeps all relevant crypto
+> contexts and parameters together, and will make it easier to pass the<= +br> +> stuff around and clean it up. =C2=A0The name of the crypto context ins= +ide
+> this new struct will change, to reflect that it is actually a GPG
+> context, which is a sub type of Crypto context. =C2=A0There are other = +types
+> of Crypto contexts (Pkcs7 in particular, which we hope to support) so<= +br> +> we want to be clear.
+>
+> The new crypto.c contains functions to return the proper context from<= +br> +> the struct for a given protocol (and initialize it if needed), and to<= +br> +> cleanup a struct by releasing the crypto contexts.
+> ---
+> =C2=A0Makefile.local =C2=A0 | =C2=A0 =C2=A01 +
+> =C2=A0crypto.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 | =C2=A0 65 +++++++++++++++= ++++++++++++++++++++++++++++++++++++++++
+> =C2=A0notmuch-client.h | =C2=A0 15 +++++++++++++
+> =C2=A03 files changed, 81 insertions(+)
+> =C2=A0create mode 100644 crypto.c
+>
+> diff --git a/Makefile.local b/Makefile.local
+> index 53b4a0d..a890df2 100644
+> --- a/Makefile.local
+> +++ b/Makefile.local
+> @@ -292,6 +292,7 @@ notmuch_client_srcs =3D =C2=A0 =C2=A0 =C2=A0 =C2= +=A0 =C2=A0 =C2=A0 =C2=A0 \
+> =C2=A0 =C2=A0 =C2=A0 =C2=A0notmuch-time.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 = +=C2=A0\
+> =C2=A0 =C2=A0 =C2=A0 =C2=A0query-string.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 = +=C2=A0\
+> =C2=A0 =C2=A0 =C2=A0 =C2=A0mime-node.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= +=A0 =C2=A0 \
+> + =C2=A0 =C2=A0 =C2=A0 crypto.c =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= +=A0 =C2=A0 =C2=A0\
+> =C2=A0 =C2=A0 =C2=A0 =C2=A0json.c
+>
+> =C2=A0notmuch_client_modules =3D $(notmuch_client_srcs:.c=3D.o)
+> diff --git a/crypto.c b/crypto.c
+> new file mode 100644
+> index 0000000..c346999
+> --- /dev/null
+> +++ b/crypto.c
+> @@ -0,0 +1,65 @@
+> +/* notmuch - Not much of an email program, (just index and search) +> + *
+> + * Copyright =C2=A9 2012 Jameson Rollins
+> + *
+> + * This program is free software: you can redistribute it and/or modi= +fy
+> + * it under the terms of the GNU General Public License as published = +by
+> + * the Free Software Foundation, either version 3 of the License, or<= +br> +> + * (at your option) any later version.
+> + *
+> + * This program is distributed in the hope that it will be useful, +> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
+> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. =C2=A0See the= +
+> + * GNU General Public License for more details.
+> + *
+> + * You should have received a copy of the GNU General Public License<= +br> +> + * along with this program. =C2=A0If not, see http://www.gnu.org/licenses/ .
+> + *
+> + * Authors: Jameson Rollins <jrollins@finestructure.net>
+> + */
+> +
+> +#include "notmuch-client.h"
+> +
+> +/* for the specified protocol return the context pointer (initializin= +g
+> + * if needed) */
+> +GMimeCryptoContext *
+> +notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *pro= +tocol)
+> +{
+> + =C2=A0 =C2=A0GMimeCryptoContext *cryptoctx =3D NULL;

+

Isn't GMimeCryptoContext gmime 2.6 specific? It's #ifdeffed else= +where at least. Also affects the return type.

+

> +
+> + =C2=A0 =C2=A0if ((strcmp (protocol, "application/pgp-signature&= +quot;) =3D=3D 0)
+> + =C2=A0 =C2=A0 =C2=A0 || (strcmp (protocol, "application/pgp-enc= +rypted") =3D=3D 0)) {

+

Is protocol guaranteed to be lower case?

+

> + =C2=A0 =C2=A0 =C2=A0 if (!crypto->gpgctx) {
+> +#ifdef GMIME_ATLEAST_26
+> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* TODO: GMimePasswordRequestFunc= + */
+> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 crypto->gpgctx =3D g_mime_gpg_= +context_new (NULL, "gpg");
+> +#else
+> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 GMimeSession* session =3D g_objec= +t_new (g_mime_session_get_type(), NULL);
+> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 crypto->gpgctx =3D g_mime_gpg_= +context_new (session, "gpg");
+> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 g_object_unref (session);
+> +#endif
+> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (crypto->gpgctx) {
+> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 g_mime_gpg_context_= +set_always_trust ((GMimeGpgContext*) crypto->gpgctx, FALSE);
+> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 } else {
+> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 fprintf (stderr, &q= +uot;Failed to construct gpg context.\n");
+> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
+> + =C2=A0 =C2=A0 =C2=A0 }
+> + =C2=A0 =C2=A0 =C2=A0 cryptoctx =3D crypto->gpgctx;
+> +
+> + =C2=A0 =C2=A0} else {
+> + =C2=A0 =C2=A0 =C2=A0 fprintf (stderr, "Unknown or unsupported c= +ryptographic protocol.\n");
+> + =C2=A0 =C2=A0}
+> +
+> + =C2=A0 =C2=A0return cryptoctx;
+> +}
+> +
+> +int
+> +notmuch_crypto_cleanup (notmuch_crypto_t *crypto)
+> +{
+> + =C2=A0 =C2=A0if (crypto->gpgctx) {
+> + =C2=A0 =C2=A0 =C2=A0 g_object_unref(crypto->gpgctx);
+> + =C2=A0 =C2=A0 =C2=A0 crypto->gpgctx =3D NULL;
+> + =C2=A0 =C2=A0}
+> +
+> + =C2=A0 =C2=A0return 0;
+> +}
+> diff --git a/notmuch-client.h b/notmuch-client.h
+> index 19b7f01..14d1e2f 100644
+> --- a/notmuch-client.h
+> +++ b/notmuch-client.h
+> @@ -74,6 +74,15 @@ typedef struct notmuch_show_format {
+> =C2=A0 =C2=A0 const char *message_set_end;
+> =C2=A0} notmuch_show_format_t;
+>
+> +typedef struct notmuch_crypto {
+> +#ifdef GMIME_ATLEAST_26
+> + =C2=A0 =C2=A0GMimeCryptoContext* gpgctx;
+> +#else
+> + =C2=A0 =C2=A0GMimeCipherContext* gpgctx;
+> +#endif
+> + =C2=A0 =C2=A0notmuch_bool_t decrypt;
+> +} notmuch_crypto_t;
+> +
+> =C2=A0typedef struct notmuch_show_params {
+> =C2=A0 =C2=A0 notmuch_bool_t entire_thread;
+> =C2=A0 =C2=A0 notmuch_bool_t omit_excluded;
+> @@ -113,6 +122,12 @@ chomp_newline (char *str)
+> =C2=A0 =C2=A0 =C2=A0 =C2=A0str[strlen(str)-1] =3D '\0';
+> =C2=A0}
+>
+> +GMimeCryptoContext *
+> +notmuch_crypto_get_context (notmuch_crypto_t *crypto, const char *pro= +tocol);
+> +
+> +int
+> +notmuch_crypto_cleanup (notmuch_crypto_t *crypto);
+> +
+> =C2=A0int
+> =C2=A0notmuch_count_command (void *ctx, int argc, char *argv[]);
+>
+> --
+> 1.7.10
+>
+> _______________________________________________
+> notmuch mailing list
+> notmuch@notmuchmail.org= +
+> http://not= +muchmail.org/mailman/listinfo/notmuch
+

+ +--e89a8f83a3456f3bdb04c0add800-- -- 2.26.2