aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2001-04-13 01:14:20 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2001-04-13 01:14:20 +0800
commit769f404db36aa9082ac153c2935f1b7bfe1d3527 (patch)
treea7b9d5c5442df7ecb8dc0a40cb62dab2eddadfe6 /mail
parentfabdba6f1ca3ada8be27a81bdc069bdb8270e1c3 (diff)
downloadgsoc2013-evolution-769f404db36aa9082ac153c2935f1b7bfe1d3527.tar
gsoc2013-evolution-769f404db36aa9082ac153c2935f1b7bfe1d3527.tar.gz
gsoc2013-evolution-769f404db36aa9082ac153c2935f1b7bfe1d3527.tar.bz2
gsoc2013-evolution-769f404db36aa9082ac153c2935f1b7bfe1d3527.tar.lz
gsoc2013-evolution-769f404db36aa9082ac153c2935f1b7bfe1d3527.tar.xz
gsoc2013-evolution-769f404db36aa9082ac153c2935f1b7bfe1d3527.tar.zst
gsoc2013-evolution-769f404db36aa9082ac153c2935f1b7bfe1d3527.zip
Updated for changes to PGP code.
2001-04-12 Jeffrey Stedfast <fejj@ximian.com> * mail-accounts.c (pgp_path_changed): Updated for changes to PGP code. * component-factory.c (owner_set_cb): Don't init openpgp anymore because we don't need it. * mail-crypto.c: Simply wrap the camel-pgp-mime functions (also renamed the functions to be prefixed with mail_crypto). * mail-format.c (handle_multipart_signed): Update to use camel_pgp_mime_is_rfc2015_signed() and other camel-pgp-mime functions. (handle_multipart_encrypted): Same but for rfc2015_encrypted. (decode_pgp): Updated to use camel-pgp-context (try_inline_pgp): Updated to use camel-pgp-context's. (try_inline_pgp_sig): Same. svn path=/trunk/; revision=9269
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog19
-rw-r--r--mail/Makefile.am2
-rw-r--r--mail/component-factory.c3
-rw-r--r--mail/mail-accounts.c10
-rw-r--r--mail/mail-crypto.c448
-rw-r--r--mail/mail-crypto.h27
-rw-r--r--mail/mail-format.c101
7 files changed, 131 insertions, 479 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 1b9d91bd21..f492ba39a8 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,22 @@
+2001-04-12 Jeffrey Stedfast <fejj@ximian.com>
+
+ * mail-accounts.c (pgp_path_changed): Updated for changes to PGP
+ code.
+
+ * component-factory.c (owner_set_cb): Don't init openpgp anymore
+ because we don't need it.
+
+ * mail-crypto.c: Simply wrap the camel-pgp-mime functions (also
+ renamed the functions to be prefixed with mail_crypto).
+
+ * mail-format.c (handle_multipart_signed): Update to use
+ camel_pgp_mime_is_rfc2015_signed() and other camel-pgp-mime
+ functions.
+ (handle_multipart_encrypted): Same but for rfc2015_encrypted.
+ (decode_pgp): Updated to use camel-pgp-context
+ (try_inline_pgp): Updated to use camel-pgp-context's.
+ (try_inline_pgp_sig): Same.
+
2001-04-11 Dan Winship <danw@ximian.com>
* mail-format.c (handle_text_plain): Only look for special
diff --git a/mail/Makefile.am b/mail/Makefile.am
index 4d967545e9..0d7a94fb53 100644
--- a/mail/Makefile.am
+++ b/mail/Makefile.am
@@ -96,8 +96,6 @@ evolution_mail_SOURCES = \
main.c \
message-list.c \
message-list.h \
- openpgp-utils.c \
- openpgp-utils.h \
session.c \
mail-session.h \
subscribe-dialog.c \
diff --git a/mail/component-factory.c b/mail/component-factory.c
index bd9b701e48..239611bd6a 100644
--- a/mail/component-factory.c
+++ b/mail/component-factory.c
@@ -45,7 +45,6 @@
#include "mail-mt.h"
#include "mail-importer.h"
#include "mail-vfolder.h" /* vfolder_create_storage */
-#include "openpgp-utils.h"
#include "component-factory.h"
@@ -210,8 +209,6 @@ owner_set_cb (EvolutionShellComponent *shell_component,
mail_config_init ();
- openpgp_init (mail_config_get_pgp_path (), mail_config_get_pgp_type ());
-
storages_hash = g_hash_table_new (NULL, NULL);
vfolder_create_storage (shell_component);
diff --git a/mail/mail-accounts.c b/mail/mail-accounts.c
index ab0ccbe5e9..09e1903cba 100644
--- a/mail/mail-accounts.c
+++ b/mail/mail-accounts.c
@@ -29,7 +29,7 @@
#include <string.h>
#include <libgnomeui/gnome-stock.h>
#include <camel/camel-url.h>
-#include <openpgp-utils.h>
+#include <camel/camel-pgp-context.h>
#include "mail-accounts.h"
#include "mail-config.h"
@@ -492,18 +492,18 @@ static void
pgp_path_changed (GtkEntry *entry, gpointer data)
{
const char *path, *bin;
- PgpType type = PGP_TYPE_NONE;
+ CamelPgpType type = CAMEL_PGP_TYPE_NONE;
path = gtk_entry_get_text (entry);
bin = g_basename (path);
/* FIXME: This detection should be better */
if (!strcmp (bin, "pgp"))
- type = PGP_TYPE_PGP2;
+ type = CAMEL_PGP_TYPE_PGP2;
else if (!strcmp (bin, "pgpv") || !strcmp (bin, "pgpe") || !strcmp (bin, "pgpk") || !strcmp (bin, "pgps"))
- type = PGP_TYPE_PGP5;
+ type = CAMEL_PGP_TYPE_PGP5;
else if (!strcmp (bin, "gpg"))
- type = PGP_TYPE_GPG;
+ type = CAMEL_PGP_TYPE_GPG;
mail_config_set_pgp_path (path && *path ? path : NULL);
mail_config_set_pgp_type (type);
diff --git a/mail/mail-crypto.c b/mail/mail-crypto.c
index 51a64cc09d..e77893c4af 100644
--- a/mail/mail-crypto.c
+++ b/mail/mail-crypto.c
@@ -27,105 +27,9 @@
#include <stdlib.h>
#include <string.h>
-#include <camel/camel-mime-filter-from.h>
-
#include "mail-crypto.h"
#include "mail-session.h"
-
-
-/** rfc2015 stuff (aka PGP/MIME) *******************************/
-
-gboolean
-mail_crypto_is_rfc2015_signed (CamelMimePart *mime_part)
-{
- CamelDataWrapper *wrapper;
- CamelMultipart *mp;
- CamelMimePart *part;
- CamelContentType *type;
- const gchar *param, *micalg;
- int nparts;
-
- /* check that we have a multipart/signed */
- type = camel_mime_part_get_content_type (mime_part);
- if (!header_content_type_is (type, "multipart", "signed"))
- return FALSE;
-
- /* check that we have a protocol param with the value: "application/pgp-signed" */
- param = header_content_type_param (type, "protocol");
- if (!param || g_strcasecmp (param, "application/pgp-signature"))
- return FALSE;
-
- /* check that we have a micalg parameter */
- micalg = header_content_type_param (type, "micalg");
- if (!micalg)
- return FALSE;
-
- /* check that we have exactly 2 subparts */
- wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (mime_part));
- mp = CAMEL_MULTIPART (wrapper);
- nparts = camel_multipart_get_number (mp);
- if (nparts != 2)
- return FALSE;
-
- /* The first part may be of any type except for
- * application/pgp-signature - check it. */
- part = camel_multipart_get_part (mp, 0);
- type = camel_mime_part_get_content_type (part);
- if (header_content_type_is (type, "application", "pgp-signature"))
- return FALSE;
-
- /* The second part should be application/pgp-signature. */
- part = camel_multipart_get_part (mp, 1);
- type = camel_mime_part_get_content_type (part);
- if (!header_content_type_is (type, "application", "pgp-signature"))
- return FALSE;
-
- return TRUE;
-}
-
-gboolean
-mail_crypto_is_rfc2015_encrypted (CamelMimePart *mime_part)
-{
- CamelDataWrapper *wrapper;
- CamelMultipart *mp;
- CamelMimePart *part;
- CamelContentType *type;
- const gchar *param;
- int nparts;
-
- /* check that we have a multipart/encrypted */
- type = camel_mime_part_get_content_type (mime_part);
- if (!header_content_type_is (type, "multipart", "encrypted"))
- return FALSE;
-
- /* check that we have a protocol param with the value: "application/pgp-encrypted" */
- param = header_content_type_param (type, "protocol");
- if (!param || g_strcasecmp (param, "application/pgp-encrypted"))
- return FALSE;
-
- /* check that we have at least 2 subparts */
- wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (mime_part));
- mp = CAMEL_MULTIPART (wrapper);
- nparts = camel_multipart_get_number (mp);
- if (nparts < 2)
- return FALSE;
-
- /* The first part should be application/pgp-encrypted */
- part = camel_multipart_get_part (mp, 0);
- type = camel_mime_part_get_content_type (part);
- if (!header_content_type_is (type, "application", "pgp-encrypted"))
- return FALSE;
-
- /* The second part should be application/octet-stream - this
- is the one we care most about */
- part = camel_multipart_get_part (mp, 1);
- type = camel_mime_part_get_content_type (part);
- if (!header_content_type_is (type, "application", "octet-stream"))
- return FALSE;
-
- return TRUE;
-}
-
+#include "mail-config.h"
/** rfc2633 stuff (aka S/MIME v3) ********************************/
@@ -216,68 +120,9 @@ mail_crypto_is_pkcs7_mime (CamelMimePart *mime_part)
return FALSE;
}
-static void
-pgp_mime_part_sign_restore_part (CamelMimePart *mime_part, GSList *encodings)
-{
- CamelDataWrapper *wrapper;
-
- wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (mime_part));
- if (!wrapper)
- return;
-
- if (CAMEL_IS_MULTIPART (wrapper)) {
- int parts, i;
-
- parts = camel_multipart_get_number (CAMEL_MULTIPART (wrapper));
- for (i = 0; i < parts; i++) {
- CamelMimePart *part = camel_multipart_get_part (CAMEL_MULTIPART (wrapper), i);
-
- pgp_mime_part_sign_restore_part (part, encodings);
- encodings = encodings->next;
- }
- } else {
- CamelMimePartEncodingType encoding;
-
- encoding = GPOINTER_TO_INT (encodings->data);
-
- camel_mime_part_set_encoding (mime_part, encoding);
- }
-}
-
-static void
-pgp_mime_part_sign_prepare_part (CamelMimePart *mime_part, GSList **encodings)
-{
- CamelDataWrapper *wrapper;
- int parts, i;
-
- wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (mime_part));
- if (!wrapper)
- return;
-
- if (CAMEL_IS_MULTIPART (wrapper)) {
- parts = camel_multipart_get_number (CAMEL_MULTIPART (wrapper));
- for (i = 0; i < parts; i++) {
- CamelMimePart *part = camel_multipart_get_part (CAMEL_MULTIPART (wrapper), i);
-
- pgp_mime_part_sign_prepare_part (part, encodings);
- }
- } else {
- CamelMimePartEncodingType encoding;
-
- encoding = camel_mime_part_get_encoding (mime_part);
-
- /* FIXME: find the best encoding for this part and use that instead?? */
- /* the encoding should really be QP or Base64 */
- if (encoding != CAMEL_MIME_PART_ENCODING_BASE64)
- camel_mime_part_set_encoding (mime_part, CAMEL_MIME_PART_ENCODING_QUOTEDPRINTABLE);
-
- *encodings = g_slist_append (*encodings, GINT_TO_POINTER (encoding));
- }
-}
-
/**
- * pgp_mime_part_sign:
+ * mail_crypto_pgp_mime_part_sign:
* @mime_part: a MIME part that will be replaced by a pgp signed part
* @userid: userid to sign with
* @hash: one of PGP_HASH_TYPE_MD5 or PGP_HASH_TYPE_SHA1
@@ -288,166 +133,41 @@ pgp_mime_part_sign_prepare_part (CamelMimePart *mime_part, GSList **encodings)
* #ex will be set and #part will remain untouched.
**/
void
-pgp_mime_part_sign (CamelMimePart **mime_part, const gchar *userid, PgpHashType hash, CamelException *ex)
+mail_crypto_pgp_mime_part_sign (CamelMimePart **mime_part, const char *userid, CamelPgpHashType hash, CamelException *ex)
{
- CamelMimePart *part, *signed_part;
- CamelMultipart *multipart;
- CamelContentType *mime_type;
- CamelStreamFilter *filtered_stream;
- CamelMimeFilter *crlf_filter, *from_filter;
- CamelStream *stream;
- GByteArray *content;
- gchar *signature;
- gchar *hash_type = NULL;
- GSList *encodings = NULL;
-
- g_return_if_fail (*mime_part != NULL);
- g_return_if_fail (CAMEL_IS_MIME_PART (*mime_part));
- g_return_if_fail (userid != NULL);
- g_return_if_fail (hash != PGP_HASH_TYPE_NONE);
-
- part = *mime_part;
-
- /* Prepare all the parts for signing... */
- pgp_mime_part_sign_prepare_part (part, &encodings);
-
- /* get the cleartext */
- content = g_byte_array_new ();
- stream = camel_stream_mem_new ();
- camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (stream), content);
- crlf_filter = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_ENCODE,
- CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY);
- from_filter = CAMEL_MIME_FILTER (camel_mime_filter_from_new ());
- filtered_stream = camel_stream_filter_new_with_stream (stream);
- camel_stream_filter_add (filtered_stream, CAMEL_MIME_FILTER (crlf_filter));
- camel_object_unref (CAMEL_OBJECT (crlf_filter));
- camel_stream_filter_add (filtered_stream, CAMEL_MIME_FILTER (from_filter));
- camel_object_unref (CAMEL_OBJECT (from_filter));
- camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (part), CAMEL_STREAM (filtered_stream));
- camel_object_unref (CAMEL_OBJECT (filtered_stream));
- camel_object_unref (CAMEL_OBJECT (stream));
-
- /* get the signature */
- signature = openpgp_sign (content->data, content->len, userid, hash, ex);
- g_byte_array_free (content, TRUE);
- if (camel_exception_is_set (ex)) {
- /* restore the original encoding */
- pgp_mime_part_sign_restore_part (part, encodings);
- g_slist_free (encodings);
- return;
- }
-
- /* we don't need these anymore... */
- g_slist_free (encodings);
+ CamelPgpContext *context;
- /* construct the pgp-signature mime part */
- fprintf (stderr, "signature:\n%s\n", signature);
- signed_part = camel_mime_part_new ();
- camel_mime_part_set_content (signed_part, signature, strlen (signature),
- "application/pgp-signature");
- g_free (signature);
-
- /* construct the container multipart/signed */
- switch (hash) {
- case PGP_HASH_TYPE_MD5:
- hash_type = "pgp-md5";
- break;
- case PGP_HASH_TYPE_SHA1:
- hash_type = "pgp-sha1";
- break;
- default:
- g_assert_not_reached ();
- }
-
- multipart = camel_multipart_new ();
-
- mime_type = header_content_type_new ("multipart", "signed");
- header_content_type_set_param (mime_type, "micalg", hash_type);
- header_content_type_set_param (mime_type, "protocol", "application/pgp-signature");
- camel_data_wrapper_set_mime_type_field (CAMEL_DATA_WRAPPER (multipart), mime_type);
- header_content_type_unref (mime_type);
-
- camel_multipart_set_boundary (multipart, NULL);
-
- /* add the parts to the multipart */
- camel_multipart_add_part (multipart, part);
- camel_object_unref (CAMEL_OBJECT (part));
- camel_multipart_add_part (multipart, signed_part);
- camel_object_unref (CAMEL_OBJECT (signed_part));
-
- /* replace the input part with the output part */
- *mime_part = camel_mime_part_new ();
- camel_medium_set_content_object (CAMEL_MEDIUM (*mime_part),
- CAMEL_DATA_WRAPPER (multipart));
- camel_object_unref (CAMEL_OBJECT (multipart));
+ context = camel_pgp_context_new (session, mail_config_get_pgp_type (),
+ mail_config_get_pgp_path ());
+ camel_pgp_mime_part_sign (context, mime_part, userid, hash, ex);
+ camel_object_unref (CAMEL_OBJECT (context));
}
/**
- * pgp_mime_part_verify:
+ * mail_crypto_pgp_mime_part_verify:
* @mime_part: a multipart/signed MIME Part
* @ex: exception
*
* Returns a PgpValidity on success or NULL on fail.
**/
-PgpValidity *
-pgp_mime_part_verify (CamelMimePart *mime_part, CamelException *ex)
+CamelPgpValidity *
+mail_crypto_pgp_mime_part_verify (CamelMimePart *mime_part, CamelException *ex)
{
- CamelDataWrapper *wrapper;
- CamelMultipart *multipart;
- CamelMimePart *part, *sigpart;
- CamelStreamFilter *filtered_stream;
- CamelMimeFilter *crlf_filter, *from_filter;
- CamelStream *stream;
- GByteArray *content, *signature;
- PgpValidity *valid;
-
- g_return_val_if_fail (mime_part != NULL, NULL);
- g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), NULL);
+ CamelPgpContext *context;
+ CamelPgpValidity *valid;
- if (!mail_crypto_is_rfc2015_signed (mime_part))
- return NULL;
-
- wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (mime_part));
- multipart = CAMEL_MULTIPART (wrapper);
-
- /* get the plain part */
- part = camel_multipart_get_part (multipart, 0);
- content = g_byte_array_new ();
- stream = camel_stream_mem_new ();
- camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (stream), content);
- crlf_filter = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_ENCODE, CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY);
- from_filter = CAMEL_MIME_FILTER (camel_mime_filter_from_new ());
- filtered_stream = camel_stream_filter_new_with_stream (stream);
- camel_stream_filter_add (filtered_stream, CAMEL_MIME_FILTER (crlf_filter));
- camel_object_unref (CAMEL_OBJECT (crlf_filter));
- camel_stream_filter_add (filtered_stream, CAMEL_MIME_FILTER (from_filter));
- camel_object_unref (CAMEL_OBJECT (from_filter));
- camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (part), CAMEL_STREAM (filtered_stream));
- camel_object_unref (CAMEL_OBJECT (filtered_stream));
- camel_object_unref (CAMEL_OBJECT (stream));
-
- /* get the signed part */
- sigpart = camel_multipart_get_part (multipart, 1);
- signature = g_byte_array_new ();
- stream = camel_stream_mem_new ();
- camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (stream), signature);
- camel_data_wrapper_write_to_stream (camel_medium_get_content_object (CAMEL_MEDIUM (sigpart)), stream);
- camel_object_unref (CAMEL_OBJECT (stream));
-
- /* verify */
- valid = openpgp_verify (content->data, content->len,
- signature->data, signature->len, ex);
-
- g_byte_array_free (content, TRUE);
- g_byte_array_free (signature, TRUE);
+ context = camel_pgp_context_new (session, mail_config_get_pgp_type (),
+ mail_config_get_pgp_path ());
+ valid = camel_pgp_mime_part_verify (context, mime_part, ex);
+ camel_object_unref (CAMEL_OBJECT (context));
return valid;
}
/**
- * pgp_mime_part_encrypt:
+ * mail_crypto_pgp_mime_part_encrypt:
* @mime_part: a MIME part that will be replaced by a pgp encrypted part
* @recipients: list of recipient PGP Key IDs
* @ex: exception which will be set if there are any errors.
@@ -457,138 +177,34 @@ pgp_mime_part_verify (CamelMimePart *mime_part, CamelException *ex)
* #ex will be set and #part will remain untouched.
**/
void
-pgp_mime_part_encrypt (CamelMimePart **mime_part, const GPtrArray *recipients, CamelException *ex)
+mail_crypto_pgp_mime_part_encrypt (CamelMimePart **mime_part, GPtrArray *recipients, CamelException *ex)
{
- CamelMultipart *multipart;
- CamelMimePart *part, *version_part, *encrypted_part;
- CamelContentType *mime_type;
- CamelStreamFilter *filtered_stream;
- CamelMimeFilter *crlf_filter;
- CamelStream *stream;
- GByteArray *content;
- gchar *ciphertext;
-
- g_return_if_fail (*mime_part != NULL);
- g_return_if_fail (CAMEL_IS_MIME_PART (*mime_part));
- g_return_if_fail (recipients != NULL);
-
- part = *mime_part;
-
- /* get the contents */
- content = g_byte_array_new ();
- stream = camel_stream_mem_new ();
- camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (stream), content);
- crlf_filter = camel_mime_filter_crlf_new (CAMEL_MIME_FILTER_CRLF_ENCODE,
- CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY);
- filtered_stream = camel_stream_filter_new_with_stream (stream);
- camel_stream_filter_add (filtered_stream, CAMEL_MIME_FILTER (crlf_filter));
- camel_object_unref (CAMEL_OBJECT (crlf_filter));
- camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (part), CAMEL_STREAM (filtered_stream));
- camel_object_unref (CAMEL_OBJECT (filtered_stream));
- camel_object_unref (CAMEL_OBJECT (stream));
+ CamelPgpContext *context;
- /* pgp encrypt */
- ciphertext = openpgp_encrypt (content->data,
- content->len,
- recipients, FALSE, NULL, ex);
- g_byte_array_free (content, TRUE);
- if (camel_exception_is_set (ex))
- return;
-
- /* construct the version part */
- version_part = camel_mime_part_new ();
- camel_mime_part_set_encoding (version_part, CAMEL_MIME_PART_ENCODING_7BIT);
- camel_mime_part_set_content (version_part, "Version: 1", strlen ("Version: 1"),
- "application/pgp-encrypted");
-
- /* construct the pgp-encrypted mime part */
- encrypted_part = camel_mime_part_new ();
- camel_mime_part_set_encoding (encrypted_part, CAMEL_MIME_PART_ENCODING_7BIT);
- camel_mime_part_set_content (encrypted_part, ciphertext, strlen (ciphertext),
- "application/octet-stream");
- g_free (ciphertext);
-
- /* construct the container multipart/signed */
- multipart = camel_multipart_new ();
-
- mime_type = header_content_type_new ("multipart", "encrypted");
- header_content_type_set_param (mime_type, "protocol", "application/pgp-encrypted");
- camel_data_wrapper_set_mime_type_field (CAMEL_DATA_WRAPPER (multipart), mime_type);
- header_content_type_unref (mime_type);
-
- camel_multipart_set_boundary (multipart, NULL);
-
- /* add the parts to the multipart */
- camel_multipart_add_part (multipart, version_part);
- camel_object_unref (CAMEL_OBJECT (version_part));
- camel_multipart_add_part (multipart, encrypted_part);
- camel_object_unref (CAMEL_OBJECT (encrypted_part));
-
- /* replace the input part with the output part */
- camel_object_unref (CAMEL_OBJECT (*mime_part));
- *mime_part = camel_mime_part_new ();
- camel_medium_set_content_object (CAMEL_MEDIUM (*mime_part),
- CAMEL_DATA_WRAPPER (multipart));
- camel_object_unref (CAMEL_OBJECT (multipart));
+ context = camel_pgp_context_new (session, mail_config_get_pgp_type (),
+ mail_config_get_pgp_path ());
+ camel_pgp_mime_part_encrypt (context, mime_part, recipients, ex);
+ camel_object_unref (CAMEL_OBJECT (context));
}
/**
- * pgp_mime_part_decrypt:
+ * mail_crypto_pgp_mime_part_decrypt:
* @mime_part: a multipart/encrypted MIME Part
* @ex: exception
*
* Returns the decrypted MIME Part on success or NULL on fail.
**/
CamelMimePart *
-pgp_mime_part_decrypt (CamelMimePart *mime_part, CamelException *ex)
+mail_crypto_pgp_mime_part_decrypt (CamelMimePart *mime_part, CamelException *ex)
{
- CamelDataWrapper *wrapper;
- CamelMultipart *multipart;
- CamelMimePart *encrypted_part, *part;
- CamelContentType *mime_type;
- CamelStream *stream;
- GByteArray *content;
- gchar *cleartext;
- int clearlen;
-
- g_return_val_if_fail (mime_part != NULL, NULL);
- g_return_val_if_fail (CAMEL_IS_MIME_PART (mime_part), NULL);
-
- /* make sure the mime part is a multipart/encrypted */
- if (!mail_crypto_is_rfc2015_encrypted (mime_part))
- return NULL;
-
- wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (mime_part));
- multipart = CAMEL_MULTIPART (wrapper);
-
- /* get the encrypted part (second part) */
- encrypted_part = camel_multipart_get_part (multipart, 1 /* second part starting at 0 */);
- mime_type = camel_mime_part_get_content_type (encrypted_part);
- if (!header_content_type_is (mime_type, "application", "octet-stream"))
- return NULL;
-
- /* get the ciphertext */
- content = g_byte_array_new ();
- stream = camel_stream_mem_new ();
- camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (stream), content);
- camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (encrypted_part), stream);
- camel_object_unref (CAMEL_OBJECT (stream));
-
- /* get the cleartext */
- cleartext = openpgp_decrypt (content->data, content->len, &clearlen, ex);
- g_byte_array_free (content, TRUE);
- if (camel_exception_is_set (ex))
- return NULL;
-
- /* create a stream based on the returned cleartext */
- stream = camel_stream_mem_new_with_buffer (cleartext, clearlen);
- g_free (cleartext);
+ CamelPgpContext *context;
+ CamelMimePart *part;
- /* construct the new decrypted mime part from the stream */
- part = camel_mime_part_new ();
- camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (part), stream);
- camel_object_unref (CAMEL_OBJECT (stream));
+ context = camel_pgp_context_new (session, mail_config_get_pgp_type (),
+ mail_config_get_pgp_path ());
+ part = camel_pgp_mime_part_decrypt (context, mime_part, ex);
+ camel_object_unref (CAMEL_OBJECT (context));
return part;
}
diff --git a/mail/mail-crypto.h b/mail/mail-crypto.h
index 96fe5cb19e..a96e856d5b 100644
--- a/mail/mail-crypto.h
+++ b/mail/mail-crypto.h
@@ -24,33 +24,30 @@
#define MAIL_CRYPTO_H
#include <camel/camel.h>
-#include "openpgp-utils.h"
+#include <camel/camel-pgp-mime.h>
#ifdef __cplusplus
extern "C" {
#pragma }
#endif /* __cplusplus }*/
-gboolean mail_crypto_is_rfc2015_signed (CamelMimePart *part);
-gboolean mail_crypto_is_rfc2015_encrypted (CamelMimePart *part);
-
gboolean mail_crypto_is_smime_v3_signed (CamelMimePart *mime_part);
gboolean mail_crypto_is_pkcs7_mime (CamelMimePart *mime_part);
-void pgp_mime_part_sign (CamelMimePart **mime_part,
- const gchar *userid,
- PgpHashType hash,
- CamelException *ex);
+void mail_crypto_pgp_mime_part_sign (CamelMimePart **mime_part,
+ const char *userid,
+ CamelPgpHashType hash,
+ CamelException *ex);
-PgpValidity *pgp_mime_part_verify (CamelMimePart *mime_part,
- CamelException *ex);
+CamelPgpValidity *mail_crypto_pgp_mime_part_verify (CamelMimePart *mime_part,
+ CamelException *ex);
-void pgp_mime_part_encrypt (CamelMimePart **mime_part,
- const GPtrArray *recipients,
- CamelException *ex);
+void mail_crypto_pgp_mime_part_encrypt (CamelMimePart **mime_part,
+ GPtrArray *recipients,
+ CamelException *ex);
-CamelMimePart *pgp_mime_part_decrypt (CamelMimePart *mime_part,
- CamelException *ex);
+CamelMimePart *mail_crypto_pgp_mime_part_decrypt (CamelMimePart *mime_part,
+ CamelException *ex);
#ifdef __cplusplus
}
diff --git a/mail/mail-format.c b/mail/mail-format.c
index 3ff74238f0..63b90b913e 100644
--- a/mail/mail-format.c
+++ b/mail/mail-format.c
@@ -38,14 +38,15 @@
#include <gal/widgets/e-unicode.h>
#include <camel/camel-mime-utils.h>
+#include <camel/camel-pgp-mime.h>
#include <shell/e-setup.h>
#include <e-util/e-html-utils.h>
#include "mail.h"
#include "mail-tools.h"
#include "mail-display.h"
-#include "mail-crypto.h"
#include "mail-mt.h"
+#include "mail-crypto.h"
static char *get_data_wrapper_text (CamelDataWrapper *data);
@@ -1006,20 +1007,27 @@ destroy_part (CamelObject *root, gpointer event_data, gpointer user_data)
camel_object_unref (user_data);
}
-static char *
-decode_pgp (const char *ciphertext, int *outlen, MailDisplay *md)
+static void
+decode_pgp (CamelStream *ciphertext, CamelStream *plaintext, MailDisplay *md)
{
CamelException ex;
- char *plaintext;
camel_exception_init (&ex);
/* FIXME: multipart parts */
/* another FIXME: this doesn't have to return plaintext you realize... */
if (g_datalist_get_data (md->data, "show_pgp")) {
- plaintext = openpgp_decrypt (ciphertext, strlen (ciphertext), outlen, &ex);
- if (plaintext)
- return plaintext;
+ CamelPgpContext *ctx;
+
+ ctx = camel_pgp_context_new (session, mail_config_get_pgp_type (),
+ mail_config_get_pgp_path ());
+
+ camel_pgp_decrypt (ctx, ciphertext, plaintext, &ex);
+ camel_object_unref (CAMEL_OBJECT (ctx));
+ camel_stream_reset (plaintext);
+
+ if (!camel_exception_is_set (&ex))
+ return;
}
mail_html_write (md->html, md->stream,
@@ -1041,14 +1049,14 @@ decode_pgp (const char *ciphertext, int *outlen, MailDisplay *md)
}
mail_html_write (md->html, md->stream, "</td></tr></table>");
- return NULL;
}
static char *
try_inline_pgp (char *start, MailDisplay *md)
{
- char *end, *ciphertext, *plaintext;
- int outlen;
+ CamelStream *ciphertext, *plaintext;
+ GByteArray *buffer;
+ char *end;
end = strstr (start, "-----END PGP MESSAGE-----");
if (!end)
@@ -1060,27 +1068,37 @@ try_inline_pgp (char *start, MailDisplay *md)
/* FIXME: uhm, pgp decrypted data doesn't have to be plaintext
* however, I suppose that since it was 'inline', it probably is */
- ciphertext = g_strndup (start, end - start);
- plaintext = decode_pgp (ciphertext, &outlen, md);
- g_free (ciphertext);
- if (plaintext && outlen > 0) {
+
+ ciphertext = camel_stream_mem_new ();
+ camel_stream_write (ciphertext, start, end - start);
+ camel_stream_reset (ciphertext);
+
+ plaintext = camel_stream_mem_new ();
+ decode_pgp (ciphertext, plaintext, md);
+ camel_object_unref (CAMEL_OBJECT (ciphertext));
+
+ buffer = CAMEL_STREAM_MEM (plaintext)->buffer;
+ if (buffer && buffer->len) {
mail_html_write (md->html, md->stream,
"<table width=\"100%%\" border=2 "
"cellpadding=4><tr><td>");
- mail_text_write (md->html, md->stream, "%s", plaintext);
+ mail_text_write (md->html, md->stream, "%.*s", buffer->len, buffer->data);
mail_html_write (md->html, md->stream, "</td></tr></table>");
- g_free (plaintext);
}
+ camel_object_unref (CAMEL_OBJECT (plaintext));
+
return end;
}
static char *
try_inline_pgp_sig (char *start, MailDisplay *md)
{
- char *end, *ciphertext, *plaintext;
+ CamelPgpContext *context;
+ CamelStream *ciphertext;
+ CamelPgpValidity *valid;
CamelException *ex;
- PgpValidity *valid;
+ char *end;
end = strstr (start, "-----END PGP SIGNATURE-----");
if (!end)
@@ -1090,17 +1108,22 @@ try_inline_pgp_sig (char *start, MailDisplay *md)
mail_html_write (md->html, md->stream, "<hr>");
- ciphertext = g_strndup (start, end - start);
+ context = camel_pgp_context_new (session, mail_config_get_pgp_type (),
+ mail_config_get_pgp_path ());
+
+ ciphertext = camel_stream_mem_new ();
+ camel_stream_write (ciphertext, start, end - start);
+ camel_stream_reset (ciphertext);
+
ex = camel_exception_new ();
- valid = openpgp_verify (ciphertext, end - start, NULL, 0, ex);
- g_free (ciphertext);
+ valid = camel_pgp_verify (context, ciphertext, NULL, ex);
+ camel_object_unref (CAMEL_OBJECT (ciphertext));
+ camel_object_unref (CAMEL_OBJECT (context));
- plaintext = g_strndup (start, end - start);
- mail_text_write (md->html, md->stream, "%s", plaintext);
- g_free (plaintext);
+ mail_text_write (md->html, md->stream, "%.*s", end - start, start);
/* Now display the "seal-of-authenticity" or something... */
- if (valid && openpgp_validity_get_valid (valid)) {
+ if (valid && camel_pgp_validity_get_valid (valid)) {
mail_html_write (md->html, md->stream,
"<hr>\n<table><tr valign=top>"
"<td><img src=\"%s\"></td>"
@@ -1118,16 +1141,16 @@ try_inline_pgp_sig (char *start, MailDisplay *md)
"not be proven to be authentic."));
}
- if (valid && openpgp_validity_get_description (valid)) {
+ if (valid && camel_pgp_validity_get_description (valid)) {
mail_error_write (md->html, md->stream,
- openpgp_validity_get_description (valid));
+ camel_pgp_validity_get_description (valid));
mail_html_write (md->html, md->stream, "<br><br>");
}
mail_html_write (md->html, md->stream, "</font></td></table>");
camel_exception_free (ex);
- openpgp_validity_free (valid);
+ camel_pgp_validity_free (valid);
return end;
}
@@ -1433,13 +1456,15 @@ handle_multipart_encrypted (CamelMimePart *part, const char *mime_type,
g_return_val_if_fail (CAMEL_IS_MULTIPART (wrapper), FALSE);
/* Currently we only handle RFC2015-style PGP encryption. */
- if (!mail_crypto_is_rfc2015_encrypted (part))
+ if (!camel_pgp_mime_is_rfc2015_encrypted (part))
return handle_multipart_mixed (part, mime_type, md);
camel_exception_init (&ex);
- mime_part = pgp_mime_part_decrypt (part, &ex);
+ mime_part = mail_crypto_pgp_mime_part_decrypt (part, &ex);
+
if (camel_exception_is_set (&ex)) {
/* I guess we just treat this as a multipart/mixed */
+ camel_exception_clear (&ex);
return handle_multipart_mixed (part, mime_type, md);
} else {
gboolean retcode;
@@ -1459,7 +1484,7 @@ handle_multipart_signed (CamelMimePart *part, const char *mime_type,
CamelMultipart *mp;
CamelException *ex;
gboolean output = FALSE;
- PgpValidity *valid;
+ CamelPgpValidity *valid;
int nparts, i;
wrapper = camel_medium_get_content_object (CAMEL_MEDIUM (part));
@@ -1467,11 +1492,11 @@ handle_multipart_signed (CamelMimePart *part, const char *mime_type,
g_return_val_if_fail (CAMEL_IS_MULTIPART (wrapper), FALSE);
/* Currently we only handle RFC2015-style PGP signatures. */
- if (!mail_crypto_is_rfc2015_signed (part))
+ if (!camel_pgp_mime_is_rfc2015_signed (part))
return handle_multipart_mixed (part, mime_type, md);
ex = camel_exception_new ();
- valid = pgp_mime_part_verify (part, ex);
+ valid = mail_crypto_pgp_mime_part_verify (part, ex);
/* now display all the subparts *except* the signature */
mp = CAMEL_MULTIPART (wrapper);
@@ -1487,7 +1512,7 @@ handle_multipart_signed (CamelMimePart *part, const char *mime_type,
}
/* Now display the "seal-of-authenticity" or something... */
- if (valid && openpgp_validity_get_valid (valid)) {
+ if (valid && camel_pgp_validity_get_valid (valid)) {
mail_html_write (md->html, md->stream,
"<hr>\n<table><tr valign=top>"
"<td><img src=\"%s\"></td>"
@@ -1504,17 +1529,17 @@ handle_multipart_signed (CamelMimePart *part, const char *mime_type,
_("This message is digitally signed but can "
"not be proven to be authentic."));
}
-
- if (valid && openpgp_validity_get_description (valid)) {
+
+ if (valid && camel_pgp_validity_get_description (valid)) {
mail_error_write (md->html, md->stream,
- openpgp_validity_get_description (valid));
+ camel_pgp_validity_get_description (valid));
mail_html_write (md->html, md->stream, "<br><br>");
}
mail_html_write (md->html, md->stream, "</font></td></table>");
camel_exception_free (ex);
- openpgp_validity_free (valid);
+ camel_pgp_validity_free (valid);
return TRUE;
}