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

« back to all changes in this revision

Viewing changes to security/nss-fips/lib/certdb/certt.h

  • 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
 * certt.h - public data structures for the certificate library
 
38
 *
 
39
 * $Id: certt.h,v 1.33.2.1 2006/02/16 00:14:18 julien.pierre.bugs%sun.com Exp $
 
40
 */
 
41
#ifndef _CERTT_H_
 
42
#define _CERTT_H_
 
43
 
 
44
#include "prclist.h"
 
45
#include "pkcs11t.h"
 
46
#include "seccomon.h"
 
47
#include "secmodt.h"
 
48
#include "secoidt.h"
 
49
#include "plarena.h"
 
50
#include "prcvar.h"
 
51
#include "nssilock.h"
 
52
#include "prio.h"
 
53
#include "prmon.h"
 
54
 
 
55
/* Stan data types */
 
56
struct NSSCertificateStr;
 
57
struct NSSTrustDomainStr;
 
58
 
 
59
/* Non-opaque objects */
 
60
typedef struct CERTAVAStr                        CERTAVA;
 
61
typedef struct CERTAttributeStr                  CERTAttribute;
 
62
typedef struct CERTAuthInfoAccessStr             CERTAuthInfoAccess;
 
63
typedef struct CERTAuthKeyIDStr                  CERTAuthKeyID;
 
64
typedef struct CERTBasicConstraintsStr           CERTBasicConstraints;
 
65
#ifdef NSS_CLASSIC
 
66
typedef struct CERTCertDBHandleStr               CERTCertDBHandle;
 
67
#else
 
68
typedef struct NSSTrustDomainStr                 CERTCertDBHandle;
 
69
#endif
 
70
typedef struct CERTCertExtensionStr              CERTCertExtension;
 
71
typedef struct CERTCertKeyStr                    CERTCertKey;
 
72
typedef struct CERTCertListStr                   CERTCertList;
 
73
typedef struct CERTCertListNodeStr               CERTCertListNode;
 
74
typedef struct CERTCertNicknamesStr              CERTCertNicknames;
 
75
typedef struct CERTCertTrustStr                  CERTCertTrust;
 
76
typedef struct CERTCertificateStr                CERTCertificate;
 
77
typedef struct CERTCertificateListStr            CERTCertificateList;
 
78
typedef struct CERTCertificateRequestStr         CERTCertificateRequest;
 
79
typedef struct CERTCrlStr                        CERTCrl;
 
80
typedef struct CERTCrlDistributionPointsStr      CERTCrlDistributionPoints; 
 
81
typedef struct CERTCrlEntryStr                   CERTCrlEntry;
 
82
typedef struct CERTCrlHeadNodeStr                CERTCrlHeadNode;
 
83
typedef struct CERTCrlKeyStr                     CERTCrlKey;
 
84
typedef struct CERTCrlNodeStr                    CERTCrlNode;
 
85
typedef struct CERTDERCertsStr                   CERTDERCerts;
 
86
typedef struct CERTDistNamesStr                  CERTDistNames;
 
87
typedef struct CERTGeneralNameStr                CERTGeneralName;
 
88
typedef struct CERTGeneralNameListStr            CERTGeneralNameList;
 
89
typedef struct CERTIssuerAndSNStr                CERTIssuerAndSN;
 
90
typedef struct CERTNameStr                       CERTName;
 
91
typedef struct CERTNameConstraintStr             CERTNameConstraint;
 
92
typedef struct CERTNameConstraintsStr            CERTNameConstraints;
 
93
typedef struct CERTOKDomainNameStr               CERTOKDomainName;
 
94
typedef struct CERTPrivKeyUsagePeriodStr         CERTPrivKeyUsagePeriod;
 
95
typedef struct CERTPublicKeyAndChallengeStr      CERTPublicKeyAndChallenge;
 
96
typedef struct CERTRDNStr                        CERTRDN;
 
97
typedef struct CERTSignedCrlStr                  CERTSignedCrl;
 
98
typedef struct CERTSignedDataStr                 CERTSignedData;
 
99
typedef struct CERTStatusConfigStr               CERTStatusConfig;
 
100
typedef struct CERTSubjectListStr                CERTSubjectList;
 
101
typedef struct CERTSubjectNodeStr                CERTSubjectNode;
 
102
typedef struct CERTSubjectPublicKeyInfoStr       CERTSubjectPublicKeyInfo;
 
103
typedef struct CERTValidityStr                   CERTValidity;
 
104
typedef struct CERTVerifyLogStr                  CERTVerifyLog;
 
105
typedef struct CERTVerifyLogNodeStr              CERTVerifyLogNode;
 
106
typedef struct CRLDistributionPointStr           CRLDistributionPoint;
 
107
 
 
108
/* CRL extensions type */
 
109
typedef unsigned long CERTCrlNumber;
 
110
 
 
111
/*
 
112
** An X.500 AVA object
 
113
*/
 
114
struct CERTAVAStr {
 
115
    SECItem type;
 
116
    SECItem value;
 
117
};
 
