From 6c51c0c4f4ccae59dada83eeac3696e114e97e40 Mon Sep 17 00:00:00 2001 From: diviocity Date: Mon, 30 Nov 2026 04:44:14 +0100 Subject: [PATCH] Verify signed repository metadata with GPGME in the Vinix guest --- BOOTSTRAP.md | 2 ++ tests/userland/signatures.sh | 27 +++++++++++++++++++++ tests/userland/verify-index.c | 45 +++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 tests/userland/signatures.sh create mode 100644 tests/userland/verify-index.c diff --git a/BOOTSTRAP.md b/BOOTSTRAP.md index c1c2686..b0089ed 100644 --- a/BOOTSTRAP.md +++ b/BOOTSTRAP.md @@ -64,6 +64,8 @@ The installed x86_64 XBPS 0.59.2-1 tools created a package, indexed it, installe 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`. +The published x86_64 Vinix kernel booted that 22-package root. Both `gpgv` and the GPGME OpenPGP engine verified the feed's actual detached database signature against the packaged public key. Both reported a bad signature when the guest appended bytes to the database. To repeat the check, compile `tests/userland/verify-index.c` with the target SDK and `-lgpgme`. Stage the executable, the signed `vinix.db` and its signature as `/signature-fixture/{verify-index,index,index.sig}`, then boot with `tests/userland/signatures.sh`. The worker receipt manifest is `foundation/signature-engine-guest-03/receipts.sha256`, SHA-256 `71ce37b04b4e75936bd4082396f3b312ee7b4ef68a05cc9e7338849f6889293e`. + 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/tests/userland/signatures.sh b/tests/userland/signatures.sh new file mode 100644 index 0000000..b0c89aa --- /dev/null +++ b/tests/userland/signatures.sh @@ -0,0 +1,27 @@ +#!/bin/sh +set -eu +export PATH=/bin:/usr/bin:/sbin:/usr/sbin LC_ALL=C HOME=/tmp GNUPGHOME=/tmp/pgp +phase=keyring +finish() { + status=$? + if [ "$status" -ne 0 ]; then echo "VPAC SIGNATURE FAIL at $phase with status $status"; fi + /sbin/poweroff -f +} +trap finish EXIT +test "$(uname -o)" = Vinix +cd /signature-fixture +mkdir -p -m 700 "$GNUPGHOME" +ring=/usr/share/vpac/keyrings/vinix.gpg +fingerprint=$(cat /usr/share/vpac/keyrings/vinix.fingerprint) +gpg --no-options --batch --import "$ring" +phase=good-signature +gpgv --keyring "$ring" --status-fd 1 index.sig index >"$HOME/valid" +grep -F "[GNUPG:] VALIDSIG $fingerprint " "$HOME/valid" +./verify-index valid index.sig index "$fingerprint" +phase=damaged-index +cp index "$HOME/damaged" +printf '\nmodified\n' >>"$HOME/damaged" +if gpgv --keyring "$ring" --status-fd 1 index.sig "$HOME/damaged" >"$HOME/bad"; then exit 1; fi +grep -F "[GNUPG:] BADSIG " "$HOME/bad" +./verify-index damaged index.sig "$HOME/damaged" "$fingerprint" +echo 'VPAC FIXTURE GUEST PASS' diff --git a/tests/userland/verify-index.c b/tests/userland/verify-index.c new file mode 100644 index 0000000..ad99b06 --- /dev/null +++ b/tests/userland/verify-index.c @@ -0,0 +1,45 @@ +/* Exercise the GPGME OpenPGP engine used by vpac against a detached signature. */ +#include +#include +#include + +static int check(gpgme_error_t err, const char *operation) +{ + if (err) + fprintf(stderr, "%s: %s\n", operation, gpgme_strerror(err)); + return err != 0; +} + +int main(int argc, char **argv) +{ + if (argc != 5 || (strcmp(argv[1], "valid") && strcmp(argv[1], "damaged"))) + return 2; + gpgme_check_version(NULL); + gpgme_ctx_t ctx; + if (check(gpgme_new(&ctx), "create GPGME context")) + return 1; + gpgme_data_t signature = NULL, input = NULL; + int result = 1; + if (check(gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP), "select OpenPGP") || + check(gpgme_data_new_from_file(&signature, argv[2], 1), "read signature") || + check(gpgme_data_new_from_file(&input, argv[3], 1), "read index") || + check(gpgme_op_verify(ctx, signature, input, NULL), "verify index")) + goto done; + gpgme_verify_result_t verification = gpgme_op_verify_result(ctx); + gpgme_signature_t sig = verification ? verification->signatures : NULL; + if (!sig || sig->next) { + fprintf(stderr, "expected one index signature\n"); + goto done; + } + printf("GPGME %s index: %s, signer %s\n", argv[1], gpgme_strerror(sig->status), + sig->fpr ? sig->fpr : "unknown"); + if (!strcmp(argv[1], "valid")) + result = sig->status || !sig->fpr || strcmp(sig->fpr, argv[4]); + else + result = gpgme_err_code(sig->status) != GPG_ERR_BAD_SIGNATURE; +done: + if (signature) gpgme_data_release(signature); + if (input) gpgme_data_release(input); + gpgme_release(ctx); + return result; +} -- 2.56.1