1*27b03b36SApple OSS Distributions /* 2*27b03b36SApple OSS Distributions * Copyright (c) 2018 Apple Computer, Inc. All rights reserved. 3*27b03b36SApple OSS Distributions * 4*27b03b36SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*27b03b36SApple OSS Distributions * 6*27b03b36SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*27b03b36SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*27b03b36SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*27b03b36SApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*27b03b36SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*27b03b36SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*27b03b36SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*27b03b36SApple OSS Distributions * terms of an Apple operating system software license agreement. 14*27b03b36SApple OSS Distributions * 15*27b03b36SApple OSS Distributions * Please obtain a copy of the License at 16*27b03b36SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*27b03b36SApple OSS Distributions * 18*27b03b36SApple OSS Distributions * The Original Code and all software distributed under the License are 19*27b03b36SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*27b03b36SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*27b03b36SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*27b03b36SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*27b03b36SApple OSS Distributions * Please see the License for the specific language governing rights and 24*27b03b36SApple OSS Distributions * limitations under the License. 25*27b03b36SApple OSS Distributions * 26*27b03b36SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*27b03b36SApple OSS Distributions */ 28*27b03b36SApple OSS Distributions 29*27b03b36SApple OSS Distributions #ifndef _KERN_TRUSTCACHE_H_ 30*27b03b36SApple OSS Distributions #define _KERN_TRUSTCACHE_H_ 31*27b03b36SApple OSS Distributions 32*27b03b36SApple OSS Distributions #include <stdint.h> 33*27b03b36SApple OSS Distributions 34*27b03b36SApple OSS Distributions #include <kern/cs_blobs.h> 35*27b03b36SApple OSS Distributions 36*27b03b36SApple OSS Distributions #include <uuid/uuid.h> 37*27b03b36SApple OSS Distributions 38*27b03b36SApple OSS Distributions #ifdef PLATFORM_BridgeOS 39*27b03b36SApple OSS Distributions /* Version 0 trust caches: No defined sorting order (thus only suitable for small trust caches). 40*27b03b36SApple OSS Distributions * Used for loadable trust caches only, until phasing out support. */ 41*27b03b36SApple OSS Distributions typedef uint8_t trust_cache_hash0[CS_CDHASH_LEN]; 42*27b03b36SApple OSS Distributions struct trust_cache_module0 { 43*27b03b36SApple OSS Distributions uint32_t version; 44*27b03b36SApple OSS Distributions uuid_t uuid; 45*27b03b36SApple OSS Distributions uint32_t num_hashes; 46*27b03b36SApple OSS Distributions trust_cache_hash0 hashes[]; 47*27b03b36SApple OSS Distributions } __attribute__((__packed__)); 48*27b03b36SApple OSS Distributions #endif 49*27b03b36SApple OSS Distributions 50*27b03b36SApple OSS Distributions 51*27b03b36SApple OSS Distributions /* Version 1 trust caches: Always sorted by cdhash, added hash type and flags field. 52*27b03b36SApple OSS Distributions * Suitable for all trust caches. */ 53*27b03b36SApple OSS Distributions 54*27b03b36SApple OSS Distributions struct trust_cache_entry1 { 55*27b03b36SApple OSS Distributions uint8_t cdhash[CS_CDHASH_LEN]; 56*27b03b36SApple OSS Distributions uint8_t hash_type; 57*27b03b36SApple OSS Distributions uint8_t flags; 58*27b03b36SApple OSS Distributions } __attribute__((__packed__)); 59*27b03b36SApple OSS Distributions 60*27b03b36SApple OSS Distributions struct trust_cache_module1 { 61*27b03b36SApple OSS Distributions uint32_t version; 62*27b03b36SApple OSS Distributions uuid_t uuid; 63*27b03b36SApple OSS Distributions uint32_t num_entries; 64*27b03b36SApple OSS Distributions struct trust_cache_entry1 entries[]; 65*27b03b36SApple OSS Distributions } __attribute__((__packed__)); 66*27b03b36SApple OSS Distributions 67*27b03b36SApple OSS Distributions // Trust Cache Entry Flags 68*27b03b36SApple OSS Distributions #define CS_TRUST_CACHE_AMFID 0x1 // valid cdhash for amfid 69*27b03b36SApple OSS Distributions 70*27b03b36SApple OSS Distributions /* Trust Cache lookup functions return their result as a 32bit value 71*27b03b36SApple OSS Distributions * comprised of subfields, for straightforward passing through layers. 72*27b03b36SApple OSS Distributions * 73*27b03b36SApple OSS Distributions * Format: 74*27b03b36SApple OSS Distributions * 75*27b03b36SApple OSS Distributions * 0xXXCCBBAA 76*27b03b36SApple OSS Distributions * 77*27b03b36SApple OSS Distributions * AA: 0-7: lookup result 78*27b03b36SApple OSS Distributions * bit 0: TC_LOOKUP_FOUND: set if any entry found 79*27b03b36SApple OSS Distributions * bit 1: (obsolete) TC_LOOKUP_FALLBACK: set if found in legacy static trust cache 80*27b03b36SApple OSS Distributions * bit 2-7: reserved 81*27b03b36SApple OSS Distributions * BB: 8-15: entry flags pass-through, see "Trust Cache Entry Flags" above 82*27b03b36SApple OSS Distributions * CC: 16-23: code directory hash type of entry, see CS_HASHTYPE_* in cs_blobs.h 83*27b03b36SApple OSS Distributions * XX: 24-31: reserved 84*27b03b36SApple OSS Distributions */ 85*27b03b36SApple OSS Distributions 86*27b03b36SApple OSS Distributions #define TC_LOOKUP_HASH_TYPE_SHIFT 16 87*27b03b36SApple OSS Distributions #define TC_LOOKUP_HASH_TYPE_MASK 0xff0000L; 88*27b03b36SApple OSS Distributions #define TC_LOOKUP_FLAGS_SHIFT 8 89*27b03b36SApple OSS Distributions #define TC_LOOKUP_FLAGS_MASK 0xff00L 90*27b03b36SApple OSS Distributions #define TC_LOOKUP_RESULT_SHIFT 0 91*27b03b36SApple OSS Distributions #define TC_LOOKUP_RESULT_MASK 0xffL 92*27b03b36SApple OSS Distributions 93*27b03b36SApple OSS Distributions #define TC_LOOKUP_FOUND 1 94*27b03b36SApple OSS Distributions 95*27b03b36SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE 96*27b03b36SApple OSS Distributions 97*27b03b36SApple OSS Distributions // Serialized Trust Caches 98*27b03b36SApple OSS Distributions 99*27b03b36SApple OSS Distributions /* This is how iBoot delivers them to us. */ 100*27b03b36SApple OSS Distributions struct serialized_trust_caches { 101*27b03b36SApple OSS Distributions uint32_t num_caches; 102*27b03b36SApple OSS Distributions uint32_t offsets[0]; 103*27b03b36SApple OSS Distributions } __attribute__((__packed__)); 104*27b03b36SApple OSS Distributions 105*27b03b36SApple OSS Distributions 106*27b03b36SApple OSS Distributions void trust_cache_init(void); 107*27b03b36SApple OSS Distributions 108*27b03b36SApple OSS Distributions uint32_t lookup_in_static_trust_cache(const uint8_t cdhash[CS_CDHASH_LEN]); 109*27b03b36SApple OSS Distributions 110*27b03b36SApple OSS Distributions bool lookup_in_trust_cache_module(struct trust_cache_module1 const * const module, 111*27b03b36SApple OSS Distributions uint8_t const cdhash[CS_CDHASH_LEN], 112*27b03b36SApple OSS Distributions uint8_t * const hash_type, 113*27b03b36SApple OSS Distributions uint8_t * const flags); 114*27b03b36SApple OSS Distributions 115*27b03b36SApple OSS Distributions #endif 116*27b03b36SApple OSS Distributions 117*27b03b36SApple OSS Distributions #endif /* _KERN_TRUSTCACHE_H */ 118