from pathlib import Path import hashlib import zipfile BASELINE_SHA256 = '4585825d0ac6cc70b0c95988cf4e8eb0f378e473d33a10b0a98c4b75fee51a8d' OVERLAY = 'com/dunerealms/menus/SuppliedDocument.class' RETAINED_TREE = 'b8ed957242f45c034250cb482a23f91af7affe11167e5a7e9d070360d57f85df' DESCRIPTOR_SHA256 = '0fb38d824e501a45cefee7f04d8b3034c3d735ee9833a48207d58b193717e70f' 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 DuneMenus archive entry') markup = jar.read(OVERLAY) if b'THE SPICE MUST FLOW' not in markup or b'house-choices' not in markup: raise ValueError('Compact menu or House-choice markup is missing') if hashlib.sha256(jar.read('plugin.yml')).hexdigest() != DESCRIPTOR_SHA256: raise ValueError('DuneMenus 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('DuneMenus changed outside the reviewed compact UI and version') if __name__ == '__main__': import sys verify_jar(Path(sys.argv[1]))