security/nss/lib/certdb/certt.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4 /*
michael@0 5 * certt.h - public data structures for the certificate library
michael@0 6 */
michael@0 7 #ifndef _CERTT_H_
michael@0 8 #define _CERTT_H_
michael@0 9
michael@0 10 #include "prclist.h"
michael@0 11 #include "pkcs11t.h"
michael@0 12 #include "seccomon.h"
michael@0 13 #include "secmodt.h"
michael@0 14 #include "secoidt.h"
michael@0 15 #include "plarena.h"
michael@0 16 #include "prcvar.h"
michael@0 17 #include "nssilock.h"
michael@0 18 #include "prio.h"
michael@0 19 #include "prmon.h"
michael@0 20
michael@0 21 /* Stan data types */
michael@0 22 struct NSSCertificateStr;
michael@0 23 struct NSSTrustDomainStr;
michael@0 24
michael@0 25 /* Non-opaque objects */
michael@0 26 typedef struct CERTAVAStr CERTAVA;
michael@0 27 typedef struct CERTAttributeStr CERTAttribute;
michael@0 28 typedef struct CERTAuthInfoAccessStr CERTAuthInfoAccess;
michael@0 29 typedef struct CERTAuthKeyIDStr CERTAuthKeyID;
michael@0 30 typedef struct CERTBasicConstraintsStr CERTBasicConstraints;
michael@0 31 typedef struct NSSTrustDomainStr CERTCertDBHandle;
michael@0 32 typedef struct CERTCertExtensionStr CERTCertExtension;
michael@0 33 typedef struct CERTCertKeyStr CERTCertKey;
michael@0 34 typedef struct CERTCertListStr CERTCertList;
michael@0 35 typedef struct CERTCertListNodeStr CERTCertListNode;
michael@0 36 typedef struct CERTCertNicknamesStr CERTCertNicknames;
michael@0 37 typedef struct CERTCertTrustStr CERTCertTrust;
michael@0 38 typedef struct CERTCertificateStr CERTCertificate;
michael@0 39 typedef struct CERTCertificateListStr CERTCertificateList;
michael@0 40 typedef struct CERTCertificateRequestStr CERTCertificateRequest;
michael@0 41 typedef struct CERTCrlStr CERTCrl;
michael@0 42 typedef struct CERTCrlDistributionPointsStr CERTCrlDistributionPoints;
michael@0 43 typedef struct CERTCrlEntryStr CERTCrlEntry;
michael@0 44 typedef struct CERTCrlHeadNodeStr CERTCrlHeadNode;
michael@0 45 typedef struct CERTCrlKeyStr CERTCrlKey;
michael@0 46 typedef struct CERTCrlNodeStr CERTCrlNode;
michael@0 47 typedef struct CERTDERCertsStr CERTDERCerts;
michael@0 48 typedef struct CERTDistNamesStr CERTDistNames;
michael@0 49 typedef struct CERTGeneralNameStr CERTGeneralName;
michael@0 50 typedef struct CERTGeneralNameListStr CERTGeneralNameList;
michael@0 51 typedef struct CERTIssuerAndSNStr CERTIssuerAndSN;
michael@0 52 typedef struct CERTNameStr CERTName;
michael@0 53 typedef struct CERTNameConstraintStr CERTNameConstraint;
michael@0 54 typedef struct CERTNameConstraintsStr CERTNameConstraints;
michael@0 55 typedef struct CERTOKDomainNameStr CERTOKDomainName;
michael@0 56 typedef struct CERTPrivKeyUsagePeriodStr CERTPrivKeyUsagePeriod;
michael@0 57 typedef struct CERTPublicKeyAndChallengeStr CERTPublicKeyAndChallenge;
michael@0 58 typedef struct CERTRDNStr CERTRDN;
michael@0 59 typedef struct CERTSignedCrlStr CERTSignedCrl;
michael@0 60 typedef struct CERTSignedDataStr CERTSignedData;
michael@0 61 typedef struct CERTStatusConfigStr CERTStatusConfig;
michael@0 62 typedef struct CERTSubjectListStr CERTSubjectList;
michael@0 63 typedef struct CERTSubjectNodeStr CERTSubjectNode;
michael@0 64 typedef struct CERTSubjectPublicKeyInfoStr CERTSubjectPublicKeyInfo;
michael@0 65 typedef struct CERTValidityStr CERTValidity;
michael@0 66 typedef struct CERTVerifyLogStr CERTVerifyLog;
michael@0 67 typedef struct CERTVerifyLogNodeStr CERTVerifyLogNode;
michael@0 68 typedef struct CRLDistributionPointStr CRLDistributionPoint;
michael@0 69
michael@0 70 /* CRL extensions type */
michael@0 71 typedef unsigned long CERTCrlNumber;
michael@0 72
michael@0 73 /*
michael@0 74 ** An X.500 AVA object
michael@0 75 */
michael@0 76 struct CERTAVAStr {
michael@0 77 SECItem type;
michael@0 78 SECItem value;
michael@0 79 };
michael@0 80
michael@0 81 /*
michael@0 82 ** An X.500 RDN object
michael@0 83 */
michael@0 84 struct CERTRDNStr {
michael@0 85 CERTAVA **avas;
michael@0 86 };
michael@0 87
michael@0 88 /*
michael@0 89 ** An X.500 name object
michael@0 90 */
michael@0 91 struct CERTNameStr {
michael@0 92 PLArenaPool *arena;
michael@0 93 CERTRDN **rdns;
michael@0 94 };
michael@0 95
michael@0 96 /*
michael@0 97 ** An X.509 validity object
michael@0 98 */
michael@0 99 struct CERTValidityStr {
michael@0 100 PLArenaPool *arena;
michael@0 101 SECItem notBefore;
michael@0 102 SECItem notAfter;
michael@0 103 };
michael@0 104
michael@0 105 /*
michael@0 106 * A serial number and issuer name, which is used as a database key
michael@0 107 */
michael@0 108 struct CERTCertKeyStr {
michael@0 109 SECItem serialNumber;
michael@0 110 SECItem derIssuer;
michael@0 111 };
michael@0 112
michael@0 113 /*
michael@0 114 ** A signed data object. Used to implement the "signed" macro used
michael@0 115 ** in the X.500 specs.
michael@0 116 */
michael@0 117 struct CERTSignedDataStr {
michael@0 118 SECItem data;
michael@0 119 SECAlgorithmID signatureAlgorithm;
michael@0 120 SECItem signature;
michael@0 121 };
michael@0 122
michael@0 123 /*
michael@0 124 ** An X.509 subject-public-key-info object
michael@0 125 */
michael@0 126 struct CERTSubjectPublicKeyInfoStr {
michael@0 127 PLArenaPool *arena;
michael@0 128 SECAlgorithmID algorithm;
michael@0 129 SECItem subjectPublicKey;
michael@0 130 };
michael@0 131
michael@0 132 struct CERTPublicKeyAndChallengeStr {
michael@0 133 SECItem spki;
michael@0 134 SECItem challenge;
michael@0 135 };
michael@0 136
michael@0 137 struct CERTCertTrustStr {
michael@0 138 unsigned int sslFlags;
michael@0 139 unsigned int emailFlags;
michael@0 140 unsigned int objectSigningFlags;
michael@0 141 };
michael@0 142
michael@0 143 /*
michael@0 144 * defined the types of trust that exist
michael@0 145 */
michael@0 146 typedef enum SECTrustTypeEnum {
michael@0 147 trustSSL = 0,
michael@0 148 trustEmail = 1,
michael@0 149 trustObjectSigning = 2,
michael@0 150 trustTypeNone = 3
michael@0 151 } SECTrustType;
michael@0 152
michael@0 153 #define SEC_GET_TRUST_FLAGS(trust,type) \
michael@0 154 (((type)==trustSSL)?((trust)->sslFlags): \
michael@0 155 (((type)==trustEmail)?((trust)->emailFlags): \
michael@0 156 (((type)==trustObjectSigning)?((trust)->objectSigningFlags):0)))
michael@0 157
michael@0 158 /*
michael@0 159 ** An X.509.3 certificate extension
michael@0 160 */
michael@0 161 struct CERTCertExtensionStr {
michael@0 162 SECItem id;
michael@0 163 SECItem critical;
michael@0 164 SECItem value;
michael@0 165 };
michael@0 166
michael@0 167 struct CERTSubjectNodeStr {
michael@0 168 struct CERTSubjectNodeStr *next;
michael@0 169 struct CERTSubjectNodeStr *prev;
michael@0 170 SECItem certKey;
michael@0 171 SECItem keyID;
michael@0 172 };
michael@0 173
michael@0 174 struct CERTSubjectListStr {
michael@0 175 PLArenaPool *arena;
michael@0 176 int ncerts;
michael@0 177 char *emailAddr;
michael@0 178 CERTSubjectNode *head;
michael@0 179 CERTSubjectNode *tail; /* do we need tail? */
michael@0 180 void *entry;
michael@0 181 };
michael@0 182
michael@0 183 /*
michael@0 184 ** An X.509 certificate object (the unsigned form)
michael@0 185 */
michael@0 186 struct CERTCertificateStr {
michael@0 187 /* the arena is used to allocate any data structures that have the same
michael@0 188 * lifetime as the cert. This is all stuff that hangs off of the cert
michael@0 189 * structure, and is all freed at the same time. I is used when the
michael@0 190 * cert is decoded, destroyed, and at some times when it changes
michael@0 191 * state
michael@0 192 */
michael@0 193 PLArenaPool *arena;
michael@0 194
michael@0 195 /* The following fields are static after the cert has been decoded */
michael@0 196 char *subjectName;
michael@0 197 char *issuerName;
michael@0 198 CERTSignedData signatureWrap; /* XXX */
michael@0 199 SECItem derCert; /* original DER for the cert */
michael@0 200 SECItem derIssuer; /* DER for issuer name */
michael@0 201 SECItem derSubject; /* DER for subject name */
michael@0 202 SECItem derPublicKey; /* DER for the public key */
michael@0 203 SECItem certKey; /* database key for this cert */
michael@0 204 SECItem version;
michael@0 205 SECItem serialNumber;
michael@0 206 SECAlgorithmID signature;
michael@0 207 CERTName issuer;
michael@0 208 CERTValidity validity;
michael@0 209 CERTName subject;
michael@0 210 CERTSubjectPublicKeyInfo subjectPublicKeyInfo;
michael@0 211 SECItem issuerID;
michael@0 212 SECItem subjectID;
michael@0 213 CERTCertExtension **extensions;
michael@0 214 char *emailAddr;
michael@0 215 CERTCertDBHandle *dbhandle;
michael@0 216 SECItem subjectKeyID; /* x509v3 subject key identifier */
michael@0 217 PRBool keyIDGenerated; /* was the keyid generated? */
michael@0 218 unsigned int keyUsage; /* what uses are allowed for this cert */
michael@0 219 unsigned int rawKeyUsage; /* value of the key usage extension */
michael@0 220 PRBool keyUsagePresent; /* was the key usage extension present */
michael@0 221 PRUint32 nsCertType; /* value of the ns cert type extension */
michael@0 222 /* must be 32-bit for PR_ATOMIC_SET */
michael@0 223
michael@0 224 /* these values can be set by the application to bypass certain checks
michael@0 225 * or to keep the cert in memory for an entire session.
michael@0 226 * XXX - need an api to set these
michael@0 227 */
michael@0 228 PRBool keepSession; /* keep this cert for entire session*/
michael@0 229 PRBool timeOK; /* is the bad validity time ok? */
michael@0 230 CERTOKDomainName *domainOK; /* these domain names are ok */
michael@0 231
michael@0 232 /*
michael@0 233 * these values can change when the cert changes state. These state
michael@0 234 * changes include transitions from temp to perm or vice-versa, and
michael@0 235 * changes of trust flags
michael@0 236 */
michael@0 237 PRBool isperm;
michael@0 238 PRBool istemp;
michael@0 239 char *nickname;
michael@0 240 char *dbnickname;
michael@0 241 struct NSSCertificateStr *nssCertificate; /* This is Stan stuff. */
michael@0 242 CERTCertTrust *trust;
michael@0 243
michael@0 244 /* the reference count is modified whenever someone looks up, dups
michael@0 245 * or destroys a certificate
michael@0 246 */
michael@0 247 int referenceCount;
michael@0 248
michael@0 249 /* The subject list is a list of all certs with the same subject name.
michael@0 250 * It can be modified any time a cert is added or deleted from either
michael@0 251 * the in-memory(temporary) or on-disk(permanent) database.
michael@0 252 */
michael@0 253 CERTSubjectList *subjectList;
michael@0 254
michael@0 255 /* these belong in the static section, but are here to maintain
michael@0 256 * the structure's integrity
michael@0 257 */
michael@0 258 CERTAuthKeyID * authKeyID; /* x509v3 authority key identifier */
michael@0 259 PRBool isRoot; /* cert is the end of a chain */
michael@0 260
michael@0 261 /* these fields are used by client GUI code to keep track of ssl sockets
michael@0 262 * that are blocked waiting on GUI feedback related to this cert.
michael@0 263 * XXX - these should be moved into some sort of application specific
michael@0 264 * data structure. They are only used by the browser right now.
michael@0 265 */
michael@0 266 union {
michael@0 267 void* apointer; /* was struct SECSocketNode* authsocketlist */
michael@0 268 struct {
michael@0 269 unsigned int hasUnsupportedCriticalExt :1;
michael@0 270 /* add any new option bits needed here */
michael@0 271 } bits;
michael@0 272 } options;
michael@0 273 int series; /* was int authsocketcount; record the series of the pkcs11ID */
michael@0 274
michael@0 275 /* This is PKCS #11 stuff. */
michael@0 276 PK11SlotInfo *slot; /*if this cert came of a token, which is it*/
michael@0 277 CK_OBJECT_HANDLE pkcs11ID; /*and which object on that token is it */
michael@0 278 PRBool ownSlot; /*true if the cert owns the slot reference */
michael@0 279 };
michael@0 280 #define SEC_CERTIFICATE_VERSION_1 0 /* default created */
michael@0 281 #define SEC_CERTIFICATE_VERSION_2 1 /* v2 */
michael@0 282 #define SEC_CERTIFICATE_VERSION_3 2 /* v3 extensions */
michael@0 283
michael@0 284 #define SEC_CRL_VERSION_1 0 /* default */
michael@0 285 #define SEC_CRL_VERSION_2 1 /* v2 extensions */
michael@0 286
michael@0 287 /*
michael@0 288 * used to identify class of cert in mime stream code
michael@0 289 */
michael@0 290 #define SEC_CERT_CLASS_CA 1
michael@0 291 #define SEC_CERT_CLASS_SERVER 2
michael@0 292 #define SEC_CERT_CLASS_USER 3
michael@0 293 #define SEC_CERT_CLASS_EMAIL 4
michael@0 294
michael@0 295 struct CERTDERCertsStr {
michael@0 296 PLArenaPool *arena;
michael@0 297 int numcerts;
michael@0 298 SECItem *rawCerts;
michael@0 299 };
michael@0 300
michael@0 301 /*
michael@0 302 ** A PKCS ? Attribute
michael@0 303 ** XXX this is duplicated through out the code, it *should* be moved
michael@0 304 ** to a central location. Where would be appropriate?
michael@0 305 */
michael@0 306 struct CERTAttributeStr {
michael@0 307 SECItem attrType;
michael@0 308 SECItem **attrValue;
michael@0 309 };
michael@0 310
michael@0 311 /*
michael@0 312 ** A PKCS#10 certificate-request object (the unsigned form)
michael@0 313 */
michael@0 314 struct CERTCertificateRequestStr {
michael@0 315 PLArenaPool *arena;
michael@0 316 SECItem version;
michael@0 317 CERTName subject;
michael@0 318 CERTSubjectPublicKeyInfo subjectPublicKeyInfo;
michael@0 319 CERTAttribute **attributes;
michael@0 320 };
michael@0 321 #define SEC_CERTIFICATE_REQUEST_VERSION 0 /* what we *create* */
michael@0 322
michael@0 323
michael@0 324 /*
michael@0 325 ** A certificate list object.
michael@0 326 */
michael@0 327 struct CERTCertificateListStr {
michael@0 328 SECItem *certs;
michael@0 329 int len; /* number of certs */
michael@0 330 PLArenaPool *arena;
michael@0 331 };
michael@0 332
michael@0 333 struct CERTCertListNodeStr {
michael@0 334 PRCList links;
michael@0 335 CERTCertificate *cert;
michael@0 336 void *appData;
michael@0 337 };
michael@0 338
michael@0 339 struct CERTCertListStr {
michael@0 340 PRCList list;
michael@0 341 PLArenaPool *arena;
michael@0 342 };
michael@0 343
michael@0 344 #define CERT_LIST_HEAD(l) ((CERTCertListNode *)PR_LIST_HEAD(&l->list))
michael@0 345 #define CERT_LIST_TAIL(l) ((CERTCertListNode *)PR_LIST_TAIL(&l->list))
michael@0 346 #define CERT_LIST_NEXT(n) ((CERTCertListNode *)n->links.next)
michael@0 347 #define CERT_LIST_END(n,l) (((void *)n) == ((void *)&l->list))
michael@0 348 #define CERT_LIST_EMPTY(l) CERT_LIST_END(CERT_LIST_HEAD(l), l)
michael@0 349
michael@0 350 struct CERTCrlEntryStr {
michael@0 351 SECItem serialNumber;
michael@0 352 SECItem revocationDate;
michael@0 353 CERTCertExtension **extensions;
michael@0 354 };
michael@0 355
michael@0 356 struct CERTCrlStr {
michael@0 357 PLArenaPool *arena;
michael@0 358 SECItem version;
michael@0 359 SECAlgorithmID signatureAlg;
michael@0 360 SECItem derName;
michael@0 361 CERTName name;
michael@0 362 SECItem lastUpdate;
michael@0 363 SECItem nextUpdate; /* optional for x.509 CRL */
michael@0 364 CERTCrlEntry **entries;
michael@0 365 CERTCertExtension **extensions;
michael@0 366 /* can't add anything there for binary backwards compatibility reasons */
michael@0 367 };
michael@0 368
michael@0 369 struct CERTCrlKeyStr {
michael@0 370 SECItem derName;
michael@0 371 SECItem dummy; /* The decoder can not skip a primitive,
michael@0 372 this serves as a place holder for the
michael@0 373 decoder to finish its task only
michael@0 374 */
michael@0 375 };
michael@0 376
michael@0 377 struct CERTSignedCrlStr {
michael@0 378 PLArenaPool *arena;
michael@0 379 CERTCrl crl;
michael@0 380 void *reserved1;
michael@0 381 PRBool reserved2;
michael@0 382 PRBool isperm;
michael@0 383 PRBool istemp;
michael@0 384 int referenceCount;
michael@0 385 CERTCertDBHandle *dbhandle;
michael@0 386 CERTSignedData signatureWrap; /* XXX */
michael@0 387 char *url;
michael@0 388 SECItem *derCrl;
michael@0 389 PK11SlotInfo *slot;
michael@0 390 CK_OBJECT_HANDLE pkcs11ID;
michael@0 391 void* opaque; /* do not touch */
michael@0 392 };
michael@0 393
michael@0 394
michael@0 395 struct CERTCrlHeadNodeStr {
michael@0 396 PLArenaPool *arena;
michael@0 397 CERTCertDBHandle *dbhandle;
michael@0 398 CERTCrlNode *first;
michael@0 399 CERTCrlNode *last;
michael@0 400 };
michael@0 401
michael@0 402
michael@0 403 struct CERTCrlNodeStr {
michael@0 404 CERTCrlNode *next;
michael@0 405 int type;
michael@0 406 CERTSignedCrl *crl;
michael@0 407 };
michael@0 408
michael@0 409
michael@0 410 /*
michael@0 411 * Array of X.500 Distinguished Names
michael@0 412 */
michael@0 413 struct CERTDistNamesStr {
michael@0 414 PLArenaPool *arena;
michael@0 415 int nnames;
michael@0 416 SECItem *names;
michael@0 417 void *head; /* private */
michael@0 418 };
michael@0 419
michael@0 420
michael@0 421 #define NS_CERT_TYPE_SSL_CLIENT (0x80) /* bit 0 */
michael@0 422 #define NS_CERT_TYPE_SSL_SERVER (0x40) /* bit 1 */
michael@0 423 #define NS_CERT_TYPE_EMAIL (0x20) /* bit 2 */
michael@0 424 #define NS_CERT_TYPE_OBJECT_SIGNING (0x10) /* bit 3 */
michael@0 425 #define NS_CERT_TYPE_RESERVED (0x08) /* bit 4 */
michael@0 426 #define NS_CERT_TYPE_SSL_CA (0x04) /* bit 5 */
michael@0 427 #define NS_CERT_TYPE_EMAIL_CA (0x02) /* bit 6 */
michael@0 428 #define NS_CERT_TYPE_OBJECT_SIGNING_CA (0x01) /* bit 7 */
michael@0 429
michael@0 430 #define EXT_KEY_USAGE_TIME_STAMP (0x8000)
michael@0 431 #define EXT_KEY_USAGE_STATUS_RESPONDER (0x4000)
michael@0 432
michael@0 433 #define NS_CERT_TYPE_APP ( NS_CERT_TYPE_SSL_CLIENT | \
michael@0 434 NS_CERT_TYPE_SSL_SERVER | \
michael@0 435 NS_CERT_TYPE_EMAIL | \
michael@0 436 NS_CERT_TYPE_OBJECT_SIGNING )
michael@0 437
michael@0 438 #define NS_CERT_TYPE_CA ( NS_CERT_TYPE_SSL_CA | \
michael@0 439 NS_CERT_TYPE_EMAIL_CA | \
michael@0 440 NS_CERT_TYPE_OBJECT_SIGNING_CA | \
michael@0 441 EXT_KEY_USAGE_STATUS_RESPONDER )
michael@0 442 typedef enum SECCertUsageEnum {
michael@0 443 certUsageSSLClient = 0,
michael@0 444 certUsageSSLServer = 1,
michael@0 445 certUsageSSLServerWithStepUp = 2,
michael@0 446 certUsageSSLCA = 3,
michael@0 447 certUsageEmailSigner = 4,
michael@0 448 certUsageEmailRecipient = 5,
michael@0 449 certUsageObjectSigner = 6,
michael@0 450 certUsageUserCertImport = 7,
michael@0 451 certUsageVerifyCA = 8,
michael@0 452 certUsageProtectedObjectSigner = 9,
michael@0 453 certUsageStatusResponder = 10,
michael@0 454 certUsageAnyCA = 11
michael@0 455 } SECCertUsage;
michael@0 456
michael@0 457 typedef PRInt64 SECCertificateUsage;
michael@0 458
michael@0 459 #define certificateUsageCheckAllUsages (0x0000)
michael@0 460 #define certificateUsageSSLClient (0x0001)
michael@0 461 #define certificateUsageSSLServer (0x0002)
michael@0 462 #define certificateUsageSSLServerWithStepUp (0x0004)
michael@0 463 #define certificateUsageSSLCA (0x0008)
michael@0 464 #define certificateUsageEmailSigner (0x0010)
michael@0 465 #define certificateUsageEmailRecipient (0x0020)
michael@0 466 #define certificateUsageObjectSigner (0x0040)
michael@0 467 #define certificateUsageUserCertImport (0x0080)
michael@0 468 #define certificateUsageVerifyCA (0x0100)
michael@0 469 #define certificateUsageProtectedObjectSigner (0x0200)
michael@0 470 #define certificateUsageStatusResponder (0x0400)
michael@0 471 #define certificateUsageAnyCA (0x0800)
michael@0 472
michael@0 473 #define certificateUsageHighest certificateUsageAnyCA
michael@0 474
michael@0 475 /*
michael@0 476 * Does the cert belong to the user, a peer, or a CA.
michael@0 477 */
michael@0 478 typedef enum CERTCertOwnerEnum {
michael@0 479 certOwnerUser = 0,
michael@0 480 certOwnerPeer = 1,
michael@0 481 certOwnerCA = 2
michael@0 482 } CERTCertOwner;
michael@0 483
michael@0 484 /*
michael@0 485 * This enum represents the state of validity times of a certificate
michael@0 486 */
michael@0 487 typedef enum SECCertTimeValidityEnum {
michael@0 488 secCertTimeValid = 0,
michael@0 489 secCertTimeExpired = 1,
michael@0 490 secCertTimeNotValidYet = 2,
michael@0 491 secCertTimeUndetermined = 3 /* validity could not be decoded from the
michael@0 492 cert, most likely because it was NULL */
michael@0 493 } SECCertTimeValidity;
michael@0 494
michael@0 495 /*
michael@0 496 * This is used as return status in functions that compare the validity
michael@0 497 * periods of two certificates A and B, currently only
michael@0 498 * CERT_CompareValidityTimes.
michael@0 499 */
michael@0 500
michael@0 501 typedef enum CERTCompareValidityStatusEnum
michael@0 502 {
michael@0 503 certValidityUndetermined = 0, /* the function is unable to select one cert
michael@0 504 over another */
michael@0 505 certValidityChooseB = 1, /* cert B should be preferred */
michael@0 506 certValidityEqual = 2, /* both certs have the same validity period */
michael@0 507 certValidityChooseA = 3 /* cert A should be preferred */
michael@0 508 } CERTCompareValidityStatus;
michael@0 509
michael@0 510 /*
michael@0 511 * Interface for getting certificate nickname strings out of the database
michael@0 512 */
michael@0 513
michael@0 514 /* these are values for the what argument below */
michael@0 515 #define SEC_CERT_NICKNAMES_ALL 1
michael@0 516 #define SEC_CERT_NICKNAMES_USER 2
michael@0 517 #define SEC_CERT_NICKNAMES_SERVER 3
michael@0 518 #define SEC_CERT_NICKNAMES_CA 4
michael@0 519
michael@0 520 struct CERTCertNicknamesStr {
michael@0 521 PLArenaPool *arena;
michael@0 522 void *head;
michael@0 523 int numnicknames;
michael@0 524 char **nicknames;
michael@0 525 int what;
michael@0 526 int totallen;
michael@0 527 };
michael@0 528
michael@0 529 struct CERTIssuerAndSNStr {
michael@0 530 SECItem derIssuer;
michael@0 531 CERTName issuer;
michael@0 532 SECItem serialNumber;
michael@0 533 };
michael@0 534
michael@0 535
michael@0 536 /* X.509 v3 Key Usage Extension flags */
michael@0 537 #define KU_DIGITAL_SIGNATURE (0x80) /* bit 0 */
michael@0 538 #define KU_NON_REPUDIATION (0x40) /* bit 1 */
michael@0 539 #define KU_KEY_ENCIPHERMENT (0x20) /* bit 2 */
michael@0 540 #define KU_DATA_ENCIPHERMENT (0x10) /* bit 3 */
michael@0 541 #define KU_KEY_AGREEMENT (0x08) /* bit 4 */
michael@0 542 #define KU_KEY_CERT_SIGN (0x04) /* bit 5 */
michael@0 543 #define KU_CRL_SIGN (0x02) /* bit 6 */
michael@0 544 #define KU_ENCIPHER_ONLY (0x01) /* bit 7 */
michael@0 545 #define KU_ALL (KU_DIGITAL_SIGNATURE | \
michael@0 546 KU_NON_REPUDIATION | \
michael@0 547 KU_KEY_ENCIPHERMENT | \
michael@0 548 KU_DATA_ENCIPHERMENT | \
michael@0 549 KU_KEY_AGREEMENT | \
michael@0 550 KU_KEY_CERT_SIGN | \
michael@0 551 KU_CRL_SIGN | \
michael@0 552 KU_ENCIPHER_ONLY)
michael@0 553
michael@0 554 /* This value will not occur in certs. It is used internally for the case
michael@0 555 * when either digital signature or non-repudiation is the correct value.
michael@0 556 */
michael@0 557 #define KU_DIGITAL_SIGNATURE_OR_NON_REPUDIATION (0x2000)
michael@0 558
michael@0 559 /* This value will not occur in certs. It is used internally for the case
michael@0 560 * when the key type is not know ahead of time and either key agreement or
michael@0 561 * key encipherment are the correct value based on key type
michael@0 562 */
michael@0 563 #define KU_KEY_AGREEMENT_OR_ENCIPHERMENT (0x4000)
michael@0 564
michael@0 565 /* internal bits that do not match bits in the x509v3 spec, but are used
michael@0 566 * for similar purposes
michael@0 567 */
michael@0 568 #define KU_NS_GOVT_APPROVED (0x8000) /*don't make part of KU_ALL!*/
michael@0 569 /*
michael@0 570 * x.509 v3 Basic Constraints Extension
michael@0 571 * If isCA is false, the pathLenConstraint is ignored.
michael@0 572 * Otherwise, the following pathLenConstraint values will apply:
michael@0 573 * < 0 - there is no limit to the certificate path
michael@0 574 * 0 - CA can issues end-entity certificates only
michael@0 575 * > 0 - the number of certificates in the certificate path is
michael@0 576 * limited to this number
michael@0 577 */
michael@0 578 #define CERT_UNLIMITED_PATH_CONSTRAINT -2
michael@0 579
michael@0 580 struct CERTBasicConstraintsStr {
michael@0 581 PRBool isCA; /* on if is CA */
michael@0 582 int pathLenConstraint; /* maximum number of certificates that can be
michael@0 583 in the cert path. Only applies to a CA
michael@0 584 certificate; otherwise, it's ignored.
michael@0 585 */
michael@0 586 };
michael@0 587
michael@0 588 /* Maximum length of a certificate chain */
michael@0 589 #define CERT_MAX_CERT_CHAIN 20
michael@0 590
michael@0 591 #define CERT_MAX_SERIAL_NUMBER_BYTES 20 /* from RFC 3280 */
michael@0 592 #define CERT_MAX_DN_BYTES 4096 /* arbitrary */
michael@0 593
michael@0 594 /* x.509 v3 Reason Flags, used in CRLDistributionPoint Extension */
michael@0 595 #define RF_UNUSED (0x80) /* bit 0 */
michael@0 596 #define RF_KEY_COMPROMISE (0x40) /* bit 1 */
michael@0 597 #define RF_CA_COMPROMISE (0x20) /* bit 2 */
michael@0 598 #define RF_AFFILIATION_CHANGED (0x10) /* bit 3 */
michael@0 599 #define RF_SUPERSEDED (0x08) /* bit 4 */
michael@0 600 #define RF_CESSATION_OF_OPERATION (0x04) /* bit 5 */
michael@0 601 #define RF_CERTIFICATE_HOLD (0x02) /* bit 6 */
michael@0 602
michael@0 603 /* enum for CRL Entry Reason Code */
michael@0 604 typedef enum CERTCRLEntryReasonCodeEnum {
michael@0 605 crlEntryReasonUnspecified = 0,
michael@0 606 crlEntryReasonKeyCompromise = 1,
michael@0 607 crlEntryReasonCaCompromise = 2,
michael@0 608 crlEntryReasonAffiliationChanged = 3,
michael@0 609 crlEntryReasonSuperseded = 4,
michael@0 610 crlEntryReasonCessationOfOperation = 5,
michael@0 611 crlEntryReasoncertificatedHold = 6,
michael@0 612 crlEntryReasonRemoveFromCRL = 8,
michael@0 613 crlEntryReasonPrivilegeWithdrawn = 9,
michael@0 614 crlEntryReasonAaCompromise = 10
michael@0 615 } CERTCRLEntryReasonCode;
michael@0 616
michael@0 617 /* If we needed to extract the general name field, use this */
michael@0 618 /* General Name types */
michael@0 619 typedef enum CERTGeneralNameTypeEnum {
michael@0 620 certOtherName = 1,
michael@0 621 certRFC822Name = 2,
michael@0 622 certDNSName = 3,
michael@0 623 certX400Address = 4,
michael@0 624 certDirectoryName = 5,
michael@0 625 certEDIPartyName = 6,
michael@0 626 certURI = 7,
michael@0 627 certIPAddress = 8,
michael@0 628 certRegisterID = 9
michael@0 629 } CERTGeneralNameType;
michael@0 630
michael@0 631
michael@0 632 typedef struct OtherNameStr {
michael@0 633 SECItem name;
michael@0 634 SECItem oid;
michael@0 635 }OtherName;
michael@0 636
michael@0 637
michael@0 638
michael@0 639 struct CERTGeneralNameStr {
michael@0 640 CERTGeneralNameType type; /* name type */
michael@0 641 union {
michael@0 642 CERTName directoryName; /* distinguish name */
michael@0 643 OtherName OthName; /* Other Name */
michael@0 644 SECItem other; /* the rest of the name forms */
michael@0 645 }name;
michael@0 646 SECItem derDirectoryName; /* this is saved to simplify directory name
michael@0 647 comparison */
michael@0 648 PRCList l;
michael@0 649 };
michael@0 650
michael@0 651 struct CERTGeneralNameListStr {
michael@0 652 PLArenaPool *arena;
michael@0 653 CERTGeneralName *name;
michael@0 654 int refCount;
michael@0 655 int len;
michael@0 656 PZLock *lock;
michael@0 657 };
michael@0 658
michael@0 659 struct CERTNameConstraintStr {
michael@0 660 CERTGeneralName name;
michael@0 661 SECItem DERName;
michael@0 662 SECItem min;
michael@0 663 SECItem max;
michael@0 664 PRCList l;
michael@0 665 };
michael@0 666
michael@0 667
michael@0 668 struct CERTNameConstraintsStr {
michael@0 669 CERTNameConstraint *permited;
michael@0 670 CERTNameConstraint *excluded;
michael@0 671 SECItem **DERPermited;
michael@0 672 SECItem **DERExcluded;
michael@0 673 };
michael@0 674
michael@0 675
michael@0 676 /* Private Key Usage Period extension struct. */
michael@0 677 struct CERTPrivKeyUsagePeriodStr {
michael@0 678 SECItem notBefore;
michael@0 679 SECItem notAfter;
michael@0 680 PLArenaPool *arena;
michael@0 681 };
michael@0 682
michael@0 683 /* X.509 v3 Authority Key Identifier extension. For the authority certificate
michael@0 684 issuer field, we only support URI now.
michael@0 685 */
michael@0 686 struct CERTAuthKeyIDStr {
michael@0 687 SECItem keyID; /* unique key identifier */
michael@0 688 CERTGeneralName *authCertIssuer; /* CA's issuer name. End with a NULL */
michael@0 689 SECItem authCertSerialNumber; /* CA's certificate serial number */
michael@0 690 SECItem **DERAuthCertIssuer; /* This holds the DER encoded format of
michael@0 691 the authCertIssuer field. It is used
michael@0 692 by the encoding engine. It should be
michael@0 693 used as a read only field by the caller.
michael@0 694 */
michael@0 695 };
michael@0 696
michael@0 697 /* x.509 v3 CRL Distributeion Point */
michael@0 698
michael@0 699 /*
michael@0 700 * defined the types of CRL Distribution points
michael@0 701 */
michael@0 702 typedef enum DistributionPointTypesEnum {
michael@0 703 generalName = 1, /* only support this for now */
michael@0 704 relativeDistinguishedName = 2
michael@0 705 } DistributionPointTypes;
michael@0 706
michael@0 707 struct CRLDistributionPointStr {
michael@0 708 DistributionPointTypes distPointType;
michael@0 709 union {
michael@0 710 CERTGeneralName *fullName;
michael@0 711 CERTRDN relativeName;
michael@0 712 } distPoint;
michael@0 713 SECItem reasons;
michael@0 714 CERTGeneralName *crlIssuer;
michael@0 715
michael@0 716 /* Reserved for internal use only*/
michael@0 717 SECItem derDistPoint;
michael@0 718 SECItem derRelativeName;
michael@0 719 SECItem **derCrlIssuer;
michael@0 720 SECItem **derFullName;
michael@0 721 SECItem bitsmap;
michael@0 722 };
michael@0 723
michael@0 724 struct CERTCrlDistributionPointsStr {
michael@0 725 CRLDistributionPoint **distPoints;
michael@0 726 };
michael@0 727
michael@0 728 /*
michael@0 729 * This structure is used to keep a log of errors when verifying
michael@0 730 * a cert chain. This allows multiple errors to be reported all at
michael@0 731 * once.
michael@0 732 */
michael@0 733 struct CERTVerifyLogNodeStr {
michael@0 734 CERTCertificate *cert; /* what cert had the error */
michael@0 735 long error; /* what error was it? */
michael@0 736 unsigned int depth; /* how far up the chain are we */
michael@0 737 void *arg; /* error specific argument */
michael@0 738 struct CERTVerifyLogNodeStr *next; /* next in the list */
michael@0 739 struct CERTVerifyLogNodeStr *prev; /* next in the list */
michael@0 740 };
michael@0 741
michael@0 742
michael@0 743 struct CERTVerifyLogStr {
michael@0 744 PLArenaPool *arena;
michael@0 745 unsigned int count;
michael@0 746 struct CERTVerifyLogNodeStr *head;
michael@0 747 struct CERTVerifyLogNodeStr *tail;
michael@0 748 };
michael@0 749
michael@0 750
michael@0 751 struct CERTOKDomainNameStr {
michael@0 752 CERTOKDomainName *next;
michael@0 753 char name[1]; /* actual length may be longer. */
michael@0 754 };
michael@0 755
michael@0 756
michael@0 757 typedef SECStatus (PR_CALLBACK *CERTStatusChecker) (CERTCertDBHandle *handle,
michael@0 758 CERTCertificate *cert,
michael@0 759 PRTime time,
michael@0 760 void *pwArg);
michael@0 761
michael@0 762 typedef SECStatus (PR_CALLBACK *CERTStatusDestroy) (CERTStatusConfig *handle);
michael@0 763
michael@0 764 struct CERTStatusConfigStr {
michael@0 765 CERTStatusChecker statusChecker; /* NULL means no checking enabled */
michael@0 766 CERTStatusDestroy statusDestroy; /* enabled or no, will clean up */
michael@0 767 void *statusContext; /* cx specific to checking protocol */
michael@0 768 };
michael@0 769
michael@0 770 struct CERTAuthInfoAccessStr {
michael@0 771 SECItem method;
michael@0 772 SECItem derLocation;
michael@0 773 CERTGeneralName *location; /* decoded location */
michael@0 774 };
michael@0 775
michael@0 776
michael@0 777 /* This is the typedef for the callback passed to CERT_OpenCertDB() */
michael@0 778 /* callback to return database name based on version number */
michael@0 779 typedef char * (*CERTDBNameFunc)(void *arg, int dbVersion);
michael@0 780
michael@0 781 /*
michael@0 782 * types of cert packages that we can decode
michael@0 783 */
michael@0 784 typedef enum CERTPackageTypeEnum {
michael@0 785 certPackageNone = 0,
michael@0 786 certPackageCert = 1,
michael@0 787 certPackagePKCS7 = 2,
michael@0 788 certPackageNSCertSeq = 3,
michael@0 789 certPackageNSCertWrap = 4
michael@0 790 } CERTPackageType;
michael@0 791
michael@0 792 /*
michael@0 793 * these types are for the PKIX Certificate Policies extension
michael@0 794 */
michael@0 795 typedef struct {
michael@0 796 SECOidTag oid;
michael@0 797 SECItem qualifierID;
michael@0 798 SECItem qualifierValue;
michael@0 799 } CERTPolicyQualifier;
michael@0 800
michael@0 801 typedef struct {
michael@0 802 SECOidTag oid;
michael@0 803 SECItem policyID;
michael@0 804 CERTPolicyQualifier **policyQualifiers;
michael@0 805 } CERTPolicyInfo;
michael@0 806
michael@0 807 typedef struct {
michael@0 808 PLArenaPool *arena;
michael@0 809 CERTPolicyInfo **policyInfos;
michael@0 810 } CERTCertificatePolicies;
michael@0 811
michael@0 812 typedef struct {
michael@0 813 SECItem organization;
michael@0 814 SECItem **noticeNumbers;
michael@0 815 } CERTNoticeReference;
michael@0 816
michael@0 817 typedef struct {
michael@0 818 PLArenaPool *arena;
michael@0 819 CERTNoticeReference noticeReference;
michael@0 820 SECItem derNoticeReference;
michael@0 821 SECItem displayText;
michael@0 822 } CERTUserNotice;
michael@0 823
michael@0 824 typedef struct {
michael@0 825 PLArenaPool *arena;
michael@0 826 SECItem **oids;
michael@0 827 } CERTOidSequence;
michael@0 828
michael@0 829 /*
michael@0 830 * these types are for the PKIX Policy Mappings extension
michael@0 831 */
michael@0 832 typedef struct {
michael@0 833 SECItem issuerDomainPolicy;
michael@0 834 SECItem subjectDomainPolicy;
michael@0 835 } CERTPolicyMap;
michael@0 836
michael@0 837 typedef struct {
michael@0 838 PLArenaPool *arena;
michael@0 839 CERTPolicyMap **policyMaps;
michael@0 840 } CERTCertificatePolicyMappings;
michael@0 841
michael@0 842 /*
michael@0 843 * these types are for the PKIX inhibitAnyPolicy extension
michael@0 844 */
michael@0 845 typedef struct {
michael@0 846 SECItem inhibitAnySkipCerts;
michael@0 847 } CERTCertificateInhibitAny;
michael@0 848
michael@0 849 /*
michael@0 850 * these types are for the PKIX Policy Constraints extension
michael@0 851 */
michael@0 852 typedef struct {
michael@0 853 SECItem explicitPolicySkipCerts;
michael@0 854 SECItem inhibitMappingSkipCerts;
michael@0 855 } CERTCertificatePolicyConstraints;
michael@0 856
michael@0 857 /*
michael@0 858 * These types are for the validate chain callback param.
michael@0 859 *
michael@0 860 * CERTChainVerifyCallback is an application-supplied callback that can be used
michael@0 861 * to augment libpkix's certificate chain validation with additional
michael@0 862 * application-specific checks. It may be called multiple times if there are
michael@0 863 * multiple potentially-valid paths for the certificate being validated. This
michael@0 864 * callback is called before revocation checking is done on the certificates in
michael@0 865 * the given chain.
michael@0 866 *
michael@0 867 * - isValidChainArg contains the application-provided opaque argument
michael@0 868 * - currentChain is the currently validated chain. It is ordered with the leaf
michael@0 869 * certificate at the head and the trust anchor at the tail.
michael@0 870 *
michael@0 871 * The callback should set *chainOK = PR_TRUE and return SECSuccess if the
michael@0 872 * certificate chain is acceptable. It should set *chainOK = PR_FALSE and
michael@0 873 * return SECSuccess if the chain is unacceptable, to indicate that the given
michael@0 874 * chain is bad and path building should continue. It should return SECFailure
michael@0 875 * to indicate an fatal error that will cause path validation to fail
michael@0 876 * immediately.
michael@0 877 */
michael@0 878 typedef SECStatus (*CERTChainVerifyCallbackFunc)
michael@0 879 (void *isChainValidArg,
michael@0 880 const CERTCertList *currentChain,
michael@0 881 PRBool *chainOK);
michael@0 882
michael@0 883 /*
michael@0 884 * Note: If extending this structure, it will be necessary to change the
michael@0 885 * associated CERTValParamInType
michael@0 886 */
michael@0 887 typedef struct {
michael@0 888 CERTChainVerifyCallbackFunc isChainValid;
michael@0 889 void *isChainValidArg;
michael@0 890 } CERTChainVerifyCallback;
michael@0 891
michael@0 892 /*
michael@0 893 * these types are for the CERT_PKIX* Verification functions
michael@0 894 * These are all optional parameters.
michael@0 895 */
michael@0 896
michael@0 897 typedef enum {
michael@0 898 cert_pi_end = 0, /* SPECIAL: signifies end of array of
michael@0 899 * CERTValParam* */
michael@0 900 cert_pi_nbioContext = 1, /* specify a non-blocking IO context used to
michael@0 901 * resume a session. If this argument is
michael@0 902 * specified, no other arguments should be.
michael@0 903 * Specified in value.pointer.p. If the
michael@0 904 * operation completes the context will be
michael@0 905 * freed. */
michael@0 906 cert_pi_nbioAbort = 2, /* specify a non-blocking IO context for an
michael@0 907 * existing operation which the caller wants
michael@0 908 * to abort. If this argument is
michael@0 909 * specified, no other arguments should be.
michael@0 910 * Specified in value.pointer.p. If the
michael@0 911 * operation succeeds the context will be
michael@0 912 * freed. */
michael@0 913 cert_pi_certList = 3, /* specify the chain to validate against. If
michael@0 914 * this value is given, then the path
michael@0 915 * construction step in the validation is
michael@0 916 * skipped. Specified in value.pointer.chain */
michael@0 917 cert_pi_policyOID = 4, /* validate certificate for policy OID.
michael@0 918 * Specified in value.array.oids. Cert must
michael@0 919 * be good for at least one OID in order
michael@0 920 * to validate. Default is that the user is not
michael@0 921 * concerned about certificate policy. */
michael@0 922 cert_pi_policyFlags = 5, /* flags for each policy specified in policyOID.
michael@0 923 * Specified in value.scalar.ul. Policy flags
michael@0 924 * apply to all specified oids.
michael@0 925 * Use CERT_POLICY_FLAG_* macros below. If not
michael@0 926 * specified policy flags default to 0 */
michael@0 927 cert_pi_keyusage = 6, /* specify what the keyusages the certificate
michael@0 928 * will be evaluated against, specified in
michael@0 929 * value.scalar.ui. The cert must validate for
michael@0 930 * at least one of the specified key usages.
michael@0 931 * Values match the KU_ bit flags defined
michael@0 932 * in this file. Default is derived from
michael@0 933 * the 'usages' function argument */
michael@0 934 cert_pi_extendedKeyusage= 7, /* specify what the required extended key
michael@0 935 * usage of the certificate. Specified as
michael@0 936 * an array of oidTags in value.array.oids.
michael@0 937 * The cert must validate for at least one
michael@0 938 * of the specified extended key usages.
michael@0 939 * If not specified, no extended key usages
michael@0 940 * will be checked. */
michael@0 941 cert_pi_date = 8, /* validate certificate is valid as of date
michael@0 942 * specified in value.scalar.time. A special
michael@0 943 * value '0' indicates 'now'. default is '0' */
michael@0 944 cert_pi_revocationFlags = 9, /* Specify what revocation checking to do.
michael@0 945 * See CERT_REV_FLAG_* macros below
michael@0 946 * Set in value.pointer.revocation */
michael@0 947 cert_pi_certStores = 10,/* Bitmask of Cert Store flags (see below)
michael@0 948 * Set in value.scalar.ui */
michael@0 949 cert_pi_trustAnchors = 11,/* Specify the list of trusted roots to
michael@0 950 * validate against.
michael@0 951 * The default set of trusted roots, these are
michael@0 952 * root CA certs from libnssckbi.so or CA
michael@0 953 * certs trusted by user, are used in any of
michael@0 954 * the following cases:
michael@0 955 * * when the parameter is not set.
michael@0 956 * * when the list of trust anchors is empty.
michael@0 957 * Note that this handling can be further altered by altering the
michael@0 958 * cert_pi_useOnlyTrustAnchors flag
michael@0 959 * Specified in value.pointer.chain */
michael@0 960 cert_pi_useAIACertFetch = 12, /* Enables cert fetching using AIA extension.
michael@0 961 * In NSS 3.12.1 or later. Default is off.
michael@0 962 * Value is in value.scalar.b */
michael@0 963 cert_pi_chainVerifyCallback = 13,
michael@0 964 /* The callback container for doing extra
michael@0 965 * validation on the currently calculated chain.
michael@0 966 * Value is in value.pointer.chainVerifyCallback */
michael@0 967 cert_pi_useOnlyTrustAnchors = 14,/* If true, disables trusting any
michael@0 968 * certificates other than the ones passed in via cert_pi_trustAnchors.
michael@0 969 * If false, then the certificates specified via cert_pi_trustAnchors
michael@0 970 * will be combined with the pre-existing trusted roots, but only for
michael@0 971 * the certificate validation being performed.
michael@0 972 * If no value has been supplied via cert_pi_trustAnchors, this has no
michael@0 973 * effect.
michael@0 974 * The default value is true, meaning if this is not supplied, only
michael@0 975 * trust anchors supplied via cert_pi_trustAnchors are trusted.
michael@0 976 * Specified in value.scalar.b */
michael@0 977 cert_pi_max /* SPECIAL: signifies maximum allowed value,
michael@0 978 * can increase in future releases */
michael@0 979 } CERTValParamInType;
michael@0 980
michael@0 981 /*
michael@0 982 * for all out parameters:
michael@0 983 * out parameters are only returned if the caller asks for them in
michael@0 984 * the CERTValOutParam array. Caller is responsible for the CERTValOutParam
michael@0 985 * array itself. The pkix verify function will allocate and other arrays
michael@0 986 * pointers, or objects. The Caller is responsible for freeing those results.
michael@0 987 * If SECWouldBlock is returned, only cert_pi_nbioContext is returned.
michael@0 988 */
michael@0 989 typedef enum {
michael@0 990 cert_po_end = 0, /* SPECIAL: signifies end of array of
michael@0 991 * CERTValParam* */
michael@0 992 cert_po_nbioContext = 1, /* Return a nonblocking context. If no
michael@0 993 * non-blocking context is specified, then
michael@0 994 * blocking IO will be used.
michael@0 995 * Returned in value.pointer.p. The context is
michael@0 996 * freed after an abort or a complete operation.
michael@0 997 * This value is only returned on SECWouldBlock.
michael@0 998 */
michael@0 999 cert_po_trustAnchor = 2, /* Return the trust anchor for the chain that
michael@0 1000 * was validated. Returned in
michael@0 1001 * value.pointer.cert, this value is only
michael@0 1002 * returned on SECSuccess. */
michael@0 1003 cert_po_certList = 3, /* Return the entire chain that was validated.
michael@0 1004 * Returned in value.pointer.certList. If no
michael@0 1005 * chain could be constructed, this value
michael@0 1006 * would be NULL. */
michael@0 1007 cert_po_policyOID = 4, /* Return the policies that were found to be
michael@0 1008 * valid. Returned in value.array.oids as an
michael@0 1009 * array. This is only returned on
michael@0 1010 * SECSuccess. */
michael@0 1011 cert_po_errorLog = 5, /* Return a log of problems with the chain.
michael@0 1012 * Returned in value.pointer.log */
michael@0 1013 cert_po_usages = 6, /* Return what usages the certificate is valid
michael@0 1014 for. Returned in value.scalar.usages */
michael@0 1015 cert_po_keyUsage = 7, /* Return what key usages the certificate
michael@0 1016 * is valid for.
michael@0 1017 * Returned in value.scalar.usage */
michael@0 1018 cert_po_extendedKeyusage= 8, /* Return what extended key usages the
michael@0 1019 * certificate is valid for.
michael@0 1020 * Returned in value.array.oids */
michael@0 1021 cert_po_max /* SPECIAL: signifies maximum allowed value,
michael@0 1022 * can increase in future releases */
michael@0 1023
michael@0 1024 } CERTValParamOutType;
michael@0 1025
michael@0 1026 typedef enum {
michael@0 1027 cert_revocation_method_crl = 0,
michael@0 1028 cert_revocation_method_ocsp,
michael@0 1029 cert_revocation_method_count
michael@0 1030 } CERTRevocationMethodIndex;
michael@0 1031
michael@0 1032
michael@0 1033 /*
michael@0 1034 * The following flags are supposed to be used to control bits in
michael@0 1035 * each integer contained in the array pointed to be:
michael@0 1036 * CERTRevocationTests.cert_rev_flags_per_method
michael@0 1037 * All Flags are prefixed by CERT_REV_M_, where _M_ indicates
michael@0 1038 * this is a method dependent flag.
michael@0 1039 */
michael@0 1040
michael@0 1041 /*
michael@0 1042 * Whether or not to use a method for revocation testing.
michael@0 1043 * If set to "do not test", then all other flags are ignored.
michael@0 1044 */
michael@0 1045 #define CERT_REV_M_DO_NOT_TEST_USING_THIS_METHOD 0UL
michael@0 1046 #define CERT_REV_M_TEST_USING_THIS_METHOD 1UL
michael@0 1047
michael@0 1048 /*
michael@0 1049 * Whether or not NSS is allowed to attempt to fetch fresh information
michael@0 1050 * from the network.
michael@0 1051 * (Although fetching will never happen if fresh information for the
michael@0 1052 * method is already locally available.)
michael@0 1053 */
michael@0 1054 #define CERT_REV_M_ALLOW_NETWORK_FETCHING 0UL
michael@0 1055 #define CERT_REV_M_FORBID_NETWORK_FETCHING 2UL
michael@0 1056
michael@0 1057 /*
michael@0 1058 * Example for an implicit default source:
michael@0 1059 * The globally configured default OCSP responder.
michael@0 1060 * IGNORE means:
michael@0 1061 * ignore the implicit default source, whether it's configured or not.
michael@0 1062 * ALLOW means:
michael@0 1063 * if an implicit default source is configured,
michael@0 1064 * then it overrides any available or missing source in the cert.
michael@0 1065 * if no implicit default source is configured,
michael@0 1066 * then we continue to use what's available (or not available)
michael@0 1067 * in the certs.
michael@0 1068 */
michael@0 1069 #define CERT_REV_M_ALLOW_IMPLICIT_DEFAULT_SOURCE 0UL
michael@0 1070 #define CERT_REV_M_IGNORE_IMPLICIT_DEFAULT_SOURCE 4UL
michael@0 1071
michael@0 1072 /*
michael@0 1073 * Defines the behavior if no fresh information is available,
michael@0 1074 * fetching from the network is allowed, but the source of revocation
michael@0 1075 * information is unknown (even after considering implicit sources,
michael@0 1076 * if allowed by other flags).
michael@0 1077 * SKIPT_TEST means:
michael@0 1078 * We ignore that no fresh information is available and
michael@0 1079 * skip this test.
michael@0 1080 * REQUIRE_INFO means:
michael@0 1081 * We still require that fresh information is available.
michael@0 1082 * Other flags define what happens on missing fresh info.
michael@0 1083 */
michael@0 1084 #define CERT_REV_M_SKIP_TEST_ON_MISSING_SOURCE 0UL
michael@0 1085 #define CERT_REV_M_REQUIRE_INFO_ON_MISSING_SOURCE 8UL
michael@0 1086
michael@0 1087 /*
michael@0 1088 * Defines the behavior if we are unable to obtain fresh information.
michael@0 1089 * INGORE means:
michael@0 1090 * Return "cert status unknown"
michael@0 1091 * FAIL means:
michael@0 1092 * Return "cert revoked".
michael@0 1093 */
michael@0 1094 #define CERT_REV_M_IGNORE_MISSING_FRESH_INFO 0UL
michael@0 1095 #define CERT_REV_M_FAIL_ON_MISSING_FRESH_INFO 16UL
michael@0 1096
michael@0 1097 /*
michael@0 1098 * What should happen if we were able to find fresh information using
michael@0 1099 * this method, and the data indicated the cert is good?
michael@0 1100 * STOP_TESTING means:
michael@0 1101 * Our success is sufficient, do not continue testing
michael@0 1102 * other methods.
michael@0 1103 * CONTINUE_TESTING means:
michael@0 1104 * We will continue and test the next allowed
michael@0 1105 * specified method.
michael@0 1106 */
michael@0 1107 #define CERT_REV_M_STOP_TESTING_ON_FRESH_INFO 0UL
michael@0 1108 #define CERT_REV_M_CONTINUE_TESTING_ON_FRESH_INFO 32UL
michael@0 1109
michael@0 1110 /* When this flag is used, libpkix will never attempt to use the GET HTTP
michael@0 1111 * method for OCSP requests; it will always use POST.
michael@0 1112 */
michael@0 1113 #define CERT_REV_M_FORCE_POST_METHOD_FOR_OCSP 64UL
michael@0 1114
michael@0 1115 /*
michael@0 1116 * The following flags are supposed to be used to control bits in
michael@0 1117 * CERTRevocationTests.cert_rev_method_independent_flags
michael@0 1118 * All Flags are prefixed by CERT_REV_M_, where _M_ indicates
michael@0 1119 * this is a method independent flag.
michael@0 1120 */
michael@0 1121
michael@0 1122 /*
michael@0 1123 * This defines the order to checking.
michael@0 1124 * EACH_METHOD_SEPARATELY means:
michael@0 1125 * Do all tests related to a particular allowed method
michael@0 1126 * (both local information and network fetching) in a single step.
michael@0 1127 * Only after testing for a particular method is done,
michael@0 1128 * then switching to the next method will happen.
michael@0 1129 * ALL_LOCAL_INFORMATION_FIRST means:
michael@0 1130 * Start by testing the information for all allowed methods
michael@0 1131 * which are already locally available. Only after that is done
michael@0 1132 * consider to fetch from the network (as allowed by other flags).
michael@0 1133 */
michael@0 1134 #define CERT_REV_MI_TEST_EACH_METHOD_SEPARATELY 0UL
michael@0 1135 #define CERT_REV_MI_TEST_ALL_LOCAL_INFORMATION_FIRST 1UL
michael@0 1136
michael@0 1137 /*
michael@0 1138 * Use this flag to specify that it's necessary that fresh information
michael@0 1139 * is available for at least one of the allowed methods, but it's
michael@0 1140 * irrelevant which of the mechanisms succeeded.
michael@0 1141 * NO_OVERALL_INFO_REQUIREMENT means:
michael@0 1142 * We strictly follow the requirements for each individual method.
michael@0 1143 * REQUIRE_SOME_FRESH_INFO_AVAILABLE means:
michael@0 1144 * After the individual tests have been executed, we must have
michael@0 1145 * been able to find fresh information using at least one method.
michael@0 1146 * If we were unable to find fresh info, it's a failure.
michael@0 1147 * This setting overrides the CERT_REV_M_FAIL_ON_MISSING_FRESH_INFO
michael@0 1148 * flag on all methods.
michael@0 1149 */
michael@0 1150 #define CERT_REV_MI_NO_OVERALL_INFO_REQUIREMENT 0UL
michael@0 1151 #define CERT_REV_MI_REQUIRE_SOME_FRESH_INFO_AVAILABLE 2UL
michael@0 1152
michael@0 1153
michael@0 1154 typedef struct {
michael@0 1155 /*
michael@0 1156 * The size of the array that cert_rev_flags_per_method points to,
michael@0 1157 * meaning, the number of methods that are known and defined
michael@0 1158 * by the caller.
michael@0 1159 */
michael@0 1160 PRUint32 number_of_defined_methods;
michael@0 1161
michael@0 1162 /*
michael@0 1163 * A pointer to an array of integers.
michael@0 1164 * Each integer defines revocation checking for a single method,
michael@0 1165 * by having individual CERT_REV_M_* bits set or not set.
michael@0 1166 * The meaning of index numbers into this array are defined by
michael@0 1167 * enum CERTRevocationMethodIndex
michael@0 1168 * The size of the array must be specified by the caller in the separate
michael@0 1169 * variable number_of_defined_methods.
michael@0 1170 * The size of the array may be smaller than
michael@0 1171 * cert_revocation_method_count, it can happen if a caller
michael@0 1172 * is not yet aware of the latest revocation methods
michael@0 1173 * (or does not want to use them).
michael@0 1174 */
michael@0 1175 PRUint64 *cert_rev_flags_per_method;
michael@0 1176
michael@0 1177 /*
michael@0 1178 * How many preferred methods are specified?
michael@0 1179 * This is equivalent to the size of the array that
michael@0 1180 * preferred_revocation_methods points to.
michael@0 1181 * It's allowed to set this value to zero,
michael@0 1182 * then NSS will decide which methods to prefer.
michael@0 1183 */
michael@0 1184 PRUint32 number_of_preferred_methods;
michael@0 1185
michael@0 1186 /* Array that may specify an optional order of preferred methods.
michael@0 1187 * Each array entry shall contain a method identifier as defined
michael@0 1188 * by CERTRevocationMethodIndex.
michael@0 1189 * The entry at index [0] specifies the method with highest preferrence.
michael@0 1190 * These methods will be tested first for locally available information.
michael@0 1191 * Methods allowed for downloading will be attempted in the same order.
michael@0 1192 */
michael@0 1193 CERTRevocationMethodIndex *preferred_methods;
michael@0 1194
michael@0 1195 /*
michael@0 1196 * An integer which defines certain aspects of revocation checking
michael@0 1197 * (independent of individual methods) by having individual
michael@0 1198 * CERT_REV_MI_* bits set or not set.
michael@0 1199 */
michael@0 1200 PRUint64 cert_rev_method_independent_flags;
michael@0 1201 } CERTRevocationTests;
michael@0 1202
michael@0 1203 typedef struct {
michael@0 1204 CERTRevocationTests leafTests;
michael@0 1205 CERTRevocationTests chainTests;
michael@0 1206 } CERTRevocationFlags;
michael@0 1207
michael@0 1208 typedef struct CERTValParamInValueStr {
michael@0 1209 union {
michael@0 1210 PRBool b;
michael@0 1211 PRInt32 i;
michael@0 1212 PRUint32 ui;
michael@0 1213 PRInt64 l;
michael@0 1214 PRUint64 ul;
michael@0 1215 PRTime time;
michael@0 1216 } scalar;
michael@0 1217 union {
michael@0 1218 const void* p;
michael@0 1219 const char* s;
michael@0 1220 const CERTCertificate* cert;
michael@0 1221 const CERTCertList *chain;
michael@0 1222 const CERTRevocationFlags *revocation;
michael@0 1223 const CERTChainVerifyCallback *chainVerifyCallback;
michael@0 1224 } pointer;
michael@0 1225 union {
michael@0 1226 const PRInt32 *pi;
michael@0 1227 const PRUint32 *pui;
michael@0 1228 const PRInt64 *pl;
michael@0 1229 const PRUint64 *pul;
michael@0 1230 const SECOidTag *oids;
michael@0 1231 } array;
michael@0 1232 int arraySize;
michael@0 1233 } CERTValParamInValue;
michael@0 1234
michael@0 1235
michael@0 1236 typedef struct CERTValParamOutValueStr {
michael@0 1237 union {
michael@0 1238 PRBool b;
michael@0 1239 PRInt32 i;
michael@0 1240 PRUint32 ui;
michael@0 1241 PRInt64 l;
michael@0 1242 PRUint64 ul;
michael@0 1243 SECCertificateUsage usages;
michael@0 1244 } scalar;
michael@0 1245 union {
michael@0 1246 void* p;
michael@0 1247 char* s;
michael@0 1248 CERTVerifyLog *log;
michael@0 1249 CERTCertificate* cert;
michael@0 1250 CERTCertList *chain;
michael@0 1251 } pointer;
michael@0 1252 union {
michael@0 1253 void *p;
michael@0 1254 SECOidTag *oids;
michael@0 1255 } array;
michael@0 1256 int arraySize;
michael@0 1257 } CERTValParamOutValue;
michael@0 1258
michael@0 1259 typedef struct {
michael@0 1260 CERTValParamInType type;
michael@0 1261 CERTValParamInValue value;
michael@0 1262 } CERTValInParam;
michael@0 1263
michael@0 1264 typedef struct {
michael@0 1265 CERTValParamOutType type;
michael@0 1266 CERTValParamOutValue value;
michael@0 1267 } CERTValOutParam;
michael@0 1268
michael@0 1269 /*
michael@0 1270 * Levels of standards conformance strictness for CERT_NameToAsciiInvertible
michael@0 1271 */
michael@0 1272 typedef enum CertStrictnessLevels {
michael@0 1273 CERT_N2A_READABLE = 0, /* maximum human readability */
michael@0 1274 CERT_N2A_STRICT = 10, /* strict RFC compliance */
michael@0 1275 CERT_N2A_INVERTIBLE = 20 /* maximum invertibility,
michael@0 1276 all DirectoryStrings encoded in hex */
michael@0 1277 } CertStrictnessLevel;
michael@0 1278
michael@0 1279 /*
michael@0 1280 * policy flag defines
michael@0 1281 */
michael@0 1282 #define CERT_POLICY_FLAG_NO_MAPPING 1
michael@0 1283 #define CERT_POLICY_FLAG_EXPLICIT 2
michael@0 1284 #define CERT_POLICY_FLAG_NO_ANY 4
michael@0 1285
michael@0 1286 /*
michael@0 1287 * CertStore flags
michael@0 1288 */
michael@0 1289 #define CERT_ENABLE_LDAP_FETCH 1
michael@0 1290 #define CERT_ENABLE_HTTP_FETCH 2
michael@0 1291
michael@0 1292 /* This functin pointer type may be used for any function that takes
michael@0 1293 * a CERTCertificate * and returns an allocated string, which must be
michael@0 1294 * freed by a call to PORT_Free.
michael@0 1295 */
michael@0 1296 typedef char * (*CERT_StringFromCertFcn)(CERTCertificate *cert);
michael@0 1297
michael@0 1298 /* XXX Lisa thinks the template declarations belong in cert.h, not here? */
michael@0 1299
michael@0 1300 #include "secasn1t.h" /* way down here because I expect template stuff to
michael@0 1301 * move out of here anyway */
michael@0 1302
michael@0 1303 SEC_BEGIN_PROTOS
michael@0 1304
michael@0 1305 extern const SEC_ASN1Template CERT_CertificateRequestTemplate[];
michael@0 1306 extern const SEC_ASN1Template CERT_CertificateTemplate[];
michael@0 1307 extern const SEC_ASN1Template SEC_SignedCertificateTemplate[];
michael@0 1308 extern const SEC_ASN1Template CERT_CertExtensionTemplate[];
michael@0 1309 extern const SEC_ASN1Template CERT_SequenceOfCertExtensionTemplate[];
michael@0 1310 extern const SEC_ASN1Template SECKEY_PublicKeyTemplate[];
michael@0 1311 extern const SEC_ASN1Template CERT_SubjectPublicKeyInfoTemplate[];
michael@0 1312 extern const SEC_ASN1Template CERT_TimeChoiceTemplate[];
michael@0 1313 extern const SEC_ASN1Template CERT_ValidityTemplate[];
michael@0 1314 extern const SEC_ASN1Template CERT_PublicKeyAndChallengeTemplate[];
michael@0 1315 extern const SEC_ASN1Template SEC_CertSequenceTemplate[];
michael@0 1316
michael@0 1317 extern const SEC_ASN1Template CERT_IssuerAndSNTemplate[];
michael@0 1318 extern const SEC_ASN1Template CERT_NameTemplate[];
michael@0 1319 extern const SEC_ASN1Template CERT_SetOfSignedCrlTemplate[];
michael@0 1320 extern const SEC_ASN1Template CERT_RDNTemplate[];
michael@0 1321 extern const SEC_ASN1Template CERT_SignedDataTemplate[];
michael@0 1322 extern const SEC_ASN1Template CERT_CrlTemplate[];
michael@0 1323 extern const SEC_ASN1Template CERT_SignedCrlTemplate[];
michael@0 1324
michael@0 1325 /*
michael@0 1326 ** XXX should the attribute stuff be centralized for all of ns/security?
michael@0 1327 */
michael@0 1328 extern const SEC_ASN1Template CERT_AttributeTemplate[];
michael@0 1329 extern const SEC_ASN1Template CERT_SetOfAttributeTemplate[];
michael@0 1330
michael@0 1331 /* These functions simply return the address of the above-declared templates.
michael@0 1332 ** This is necessary for Windows DLLs. Sigh.
michael@0 1333 */
michael@0 1334 SEC_ASN1_CHOOSER_DECLARE(CERT_CertificateRequestTemplate)
michael@0 1335 SEC_ASN1_CHOOSER_DECLARE(CERT_CertificateTemplate)
michael@0 1336 SEC_ASN1_CHOOSER_DECLARE(CERT_CrlTemplate)
michael@0 1337 SEC_ASN1_CHOOSER_DECLARE(CERT_IssuerAndSNTemplate)
michael@0 1338 SEC_ASN1_CHOOSER_DECLARE(CERT_NameTemplate)
michael@0 1339 SEC_ASN1_CHOOSER_DECLARE(CERT_SequenceOfCertExtensionTemplate)
michael@0 1340 SEC_ASN1_CHOOSER_DECLARE(CERT_SetOfSignedCrlTemplate)
michael@0 1341 SEC_ASN1_CHOOSER_DECLARE(CERT_SignedDataTemplate)
michael@0 1342 SEC_ASN1_CHOOSER_DECLARE(CERT_SubjectPublicKeyInfoTemplate)
michael@0 1343 SEC_ASN1_CHOOSER_DECLARE(SEC_SignedCertificateTemplate)
michael@0 1344 SEC_ASN1_CHOOSER_DECLARE(CERT_SignedCrlTemplate)
michael@0 1345 SEC_ASN1_CHOOSER_DECLARE(CERT_TimeChoiceTemplate)
michael@0 1346
michael@0 1347 SEC_END_PROTOS
michael@0 1348
michael@0 1349 #endif /* _CERTT_H_ */

mercurial