Import from 1.9a8 tarball
[mozilla-nss.git] / security / nss / lib / pki / pkim.h
blob0b620333ee9d183f6517233688566f7feb249b19
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
14 * The Original Code is the Netscape security libraries.
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.
21 * Contributor(s):
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.
35 * ***** END LICENSE BLOCK ***** */
37 #ifndef PKIM_H
38 #define PKIM_H
40 #ifdef DEBUG
41 static const char PKIM_CVS_ID[] = "@(#) $RCSfile: pkim.h,v $ $Revision: 1.28 $ $Date: 2006/08/22 22:54:11 $";
42 #endif /* DEBUG */
44 #ifndef BASE_H
45 #include "base.h"
46 #endif /* BASE_H */
48 #ifndef PKI_H
49 #include "pki.h"
50 #endif /* PKI_H */
52 #ifndef PKITM_H
53 #include "pkitm.h"
54 #endif /* PKITM_H */
56 PR_BEGIN_EXTERN_C
58 /* nssPKIObject
60 * This is the base object class, common to all PKI objects defined in
61 * in this module. Each object can be safely 'casted' to an nssPKIObject,
62 * then passed to these methods.
64 * nssPKIObject_Create
65 * nssPKIObject_Destroy
66 * nssPKIObject_AddRef
67 * nssPKIObject_AddInstance
68 * nssPKIObject_HasInstance
69 * nssPKIObject_GetTokens
70 * nssPKIObject_GetNicknameForToken
71 * nssPKIObject_RemoveInstanceForToken
72 * nssPKIObject_DeleteStoredObject
75 NSS_EXTERN void nssPKIObject_Lock (nssPKIObject * object);
76 NSS_EXTERN void nssPKIObject_Unlock (nssPKIObject * object);
77 NSS_EXTERN PRStatus nssPKIObject_NewLock (nssPKIObject * object,
78 nssPKILockType lockType);
79 NSS_EXTERN void nssPKIObject_DestroyLock(nssPKIObject * object);
81 /* nssPKIObject_Create
83 * A generic PKI object. It must live in a trust domain. It may be
84 * initialized with a token instance, or alternatively in a crypto context.
86 NSS_EXTERN nssPKIObject *
87 nssPKIObject_Create
89 NSSArena *arenaOpt,
90 nssCryptokiObject *instanceOpt,
91 NSSTrustDomain *td,
92 NSSCryptoContext *ccOpt,
93 nssPKILockType lockType
96 /* nssPKIObject_AddRef
98 NSS_EXTERN nssPKIObject *
99 nssPKIObject_AddRef
101 nssPKIObject *object
104 /* nssPKIObject_Destroy
106 * Returns true if object was destroyed. This notifies the subclass that
107 * all references are gone and it should delete any members it owns.
109 NSS_EXTERN PRBool
110 nssPKIObject_Destroy
112 nssPKIObject *object
115 /* nssPKIObject_AddInstance
117 * Add a token instance to the object, if it does not have it already.
119 NSS_EXTERN PRStatus
120 nssPKIObject_AddInstance
122 nssPKIObject *object,
123 nssCryptokiObject *instance
126 /* nssPKIObject_HasInstance
128 * Query the object for a token instance.
130 NSS_EXTERN PRBool
131 nssPKIObject_HasInstance
133 nssPKIObject *object,
134 nssCryptokiObject *instance
137 /* nssPKIObject_GetTokens
139 * Get all tokens which have an instance of the object.
141 NSS_EXTERN NSSToken **
142 nssPKIObject_GetTokens
144 nssPKIObject *object,
145 PRStatus *statusOpt
148 /* nssPKIObject_GetNicknameForToken
150 * tokenOpt == NULL means take the first available, otherwise return the
151 * nickname for the specified token.
153 NSS_EXTERN NSSUTF8 *
154 nssPKIObject_GetNicknameForToken
156 nssPKIObject *object,
157 NSSToken *tokenOpt
160 /* nssPKIObject_RemoveInstanceForToken
162 * Remove the instance of the object on the specified token.
164 NSS_EXTERN PRStatus
165 nssPKIObject_RemoveInstanceForToken
167 nssPKIObject *object,
168 NSSToken *token
171 /* nssPKIObject_DeleteStoredObject
173 * Delete all token instances of the object, as well as any crypto context
174 * instances (TODO). If any of the instances are read-only, or if the
175 * removal fails, the object will keep those instances. 'isFriendly' refers
176 * to the object -- can this object be removed from a friendly token without
177 * login? For example, certificates are friendly, private keys are not.
178 * Note that if the token is not friendly, authentication will be required
179 * regardless of the value of 'isFriendly'.
181 NSS_EXTERN PRStatus
182 nssPKIObject_DeleteStoredObject
184 nssPKIObject *object,
185 NSSCallback *uhh,
186 PRBool isFriendly
189 #ifdef NSS_3_4_CODE
190 NSS_EXTERN nssCryptokiObject **
191 nssPKIObject_GetInstances
193 nssPKIObject *object
195 #endif
197 NSS_EXTERN NSSCertificate **
198 nssTrustDomain_FindCertificatesByID
200 NSSTrustDomain *td,
201 NSSItem *id,
202 NSSCertificate **rvOpt,
203 PRUint32 maximumOpt,
204 NSSArena *arenaOpt
207 NSS_EXTERN NSSCRL **
208 nssTrustDomain_FindCRLsBySubject
210 NSSTrustDomain *td,
211 NSSDER *subject
214 /* module-private nsspki methods */
216 NSS_EXTERN NSSCryptoContext *
217 nssCryptoContext_Create
219 NSSTrustDomain *td,
220 NSSCallback *uhhOpt
223 /* XXX for the collection */
224 NSS_EXTERN NSSCertificate *
225 nssCertificate_Create
227 nssPKIObject *object
230 NSS_EXTERN PRStatus
231 nssCertificate_SetCertTrust
233 NSSCertificate *c,
234 NSSTrust *trust
237 NSS_EXTERN nssDecodedCert *
238 nssCertificate_GetDecoding
240 NSSCertificate *c
243 extern PRIntn
244 nssCertificate_SubjectListSort
246 void *v1,
247 void *v2
250 NSS_EXTERN nssDecodedCert *
251 nssDecodedCert_Create
253 NSSArena *arenaOpt,
254 NSSDER *encoding,
255 NSSCertificateType type
258 NSS_EXTERN PRStatus
259 nssDecodedCert_Destroy
261 nssDecodedCert *dc
264 NSS_EXTERN NSSTrust *
265 nssTrust_Create
267 nssPKIObject *object,
268 NSSItem *certData
271 NSS_EXTERN NSSCRL *
272 nssCRL_Create
274 nssPKIObject *object
277 NSS_EXTERN NSSCRL *
278 nssCRL_AddRef
280 NSSCRL *crl
283 NSS_EXTERN PRStatus
284 nssCRL_Destroy
286 NSSCRL *crl
289 NSS_EXTERN PRStatus
290 nssCRL_DeleteStoredObject
292 NSSCRL *crl,
293 NSSCallback *uhh
296 NSS_EXTERN NSSPrivateKey *
297 nssPrivateKey_Create
299 nssPKIObject *o
302 NSS_EXTERN NSSDER *
303 nssCRL_GetEncoding
305 NSSCRL *crl
308 NSS_EXTERN NSSPublicKey *
309 nssPublicKey_Create
311 nssPKIObject *object
314 /* nssCertificateArray
316 * These are being thrown around a lot, might as well group together some
317 * functionality.
319 * nssCertificateArray_Destroy
320 * nssCertificateArray_Join
321 * nssCertificateArray_FindBestCertificate
322 * nssCertificateArray_Traverse
325 /* nssCertificateArray_Destroy
327 * Will destroy the array and the certs within it. If the array was created
328 * in an arena, will *not* (of course) destroy the arena. However, is safe
329 * to call this method on an arena-allocated array.
331 NSS_EXTERN void
332 nssCertificateArray_Destroy
334 NSSCertificate **certs
337 /* nssCertificateArray_Join
339 * Join two arrays into one. The two arrays, certs1 and certs2, should
340 * be considered invalid after a call to this function (they may be destroyed
341 * as part of the join). certs1 and/or certs2 may be NULL. Safe to
342 * call with arrays allocated in an arena, the result will also be in the
343 * arena.
345 NSS_EXTERN NSSCertificate **
346 nssCertificateArray_Join
348 NSSCertificate **certs1,
349 NSSCertificate **certs2
352 /* nssCertificateArray_FindBestCertificate
354 * Use the usual { time, usage, policies } to find the best cert in the
355 * array.
357 NSS_EXTERN NSSCertificate *
358 nssCertificateArray_FindBestCertificate
360 NSSCertificate **certs,
361 NSSTime *timeOpt,
362 const NSSUsage *usage,
363 NSSPolicies *policiesOpt
366 /* nssCertificateArray_Traverse
368 * Do the callback for each cert, terminate the traversal if the callback
369 * fails.
371 NSS_EXTERN PRStatus
372 nssCertificateArray_Traverse
374 NSSCertificate **certs,
375 PRStatus (* callback)(NSSCertificate *c, void *arg),
376 void *arg
379 NSS_EXTERN void
380 nssCRLArray_Destroy
382 NSSCRL **crls
385 /* nssPKIObjectCollection
387 * This is a handy way to group objects together and perform operations
388 * on them. It can also handle "proto-objects"-- references to
389 * objects instances on tokens, where the actual object hasn't
390 * been formed yet.
392 * nssCertificateCollection_Create
393 * nssPrivateKeyCollection_Create
394 * nssPublicKeyCollection_Create
396 * If this was a language that provided for inheritance, each type would
397 * inherit all of the following methods. Instead, there is only one
398 * type (nssPKIObjectCollection), shared among all. This may cause
399 * confusion; an alternative would be to define all of the methods
400 * for each subtype (nssCertificateCollection_Destroy, ...), but that doesn't
401 * seem worth the code bloat.. It is left up to the caller to remember
402 * what type of collection he/she is dealing with.
404 * nssPKIObjectCollection_Destroy
405 * nssPKIObjectCollection_Count
406 * nssPKIObjectCollection_AddObject
407 * nssPKIObjectCollection_AddInstances
408 * nssPKIObjectCollection_Traverse
410 * Back to type-specific methods.
412 * nssPKIObjectCollection_GetCertificates
413 * nssPKIObjectCollection_GetCRLs
414 * nssPKIObjectCollection_GetPrivateKeys
415 * nssPKIObjectCollection_GetPublicKeys
418 /* nssCertificateCollection_Create
420 * Create a collection of certificates in the specified trust domain.
421 * Optionally provide a starting set of certs.
423 NSS_EXTERN nssPKIObjectCollection *
424 nssCertificateCollection_Create
426 NSSTrustDomain *td,
427 NSSCertificate **certsOpt
430 /* nssCRLCollection_Create
432 * Create a collection of CRLs/KRLs in the specified trust domain.
433 * Optionally provide a starting set of CRLs.
435 NSS_EXTERN nssPKIObjectCollection *
436 nssCRLCollection_Create
438 NSSTrustDomain *td,
439 NSSCRL **crlsOpt
442 /* nssPrivateKeyCollection_Create
444 * Create a collection of private keys in the specified trust domain.
445 * Optionally provide a starting set of keys.
447 NSS_EXTERN nssPKIObjectCollection *
448 nssPrivateKeyCollection_Create
450 NSSTrustDomain *td,
451 NSSPrivateKey **pvkOpt
454 /* nssPublicKeyCollection_Create
456 * Create a collection of public keys in the specified trust domain.
457 * Optionally provide a starting set of keys.
459 NSS_EXTERN nssPKIObjectCollection *
460 nssPublicKeyCollection_Create
462 NSSTrustDomain *td,
463 NSSPublicKey **pvkOpt
466 /* nssPKIObjectCollection_Destroy
468 NSS_EXTERN void
469 nssPKIObjectCollection_Destroy
471 nssPKIObjectCollection *collection
474 /* nssPKIObjectCollection_Count
476 NSS_EXTERN PRUint32
477 nssPKIObjectCollection_Count
479 nssPKIObjectCollection *collection
482 NSS_EXTERN PRStatus
483 nssPKIObjectCollection_AddObject
485 nssPKIObjectCollection *collection,
486 nssPKIObject *object
489 /* nssPKIObjectCollection_AddInstances
491 * Add a set of object instances to the collection. The instances
492 * will be sorted into any existing certs/proto-certs that may be in
493 * the collection. The instances will be absorbed by the collection,
494 * the array should not be used after this call (except to free it).
496 * Failure means the collection is in an invalid state.
498 * numInstances = 0 means the array is NULL-terminated
500 NSS_EXTERN PRStatus
501 nssPKIObjectCollection_AddInstances
503 nssPKIObjectCollection *collection,
504 nssCryptokiObject **instances,
505 PRUint32 numInstances
508 /* nssPKIObjectCollection_Traverse
510 NSS_EXTERN PRStatus
511 nssPKIObjectCollection_Traverse
513 nssPKIObjectCollection *collection,
514 nssPKIObjectCallback *callback
517 /* This function is being added for NSS 3.5. It corresponds to the function
518 * nssToken_TraverseCertificates. The idea is to use the collection during
519 * a traversal, creating certs each time a new instance is added for which
520 * a cert does not already exist.
522 NSS_EXTERN PRStatus
523 nssPKIObjectCollection_AddInstanceAsObject
525 nssPKIObjectCollection *collection,
526 nssCryptokiObject *instance
529 /* nssPKIObjectCollection_GetCertificates
531 * Get all of the certificates in the collection.
533 NSS_EXTERN NSSCertificate **
534 nssPKIObjectCollection_GetCertificates
536 nssPKIObjectCollection *collection,
537 NSSCertificate **rvOpt,
538 PRUint32 maximumOpt,
539 NSSArena *arenaOpt
542 NSS_EXTERN NSSCRL **
543 nssPKIObjectCollection_GetCRLs
545 nssPKIObjectCollection *collection,
546 NSSCRL **rvOpt,
547 PRUint32 maximumOpt,
548 NSSArena *arenaOpt
551 NSS_EXTERN NSSPrivateKey **
552 nssPKIObjectCollection_GetPrivateKeys
554 nssPKIObjectCollection *collection,
555 NSSPrivateKey **rvOpt,
556 PRUint32 maximumOpt,
557 NSSArena *arenaOpt
560 NSS_EXTERN NSSPublicKey **
561 nssPKIObjectCollection_GetPublicKeys
563 nssPKIObjectCollection *collection,
564 NSSPublicKey **rvOpt,
565 PRUint32 maximumOpt,
566 NSSArena *arenaOpt
569 NSS_EXTERN NSSTime *
570 NSSTime_Now
572 NSSTime *timeOpt
575 NSS_EXTERN NSSTime *
576 NSSTime_SetPRTime
578 NSSTime *timeOpt,
579 PRTime prTime
582 NSS_EXTERN PRTime
583 NSSTime_GetPRTime
585 NSSTime *time
588 NSS_EXTERN nssHash *
589 nssHash_CreateCertificate
591 NSSArena *arenaOpt,
592 PRUint32 numBuckets
595 /* 3.4 Certificate cache routines */
597 NSS_EXTERN PRStatus
598 nssTrustDomain_InitializeCache
600 NSSTrustDomain *td,
601 PRUint32 cacheSize
604 NSS_EXTERN PRStatus
605 nssTrustDomain_AddCertsToCache
607 NSSTrustDomain *td,
608 NSSCertificate **certs,
609 PRUint32 numCerts
612 NSS_EXTERN void
613 nssTrustDomain_RemoveCertFromCacheLOCKED (
614 NSSTrustDomain *td,
615 NSSCertificate *cert
618 NSS_EXTERN void
619 nssTrustDomain_LockCertCache (
620 NSSTrustDomain *td
623 NSS_EXTERN void
624 nssTrustDomain_UnlockCertCache (
625 NSSTrustDomain *td
628 NSS_IMPLEMENT PRStatus
629 nssTrustDomain_DestroyCache
631 NSSTrustDomain *td
635 * Remove all certs for the given token from the cache. This is
636 * needed if the token is removed.
638 NSS_EXTERN PRStatus
639 nssTrustDomain_RemoveTokenCertsFromCache
641 NSSTrustDomain *td,
642 NSSToken *token
645 NSS_EXTERN PRStatus
646 nssTrustDomain_UpdateCachedTokenCerts
648 NSSTrustDomain *td,
649 NSSToken *token
653 * Find all cached certs with this nickname (label).
655 NSS_EXTERN NSSCertificate **
656 nssTrustDomain_GetCertsForNicknameFromCache
658 NSSTrustDomain *td,
659 NSSUTF8 *nickname,
660 nssList *certListOpt
664 * Find all cached certs with this email address.
666 NSS_EXTERN NSSCertificate **
667 nssTrustDomain_GetCertsForEmailAddressFromCache
669 NSSTrustDomain *td,
670 NSSASCII7 *email,
671 nssList *certListOpt
675 * Find all cached certs with this subject.
677 NSS_EXTERN NSSCertificate **
678 nssTrustDomain_GetCertsForSubjectFromCache
680 NSSTrustDomain *td,
681 NSSDER *subject,
682 nssList *certListOpt
686 * Look for a specific cert in the cache.
688 NSS_EXTERN NSSCertificate *
689 nssTrustDomain_GetCertForIssuerAndSNFromCache
691 NSSTrustDomain *td,
692 NSSDER *issuer,
693 NSSDER *serialNum
697 * Look for a specific cert in the cache.
699 NSS_EXTERN NSSCertificate *
700 nssTrustDomain_GetCertByDERFromCache
702 NSSTrustDomain *td,
703 NSSDER *der
706 /* Get all certs from the cache */
707 /* XXX this is being included to make some old-style calls word, not to
708 * say we should keep it
710 NSS_EXTERN NSSCertificate **
711 nssTrustDomain_GetCertsFromCache
713 NSSTrustDomain *td,
714 nssList *certListOpt
717 NSS_EXTERN void
718 nssTrustDomain_DumpCacheInfo
720 NSSTrustDomain *td,
721 void (* cert_dump_iter)(const void *, void *, void *),
722 void *arg
725 NSS_EXTERN void
726 nssCertificateList_AddReferences
728 nssList *certList
731 PR_END_EXTERN_C
733 #endif /* PKIM_H */