~ubuntu-branches/ubuntu/maverick/nss/maverick

« back to all changes in this revision

Viewing changes to mozilla/security/nss/lib/jar/jar.h

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2010-03-25 13:46:06 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20100325134606-bl6liuok2w9l7snv
Tags: 3.12.6-0ubuntu1
* New upstream release 3.12.6 RTM (NSS_3_12_6_RTM)
  - fixes CVE-2009-3555 aka US-CERT VU#120541
* Adjust patches to changed upstream code base
  - update debian/patches/38_kbsd.patch
  - update debian/patches/38_mips64_build.patch
  - update debian/patches/85_security_load.patch
* Remove patches that are merged upstream
  - delete debian/patches/91_nonexec_stack.patch
  - update debian/patches/series
* Bump nspr dependency to 4.8
  - update debian/control
* Add new symbols for 3.12.6
  - update debian/libnss3-1d.symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
/* nspr 2.0 includes */
51
51
#include "prio.h"
52
52
 
53
 
#ifndef ZHUGEP
54
 
#ifdef XP_WIN16
55
 
#define ZHUGEP __huge
56
 
#else
57
53
#define ZHUGEP
58
 
#endif
59
 
#endif
60
54
 
61
55
#include <stdio.h>
62
56
 
63
57
/* various types */
64
58
 
65
 
typedef enum
66
 
  {
67
 
  jarTypeMF = 2,
68
 
  jarTypeSF = 3,
69
 
  jarTypeMeta = 6,
70
 
  jarTypePhy = 7,
71
 
  jarTypeSign = 10,
72
 
  jarTypeSect = 11,
73
 
  jarTypeOwner = 13
74
 
  }
75
 
jarType;
 
59
typedef enum {
 
60
    jarTypeMF = 2,
 
61
    jarTypeSF = 3,
 
62
    jarTypeMeta = 6,
 
63
    jarTypePhy = 7,
 
64
    jarTypeSign = 10,
 
65
    jarTypeSect = 11,
 
66
    jarTypeOwner = 13
 
67
} jarType;
76
68
 
77
69
/* void data in ZZList's contain JAR_Item type */
78
 
 
79
 
typedef struct JAR_Item_
80
 
  {
81
 
  char *pathname;        /* relative. inside zip file */
82
 
  jarType type;          /* various types */
83
 
  size_t size;           /* size of data below */
84
 
  void *data;            /* totally opaque */
85
 
  }
86
 
JAR_Item;
87
 
 
 
70
typedef struct JAR_Item_ {
 
71
    char *pathname;        /* relative. inside zip file */
 
72
    jarType type;          /* various types */
 
73
    size_t size;           /* size of data below */
 
74
    void *data;            /* totally opaque */
 
75
} JAR_Item;
88
76
 
89
77
/* hashes */
90
 
 
91
 
typedef enum
92
 
  {
93
 
  jarHashNone = 0,
94
 
  jarHashBad = 1,
95
 
  jarHashPresent = 2
96
 
  }
97
 
jarHash;
98
 
 
99
 
typedef struct JAR_Digest_
100
 
  {
101
 
  jarHash md5_status;
102
 
  unsigned char md5 [MD5_LENGTH];
103
 
  jarHash sha1_status;
104
 
  unsigned char sha1 [SHA1_LENGTH];
105
 
  }
106
 
JAR_Digest;
107
 
 
 
78
typedef enum {
 
79
    jarHashNone = 0,
 
80
    jarHashBad = 1,
 
81
    jarHashPresent = 2
 
82
} jarHash;
 
83
 
 
84
typedef struct JAR_Digest_ {
 
85
    jarHash md5_status;
 
86
    unsigned char md5 [MD5_LENGTH];
 
87
    jarHash sha1_status;
 
88
    unsigned char sha1 [SHA1_LENGTH];
 
89
} JAR_Digest;
108
90
 
109
91
/* physical archive formats */
110
 
 
111
 
