From 2f99f8636abd7efc68bfa5de1591c594e9f532eb Mon Sep 17 00:00:00 2001 From: Not Zed Date: Mon, 24 Nov 2003 22:35:33 +0000 Subject: set session on print formatter for signatures to work. 2003-11-25 Not Zed * em-folder-view.c (em_folder_view_print): set session on print formatter for signatures to work. * em-message-browser.c (emmb_destroy): kill warning. * em-format-html.c (efh_output_secure): same as efhd_output_secure, output the security bar, but for printing/plain html. (efh_application_xpkcs7mime): use output_secure. (em_format_html_multipart_signed_sign): removed, output_secure does what this did. * em-format-html-display.c (smime_sign_table, smime_encrypt_table): Added a short description for the mail display. (efhd_xpkcs7mime_button): only good/bad signature at this point, if only encrypted, then display 'bad' icon. (efhd_output_secure): output the security bar/button and handle multi-level enveloping properly. (efhd_application_xpkcs7mime): just call output_secure to do the security bar. (efhd_multipart_signed): same. (efhd_signature_button): removed, no longer used. (efhd_signature_check): removed, no longer used. svn path=/trunk/; revision=23483 --- mail/em-format-html-display.c | 197 ++++++++++++++++++------------------------ 1 file changed, 84 insertions(+), 113 deletions(-) (limited to 'mail/em-format-html-display.c') diff --git a/mail/em-format-html-display.c b/mail/em-format-html-display.c index ec606ec5d7..07fe4869b4 100644 --- a/mail/em-format-html-display.c +++ b/mail/em-format-html-display.c @@ -589,22 +589,24 @@ efhd_complete(EMFormat *emf) /* ********************************************************************** */ +/* TODO: rename some of this stuff, it isn't 'smime' specific */ +/* FIXME: also in em-format-html.c */ static const struct { - const char *icon, *description; + const char *icon, *shortdesc, *description; } smime_sign_table[4] = { - { NULL, N_("This message is not signed. There is no guarantee the sender of the message is authentic.") }, - { "pgp-signature-ok.png", N_("This message is signed and is valid, the sender of this message is very likely who they claim to be.") }, - { "pgp-signature-bad.png", N_("The signature of this message cannot be verified, it may have been altered in transit.") }, - { "pgp-signature-nokey.png", N_("This message is signed with a valid signature, but the sender of the message cannot be verified.") }, + { NULL, N_("Unsigned"), N_("This message is not signed. There is no guarantee the sender of the message is authentic.") }, + { "pgp-signature-ok.png",N_("Valid signature"), N_("This message is signed and is valid, the sender of this message is very likely who they claim to be.") }, + { "pgp-signature-bad.png", N_("Invalid signature"), N_("The signature of this message cannot be verified, it may have been altered in transit.") }, + { "pgp-signature-nokey.png", N_("Valid signature, cannot verify sender"), N_("This message is signed with a valid signature, but the sender of the message cannot be verified.") }, }; static const struct { - const char *icon, *description; + const char *icon, *shortdesc, *description; } smime_encrypt_table[4] = { - { NULL, N_("This message is not encrypted. It's content may be viewed in transit across The Internet.") }, - { "pgp-signature-ok.png", N_("This message is encrypted, but with a weak encryption algorithm. It would be difficult, but not impossible for an outsider to view the content of this message in a practical amount of time.") }, - { "pgp-signature-ok.png", N_("This message is encrypted. It would be difficult for an outsider to view the content of this message.") }, - { "pgp-signature-ok.png", N_("This message is encrypted, with a strong encryption algorithm. It would be very difficult for an outsider to view the content of this message in a practical amount of time.") }, + { NULL, N_("Unencrypted"), N_("This message is not encrypted. It's content may be viewed in transit across The Internet.") }, + { "pgp-signature-ok.png", N_("Encrypted, weak"), N_("This message is encrypted, but with a weak encryption algorithm. It would be difficult, but not impossible for an outsider to view the content of this message in a practical amount of time.") }, + { "pgp-signature-ok.png", N_("Encrypted"), N_("This message is encrypted. It would be difficult for an outsider to view the content of this message.") }, + { "pgp-signature-ok.png", N_("Encrypted, strong"), N_("This message is encrypted, with a strong encryption algorithm. It would be very difficult for an outsider to view the content of this message in a practical amount of time.") }, }; struct _smime_pobject { @@ -683,10 +685,11 @@ efhd_xpkcs7mime_button(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObje char *file; const char *name; - if (po->signature) - name = smime_sign_table[po->valid->sign.status].icon; + /* FIXME: need to have it based on encryption and signing too */ + if (po->valid->sign.status == CAMEL_CIPHER_VALIDITY_SIGN_GOOD) + name = "pgp-signature-ok.png"; else - name = smime_encrypt_table[po->valid->encrypt.status].icon; + name = "pgp-signature-bad.png"; file = g_build_filename(EVOLUTION_ICONSDIR, name, NULL); pixbuf = gdk_pixbuf_new_from_file(file, NULL); @@ -709,6 +712,50 @@ efhd_xpkcs7mime_button(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObje return TRUE; } +static void +efhd_output_secure(EMFormat *emf, CamelStream *stream, CamelMimePart *part, CamelCipherValidity *valid) +{ + CamelCipherValidity *save = ((EMFormatHTML *)emf)->valid_parent; + + /* Note: this same logic is in efh_output_secure */ + + if (((EMFormatHTML *)emf)->valid == NULL) { + ((EMFormatHTML *)emf)->valid = valid; + } else { + e_dlist_addtail(&((EMFormatHTML *)emf)->valid_parent->children, (EDListNode *)valid); + camel_cipher_validity_envelope(((EMFormatHTML *)emf)->valid_parent, valid); + } + + ((EMFormatHTML *)emf)->valid_parent = valid; + em_format_part(emf, stream, part); + ((EMFormatHTML *)emf)->valid_parent = save; + + if (((EMFormatHTML *)emf)->valid == valid + && (valid->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE + || valid->sign.status != CAMEL_CIPHER_VALIDITY_SIGN_NONE)) { + char *classid; + struct _smime_pobject *pobj; + + camel_stream_printf(stream, "", + valid->sign.status == CAMEL_CIPHER_VALIDITY_SIGN_GOOD?"#88bb88":"#bb8888"); + classid = g_strdup_printf("smime:///em-format-html/%p/icon/signed", part); + pobj = (struct _smime_pobject *)em_format_html_add_pobject((EMFormatHTML *)emf, sizeof(*pobj), classid, part, efhd_xpkcs7mime_button); + pobj->valid = camel_cipher_validity_clone(valid); + pobj->object.free = efhd_xpkcs7mime_free; + camel_stream_printf(stream, "
", classid); + + if (valid->sign.status != CAMEL_CIPHER_VALIDITY_SIGN_NONE) { + camel_stream_printf(stream, "%s
", _(smime_sign_table[valid->sign.status].shortdesc)); + } + + if (valid->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE) { + camel_stream_printf(stream, "%s
", _(smime_encrypt_table[valid->encrypt.status].shortdesc)); + } + + camel_stream_printf(stream, "
"); + } +} + static void efhd_application_xpkcs7mime(EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info) { @@ -728,46 +775,7 @@ efhd_application_xpkcs7mime(EMFormat *emf, CamelStream *stream, CamelMimePart *p em_format_format_error(emf, stream, ex->desc?ex->desc:_("Could not parse S/MIME message: Unknown error")); em_format_part_as(emf, stream, part, NULL); } else { - CamelCipherValidity *save = ((EMFormatHTML *)emf)->enveloped_validity; - - if (save != NULL) - camel_cipher_validity_envelope(valid, save); - - ((EMFormatHTML *)emf)->enveloped_validity = valid; - em_format_part(emf, stream, opart); - ((EMFormatHTML *)emf)->enveloped_validity = save; - - if (save != NULL - && (valid->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE - || valid->sign.status != CAMEL_CIPHER_VALIDITY_SIGN_NONE)) { - char *classid; - struct _smime_pobject *pobj; - - camel_stream_printf(stream, ""); - - if (valid->sign.status != CAMEL_CIPHER_VALIDITY_SIGN_NONE) { - classid = g_strdup_printf("smime:///em-format-html/%p/icon/signed", part); - pobj = (struct _smime_pobject *)em_format_html_add_pobject((EMFormatHTML *)emf, sizeof(*pobj), classid, part, efhd_xpkcs7mime_button); - pobj->valid = camel_cipher_validity_clone(valid); - pobj->signature = TRUE; - pobj->object.free = efhd_xpkcs7mime_free; - camel_stream_printf(stream, "", classid, valid->sign.description); - g_free(classid); - } - - if (valid->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE) { - classid = g_strdup_printf("smime:///em-format-html/%p/icon/encrypted", part); - pobj = (struct _smime_pobject *)em_format_html_add_pobject((EMFormatHTML *)emf, sizeof(*pobj), classid, part, efhd_xpkcs7mime_button); - pobj->valid = camel_cipher_validity_clone(valid); - pobj->object.free = efhd_xpkcs7mime_free; - camel_stream_printf(stream, "", classid, valid->encrypt.description); - g_free(classid); - } - - camel_stream_printf(stream, "

%s

%s
"); - } - - camel_cipher_validity_free(valid); + efhd_output_secure(emf, stream, opart, valid); } camel_object_unref(opart); @@ -777,48 +785,12 @@ efhd_application_xpkcs7mime(EMFormat *emf, CamelStream *stream, CamelMimePart *p /* ********************************************************************** */ -static void -efhd_signature_check(GtkWidget *w, EMFormatHTMLPObject *pobject) -{ - d(printf("insert signature check here ... redraw ? or what ?\n")); - /* blah, do the old way for now, force a complete re-draw */ - em_format_set_inline((EMFormat *)pobject->format, pobject->part, TRUE); - em_format_format_clone((EMFormat *)pobject->format, ((EMFormat *)pobject->format)->message, (EMFormat *)pobject->format); -} - -static gboolean -efhd_signature_button(EMFormatHTML *efh, GtkHTMLEmbedded *eb, EMFormatHTMLPObject *pobject) -{ - GtkWidget *icon, *button; - GdkPixbuf *pixbuf; - - pixbuf = gdk_pixbuf_new_from_file(EVOLUTION_ICONSDIR "/pgp-signature-nokey.png", NULL); - if (pixbuf == NULL) - return FALSE; - - /* wtf isn't this just scaled on disk? */ - icon = gtk_image_new_from_pixbuf(gdk_pixbuf_scale_simple(pixbuf, 24, 24, GDK_INTERP_BILINEAR)); - g_object_unref(pixbuf); - gtk_widget_show(icon); - - button = gtk_button_new(); - g_signal_connect(button, "clicked", G_CALLBACK (efhd_signature_check), pobject); - /*g_signal_connect (button, "key_press_event", G_CALLBACK (inline_button_press), part);*/ - - gtk_container_add((GtkContainer *)button, icon); - gtk_widget_show(button); - gtk_container_add((GtkContainer *)eb, button); - - return TRUE; -} - static void efhd_multipart_signed (EMFormat *emf, CamelStream *stream, CamelMimePart *part, const EMFormatHandler *info) { - char *classid; - static int signedid; CamelMultipartSigned *mps; CamelMimePart *cpart; + CamelCipherContext *cipher = NULL; mps = (CamelMultipartSigned *)camel_medium_get_content_object((CamelMedium *)part); if (!CAMEL_IS_MULTIPART_SIGNED(mps) @@ -827,31 +799,30 @@ efhd_multipart_signed (EMFormat *emf, CamelStream *stream, CamelMimePart *part, return; } - em_format_part(emf, stream, cpart); + /* FIXME: Should be done via a plugin interface */ + /* FIXME: duplicated in em-format-html.c */ + if (g_ascii_strcasecmp("application/x-pkcs7-signature", mps->protocol) == 0) + cipher = camel_smime_context_new(emf->session); + else if (g_ascii_strcasecmp("application/pgp-signature", mps->protocol) == 0) + cipher = camel_gpg_context_new(emf->session); - if (em_format_is_inline(emf, part)) { - em_format_html_multipart_signed_sign(emf, stream, part); + if (cipher == NULL) { + em_format_format_error(emf, stream, _("Unsupported signature format")); + em_format_part_as(emf, stream, part, NULL); } else { - classid = g_strdup_printf("multipart-signed:///icon/%d", signedid++); - - /* wtf is this so fugly? */ - camel_stream_printf(stream, - "
" - "" - "" - "" - "" - "
" - "
" - "
%s
" - "" - "" - "
\n", - classid, - _("This message is digitally signed. Click the lock icon for more information.")); - - em_format_html_add_pobject((EMFormatHTML *)emf, sizeof(EMFormatHTMLPObject), classid, part, efhd_signature_button); - g_free(classid); + CamelException *ex = camel_exception_new(); + CamelCipherValidity *valid; + + valid = camel_cipher_verify(cipher, part, ex); + if (valid == NULL) { + em_format_format_error(emf, stream, ex->desc?ex->desc:_("Unknown error verifying signature")); + em_format_part_as(emf, stream, part, NULL); + } else { + efhd_output_secure(emf, stream, cpart, valid); + } + + camel_exception_free(ex); + camel_object_unref(cipher); } } -- cgit v1.2.3