]> git.saurik.com Git - apple/security.git/blob - OSX/sec/Security/SecTrustSettingsPriv.h
Security-57740.20.22.tar.gz
[apple/security.git] / OSX / sec / Security / SecTrustSettingsPriv.h
1 /*
2 * Copyright (c) 2007-2008,2010,2012-2015 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 * SecTrustSettingsPriv.h - TrustSettings SPI functions.
26 */
27
28 #ifndef _SECURITY_SECTRUSTSETTINGSPRIV_H_
29 #define _SECURITY_SECTRUSTSETTINGSPRIV_H_
30
31 #include <CoreFoundation/CoreFoundation.h>
32 #include <Security/SecPolicy.h>
33 #include <Security/SecCertificate.h>
34 #include <Security/SecTrustSettings.h>
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /*
41 * A TrustSettings Record contains the XML encoding of a CFDictionary. This dictionary
42 * currently contains two name/value pairs:
43 *
44 * key = kTrustRecordVersion, value = SInt32 version number
45 * key = kTrustRecordTrustList, value = CFDictionary
46 *
47 * Each key/value pair of the CFDictionary associated with key kTrustRecordTrustList
48 * consists of:
49 * -- key = the ASCII representation (with alpha characters in upper case) of the
50 * cert's SHA1 digest.
51 * -- value = a CFDictionary representing one cert.
52 *
53 * Key/value pairs in the per-cert dictionary are as follows:
54 *
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.
64 *
65 * A usageConstraints dictionary is like so (all elements are optional). These key
66 * strings are defined in SecUserTrust.h.
67 *
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
76 */
77
78 /*
79 * Keys in the top-level dictionary
80 */
81 #define kTrustRecordVersion CFSTR("trustVersion")
82 #define kTrustRecordTrustList CFSTR("trustList")
83
84 /*
85 * Keys in the per-cert dictionary in the TrustedRootList record.
86 */
87 /* value = non-normalized issuer as CFData */
88 #define kTrustRecordIssuer CFSTR("issuerName")
89
90 /* value = serial number as CFData */
91 #define kTrustRecordSerialNumber CFSTR("serialNumber")
92
93 /* value = CFDateRef representation of modification date */
94 #define kTrustRecordModDate CFSTR("modDate")
95
96 /*
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).
101 */
102 #define kTrustRecordTrustSettings CFSTR("trustSettings")
103
104 /*
105 * Version of the top-level dictionary.
106 */
107 enum {
108 kSecTrustRecordVersionInvalid = 0, /* should never be seen on disk */
109 kSecTrustRecordVersionCurrent = 1
110 };
111
112 /*
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).
118 */
119 #define kSecTrustRecordDefaultRootCert CFSTR("kSecTrustRecordDefaultRootCert")
120
121 /*
122 * The location of the system root keychain and its associated TrustSettings.
123 * These are immutable; this module never modifies either of them.
124 */
125 #define SYSTEM_ROOT_STORE_PATH "/System/Library/Keychains/SystemRootCertificates.keychain"
126 #define SYSTEM_TRUST_SETTINGS_PATH "/System/Library/Keychains/SystemTrustSettings.plist"
127
128 /*
129 * The local admin cert store.
130 */
131 #define ADMIN_CERT_STORE_PATH "/Library/Keychains/System.keychain"
132
133 /*
134 * Per-user and local admin TrustSettings are stored in this directory.
135 * Per-user settings are of the form <uuid>.plist.
136 */
137 #define TRUST_SETTINGS_PATH "/Library/Trust Settings"
138 #define ADMIN_TRUST_SETTINGS "Admin.plist"
139
140 /*
141 * Additional values for the SecTrustSettingsDomain enum.
142 */
143 enum {
144 /*
145 * This indicates a TrustSettings that exists only in memory; it
146 * can't be written to disk.
147 */
148 kSecTrustSettingsDomainMemory = 100
149 };
150
151 typedef struct __SecTrustSettings *SecTrustSettingsRef;
152
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);
161
162 /*
163 * Fundamental routine used to ascertain status of one cert.
164 *
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.
172 *
173 * Returns the domain in which a setting was found in *foundDomain.
174 *
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.
178 */
179 OSStatus SecTrustSettingsEvaluateCertificate(
180 SecCertificateRef certificate,
181 SecPolicyRef policy,
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 */
190
191 /*
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).
195 *
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.
200 *
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.
204 *
205 * The external representation is written to the settingOut argument,
206 * which must eventually be CFReleased by the caller.
207 */
208 #if SECTRUST_OSX
209 OSStatus SecTrustSettingsSetTrustSettingsExternal_ios(
210 #else
211 OSStatus SecTrustSettingsSetTrustSettingsExternal(
212 #endif
213 CFDataRef settingsIn, /* optional */
214 SecCertificateRef certRef, /* optional */
215 CFTypeRef trustSettingsDictOrArray, /* optional */
216 CFDataRef *settingsOut); /* RETURNED */
217
218 #if (SECTRUST_OSX && !TARGET_OS_IPHONE)
219 /*
220 * A wrapper around SecTrustSettingsCopyCertificates that combines user and admin
221 * domain outputs.
222 */
223 OSStatus SecTrustSettingsCopyCertificatesForUserAdminDomains(
224 CFArrayRef CF_RETURNS_RETAINED *certArray);
225
226 /*
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.
230 */
231 OSStatus SecTrustSettingsCopyTrustSettings(
232 SecCertificateRef certRef,
233 SecTrustSettingsDomain domain,
234 CFArrayRef * CF_RETURNS_RETAINED trustSettings); /* RETURNED */
235 #endif
236
237 #ifdef __cplusplus
238 }
239 #endif
240
241 #endif /* _SECURITY_SECTRUSTSETTINGSPRIV_H_ */
242