2 * Copyright (c) 2006-2007,2011,2013 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
26 SecCodePriv is the private counter-part to SecCode. Its contents are not
27 official API, and are subject to change without notice.
29 #ifndef _H_SECCODEPRIV
30 #define _H_SECCODEPRIV
32 #include <Security/SecCode.h>
40 * Private constants for SecCodeCopySigningInformation.
41 * These are returned with the
43 extern const CFStringRef kSecCodeInfoCodeDirectory
; /* Internal */
44 extern const CFStringRef kSecCodeInfoCodeOffset
; /* Internal */
45 extern const CFStringRef kSecCodeInfoDiskRepInfo
; /* Internal */
46 extern const CFStringRef kSecCodeInfoResourceDirectory
; /* Internal */
48 extern const CFStringRef kSecCodeInfoDiskRepOSPlatform
; /* Number */
49 extern const CFStringRef kSecCodeInfoDiskRepOSVersionMin
; /* Number */
50 extern const CFStringRef kSecCodeInfoDiskRepOSSDKVersion
; /* Number */
51 extern const CFStringRef kSecCodeInfoDiskRepNoLibraryValidation
; /* String */
54 @function SecCodeGetStatus
55 Retrieves the dynamic status for a SecCodeRef.
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.
67 @param code A valid SecCode object reference representing code running
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.
73 @result Upon success, errSecSuccess. Upon error, an OSStatus value documented in
74 CSCommon.h or certain other Security framework headers.
76 OSStatus
SecCodeGetStatus(SecCodeRef code
, SecCSFlags flags
, SecCodeStatus
*status
);
78 typedef uint32_t SecCodeStatusOperation
;
80 kSecCodeOperationNull
= 0,
81 kSecCodeOperationInvalidate
= 1,
82 kSecCodeOperationSetHard
= 2,
83 kSecCodeOperationSetKill
= 3,
87 @function SecCodeSetStatus
88 Change the dynamic status of a SecCodeRef.
90 @param code A valid SecCode object reference representing code running
92 @param flags Optional flags. Pass kSecCSDefaultFlags for standard behavior.
94 @result Upon success, errSecSuccess. Upon error, an OSStatus value documented in
95 CSCommon.h or certain other Security framework headers.
97 OSStatus
SecCodeSetStatus(SecCodeRef code
, SecCodeStatusOperation operation
,
98 CFDictionaryRef arguments
, SecCSFlags flags
);
102 @function SecCodeCopyInternalRequirement
103 For a given Code or StaticCode object, retrieves a particular kind of internal
104 requirement that was sealed during signing.
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.
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.
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
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.
125 OSStatus
SecCodeCopyInternalRequirement(SecStaticCodeRef code
, SecRequirementType type
,
126 SecCSFlags flags
, SecRequirementRef
*requirement
);
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.
135 This is a deprecated convenience function.
136 Call SecCodeCopyGuestWithAttributes instead.
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.
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
;
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).
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
177 @param flags Optional flags. Pass kSecCSDefaultFlags for standard behavior.
179 OSStatus
SecCodeSetDetachedSignature(SecStaticCodeRef code
, CFDataRef signature
,
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.
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.
195 CFDataRef
SecCodeCopyComponent(SecCodeRef code
, int slot
, CFDataRef hash
);
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.
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.
214 OSStatus
SecCodeValidateFileResource(SecStaticCodeRef code
, CFStringRef relativePath
, CFDataRef fileData
, SecCSFlags flags
);