gunk-dev/the-valley

sigverify-e2e.sh

source6c05fb80e723main's published tip history
3.3 KiB
1# shellcheck shell=bash
2# Paths and fixtures come from the derivation environment.
3# shellcheck disable=SC2154
4#
5# The shipped sigverify over a real repository, called the way cosmo calls
6# it to verify a release tag. ssh-keygen signs through the sk-dummy
7# authenticator the derivation names in SSH_SK_PROVIDER.
8export HOME="$TMPDIR"
9export GIT_CONFIG_NOSYSTEM=1
10git config --global user.name valley-check
11git config --global user.email valley-check@localhost
12git config --global init.defaultBranch main
13git config --global gpg.format ssh
14
15# Two security keys that differ in one respect: the first asks the
16# authenticator for a touch, and the second does not. Both are listed.
17ssh-keygen -q -t ed25519-sk -N "" -C touched -f "$TMPDIR/touched"
18ssh-keygen -q -t ed25519-sk -N "" -C untouched -O no-touch-required -f "$TMPDIR/untouched"
19{
20 echo "release@valley.invalid $(cat "$TMPDIR/touched.pub")"
21 echo "release@valley.invalid $(cat "$TMPDIR/untouched.pub")"
22} > "$TMPDIR/allowed_signers"
23git config --global gpg.ssh.allowedSignersFile "$TMPDIR/allowed_signers"
24
25git init --quiet "$TMPDIR/repo"
26cd "$TMPDIR/repo" || exit 1
27echo release > file
28git add file
29git commit --quiet -m release
30git -c user.signingKey="$TMPDIR/touched" tag -s v1 -m 'release 1'
31git -c user.signingKey="$TMPDIR/untouched" tag -s v2 -m 'release 2'
32
33# sigverify runs with an empty environment: no PATH to find a git on, and
34# no GIT_* variables. The git it runs is compiled into it.
35sigverify="$(command -v sigverify)"
36verify() {
37 status=0
38 env -i "$sigverify" git-tag --repo "$TMPDIR/repo" --tag "$1" \
39 --allowed-signers "$TMPDIR/allowed_signers" --principal release@valley.invalid \
40 > "$1.out" 2> "$1.err" || status=$?
41}
42
43# A touched tag is verified, and the output names the commit to apply.
44verify v1
45if [ "$status" -ne 0 ]; then
46 echo "sigverify-e2e: the touched tag was not verified" >&2
47 cat v1.out v1.err >&2
48 exit 1
49fi
50grep -qx verified v1.out
51grep -qx "commit $(git rev-parse HEAD)" v1.out
52grep -qx 'user-presence yes' v1.out
53
54# git verify-tag accepts the untouched tag. sigverify refuses it, with
55# exit status 1.
56if ! git verify-tag v2 2> v2.git; then
57 echo "sigverify-e2e: git verify-tag refused the untouched tag, so the gap is closed upstream" >&2
58 cat v2.git >&2
59 exit 1
60fi
61verify v2
62if [ "$status" -ne 1 ]; then
63 echo "sigverify-e2e: the untouched tag gave exit status $status, not 1" >&2
64 cat v2.out v2.err >&2
65 exit 1
66fi
67# A refusal is its reason and nothing else.
68if [ "$(cat v2.out)" != 'refused no-user-presence' ]; then
69 echo "sigverify-e2e: the refusal printed more than its reason" >&2
70 cat v2.out >&2
71 exit 1
72fi
73
74# A tag that does not exist is an error, exit status 2: nothing was
75# verified or refused.
76verify v3
77if [ "$status" -ne 2 ] || [ -s v3.out ]; then
78 echo "sigverify-e2e: a missing tag gave exit status $status, not 2, or printed a report" >&2
79 exit 1
80fi
81
82# A report that cannot be written is an error, never exit status 0.
83status=0
84env -i "$sigverify" git-tag --repo "$TMPDIR/repo" --tag v1 \
85 --allowed-signers "$TMPDIR/allowed_signers" --principal release@valley.invalid \
86 > /dev/full 2> full.err || status=$?
87if [ "$status" -ne 2 ]; then
88 echo "sigverify-e2e: a report written to /dev/full gave exit status $status, not 2" >&2
89 exit 1
90fi
91
92echo "sigverify-e2e: a touched tag verified, an untouched one refused"
93touch "$out"