"""Sign a fixture with a throwaway host key, then verify it with target gpgv.""" from pathlib import Path import subprocess import tempfile def run(*args, **kwargs): return subprocess.run(args, check=True, capture_output=True, timeout=30, **kwargs) # Keep the agent socket below the kernel's Unix-domain path limit even in # a deeply nested build tree. Only the exported fixture key enters the tree. with tempfile.TemporaryDirectory(prefix="gpg-", dir="/tmp") as home: identity = "Vinix fixture " host = ["gpg", "--homedir", home, "--batch"] try: run(*host, "--pinentry-mode", "loopback", "--passphrase", "", "--quick-generate-key", identity, "ed25519", "sign", "0") Path("fixture.gpg").write_bytes(run(*host, "--export", identity).stdout) package = Path("package-list") package.write_text("Vinix packages\n") run(*host, "--detach-sign", "--output", "package-list.sig", str(package)) verify = ["vinix-run", "g10/gpgv", "--keyring", str(Path("fixture.gpg").resolve()), "--status-fd", "1", "package-list.sig", str(package)] assert b"[GNUPG:] VALIDSIG " in run(*verify).stdout package.write_text("changed\n") bad = subprocess.run(verify, capture_output=True, timeout=15) assert bad.returncode != 0 and b"[GNUPG:] BADSIG " in bad.stdout, bad.stderr finally: subprocess.run(["gpgconf", "--homedir", home, "--kill", "all"], timeout=10)