Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
jarint.h File Reference
#include "nspr.h"
#include "key.h"
#include "base64.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define ADDITEM(list, type, pathname, data, size)
#define JAR_FILE   PRFileDesc *
#define JAR_FOPEN(fn, mode)   JAR_FOPEN_to_PR_Open(fn,mode)
#define JAR_FCLOSE   PR_Close
#define JAR_FSEEK   PR_Seek
#define JAR_FREAD   PR_Read
#define JAR_FWRITE   PR_Write

Functions

CERTCertDBHandle * JAR_open_database (void)
int JAR_close_database (CERTCertDBHandle *certdb)
int jar_close_key_database (void *keydb)
voidjar_open_key_database (void)
JAR_SignerJAR_new_signer (void)
void JAR_destroy_signer (JAR_Signer *signer)
JAR_Signerjar_get_signer (JAR *jar, char *basename)
int jar_append (ZZList *list, int type, char *pathname, void *data, size_t size)
PRFileDescJAR_FOPEN_to_PR_Open (const char *name, const char *mode)
int jar_create_pk7 (CERTCertDBHandle *certdb, void *keydb, CERTCertificate *cert, char *password, JAR_FILE infp, JAR_FILE outfp)

Define Documentation

#define ADDITEM (   list,
  type,
  pathname,
  data,
  size 
)
Value:
{ int err; err = jar_append (list, type, pathname, data, size); \
    if (err < 0) return err; }

Definition at line 68 of file jarint.h.

Definition at line 100 of file jarint.h.

Definition at line 97 of file jarint.h.

Definition at line 99 of file jarint.h.

Definition at line 102 of file jarint.h.

Definition at line 101 of file jarint.h.

Definition at line 103 of file jarint.h.


Function Documentation

int jar_append ( ZZList *  list,
int  type,
char *  pathname,
void data,
size_t  size 
)

Definition at line 1938 of file jarver.c.

  {
  JAR_Item *it;
  ZZLink *entity;

  it = (JAR_Item*)PORT_ZAlloc (sizeof (JAR_Item));

  if (it == NULL)
    goto loser;

  if (pathname)
    {
    it->pathname = PORT_Strdup (pathname);
    if (it->pathname == NULL)
      goto loser;
    }

  it->type = (jarType)type;
  it->data = (unsigned char *) data;
  it->size = size;

  entity = ZZ_NewLink (it);

  if (entity)
    {
    ZZ_AppendLink (list, entity);
    return 0;
    }

loser:

  if (it)
    {
    if (it->pathname) PORT_Free (it->pathname);
    PORT_Free (it);
    }

  return JAR_ERR_MEMORY;
  }

Here is the call graph for this function:

int JAR_close_database ( CERTCertDBHandle *  certdb)

Definition at line 1832 of file jarver.c.

  {
#ifdef notdef
  CERTCertDBHandle *defaultdb;

  /* This really just retrieves the handle, nothing more */
  defaultdb = CERT_GetDefaultCertDB();

  /* If there is no default db, it means we opened 
     the permanent database for some reason */

  if (defaultdb == NULL && certdb != NULL)
    CERT_ClosePermCertDB (certdb);
#endif

  return 0;
  }

Here is the call graph for this function:

Definition at line 236 of file jarsign.c.

  {
  /* We never do close it */
  return 0;
  }
int jar_create_pk7 ( CERTCertDBHandle *  certdb,
void keydb,
CERTCertificate *  cert,
char *  password,
JAR_FILE  infp,
JAR_FILE  outfp 
)

