# SPDX-License-Identifier: GPL-3.0-or-later """Validate the explicitly staged private disk-driver extension.""" import hashlib STANDALONE_FILES = { 'share/cmoc/lib/libdskcon-standalone.a', 'share/cmoc/include/dskcon-standalone.h', 'LICENSES/DSKCON-STANDALONE-NOTICE.txt', } def validate_private_inputs(runtime, record): disk = record.get('standaloneDisk') if disk is None: if record.get('privateRuntimeInputs') is not False: raise ValueError('Private runtime input declaration is missing') if any((runtime / path).exists() for path in STANDALONE_FILES - {'share/cmoc/include/dskcon-standalone.h'}): raise ValueError('Undeclared standalone disk payload') return if record.get('privateRuntimeInputs') is not True or disk.get('profile') != 'decb-derived-standalone': raise ValueError('Unsupported private runtime profile') hashes = disk.get('filesSHA256', {}) if set(hashes) != STANDALONE_FILES: raise ValueError('Incomplete standalone disk payload declaration') if disk.get('license') != 'public-domain-except-DECB-derived-portions': raise ValueError('Missing standalone disk license distinction') if not isinstance(disk.get('sourceSHA256'), str) or len(disk['sourceSHA256']) != 64: raise ValueError('Missing standalone disk source identity') for relative, expected in hashes.items(): path = runtime / relative if path.is_symlink() or not path.is_file() or hashlib.sha256(path.read_bytes()).hexdigest() != expected: raise ValueError('Standalone disk payload does not match its manifest: ' + relative)