]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_codesigning/lib/SecAssessment.h
Security-57337.50.23.tar.gz
[apple/security.git] / OSX / libsecurity_codesigning / lib / 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 kSecAssessmentContextKeyUTI; // caller determination of UTI for primary assessment subject
140
141 extern CFStringRef kSecAssessmentContextKeyFeedback; // feedback reporting block
142 typedef Boolean (^SecAssessmentFeedback)(CFStringRef type, CFDictionaryRef information);
143 extern CFStringRef kSecAssessmentFeedbackProgress; // progress reporting feedback
144 extern CFStringRef kSecAssessmentFeedbackInfoCurrent; // info key: current work progress
145 extern CFStringRef kSecAssessmentFeedbackInfoTotal; // info key: total expected work
146
147 extern CFStringRef kSecAssessmentAssessmentVerdict; // CFBooleanRef: master result - allow or deny
148 extern CFStringRef kSecAssessmentAssessmentOriginator; // CFStringRef: describing the signature originator
149 extern CFStringRef kSecAssessmentAssessmentAuthority; // CFDictionaryRef: authority used to arrive at result
150 extern CFStringRef kSecAssessmentAssessmentSource; // CFStringRef: primary source of authority
151 extern CFStringRef kSecAssessmentAssessmentFromCache; // present if result is from cache
152 extern CFStringRef kSecAssessmentAssessmentWeakSignature; // present if result attributable to signature weakness
153 extern CFStringRef kSecAssessmentAssessmentCodeSigningError; // error code returned by code signing API
154 extern CFStringRef kSecAssessmentAssessmentAuthorityRow; // (internal)
155 extern CFStringRef kSecAssessmentAssessmentAuthorityOverride; // (internal)
156 extern CFStringRef kSecAssessmentAssessmentAuthorityOriginalVerdict; // (internal)
157
158 extern CFStringRef kDisabledOverride; // AuthorityOverride value for "Gatekeeper is disabled"
159
160 enum {
161 kSecAssessmentFlagRequestOrigin = 1 << 0, // request origin information (slower)
162 };
163
164 SecAssessmentRef SecAssessmentCreate(CFURLRef path,
165 SecAssessmentFlags flags,
166 CFDictionaryRef context,
167 CFErrorRef *errors);
168
169
170 /*!
171 @function SecAssessmentCopyResult
172
173 Extract results from a completed assessment and return them as a CFDictionary.
174
175 @param assessment A SecAssessmentRef created with SecAssessmentCreate.
176 @param flags Operation flags and options. Pass kSecAssessmentDefaultFlags for default
177 behavior.
178 @errors Standard CFError argument for reporting errors. Note that declining to permit
179 the proposed operation is not an error. Inability to form a judgment is.
180 @result On success, a CFDictionary describing the outcome and various corroborating
181 data as requested by flags. The caller owns this dictionary and should release it
182 when done with it. On error, NULL (with *errors set).
183
184 Assessment result keys (dictionary keys returned on success):
185
186 @constant kSecAssessmentAssessmentVerdict A CFBoolean value indicating whether the system policy
187 allows (kCFBooleanTrue) or denies (kCFBooleanFalse) the proposed operation.
188 @constant kSecAssessmentAssessmentAuthority A CFDictionary describing what sources of authority
189 were used to arrive at this result.
190 @constant kSecAssessmentAssessmentOriginator A human-readable CFString describing the originator
191 of the signature securing the subject of the verdict. Requires kSecAssessmentFlagRequireOrigin.
192 May be missing anyway if no reliable source of origin can be determined.
193 */
194 CFDictionaryRef SecAssessmentCopyResult(SecAssessmentRef assessment,
195 SecAssessmentFlags flags,
196 CFErrorRef *errors);
197
198
199 /*!
200 @function SecAssessmentCopyUpdate
201 Make changes to the system policy configuration.
202
203 @param path CFTypeRef describing the subject of the operation. Depending on the operation,
204 this may be a CFURL denoting a (single) file or bundle; a SecRequirement describing
205 a group of files; a CFNumber denoting an existing rule by rule number, or NULL to perform
206 global changes.
207 @param flags Operation flags and options. Pass kSecAssessmentDefaultFlags for default
208 behavior.
209 @param context Required CFDictionaryRef containing information bearing
210 on the requested assessment. Must at least contain the kSecAssessmentContextKeyEdit key.
211 @param errors Standard CFError argument for reporting errors. Note that declining to permit
212 the proposed operation is not an error. Inability to form a judgment is.
213 @result Returns On success, a CFDictionary containing information pertaining to the completed operation.
214 Caller must CFRelease it when done. On failure, NULL, with *errors set if provided.
215
216 Note: The SecAssessmentUpdate variant does not return data. It returns True on success, or False on error.
217
218 Context keys and values:
219
220 @constant kSecAssessmentContextKeyEdit Required context key describing the kind of change
221 requested to the system policy configuration. Currently understood values:
222 @constant kSecAssessmentUpdateOperationAdd Add a new rule to the assessment rule database.
223 @constant kSecAssessmentUpdateOperationRemove Remove rules from the rule database.
224 @constant kSecAssessmentUpdateOperationEnable (Re)enable rules in the rule database.
225 @constant kSecAssessmentUpdateOperationDisable Disable rules in the rule database.
226 @constant kSecAssessmentUpdateOperationFind Locate and return rules from the rule database.
227 This operation does not change the database, and does not require authorization or privileges.
228
229 @constant kSecAssessmentUpdateKeyAuthorization A CFData containing the external form of a
230 system AuthorizationRef used to authorize the change. The call will automatically generate
231 a suitable authorization if this is missing; however, if the request is on behalf of
232 another client, an AuthorizationRef should be created there and passed along here.
233 @constant kSecAssessmentUpdateKeyPriority CFNumber denoting a (floating point) priority
234 for the rule(s) being processed.
235 @constant kSecAssessmentUpdateKeyLabel CFString denoting a label string applied to the rule(s)
236 being processed.
237 @constant kSecAssessmentUpdateKeyExpires CFDate denoting an (absolute, future) expiration date
238 for rule(s) being processed.
239 @constant kSecAssessmentUpdateKeyAllow CFBoolean denoting whether a new rule allows or denies
240 assessment. The default is to allow; set to kCFBooleanFalse to create a negative (denial) rule.
241 @constant kSecAssessmentUpdateKeyRemarks CFString containing a colloquial description or comment
242 about a newly created rule. This is mean to be human readable and is not used when evaluating rules.
243
244 Keys returned as the result of a successful kSecAssessmentUpdateOperationFind operation:
245
246 @constant kSecAssessmentRuleKeyID A CFNumber uniquely identifying a rule.
247 @constant kSecAssessmentRuleKeyPriority A CFNumber indicating the rule's priority.
248 This is a floating point number. Higher values indicate higher priority.
249 @constant kSecAssessmentRuleKeyAllow A CFBoolean indicating whether the rule allows (true) or denies (false) the operation.
250 @constant kSecAssessmentRuleKeyLabel An optional CFString labeling the rule. Multiple rules may have the same label;
251 this can be used to group rules. Labels are not presented to the user. The label has no effect on evaluation.
252 @constant kSecAssessmentRuleKeyRemarks An optional CFString containing user-readable text characterizing the rule's meaning.
253 The remark has no effect on the evaluation.
254 @constant kSecAssessmentRuleKeyRequirement A CFString containing the (text form of) the code requirement governing the rule's match.
255 @constant kSecAssessmentRuleKeyType A CFString denoting the type of operation governed by the rule.
256 One of the kSecAssessmentOperationType* constants.
257 @constant kSecAssessmentRuleKeyExpires A CFDate indicating when the rule expires. Absent if the rule does not expire. Expired rules are never returned.
258 @constant kSecAssessmentRuleKeyDisabled A CFNumber; non zero if temporarily disabled. Optional.
259 @constant kSecAssessmentRuleKeyBookmark A CFData with the bookmark to the rule. Optional.
260 */
261 extern CFStringRef kSecAssessmentContextKeyUpdate; // proposed operation
262 extern CFStringRef kSecAssessmentUpdateOperationAdd; // add rule to policy database
263 extern CFStringRef kSecAssessmentUpdateOperationRemove; // remove rule from policy database
264 extern CFStringRef kSecAssessmentUpdateOperationEnable; // enable rule(s) in policy database
265 extern CFStringRef kSecAssessmentUpdateOperationDisable; // disable rule(s) in policy database
266 extern CFStringRef kSecAssessmentUpdateOperationFind; // extract rule(s) from the policy database
267
268 extern CFStringRef kSecAssessmentUpdateKeyAuthorization; // [CFData] external form of governing authorization
269
270 extern CFStringRef kSecAssessmentUpdateKeyPriority; // rule priority
271 extern CFStringRef kSecAssessmentUpdateKeyLabel; // rule label
272 extern CFStringRef kSecAssessmentUpdateKeyExpires; // rule expiration
273 extern CFStringRef kSecAssessmentUpdateKeyAllow; // rule outcome (allow/deny)
274 extern CFStringRef kSecAssessmentUpdateKeyRemarks; // rule remarks (human readable)
275
276 extern CFStringRef kSecAssessmentUpdateKeyRow; // rule identifier (CFNumber; add only)
277 extern CFStringRef kSecAssessmentUpdateKeyCount; // count of changed rules (CFNumber)
278 extern CFStringRef kSecAssessmentUpdateKeyFound; // set of found rules (CFArray of CFDictionaries)
279
280 extern CFStringRef kSecAssessmentRuleKeyID; // rule content returned: rule ID
281 extern CFStringRef kSecAssessmentRuleKeyPriority; // rule content returned: rule priority (floating point)
282 extern CFStringRef kSecAssessmentRuleKeyAllow; // rule content returned: rule allows (boolean)
283 extern CFStringRef kSecAssessmentRuleKeyLabel; // rule content returned: rule label (string; optional)
284 extern CFStringRef kSecAssessmentRuleKeyRemarks; // rule content returned: rule remarks (string; optional)
285 extern CFStringRef kSecAssessmentRuleKeyRequirement; // rule content returned: rule code requirement (string)
286 extern CFStringRef kSecAssessmentRuleKeyType; // rule content returned: rule type (string)
287 extern CFStringRef kSecAssessmentRuleKeyExpires; // rule content returned: rule expiration (CFDate; optional)
288 extern CFStringRef kSecAssessmentRuleKeyDisabled; // rule content returned: rule disabled (CFNumber; nonzero means temporarily disabled)
289 extern CFStringRef kSecAssessmentRuleKeyBookmark; // rule content returned: bookmark data (CFBookmark; optional)
290
291 CFDictionaryRef SecAssessmentCopyUpdate(CFTypeRef target,
292 SecAssessmentFlags flags,
293 CFDictionaryRef context,
294 CFErrorRef *errors);
295
296 Boolean SecAssessmentUpdate(CFTypeRef target,
297 SecAssessmentFlags flags,
298 CFDictionaryRef context,
299 CFErrorRef *errors);
300
301
302 /*!
303 @function SecAssessmentControl
304 Miscellaneous system policy operations.
305
306 @param control A CFString indicating which operation is requested.
307 @param arguments Arguments to the operation as documented for control.
308 @param errors Standard CFErrorRef * argument to report errors.
309 @result Returns True on success. Returns False on failure (and sets *errors).
310 */
311 Boolean SecAssessmentControl(CFStringRef control, void *arguments, CFErrorRef *errors);
312
313
314 #ifdef __cplusplus
315 }
316 #endif
317
318 #endif //_H_SECASSESSMENT