typedef enum
112
 
  {
113
 
  jarArchGuess = 0,
114
 
  jarArchNone = 1,
115
 
  jarArchZip = 2,
116
 
  jarArchTar = 3
117
 
  }
118
 
jarArch;
119
 
 
 
92
typedef enum {
 
93
    jarArchGuess = 0,
 
94
    jarArchNone = 1,
 
95
    jarArchZip = 2,
 
96
    jarArchTar = 3
 
97
} jarArch;
120
98
 
121
99
#include "jar-ds.h"
122
100
 
 
101
struct JAR_;
 
102
 
 
103
typedef int jar_settable_callback_fn(int status, struct JAR_ *jar, 
 
104
                                     const char *metafile, char *pathname, 
 
105
                                     char *errortext);
 
106
 
123
107
/* jar object */
124
 
 
125
 
typedef struct JAR_
126
 
  {
127
 
  jarArch format;       /* physical archive format */ 
128
 
  char *url;            /* Where it came from */
129
 
  char *filename;       /* Disk location */
130
 
  FILE *fp;             /* For multiple extractions */    /* JAR_FILE */
131
 
 
132
 
  /* various linked lists */
133
 
 
134
 
  ZZList *manifest;     /* Digests of MF sections */
135
 
  ZZList *hashes;       /* Digests of actual signed files */
136
 
  ZZList *phy;          /* Physical layout of JAR file */
137
 
  ZZList *metainfo;     /* Global metainfo */
138
 
 
139
 
  JAR_Digest *globalmeta;  /* digest of .MF global portion */
140
 
 
141
 
  /* Below will change to a linked list to support multiple sigs */
142
 
 
143
 
  int pkcs7;            /* Enforced opaqueness */
144
 
  int valid;            /* PKCS7 signature validated */
145
 
 
146
 
  ZZList *signers;      /* the above, per signer */
147
 
 
148
 
  /* Window context, very necessary for PKCS11 now */
149
 
 
150
 
  void *mw;             /* MWContext window context */
151
 
 
152
 
  /* Signal callback function */
153
 
 
154
 
  int (*signal) (int status, struct JAR_ *jar, 
155
 
     const char *metafile, char *pathname, char *errorstring);
156
 
  }
157
 
JAR;
158
 
 
 
108
typedef struct JAR_ {
 
109
    jarArch format;       /* physical archive format */
 
110
 
 
111
    char *url;            /* Where it came from */
 
112
    char *filename;       /* Disk location */
 
113
    FILE *fp;             /* For multiple extractions */
 
114
    /* JAR_FILE */
 
115
 
 
116
    /* various linked lists */
 
117
    ZZList *manifest;     /* Digests of MF sections */
 
118
    ZZList *hashes;       /* Digests of actual signed files */
 
119
    ZZList *phy;          /* Physical layout of JAR file */
 
120
    ZZList *metainfo;     /* Global metainfo */
 
121
 
 
122
    JAR_Digest *globalmeta;  /* digest of .MF global portion */
 
123
 
 
124
    /* Below will change to a linked list to support multiple sigs */
 
125
    int pkcs7;            /* Enforced opaqueness */
 
126
    int valid;            /* PKCS7 signature validated */
 
127
 
 
128
    ZZList *signers;      /* the above, per signer */
 
129
 
 
130
    /* Window context, very necessary for PKCS11 now */
 
131
    void *mw;             /* MWContext window context */
 
132
 
 
133
    /* Signal callback function */
 
134
    jar_settable_callback_fn *signal;
 
135
} JAR;
159
136
 
160
137
/*
161
138
 *  Iterator
165
142
 *  multiple signers. "nextsign" is used for this purpose.
166
143
 *
167
144
 */
168
 
 
169
 
typedef struct JAR_Context_
170
 
  {
171
 
  JAR *jar;             /* Jar we are searching */
172
 
  char *pattern;        /* Regular expression */
173
 
  jarType finding;      /* Type of item to find */
174
 
  ZZLink *next;         /* Next item in find */
175
 
  ZZLink *nextsign;     /* Next signer, sometimes */
176
 
  }
