gunk-dev/the-valley

sigverify-e2e.sh

sourcefe4ab5bf3cabmain's published tip history
2.5 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
33verify() {
34 status=0
35 sigverify git-tag --repo "$TMPDIR/repo" --tag "$1" \
36 --allowed-signers "$TMPDIR/allowed_signers" > "$1.out" 2> "$1.err" || status=$?
37}
38
39# A touched tag is verified, and the output names the commit to apply.
40verify v1
41if [ "$status" -ne 0 ]; then
42 echo "sigverify-e2e: the touched tag was not verified" >&2
43 cat v1.out v1.err >&2
44 exit 1
45fi
46grep -qx verified v1.out
47grep -qx "object $(git rev-parse HEAD)" v1.out
48grep -qx 'user-presence yes' v1.out
49
50# git verify-tag accepts the untouched tag. sigverify refuses it, with
51# exit status 1.
52if ! git verify-tag v2 2> v2.git; then
53 echo "sigverify-e2e: git verify-tag refused the untouched tag, so the gap is closed upstream" >&2
54 cat v2.git >&2
55 exit 1
56fi
57verify v2
58if [ "$status" -ne 1 ]; then
59 echo "sigverify-e2e: the untouched tag gave exit status $status, not 1" >&2
60 cat v2.out v2.err >&2
61 exit 1
62fi
63grep -qx 'refused no-user-presence' v2.out
64
65# A tag that does not exist is an error, exit status 2: nothing was
66# verified or refused.
67verify v3
68if [ "$status" -ne 2 ]; then
69 echo "sigverify-e2e: a missing tag gave exit status $status, not 2" >&2
70 exit 1
71fi
72
73echo "sigverify-e2e: a touched tag verified, an untouched one refused"
74touch "$out"