118
 
 
119
/*
 
120
** An X.500 RDN object
 
121
*/
 
122
struct CERTRDNStr {
 
123
    CERTAVA **avas;
 
124
};
 
125
 
 
126
/*
 
127
** An X.500 name object
 
128
*/
 
129
struct CERTNameStr {
 
130
    PRArenaPool *arena;
 
131
    CERTRDN **rdns;
 
132
};
 
133
 
 
134
/*
 
135
** An X.509 validity object
 
136
*/
 
137
struct CERTValidityStr {
 
138
    PRArenaPool *arena;
 
139
    SECItem notBefore;
 
140
    SECItem notAfter;
 
141
};
 
142
 
 
143
/*
 
144
 * A serial number and issuer name, which is used as a database key
 
145
 */
 
146
struct CERTCertKeyStr {
 
147
    SECItem serialNumber;
 
148
    SECItem derIssuer;
 
149
};
 
150
 
 
151
/*
 
152
** A signed data object. Used to implement the "signed" macro used
 
153
** in the X.500 specs.
 
154
*/
 
155
struct CERTSignedDataStr {
 
156
    SECItem data;
 
157
    SECAlgorithmID signatureAlgorithm;
 
158
    SECItem signature;
 
159
};
 
160
 
 
161
/*
 
162
** An X.509 subject-public-key-info object
 
163
*/
 
164
struct CERTSubjectPublicKeyInfoStr {
 
165
    PRArenaPool *arena;
 
166
    SECAlgorithmID algorithm;
 
167
    SECItem subjectPublicKey;
 
168
};
 
169
 
 
170
struct CERTPublicKeyAndChallengeStr {
 
171
    SECItem spki;
 
172
    SECItem challenge;
 
173
};
 
174
 
 
175
struct CERTCertTrustStr {
 
176
    unsigned int sslFlags;
 
177
    unsigned int emailFlags;
 
178
    unsigned int objectSigningFlags;
 
179
};
 
180
 
 
181
/*
 
182
 * defined the types of trust that exist
 
183
 */
 
184
typedef enum SECTrustTypeEnum {
 
185
    trustSSL = 0,
 
186
    trustEmail = 1,
 
187
    trustObjectSigning = 2,
 
188
    trustTypeNone = 3
 
189
} SECTrustType;
 
190
 
 
191
#define SEC_GET_TRUST_FLAGS(trust,type) \
 
192
        (((type)==trustSSL)?((trust)->sslFlags): \
 
193
         (((type)==trustEmail)?((trust)->emailFlags): \
 
194
          (((type)==trustObjectSigning)?((trust)->objectSigningFlags):0)))
 
195
 
 
196
/*
 
197
** An X.509.3 certificate extension
 
198
*/
 
199
struct CERTCertExtensionStr {
 
200
    SECItem id;
 
201
    SECItem critical;
 
202
    SECItem value;
 
203
};
 
204
 
 
205
struct CERTSubjectNodeStr {
 
206
    struct CERTSubjectNodeStr *next;
 
207
    struct CERTSubjectNodeStr *prev;
 
208
    SECItem certKey;
 
209
    SECItem keyID;
 
210
};
 
211
 
 
212
struct CERTSubjectListStr {
 
213
    PRArenaPool *arena;
 
214
    int ncerts;
 
215
    char *emailAddr;
 
216
    CERTSubjectNode *head;
 
217
    CERTSubjectNode *tail; /* do we need tail? */
 
218
    void *entry;
 
219
};
 
220
 
 
221
/*
 
222
** An X.509 certificate object (the unsigned form)
 
223
*/
 
