2 * Copyright (c) 2002-2016 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
26 The functions and data types in SecTrust implement trust computation
27 and allow the caller to apply trust decisions to the evaluation.
30 #ifndef _SECURITY_SECTRUST_H_
31 #define _SECURITY_SECTRUST_H_
33 #include <Security/SecBase.h>
34 #include <CoreFoundation/CoreFoundation.h>
35 #include <AvailabilityMacros.h>
39 CF_ASSUME_NONNULL_BEGIN
40 CF_IMPLICIT_BRIDGING_ENABLED
43 @typedef SecTrustResultType
44 @abstract Specifies the trust result type.
45 @discussion SecTrustResultType results have two dimensions. They specify
46 both whether evaluation succeeded 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
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
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.
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
96 @abstract CFType used for performing X.509 certificate trust evaluations.
98 typedef struct CF_BRIDGED_TYPE(id
) __SecTrust
*SecTrustRef
;
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.
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
);
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
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.
156 extern const CFStringRef kSecTrustEvaluationDate
157 __OSX_AVAILABLE_STARTING(__MAC_10_9
, __IPHONE_7_0
);
158 extern const CFStringRef kSecTrustExtendedValidation
159 __OSX_AVAILABLE_STARTING(__MAC_10_9
, __IPHONE_7_0
);
160 extern const CFStringRef kSecTrustOrganizationName
161 __OSX_AVAILABLE_STARTING(__MAC_10_9
, __IPHONE_7_0
);
162 extern const CFStringRef kSecTrustResultValue
163 __OSX_AVAILABLE_STARTING(__MAC_10_9
, __IPHONE_7_0
);
164 extern const CFStringRef kSecTrustRevocationChecked
165 __OSX_AVAILABLE_STARTING(__MAC_10_9
, __IPHONE_7_0
);
166 extern const CFStringRef kSecTrustRevocationValidUntilDate
167 __OSX_AVAILABLE_STARTING(__MAC_10_9
, __IPHONE_7_0
);
168 extern const CFStringRef kSecTrustCertificateTransparency
169 __OSX_AVAILABLE_STARTING(__MAC_10_11
, __IPHONE_9_0
);
170 extern const CFStringRef kSecTrustCertificateTransparencyWhiteList
171 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_12
, __MAC_10_13
, __IPHONE_10_0
, __IPHONE_11_0
);
175 @typedef SecTrustCallback
176 @abstract Delivers the result from an asynchronous trust evaluation.
177 @param trustRef A reference to the trust object which has been evaluated.
178 @param trustResult The trust result of the evaluation. Additional status
179 information can be obtained by calling SecTrustCopyProperties().
181 typedef void (^SecTrustCallback
)(SecTrustRef trustRef
, SecTrustResultType trustResult
);
182 #endif /* __BLOCKS__ */
186 @function SecTrustGetTypeID
187 @abstract Returns the type identifier of SecTrust instances.
188 @result The CFTypeID of SecTrust instances.
190 CFTypeID
SecTrustGetTypeID(void)
191 __OSX_AVAILABLE_STARTING(__MAC_10_3
, __IPHONE_2_0
);
194 @function SecTrustCreateWithCertificates
195 @abstract Creates a trust object based on the given certificates and
197 @param certificates The group of certificates to verify. This can either
198 be a CFArrayRef of SecCertificateRef objects or a single SecCertificateRef
199 @param policies An array of one or more policies. You may pass a
200 SecPolicyRef to represent a single policy.
201 @param trust On return, a pointer to the trust management reference.
202 @result A result code. See "Security Error Codes" (SecBase.h).
203 @discussion If multiple policies are passed in, all policies must verify
204 for the chain to be considered valid.
206 OSStatus
SecTrustCreateWithCertificates(CFTypeRef certificates
,
207 CFTypeRef __nullable policies
, SecTrustRef
* __nonnull CF_RETURNS_RETAINED trust
)
208 __OSX_AVAILABLE_STARTING(__MAC_10_3
, __IPHONE_2_0
);
211 @function SecTrustSetPolicies
212 @abstract Set the policies for which trust should be verified.
213 @param trust A trust reference.
214 @param policies An array of one or more policies. You may pass a
215 SecPolicyRef to represent a single policy.
216 @result A result code. See "Security Error Codes" (SecBase.h).
217 @discussion This function will invalidate the existing trust result,
218 requiring a fresh evaluation for the newly-set policies.
220 OSStatus
SecTrustSetPolicies(SecTrustRef trust
, CFTypeRef policies
)
221 __OSX_AVAILABLE_STARTING(__MAC_10_3
, __IPHONE_6_0
);
224 @function SecTrustCopyPolicies
225 @abstract Returns an array of policies used for this evaluation.
226 @param trust A reference to a trust object.
227 @param policies On return, an array of policies used by this trust.
228 Call the CFRelease function to release this reference.
229 @result A result code. See "Security Error Codes" (SecBase.h).
231 OSStatus
SecTrustCopyPolicies(SecTrustRef trust
, CFArrayRef
* __nonnull CF_RETURNS_RETAINED policies
)
232 __OSX_AVAILABLE_STARTING(__MAC_10_3
, __IPHONE_7_0
);
235 @function SecTrustSetNetworkFetchAllowed
236 @abstract Specifies whether a trust evaluation is permitted to fetch missing
237 intermediate certificates from the network.
238 @param trust A trust reference.
239 @param allowFetch If true, and a certificate's issuer is not present in the
240 trust reference but its network location is known, the evaluation is permitted
241 to attempt to download it automatically. Pass false to disable network fetch
242 for this trust evaluation.
243 @result A result code. See "Security Error Codes" (SecBase.h).
244 @discussion By default, network fetch of missing certificates is enabled if
245 the trust evaluation includes the SSL policy, otherwise it is disabled.
247 OSStatus
SecTrustSetNetworkFetchAllowed(SecTrustRef trust
,
249 __OSX_AVAILABLE_STARTING(__MAC_10_9
, __IPHONE_7_0
);
252 @function SecTrustGetNetworkFetchAllowed
253 @abstract Returns whether a trust evaluation is permitted to fetch missing
254 intermediate certificates from the network.
255 @param trust A trust reference.
256 @param allowFetch On return, the boolean pointed to by this parameter is
257 set to true if the evaluation is permitted to download missing certificates.
258 @result A result code. See "Security Error Codes" (SecBase.h).
259 @discussion By default, network fetch of missing certificates is enabled if
260 the trust evaluation includes the SSL policy, otherwise it is disabled.
262 OSStatus
SecTrustGetNetworkFetchAllowed(SecTrustRef trust
,
264 __OSX_AVAILABLE_STARTING(__MAC_10_9
, __IPHONE_7_0
);
267 @function SecTrustSetAnchorCertificates
268 @abstract Sets the anchor certificates for a given trust.
269 @param trust A reference to a trust object.
270 @param anchorCertificates An array of anchor certificates.
271 @result A result code. See "Security Error Codes" (SecBase.h).
272 @discussion Calling this function without also calling
273 SecTrustSetAnchorCertificatesOnly() will disable trusting any
274 anchors other than the ones in anchorCertificates.
276 OSStatus
SecTrustSetAnchorCertificates(SecTrustRef trust
,
277 CFArrayRef anchorCertificates
)
278 __OSX_AVAILABLE_STARTING(__MAC_10_3
, __IPHONE_2_0
);
281 @function SecTrustSetAnchorCertificatesOnly
282 @abstract Reenables trusting anchor certificates in addition to those
283 passed in via the SecTrustSetAnchorCertificates API.
284 @param trust A reference to a trust object.
285 @param anchorCertificatesOnly If true, disables trusting any anchors other
286 than the ones passed in via SecTrustSetAnchorCertificates(). If false,
287 the built in anchor certificates are also trusted.
288 @result A result code. See "Security Error Codes" (SecBase.h).
290 OSStatus
SecTrustSetAnchorCertificatesOnly(SecTrustRef trust
,
291 Boolean anchorCertificatesOnly
)
292 __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_2_0
);
295 @function SecTrustCopyCustomAnchorCertificates
296 @abstract Returns an array of custom anchor certificates used by a given
297 trust, as set by a prior call to SecTrustSetAnchorCertificates, or NULL if
298 no custom anchors have been specified.
299 @param trust A reference to a trust object.
300 @param anchors On return, an array of custom anchor certificates (roots)
301 used by this trust, or NULL if no custom anchors have been specified. Call
302 the CFRelease function to release this reference.
303 @result A result code. See "Security Error Codes" (SecBase.h).
305 OSStatus
SecTrustCopyCustomAnchorCertificates(SecTrustRef trust
,
306 CFArrayRef
* __nonnull CF_RETURNS_RETAINED anchors
)
307 __OSX_AVAILABLE_STARTING(__MAC_10_5
, __IPHONE_7_0
);
310 @function SecTrustSetVerifyDate
311 @abstract Set the date for which the trust should be verified.
312 @param trust A reference to a trust object.
313 @param verifyDate The date for which to verify trust.
314 @result A result code. See "Security Error Codes" (SecBase.h).
315 @discussion This function lets you evaluate certificate validity for a
316 given date (for example, to determine if a signature was valid on the date
317 it was signed, even if the certificate has since expired.) If this function
318 is not called, the time at which SecTrustEvaluate() is called is used
319 implicitly as the verification time.
321 OSStatus
SecTrustSetVerifyDate(SecTrustRef trust
, CFDateRef verifyDate
)
322 __OSX_AVAILABLE_STARTING(__MAC_10_3
, __IPHONE_2_0
);
325 @function SecTrustGetVerifyTime
326 @abstract Returns the verify time.
327 @param trust A reference to the trust object being verified.
328 @result A CFAbsoluteTime value representing the time at which certificates
329 should be checked for validity.
330 @discussion This function retrieves the verification time for the given
331 trust reference, as set by a prior call to SecTrustSetVerifyDate(). If the
332 verification time has not been set, this function returns a value of 0,
333 indicating that the current date/time is implicitly used for verification.
335 CFAbsoluteTime
SecTrustGetVerifyTime(SecTrustRef trust
)
336 __OSX_AVAILABLE_STARTING(__MAC_10_6
, __IPHONE_2_0
);
339 @function SecTrustEvaluate
340 @abstract Evaluates a trust reference synchronously.
341 @param trust A reference to the trust object to evaluate.
342 @param result A pointer to a result type.
343 @result A result code. See "Security Error Codes" (SecBase.h).
344 @discussion This function will completely evaluate trust before returning,
345 possibly including network access to fetch intermediate certificates or to
346 perform revocation checking. Since this function can block during those
347 operations, you should call it from within a function that is placed on a
348 dispatch queue, or in a separate thread from your application's main
349 run loop. Alternatively, you can use the SecTrustEvaluateAsync function.
351 OSStatus
SecTrustEvaluate(SecTrustRef trust
, SecTrustResultType
*result
)
352 __OSX_AVAILABLE_STARTING(__MAC_10_3
, __IPHONE_2_0
);
356 @function SecTrustEvaluateAsync
357 @abstract Evaluates a trust reference asynchronously.
358 @param trust A reference to the trust object to evaluate.
359 @param queue A dispatch queue on which the result callback should be
360 executed. Pass NULL to use the current dispatch queue.
361 @param result A SecTrustCallback block which will be executed when the
362 trust evaluation is complete.
363 @result A result code. See "Security Error Codes" (SecBase.h).
365 OSStatus
SecTrustEvaluateAsync(SecTrustRef trust
,
366 dispatch_queue_t __nullable queue
, SecTrustCallback result
)
367 __OSX_AVAILABLE_STARTING(__MAC_10_7
, __IPHONE_7_0
);
371 @function SecTrustEvaluateWithError
372 @abstract Evaluates a trust reference synchronously.
373 @param trust A reference to the trust object to evaluate.
374 @param error A pointer to an error object
375 @result A boolean value indicating whether the certificate is trusted
376 @discussion This function will completely evaluate trust before returning,
377 possibly including network access to fetch intermediate certificates or to
378 perform revocation checking. Since this function can block during those
379 operations, you should call it from within a function that is placed on a
380 dispatch queue, or in a separate thread from your application's main
382 If the certificate is trusted and the result is true, the error will be set to NULL.
383 If the certificate is not trusted or the evaluation was unable to complete, the result
384 will be false and the error will be set with a description of the failure.
385 The error contains a code for the most serious error encountered (if multiple trust
386 failures occurred). The localized description indicates the certificate with the most
387 serious problem and the type of error. The underlying error contains a localized
388 description of each certificate in the chain that had an error and all errors found
389 with that certificate.
391 __attribute__((warn_unused_result
)) bool
392 SecTrustEvaluateWithError(SecTrustRef trust
, CFErrorRef _Nullable
* _Nullable CF_RETURNS_RETAINED error
)
393 API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0));
396 @function SecTrustGetTrustResult
397 @param trust A reference to a trust object.
398 @param result A pointer to the result from the most recent call to
399 SecTrustEvaluate for this trust reference. If SecTrustEvaluate has not been
400 called or trust parameters have changed, the result is kSecTrustResultInvalid.
401 @result A result code. See "Security Error Codes" (SecBase.h).
402 @discussion This function replaces SecTrustGetResult for the purpose of
403 obtaining the current evaluation result of a given trust reference.
405 OSStatus
SecTrustGetTrustResult(SecTrustRef trust
,
406 SecTrustResultType
*result
)
407 __OSX_AVAILABLE_STARTING(__MAC_10_7
, __IPHONE_7_0
);
410 @function SecTrustCopyPublicKey
411 @abstract Return the public key for a leaf certificate after it has
413 @param trust A reference to the trust object which has been evaluated.
414 @result The certificate's public key, or NULL if it the public key could
415 not be extracted (this can happen if the public key algorithm is not
416 supported). The caller is responsible for calling CFRelease on the
417 returned key when it is no longer needed.
420 SecKeyRef
SecTrustCopyPublicKey(SecTrustRef trust
)
421 __OSX_AVAILABLE_STARTING(__MAC_10_7
, __IPHONE_2_0
);
424 @function SecTrustGetCertificateCount
425 @abstract Returns the number of certificates in an evaluated certificate
427 @param trust A reference to a trust object.
428 @result The number of certificates in the trust chain, including the anchor.
429 @discussion Important: if the trust reference has not yet been evaluated,
430 this function will evaluate it first before returning. If speed is critical,
431 you may want to call SecTrustGetTrustResult first to make sure that a
432 result other than kSecTrustResultInvalid is present for the trust object.
434 CFIndex
SecTrustGetCertificateCount(SecTrustRef trust
)
435 __OSX_AVAILABLE_STARTING(__MAC_10_7
, __IPHONE_2_0
);
438 @function SecTrustGetCertificateAtIndex
439 @abstract Returns a certificate from the trust chain.
440 @param trust Reference to a trust object.
441 @param ix The index of the requested certificate. Indices run from 0
442 (leaf) to the anchor (or last certificate found if no anchor was found).
443 The leaf cert (index 0) is always present regardless of whether the trust
444 reference has been evaluated or not.
445 @result A SecCertificateRef for the requested certificate.
448 SecCertificateRef
SecTrustGetCertificateAtIndex(SecTrustRef trust
, CFIndex ix
)
449 __OSX_AVAILABLE_STARTING(__MAC_10_7
, __IPHONE_2_0
);
452 @function SecTrustCopyExceptions
453 @abstract Returns an opaque cookie which will allow future evaluations
454 of the current certificate to succeed.
455 @param trust A reference to an evaluated trust object.
456 @result An opaque cookie which when passed to SecTrustSetExceptions() will
457 cause a call to SecTrustEvaluate() return kSecTrustResultProceed. This
458 will happen upon subsequent evaluation of the current certificate unless
459 some new error starts happening that wasn't being reported when the cookie
460 was returned from this function (for example, if the certificate expires
461 then evaluation will start failing again until a new cookie is obtained.)
462 @discussion Normally this API should only be called once the errors have
463 been presented to the user and the user decided to trust the current
464 certificate chain regardless of the errors being presented, for the
465 current application/server/protocol combination.
467 CFDataRef
SecTrustCopyExceptions(SecTrustRef trust
)
468 __OSX_AVAILABLE_STARTING(__MAC_10_9
, __IPHONE_4_0
);
471 @function SecTrustSetExceptions
472 @abstract Set a trust cookie to be used for evaluating this certificate chain.
473 @param trust A reference to a trust object.
474 @param exceptions An exceptions cookie as returned by a call to
475 SecTrustCopyExceptions() in the past. You may pass NULL to clear any
476 exceptions which have been previously set on this trust reference.
477 @result Upon calling SecTrustEvaluate(), any failures that were present at the
478 time the exceptions object was created are ignored, and instead of returning
479 kSecTrustResultRecoverableTrustFailure, kSecTrustResultProceed will be returned
480 (if the certificate for which exceptions was created matches the current leaf
482 @result Returns true if the exceptions cookies was valid and matches the current
483 leaf certificate, false otherwise. This function will invalidate the existing
484 trust result, requiring a subsequent evaluation for the newly-set exceptions.
485 Note that this function returning true doesn't mean the caller can skip calling
486 SecTrustEvaluate, as there may be new errors since the exceptions cookie was
487 created (for example, a certificate may have subsequently expired.)
488 @discussion Clients of this interface will need to establish the context of this
489 exception to later decide when this exception cookie is to be used.
490 Examples of this context would be the server we are connecting to, the ssid
491 of the wireless network for which this cert is needed, the account for which
492 this cert should be considered valid, and so on.
494 bool SecTrustSetExceptions(SecTrustRef trust
, CFDataRef __nullable exceptions
)
495 __OSX_AVAILABLE_STARTING(__MAC_10_9
, __IPHONE_4_0
);
498 @function SecTrustCopyProperties
499 @abstract Return a property array for this trust evaluation.
500 @param trust A reference to a trust object. If the trust has not been
501 evaluated, the returned property array will be empty.
502 @result A property array. It is the caller's responsibility to CFRelease
503 the returned array when it is no longer needed.
504 @discussion This function returns an ordered array of CFDictionaryRef
505 instances for each certificate in the chain. Indices run from 0 (leaf) to
506 the anchor (or last certificate found if no anchor was found.) See the
507 "Trust Property Constants" section for a list of currently defined keys.
510 CFArrayRef
SecTrustCopyProperties(SecTrustRef trust
)
511 __OSX_AVAILABLE_STARTING(__MAC_10_7
, __IPHONE_2_0
);
514 @function SecTrustCopyResult
515 @abstract Returns a dictionary containing information about the
516 evaluated certificate chain for use by clients.
517 @param trust A reference to a trust object.
518 @result A dictionary with various fields that can be displayed to the user,
519 or NULL if no additional info is available or the trust has not yet been
520 validated. The caller is responsible for calling CFRelease on the value
521 returned when it is no longer needed.
522 @discussion Returns a dictionary for the overall trust evaluation. See the
523 "Trust Result Constants" section for a list of currently defined keys.
526 CFDictionaryRef
SecTrustCopyResult(SecTrustRef trust
)
527 __OSX_AVAILABLE_STARTING(__MAC_10_9
, __IPHONE_7_0
);
530 @function SecTrustSetOCSPResponse
531 @abstract Attach OCSPResponse data to a trust object.
532 @param trust A reference to a trust object.
533 @param responseData This may be either a CFData object containing a single
534 DER-encoded OCSPResponse (per RFC 2560), or a CFArray of these.
535 @result A result code. See "Security Error Codes" (SecBase.h).
536 @discussion Allows the caller to provide OCSPResponse data (which may be
537 obtained during a TLS/SSL handshake, per RFC 3546) as input to a trust
538 evaluation. If this data is available, it can obviate the need to contact
539 an OCSP server for current revocation information.
541 OSStatus
SecTrustSetOCSPResponse(SecTrustRef trust
, CFTypeRef __nullable responseData
)
542 __OSX_AVAILABLE_STARTING(__MAC_10_9
, __IPHONE_7_0
);
544 CF_IMPLICIT_BRIDGING_DISABLED
545 CF_ASSUME_NONNULL_END
548 * Legacy functions (OS X only)
550 #if TARGET_OS_MAC && !TARGET_OS_IPHONE
551 #include <Security/cssmtype.h>
552 #include <Security/cssmapple.h>
554 CF_ASSUME_NONNULL_BEGIN
555 CF_IMPLICIT_BRIDGING_ENABLED
558 @typedef SecTrustUserSetting
559 @abstract Specifies a user-specified trust setting value.
560 @discussion Deprecated in OS X 10.9. User trust settings are managed by
561 functions in SecTrustSettings.h (starting with OS X 10.5), and by the
562 SecTrustCopyExceptions and SecTrustSetExceptions functions (starting with
563 iOS 4 and OS X 10.9). The latter two functions are recommended for both OS X
564 and iOS, as they avoid the need to explicitly specify these values.
566 typedef SecTrustResultType SecTrustUserSetting
567 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
, __MAC_10_9
, __IPHONE_NA
, __IPHONE_NA
);
570 @typedef SecTrustOptionFlags
571 @abstract Options for customizing trust evaluation.
572 @constant kSecTrustOptionAllowExpired Allow expired certificates.
573 @constant kSecTrustOptionLeafIsCA Allow CA as leaf certificate.
574 @constant kSecTrustOptionFetchIssuerFromNet Allow network fetch of CA cert.
575 @constant kSecTrustOptionAllowExpiredRoot Allow expired roots.
576 @constant kSecTrustOptionRequireRevPerCert Require positive revocation
577 check per certificate.
578 @constant kSecTrustOptionUseTrustSettings Use TrustSettings instead of
580 @constant kSecTrustOptionImplicitAnchors Properly self-signed certs are
581 treated as anchors implicitly.
583 typedef CF_OPTIONS(uint32_t, SecTrustOptionFlags
) {
584 kSecTrustOptionAllowExpired
= 0x00000001,
585 kSecTrustOptionLeafIsCA
= 0x00000002,
586 kSecTrustOptionFetchIssuerFromNet
= 0x00000004,
587 kSecTrustOptionAllowExpiredRoot
= 0x00000008,
588 kSecTrustOptionRequireRevPerCert
= 0x00000010,
589 kSecTrustOptionUseTrustSettings
= 0x00000020,
590 kSecTrustOptionImplicitAnchors
= 0x00000040
594 @function SecTrustSetOptions
595 @abstract Sets optional flags for customizing a trust evaluation.
596 @param trustRef A trust reference.
597 @param options Flags to change evaluation behavior for this trust.
598 @result A result code. See "Security Error Codes" (SecBase.h).
599 @discussion This function is not available on iOS. Use SecTrustSetExceptions
600 and SecTrustCopyExceptions to modify default trust results, and
601 SecTrustSetNetworkFetchAllowed to specify whether missing CA certificates
602 can be fetched from the network.
604 OSStatus
SecTrustSetOptions(SecTrustRef trustRef
, SecTrustOptionFlags options
)
605 __OSX_AVAILABLE_STARTING(__MAC_10_7
, __IPHONE_NA
);
608 @function SecTrustSetParameters
609 @abstract Sets the action and action data for a trust object.
610 @param trustRef The reference to the trust to change.
611 @param action A trust action.
612 @param actionData A reference to data associated with this action.
613 @result A result code. See "Security Error Codes" (SecBase.h).
614 @discussion This function is deprecated in OS X 10.7 and later, where it
615 was replaced by SecTrustSetOptions, and is not available on iOS. Your code
616 should use SecTrustSetExceptions and SecTrustCopyExceptions to modify default
617 trust results, and SecTrustSetNetworkFetchAllowed to specify whether missing
618 CA certificates can be fetched from the network.
620 OSStatus
SecTrustSetParameters(SecTrustRef trustRef
,
621 CSSM_TP_ACTION action
, CFDataRef actionData
)
622 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
, __MAC_10_7
, __IPHONE_NA
, __IPHONE_NA
);
625 @function SecTrustSetKeychains
626 @abstract Sets the keychains for a given trust object.
627 @param trust A reference to a trust object.
628 @param keychainOrArray A reference to an array of keychains to search, a
629 single keychain, or NULL to use the default keychain search list.
630 @result A result code. See "Security Error Codes" (SecBase.h).
631 @discussion This function is deprecated in macOS 10.13 and later. Beginning in
632 macOS 10.12, this function no longer affected the behavior of the trust
633 evaluation: the user's keychain search list and the system
634 anchors keychain are searched for certificates to complete the chain. To change
635 the keychains that are searched, callers must use SecKeychainSetSearchList to
636 change the user's keychain search list.
637 Note: this function was never applicable to iOS.
639 OSStatus
SecTrustSetKeychains(SecTrustRef trust
, CFTypeRef __nullable keychainOrArray
)
640 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_3
, __MAC_10_13
, __IPHONE_NA
, __IPHONE_NA
);
643 @function SecTrustGetResult
644 @abstract Returns detailed information on the outcome of an evaluation.
645 @param trustRef A reference to a trust object.
646 @param result A pointer to the result from the call to SecTrustEvaluate.
647 @param certChain On return, a pointer to the certificate chain used to
648 validate the input certificate. Call the CFRelease function to release
650 @param statusChain On return, a pointer to the status of the certificate
651 chain. Do not attempt to free this pointer; it remains valid until the
652 trust is destroyed or the next call to SecTrustEvaluate.
653 @result A result code. See "Security Error Codes" (SecBase.h).
654 @discussion This function is deprecated in OS X 10.7 and later,
655 and is not available on iOS.
656 To get the complete certificate chain, use SecTrustGetCertificateCount and
657 SecTrustGetCertificateAtIndex. To get detailed status information for each
658 certificate, use SecTrustCopyProperties. To get the overall trust result
659 for the evaluation, use SecTrustGetTrustResult.
661 OSStatus
SecTrustGetResult(SecTrustRef trustRef
, SecTrustResultType
* __nullable result
,
662 CFArrayRef
* __nullable CF_RETURNS_RETAINED certChain
, CSSM_TP_APPLE_EVIDENCE_INFO
* __nullable
* __nullable statusChain
)
663 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
, __MAC_10_7
, __IPHONE_NA
, __IPHONE_NA
);
666 @function SecTrustGetCssmResult
667 @abstract Gets the CSSM trust result.
668 @param trust A reference to a trust.
669 @param result On return, a pointer to the CSSM trust result.
670 @result A result code. See "Security Error Codes" (SecBase.h).
671 @discussion This function is deprecated in OS X 10.7 and later,
672 and is not available on iOS.
673 To get detailed status information for each certificate, use
674 SecTrustCopyProperties. To get the overall trust result for the evaluation,
675 use SecTrustGetTrustResult.
677 OSStatus
SecTrustGetCssmResult(SecTrustRef trust
,
678 CSSM_TP_VERIFY_CONTEXT_RESULT_PTR __nullable
* __nonnull result
)
679 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
, __MAC_10_7
, __IPHONE_NA
, __IPHONE_NA
);
682 @function SecTrustGetCssmResultCode
683 @abstract Gets the result code from the most recent call to SecTrustEvaluate
684 for the specified trust.
685 @param trust A reference to a trust.
686 @param resultCode On return, the result code produced by the most recent
687 evaluation of the given trust (cssmerr.h). The value of resultCode is
688 undefined if SecTrustEvaluate has not been called.
689 @result A result code. See "Security Error Codes" (SecBase.h). Returns
690 errSecTrustNotAvailable if SecTrustEvaluate has not been called for the
692 @discussion This function is deprecated in OS X 10.7 and later,
693 and is not available on iOS.
694 To get detailed status information for each certificate, use
695 SecTrustCopyProperties. To get the overall trust result for the evaluation,
696 use SecTrustGetTrustResult.
698 OSStatus
SecTrustGetCssmResultCode(SecTrustRef trust
, OSStatus
*resultCode
)
699 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
, __MAC_10_7
, __IPHONE_NA
, __IPHONE_NA
);
702 @function SecTrustGetTPHandle
703 @abstract Gets the CSSM trust handle
704 @param trust A reference to a trust.
705 @param handle On return, a CSSM trust handle.
706 @result A result code. See "Security Error Codes" (SecBase.h).
707 @discussion This function is deprecated in OS X 10.7 and later.
709 OSStatus
SecTrustGetTPHandle(SecTrustRef trust
, CSSM_TP_HANDLE
*handle
)
710 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_10_2
, __MAC_10_7
, __IPHONE_NA
, __IPHONE_NA
);
713 @function SecTrustCopyAnchorCertificates
714 @abstract Returns an array of default anchor (root) certificates used by
716 @param anchors On return, an array containing the system's default anchors
717 (roots). Call the CFRelease function to release this pointer.
718 @result A result code. See "Security Error Codes" (SecBase.h).
719 @discussion This function is not available on iOS, as certificate data
720 for system-trusted roots is currently unavailable on that platform.
722 OSStatus
SecTrustCopyAnchorCertificates(CFArrayRef
* __nonnull CF_RETURNS_RETAINED anchors
)
723 __OSX_AVAILABLE_STARTING(__MAC_10_3
, __IPHONE_NA
);
725 CF_IMPLICIT_BRIDGING_DISABLED
726 CF_ASSUME_NONNULL_END
728 #endif /* TARGET_OS_MAC && !TARGET_OS_IPHONE */
732 #endif /* !_SECURITY_SECTRUST_H_ */