#!/usr/bin/env python3 """Checks an Update File (.ota) the way the device does, on a PC: header, signature, image hash. Usage: scripts/ota_verify.py [public key, default keys/ota-public.pem] Exits 0 and prints the version if a device would accept the file. """ import hashlib import os import struct import subprocess import sys import tempfile HEADER_SIZE = 160 SIGNED_BYTES = 80 def main(): if len(sys.argv) < 2: sys.exit(__doc__) root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) key = sys.argv[2] if len(sys.argv) > 2 else os.path.join(root, "keys", "ota-public.pem") data = open(sys.argv[1], "rb").read() if len(data) < HEADER_SIZE or data[:8] != b"RORO-OTA": sys.exit("not an update file") fmt, header_size, image_size = struct.unpack("