224
struct CERTCertificateStr {
 
225
    /* the arena is used to allocate any data structures that have the same
 
226
     * lifetime as the cert.  This is all stuff that hangs off of the cert
 
227
     * structure, and is all freed at the same time.  I is used when the
 
228
     * cert is decoded, destroyed, and at some times when it changes
 
229
     * state
 
230
     */
 
231
    PRArenaPool *arena;
 
232
 
 
233
    /* The following fields are static after the cert has been decoded */
 
234
    char *subjectName;
 
235
    char *issuerName;
 
236
    CERTSignedData signatureWrap;       /* XXX */
 
237
    SECItem derCert;                    /* original DER for the cert */
 
238
    SECItem derIssuer;                  /* DER for issuer name */
 
239
    SECItem derSubject;                 /* DER for subject name */
 
240
    SECItem derPublicKey;               /* DER for the public key */
 
241
    SECItem certKey;                    /* database key for this cert */
 
242
    SECItem version;
 
243
    SECItem serialNumber;
 
244
    SECAlgorithmID signature;
 
245
    CERTName issuer;
 
246
    CERTValidity validity;
 
247
    CERTName subject;
 
248
    CERTSubjectPublicKeyInfo subjectPublicKeyInfo;
 
249
    SECItem issuerID;
 
250
    SECItem subjectID;
 
251
    CERTCertExtension **extensions;
 
252
    char *emailAddr;
 
253
    CERTCertDBHandle *dbhandle;
 
254
    SECItem subjectKeyID;       /* x509v3 subject key identifier */
 
255
    PRBool keyIDGenerated;      /* was the keyid generated? */
 
256
    unsigned int keyUsage;      /* what uses are allowed for this cert */
 
257
    unsigned int rawKeyUsage;   /* value of the key usage extension */
 
258
    PRBool keyUsagePresent;     /* was the key usage extension present */
 
259
    PRUint32 nsCertType;        /* value of the ns cert type extension */
 
260
                                /* must be 32-bit for PR_AtomicSet */
 
261
 
 
262
    /* these values can be set by the application to bypass certain checks
 
263
     * or to keep the cert in memory for an entire session.
 
264
     * XXX - need an api to set these
 
265
     */
 
266
    PRBool keepSession;                 /* keep this cert for entire session*/
 
267
    PRBool timeOK;                      /* is the bad validity time ok? */
 
268
    CERTOKDomainName *domainOK;         /* these domain names are ok */
 
269
 
 
270
    /*
 
271
     * these values can change when the cert changes state.  These state
 
272
     * changes include transitions from temp to perm or vice-versa, and
 
273
     * changes of trust flags
 
274
     */
 
275
    PRBool isperm;
 
276
    PRBool istemp;
 
277
    char *nickname;
 
278
    char *dbnickname;
 
279
    struct NSSCertificateStr *nssCertificate;   /* This is Stan stuff. */
 
280
    CERTCertTrust *trust;
 
281
 
 
282
    /* the reference count is modified whenever someone looks up, dups
 
283
     * or destroys a certificate
 
284
     */
 
285
    int referenceCount;
 
286
 
 
287
    /* The subject list is a list of all certs with the same subject name.
 
288
     * It can be modified any time a cert is added or deleted from either
 
289
     * the in-memory(temporary) or on-disk(permanent) database.
 
290
     */
 
291
    CERTSubjectList *subjectList;
 
292
 
 
293
    /* these belong in the static section, but are here to maintain
 
294
     * the structure's integrity
 
295
     */
 
296
    CERTAuthKeyID * authKeyID;  /* x509v3 authority key identifier */
 
297
    PRBool isRoot;              /* cert is the end of a chain */
 
298
 
 
299
    /* these fields are used by client GUI code to keep track of ssl sockets
 
300
     * that are blocked waiting on GUI feedback related to this cert.
 
301
     * XXX - these should be moved into some sort of application specific
 
302
     *       data structure.  They are only used by the browser right now.
 
303
     */
 
304
    union {
 
305
        void* apointer; /* was struct SECSocketNode* authsocketlist */
 
306
        struct {
 
307
            unsigned int hasUnsupportedCriticalExt :1;
 
308
            /* add any new option bits needed here */
 
309
        } bits;
 
310
    } options;
 
311
    int series; /* was int authsocketcount; record the series of the pkcs11ID */
 
312
 
 
313
    /* This is PKCS #11 stuff. */
 
314
    PK11SlotInfo *slot;         /*if this cert came of a token, which is it*/
 
315
    CK_OBJECT_HANDLE pkcs11ID;  /*and which object on that token is it */
 
316
    PRBool ownSlot;             /*true if the cert owns the slot reference */
 
317
};
 
318
#define SEC_CERTIFICATE_VERSION_1               0       /* default created */
 
319
#define SEC_CERTIFICATE_VERSION_2               1       /* v2 */
 
320
#define SEC_CERTIFICATE_VERSION_3               2       /* v3 extensions */
 
321
 
 
322
#define SEC_CRL_VERSION_1               0       /* default */
 
323
#define SEC_CRL_VERSION_2               1       /* v2 extensions */
 
324
 
 
325
/*
 
326
 * used to identify class of cert in mime stream code
 
327
 */
 
328
#define SEC_CERT_CLASS_CA       1
 
329
#define SEC_CERT_CLASS_SERVER   2
 
330
#define SEC_CERT_CLASS_USER     3
 
331
#define SEC_CERT_CLASS_EMAIL    4
 
332
 
 
333
struct CERTDERCertsStr {
 
334
    PRArenaPool *arena;
 
335
    int numcerts;
 
336
    SECItem *rawCerts;
 
337
};
 
338
 
 
339
/*
 
340
** A PKCS ? Attribute
 
341
** XXX this is duplicated through out the code, it *should* be moved
 
342
** to a central location.  Where would be appropriate?
 
343
*/
 
344
struct CERTAttributeStr {
 
345
    SECItem attrType;
 
346
    SECItem **attrValue;
 
347
};
 
348
 
 
349
/*
 
350
** A PKCS#10 certificate-request object (the unsigned form)
 
351
*/
 
352
struct CERTCertificateRequestStr {
 
353
    PRArenaPool *arena;
 
354
    SECItem version;
 
355
    CERTName subject;
 
356
    CERTSubjectPublicKeyInfo subjectPublicKeyInfo;
 
357
    CERTAttribute **attributes;
 
358
};
 
359
#define SEC_CERTIFICATE_REQUEST_VERSION         0       /* what we *create* */
 
