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/Trust.h>
21 #include "SecBridge.h"
24 static inline Trust
*Required(SecTrustRef trustRef
)
26 return gTypes().trust
.required(trustRef
);
33 CFTypeID
SecTrustGetTypeID(void)
37 return gTypes().trust
.typeId
;
39 END_SECAPI1(_kCFRuntimeNotATypeID
)
44 // Sec* API bridge functions
46 OSStatus
SecTrustCreateWithCertificates(
47 CFArrayRef certificates
,
49 SecTrustRef
*trustRef
)
52 Required(trustRef
); // preflight
53 RefPointer
<Trust
> trust(new Trust(certificates
, policies
));
54 *trustRef
= gTypes().trust
.handle(*trust
);
59 OSStatus
SecTrustSetParameters(
61 CSSM_TP_ACTION action
,
65 Trust
*trust
= gTypes().trust
.required(trustRef
);
66 trust
->action(action
);
67 trust
->actionData(actionData
);
72 OSStatus
SecTrustSetAnchorCertificates(SecTrustRef trust
, CFArrayRef anchorCertificates
)
75 Required(trust
)->anchors(anchorCertificates
);
80 OSStatus
SecTrustSetKeychains(SecTrustRef trust
, CFTypeRef keychainOrArray
)
83 StorageManager::KeychainList keychains
;
84 globals().storageManager
.optionalSearchList(keychainOrArray
, keychains
);
85 Required(trust
)->searchLibs() = keychains
;
90 OSStatus
SecTrustSetVerifyDate(SecTrustRef trust
, CFDateRef verifyDate
)
93 Required(trust
)->time(verifyDate
);
98 OSStatus
SecTrustEvaluate(SecTrustRef trustRef
, SecTrustResultType
*resultP
)
101 Trust
*trust
= Required(trustRef
);
104 *resultP
= trust
->result();
110 // Construct the "official" result evidence and return it
112 OSStatus
SecTrustGetResult(
113 SecTrustRef trustRef
,
114 SecTrustResultType
*result
,
115 CFArrayRef
*certChain
, CSSM_TP_APPLE_EVIDENCE_INFO
**statusChain
)
118 Trust
*trust
= Required(trustRef
);
120 *result
= trust
->result();
121 if (certChain
&& statusChain
)
122 trust
->buildEvidence(*certChain
, TPEvidenceInfo::overlayVar(*statusChain
));
128 // Retrieve CSSM-level information for those who want to dig down
130 OSStatus
SecTrustGetCssmResult(SecTrustRef trust
, CSSM_TP_VERIFY_CONTEXT_RESULT_PTR
*result
)
133 Required(result
) = Required(trust
)->cssmResult();
137 OSStatus
SecTrustGetTPHandle(SecTrustRef trust
, CSSM_TP_HANDLE
*handle
)
140 Required(handle
) = Required(trust
)->getTPHandle();
146 // Get the user's default anchor certificate set
148 OSStatus
SecTrustCopyAnchorCertificates(CFArrayRef
* anchorCertificates
)
151 Required(anchorCertificates
) = Trust::gStore().copyRootCertificates();
155 OSStatus
SecTrustGetCSSMAnchorCertificates(const CSSM_DATA
**cssmAnchors
,
156 uint32
*cssmAnchorCount
)
160 Trust::gStore().getCssmRootCertificates(certs
);
161 Required(cssmAnchors
) = certs
.blobCerts();
162 Required(cssmAnchorCount
) = certs
.count();
168 // Get and set user trust settings
170 OSStatus
SecTrustGetUserTrust(SecCertificateRef certificate
,
171 SecPolicyRef policy
, SecTrustUserSetting
*trustSetting
)
174 Required(trustSetting
) = Trust::gStore().find(
175 gTypes().certificate
.required(certificate
),
176 gTypes().policy
.required(policy
));
180 OSStatus
SecTrustSetUserTrust(SecCertificateRef certificate
,
181 SecPolicyRef policy
, SecTrustUserSetting trustSetting
)
184 switch (trustSetting
) {
185 case kSecTrustResultProceed
:
186 case kSecTrustResultConfirm
:
187 case kSecTrustResultDeny
:
188 case kSecTrustResultUnspecified
:
191 MacOSError::throwMe(errSecInvalidTrustSetting
);
193 Trust::gStore().assign(
194 gTypes().certificate
.required(certificate
),
195 gTypes().policy
.required(policy
),