Bug #106507 --> if BUILD_SMIME is defined in the build environment (which it isn't), build the new smime

files.

The mime changes have been contributed by ddrinan@netscape.com
r=ducarroz
sr=mscott


git-svn-id: svn://10.0.0.236/trunk@107139 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
mscott%netscape.com
2001-11-03 00:31:15 +00:00
parent 3fe59f450a
commit a0c8ea554b
18 changed files with 585 additions and 333 deletions

View File

@@ -1,4 +1,4 @@
#
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
@@ -26,6 +26,10 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
ifdef BUILD_SMIME
DEFINES += -DENABLE_SMIME
endif
MODULE = mime
LIBRARY_NAME = mime_s
META_COMPONENT = mail
@@ -51,6 +55,8 @@ REQUIRES = xpcom \
mimetype \
uriloader \
xpconnect \
pipnss \
windowwatcher \
$(NULL)
CPPSRCS = \
@@ -93,6 +99,15 @@ CPPSRCS = \
nsStreamConverter.cpp \
mimedrft.cpp \
nsMimeHeaders.cpp \
mimecryp.cpp
ifdef BUILD_SMIME
CPPSRCS += \
mimecms.cpp \
mimemcms.cpp
endif
CPPSRCS += \
$(NULL)
EXPORTS = \

View File

@@ -42,6 +42,8 @@ REQUIRES = xpcom \
mimetype \
uriloader \
xpconnect \
pipnss \
windowwatcher \
$(NULL)
include <$(DEPTH)\config\config.mak>
@@ -79,6 +81,10 @@ LIBRARY_NAME=mime_s
DEFINES= -DEBUG_rhp
!if defined(BUILD_SMIME)
DEFINES = -DENABLE_SMIME $(DEFINES)
!endif
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
@@ -128,6 +134,11 @@ OBJS= \
.\$(OBJDIR)\nsMimeHeaders.obj \
# XP-COM BRIDGES
.\$(OBJDIR)\comi18n.obj \
.\$(OBJDIR)\mimecryp.obj \
!if defined(BUILD_SMIME)
.\$(OBJDIR)\mimecms.obj \
.\$(OBJDIR)\mimemcms.obj \
!endif
$(NULL)

View File

