Blame SOURCES/evolution-3.28.5-cve-2018-15587-reposition-signature-bar.patch

f33b1a
diff -up evolution-3.28.5/src/em-format/e-mail-formatter-utils.c.cve-2018-15587-reposition-signature-bar evolution-3.28.5/src/em-format/e-mail-formatter-utils.c
f33b1a
--- evolution-3.28.5/src/em-format/e-mail-formatter-utils.c.cve-2018-15587-reposition-signature-bar	2018-07-30 15:37:05.000000000 +0200
f33b1a
+++ evolution-3.28.5/src/em-format/e-mail-formatter-utils.c	2019-10-24 16:21:32.730944332 +0200
f33b1a
@@ -549,71 +549,136 @@ e_mail_formatter_format_security_header
f33b1a
                                          EMailPart *part,
f33b1a
                                          guint32 flags)
f33b1a
 {
f33b1a
-	const gchar* part_id;
f33b1a
-	gchar* part_id_prefix;
f33b1a
-	GString* tmp;
f33b1a
+	struct _validity_flags {
f33b1a
+		guint32 flags;
f33b1a
+		const gchar *description_complete;
f33b1a
+		const gchar *description_partial;
f33b1a
+	} validity_flags[] = {
f33b1a
+		{ E_MAIL_PART_VALIDITY_PGP | E_MAIL_PART_VALIDITY_SIGNED, N_("GPG signed"), N_("partially GPG signed") },
f33b1a
+		{ E_MAIL_PART_VALIDITY_PGP | E_MAIL_PART_VALIDITY_ENCRYPTED, N_("GPG encrypted"), N_("partially GPG encrypted") },
f33b1a
+		{ E_MAIL_PART_VALIDITY_SMIME | E_MAIL_PART_VALIDITY_SIGNED, N_("S/MIME signed"), N_("partially S/MIME signed") },
f33b1a
+		{ E_MAIL_PART_VALIDITY_SMIME | E_MAIL_PART_VALIDITY_ENCRYPTED, N_("S/MIME encrypted"), N_("partially S/MIME encrypted") }
f33b1a
+	};
f33b1a
+	const gchar *part_id;
f33b1a
+	gchar *part_id_prefix;
f33b1a
 	GQueue queue = G_QUEUE_INIT;
f33b1a
 	GList *head, *link;
f33b1a
+	guint32 check_valid_flags = 0;
f33b1a
+	gint part_id_prefix_len;
f33b1a
+	gboolean is_partial = FALSE;
f33b1a
+	guint ii;
f33b1a
 
f33b1a
 	g_return_if_fail (E_IS_MAIL_PART_HEADERS (part));
f33b1a
 
f33b1a
 	/* Get prefix of this PURI */
f33b1a
 	part_id = e_mail_part_get_id (part);
f33b1a
 	part_id_prefix = g_strndup (part_id, g_strrstr (part_id, ".") - part_id);
f33b1a
-
f33b1a
-	/* Add encryption/signature header */
f33b1a
-	tmp = g_string_new ("");
f33b1a
+	part_id_prefix_len = strlen (part_id_prefix);
f33b1a
 
f33b1a
 	e_mail_part_list_queue_parts (context->part_list, NULL, &queue);
f33b1a
 
f33b1a
 	head = g_queue_peek_head_link (&queue);
f33b1a
 
f33b1a
-	/* Find first secured part. */
f33b1a
-	for (link = head; link != NULL; link = g_list_next(link)) {
f33b1a
+	/* Ignore the main message, the headers and the end parts */
f33b1a
+	#define should_skip_part(_id) \
f33b1a
+		(g_strcmp0 (_id, part_id_prefix) == 0 || \
f33b1a
+		(_id && g_str_has_suffix (_id, ".rfc822.end")) || \
f33b1a
+		(_id && strlen (_id) == part_id_prefix_len + 8 /* strlen (".headers") */ && \
f33b1a
+		g_strcmp0 (_id + part_id_prefix_len, ".headers") == 0))
f33b1a
+
f33b1a
+	/* Check parts for this ID. */
f33b1a
+	for (link = head; link != NULL; link = g_list_next (link)) {
f33b1a
 		EMailPart *mail_part = link->data;
f33b1a
+		const gchar *id = e_mail_part_get_id (mail_part);
f33b1a
 
f33b1a
-		if (!e_mail_part_has_validity (mail_part))
f33b1a
+		if (!e_mail_part_id_has_prefix (mail_part, part_id_prefix))
f33b1a
 			continue;
f33b1a
 
f33b1a
-		if (!e_mail_part_id_has_prefix (mail_part, part_id_prefix))
f33b1a
+		if (should_skip_part (id))
f33b1a
 			continue;
f33b1a
 
f33b1a
-		if (e_mail_part_get_validity (mail_part, E_MAIL_PART_VALIDITY_PGP | E_MAIL_PART_VALIDITY_SIGNED)) {
f33b1a
-			g_string_append (tmp, _("GPG signed"));
f33b1a
+		if (!e_mail_part_has_validity (mail_part)) {
f33b1a
+			/* A part without validity, thus it's partially signed/encrypted */
f33b1a
+			is_partial = TRUE;
f33b1a
+		} else {
f33b1a
+			guint32 validies = 0;
f33b1a
+			for (ii = 0; ii < G_N_ELEMENTS (validity_flags); ii++) {
f33b1a
+				if (e_mail_part_get_validity (mail_part, validity_flags[ii].flags))
f33b1a
+					validies |= validity_flags[ii].flags;
f33b1a
+			}
f33b1a
+			check_valid_flags |= validies;
f33b1a
 		}
f33b1a
 
f33b1a
-		if (e_mail_part_get_validity (mail_part, E_MAIL_PART_VALIDITY_PGP | E_MAIL_PART_VALIDITY_ENCRYPTED)) {
f33b1a
-			if (tmp->len > 0)
f33b1a
-				g_string_append (tmp, ", ");
f33b1a
-			g_string_append (tmp, _("GPG encrypted"));
f33b1a
-		}
f33b1a
+		/* Do not traverse sub-messages */
f33b1a
+		if (g_str_has_suffix (e_mail_part_get_id (mail_part), ".rfc822") &&
f33b1a
+		    !g_str_equal (e_mail_part_get_id (mail_part), part_id_prefix))
f33b1a
+			link = e_mail_formatter_find_rfc822_end_iter (link);
f33b1a
+	}
f33b1a
 
f33b1a
-		if (e_mail_part_get_validity (mail_part, E_MAIL_PART_VALIDITY_SMIME | E_MAIL_PART_VALIDITY_SIGNED)) {
f33b1a
-			if (tmp->len > 0)
f33b1a
-				g_string_append (tmp, ", ");
f33b1a
-			g_string_append (tmp, _("S/MIME signed"));
f33b1a
+	if (check_valid_flags) {
f33b1a
+		GString *tmp;
f33b1a
+
f33b1a
+		if (!is_partial) {
f33b1a
+			for (link = head; link != NULL && !is_partial; link = g_list_next (link)) {
f33b1a
+				EMailPart *mail_part = link->data;
f33b1a
+				const gchar *id = e_mail_part_get_id (mail_part);
f33b1a
+
f33b1a
+				if (!e_mail_part_id_has_prefix (mail_part, part_id_prefix))
f33b1a
+					continue;
f33b1a
+
f33b1a
+				if (should_skip_part (id))
f33b1a
+					continue;
f33b1a
+
f33b1a
+				if (!e_mail_part_has_validity (mail_part)) {
f33b1a
+					/* A part without validity, thus it's partially signed/encrypted */
f33b1a
+					is_partial = TRUE;
f33b1a
+					break;
f33b1a
+				}
f33b1a
+
f33b1a
+				is_partial = !e_mail_part_get_validity (mail_part, check_valid_flags);
f33b1a
+
f33b1a
+				/* Do not traverse sub-messages */
f33b1a
+				if (g_str_has_suffix (e_mail_part_get_id (mail_part), ".rfc822") &&
f33b1a
+				    !g_str_equal (e_mail_part_get_id (mail_part), part_id_prefix))
f33b1a
+					link = e_mail_formatter_find_rfc822_end_iter (link);
f33b1a
+			}
f33b1a
 		}
f33b1a
 
f33b1a
-		if (e_mail_part_get_validity (mail_part, E_MAIL_PART_VALIDITY_SMIME | E_MAIL_PART_VALIDITY_ENCRYPTED)) {
f33b1a
-			if (tmp->len > 0)
f33b1a
-				g_string_append (tmp, ", ");
f33b1a
-			g_string_append (tmp, _("S/MIME encrypted"));
f33b1a
+		/* Add encryption/signature header */
f33b1a
+		tmp = g_string_new ("");
f33b1a
+
f33b1a
+		for (link = head; link; link = g_list_next (link)) {
f33b1a
+			EMailPart *mail_part = link->data;
f33b1a
+			const gchar *id = e_mail_part_get_id (mail_part);
f33b1a
+
f33b1a
+			if (!e_mail_part_has_validity (mail_part) ||
f33b1a
+			    !e_mail_part_id_has_prefix (mail_part, part_id_prefix))
f33b1a
+				continue;
f33b1a
+
f33b1a
+			if (should_skip_part (id))
f33b1a
+				continue;
f33b1a
+
f33b1a
+			for (ii = 0; ii < G_N_ELEMENTS (validity_flags); ii++) {
f33b1a
+				if (e_mail_part_get_validity (mail_part, validity_flags[ii].flags)) {
f33b1a
+					if (tmp->len > 0)
f33b1a
+						g_string_append (tmp, ", ");
f33b1a
+					g_string_append (tmp, is_partial ? _(validity_flags[ii].description_partial) : _(validity_flags[ii].description_complete));
f33b1a
+				}
f33b1a
+			}
f33b1a
+
f33b1a
+			break;
f33b1a
 		}
f33b1a
 
f33b1a
-		break;
f33b1a
-	}
f33b1a
+		if (tmp->len > 0)
f33b1a
+			e_mail_formatter_format_header (formatter, buffer, _("Security"), tmp->str, flags, "UTF-8");
f33b1a
 
f33b1a
-	if (tmp->len > 0) {
f33b1a
-		e_mail_formatter_format_header (
f33b1a
-			formatter, buffer,
f33b1a
-			_("Security"), tmp->str,
f33b1a
-			flags,
f33b1a
-			"UTF-8");
f33b1a
+		g_string_free (tmp, TRUE);
f33b1a
 	}
f33b1a
 
f33b1a
+	#undef should_skip_part
f33b1a
+
f33b1a
 	while (!g_queue_is_empty (&queue))
f33b1a
 		g_object_unref (g_queue_pop_head (&queue));
f33b1a
 
f33b1a
-	g_string_free (tmp, TRUE);
f33b1a
 	g_free (part_id_prefix);
f33b1a
 }
f33b1a
diff -up evolution-3.28.5/src/em-format/e-mail-parser-application-smime.c.cve-2018-15587-reposition-signature-bar evolution-3.28.5/src/em-format/e-mail-parser-application-smime.c
f33b1a
--- evolution-3.28.5/src/em-format/e-mail-parser-application-smime.c.cve-2018-15587-reposition-signature-bar	2018-07-30 15:37:05.000000000 +0200
f33b1a
+++ evolution-3.28.5/src/em-format/e-mail-parser-application-smime.c	2019-10-24 16:21:32.730944332 +0200
f33b1a
@@ -22,6 +22,7 @@
f33b1a
 
f33b1a
 #include <e-util/e-util.h>
f33b1a
 
f33b1a
+#include "e-mail-formatter-utils.h"
f33b1a
 #include "e-mail-parser-extension.h"
f33b1a
 #include "e-mail-part-utils.h"
f33b1a
 
f33b1a
@@ -104,6 +105,10 @@ empe_app_smime_parse (EMailParserExtensi
f33b1a
 				mail_part, valid,
f33b1a
 				E_MAIL_PART_VALIDITY_ENCRYPTED |
f33b1a
 				E_MAIL_PART_VALIDITY_SMIME);
f33b1a
+
f33b1a
+			/* Do not traverse sub-messages */
f33b1a
+			if (g_str_has_suffix (e_mail_part_get_id (mail_part), ".rfc822"))
f33b1a
+				link = e_mail_formatter_find_rfc822_end_iter (link);
f33b1a
 		}
f33b1a
 
f33b1a
 		e_queue_transfer (&work_queue, out_mail_parts);
f33b1a
diff -up evolution-3.28.5/src/em-format/e-mail-parser.c.cve-2018-15587-reposition-signature-bar evolution-3.28.5/src/em-format/e-mail-parser.c
f33b1a
--- evolution-3.28.5/src/em-format/e-mail-parser.c.cve-2018-15587-reposition-signature-bar	2018-07-30 15:37:05.000000000 +0200
f33b1a
+++ evolution-3.28.5/src/em-format/e-mail-parser.c	2019-10-24 16:21:32.729944332 +0200
f33b1a
@@ -79,6 +79,67 @@ GType e_mail_parser_application_smime_ge
f33b1a
 static gpointer parent_class;
f33b1a
 
f33b1a
 static void
f33b1a
+mail_parser_move_security_before_headers (GQueue *part_queue)
f33b1a
+{
f33b1a
+	GList *link, *last_headers = NULL;
f33b1a
+	GSList *headers_stack = NULL;
f33b1a
+
f33b1a
+	link = g_queue_peek_head_link (part_queue);
f33b1a
+	while (link) {
f33b1a
+		EMailPart *part = link->data;
f33b1a
+		const gchar *id;
f33b1a
+
f33b1a
+		if (!part) {
f33b1a
+			link = g_list_next (link);
f33b1a
+			continue;
f33b1a
+		}
f33b1a
+
f33b1a
+		id = e_mail_part_get_id (part);
f33b1a
+		if (!id) {
f33b1a
+			link = g_list_next (link);
f33b1a
+			continue;
f33b1a
+		}
f33b1a
+
f33b1a
+		if (g_str_has_suffix (id, ".rfc822")) {
f33b1a
+			headers_stack = g_slist_prepend (headers_stack, last_headers);
f33b1a
+			last_headers = NULL;
f33b1a
+		} else if (g_str_has_suffix (id, ".rfc822.end")) {
f33b1a
+			g_warn_if_fail (headers_stack != NULL);
f33b1a
+
f33b1a
+			if (headers_stack) {
f33b1a
+				last_headers = headers_stack->data;
f33b1a
+				headers_stack = g_slist_remove (headers_stack, last_headers);
f33b1a
+			} else {
f33b1a
+				last_headers = NULL;
f33b1a
+			}
f33b1a
+		}
f33b1a
+
f33b1a
+		if (g_strcmp0 (e_mail_part_get_mime_type (part), "application/vnd.evolution.headers") == 0) {
f33b1a
+			last_headers = link;
f33b1a
+			link = g_list_next (link);
f33b1a
+		} else if (g_strcmp0 (e_mail_part_get_mime_type (part), "application/vnd.evolution.secure-button") == 0) {
f33b1a
+			g_warn_if_fail (last_headers != NULL);
f33b1a
+
f33b1a
+			if (last_headers) {
f33b1a
+				GList *next = g_list_next (link);
f33b1a
+
f33b1a
+				g_warn_if_fail (g_queue_remove (part_queue, part));
f33b1a
+				g_queue_insert_before (part_queue, last_headers, part);
f33b1a
+
f33b1a
+				link = next;
f33b1a
+			} else {
f33b1a
+				link = g_list_next (link);
f33b1a
+			}
f33b1a
+		} else {
f33b1a
+			link = g_list_next (link);
f33b1a
+		}
f33b1a
+	}
f33b1a
+
f33b1a
+	g_warn_if_fail (headers_stack == NULL);
f33b1a
+	g_slist_free (headers_stack);
f33b1a
+}
f33b1a
+
f33b1a
+static void
f33b1a
 mail_parser_run (EMailParser *parser,
f33b1a
                  EMailPartList *part_list,
f33b1a
                  GCancellable *cancellable)
f33b1a
@@ -132,6 +193,8 @@ mail_parser_run (EMailParser *parser,
f33b1a
 			break;
f33b1a
 	}
f33b1a
 
f33b1a
+	mail_parser_move_security_before_headers (&mail_part_queue);
f33b1a
+
f33b1a
 	while (!g_queue_is_empty (&mail_part_queue)) {
f33b1a
 		mail_part = g_queue_pop_head (&mail_part_queue);
f33b1a
 		e_mail_part_list_add_part (part_list, mail_part);
f33b1a
diff -up evolution-3.28.5/src/em-format/e-mail-parser-inlinepgp-encrypted.c.cve-2018-15587-reposition-signature-bar evolution-3.28.5/src/em-format/e-mail-parser-inlinepgp-encrypted.c
f33b1a
--- evolution-3.28.5/src/em-format/e-mail-parser-inlinepgp-encrypted.c.cve-2018-15587-reposition-signature-bar	2018-07-30 15:37:05.000000000 +0200
f33b1a
+++ evolution-3.28.5/src/em-format/e-mail-parser-inlinepgp-encrypted.c	2019-10-24 16:21:32.730944332 +0200
f33b1a
@@ -22,6 +22,7 @@
f33b1a
 
f33b1a
 #include <e-util/e-util.h>
f33b1a
 
f33b1a
+#include "e-mail-formatter-utils.h"
f33b1a
 #include "e-mail-parser-extension.h"
f33b1a
 #include "e-mail-part-utils.h"
f33b1a
 
f33b1a
@@ -135,6 +136,10 @@ empe_inlinepgp_encrypted_parse (EMailPar
f33b1a
 			mail_part, valid,
f33b1a
 			E_MAIL_PART_VALIDITY_ENCRYPTED |
f33b1a
 			E_MAIL_PART_VALIDITY_PGP);
f33b1a
+
f33b1a
+		/* Do not traverse sub-messages */
f33b1a
+		if (g_str_has_suffix (e_mail_part_get_id (mail_part), ".rfc822"))
f33b1a
+			link = e_mail_formatter_find_rfc822_end_iter (link);
f33b1a
 	}
f33b1a
 
f33b1a
 	e_queue_transfer (&work_queue, out_mail_parts);
f33b1a
diff -up evolution-3.28.5/src/em-format/e-mail-parser-inlinepgp-signed.c.cve-2018-15587-reposition-signature-bar evolution-3.28.5/src/em-format/e-mail-parser-inlinepgp-signed.c
f33b1a
--- evolution-3.28.5/src/em-format/e-mail-parser-inlinepgp-signed.c.cve-2018-15587-reposition-signature-bar	2018-07-30 15:37:05.000000000 +0200
f33b1a
+++ evolution-3.28.5/src/em-format/e-mail-parser-inlinepgp-signed.c	2019-10-24 16:21:32.731944332 +0200
f33b1a
@@ -22,6 +22,7 @@
f33b1a
 
f33b1a
 #include <e-util/e-util.h>
f33b1a
 
f33b1a
+#include "e-mail-formatter-utils.h"
f33b1a
 #include "e-mail-parser-extension.h"
f33b1a
 #include "e-mail-part-utils.h"
f33b1a
 
f33b1a
@@ -142,6 +143,10 @@ empe_inlinepgp_signed_parse (EMailParser
f33b1a
 			mail_part, valid,
f33b1a
 			E_MAIL_PART_VALIDITY_SIGNED |
f33b1a
 			E_MAIL_PART_VALIDITY_PGP);
f33b1a
+
f33b1a
+		/* Do not traverse sub-messages */
f33b1a
+		if (g_str_has_suffix (e_mail_part_get_id (mail_part), ".rfc822"))
f33b1a
+			link = e_mail_formatter_find_rfc822_end_iter (link);
f33b1a
 	}
f33b1a
 
f33b1a
 	e_queue_transfer (&work_queue, out_mail_parts);
f33b1a
diff -up evolution-3.28.5/src/em-format/e-mail-parser-multipart-encrypted.c.cve-2018-15587-reposition-signature-bar evolution-3.28.5/src/em-format/e-mail-parser-multipart-encrypted.c
f33b1a
--- evolution-3.28.5/src/em-format/e-mail-parser-multipart-encrypted.c.cve-2018-15587-reposition-signature-bar	2018-07-30 15:37:05.000000000 +0200
f33b1a
+++ evolution-3.28.5/src/em-format/e-mail-parser-multipart-encrypted.c	2019-10-24 16:21:32.731944332 +0200
f33b1a
@@ -21,6 +21,7 @@
f33b1a
 
f33b1a
 #include <libedataserver/libedataserver.h>
f33b1a
 
f33b1a
+#include "e-mail-formatter-utils.h"
f33b1a
 #include "e-mail-parser-extension.h"
f33b1a
 #include "e-mail-part-utils.h"
f33b1a
 
f33b1a
@@ -126,6 +127,10 @@ empe_mp_encrypted_parse (EMailParserExte
f33b1a
 			mail_part, valid,
f33b1a
 			E_MAIL_PART_VALIDITY_ENCRYPTED |
f33b1a
 			E_MAIL_PART_VALIDITY_PGP);
f33b1a
+
f33b1a
+		/* Do not traverse sub-messages */
f33b1a
+		if (g_str_has_suffix (e_mail_part_get_id (mail_part), ".rfc822"))
f33b1a
+			link = e_mail_formatter_find_rfc822_end_iter (link);
f33b1a
 	}
f33b1a
 
f33b1a
 	e_queue_transfer (&work_queue, out_mail_parts);
f33b1a
diff -up evolution-3.28.5/src/em-format/e-mail-parser-multipart-signed.c.cve-2018-15587-reposition-signature-bar evolution-3.28.5/src/em-format/e-mail-parser-multipart-signed.c
f33b1a
--- evolution-3.28.5/src/em-format/e-mail-parser-multipart-signed.c.cve-2018-15587-reposition-signature-bar	2018-07-30 15:37:05.000000000 +0200
f33b1a
+++ evolution-3.28.5/src/em-format/e-mail-parser-multipart-signed.c	2019-10-24 16:21:32.731944332 +0200
f33b1a
@@ -21,6 +21,7 @@
f33b1a
 
f33b1a
 #include <libedataserver/libedataserver.h>
f33b1a
 
f33b1a
+#include "e-mail-formatter-utils.h"
f33b1a
 #include "e-mail-parser-extension.h"
f33b1a
 #include "e-mail-part-utils.h"
f33b1a
 
f33b1a
@@ -170,6 +171,10 @@ empe_mp_signed_parse (EMailParserExtensi
f33b1a
 			e_mail_part_update_validity (
f33b1a
 				mail_part, valid,
f33b1a
 				validity_type | E_MAIL_PART_VALIDITY_SIGNED);
f33b1a
+
f33b1a
+			/* Do not traverse sub-messages */
f33b1a
+			if (g_str_has_suffix (e_mail_part_get_id (mail_part), ".rfc822"))
f33b1a
+				link = e_mail_formatter_find_rfc822_end_iter (link);
f33b1a
 		}
f33b1a
 
f33b1a
 		e_queue_transfer (&work_queue, out_mail_parts);
f33b1a
diff -up evolution-3.28.5/src/em-format/e-mail-part.c.cve-2018-15587-reposition-signature-bar evolution-3.28.5/src/em-format/e-mail-part.c
f33b1a
--- evolution-3.28.5/src/em-format/e-mail-part.c.cve-2018-15587-reposition-signature-bar	2018-07-30 15:37:05.000000000 +0200
f33b1a
+++ evolution-3.28.5/src/em-format/e-mail-part.c	2019-10-24 16:21:32.731944332 +0200
f33b1a
@@ -662,6 +662,15 @@ e_mail_part_update_validity (EMailPart *
f33b1a
 
f33b1a
 	mask = E_MAIL_PART_VALIDITY_PGP | E_MAIL_PART_VALIDITY_SMIME;
f33b1a
 
f33b1a
+	/* Auto-add flags when the related part is present */
f33b1a
+	if (!(validity_type & E_MAIL_PART_VALIDITY_SIGNED) &&
f33b1a
+	    validity->sign.status != CAMEL_CIPHER_VALIDITY_SIGN_NONE)
f33b1a
+		validity_type |= E_MAIL_PART_VALIDITY_SIGNED;
f33b1a
+
f33b1a
+	if (!(validity_type & E_MAIL_PART_VALIDITY_ENCRYPTED) &&
f33b1a
+	    validity->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE)
f33b1a
+		validity_type |= E_MAIL_PART_VALIDITY_ENCRYPTED;
f33b1a
+
f33b1a
 	pair = mail_part_find_validity_pair (part, validity_type & mask);
f33b1a
 	if (pair != NULL) {
f33b1a
 		pair->validity_type |= validity_type;