Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Enumerations | Functions
jar.h File Reference
#include "cert.h"
#include "hasht.h"
#include "prio.h"
#include <stdio.h>
#include "jar-ds.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  JAR_Item_
struct  JAR_Digest_
struct  JAR_
struct  JAR_Context_
struct  JAR_Signer_
struct  JAR_Metainfo_
struct  JAR_Physical_
struct  JAR_Cert_

Defines

#define ZHUGEP
#define JAR_CB_SIGNAL   1
#define SEC_ERR_BASE   (-0x2000)
#define JAR_BASE   SEC_ERR_BASE + 300
#define JAR_ERR_GENERAL   (JAR_BASE + 1)
#define JAR_ERR_FNF   (JAR_BASE + 2)
#define JAR_ERR_CORRUPT   (JAR_BASE + 3)
#define JAR_ERR_MEMORY   (JAR_BASE + 4)
#define JAR_ERR_DISK   (JAR_BASE + 5)
#define JAR_ERR_ORDER   (JAR_BASE + 6)
#define JAR_ERR_SIG   (JAR_BASE + 7)
#define JAR_ERR_METADATA   (JAR_BASE + 8)
#define JAR_ERR_ENTRY   (JAR_BASE + 9)
#define JAR_ERR_HASH   (JAR_BASE + 10)
#define JAR_ERR_PK7   (JAR_BASE + 11)
#define JAR_ERR_PNF   (JAR_BASE + 12)

Typedefs

typedef struct JAR_Item_ JAR_Item
typedef struct JAR_Digest_ JAR_Digest
typedef struct JAR_ JAR
typedef struct JAR_Context_ JAR_Context
typedef struct JAR_Signer_ JAR_Signer
typedef struct JAR_Metainfo_ JAR_Metainfo
typedef struct JAR_Physical_ JAR_Physical
typedef struct JAR_Cert_ JAR_Cert

Enumerations

enum  jarType {
  jarTypeMF = 2, jarTypeSF = 3, jarTypeMeta = 6, jarTypePhy = 7,
  jarTypeSign = 10, jarTypeSect = 11, jarTypeOwner = 13, jarTypeMF = 2,
  jarTypeSF = 3, jarTypeMeta = 6, jarTypePhy = 7, jarTypeSign = 10,
  jarTypeSect = 11, jarTypeOwner = 13
}
enum  jarHash {
  jarHashNone = 0, jarHashBad = 1, jarHashPresent = 2, jarHashNone = 0,
  jarHashBad = 1, jarHashPresent = 2
}
enum  jarArch {
  jarArchGuess = 0, jarArchNone = 1, jarArchZip = 2, jarArchTar = 3,
  jarArchGuess = 0, jarArchNone = 1, jarArchZip = 2, jarArchTar = 3
}
enum  jarCert {
  jarCertCompany = 1, jarCertCA = 2, jarCertSerial = 3, jarCertExpires = 4,
  jarCertNickname = 5, jarCertFinger = 6, jarCertJavaHack = 100, jarCertCompany = 1,
  jarCertCA = 2, jarCertSerial = 3, jarCertExpires = 4, jarCertNickname = 5,
  jarCertFinger = 6, jarCertJavaHack = 100
}

Functions

JARJAR_new (void)
void PR_CALLBACK JAR_destroy (JAR *jar)
char * JAR_get_error (int status)
int JAR_set_callback (int type, JAR *jar, int(*fn)(int status, JAR *jar, const char *metafile, char *pathname, char *errortext))
void JAR_init_callbacks (char *(*string_cb)(int), void *(*find_cx)(void), void *(*init_cx)(void))
int JAR_set_context (JAR *jar, void *mw)
JAR_ContextJAR_find (JAR *jar, char *pattern, jarType type)
int JAR_find_next (JAR_Context *ctx, JAR_Item **it)
void JAR_find_end (JAR_Context *ctx)
int JAR_parse_manifest (JAR *jar, char ZHUGEP *raw_manifest, long length, const char *path, const char *url)
JAR_Digest *PR_CALLBACK JAR_calculate_digest (void ZHUGEP *data, long length)
int PR_CALLBACK JAR_verify_digest (JAR *jar, const char *name, JAR_Digest *dig)
int JAR_digest_file (char *filename, JAR_Digest *dig)
int PR_CALLBACK JAR_cert_attribute (JAR *jar, jarCert attrib, long keylen, void *key, void **result, unsigned long *length)
int JAR_get_metainfo (JAR *jar, char *name, char *header, void **info, unsigned long *length)
char * JAR_get_filename (JAR *jar)
char * JAR_get_url (JAR *jar)
char * JAR_cert_html (JAR *jar, int style, long keylen, void *key, int *result)
int PR_CALLBACK JAR_stash_cert (JAR *jar, long keylen, void *key)
voidJAR_fetch_cert (long length, void *key)
int JAR_pass_archive (JAR *jar, jarArch format, char *filename, const char *url)
int JAR_pass_archive_unverified (JAR *jar, jarArch format, char *filename, const char *url)
int JAR_verified_extract (JAR *jar, char *path, char *outpath)
int JAR_extract (JAR *jar, char *path, char *outpath)

Class Documentation

struct JAR_Item_

Definition at line 79 of file jar.h.

Class Members
void * data
char * pathname
size_t size
jarType type
struct JAR_Digest_

