]> git.saurik.com Git - apple/libsecurity_codesigning.git/blob - lib/SecCodeSigner.h
2e081d199eea09761d6a60f0946c4c7f361ad1e9
[apple/libsecurity_codesigning.git] / lib / SecCodeSigner.h
1 /*
2 * Copyright (c) 2006-2007 Apple Computer, 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 SecCodeSigner
26 SecCodeSigner represents an object that can sign code.
27 */
28 #ifndef _H_SECCODESIGNER
29 #define _H_SECCODESIGNER
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 #include <Security/CSCommon.h>
36
37 /*!
38 @typedef SecCodeSignerRef
39 This is the type of a reference to a code requirement.
40 */
41 typedef struct __SecCodeSigner *SecCodeSignerRef; /* code signing object */
42
43
44 /*!
45 @function SecCodeGetTypeID
46 Returns the type identifier of all SecCodeSigner instances.
47 */
48 CFTypeID SecCodeSignerGetTypeID(void);
49
50
51 /*!
52 The following CFString constants can be used as keys in the parameters argument
53 of SecCodeSignerCreate to specify various modes and options of the signing operation.
54 Passing any keys not specified here may lead to undefined behavior and is not supported.
55 The same applies to passing objects of types not explicitly allowed here.
56
57 @constant kSecCodeSignerDetached Determines where the signature is written.
58 If this key is absent, the code being signed is modified to contain the signature,
59 replacing any signature already embedded there.
60 If the value is kCFNull, the signature is written to the system-wide detached
61 signature database. (You must have root privileges to write there.)
62 If the value of this key is a CFURL, the signature is written to a file at that location,
63 replacing any data there.
64 If the value is a CFMutableData, the signature is appended to that data.
65 @constant kSecCodeSignerDryRun A boolean value. If present and true, the actual writing
66 of the signature is inhibited, and the code is not modified, but all operations
67 leading up to this are performed normally, including the cryptographic access to
68 the signing identity (if any).
69 @constant kSecCodeSignerFlags A CFNumber specifying which flags to set in the code signature.
70 Note that depending on circumstances, this value may be augmented or modified
71 as part of the signing operation.
72 @constant kSecCodeSignerIdentifier If present, a CFString that explicitly specifies
73 the unique identifier string sealed into the code signature. If absent, the identifier
74 is derived implicitly from the code being signed.
75 @constant kSecCodeSignerIdentifierPrefix If the unique identifier string of the code signature
76 is implicitly generated, and the resulting string does not contain any "." (dot)
77 characters, then the (string) value of this parameter is prepended to the identifier.
78 By convention, the prefix is usually of the form "com.yourcompany.", but any value
79 is acceptable. If the kSecCodeSignerIdentifier parameter is specified, this parameter
80 is ineffective (but still allowed).
81 @constant kSecCodeSignerIdentity A SecIdentityRef describing the signing identity
82 to use for signing code. This is a mandatory parameter for signing operations.
83 Its value must be either a SecIdentityRef specifying a cryptographic identity
84 valid for Code Signing, or the special value kCFNull to indicate ad-hoc signing.
85 @constant kSecCodeSignerOperation The type of operation to be performed. Valid values
86 are kSecCodeSignerOperationSign to sign code, and kSecCodeSignerOperationRemove
87 to remove any existing signature from code. The default operation is to sign code.
88 @constant kSecCodeSignerPageSize An integer value explicitly specifying the page size
89 used to sign the main executable. This must be a power of two. A value of zero indicates
90 infinite size (no paging).
91 Only certain page sizes are allowed in most circumstances, and specifying an inappropriate
92 size will lead to spurious verification failures. This is for expert use only.
93 @constant kSecCodeSignerRequirements Specifies the internal requirements to be sealed into
94 the code signature. Must be either a CFData containing the binary (compiled) form of
95 a requirements set (SuperBlob), or a CFString containing a valid text form to be
96 compiled into binary form. Default requirements are automatically generated if this
97 parameter is omitted, and defaults may be applied to particular requirement types
98 that are not specified; but any requirement type you specify is sealed exactly as
99 specified.
100 @constant kSecCodeSignerResourceRules A CFDictionary containing resource scanning rules
101 determining what resource files are sealed into the signature (and in what way).
102 A situation-dependent default is applied if this parameter is not specified.
103 @constant kSecCodeSignerSigningTime Specifies what date and time is sealed into the
104 code signature's CMS data. Can be either a CFDate object specifying a date, or
105 the value kCFNull indicating that no date should be included in the signature.
106 If not specified, the current date is chosen and sealed.
107 Since an ad-hoc signature has no CMS data, this argument is ineffective
108 for ad-hoc signing operations.
109 */
110 extern const CFStringRef kSecCodeSignerApplicationData;
111 extern const CFStringRef kSecCodeSignerDetached;
112 extern const CFStringRef kSecCodeSignerDryRun;
113 extern const CFStringRef kSecCodeSignerEntitlements;
114 extern const CFStringRef kSecCodeSignerFlags;
115 extern const CFStringRef kSecCodeSignerIdentifier;
116 extern const CFStringRef kSecCodeSignerIdentifierPrefix;
117 extern const CFStringRef kSecCodeSignerIdentity;
118 extern const CFStringRef kSecCodeSignerPageSize;
119 extern const CFStringRef kSecCodeSignerRequirements;
120 extern const CFStringRef kSecCodeSignerResourceRules;
121 extern const CFStringRef kSecCodeSignerSigningTime;
122
123
124 /*!
125 @function SecCodeSignerCreate
126 Create a (new) SecCodeSigner object to be used for signing code.
127
128 @param parameters An optional CFDictionary containing parameters that influence
129 signing operations with the newly created SecCodeSigner. If NULL, defaults
130 are applied to all parameters; note however that some parameters do not have
131 useful defaults, and will need to be set before signing is attempted.
132 @param flags Optional flags. Pass kSecCSDefaultFlags for standard behavior.
133 The kSecCSRemoveSignature flag requests that any existing signature be stripped
134 from the target code instead of signing.
135 @param staticCode On successful return, a SecStaticCode object reference representing
136 the file system origin of the given SecCode. On error, unchanged.
137 @result Upon success, noErr. Upon error, an OSStatus value documented in
138 CSCommon.h or certain other Security framework headers.
139 */
140 enum {
141 kSecCSRemoveSignature = 1 << 0, // strip existing signature
142 };
143
144
145 OSStatus SecCodeSignerCreate(CFDictionaryRef parameters, SecCSFlags flags,
146 SecCodeSignerRef *signer);
147
148
149 /*!
150 @function SecCodeSignerAddSignature
151 Create a code signature and add it to the StaticCode object being signed.
152
153 @param signer A SecCodeSigner object containing all the information required
154 to sign code.
155 @param code A valid SecStaticCode object reference representing code files
156 on disk. This code will be signed, and will ordinarily be modified to contain
157 the resulting signature data.
158 @param flags Optional flags. Pass kSecCSDefaultFlags for standard behavior.
159 @param errors An optional pointer to a CFErrorRef variable. If the call fails
160 (and something other than noErr is returned), and this argument is non-NULL,
161 a CFErrorRef is stored there further describing the nature and circumstances
162 of the failure. The caller must CFRelease() this error object when done with it.
163 @result Upon success, noErr. Upon error, an OSStatus value documented in
164 CSCommon.h or certain other Security framework headers.
165 */
166 OSStatus SecCodeSignerAddSignature(SecCodeSignerRef signer,
167 SecStaticCodeRef code, SecCSFlags flags);
168
169 OSStatus SecCodeSignerAddSignatureWithErrors(SecCodeSignerRef signer,
170 SecStaticCodeRef code, SecCSFlags flags, CFErrorRef *errors);
171
172
173 #ifdef __cplusplus
174 }
175 #endif
176
177 #endif //_H_SECCODESIGNER