360
 
 
361
 
 
362
/*
 
363
** A certificate list object.
 
364
*/
 
365
struct CERTCertificateListStr {
 
366
    SECItem *certs;
 
367
    int len;                                    /* number of certs */
 
368
    PRArenaPool *arena;
 
369
};
 
370
 
 
371
struct CERTCertListNodeStr {
 
372
    PRCList links;
 
373
    CERTCertificate *cert;
 
374
    void *appData;
 
375
};
 
376
 
 
377
struct CERTCertListStr {
 
378
    PRCList list;
 
379
    PRArenaPool *arena;
 
380
};
 
381
 
 
382
#define CERT_LIST_HEAD(l) ((CERTCertListNode *)PR_LIST_HEAD(&l->list))
 
383
#define CERT_LIST_NEXT(n) ((CERTCertListNode *)n->links.next)
 
384
#define CERT_LIST_END(n,l) (((void *)n) == ((void *)&l->list))
 
385
#define CERT_LIST_EMPTY(l) CERT_LIST_END(CERT_LIST_HEAD(l), l)
 
386
 
 
387
struct CERTCrlEntryStr {
 
388
    SECItem serialNumber;
 
389
    SECItem revocationDate;
 
390
    CERTCertExtension **extensions;    
 
391
};
 
392
 
 
393
struct CERTCrlStr {
 
394
    PRArenaPool *arena;
 
395
    SECItem version;
 
396
    SECAlgorithmID signatureAlg;
 
397
    SECItem derName;
 
398
    CERTName name;
 
399
    SECItem lastUpdate;
 
400
    SECItem nextUpdate;                         /* optional for x.509 CRL  */
 
401
    CERTCrlEntry **entries;
 
402
    CERTCertExtension **extensions;    
 
403
    /* can't add anything there for binary backwards compatibility reasons */
 
404
};
 
405
 
 
406
struct CERTCrlKeyStr {
 
407
    SECItem derName;
 
408
    SECItem dummy;                      /* The decoder can not skip a primitive,
 
409
                                           this serves as a place holder for the
 
410
                                           decoder to finish its task only
 
411
                                        */
 
412
};
 
413
 
 
414
struct CERTSignedCrlStr {
 
415
    PRArenaPool *arena;
 
416
    CERTCrl crl;
 
417
    void *reserved1;
 
418
    PRBool reserved2;
 
419
    PRBool isperm;
 
420
    PRBool istemp;
 
421
    int referenceCount;
 
422
    CERTCertDBHandle *dbhandle;
 
423
    CERTSignedData signatureWrap;       /* XXX */
 
424
    char *url;
 
425
    SECItem *derCrl;
 
426
    PK11SlotInfo *slot;
 
427
    CK_OBJECT_HANDLE pkcs11ID;
 
428
    void* opaque; /* do not touch */
 
429
};
 
430
 
 
431
 
 
432
struct CERTCrlHeadNodeStr {
 
433
    PRArenaPool *arena;
 
434
    CERTCertDBHandle *dbhandle;
 
435
    CERTCrlNode *first;
 
436
    CERTCrlNode *last;
 
437
};
 
438
 
 
439
 
 
440
struct CERTCrlNodeStr {
 
441
    CERTCrlNode *next;
 
442
    int         type;
 
443
    CERTSignedCrl *crl;
 
444
};
 
445
 
 
446
 
 
447
/*
 
448
 * Array of X.500 Distinguished Names
 
449
 */
 
450
struct CERTDistNamesStr {
 
451
    PRArenaPool *arena;
 
452
    int nnames;
 
453
    SECItem  *names;
 
454
    void *head; /* private */
 
455
};
 
456
 
 
457
 
 
458
#define NS_CERT_TYPE_SSL_CLIENT         (0x80)  /* bit 0 */
 
459
#define NS_CERT_TYPE_SSL_SERVER         (0x40)  /* bit 1 */
 
460
#define NS_CERT_TYPE_EMAIL              (0x20)  /* bit 2 */
 
461
#define NS_CERT_TYPE_OBJECT_SIGNING     (0x10)  /* bit 3 */
 
462
#define NS_CERT_TYPE_RESERVED           (0x08)  /* bit 4 */
 
463
#define NS_CERT_TYPE_SSL_CA             (0x04)  /* bit 5 */
 
464
#define NS_CERT_TYPE_EMAIL_CA           (0x02)  /* bit 6 */
 
465
#define NS_CERT_TYPE_OBJECT_SIGNING_CA  (0x01)  /* bit 7 */
 
466
 
 
467
#define EXT_KEY_USAGE_TIME_STAMP        (0x8000)
 
468
#define EXT_KEY_USAGE_STATUS_RESPONDER  (0x4000)
 
469
 
 
470
#define NS_CERT_TYPE_APP ( NS_CERT_TYPE_SSL_CLIENT | \
 
471
                          NS_CERT_TYPE_SSL_SERVER | \
 
472
                          NS_CERT_TYPE_EMAIL | \
 