Definition at line 99 of file jar.h.

Class Members
unsigned char md5
jarHash md5_status
unsigned char sha1
jarHash sha1_status
struct JAR_Context_

Definition at line 169 of file jar.h.

Collaboration diagram for JAR_Context_:
Class Members
jarType finding
JAR * jar
ZZLink * next
ZZLink * nextsign
char * pattern
struct JAR_Signer_

Definition at line 179 of file jar.h.

Collaboration diagram for JAR_Signer_:
Class Members
ZZList * certs
JAR_Digest * digest
char * owner
int pkcs7
ZZList * sf
int valid
struct JAR_Metainfo_

Definition at line 194 of file jar.h.

Class Members
char * header
char * info
struct JAR_Physical_

Definition at line 203 of file jar.h.

Class Members
unsigned char compression
unsigned long length
unsigned long offset
unsigned long uncompressed_length
struct JAR_Cert_

Definition at line 215 of file jar.h.

Class Members
CERTCertificate * cert
void * key
size_t length

Define Documentation

Definition at line 254 of file jar.h.

Definition at line 240 of file jar.h.

Definition at line 260 of file jar.h.

Definition at line 262 of file jar.h.

Definition at line 266 of file jar.h.

Definition at line 259 of file jar.h.

Definition at line 258 of file jar.h.

Definition at line 267 of file jar.h.

Definition at line 261 of file jar.h.

Definition at line 265 of file jar.h.

Definition at line 263 of file jar.h.

#define JAR_ERR_PK7   (JAR_BASE + 11)

Definition at line 268 of file jar.h.

#define JAR_ERR_PNF   (JAR_BASE + 12)

Definition at line 269 of file jar.h.

Definition at line 264 of file jar.h.

#define SEC_ERR_BASE   (-0x2000)

Definition at line 251 of file jar.h.

Definition at line 57 of file jar.h.


Typedef Documentation

typedef struct JAR_ JAR
typedef struct JAR_Cert_ JAR_Cert
typedef struct JAR_Context_ JAR_Context
typedef struct JAR_Digest_ JAR_Digest
typedef struct JAR_Item_ JAR_Item
typedef struct JAR_Metainfo_ JAR_Metainfo
typedef struct JAR_Physical_ JAR_Physical
typedef struct JAR_Signer_ JAR_Signer

Enumeration Type Documentation

enum jarArch
Enumerator:
jarArchGuess 
jarArchNone 
jarArchZip 
jarArchTar 
jarArchGuess 
jarArchNone 
jarArchZip 
jarArchTar 

Definition at line 111 of file jar.h.

enum jarCert
Enumerator:
jarCertCompany 
jarCertCA 
jarCertSerial 
jarCertExpires 
jarCertNickname 
jarCertFinger 
jarCertJavaHack 
jarCertCompany 
jarCertCA 
jarCertSerial 
jarCertExpires 
jarCertNickname 
jarCertFinger 
jarCertJavaHack 

Definition at line 226 of file jar.h.

enum jarHash
Enumerator:
jarHashNone 
jarHashBad 
jarHashPresent 
jarHashNone 
jarHashBad 
jarHashPresent 

Definition at line 91 of file jar.h.

enum jarType
Enumerator:
jarTypeMF 
jarTypeSF 
jarTypeMeta 
jarTypePhy 
jarTypeSign 
jarTypeSect 
jarTypeOwner 
jarTypeMF 
jarTypeSF 
jarTypeMeta 
jarTypePhy 
jarTypeSign 
jarTypeSect 
jarTypeOwner 

Definition at line 65 of file jar.h.

  {
  jarTypeMF = 2,
  jarTypeSF = 3,
  jarTypeMeta = 6,
  jarTypePhy = 7,
  jarTypeSign = 10,
  jarTypeSect = 11,
  jarTypeOwner = 13
  }

Function Documentation

Definition at line 89 of file jarsign.c.

  {
  long chunq;
  JAR_Digest *dig;

  unsigned int md5_length, sha1_length;

  PK11Context *md5  = 0;
  PK11Context *sha1 = 0;

  dig = (JAR_Digest *) PORT_ZAlloc (sizeof (JAR_Digest));

  if (dig == NULL) 
    {
    /* out of memory allocating digest */
    return NULL;
    }

#if defined(XP_WIN16)
  PORT_Assert ( !IsBadHugeReadPtr(data, length) );
#endif

  md5  = PK11_CreateDigestContext (SEC_OID_MD5);
  sha1 = PK11_CreateDigestContext (SEC_OID_SHA1);

  if (length >= 0) 
    {
    PK11_DigestBegin (md5);
    PK11_DigestBegin (sha1);

    do {
       chunq = length;

#ifdef XP_WIN16
       if (length > CHUNQ) chunq = CHUNQ;

       /*
        *  If the block of data crosses one or more segment 
        *  boundaries then only pass the chunk of data in the 
        *  first segment.
        * 
        *  This allows the data to be treated as FAR by the
        *  PK11_DigestOp(...) routine.
        *
        */

       if (OFFSETOF(data) + chunq >= 0x10000) 
         chunq = 0x10000 - OFFSETOF(data);
#endif

       PK11_DigestOp (md5,  (unsigned char*)data, chunq);
       PK11_DigestOp (sha1, (unsigned char*)data, chunq);

       length -= chunq;
       data = ((char ZHUGEP *) data + chunq);
       } 
    while (length > 0);

    PK11_DigestFinal (md5,  dig->md5,  &md5_length,  MD5_LENGTH);
    PK11_DigestFinal (sha1, dig->sha1, &sha1_length, SHA1_LENGTH);

    PK11_DestroyContext (md5,  PR_TRUE);
    PK11_DestroyContext (sha1, PR_TRUE);
    }

  return dig;
  }

