]> git.saurik.com Git - apple/security.git/blob - OSX/sec/Security/SecTrust.h
Security-57740.20.22.tar.gz
[apple/security.git] / OSX / sec / Security / SecTrust.h
1 /*
2 * Copyright (c) 2002-2016 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 /*!
25 @header SecTrust
26 The functions and data types in SecTrust implement trust computation
27 and allow the caller to apply trust decisions to the evaluation.
28 */
29
30 #ifndef _SECURITY_SECTRUST_H_
31 #define _SECURITY_SECTRUST_H_
32
33 #include <Security/SecBase.h>
34 #include <CoreFoundation/CoreFoundation.h>
35 #include <AvailabilityMacros.h>
36
37 __BEGIN_DECLS
38
39 CF_ASSUME_NONNULL_BEGIN
40 CF_IMPLICIT_BRIDGING_ENABLED
41
42 /*!
43 @typedef SecTrustResultType
44 @abstract Specifies the trust result type.
45 @discussion SecTrustResultType results have two dimensions. They specify
46 both whether evaluation suceeded and whether this is because of a user
47 decision. The commonly expected result is kSecTrustResultUnspecified,
48 which indicates a positive result that wasn't decided by the user. The
49 common failure is kSecTrustResultRecoverableTrustFailure, which means a
50 negative result. kSecTrustResultProceed and kSecTrustResultDeny are the
51 positive and negative result respectively when decided by the user. User
52 decisions are persisted through the use of SecTrustCopyExceptions() and
53 SecTrustSetExceptions(). Finally, kSecTrustResultFatalTrustFailure is a
54 negative result that must not be circumvented.
55 @constant kSecTrustResultInvalid Indicates an invalid setting or result.
56 This result usually means that SecTrustEvaluate has not yet been called.
57 @constant kSecTrustResultProceed Indicates you may proceed. This value
58 may be returned by the SecTrustEvaluate function or stored as part of
59 the user trust settings.
60 @constant kSecTrustResultConfirm Indicates confirmation with the user
61 is required before proceeding. Important: this value is no longer returned
62 or supported by SecTrustEvaluate or the SecTrustSettings API starting in
63 OS X 10.5; its use is deprecated in OS X 10.9 and later, as well as in iOS.
64 @constant kSecTrustResultDeny Indicates a user-configured deny; do not
65 proceed. This value may be returned by the SecTrustEvaluate function
66 or stored as part of the user trust settings.
67 @constant kSecTrustResultUnspecified Indicates the evaluation succeeded
68 and the certificate is implicitly trusted, but user intent was not
69 explicitly specified. This value may be returned by the SecTrustEvaluate
70 function or stored as part of the user trust settings.
71 @constant kSecTrustResultRecoverableTrustFailure Indicates a trust policy
72 failure which can be overridden by the user. This value may be returned
73 by the SecTrustEvaluate function but not stored as part of the user
74 trust settings.
75 @constant kSecTrustResultFatalTrustFailure Indicates a trust failure
76 which cannot be overridden by the user. This value may be returned by the
77 SecTrustEvaluate function but not stored as part of the user trust
78 settings.
79 @constant kSecTrustResultOtherError Indicates a failure other than that
80 of trust evaluation. This value may be returned by the SecTrustEvaluate
81 function but not stored as part of the user trust settings.
82 */
83 typedef CF_ENUM(uint32_t, SecTrustResultType) {
84 kSecTrustResultInvalid CF_ENUM_AVAILABLE(10_3, 2_0) = 0,
85 kSecTrustResultProceed CF_ENUM_AVAILABLE(10_3, 2_0) = 1,
86 kSecTrustResultConfirm CF_ENUM_DEPRECATED(10_3, 10_9, 2_0, 7_0) = 2,
87 kSecTrustResultDeny CF_ENUM_AVAILABLE(10_3, 2_0) = 3,
88 kSecTrustResultUnspecified CF_ENUM_AVAILABLE(10_3, 2_0) = 4,
89 kSecTrustResultRecoverableTrustFailure CF_ENUM_AVAILABLE(10_3, 2_0) = 5,
90 kSecTrustResultFatalTrustFailure CF_ENUM_AVAILABLE(10_3, 2_0) = 6,
91 kSecTrustResultOtherError CF_ENUM_AVAILABLE(10_3, 2_0) = 7
92 };
93
94 /*!
95 @typedef SecTrustRef
96 @abstract CFType used for performing X.509 certificate trust evaluations.
97 */
98 typedef struct CF_BRIDGED_TYPE(id) __SecTrust *SecTrustRef;
99
100 /*!
101 @enum Trust Property Constants
102 @discussion Predefined key constants used to obtain values in a
103 per-certificate dictionary of trust evaluation results,
104 as retrieved from a call to SecTrustCopyProperties.
105 @constant kSecPropertyTypeTitle Specifies a key whose value is a
106 CFStringRef containing the title (display name) of this certificate.
107 @constant kSecPropertyTypeError Specifies a key whose value is a
108 CFStringRef containing the reason for a trust evaluation failure.
109 */
110 extern const CFStringRef kSecPropertyTypeTitle
111 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_7_0);
112 extern const CFStringRef kSecPropertyTypeError
113 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_7_0);
114
115 /*!
116 @enum Trust Result Constants
117 @discussion Predefined key constants used to obtain values in a
118 dictionary of trust evaluation results for a certificate chain,
119 as retrieved from a call to SecTrustCopyResult.
120 @constant kSecTrustEvaluationDate
121 This key will be present if a trust evaluation has been performed
122 and results are available. Its value is a CFDateRef representing
123 when the evaluation for this trust object took place.
124 @constant kSecTrustExtendedValidation
125 This key will be present and have a value of kCFBooleanTrue
126 if this chain was validated for EV.
127 @constant kSecTrustOrganizationName
128 Organization name field of subject of leaf certificate. This
129 field is meant to be displayed to the user as the validated
130 name of the company or entity that owns the certificate if the
131 kSecTrustExtendedValidation key is present.
132 @constant kSecTrustResultValue
133 This key will be present if a trust evaluation has been performed.
134 Its value is a CFNumberRef representing the SecTrustResultType result
135 for the evaluation.
136 @constant kSecTrustRevocationChecked
137 This key will be present iff this chain had its revocation checked.
138 The value will be a kCFBooleanTrue if revocation checking was
139 successful and none of the certificates in the chain were revoked.
140 The value will be kCFBooleanFalse if no current revocation status
141 could be obtained for one or more certificates in the chain due
142 to connection problems or timeouts. This is a hint to a client
143 to retry revocation checking at a later time.
144 @constant kSecTrustRevocationValidUntilDate
145 This key will be present iff kSecTrustRevocationChecked has a
146 value of kCFBooleanTrue. The value will be a CFDateRef representing
147 the earliest date at which the revocation info for one of the
148 certificates in this chain might change.
149 @constant kSecTrustCertificateTransparency
150 This key will be present and have a value of kCFBooleanTrue
151 if this chain is CT qualified.
152 @constant kSecTrustCertificateTransparencyWhiteList
153 This key will be present and have a value of kCFBooleanTrue
154 if this chain is EV, not CT qualified, but included of the CT WhiteList.
155
156 */
157 extern const CFStringRef kSecTrustEvaluationDate
158 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
159 extern const CFStringRef kSecTrustExtendedValidation
160 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
161 extern const CFStringRef kSecTrustOrganizationName
162 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
163 extern const CFStringRef kSecTrustResultValue
164 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
165 extern const CFStringRef kSecTrustRevocationChecked
166 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
167 extern const CFStringRef kSecTrustRevocationValidUntilDate
168 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
169 extern const CFStringRef kSecTrustCertificateTransparency
170 __OSX_AVAILABLE_STARTING(__MAC_10_11, __IPHONE_9_0);
171 extern const CFStringRef kSecTrustCertificateTransparencyWhiteList
172 __OSX_AVAILABLE_STARTING(__MAC_10_12, __IPHONE_10_0);
173
174 #ifdef __BLOCKS__
175 /*!
176 @typedef SecTrustCallback
177 @abstract Delivers the result from an asynchronous trust evaluation.
178 @param trustRef A reference to the trust object which has been evaluated.
179 @param trustResult The trust result of the evaluation. Additional status
180 information can be obtained by calling SecTrustCopyProperties().
181 */
182 typedef void (^SecTrustCallback)(SecTrustRef trustRef, SecTrustResultType trustResult);
183 #endif /* __BLOCKS__ */
184
185
186 /*!
187 @function SecTrustGetTypeID
188 @abstract Returns the type identifier of SecTrust instances.
189 @result The CFTypeID of SecTrust instances.
190 */
191 CFTypeID SecTrustGetTypeID(void)
192 __OSX_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_2_0);
193
194 /*!
195 @function SecTrustCreateWithCertificates
196 @abstract Creates a trust object based on the given certificates and
197 policies.
198 @param certificates The group of certificates to verify. This can either
199 be a CFArrayRef of SecCertificateRef objects or a single SecCertificateRef
200 @param policies An array of one or more policies. You may pass a
201 SecPolicyRef to represent a single policy.
202 @param trust On return, a pointer to the trust management reference.
203 @result A result code. See "Security Error Codes" (SecBase.h).
204 @discussion If multiple policies are passed in, all policies must verify
205 for the chain to be considered valid.
206 */
207 OSStatus SecTrustCreateWithCertificates(CFTypeRef certificates,
208 CFTypeRef __nullable policies, SecTrustRef * __nonnull CF_RETURNS_RETAINED trust)
209 __OSX_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_2_0);
210
211 /*!
212 @function SecTrustSetPolicies
213 @abstract Set the policies for which trust should be verified.
214 @param trust A trust reference.
215 @param policies An array of one or more policies. You may pass a
216 SecPolicyRef to represent a single policy.
217 @result A result code. See "Security Error Codes" (SecBase.h).
218 @discussion This function will invalidate the existing trust result,
219 requiring a fresh evaluation for the newly-set policies.
220 */
221 OSStatus SecTrustSetPolicies(SecTrustRef trust, CFTypeRef policies)
222 __OSX_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_6_0);
223
224 /*!
225 @function SecTrustCopyPolicies
226 @abstract Returns an array of policies used for this evaluation.
227 @param trust A reference to a trust object.
228 @param policies On return, an array of policies used by this trust.
229 Call the CFRelease function to release this reference.
230 @result A result code. See "Security Error Codes" (SecBase.h).
231 */
232 OSStatus SecTrustCopyPolicies(SecTrustRef trust, CFArrayRef * __nonnull CF_RETURNS_RETAINED policies)
233 __OSX_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_7_0);
234
235 /*!
236 @function SecTrustSetNetworkFetchAllowed
237 @abstract Specifies whether a trust evaluation is permitted to fetch missing
238 intermediate certificates from the network.
239 @param trust A trust reference.
240 @param allowFetch If true, and a certificate's issuer is not present in the
241 trust reference but its network location is known, the evaluation is permitted
242 to attempt to download it automatically. Pass false to disable network fetch
243 for this trust evaluation.
244 @result A result code. See "Security Error Codes" (SecBase.h).
245 @discussion By default, network fetch of missing certificates is enabled if
246 the trust evaluation includes the SSL policy, otherwise it is disabled.
247 */
248 OSStatus SecTrustSetNetworkFetchAllowed(SecTrustRef trust,
249 Boolean allowFetch)
250 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
251
252 /*!
253 @function SecTrustGetNetworkFetchAllowed
254 @abstract Returns whether a trust evaluation is permitted to fetch missing
255 intermediate certificates from the network.
256 @param trust A trust reference.
257 @param allowFetch On return, the boolean pointed to by this parameter is
258 set to true if the evaluation is permitted to download missing certificates.
259 @result A result code. See "Security Error Codes" (SecBase.h).
260 @discussion By default, network fetch of missing certificates is enabled if
261 the trust evaluation includes the SSL policy, otherwise it is disabled.
262 */
263 OSStatus SecTrustGetNetworkFetchAllowed(SecTrustRef trust,
264 Boolean *allowFetch)
265 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
266
267 /*!
268 @function SecTrustSetAnchorCertificates
269 @abstract Sets the anchor certificates for a given trust.
270 @param trust A reference to a trust object.
271 @param anchorCertificates An array of anchor certificates.
272 @result A result code. See "Security Error Codes" (SecBase.h).
273 @discussion Calling this function without also calling
274 SecTrustSetAnchorCertificatesOnly() will disable trusting any
275 anchors other than the ones in anchorCertificates.
276 */
277 OSStatus SecTrustSetAnchorCertificates(SecTrustRef trust,
278 CFArrayRef anchorCertificates)
279 __OSX_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_2_0);
280
281 /*!
282 @function SecTrustSetAnchorCertificatesOnly
283 @abstract Reenables trusting anchor certificates in addition to those
284 passed in via the SecTrustSetAnchorCertificates API.
285 @param trust A reference to a trust object.
286 @param anchorCertificatesOnly If true, disables trusting any anchors other
287 than the ones passed in via SecTrustSetAnchorCertificates(). If false,
288 the built in anchor certificates are also trusted.
289 @result A result code. See "Security Error Codes" (SecBase.h).
290 */
291 OSStatus SecTrustSetAnchorCertificatesOnly(SecTrustRef trust,
292 Boolean anchorCertificatesOnly)
293 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_2_0);
294
295 /*!
296 @function SecTrustCopyCustomAnchorCertificates
297 @abstract Returns an array of custom anchor certificates used by a given
298 trust, as set by a prior call to SecTrustSetAnchorCertificates, or NULL if
299 no custom anchors have been specified.
300 @param trust A reference to a trust object.
301 @param anchors On return, an array of custom anchor certificates (roots)
302 used by this trust, or NULL if no custom anchors have been specified. Call
303 the CFRelease function to release this reference.
304 @result A result code. See "Security Error Codes" (SecBase.h).
305 */
306 OSStatus SecTrustCopyCustomAnchorCertificates(SecTrustRef trust,
307 CFArrayRef * __nonnull CF_RETURNS_RETAINED anchors)
308 __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_7_0);
309
310 /*!
311 @function SecTrustSetVerifyDate
312 @abstract Set the date for which the trust should be verified.
313 @param trust A reference to a trust object.
314 @param verifyDate The date for which to verify trust.
315 @result A result code. See "Security Error Codes" (SecBase.h).
316 @discussion This function lets you evaluate certificate validity for a
317 given date (for example, to determine if a signature was valid on the date
318 it was signed, even if the certificate has since expired.) If this function
319 is not called, the time at which SecTrustEvaluate() is called is used
320 implicitly as the verification time.
321 */
322 OSStatus SecTrustSetVerifyDate(SecTrustRef trust, CFDateRef verifyDate)
323 __OSX_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_2_0);
324
325 /*!
326 @function SecTrustGetVerifyTime
327 @abstract Returns the verify time.
328 @param trust A reference to the trust object being verified.
329 @result A CFAbsoluteTime value representing the time at which certificates
330 should be checked for validity.
331 @discussion This function retrieves the verification time for the given
332 trust reference, as set by a prior call to SecTrustSetVerifyDate(). If the
333 verification time has not been set, this function returns a value of 0,
334 indicating that the current date/time is implicitly used for verification.
335 */
336 CFAbsoluteTime SecTrustGetVerifyTime(SecTrustRef trust)
337 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_2_0);
338
339 /*!
340 @function SecTrustEvaluate
341 @abstract Evaluates a trust reference synchronously.
342 @param trust A reference to the trust object to evaluate.
343 @param result A pointer to a result type.
344 @result A result code. See "Security Error Codes" (SecBase.h).
345 @discussion This function will completely evaluate trust before returning,
346 possibly including network access to fetch intermediate certificates or to
347 perform revocation checking. Since this function can block during those
348 operations, you should call it from within a function that is placed on a
349 dispatch queue, or in a separate thread from your application's main
350 run loop. Alternatively, you can use the SecTrustEvaluateAsync function.
351 */
352 OSStatus SecTrustEvaluate(SecTrustRef trust, SecTrustResultType * __nullable result)
353 __OSX_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_2_0);
354
355 #ifdef __BLOCKS__
356 /*!
357 @function SecTrustEvaluateAsync
358 @abstract Evaluates a trust reference asynchronously.
359 @param trust A reference to the trust object to evaluate.
360 @param queue A dispatch queue on which the result callback should be
361 executed. Pass NULL to use the current dispatch queue.
362 @param result A SecTrustCallback block which will be executed when the
363 trust evaluation is complete.
364 @result A result code. See "Security Error Codes" (SecBase.h).
365 */
366 OSStatus SecTrustEvaluateAsync(SecTrustRef trust,
367 dispatch_queue_t __nullable queue, SecTrustCallback result)
368 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_7_0);
369 #endif
370
371 /*!
372 @function SecTrustGetTrustResult
373 @param trust A reference to a trust object.
374 @param result A pointer to the result from the most recent call to
375 SecTrustEvaluate for this trust reference. If SecTrustEvaluate has not been
376 called or trust parameters have changed, the result is kSecTrustResultInvalid.
377 @result A result code. See "Security Error Codes" (SecBase.h).
378 @discussion This function replaces SecTrustGetResult for the purpose of
379 obtaining the current evaluation result of a given trust reference.
380 */
381 OSStatus SecTrustGetTrustResult(SecTrustRef trust,
382 SecTrustResultType *result)
383 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_7_0);
384
385 /*!
386 @function SecTrustCopyPublicKey
387 @abstract Return the public key for a leaf certificate after it has
388 been evaluated.
389 @param trust A reference to the trust object which has been evaluated.
390 @result The certificate's public key, or NULL if it the public key could
391 not be extracted (this can happen with DSA certificate chains if the
392 parameters in the chain cannot be found). The caller is responsible
393 for calling CFRelease on the returned key when it is no longer needed.
394 */
395 __nullable
396 SecKeyRef SecTrustCopyPublicKey(SecTrustRef trust)
397 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_2_0);
398
399 /*!
400 @function SecTrustGetCertificateCount
401 @abstract Returns the number of certificates in an evaluated certificate
402 chain.
403 @param trust A reference to a trust object.
404 @result The number of certificates in the trust chain, including the anchor.
405 @discussion Important: if the trust reference has not yet been evaluated,
406 this function will evaluate it first before returning. If speed is critical,
407 you may want to call SecTrustGetTrustResult first to make sure that a
408 result other than kSecTrustResultInvalid is present for the trust object.
409 */
410 CFIndex SecTrustGetCertificateCount(SecTrustRef trust)
411 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_2_0);
412
413 /*!
414 @function SecTrustGetCertificateAtIndex
415 @abstract Returns a certificate from the trust chain.
416 @param trust Reference to a trust object.
417 @param ix The index of the requested certificate. Indices run from 0
418 (leaf) to the anchor (or last certificate found if no anchor was found).
419 The leaf cert (index 0) is always present regardless of whether the trust
420 reference has been evaluated or not.
421 @result A SecCertificateRef for the requested certificate.
422 */
423 __nullable
424 SecCertificateRef SecTrustGetCertificateAtIndex(SecTrustRef trust, CFIndex ix)
425 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_2_0);
426
427 /*!
428 @function SecTrustCopyExceptions
429 @abstract Returns an opaque cookie which will allow future evaluations
430 of the current certificate to succeed.
431 @param trust A reference to an evaluated trust object.
432 @result An opaque cookie which when passed to SecTrustSetExceptions() will
433 cause a call to SecTrustEvaluate() return kSecTrustResultProceed. This
434 will happen upon subsequent evaluation of the current certificate unless
435 some new error starts happening that wasn't being reported when the cookie
436 was returned from this function (for example, if the certificate expires
437 then evaluation will start failing again until a new cookie is obtained.)
438 @discussion Normally this API should only be called once the errors have
439 been presented to the user and the user decided to trust the current
440 certificate chain regardless of the errors being presented, for the
441 current application/server/protocol combination.
442 */
443 CFDataRef SecTrustCopyExceptions(SecTrustRef trust)
444 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_4_0);
445
446 /*!
447 @function SecTrustSetExceptions
448 @abstract Set a trust cookie to be used for evaluating this certificate chain.
449 @param trust A reference to a trust object.
450 @param exceptions An exceptions cookie as returned by a call to
451 SecTrustCopyExceptions() in the past. You may pass NULL to clear any
452 exceptions which have been previously set on this trust reference.
453 @result Upon calling SecTrustEvaluate(), any failures that were present at the
454 time the exceptions object was created are ignored, and instead of returning
455 kSecTrustResultRecoverableTrustFailure, kSecTrustResultProceed will be returned
456 (if the certificate for which exceptions was created matches the current leaf
457 certificate).
458 @result Returns true if the exceptions cookies was valid and matches the current
459 leaf certificate, false otherwise. This function will invalidate the existing
460 trust result, requiring a subsequent evaluation for the newly-set exceptions.
461 Note that this function returning true doesn't mean the caller can skip calling
462 SecTrustEvaluate, as there may be new errors since the exceptions cookie was
463 created (for example, a certificate may have subsequently expired.)
464 @discussion Clients of this interface will need to establish the context of this
465 exception to later decide when this exception cookie is to be used.
466 Examples of this context would be the server we are connecting to, the ssid
467 of the wireless network for which this cert is needed, the account for which
468 this cert should be considered valid, and so on.
469 */
470 bool SecTrustSetExceptions(SecTrustRef trust, CFDataRef __nullable exceptions)
471 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_4_0);
472
473 /*!
474 @function SecTrustCopyProperties
475 @abstract Return a property array for this trust evaluation.
476 @param trust A reference to a trust object. If the trust has not been
477 evaluated, the returned property array will be empty.
478 @result A property array. It is the caller's responsibility to CFRelease
479 the returned array when it is no longer needed.
480 @discussion This function returns an ordered array of CFDictionaryRef
481 instances for each certificate in the chain. Indices run from 0 (leaf) to
482 the anchor (or last certificate found if no anchor was found.) See the
483 "Trust Property Constants" section for a list of currently defined keys.
484 */
485 __nullable
486 CFArrayRef SecTrustCopyProperties(SecTrustRef trust)
487 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_2_0);
488
489 /*!
490 @function SecTrustCopyResult
491 @abstract Returns a dictionary containing information about the
492 evaluated certificate chain for use by clients.
493 @param trust A reference to a trust object.
494 @result A dictionary with various fields that can be displayed to the user,
495 or NULL if no additional info is available or the trust has not yet been
496 validated. The caller is responsible for calling CFRelease on the value
497 returned when it is no longer needed.
498 @discussion Returns a dictionary for the overall trust evaluation. See the
499 "Trust Result Constants" section for a list of currently defined keys.
500 */
501 __nullable
502 CFDictionaryRef SecTrustCopyResult(SecTrustRef trust)
503 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
504
505 /*!
506 @function SecTrustSetOCSPResponse
507 @abstract Attach OCSPResponse data to a trust object.
508 @param trust A reference to a trust object.
509 @param responseData This may be either a CFData object containing a single
510 DER-encoded OCSPResponse (per RFC 2560), or a CFArray of these.
511 @result A result code. See "Security Error Codes" (SecBase.h).
512 @discussion Allows the caller to provide OCSPResponse data (which may be
513 obtained during a TLS/SSL handshake, per RFC 3546) as input to a trust
514 evaluation. If this data is available, it can obviate the need to contact
515 an OCSP server for current revocation information.
516 */
517 OSStatus SecTrustSetOCSPResponse(SecTrustRef trust, CFTypeRef __nullable responseData)
518 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
519
520 CF_IMPLICIT_BRIDGING_DISABLED
521 CF_ASSUME_NONNULL_END
522
523 /*
524 * Legacy functions (OS X only)
525 */
526 #if TARGET_OS_MAC && !TARGET_OS_IPHONE
527 #include <Security/cssmtype.h>
528 #include <Security/cssmapple.h>
529
530 CF_ASSUME_NONNULL_BEGIN
531 CF_IMPLICIT_BRIDGING_ENABLED
532
533 /*!
534 @typedef SecTrustUserSetting
535 @abstract Specifies a user-specified trust setting value.
536 @discussion Deprecated in OS X 10.9. User trust settings are managed by
537 functions in SecTrustSettings.h (starting with OS X 10.5), and by the
538 SecTrustCopyExceptions and SecTrustSetExceptions functions (starting with
539 iOS 4 and OS X 10.9). The latter two functions are recommended for both OS X
540 and iOS, as they avoid the need to explicitly specify these values.
541 */
542 typedef SecTrustResultType SecTrustUserSetting
543 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2, __MAC_10_9, __IPHONE_NA, __IPHONE_NA);
544
545 /*!
546 @typedef SecTrustOptionFlags
547 @abstract Options for customizing trust evaluation.
548 @constant kSecTrustOptionAllowExpired Allow expired certificates.
549 @constant kSecTrustOptionLeafIsCA Allow CA as leaf certificate.
550 @constant kSecTrustOptionFetchIssuerFromNet Allow network fetch of CA cert.
551 @constant kSecTrustOptionAllowExpiredRoot Allow expired roots.
552 @constant kSecTrustOptionRequireRevPerCert Require positive revocation
553 check per certificate.
554 @constant kSecTrustOptionUseTrustSettings Use TrustSettings instead of
555 anchors.
556 @constant kSecTrustOptionImplicitAnchors Properly self-signed certs are
557 treated as anchors implicitly.
558 */
559 typedef CF_OPTIONS(uint32_t, SecTrustOptionFlags) {
560 kSecTrustOptionAllowExpired = 0x00000001,
561 kSecTrustOptionLeafIsCA = 0x00000002,
562 kSecTrustOptionFetchIssuerFromNet = 0x00000004,
563 kSecTrustOptionAllowExpiredRoot = 0x00000008,
564 kSecTrustOptionRequireRevPerCert = 0x00000010,
565 kSecTrustOptionUseTrustSettings = 0x00000020,
566 kSecTrustOptionImplicitAnchors = 0x00000040
567 };
568
569 /*!
570 @function SecTrustSetOptions
571 @abstract Sets optional flags for customizing a trust evaluation.
572 @param trustRef A trust reference.
573 @param options Flags to change evaluation behavior for this trust.
574 @result A result code. See "Security Error Codes" (SecBase.h).
575 @discussion This function is not available on iOS. Use SecTrustSetExceptions
576 and SecTrustCopyExceptions to modify default trust results, and
577 SecTrustSetNetworkFetchAllowed to specify whether missing CA certificates
578 can be fetched from the network.
579 */
580 OSStatus SecTrustSetOptions(SecTrustRef trustRef, SecTrustOptionFlags options)
581 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
582
583 /*!
584 @function SecTrustSetParameters
585 @abstract Sets the action and action data for a trust object.
586 @param trustRef The reference to the trust to change.
587 @param action A trust action.
588 @param actionData A reference to data associated with this action.
589 @result A result code. See "Security Error Codes" (SecBase.h).
590 @discussion This function is deprecated in OS X 10.7 and later, where it
591 was replaced by SecTrustSetOptions, and is not available on iOS. Your code
592 should use SecTrustSetExceptions and SecTrustCopyExceptions to modify default
593 trust results, and SecTrustSetNetworkFetchAllowed to specify whether missing
594 CA certificates can be fetched from the network.
595 */
596 OSStatus SecTrustSetParameters(SecTrustRef trustRef,
597 CSSM_TP_ACTION action, CFDataRef actionData)
598 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2, __MAC_10_7, __IPHONE_NA, __IPHONE_NA);
599
600 /*!
601 @function SecTrustSetKeychains
602 @abstract Sets the keychains for a given trust object.
603 @param trust A reference to a trust object.
604 @param keychainOrArray A reference to an array of keychains to search, a
605 single keychain, or NULL to use the default keychain search list.
606 @result A result code. See "Security Error Codes" (SecBase.h).
607 @discussion By default, the user's keychain search list and the system
608 anchors keychain are searched for certificates to complete the chain. You
609 can specify a zero-element array if you do not want any keychains searched.
610 Note: this function is not applicable to iOS.
611 */
612 OSStatus SecTrustSetKeychains(SecTrustRef trust, CFTypeRef __nullable keychainOrArray)
613 __OSX_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_NA);
614
615 /*!
616 @function SecTrustGetResult
617 @abstract Returns detailed information on the outcome of an evaluation.
618 @param trustRef A reference to a trust object.
619 @param result A pointer to the result from the call to SecTrustEvaluate.
620 @param certChain On return, a pointer to the certificate chain used to
621 validate the input certificate. Call the CFRelease function to release
622 this pointer.
623 @param statusChain On return, a pointer to the status of the certificate
624 chain. Do not attempt to free this pointer; it remains valid until the
625 trust is destroyed or the next call to SecTrustEvaluate.
626 @result A result code. See "Security Error Codes" (SecBase.h).
627 @discussion This function is deprecated in OS X 10.7 and later,
628 and is not available on iOS.
629 To get the complete certificate chain, use SecTrustGetCertificateCount and
630 SecTrustGetCertificateAtIndex. To get detailed status information for each
631 certificate, use SecTrustCopyProperties. To get the overall trust result
632 for the evaluation, use SecTrustGetTrustResult.
633 */
634 OSStatus SecTrustGetResult(SecTrustRef trustRef, SecTrustResultType * __nullable result,
635 CFArrayRef * __nullable CF_RETURNS_RETAINED certChain, CSSM_TP_APPLE_EVIDENCE_INFO * __nullable * __nullable statusChain)
636 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2, __MAC_10_7, __IPHONE_NA, __IPHONE_NA);
637
638 /*!
639 @function SecTrustGetCssmResult
640 @abstract Gets the CSSM trust result.
641 @param trust A reference to a trust.
642 @param result On return, a pointer to the CSSM trust result.
643 @result A result code. See "Security Error Codes" (SecBase.h).
644 @discussion This function is deprecated in OS X 10.7 and later,
645 and is not available on iOS.
646 To get detailed status information for each certificate, use
647 SecTrustCopyProperties. To get the overall trust result for the evaluation,
648 use SecTrustGetTrustResult.
649 */
650 OSStatus SecTrustGetCssmResult(SecTrustRef trust,
651 CSSM_TP_VERIFY_CONTEXT_RESULT_PTR __nullable * __nonnull result)
652 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2, __MAC_10_7, __IPHONE_NA, __IPHONE_NA);
653
654 /*!
655 @function SecTrustGetCssmResultCode
656 @abstract Gets the result code from the most recent call to SecTrustEvaluate
657 for the specified trust.
658 @param trust A reference to a trust.
659 @param resultCode On return, the result code produced by the most recent
660 evaluation of the given trust (cssmerr.h). The value of resultCode is
661 undefined if SecTrustEvaluate has not been called.
662 @result A result code. See "Security Error Codes" (SecBase.h). Returns
663 errSecTrustNotAvailable if SecTrustEvaluate has not been called for the
664 specified trust.
665 @discussion This function is deprecated in OS X 10.7 and later,
666 and is not available on iOS.
667 To get detailed status information for each certificate, use
668 SecTrustCopyProperties. To get the overall trust result for the evaluation,
669 use SecTrustGetTrustResult.
670 */
671 OSStatus SecTrustGetCssmResultCode(SecTrustRef trust, OSStatus *resultCode)
672 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2, __MAC_10_7, __IPHONE_NA, __IPHONE_NA);
673
674 /*!
675 @function SecTrustGetTPHandle
676 @abstract Gets the CSSM trust handle
677 @param trust A reference to a trust.
678 @param handle On return, a CSSM trust handle.
679 @result A result code. See "Security Error Codes" (SecBase.h).
680 @discussion This function is deprecated in OS X 10.7 and later.
681 */
682 OSStatus SecTrustGetTPHandle(SecTrustRef trust, CSSM_TP_HANDLE *handle)
683 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2, __MAC_10_7, __IPHONE_NA, __IPHONE_NA);
684
685 /*!
686 @function SecTrustCopyAnchorCertificates
687 @abstract Returns an array of default anchor (root) certificates used by
688 the system.
689 @param anchors On return, an array containing the system's default anchors
690 (roots). Call the CFRelease function to release this pointer.
691 @result A result code. See "Security Error Codes" (SecBase.h).
692 @discussion This function is not available on iOS, as certificate data
693 for system-trusted roots is currently unavailable on that platform.
694 */
695 OSStatus SecTrustCopyAnchorCertificates(CFArrayRef * __nonnull CF_RETURNS_RETAINED anchors)
696 __OSX_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_NA);
697
698 CF_IMPLICIT_BRIDGING_DISABLED
699 CF_ASSUME_NONNULL_END
700
701 #endif /* TARGET_OS_MAC && !TARGET_OS_IPHONE */
702
703 __END_DECLS
704
705 #endif /* !_SECURITY_SECTRUST_H_ */