30 lines
1.4 KiB
Python
30 lines
1.4 KiB
Python
from pathlib import Path
|
|
import hashlib
|
|
import zipfile
|
|
|
|
BASELINE_SHA256 = '1b8bbfe5ff34341e54267bca2fb87aabc780e483b5ea015870dd517b99af8871'
|
|
OVERLAY = 'com/dunerealms/menus/SuppliedDocument.class'
|
|
RETAINED_TREE = 'b8ed957242f45c034250cb482a23f91af7affe11167e5a7e9d070360d57f85df'
|
|
DESCRIPTOR_SHA256 = '209c7f8da76a2788ce40de9e83fbca9e4370c665cf5d9803b5ea31d812f1894b'
|
|
|
|
|
|
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')
|
|
if b'THE SPICE MUST FLOW' not in jar.read(OVERLAY):
|
|
raise ValueError('Compact menu 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]))
|

Staff