2 * Copyright (c) 2017 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_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. 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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _KERN_CODESIGN_H_
30 #define _KERN_CODESIGN_H_
32 /* code signing attributes of a process */
33 #define CS_VALID 0x0000001 /* dynamically valid */
34 #define CS_ADHOC 0x0000002 /* ad hoc signed */
35 #define CS_GET_TASK_ALLOW 0x0000004 /* has get-task-allow entitlement */
36 #define CS_INSTALLER 0x0000008 /* has installer entitlement */
38 #define CS_HARD 0x0000100 /* don't load invalid pages */
39 #define CS_KILL 0x0000200 /* kill process if it becomes invalid */
40 #define CS_CHECK_EXPIRATION 0x0000400 /* force expiration checking */
41 #define CS_RESTRICT 0x0000800 /* tell dyld to treat restricted */
42 #define CS_ENFORCEMENT 0x0001000 /* require enforcement */
43 #define CS_REQUIRE_LV 0x0002000 /* require library validation */
44 #define CS_ENTITLEMENTS_VALIDATED 0x0004000 /* code signature permits restricted entitlements */
45 #define CS_NVRAM_UNRESTRICTED 0x0008000 /* has com.apple.rootless.restricted-nvram-variables.heritable entitlement */
47 #define CS_ALLOWED_MACHO (CS_ADHOC | CS_HARD | CS_KILL | CS_CHECK_EXPIRATION | \
48 CS_RESTRICT | CS_ENFORCEMENT | CS_REQUIRE_LV)
50 #define CS_EXEC_SET_HARD 0x0100000 /* set CS_HARD on any exec'ed process */
51 #define CS_EXEC_SET_KILL 0x0200000 /* set CS_KILL on any exec'ed process */
52 #define CS_EXEC_SET_ENFORCEMENT 0x0400000 /* set CS_ENFORCEMENT on any exec'ed process */
53 #define CS_EXEC_INHERIT_SIP 0x0800000 /* set CS_INSTALLER on any exec'ed process */
55 #define CS_KILLED 0x1000000 /* was killed by kernel for invalidity */
56 #define CS_DYLD_PLATFORM 0x2000000 /* dyld used to load this is a platform binary */
57 #define CS_PLATFORM_BINARY 0x4000000 /* this is a platform binary */
58 #define CS_PLATFORM_PATH 0x8000000 /* platform binary by the fact of path (osx only) */
59 #define CS_DEBUGGED 0x10000000 /* process is currently or has previously been debugged and allowed to run with invalid pages */
60 #define CS_SIGNED 0x20000000 /* process has a signature (may have gone invalid) */
61 #define CS_DEV_CODE 0x40000000 /* code is dev signed, cannot be loaded into prod signed code (will go away with rdar://problem/28322552) */
62 #define CS_DATAVAULT_CONTROLLER 0x80000000 /* has Data Vault controller entitlement */
64 #define CS_ENTITLEMENT_FLAGS (CS_GET_TASK_ALLOW | CS_INSTALLER | CS_DATAVAULT_CONTROLLER | CS_NVRAM_UNRESTRICTED)
66 /* executable segment flags */
68 #define CS_EXECSEG_MAIN_BINARY 0x1 /* executable segment denotes main binary */
69 #define CS_EXECSEG_ALLOW_UNSIGNED 0x10 /* allow unsigned pages (for debugging) */
70 #define CS_EXECSEG_DEBUGGER 0x20 /* main binary is debugger */
71 #define CS_EXECSEG_JIT 0x40 /* JIT enabled */
72 #define CS_EXECSEG_SKIP_LV 0x80 /* skip library validation */
73 #define CS_EXECSEG_CAN_LOAD_CDHASH 0x100 /* can bless cdhash for execution */
74 #define CS_EXECSEG_CAN_EXEC_CDHASH 0x200 /* can execute blessed cdhash */
77 * Magic numbers used by Code Signing
80 CSMAGIC_REQUIREMENT
= 0xfade0c00, /* single Requirement blob */
81 CSMAGIC_REQUIREMENTS
= 0xfade0c01, /* Requirements vector (internal requirements) */
82 CSMAGIC_CODEDIRECTORY
= 0xfade0c02, /* CodeDirectory blob */
83 CSMAGIC_EMBEDDED_SIGNATURE
= 0xfade0cc0, /* embedded form of signature data */
84 CSMAGIC_EMBEDDED_SIGNATURE_OLD
= 0xfade0b02, /* XXX */
85 CSMAGIC_EMBEDDED_ENTITLEMENTS
= 0xfade7171, /* embedded entitlements */
86 CSMAGIC_DETACHED_SIGNATURE
= 0xfade0cc1, /* multi-arch collection of embedded signatures */
87 CSMAGIC_BLOBWRAPPER
= 0xfade0b01, /* CMS Signature, among other things */
89 CS_SUPPORTSSCATTER
= 0x20100,
90 CS_SUPPORTSTEAMID
= 0x20200,
91 CS_SUPPORTSCODELIMIT64
= 0x20300,
92 CS_SUPPORTSEXECSEG
= 0x20400,
94 CSSLOT_CODEDIRECTORY
= 0, /* slot index for CodeDirectory */
96 CSSLOT_REQUIREMENTS
= 2,
97 CSSLOT_RESOURCEDIR
= 3,
98 CSSLOT_APPLICATION
= 4,
99 CSSLOT_ENTITLEMENTS
= 5,
101 CSSLOT_ALTERNATE_CODEDIRECTORIES
= 0x1000, /* first alternate CodeDirectory, if any */
102 CSSLOT_ALTERNATE_CODEDIRECTORY_MAX
= 5, /* max number of alternate CD slots */
103 CSSLOT_ALTERNATE_CODEDIRECTORY_LIMIT
= CSSLOT_ALTERNATE_CODEDIRECTORIES
+ CSSLOT_ALTERNATE_CODEDIRECTORY_MAX
, /* one past the last */
105 CSSLOT_SIGNATURESLOT
= 0x10000, /* CMS Signature */
107 CSTYPE_INDEX_REQUIREMENTS
= 0x00000002, /* compat with amfi */
108 CSTYPE_INDEX_ENTITLEMENTS
= 0x00000005, /* compat with amfi */
110 CS_HASHTYPE_SHA1
= 1,
111 CS_HASHTYPE_SHA256
= 2,
112 CS_HASHTYPE_SHA256_TRUNCATED
= 3,
113 CS_HASHTYPE_SHA384
= 4,
117 CS_SHA256_TRUNCATED_LEN
= 20,
119 CS_CDHASH_LEN
= 20, /* always - larger hashes are truncated */
120 CS_HASH_MAX_SIZE
= 48, /* max size of the hash we'll support */
123 * Currently only to support Legacy VPN plugins,
124 * but intended to replace all the various platform code, dev code etc. bits.
126 CS_SIGNER_TYPE_UNKNOWN
= 0,
127 CS_SIGNER_TYPE_LEGACYVPN
= 5,
130 #define KERNEL_HAVE_CS_CODEDIRECTORY 1
131 #define KERNEL_CS_CODEDIRECTORY_HAVE_PLATFORM 1
134 * C form of a CodeDirectory.
136 typedef struct __CodeDirectory
{
137 uint32_t magic
; /* magic number (CSMAGIC_CODEDIRECTORY) */
138 uint32_t length
; /* total length of CodeDirectory blob */
139 uint32_t version
; /* compatibility version */
140 uint32_t flags
; /* setup and mode flags */
141 uint32_t hashOffset
; /* offset of hash slot element at index zero */
142 uint32_t identOffset
; /* offset of identifier string */
143 uint32_t nSpecialSlots
; /* number of special hash slots */
144 uint32_t nCodeSlots
; /* number of ordinary (code) hash slots */
145 uint32_t codeLimit
; /* limit to main image signature range */
146 uint8_t hashSize
; /* size of each hash in bytes */
147 uint8_t hashType
; /* type of hash (cdHashType* constants) */
148 uint8_t platform
; /* platform identifier; zero if not platform binary */
149 uint8_t pageSize
; /* log2(page size in bytes); 0 => infinite */
150 uint32_t spare2
; /* unused (must be zero) */
152 char end_earliest
[0];
154 /* Version 0x20100 */
155 uint32_t scatterOffset
; /* offset of optional scatter vector */
156 char end_withScatter
[0];
158 /* Version 0x20200 */
159 uint32_t teamOffset
; /* offset of optional team identifier */
160 char end_withTeam
[0];
162 /* Version 0x20300 */
163 uint32_t spare3
; /* unused (must be zero) */
164 uint64_t codeLimit64
; /* limit to main image signature range, 64 bits */
165 char end_withCodeLimit64
[0];
167 /* Version 0x20400 */
168 uint64_t execSegBase
; /* offset of executable segment */
169 uint64_t execSegLimit
; /* limit of executable segment */
170 uint64_t execSegFlags
; /* executable segment flags */
171 char end_withExecSeg
[0];
173 /* followed by dynamic content as located by offset fields above */
175 __attribute__ ((aligned(1)));
178 * Structure of an embedded-signature SuperBlob
181 typedef struct __BlobIndex
{
182 uint32_t type
; /* type of entry */
183 uint32_t offset
; /* offset of entry */
185 __attribute__ ((aligned(1)));
187 typedef struct __SC_SuperBlob
{
188 uint32_t magic
; /* magic number */
189 uint32_t length
; /* total length of SuperBlob */
190 uint32_t count
; /* number of index entries following */
191 CS_BlobIndex index
[]; /* (count) entries */
192 /* followed by Blobs in no particular order as indicated by offsets in index */
194 __attribute__ ((aligned(1)));
196 #define KERNEL_HAVE_CS_GENERICBLOB 1
197 typedef struct __SC_GenericBlob
{
198 uint32_t magic
; /* magic number */
199 uint32_t length
; /* total length of blob */
202 __attribute__ ((aligned(1)));
204 typedef struct __SC_Scatter
{
205 uint32_t count
; // number of pages; zero for sentinel (only)
206 uint32_t base
; // first page number
207 uint64_t targetOffset
; // offset in target
208 uint64_t spare
; // reserved
210 __attribute__ ((aligned(1)));
213 #endif /* _KERN_CODESIGN_H */