~ubuntu-branches/ubuntu/lucid/seamonkey/lucid-security

« back to all changes in this revision

Viewing changes to security/nss-fips/lib/jar/jar.c

  • Committer: Bazaar Package Importer
  • Author(s): Fabien Tassin
  • Date: 2008-07-29 21:29:02 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080729212902-spm9kpvchp9udwbw
Tags: 1.1.11+nobinonly-0ubuntu1
* New security upstream release: 1.1.11 (LP: #218534)
  Fixes USN-602-1, USN-619-1, USN-623-1 and USN-629-1
* Refresh diverged patch:
  - update debian/patches/80_security_build.patch
* Fix FTBFS with missing -lfontconfig
  - add debian/patches/11_fix_ftbfs_with_fontconfig.patch
  - update debian/patches/series
* Build with default gcc (hardy: 4.2, intrepid: 4.3)
  - update debian/rules
  - update debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ***** BEGIN LICENSE BLOCK *****
 
2
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
3
 *
 
4
 * The contents of this file are subject to the Mozilla Public License Version
 
5
 * 1.1 (the "License"); you may not use this file except in compliance with
 
6
 * the License. You may obtain a copy of the License at
 
7
 * http://www.mozilla.org/MPL/
 
8
 *
 
9
 * Software distributed under the License is distributed on an "AS IS" basis,
 
10
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
11
 * for the specific language governing rights and limitations under the
 
12
 * License.
 
13
 *
 
14
 * The Original Code is the Netscape security libraries.
 
15
 *
 
16
 * The Initial Developer of the Original Code is
 
17
 * Netscape Communications Corporation.
 
18
 * Portions created by the Initial Developer are Copyright (C) 1994-2000
 
19
 * the Initial Developer. All Rights Reserved.
 
20
 *
 
21
 * Contributor(s):
 
22
 *
 
23
 * Alternatively, the contents of this file may be used under the terms of
 
24
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
25
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
26
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
27
 * of those above. If you wish to allow use of your version of this file only
 
28
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
29
 * use your version of this file under the terms of the MPL, indicate your
 
30
 * decision by deleting the provisions above and replace them with the notice
 
31
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
32
 * the provisions above, a recipient may use your version of this file under
 
33
 * the terms of any one of the MPL, the GPL or the LGPL.
 
34
 *
 
35
 * ***** END LICENSE BLOCK ***** */
 
36
 
 
37
/*
 
38
 *  JAR.C
 
39
 *
 
40
 *  Jarnature.
 
41
 *  Routines common to signing and validating.
 
42
 *
 
43
 */
 
44
 
 
45
#include "jar.h"
 
46
#include "jarint.h"
 
47
 
 
48
static void jar_destroy_list (ZZList *list);
 
49
 
 
50
static int jar_find_first_cert 
 
51
    (JAR_Signer *signer, int type, JAR_Item **it);
 
52
 
 
53
/*
 
54
 *  J A R _ n e w 
 
55
 *
 
56
 *  Create a new instantiation of a manifest representation.
 
57
 *  Use this as a token to any calls to this API.
 
58
 *
 
59
 */
 
60
 
 
61
JAR *JAR_new (void)
 
62
  {
 
63
  JAR *jar;
 
64
 
 
65
  if ((jar = (JAR*)PORT_ZAlloc (sizeof (JAR))) == NULL)
 
66
    goto loser;
 
67
 
 
68
  if ((jar->manifest = ZZ_NewList()) == NULL)
 
69
    goto loser;
 
70
 
 
71
  if ((jar->hashes = ZZ_NewList()) == NULL)
 
72
    goto loser;
 
73
 
 
74
  if ((jar->phy = ZZ_NewList()) == NULL)
 
75
    goto loser;
 
76
 
 
77
  if ((jar->metainfo = ZZ_NewList()) == NULL)
 
78
    goto loser;
 
79
 
 
80
  if ((jar->signers = ZZ_NewList()) == NULL)
 
81
    goto loser;
 
82
 
 
83
  return jar;
 
84
 
 
85
loser:
 
86
 
 
87
  if (jar)
 
88
    {
 
89
    if (jar->manifest)
 
90
      ZZ_DestroyList (jar->manifest);
 
91
 
 
92
    if (jar->hashes)
 
93
      ZZ_DestroyList (jar->hashes);
 
94
 
 
95
    if (jar->phy)
 
96
      ZZ_DestroyList (jar->phy);
 
97
 
 
98
    if (jar->metainfo)
 
99
      ZZ_DestroyList (jar->metainfo);
 
100
 
 
101
    if (jar->signers)
 
102
      ZZ_DestroyList (jar->signers);
 
103
 
 
104
    PORT_Free (jar);
 
105
    }
 
106
 
 
107
  return NULL;
 
108
  }
 
109
 
 
110
/* 
 
111
 *  J A R _ d e s t r o y
 
112
 *
 
113
 *  Godzilla.
 
114
 *
 
115
 */
 
116
 
 
117
void PR_CALLBACK JAR_destroy (JAR *jar)
 
118
  {
 
119
  PORT_Assert( jar != NULL );
 
120
 
 
121
  if (jar == NULL)
 
122
    return;
 
123
 
 
124
  if (jar->fp) JAR_FCLOSE ((PRFileDesc*)jar->fp);
 
125
 
 
126
  if (jar->url)      PORT_Free (jar->url);
 
127
  if (jar->filename) PORT_Free (jar->filename);
 
128
 
 
129
  /* Free the linked list elements */
 
130
 
 
131
  jar_destroy_list (jar->manifest);
 
132
  ZZ_DestroyList (jar->manifest);
 
133
 
 
134
  jar_destroy_list (jar->hashes);
 
135
  ZZ_DestroyList (jar->hashes);
 
136
 
 
137
  jar_destroy_list (jar->phy);
 
138
  ZZ_DestroyList (jar->phy);
 
139
 
 
140
  jar_destroy_list (jar->metainfo);
 
141
  ZZ_DestroyList (jar->metainfo);
 
142
 
 
143
  jar_destroy_list (jar->signers);
 
144
  ZZ_DestroyList (jar->signers);
 
145
 
 
146
  PORT_Free (jar);
 
147
  }
 
148
 
 
149
static void jar_destroy_list (ZZList *list)
 
150
  {
 
151
  ZZLink *link, *oldlink;
 
152
 
 
153
  JAR_Item *it;
 
154
 
 
155
  JAR_Physical *phy;
 
156
  JAR_Digest *dig;
 
157
  JAR_Cert *fing;
 
158
  JAR_Metainfo *met;
 
159
  JAR_Signer *signer;
 
160
 
 
161
  if (list && !ZZ_ListEmpty (list))
 
162
    {
 
163
    link = ZZ_ListHead (list);
 
164
 
 
165
    while (!ZZ_ListIterDone (list, link))
 
166
      {
 
167
      it = link->thing;
 
168
      if (!it) goto next;
 
169
 
 
170
      if (it->pathname) PORT_Free (it->pathname);
 
171
 
 
172
      switch (it->type)
 
173
        {
 
174
        case jarTypeMeta:
 
175
 
 
176
          met = (JAR_Metainfo *) it->data;
 
177
          if (met)
 
178
            {
 
179
            if (met->header) PORT_Free (met->header);
 
180
            if (met->info) PORT_Free (met->info);
 
181
            PORT_Free (met);
 
182
            }
 
183
          break;
 
184
 
 
185
        case jarTypePhy:
 
186
 
 
187
          phy = (JAR_Physical *) it->data;
 
188
          if (phy)
 
189
            PORT_Free (phy);
 
190
          break;
 
191
 
 
192
        case jarTypeSign:
 
193
 
 
194
          fing = (JAR_Cert *) it->data;
 
195
          if (fing)
 
196
            {
 
197
            if (fing->cert)
 
198
              CERT_DestroyCertificate (fing->cert);
 
199
            if (fing->key)
 
200
              PORT_Free (fing->key);
 
201
            PORT_Free (fing);
 
202
            }
 
203
          break;
 
204
 
 
205
        case jarTypeSect:
 
206
        case jarTypeMF:
 
207
        case jarTypeSF:
 
208
 
 
209
          dig = (JAR_Digest *) it->data;
 
210
          if (dig)
 
211
            {
 
212
            PORT_Free (dig);
 
213
            }
 
214
          break;
 
215
 
 
216
        case jarTypeOwner:
 
217
 
 
218
          signer = (JAR_Signer *) it->data;
 
219
 
 
220
          if (signer)
 
221
            JAR_destroy_signer (signer);
 
222
 
 
223
          break;
 
224
 
 
225
        default:
 
226
 
 
227
          /* PORT_Assert( 1 != 2 ); */
 
228
          break;
 
229
        }
 
230
 
 
231
      PORT_Free (it);
 
232
 
 
233
    next:
 
234
 
 
235
      oldlink = link;
 
236
      link = link->next;
 
237
 
 
238
      ZZ_DestroyLink (oldlink);
 
239
      }
 
240
    }
 
241
  }
 
242
 
 
243
/*
 
244
 *  J A R _ g e t _ m e t a i n f o
 
245
 *
 
246
 *  Retrieve meta information from the manifest file.
 
247
 *  It doesn't matter whether it's from .MF or .SF, does it?
 
248
 *
 
249
 */
 
250
 
 
251
int JAR_get_metainfo
 
252
    (JAR *jar, char *name, char *header, void **info, unsigned long *length)
 
253
  {
 
254
  JAR_Item *it;
 
255
 
 
256
  ZZLink *link;
 
257
  ZZList *list;
 
258
 
 
259
  JAR_Metainfo *met;
 
260
 
 
261
  PORT_Assert( jar != NULL && header != NULL );
 
262
 
 
263
  if (jar == NULL || header == NULL)
 
264
    return JAR_ERR_PNF;
 
265
 
 
266
  list = jar->metainfo;
 
267
 
 
268
  if (ZZ_ListEmpty (list))
 
269
    return JAR_ERR_PNF;
 
270
 
 
271
  for (link = ZZ_ListHead (list); 
 
272
       !ZZ_ListIterDone (list, link); 
 
273
       link = link->next)
 
274
    {
 
275
    it = link->thing;
 
276
    if (it->type == jarTypeMeta)
 
277
      {
 
278
      if ((name && !it->pathname) || (!name && it->pathname))
 
279
        continue;
 
280
 
 
281
      if (name && it->pathname && strcmp (it->pathname, name))
 
282
        continue;
 
283
 
 
284
      met = (JAR_Metainfo *) it->data;
 
285
 
 
286
      if (!PORT_Strcasecmp (met->header, header))
 
287
        {
 
288
        *info = PORT_Strdup (met->info);
 
289
        *length = PORT_Strlen (met->info);
 
290
        return 0;
 
291
        }
 
292
      }
 
293
    }
 
294
 
 
295
  return JAR_ERR_PNF;
 
296
  }
 
297
 
 
298
/*
 
299
 *  J A R _ f i n d
 
300
 *
 
301
 *  Establish the search pattern for use
 
302
 *  by JAR_find_next, to traverse the filenames
 
303
 *  or certificates in the JAR structure.
 
304
 *
 
305
 *  See jar.h for a description on how to use.
 
306
 *
 
307
 */
 
308
 
 
309
JAR_Context *JAR_find (JAR *jar, char *pattern, jarType type)
 
310
  {
 
311
  JAR_Context *ctx;
 
312
 
 
313
  PORT_Assert( jar != NULL );
 
314
 
 
315
  if (!jar)
 
316
    return NULL;
 
317
 
 
318
  ctx = (JAR_Context *) PORT_ZAlloc (sizeof (JAR_Context));
 
319
 
 
320
  if (ctx == NULL)
 
321
    return NULL;
 
322
 
 
323
  ctx->jar = jar;
 
324
 
 
325
  if (pattern)
 
326
    {
 
327
    if ((ctx->pattern = PORT_Strdup (pattern)) == NULL)
 
328
      {
 
329
      PORT_Free (ctx);
 
330
      return NULL;
 
331
      }
 
332
    }
 
333
 
 
334
  ctx->finding = type;
 
335
 
 
336
  switch (type)
 
337
    {
 
338
    case jarTypeMF:     ctx->next = ZZ_ListHead (jar->hashes);
 
339
                        break;
 
340
 
 
341
    case jarTypeSF:
 
342
    case jarTypeSign:   ctx->next = NULL;
 
343
                        ctx->nextsign = ZZ_ListHead (jar->signers);
 
344
                        break;
 
345
 
 
346
    case jarTypeSect:   ctx->next = ZZ_ListHead (jar->manifest);
 
347
                        break;
 
348
 
 
349
    case jarTypePhy:    ctx->next = ZZ_ListHead (jar->phy);
 
350
                        break;
 
351
 
 
352
    case jarTypeOwner:  if (jar->signers)
 
353
                          ctx->next = ZZ_ListHead (jar->signers);
 
354
                        else
 
355
                          ctx->next = NULL;
 
356
                        break;
 
357
 
 
358
    case jarTypeMeta:   ctx->next = ZZ_ListHead (jar->metainfo);
 
359
                        break;
 
360
 
 
361
    default:            PORT_Assert( 1 != 2);
 
362
                        break;
 
363
    }
 
364
 
 
365
  return ctx;
 
366
  }
 
367
 
 
368
/*
 
369
 *  J A R _ f i n d _ e n d
 
370
 *
 
371
 *  Destroy the find iterator context.
 
372
 *
 
373
 */
 
374
 
 
375
void JAR_find_end (JAR_Context *ctx)
 
376
  {
 
377
  PORT_Assert( ctx != NULL );
 
378
 
 
379
  if (ctx)
 
380
    {
 
381
    if (ctx->pattern) 
 
382
      PORT_Free (ctx->pattern);
 
383
    PORT_Free (ctx);
 
384
    }
 
385
  }
 
386
 
 
387
/*
 
388
 *  J A R _ f i n d _ n e x t
 
389
 *
 
390
 *  Return the next item of the given type
 
391
 *  from one of the JAR linked lists.
 
392
 *
 
393
 */
 
394
 
 
395
int JAR_find_next (JAR_Context *ctx, JAR_Item **it)
 
396
  {
 
397
  JAR *jar;
 
398
  ZZList *list = NULL;
 
399
 
 
400
  int finding;
 
401
 
 
402
  JAR_Signer *signer = NULL;
 
403
 
 
404
  PORT_Assert( ctx != NULL );
 
405
  PORT_Assert( ctx->jar != NULL );
 
406
 
 
407
  jar = ctx->jar;
 
408
 
 
409
  /* Internally, convert jarTypeSign to jarTypeSF, and return
 
410
     the actual attached certificate later */
 
411
 
 
412
  finding = (ctx->finding == jarTypeSign) ? jarTypeSF : ctx->finding;
 
413
 
 
414
  if (ctx->nextsign)
 
415
    {
 
416
      if (ZZ_ListIterDone (jar->signers, ctx->nextsign))
 
417
       {
 
418
       *it = NULL;
 
419
       return -1;
 
420
       }
 
421
    PORT_Assert (ctx->nextsign->thing != NULL);
 
422
    signer = (JAR_Signer*)ctx->nextsign->thing->data;
 
423
    }
 
424
 
 
425
 
 
426
  /* Find out which linked list to traverse. Then if
 
427
     necessary, advance to the next linked list. */
 
428
 
 
429
  while (1)
 
430
    {
 
431
    switch (finding)
 
432
      {
 
433
      case jarTypeSign:    /* not any more */
 
434
                           PORT_Assert( finding != jarTypeSign );
 
435
                           list = signer->certs;
 
436
                           break;
 
437
 
 
438
      case jarTypeSect:    list = jar->manifest;
 
439
                           break;
 
440
 
 
441
      case jarTypePhy:     list = jar->phy;
 
442
                           break;
 
443
 
 
444
      case jarTypeSF:      /* signer, not jar */
 
445
                           PORT_Assert( signer != NULL );
 
446
                           list = signer->sf;
 
447
                           break;
 
448
 
 
449
      case jarTypeMF:      list = jar->hashes;
 
450
                           break;
 
451
 
 
452
      case jarTypeOwner:   list = jar->signers;
 
453
                           break;
 
454
 
 
455
      case jarTypeMeta:    list = jar->metainfo;
 
456
                           break;
 
457
 
 
458
      default:             PORT_Assert( 1 != 2 );
 
459
                           break;
 
460
      }
 
461
 
 
462
    if (list == NULL)
 
463
      {
 
464
      *it = NULL;
 
465
      return -1;
 
466
      }
 
467
 
 
468
    /* When looping over lists of lists, advance
 
469
       to the next signer. This is done when multiple
 
470
       signers are possible. */
 
471
 
 
472
    if (ZZ_ListIterDone (list, ctx->next))
 
473
      {
 
474
      if (ctx->nextsign && jar->signers) 
 
475
        {
 
476
        ctx->nextsign = ctx->nextsign->next;
 
477
        if (!ZZ_ListIterDone (jar->signers, ctx->nextsign)) 
 
478
          {
 
479
          PORT_Assert (ctx->nextsign->thing != NULL);
 
480
 
 
481
          signer = (JAR_Signer*)ctx->nextsign->thing->data;
 
482
          PORT_Assert( signer != NULL );
 
483
 
 
484
          ctx->next = NULL;
 
485
          continue;
 
486
          }
 
487
        }
 
488
      *it = NULL;
 
489
      return -1;
 
490
      }
 
491
 
 
492
    /* if the signer changed, still need to fill
 
493
       in the "next" link */
 
494
 
 
495
    if (ctx->nextsign && ctx->next == NULL)
 
496
      {
 
497
      switch (finding)
 
498
        {
 
499
        case jarTypeSF:
 
500
 
 
501
          ctx->next = ZZ_ListHead (signer->sf);
 
502
          break;
 
503
 
 
504
        case jarTypeSign:
 
505
 
 
506
          ctx->next = ZZ_ListHead (signer->certs);
 
507
          break;
 
508
        }
 
509
      }
 
510
 
 
511
    PORT_Assert( ctx->next != NULL );
 
512
 
 
513
 
 
514
    while (!ZZ_ListIterDone (list, ctx->next))
 
515
      {
 
516
      *it = ctx->next->thing;
 
517
      ctx->next = ctx->next->next;
 
518
 
 
519
      if (!it || !*it || (*it)->type != finding)
 
520
        continue;
 
521
 
 
522
      if (ctx->pattern && *ctx->pattern)
 
523
        {
 
524
        if (PORT_Strcmp ((*it)->pathname, ctx->pattern))
 
525
          continue;
 
526
        }
 
527
 
 
528
      /* We have a valid match. If this is a jarTypeSign
 
529
         return the certificate instead.. */
 
530
 
 
531
      if (ctx->finding == jarTypeSign)
 
532
        {
 
533
        JAR_Item *itt;
 
534
 
 
535
        /* just the first one for now */
 
536
        if (jar_find_first_cert (signer, jarTypeSign, &itt) >= 0) 
 
537
           {
 
538
           *it = itt;
 
539
           return 0;
 
540
           }
 
541
 
 
542
        continue;      
 
543
        }
 
544
 
 
545
      return 0;
 
546
      }
 
547
 
 
548
    } /* end while */
 
549
  }
 
550
 
 
551
static int jar_find_first_cert 
 
552
    (JAR_Signer *signer, int type, JAR_Item **it)
 
553
  {
 
554
  ZZLink *link;
 
555
  ZZList *list;
 
556
 
 
557
  int status = JAR_ERR_PNF;
 
558
 
 
559
  list = signer->certs;
 
560
 
 
561
  *it = NULL;
 
562
 
 
563
  if (ZZ_ListEmpty (list))
 
564
    {
 
565
    /* empty list */
 
566
    return JAR_ERR_PNF;
 
567
    }
 
568
 
 
569
  for (link = ZZ_ListHead (list); 
 
570
       !ZZ_ListIterDone (list, link); 
 
571
       link = link->next)
 
572
    {
 
573
    if (link->thing->type == type)
 
574
      {
 
575
      *it = link->thing;
 
576
      status = 0;
 
577
      break;
 
578
      }
 
579
    }
 
580
 
 
581
  return status;
 
582
  }
 
583
 
 
584
JAR_Signer *JAR_new_signer (void)
 
585
  {
 
586
  JAR_Signer *signer;
 
587
 
 
588
  signer = (JAR_Signer *) PORT_ZAlloc (sizeof (JAR_Signer));
 
589
 
 
590
  if (signer == NULL)
 
591
    goto loser;
 
592
 
 
593
 
 
594
  /* certs */
 
595
  signer->certs = ZZ_NewList();
 
596
 
 
597
  if (signer->certs == NULL)
 
598
    goto loser;
 
599
 
 
600
 
 
601
  /* sf */
 
602
  signer->sf = ZZ_NewList();
 
603
 
 
604
  if (signer->sf == NULL)
 
605
    goto loser;
 
606
 
 
607
 
 
608
  return signer;
 
609
 
 
610
 
 
611
loser:
 
612
 
 
613
  if (signer)
 
614
    {
 
615
    if (signer->certs) 
 
616
      ZZ_DestroyList (signer->certs);
 
617
 
 
618
    if (signer->sf) 
 
619
      ZZ_DestroyList (signer->sf);
 
620
 
 
621
    PORT_Free (signer);
 
622
    }
 
623
 
 
624
  return NULL;
 
625
  }
 
626
 
 
627
void JAR_destroy_signer (JAR_Signer *signer)
 
628
  {
 
629
  if (signer)
 
630
    {
 
631
    if (signer->owner) PORT_Free (signer->owner);
 
632
    if (signer->digest) PORT_Free (signer->digest);
 
633
 
 
634
    jar_destroy_list (signer->sf);
 
635
    ZZ_DestroyList (signer->sf);
 
636
 
 
637
    jar_destroy_list (signer->certs);
 
638
    ZZ_DestroyList (signer->certs);
 
639
 
 
640
    PORT_Free (signer);
 
641
    }
 
642
  }
 
643
 
 
644
JAR_Signer *jar_get_signer (JAR *jar, char *basename)
 
645
  {
 
646
  JAR_Item *it;
 
647
  JAR_Context *ctx;
 
648
 
 
649
  JAR_Signer *candidate;
 
650
  JAR_Signer *signer = NULL;
 
651
 
 
652
  ctx = JAR_find (jar, NULL, jarTypeOwner);
 
653
 
 
654
  if (ctx == NULL)
 
655
    return NULL;
 
656
 
 
657
  while (JAR_find_next (ctx, &it) >= 0)
 
658
    {
 
659
    candidate = (JAR_Signer *) it->data;
 
660
    if (*basename == '*' || !PORT_Strcmp (candidate->owner, basename))
 
661
      {
 
662
      signer = candidate;
 
663
      break;
 
664
      }
 
665
    }
 
666
 
 
667
  JAR_find_end (ctx);
 
668
 
 
669
  return signer;
 
670
  }
 
671
 
 
672
/*
 
673
 *  J A R _ g e t _ f i l e n a m e
 
674
 *
 
675
 *  Returns the filename associated with
 
676
 *  a JAR structure.
 
677
 *
 
678
 */
 
679
 
 
680
char *JAR_get_filename (JAR *jar)
 
681
  {
 
682
  return jar->filename;
 
683
  }
 
684
 
 
685
/*
 
686
 *  J A R _ g e t _ u r l
 
687
 *
 
688
 *  Returns the URL associated with
 
689
 *  a JAR structure. Nobody really uses this now.
 
690
 *
 
691
 */
 
692
 
 
693
char *JAR_get_url (JAR *jar)
 
694
  {
 
695
  return jar->url;
 
696
  }
 
697
 
 
698
/*
 
699
 *  J A R _ s e t _ c a l l b a c k
 
700
 *
 
701
 *  Register some manner of callback function for this jar. 
 
702
 *
 
703
 */
 
704
 
 
705
int JAR_set_callback (int type, JAR *jar, 
 
706
      int (*fn) (int status, JAR *jar, 
 
707
         const char *metafile, char *pathname, char *errortext))
 
708
  {
 
709
  if (type == JAR_CB_SIGNAL)
 
710
    {
 
711
    jar->signal = fn;
 
712
    return 0;
 
713
    }
 
714
  else
 
715
    return -1;
 
716
  }
 
717
 
 
718
/*
 
719
 *  Callbacks
 
720
 *
 
721
 */
 
722
 
 
723
/* To return an error string */
 
724
char *(*jar_fn_GetString) (int) = NULL;
 
725
 
 
726
/* To return an MWContext for Java */
 
727
void *(*jar_fn_FindSomeContext) (void) = NULL;
 
728
 
 
729
/* To fabricate an MWContext for FE_GetPassword */
 
730
void *(*jar_fn_GetInitContext) (void) = NULL;
 
731
 
 
732
void
 
733
JAR_init_callbacks
 
734
     ( 
 
735
     char *(*string_cb)(int), 
 
736
     void *(*find_cx)(void), 
 
737
     void *(*init_cx)(void) 
 
738
     )
 
739
  {
 
740
  jar_fn_GetString = string_cb;
 
741
  jar_fn_FindSomeContext = find_cx;
 
742
  jar_fn_GetInitContext = init_cx;
 
743
  }
 
744
 
 
745
/*
 
746
 *  J A R _ g e t _ e r r o r
 
747
 *
 
748
 *  This is provided to map internal JAR errors to strings for
 
749
 *  the Java console. Also, a DLL may call this function if it does
 
750
 *  not have access to the XP_GetString function.
 
751
 *
 
752
 *  These strings aren't UI, since they are Java console only.
 
753
 *
 
754
 */
 
755
 
 
756
char *JAR_get_error (int status)
 
757
  { 
 
758
  char *errstring = NULL;
 
759
 
 
760
  switch (status)
 
761
    {
 
762
    case JAR_ERR_GENERAL:
 
763
      errstring = "General JAR file error";
 
764
      break;
 
765
 
 
766
    case JAR_ERR_FNF:
 
767
      errstring = "JAR file not found";
 
768
      break;
 
769
 
 
770
    case JAR_ERR_CORRUPT:
 
771
      errstring = "Corrupt JAR file";
 
772
      break;
 
773
 
 
774
    case JAR_ERR_MEMORY:
 
775
      errstring = "Out of memory";
 
776
      break;
 
777
 
 
778
    case JAR_ERR_DISK:
 
779
      errstring = "Disk error (perhaps out of space)";
 
780
      break;
 
781
 
 
782
    case JAR_ERR_ORDER:
 
783
      errstring = "Inconsistent files in META-INF directory";
 
784
      break;
 
785
 
 
786
    case JAR_ERR_SIG:
 
787
      errstring = "Invalid digital signature file";
 
788
      break;
 
789
 
 
790
    case JAR_ERR_METADATA:
 
791
      errstring = "JAR metadata failed verification";
 
792
      break;
 
793
 
 
794
    case JAR_ERR_ENTRY:
 
795
      errstring = "No Manifest entry for this JAR entry";
 
796
      break;
 
797
 
 
798
    case JAR_ERR_HASH:
 
799
      errstring = "Invalid Hash of this JAR entry";
 
800
      break;
 
801
 
 
802
    case JAR_ERR_PK7:
 
803
      errstring = "Strange PKCS7 or RSA failure";
 
804
      break;
 
805
 
 
806
    case JAR_ERR_PNF:
 
807
      errstring = "Path not found inside JAR file";
 
808
      break;
 
809
 
 
810
    default:
 
811
      if (jar_fn_GetString)
 
812
        {
 
813
        errstring = jar_fn_GetString (status);
 
814
        }
 
815
      else
 
816
        {
 
817
        /* this is not a normal situation, and would only be
 
818
           called in cases of improper initialization */
 
819
 
 
820
        char *err;
 
821
 
 
822
        err = (char*)PORT_Alloc (40);
 
823
        if (err)
 
824
          PR_snprintf (err, 39,  "Error %d\n", status);
 
825
        else
 
826
          err = "Error! Bad! Out of memory!";
 
827
 
 
828
        return err;
 
829
        }
 
830
      break;
 
831
    }
 
832
 
 
833
  return errstring;
 
834
  }