@@ -1,38 +1,37 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
* The Original Code is Mozilla Communicator.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* The Initial Developer of the Original Code is
* Netscape Communications Corp..
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* David Drinan <ddrinan@netscape.com>
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
@@ -130,10 +129,8 @@ MimeCMS_content_callback (void *arg, const char *buf, unsigned long length)
{
int status;
MimeCMSdata *data = (MimeCMSdata *) arg;
PR_ASSERT(data);
if (!data) return;
PR_ASSERT(data->output_fn);
if (!data->output_fn)
return;
@@ -152,7 +149,6 @@ MimeEncryptedCMS_encrypted_p (MimeObject *obj)
{
PRBool encrypted;
PR_ASSERT(obj);
if (!obj) return PR_FALSE;
if (mime_typep(obj, (MimeObjectClass *) &mimeEncryptedCMSClass))
{
@@ -180,21 +176,20 @@ MimeCMSHeadersAndCertsMatch(MimeObject *obj,
char **sender_email_addr_return)
{
MimeHeaders *msg_headers = 0;
char *from_addr = 0;
char *from_name = 0;
char *sender_addr = 0;
char *sender_name = 0;
char *cert_name = 0;
char *cert_addr = 0;
nsXPIDLCString from_addr;
nsXPIDLCString from_name;
nsXPIDLCString sender_addr;
nsXPIDLCString sender_name;
nsXPIDLCString cert_name;
nsXPIDLCString cert_addr;
PRBool match = PR_TRUE;
/* Find the name and address in the cert.
*/
PR_ASSERT(content_info);
if (content_info)
{
content_info->GetSignerCommonName (&cert_name);
content_info->GetSignerEmailAddress (&cert_addr);
content_info->GetSignerCommonName (getter_Copies(cert_name));
content_info->GetSignerEmailAddress (getter_Copies(cert_addr));
}
if (!cert_name && !cert_addr) goto DONE;
@@ -213,7 +208,6 @@ MimeCMSHeadersAndCertsMatch(MimeObject *obj,
}
}
PR_ASSERT(msg_headers);
if (!msg_headers) goto DONE;
/* Find the names and addresses in the From and/or Sender fields.
@@ -225,8 +219,7 @@ MimeCMSHeadersAndCertsMatch(MimeObject *obj,
s = MimeHeaders_get(msg_headers, HEADER_FROM, PR_FALSE, PR_FALSE);
if (s)
{
int n = ParseRFC822Addresses(s, &from_name, &from_addr);
PR_ASSERT(n <= 1);
int n = ParseRFC822Addresses(s, getter_Copies(from_name), getter_Copies(from_addr));
PR_FREEIF(s);
}
@@ -234,8 +227,7 @@ MimeCMSHeadersAndCertsMatch(MimeObject *obj,
s = MimeHeaders_get(msg_headers, HEADER_SENDER, PR_FALSE, PR_FALSE);
if (s)
{
int n = ParseRFC822Addresses(s, &sender_name, &sender_addr);
PR_ASSERT(n <= 1);
int n = ParseRFC822Addresses(s, getter_Copies(sender_name), getter_Copies(sender_addr));
PR_FREEIF(s);
}
}
@@ -250,10 +242,6 @@ MimeCMSHeadersAndCertsMatch(MimeObject *obj,
but the message headers do not.
*/
PR_ASSERT(match == PR_TRUE);
match = PR_TRUE;
/* ======================================================================
First check the addresses.
*/
@@ -267,20 +255,20 @@ MimeCMSHeadersAndCertsMatch(MimeObject *obj,
else if (from_addr && *from_addr &&
sender_addr && *sender_addr)
{
if (!!nsCRT::strcasecmp(cert_addr, from_addr) &&
!!nsCRT::strcasecmp(cert_addr, sender_addr))
if (nsCRT::strcasecmp(cert_addr, from_addr) &&
nsCRT::strcasecmp(cert_addr, sender_addr))
match = PR_FALSE;
}
/* If there is a from but no sender, and it doesn't match, then error. */
else if (from_addr && *from_addr)
{
if (!!nsCRT::strcasecmp(cert_addr, from_addr))
if (nsCRT::strcasecmp(cert_addr, from_addr))
match = PR_FALSE;
}
/* If there is a sender but no from, and it doesn't match, then error. */
else if (sender_addr && *sender_addr)
{
if (!!nsCRT::strcasecmp(cert_addr, sender_addr))
if (nsCRT::strcasecmp(cert_addr, sender_addr))
match = PR_FALSE;
}
/* Else there are no addresses at all -- error. */
@@ -290,64 +278,18 @@ MimeCMSHeadersAndCertsMatch(MimeObject *obj,
}
if (sender_email_addr_return)
{
if (match && cert_addr)
if (sender_email_addr_return) {
if (match && cert_addr)
*sender_email_addr_return = nsCRT::strdup(cert_addr);
else if (from_addr && *from_addr)
else if (from_addr && *from_addr)
*sender_email_addr_return = nsCRT::strdup(from_addr);
else if (sender_addr && *sender_addr)
else if (sender_addr && *sender_addr)
*sender_email_addr_return = nsCRT::strdup(sender_addr);
else
*sender_email_addr_return = 0;
}
/* ======================================================================
Next, check the names.
*/
#if 0
/* No, don't check the names, that's a nightmare that just won't end. */
if (match == PR_FALSE)
; /* nevermind */
/* If there is no name in the cert, then consider it a match. */
else if (!cert_name)
match = PR_TRUE;
/* If there is both a from and sender name, and if neither of
them match, then error. */
else if (from_name && *from_name &&
sender_name && *sender_name)
{
if (!!strcasecomp(cert_name, from_name) &&
!!strcasecomp(cert_name, sender_name))
match = PR_FALSE;
}
/* If there is a from but no sender, and it doesn't match, then error. */
else if (from_name && *from_name)
{
if (!!strcasecomp(cert_name, from_name))
match = PR_FALSE;
}
/* If there is a sender but no from, and it doesn't match, then error. */
else if (sender_name && *sender_name)
{
if (!!strcasecomp(cert_name, sender_name))
match = PR_FALSE;
else
*sender_email_addr_return = 0;
}
/* Else there are no names at all -- consider that a match. */
#endif /* 0 */
DONE:
PR_FREEIF(from_addr);
PR_FREEIF(from_name);
PR_FREEIF(sender_addr);
PR_FREEIF(sender_name);
PR_FREEIF(cert_addr);
PR_FREEIF(cert_name);
return match;
}
@@ -361,7 +303,6 @@ MimeCMS_init(MimeObject *obj,
MimeDisplayOptions *opts;
nsresult rv;
PR_ASSERT(obj && obj->options && output_fn);
if (!(obj && obj->options && output_fn)) return 0;
opts = obj->options;
@@ -381,7 +322,6 @@ MimeCMS_init(MimeObject *obj,
if (NS_FAILED(rv)) return 0;
// XXX Fix later XXX //
#if 0
data->parent_holds_stamp_p =
(obj->parent &&
(mime_crypto_stamped_p(obj->parent) ||
@@ -399,7 +339,6 @@ MimeCMS_init(MimeObject *obj,
obj->parent && obj->parent->parent)
data->parent_holds_stamp_p =
mime_crypto_stamped_p (obj->parent->parent);
#endif
return data;
}
@@ -410,7 +349,6 @@ MimeCMS_write (const char *buf, PRInt32 buf_size, void *closure)
MimeCMSdata *data = (MimeCMSdata *) closure;
nsresult rv;
PR_ASSERT(data && data->output_fn && data->decoder_context);
if (!data || !data->output_fn || !data->decoder_context) return -1;
PR_SetError(0, 0);
@@ -431,7 +369,6 @@ MimeCMS_eof (void *crypto_closure, PRBool abort_p)
nsCOMPtr<nsIPrompt> prompter;
wwatch->GetNewPrompter(0, getter_AddRefs(prompter));
PR_ASSERT(data && data->output_fn && data->decoder_context);
if (!data || !data->output_fn || !data->decoder_context)
return -1;
@@ -441,6 +378,9 @@ MimeCMS_eof (void *crypto_closure, PRBool abort_p)
We save away the value returned and will use it later to emit a
blurb about whether the signature validation was cool.
NOTE: We currently put up a dialog box to alert the user. This will go away
very soon
*/
PR_SetError(0, 0);
@@ -467,11 +407,8 @@ static void
MimeCMS_free (void *crypto_closure)
{
MimeCMSdata *data = (MimeCMSdata *) crypto_closure;
PR_ASSERT(data);
if (!data) return;
PR_ASSERT(!data->decoder_context);
PR_FREEIF(data->sender_addr);
if (data->content_info)
@@ -559,7 +496,6 @@ MimeCMS_generate (void *crypto_closure)
PRBool good_p = PR_TRUE;
PRBool unverified_p = PR_FALSE;
PR_ASSERT(data && data->output_fn);
if (!data || !data->output_fn) return 0;
if (data->content_info)
@@ -572,16 +508,10 @@ MimeCMS_generate (void *crypto_closure)
{
PR_SetError(0, 0);
good_p = data->content_info->VerifySignature();
#if 0 // XXX Fix this XXX //
good_p = SEC_PKCS7VerifySignature(data->content_info,
0, /*certUsageEmailSigner */ /* #### */
PR_TRUE); /* #### keepcerts */
#endif
if (!good_p)
{
if (!data->verify_error)
data->verify_error = PR_GetError();
PR_ASSERT(data->verify_error < 0);
if (data->verify_error >= 0)
data->verify_error = -1;
}
@@ -623,9 +553,8 @@ MimeCMS_generate (void *crypto_closure)
unverified_p = data->self->options->missing_parts;
PR_ASSERT(data->self);
if (data->self && data->self->parent)
// mime_set_crypto_stamp(data->self->parent, self_signed_p, self_encrypted_p); XXX Fix later XXX //
mime_set_crypto_stamp(data->self->parent, self_signed_p, self_encrypted_p);
{
@@ -639,7 +568,6 @@ MimeCMS_generate (void *crypto_closure)
stamp_url = MimeCMS_MakeSAURL(data->self);
}
#if 0 // XXX Fix this later XXX //
result =
MimeHeaders_make_crypto_stamp (union_encrypted_p,
self_signed_p,
@@ -647,7 +575,6 @@ MimeCMS_generate (void *crypto_closure)
unverified_p,
data->parent_holds_stamp_p,
stamp_url);
#endif
PR_FREEIF(stamp_url);
return result;
}

View File

@@ -1,38 +1,37 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
* The Original Code is Mozilla Communicator.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* The Initial Developer of the Original Code is
* Netscape Communications Corp..
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* David Drinan <ddrinan@netscape.com>
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */

View File

@@ -1,38 +1,37 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
* The Original Code is Mozilla Communicator.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* The Initial Developer of the Original Code is
* Netscape Communications Corp..
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* David Drinan <ddrinan@netscape.com>
* Contributor(s): David Drinan <ddrinan@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
@@ -103,7 +102,6 @@ MimeEncrypted_parse_begin (MimeObject *obj)
MimeEncrypted *enc = (MimeEncrypted *) obj;
MimeDecoderData *(*fn) (nsresult (*) (const char*, PRInt32, void*), void*) = 0;
PR_ASSERT(!enc->crypto_closure);
if (enc->crypto_closure)
return -1;
@@ -151,7 +149,6 @@ MimeEncrypted_parse_buffer (char *buffer, PRInt32 size, MimeObject *obj)
MimeEncrypted *enc = (MimeEncrypted *) obj;
PR_ASSERT(!obj->closed_p);
if (obj->closed_p) return -1;
/* Don't consult output_p here, since at this point we're behaving as a
@@ -261,17 +258,6 @@ MimeEncrypted_parse_end (MimeObject *obj, PRBool abort_p)
{
MimeEncrypted *enc = (MimeEncrypted *) obj;
/* Don't free these yet -- keep them around for the lifetime of the
MIME object, so that we can get at the security info of sub-parts
of the currently-displayed message. */
#if 0
if (enc->crypto_closure)
{
((MimeEncryptedClass *) obj->class)->crypto_free (enc->crypto_closure);
enc->crypto_closure = 0;
}
#endif /* 0 */
return ((MimeObjectClass*)&MIME_SUPERCLASS)->parse_end (obj, abort_p);
}
@@ -358,7 +344,6 @@ MimeHandleDecryptedOutputLine (char *line, PRInt32 length, MimeObject *obj)
MimeEncrypted *enc = (MimeEncrypted *) obj;
int status = 0;
PR_ASSERT(line && *line);
if (!line || !*line) return -1;
/* If we're supposed to write this object, but aren't supposed to convert
@@ -406,7 +391,6 @@ MimeEncrypted_close_headers (MimeObject *obj)
{
MimeEncrypted *enc = (MimeEncrypted *) obj;
PR_ASSERT(!enc->part_buffer);
if (enc->part_buffer) return -1;
enc->part_buffer = MimePartBufferCreate();
if (!enc->part_buffer)
@@ -420,11 +404,9 @@ static int
MimeEncrypted_add_child (MimeObject *parent, MimeObject *child)
{
MimeContainer *cont = (MimeContainer *) parent;
PR_ASSERT(parent && child);
if (!parent || !child) return -1;
/* Encryption containers can only have one child. */
PR_ASSERT(cont->nchildren == 0);
if (cont->nchildren != 0) return -1;
return ((MimeContainerClass*)&MIME_SUPERCLASS)->add_child (parent, child);

View File

@@ -1189,7 +1189,7 @@ mime_parse_stream_complete (nsMIMESession *stream)
status = mdd->obj->clazz->parse_eof ( mdd->obj, PR_FALSE );
mdd->obj->clazz->parse_end( mdd->obj, status < 0 ? PR_TRUE : PR_FALSE );
xlate_p = mdd->options->dexlate_p;
xlate_p = mdd->options->decrypt_p;
sign_p = mdd->options->signed_p;
// RICHIE
@@ -1845,7 +1845,7 @@ mime_decompose_file_init_fn ( void *stream_closure, MimeHeaders *headers )
//
// Initialize a decoder if necessary.
//
if (!newAttachment->encoding || mdd->options->dexlate_p)
if (!newAttachment->encoding || mdd->options->decrypt_p)
;
else if (!nsCRT::strcasecmp(newAttachment->encoding, ENCODING_BASE64))
fn = &MimeB64DecoderInit;

View File

@@ -1031,3 +1031,33 @@ MimeHeaders_write_raw_headers (MimeHeaders *hdrs, MimeDisplayOptions *opt,
return 0;
}
// XXX Fix this XXX //
char *
MimeHeaders_open_crypto_stamp(void)
{
return nsnull;
}
char *
MimeHeaders_finish_open_crypto_stamp(void)
{
return nsnull;
}
char *
MimeHeaders_close_crypto_stamp(void)
{
return nsnull;
}
char *
MimeHeaders_make_crypto_stamp(PRBool encrypted_p,
PRBool signed_p,
PRBool good_p,
PRBool unverified_p,
PRBool close_parent_stamp_p,
const char *stamp_url)
{
return nsnull;
}

View File

@@ -84,9 +84,23 @@ extern int MimeHeaders_write_raw_headers (MimeHeaders *hdrs,
PRBool dont_write_content_type);
#ifdef MOZ_SECURITY
HG77761
#endif
/* Some crypto-related HTML-generated utility routines.
* XXX This may not be needed. XXX
*/
extern char *MimeHeaders_open_crypto_stamp(void);
extern char *MimeHeaders_finish_open_crypto_stamp(void);
extern char *MimeHeaders_close_crypto_stamp(void);
extern char *MimeHeaders_make_crypto_stamp(PRBool encrypted_p,
PRBool signed_p,
PRBool good_p,
PRBool unverified_p,
PRBool close_parent_stamp_p,
const char *stamp_url);
/* Does all the heuristic silliness to find the filename in the given headers.
*/

View File

@@ -26,10 +26,6 @@
* 04/20/2000 IBM Corp. OS/2 VisualAge build.
*/
#ifdef MOZ_SECURITY
#include HG01966
#endif
#include "nsCOMPtr.h"
#include "mimeobj.h" /* MimeObject (abstract) */
#include "mimecont.h" /* |--- MimeContainer (abstract) */
@@ -42,7 +38,13 @@
#include "mimemapl.h" /* | | |--- MimeMultipartAppleDouble */
#include "mimesun.h" /* | | |--- MimeSunAttachment */
#include "mimemsig.h" /* | | |--- MimeMultipartSigned (abstract)*/
#ifdef ENABLE_SMIME
#include "mimemcms.h" /* | | |---MimeMultipartSignedCMS */
#endif
#include "mimecryp.h" /* | |--- MimeEncrypted (abstract) */
#ifdef ENABLE_SMIME
#include "mimecms.h" /* | | |--- MimeEncryptedPKCS7 */
#endif
#include "mimemsg.h" /* | |--- MimeMessage */
#include "mimeunty.h" /* | |--- MimeUntypedText */
@@ -383,7 +385,7 @@ mime_find_class (const char *content_type, MimeHeaders *hdrs,
clazz = (MimeObjectClass *)&mimeMultipartParallelClass;
else if (!nsCRT::strcasecmp(content_type+10, "mixed"))
clazz = (MimeObjectClass *)&mimeMultipartMixedClass;
#ifdef ENABLE_SMIME
else if (!nsCRT::strcasecmp(content_type+10, "signed"))
{
/* Check that the "protocol" and "micalg" parameters are ones we
@@ -399,14 +401,22 @@ mime_find_class (const char *content_type, MimeHeaders *hdrs,
? MimeHeaders_get_parameter(ct, PARAM_MICALG, NULL, NULL)
: 0);
#ifdef MOZ_SECURITY
HG01444
#endif
PR_FREEIF(proto);
if (proto && (!nsCRT::strcasecmp(proto, APPLICATION_XPKCS7_SIGNATURE) &&
micalg && (!nsCRT::strcasecmp(micalg, PARAM_MICALG_MD5) ||
!nsCRT::strcasecmp(micalg, PARAM_MICALG_SHA1) ||
!nsCRT::strcasecmp(micalg, PARAM_MICALG_SHA1_2) ||
!nsCRT::strcasecmp(micalg, PARAM_MICALG_SHA1_3) ||
!nsCRT::strcasecmp(micalg, PARAM_MICALG_SHA1_4) ||
!nsCRT::strcasecmp(micalg, PARAM_MICALG_SHA1_5) ||
!nsCRT::strcasecmp(micalg, PARAM_MICALG_MD2))))
clazz = (MimeObjectClass *)&mimeMultipartSignedCMSClass;
else
clazz = 0;
PR_FREEIF(proto);
PR_FREEIF(micalg);
PR_FREEIF(ct);
}
}
#endif
if (!clazz && !exact_match_p)
/* Treat all unknown multipart subtypes as "multipart/mixed" */
@@ -441,10 +451,10 @@ mime_find_class (const char *content_type, MimeHeaders *hdrs,
!nsCRT::strcasecmp(content_type, IMAGE_XBM3))
clazz = (MimeObjectClass *)&mimeInlineImageClass;
#ifdef MOZ_SECURITY
HG01555
#ifdef ENABLE_SMIME
else if (!nsCRT::strcasecmp(content_type, APPLICATION_XPKCS7_MIME))
clazz = (MimeObjectClass *)&mimeEncryptedCMSClass;
#endif
/* A few types which occur in the real world and which we would otherwise
treat as non-text types (which would be bad) without this special-case...
*/
@@ -779,11 +789,254 @@ mime_imap_part_address(MimeObject *obj)
return imap_part;
}
#ifdef MOZ_SECURITY
HG08555
HG92103
HG08232
#endif
#ifdef ENABLE_SMIME
/* Asks whether the given object is one of the cryptographically signed
or encrypted objects that we know about. (MimeMessageClass uses this
to decide if the headers need to be presented differently.)
*/
PRBool
mime_crypto_object_p(MimeHeaders *hdrs, PRBool clearsigned_counts)
{
char *ct;
MimeObjectClass *clazz;
if (!hdrs) return PR_FALSE;
ct = MimeHeaders_get (hdrs, HEADER_CONTENT_TYPE, PR_TRUE, PR_FALSE);
if (!ct) return PR_FALSE;
/* Rough cut -- look at the string before doing a more complex comparison. */
if (nsCRT::strcasecmp(ct, MULTIPART_SIGNED) &&
nsCRT::strncasecmp(ct, "application/", 12))
{
PR_Free(ct);
return PR_FALSE;
}
/* It's a candidate for being a crypto object. Let's find out for sure... */
clazz = mime_find_class (ct, hdrs, 0, PR_TRUE);
PR_Free(ct);
if (clazz == ((MimeObjectClass *)&mimeEncryptedCMSClass))
return PR_TRUE;
else if (clearsigned_counts &&
clazz == ((MimeObjectClass *)&mimeMultipartSignedCMSClass))
return PR_TRUE;
else
return PR_FALSE;
}
/* Whether the given object has written out the HTML version of its headers
in such a way that it will have a "crypto stamp" next to the headers. If
this is true, then the child must write out its HTML slightly differently
to take this into account...
*/
PRBool
mime_crypto_stamped_p(MimeObject *obj)
{
if (!obj) return PR_FALSE;
if (mime_typep (obj, (MimeObjectClass *) &mimeMessageClass))
return ((MimeMessage *) obj)->crypto_stamped_p;
else
return PR_FALSE;
}
/* Tells whether the given MimeObject is a message which has been encrypted
or signed. (Helper for MIME_GetMessageCryptoState()).
*/
void
mime_get_crypto_state (MimeObject *obj,
PRBool *signed_ret,
PRBool *encrypted_ret,
PRBool *signed_ok_ret,
PRBool *encrypted_ok_ret)
{
PRBool signed_p, encrypted_p;
if (signed_ret) *signed_ret = PR_FALSE;
if (encrypted_ret) *encrypted_ret = PR_FALSE;
if (signed_ok_ret) *signed_ok_ret = PR_FALSE;
if (encrypted_ok_ret) *encrypted_ok_ret = PR_FALSE;
PR_ASSERT(obj);
if (!obj) return;
if (!mime_typep (obj, (MimeObjectClass *) &mimeMessageClass))
return;
signed_p = ((MimeMessage *) obj)->crypto_msg_signed_p;
encrypted_p = ((MimeMessage *) obj)->crypto_msg_encrypted_p;
if (signed_ret)
*signed_ret = signed_p;
if (encrypted_ret)
*encrypted_ret = encrypted_p;
if ((signed_p || encrypted_p) &&
(signed_ok_ret || encrypted_ok_ret))
{
nsICMSMessage *encrypted_ci = 0;
nsICMSMessage *signed_ci = 0;
PRInt32 decode_error = 0, verify_error = 0;
char *addr = mime_part_address(obj);
mime_find_security_info_of_part(addr, obj,
&encrypted_ci,
&signed_ci,
0, /* email_addr */
&decode_error, &verify_error);
if (encrypted_p && encrypted_ok_ret)
*encrypted_ok_ret = (encrypted_ci && decode_error >= 0);
if (signed_p && signed_ok_ret)
*signed_ok_ret = (verify_error >= 0 && decode_error >= 0);
PR_FREEIF(addr);
}
}
/* How the crypto code tells the MimeMessage object what the crypto stamp
on it says. */
void
mime_set_crypto_stamp(MimeObject *obj, PRBool signed_p, PRBool encrypted_p)
{
if (!obj) return;
if (mime_typep (obj, (MimeObjectClass *) &mimeMessageClass))
{
MimeMessage *msg = (MimeMessage *) obj;
if (!msg->crypto_msg_signed_p)
msg->crypto_msg_signed_p = signed_p;
if (!msg->crypto_msg_encrypted_p)
msg->crypto_msg_encrypted_p = encrypted_p;
/* If the `decrypt_p' option is on, record whether any decryption has
actually occurred. */
if (encrypted_p &&
obj->options &&
obj->options->decrypt_p &&
obj->options->state)
{
/* decrypt_p and write_html_p are incompatible. */
PR_ASSERT(!obj->options->write_html_p);
obj->options->state->decrypted_p = PR_TRUE;
}
return; /* continue up the tree? I think that's not a good idea. */
}
if (obj->parent)
mime_set_crypto_stamp(obj->parent, signed_p, encrypted_p);
}
/* Given a part ID, looks through the MimeObject tree for a sub-part whose ID
number matches; if one is found, and if it represents a PKCS7-encrypted
object, returns information about the security status of that object.
`part' is not a URL -- it's of the form "1.3.5" and is interpreted relative
to the `obj' argument.
Returned values:
void **pkcs7_content_info_return
this is the SEC_PKCS7ContentInfo* of the object.
int32 *decode_error_return
this is the error code, if any, that the security library returned
while trying to parse the PKCS7 data (if this is negative, then it
probably means the message was corrupt in some way.)
int32 *verify_error_return
this is the error code, if any, that the security library returned
while trying to decrypt or verify or otherwise validate the data
(if this is negative, it might mean the message was corrupt, or might
mean the signature didn't match, or the cert was expired, or...)
*/
void
mime_find_security_info_of_part(const char *part, MimeObject *obj,
nsICMSMessage **pkcs7_encrypted_content_info_return,
nsICMSMessage **pkcs7_signed_content_info_return,
char **sender_email_addr_return,
PRInt32 *decode_error_return,
PRInt32 *verify_error_return)
{
obj = mime_address_to_part(part, obj);
*pkcs7_encrypted_content_info_return = 0;
*pkcs7_signed_content_info_return = 0;
*decode_error_return = 0;
*verify_error_return = 0;
if (sender_email_addr_return)
*sender_email_addr_return = 0;
if (!obj)
return;
/* If someone asks for the security info of a message/rfc822 object,
instead give them the security info of its child (the body of the
message.)
*/
if (mime_typep (obj, (MimeObjectClass *) &mimeMessageClass))
{
MimeContainer *cont = (MimeContainer *) obj;
if (cont->nchildren >= 1)
{
PR_ASSERT(cont->nchildren == 1);
obj = cont->children[0];
}
}
while (obj &&
(mime_typep(obj, (MimeObjectClass *) &mimeEncryptedCMSClass) ||
mime_typep(obj, (MimeObjectClass *) &mimeMultipartSignedCMSClass)))
{
nsICMSMessage *ci = 0;
PRInt32 decode_error = 0, verify_error = 0;
PRBool ci_is_encrypted = PR_FALSE;
char *sender = 0;
if (mime_typep(obj, (MimeObjectClass *) &mimeEncryptedCMSClass)) {
(((MimeEncryptedCMSClass *) (obj->clazz))
->get_content_info) (obj, &ci, &sender, &decode_error, &verify_error, &ci_is_encrypted);
} else if (mime_typep(obj,
(MimeObjectClass *) &mimeMultipartSignedCMSClass)) {
(((MimeMultipartSignedCMSClass *) (obj->clazz))
->get_content_info) (obj, &ci, &sender, &decode_error, &verify_error, &ci_is_encrypted);
}
if (ci) {
if (ci_is_encrypted) {
*pkcs7_encrypted_content_info_return = ci;
} else {
*pkcs7_signed_content_info_return = ci;
}
}
if (sender_email_addr_return)
*sender_email_addr_return = sender;
else
PR_FREEIF(sender);
if (*decode_error_return >= 0)
*decode_error_return = decode_error;
if (*verify_error_return >= 0)
*verify_error_return = verify_error;
PR_ASSERT(mime_typep(obj, (MimeObjectClass *) &mimeContainerClass) &&
((MimeContainer *) obj)->nchildren <= 1);
obj = ((((MimeContainer *) obj)->nchildren > 0)
? ((MimeContainer *) obj)->children[0]
: 0);
}
}
#endif // ENABLE_SMIME
/* Puts a part-number into a URL. If append_p is true, then the part number
is appended to any existing part-number already in that URL; otherwise,
@@ -1054,10 +1307,6 @@ mime_find_suggested_name_of_part(const char *part, MimeObject *obj)
return result;
}
#ifdef MOZ_SECURITY
HG78888
#endif
/* Parse the various "?" options off the URL and into the options struct.
*/
int
@@ -1362,3 +1611,4 @@ MimeObject_output_init(MimeObject *obj, const char *content_type)
}
return 0;
}

View File

@@ -220,6 +220,10 @@
typedef struct MimeObject MimeObject;
typedef struct MimeObjectClass MimeObjectClass;
#ifdef ENABLE_SMIME
class nsICMSMessage;
#endif // ENABLE_SMIME
/* (I don't pretend to understand this.) */
#define cpp_stringify_noop_helper(x)#x
#define cpp_stringify(x) cpp_stringify_noop_helper(x)
@@ -312,17 +316,52 @@ extern char *mime_find_suggested_name_of_part(const char *part,
*/
extern char *mime_find_content_type_of_part(const char *part, MimeObject *obj);
#ifdef MOZ_SECURITY
HG23957
#endif /* MOZ_SECURITY */
/* Parse the various "?" options off the URL and into the options struct.
*/
extern int mime_parse_url_options(const char *url, MimeDisplayOptions *);
#ifdef MOZ_SECURITY
HG22990
#endif
#ifdef ENABLE_SMIME
/* Given a part ID, looks through the MimeObject tree for a sub-part whose ID
number matches; if one is found, and if it represents a PKCS7-encrypted
object, returns information about the security status of that object.
`part' is not a URL -- it's of the form "1.3.5" and is interpreted relative
to the `obj' argument.
*/
extern void mime_find_security_info_of_part(const char *part, MimeObject *obj,
nsICMSMessage **cms_encrypt_content_info_return,
nsICMSMessage **cms_sign_content_info_return,
char **sender_email_addr_return,
PRInt32 *decode_error_return,
PRInt32 *verify_error_return);
/* Asks whether the given object is one of the cryptographically signed
or encrypted objects that we know about. (MimeMessageClass uses this
to decide if the headers need to be presented differently.)
*/
extern PRBool mime_crypto_object_p(MimeHeaders *, PRBool clearsigned_counts);
/* Tells whether the given MimeObject is a message which has been encrypted
or signed. (Helper for MIME_GetMessageCryptoState()).
*/
extern void mime_get_crypto_state (MimeObject *obj,
PRBool *signed_p, PRBool *encrypted_p,
PRBool *signed_ok, PRBool *encrypted_ok);
/* Whether the given object has written out the HTML version of its headers
in such a way that it will have a "crypto stamp" next to the headers. If
this is true, then the child must write out its HTML slightly differently
to take this into account...
*/
extern PRBool mime_crypto_stamped_p(MimeObject *obj);
/* How the crypto code tells the MimeMessage object what the crypto stamp
on it says. */
extern void mime_set_crypto_stamp(MimeObject *obj,
PRBool signed_p, PRBool encrypted_p);
#endif // ENABLE_SMIME
struct MimeParseStateObject {
@@ -348,7 +387,7 @@ struct MimeParseStateObject {
PRBool first_data_written_p; /* State used for Mozilla lazy-stream-
creation evilness. */
PRBool xlated_p; /* If options->dexlate_p is true, then this
PRBool decrypted_p; /* If options->dexlate_p is true, then this
will be set to indicate whether any
dexlateion did in fact occur.
*/

View File

@@ -1,38 +1,37 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
* The Original Code is Mozilla Communicator.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* The Initial Developer of the Original Code is
* Netscape Communications Corp..
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* David Drinan <ddrinan@netscape.com>
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
@@ -185,9 +184,6 @@ MimeMultCMS_init (MimeObject *obj)
data->self = obj;
data->hash_type = hash_type;
PR_ASSERT(!data->data_hash_context);
PR_ASSERT(!data->sig_decoder_context);
data->data_hash_context = do_CreateInstance(NS_HASH_CONTRACTID, &rv);
if (NS_FAILED(rv)) return 0;
@@ -229,15 +225,15 @@ static int
MimeMultCMS_data_hash (char *buf, PRInt32 size, void *crypto_closure)
{
MimeMultCMSdata *data = (MimeMultCMSdata *) crypto_closure;
PR_ASSERT(data && data->data_hash_context);
if (!data || !data->data_hash_context) return -1;
PR_ASSERT(!data->sig_decoder_context);
if (!data || !data->data_hash_context) {
return -1;
}
PR_SetError(0, 0);
data->data_hash_context->Update((unsigned char *) buf, size);
if (!data->verify_error)
data->verify_error = PR_GetError();
if (!data->verify_error) {
data->verify_error = PR_GetError();
}
return 0;
}
@@ -246,10 +242,9 @@ static int
MimeMultCMS_data_eof (void *crypto_closure, PRBool abort_p)
{
MimeMultCMSdata *data = (MimeMultCMSdata *) crypto_closure;
PR_ASSERT(data && data->data_hash_context);
if (!data || !data->data_hash_context) return -1;
PR_ASSERT(!data->sig_decoder_context);
if (!data || !data->data_hash_context) {
return -1;
}
data->data_hash_context->ResultLen(data->hash_type, &data->item_len);
data->item_data = (unsigned char *) PR_MALLOC(data->item_len);
@@ -257,8 +252,9 @@ MimeMultCMS_data_eof (void *crypto_closure, PRBool abort_p)
PR_SetError(0, 0);
data->data_hash_context->End(data->item_data, &data->item_len, data->item_len);
if (!data->verify_error)
data->verify_error = PR_GetError();
if (!data->verify_error) {
data->verify_error = PR_GetError();
}
// Release our reference to nsIHash //
data->data_hash_context = 0;
@@ -282,11 +278,9 @@ MimeMultCMS_sig_init (void *crypto_closure,
int status = 0;
nsresult rv;
PR_ASSERT(!data->data_hash_context);
PR_ASSERT(!data->sig_decoder_context);
PR_ASSERT(signature_hdrs);
if (!signature_hdrs) return -1;
if (!signature_hdrs) {
return -1;
}
ct = MimeHeaders_get (signature_hdrs, HEADER_CONTENT_TYPE, PR_TRUE, PR_FALSE);
@@ -303,7 +297,6 @@ MimeMultCMS_sig_init (void *crypto_closure,
rv = data->sig_decoder_context->Start(nsnull, nsnull);
if (NS_FAILED(rv)) {
status = PR_GetError();
PR_ASSERT(status < 0);
if (status >= 0) status = -1;
}
return status;
@@ -316,16 +309,14 @@ MimeMultCMS_sig_hash (char *buf, PRInt32 size, void *crypto_closure)
MimeMultCMSdata *data = (MimeMultCMSdata *) crypto_closure;
nsresult rv;
PR_ASSERT(data && data->sig_decoder_context);
if (!data || !data->sig_decoder_context) return -1;
PR_ASSERT(!data->data_hash_context);
if (!data || !data->sig_decoder_context) {
return -1;
}
rv = data->sig_decoder_context->Update(buf, size);
if (NS_FAILED(rv)) {
if (!data->verify_error)
data->verify_error = PR_GetError();
PR_ASSERT(data->verify_error < 0);
if (data->verify_error >= 0)
data->verify_error = -1;
}
@@ -338,9 +329,9 @@ MimeMultCMS_sig_eof (void *crypto_closure, PRBool abort_p)
{
MimeMultCMSdata *data = (MimeMultCMSdata *) crypto_closure;
if (!data) return -1;
PR_ASSERT(!data->data_hash_context);
if (!data) {
return -1;
}
/* Hand an EOF to the crypto library.
@@ -348,21 +339,16 @@ MimeMultCMS_sig_eof (void *crypto_closure, PRBool abort_p)
blurb about whether the signature validation was cool.
*/
PR_ASSERT(!data->content_info);
if (data->sig_decoder_context)
{
if (data->sig_decoder_context) {
data->sig_decoder_context->Finish(getter_AddRefs(data->content_info));
// Release our reference to nsICMSDecoder //
data->sig_decoder_context = 0;
if (!data->content_info && !data->verify_error)
data->verify_error = PR_GetError();
PR_ASSERT(data->content_info ||
data->verify_error || data->decode_error);
}
if (!data->content_info && !data->verify_error) {
data->verify_error = PR_GetError();
}
}
return 0;
}
@@ -371,7 +357,6 @@ static void
MimeMultCMS_free (void *crypto_closure)
{
MimeMultCMSdata *data = (MimeMultCMSdata *) crypto_closure;
PR_ASSERT(data);
if (!data) return;
PR_FREEIF(data->sender_addr);
@@ -412,7 +397,6 @@ MimeMultCMS_generate (void *crypto_closure)
nsCOMPtr<nsIPrompt> prompter;
wwatch->GetNewPrompter(0, getter_AddRefs(prompter));
PR_ASSERT(data);
if (!data) return 0;
encrypted_p = data->parent_is_encrypted_p;
@@ -422,7 +406,6 @@ MimeMultCMS_generate (void *crypto_closure)
if (NS_FAILED(rv)) {
if (!data->verify_error)
data->verify_error = PR_GetError();
PR_ASSERT(data->verify_error < 0);
if (data->verify_error >= 0)
data->verify_error = -1;
} else {
@@ -471,7 +454,6 @@ MimeMultCMS_generate (void *crypto_closure)
unverified_p = data->self->options->missing_parts;
PR_ASSERT(data->self);
if (data->self && data->self->parent)
mime_set_crypto_stamp(data->self->parent, signed_p, encrypted_p);

View File

@@ -1,38 +1,37 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
* The Original Code is Mozilla Communicator.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* The Initial Developer of the Original Code is
* Netscape Communications Corp..
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* David Drinan <ddrinan@netscape.com>
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */

View File

@@ -1266,7 +1266,7 @@ MimeDisplayOptions::MimeDisplayOptions()
write_html_p = PR_FALSE;
dexlate_p = PR_FALSE;
decrypt_p = PR_FALSE;
nice_html_only_p = PR_FALSE;
@@ -1528,7 +1528,7 @@ mime_bridge_create_display_stream(
msd->obj = obj;
/* Both of these better not be true at the same time. */
PR_ASSERT(! (obj->options->dexlate_p && obj->options->write_html_p));
PR_ASSERT(! (obj->options->decrypt_p && obj->options->write_html_p));
stream = PR_NEW(nsMIMESession);
if (!stream)

View File

@@ -205,7 +205,7 @@ MimeMessage_parse_line (char *line, PRInt32 length, MimeObject *obj)
! obj->options->is_multipart_msg &&
obj->options->decompose_file_output_fn )
{
if (!obj->options->dexlate_p) {
if (!obj->options->decrypt_p) {
status = obj->options->decompose_file_output_fn (line,
length,
obj->options->stream_closure);
@@ -411,7 +411,7 @@ HG09091
status = MimeObject_write(obj, "", 0, PR_FALSE); /* initialize */
if (status < 0) return status;
status = MimeHeaders_write_raw_headers(msg->hdrs, obj->options,
obj->options->dexlate_p);
obj->options->decrypt_p);
if (status < 0) return status;
}
@@ -738,7 +738,7 @@ MimeMessage_write_headers_html (MimeObject *obj)
return status;
}
if (msg->xlation_stamped_p)
if (msg->crypto_stamped_p)
{
#ifdef MOZ_SECURITY
HG11995

View File

@@ -57,12 +57,12 @@ struct MimeMessage {
MimeContainer container; /* superclass variables */
MimeHeaders *hdrs; /* headers of this message */
PRBool newline_p; /* whether the last line ended in a newline */
PRBool xlation_stamped_p; /* whether the header of this message has been
PRBool crypto_stamped_p; /* whether the header of this message has been
emitted expecting its child to emit HTML
which says that it is xlated. */
PRBool xlation_msg_signed_p; /* What the emitted xlation-stamp *says*. */
PRBool xlation_msg_xlated_p;
PRBool crypto_msg_signed_p; /* What the emitted xlation-stamp *says*. */
PRBool crypto_msg_encrypted_p;
PRBool grabSubject; /* Should we try to grab the subject of this message */
};

View File

@@ -117,9 +117,13 @@ MimeMultipartSigned_cleanup (MimeObject *obj, PRBool finalizing_p)
mult->state = MimeMultipartEpilogue; /* #58075. Fix suggested by jwz */
sig->state = MimeMultipartSignedEpilogue;
#ifdef MOZ_SECURITY
HG09003
#endif /* MOZ_SECURITY */
if (finalizing_p && sig->crypto_closure) {
/* Don't free these until this object is really going away -- keep them
around for the lifetime of the MIME object, so that we can get at the
security info of sub-parts of the currently-displayed message. */
((MimeMultipartSignedClass *) obj->clazz)->crypto_free (sig->crypto_closure);
sig->crypto_closure = 0;
}
if (sig->sig_decoder_data)
{
@@ -128,7 +132,6 @@ HG09003
}
}
static int
MimeMultipartSigned_parse_eof (MimeObject *obj, PRBool abort_p)
{
@@ -144,9 +147,8 @@ MimeMultipartSigned_parse_eof (MimeObject *obj, PRBool abort_p)
sig->state == MimeMultipartSignedSignatureLine ||
sig->state == MimeMultipartSignedEpilogue)
{
#ifdef MOZ_SECURITY
HG77782
#endif /* MOZ_SECURITY */
status = (((MimeMultipartSignedClass *) obj->clazz)->crypto_signature_eof) (sig->crypto_closure, abort_p);
if (status < 0) return status;
}
if (!abort_p)
@@ -286,14 +288,14 @@ MimeMultipartSigned_parse_line (char *line, PRInt32 length, MimeObject *obj)
case MimeMultipartSignedBodyHeaders:
case MimeMultipartSignedBodyLine:
if (!sig->xlation_closure)
if (!sig->crypto_closure)
{
/* Set error change */
PR_SetError(0, 0);
/* Initialize the signature verification library. */
sig->xlation_closure = (((MimeMultipartSignedClass *) obj->clazz)
->xlation_init) (obj);
if (!sig->xlation_closure)
sig->crypto_closure = (((MimeMultipartSignedClass *) obj->clazz)
->crypto_init) (obj);
if (!sig->crypto_closure)
{
status = PR_GetError();
PR_ASSERT(status < 0);
@@ -324,7 +326,7 @@ MimeMultipartSigned_parse_line (char *line, PRInt32 length, MimeObject *obj)
of after, except for the first line, which is not preceeded by a
newline.
For purposes of xlationgraphic hashing, we always hash line
For purposes of cryptographic hashing, we always hash line
breaks as CRLF -- the canonical, on-the-wire linebreaks, since
we have no idea of knowing what line breaks were used on the
originating system (SMTP rightly destroys that information.)
@@ -334,28 +336,28 @@ MimeMultipartSigned_parse_line (char *line, PRInt32 length, MimeObject *obj)
if (length > 0 && line[length-1] == nsCRT::LF) length--;
if (length > 0 && line[length-1] == nsCRT::CR) length--;
PR_ASSERT(sig->xlation_closure);
PR_ASSERT(sig->crypto_closure);
if (!first_line_p)
{
/* Push out a preceeding newline... */
char nl[] = CRLF;
status = (((MimeMultipartSignedClass *) obj->clazz)
->xlation_data_hash (nl, 2, sig->xlation_closure));
->crypto_data_hash (nl, 2, sig->crypto_closure));
if (status < 0) return status;
}
/* Now push out the line sans trailing newline. */
if (length > 0)
status = (((MimeMultipartSignedClass *) obj->clazz)
->xlation_data_hash (line,length, sig->xlation_closure));
->crypto_data_hash (line,length, sig->crypto_closure));
if (status < 0) return status;
}
break;
case MimeMultipartSignedSignatureHeaders:
if (sig->xlation_closure &&
if (sig->crypto_closure &&
old_state != mult->state)
{
/* We have just moved out of the MimeMultipartSignedBodyLine
@@ -363,7 +365,7 @@ MimeMultipartSigned_parse_line (char *line, PRInt32 length, MimeObject *obj)
reached the end of the signed data.
*/
status = (((MimeMultipartSignedClass *) obj->clazz)
->xlation_data_eof) (sig->xlation_closure, PR_FALSE);
->crypto_data_eof) (sig->crypto_closure, PR_FALSE);
if (status < 0) return status;
}
break;
@@ -403,18 +405,18 @@ MimeMultipartSigned_parse_line (char *line, PRInt32 length, MimeObject *obj)
sig->sig_decoder_data =
fn (((nsresult (*) (const char *, PRInt32, void *))
(((MimeMultipartSignedClass *) obj->clazz)
->xlation_signature_hash)),
sig->xlation_closure);
->crypto_signature_hash)),
sig->crypto_closure);
if (!sig->sig_decoder_data)
return MIME_OUT_OF_MEMORY;
}
}
/* Show these headers to the xlation module. */
/* Show these headers to the crypto module. */
if (hash_line_p)
{
status = (((MimeMultipartSignedClass *) obj->clazz)
->xlation_signature_init) (sig->xlation_closure,
->crypto_signature_init) (sig->crypto_closure,
obj, sig->sig_hdrs);
if (status < 0) return status;
}
@@ -430,8 +432,8 @@ MimeMultipartSigned_parse_line (char *line, PRInt32 length, MimeObject *obj)
status = MimeDecoderWrite (sig->sig_decoder_data, line, length);
else
status = (((MimeMultipartSignedClass *) obj->clazz)
->xlation_signature_hash (line, length,
sig->xlation_closure));
->crypto_signature_hash (line, length,
sig->crypto_closure));
if (status < 0) return status;
}
break;
@@ -597,7 +599,7 @@ MimeMultipartSigned_emit_child (MimeObject *obj)
int status = 0;
MimeObject *body;
PR_ASSERT(sig->xlation_closure);
PR_ASSERT(sig->crypto_closure);
/* Emit some HTML saying whether the signature was cool.
But don't emit anything if in FO_QUOTE_MESSAGE mode.
@@ -607,17 +609,19 @@ MimeMultipartSigned_emit_child (MimeObject *obj)
obj->options->write_html_p &&
obj->options->output_fn &&
obj->options->headers != MimeHeadersCitation &&
sig->xlation_closure)
sig->crypto_closure)
{
char *html = (((MimeMultipartSignedClass *) obj->clazz)
->xlation_generate_html (sig->xlation_closure));
->crypto_generate_html (sig->crypto_closure));
#if 0 // XXX For the moment, no HTML output. Fix this XXX //
if (!html) return -1; /* MIME_OUT_OF_MEMORY? */
status = MimeObject_write(obj, html, nsCRT::strlen(html), PR_FALSE);
PR_Free(html);
if (status < 0) return status;
#endif
/* Now that we have written out the xlation stamp, the outermost header
/* Now that we have written out the crypto stamp, the outermost header
block is well and truly closed. If this is in fact the outermost
message, then run the post_header_html_fn now.
*/

View File

@@ -43,63 +43,63 @@
#include "modmimee.h"
/* The MimeMultipartSigned class implements the multipart/signed MIME
container, which provides a general method of associating a xlationgraphic
container, which provides a general method of associating a cryptographic
signature to an arbitrary MIME object.
The MimeMultipartSigned class provides the following methods:
void *xlation_init (MimeObject *multipart_object)
void *crypto_init (MimeObject *multipart_object)
This is called with the object, the object->headers of which should be
used to initialize the dexlateion engine. NULL indicates failure;
otherwise, an opaque closure object should be returned.
int xlation_data_hash (char *data, PRInt32 data_size,
void *xlation_closure)
int crypto_data_hash (char *data, PRInt32 data_size,
void *crypto_closure)
This is called with the raw data, for which a signature has been computed.
The xlation module should examine this, and compute a signature for it.
The crypto module should examine this, and compute a signature for it.
int xlation_data_eof (void *xlation_closure, PRBool abort_p)
int crypto_data_eof (void *crypto_closure, PRBool abort_p)
This is called when no more data remains. If `abort_p' is true, then the
xlation module may choose to discard any data rather than processing it,
crypto module may choose to discard any data rather than processing it,
as we're terminating abnormally.
int xlation_signature_init (void *xlation_closure,
int crypto_signature_init (void *crypto_closure,
MimeObject *multipart_object,
MimeHeaders *signature_hdrs)
This is called after xlation_data_eof() and just before the first call to
xlation_signature_hash(). The xlation module may wish to do some
This is called after crypto_data_eof() and just before the first call to
crypto_signature_hash(). The crypto module may wish to do some
initialization here, or may wish to examine the actual headers of the
signature object itself.
int xlation_signature_hash (char *data, PRInt32 data_size,
void *xlation_closure)
int crypto_signature_hash (char *data, PRInt32 data_size,
void *crypto_closure)
This is called with the raw data of the detached signature block. It will
be called after xlation_data_eof() has been called to signify the end of
be called after crypto_data_eof() has been called to signify the end of
the data which is signed. This data is the data of the signature itself.
int xlation_signature_eof (void *xlation_closure, PRBool abort_p)
int crypto_signature_eof (void *crypto_closure, PRBool abort_p)
This is called when no more signature data remains. If `abort_p' is true,
then the xlation module may choose to discard any data rather than
then the crypto module may choose to discard any data rather than
processing it, as we're terminating abnormally.
char * xlation_generate_html (void *xlation_closure)
char * crypto_generate_html (void *crypto_closure)
This is called after `xlation_signature_eof' but before `xlation_free'.
The xlation module should return a newly-allocated string of HTML code
This is called after `crypto_signature_eof' but before `crypto_free'.
The crypto module should return a newly-allocated string of HTML code
which explains the status of the dexlateion to the user (whether the
signature checks out, etc.)
void xlation_free (void *xlation_closure)
void crypto_free (void *crypto_closure)
This will be called when we're all done, after `xlation_signature_eof' and
`xlation_emit_html'. It is intended to free any data represented by the
xlation_closure.
This will be called when we're all done, after `crypto_signature_eof' and
`crypto_emit_html'. It is intended to free any data represented by the
crypto_closure.
*/
typedef struct MimeMultipartSignedClass MimeMultipartSignedClass;
@@ -121,23 +121,23 @@ struct MimeMultipartSignedClass {
MimeMultipartClass multipart;
/* Callbacks used by dexlateion (really, signature verification) module. */
void * (*xlation_init) (MimeObject *multipart_object);
void * (*crypto_init) (MimeObject *multipart_object);
int (*xlation_data_hash) (char *data, PRInt32 data_size,
void *xlation_closure);
int (*xlation_signature_hash) (char *data, PRInt32 data_size,
void *xlation_closure);
int (*crypto_data_hash) (char *data, PRInt32 data_size,
void *crypto_closure);
int (*crypto_signature_hash) (char *data, PRInt32 data_size,
void *crypto_closure);
int (*xlation_data_eof) (void *xlation_closure, PRBool abort_p);
int (*xlation_signature_eof) (void *xlation_closure, PRBool abort_p);
int (*crypto_data_eof) (void *crypto_closure, PRBool abort_p);
int (*crypto_signature_eof) (void *crypto_closure, PRBool abort_p);
int (*xlation_signature_init) (void *xlation_closure,
int (*crypto_signature_init) (void *crypto_closure,
MimeObject *multipart_object,
MimeHeaders *signature_hdrs);
char * (*xlation_generate_html) (void *xlation_closure);
char * (*crypto_generate_html) (void *crypto_closure);
void (*xlation_free) (void *xlation_closure);
void (*crypto_free) (void *crypto_closure);
};
extern "C" MimeMultipartSignedClass mimeMultipartSignedClass;
@@ -146,7 +146,7 @@ struct MimeMultipartSigned {
MimeMultipart multipart;
MimeMultipartSignedParseState state; /* State of parser */
void *xlation_closure; /* Opaque data used by signature
void *crypto_closure; /* Opaque data used by signature
verification module. */
MimeHeaders *body_hdrs; /* The headers of the signed object. */

View File

@@ -196,7 +196,7 @@ public:
PRBool write_html_p; /* Whether the output should be HTML, or raw. */
PRBool dexlate_p; /* Whether all traces of xlateion should be
PRBool decrypt_p; /* Whether all traces of xlateion should be
eradicated -- this is only meaningful when
write_html_p is PR_FALSE; we set this when
attaching a message for forwarding, since