]> git.saurik.com Git - apple/security.git/blob - trust/SecTrust.h
Security-59306.11.20.tar.gz
[apple/security.git] / trust / 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 #include <Availability.h>
37
38 __BEGIN_DECLS
39
40 CF_ASSUME_NONNULL_BEGIN
41 CF_IMPLICIT_BRIDGING_ENABLED
42
43 /*!
44 @typedef SecTrustResultType
45 @abstract Specifies the trust result type.
46 @discussion SecTrustResultType results have two dimensions. They specify
47 both whether evaluation succeeded and whether this is because of a user
48 decision. The commonly expected result is kSecTrustResultUnspecified,
49 which indicates a positive result that wasn't decided by the user. The
50 common failure is kSecTrustResultRecoverableTrustFailure, which means a
51 negative result. kSecTrustResultProceed and kSecTrustResultDeny are the
52 positive and negative result respectively when decided by the user. User
53 decisions are persisted through the use of SecTrustCopyExceptions() and
54 SecTrustSetExceptions(). Finally, kSecTrustResultFatalTrustFailure is a
55 negative result that must not be circumvented.
56 @constant kSecTrustResultInvalid Indicates an invalid setting or result.
57 This result usually means that SecTrustEvaluate has not yet been called.
58 @constant kSecTrustResultProceed Indicates you may proceed. This value
59 may be returned by the SecTrustEvaluate function or stored as part of
60 the user trust settings.
61 @constant kSecTrustResultConfirm Indicates confirmation with the user
62 is required before proceeding. Important: this value is no longer returned
63 or supported by SecTrustEvaluate or the SecTrustSettings API starting in
64 OS X 10.5; its use is deprecated in OS X 10.9 and later, as well as in iOS.
65 @constant kSecTrustResultDeny Indicates a user-configured deny; do not
66 proceed. This value may be returned by the SecTrustEvaluate function
67 or stored as part of the user trust settings.
68 @constant kSecTrustResultUnspecified Indicates the evaluation succeeded
69 and the certificate is implicitly trusted, but user intent was not
70 explicitly specified. This value may be returned by the SecTrustEvaluate
71 function or stored as part of the user trust settings.
72 @constant kSecTrustResultRecoverableTrustFailure Indicates a trust policy
73 failure which can be overridden by the user. This value may be returned
74 by the SecTrustEvaluate function but not stored as part of the user
75 trust settings.
76 @constant kSecTrustResultFatalTrustFailure Indicates a trust failure
77 which cannot be overridden by the user. This value may be returned by the
78 SecTrustEvaluate function but not stored as part of the user trust
79 settings.
80 @constant kSecTrustResultOtherError Indicates a failure other than that
81 of trust evaluation. This value may be returned by the SecTrustEvaluate
82 function but not stored as part of the user trust settings.
83 */
84 typedef CF_ENUM(uint32_t, SecTrustResultType) {
85 kSecTrustResultInvalid CF_ENUM_AVAILABLE(10_3, 2_0) = 0,
86 kSecTrustResultProceed CF_ENUM_AVAILABLE(10_3, 2_0) = 1,
87 kSecTrustResultConfirm CF_ENUM_DEPRECATED(10_3, 10_9, 2_0, 7_0) = 2,
88 kSecTrustResultDeny CF_ENUM_AVAILABLE(10_3, 2_0) = 3,
89 kSecTrustResultUnspecified CF_ENUM_AVAILABLE(10_3, 2_0) = 4,
90 kSecTrustResultRecoverableTrustFailure CF_ENUM_AVAILABLE(10_3, 2_0) = 5,
91 kSecTrustResultFatalTrustFailure CF_ENUM_AVAILABLE(10_3, 2_0) = 6,
92 kSecTrustResultOtherError CF_ENUM_AVAILABLE(10_3, 2_0) = 7
93 };
94
95 /*!
96 @typedef SecTrustRef
97 @abstract CFType used for performing X.509 certificate trust evaluations.
98 */
99 typedef struct CF_BRIDGED_TYPE(id) __SecTrust *SecTrustRef;
100
101 /*!
102 @enum Trust Property Constants
103 @discussion Predefined key constants used to obtain values in a
104 per-certificate dictionary of trust evaluation results,
105 as retrieved from a call to SecTrustCopyProperties.
106 @constant kSecPropertyTypeTitle Specifies a key whose value is a
107 CFStringRef containing the title (display name) of this certificate.
108 @constant kSecPropertyTypeError Specifies a key whose value is a
109 CFStringRef containing the reason for a trust evaluation failure.
110 */
111 extern const CFStringRef kSecPropertyTypeTitle
112 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_7_0);
113 extern const CFStringRef kSecPropertyTypeError
114 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_7_0);
115
116 /*!
117 @enum Trust Result Constants
118 @discussion Predefined key constants used to obtain values in a
119 dictionary of trust evaluation results for a certificate chain,
120 as retrieved from a call to SecTrustCopyResult.
121 @constant kSecTrustEvaluationDate
122 This key will be present if a trust evaluation has been performed
123 and results are available. Its value is a CFDateRef representing
124 when the evaluation for this trust object took place.
125 @constant kSecTrustExtendedValidation
126 This key will be present and have a value of kCFBooleanTrue
127 if this chain was validated for EV.
128 @constant kSecTrustOrganizationName
129 Organization name field of subject of leaf certificate. This
130 field is meant to be displayed to the user as the validated
131 name of the company or entity that owns the certificate if the
132 kSecTrustExtendedValidation key is present.
133 @constant kSecTrustResultValue
134 This key will be present if a trust evaluation has been performed.
135 Its value is a CFNumberRef representing the SecTrustResultType result
136 for the evaluation.
137 @constant kSecTrustRevocationChecked
138 This key will be present iff this chain had its revocation checked.
139 The value will be a kCFBooleanTrue if revocation checking was
140 successful and none of the certificates in the chain were revoked.
141 The value will be kCFBooleanFalse if no current revocation status
142 could be obtained for one or more certificates in the chain due
143 to connection problems or timeouts. This is a hint to a client
144 to retry revocation checking at a later time.
145 @constant kSecTrustRevocationValidUntilDate
146 This key will be present iff kSecTrustRevocationChecked has a
147 value of kCFBooleanTrue. The value will be a CFDateRef representing
148 the earliest date at which the revocation info for one of the
149 certificates in this chain might change.
150 @constant kSecTrustCertificateTransparency
151 This key will be present and have a value of kCFBooleanTrue
152 if this chain is CT qualified.
153 @constant kSecTrustCertificateTransparencyWhiteList
154 This key will be present and have a value of kCFBooleanTrue
155 if this chain is EV, not CT qualified, but included of the CT WhiteList.
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_BUT_DEPRECATED(__MAC_10_12, __MAC_10_13, __IPHONE_10_0, __IPHONE_11_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 Pass NULL to restore the default set of anchor certificates.
273 @result A result code. See "Security Error Codes" (SecBase.h).
274 @discussion Calling this function without also calling
275 SecTrustSetAnchorCertificatesOnly() will disable trusting any
276 anchors other than the ones in anchorCertificates.
277 */
278 OSStatus SecTrustSetAnchorCertificates(SecTrustRef trust,
279 CFArrayRef __nullable anchorCertificates)
280 __OSX_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_2_0);
281
282 /*!
283 @function SecTrustSetAnchorCertificatesOnly
284 @abstract Reenables trusting anchor certificates in addition to those
285 passed in via the SecTrustSetAnchorCertificates API.
286 @param trust A reference to a trust object.
287 @param anchorCertificatesOnly If true, disables trusting any anchors other
288 than the ones passed in via SecTrustSetAnchorCertificates(). If false,
289 the built in anchor certificates are also trusted.
290 @result A result code. See "Security Error Codes" (SecBase.h).
291 */
292 OSStatus SecTrustSetAnchorCertificatesOnly(SecTrustRef trust,
293 Boolean anchorCertificatesOnly)
294 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_2_0);
295
296 /*!
297 @function SecTrustCopyCustomAnchorCertificates
298 @abstract Returns an array of custom anchor certificates used by a given
299 trust, as set by a prior call to SecTrustSetAnchorCertificates, or NULL if
300 no custom anchors have been specified.
301 @param trust A reference to a trust object.
302 @param anchors On return, an array of custom anchor certificates (roots)
303 used by this trust, or NULL if no custom anchors have been specified. Call
304 the CFRelease function to release this reference.
305 @result A result code. See "Security Error Codes" (SecBase.h).
306 */
307 OSStatus SecTrustCopyCustomAnchorCertificates(SecTrustRef trust,
308 CFArrayRef * __nonnull CF_RETURNS_RETAINED anchors)
309 __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_7_0);
310
311 /*!
312 @function SecTrustSetVerifyDate
313 @abstract Set the date for which the trust should be verified.
314 @param trust A reference to a trust object.
315 @param verifyDate The date for which to verify trust.
316 @result A result code. See "Security Error Codes" (SecBase.h).
317 @discussion This function lets you evaluate certificate validity for a
318 given date (for example, to determine if a signature was valid on the date
319 it was signed, even if the certificate has since expired.) If this function
320 is not called, the time at which SecTrustEvaluate() is called is used
321 implicitly as the verification time.
322 */
323 OSStatus SecTrustSetVerifyDate(SecTrustRef trust, CFDateRef verifyDate)
324 __OSX_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_2_0);
325
326 /*!
327 @function SecTrustGetVerifyTime
328 @abstract Returns the verify time.
329 @param trust A reference to the trust object being verified.
330 @result A CFAbsoluteTime value representing the time at which certificates
331 should be checked for validity.
332 @discussion This function retrieves the verification time for the given
333 trust reference, as set by a prior call to SecTrustSetVerifyDate(). If the
334 verification time has not been set, this function returns a value of 0,
335 indicating that the current date/time is implicitly used for verification.
336 */
337 CFAbsoluteTime SecTrustGetVerifyTime(SecTrustRef trust)
338 __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_2_0);
339
340 /*!
341 @function SecTrustEvaluate
342 @abstract Evaluates a trust reference synchronously.
343 @param trust A reference to the trust object to evaluate.
344 @param result A pointer to a result type.
345 @result A result code. See "Security Error Codes" (SecBase.h).
346 @discussion This function will completely evaluate trust before returning,
347 possibly including network access to fetch intermediate certificates or to
348 perform revocation checking. Since this function can block during those
349 operations, you should call it from within a function that is placed on a
350 dispatch queue, or in a separate thread from your application's main
351 run loop. Alternatively, you can use the SecTrustEvaluateAsync function.
352 */
353 OSStatus SecTrustEvaluate(SecTrustRef trust, SecTrustResultType *result)
354 API_DEPRECATED_WITH_REPLACEMENT("SecTrustEvaluateWithError",
355 macos(10.3, 10.15),
356 ios(2.0, 13.0),
357 watchos(1.0, 6.0),
358 tvos(2.0, 13.0));
359
360 #ifdef __BLOCKS__
361 /*!
362 @function SecTrustEvaluateAsync
363 @abstract Evaluates a trust reference asynchronously.
364 @param trust A reference to the trust object to evaluate.
365 @param queue A dispatch queue on which the result callback should be
366 executed. Pass NULL to use the current dispatch queue.
367 @param result A SecTrustCallback block which will be executed when the
368 trust evaluation is complete.
369 @result A result code. See "Security Error Codes" (SecBase.h).
370 */
371 OSStatus SecTrustEvaluateAsync(SecTrustRef trust,
372 dispatch_queue_t __nullable queue, SecTrustCallback result)
373 API_DEPRECATED_WITH_REPLACEMENT("SecTrustEvaluateAsyncWithError",
374 macos(10.7, 10.15),
375 ios(7.0, 13.0),
376 watchos(1.0, 6.0),
377 tvos(7.0, 13.0));
378 #endif
379
380 /*!
381 @function SecTrustEvaluateWithError
382 @abstract Evaluates a trust reference synchronously.
383 @param trust A reference to the trust object to evaluate.
384 @param error A pointer to an error object
385 @result A boolean value indicating whether the certificate is trusted
386 @discussion This function will completely evaluate trust before returning,
387 possibly including network access to fetch intermediate certificates or to
388 perform revocation checking. Since this function can block during those
389 operations, you should call it from within a function that is placed on a
390 dispatch queue, or in a separate thread from your application's main
391 run loop.
392 If the certificate is trusted and the result is true, the error will be set to NULL.
393 If the certificate is not trusted or the evaluation was unable to complete, the result
394 will be false and the error will be set with a description of the failure.
395 The error contains a code for the most serious error encountered (if multiple trust
396 failures occurred). The localized description indicates the certificate with the most
397 serious problem and the type of error. The underlying error contains a localized
398 description of each certificate in the chain that had an error and all errors found
399 with that certificate.
400 */
401 __attribute__((warn_unused_result)) bool
402 SecTrustEvaluateWithError(SecTrustRef trust, CFErrorRef _Nullable * _Nullable CF_RETURNS_RETAINED error)
403 API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0));
404
405 #ifdef __BLOCKS__
406 /*!
407 @typedef SecTrustWithErrorCallback
408 @abstract Delivers the result from an asynchronous trust evaluation.
409 @param trustRef A reference to the trust object which has been evaluated.
410 @param result A boolean value indicating whether the certificate is trusted.
411 @param error An error if the trust evaluation failed.
412 */
413 typedef void (^SecTrustWithErrorCallback)(SecTrustRef trustRef, bool result, CFErrorRef _Nullable error);
414
415 /*!
416 @function SecTrustEvaluateAsyncWithError
417 @abstract Evaluates a trust reference asynchronously.
418 @param trust A reference to the trust object to evaluate.
419 @param queue A dispatch queue on which the result callback will be executed. Note that this
420 function MUST be called from that queue.
421 @param result A SecTrustWithErrorCallback block which will be executed when the trust evaluation
422 is complete.
423 The block is guaranteed to be called exactly once when the result code is errSecSuccess, and not
424 called otherwise. Note that this block may be called synchronously inline if no asynchronous
425 operations are required.
426 @result A result code. See "Security Error Codes" (SecBase.h).
427 @discussion If the certificate is trusted, the callback will return a result parameter of true
428 and the error will be set to NULL.
429 If the certificate is not trusted or the evaluation was unable to complete, the result parameter
430 will be false and the error will be set with a description of the failure. The error contains a
431 code for the most serious error encountered (if multiple trust failures occurred). The localized
432 description indicates the certificate with the most serious problem and the type of error. The
433 underlying error contains a localized description of each certificate in the chain that had an
434 error and all errors found with that certificate.
435 */
436 OSStatus SecTrustEvaluateAsyncWithError(SecTrustRef trust, dispatch_queue_t queue, SecTrustWithErrorCallback result)
437 API_AVAILABLE(macos(10.15), ios(13.0), tvos(13.0), watchos(6.0));
438 #endif /* __BLOCKS__ */
439
440 /*!
441 @function SecTrustGetTrustResult
442 @param trust A reference to a trust object.
443 @param result A pointer to the result from the most recent call to
444 SecTrustEvaluate for this trust reference. If SecTrustEvaluate has not been
445 called or trust parameters have changed, the result is kSecTrustResultInvalid.
446 @result A result code. See "Security Error Codes" (SecBase.h).
447 @discussion This function replaces SecTrustGetResult for the purpose of
448 obtaining the current evaluation result of a given trust reference.
449 */
450 OSStatus SecTrustGetTrustResult(SecTrustRef trust,
451 SecTrustResultType *result)
452 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_7_0);
453
454 /*!
455 @function SecTrustCopyPublicKey
456 @abstract Return the public key for a leaf certificate after it has
457 been evaluated.
458 @param trust A reference to the trust object which has been evaluated.
459 @result The certificate's public key, or NULL if it the public key could
460 not be extracted (this can happen if the public key algorithm is not
461 supported). The caller is responsible for calling CFRelease on the
462 returned key when it is no longer needed.
463 */
464 __nullable
465 SecKeyRef SecTrustCopyPublicKey(SecTrustRef trust)
466 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_2_0);
467
468 /*!
469 @function SecTrustGetCertificateCount
470 @abstract Returns the number of certificates in an evaluated certificate
471 chain.
472 @param trust A reference to a trust object.
473 @result The number of certificates in the trust chain, including the anchor.
474 @discussion Important: if the trust reference has not yet been evaluated,
475 this function will evaluate it first before returning. If speed is critical,
476 you may want to call SecTrustGetTrustResult first to make sure that a
477 result other than kSecTrustResultInvalid is present for the trust object.
478 */
479 CFIndex SecTrustGetCertificateCount(SecTrustRef trust)
480 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_2_0);
481
482 /*!
483 @function SecTrustGetCertificateAtIndex
484 @abstract Returns a certificate from the trust chain.
485 @param trust Reference to a trust object.
486 @param ix The index of the requested certificate. Indices run from 0
487 (leaf) to the anchor (or last certificate found if no anchor was found).
488 The leaf cert (index 0) is always present regardless of whether the trust
489 reference has been evaluated or not.
490 @result A SecCertificateRef for the requested certificate.
491 */
492 __nullable
493 SecCertificateRef SecTrustGetCertificateAtIndex(SecTrustRef trust, CFIndex ix)
494 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_2_0);
495
496 /*!
497 @function SecTrustCopyExceptions
498 @abstract Returns an opaque cookie which will allow future evaluations
499 of the current certificate to succeed.
500 @param trust A reference to an evaluated trust object.
501 @result An opaque cookie which when passed to SecTrustSetExceptions() will
502 cause a call to SecTrustEvaluate() return kSecTrustResultProceed. This
503 will happen upon subsequent evaluation of the current certificate unless
504 some new error starts happening that wasn't being reported when the cookie
505 was returned from this function (for example, if the certificate expires
506 then evaluation will start failing again until a new cookie is obtained.)
507 @discussion Normally this API should only be called once the errors have
508 been presented to the user and the user decided to trust the current
509 certificate chain regardless of the errors being presented, for the
510 current application/server/protocol combination.
511 */
512 CFDataRef SecTrustCopyExceptions(SecTrustRef trust)
513 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_4_0);
514
515 /*!
516 @function SecTrustSetExceptions
517 @abstract Set a trust cookie to be used for evaluating this certificate chain.
518 @param trust A reference to a trust object.
519 @param exceptions An exceptions cookie as returned by a call to
520 SecTrustCopyExceptions() in the past. You may pass NULL to clear any
521 exceptions which have been previously set on this trust reference.
522 @result Upon calling SecTrustEvaluate(), any failures that were present at the
523 time the exceptions object was created are ignored, and instead of returning
524 kSecTrustResultRecoverableTrustFailure, kSecTrustResultProceed will be returned
525 (if the certificate for which exceptions was created matches the current leaf
526 certificate).
527 @result Returns true if the exceptions cookies was valid and matches the current
528 leaf certificate, false otherwise. This function will invalidate the existing
529 trust result, requiring a subsequent evaluation for the newly-set exceptions.
530 Note that this function returning true doesn't mean the caller can skip calling
531 SecTrustEvaluate, as there may be new errors since the exceptions cookie was
532 created (for example, a certificate may have subsequently expired.)
533 @discussion Clients of this interface will need to establish the context of this
534 exception to later decide when this exception cookie is to be used.
535 Examples of this context would be the server we are connecting to, the ssid
536 of the wireless network for which this cert is needed, the account for which
537 this cert should be considered valid, and so on.
538 */
539 bool SecTrustSetExceptions(SecTrustRef trust, CFDataRef __nullable exceptions)
540 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_4_0);
541
542 /*!
543 @function SecTrustCopyProperties
544 @abstract Return a property array for this trust evaluation.
545 @param trust A reference to a trust object. If the trust has not been
546 evaluated, the returned property array will be empty.
547 @result A property array. It is the caller's responsibility to CFRelease
548 the returned array when it is no longer needed.
549 @discussion This function returns an ordered array of CFDictionaryRef
550 instances for each certificate in the chain. Indices run from 0 (leaf) to
551 the anchor (or last certificate found if no anchor was found.) See the
552 "Trust Property Constants" section for a list of currently defined keys.
553 */
554 __nullable
555 CFArrayRef SecTrustCopyProperties(SecTrustRef trust)
556 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_2_0);
557
558 /*!
559 @function SecTrustCopyResult
560 @abstract Returns a dictionary containing information about the
561 evaluated certificate chain for use by clients.
562 @param trust A reference to a trust object.
563 @result A dictionary with various fields that can be displayed to the user,
564 or NULL if no additional info is available or the trust has not yet been
565 validated. The caller is responsible for calling CFRelease on the value
566 returned when it is no longer needed.
567 @discussion Returns a dictionary for the overall trust evaluation. See the
568 "Trust Result Constants" section for a list of currently defined keys.
569 */
570 __nullable
571 CFDictionaryRef SecTrustCopyResult(SecTrustRef trust)
572 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
573
574 /*!
575 @function SecTrustSetOCSPResponse
576 @abstract Attach OCSPResponse data to a trust object.
577 @param trust A reference to a trust object.
578 @param responseData This may be either a CFData object containing a single
579 DER-encoded OCSPResponse (per RFC 2560), or a CFArray of these.
580 @result A result code. See "Security Error Codes" (SecBase.h).
581 @discussion Allows the caller to provide OCSPResponse data (which may be
582 obtained during a TLS/SSL handshake, per RFC 3546) as input to a trust
583 evaluation. If this data is available, it can obviate the need to contact
584 an OCSP server for current revocation information.
585 */
586 OSStatus SecTrustSetOCSPResponse(SecTrustRef trust, CFTypeRef __nullable responseData)
587 __OSX_AVAILABLE_STARTING(__MAC_10_9, __IPHONE_7_0);
588
589 /*!
590 @function SecTrustSignedCertificateTimestamps
591 @abstract Attach SignedCertificateTimestamp data to a trust object.
592 @param trust A reference to a trust object.
593 @param sctArray is a CFArray of CFData objects each containing a SCT (per RFC 6962).
594 @result A result code. See "Security Error Codes" (SecBase.h).
595 @discussion Allows the caller to provide SCT data (which may be
596 obtained during a TLS/SSL handshake, per RFC 6962) as input to a trust
597 evaluation.
598 */
599 OSStatus SecTrustSetSignedCertificateTimestamps(SecTrustRef trust, CFArrayRef __nullable sctArray)
600 API_AVAILABLE(macos(10.14.2), ios(12.1.1), tvos(12.1.1), watchos(5.1.1));
601
602 CF_IMPLICIT_BRIDGING_DISABLED
603 CF_ASSUME_NONNULL_END
604
605 /*
606 * Legacy functions (OS X only)
607 */
608 #if TARGET_OS_OSX
609 #include <Security/cssmtype.h>
610 #include <Security/cssmapple.h>
611
612 CF_ASSUME_NONNULL_BEGIN
613 CF_IMPLICIT_BRIDGING_ENABLED
614
615 /*!
616 @typedef SecTrustUserSetting
617 @abstract Specifies a user-specified trust setting value.
618 @discussion Deprecated in OS X 10.9. User trust settings are managed by
619 functions in SecTrustSettings.h (starting with OS X 10.5), and by the
620 SecTrustCopyExceptions and SecTrustSetExceptions functions (starting with
621 iOS 4 and OS X 10.9). The latter two functions are recommended for both OS X
622 and iOS, as they avoid the need to explicitly specify these values.
623 */
624 typedef SecTrustResultType SecTrustUserSetting
625 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2, __MAC_10_9, __IPHONE_NA, __IPHONE_NA);
626
627 /*!
628 @typedef SecTrustOptionFlags
629 @abstract Options for customizing trust evaluation.
630 @constant kSecTrustOptionAllowExpired Allow expired certificates.
631 @constant kSecTrustOptionLeafIsCA Allow CA as leaf certificate.
632 @constant kSecTrustOptionFetchIssuerFromNet Allow network fetch of CA cert.
633 @constant kSecTrustOptionAllowExpiredRoot Allow expired roots.
634 @constant kSecTrustOptionRequireRevPerCert Require positive revocation
635 check per certificate.
636 @constant kSecTrustOptionUseTrustSettings Use TrustSettings instead of
637 anchors.
638 @constant kSecTrustOptionImplicitAnchors Properly self-signed certs are
639 treated as anchors implicitly.
640 */
641 typedef CF_OPTIONS(uint32_t, SecTrustOptionFlags) {
642 kSecTrustOptionAllowExpired = 0x00000001,
643 kSecTrustOptionLeafIsCA = 0x00000002,
644 kSecTrustOptionFetchIssuerFromNet = 0x00000004,
645 kSecTrustOptionAllowExpiredRoot = 0x00000008,
646 kSecTrustOptionRequireRevPerCert = 0x00000010,
647 kSecTrustOptionUseTrustSettings = 0x00000020,
648 kSecTrustOptionImplicitAnchors = 0x00000040
649 };
650
651 /*!
652 @function SecTrustSetOptions
653 @abstract Sets optional flags for customizing a trust evaluation.
654 @param trustRef A trust reference.
655 @param options Flags to change evaluation behavior for this trust.
656 @result A result code. See "Security Error Codes" (SecBase.h).
657 @discussion This function is not available on iOS. Use SecTrustSetExceptions
658 and SecTrustCopyExceptions to modify default trust results, and
659 SecTrustSetNetworkFetchAllowed to specify whether missing CA certificates
660 can be fetched from the network.
661 */
662 OSStatus SecTrustSetOptions(SecTrustRef trustRef, SecTrustOptionFlags options)
663 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);
664
665 /*!
666 @function SecTrustSetParameters
667 @abstract Sets the action and action data for a trust object.
668 @param trustRef The reference to the trust to change.
669 @param action A trust action.
670 @param actionData A reference to data associated with this action.
671 @result A result code. See "Security Error Codes" (SecBase.h).
672 @discussion This function is deprecated in OS X 10.7 and later, where it
673 was replaced by SecTrustSetOptions, and is not available on iOS. Your code
674 should use SecTrustSetExceptions and SecTrustCopyExceptions to modify default
675 trust results, and SecTrustSetNetworkFetchAllowed to specify whether missing
676 CA certificates can be fetched from the network.
677 */
678 OSStatus SecTrustSetParameters(SecTrustRef trustRef,
679 CSSM_TP_ACTION action, CFDataRef actionData)
680 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2, __MAC_10_7, __IPHONE_NA, __IPHONE_NA);
681
682 /*!
683 @function SecTrustSetKeychains
684 @abstract Sets the keychains for a given trust object.
685 @param trust A reference to a trust object.
686 @param keychainOrArray A reference to an array of keychains to search, a
687 single keychain, or NULL to use the default keychain search list.
688 @result A result code. See "Security Error Codes" (SecBase.h).
689 @discussion This function is deprecated in macOS 10.13 and later. Beginning in
690 macOS 10.12, this function no longer affected the behavior of the trust
691 evaluation: the user's keychain search list and the system
692 anchors keychain are searched for certificates to complete the chain. To change
693 the keychains that are searched, callers must use SecKeychainSetSearchList to
694 change the user's keychain search list.
695 Note: this function was never applicable to iOS.
696 */
697 OSStatus SecTrustSetKeychains(SecTrustRef trust, CFTypeRef __nullable keychainOrArray)
698 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_3, __MAC_10_13, __IPHONE_NA, __IPHONE_NA);
699
700 /*!
701 @function SecTrustGetResult
702 @abstract Returns detailed information on the outcome of an evaluation.
703 @param trustRef A reference to a trust object.
704 @param result A pointer to the result from the call to SecTrustEvaluate.
705 @param certChain On return, a pointer to the certificate chain used to
706 validate the input certificate. Call the CFRelease function to release
707 this pointer.
708 @param statusChain On return, a pointer to the status of the certificate
709 chain. Do not attempt to free this pointer; it remains valid until the
710 trust is destroyed or the next call to SecTrustEvaluate.
711 @result A result code. See "Security Error Codes" (SecBase.h).
712 @discussion This function is deprecated in OS X 10.7 and later,
713 and is not available on iOS.
714 To get the complete certificate chain, use SecTrustGetCertificateCount and
715 SecTrustGetCertificateAtIndex. To get detailed status information for each
716 certificate, use SecTrustCopyProperties. To get the overall trust result
717 for the evaluation, use SecTrustGetTrustResult.
718 */
719 OSStatus SecTrustGetResult(SecTrustRef trustRef, SecTrustResultType * __nullable result,
720 CFArrayRef * __nullable CF_RETURNS_RETAINED certChain, CSSM_TP_APPLE_EVIDENCE_INFO * __nullable * __nullable statusChain)
721 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2, __MAC_10_7, __IPHONE_NA, __IPHONE_NA);
722
723 /*!
724 @function SecTrustGetCssmResult
725 @abstract Gets the CSSM trust result.
726 @param trust A reference to a trust.
727 @param result On return, a pointer to the CSSM trust result.
728 @result A result code. See "Security Error Codes" (SecBase.h).
729 @discussion This function is deprecated in OS X 10.7 and later,
730 and is not available on iOS.
731 To get detailed status information for each certificate, use
732 SecTrustCopyProperties. To get the overall trust result for the evaluation,
733 use SecTrustGetTrustResult.
734 */
735 OSStatus SecTrustGetCssmResult(SecTrustRef trust,
736 CSSM_TP_VERIFY_CONTEXT_RESULT_PTR __nullable * __nonnull result)
737 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2, __MAC_10_7, __IPHONE_NA, __IPHONE_NA);
738
739 /*!
740 @function SecTrustGetCssmResultCode
741 @abstract Gets the result code from the most recent call to SecTrustEvaluate
742 for the specified trust.
743 @param trust A reference to a trust.
744 @param resultCode On return, the result code produced by the most recent
745 evaluation of the given trust (cssmerr.h). The value of resultCode is
746 undefined if SecTrustEvaluate has not been called.
747 @result A result code. See "Security Error Codes" (SecBase.h). Returns
748 errSecTrustNotAvailable if SecTrustEvaluate has not been called for the
749 specified trust.
750 @discussion This function is deprecated in OS X 10.7 and later,
751 and is not available on iOS.
752 To get detailed status information for each certificate, use
753 SecTrustCopyProperties. To get the overall trust result for the evaluation,
754 use SecTrustGetTrustResult.
755 */
756 OSStatus SecTrustGetCssmResultCode(SecTrustRef trust, OSStatus *resultCode)
757 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2, __MAC_10_7, __IPHONE_NA, __IPHONE_NA);
758
759 /*!
760 @function SecTrustGetTPHandle
761 @abstract Gets the CSSM trust handle
762 @param trust A reference to a trust.
763 @param handle On return, a CSSM trust handle.
764 @result A result code. See "Security Error Codes" (SecBase.h).
765 @discussion This function is deprecated in OS X 10.7 and later.
766 */
767 OSStatus SecTrustGetTPHandle(SecTrustRef trust, CSSM_TP_HANDLE *handle)
768 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2, __MAC_10_7, __IPHONE_NA, __IPHONE_NA);
769
770 /*!
771 @function SecTrustCopyAnchorCertificates
772 @abstract Returns an array of default anchor (root) certificates used by
773 the system.
774 @param anchors On return, an array containing the system's default anchors
775 (roots). Call the CFRelease function to release this pointer.
776 @result A result code. See "Security Error Codes" (SecBase.h).
777 @discussion This function is not available on iOS, as certificate data
778 for system-trusted roots is currently unavailable on that platform.
779 */
780 OSStatus SecTrustCopyAnchorCertificates(CFArrayRef * __nonnull CF_RETURNS_RETAINED anchors)
781 __OSX_AVAILABLE_STARTING(__MAC_10_3, __IPHONE_NA);
782
783 CF_IMPLICIT_BRIDGING_DISABLED
784 CF_ASSUME_NONNULL_END
785
786 #endif /* TARGET_OS_MAC && !TARGET_OS_IPHONE */
787
788 __END_DECLS
789
790 #endif /* !_SECURITY_SECTRUST_H_ */