2 * Copyright (c) 2007-2008,2010,2012-2015 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@
25 * SecTrustSettingsPriv.h - TrustSettings SPI functions.
28 #ifndef _SECURITY_SECTRUSTSETTINGSPRIV_H_
29 #define _SECURITY_SECTRUSTSETTINGSPRIV_H_
31 #include <CoreFoundation/CoreFoundation.h>
32 #include <Security/SecPolicy.h>
33 #include <Security/SecCertificate.h>
34 #include <Security/SecTrustSettings.h>
41 * A TrustSettings Record contains the XML encoding of a CFDictionary. This dictionary
42 * currently contains two name/value pairs:
44 * key = kTrustRecordVersion, value = SInt32 version number
45 * key = kTrustRecordTrustList, value = CFDictionary
47 * Each key/value pair of the CFDictionary associated with key kTrustRecordTrustList
49 * -- key = the ASCII representation (with alpha characters in upper case) of the
51 * -- value = a CFDictionary representing one cert.
53 * Key/value pairs in the per-cert dictionary are as follows:
55 * -- key = kTrustRecordIssuer, value = non-normalized issuer as CFData
56 * -- key = kTrustRecordSerialNumber, value = serial number as CFData
57 * -- key = kTrustRecordModDate, value = CFDateRef of the last modification
58 date of the per-cert entry.
59 * -- key = kTrustRecordTrustSettings, value = array of dictionaries. The
60 * dictionaries are as described in the API in SecUserTrust.h
61 * although we store the values differently (see below).
62 * As written to disk, this key/value is always present although
63 * the usageConstraints array may be empty.
65 * A usageConstraints dictionary is like so (all elements are optional). These key
66 * strings are defined in SecUserTrust.h.
68 * key = kSecTrustSettingsPolicy value = policy OID as CFString
69 * key = kSecTrustSettingsPolicyName value = policy name as CFString
70 * key = kSecTrustSettingsApplication value = application path as CFString
71 * key = kSecTrustSettingsPolicyString value = CFString, policy-specific
72 * key = kSecTrustSettingsAllowedError value = CFNumber, an SInt32 CSSM_RETURN
73 * key = kSecTrustSettingsResult value = CFNumber, an SInt32 SecTrustSettingsResult
74 * key = kSecTrustSettingsKeyUsage value = CFNumber, an SInt32 key usage
75 * key = kSecTrustSettingsModifyDate value = CFDate, last modification
79 * Keys in the top-level dictionary
81 #define kTrustRecordVersion CFSTR("trustVersion")
82 #define kTrustRecordTrustList CFSTR("trustList")
85 * Keys in the per-cert dictionary in the TrustedRootList record.
87 /* value = non-normalized issuer as CFData */
88 #define kTrustRecordIssuer CFSTR("issuerName")
90 /* value = serial number as CFData */
91 #define kTrustRecordSerialNumber CFSTR("serialNumber")
93 /* value = CFDateRef representation of modification date */
94 #define kTrustRecordModDate CFSTR("modDate")
97 * value = array of CFDictionaries as used in public API
98 * Not present for a cert which has no usage Constraints (i.e.
99 * "wide open" unrestricted, kSecTrustSettingsResultTrustRoot as
100 * the default SecTrustSettingsResult).
102 #define kTrustRecordTrustSettings CFSTR("trustSettings")
105 * Version of the top-level dictionary.
108 kSecTrustRecordVersionInvalid
= 0, /* should never be seen on disk */
109 kSecTrustRecordVersionCurrent
= 1
113 * Key for the (optional) default entry in a TrustSettings record. This
114 * appears in place of the cert's hash string, and corresponds to
115 * kSecTrustSettingsDefaultRootCertSetting at the public API.
116 * If you change this, make sure it has characters other than those
117 * appearing in a normal cert hash string (0..9 and A..F).
119 #define kSecTrustRecordDefaultRootCert CFSTR("kSecTrustRecordDefaultRootCert")
122 * The location of the system root keychain and its associated TrustSettings.
123 * These are immutable; this module never modifies either of them.
125 #define SYSTEM_ROOT_STORE_PATH "/System/Library/Keychains/SystemRootCertificates.keychain"
126 #define SYSTEM_TRUST_SETTINGS_PATH "/System/Library/Keychains/SystemTrustSettings.plist"
129 * The local admin cert store.
131 #define ADMIN_CERT_STORE_PATH "/Library/Keychains/System.keychain"
134 * Per-user and local admin TrustSettings are stored in this directory.
135 * Per-user settings are of the form <uuid>.plist.
137 #define TRUST_SETTINGS_PATH "/Library/Trust Settings"
138 #define ADMIN_TRUST_SETTINGS "Admin.plist"
141 * Additional values for the SecTrustSettingsDomain enum.
145 * This indicates a TrustSettings that exists only in memory; it
146 * can't be written to disk.
148 kSecTrustSettingsDomainMemory
= 100
151 typedef struct __SecTrustSettings
*SecTrustSettingsRef
;
153 CFTypeID
SecTrustSettingsGetTypeID(void);
154 OSStatus
SecTrustSettingsCreateFromExternal(SecTrustSettingsDomain domain
,
155 CFDataRef external
, SecTrustSettingsRef
*ts
);
156 SecTrustSettingsRef
SecTrustSettingsCreate(SecTrustSettingsDomain domain
,
157 bool create
, bool trim
);
158 CFDataRef
SecTrustSettingsCopyExternal(SecTrustSettingsRef ts
);
159 void SecTrustSettingsSet(SecCertificateRef certRef
,
160 CFTypeRef trustSettingsDictOrArray
);
163 * Fundamental routine used to ascertain status of one cert.
165 * Returns true in *foundMatchingEntry if a trust setting matching
166 * specific constraints was found for the cert. Returns true in
167 * *foundAnyEntry if any entry was found for the cert, even if it
168 * did not match the specified constraints. The TP uses this to
169 * optimize for the case where a cert is being evaluated for
170 * one type of usage, and then later for another type. If
171 * foundAnyEntry is false, the second evaluation need not occur.
173 * Returns the domain in which a setting was found in *foundDomain.
175 * Allowed errors applying to the specified cert evaluation
176 * are returned in a mallocd array in *allowedErrors and must
177 * be freed by caller.
179 OSStatus
SecTrustSettingsEvaluateCertificate(
180 SecCertificateRef certificate
,
182 SecTrustSettingsKeyUsage keyUsage
, /* optional */
183 bool isSelfSignedCert
, /* for checking default setting */
184 /* RETURNED values */
185 SecTrustSettingsDomain
*foundDomain
,
186 CFArrayRef
*allowedErrors
, /* RETURNED */
187 SecTrustSettingsResult
*resultType
, /* RETURNED */
188 bool *foundMatchingEntry
,/* RETURNED */
189 bool *foundAnyEntry
); /* RETURNED */
192 * Add a cert's TrustSettings to a non-persistent TrustSettings record.
193 * Primarily intended for use in creating a system TrustSettings record
194 * (which is itself immutable via this module).
196 * The settingsIn argument is an external representation of a TrustSettings
197 * record, obtianed from this function or from
198 * SecTrustSettingsCreateExternalRepresentation().
199 * If settingsIn is NULL, a new (empty) TrustSettings will be created.
201 * The certRef and trustSettingsDictOrArray arguments are as in
202 * SecTrustSettingsSetTrustSettings(). May be NULL, when e.g. creating
203 * a new and empty TrustSettings record.
205 * The external representation is written to the settingOut argument,
206 * which must eventually be CFReleased by the caller.
209 OSStatus
SecTrustSettingsSetTrustSettingsExternal_ios(
211 OSStatus
SecTrustSettingsSetTrustSettingsExternal(
213 CFDataRef settingsIn
, /* optional */
214 SecCertificateRef certRef
, /* optional */
215 CFTypeRef trustSettingsDictOrArray
, /* optional */
216 CFDataRef
*settingsOut
); /* RETURNED */
218 #if (SECTRUST_OSX && !TARGET_OS_IPHONE)
220 * A wrapper around SecTrustSettingsCopyCertificates that combines user and admin
223 OSStatus
SecTrustSettingsCopyCertificatesForUserAdminDomains(
224 CFArrayRef CF_RETURNS_RETAINED
*certArray
);
227 * Obtain Trust Settings for specified cert.
228 * Caller must CFRelease() the returned CFArray.
229 * Returns errSecItemNotFound if no Trust settings exist for the cert.
231 OSStatus
SecTrustSettingsCopyTrustSettings(
232 SecCertificateRef certRef
,
233 SecTrustSettingsDomain domain
,
234 CFArrayRef
* CF_RETURNS_RETAINED trustSettings
); /* RETURNED */
241 #endif /* _SECURITY_SECTRUSTSETTINGSPRIV_H_ */