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
; }
69 class CssmDlDbList
: public PodWrapper
<CssmDlDbList
, CSSM_DL_DB_LIST
> {
71 uint32
count() const { return NumHandles
; }
72 uint32
&count() { return NumHandles
; }
73 CssmDlDbHandle
*handles() const { return CssmDlDbHandle::overlay(DLDBHandle
); }
74 CssmDlDbHandle
* &handles() { return CssmDlDbHandle::overlayVar(DLDBHandle
); }
76 CssmDlDbHandle
&operator [] (uint32 ix
) const
77 { assert(ix
< count()); return CssmDlDbHandle::overlay(DLDBHandle
[ix
]); }
79 void setDlDbList(uint32 n
, CSSM_DL_DB_HANDLE
*list
)
80 { count() = n
; handles() = CssmDlDbHandle::overlay(list
); }
85 // TP caller authentication contexts
87 class TPCallerAuth
: public PodWrapper
<TPCallerAuth
, CSSM_TP_CALLERAUTH_CONTEXT
> {
89 CSSM_TP_STOP_ON
stopCriterion() const { return VerificationAbortOn
; }
90 void stopCriterion(CSSM_TP_STOP_ON stop
) { VerificationAbortOn
= stop
; }
92 CSSM_TIMESTRING
time() const { return VerifyTime
; }
93 void time(CSSM_TIMESTRING newTime
) { VerifyTime
= newTime
; }
95 PolicyInfo
&policies() { return PolicyInfo::overlay(Policy
); }
96 const PolicyInfo
&policies() const { return PolicyInfo::overlay(Policy
); }
97 void setPolicies(uint32 n
, CSSM_FIELD
*p
) { policies().setPolicies(n
, p
); }
99 AccessCredentials
*creds() const
100 { return AccessCredentials::optional(CallerCredentials
); }
101 void creds(AccessCredentials
*newCreds
) { CallerCredentials
= newCreds
; }
103 uint32
anchorCount() const { return NumberOfAnchorCerts
; }
104 uint32
&anchorCount() { return NumberOfAnchorCerts
; }
105 CssmData
*anchors() const { return CssmData::overlay(AnchorCerts
); }
106 CssmData
* &anchors() { return CssmData::overlayVar(AnchorCerts
); }
108 CssmDlDbList
*dlDbList() const { return CssmDlDbList::overlay(DBList
); }
109 CssmDlDbList
* &dlDbList() { return CssmDlDbList::overlayVar(DBList
); }
114 // TP Verify Contexts - a monster collection of possibly useful stuff
115 // when verifying a certificate against trust policies
117 class TPVerifyContext
: public PodWrapper
<TPVerifyContext
, CSSM_TP_VERIFY_CONTEXT
> {
119 CSSM_TP_ACTION
action() const { return Action
; }
120 CssmData
&actionData() { return CssmData::overlay(ActionData
); }
121 const CssmData
&actionData() const { return CssmData::overlay(ActionData
); }
123 // set and reference the CallerAuth component
124 TPCallerAuth
&callerAuth() const { return TPCallerAuth::required(Cred
); }
125 operator TPCallerAuth
&() const { return callerAuth(); }
126 TPCallerAuth
*callerAuthPtr() const { return TPCallerAuth::optional(Cred
); }
127 void callerAuthPtr(CSSM_TP_CALLERAUTH_CONTEXT
*p
) { Cred
= p
; }
129 // forward CallerAuth operations
131 CSSM_TP_STOP_ON
stopCriterion() const { return callerAuth().stopCriterion(); }
132 void stopCriterion(CSSM_TP_STOP_ON stop
) { return callerAuth().stopCriterion(stop
); }
133 PolicyInfo
&policies() const { return callerAuth().policies(); }
134 void setPolicies(uint32 n
, CSSM_FIELD
*p
) { policies().setPolicies(n
, p
); }
135 CSSM_TIMESTRING
time() const { return callerAuth().time(); }
136 void time(CSSM_TIMESTRING newTime
) { return callerAuth().time(newTime
); }
137 AccessCredentials
*creds() const { return callerAuth().creds(); }
138 void creds(AccessCredentials
*newCreds
) const { return callerAuth().creds(newCreds
); }
139 uint32
anchorCount() const { return callerAuth().anchorCount(); }
140 uint32
&anchorCount() { return callerAuth().anchorCount(); }
141 CssmData
*anchors() const { return callerAuth().anchors(); }
142 CssmData
* &anchors() { return callerAuth().anchors(); }
143 void anchors(uint32 count
, CSSM_DATA
*vector
)
144 { anchorCount() = count
; anchors() = CssmData::overlay(vector
); }
145 void setDlDbList(uint32 n
, CSSM_DL_DB_HANDLE
*list
)
146 { callerAuth().dlDbList()->setDlDbList(n
, list
); }
151 // The result of a (raw) TP trust verification call
153 class TPEvidence
: public PodWrapper
<TPEvidence
, CSSM_EVIDENCE
> {
155 CSSM_EVIDENCE_FORM
form() const { return EvidenceForm
; }
156 void *data() const { return Evidence
; }
157 operator void *() const { return data(); }
160 T
*as() const { return reinterpret_cast<T
*>(Evidence
); }
163 class TPVerifyResult
: public PodWrapper
<TPVerifyResult
, CSSM_TP_VERIFY_CONTEXT_RESULT
> {
165 uint32
count() const { return NumberOfEvidences
; }
166 const TPEvidence
&operator [] (uint32 ix
) const
167 { assert(ix
< count()); return TPEvidence::overlay(Evidence
[ix
]); }
172 // A PodWrapper for Apple's TP supporting-evidence structure
174 class TPEvidenceInfo
: public PodWrapper
<TPEvidenceInfo
, CSSM_TP_APPLE_EVIDENCE_INFO
> {
176 CSSM_TP_APPLE_CERT_STATUS
status() const { return StatusBits
; }
177 CSSM_TP_APPLE_CERT_STATUS
status(CSSM_TP_APPLE_CERT_STATUS flags
) const
178 { return status() & flags
; }
180 uint32
index() const { return Index
; }
181 const CssmDlDbHandle
&dldb() const { return CssmDlDbHandle::overlay(DlDbHandle
); }
182 CSSM_DB_UNIQUE_RECORD_PTR
recordId() const { return UniqueRecord
; }
184 uint32
codes() const { return NumStatusCodes
; }
185 CSSM_RETURN
operator [] (uint32 ix
)
186 { assert(ix
< NumStatusCodes
); return StatusCodes
[ix
]; }
188 void destroy(CssmAllocator
&allocator
);
195 namespace DataWalkers
{
200 } // end namespace DataWalkers
201 } // end namespace Security
203 #endif //_H_CSSMTRUST