]> git.saurik.com Git - apple/security.git/blame - OSX/include/security_codesigning/SecCodeSigner.cpp
Security-57336.1.9.tar.gz
[apple/security.git] / OSX / include / security_codesigning / SecCodeSigner.cpp
CommitLineData
b1ab9ed8 1/*
d8f41ccd 2 * Copyright (c) 2006-2012,2014 Apple Inc. All Rights Reserved.
b1ab9ed8
A
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// SecCode - API frame for SecCode objects.
26//
27// Note that some SecCode* functions take SecStaticCodeRef arguments in order to
28// accept either static or dynamic code references, operating on the respective
29// StaticCode. Those functions are in SecStaticCode.cpp, not here, despite their name.
30//
31#include "cs.h"
32#include "CodeSigner.h"
33#include "cskernel.h"
34
35using namespace CodeSigning;
36
37
38//
39// Parameter keys
40//
41const CFStringRef kSecCodeSignerApplicationData = CFSTR("application-specific");
42const CFStringRef kSecCodeSignerDetached = CFSTR("detached");
43const CFStringRef kSecCodeSignerDigestAlgorithm = CFSTR("digest-algorithm");
44const CFStringRef kSecCodeSignerDryRun = CFSTR("dryrun");
45const CFStringRef kSecCodeSignerEntitlements = CFSTR("entitlements");
46const CFStringRef kSecCodeSignerFlags = CFSTR("flags");
47const CFStringRef kSecCodeSignerIdentifier = CFSTR("identifier");
48const CFStringRef kSecCodeSignerIdentifierPrefix = CFSTR("identifier-prefix");
49const CFStringRef kSecCodeSignerIdentity = CFSTR("signer");
50const CFStringRef kSecCodeSignerPageSize = CFSTR("pagesize");
51const CFStringRef kSecCodeSignerRequirements = CFSTR("requirements");
52const CFStringRef kSecCodeSignerResourceRules = CFSTR("resource-rules");
53const CFStringRef kSecCodeSignerSDKRoot = CFSTR("sdkroot");
54const CFStringRef kSecCodeSignerSigningTime = CFSTR("signing-time");
55const CFStringRef kSecCodeSignerRequireTimestamp = CFSTR("timestamp-required");
56const CFStringRef kSecCodeSignerTimestampServer = CFSTR("timestamp-url");
57const CFStringRef kSecCodeSignerTimestampAuthentication = CFSTR("timestamp-authentication");
58const CFStringRef kSecCodeSignerTimestampOmitCertificates = CFSTR("timestamp-omit-certificates");
427c49bc 59const CFStringRef kSecCodeSignerPreserveMetadata = CFSTR("preserve-metadata");
420ff9d9 60const CFStringRef kSecCodeSignerTeamIdentifier = CFSTR("teamidentifier");
5c19dc3a 61const CFStringRef kSecCodeSignerPlatformIdentifier = CFSTR("platform-identifier");
b1ab9ed8
A
62
63// temporary add-back to bridge B&I build dependencies -- remove soon
64const CFStringRef kSecCodeSignerTSAUse = CFSTR("timestamp-required");
65const CFStringRef kSecCodeSignerTSAURL = CFSTR("timestamp-url");
66const CFStringRef kSecCodeSignerTSAClientAuth = CFSTR("timestamp-authentication");
67const CFStringRef kSecCodeSignerTSANoCerts = CFSTR("timestamp-omit-certificates");
68
69
70//
71// CF-standard type code functions
72//
73CFTypeID SecCodeSignerGetTypeID(void)
74{
75 BEGIN_CSAPI
76 return gCFObjects().CodeSigner.typeID;
77 END_CSAPI1(_kCFRuntimeNotATypeID)
78}
79
80
81//
82// Create a signer object
83//
84OSStatus SecCodeSignerCreate(CFDictionaryRef parameters, SecCSFlags flags,
85 SecCodeSignerRef *signerRef)
86{
87 BEGIN_CSAPI
88
427c49bc
A
89 checkFlags(flags,
90 kSecCSRemoveSignature
91 | kSecCSSignPreserveSignature
92 | kSecCSSignNestedCode
93 | kSecCSSignOpaque
94 | kSecCSSignV1
80e23899
A
95 | kSecCSSignNoV1
96 | kSecCSSignBundleRoot
97 | kSecCSSignStrictPreflight);
b1ab9ed8
A
98 SecPointer<SecCodeSigner> signer = new SecCodeSigner(flags);
99 signer->parameters(parameters);
100 CodeSigning::Required(signerRef) = signer->handle();
101
102 END_CSAPI
103}
104
105
106//
107// Generate a signature
108//
109OSStatus SecCodeSignerAddSignature(SecCodeSignerRef signerRef,
110 SecStaticCodeRef codeRef, SecCSFlags flags)
111{
112 return SecCodeSignerAddSignatureWithErrors(signerRef, codeRef, flags, NULL);
113}
114
115OSStatus SecCodeSignerAddSignatureWithErrors(SecCodeSignerRef signerRef,
116 SecStaticCodeRef codeRef, SecCSFlags flags, CFErrorRef *errors)
117{
118 BEGIN_CSAPI
d8f41ccd
A
119 checkFlags(flags,
120 kSecCSReportProgress
121 );
b1ab9ed8
A
122 SecCodeSigner::required(signerRef)->sign(SecStaticCode::required(codeRef), flags);
123 END_CSAPI_ERRORS
124}