48 lines
2.0 KiB
Python
48 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
"""Validate Phase-1.0AG byte identities and closed parser boundary."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import ast
|
|
import hashlib
|
|
import json
|
|
from pathlib import Path
|
|
|
|
|
|
def identity(path: Path) -> tuple[int, str]:
|
|
data = path.read_bytes()
|
|
return len(data), hashlib.sha256(data).hexdigest()
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--root", type=Path, required=True)
|
|
root = parser.parse_args().root
|
|
data = json.loads((root / "manifests/retroarch/phase-1.0ag-bounded-elf-contract.json").read_text(encoding="utf-8"))
|
|
bindings = data["source_bindings"]
|
|
assert hashlib.sha256((root / "manifests/retroarch/phase-1.0af-bigapp-lifecycle-model.json").read_bytes()).hexdigest() == bindings["phase10af_manifest_sha256"]
|
|
for prefix, relative in (("validator", "tools/phase10ag_bounded_elf.py"),
|
|
("tests", "tests/test_phase10ag_bounded_elf.py")):
|
|
size, digest = identity(root / relative)
|
|
assert size == bindings[f"{prefix}_size"]
|
|
assert digest == bindings[f"{prefix}_sha256"]
|
|
source = (root / "tools/phase10ag_bounded_elf.py").read_text(encoding="utf-8")
|
|
tree = ast.parse(source)
|
|
imports = {alias.name.split(".")[0] for node in ast.walk(tree)
|
|
if isinstance(node, ast.Import) for alias in node.names}
|
|
imports.update(node.module.split(".")[0] for node in ast.walk(tree)
|
|
if isinstance(node, ast.ImportFrom) and node.module)
|
|
assert not imports.intersection({"pathlib", "os", "sys", "subprocess", "socket", "ctypes", "mmap"})
|
|
assert data["historical_reference"]["validated_by_phase10ag"] is False
|
|
assert not any(data["authorizations"].values())
|
|
assert data["decision"]["target_implementation_allowed"] is False
|
|
assert data["decision"]["device_action_allowed"] is False
|
|
print("Phase-1.0AG bounded ELF contract validation passed")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|