]> git.saurik.com Git - apple/libsecurity_codesigning.git/blob - lib/CSCommon.h
564165f4f95b849dde801db91d59af5b12ae53c3
[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 errSecCSCMSTooLarge, /* signature too large to embed */
82 };
83
84
85 /*
86 * Code Signing specific CFError "user info" keys.
87 * In calls that can return CFErrorRef indications, if a CFErrorRef is actually
88 * returned, its "user info" dictionary will contain some (but not all) of the
89 * following keys to more closely describe the circumstances of the failure.
90 */
91 extern const CFStringRef kSecCFErrorPattern; /* CFStringRef: invalid resource selection pattern encountered */
92 extern const CFStringRef kSecCFErrorResourceSeal; /* CFTypeRef: invalid component in resource seal (CodeResources) */
93 extern const CFStringRef kSecCFErrorResourceAdded; /* CFURLRef: unsealed resource found */
94 extern const CFStringRef kSecCFErrorResourceAltered; /* CFURLRef: modified resource found */
95 extern const CFStringRef kSecCFErrorResourceMissing; /* CFURLRef: sealed (non-optional) resource missing */
96 extern const CFStringRef kSecCFErrorInfoPlist; /* CFTypeRef: Info.plist dictionary or component found invalid */
97 extern const CFStringRef kSecCFErrorGuestAttributes; /* CFTypeRef: Guest attribute set of element not accepted */
98 extern const CFStringRef kSecCFErrorRequirementSyntax; /* CFStringRef: compilation error for Requirement source */
99
100
101 /*!
102 @typedef SecCodeRef
103 This is the type of a reference to running code.
104
105 In many (but not all) calls, this can be passed to a SecStaticCodeRef
106 argument, which performs an implicit SecCodeCopyStaticCode call and
107 operates on the result.
108 */
109 typedef struct __SecCode *SecCodeRef; /* running code */
110
111 /*!
112 @typedef SecStaticCodeRef
113 This is the type of a reference to static code on disk.
114 */
115 typedef struct __SecCode const *SecStaticCodeRef; /* code on disk */
116
117 /*!
118 @typedef SecRequirementRef
119 This is the type of a reference to a code requirement.
120 */
121 typedef struct __SecRequirement *SecRequirementRef; /* code requirement */
122
123
124 /*!
125 @typedef SecGuestRef
126 An abstract handle to identify a particular Guest in the context of its Host.
127
128 Guest handles are assigned by the host at will, with kSecNoGuest (zero) being
129 reserved as the null value). They can be reused for new children if desired.
130 */
131 typedef u_int32_t SecGuestRef;
132
133 enum {
134 kSecNoGuest = 0, /* not a valid SecGuestRef */
135 };
136
137
138 /*!
139 @typddef SecCSFlags
140 This is the type of flags arguments to Code Signing API calls.
141 It provides a bit mask of request and option flags. All of the bits in these
142 masks are reserved to Apple; if you set any bits not defined in these headers,
143 the behavior is generally undefined.
144
145 This list describes the flags that are shared among several Code Signing API calls.
146 Flags that only apply to one call are defined and documented with that call.
147 Global flags are assigned from high order down (31 -> 0); call-specific flags
148 are assigned from the bottom up (0 -> 31).
149
150 @constant kSecCSDefaultFlags
151 When passed to a flags argument throughout, indicates that default behavior
152 is desired. Do not mix with other flags values.
153 @constant kSecCSConsiderExpiration
154 When passed to a call that performs code validation, requests that code signatures
155 made by expired certificates be rejected. By default, expiration of participating
156 certificates is not automatic grounds for rejection.
157 */
158 typedef uint32_t SecCSFlags;
159
160 enum {
161 kSecCSDefaultFlags = 0, /* no particular flags (default behavior) */
162
163 kSecCSConsiderExpiration = 1 << 31, /* consider expired certificates invalid */
164 };
165
166
167 /*!
168 @typedef SecCodeSignatureFlags
169 This is the type of option flags that can be embedded in a code signature
170 during signing, and that govern the use of the signature thereafter.
171 Some of these flags can be set through the codesign(1) command's --options
172 argument; some are set implicitly based on signing circumstances; and all
173 can be set with the kSecCodeSignerFlags item of a signing information dictionary.
174
175 @constant kSecCodeSignatureHost
176 Indicates that the code may act as a host that controls and supervises guest
177 code. If this flag is not set in a code signature, the code is never considered
178 eligible to be a host, and any attempt to act like one will be ignored.
179 @constant kSecCodeSignatureAdhoc
180 The code has been sealed without a signing identity. No identity may be retrieved
181 from it, and any code requirement placing restrictions on the signing identity
182 will fail. This flag is set by the code signing API and cannot be set explicitly.
183 @constant kSecCodeSignatureForceHard
184 Implicitly set the "hard" status bit for the code when it starts running.
185 This bit indicates that the code prefers to be denied access to a resource
186 if gaining such access would cause its invalidation. Since the hard bit is
187 sticky, setting this option bit guarantees that the code will always have
188 it set.
189 @constant kSecCodeSignatureForceKill
190 Implicitly set the "kill" status bit for the code when it starts running.
191 This bit indicates that the code wishes to be terminated with prejudice if
192 it is ever invalidated. Since the kill bit is sticky, setting this option bit
193 guarantees that the code will always be valid, since it will die immediately
194 if it becomes invalid.
195 @constant kSecCodeSignatureForceExpiration
196 Forces the kSecCSConsiderExpiration on all validations of the code.
197 */
198 typedef uint32_t SecCodeSignatureFlags;
199
200 enum {
201 kSecCodeSignatureHost = 0x0001, /* may host guest code */
202 kSecCodeSignatureAdhoc = 0x0002, /* must be used without signer */
203 kSecCodeSignatureForceHard = 0x0100, /* always set HARD mode on launch */
204 kSecCodeSignatureForceKill = 0x0200, /* always set KILL mode on launch */
205 kSecCodeSignatureForceExpiration = 0x0400, /* force certificat expiration checks */
206 };
207
208
209 /*!
210 @typedef SecRequirementType
211 An enumeration indicating different types of internal requirements for code.
212 */
213 typedef uint32_t SecRequirementType;
214
215 enum {
216 kSecHostRequirementType = 1, /* what hosts may run us */
217 kSecGuestRequirementType = 2, /* what guests we may run */
218 kSecDesignatedRequirementType = 3, /* designated requirement */
219 kSecLibraryRequirementType = 4, /* what libraries we may link against */
220 kSecInvalidRequirementType, /* invalid type of Requirement (must be last) */
221 kSecRequirementTypeCount = kSecInvalidRequirementType /* number of valid requirement types */
222 };
223
224
225 #ifdef __cplusplus
226 }
227 #endif
228
229 #endif //_H_CSCOMMON