[gmime] Properly handle application/x-pkcs7-signature



commit 385b6fdaf88d1e8ab83987f1fdcdfc247ccdd5ba
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Sun Apr 22 16:18:38 2012 -0400

    Properly handle application/x-pkcs7-signature
    
    2012-04-22  Jeffrey Stedfast  <fejj gnome org>
    
    	* gmime/gmime-multipart-signed.c
    	(g_mime_multipart_signed_verify): Match protocols like
    	application/x-pkcs7-signature, too.
    
    	Fixes bug #674032.

 ChangeLog                      |    7 +++++++
 gmime/gmime-multipart-signed.c |   36 +++++++++++++++++++++++++++++++++++-
 2 files changed, 42 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 6aa4012..851a02b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2012-04-22  Jeffrey Stedfast  <fejj gnome org>
+
+	* gmime/gmime-multipart-signed.c (g_mime_multipart_signed_verify):
+	Match protocols like application/x-pkcs7-signature, too.
+
+	Fixes bug #674032.
+
 2012-04-19  Jeffrey Stedfast  <fejj gnome org>
 
 	* README: Bumped version
diff --git a/gmime/gmime-multipart-signed.c b/gmime/gmime-multipart-signed.c
index 218971e..0ea7338 100644
--- a/gmime/gmime-multipart-signed.c
+++ b/gmime/gmime-multipart-signed.c
@@ -321,6 +321,40 @@ g_mime_multipart_signed_sign (GMimeMultipartSigned *mps, GMimeObject *content,
 	return 0;
 }
 
+static gboolean
+check_protocol_supported (const char *protocol, const char *supported)
+{
+	const char *subtype;
+	char *xsupported;
+	gboolean rv;
+	
+	if (!supported)
+		return FALSE;
+	
+	if (!g_ascii_strcasecmp (protocol, supported))
+		return TRUE;
+	
+	if (!(subtype = strrchr (supported, '/')))
+		return FALSE;
+	
+	subtype++;
+	
+	/* If the subtype already begins with "x-", then there's
+	 * nothing else to check. */
+	if (!g_ascii_strncasecmp (subtype, "x-", 2))
+		return FALSE;
+	
+	/* Check if the "x-" version of the subtype matches the
+	 * protocol. For example, if the supported protocol is
+	 * "application/pkcs7-signature", then we also want to
+	 * match "application/x-pkcs7-signature". */
+	xsupported = g_strdup_printf ("%.*sx-%s", subtype - supported, supported, subtype);
+	rv = !g_ascii_strcasecmp (protocol, supported);
+	g_free (xsupported);
+	
+	return rv;
+}
+
 
 /**
  * g_mime_multipart_signed_verify:
@@ -365,7 +399,7 @@ g_mime_multipart_signed_verify (GMimeMultipartSigned *mps, GMimeCryptoContext *c
 	
 	if (protocol) {
 		/* make sure the protocol matches the crypto sign protocol */
-		if (!supported || g_ascii_strcasecmp (supported, protocol) != 0) {
+		if (!check_protocol_supported (protocol, supported)) {
 			g_set_error (err, GMIME_ERROR, GMIME_ERROR_PROTOCOL_ERROR,
 				     _("Cannot verify multipart/signed part: unsupported signature protocol '%s'."),
 				     protocol);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]