177
 
JAR_Context;
178
 
 
179
 
typedef struct JAR_Signer_
180
 
  {
181
 
  int pkcs7;            /* Enforced opaqueness */
182
 
  int valid;            /* PKCS7 signature validated */
183
 
  char *owner;          /* name of .RSA file */
184
 
  JAR_Digest *digest;   /* of .SF file */
185
 
  ZZList *sf;           /* Linked list of .SF file contents */
186
 
  ZZList *certs;        /* Signing information */
187
 
  }
188
 
JAR_Signer;
189
 
 
 
145
typedef struct JAR_Context_ {
 
146
    JAR *jar;             /* Jar we are searching */
 
147
    char *pattern;        /* Regular expression */
 
148
    jarType finding;      /* Type of item to find */
 
149
    ZZLink *next;         /* Next item in find */
 
150
    ZZLink *nextsign;     /* Next signer, sometimes */
 
151
} JAR_Context;
 
152
 
 
153
typedef struct JAR_Signer_ {
 
154
    int pkcs7;            /* Enforced opaqueness */
 
155
    int valid;            /* PKCS7 signature validated */
 
156
    char *owner;          /* name of .RSA file */
 
157
    JAR_Digest *digest;   /* of .SF file */
 
158
    ZZList *sf;           /* Linked list of .SF file contents */
 
159
    ZZList *certs;        /* Signing information */
 
160
} JAR_Signer;
190
161
 
191
162
/* Meta informaton, or "policy", from the manifest file.
192
163
   Right now just one tuple per JAR_Item. */
193
 
 
194
 
typedef struct JAR_Metainfo_
195
 
  {
196
 
  char *header;
197
 
  char *info;
198
 
  }
199
 
JAR_Metainfo;
 
164
typedef struct JAR_Metainfo_ {
 
165
    char *header;
 
166
    char *info;
 
167
} JAR_Metainfo;
200
168
 
201
169
/* This should not be global */
202
 
 
203
 
typedef struct JAR_Physical_
204
 
  {
205
 
  unsigned char compression;
206
 
  unsigned long offset;
207
 
  unsigned long length;
208
 
  unsigned long uncompressed_length;
 
170
typedef struct JAR_Physical_ {
 
171
    unsigned char compression;
 
172
    unsigned long offset;
 
173
    unsigned long length;
 
174
    unsigned long uncompressed_length;
209
175
#if defined(XP_UNIX) || defined(XP_BEOS)
210
 
  uint16 mode;
 
176
    uint16 mode;
211
177
#endif
212
 
  }
213
 
JAR_Physical;
 
178
} JAR_Physical;
214
179
 
215
 
typedef struct JAR_Cert_
216
 
  {
217
 
  size_t length;
218
 
  void *key;
219
 
  CERTCertificate *cert;
220
 
  }
221
 
JAR_Cert;
 
180
typedef struct JAR_Cert_ {
 
181
    size_t length;
 
182
    void *key;
 
183
    CERTCertificate *cert;
 
184
} JAR_Cert;
222
185
 
223
186
 
224
187
/* certificate stuff */
225
 
 
226
 
typedef enum
227
 
  {
228
 
  jarCertCompany = 1,
229
 
  jarCertCA = 2,
230
 
  jarCertSerial = 3,
231
 
  jarCertExpires = 4,
232
 
  jarCertNickname = 5,
233
 
  jarCertFinger = 6,
234
 
  jarCertJavaHack = 100
235
 
  }
236
 
jarCert;
 
188
typedef enum {
 
189
    jarCertCompany = 1,
 
190
    jarCertCA = 2,
 
191
    jarCertSerial = 3,
 
192
    jarCertExpires = 4,
 
193
    jarCertNickname = 5,
 
194
    jarCertFinger = 6,
 
195
    jarCertJavaHack = 100
 
196
} jarCert;
237
197
 
