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 kSecCodeInfoDiskRepVersionPlatform
;     /* Number */ 
  49 extern const CFStringRef kSecCodeInfoDiskRepVersionMin
;          /* Number */ 
  50 extern const CFStringRef kSecCodeInfoDiskRepVersionSDK
;          /* 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
); 
 131         @function SecCodeCreateWithPID 
 132         Asks the kernel to return a SecCode object for a process identified 
 133         by a UNIX process id (pid). This is a shorthand for asking SecGetRootCode() 
 134         for a guest whose "pid" attribute has the given pid value. 
 136         This is a deprecated convenience function. 
 137         Call SecCodeCopyGuestWithAttributes instead. 
 139         @param pid A process id for an existing UNIX process on the system. 
 140         @param flags Optional flags. Pass kSecCSDefaultFlags for standard behavior. 
 141         @param process On successful return, a SecCode object reference identifying 
 142         the requesteed process. 
 143         @result Upon success, errSecSuccess. Upon error, an OSStatus value documented in 
 144         CSCommon.h or certain other Security framework headers. 
 146 OSStatus 
SecCodeCreateWithPID(pid_t pid
, SecCSFlags flags
, SecCodeRef 
*process
) 
 147         AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_6
; 
 152         @function SecCodeSetDetachedSignature 
 153         For a given Code or StaticCode object, explicitly specify the detached signature 
 154         data used to verify it. 
 155         This call unconditionally overrides any signature embedded in the Code and any 
 156         previously specified detached signature; only the signature data specified here 
 157         will be used from now on for this Code object. If NULL data is specified, the 
 158         code object is returned to its natural signing state (before a detached 
 159         signature was first attached to it). 
 160         Any call to this function voids all cached validations for the Code object. 
 161         Validations will be performed again as needed in the future. This call does not, 
 162         by itself, perform or trigger any validations. 
 163         Please note that it is possible to have multiple Code objects for the same static 
 164         or dynamic code entity in the system. This function only attaches signature data 
 165         to the particular SecStaticCodeRef involved. It is your responsibility to understand 
 166         the object graph and pick the right one(s). 
 168         @param code A Code or StaticCode object whose signature information is to be changed. 
 169         @param signature A CFDataRef containing the signature data to be used for validating 
 170                 the given Code. This must be exactly the data previously generated as a detached 
 171                 signature by the SecCodeSignerAddSignature API or the codesign(1) command with 
 172                 the -D/--detached option. 
 173                 If signature is NULL, discards any previously set signature data and reverts 
 174                 to using the embedded signature, if any. If not NULL, the data is retained and used 
 175                 for future validation operations. 
 176                 The data may be retained or copied. Behavior is undefined if this object 
 177                 is modified after this call before it is replaced through another call to this 
 179         @param flags Optional flags. Pass kSecCSDefaultFlags for standard behavior. 
 181 OSStatus 
SecCodeSetDetachedSignature(SecStaticCodeRef code
, CFDataRef signature
, 
 187         @function SecCodeCopyComponent 
 188         For a SecStaticCodeRef, directly retrieve the binary blob for a special slot, 
 189         optionally checking that its native hash is the one given. 
 191         @param code A code or StaticCode object. 
 192         @param slot The (positive) special slot number requested. 
 193         @param hash A CFDataRef containing the native slot hash for the slot requested. 
 194         @result NULL if anything went wrong (including a missing slot), or a CFDataRef 
 195                 containing the slot data. 
 197 CFDataRef 
SecCodeCopyComponent(SecCodeRef code
, int slot
, CFDataRef hash
); 
 201     @function SecCodeValidateFileResource 
 202     For a SecStaticCodeRef, check that a given CFData object faithfully represents 
 203     a plain-file resource in its resource seal. 
 204     This call will fail if the file is missing in the bundle, even if it is optional. 
 206     @param code A code or StaticCode object. 
 207     @param relativePath A CFStringRef containing the relative path to a sealed resource 
 208         file. This path is relative to the resource base, which is either Contents or 
 209         the bundle root, depending on bundle format. 
 210     @param fileData A CFDataRef containing the exact contents of that resource file. 
 211     @param flags Pass kSecCSDefaultFlags. 
 212     @result noErr if fileData is the exact content of the file at relativePath at the 
 213         time it was signed. Various error codes if it is different, there was no such file, 
 214         it was not a plain file, or anything is irregular. 
 216 OSStatus 
SecCodeValidateFileResource(SecStaticCodeRef code
, CFStringRef relativePath
, CFDataRef fileData
, SecCSFlags flags
);