evolution-3.6.4/em-format/e-mail-parser-multipart-encrypted.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-parser-multipart-encrypted.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-parser-multipart-encrypted.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  * e-mail-parser-multipart-encrypted.c
  3  *
  4  * This program is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2 of the License, or (at your option) version 3.
  8  *
  9  * This program is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 16  *
 17  */
 18 
 19 #ifdef HAVE_CONFIG_H
 20 #include <config.h>
 21 #endif
 22 
 23 #include "e-mail-format-extensions.h"
 24 
 25 #include <em-format/e-mail-parser-extension.h>
 26 #include <em-format/e-mail-parser.h>
 27 #include <em-format/e-mail-part-utils.h>
 28 
 29 #include <glib/gi18n-lib.h>
 30 #include <camel/camel.h>
 31 
 32 typedef struct _EMailParserMultipartEncrypted {
 33 	GObject parent;
 34 } EMailParserMultipartEncrypted;
 35 
 36 typedef struct _EMailParserMultipartEncryptedClass {
 37 	GObjectClass parent_class;
 38 } EMailParserMultipartEncryptedClass;
 39 
 40 static void e_mail_parser_parser_extension_interface_init (EMailParserExtensionInterface *iface);
 41 static void e_mail_parser_mail_extension_interface_init (EMailExtensionInterface *iface);
 42 
 43 G_DEFINE_TYPE_EXTENDED (
 44 	EMailParserMultipartEncrypted,
 45 	e_mail_parser_multipart_encrypted,
 46 	G_TYPE_OBJECT,
 47 	0,
 48 	G_IMPLEMENT_INTERFACE (
 49 		E_TYPE_MAIL_EXTENSION,
 50 		e_mail_parser_mail_extension_interface_init)
 51 	G_IMPLEMENT_INTERFACE (
 52 		E_TYPE_MAIL_PARSER_EXTENSION,
 53 		e_mail_parser_parser_extension_interface_init))
 54 
 55 static const gchar * parser_mime_types[] = { "multipart/encrypted", NULL };
 56 
 57 static GSList *
 58 empe_mp_encrypted_parse (EMailParserExtension *extension,
 59                          EMailParser *parser,
 60                          CamelMimePart *part,
 61                          GString *part_id,
 62                          GCancellable *cancellable)
 63 {
 64 	CamelCipherContext *context;
 65 	const gchar *protocol;
 66 	CamelMimePart *opart;
 67 	CamelCipherValidity *valid;
 68 	CamelMultipartEncrypted *mpe;
 69 	GError *local_error = NULL;
 70 	GSList *parts;
 71 	gint len;
 72 	GSList *iter;
 73 
 74 	if (g_cancellable_is_cancelled (cancellable))
 75 		return NULL;
 76 
 77 	mpe = (CamelMultipartEncrypted *) camel_medium_get_content ((CamelMedium *) part);
 78 	if (!CAMEL_IS_MULTIPART_ENCRYPTED (mpe)) {
 79 		parts = e_mail_parser_error (
 80 			parser, cancellable,
 81 			_("Could not parse MIME message. "
 82 			"Displaying as source."));
 83 		parts = g_slist_concat (
 84 			parts,
 85 			e_mail_parser_parse_part_as (
 86 				parser, part, part_id,
 87 				"application/vnd.evolution/source",
 88 				cancellable));
 89 
 90 		return parts;
 91 	}
 92 
 93 	/* Currently we only handle RFC2015-style PGP encryption. */
 94 	protocol = camel_content_type_param (
 95 		((CamelDataWrapper *) mpe)->mime_type, "protocol");
 96 	if (!protocol || g_ascii_strcasecmp (protocol, "application/pgp-encrypted") != 0) {
 97 		parts = e_mail_parser_error (
 98 			parser, cancellable,
 99 			_("Unsupported encryption type for multipart/encrypted"));
100 
101 		parts = g_slist_concat (
102 			parts,
103 			e_mail_parser_parse_part_as (
104 				parser, part, part_id,
105 				"multipart/mixed", cancellable));
106 		return parts;
107 	}
108 
109 	context = camel_gpg_context_new (e_mail_parser_get_session (parser));
110 
111 	opart = camel_mime_part_new ();
112 	valid = camel_cipher_context_decrypt_sync (
113 		context, part, opart, cancellable, &local_error);
114 
115 	e_mail_part_preserve_charset_in_content_type (part, opart);
116 
117 	if (local_error != NULL) {
118 		parts = e_mail_parser_error (
119 			parser, cancellable,
120 			_("Could not parse PGP/MIME message: %s"),
121 			local_error->message);
122 
123 		g_error_free (local_error);
124 
125 		parts = g_slist_concat (
126 			parts,
127 			e_mail_parser_parse_part_as (
128 				parser, part, part_id,
129 				"multipart/mixed", cancellable));
130 
131 		g_object_unref (opart);
132 		g_object_unref (context);
133 
134 		return parts;
135 	}
136 
137 	len = part_id->len;
138 	g_string_append (part_id, ".encrypted");
139 
140 	parts = e_mail_parser_parse_part (
141 		parser, opart, part_id, cancellable);
142 
143 	g_string_truncate (part_id, len);
144 
145 	/* Update validity of all encrypted sub-parts */
146 	for (iter = parts; iter; iter = iter->next) {
147 		EMailPart *mail_part;
148 
149 		mail_part = iter->data;
150 		if (!mail_part)
151 			continue;
152 
153 		e_mail_part_update_validity (
154 			mail_part, valid,
155 			E_MAIL_PART_VALIDITY_ENCRYPTED |
156 			E_MAIL_PART_VALIDITY_PGP);
157 	}
158 
159 	/* Add a widget with details about the encryption, but only when
160 	 * the decrypted part isn't itself secured, in that case it has
161 	 * created the button itself. */
162 	if (!e_mail_part_is_secured (opart)) {
163 		GSList *button;
164 		EMailPart *mail_part;
165 		g_string_append (part_id, ".encrypted.button");
166 
167 		button = e_mail_parser_parse_part_as (
168 			parser, part, part_id,
169 			"application/vnd.evolution.widget.secure-button",
170 			cancellable);
171 		if (button && button->data) {
172 			mail_part = button->data;
173 
174 			e_mail_part_update_validity (
175 				mail_part, valid,
176 				E_MAIL_PART_VALIDITY_ENCRYPTED |
177 				E_MAIL_PART_VALIDITY_PGP);
178 		}
179 
180 		parts = g_slist_concat (parts, button);
181 
182 		g_string_truncate (part_id, len);
183 	}
184 
185 	camel_cipher_validity_free (valid);
186 
187 	/* TODO: Make sure when we finalize this part, it is zero'd out */
188 	g_object_unref (opart);
189 	g_object_unref (context);
190 
191 	return parts;
192 }
193 
194 static const gchar **
195 empe_mp_encrypted_mime_types (EMailExtension *extension)
196 {
197 	return parser_mime_types;
198 }
199 
200 static void
201 e_mail_parser_multipart_encrypted_class_init (EMailParserMultipartEncryptedClass *class)
202 {
203 }
204 
205 static void
206 e_mail_parser_parser_extension_interface_init (EMailParserExtensionInterface *iface)
207 {
208 	iface->parse = empe_mp_encrypted_parse;
209 }
210 
211 static void
212 e_mail_parser_mail_extension_interface_init (EMailExtensionInterface *iface)
213 {
214 	iface->mime_types = empe_mp_encrypted_mime_types;
215 }
216 
217 static void
218 e_mail_parser_multipart_encrypted_init (EMailParserMultipartEncrypted *parser)
219 {
220 
221 }