238
198
/* callback types */
239
 
 
240
199
#define JAR_CB_SIGNAL   1
241
200
 
242
 
 
243
 
/* 
 
201
/*
244
202
 *  This is the base for the JAR error codes. It will
245
203
 *  change when these are incorporated into allxpstr.c,
246
204
 *  but right now they won't let me put them there.
247
205
 *
248
206
 */
249
 
 
250
207
#ifndef SEC_ERR_BASE
251
 
#define SEC_ERR_BASE            (-0x2000)
 
208
#define SEC_ERR_BASE        (-0x2000)
252
209
#endif
253
 
 
254
 
#define JAR_BASE                SEC_ERR_BASE + 300
 
210
 
 
211
#define JAR_BASE        SEC_ERR_BASE + 300
255
212
 
256
213
/* Jar specific error definitions */
257
214
 
258
 
#define JAR_ERR_GENERAL         (JAR_BASE + 1)
 
215
#define JAR_ERR_GENERAL         (JAR_BASE + 1)
259
216
#define JAR_ERR_FNF             (JAR_BASE + 2)
260
 
#define JAR_ERR_CORRUPT         (JAR_BASE + 3)
261
 
#define JAR_ERR_MEMORY          (JAR_BASE + 4)
262
 
#define JAR_ERR_DISK            (JAR_BASE + 5)
263
 
#define JAR_ERR_ORDER           (JAR_BASE + 6)
 
217
#define JAR_ERR_CORRUPT         (JAR_BASE + 3)
 
218
#define JAR_ERR_MEMORY          (JAR_BASE + 4)
 
219
#define JAR_ERR_DISK            (JAR_BASE + 5)
 
220
#define JAR_ERR_ORDER           (JAR_BASE + 6)
264
221
#define JAR_ERR_SIG             (JAR_BASE + 7)
265
 
#define JAR_ERR_METADATA        (JAR_BASE + 8)
266
 
#define JAR_ERR_ENTRY           (JAR_BASE + 9)
267
 
#define JAR_ERR_HASH            (JAR_BASE + 10)
 
222
#define JAR_ERR_METADATA        (JAR_BASE + 8)
 
223
#define JAR_ERR_ENTRY           (JAR_BASE + 9)
 
224
#define JAR_ERR_HASH            (JAR_BASE + 10)
268
225
#define JAR_ERR_PK7             (JAR_BASE + 11)
269
226
#define JAR_ERR_PNF             (JAR_BASE + 12)
270
227
 
271
 
 
272
 
/*
273
 
 *  Birth and death 
274
 
 *
275
 
 */
 
228
/* Function declarations */
276
229
 
277
230
extern JAR *JAR_new (void);
278
231
 
280
233
 
281
234
extern char *JAR_get_error (int status);
282
235
 
283
 
extern int JAR_set_callback (int type, JAR *jar, 
284
 
  int (*fn) (int status, JAR *jar, 
285
 
  const char *metafile, char *pathname, char *errortext));
 
236
extern int JAR_set_callback(int type, JAR *jar, jar_settable_callback_fn *fn);
286
237
 
287
 
extern void JAR_init_callbacks
288
 
  ( char *(*string_cb)(int), void *(*find_cx)(void), void *(*init_cx)(void) );
 
238
extern void 
 
239
JAR_init_callbacks(char *(*string_cb)(int), 
 
240
                   void *(*find_cx)(void), 
 
241
                   void *(*init_cx)(void) );
289
242
 
290
243
/*
291
244
 *  JAR_set_context
294
247
 *  before any crypto routines may be called. This will require
295
248
 *  a window context if used from inside Mozilla.
296
249
 *
297
 
 *  Call this routine with your context before calling 
 
250
 *  Call this routine with your context before calling
298
251
 *  verifying or signing. If you have no context, call with NULL
299
252
 *  and one will be chosen for you.
300
253
 *
301
254
 */
