]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_codesigning/lib/SecCodePriv.h
Security-57740.60.18.tar.gz
[apple/security.git] / OSX / libsecurity_codesigning / lib / SecCodePriv.h
1 /*
2 * Copyright (c) 2006-2007,2011,2013 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 SecCodePriv
26 SecCodePriv is the private counter-part to SecCode. Its contents are not
27 official API, and are subject to change without notice.
28 */
29 #ifndef _H_SECCODEPRIV
30 #define _H_SECCODEPRIV
31
32 #include <Security/SecCode.h>
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38
39 /*
40 * Private constants for SecCodeCopySigningInformation.
41 * These are returned with the
42 */
43 extern const CFStringRef kSecCodeInfoCodeDirectory; /* Internal */
44 extern const CFStringRef kSecCodeInfoCodeOffset; /* Internal */
45 extern const CFStringRef kSecCodeInfoDiskRepInfo; /* Internal */
46 extern const CFStringRef kSecCodeInfoResourceDirectory; /* Internal */
47
48 extern const CFStringRef kSecCodeInfoDiskRepOSPlatform; /* Number */
49 extern const CFStringRef kSecCodeInfoDiskRepOSVersionMin; /* Number */
50 extern const CFStringRef kSecCodeInfoDiskRepOSSDKVersion; /* Number */
51 extern const CFStringRef kSecCodeInfoDiskRepNoLibraryValidation; /* String */
52
53 /*!
54 @function SecCodeGetStatus
55 Retrieves the dynamic status for a SecCodeRef.
56
57 The dynamic status of a code can change at any time; the value returned is a snapshot
58 in time that is inherently stale by the time it is received by the caller. However,
59 since the status bits can only change in certain ways, some information is indefinitely
60 valid. For example, an indication of invalidity (kSecCodeStatusValid bit off) is permanent
61 since the valid bit cannot be set once clear, while an indication of validity (bit set)
62 may already be out of date.
63 Use this call with caution; it is usually wiser to call the validation API functions
64 and let then consider the status as part of their holistic computation. However,
65 SecCodeGetStatus is useful at times to capture persistent (sticky) status configurations.
66
67 @param code A valid SecCode object reference representing code running
68 on the system.
69 @param flags Optional flags. Pass kSecCSDefaultFlags for standard behavior.
70 @param status Upon successful return, contains the dynamic status of code as
71 determined by its host.
72
73 @result Upon success, errSecSuccess. Upon error, an OSStatus value documented in
74 CSCommon.h or certain other Security framework headers.
75 */
76 OSStatus SecCodeGetStatus(SecCodeRef code, SecCSFlags flags, SecCodeStatus *status);
77
78 typedef uint32_t SecCodeStatusOperation;
79 enum {
80 kSecCodeOperationNull = 0,
81 kSecCodeOperationInvalidate = 1,
82 kSecCodeOperationSetHard = 2,
83 kSecCodeOperationSetKill = 3,
84 };
85
86 /*!
87 @function SecCodeSetStatus
88 Change the dynamic status of a SecCodeRef.
89
90 @param code A valid SecCode object reference representing code running
91 on the system.
92 @param flags Optional flags. Pass kSecCSDefaultFlags for standard behavior.
93
94 @result Upon success, errSecSuccess. Upon error, an OSStatus value documented in
95 CSCommon.h or certain other Security framework headers.
96 */
97 OSStatus SecCodeSetStatus(SecCodeRef code, SecCodeStatusOperation operation,
98 CFDictionaryRef arguments, SecCSFlags flags);
99
100
101 /*!
102 @function SecCodeCopyInternalRequirement
103 For a given Code or StaticCode object, retrieves a particular kind of internal
104 requirement that was sealed during signing.
105
106 This function will always fail for unsigned code. Requesting a type of internal
107 requirement that was not given during signing is not an error.
108
109 Specifying a type of kSecDesignatedRequirementType is not the same as calling
110 SecCodeCopyDesignatedRequirement. This function will only return an explicit
111 Designated Requirement if one was specified during signing. SecCodeCopyDesignatedRequirement
112 will synthesize a suitable Designated Requirement if one was not given explicitly.
113
114 @param code The Code or StaticCode object to be interrogated. For a Code
115 argument, its StaticCode is processed as per SecCodeCopyStaticCode.
116 @param type A SecRequirementType specifying which internal requirement is being
117 requested.
118 @param flags Optional flags. Pass kSecCSDefaultFlags for standard behavior.
119 @param requirement On successful return, contains a copy of the internal requirement
120 of the given type included in the given code. If the code has no such internal
121 requirement, this argument is set to NULL (with no error).
122 @result On success, errSecSuccess. On error, an OSStatus value
123 documented in CSCommon.h or certain other Security framework headers.
124 */
125 OSStatus SecCodeCopyInternalRequirement(SecStaticCodeRef code, SecRequirementType type,
126 SecCSFlags flags, SecRequirementRef *requirement);
127
128
129 /*!
130 @function SecCodeCreateWithPID
131 Asks the kernel to return a SecCode object for a process identified
132 by a UNIX process id (pid). This is a shorthand for asking SecGetRootCode()
133 for a guest whose "pid" attribute has the given pid value.
134
135 This is a deprecated convenience function.
136 Call SecCodeCopyGuestWithAttributes instead.
137
138 @param pid A process id for an existing UNIX process on the system.
139 @param flags Optional flags. Pass kSecCSDefaultFlags for standard behavior.
140 @param process On successful return, a SecCode object reference identifying
141 the requesteed process.
142 @result Upon success, errSecSuccess. Upon error, an OSStatus value documented in
143 CSCommon.h or certain other Security framework headers.
144 */
145 OSStatus SecCodeCreateWithPID(pid_t pid, SecCSFlags flags, SecCodeRef *process)
146 AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_6;
147
148
149 /*
150 @function SecCodeSetDetachedSignature
151 For a given Code or StaticCode object, explicitly specify the detached signature
152 data used to verify it.
153 This call unconditionally overrides any signature embedded in the Code and any
154 previously specified detached signature; only the signature data specified here
155 will be used from now on for this Code object. If NULL data is specified, the
156 code object is returned to its natural signing state (before a detached
157 signature was first attached to it).
158 Any call to this function voids all cached validations for the Code object.
159 Validations will be performed again as needed in the future. This call does not,
160 by itself, perform or trigger any validations.
161 Please note that it is possible to have multiple Code objects for the same static
162 or dynamic code entity in the system. This function only attaches signature data
163 to the particular SecStaticCodeRef involved. It is your responsibility to understand
164 the object graph and pick the right one(s).
165
166 @param code A Code or StaticCode object whose signature information is to be changed.
167 @param signature A CFDataRef containing the signature data to be used for validating
168 the given Code. This must be exactly the data previously generated as a detached
169 signature by the SecCodeSignerAddSignature API or the codesign(1) command with
170 the -D/--detached option.
171 If signature is NULL, discards any previously set signature data and reverts
172 to using the embedded signature, if any. If not NULL, the data is retained and used
173 for future validation operations.
174 The data may be retained or copied. Behavior is undefined if this object
175 is modified after this call before it is replaced through another call to this
176 function).
177 @param flags Optional flags. Pass kSecCSDefaultFlags for standard behavior.
178 */
179 OSStatus SecCodeSetDetachedSignature(SecStaticCodeRef code, CFDataRef signature,
180 SecCSFlags flags);
181
182
183
184 /*
185 @function SecCodeCopyComponent
186 For a SecStaticCodeRef, directly retrieve the binary blob for a special slot,
187 optionally checking that its native hash is the one given.
188
189 @param code A code or StaticCode object.
190 @param slot The (positive) special slot number requested.
191 @param hash A CFDataRef containing the native slot hash for the slot requested.
192 @result NULL if anything went wrong (including a missing slot), or a CFDataRef
193 containing the slot data.
194 */
195 CFDataRef SecCodeCopyComponent(SecCodeRef code, int slot, CFDataRef hash);
196
197
198 /*
199 @funtion SecCodeValidateFileResource
200 For a SecStaticCodeRef, check that a given CFData object faithfully represents
201 a plain-file resource in its resource seal.
202 This call will fail if the file is missing in the bundle, even if it is optional.
203
204 @param code A code or StaticCode object.
205 @param relativePath A CFStringRef containing the relative path to a sealed resource
206 file. This path is relative to the resource base, which is either Contents or
207 the bundle root, depending on bundle format.
208 @param fileData A CFDataRef containing the exact contents of that resource file.
209 @param flags Pass kSecCSDefaultFlags.
210 @result noErr if fileData is the exact content of the file at relativePath at the
211 time it was signed. Various error codes if it is different, there was no such file,
212 it was not a plain file, or anything is irregular.
213 */
214 OSStatus SecCodeValidateFileResource(SecStaticCodeRef code, CFStringRef relativePath, CFDataRef fileData, SecCSFlags flags);
215
216 #ifdef __cplusplus
217 }
218 #endif
219
220 #endif //_H_SECCODE