Verify signed repository metadata with GPGME in the Vinix guest
@@ -64,6 +64,8 @@ The installed x86_64 XBPS 0.59.2-1 tools created a package, indexed it, installe
6464
6565The 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`.
6666
67+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`.
68+
6769For 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.
6870
6971```sh
@@ -0,0 +1,27 @@
1+#!/bin/sh
2+set -eu
3+export PATH=/bin:/usr/bin:/sbin:/usr/sbin LC_ALL=C HOME=/tmp GNUPGHOME=/tmp/pgp
4+phase=keyring
5+finish() {
6+ status=$?
7+ if [ "$status" -ne 0 ]; then echo "VPAC SIGNATURE FAIL at $phase with status $status"; fi
8+ /sbin/poweroff -f
9+}
10+trap finish EXIT
11+test "$(uname -o)" = Vinix
12+cd /signature-fixture
13+mkdir -p -m 700 "$GNUPGHOME"
14+ring=/usr/share/vpac/keyrings/vinix.gpg
15+fingerprint=$(cat /usr/share/vpac/keyrings/vinix.fingerprint)
16+gpg --no-options --batch --import "$ring"
17+phase=good-signature
18+gpgv --keyring "$ring" --status-fd 1 index.sig index >"$HOME/valid"
19+grep -F "[GNUPG:] VALIDSIG $fingerprint " "$HOME/valid"
20+./verify-index valid index.sig index "$fingerprint"
21+phase=damaged-index
22+cp index "$HOME/damaged"
23+printf '\nmodified\n' >>"$HOME/damaged"
24+if gpgv --keyring "$ring" --status-fd 1 index.sig "$HOME/damaged" >"$HOME/bad"; then exit 1; fi
25+grep -F "[GNUPG:] BADSIG " "$HOME/bad"
26+./verify-index damaged index.sig "$HOME/damaged" "$fingerprint"
27+echo 'VPAC FIXTURE GUEST PASS'
@@ -0,0 +1,45 @@
1+/* Exercise the GPGME OpenPGP engine used by vpac against a detached signature. */
2+#include <gpgme.h>
3+#include <stdio.h>
4+#include <string.h>
5+
6+static int check(gpgme_error_t err, const char *operation)
7+{
8+ if (err)
9+ fprintf(stderr, "%s: %s\n", operation, gpgme_strerror(err));
10+ return err != 0;
11+}
12+
13+int main(int argc, char **argv)
14+{
15+ if (argc != 5 || (strcmp(argv[1], "valid") && strcmp(argv[1], "damaged")))
16+ return 2;
17+ gpgme_check_version(NULL);
18+ gpgme_ctx_t ctx;
19+ if (check(gpgme_new(&ctx), "create GPGME context"))
20+ return 1;
21+ gpgme_data_t signature = NULL, input = NULL;
22+ int result = 1;
23+ if (check(gpgme_set_protocol(ctx, GPGME_PROTOCOL_OpenPGP), "select OpenPGP") ||
24+ check(gpgme_data_new_from_file(&signature, argv[2], 1), "read signature") ||
25+ check(gpgme_data_new_from_file(&input, argv[3], 1), "read index") ||
26+ check(gpgme_op_verify(ctx, signature, input, NULL), "verify index"))
27+ goto done;
28+ gpgme_verify_result_t verification = gpgme_op_verify_result(ctx);
29+ gpgme_signature_t sig = verification ? verification->signatures : NULL;
30+ if (!sig || sig->next) {
31+ fprintf(stderr, "expected one index signature\n");
32+ goto done;
33+ }
34+ printf("GPGME %s index: %s, signer %s\n", argv[1], gpgme_strerror(sig->status),
35+ sig->fpr ? sig->fpr : "unknown");
36+ if (!strcmp(argv[1], "valid"))
37+ result = sig->status || !sig->fpr || strcmp(sig->fpr, argv[4]);
38+ else
39+ result = gpgme_err_code(sig->status) != GPG_ERR_BAD_SIGNATURE;
40+done:
41+ if (signature) gpgme_data_release(signature);
42+ if (input) gpgme_data_release(input);
43+ gpgme_release(ctx);
44+ return result;
45+}