302
 
 
303
255
int JAR_set_context (JAR *jar, void /*MWContext*/ *mw);
304
256
 
305
257
/*
315
267
 *
316
268
 *     JAR_Item *item;
317
269
 *     JAR_find (jar, "*.class", jarTypeMF);
318
 
 *     while (JAR_find_next (jar, &item) >= 0) 
319
 
 *       { do stuff }
 
270
 *     while (JAR_find_next (jar, &item) >= 0)
 
271
 *       { do stuff }
320
272
 *
321
273
 */
322
274
 
323
 
 
324
275
/* Replacement functions with an external context */
325
276
 
326
277
extern JAR_Context *JAR_find (JAR *jar, char *pattern, jarType type);
329
280
 
330
281
extern void JAR_find_end (JAR_Context *ctx);
331
282
 
332
 
 
333
283
/*
334
284
 *  Function to parse manifest file:
335
285
 *
336
286
 *  Many signatures may be attached to a single filename located
337
287
 *  inside the zip file. We only support one.
338
288
 *
339
 
 *  Several manifests may be included in the zip file. 
 
289
 *  Several manifests may be included in the zip file.
340
290
 *
341
291
 *  You must pass the MANIFEST.MF file before any .SF files.
342
292
 *
355
305
 *
356
306
 */
357
307
 
358
 
extern int JAR_parse_manifest 
359
 
    (JAR *jar, char ZHUGEP *raw_manifest, 
360
 
       long length, const char *path, const char *url);
 
308
extern int 
 
309
JAR_parse_manifest(JAR *jar, char *raw_manifest, long length, const char *path,
 
310
                   const char *url);
361
311
 
362
312
/*
363
313
 *  Verify data (nonstreaming). The signature is actually
365
315
 *
366
316
 */
367
317
 
368
 
extern JAR_Digest * PR_CALLBACK JAR_calculate_digest 
369
 
    (void ZHUGEP *data, long length);
370
 
 
371
 
extern int PR_CALLBACK JAR_verify_digest
372
 
    (JAR *jar, const char *name, JAR_Digest *dig);
373
 
 
374
 
extern int JAR_digest_file (char *filename, JAR_Digest *dig);
 
318
extern JAR_Digest * PR_CALLBACK 
 
319
JAR_calculate_digest(void *data, long length);
 
320
 
 
321
extern int PR_CALLBACK 
 
322
JAR_verify_digest(JAR *jar, const char *name, JAR_Digest *dig);
 
323
 
 
324
extern int 
 
325
JAR_digest_file(char *filename, JAR_Digest *dig);
375
326
 
376
327
/*
377
328
 *  Get attribute from certificate:
382
333
 *
383
334
 */
384
335
 
385
 
extern int PR_CALLBACK JAR_cert_attribute
386
 
    (JAR *jar, jarCert attrib, long keylen, void *key, 
387
 
       void **result, unsigned long *length);
 
336
extern int PR_CALLBACK 
 
337
JAR_cert_attribute(JAR *jar, jarCert attrib, long keylen, void *key,
 
338
                   void **result, unsigned long *length);
388
339
 
389
340
/*
390
341
 *  Meta information
391
342
 *
392
343
 *  Currently, since this call does not support passing of an owner
393
344
 *  (certificate, or physical name of the .sf file), it is restricted to
394
 
 *  returning information located in the manifest.mf file. 
 
345
 *  returning information located in the manifest.mf file.
395
346
 *
396
347
 *  Meta information is a name/value pair inside the archive file. Here,
397
348
 *  the name is passed in *header and value returned in **info.
403
354
 *
404
355
 */
405
356
 
406
 
extern int JAR_get_metainfo
407
 
    (JAR *jar, char *name, char *header, void **info, unsigned long *length);
 
357
extern int 
 
358
JAR_get_metainfo(JAR *jar, char *name, char *header, void **info, 
 
359
                 unsigned long *length);
408
360
 
409
361
extern char *JAR_get_filename (JAR *jar);
410
362
 
