#!/usr/bin/env python3 """Build-time SDK acquisition. Never installed or executed on an operator Node. Pin every byte from a public mirror; do not execute SDK code to inspect it. The source lock is provenance, not a claim of vendor authenticity or licensing. """ import argparse import hashlib import json import re import shutil import struct import tempfile import urllib.request from pathlib import Path, PurePosixPath ROOT = Path(__file__).resolve().parents[1] LOCK = Path(__file__).with_name("sdk-lock.json") def entries(lock): if lock["schema"] != "missioncore.insta360.sdk-source/v1": raise ValueError("Unsupported SDK lock") if not re.fullmatch(r"[0-9a-f]{40}", lock["commit"]): raise ValueError("SDK source must be an immutable commit") seen = set() for entry in lock["files"]: path = PurePosixPath(entry["path"]) if ( path.is_absolute() or ".." in path.parts or "\\" in entry["path"] or path.as_posix() != entry["path"] or entry["path"] in seen or not re.fullmatch(r"[0-9a-f]{64}", entry["sha256"]) or not 0 < entry["bytes"] <= 32 * 1024 * 1024 ): raise ValueError("Invalid SDK payload entry") seen.add(entry["path"]) yield entry def verified_bytes(data, entry): if len(data) != entry["bytes"] or hashlib.sha256(data).hexdigest() != entry["sha256"]: raise ValueError("SDK checksum mismatch: " + entry["path"]) return data def inspect_elf(path): """Parse ELF64 sections without loading the library (never ldd/dlopen).""" data = path.read_bytes() if ( len(data) < 64 or data[:7] != b"\x7fELF\x02\x01\x01" or struct.unpack_from(" len(data): raise ValueError("Invalid ELF section table") sections = [struct.unpack_from("= count: raise ValueError("Invalid ELF string table") strings = sections[section[6]] table = data[strings[4] : strings[4] + strings[5]] if section[4] + section[5] > len(data) or section[5] % 16: raise ValueError("Invalid ELF dynamic table") for at in range(section[4], section[4] + section[5], 16): tag, value = struct.unpack_from("