Here is the caller graph for this function:

int PR_CALLBACK JAR_cert_attribute ( JAR jar,
jarCert  attrib,
long  keylen,
void key,
void **  result,
unsigned long length 
)

Definition at line 1060 of file jarver.c.

  {
  int status = 0;
  char *ret = NULL;

  CERTCertificate *cert;

  CERTCertDBHandle *certdb;

  JAR_Digest *dig;
  SECItem hexme;

  *length = 0;

  if (attrib == 0 || key == 0)
    return JAR_ERR_GENERAL;

  if (attrib == jarCertJavaHack)
    {
    cert = (CERTCertificate *) NULL;
    certdb = JAR_open_database();

    if (certdb)
      {
#ifdef USE_MOZ_THREAD
      cert = jar_moz_nickname (certdb, (char*)key);
#else
      cert = CERT_FindCertByNickname (certdb, key);
#endif

      if (cert)
        {
        *length = cert->certKey.len;

        *result = (void *) PORT_ZAlloc (*length);

        if (*result)
          PORT_Memcpy (*result, cert->certKey.data, *length);
        else
          return JAR_ERR_MEMORY;
        }
      JAR_close_database (certdb);
      }

    return cert ? 0 : JAR_ERR_GENERAL;
    }

  if (jar && jar->pkcs7 == 0)
    return JAR_ERR_GENERAL;

  cert = jar_get_certificate (jar, keylen, key, &status);

  if (cert == NULL || status < 0)
    return JAR_ERR_GENERAL;

#define SEP " <br> "
#define SEPLEN (PORT_Strlen(SEP))

  switch (attrib)
    {
    case jarCertCompany:

      ret = cert->subjectName;

      /* This is pretty ugly looking but only used
         here for this one purpose. */

      if (ret)
        {
        int retlen = 0;

        char *cer_ou1, *cer_ou2, *cer_ou3;
       char *cer_cn, *cer_e, *cer_o, *cer_l;

       cer_cn  = CERT_GetCommonName (&cert->subject);
        cer_e   = CERT_GetCertEmailAddress (&cert->subject);
        cer_ou3 = jar_cert_element (ret, "OU=", 3);
        cer_ou2 = jar_cert_element (ret, "OU=", 2);
        cer_ou1 = jar_cert_element (ret, "OU=", 1);
        cer_o   = CERT_GetOrgName (&cert->subject);
        cer_l   = CERT_GetCountryName (&cert->subject);

        if (cer_cn)  retlen += SEPLEN + PORT_Strlen (cer_cn);
        if (cer_e)   retlen += SEPLEN + PORT_Strlen (cer_e);
        if (cer_ou1) retlen += SEPLEN + PORT_Strlen (cer_ou1);
        if (cer_ou2) retlen += SEPLEN + PORT_Strlen (cer_ou2);
        if (cer_ou3) retlen += SEPLEN + PORT_Strlen (cer_ou3);
        if (cer_o)   retlen += SEPLEN + PORT_Strlen (cer_o);
        if (cer_l)   retlen += SEPLEN + PORT_Strlen (cer_l);

        ret = (char *) PORT_ZAlloc (1 + retlen);

        if (cer_cn)  { PORT_Strcpy (ret, cer_cn);  PORT_Strcat (ret, SEP); }
        if (cer_e)   { PORT_Strcat (ret, cer_e);   PORT_Strcat (ret, SEP); }
        if (cer_ou1) { PORT_Strcat (ret, cer_ou1); PORT_Strcat (ret, SEP); }
        if (cer_ou2) { PORT_Strcat (ret, cer_ou2); PORT_Strcat (ret, SEP); }
        if (cer_ou3) { PORT_Strcat (ret, cer_ou3); PORT_Strcat (ret, SEP); }
        if (cer_o)   { PORT_Strcat (ret, cer_o);   PORT_Strcat (ret, SEP); }
        if (cer_l)     PORT_Strcat (ret, cer_l);

       /* return here to avoid unsightly memory leak */

        *result = ret;
        *length = PORT_Strlen (ret);

        return 0;
        }
      break;

    case jarCertCA:

      ret = cert->issuerName;

      if (ret)
        {
        int retlen = 0;

        char *cer_ou1, *cer_ou2, *cer_ou3;
       char *cer_cn, *cer_e, *cer_o, *cer_l;

        /* This is pretty ugly looking but only used
           here for this one purpose. */

       cer_cn  = CERT_GetCommonName (&cert->issuer);
        cer_e   = CERT_GetCertEmailAddress (&cert->issuer);
        cer_ou3 = jar_cert_element (ret, "OU=", 3);
        cer_ou2 = jar_cert_element (ret, "OU=", 2);
        cer_ou1 = jar_cert_element (ret, "OU=", 1);
        cer_o   = CERT_GetOrgName (&cert->issuer);
        cer_l   = CERT_GetCountryName (&cert->issuer);

        if (cer_cn)  retlen += SEPLEN + PORT_Strlen (cer_cn);
        if (cer_e)   retlen += SEPLEN + PORT_Strlen (cer_e);
        if (cer_ou1) retlen += SEPLEN + PORT_Strlen (cer_ou1);
        if (cer_ou2) retlen += SEPLEN + PORT_Strlen (cer_ou2);
        if (cer_ou3) retlen += SEPLEN + PORT_Strlen (cer_ou3);
        if (cer_o)   retlen += SEPLEN + PORT_Strlen (cer_o);
        if (cer_l)   retlen += SEPLEN + PORT_Strlen (cer_l);

        ret = (char *) PORT_ZAlloc (1 + retlen);

        if (cer_cn)  { PORT_Strcpy (ret, cer_cn);  PORT_Strcat (ret, SEP); }
        if (cer_e)   { PORT_Strcat (ret, cer_e);   PORT_Strcat (ret, SEP); }
        if (cer_ou1) { PORT_Strcat (ret, cer_ou1); PORT_Strcat (ret, SEP); }
        if (cer_ou2) { PORT_Strcat (ret, cer_ou2); PORT_Strcat (ret, SEP); }
        if (cer_ou3) { PORT_Strcat (ret, cer_ou3); PORT_Strcat (ret, SEP); }
        if (cer_o)   { PORT_Strcat (ret, cer_o);   PORT_Strcat (ret, SEP); }
        if (cer_l)     PORT_Strcat (ret, cer_l);

       /* return here to avoid unsightly memory leak */

        *result = ret;
        *length = PORT_Strlen (ret);

        return 0;
        }

      break;

    case jarCertSerial:

      ret = CERT_Hexify (&cert->serialNumber, 1);
      break;

    case jarCertExpires:

      ret = DER_UTCDayToAscii (&cert->validity.notAfter);
      break;

    case jarCertNickname:

      ret = jar_choose_nickname (cert);
      break;

    case jarCertFinger:

      dig = JAR_calculate_digest 
         ((char *) cert->derCert.data, cert->derCert.len);

      if (dig)
        {
        hexme.len = sizeof (dig->md5);
        hexme.data = dig->md5;
        ret = CERT_Hexify (&hexme, 1);
        }
      break;

    default:

      return JAR_ERR_GENERAL;
    }

  *result = ret ? PORT_Strdup (ret) : NULL;
  *length = ret ? PORT_Strlen (ret) : 0;

  return 0;
  }