Definition at line 254 of file jarsign.c.

  {
  int nb;
  unsigned char buffer [4096], digestdata[32];
  const SECHashObject *hashObj;
  void *hashcx;
  unsigned int len;

  int status = 0;
  char *errstring;

  SECItem digest;
  SEC_PKCS7ContentInfo *cinfo;
  SECStatus rv;

  void /*MWContext*/ *mw;

  if (outfp == NULL || infp == NULL || cert == NULL)
    return JAR_ERR_GENERAL;

  /* we sign with SHA */
  hashObj = HASH_GetHashObject(HASH_AlgSHA1);

  hashcx = (* hashObj->create)();
  if (hashcx == NULL)
    return JAR_ERR_GENERAL;

  (* hashObj->begin)(hashcx);

  while (1)
    {
    /* nspr2.0 doesn't support feof 
       if (feof (infp)) break; */

    nb = JAR_FREAD (infp, buffer, sizeof (buffer));
    if (nb == 0) 
      {
#if 0
      if (ferror(infp)) 
        {
        /* PORT_SetError(SEC_ERROR_IO); */ /* FIX */
       (* hashObj->destroy) (hashcx, PR_TRUE);
       return JAR_ERR_GENERAL;
        }
#endif
      /* eof */
      break;
      }
    (* hashObj->update) (hashcx, buffer, nb);
    }

  (* hashObj->end) (hashcx, digestdata, &len, 32);
  (* hashObj->destroy) (hashcx, PR_TRUE);

  digest.data = digestdata;
  digest.len = len;

  /* signtool must use any old context it can find since it's
     calling from inside javaland. */

#ifdef MOZILLA_CLIENT_OLD
  mw = XP_FindSomeContext();
#else
  mw = NULL;
#endif

  PORT_SetError (0);

  cinfo = SEC_PKCS7CreateSignedData 
             (cert, certUsageObjectSigner, NULL, 
                SEC_OID_SHA1, &digest, NULL, (void *) mw);

  if (cinfo == NULL)
    return JAR_ERR_PK7;

  rv = SEC_PKCS7IncludeCertChain (cinfo, NULL);
  if (rv != SECSuccess) 
    {
    status = PORT_GetError();
    SEC_PKCS7DestroyContentInfo (cinfo);
    return status;
    }

  /* Having this here forces signtool to always include
     signing time. */

  rv = SEC_PKCS7AddSigningTime (cinfo);
  if (rv != SECSuccess)
    {
    /* don't check error */
    }

  PORT_SetError (0);

#ifdef USE_MOZ_THREAD
  /* if calling from mozilla */
  rv = jar_moz_encode
             (cinfo, jar_pk7_out, outfp, 
                 NULL,  /* pwfn */ NULL,  /* pwarg */ (void *) mw);
#else
  /* if calling from mozilla thread*/
  rv = SEC_PKCS7Encode 
             (cinfo, jar_pk7_out, outfp, 
                 NULL,  /* pwfn */ NULL,  /* pwarg */ (void *) mw):
#endif

  if (rv != SECSuccess)
    status = PORT_GetError();

  SEC_PKCS7DestroyContentInfo (cinfo);

  if (rv != SECSuccess)
    {
    errstring = JAR_get_error (status);
    /*XP_TRACE (("Jar signing failed (reason %d = %s)", status, errstring));*/
    return status < 0 ? status : JAR_ERR_GENERAL;
    }

  return 0;
  }

Here is the call graph for this function:

Definition at line 627 of file jar.c.

  {
  if (signer)
    {
    if (signer->owner) PORT_Free (signer->owner);
    if (signer->digest) PORT_Free (signer->digest);

    jar_destroy_list (signer->sf);
    ZZ_DestroyList (signer->sf);

    jar_destroy_list (signer->certs);
    ZZ_DestroyList (signer->certs);

    PORT_Free (signer);
    }
  }

Here is the call graph for this function:

Here is the caller graph for this function:

PRFileDesc* JAR_FOPEN_to_PR_Open ( const char *  name,
const char *  mode 
)

Definition at line 49 of file jarint.c.

{

       PRIntn prflags=0, prmode=0;

       /* Get read/write flags */
       if(strchr(mode, 'r') && !strchr(mode, '+')) {
              prflags |= PR_RDONLY;
       } else if( (strchr(mode, 'w') || strchr(mode, 'a')) &&
                     !strchr(mode,'+') ) {
              prflags |= PR_WRONLY;
       } else {
              prflags |= PR_RDWR;
       }

       /* Create a new file? */
       if(strchr(mode, 'w') || strchr(mode, 'a')) {
              prflags |= PR_CREATE_FILE;
       }

       /* Append? */
       if(strchr(mode, 'a')) {
              prflags |= PR_APPEND;
       }

       /* Truncate? */
       if(strchr(mode, 'w')) {
              prflags |= PR_TRUNCATE;
       }

       /* We can't do umask because it isn't XP.  Choose some default
          mode for created files */
       prmode = 0755;

       return PR_Open(name, prflags, prmode);
}

Here is the call graph for this function:

JAR_Signer* jar_get_signer ( JAR jar,
char *  basename 
)

Definition at line 644 of file jar.c.

  {
  JAR_Item *it;
  JAR_Context *ctx;

  JAR_Signer *candidate;
  JAR_Signer *signer = NULL;

  ctx = JAR_find (jar, NULL, jarTypeOwner);

  if (ctx == NULL)
    return NULL;

  while (JAR_find_next (ctx, &it) >= 0)
    {
    candidate = (JAR_Signer *) it->data;
    if (*basename == '*' || !PORT_Strcmp (candidate->owner, basename))
      {
      signer = candidate;
      break;
      }
    }

  JAR_find_end (ctx);

  return signer;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 584 of file jar.c.

  {
  JAR_Signer *signer;

  signer = (JAR_Signer *) PORT_ZAlloc (sizeof (JAR_Signer));

  if (signer == NULL)
    goto loser;


  /* certs */
  signer->certs = ZZ_NewList();

  if (signer->certs == NULL)
    goto loser;


  /* sf */
  signer->sf = ZZ_NewList();

  if (signer->sf == NULL)
    goto loser;


  return signer;


loser:

  if (signer)
    {
    if (signer->certs) 
      ZZ_DestroyList (signer->certs);

    if (signer->sf) 
      ZZ_DestroyList (signer->sf);

    PORT_Free (signer);
    }

  return NULL;
  }

Here is the call graph for this function:

Here is the caller graph for this function:

CERTCertDBHandle* JAR_open_database ( void  )

Definition at line 1815 of file jarver.c.

  {
  CERTCertDBHandle *certdb;

  certdb = CERT_GetDefaultCertDB();

  return certdb;
  }

Here is the call graph for this function:

Definition at line 231 of file jarsign.c.

  {
    return NULL;
  }