2 * Copyright (c) 2000-2001 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 * TPCertInfo.h - TP's private certificate info and cert group classes
22 * Written 10/23/2000 by Doug Mitchell.
25 #ifndef _TP_CERT_INFO_H_
26 #define _TP_CERT_INFO_H_
28 #include <Security/cssmtype.h>
29 #include <Security/utilities.h>
30 #include <Security/cssmalloc.h>
33 * Class representing one certificate. The raw cert data usually comes from
34 * a client (via incoming cert groups in CertGroupConstruct() and CertGroupVerify());
35 * In this case, we don't own the raw data and don't copy or free it. Caller can
36 * optionally specify that we copy (and own and eventnually free) the raw cert data.
37 * The constructor throws on any error (bad cert data); subsequent to successful
38 * construction, no CSSM errors are thrown and it's guaranteed that the cert is
39 * basically good and successfully cached in the CL, and that we have a locally
40 * cached subject and issuer name (in normalized encoded format).
46 * No default constructor - this is the only way.
47 * This caches the cert and fetches subjectName and issuerName
48 * to ensure the incoming certData is well-constructed.
51 const CSSM_DATA
*certData
,
52 CSSM_CL_HANDLE clHand
,
53 bool copyCertData
= false); // true: we copy, we free
54 // false - caller owns
56 /* frees mSubjectName, mIssuerName, mCacheHand via mClHand */
60 * Fetch arbitrary field from cached cert.
61 * Only should be used when caller is sure there is either zero or one
62 * of the requested fields present in the cert.
64 CSSM_RETURN
fetchField(
65 const CSSM_OID
*fieldOid
,
66 CSSM_DATA_PTR
*fieldData
); // mallocd by CL and RETURNED
68 /* free arbitrary field obtained from fetchField() */
69 CSSM_RETURN
freeField(
70 const CSSM_OID
*fieldOid
,
71 CSSM_DATA_PTR fieldData
);
74 CSSM_CL_HANDLE
clHand();
75 CSSM_HANDLE
cacheHand();
76 const CSSM_DATA
*certData();
77 const CSSM_DATA
*subjectName();
78 const CSSM_DATA
*issuerName();
80 bool isSelfSigned(); // i.e., subject == issuer
83 * Verify validity (not before/after). Returns
84 * CSSMERR_TP_CERT_NOT_VALID_YET
85 * CSSMERR_TP_CERT_EXPIRED
87 * CSSMERR_TP_INVALID_CERT_POINTER, other "bogus cert" errors
89 CSSM_RETURN
isCurrent(
90 CSSM_BOOL allowExpired
= CSSM_FALSE
);
93 CSSM_DATA
*mCertData
; // always valid
94 bool mWeOwnTheData
; // if true, we have to free mCertData
95 CSSM_CL_HANDLE mClHand
; // always valid
96 CSSM_HANDLE mCacheHand
; // always valid
97 CSSM_DATA_PTR mSubjectName
; // always valid
98 CSSM_DATA_PTR mIssuerName
; // always valid
100 void releaseResources();
102 /* other field accessors here */
106 * TP's private Cert Group class. Provides a list of TPCertInfo pointers, to which
107 * caller can append additional elements, access an element at an arbitrary position,
108 * and remover an element at an arbitrrary position.
114 * No default constructor - use this to cook up an instance with
115 * space for numCerts TPCertInfos.
118 CssmAllocator
&alloc
,
122 * Deletes all TPCertInfo's.
126 /* add/remove/access TPTCertInfo's. */
128 TPCertInfo
*certInfo
); // appends to end of mCertInfo
129 TPCertInfo
*certAtIndex(
131 TPCertInfo
*removeCertAtIndex(
132 unsigned index
); // doesn't delete the cert, just
133 // removes it from our list
134 unsigned numCerts(); // how many do we have?
137 * Convenience accessors for first and last cert, only valid when we have
145 /* build a CSSM_CERTGROUP corresponding with our mCertInfo */
147 buildCssmCertGroup();
150 CssmAllocator
&mAlloc
;
151 TPCertInfo
**mCertInfo
; // just an array of pointers
152 unsigned mNumCerts
; // valid certs in certInfo
153 unsigned mSizeofCertInfo
; // mallocd space in certInfo
155 #endif /* _TP_CERT_INFO_H_ */