2 * Copyright (c) 2002 Apple Computer, Inc. All Rights Reserved.
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
20 * TPCrlInfo.h - TP's private CRL and CRL group classes
22 * Written 9/25/2001 by Doug Mitchell.
25 #ifndef _TP_CRL_INFO_H_
26 #define _TP_CRL_INFO_H_
28 #include <Security/cssmtype.h>
29 #include <Security/utilities.h>
30 #include <Security/cssmalloc.h>
31 #include <Security/threading.h>
32 #include <Security/globalizer.h>
33 #include "TPCertInfo.h"
34 #include "tpCrlVerify.h"
37 * Verification state of a TPCrlInfo. Verification refers to the process
38 * of cert chain validation from the CRL to a trusted root. Since this
39 * is a rather heavyweight operation, this is done on demand, when a given
40 * CRL is "believed to be" the appropriate one for a given cert. It
41 * is separate from not before/after verification, which is performed
42 * on the fly as needed.
45 CVS_Unknown
, // initial default state
46 CVS_Good
, // known good
51 * Indicates where a particular CRL came from. Currently only used
52 * in the tpCrlVerify module.
55 CFW_Nowhere
, // default, never returned
56 CFW_InGroup
, // from incoming TPCrlGroup
57 CFW_DlDb
, // verifyContext.dbList
58 CFW_LocalCache
, // tpGlobalCrlCache
59 CFW_Net
, // tpFetchCrlFromNet
65 * Class representing one CRL. The raw CRL data usually comes from
66 * a client (via incoming CSSM_TP_VERIFY_CONTEXT.Crls); in this case, we
67 * don't own the raw data and don't copy or free it. Caller can
68 * optionally specify that we copy (and own and eventually free) the raw cert data.
69 * Currently this is only done when we find a CRL in a DlDb. The constructor throws
70 * on any error (bad CRL data); subsequent to successful construction, no CSSM
71 * errors are thrown and it's guaranteed that the CRL is basically readable and
72 * successfully cached in the CL, and that we have a locally cached
73 * CSSM_X509_SIGNED_CRL and issuer name (in normalized encoded format).
75 class TPCrlInfo
: public TPClItemInfo
80 * No default constructor - this is the only way.
83 CSSM_CL_HANDLE clHand
,
84 CSSM_CSP_HANDLE cspHand
,
85 const CSSM_DATA
*crlData
,
86 TPItemCopy copyCrlData
,
87 const char *verifyTime
); // NULL ==> time = right now
89 /* frees mIssuerName, mCacheHand, mX509Crl via mClHand */
93 * The heavyweight "perform full verification" op.
94 * If doCrlVerify is true, we'll do an eventually recursive
95 * CRL verification test on the cert group we construct
96 * here to verify the CRL in question. This recursive
97 * verifdy is also done if the CRL is an indirect CRL.
98 * Currently, the doCrlVerifyFlag will be set false in the
99 * normal case of verifying a cert chain; in that case the
100 * various certs needed to verify the CRL are assumed to
101 * be a subset of the cert chain being verified, and CRL
102 * verification of that cert chain is being performed
103 * elsewhere. The caller would set doCrlVerify true when
104 * the top-level op is simply a CRL verify.
106 CSSM_RETURN
verifyWithContext(
107 TPCrlVerifyContext
&tpVerifyContext
,
108 TPCertInfo
*forCert
, // optional
109 bool doCrlVerify
= false);
112 * Do I have the same issuer as the specified subject cert?
113 * Returns true if so.
115 bool TPCrlInfo::hasSameIssuer(
116 const TPCertInfo
&subject
);
119 * Determine if specified cert has been revoked. Assumes that
120 * the current CRL has been fully verified.
122 CSSM_RETURN
isCertRevoked(
123 TPCertInfo
&subjectCert
);
126 const CSSM_X509_SIGNED_CRL
*x509Crl() { return mX509Crl
; }
127 TPCrlVerifyState
verifyState() { return mVerifyState
; }
129 const CSSM_DATA
*uri() { return &mUri
; }
130 void uri(const CSSM_DATA
&uri
);
133 * Ref count info maintained by caller (currently only in
134 * tpCrlVfy.cpp's global cache module).
139 /* used only by tpCrlVerify */
140 TPCrlFromWhere mFromWhere
;
144 CSSM_X509_SIGNED_CRL
*mX509Crl
;
145 CSSM_DATA_PTR mCrlFieldToFree
;
146 TPCrlVerifyState mVerifyState
;
147 CSSM_RETURN mVerifyError
; // only if mVerifyState = CVS_Bad
148 CSSM_DATA mUri
; // if fetched from net
150 void releaseResources();
151 CSSM_RETURN
parseExtensions(
152 TPCrlVerifyContext
&tpVerifyContext
,
154 uint32 entryIndex
, // if isPerEntry
155 const CSSM_X509_EXTENSIONS
&extens
,
156 TPCertInfo
*forCert
, // optional
157 bool &isIndirectCrl
);// RETURNED
162 * TP's private CRL Group class.
168 /* construct empty CRL group */
170 CssmAllocator
&alloc
,
171 TPGroupOwner whoOwns
); // if TGO_Group, we delete
174 * Construct from unordered, untrusted CSSM_CRLGROUP. Resulting
175 * TPCrlInfos are more or less in the same order as the incoming
176 * CRLs, though incoming CRLs are discarded if they don't parse.
177 * No verification of any sort is performed.
180 const CSSM_CRLGROUP
*cssmCrlGroup
, // optional
181 CSSM_CL_HANDLE clHand
,
182 CSSM_CSP_HANDLE cspHand
,
183 CssmAllocator
&alloc
,
184 const char *cssmTimeStr
, // may be NULL
185 TPGroupOwner whoOwns
);
188 * Deletes all TPCrlInfo's.
192 /* add/remove/access TPCrlInfo's. */
194 TPCrlInfo
&crlInfo
); // appends to end of mCertInfo
195 TPCrlInfo
*crlAtIndex(
197 TPCrlInfo
&removeCrlAtIndex(
198 unsigned index
); // doesn't delete the cert, just
199 // removes it from our list
201 TPCrlInfo
&crlInfo
); // ditto
204 * Convenience accessors for first and last CRL, only valid when we have
207 TPCrlInfo
*firstCrl();
208 TPCrlInfo
*lastCrl();
211 * Find a CRL whose issuer matches specified subject cert.
212 * Returned CRL has not necessarily been verified.
214 TPCrlInfo
*findCrlForCert(
215 TPCertInfo
&subject
);
217 CssmAllocator
&alloc() { return mAlloc
; }
218 unsigned numCrls() { return mNumCrls
; }
221 CssmAllocator
&mAlloc
;
222 TPCrlInfo
**mCrlInfo
; // just an array of pointers
223 unsigned mNumCrls
; // valid certs in certInfo
224 unsigned mSizeofCrlInfo
; // mallocd space in certInfo
225 TPGroupOwner mWhoOwns
; // if TGO_Group, we delete CRLs
228 #endif /* _TP_CRL_INFO_H_ */