char* JAR_cert_html ( JAR jar,
int  style,
long  keylen,
void key,
int result 
)

Definition at line 1381 of file jarver.c.

  {
#ifdef notdef
  char *html;
#endif
  CERTCertificate *cert;

  *result = -1;

  if (style != 0)
    return NULL;

  cert = jar_get_certificate (jar, keylen, key, result);

  if (cert == NULL || *result < 0)
    return NULL;

  *result = -1;

   return NULL;

#ifdef notdef
  html = CERT_HTMLCertInfo (cert, /* show images */ PR_TRUE,
              /*show issuer*/PR_TRUE);

  if (html == NULL)
    *result = -1;

  return html;
#endif
  }

Definition at line 117 of file jar.c.

  {
  PORT_Assert( jar != NULL );

  if (jar == NULL)
    return;

  if (jar->fp) JAR_FCLOSE ((PRFileDesc*)jar->fp);

  if (jar->url)      PORT_Free (jar->url);
  if (jar->filename) PORT_Free (jar->filename);

  /* Free the linked list elements */

  jar_destroy_list (jar->manifest);
  ZZ_DestroyList (jar->manifest);

  jar_destroy_list (jar->hashes);
  ZZ_DestroyList (jar->hashes);

  jar_destroy_list (jar->phy);
  ZZ_DestroyList (jar->phy);

  jar_destroy_list (jar->metainfo);
  ZZ_DestroyList (jar->metainfo);

  jar_destroy_list (jar->signers);
  ZZ_DestroyList (jar->signers);

  PORT_Free (jar);
  }
int JAR_digest_file ( char *  filename,
JAR_Digest dig 
)

Definition at line 165 of file jarsign.c.

    {
    JAR_FILE fp;

    int num;
    unsigned char *buf;

    PK11Context *md5 = 0;
    PK11Context *sha1 = 0;

    unsigned int md5_length, sha1_length;

    buf = (unsigned char *) PORT_ZAlloc (FILECHUNQ);
    if (buf == NULL)
      {
      /* out of memory */
      return JAR_ERR_MEMORY;
      }
 
    if ((fp = JAR_FOPEN (filename, "rb")) == 0)
      {
      /* perror (filename); FIX XXX XXX XXX XXX XXX XXX */
      PORT_Free (buf);
      return JAR_ERR_FNF;
      }

    md5 = PK11_CreateDigestContext (SEC_OID_MD5);
    sha1 = PK11_CreateDigestContext (SEC_OID_SHA1);

    if (md5 == NULL || sha1 == NULL) 
      {
      /* can't generate digest contexts */
      PORT_Free (buf);
      JAR_FCLOSE (fp);
      return JAR_ERR_GENERAL;
      }

    PK11_DigestBegin (md5);
    PK11_DigestBegin (sha1);

    while (1)
      {
      if ((num = JAR_FREAD (fp, buf, FILECHUNQ)) == 0)
        break;

      PK11_DigestOp (md5, buf, num);
      PK11_DigestOp (sha1, buf, num);
      }

    PK11_DigestFinal (md5, dig->md5, &md5_length, MD5_LENGTH);
    PK11_DigestFinal (sha1, dig->sha1, &sha1_length, SHA1_LENGTH);

    PK11_DestroyContext (md5, PR_TRUE);
    PK11_DestroyContext (sha1, PR_TRUE);

    PORT_Free (buf);
    JAR_FCLOSE (fp);

    return 0;
    }

