]>
Commit | Line | Data |
---|---|---|
5ba3f43e A |
1 | /* |
2 | * Copyright (c) 2017 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_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. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | ||
29 | #ifndef _KERN_CODESIGN_H_ | |
30 | #define _KERN_CODESIGN_H_ | |
31 | ||
32 | /* code signing attributes of a process */ | |
d9a64523 A |
33 | #define CS_VALID 0x00000001 /* dynamically valid */ |
34 | #define CS_ADHOC 0x00000002 /* ad hoc signed */ | |
35 | #define CS_GET_TASK_ALLOW 0x00000004 /* has get-task-allow entitlement */ | |
36 | #define CS_INSTALLER 0x00000008 /* has installer entitlement */ | |
37 | ||
38 | #define CS_FORCED_LV 0x00000010 /* Library Validation required by Hardened System Policy */ | |
39 | #define CS_INVALID_ALLOWED 0x00000020 /* (macOS Only) Page invalidation allowed by task port policy */ | |
40 | ||
41 | #define CS_HARD 0x00000100 /* don't load invalid pages */ | |
42 | #define CS_KILL 0x00000200 /* kill process if it becomes invalid */ | |
43 | #define CS_CHECK_EXPIRATION 0x00000400 /* force expiration checking */ | |
44 | #define CS_RESTRICT 0x00000800 /* tell dyld to treat restricted */ | |
45 | ||
46 | #define CS_ENFORCEMENT 0x00001000 /* require enforcement */ | |
47 | #define CS_REQUIRE_LV 0x00002000 /* require library validation */ | |
48 | #define CS_ENTITLEMENTS_VALIDATED 0x00004000 /* code signature permits restricted entitlements */ | |
49 | #define CS_NVRAM_UNRESTRICTED 0x00008000 /* has com.apple.rootless.restricted-nvram-variables.heritable entitlement */ | |
50 | ||
0a7de745 | 51 | #define CS_RUNTIME 0x00010000 /* Apply hardened runtime policies */ |
d9a64523 A |
52 | |
53 | #define CS_ALLOWED_MACHO (CS_ADHOC | CS_HARD | CS_KILL | CS_CHECK_EXPIRATION | \ | |
0a7de745 | 54 | CS_RESTRICT | CS_ENFORCEMENT | CS_REQUIRE_LV | CS_RUNTIME) |
d9a64523 A |
55 | |
56 | #define CS_EXEC_SET_HARD 0x00100000 /* set CS_HARD on any exec'ed process */ | |
57 | #define CS_EXEC_SET_KILL 0x00200000 /* set CS_KILL on any exec'ed process */ | |
58 | #define CS_EXEC_SET_ENFORCEMENT 0x00400000 /* set CS_ENFORCEMENT on any exec'ed process */ | |
59 | #define CS_EXEC_INHERIT_SIP 0x00800000 /* set CS_INSTALLER on any exec'ed process */ | |
60 | ||
61 | #define CS_KILLED 0x01000000 /* was killed by kernel for invalidity */ | |
62 | #define CS_DYLD_PLATFORM 0x02000000 /* dyld used to load this is a platform binary */ | |
63 | #define CS_PLATFORM_BINARY 0x04000000 /* this is a platform binary */ | |
64 | #define CS_PLATFORM_PATH 0x08000000 /* platform binary by the fact of path (osx only) */ | |
65 | ||
66 | #define CS_DEBUGGED 0x10000000 /* process is currently or has previously been debugged and allowed to run with invalid pages */ | |
67 | #define CS_SIGNED 0x20000000 /* process has a signature (may have gone invalid) */ | |
68 | #define CS_DEV_CODE 0x40000000 /* code is dev signed, cannot be loaded into prod signed code (will go away with rdar://problem/28322552) */ | |
69 | #define CS_DATAVAULT_CONTROLLER 0x80000000 /* has Data Vault controller entitlement */ | |
70 | ||
71 | #define CS_ENTITLEMENT_FLAGS (CS_GET_TASK_ALLOW | CS_INSTALLER | CS_DATAVAULT_CONTROLLER | CS_NVRAM_UNRESTRICTED) | |
5ba3f43e A |
72 | |
73 | /* executable segment flags */ | |
74 | ||
0a7de745 A |
75 | #define CS_EXECSEG_MAIN_BINARY 0x1 /* executable segment denotes main binary */ |
76 | #define CS_EXECSEG_ALLOW_UNSIGNED 0x10 /* allow unsigned pages (for debugging) */ | |
77 | #define CS_EXECSEG_DEBUGGER 0x20 /* main binary is debugger */ | |
78 | #define CS_EXECSEG_JIT 0x40 /* JIT enabled */ | |
79 | #define CS_EXECSEG_SKIP_LV 0x80 /* OBSOLETE: skip library validation */ | |
80 | #define CS_EXECSEG_CAN_LOAD_CDHASH 0x100 /* can bless cdhash for execution */ | |
81 | #define CS_EXECSEG_CAN_EXEC_CDHASH 0x200 /* can execute blessed cdhash */ | |
5ba3f43e A |
82 | |
83 | /* | |
84 | * Magic numbers used by Code Signing | |
85 | */ | |
86 | enum { | |
0a7de745 A |
87 | CSMAGIC_REQUIREMENT = 0xfade0c00, /* single Requirement blob */ |
88 | CSMAGIC_REQUIREMENTS = 0xfade0c01, /* Requirements vector (internal requirements) */ | |
89 | CSMAGIC_CODEDIRECTORY = 0xfade0c02, /* CodeDirectory blob */ | |
5ba3f43e | 90 | CSMAGIC_EMBEDDED_SIGNATURE = 0xfade0cc0, /* embedded form of signature data */ |
0a7de745 A |
91 | CSMAGIC_EMBEDDED_SIGNATURE_OLD = 0xfade0b02, /* XXX */ |
92 | CSMAGIC_EMBEDDED_ENTITLEMENTS = 0xfade7171, /* embedded entitlements */ | |
5ba3f43e | 93 | CSMAGIC_DETACHED_SIGNATURE = 0xfade0cc1, /* multi-arch collection of embedded signatures */ |
0a7de745 | 94 | CSMAGIC_BLOBWRAPPER = 0xfade0b01, /* CMS Signature, among other things */ |
5ba3f43e A |
95 | |
96 | CS_SUPPORTSSCATTER = 0x20100, | |
97 | CS_SUPPORTSTEAMID = 0x20200, | |
98 | CS_SUPPORTSCODELIMIT64 = 0x20300, | |
99 | CS_SUPPORTSEXECSEG = 0x20400, | |
100 | ||
0a7de745 | 101 | CSSLOT_CODEDIRECTORY = 0, /* slot index for CodeDirectory */ |
5ba3f43e A |
102 | CSSLOT_INFOSLOT = 1, |
103 | CSSLOT_REQUIREMENTS = 2, | |
104 | CSSLOT_RESOURCEDIR = 3, | |
105 | CSSLOT_APPLICATION = 4, | |
106 | CSSLOT_ENTITLEMENTS = 5, | |
107 | ||
108 | CSSLOT_ALTERNATE_CODEDIRECTORIES = 0x1000, /* first alternate CodeDirectory, if any */ | |
0a7de745 | 109 | CSSLOT_ALTERNATE_CODEDIRECTORY_MAX = 5, /* max number of alternate CD slots */ |
5ba3f43e A |
110 | CSSLOT_ALTERNATE_CODEDIRECTORY_LIMIT = CSSLOT_ALTERNATE_CODEDIRECTORIES + CSSLOT_ALTERNATE_CODEDIRECTORY_MAX, /* one past the last */ |
111 | ||
0a7de745 | 112 | CSSLOT_SIGNATURESLOT = 0x10000, /* CMS Signature */ |
d9a64523 A |
113 | CSSLOT_IDENTIFICATIONSLOT = 0x10001, |
114 | CSSLOT_TICKETSLOT = 0x10002, | |
5ba3f43e | 115 | |
0a7de745 A |
116 | CSTYPE_INDEX_REQUIREMENTS = 0x00000002, /* compat with amfi */ |
117 | CSTYPE_INDEX_ENTITLEMENTS = 0x00000005, /* compat with amfi */ | |
5ba3f43e A |
118 | |
119 | CS_HASHTYPE_SHA1 = 1, | |
120 | CS_HASHTYPE_SHA256 = 2, | |
121 | CS_HASHTYPE_SHA256_TRUNCATED = 3, | |
122 | CS_HASHTYPE_SHA384 = 4, | |
123 | ||
124 | CS_SHA1_LEN = 20, | |
125 | CS_SHA256_LEN = 32, | |
126 | CS_SHA256_TRUNCATED_LEN = 20, | |
127 | ||
0a7de745 | 128 | CS_CDHASH_LEN = 20, /* always - larger hashes are truncated */ |
5ba3f43e A |
129 | CS_HASH_MAX_SIZE = 48, /* max size of the hash we'll support */ |
130 | ||
131 | /* | |
4ba76501 | 132 | * Currently only to support Legacy VPN plugins, and Mac App Store |
5ba3f43e A |
133 | * but intended to replace all the various platform code, dev code etc. bits. |
134 | */ | |
135 | CS_SIGNER_TYPE_UNKNOWN = 0, | |
136 | CS_SIGNER_TYPE_LEGACYVPN = 5, | |
4ba76501 | 137 | CS_SIGNER_TYPE_MAC_APP_STORE = 6, |
5ba3f43e A |
138 | }; |
139 | ||
140 | #define KERNEL_HAVE_CS_CODEDIRECTORY 1 | |
141 | #define KERNEL_CS_CODEDIRECTORY_HAVE_PLATFORM 1 | |
142 | ||
143 | /* | |
144 | * C form of a CodeDirectory. | |
145 | */ | |
146 | typedef struct __CodeDirectory { | |
0a7de745 A |
147 | uint32_t magic; /* magic number (CSMAGIC_CODEDIRECTORY) */ |
148 | uint32_t length; /* total length of CodeDirectory blob */ | |
149 | uint32_t version; /* compatibility version */ | |
150 | uint32_t flags; /* setup and mode flags */ | |
151 | uint32_t hashOffset; /* offset of hash slot element at index zero */ | |
152 | uint32_t identOffset; /* offset of identifier string */ | |
153 | uint32_t nSpecialSlots; /* number of special hash slots */ | |
154 | uint32_t nCodeSlots; /* number of ordinary (code) hash slots */ | |
155 | uint32_t codeLimit; /* limit to main image signature range */ | |
156 | uint8_t hashSize; /* size of each hash in bytes */ | |
157 | uint8_t hashType; /* type of hash (cdHashType* constants) */ | |
158 | uint8_t platform; /* platform identifier; zero if not platform binary */ | |
159 | uint8_t pageSize; /* log2(page size in bytes); 0 => infinite */ | |
160 | uint32_t spare2; /* unused (must be zero) */ | |
5ba3f43e A |
161 | |
162 | char end_earliest[0]; | |
163 | ||
164 | /* Version 0x20100 */ | |
0a7de745 | 165 | uint32_t scatterOffset; /* offset of optional scatter vector */ |
5ba3f43e A |
166 | char end_withScatter[0]; |
167 | ||
168 | /* Version 0x20200 */ | |
0a7de745 | 169 | uint32_t teamOffset; /* offset of optional team identifier */ |
5ba3f43e A |
170 | char end_withTeam[0]; |
171 | ||
172 | /* Version 0x20300 */ | |
0a7de745 A |
173 | uint32_t spare3; /* unused (must be zero) */ |
174 | uint64_t codeLimit64; /* limit to main image signature range, 64 bits */ | |
5ba3f43e A |
175 | char end_withCodeLimit64[0]; |
176 | ||
177 | /* Version 0x20400 */ | |
0a7de745 A |
178 | uint64_t execSegBase; /* offset of executable segment */ |
179 | uint64_t execSegLimit; /* limit of executable segment */ | |
180 | uint64_t execSegFlags; /* executable segment flags */ | |
5ba3f43e A |
181 | char end_withExecSeg[0]; |
182 | ||
183 | /* followed by dynamic content as located by offset fields above */ | |
184 | } CS_CodeDirectory | |
185 | __attribute__ ((aligned(1))); | |
186 | ||
187 | /* | |
188 | * Structure of an embedded-signature SuperBlob | |
189 | */ | |
190 | ||
191 | typedef struct __BlobIndex { | |
0a7de745 A |
192 | uint32_t type; /* type of entry */ |
193 | uint32_t offset; /* offset of entry */ | |
5ba3f43e A |
194 | } CS_BlobIndex |
195 | __attribute__ ((aligned(1))); | |
196 | ||
197 | typedef struct __SC_SuperBlob { | |
0a7de745 A |
198 | uint32_t magic; /* magic number */ |
199 | uint32_t length; /* total length of SuperBlob */ | |
200 | uint32_t count; /* number of index entries following */ | |
201 | CS_BlobIndex index[]; /* (count) entries */ | |
5ba3f43e A |
202 | /* followed by Blobs in no particular order as indicated by offsets in index */ |
203 | } CS_SuperBlob | |
204 | __attribute__ ((aligned(1))); | |
205 | ||
206 | #define KERNEL_HAVE_CS_GENERICBLOB 1 | |
207 | typedef struct __SC_GenericBlob { | |
0a7de745 A |
208 | uint32_t magic; /* magic number */ |
209 | uint32_t length; /* total length of blob */ | |
5ba3f43e A |
210 | char data[]; |
211 | } CS_GenericBlob | |
212 | __attribute__ ((aligned(1))); | |
213 | ||
214 | typedef struct __SC_Scatter { | |
0a7de745 A |
215 | uint32_t count; // number of pages; zero for sentinel (only) |
216 | uint32_t base; // first page number | |
217 | uint64_t targetOffset; // offset in target | |
218 | uint64_t spare; // reserved | |
5ba3f43e A |
219 | } SC_Scatter |
220 | __attribute__ ((aligned(1))); | |
221 | ||
222 | ||
223 | #endif /* _KERN_CODESIGN_H */ |