plugins/tools/plugin_arrakis_raw_spice.py
unimatrixgit 90cd25de67
Some checks failed
Arrakis Raw Spice Build / raw-spice (push) Failing after 41s
DuneRealms Plugin CI / plugins (push) Has been cancelled
Assemble the spice overlay against the exact retained Arrakis JAR
2026-11-30 20:33:08 +01:00

53 lines
2.5 KiB
Python

from pathlib import Path
import hashlib
import io
import zipfile
BASELINE_SHA256 = 'ebe8d2edc9f3300a039de1f76b81a2435895569704b2087e0625db699effe5d7'
OVERLAY = 'com/dunerealms/jarvis/ItemMetadataOverlay.class'
RETAINED_TREE = '80df0c65f8d85bcac8dd52c620197f4013a7f17e48a422ef8da1d451674c2'
DESCRIPTOR_SHA256 = '5d953df8bfa49bc5e57a698c018ea24bba3253a53d291ac6e48dd03d7e162a5a'
def verify_jar(path):
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')
def assemble(baseline_artifact, compiled, output):
with zipfile.ZipFile(baseline_artifact) as wrapper:
names = wrapper.namelist()
if len(names) == 1 and names[0].endswith('.zip'):
with zipfile.ZipFile(io.BytesIO(wrapper.read(names[0]))) as release:
baseline = release.read('jarvistranslator.jar')
else:
baseline = wrapper.read('jarvistranslator.jar')
if hashlib.sha256(baseline).hexdigest() != BASELINE_SHA256:
raise ValueError('Retained Jarvis baseline differs from deployed Arrakis runtime')
with zipfile.ZipFile(io.BytesIO(baseline)) as original, zipfile.ZipFile(compiled) as build:
replacements = {entry: build.read(entry) for entry in (OVERLAY, 'plugin.yml')}
with zipfile.ZipFile(output, 'x') as result:
for info in original.infolist():
data = replacements[info.filename] if info.filename in replacements else original.read(info)
result.writestr(info, data)
verify_jar(output)
if __name__ == '__main__':
import sys
if len(sys.argv) == 4:
assemble(*map(Path, sys.argv[1:]))
elif len(sys.argv) == 2:
verify_jar(Path(sys.argv[1]))
else:
raise SystemExit('Specify a JAR to verify, or baseline artifact, built JAR and output JAR')