Here is the caller graph for this function:

int JAR_extract ( JAR jar,
char *  path,
char *  outpath 
)

Definition at line 219 of file jarfile.c.

  {
  int result;

  JAR_Physical *phy;

  if (jar->fp == NULL && jar->filename)
    {
    jar->fp = (FILE*)JAR_FOPEN (jar->filename, "rb");
    }

  if (jar->fp == NULL)
    {
    /* file not found */
    return JAR_ERR_FNF;
    }

  phy = jar_get_physical (jar, path);

  if (phy)
    {
    if (phy->compression != 0 && phy->compression != 8)
      {
      /* unsupported compression method */
      result = JAR_ERR_CORRUPT;
      }

    if (phy->compression == 0)
      {
      result = jar_physical_extraction 
         ((PRFileDesc*)jar->fp, outpath, phy->offset, phy->length);
      }
    else
      {
      result = jar_physical_inflate 
         ((PRFileDesc*)jar->fp, outpath, phy->offset, phy->length, 
            (unsigned int) phy->compression);
      }

#if defined(XP_UNIX) || defined(XP_BEOS)
    if (phy->mode)
      chmod (outpath, 0400 | (mode_t) phy->mode);
#endif
    }
  else
    {
    /* pathname not found in archive */
    result = JAR_ERR_PNF;
    }

  return result;
  }

Here is the caller graph for this function:

void* JAR_fetch_cert ( long  length,
void key 
)

Definition at line 1517 of file jarver.c.

  {
  CERTIssuerAndSN issuerSN;
  CERTCertificate *cert = NULL;

  CERTCertDBHandle *certdb;

  certdb = JAR_open_database();

  if (certdb)
    {
    unsigned char *keyData = (unsigned char *)key;
    issuerSN.derIssuer.len = (keyData[0] << 8) + keyData[0];
    issuerSN.derIssuer.data = &keyData[2];
    issuerSN.serialNumber.len = length - (2 + issuerSN.derIssuer.len);
    issuerSN.serialNumber.data = &keyData[2+issuerSN.derIssuer.len];

#ifdef USE_MOZ_THREAD
    cert = jar_moz_certkey (certdb, &issuerSN);
#else
    cert = CERT_FindCertByIssuerAndSN (certdb, &issuerSN);
#endif

    JAR_close_database (certdb);
    }

  return (void *) cert;
  }

Here is the caller graph for this function:

JAR_Context* JAR_find ( JAR jar,
char *  pattern,
jarType  type 
)

Definition at line 309 of file jar.c.

  {
  JAR_Context *ctx;

  PORT_Assert( jar != NULL );

  if (!jar)
    return NULL;

  ctx = (JAR_Context *) PORT_ZAlloc (sizeof (JAR_Context));

  if (ctx == NULL)
    return NULL;

  ctx->jar = jar;

  if (pattern)
    {
    if ((ctx->pattern = PORT_Strdup (pattern)) == NULL)
      {
      PORT_Free (ctx);
      return NULL;
      }
    }

  ctx->finding = type;

  switch (type)
    {
    case jarTypeMF:     ctx->next = ZZ_ListHead (jar->hashes);
                        break;

    case jarTypeSF:
    case jarTypeSign:   ctx->next = NULL;
                        ctx->nextsign = ZZ_ListHead (jar->signers);
                        break;

    case jarTypeSect:   ctx->next = ZZ_ListHead (jar->manifest);
                        break;

    case jarTypePhy:    ctx->next = ZZ_ListHead (jar->phy);
                        break;

    case jarTypeOwner:  if (jar->signers)
                          ctx->next = ZZ_ListHead (jar->signers);
                        else
                          ctx->next = NULL;
                        break;

    case jarTypeMeta:   ctx->next = ZZ_ListHead (jar->metainfo);
                        break;

    default:            PORT_Assert( 1 != 2);
                        break;
    }

  return ctx;
  }

Definition at line 375 of file jar.c.

  {
  PORT_Assert( ctx != NULL );

  if (ctx)
    {
    if (ctx->pattern) 
      PORT_Free (ctx->pattern);
    PORT_Free (ctx);
    }
  }
int JAR_find_next ( JAR_Context ctx,
JAR_Item **  it 
)

