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.0AF identities and offline-only 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.0af-bigapp-lifecycle-model.json").read_text(encoding="utf-8"))
|
|
bindings = data["source_bindings"]
|
|
assert hashlib.sha256((root / "manifests/retroarch/phase-1.0ae-launcher-architecture.json").read_bytes()).hexdigest() == bindings["phase10ae_manifest_sha256"]
|
|
for prefix, relative in (("model", "tools/phase10af_bigapp_lifecycle_model.py"),
|
|
("tests", "tests/test_phase10af_bigapp_lifecycle_model.py")):
|
|
size, digest = identity(root / relative)
|
|
assert bindings[f"{prefix}_size"] == size
|
|
assert bindings[f"{prefix}_sha256"] == digest
|
|
source = (root / "tools/phase10af_bigapp_lifecycle_model.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({"socket", "subprocess", "os", "sys", "ctypes", "time", "pathlib"})
|
|
assert "PPSA01659" in source and "FAKE00000" not in source
|
|
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.0AF offline lifecycle validation passed")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|