2 * Copyright (c) 2011-2014 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@
23 #ifndef _H_SECASSESSMENT
24 #define _H_SECASSESSMENT
26 #include <CoreFoundation/CoreFoundation.h>
34 * @type SecAccessmentRef An assessment being performed.
36 typedef struct _SecAssessment
*SecAssessmentRef
;
40 * CF-standard type function
42 CFTypeID
SecAssessmentGetTypeID();
46 * Notifications sent when the policy authority database changes.
47 * (Should move to /usr/include/notify_keys.h eventually.)
49 #define kNotifySecAssessmentMasterSwitch "com.apple.security.assessment.masterswitch"
50 #define kNotifySecAssessmentUpdate "com.apple.security.assessment.update"
51 #define kNotifySecAssessmentRecordingChange "com.apple.security.assessment.UIRecordRejectDidChangeNotification"
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.)
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
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.
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
75 Operational flags for SecAssessment calls
77 @type SecAssessmentFlags A mask of flag bits passed to SecAssessment calls to influence their
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 kSecAssessmentFlagIgnoreActiveAssessments Permit parallel re-assessment of the same target.
91 @constant kSecAssessmentFlagLowPriority Run the assessment in low priority.
93 Flags common to multiple calls are assigned from high-bit down. Flags for particular calls
94 are assigned low-bit up, and are documented with that call.
96 typedef uint64_t SecAssessmentFlags
;
98 kSecAssessmentDefaultFlags
= 0, // default behavior
100 kSecAssessmentFlagDirect
= 1 << 30, // in-process evaluation
101 kSecAssessmentFlagAsynchronous
= 1 << 29, // request asynchronous operation
102 kSecAssessmentFlagIgnoreCache
= 1 << 28, // do not search cache
103 kSecAssessmentFlagNoCache
= 1 << 27, // do not populate cache
104 kSecAssessmentFlagEnforce
= 1 << 26, // force on (disable bypass switches)
105 kSecAssessmentFlagAllowWeak
= 1 << 25, // allow weak signatures
106 kSecAssessmentFlagIgnoreWhitelist
= 1 << 24, // do not search weak signature whitelist
107 // 1 << 23 removed (was kSecAssessmentFlagDequarantine)
108 kSecAssessmentFlagIgnoreActiveAssessments
= 1 << 22, // permit parallel re-assessment of the same target
109 kSecAssessmentFlagLowPriority
= 1 << 21, // run the assessment in low priority
114 @function SecAssessmentCreate
115 Ask the system for its assessment of a proposed operation.
117 @param path CFURL describing the file central to the operation - the program
118 to be executed, archive to be installed, plugin to be loaded, etc.
119 @param flags Operation flags and options. Pass kSecAssessmentDefaultFlags for default
121 @param context Optional CFDictionaryRef containing additional information bearing
122 on the requested assessment.
123 @param errors Standard CFError argument for reporting errors. Note that declining to permit
124 the proposed operation is not an error. Inability to arrive at a judgment is.
125 @result On success, a SecAssessment object that can be queried for its outcome.
126 On error, NULL (with *errors set).
130 @constant kSecAssessmentFlagRequestOrigin Request additional work to produce information on
131 the originator (signer) of the object being discussed.
135 @constant kSecAssessmentContextKeyOperation Type of operation (see overview above). This defaults
136 to the kSecAssessmentOperationTypeExecute.
138 extern CFStringRef kSecAssessmentContextKeyUTI
; // caller determination of UTI for primary assessment subject
140 extern CFStringRef kSecAssessmentContextKeyFeedback
; // feedback reporting block
141 typedef Boolean (^SecAssessmentFeedback
)(CFStringRef type
, CFDictionaryRef information
);
142 extern CFStringRef kSecAssessmentFeedbackProgress
; // progress reporting feedback
143 extern CFStringRef kSecAssessmentFeedbackInfoCurrent
; // info key: current work progress
144 extern CFStringRef kSecAssessmentFeedbackInfoTotal
; // info key: total expected work
146 extern CFStringRef kSecAssessmentContextKeyPrimarySignature
; // on document assessment, treat code signature as primary and return its status
148 extern CFStringRef kSecAssessmentAssessmentVerdict
; // CFBooleanRef: master result - allow or deny
149 extern CFStringRef kSecAssessmentAssessmentOriginator
; // CFStringRef: describing the signature originator
150 extern CFStringRef kSecAssessmentAssessmentAuthority
; // CFDictionaryRef: authority used to arrive at result
151 extern CFStringRef kSecAssessmentAssessmentSource
; // CFStringRef: primary source of authority
152 extern CFStringRef kSecAssessmentAssessmentFromCache
; // present if result is from cache
153 extern CFStringRef kSecAssessmentAssessmentWeakSignature
; // present if result attributable to signature weakness
154 extern CFStringRef kSecAssessmentAssessmentCodeSigningError
; // error code returned by code signing API
155 extern CFStringRef kSecAssessmentAssessmentAuthorityRow
; // (internal)
156 extern CFStringRef kSecAssessmentAssessmentAuthorityOverride
; // (internal)
157 extern CFStringRef kSecAssessmentAssessmentAuthorityOriginalVerdict
; // (internal)
158 extern CFStringRef kSecAssessmentAssessmentAuthorityFlags
; // (internal)
160 extern CFStringRef kDisabledOverride
; // AuthorityOverride value for "Gatekeeper is disabled"
163 kSecAssessmentFlagRequestOrigin
= 1 << 0, // request origin information (slower)
166 SecAssessmentRef
SecAssessmentCreate(CFURLRef path
,
167 SecAssessmentFlags flags
,
168 CFDictionaryRef context
,
173 @function SecAssessmentCopyResult
175 Extract results from a completed assessment and return them as a CFDictionary.
177 @param assessment A SecAssessmentRef created with SecAssessmentCreate.
178 @param flags Operation flags and options. Pass kSecAssessmentDefaultFlags for default
180 @errors Standard CFError argument for reporting errors. Note that declining to permit
181 the proposed operation is not an error. Inability to form a judgment is.
182 @result On success, a CFDictionary describing the outcome and various corroborating
183 data as requested by flags. The caller owns this dictionary and should release it
184 when done with it. On error, NULL (with *errors set).
186 Assessment result keys (dictionary keys returned on success):
188 @constant kSecAssessmentAssessmentVerdict A CFBoolean value indicating whether the system policy
189 allows (kCFBooleanTrue) or denies (kCFBooleanFalse) the proposed operation.
190 @constant kSecAssessmentAssessmentAuthority A CFDictionary describing what sources of authority
191 were used to arrive at this result.
192 @constant kSecAssessmentAssessmentOriginator A human-readable CFString describing the originator
193 of the signature securing the subject of the verdict. Requires kSecAssessmentFlagRequireOrigin.
194 May be missing anyway if no reliable source of origin can be determined.
196 CFDictionaryRef
SecAssessmentCopyResult(SecAssessmentRef assessment
,
197 SecAssessmentFlags flags
,
202 @function SecAssessmentCopyUpdate
203 Make changes to the system policy configuration.
205 @param path CFTypeRef describing the subject of the operation. Depending on the operation,
206 this may be a CFURL denoting a (single) file or bundle; a SecRequirement describing
207 a group of files; a CFNumber denoting an existing rule by rule number, or NULL to perform
209 @param flags Operation flags and options. Pass kSecAssessmentDefaultFlags for default
211 @param context Required CFDictionaryRef containing information bearing
212 on the requested assessment. Must at least contain the kSecAssessmentContextKeyEdit key.
213 @param errors Standard CFError argument for reporting errors. Note that declining to permit
214 the proposed operation is not an error. Inability to form a judgment is.
215 @result Returns On success, a CFDictionary containing information pertaining to the completed operation.
216 Caller must CFRelease it when done. On failure, NULL, with *errors set if provided.
218 Note: The SecAssessmentUpdate variant does not return data. It returns True on success, or False on error.
220 Context keys and values:
222 @constant kSecAssessmentContextKeyEdit Required context key describing the kind of change
223 requested to the system policy configuration. Currently understood values:
224 @constant kSecAssessmentUpdateOperationAdd Add a new rule to the assessment rule database.
225 @constant kSecAssessmentUpdateOperationRemove Remove rules from the rule database.
226 @constant kSecAssessmentUpdateOperationEnable (Re)enable rules in the rule database.
227 @constant kSecAssessmentUpdateOperationDisable Disable rules in the rule database.
228 @constant kSecAssessmentUpdateOperationFind Locate and return rules from the rule database.
229 This operation does not change the database, and does not require authorization or privileges.
231 @constant kSecAssessmentUpdateKeyAuthorization A CFData containing the external form of a
232 system AuthorizationRef used to authorize the change. The call will automatically generate
233 a suitable authorization if this is missing; however, if the request is on behalf of
234 another client, an AuthorizationRef should be created there and passed along here.
235 @constant kSecAssessmentUpdateKeyPriority CFNumber denoting a (floating point) priority
236 for the rule(s) being processed.
237 @constant kSecAssessmentUpdateKeyLabel CFString denoting a label string applied to the rule(s)
239 @constant kSecAssessmentUpdateKeyExpires CFDate denoting an (absolute, future) expiration date
240 for rule(s) being processed.
241 @constant kSecAssessmentUpdateKeyAllow CFBoolean denoting whether a new rule allows or denies
242 assessment. The default is to allow; set to kCFBooleanFalse to create a negative (denial) rule.
243 @constant kSecAssessmentUpdateKeyRemarks CFString containing a colloquial description or comment
244 about a newly created rule. This is mean to be human readable and is not used when evaluating rules.
246 Keys returned as the result of a successful kSecAssessmentUpdateOperationFind operation:
248 @constant kSecAssessmentRuleKeyID A CFNumber uniquely identifying a rule.
249 @constant kSecAssessmentRuleKeyPriority A CFNumber indicating the rule's priority.
250 This is a floating point number. Higher values indicate higher priority.
251 @constant kSecAssessmentRuleKeyAllow A CFBoolean indicating whether the rule allows (true) or denies (false) the operation.
252 @constant kSecAssessmentRuleKeyLabel An optional CFString labeling the rule. Multiple rules may have the same label;
253 this can be used to group rules. Labels are not presented to the user. The label has no effect on evaluation.
254 @constant kSecAssessmentRuleKeyRemarks An optional CFString containing user-readable text characterizing the rule's meaning.
255 The remark has no effect on the evaluation.
256 @constant kSecAssessmentRuleKeyRequirement A CFString containing the (text form of) the code requirement governing the rule's match.
257 @constant kSecAssessmentRuleKeyType A CFString denoting the type of operation governed by the rule.
258 One of the kSecAssessmentOperationType* constants.
259 @constant kSecAssessmentRuleKeyExpires A CFDate indicating when the rule expires. Absent if the rule does not expire. Expired rules are never returned.
260 @constant kSecAssessmentRuleKeyDisabled A CFNumber; non zero if temporarily disabled. Optional.
261 @constant kSecAssessmentRuleKeyBookmark A CFData with the bookmark to the rule. Optional.
263 extern CFStringRef kSecAssessmentContextKeyUpdate
; // proposed operation
264 extern CFStringRef kSecAssessmentUpdateOperationAdd
; // add rule to policy database
265 extern CFStringRef kSecAssessmentUpdateOperationRemove
; // remove rule from policy database
266 extern CFStringRef kSecAssessmentUpdateOperationEnable
; // enable rule(s) in policy database
267 extern CFStringRef kSecAssessmentUpdateOperationDisable
; // disable rule(s) in policy database
268 extern CFStringRef kSecAssessmentUpdateOperationFind
; // extract rule(s) from the policy database
270 extern CFStringRef kSecAssessmentUpdateKeyAuthorization
; // [CFData] external form of governing authorization
272 extern CFStringRef kSecAssessmentUpdateKeyPriority
; // rule priority
273 extern CFStringRef kSecAssessmentUpdateKeyLabel
; // rule label
274 extern CFStringRef kSecAssessmentUpdateKeyExpires
; // rule expiration
275 extern CFStringRef kSecAssessmentUpdateKeyAllow
; // rule outcome (allow/deny)
276 extern CFStringRef kSecAssessmentUpdateKeyRemarks
; // rule remarks (human readable)
278 extern CFStringRef kSecAssessmentUpdateKeyRow
; // rule identifier (CFNumber; add only)
279 extern CFStringRef kSecAssessmentUpdateKeyCount
; // count of changed rules (CFNumber)
280 extern CFStringRef kSecAssessmentUpdateKeyFound
; // set of found rules (CFArray of CFDictionaries)
282 extern CFStringRef kSecAssessmentRuleKeyID
; // rule content returned: rule ID
283 extern CFStringRef kSecAssessmentRuleKeyPriority
; // rule content returned: rule priority (floating point)
284 extern CFStringRef kSecAssessmentRuleKeyAllow
; // rule content returned: rule allows (boolean)
285 extern CFStringRef kSecAssessmentRuleKeyLabel
; // rule content returned: rule label (string; optional)
286 extern CFStringRef kSecAssessmentRuleKeyRemarks
; // rule content returned: rule remarks (string; optional)
287 extern CFStringRef kSecAssessmentRuleKeyRequirement
; // rule content returned: rule code requirement (string)
288 extern CFStringRef kSecAssessmentRuleKeyType
; // rule content returned: rule type (string)
289 extern CFStringRef kSecAssessmentRuleKeyExpires
; // rule content returned: rule expiration (CFDate; optional)
290 extern CFStringRef kSecAssessmentRuleKeyDisabled
; // rule content returned: rule disabled (CFNumber; nonzero means temporarily disabled)
291 extern CFStringRef kSecAssessmentRuleKeyBookmark
; // rule content returned: bookmark data (CFBookmark; optional)
293 CFDictionaryRef
SecAssessmentCopyUpdate(CFTypeRef target
,
294 SecAssessmentFlags flags
,
295 CFDictionaryRef context
,
298 Boolean
SecAssessmentUpdate(CFTypeRef target
,
299 SecAssessmentFlags flags
,
300 CFDictionaryRef context
,
305 @function SecAssessmentControl
306 Miscellaneous system policy operations.
308 @param control A CFString indicating which operation is requested.
309 @param arguments Arguments to the operation as documented for control.
310 @param errors Standard CFErrorRef * argument to report errors.
311 @result Returns True on success. Returns False on failure (and sets *errors).
313 Boolean
SecAssessmentControl(CFStringRef control
, void *arguments
, CFErrorRef
*errors
);
320 #endif //_H_SECASSESSMENT