Definition at line 395 of file jar.c.

  {
  JAR *jar;
  ZZList *list = NULL;

  int finding;

  JAR_Signer *signer = NULL;

  PORT_Assert( ctx != NULL );
  PORT_Assert( ctx->jar != NULL );

  jar = ctx->jar;

  /* Internally, convert jarTypeSign to jarTypeSF, and return
     the actual attached certificate later */

  finding = (ctx->finding == jarTypeSign) ? jarTypeSF : ctx->finding;

  if (ctx->nextsign)
    {
      if (ZZ_ListIterDone (jar->signers, ctx->nextsign))
       {
       *it = NULL;
       return -1;
       }
    PORT_Assert (ctx->nextsign->thing != NULL);
    signer = (JAR_Signer*)ctx->nextsign->thing->data;
    }


  /* Find out which linked list to traverse. Then if
     necessary, advance to the next linked list. */

  while (1)
    {
    switch (finding)
      {
      case jarTypeSign:    /* not any more */
                           PORT_Assert( finding != jarTypeSign );
                           list = signer->certs;
                           break;

      case jarTypeSect:    list = jar->manifest;
                           break;

      case jarTypePhy:     list = jar->phy;
                           break;

      case jarTypeSF:      /* signer, not jar */
                           PORT_Assert( signer != NULL );
                           list = signer->sf;
                           break;

      case jarTypeMF:      list = jar->hashes;
                           break;

      case jarTypeOwner:   list = jar->signers;
                           break;

      case jarTypeMeta:    list = jar->metainfo;
                           break;

      default:             PORT_Assert( 1 != 2 );
                           break;
      }

    if (list == NULL)
      {
      *it = NULL;
      return -1;
      }

    /* When looping over lists of lists, advance
       to the next signer. This is done when multiple
       signers are possible. */

    if (ZZ_ListIterDone (list, ctx->next))
      {
      if (ctx->nextsign && jar->signers) 
        {
        ctx->nextsign = ctx->nextsign->next;
        if (!ZZ_ListIterDone (jar->signers, ctx->nextsign)) 
          {
          PORT_Assert (ctx->nextsign->thing != NULL);

          signer = (JAR_Signer*)ctx->nextsign->thing->data;
          PORT_Assert( signer != NULL );

          ctx->next = NULL;
          continue;
          }
        }
      *it = NULL;
      return -1;
      }

    /* if the signer changed, still need to fill
       in the "next" link */

    if (ctx->nextsign && ctx->next == NULL)
      {
      switch (finding)
        {
        case jarTypeSF:

          ctx->next = ZZ_ListHead (signer->sf);
          break;

        case jarTypeSign:

          ctx->next = ZZ_ListHead (signer->certs);
          break;
        }
      }

    PORT_Assert( ctx->next != NULL );


    while (!ZZ_ListIterDone (list, ctx->next))
      {
      *it = ctx->next->thing;
      ctx->next = ctx->next->next;

      if (!it || !*it || (*it)->type != finding)
        continue;

      if (ctx->pattern && *ctx->pattern)
        {
        if (PORT_Strcmp ((*it)->pathname, ctx->pattern))
          continue;
        }

      /* We have a valid match. If this is a jarTypeSign
         return the certificate instead.. */

      if (ctx->finding == jarTypeSign)
        {
        JAR_Item *itt;

        /* just the first one for now */
        if (jar_find_first_cert (signer, jarTypeSign, &itt) >= 0) 
           {
           *it = itt;
           return 0;
           }

        continue;      
        }

      return 0;
      }

    } /* end while */
  }
char* JAR_get_error ( int  status)

Definition at line 756 of file jar.c.

  { 
  char *errstring = NULL;

  switch (status)
    {
    case JAR_ERR_GENERAL:
      errstring = "General JAR file error";
      break;

    case JAR_ERR_FNF:
      errstring = "JAR file not found";
      break;

    case JAR_ERR_CORRUPT:
      errstring = "Corrupt JAR file";
      break;

    case JAR_ERR_MEMORY:
      errstring = "Out of memory";
      break;

    case JAR_ERR_DISK:
      errstring = "Disk error (perhaps out of space)";
      break;

    case JAR_ERR_ORDER:
      errstring = "Inconsistent files in META-INF directory";
      break;

    case JAR_ERR_SIG:
      errstring = "Invalid digital signature file";
      break;

    case JAR_ERR_METADATA:
      errstring = "JAR metadata failed verification";
      break;

    case JAR_ERR_ENTRY:
      errstring = "No Manifest entry for this JAR entry";
      break;

    case JAR_ERR_HASH:
      errstring = "Invalid Hash of this JAR entry";
      break;

    case JAR_ERR_PK7:
      errstring = "Strange PKCS7 or RSA failure";
      break;

    case JAR_ERR_PNF:
      errstring = "Path not found inside JAR file";
      break;

    default:
      if (jar_fn_GetString)
        {
        errstring = jar_fn_GetString (status);
        }
      else
        {
        /* this is not a normal situation, and would only be
           called in cases of improper initialization */

        char *err;

        err = (char*)PORT_Alloc (40);
        if (err)
          PR_snprintf (err, 39,  "Error %d\n", status);
        else
          err = "Error! Bad! Out of memory!";

        return err;
        }
      break;
    }

  return errstring;
  }
char* JAR_get_filename ( JAR jar)

Definition at line 680 of file jar.c.

  {
  return jar->filename;
  }
int JAR_get_metainfo ( JAR jar,
char *  name,
char *  header,
void **  info,
unsigned long length 
)

