2 * Copyright (c) 2002-2017 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@
24 #ifndef _SECURITY_SECTRUSTSETTINGSPRIV_H_
25 #define _SECURITY_SECTRUSTSETTINGSPRIV_H_
27 #include <Security/SecBase.h>
29 #include <CoreFoundation/CoreFoundation.h>
30 #include <Security/SecPolicy.h>
31 #include <Security/SecCertificate.h>
32 #include <Security/SecTrustSettings.h>
34 #include <Security/cssmtype.h>
40 * Private Keys in the Usage Contraints dictionary.
41 * kSecTrustSettingsPolicyName Specifies a cert verification policy, e.g.,
42 * sslServer, eapClient, etc, using policy names.
43 * This entry can be used to restrict the policy where
44 * the same Policy Constant is used for multiple policyNames.
45 * kSectrustSettingsPolicyOptions Specifies a dictionary of policy options (from
46 * SecPolicyInternal.h). This entry can be used to require
47 * a particular SecPolicyCheck whenever this certificate is
48 * encountered during trust evaluation.
50 #define kSecTrustSettingsPolicyName CFSTR("kSecTrustSettingsPolicyName")
51 #define kSecTrustSettingsPolicyOptions CFSTR("kSecTrustSettingsPolicyOptions")
56 * Fundamental routine used by TP to ascertain status of one cert.
58 * Returns true in *foundMatchingEntry if a trust setting matching
59 * specific constraints was found for the cert. Returns true in
60 * *foundAnyEntry if any entry was found for the cert, even if it
61 * did not match the specified constraints. The TP uses this to
62 * optimize for the case where a cert is being evaluated for
63 * one type of usage, and then later for another type. If
64 * foundAnyEntry is false, the second evaluation need not occur.
66 * Returns the domain in which a setting was found in *foundDomain.
68 * Allowed errors applying to the specified cert evaluation
69 * are returned in a mallocd array in *allowedErrors and must
72 OSStatus
SecTrustSettingsEvaluateCert(
73 CFStringRef certHashStr
,
74 /* parameters describing the current cert evalaution */
75 const CSSM_OID
*policyOID
,
76 const char *policyString
, /* optional */
77 uint32 policyStringLen
,
78 SecTrustSettingsKeyUsage keyUsage
, /* optional */
79 bool isRootCert
, /* for checking default setting */
81 SecTrustSettingsDomain
*foundDomain
,
82 CSSM_RETURN
**allowedErrors
, /* mallocd and RETURNED */
83 uint32
*numAllowedErrors
, /* RETURNED */
84 SecTrustSettingsResult
*resultType
, /* RETURNED */
85 bool *foundMatchingEntry
, /* RETURNED */
86 bool *foundAnyEntry
); /* RETURNED */
89 * Obtain trusted certs which match specified usage.
90 * Only certs with a SecTrustSettingsResult of
91 * kSecTrustSettingsResultTrustRoot or
92 * or kSecTrustSettingsResultTrustAsRoot will be returned.
94 * To be used by SecureTransport for its (hopefully soon-to-be-
95 * deprecated) SSLSetTrustedRoots() call; I hope nothing else has
98 * Caller must CFRelease the returned CFArrayRef.
100 OSStatus
SecTrustSettingsCopyQualifiedCerts(
101 const CSSM_OID
*policyOID
,
102 const char *policyString
, /* optional */
103 uint32 policyStringLen
,
104 SecTrustSettingsKeyUsage keyUsage
, /* optional */
105 CFArrayRef
*certArray
); /* RETURNED */
108 * Obtain unrestricted root certificates from the specified domain(s).
109 * Only returns root certificates with no usage constraints.
110 * Caller must CFRelease the returned CFArrayRef.
112 OSStatus
SecTrustSettingsCopyUnrestrictedRoots(
115 Boolean systemDomain
,
116 CFArrayRef
*certArray
); /* RETURNED */
119 * Obtain a string representing a cert's SHA1 digest. This string is
120 * the key used to look up per-cert trust settings in a TrustSettings record.
122 CFStringRef CF_RETURNS_RETAINED
SecTrustSettingsCertHashStrFromCert(
123 SecCertificateRef certRef
);
125 CFStringRef CF_RETURNS_RETAINED
SecTrustSettingsCertHashStrFromData(
130 * Add a cert's TrustSettings to a non-persistent TrustSettings record.
131 * Primarily intended for use in creating a system TrustSettings record
132 * (which is itself immutable via this module).
134 * The settingsIn argument is an external representation of a TrustSettings
135 * record, obtained from this function or from
136 * SecTrustSettingsCreateExternalRepresentation().
137 * If settingsIn is NULL, a new (empty) TrustSettings will be created.
139 * The certRef and trustSettingsDictOrArray arguments are as in
140 * SecTrustSettingsSetTrustSettings(). May be NULL, when e.g. creating
141 * a new and empty TrustSettings record.
143 * The external representation is written to the settingOut argument,
144 * which must eventually be CFReleased by the caller.
146 OSStatus
SecTrustSettingsSetTrustSettingsExternal(
147 CFDataRef settingsIn
, /* optional */
148 SecCertificateRef certRef
, /* optional */
149 CFTypeRef trustSettingsDictOrArray
, /* optional */
150 CFDataRef
*settingsOut
); /* RETURNED */
153 * Add user trust settings for a SSL certificate and a given hostname.
154 * This is a wrapper around the SecTrustSettingsSetTrustSettings API
155 * and should be functionally equivalent to "Always trust" in the UI.
157 * When this function is called, the user will be prompted to authorize
158 * the trust settings change. After they successfully authenticate, or
159 * cancel the dialog, the result block will be called to indicate the
160 * current trust status. If an error occurred (such as errUserCanceled),
161 * the error reference provided to the block will be non-NULL.
163 void SecTrustSettingsSetTrustedCertificateForSSLHost(
164 SecCertificateRef certificate
,
165 CFStringRef hostname
,
166 void (^result
)(SecTrustSettingsResult trustResult
, CFErrorRef error
))
167 __OSX_AVAILABLE_STARTING(__MAC_10_13
, __IPHONE_NA
);
170 * Purge the cache of User and Admin Certs
172 void SecTrustSettingsPurgeUserAdminCertsCache(void);
175 #if SEC_OS_OSX_INCLUDES
177 * A wrapper around SecTrustSettingsCopyCertificates that combines user and admin
180 OSStatus
SecTrustSettingsCopyCertificatesForUserAdminDomains(
181 CFArrayRef CF_RETURNS_RETAINED
*certArray
);
182 #endif /* SEC_OS_OSX_INCLUDES */
186 #endif // _SECURITY_SECTRUSTSETTINGSPRIV_H_