|
|
@@ -50,7 +50,7 @@ def prepare_identity(product,bitstream,receipt_path):
|
|
|
'bitstream_sha256':bit_hash,'bitstream_source_commit':receipt['commit'],'bitstream_source_tree':receipt['tree'],
|
|
|
'source_manifest_sha256':manifest_sha,'td_receipt_sha256':sha(receipt_path)}
|
|
|
|
|
|
-def validate_executable(exe,metadata):
|
|
|
+def validate_executable(exe,metadata,assets):
|
|
|
from PyInstaller.archive.readers import CArchiveReader
|
|
|
if Path(exe).read_bytes()[:2]!=b'MZ':raise ValueError('GUI is not a Windows PE executable')
|
|
|
reader=CArchiveReader(str(exe))
|
|
|
@@ -58,10 +58,18 @@ def validate_executable(exe,metadata):
|
|
|
if len(keys)!=1:raise ValueError('embedded GUI metadata missing or ambiguous')
|
|
|
embedded=json.loads(reader.extract(keys[0]))
|
|
|
if embedded!=metadata:raise ValueError('actual embedded GUI metadata mismatch')
|
|
|
+ asset_hashes={}
|
|
|
+ for path,destination in assets:
|
|
|
+ name=(destination+'/'+Path(path).name).removeprefix('./')
|
|
|
+ matches=[key for key in reader.toc if key.replace('\\','/')==name]
|
|
|
+ if len(matches)!=1:raise ValueError('embedded GUI asset missing: '+name)
|
|
|
+ actual=hashlib.sha256(reader.extract(matches[0])).hexdigest()
|
|
|
+ if actual!=sha(path):raise ValueError('embedded GUI asset differs from source: '+name)
|
|
|
+ asset_hashes[name]=actual
|
|
|
run=subprocess.run([str(exe),'--self-test'],capture_output=True,timeout=60,creationflags=getattr(subprocess,'CREATE_NO_WINDOW',0))
|
|
|
if run.returncode:raise ValueError('offline GUI self-test failed: '+str(run.returncode))
|
|
|
return {'schema':'prod2u-gui-validation-v1','exe_sha256':sha(exe),'self_test_exit':run.returncode,
|
|
|
- 'embedded_metadata':embedded,'ui_visual_validation':'PENDING','hardware':'NOT_RUN'}
|
|
|
+ 'embedded_metadata':embedded,'embedded_assets_sha256':asset_hashes,'ui_visual_validation':'PENDING','hardware':'NOT_RUN'}
|
|
|
|
|
|
def main(fixed_product=None):
|
|
|
ap=argparse.ArgumentParser(description=__doc__)
|
|
|
@@ -94,7 +102,7 @@ def main(fixed_product=None):
|
|
|
'--paths',str(ROOT/'tools/_vendor'),'--hidden-import','hth_protocol','--hidden-import','prod2u_status']
|
|
|
for path,destination in assets:command+=['--add-data',str(path)+';'+destination]
|
|
|
subprocess.run(command+[str(ROOT/'tools'/PRODUCTS[product]['script'])],cwd=ROOT,check=True)
|
|
|
- validation=validate_executable(exe,metadata)
|
|
|
+ validation=validate_executable(exe,metadata,assets)
|
|
|
(out/'GUI-VALIDATION.json').write_text(json.dumps(validation,indent=2)+'\n')
|
|
|
print(json.dumps({'exe':str(exe),'sha256':sha(exe),'bytes':exe.stat().st_size,**metadata},indent=2))
|
|
|
return 0
|