50
50
/* nspr 2.0 includes */
63
57
/* various types */
77
69
/* void data in ZZList's contain JAR_Item type */
79
typedef struct JAR_Item_
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 */
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 */
99
typedef struct JAR_Digest_
102
unsigned char md5 [MD5_LENGTH];
104
unsigned char sha1 [SHA1_LENGTH];
84
typedef struct JAR_Digest_ {
86
unsigned char md5 [MD5_LENGTH];
88
unsigned char sha1 [SHA1_LENGTH];
109
91
/* physical archive formats */
121
99
#include "jar-ds.h"
103
typedef int jar_settable_callback_fn(int status, struct JAR_ *jar,
104
const char *metafile, char *pathname,
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 */
132
/* various linked lists */
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 */
139
JAR_Digest *globalmeta; /* digest of .MF global portion */
141
/* Below will change to a linked list to support multiple sigs */
143
int pkcs7; /* Enforced opaqueness */
144
int valid; /* PKCS7 signature validated */
146
ZZList *signers; /* the above, per signer */
148
/* Window context, very necessary for PKCS11 now */
150
void *mw; /* MWContext window context */
152
/* Signal callback function */
154
int (*signal) (int status, struct JAR_ *jar,
155
const char *metafile, char *pathname, char *errorstring);
108
typedef struct JAR_ {
109
jarArch format; /* physical archive format */
111
char *url; /* Where it came from */
112
char *filename; /* Disk location */
113
FILE *fp; /* For multiple extractions */
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 */
122
JAR_Digest *globalmeta; /* digest of .MF global portion */
124
/* Below will change to a linked list to support multiple sigs */
125
int pkcs7; /* Enforced opaqueness */
126
int valid; /* PKCS7 signature validated */
128
ZZList *signers; /* the above, per signer */
130
/* Window context, very necessary for PKCS11 now */
131
void *mw; /* MWContext window context */
133
/* Signal callback function */
134
jar_settable_callback_fn *signal;
165
142
* multiple signers. "nextsign" is used for this purpose.
169
typedef struct JAR_Context_
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 */
179
typedef struct JAR_Signer_
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 */
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 */
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 */
191
162
/* Meta informaton, or "policy", from the manifest file.
192
163
Right now just one tuple per JAR_Item. */
194
typedef struct JAR_Metainfo_
164
typedef struct JAR_Metainfo_ {
201
169
/* This should not be global */
203
typedef struct JAR_Physical_
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)
215
typedef struct JAR_Cert_
219
CERTCertificate *cert;
180
typedef struct JAR_Cert_ {
183
CERTCertificate *cert;
224
187
/* certificate stuff */
234
jarCertJavaHack = 100
195
jarCertJavaHack = 100
238
198
/* callback types */
240
199
#define JAR_CB_SIGNAL 1
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.
250
207
#ifndef SEC_ERR_BASE
251
#define SEC_ERR_BASE (-0x2000)
208
#define SEC_ERR_BASE (-0x2000)
254
#define JAR_BASE SEC_ERR_BASE + 300
211
#define JAR_BASE SEC_ERR_BASE + 300
256
213
/* Jar specific error definitions */
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)
228
/* Function declarations */
277
230
extern JAR *JAR_new (void);
281
234
extern char *JAR_get_error (int status);
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);
287
extern void JAR_init_callbacks
288
( char *(*string_cb)(int), void *(*find_cx)(void), void *(*init_cx)(void) );
239
JAR_init_callbacks(char *(*string_cb)(int),
240
void *(*find_cx)(void),
241
void *(*init_cx)(void) );
291
244
* JAR_set_context
368
extern JAR_Digest * PR_CALLBACK JAR_calculate_digest
369
(void ZHUGEP *data, long length);
371
extern int PR_CALLBACK JAR_verify_digest
372
(JAR *jar, const char *name, JAR_Digest *dig);
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);
321
extern int PR_CALLBACK
322
JAR_verify_digest(JAR *jar, const char *name, JAR_Digest *dig);
325
JAR_digest_file(char *filename, JAR_Digest *dig);
377
328
* Get attribute from certificate:
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);
390
341
* Meta information
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.
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.
406
extern int JAR_get_metainfo
407
(JAR *jar, char *name, char *header, void **info, unsigned long *length);
358
JAR_get_metainfo(JAR *jar, char *name, char *header, void **info,
359
unsigned long *length);
409
361
extern char *JAR_get_filename (JAR *jar);
411
363
extern char *JAR_get_url (JAR *jar);
414
* Return an HTML mockup of a certificate or signature.
416
* Returns a zero terminated ascii string
417
* in raw HTML format.
421
extern char *JAR_cert_html
422
(JAR *jar, int style, long keylen, void *key, int *result);
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. */
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);
431
371
/* retrieve a certificate presumably stashed with the above
432
372
function, but may be any certificate. Type is &CERTCertificate */
434
void *JAR_fetch_cert (long length, void *key);
374
JAR_fetch_cert(long length, void *key);
437
377
* New functions to handle archives alone
438
378
* (call JAR_new beforehand)
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.
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.
450
extern int JAR_pass_archive
451
(JAR *jar, jarArch format, char *filename, const char *url);
390
JAR_pass_archive(JAR *jar, jarArch format, char *filename, const char *url);
454
393
* Same thing, but don't check signatures
456
extern int JAR_pass_archive_unverified
457
(JAR *jar, jarArch format, char *filename, const char *url);
396
JAR_pass_archive_unverified(JAR *jar, jarArch format, char *filename,
460
400
* Extracts a relative pathname from the archive and places it
461
* in the filename specified.
401
* in the filename specified.
463
403
* Call JAR_set_nailed if you want to keep the file descriptors
464
404
* open between multiple calls to JAR_verify_extract.
468
extern int JAR_verified_extract
469
(JAR *jar, char *path, char *outpath);
408
JAR_verified_extract(JAR *jar, char *path, char *outpath);
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.
477
extern int JAR_extract
478
(JAR *jar, char *path, char *outpath);
481
#endif /* __JAR_h_ */
416
JAR_extract(JAR *jar, char *path, char *outpath);
418
#endif /* __JAR_h_ */