473
                          NS_CERT_TYPE_OBJECT_SIGNING )
 
474
 
 
475
#define NS_CERT_TYPE_CA ( NS_CERT_TYPE_SSL_CA | \
 
476
                         NS_CERT_TYPE_EMAIL_CA | \
 
477
                         NS_CERT_TYPE_OBJECT_SIGNING_CA | \
 
478
                         EXT_KEY_USAGE_STATUS_RESPONDER )
 
479
typedef enum SECCertUsageEnum {
 
480
    certUsageSSLClient = 0,
 
481
    certUsageSSLServer = 1,
 
482
    certUsageSSLServerWithStepUp = 2,
 
483
    certUsageSSLCA = 3,
 
484
    certUsageEmailSigner = 4,
 
485
    certUsageEmailRecipient = 5,
 
486
    certUsageObjectSigner = 6,
 
487
    certUsageUserCertImport = 7,
 
488
    certUsageVerifyCA = 8,
 
489
    certUsageProtectedObjectSigner = 9,
 
490
    certUsageStatusResponder = 10,
 
491
    certUsageAnyCA = 11
 
492
} SECCertUsage;
 
493
 
 
494
typedef PRInt64 SECCertificateUsage;
 
495
 
 
496
#define certificateUsageSSLClient              (0x0001)
 
497
#define certificateUsageSSLServer              (0x0002)
 
498
#define certificateUsageSSLServerWithStepUp    (0x0004)
 
499
#define certificateUsageSSLCA                  (0x0008)
 
500
#define certificateUsageEmailSigner            (0x0010)
 
501
#define certificateUsageEmailRecipient         (0x0020)
 
502
#define certificateUsageObjectSigner           (0x0040)
 
503
#define certificateUsageUserCertImport         (0x0080)
 
504
#define certificateUsageVerifyCA               (0x0100)
 
505
#define certificateUsageProtectedObjectSigner  (0x0200)
 
506
#define certificateUsageStatusResponder        (0x0400)
 
507
#define certificateUsageAnyCA                  (0x0800)
 
508
 
 
509
#define certificateUsageHighest certificateUsageAnyCA
 
510
 
 
511
/*
 
512
 * Does the cert belong to the user, a peer, or a CA.
 
513
 */
 
514
typedef enum CERTCertOwnerEnum {
 
515
    certOwnerUser = 0,
 
516
    certOwnerPeer = 1,
 
517
    certOwnerCA = 2
 
518
} CERTCertOwner;
 
519
 
 
520
/*
 
521
 * This enum represents the state of validity times of a certificate
 
522
 */
 
523
typedef enum SECCertTimeValidityEnum {
 
524
    secCertTimeValid = 0,
 
525
    secCertTimeExpired = 1,
 
526
    secCertTimeNotValidYet = 2,
 
527
    secCertTimeUndetermined = 3 /* validity could not be decoded from the
 
528
                                   cert, most likely because it was NULL */
 
529
} SECCertTimeValidity;
 
530
 
 
531
/*
 
532
 * This is used as return status in functions that compare the validity
 
533
 * periods of two certificates A and B, currently only
 
534
 * CERT_CompareValidityTimes.
 
535
 */
 
536
 
 
537
typedef enum CERTCompareValidityStatusEnum
 
538
{
 
539
    certValidityUndetermined = 0, /* the function is unable to select one cert 
 
540
                                     over another */
 
541
    certValidityChooseB = 1,      /* cert B should be preferred */
 
542
    certValidityEqual = 2,        /* both certs have the same validity period */
 
543
    certValidityChooseA = 3       /* cert A should be preferred */
 
544
} CERTCompareValidityStatus;
 
545
 
 
546
/*
 
547
 * Interface for getting certificate nickname strings out of the database
 
548
 */
 
549
 
 
550
/* these are values for the what argument below */
 
551
#define SEC_CERT_NICKNAMES_ALL          1
 
552
#define SEC_CERT_NICKNAMES_USER         2
 
553
#define SEC_CERT_NICKNAMES_SERVER       3
 
554
#define SEC_CERT_NICKNAMES_CA           4
 
555
 
 
556
struct CERTCertNicknamesStr {
 
557
    PRArenaPool *arena;
 
558
    void *head;
 
559
    int numnicknames;
 
560
    char **nicknames;
 
561
    int what;
 
562
    int totallen;
 
563
};
 
564
 
 
565
struct CERTIssuerAndSNStr {
 
566
    SECItem derIssuer;
 
567
    CERTName issuer;
 
568
    SECItem serialNumber;
 
569
};
 
570
 
 
571
 
 
572
/* X.509 v3 Key Usage Extension flags */
 
573
#define KU_DIGITAL_SIGNATURE            (0x80)  /* bit 0 */
 
574
#define KU_NON_REPUDIATION              (0x40)  /* bit 1 */
 
575
#define KU_KEY_ENCIPHERMENT             (0x20)  /* bit 2 */
 
576
#define KU_DATA_ENCIPHERMENT            (0x10)  /* bit 3 */
 
577
#define KU_KEY_AGREEMENT                (0x08)  /* bit 4 */
 
