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.
18 #include <Security/SecTrust.h>
19 #include <Security/SecTrustPriv.h>
20 #include <Security/Trust.h>
21 #include "SecBridge.h"
26 CFTypeID
SecTrustGetTypeID(void)
30 return gTypes().Trust
.typeID
;
32 END_SECAPI1(_kCFRuntimeNotATypeID
)
37 // Sec* API bridge functions
39 OSStatus
SecTrustCreateWithCertificates(
40 CFArrayRef certificates
,
42 SecTrustRef
*trustRef
)
46 *trustRef
= (new Trust(certificates
, policies
))->handle();
52 SecTrustSetPolicies(SecTrustRef trustRef
, CFTypeRef policies
)
55 Trust::required(trustRef
)->policies(policies
);
60 OSStatus
SecTrustSetParameters(
62 CSSM_TP_ACTION action
,
66 Trust
*trust
= Trust::required(trustRef
);
67 trust
->action(action
);
68 trust
->actionData(actionData
);
73 OSStatus
SecTrustSetAnchorCertificates(SecTrustRef trust
, CFArrayRef anchorCertificates
)
76 Trust::required(trust
)->anchors(anchorCertificates
);
81 OSStatus
SecTrustSetKeychains(SecTrustRef trust
, CFTypeRef keychainOrArray
)
84 StorageManager::KeychainList keychains
;
85 globals().storageManager
.optionalSearchList(keychainOrArray
, keychains
);
86 Trust::required(trust
)->searchLibs() = keychains
;
91 OSStatus
SecTrustSetVerifyDate(SecTrustRef trust
, CFDateRef verifyDate
)
94 Trust::required(trust
)->time(verifyDate
);
99 OSStatus
SecTrustEvaluate(SecTrustRef trustRef
, SecTrustResultType
*resultP
)
102 Trust
*trust
= Trust::required(trustRef
);
105 *resultP
= trust
->result();
111 // Construct the "official" result evidence and return it
113 OSStatus
SecTrustGetResult(
114 SecTrustRef trustRef
,
115 SecTrustResultType
*result
,
116 CFArrayRef
*certChain
, CSSM_TP_APPLE_EVIDENCE_INFO
**statusChain
)
119 Trust
*trust
= Trust::required(trustRef
);
121 *result
= trust
->result();
122 if (certChain
&& statusChain
)
123 trust
->buildEvidence(*certChain
, TPEvidenceInfo::overlayVar(*statusChain
));
129 // Retrieve CSSM-level information for those who want to dig down
131 OSStatus
SecTrustGetCssmResult(SecTrustRef trust
, CSSM_TP_VERIFY_CONTEXT_RESULT_PTR
*result
)
134 Required(result
) = Trust::required(trust
)->cssmResult();
139 // Retrieve CSSM_LEVEL TP return code
141 OSStatus
SecTrustGetCssmResultCode(SecTrustRef trustRef
, OSStatus
*result
)
144 Trust
*trust
= Trust::required(trustRef
);
145 if (trust
->result() == kSecTrustResultInvalid
)
148 Required(result
) = trust
->cssmResultCode();
152 OSStatus
SecTrustGetTPHandle(SecTrustRef trust
, CSSM_TP_HANDLE
*handle
)
155 Required(handle
) = Trust::required(trust
)->getTPHandle();
161 // Get the user's default anchor certificate set
163 OSStatus
SecTrustCopyAnchorCertificates(CFArrayRef
* anchorCertificates
)
166 Required(anchorCertificates
) = Trust::gStore().copyRootCertificates();
170 OSStatus
SecTrustGetCSSMAnchorCertificates(const CSSM_DATA
**cssmAnchors
,
171 uint32
*cssmAnchorCount
)
175 Trust::gStore().getCssmRootCertificates(certs
);
176 Required(cssmAnchors
) = certs
.blobCerts();
177 Required(cssmAnchorCount
) = certs
.count();
183 // Get and set user trust settings
185 OSStatus
SecTrustGetUserTrust(SecCertificateRef certificate
,
186 SecPolicyRef policy
, SecTrustUserSetting
*trustSetting
)
189 Required(trustSetting
) = Trust::gStore().find(
190 Certificate::required(certificate
),
191 Policy::required(policy
));
195 OSStatus
SecTrustSetUserTrust(SecCertificateRef certificate
,
196 SecPolicyRef policy
, SecTrustUserSetting trustSetting
)
199 switch (trustSetting
) {
200 case kSecTrustResultProceed
:
201 case kSecTrustResultConfirm
:
202 case kSecTrustResultDeny
:
203 case kSecTrustResultUnspecified
:
206 MacOSError::throwMe(errSecInvalidTrustSetting
);
208 Trust::gStore().assign(
209 Certificate::required(certificate
),
210 Policy::required(policy
),