From ae05d707ad0185f657c466181b0320ad04ed0ee8 Mon Sep 17 00:00:00 2001 From: Jeffrey Stedfast Date: Wed, 7 Mar 2001 06:37:18 +0000 Subject: New function to decide if a mime part is an S/MIME v3 signed part. 2001-03-07 Jeffrey Stedfast * mail-crypto.c (mail_crypto_is_smime_v3_signed): New function to decide if a mime part is an S/MIME v3 signed part. (mail_crypto_is_pkcs7_mime): New function to decide if a mime part is an application/pkcs7-mime part (or an application/octet-stream part with application/pkcs7-mime data). svn path=/trunk/; revision=8578 --- mail/ChangeLog | 6 +++ mail/mail-crypto.c | 118 ++++++++++++++++++++++++++++++++++++++++++++--------- mail/mail-crypto.h | 4 +- 3 files changed, 107 insertions(+), 21 deletions(-) (limited to 'mail') diff --git a/mail/ChangeLog b/mail/ChangeLog index 757cf4fa44..0434931791 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,5 +1,11 @@ 2001-03-07 Jeffrey Stedfast + * mail-crypto.c (mail_crypto_is_smime_v3_signed): New function to + decide if a mime part is an S/MIME v3 signed part. + (mail_crypto_is_pkcs7_mime): New function to decide if a mime part + is an application/pkcs7-mime part (or an application/octet-stream + part with application/pkcs7-mime data). + * mail-account-editor.c (source_auth_init): Move the signal emittion to after the set_menu call so that it actually works. (transport_type_changed): Updated to manipulate the user/passwd diff --git a/mail/mail-crypto.c b/mail/mail-crypto.c index fcba02c0a4..0ae5083c33 100644 --- a/mail/mail-crypto.c +++ b/mail/mail-crypto.c @@ -29,25 +29,9 @@ #include "mail-crypto.h" #include "mail-session.h" -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include -/** rfc2015 stuff *******************************/ +/** rfc2015 stuff (aka PGP/MIME) *******************************/ gboolean mail_crypto_is_rfc2015_signed (CamelMimePart *mime_part) @@ -56,7 +40,7 @@ mail_crypto_is_rfc2015_signed (CamelMimePart *mime_part) CamelMultipart *mp; CamelMimePart *part; CamelContentType *type; - const gchar *param; + const gchar *param, *micalg; int nparts; /* check that we have a multipart/signed */ @@ -69,6 +53,11 @@ mail_crypto_is_rfc2015_signed (CamelMimePart *mime_part) 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); @@ -89,8 +78,6 @@ mail_crypto_is_rfc2015_signed (CamelMimePart *mime_part) if (!header_content_type_is (type, "application", "pgp-signature")) return FALSE; - /* FIXME: Implement multisig stuff */ - return TRUE; } @@ -137,6 +124,97 @@ mail_crypto_is_rfc2015_encrypted (CamelMimePart *mime_part) return TRUE; } + +/** rfc2633 stuff (aka S/MIME v3) ********************************/ + +gboolean +mail_crypto_is_smime_v3_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/pkcs7-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/pkcs7-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", "pkcs7-signature")) + return FALSE; + + /* The second part should be application/pkcs7-signature. */ + part = camel_multipart_get_part (mp, 1); + type = camel_mime_part_get_content_type (part); + if (!header_content_type_is (type, "application", "pkcs7-signature")) + return FALSE; + + return TRUE; +} + +gboolean +mail_crypto_is_pkcs7_mime (CamelMimePart *mime_part) +{ + char *types[] = { "p7m", "p7c", "p7s", NULL }; + const gchar *param, *filename; + CamelContentType *type; + int i; + + /* check that we have a application/pkcs7-mime part */ + type = camel_mime_part_get_content_type (mime_part); + if (header_content_type_is (type, "application", "pkcs7-mime")) + return TRUE; + + if (header_content_type_is (type, "application", "octent-stream")) { + /* check to see if we have a paremeter called "smime-type" */ + param = header_content_type_param (type, "smime-type"); + if (param) + return TRUE; + + /* check to see if there is a name param and if it has a smime extension */ + param = header_content_type_param (type, "smime-type"); + if (param && *param && strlen (param) > 4) { + for (i = 0; types[i]; i++) + if (!g_strcasecmp (param + strlen (param)-4, types[i])) + return TRUE; + } + + /* check to see if there is a name param and if it has a smime extension */ + filename = camel_mime_part_get_filename (mime_part); + if (filename && *filename && strlen (filename) > 4) { + for (i = 0; types[i]; i++) + if (!g_strcasecmp (filename + strlen (filename)-4, types[i])) + return TRUE; + } + } + + return FALSE; +} + + /** * pgp_mime_part_sign: * @mime_part: a MIME part that will be replaced by a pgp signed part diff --git a/mail/mail-crypto.h b/mail/mail-crypto.h index 8a5c328c9c..746320082e 100644 --- a/mail/mail-crypto.h +++ b/mail/mail-crypto.h @@ -33,9 +33,11 @@ extern "C" { #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, -- cgit v1.2.3