578
#define KU_KEY_CERT_SIGN                (0x04)  /* bit 5 */
 
579
#define KU_CRL_SIGN                     (0x02)  /* bit 6 */
 
580
#define KU_ALL                          (KU_DIGITAL_SIGNATURE | \
 
581
                                         KU_NON_REPUDIATION | \
 
582
                                         KU_KEY_ENCIPHERMENT | \
 
583
                                         KU_DATA_ENCIPHERMENT | \
 
584
                                         KU_KEY_AGREEMENT | \
 
585
                                         KU_KEY_CERT_SIGN | \
 
586
                                         KU_CRL_SIGN)
 
587
 
 
588
/* This value will not occur in certs.  It is used internally for the case
 
589
 * when the key type is not know ahead of time and either key agreement or
 
590
 * key encipherment are the correct value based on key type
 
591
 */
 
592
#define KU_KEY_AGREEMENT_OR_ENCIPHERMENT (0x4000)
 
593
 
 
594
/* internal bits that do not match bits in the x509v3 spec, but are used
 
595
 * for similar purposes
 
596
 */
 
597
#define KU_NS_GOVT_APPROVED             (0x8000) /*don't make part of KU_ALL!*/
 
598
/*
 
599
 * x.509 v3 Basic Constraints Extension
 
600
 * If isCA is false, the pathLenConstraint is ignored.
 
601
 * Otherwise, the following pathLenConstraint values will apply:
 
602
 *      < 0 - there is no limit to the certificate path
 
603
 *      0   - CA can issues end-entity certificates only
 
604
 *      > 0 - the number of certificates in the certificate path is
 
605
 *            limited to this number
 
606
 */
 
607
#define CERT_UNLIMITED_PATH_CONSTRAINT -2
 
608
 
 
609
struct CERTBasicConstraintsStr {
 
610
    PRBool isCA;                        /* on if is CA */
 
611
    int pathLenConstraint;              /* maximum number of certificates that can be
 
612
                                           in the cert path.  Only applies to a CA
 
613
                                           certificate; otherwise, it's ignored.
 
614
                                         */
 
615
};
 
616
 
 
617
/* Maximum length of a certificate chain */
 
618
#define CERT_MAX_CERT_CHAIN 20
 
619
 
 
620
/* x.509 v3 Reason Falgs, used in CRLDistributionPoint Extension */
 
621
#define RF_UNUSED                       (0x80)  /* bit 0 */
 
622
#define RF_KEY_COMPROMISE               (0x40)  /* bit 1 */
 
623
#define RF_CA_COMPROMISE                (0x20)  /* bit 2 */
 
624
#define RF_AFFILIATION_CHANGED          (0x10)  /* bit 3 */
 
625
#define RF_SUPERSEDED                   (0x08)  /* bit 4 */
 
626
#define RF_CESSATION_OF_OPERATION       (0x04)  /* bit 5 */
 
627
#define RF_CERTIFICATE_HOLD             (0x02)  /* bit 6 */
 
628
 
 
629
/* If we needed to extract the general name field, use this */
 
630
/* General Name types */
 
631
typedef enum CERTGeneralNameTypeEnum {
 
632
    certOtherName = 1,
 
633
    certRFC822Name = 2,
 
634
    certDNSName = 3,
 
635
    certX400Address = 4,
 
636
    certDirectoryName = 5,
 
637
    certEDIPartyName = 6,
 
638
    certURI = 7,
 
639
    certIPAddress = 8,
 
640
    certRegisterID = 9
 
641
} CERTGeneralNameType;
 
642
 
 
643
 
 
644
typedef struct OtherNameStr {
 
645
    SECItem          name;
 
646
    SECItem          oid;
 
647
}OtherName;
 
648
 
 
649
 
 
650
 
 
651
struct CERTGeneralNameStr {
 
652
    CERTGeneralNameType type;           /* name type */
 
653
    union {
 
654
        CERTName directoryName;         /* distinguish name */
 
655
        OtherName  OthName;             /* Other Name */
 
656
        SECItem other;                  /* the rest of the name forms */
 
657
    }name;
 
658
    SECItem derDirectoryName;           /* this is saved to simplify directory name
 
659
                                           comparison */
 
660
    PRCList l;
 
661
};
 
662
 
 
663
struct CERTGeneralNameListStr {
 
664
    PRArenaPool *arena;
 
665
    CERTGeneralName *name;
 
666
    int refCount;
 
667
    int len;
 
668
    PZLock *lock;
 
669
};
 
670
 
 
671
struct CERTNameConstraintStr {
 
672
    CERTGeneralName  name;
 
673
    SECItem          DERName;
 
674
    SECItem          min;
 
675
    SECItem          max;
 
676
    PRCList          l;
 
677
};
 
678
 
 
679
 
 
680
struct CERTNameConstraintsStr {
 
681
    CERTNameConstraint  *permited;
 
682
    CERTNameConstraint  *excluded;
 
683
    SECItem             **DERPermited;
 
684
    SECItem             **DERExcluded;
 
685
};
 
