[PATCH v3 1/6] cli: new crypto structure to store crypto contexts and parameters...
authorJameson Graef Rollins <jrollins@finestructure.net>
Wed, 23 May 2012 01:43:45 +0000 (18:43 +1700)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:47:15 +0000 (09:47 -0800)
ae/a6706f8b35dec2399cf052b533c68de6bd3194 [new file with mode: 0644]

diff --git a/ae/a6706f8b35dec2399cf052b533c68de6bd3194 b/ae/a6706f8b35dec2399cf052b533c68de6bd3194
new file mode 100644 (file)
index 0000000..9f26b91
--- /dev/null
@@ -0,0 +1,192 @@
+Return-Path: <jrollins@finestructure.net>\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 406EA431FAF\r
+       for <notmuch@notmuchmail.org>; Tue, 22 May 2012 18:44:03 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_MED=-2.3] 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 jKvW75XhdbAu for <notmuch@notmuchmail.org>;\r
+       Tue, 22 May 2012 18:44:01 -0700 (PDT)\r
+Received: from outgoing-mail.its.caltech.edu (outgoing-mail.its.caltech.edu\r
+       [131.215.239.19])\r
+       by olra.theworths.org (Postfix) with ESMTP id B9D3A431FC3\r
+       for <notmuch@notmuchmail.org>; Tue, 22 May 2012 18:43:58 -0700 (PDT)\r
+Received: from fire-doxen.imss.caltech.edu (localhost [127.0.0.1])\r
+       by fire-doxen-postvirus (Postfix) with ESMTP id 8EE13328044\r
+       for <notmuch@notmuchmail.org>; Tue, 22 May 2012 18:43:57 -0700 (PDT)\r
+X-Spam-Scanned: at Caltech-IMSS on fire-doxen by amavisd-new\r
+Received: from finestructure.net (gwave-125.ligo.caltech.edu\r
+ [131.215.114.125])    (Authenticated sender: jrollins)        by fire-doxen-submit\r
+ (Postfix) with ESMTP id 4FFFB2E506F3  for <notmuch@notmuchmail.org>; Tue, 22\r
+ May 2012 18:43:54 -0700 (PDT)\r
+Received: by finestructure.net (Postfix, from userid 1000)\r
+       id 32C605D; Tue, 22 May 2012 18:43:54 -0700 (PDT)\r
+From: Jameson Graef Rollins <jrollins@finestructure.net>\r
+To: Notmuch Mail <notmuch@notmuchmail.org>\r
+Subject: [PATCH v3 1/6] cli: new crypto structure to store crypto contexts and parameters, and functions to support it\r
+Date: Tue, 22 May 2012 18:43:45 -0700\r
+Message-Id: <1337737430-21160-2-git-send-email-jrollins@finestructure.net>\r
+X-Mailer: git-send-email 1.7.10\r
+In-Reply-To: <1337737430-21160-1-git-send-email-jrollins@finestructure.net>\r
+References: <1337737430-21160-1-git-send-email-jrollins@finestructure.net>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=UTF-8\r
+Content-Transfer-Encoding: 8bit\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: Wed, 23 May 2012 01:44:03 -0000\r
+\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         |   65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ notmuch-client.h |   15 +++++++++++++\r
+ 3 files changed, 81 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..c346999\r
+--- /dev/null\r
++++ b/crypto.c\r
+@@ -0,0 +1,65 @@\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
++    if ((strcmp (protocol, "application/pgp-signature") == 0)\r
++      || (strcmp (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
++      crypto->gpgctx = NULL;\r
++    }\r
++\r
++    return 0;\r
++}\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index 19b7f01..14d1e2f 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -74,6 +74,15 @@ typedef struct notmuch_show_format {\r
+     const char *message_set_end;\r
+ } notmuch_show_format_t;\r
\r
++typedef struct notmuch_crypto {\r
++#ifdef GMIME_ATLEAST_26\r
++    GMimeCryptoContext* gpgctx;\r
++#else\r
++    GMimeCipherContext* gpgctx;\r
++#endif\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
+@@ -113,6 +122,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
+-- \r
+1.7.10\r
+\r