2 * Copyright (c) 2000-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 // cssmtrust - CSSM layer Trust (TP) related objects.
25 #include <Security/utilities.h>
26 #include <Security/cssmcert.h>
27 #include <Security/cssmcred.h>
34 // A TP "POLICYINFO" structure, essentially an OID/Data pair.
36 class PolicyInfo
: public PodWrapper
<PolicyInfo
, CSSM_TP_POLICYINFO
> {
38 uint32
count() const { return NumberOfPolicyIds
; }
39 uint32
&count() { return NumberOfPolicyIds
; }
40 CssmField
*policies() const { return CssmField::overlay(PolicyIds
); }
41 CssmField
* &policies() { return CssmField::overlayVar(PolicyIds
); }
42 void *control() const { return PolicyControl
; }
44 CssmField
&operator [] (uint32 ix
)
45 { assert(ix
< count()); return policies()[ix
]; }
47 void setPolicies(uint32 n
, CSSM_FIELD
*p
)
48 { count() = n
; policies() = CssmField::overlay(p
); }
53 // A CSSM_DL_DB_LIST wrapper.
54 // Note that there is a DLDBList class elsewhere that is quite
55 // unrelated to this structure.
57 class CssmDlDbHandle
: public PodWrapper
<CssmDlDbHandle
, CSSM_DL_DB_HANDLE
> {
59 CssmDlDbHandle(CSSM_DL_HANDLE dl
, CSSM_DB_HANDLE db
)
60 { DLHandle
= dl
; DBHandle
= db
; }
62 CSSM_DL_HANDLE
dl() const { return DLHandle
; }
63 CSSM_DB_HANDLE
db() const { return DBHandle
; }
65 operator bool() const { return DLHandle
&& DBHandle
; }
68 inline bool operator < (const CSSM_DL_DB_HANDLE
&h1
, const CSSM_DL_DB_HANDLE
&h2
)
70 return h1
.DLHandle
< h2
.DLHandle
71 || (h1
.DLHandle
== h2
.DLHandle
&& h1
.DBHandle
< h2
.DBHandle
);
74 inline bool operator == (const CSSM_DL_DB_HANDLE
&h1
, const CSSM_DL_DB_HANDLE
&h2
)
76 return h1
.DLHandle
== h2
.DLHandle
&& h1
.DBHandle
== h2
.DBHandle
;
79 inline bool operator != (const CSSM_DL_DB_HANDLE
&h1
, const CSSM_DL_DB_HANDLE
&h2
)
81 return h1
.DLHandle
!= h2
.DLHandle
|| h1
.DBHandle
!= h2
.DBHandle
;
85 class CssmDlDbList
: public PodWrapper
<CssmDlDbList
, CSSM_DL_DB_LIST
> {
87 uint32
count() const { return NumHandles
; }
88 uint32
&count() { return NumHandles
; }
89 CssmDlDbHandle
*handles() const { return CssmDlDbHandle::overlay(DLDBHandle
); }
90 CssmDlDbHandle
* &handles() { return CssmDlDbHandle::overlayVar(DLDBHandle
); }
92 CssmDlDbHandle
&operator [] (uint32 ix
) const
93 { assert(ix
< count()); return CssmDlDbHandle::overlay(DLDBHandle
[ix
]); }
95 void setDlDbList(uint32 n
, CSSM_DL_DB_HANDLE
*list
)
96 { count() = n
; handles() = CssmDlDbHandle::overlay(list
); }
101 // TP caller authentication contexts
103 class TPCallerAuth
: public PodWrapper
<TPCallerAuth
, CSSM_TP_CALLERAUTH_CONTEXT
> {
105 CSSM_TP_STOP_ON
stopCriterion() const { return VerificationAbortOn
; }
106 void stopCriterion(CSSM_TP_STOP_ON stop
) { VerificationAbortOn
= stop
; }
108 CSSM_TIMESTRING
time() const { return VerifyTime
; }
109 void time(CSSM_TIMESTRING newTime
) { VerifyTime
= newTime
; }
111 PolicyInfo
&policies() { return PolicyInfo::overlay(Policy
); }
112 const PolicyInfo
&policies() const { return PolicyInfo::overlay(Policy
); }
113 void setPolicies(uint32 n
, CSSM_FIELD
*p
) { policies().setPolicies(n
, p
); }
115 AccessCredentials
*creds() const
116 { return AccessCredentials::optional(CallerCredentials
); }
117 void creds(AccessCredentials
*newCreds
) { CallerCredentials
= newCreds
; }
119 uint32
anchorCount() const { return NumberOfAnchorCerts
; }
120 uint32
&anchorCount() { return NumberOfAnchorCerts
; }
121 CssmData
*anchors() const { return CssmData::overlay(AnchorCerts
); }
122 CssmData
* &anchors() { return CssmData::overlayVar(AnchorCerts
); }
124 CssmDlDbList
*dlDbList() const { return CssmDlDbList::overlay(DBList
); }
125 CssmDlDbList
* &dlDbList() { return CssmDlDbList::overlayVar(DBList
); }
130 // TP Verify Contexts - a monster collection of possibly useful stuff
131 // when verifying a certificate against trust policies
133 class TPVerifyContext
: public PodWrapper
<TPVerifyContext
, CSSM_TP_VERIFY_CONTEXT
> {
135 CSSM_TP_ACTION
action() const { return Action
; }
136 CssmData
&actionData() { return CssmData::overlay(ActionData
); }
137 const CssmData
&actionData() const { return CssmData::overlay(ActionData
); }
139 // set and reference the CallerAuth component
140 TPCallerAuth
&callerAuth() const { return TPCallerAuth::required(Cred
); }
141 operator TPCallerAuth
&() const { return callerAuth(); }
142 TPCallerAuth
*callerAuthPtr() const { return TPCallerAuth::optional(Cred
); }
143 void callerAuthPtr(CSSM_TP_CALLERAUTH_CONTEXT
*p
) { Cred
= p
; }
145 // forward CallerAuth operations
147 CSSM_TP_STOP_ON
stopCriterion() const { return callerAuth().stopCriterion(); }
148 void stopCriterion(CSSM_TP_STOP_ON stop
) { return callerAuth().stopCriterion(stop
); }
149 PolicyInfo
&policies() const { return callerAuth().policies(); }
150 void setPolicies(uint32 n
, CSSM_FIELD
*p
) { policies().setPolicies(n
, p
); }
151 CSSM_TIMESTRING
time() const { return callerAuth().time(); }
152 void time(CSSM_TIMESTRING newTime
) { return callerAuth().time(newTime
); }
153 AccessCredentials
*creds() const { return callerAuth().creds(); }
154 void creds(AccessCredentials
*newCreds
) const { return callerAuth().creds(newCreds
); }
155 uint32
anchorCount() const { return callerAuth().anchorCount(); }
156 uint32
&anchorCount() { return callerAuth().anchorCount(); }
157 CssmData
*anchors() const { return callerAuth().anchors(); }
158 CssmData
* &anchors() { return callerAuth().anchors(); }
159 void anchors(uint32 count
, CSSM_DATA
*vector
)
160 { anchorCount() = count
; anchors() = CssmData::overlay(vector
); }
161 void setDlDbList(uint32 n
, CSSM_DL_DB_HANDLE
*list
)
162 { callerAuth().dlDbList()->setDlDbList(n
, list
); }
167 // The result of a (raw) TP trust verification call
169 class TPEvidence
: public PodWrapper
<TPEvidence
, CSSM_EVIDENCE
> {
171 CSSM_EVIDENCE_FORM
form() const { return EvidenceForm
; }
172 void *data() const { return Evidence
; }
173 operator void *() const { return data(); }
176 T
*as() const { return reinterpret_cast<T
*>(Evidence
); }
179 class TPVerifyResult
: public PodWrapper
<TPVerifyResult
, CSSM_TP_VERIFY_CONTEXT_RESULT
> {
181 uint32
count() const { return NumberOfEvidences
; }
182 const TPEvidence
&operator [] (uint32 ix
) const
183 { assert(ix
< count()); return TPEvidence::overlay(Evidence
[ix
]); }
188 // A PodWrapper for Apple's TP supporting-evidence structure
190 class TPEvidenceInfo
: public PodWrapper
<TPEvidenceInfo
, CSSM_TP_APPLE_EVIDENCE_INFO
> {
192 CSSM_TP_APPLE_CERT_STATUS
status() const { return StatusBits
; }
193 CSSM_TP_APPLE_CERT_STATUS
status(CSSM_TP_APPLE_CERT_STATUS flags
) const
194 { return status() & flags
; }
196 uint32
index() const { return Index
; }
197 const CssmDlDbHandle
&dldb() const { return CssmDlDbHandle::overlay(DlDbHandle
); }
198 CSSM_DB_UNIQUE_RECORD_PTR
recordId() const { return UniqueRecord
; }
200 uint32
codes() const { return NumStatusCodes
; }
201 CSSM_RETURN
operator [] (uint32 ix
)
202 { assert(ix
< NumStatusCodes
); return StatusCodes
[ix
]; }
204 void destroy(CssmAllocator
&allocator
);
211 namespace DataWalkers
{
216 } // end namespace DataWalkers
217 } // end namespace Security
219 #endif //_H_CSSMTRUST