#!/usr/bin/env python3 # SPDX-License-Identifier: LicenseRef-Starship-1.0 # Copyright (c) 2023-2026 Robert A. James """capsule_unsign.py GENERATED.c NAME -- for the test only (#139): take one capsule's signature out of a signed build's capsule_generated.c, so that a signed kernel can be seen to refuse an unsigned capsule (docs/v4.0.0/plans/2026-11-20-capsule-trust.md, ruling 4: "Left to CI"). kernel/Makefile runs it when CAPSULE_TEST_UNSIGN names a capsule; nothing else does. Fails if NAME is not there, or was not signed.""" import re import sys path, name = sys.argv[1], sys.argv[2] text = open(path).read() m = re.search(r"/\* \[\d+\] " + re.escape(name) + r" \*/\n(.*?)\.has_sig = (\d) \}", text, re.S) if not m: sys.exit("capsule_unsign: %s is not in %s" % (name, path)) if m.group(2) != "1": sys.exit("capsule_unsign: %s is not signed in %s -- a signed build is needed" % (name, path)) start = m.start(2) open(path, "w").write(text[:start] + "0" + text[start + 1:]) print("capsule_unsign: %s left unsigned, for the test (#139)" % name)