: nply/foundationpkgs-binaries

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
#!/bin/sh
# Isolated native publication regression; never uses production keys or APT state.
set -eu
for tool in dpkg-deb apt-ftparchive sha256sum sha512sum gpg gpgv rsync; do
	command -v "$tool" >/dev/null 2>&1 || { echo "SKIP: requires $tool"; exit 0; }
done
self=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
work=$(mktemp -d)
cleanup() { gpgconf --homedir "$work/keys" --kill gpg-agent >/dev/null 2>&1 || :; rm -rf "$work"; }
trap cleanup 0
trap 'exit 1' HUP INT TERM
export GNUPGHOME=$work/keys
mkdir -m700 "$GNUPGHOME"
gpg --batch --pinentry-mode loopback --passphrase '' --quick-generate-key 'Isolated APT fixture' rsa2048 sign 1d >/dev/null 2>&1
FPKGS_APT_FINGERPRINT=$(gpg --batch --with-colons --list-keys | awk -F: '$1=="fpr" {print $10; exit}')
export FPKGS_APT_FINGERPRINT
export FPKGS_APT_ROOT=$work/publisher FPKGS_APT_PUBLIC_ROOT=$work/public FPKGS_APT_URL=https://fixture.invalid/apt
mkdir -p "$work/bin" "$work/bundle/fixture" "$work/payload/DEBIAN" "$work/payload/usr/share/fixture"
printf 'Package: fixture\nVersion: 1.0-1\nArchitecture: all\nMaintainer: Fixture <fixture@example.invalid>\nDescription: Fixture\n' > "$work/payload/DEBIAN/control"
printf 'fixture\n' > "$work/payload/usr/share/fixture/content"
dpkg-deb --root-owner-group --build "$work/payload" "$work/bundle/fixture/fixture_1.0-1_all.deb" >/dev/null
rev=1111111111111111111111111111111111111111
printf 'source snapshot fixture\n' > "$work/bundle/source.tar.gz"
printf 'pkgname=fixture\ngitrev=%s\ntarget=x86_64-unknown-linux-gnu\nformat=deb\nartifact=fixture_1.0-1_all.deb\n' "$rev" > "$work/bundle/fixture/manifest"
printf 'build log fixture\n' > "$work/bundle/fixture/build.log"
(cd "$work/bundle/fixture" && sha256sum fixture_1.0-1_all.deb > SHA256SUMS)
# The offline transport serves the real staged public tree, not canned metadata.
cat > "$work/bin/curl" <<'SH'
#!/bin/sh
set -eu
while [ "$#" -gt 0 ]; do
	case "$1" in https://fixture.invalid/apt/*) relative=${1#https://fixture.invalid/apt/} ;; -o) shift; output=$1 ;; esac
	shift
done
cp "$FPKGS_APT_PUBLIC_ROOT/apt/$relative" "$output"
SH
chmod 755 "$work/bin/curl"
export PATH=$work/bin:$PATH
run() { sh "$self/scripts/publish-apt.sh" "$@"; }
reject() { if "$@" > "$work/rejected.log" 2>&1; then echo 'FAIL: unsafe publication accepted' >&2; exit 1; fi; }
reject run deploy "$rev"
cp "$work/bundle/fixture/manifest" "$work/manifest"
printf '\ngitrev=2222222222222222222222222222222222222222\n' >> "$work/bundle/fixture/manifest"
reject run receive "$rev" "$work/bundle"
cp "$work/manifest" "$work/bundle/fixture/manifest"
cp "$work/bundle/fixture/SHA256SUMS" "$work/sums"
printf '00  ../../outside\n' > "$work/bundle/fixture/SHA256SUMS"
reject run receive "$rev" "$work/bundle"
cp "$work/sums" "$work/bundle/fixture/SHA256SUMS"
ln -s "$work/manifest" "$work/bundle/link"
reject run receive "$rev" "$work/bundle"
rm "$work/bundle/link"
run receive "$rev" "$work/bundle"
run receive "$rev" "$work/bundle"
run deploy "$rev"
[ -s "$FPKGS_APT_ROOT/provenance/$rev/DEPLOYED" ]
gpgv --keyring "$FPKGS_APT_PUBLIC_ROOT/apt/foundationpkgs-archive-keyring.gpg" "$FPKGS_APT_PUBLIC_ROOT/apt/dists/trixie/InRelease"
cp "$FPKGS_APT_PUBLIC_ROOT/apt/dists/trixie/InRelease" "$work/signed"
printf 'tampered' >> "$FPKGS_APT_PUBLIC_ROOT/apt/dists/trixie/Release"
reject gpgv --keyring "$FPKGS_APT_PUBLIC_ROOT/apt/foundationpkgs-archive-keyring.gpg" "$FPKGS_APT_PUBLIC_ROOT/apt/dists/trixie/Release.gpg" "$FPKGS_APT_PUBLIC_ROOT/apt/dists/trixie/Release"
# Repeat publication preserves old by-hash indexes and immutable package bytes.
run deploy "$rev"
[ "$(find "$FPKGS_APT_PUBLIC_ROOT/releases" -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq 2 ]
archive=$FPKGS_APT_ROOT/archive/pool/main/f/fixture/fixture_1.0-1_all.deb
printf 'different archive bytes' > "$archive"
reject run deploy "$rev"
printf 'PASS: exact revision, safe paths, copied checksums, idempotent receive, immutable versions, real indexes/signatures, atomic snapshots, tamper rejection\n'