Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
nsMsgComposeSecure.cpp File Reference
#include "nsMsgComposeSecure.h"
#include "nspr.h"
#include "nsCOMPtr.h"
#include "nsIX509Cert.h"
#include "nsISMimeCert.h"
#include "nsIMimeConverter.h"
#include "nsMimeStringResources.h"
#include "nsMimeTypes.h"
#include "nsIX509CertDB.h"
#include "nsMsgBaseCID.h"
#include "nsIMsgHeaderParser.h"
#include "nsFileStream.h"
#include "nsIServiceManager.h"
#include "nsIMsgIdentity.h"
#include "nsIMsgCompFields.h"
#include "nsCRT.h"
#include "nsReadableUtils.h"
#include "nsArray.h"
#include "prprf.h"
#include "prmem.h"
#include "nsMsgMimeCID.h"

Go to the source code of this file.

Defines

#define MIME_MULTIPART_SIGNED_BLURB   "This is a cryptographically signed message in MIME format."
#define MIME_SMIME_ENCRYPTED_CONTENT_DESCRIPTION   "S/MIME Encrypted Message"
#define MIME_SMIME_SIGNATURE_CONTENT_DESCRIPTION   "S/MIME Cryptographic Signature"
#define MK_MIME_ERROR_WRITING_FILE   -1
#define SMIME_STRBUNDLE_URL   "chrome://messenger/locale/am-smime.properties"

Functions

static void mime_crypto_write_base64 (void *closure, const char *buf, unsigned long size)
static nsresult PR_CALLBACK mime_encoder_output_fn (const char *buf, PRInt32 size, void *closure)
static nsresult PR_CALLBACK mime_nested_encoder_output_fn (const char *buf, PRInt32 size, void *closure)
static int make_multipart_signed_header_string (PRBool outer_p, char **header_return, char **boundary_return)
static char * mime_make_separator (const char *prefix)
MimeEncoderDataMIME_B64EncoderInit (nsresult(*PR_CALLBACK output_fn)(const char *buf, PRInt32 size, void *closure), void *closure)
MimeEncoderDataMIME_QPEncoderInit (nsresult(*PR_CALLBACK output_fn)(const char *buf, PRInt32 size, void *closure), void *closure)
MimeEncoderDataMIME_UUEncoderInit (char *filename, nsresult(*PR_CALLBACK output_fn)(const char *buf, PRInt32 size, void *closure), void *closure)
nsresult MIME_EncoderDestroy (MimeEncoderData *data, PRBool abort_p)
nsresult MIME_EncoderWrite (MimeEncoderData *data, const char *buffer, PRInt32 size)
static void GenerateGlobalRandomBytes (unsigned char *buf, PRInt32 len)

Define Documentation

#define MIME_MULTIPART_SIGNED_BLURB   "This is a cryptographically signed message in MIME format."

Definition at line 65 of file nsMsgComposeSecure.cpp.

Definition at line 66 of file nsMsgComposeSecure.cpp.

#define MIME_SMIME_SIGNATURE_CONTENT_DESCRIPTION   "S/MIME Cryptographic Signature"

Definition at line 67 of file nsMsgComposeSecure.cpp.

Definition at line 69 of file nsMsgComposeSecure.cpp.

#define SMIME_STRBUNDLE_URL   "chrome://messenger/locale/am-smime.properties"

Definition at line 71 of file nsMsgComposeSecure.cpp.


Function Documentation

static void GenerateGlobalRandomBytes ( unsigned char *  buf,
PRInt32  len 
) [static]

Definition at line 162 of file nsMsgComposeSecure.cpp.

{
  static PRBool    firstTime = PR_TRUE;
  
  if (firstTime)
  {
    // Seed the random-number generator with current time so that
    // the numbers will be different every time we run.
    PRInt32 aTime;
    LL_L2I(aTime, PR_Now());
    srand( (unsigned)aTime );
    firstTime = PR_FALSE;
  }
  
  for( PRInt32 i = 0; i < len; i++ )
    buf[i] = rand() % 10;
}

Here is the call graph for this function:

static int make_multipart_signed_header_string ( PRBool  outer_p,
char **  header_return,
char **  boundary_return 
) [static]

Definition at line 1076 of file nsMsgComposeSecure.cpp.