Definition at line 252 of file jar.c.

  {
  JAR_Item *it;

  ZZLink *link;
  ZZList *list;

  JAR_Metainfo *met;

  PORT_Assert( jar != NULL && header != NULL );

  if (jar == NULL || header == NULL)
    return JAR_ERR_PNF;

  list = jar->metainfo;

  if (ZZ_ListEmpty (list))
    return JAR_ERR_PNF;

  for (link = ZZ_ListHead (list); 
       !ZZ_ListIterDone (list, link); 
       link = link->next)
    {
    it = link->thing;
    if (it->type == jarTypeMeta)
      {
      if ((name && !it->pathname) || (!name && it->pathname))
        continue;

      if (name && it->pathname && strcmp (it->pathname, name))
        continue;

      met = (JAR_Metainfo *) it->data;

      if (!PORT_Strcasecmp (met->header, header))
        {
        *info = PORT_Strdup (met->info);
        *length = PORT_Strlen (met->info);
        return 0;
        }
      }
    }

  return JAR_ERR_PNF;
  }
char* JAR_get_url ( JAR jar)

Definition at line 693 of file jar.c.

  {
  return jar->url;
  }
void JAR_init_callbacks ( char *(*)(int string_cb,
void *(*)(void find_cx,
void *(*)(void init_cx 
)

Definition at line 734 of file jar.c.

  {
  jar_fn_GetString = string_cb;
  jar_fn_FindSomeContext = find_cx;
  jar_fn_GetInitContext = init_cx;
  }
JAR* JAR_new ( void  )

Definition at line 61 of file jar.c.

  {
  JAR *jar;

  if ((jar = (JAR*)PORT_ZAlloc (sizeof (JAR))) == NULL)
    goto loser;

  if ((jar->manifest = ZZ_NewList()) == NULL)
    goto loser;

  if ((jar->hashes = ZZ_NewList()) == NULL)
    goto loser;

  if ((jar->phy = ZZ_NewList()) == NULL)
    goto loser;

  if ((jar->metainfo = ZZ_NewList()) == NULL)
    goto loser;

  if ((jar->signers = ZZ_NewList()) == NULL)
    goto loser;

  return jar;

loser:

  if (jar)
    {
    if (jar->manifest)
      ZZ_DestroyList (jar->manifest);

    if (jar->hashes)
      ZZ_DestroyList (jar->hashes);

    if (jar->phy)
      ZZ_DestroyList (jar->phy);

    if (jar->metainfo)
      ZZ_DestroyList (jar->metainfo);

    if (jar->signers)
      ZZ_DestroyList (jar->signers);

    PORT_Free (jar);
    }

  return NULL;
  }
int JAR_parse_manifest ( JAR jar,
char ZHUGEP raw_manifest,
long  length,
const char *  path,
const char *  url 
)

Definition at line 142 of file jarver.c.

  {

#if defined(XP_WIN16)
    PORT_Assert( !IsBadHugeReadPtr(raw_manifest, length) );
#endif

  /* fill in the path, if supplied. This is a the location
     of the jar file on disk, if known */

  if (jar->filename == NULL && path)
    {
    jar->filename = PORT_Strdup (path);
    if (jar->filename == NULL)
      return JAR_ERR_MEMORY;
    }

  /* fill in the URL, if supplied. This is the place
     from which the jar file was retrieved. */

  if (jar->url == NULL && url)
    {
    jar->url = PORT_Strdup (url);
    if (jar->url == NULL)
      return JAR_ERR_MEMORY;
    }

  /* Determine what kind of file this is from the META-INF 
     directory. It could be MF, SF, or a binary RSA/DSA file */

  if (!xp_HUGE_STRNCASECMP (raw_manifest, "Manifest-Version:", 17))
    {
    return jar_parse_mf (jar, raw_manifest, length, path, url);
    }
  else if (!xp_HUGE_STRNCASECMP (raw_manifest, "Signature-Version:", 18))
    {
    return jar_parse_sf (jar, raw_manifest, length, path, url);
    }
  else
    {
    /* This is probably a binary signature */
    return jar_parse_sig (jar, path, raw_manifest, length);
    }
  }

Here is the caller graph for this function:

int JAR_pass_archive ( JAR jar,
jarArch  format,
char *  filename,
const char *  url 
)

Definition at line 114 of file jarfile.c.

  {
  JAR_FILE fp;
  int status = 0;

  if (filename == NULL)
    return JAR_ERR_GENERAL;

  if ((fp = JAR_FOPEN (filename, "rb")) != NULL)
    {
    if (format == jarArchGuess)
      format = (jarArch)jar_guess_jar (filename, fp);

    jar->format = format;
    jar->url = url ? PORT_Strdup (url) : NULL;
    jar->filename = PORT_Strdup (filename);

    status = jar_gen_index (jar, format, fp);

    if (status == 0)
      status = jar_extract_manifests (jar, format, fp);

    JAR_FCLOSE (fp);

    if (status < 0)
      return status;

    /* people were expecting it this way */
    return jar->valid;
    }
  else
    {
    /* file not found */
    return JAR_ERR_FNF;
    }
  }

Here is the caller graph for this function:

int JAR_pass_archive_unverified ( JAR jar,
jarArch  format,
char *  filename,
const char *  url 
)

Definition at line 158 of file jarfile.c.

{
        JAR_FILE fp;
        int status = 0;

        if (filename == NULL) {
                return JAR_ERR_GENERAL;
        }

        if ((fp = JAR_FOPEN (filename, "rb")) != NULL) {
                if (format == jarArchGuess) {
                        format = (jarArch)jar_guess_jar (filename, fp);
                }

                jar->format = format;
                jar->url = url ? PORT_Strdup (url) : NULL;
                jar->filename = PORT_Strdup (filename);

                status = jar_gen_index (jar, format, fp);

                if (status == 0) {
                        status = jar_extract_mf(jar, format, fp, "mf");
                }

                JAR_FCLOSE (fp);

                if (status < 0) {
                        return status;
                }

                /* people were expecting it this way */
                return jar->valid;
        } else {
                /* file not found */
                return JAR_ERR_FNF;
        }
}

Here is the caller graph for this function:

int JAR_set_callback ( int  type,
JAR jar,
int(*)(int status, JAR *jar, const char *metafile, char *pathname, char *errortext)  fn 
)

Definition at line 705 of file jar.c.

  {
  if (type == JAR_CB_SIGNAL)
    {
    jar->signal = fn;
    return 0;
    }
  else
    return -1;
  }
int JAR_set_context ( JAR jar,
void mw 
)

Here is the caller graph for this function:

int PR_CALLBACK JAR_stash_cert ( JAR jar,
long  keylen,
void key 
)

Definition at line 1422 of file jarver.c.

  {
  int result = 0;

  char *nickname;
  CERTCertTrust trust;

  CERTCertDBHandle *certdb;
  CERTCertificate *cert, *newcert;

  cert = jar_get_certificate (jar, keylen, key, &result);

  if (result < 0)
    return result;

  if (cert == NULL)
    return JAR_ERR_GENERAL;

  if ((certdb = JAR_open_database()) == NULL)
    return JAR_ERR_GENERAL;

  /* Attempt to give a name to the newish certificate */
  nickname = jar_choose_nickname (cert);

#ifdef USE_MOZ_THREAD
  newcert = jar_moz_nickname (certdb, nickname);
#else
  newcert = CERT_FindCertByNickname (certdb, nickname);
#endif

  if (newcert && newcert->isperm) 
    {
    /* already in permanant database */
    return 0;
    }

  if (newcert) cert = newcert;

  /* FIX, since FindCert returns a bogus dbhandle
     set it ourselves */

  cert->dbhandle = certdb;

#if 0
  nickname = cert->subjectName;
  if (nickname)
    {
    /* Not checking for a conflict here. But this should
       be a new cert or it would have been found earlier. */

    nickname = jar_cert_element (nickname, "CN=", 1);

    if (SEC_CertNicknameConflict (nickname, cert->dbhandle))
      {
      /* conflict */
      nickname = PORT_Realloc (&nickname, PORT_Strlen (nickname) + 3);

      /* Beyond one copy, there are probably serious problems 
         so we will stop at two rather than counting.. */

      PORT_Strcat (nickname, " #2");
      }
    }
#endif

  if (nickname != NULL)
    {
    PORT_Memset ((void *) &trust, 0, sizeof(trust));

#ifdef USE_MOZ_THREAD
    if (jar_moz_perm (cert, nickname, &trust) != SECSuccess) 
#else
    if (CERT_AddTempCertToPerm (cert, nickname, &trust) != SECSuccess) 
#endif
      {
      /* XXX might want to call PORT_GetError here */
      result = JAR_ERR_GENERAL;
      }
    }

  JAR_close_database (certdb);

  return result;
  }
int JAR_verified_extract ( JAR jar,
char *  path,
char *  outpath 
)

Definition at line 206 of file jarfile.c.

  {
  int status;

  status = JAR_extract (jar, path, outpath);

  if (status >= 0)
    return jar_verify_extract (jar, path, outpath);
  else
    return status;
  }

Here is the caller graph for this function:

int PR_CALLBACK JAR_verify_digest ( JAR jar,
const char *  name,
JAR_Digest dig 
)

Definition at line 991 of file jarver.c.

  {
  JAR_Item *it;

  JAR_Digest *shindig;

  ZZLink *link;
  ZZList *list;

  int result1, result2;

  list = jar->hashes;

  result1 = result2 = 0;

  if (jar->valid < 0)
    {
    /* signature not valid */
    return JAR_ERR_SIG;
    }

  if (ZZ_ListEmpty (list))
    {
    /* empty list */
    return JAR_ERR_PNF;
    }

  for (link = ZZ_ListHead (list); 
       !ZZ_ListIterDone (list, link); 
       link = link->next)
    {
    it = link->thing;
    if (it->type == jarTypeMF 
           && it->pathname && !PORT_Strcmp (it->pathname, name))
      {
      shindig = (JAR_Digest *) it->data;

      if (shindig->md5_status)
        {
        if (shindig->md5_status == jarHashBad)
          return JAR_ERR_HASH;
        else
          result1 = memcmp (dig->md5, shindig->md5, MD5_LENGTH);
        }

      if (shindig->sha1_status)
        {
        if (shindig->sha1_status == jarHashBad)
          return JAR_ERR_HASH;
        else
          result2 = memcmp (dig->sha1, shindig->sha1, SHA1_LENGTH);
        }

      return (result1 == 0 && result2 == 0) ? 0 : JAR_ERR_HASH;
      }
    }

  return JAR_ERR_PNF;
  }

Here is the caller graph for this function: