from pathlib import Path import hashlib import zipfile BASELINE_SHA256 = 'ebe8d2edc9f3300a039de1f76b81a2435895569704b2087e0625db699effe5d7' OVERLAY = 'com/dunerealms/jarvis/ItemMetadataOverlay.class' RETAINED_TREE = '80df0c65f8d85bcac8dd52c620197f4013a7f17e48a422ef8da1d451674c2be5' DESCRIPTOR_SHA256 = '5d953df8bfa49bc5e57a698c018ea24bba3253a53d291ac6e48dd03d7e162a5a' def verify_jar(path): if any(len(pin) != 64 for pin in (BASELINE_SHA256, RETAINED_TREE, DESCRIPTOR_SHA256)): raise ValueError('Expected complete SHA-256 pins') with zipfile.ZipFile(path) as jar: names = [name for name in jar.namelist() if not name.endswith('/')] if len(set(names)) != len(names): raise ValueError('Duplicate JARVIS archive entry') if b'spice_common' not in jar.read(OVERLAY): raise ValueError('Raw spice model missing from ItemMetadataOverlay') if hashlib.sha256(jar.read('plugin.yml')).hexdigest() != DESCRIPTOR_SHA256: raise ValueError('JARVIS descriptor differs outside the reviewed version') rows = [name + '\0' + hashlib.sha256(jar.read(name)).hexdigest() for name in sorted(names) if name not in {OVERLAY, 'plugin.yml'}] if hashlib.sha256('\n'.join(rows).encode()).hexdigest() != RETAINED_TREE: raise ValueError('JARVIS changed outside the reviewed raw spice overlay and version') if __name__ == '__main__': import sys verify_jar(Path(sys.argv[1]))