411
363
extern char *JAR_get_url (JAR *jar);
412
364
 
413
 
/*
414
 
 *  Return an HTML mockup of a certificate or signature.
415
 
 *
416
 
 *  Returns a zero terminated ascii string
417
 
 *  in raw HTML format.
418
 
 *
419
 
 */
420
 
 
421
 
extern char *JAR_cert_html
422
 
    (JAR *jar, int style, long keylen, void *key, int *result);
423
 
 
424
365
/* save the certificate with this fingerprint in persistent
425
 
   storage, somewhere, for retrieval in a future session when there 
 
366
   storage, somewhere, for retrieval in a future session when there
426
367
   is no corresponding JAR structure. */
427
 
 
428
 
extern int PR_CALLBACK JAR_stash_cert
429
 
        (JAR *jar, long keylen, void *key);
 
368
extern int PR_CALLBACK 
 
369
JAR_stash_cert(JAR *jar, long keylen, void *key);
430
370
 
431
371
/* retrieve a certificate presumably stashed with the above
432
372
   function, but may be any certificate. Type is &CERTCertificate */
433
 
 
434
 
void *JAR_fetch_cert (long length, void *key);
 
373
CERTCertificate *
 
374
JAR_fetch_cert(long length, void *key);
435
375
 
436
376
/*
437
377
 *  New functions to handle archives alone
438
378
 *    (call JAR_new beforehand)
439
379
 *
440
380
 *  JAR_pass_archive acts much like parse_manifest. Certificates
441
 
 *  are returned in the JAR structure but as opaque data. When calling 
442
 
 *  JAR_verified_extract you still need to decide which of these 
443
 
 *  certificates to honor. 
 
381
 *  are returned in the JAR structure but as opaque data. When calling
 
382
 *  JAR_verified_extract you still need to decide which of these
 
383
 *  certificates to honor.
444
384
 *
445
 
 *  Code to examine a JAR structure is in jarbert.c. You can obtain both 
 
385
 *  Code to examine a JAR structure is in jarbert.c. You can obtain both
446
386
 *  a list of filenames and certificates from traversing the linked list.
447
387
 *
448
388
 */
449
 
 
450
 
extern int JAR_pass_archive
451
 
    (JAR *jar, jarArch format, char *filename, const char *url);
 
389
extern int 
 
390
JAR_pass_archive(JAR *jar, jarArch format, char *filename, const char *url);
452
391
 
453
392
/*
454
393
 * Same thing, but don't check signatures
455
394
 */
456
 
extern int JAR_pass_archive_unverified
457
 
    (JAR *jar, jarArch format, char *filename, const char *url);
 
395
extern int 
 
396
JAR_pass_archive_unverified(JAR *jar, jarArch format, char *filename, 
 
397
                            const char *url);
458
398
 
459
399
/*
460
400
 *  Extracts a relative pathname from the archive and places it
461
 
 *  in the filename specified. 
462
 
 * 
 
401
 *  in the filename specified.
 
402
 *
463
403
 *  Call JAR_set_nailed if you want to keep the file descriptors
464
404
 *  open between multiple calls to JAR_verify_extract.
465
405
 *
466
406
 */
467
 
 
468
 
extern int JAR_verified_extract
469
 
    (JAR *jar, char *path, char *outpath);
 
407
extern int 
 
408
JAR_verified_extract(JAR *jar, char *path, char *outpath);
470
409
 
471
410
/*
472
411
 *  JAR_extract does no crypto checking. This can be used if you
473
412
 *  need to extract a manifest file or signature, etc.
474
413
 *
475
414
 */
476
 
 
477
 
extern int JAR_extract
478
 
    (JAR *jar, char *path, char *outpath);
479
 
 
480
 
 
481
 
#endif /* __JAR_h_ */ 
 
415
extern int 
 
416
JAR_extract(JAR *jar, char *path, char *outpath);
 
417
 
 
418
#endif /* __JAR_h_ */