| 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 a host's |
| 6 | # deploy step calls it to verify a release tag. ssh-keygen signs through |
| 7 | # the sk-dummy authenticator the derivation names in SSH_SK_PROVIDER. |
| 8 | export HOME="$TMPDIR" |
| 9 | export GIT_CONFIG_NOSYSTEM=1 |
| 10 | git config --global user.name valley-check |
| 11 | git config --global user.email valley-check@localhost |
| 12 | git config --global init.defaultBranch main |
| 13 | git 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. |
| 17 | ssh-keygen -q -t ed25519-sk -N "" -C touched -f "$TMPDIR/touched" |
| 18 | ssh-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" |
| 23 | git config --global gpg.ssh.allowedSignersFile "$TMPDIR/allowed_signers" |
| 24 | |
| 25 | git init --quiet "$TMPDIR/repo" |
| 26 | cd "$TMPDIR/repo" || exit 1 |
| 27 | echo release > file |
| 28 | git add file |
| 29 | git commit --quiet -m release |
| 30 | git -c user.signingKey="$TMPDIR/touched" tag -s v1 -m 'release 1' |
| 31 | git -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. |
| 35 | sigverify="$(command -v sigverify)" |
| 36 | verify() { |
| 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. |
| 44 | verify v1 |
| 45 | if [ "$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 |
| 49 | fi |
| 50 | grep -qx verified v1.out |
| 51 | grep -qx "commit $(git rev-parse HEAD)" v1.out |
| 52 | grep -qx 'user-presence yes' v1.out |
| 53 | |
| 54 | # git verify-tag accepts the untouched tag. sigverify refuses it, with |
| 55 | # exit status 1. |
| 56 | if ! 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 |
| 60 | fi |
| 61 | verify v2 |
| 62 | if [ "$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 |
| 66 | fi |
| 67 | # A refusal is its reason and nothing else. |
| 68 | if [ "$(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 |
| 72 | fi |
| 73 | |
| 74 | # A tag that does not exist is an error, exit status 2: nothing was |
| 75 | # verified or refused. |
| 76 | verify v3 |
| 77 | if [ "$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 |
| 80 | fi |
| 81 | |
| 82 | # A report that cannot be written is an error, never exit status 0. |
| 83 | status=0 |
| 84 | env -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=$? |
| 87 | if [ "$status" -ne 2 ]; then |
| 88 | echo "sigverify-e2e: a report written to /dev/full gave exit status $status, not 2" >&2 |
| 89 | exit 1 |
| 90 | fi |
| 91 | |
| 92 | echo "sigverify-e2e: a touched tag verified, an untouched one refused" |
| 93 | touch "$out" |