]>
Commit | Line | Data |
---|---|---|
7d31e928 | 1 | /* |
f60086fc | 2 | * Copyright (c) 2006-2010 Apple Inc. All Rights Reserved. |
7d31e928 A |
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 | @header CSCommon | |
26 | CSCommon is the common header of all Code Signing API headers. | |
27 | It defines types, constants, and error codes. | |
28 | */ | |
29 | #ifndef _H_CSCOMMON | |
30 | #define _H_CSCOMMON | |
31 | ||
32 | #ifdef __cplusplus | |
33 | extern "C" { | |
34 | #endif | |
35 | ||
36 | #include <stdint.h> | |
37 | #include <CoreFoundation/CoreFoundation.h> | |
38 | ||
39 | ||
40 | /* | |
41 | Code Signing specific OSStatus codes. | |
42 | [Assigned range 0xFFFE_FAxx]. | |
43 | */ | |
44 | enum { | |
f60086fc A |
45 | errSecCSUnimplemented = -67072, /* unimplemented code signing feature */ |
46 | errSecCSInvalidObjectRef = -67071, /* invalid API object reference */ | |
47 | errSecCSInvalidFlags = -67070, /* invalid or inappropriate API flag(s) specified */ | |
48 | errSecCSObjectRequired = -67069, /* a required pointer argument was NULL */ | |
49 | errSecCSStaticCodeNotFound = -67068, /* cannot find code object on disk */ | |
50 | errSecCSUnsupportedGuestAttributes = -67067, /* cannot locate guests using this attribute set */ | |
51 | errSecCSInvalidAttributeValues = -67066, /* given attribute values are invalid */ | |
52 | errSecCSNoSuchCode = -67065, /* host has no guest with the requested attributes */ | |
53 | errSecCSMultipleGuests = -67064, /* ambiguous guest specification (host has multiple guests with these attribute values) */ | |
54 | errSecCSGuestInvalid = -67063, /* code identity has been invalidated */ | |
55 | errSecCSUnsigned = -67062, /* code object is not signed at all */ | |
56 | errSecCSSignatureFailed = -67061, /* invalid signature (code or signature have been modified) */ | |
57 | errSecCSSignatureNotVerifiable = -67060, /* the code cannot be read by the verifier (file system permissions etc.) */ | |
58 | errSecCSSignatureUnsupported = -67059, /* unsupported type or version of signature */ | |
59 | errSecCSBadDictionaryFormat = -67058, /* a required plist file or resource is malformed */ | |
60 | errSecCSResourcesNotSealed = -67057, /* resources are present but not sealed by signature */ | |
61 | errSecCSResourcesNotFound = -67056, /* code has no resources but signature indicates they must be present */ | |
62 | errSecCSResourcesInvalid = -67055, /* the sealed resource directory is invalid */ | |
63 | errSecCSBadResource = -67054, /* a sealed resource is missing or invalid */ | |
64 | errSecCSResourceRulesInvalid = -67053, /* invalid resource specification rule(s) */ | |
65 | errSecCSReqInvalid = -67052, /* invalid or corrupted code requirement(s) */ | |
66 | errSecCSReqUnsupported = -67051, /* unsupported type or version of code requirement(s) */ | |
67 | errSecCSReqFailed = -67050, /* code failed to satisfy specified code requirement(s) */ | |
68 | errSecCSBadObjectFormat = -67049, /* object file format unrecognized, invalid, or unsuitable */ | |
69 | errSecCSInternalError = -67048, /* internal error in Code Signing subsystem */ | |
70 | errSecCSHostReject = -67047, /* code rejected its host */ | |
71 | errSecCSNotAHost = -67046, /* attempt to specify guest of code that is not a host */ | |
72 | errSecCSSignatureInvalid = -67045, /* invalid or unsupported format for signature */ | |
73 | errSecCSHostProtocolRelativePath = -67044, /* host protocol violation - absolute guest path required */ | |
74 | errSecCSHostProtocolContradiction = -67043, /* host protocol violation - contradictory hosting modes */ | |
75 | errSecCSHostProtocolDedicationError = -67042, /* host protocol violation - operation not allowed with/for a dedicated guest */ | |
76 | errSecCSHostProtocolNotProxy = -67041, /* host protocol violation - proxy hosting not engaged */ | |
77 | errSecCSHostProtocolStateError = -67040, /* host protocol violation - invalid guest state change request */ | |
78 | errSecCSHostProtocolUnrelated = -67039, /* host protocol violation - the given guest is not a guest of the given host */ | |
79 | /* -67038 obsolete (no longer issued) */ | |
80 | errSecCSNotSupported = -67037, /* operation inapplicable or not supported for this type of code */ | |
81 | errSecCSCMSTooLarge = -67036, /* signature too large to embed (size limitation of on-disk representation) */ | |
82 | errSecCSHostProtocolInvalidHash = -67035, /* host protocol violation - invalid guest hash */ | |
83 | errSecCSStaticCodeChanged = -67034, /* the code on disk does not match what is running */ | |
84 | errSecCSDBDenied = -67033, /* permission to use a database denied */ | |
85 | errSecCSDBAccess = -67032, /* cannot access a database */ | |
86 | errSecCSSigDBDenied = errSecCSDBDenied, | |
87 | errSecCSSigDBAccess = errSecCSDBAccess, | |
88 | errSecCSHostProtocolInvalidAttribute = -67031, /* host returned invalid or inconsistent guest attributes */ | |
89 | errSecCSInfoPlistFailed = -67030, /* invalid Info.plist (plist or signature have been modified) */ | |
90 | errSecCSNoMainExecutable = -67029, /* the code has no main executable file */ | |
91 | errSecCSBadBundleFormat = -67028, /* bundle format unrecognized, invalid, or unsuitable */ | |
62e4ed3d A |
92 | errSecCSNoMatches = -67027, /* no matches for search or update operation */ |
93 | errSecCSFileHardQuarantined = -67026, /* File created by an AppSandbox, exec/open not allowed */ | |
94 | errSecCSOutdated = -67025, /* presented data is out of date */ | |
95 | errSecCSDbCorrupt = -67024, /* a system database of file is corrupt */ | |
7d31e928 A |
96 | }; |
97 | ||
98 | ||
99 | /* | |
100 | * Code Signing specific CFError "user info" keys. | |
101 | * In calls that can return CFErrorRef indications, if a CFErrorRef is actually | |
f60086fc A |
102 | * returned, its "user info" dictionary may contain some of the following keys |
103 | * to more closely describe the circumstances of the failure. | |
104 | * Do not rely on the presence of any particular key to categorize a problem; | |
105 | * always use the primary OSStatus return for that. The data contained under | |
106 | * these keys is always supplemental and optional. | |
7d31e928 | 107 | */ |
f60086fc | 108 | extern const CFStringRef kSecCFErrorArchitecture; /* CFStringRef: name of architecture causing the problem */ |
7d31e928 A |
109 | extern const CFStringRef kSecCFErrorPattern; /* CFStringRef: invalid resource selection pattern encountered */ |
110 | extern const CFStringRef kSecCFErrorResourceSeal; /* CFTypeRef: invalid component in resource seal (CodeResources) */ | |
111 | extern const CFStringRef kSecCFErrorResourceAdded; /* CFURLRef: unsealed resource found */ | |
112 | extern const CFStringRef kSecCFErrorResourceAltered; /* CFURLRef: modified resource found */ | |
113 | extern const CFStringRef kSecCFErrorResourceMissing; /* CFURLRef: sealed (non-optional) resource missing */ | |
f60086fc | 114 | extern const CFStringRef kSecCFErrorInfoPlist; /* CFTypeRef: Info.plist dictionary or component thereof found invalid */ |
7d31e928 A |
115 | extern const CFStringRef kSecCFErrorGuestAttributes; /* CFTypeRef: Guest attribute set of element not accepted */ |
116 | extern const CFStringRef kSecCFErrorRequirementSyntax; /* CFStringRef: compilation error for Requirement source */ | |
f60086fc | 117 | extern const CFStringRef kSecCFErrorPath; /* CFURLRef: subcomponent containing the error */ |
7d31e928 A |
118 | |
119 | ||
120 | /*! | |
121 | @typedef SecCodeRef | |
122 | This is the type of a reference to running code. | |
123 | ||
124 | In many (but not all) calls, this can be passed to a SecStaticCodeRef | |
125 | argument, which performs an implicit SecCodeCopyStaticCode call and | |
126 | operates on the result. | |
127 | */ | |
128 | typedef struct __SecCode *SecCodeRef; /* running code */ | |
129 | ||
130 | /*! | |
131 | @typedef SecStaticCodeRef | |
132 | This is the type of a reference to static code on disk. | |
133 | */ | |
134 | typedef struct __SecCode const *SecStaticCodeRef; /* code on disk */ | |
135 | ||
136 | /*! | |
137 | @typedef SecRequirementRef | |
138 | This is the type of a reference to a code requirement. | |
139 | */ | |
140 | typedef struct __SecRequirement *SecRequirementRef; /* code requirement */ | |
141 | ||
142 | ||
143 | /*! | |
144 | @typedef SecGuestRef | |
145 | An abstract handle to identify a particular Guest in the context of its Host. | |
146 | ||
147 | Guest handles are assigned by the host at will, with kSecNoGuest (zero) being | |
d1c1ab47 | 148 | reserved as the null value. They can be reused for new children if desired. |
7d31e928 A |
149 | */ |
150 | typedef u_int32_t SecGuestRef; | |
151 | ||
152 | enum { | |
153 | kSecNoGuest = 0, /* not a valid SecGuestRef */ | |
154 | }; | |
155 | ||
156 | ||
157 | /*! | |
d1c1ab47 | 158 | @typedef SecCSFlags |
7d31e928 A |
159 | This is the type of flags arguments to Code Signing API calls. |
160 | It provides a bit mask of request and option flags. All of the bits in these | |
161 | masks are reserved to Apple; if you set any bits not defined in these headers, | |
162 | the behavior is generally undefined. | |
163 | ||
164 | This list describes the flags that are shared among several Code Signing API calls. | |
165 | Flags that only apply to one call are defined and documented with that call. | |
166 | Global flags are assigned from high order down (31 -> 0); call-specific flags | |
167 | are assigned from the bottom up (0 -> 31). | |
168 | ||
169 | @constant kSecCSDefaultFlags | |
170 | When passed to a flags argument throughout, indicates that default behavior | |
171 | is desired. Do not mix with other flags values. | |
172 | @constant kSecCSConsiderExpiration | |
173 | When passed to a call that performs code validation, requests that code signatures | |
174 | made by expired certificates be rejected. By default, expiration of participating | |
175 | certificates is not automatic grounds for rejection. | |
176 | */ | |
177 | typedef uint32_t SecCSFlags; | |
178 | ||
179 | enum { | |
180 | kSecCSDefaultFlags = 0, /* no particular flags (default behavior) */ | |
181 | ||
182 | kSecCSConsiderExpiration = 1 << 31, /* consider expired certificates invalid */ | |
935e6928 | 183 | kSecCSEnforceRevocationChecks = 1 << 30, /* force revocation checks regardless of preference settings */ |
7d31e928 A |
184 | }; |
185 | ||
186 | ||
187 | /*! | |
188 | @typedef SecCodeSignatureFlags | |
189 | This is the type of option flags that can be embedded in a code signature | |
190 | during signing, and that govern the use of the signature thereafter. | |
191 | Some of these flags can be set through the codesign(1) command's --options | |
192 | argument; some are set implicitly based on signing circumstances; and all | |
193 | can be set with the kSecCodeSignerFlags item of a signing information dictionary. | |
194 | ||
195 | @constant kSecCodeSignatureHost | |
196 | Indicates that the code may act as a host that controls and supervises guest | |
197 | code. If this flag is not set in a code signature, the code is never considered | |
f60086fc | 198 | eligible to be a host, and any attempt to act like one will be ignored or rejected. |
7d31e928 A |
199 | @constant kSecCodeSignatureAdhoc |
200 | The code has been sealed without a signing identity. No identity may be retrieved | |
201 | from it, and any code requirement placing restrictions on the signing identity | |
202 | will fail. This flag is set by the code signing API and cannot be set explicitly. | |
203 | @constant kSecCodeSignatureForceHard | |
204 | Implicitly set the "hard" status bit for the code when it starts running. | |
205 | This bit indicates that the code prefers to be denied access to a resource | |
206 | if gaining such access would cause its invalidation. Since the hard bit is | |
207 | sticky, setting this option bit guarantees that the code will always have | |
208 | it set. | |
209 | @constant kSecCodeSignatureForceKill | |
210 | Implicitly set the "kill" status bit for the code when it starts running. | |
211 | This bit indicates that the code wishes to be terminated with prejudice if | |
212 | it is ever invalidated. Since the kill bit is sticky, setting this option bit | |
f60086fc A |
213 | guarantees that the code will always be dynamically valid, since it will die |
214 | immediately if it becomes invalid. | |
7d31e928 | 215 | @constant kSecCodeSignatureForceExpiration |
d1c1ab47 | 216 | Forces the kSecCSConsiderExpiration flag on all validations of the code. |
7d31e928 A |
217 | */ |
218 | typedef uint32_t SecCodeSignatureFlags; | |
219 | ||
220 | enum { | |
221 | kSecCodeSignatureHost = 0x0001, /* may host guest code */ | |
222 | kSecCodeSignatureAdhoc = 0x0002, /* must be used without signer */ | |
223 | kSecCodeSignatureForceHard = 0x0100, /* always set HARD mode on launch */ | |
224 | kSecCodeSignatureForceKill = 0x0200, /* always set KILL mode on launch */ | |
f60086fc | 225 | kSecCodeSignatureForceExpiration = 0x0400, /* force certificate expiration checks */ |
d1c1ab47 A |
226 | }; |
227 | ||
228 | ||
229 | /*! | |
230 | @typedef SecCodeStatus | |
f60086fc | 231 | The code signing system attaches a set of status flags to each running code. |
d1c1ab47 | 232 | These flags are maintained by the code's host, and can be read by anyone. |
f60086fc A |
233 | A code may change its own flags, a host may change its guests' flags, |
234 | and root may change anyone's flags. However, these flags are sticky in that | |
235 | each can change in only one direction (and never back, for the lifetime of the code). | |
236 | Not even root can violate this restriction. | |
d1c1ab47 A |
237 | |
238 | There are other flags in SecCodeStatus that are not publicly documented. | |
f60086fc | 239 | Do not rely on them, and do not ever attempt to explicitly set them. |
d1c1ab47 A |
240 | |
241 | @constant kSecCodeStatusValid | |
f60086fc A |
242 | Indicates that the code is dynamically valid, i.e. it started correctly |
243 | and has not been invalidated since then. The valid bit can only be cleared. | |
244 | ||
245 | Warning: This bit is not your one-stop shortcut to determining the validity of code. | |
246 | It represents the dynamic component of the full validity function; if this | |
247 | bit is unset, the code is definitely invalid, but the converse is not always true. | |
248 | In fact, code hosts may represent the outcome of some delayed static validation work in this bit, | |
249 | and thus it strictly represents a blend of (all of) dynamic and (some of) static validity, | |
250 | depending on the implementation of the particular host managing the code. You can (only) | |
251 | rely that (1) dynamic invalidation will clear this bit; and (2) the combination | |
252 | of static validation and dynamic validity (as performed by the SecCodeCheckValidity* APIs) | |
253 | will give a correct answer. | |
254 | ||
d1c1ab47 A |
255 | @constant kSecCodeStatusHard |
256 | Indicates that the code prefers to be denied access to resources if gaining access | |
257 | would invalidate it. This bit can only be set. | |
f60086fc | 258 | It is undefined whether code that is marked hard and is already invalid will still |
d1c1ab47 A |
259 | be denied access to a resource that would invalidate it if it were still valid. That is, |
260 | the code may or may not get access to such a resource while being invalid, and that choice | |
f60086fc A |
261 | may appear random. |
262 | ||
d1c1ab47 A |
263 | @constant kSecCodeStatusKill |
264 | Indicates that the code wants to be killed (terminated) if it ever loses its validity. | |
f60086fc A |
265 | This bit can only be set. Code that has the kill flag set will never be dynamically invalid |
266 | (and live). Note however that a change in static validity does not necessarily trigger instant | |
267 | death. | |
d1c1ab47 A |
268 | */ |
269 | typedef uint32_t SecCodeStatus; | |
270 | enum { | |
271 | kSecCodeStatusValid = 0x0001, | |
272 | kSecCodeStatusHard = 0x0100, | |
273 | kSecCodeStatusKill = 0x0200, | |
7d31e928 A |
274 | }; |
275 | ||
276 | ||
277 | /*! | |
278 | @typedef SecRequirementType | |
279 | An enumeration indicating different types of internal requirements for code. | |
d1c1ab47 | 280 | */ |
7d31e928 A |
281 | typedef uint32_t SecRequirementType; |
282 | ||
283 | enum { | |
f60086fc A |
284 | kSecHostRequirementType = 1, /* what hosts may run us */ |
285 | kSecGuestRequirementType = 2, /* what guests we may run */ | |
286 | kSecDesignatedRequirementType = 3, /* designated requirement */ | |
287 | kSecLibraryRequirementType = 4, /* what libraries we may link against */ | |
288 | kSecPluginRequirementType = 5, /* what plug-ins we may load */ | |
7d31e928 A |
289 | kSecInvalidRequirementType, /* invalid type of Requirement (must be last) */ |
290 | kSecRequirementTypeCount = kSecInvalidRequirementType /* number of valid requirement types */ | |
291 | }; | |
292 | ||
293 | ||
294 | #ifdef __cplusplus | |
295 | } | |
296 | #endif | |
297 | ||
298 | #endif //_H_CSCOMMON |