#!/usr/bin/env python3 """Build the trust bundle for the boot image: one owner module for the Adreno Metal plugin, then the two original Apple trust modules byte for byte. Output: build/adreno-metal-plugin/owner-trust.bundle (ignored). The original modules are verified unchanged against build/original-static-system-trust; only the plugin's CDHash is added.""" import hashlib import json from pathlib import Path import struct import uuid ROOT = Path(__file__).resolve().parents[1] original = (ROOT / 'build/original-static-system-trust/original-static-system.bundle').read_bytes() if hashlib.sha256(original).hexdigest() != '7416ca4f8377146626bb284e2133c76bee6cb4e3ee0af5d648b186235a7323a7': raise SystemExit('The original static/System trust bundle differs from the unchanged target input') count = struct.unpack_from(' len(data) or end - start < 24 or struct.unpack_from('= data[at:at + 20]): return False return True if not valid_like_the_loader(bundle): raise SystemExit('The trust bundle would be refused by the boot loader') out = ROOT / 'build/adreno-metal-plugin/owner-trust.bundle' out.write_bytes(bundle) (ROOT / 'build/adreno-metal-plugin/owner-trust.json').write_text(json.dumps(dict( bundle_sha256=hashlib.sha256(bundle).hexdigest(), own_cdhashes=[h.hex() for h in hashes], original_modules_unchanged=True, apple_trust_chain_verified=False, purpose='owner trust for the Adreno Metal plugin only'), indent=2) + '\n') print('PASS: owner trust bundle (own module + both original modules)', hashlib.sha256(bundle).hexdigest())