]> git.saurik.com Git - apple/libsecurity_codesigning.git/blob - lib/SecAssessment.h
9cae77543d25b23ecee66f71da7d51b7d6afc69e
[apple/libsecurity_codesigning.git] / lib / SecAssessment.h
1 /*
2 * Copyright (c) 2011 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
52
53 /*!
54 * Primary operation types. These are operations the system policy can express
55 * opinions on. They are not operations *on* the system configuration itself.
56 * (For those, see SecAssessmentUpdate below.)
57 *
58 * @constant kSecAssessmentContextKeyOperation Context key describing the type of operation
59 * being contemplated. The default varies depending on the API call used.
60 * @constant kSecAssessmentOperationTypeExecute Value denoting the operation of running or executing
61 * code on the system.
62 * @constant kSecAssessmentOperationTypeInstall Value denoting the operation of installing
63 * software into the system.
64 * @constant kSecAssessmentOperationTypeOpenDocument Value denoting the operation of opening
65 * (in the LaunchServices sense) of documents.
66 */
67 extern const CFStringRef kSecAssessmentContextKeyOperation; // proposed operation
68 extern const CFStringRef kSecAssessmentOperationTypeExecute; // .. execute code
69 extern const CFStringRef kSecAssessmentOperationTypeInstall; // .. install software
70 extern const CFStringRef kSecAssessmentOperationTypeOpenDocument; // .. LaunchServices-level document open
71
72
73 /*!
74 Operational flags for SecAssessment calls
75
76 @type SecAssessmentFlags A mask of flag bits passed to SecAssessment calls to influence their
77 operation.
78
79 @constant kSecAssessmentDefaultFlags Pass this to indicate that default behavior is desired.
80 @constant kSecAssessmentFlagIgnoreCache Do not use cached information; always perform a full
81 evaluation of system policy. This may be substantially slower.
82 @constant kSecAssessmentFlagNoCache Do not save any evaluation outcome in the system caches.
83 Any content already there is left undisturbed. Independent of kSecAssessmentFlagIgnoreCache.
84 @constant kSecAssessmentFlagEnforce Perform normal operations even if assessments have been
85 globally bypassed (which would usually approve anything).
86
87 Flags common to multiple calls are assigned from high-bit down. Flags for particular calls
88 are assigned low-bit up, and are documented with that call.
89 */
90 typedef uint64_t SecAssessmentFlags;
91 enum {
92 kSecAssessmentDefaultFlags = 0, // default behavior
93
94 kSecAssessmentFlagDirect = 1 << 30, // in-process evaluation
95 kSecAssessmentFlagAsynchronous = 1 << 29, // request asynchronous operation
96 kSecAssessmentFlagIgnoreCache = 1 << 28, // do not search cache
97 kSecAssessmentFlagNoCache = 1 << 27, // do not populate cache
98 kSecAssessmentFlagEnforce = 1 << 26, // force on (disable bypass switches)
99 };
100
101
102 /*!
103 @function SecAssessmentCreate
104 Ask the system for its assessment of a proposed operation.
105
106 @param path CFURL describing the file central to the operation - the program
107 to be executed, archive to be installed, plugin to be loaded, etc.
108 @param flags Operation flags and options. Pass kSecAssessmentDefaultFlags for default
109 behavior.
110 @param context Optional CFDictionaryRef containing additional information bearing
111 on the requested assessment.
112 @param errors Standard CFError argument for reporting errors. Note that declining to permit
113 the proposed operation is not an error. Inability to arrive at a judgment is.
114 @result On success, a SecAssessment object that can be queried for its outcome.
115 On error, NULL (with *errors set).
116
117 Option flags:
118
119 @constant kSecAssessmentFlagRequestOrigin Request additional work to produce information on
120 the originator (signer) of the object being discussed.
121
122 Context keys:
123
124 @constant kSecAssessmentContextKeyOperation Type of operation (see overview above). This defaults
125 to the kSecAssessmentOperationTypeExecute.
126 */
127 extern const CFStringRef kSecAssessmentContextKeyCertificates; // certificate chain as provided by caller
128
129 extern const CFStringRef kSecAssessmentAssessmentVerdict; // CFBooleanRef: master result - allow or deny
130 extern const CFStringRef kSecAssessmentAssessmentOriginator; // CFStringRef: describing the signature originator
131 extern const CFStringRef kSecAssessmentAssessmentAuthority; // CFDictionaryRef: authority used to arrive at result
132 extern const CFStringRef kSecAssessmentAssessmentSource; // CFStringRef: primary source of authority
133 extern const CFStringRef kSecAssessmentAssessmentFromCache; // present if result is from cache
134 extern const CFStringRef kSecAssessmentAssessmentAuthorityRow; // (internal)
135 extern const CFStringRef kSecAssessmentAssessmentAuthorityOverride; // (internal)
136
137 enum {
138 kSecAssessmentFlagRequestOrigin = 1 << 0, // request origin information (slower)
139 };
140
141 SecAssessmentRef SecAssessmentCreate(CFURLRef path,
142 SecAssessmentFlags flags,
143 CFDictionaryRef context,
144 CFErrorRef *errors);
145
146
147 /*!
148 @function SecAssessmentCopyResult
149
150 Extract results from a completed assessment and return them as a CFDictionary.
151
152 @param assessment A SecAssessmentRef created with SecAssessmentCreate.
153 @param flags Operation flags and options. Pass kSecAssessmentDefaultFlags for default
154 behavior.
155 @errors Standard CFError argument for reporting errors. Note that declining to permit
156 the proposed operation is not an error. Inability to form a judgment is.
157 @result On success, a CFDictionary describing the outcome and various corroborating
158 data as requested by flags. The caller owns this dictionary and should release it
159 when done with it. On error, NULL (with *errors set).
160
161 Assessment result keys (dictionary keys returned on success):
162
163 @constant kSecAssessmentAssessmentVerdict A CFBoolean value indicating whether the system policy
164 allows (kCFBooleanTrue) or denies (kCFBooleanFalse) the proposed operation.
165 @constant kSecAssessmentAssessmentAuthority A CFDictionary describing what sources of authority
166 were used to arrive at this result.
167 @constant kSecAssessmentAssessmentOriginator A human-readable CFString describing the originator
168 of the signature securing the subject of the verdict. Requires kSecAssessmentFlagRequireOrigin.
169 May be missing anyway if no reliable source of origin can be determined.
170 */
171 CFDictionaryRef SecAssessmentCopyResult(SecAssessmentRef assessment,
172 SecAssessmentFlags flags,
173 CFErrorRef *errors);
174
175
176 /*!
177 @function SecAssessmentUpdate
178 Make changes to the system policy configuration.
179
180 @param path CFTypeRef describing the subject of the operation. Depending on the operation,
181 this may be a CFURL denoting a (single) file or bundle; a SecRequirement describing
182 a group of files; a CFNumber denoting an existing rule by rule number, or NULL to perform
183 global changes.
184 @param flags Operation flags and options. Pass kSecAssessmentDefaultFlags for default
185 behavior.
186 @param context Required CFDictionaryRef containing information bearing
187 on the requested assessment. Must at least contain the kSecAssessmentContextKeyEdit key.
188 @param errors Standard CFError argument for reporting errors. Note that declining to permit
189 the proposed operation is not an error. Inability to form a judgment is.
190 @result Returns True on success. Returns False on failure (and sets *error).
191
192 Context keys and values:
193
194 @constant kSecAssessmentContextKeyEdit Required context key describing the kind of change
195 requested to the system policy configuration. Currently understood values:
196 @constant kSecAssessmentUpdateOperationAdd Add a new rule to the assessment rule database.
197 @constant kSecAssessmentUpdateOperationRemove Remove rules from the rule database.
198 @constant kSecAssessmentUpdateOperationEnable (Re)enable rules in the rule database.
199 @constant kSecAssessmentUpdateOperationDisable Disable rules in the rule database.
200 @constant kSecAssessmentUpdateKeyAuthorization A CFData containing the external form of a
201 system AuthorizationRef used to authorize the change. The call will automatically generate
202 a suitable authorization if this is missing; however, if the request is on behalf of
203 another client, an AuthorizationRef should be created there and passed along here.
204 @constant kSecAssessmentUpdateKeyPriority CFNumber denoting a (floating point) priority
205 for the rule(s) being processed.
206 @constant kSecAssessmentUpdateKeyLabel CFString denoting a label string applied to the rule(s)
207 being processed.
208 @constant kSecAssessmentUpdateKeyExpires CFDate denoting an (absolute, future) expiration date
209 for rule(s) being processed.
210 @constant kSecAssessmentUpdateKeyAllow CFBoolean denoting whether a new rule allows or denies
211 assessment. The default is to allow; set to kCFBooleanFalse to create a negative (denial) rule.
212 @constant kSecAssessmentUpdateKeyRemarks CFString containing a colloquial description or comment
213 about a newly created rule. This is mean to be human readable and is not used when evaluating rules.
214 */
215 extern const CFStringRef kSecAssessmentContextKeyUpdate; // proposed operation
216 extern const CFStringRef kSecAssessmentUpdateOperationAdd; // add rule to policy database
217 extern const CFStringRef kSecAssessmentUpdateOperationRemove; // remove rule from policy database
218 extern const CFStringRef kSecAssessmentUpdateOperationEnable; // enable rule(s) in policy database
219 extern const CFStringRef kSecAssessmentUpdateOperationDisable; // disable rule(s) in policy database
220
221 extern const CFStringRef kSecAssessmentUpdateKeyAuthorization; // [CFData] external form of governing authorization
222
223 extern const CFStringRef kSecAssessmentUpdateKeyPriority; // rule priority
224 extern const CFStringRef kSecAssessmentUpdateKeyLabel; // rule label
225 extern const CFStringRef kSecAssessmentUpdateKeyExpires; // rule expiration
226 extern const CFStringRef kSecAssessmentUpdateKeyAllow; // rule outcome (allow/deny)
227 extern const CFStringRef kSecAssessmentUpdateKeyRemarks; // rule remarks (human readable)
228
229 extern const CFStringRef kSecAssessmentContextKeyCertificates; // obsolete
230
231 Boolean SecAssessmentUpdate(CFTypeRef target,
232 SecAssessmentFlags flags,
233 CFDictionaryRef context,
234 CFErrorRef *errors);
235
236
237 /*!
238 @function SecAssessmentControl
239 Miscellaneous system policy operations.
240
241 @param control A CFString indicating which operation is requested.
242 @param arguments Arguments to the operation as documented for control.
243 @param errors Standard CFErrorRef * argument to report errors.
244 @result Returns True on success. Returns False on failure (and sets *errors).
245
246 */
247 Boolean SecAssessmentControl(CFStringRef control, void *arguments, CFErrorRef *errors);
248
249
250 #ifdef __cplusplus
251 }
252 #endif
253
254 #endif //_H_SECASSESSMENT