686
 
 
687
 
 
688
/* Private Key Usage Period extension struct. */
 
689
struct CERTPrivKeyUsagePeriodStr {
 
690
    SECItem notBefore;
 
691
    SECItem notAfter;
 
692
    PRArenaPool *arena;
 
693
};
 
694
 
 
695
/* X.509 v3 Authority Key Identifier extension.  For the authority certificate
 
696
   issuer field, we only support URI now.
 
697
 */
 
698
struct CERTAuthKeyIDStr {
 
699
    SECItem keyID;                      /* unique key identifier */
 
700
    CERTGeneralName *authCertIssuer;    /* CA's issuer name.  End with a NULL */
 
701
    SECItem authCertSerialNumber;       /* CA's certificate serial number */
 
702
    SECItem **DERAuthCertIssuer;        /* This holds the DER encoded format of
 
703
                                           the authCertIssuer field. It is used
 
704
                                           by the encoding engine. It should be
 
705
                                           used as a read only field by the caller.
 
706
                                        */
 
707
};
 
708
 
 
709
/* x.509 v3 CRL Distributeion Point */
 
710
 
 
711
/*
 
712
 * defined the types of CRL Distribution points
 
713
 */
 
714
typedef enum DistributionPointTypesEnum {
 
715
    generalName = 1,                    /* only support this for now */
 
716
    relativeDistinguishedName = 2
 
717
} DistributionPointTypes;
 
718
 
 
719
struct CRLDistributionPointStr {
 
720
    DistributionPointTypes distPointType;
 
721
    union {
 
722
        CERTGeneralName *fullName;
 
723
        CERTRDN relativeName;
 
724
    } distPoint;
 
725
    SECItem reasons;
 
726
    CERTGeneralName *crlIssuer;
 
727
    
 
728
    /* Reserved for internal use only*/
 
729
    SECItem derDistPoint;
 
730
    SECItem derRelativeName;
 
731
    SECItem **derCrlIssuer;
 
732
    SECItem **derFullName;
 
733
    SECItem bitsmap;
 
734
};
 
735
 
 
736
struct CERTCrlDistributionPointsStr {
 
737
    CRLDistributionPoint **distPoints;
 
738
};
 
739
 
 
740
/*
 
741
 * This structure is used to keep a log of errors when verifying
 
742
 * a cert chain.  This allows multiple errors to be reported all at
 
743
 * once.
 
744
 */
 
745
struct CERTVerifyLogNodeStr {
 
746
    CERTCertificate *cert;      /* what cert had the error */
 
747
    long error;                 /* what error was it? */
 
748
    unsigned int depth;         /* how far up the chain are we */
 
749
    void *arg;                  /* error specific argument */
 
750
    struct CERTVerifyLogNodeStr *next; /* next in the list */
 
751
    struct CERTVerifyLogNodeStr *prev; /* next in the list */
 
752
};
 
753
 
 
754
 
 
755
struct CERTVerifyLogStr {
 
756
    PRArenaPool *arena;
 
757
    unsigned int count;
 
758
    struct CERTVerifyLogNodeStr *head;
 
759
    struct CERTVerifyLogNodeStr *tail;
 
760
};
 
761
 
 
762
 
 
763
struct CERTOKDomainNameStr {
 
764
    CERTOKDomainName *next;
 
765
    char              name[1]; /* actual length may be longer. */
 
766
};
 
767
 
 
768
 
 
769
typedef SECStatus (PR_CALLBACK *CERTStatusChecker) (CERTCertDBHandle *handle,
 
770
                                                    CERTCertificate *cert,
 
771
                                                    int64 time,
 
772
                                                    void *pwArg);
 
773
 
 
774
typedef SECStatus (PR_CALLBACK *CERTStatusDestroy) (CERTStatusConfig *handle);
 
775
 
 
776
struct CERTStatusConfigStr {
 
777
    CERTStatusChecker statusChecker;    /* NULL means no checking enabled */
 
778
    CERTStatusDestroy statusDestroy;    /* enabled or no, will clean up */
 
779
    void *statusContext;                /* cx specific to checking protocol */
 
780
};
 
781
 
 
782
struct CERTAuthInfoAccessStr {
 
783
    SECItem method;
 
784
    SECItem derLocation;
 
785
    CERTGeneralName *location;          /* decoded location */
 
786
};
 
787
 
 
788
 
 
789
/* This is the typedef for the callback passed to CERT_OpenCertDB() */
 
790
/* callback to return database name based on version number */
 
791
typedef char * (*CERTDBNameFunc)(void *arg, int dbVersion);
 
792
 
 
793
/*
 
794
 * types of cert packages that we can decode
 
795
 */
 
796
typedef enum CERTPackageTypeEnum {
 
797
    certPackageNone = 0,
 
798
    certPackageCert = 1,
 
799
    certPackagePKCS7 = 2,
 
800
    certPackageNSCertSeq = 3,
 
801
    certPackageNSCertWrap = 4
 
802
} CERTPackageType;
 
