Download this file
| 1 | #!/usr/bin/env python3 |
| 2 | """Verify pinned Codex bytes without starting a provider process.""" |
| 3 | import hashlib |
| 4 | import os |
| 5 | from pathlib import Path |
| 6 | import platform |
| 7 | import re |
| 8 | import shutil |
| 9 | import sys |
| 10 | |
| 11 | root = Path(__file__).resolve().parent.parent |
| 12 | codex = root / "internal/runner/provider/codex" |
| 13 | # The release pin on x86-64; the same release's arm64 build on an arm64 |
| 14 | # CI machine (pins.go), where no release runs. |
| 15 | if platform.machine().lower() in ("aarch64", "arm64"): |
| 16 | pin = re.search(r'ExecutableSHA256Arm64\s+= "([a-f0-9]{64})"', (codex / "pins.go").read_text()) |
| 17 | else: |
| 18 | pin = re.search(r'const ExecutableSHA256 = "([a-f0-9]{64})"', (codex / "launcher.go").read_text()) |
| 19 | path = os.environ.get("EQUIPO_CODEX_PATH") or shutil.which("codex") |
| 20 | try: |
| 21 | if not pin or not path or not os.access(path, os.X_OK): |
| 22 | sys.exit(1) |
| 23 | with open(path, "rb") as binary: |
| 24 | if hashlib.file_digest(binary, "sha256").hexdigest() != pin[1]: |
| 25 | sys.exit(1) |
| 26 | except OSError: |
| 27 | sys.exit(1) |
| 28 | |