From 59386468057b3b16ba4ae6abcedea7667e736c64 Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 04:18:51 +0100 Subject: [PATCH] Build GnuPG and verify detached signatures with the target gpgv --- BOOTSTRAP.md | 2 ++ gnupg/PKGBUILD.vile | 75 +++++++++++++++++++++++++++++++++++++++++++++ gnupg/check.py | 31 +++++++++++++++++++ 3 files changed, 108 insertions(+) create mode 100644 gnupg/PKGBUILD.vile create mode 100644 gnupg/check.py diff --git a/BOOTSTRAP.md b/BOOTSTRAP.md index 629e796..c1c2686 100644 --- a/BOOTSTRAP.md +++ b/BOOTSTRAP.md @@ -62,6 +62,8 @@ The x86_64 SQLite 3.48.0-1 build used 724 MiB at peak under the 1 GiB limit. Its The installed x86_64 XBPS 0.59.2-1 tools created a package, indexed it, installed it into an empty directory and read its version from the local database. The fixture compared the installed bytes with the input. Its 13-package signed root contained 57 target ELFs. See `foundation/signed-xbps-01`, receipt SHA-256 `c54c52e01e076177f73be1830574c3c256d6af8627679d1b24353f145cf1f078`. +The GnuPG 2.4.9-1 recipe uses the SDK's `gpgrt-config` to locate libksba. Its build check verifies a detached signature with the target `gpgv` and requires a bad-signature result after changing the signed bytes. The x86_64 archive has SHA-256 `05a9da36d6f07114af1a1683690eec0452582b506262c445dde55d1a1b5e07c4`. Installing GnuPG, GPGME, the Vinix test keyring and BusyBox init pulled in 22 signed packages with 4,893 owned files and links and 76 target ELFs. See `foundation/signature-engine-x86-02/audit.log`, SHA-256 `9762624c6ba59640955091783d9bea47a6e9859ef3d5a1f45e11cecbc461ef34`. + For later builds, `tools/build-queue.py` uses the source order and a verified bootstrap feed. Place the input archives and a `NAME.sha256` receipt for each in `$work/artifacts`. Configure the host compiler and signing tools as for a single native build, then select the ports to build. The worker uses this command form. ```sh diff --git a/gnupg/PKGBUILD.vile b/gnupg/PKGBUILD.vile new file mode 100644 index 0000000..380a0e5 --- /dev/null +++ b/gnupg/PKGBUILD.vile @@ -0,0 +1,75 @@ +; OpenPGP package signing, key management and offline verification. +defpkgbuild(gnupg, + #:pkgname, "gnupg", + #:pkgver, "2.4.9", + #:pkgrel, 1, + #:pkgdesc, "GnuPG tools and agent for signing and verifying packages", + #:arch, [#:x86-64, #:aarch64], + #:license, "GPL-3.0-or-later", + #:url, "https://gnupg.org/", + #:depends, ["musl", "bzip2", "libassuan", "libgcrypt", "libgpg-error", "libksba", + "npth", "pinentry", "readline", "sqlite", "zlib"], + #:source, ["https://gnupg.org/ftp/gcrypt/gnupg/gnupg-2.4.9.tar.bz2", + "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/gnupg/0010-avoid-beta-warning.patch", + "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/gnupg/0020-avoid-regenerating-defsincdate-use-shipped-file.patch", + "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/gnupg/0110-avoid-simple-memory-dumps-via-ptrace.patch", + "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/gnupg/0210-dirmngr-hkp-avoid-potential-race-condition-when-some-host-die.patch", + "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/gnupg/0230-dirmngr-avoid-automatically-checking-upstream-swdb.patch", + "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/gnupg/0330-gpg-default-to-sha512-for-all-signature-types-on-rsa-keys.patch", + "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/gnupg/0340-gpg-prefer-sha512-and-sha384-in-personal-digest.patch", + "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/gnupg/0420-gpg-drop-import-clean-from-default-keyserver-import-options.patch", + "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/gnupg/fix-i18n.patch", + "https://raw.githubusercontent.com/alpinelinux/aports/a7de3e63cc8015474a4feadd8bb7c0ecc097b1fa/main/gnupg/HACK-revert-rfc4880bis-default.patch", + "check.py"], + #:sha256sums, ["dd17ab2e9a04fd79d39d853f599cbc852062ddb9ab52a4ddeb4176fd8b302964", + "243c3a79295519b3931f9d846cf2af5caa064a78de812ee336dc786c1567b4d0", + "9bd33f7d1b875bf710a9ad58db17d8217e747733a3118ff9403e1856a2c6754a", + "9bb5282a5292f8fe4ff77253ba28bb5a2453d85ba4bdebcc646bf82bb9175c60", + "9b30351f7eff35c27376f7b7c73ee23a1b737b5bb293fdf97e41924ae6851e88", + "a059840eed2d1e0ed977fbc7420108d91031e3c256f95eede1d8fa61e6193ee4", + "1b3b0f879f1cae1d734607a0f29e0ceecb186384e39a37232e60b0adcaa56bc3", + "87b77fe213a66b78866f4865882d62649c8b861df7adf383cffb6a781675ed52", + "6ade15b536c50a88efc2d9dc958433b0ccfaf2908025b7672753e6bfce51c3c6", + "ce409e47ce4a0d8468ba7e791fd5a7311fd600a167e3a2a60f4330d5460b65be", + "f75fdd02ba73ff93e6ce5d36a6ccff3ad06f1b2e08f8918d42c912e073893a3e", + "d8a6178cd60146bdbcd509e570a85bd958b969ead3e896e90e3f085f5da1c6bd"], + #:prepare, fn() { + for-each(fn(file) { + run("patch", "--batch", "-d", "gnupg-2.4.9", "-p1", "-i", string-append("../", file)) + }, list("0010-avoid-beta-warning.patch", + "0020-avoid-regenerating-defsincdate-use-shipped-file.patch", + "0110-avoid-simple-memory-dumps-via-ptrace.patch", + "0210-dirmngr-hkp-avoid-potential-race-condition-when-some-host-die.patch", + "0230-dirmngr-avoid-automatically-checking-upstream-swdb.patch", + "0330-gpg-default-to-sha512-for-all-signature-types-on-rsa-keys.patch", + "0340-gpg-prefer-sha512-and-sha384-in-personal-digest.patch", + "0420-gpg-drop-import-clean-from-default-keyserver-import-options.patch", + "fix-i18n.patch", + "HACK-revert-rfc4880bis-default.patch")) + run("rm", "-f", "gnupg-2.4.9/tests/gpgme/setup.scm") + run("env", "-C", "gnupg-2.4.9", "AUTOCONF=autoconf", "AUTOHEADER=autoheader", "autoreconf", "-fi") + }, + #:build, fn() { + root := get-environment-variable("VPAC_MAKEPKG_ROOT") + ; libksba supplies ksba.pc. The installed gpgrt-config shell script reads + ; that record for configure, including when the target cannot run here. + run("env", string-append("GPGRT_CONFIG=", root, "/usr/bin/gpgrt-config"), + "vinix-configure", "gnupg-2.4.9/configure", + string-append("--with-libgpg-error-prefix=", root, "/usr"), + string-append("--with-libgcrypt-prefix=", root, "/usr"), + string-append("--with-libassuan-prefix=", root, "/usr"), + string-append("--with-libksba-prefix=", root, "/usr"), string-append("--with-npth-prefix=", root, "/usr"), + "--localstatedir=/var", "--disable-nls", "--enable-tofu", "--disable-scdaemon", "--disable-ccid-driver", + "--disable-dirmngr", "--disable-wks-tools", "--disable-ldap", "--disable-doc", "--disable-ntbtls") + run("make") + }, + #:check, fn() { + run("vinix-run", "g10/gpg", "--version") + run("vinix-run", "agent/gpg-agent", "--version") + run("python3", "check.py") + }, + #:package, fn() { + run("make", "install", string-append("DESTDIR=", pkgdir())) + run("rm", "-f", string-append(pkgdir(), "/usr/share/info/dir")) + run("install", "-Dm644", "gnupg-2.4.9/COPYING", string-append(pkgdir(), "/usr/share/licenses/gnupg/COPYING")) + }) diff --git a/gnupg/check.py b/gnupg/check.py new file mode 100644 index 0000000..f2eca93 --- /dev/null +++ b/gnupg/check.py @@ -0,0 +1,31 @@ +"""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) -- 2.56.1