803
 
 
804
/*
 
805
 * these types are for the PKIX Certificate Policies extension
 
806
 */
 
807
typedef struct {
 
808
    SECOidTag oid;
 
809
    SECItem qualifierID;
 
810
    SECItem qualifierValue;
 
811
} CERTPolicyQualifier;
 
812
 
 
813
typedef struct {
 
814
    SECOidTag oid;
 
815
    SECItem policyID;
 
816
    CERTPolicyQualifier **policyQualifiers;
 
817
} CERTPolicyInfo;
 
818
 
 
819
typedef struct {
 
820
    PRArenaPool *arena;
 
821
    CERTPolicyInfo **policyInfos;
 
822
} CERTCertificatePolicies;
 
823
 
 
824
typedef struct {
 
825
    SECItem organization;
 
826
    SECItem **noticeNumbers;
 
827
} CERTNoticeReference;
 
828
 
 
829
typedef struct {
 
830
    PRArenaPool *arena;
 
831
    CERTNoticeReference noticeReference;
 
832
    SECItem derNoticeReference;
 
833
    SECItem displayText;
 
834
} CERTUserNotice;
 
835
 
 
836
typedef struct {
 
837
    PRArenaPool *arena;
 
838
    SECItem **oids;
 
839
} CERTOidSequence;
 
840
 
 
841
 
 
842
/* XXX Lisa thinks the template declarations belong in cert.h, not here? */
 
843
 
 
844
#include "secasn1t.h"   /* way down here because I expect template stuff to
 
845
                         * move out of here anyway */
 
846
 
 
847
SEC_BEGIN_PROTOS
 
848
 
 
849
extern const SEC_ASN1Template CERT_CertificateRequestTemplate[];
 
850
extern const SEC_ASN1Template CERT_CertificateTemplate[];
 
851
extern const SEC_ASN1Template SEC_SignedCertificateTemplate[];
 
852
extern const SEC_ASN1Template CERT_CertExtensionTemplate[];
 
853
extern const SEC_ASN1Template CERT_SequenceOfCertExtensionTemplate[];
 
854
extern const SEC_ASN1Template SECKEY_PublicKeyTemplate[];
 
855
extern const SEC_ASN1Template CERT_SubjectPublicKeyInfoTemplate[];
 
856
extern const SEC_ASN1Template CERT_TimeChoiceTemplate[];
 
857
extern const SEC_ASN1Template CERT_ValidityTemplate[];
 
858
extern const SEC_ASN1Template CERT_PublicKeyAndChallengeTemplate[];
 
859
extern const SEC_ASN1Template SEC_CertSequenceTemplate[];
 
860
 
 
861
extern const SEC_ASN1Template CERT_IssuerAndSNTemplate[];
 
862
extern const SEC_ASN1Template CERT_NameTemplate[];
 
863
extern const SEC_ASN1Template CERT_SetOfSignedCrlTemplate[];
 
864
extern const SEC_ASN1Template CERT_RDNTemplate[];
 
865
extern const SEC_ASN1Template CERT_SignedDataTemplate[];
 
866
extern const SEC_ASN1Template CERT_CrlTemplate[];
 
867
extern const SEC_ASN1Template CERT_SignedCrlTemplate[];
 
868
 
 
869
/*
 
870
** XXX should the attribute stuff be centralized for all of ns/security?
 
871
*/
 
872
extern const SEC_ASN1Template CERT_AttributeTemplate[];
 
873
extern const SEC_ASN1Template CERT_SetOfAttributeTemplate[];
 
874
 
 
875
/* These functions simply return the address of the above-declared templates.
 
876
** This is necessary for Windows DLLs.  Sigh.
 
877
*/
 
878
SEC_ASN1_CHOOSER_DECLARE(CERT_CertificateRequestTemplate)
 
879
SEC_ASN1_CHOOSER_DECLARE(CERT_CertificateTemplate)
 
880
SEC_ASN1_CHOOSER_DECLARE(CERT_CrlTemplate)
 
881
SEC_ASN1_CHOOSER_DECLARE(CERT_IssuerAndSNTemplate)
 
882
SEC_ASN1_CHOOSER_DECLARE(CERT_NameTemplate)
 
883
SEC_ASN1_CHOOSER_DECLARE(CERT_SequenceOfCertExtensionTemplate)
 
884
SEC_ASN1_CHOOSER_DECLARE(CERT_SetOfSignedCrlTemplate)
 
885
SEC_ASN1_CHOOSER_DECLARE(CERT_SignedDataTemplate)
 
886
SEC_ASN1_CHOOSER_DECLARE(CERT_SubjectPublicKeyInfoTemplate)
 
887
SEC_ASN1_CHOOSER_DECLARE(SEC_SignedCertificateTemplate)
 
888
SEC_ASN1_CHOOSER_DECLARE(CERT_SignedCrlTemplate)
 
889
SEC_ASN1_CHOOSER_DECLARE(CERT_TimeChoiceTemplate)
 
890
 
 
891
SEC_END_PROTOS
 
892
 
 
893
#endif /* _CERTT_H_ */