]> git.saurik.com Git - apple/libsecurity_codesigning.git/blob - lib/CSCommon.h
5b24b602a2772e3305972ec4a5d12b0755c250c0
[apple/libsecurity_codesigning.git] / lib / CSCommon.h
1 /*
2 * Copyright (c) 2006-2007 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
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 {
45 errSecCSUnimplemented = -67072, /* unimplemented code signing feature */
46 errSecCSInvalidObjectRef, /* invalid API object reference */
47 errSecCSInvalidFlags, /* invalid or inapprpopriate API flag(s) specified */
48 errSecCSObjectRequired, /* a required pointer argument was NULL */
49 errSecCSStaticCodeNotFound, /* cannot find code object on disk */
50 errSecCSUnsupportedGuestAttributes, /* cannot locate guests using this attribute set */
51 errSecCSInvalidAttributeValues, /* given attribute values are invalid */
52 errSecCSNoSuchCode, /* host has no guest with the requested attributes */
53 errSecCSMultipleGuests, /* host has multiple guests with this attribute value */
54 errSecCSGuestInvalid, /* code identity has been invalidated */
55 errSecCSUnsigned, /* code object is not signed */
56 errSecCSSignatureFailed, /* code or signature modified */
57 errSecCSSignatureNotVerifiable, /* signature cannot be read, e.g., due to a filesystem that maps root to an unprivileged user */
58 errSecCSSignatureUnsupported, /* unsupported type or version of signature */
59 errSecCSBadDictionaryFormat, /* a required plist file or resource is malformed */
60 errSecCSResourcesNotSealed, /* resources are not sealed by signature */
61 errSecCSResourcesNotFound, /* cannot find sealed resources in code */
62 errSecCSResourcesInvalid, /* the sealed resource directory is invalid */
63 errSecCSBadResource, /* a sealed resource is missing or invalid */
64 errSecCSResourceRulesInvalid, /* invalid resource selection rule(s) */
65 errSecCSReqInvalid, /* invalid or corrupted code requirement(s) */
66 errSecCSReqUnsupported, /* unsupported type or version of code requirement(s) */
67 errSecCSReqFailed, /* failed to satisfy code requirement(s) */
68 errSecCSBadObjectFormat, /* object file format invalid or unsuitable */
69 errSecCSInternalError, /* internal error in Code Signing subsystem */
70 errSecCSHostReject, /* code rejected its host */
71 errSecCSNotAHost, /* this code is not a host */
72 errSecCSSignatureInvalid, /* invalid format for signature */
73 errSecCSHostProtocolRelativePath, /* host protocol violation - absolute guest path required */
74 errSecCSHostProtocolContradiction, /* host protocol violation - contradictory hosting modes */
75 errSecCSHostProtocolDedicationError, /* host protocol violation - operation not allowed with/for a dedicated guest */
76 errSecCSHostProtocolNotProxy, /* host protocol violation - proxy hosting not engaged */
77 errSecCSHostProtocolStateError, /* host protocol violation - invalid guest state change request */
78 errSecCSHostProtocolUnrelated, /* host protocol violation - the given guest is not a guest of the given host */
79 errSecCSInvalidOperation, /* requested operation is not valid */
80 errSecCSNotSupported, /* operation not supported for this type of code */
81 };
82
83
84 /*
85 * Code Signing specific CFError "user info" keys.
86 * In calls that can return CFErrorRef indications, if a CFErrorRef is actually
87 * returned, its "user info" dictionary will contain some (but not all) of the
88 * following keys to more closely describe the circumstances of the failure.
89 */
90 extern const CFStringRef kSecCFErrorPattern; /* CFStringRef: invalid resource selection pattern encountered */
91 extern const CFStringRef kSecCFErrorResourceSeal; /* CFTypeRef: invalid component in resource seal (CodeResources) */
92 extern const CFStringRef kSecCFErrorResourceAdded; /* CFURLRef: unsealed resource found */
93 extern const CFStringRef kSecCFErrorResourceAltered; /* CFURLRef: modified resource found */
94 extern const CFStringRef kSecCFErrorResourceMissing; /* CFURLRef: sealed (non-optional) resource missing */
95 extern const CFStringRef kSecCFErrorInfoPlist; /* CFTypeRef: Info.plist dictionary or component found invalid */
96 extern const CFStringRef kSecCFErrorGuestAttributes; /* CFTypeRef: Guest attribute set of element not accepted */
97 extern const CFStringRef kSecCFErrorRequirementSyntax; /* CFStringRef: compilation error for Requirement source */
98
99
100 /*!
101 @typedef SecCodeRef
102 This is the type of a reference to running code.
103
104 In many (but not all) calls, this can be passed to a SecStaticCodeRef
105 argument, which performs an implicit SecCodeCopyStaticCode call and
106 operates on the result.
107 */
108 typedef struct __SecCode *SecCodeRef; /* running code */
109
110 /*!
111 @typedef SecStaticCodeRef
112 This is the type of a reference to static code on disk.
113 */
114 typedef struct __SecCode const *SecStaticCodeRef; /* code on disk */
115
116 /*!
117 @typedef SecRequirementRef
118 This is the type of a reference to a code requirement.
119 */
120 typedef struct __SecRequirement *SecRequirementRef; /* code requirement */
121
122
123 /*!
124 @typedef SecGuestRef
125 An abstract handle to identify a particular Guest in the context of its Host.
126
127 Guest handles are assigned by the host at will, with kSecNoGuest (zero) being
128 reserved as the null value). They can be reused for new children if desired.
129 */
130 typedef u_int32_t SecGuestRef;
131
132 enum {
133 kSecNoGuest = 0, /* not a valid SecGuestRef */
134 };
135
136
137 /*!
138 @typddef SecCSFlags
139 This is the type of flags arguments to Code Signing API calls.
140 It provides a bit mask of request and option flags. All of the bits in these
141 masks are reserved to Apple; if you set any bits not defined in these headers,
142 the behavior is generally undefined.
143
144 This list describes the flags that are shared among several Code Signing API calls.
145 Flags that only apply to one call are defined and documented with that call.
146 Global flags are assigned from high order down (31 -> 0); call-specific flags
147 are assigned from the bottom up (0 -> 31).
148
149 @constant kSecCSDefaultFlags
150 When passed to a flags argument throughout, indicates that default behavior
151 is desired. Do not mix with other flags values.
152 @constant kSecCSConsiderExpiration
153 When passed to a call that performs code validation, requests that code signatures
154 made by expired certificates be rejected. By default, expiration of participating
155 certificates is not automatic grounds for rejection.
156 */
157 typedef uint32_t SecCSFlags;
158
159 enum {
160 kSecCSDefaultFlags = 0, /* no particular flags (default behavior) */
161
162 kSecCSConsiderExpiration = 1 << 31, /* consider expired certificates invalid */
163 };
164
165
166 /*!
167 @typedef SecCodeSignatureFlags
168 This is the type of option flags that can be embedded in a code signature
169 during signing, and that govern the use of the signature thereafter.
170 Some of these flags can be set through the codesign(1) command's --options
171 argument; some are set implicitly based on signing circumstances; and all
172 can be set with the kSecCodeSignerFlags item of a signing information dictionary.
173
174 @constant kSecCodeSignatureHost
175 Indicates that the code may act as a host that controls and supervises guest
176 code. If this flag is not set in a code signature, the code is never considered
177 eligible to be a host, and any attempt to act like one will be ignored.
178 @constant kSecCodeSignatureAdhoc
179 The code has been sealed without a signing identity. No identity may be retrieved
180 from it, and any code requirement placing restrictions on the signing identity
181 will fail. This flag is set by the code signing API and cannot be set explicitly.
182 @constant kSecCodeSignatureForceHard
183 Implicitly set the "hard" status bit for the code when it starts running.
184 This bit indicates that the code prefers to be denied access to a resource
185 if gaining such access would cause its invalidation. Since the hard bit is
186 sticky, setting this option bit guarantees that the code will always have
187 it set.
188 @constant kSecCodeSignatureForceKill
189 Implicitly set the "kill" status bit for the code when it starts running.
190 This bit indicates that the code wishes to be terminated with prejudice if
191 it is ever invalidated. Since the kill bit is sticky, setting this option bit
192 guarantees that the code will always be valid, since it will die immediately
193 if it becomes invalid.
194 @constant kSecCodeSignatureForceExpiration
195 Forces the kSecCSConsiderExpiration on all validations of the code.
196 */
197 typedef uint32_t SecCodeSignatureFlags;
198
199 enum {
200 kSecCodeSignatureHost = 0x0001, /* may host guest code */
201 kSecCodeSignatureAdhoc = 0x0002, /* must be used without signer */
202 kSecCodeSignatureForceHard = 0x0100, /* always set HARD mode on launch */
203 kSecCodeSignatureForceKill = 0x0200, /* always set KILL mode on launch */
204 kSecCodeSignatureForceExpiration = 0x0400, /* force certificat expiration checks */
205 };
206
207
208 /*!
209 @typedef SecRequirementType
210 An enumeration indicating different types of internal requirements for code.
211 */
212 typedef uint32_t SecRequirementType;
213
214 enum {
215 kSecHostRequirementType = 1, /* what hosts may run us */
216 kSecGuestRequirementType = 2, /* what guests we may run */
217 kSecDesignatedRequirementType = 3, /* designated requirement */
218 kSecLibraryRequirementType = 4, /* what libraries we may link against */
219 kSecInvalidRequirementType, /* invalid type of Requirement (must be last) */
220 kSecRequirementTypeCount = kSecInvalidRequirementType /* number of valid requirement types */
221 };
222
223
224 #ifdef __cplusplus
225 }
226 #endif
227
228 #endif //_H_CSCOMMON