]> git.saurik.com Git - apple/security.git/blob - OSX/include/security_codesigning/SecAssessment.h
Security-57336.1.9.tar.gz
[apple/security.git] / OSX / include / security_codesigning / SecAssessment.h
1 /*
2 * Copyright (c) 2011-2014 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 #ifndef _H_SECASSESSMENT
24 #define _H_SECASSESSMENT
25
26 #include <CoreFoundation/CoreFoundation.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32
33 /*!
34 * @type SecAccessmentRef An assessment being performed.
35 */
36 typedef struct _SecAssessment *SecAssessmentRef;
37
38
39 /*!
40 * CF-standard type function
41 */
42 CFTypeID SecAssessmentGetTypeID();
43
44
45 /*
46 * Notifications sent when the policy authority database changes.
47 * (Should move to /usr/include/notify_keys.h eventually.)
48 */
49 #define kNotifySecAssessmentMasterSwitch "com.apple.security.assessment.masterswitch"
50 #define kNotifySecAssessmentUpdate "com.apple.security.assessment.update"
51 #define kNotifySecAssessmentRecordingChange "com.apple.security.assessment.UIRecordRejectDidChangeNotification"
52
53
54 /*!
55 * Primary operation types. These are operations the system policy can express
56 * opinions on. They are not operations *on* the system configuration itself.
57 * (For those, see SecAssessmentUpdate below.)
58 *
59 * @constant kSecAssessmentContextKeyOperation Context key describing the type of operation
60 * being contemplated. The default varies depending on the API call used.
61 * @constant kSecAssessmentOperationTypeExecute Value denoting the operation of running or executing
62 * code on the system.
63 * @constant kSecAssessmentOperationTypeInstall Value denoting the operation of installing
64 * software into the system.
65 * @constant kSecAssessmentOperationTypeOpenDocument Value denoting the operation of opening
66 * (in the LaunchServices sense) of documents.
67 */
68 extern CFStringRef kSecAssessmentContextKeyOperation; // proposed operation
69 extern CFStringRef kSecAssessmentOperationTypeExecute; // .. execute code
70 extern CFStringRef kSecAssessmentOperationTypeInstall; // .. install software
71 extern CFStringRef kSecAssessmentOperationTypeOpenDocument; // .. LaunchServices-level document open
72
73
74 /*!
75 Operational flags for SecAssessment calls
76
77 @type SecAssessmentFlags A mask of flag bits passed to SecAssessment calls to influence their
78 operation.
79
80 @constant kSecAssessmentDefaultFlags Pass this to indicate that default behavior is desired.
81 @constant kSecAssessmentFlagIgnoreCache Do not use cached information; always perform a full
82 evaluation of system policy. This may be substantially slower.
83 @constant kSecAssessmentFlagNoCache Do not save any evaluation outcome in the system caches.
84 Any content already there is left undisturbed. Independent of kSecAssessmentFlagIgnoreCache.
85 @constant kSecAssessmentFlagEnforce Perform normal operations even if assessments have been
86 globally bypassed (which would usually approve anything).
87 @constant kSecAssessmentAllowWeak Allow signatures that contain known weaknesses, such as an
88 insecure resource envelope.
89 @constant kSecAssessmentIgnoreWhitelist Do not search the weak signature whitelist.
90 @constant kSecAssessmentFlagDequarantine Set the ASSESSMENT_OK flag if successful.
91 @constant kSecAssessmentFlagIgnoreActiveAssessments Permit parallel re-assessment of the same target.
92 @constant kSecAssessmentFlagLowPriority Run the assessment in low priority.
93
94 Flags common to multiple calls are assigned from high-bit down. Flags for particular calls
95 are assigned low-bit up, and are documented with that call.
96 */
97 typedef uint64_t SecAssessmentFlags;
98 enum {
99 kSecAssessmentDefaultFlags = 0, // default behavior
100
101 kSecAssessmentFlagDirect = 1 << 30, // in-process evaluation
102 kSecAssessmentFlagAsynchronous = 1 << 29, // request asynchronous operation
103 kSecAssessmentFlagIgnoreCache = 1 << 28, // do not search cache
104 kSecAssessmentFlagNoCache = 1 << 27, // do not populate cache
105 kSecAssessmentFlagEnforce = 1 << 26, // force on (disable bypass switches)
106 kSecAssessmentFlagAllowWeak = 1 << 25, // allow weak signatures
107 kSecAssessmentFlagIgnoreWhitelist = 1 << 24, // do not search weak signature whitelist
108 kSecAssessmentFlagDequarantine = 1 << 23, // set the ASSESSMENT_OK flag if successful
109 kSecAssessmentFlagIgnoreActiveAssessments = 1 << 22, // permit parallel re-assessment of the same target
110 kSecAssessmentFlagLowPriority = 1 << 21, // run the assessment in low priority
111 };
112
113
114 /*!
115 @function SecAssessmentCreate
116 Ask the system for its assessment of a proposed operation.
117
118 @param path CFURL describing the file central to the operation - the program
119 to be executed, archive to be installed, plugin to be loaded, etc.
120 @param flags Operation flags and options. Pass kSecAssessmentDefaultFlags for default
121 behavior.
122 @param context Optional CFDictionaryRef containing additional information bearing
123 on the requested assessment.
124 @param errors Standard CFError argument for reporting errors. Note that declining to permit
125 the proposed operation is not an error. Inability to arrive at a judgment is.
126 @result On success, a SecAssessment object that can be queried for its outcome.
127 On error, NULL (with *errors set).
128
129 Option flags:
130
131 @constant kSecAssessmentFlagRequestOrigin Request additional work to produce information on
132 the originator (signer) of the object being discussed.
133
134 Context keys:
135
136 @constant kSecAssessmentContextKeyOperation Type of operation (see overview above). This defaults
137 to the kSecAssessmentOperationTypeExecute.
138 */
139 extern CFStringRef kSecAssessmentContextKeyFeedback; // feedback reporting block
140 typedef Boolean (^SecAssessmentFeedback)(CFStringRef type, CFDictionaryRef information);
141 extern CFStringRef kSecAssessmentFeedbackProgress; // progress reporting feedback
142 extern CFStringRef kSecAssessmentFeedbackInfoCurrent; // info key: current work progress
143 extern CFStringRef kSecAssessmentFeedbackInfoTotal; // info key: total expected work
144
145 extern CFStringRef kSecAssessmentAssessmentVerdict; // CFBooleanRef: master result - allow or deny
146 extern CFStringRef kSecAssessmentAssessmentOriginator; // CFStringRef: describing the signature originator
147 extern CFStringRef kSecAssessmentAssessmentAuthority; // CFDictionaryRef: authority used to arrive at result
148 extern CFStringRef kSecAssessmentAssessmentSource; // CFStringRef: primary source of authority
149 extern CFStringRef kSecAssessmentAssessmentFromCache; // present if result is from cache
150 extern CFStringRef kSecAssessmentAssessmentWeakSignature; // present if result attributable to signature weakness
151 extern CFStringRef kSecAssessmentAssessmentCodeSigningError; // error code returned by code signing API
152 extern CFStringRef kSecAssessmentAssessmentAuthorityRow; // (internal)
153 extern CFStringRef kSecAssessmentAssessmentAuthorityOverride; // (internal)
154 extern CFStringRef kSecAssessmentAssessmentAuthorityOriginalVerdict; // (internal)
155
156 extern CFStringRef kDisabledOverride; // AuthorityOverride value for "Gatekeeper is disabled"
157
158 enum {
159 kSecAssessmentFlagRequestOrigin = 1 << 0, // request origin information (slower)
160 };
161
162 SecAssessmentRef SecAssessmentCreate(CFURLRef path,
163 SecAssessmentFlags flags,
164 CFDictionaryRef context,
165 CFErrorRef *errors);
166
167
168 /*!
169 @function SecAssessmentCopyResult
170
171 Extract results from a completed assessment and return them as a CFDictionary.
172
173 @param assessment A SecAssessmentRef created with SecAssessmentCreate.
174 @param flags Operation flags and options. Pass kSecAssessmentDefaultFlags for default
175 behavior.
176 @errors Standard CFError argument for reporting errors. Note that declining to permit
177 the proposed operation is not an error. Inability to form a judgment is.
178 @result On success, a CFDictionary describing the outcome and various corroborating
179 data as requested by flags. The caller owns this dictionary and should release it
180 when done with it. On error, NULL (with *errors set).
181
182 Assessment result keys (dictionary keys returned on success):
183
184 @constant kSecAssessmentAssessmentVerdict A CFBoolean value indicating whether the system policy
185 allows (kCFBooleanTrue) or denies (kCFBooleanFalse) the proposed operation.
186 @constant kSecAssessmentAssessmentAuthority A CFDictionary describing what sources of authority
187 were used to arrive at this result.
188 @constant kSecAssessmentAssessmentOriginator A human-readable CFString describing the originator
189 of the signature securing the subject of the verdict. Requires kSecAssessmentFlagRequireOrigin.
190 May be missing anyway if no reliable source of origin can be determined.
191 */
192 CFDictionaryRef SecAssessmentCopyResult(SecAssessmentRef assessment,
193 SecAssessmentFlags flags,
194 CFErrorRef *errors);
195
196
197 /*!
198 @function SecAssessmentCopyUpdate
199 Make changes to the system policy configuration.
200
201 @param path CFTypeRef describing the subject of the operation. Depending on the operation,
202 this may be a CFURL denoting a (single) file or bundle; a SecRequirement describing
203 a group of files; a CFNumber denoting an existing rule by rule number, or NULL to perform
204 global changes.
205 @param flags Operation flags and options. Pass kSecAssessmentDefaultFlags for default
206 behavior.
207 @param context Required CFDictionaryRef containing information bearing
208 on the requested assessment. Must at least contain the kSecAssessmentContextKeyEdit key.
209 @param errors Standard CFError argument for reporting errors. Note that declining to permit
210 the proposed operation is not an error. Inability to form a judgment is.
211 @result Returns On success, a CFDictionary containing information pertaining to the completed operation.
212 Caller must CFRelease it when done. On failure, NULL, with *errors set if provided.
213
214 Note: The SecAssessmentUpdate variant does not return data. It returns True on success, or False on error.
215
216 Context keys and values:
217
218 @constant kSecAssessmentContextKeyEdit Required context key describing the kind of change
219 requested to the system policy configuration. Currently understood values:
220 @constant kSecAssessmentUpdateOperationAdd Add a new rule to the assessment rule database.
221 @constant kSecAssessmentUpdateOperationRemove Remove rules from the rule database.
222 @constant kSecAssessmentUpdateOperationEnable (Re)enable rules in the rule database.
223 @constant kSecAssessmentUpdateOperationDisable Disable rules in the rule database.
224 @constant kSecAssessmentUpdateOperationFind Locate and return rules from the rule database.
225 This operation does not change the database, and does not require authorization or privileges.
226
227 @constant kSecAssessmentUpdateKeyAuthorization A CFData containing the external form of a
228 system AuthorizationRef used to authorize the change. The call will automatically generate
229 a suitable authorization if this is missing; however, if the request is on behalf of
230 another client, an AuthorizationRef should be created there and passed along here.
231 @constant kSecAssessmentUpdateKeyPriority CFNumber denoting a (floating point) priority
232 for the rule(s) being processed.
233 @constant kSecAssessmentUpdateKeyLabel CFString denoting a label string applied to the rule(s)
234 being processed.
235 @constant kSecAssessmentUpdateKeyExpires CFDate denoting an (absolute, future) expiration date
236 for rule(s) being processed.
237 @constant kSecAssessmentUpdateKeyAllow CFBoolean denoting whether a new rule allows or denies
238 assessment. The default is to allow; set to kCFBooleanFalse to create a negative (denial) rule.
239 @constant kSecAssessmentUpdateKeyRemarks CFString containing a colloquial description or comment
240 about a newly created rule. This is mean to be human readable and is not used when evaluating rules.
241
242 Keys returned as the result of a successful kSecAssessmentUpdateOperationFind operation:
243
244 @constant kSecAssessmentRuleKeyID A CFNumber uniquely identifying a rule.
245 @constant kSecAssessmentRuleKeyPriority A CFNumber indicating the rule's priority.
246 This is a floating point number. Higher values indicate higher priority.
247 @constant kSecAssessmentRuleKeyAllow A CFBoolean indicating whether the rule allows (true) or denies (false) the operation.
248 @constant kSecAssessmentRuleKeyLabel An optional CFString labeling the rule. Multiple rules may have the same label;
249 this can be used to group rules. Labels are not presented to the user. The label has no effect on evaluation.
250 @constant kSecAssessmentRuleKeyRemarks An optional CFString containing user-readable text characterizing the rule's meaning.
251 The remark has no effect on the evaluation.
252 @constant kSecAssessmentRuleKeyRequirement A CFString containing the (text form of) the code requirement governing the rule's match.
253 @constant kSecAssessmentRuleKeyType A CFString denoting the type of operation governed by the rule.
254 One of the kSecAssessmentOperationType* constants.
255 @constant kSecAssessmentRuleKeyExpires A CFDate indicating when the rule expires. Absent if the rule does not expire. Expired rules are never returned.
256 @constant kSecAssessmentRuleKeyDisabled A CFNumber; non zero if temporarily disabled. Optional.
257 @constant kSecAssessmentRuleKeyBookmark A CFData with the bookmark to the rule. Optional.
258 */
259 extern CFStringRef kSecAssessmentContextKeyUpdate; // proposed operation
260 extern CFStringRef kSecAssessmentUpdateOperationAdd; // add rule to policy database
261 extern CFStringRef kSecAssessmentUpdateOperationRemove; // remove rule from policy database
262 extern CFStringRef kSecAssessmentUpdateOperationEnable; // enable rule(s) in policy database
263 extern CFStringRef kSecAssessmentUpdateOperationDisable; // disable rule(s) in policy database
264 extern CFStringRef kSecAssessmentUpdateOperationFind; // extract rule(s) from the policy database
265
266 extern CFStringRef kSecAssessmentUpdateKeyAuthorization; // [CFData] external form of governing authorization
267
268 extern CFStringRef kSecAssessmentUpdateKeyPriority; // rule priority
269 extern CFStringRef kSecAssessmentUpdateKeyLabel; // rule label
270 extern CFStringRef kSecAssessmentUpdateKeyExpires; // rule expiration
271 extern CFStringRef kSecAssessmentUpdateKeyAllow; // rule outcome (allow/deny)
272 extern CFStringRef kSecAssessmentUpdateKeyRemarks; // rule remarks (human readable)
273
274 extern CFStringRef kSecAssessmentUpdateKeyRow; // rule identifier (CFNumber; add only)
275 extern CFStringRef kSecAssessmentUpdateKeyCount; // count of changed rules (CFNumber)
276 extern CFStringRef kSecAssessmentUpdateKeyFound; // set of found rules (CFArray of CFDictionaries)
277
278 extern CFStringRef kSecAssessmentRuleKeyID; // rule content returned: rule ID
279 extern CFStringRef kSecAssessmentRuleKeyPriority; // rule content returned: rule priority (floating point)
280 extern CFStringRef kSecAssessmentRuleKeyAllow; // rule content returned: rule allows (boolean)
281 extern CFStringRef kSecAssessmentRuleKeyLabel; // rule content returned: rule label (string; optional)
282 extern CFStringRef kSecAssessmentRuleKeyRemarks; // rule content returned: rule remarks (string; optional)
283 extern CFStringRef kSecAssessmentRuleKeyRequirement; // rule content returned: rule code requirement (string)
284 extern CFStringRef kSecAssessmentRuleKeyType; // rule content returned: rule type (string)
285 extern CFStringRef kSecAssessmentRuleKeyExpires; // rule content returned: rule expiration (CFDate; optional)
286 extern CFStringRef kSecAssessmentRuleKeyDisabled; // rule content returned: rule disabled (CFNumber; nonzero means temporarily disabled)
287 extern CFStringRef kSecAssessmentRuleKeyBookmark; // rule content returned: bookmark data (CFBookmark; optional)
288
289 CFDictionaryRef SecAssessmentCopyUpdate(CFTypeRef target,
290 SecAssessmentFlags flags,
291 CFDictionaryRef context,
292 CFErrorRef *errors);
293
294 Boolean SecAssessmentUpdate(CFTypeRef target,
295 SecAssessmentFlags flags,
296 CFDictionaryRef context,
297 CFErrorRef *errors);
298
299
300 /*!
301 @function SecAssessmentControl
302 Miscellaneous system policy operations.
303
304 @param control A CFString indicating which operation is requested.
305 @param arguments Arguments to the operation as documented for control.
306 @param errors Standard CFErrorRef * argument to report errors.
307 @result Returns True on success. Returns False on failure (and sets *errors).
308 */
309 Boolean SecAssessmentControl(CFStringRef control, void *arguments, CFErrorRef *errors);
310
311
312 #ifdef __cplusplus
313 }
314 #endif
315
316 #endif //_H_SECASSESSMENT