{
  *header_return = 0;
  *boundary_return = mime_make_separator("ms");
  const char * crypto_multipart_blurb = nsnull;

  if (!*boundary_return)
       return NS_ERROR_OUT_OF_MEMORY;

  if (outer_p) {
         crypto_multipart_blurb = MIME_MULTIPART_SIGNED_BLURB;
  }

  *header_return =
       PR_smprintf("Content-Type: " MULTIPART_SIGNED "; "
                            "protocol=\"" APPLICATION_XPKCS7_SIGNATURE "\"; "
                            "micalg=" PARAM_MICALG_SHA1 "; "
                            "boundary=\"%s\"" CRLF
                            CRLF
                            "%s%s"
                            "--%s" CRLF,

                            *boundary_return,
                            (crypto_multipart_blurb ? crypto_multipart_blurb : ""),
                            (crypto_multipart_blurb ? CRLF CRLF : ""),
                            *boundary_return);

  if (!*header_return) {
         PR_Free(*boundary_return);
         *boundary_return = 0;
         return NS_ERROR_OUT_OF_MEMORY;
       }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

MimeEncoderData* MIME_B64EncoderInit ( nsresult(*)(const char *buf, PRInt32 size, void *closure output_fn,
void closure 
)

Definition at line 91 of file nsMsgComposeSecure.cpp.

{
  MimeEncoderData *returnEncoderData = nsnull;
  nsIMimeConverter *converter;
  nsresult res = CallCreateInstance(NS_MIME_CONVERTER_CONTRACTID, &converter);
  if (NS_SUCCEEDED(res) && nsnull != converter) 
  {
    res = converter->B64EncoderInit(output_fn, closure, &returnEncoderData);
    NS_RELEASE(converter);
  }
  return NS_SUCCEEDED(res) ? returnEncoderData : nsnull;
}

Here is the call graph for this function:

static void mime_crypto_write_base64 ( void closure,
const char *  buf,
unsigned long  size 
) [static]

Definition at line 1124 of file nsMsgComposeSecure.cpp.

{
  MimeEncoderData *data = (MimeEncoderData *) closure;
  int status = MIME_EncoderWrite (data, buf, size);
  PR_SetError(status < 0 ? status : 0, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsresult PR_CALLBACK mime_encoder_output_fn ( const char *  buf,
PRInt32  size,
void closure 
) [static]

Definition at line 133 of file nsMsgComposeSecure.cpp.

{
  //MimeEncoderData *returnEncoderData = nsnull;
  nsIMimeConverter *converter;
  nsresult res = CallCreateInstance(NS_MIME_CONVERTER_CONTRACTID, &converter);
  if (NS_SUCCEEDED(res) && nsnull != converter) 
  {
    res = converter->EncoderDestroy(data, abort_p);
    NS_RELEASE(converter);
  }

  return NS_SUCCEEDED(res) ? 0 : -1;
}

Here is the call graph for this function:

nsresult MIME_EncoderWrite ( MimeEncoderData data,
const char *  buffer,
PRInt32  size 
)

Definition at line 148 of file nsMsgComposeSecure.cpp.

{
  //  MimeEncoderData *returnEncoderData = nsnull;
  nsIMimeConverter *converter;
  PRInt32 written = 0;
  nsresult res = CallCreateInstance(NS_MIME_CONVERTER_CONTRACTID, &converter);
  if (NS_SUCCEEDED(res) && nsnull != converter) {
    res = converter->EncoderWrite(data, buffer, size, &written);
    NS_RELEASE(converter);
  }
  return NS_SUCCEEDED(res) ? 0 : -1;
}

Here is the call graph for this function:

static char* mime_make_separator ( const char *  prefix) [static]
static nsresult mime_nested_encoder_output_fn ( const char *  buf,
PRInt32  size,
void closure 
) [static]

Definition at line 1153 of file nsMsgComposeSecure.cpp.

{
  nsMsgComposeSecure *state = (nsMsgComposeSecure *) closure;
  return state->MimeCryptoWriteBlock ((char *) buf, size);
}

Here is the caller graph for this function:

MimeEncoderData* MIME_QPEncoderInit ( nsresult(*)(const char *buf, PRInt32 size, void *closure output_fn,
void closure 
)

Definition at line 105 of file nsMsgComposeSecure.cpp.

{
  MimeEncoderData *returnEncoderData = nsnull;
  nsIMimeConverter *converter;
  nsresult res = CallCreateInstance(NS_MIME_CONVERTER_CONTRACTID, &converter);
  if (NS_SUCCEEDED(res) && nsnull != converter) 
  {
    res = converter->QPEncoderInit(output_fn, closure, &returnEncoderData);
    NS_RELEASE(converter);
  }
  return NS_SUCCEEDED(res) ? returnEncoderData : nsnull;
}

Here is the call graph for this function:

MimeEncoderData* MIME_UUEncoderInit ( char *  filename,
nsresult(*)(const char *buf, PRInt32 size, void *closure output_fn,
void closure 
)

Definition at line 119 of file nsMsgComposeSecure.cpp.

{
  MimeEncoderData *returnEncoderData = nsnull;
  nsIMimeConverter *converter;
  nsresult res = CallCreateInstance(NS_MIME_CONVERTER_CONTRACTID, &converter);
  if (NS_SUCCEEDED(res) && nsnull != converter) 
  {
    res = converter->UUEncoderInit(filename, output_fn, closure, &returnEncoderData);
    NS_RELEASE(converter);
  }
  return NS_SUCCEEDED(res) ? returnEncoderData : nsnull;
}

Here is the call graph for this function: