| 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. |
| 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 | verify() { |
| 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. |
| 40 | verify v1 |
| 41 | if [ "$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 |
| 45 | fi |
| 46 | grep -qx verified v1.out |
| 47 | grep -qx "object $(git rev-parse HEAD)" v1.out |
| 48 | grep -qx 'user-presence yes' v1.out |
| 49 | |
| 50 | # git verify-tag accepts the untouched tag. sigverify refuses it, with |
| 51 | # exit status 1. |
| 52 | if ! 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 |
| 56 | fi |
| 57 | verify v2 |
| 58 | if [ "$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 |
| 62 | fi |
| 63 | grep -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. |
| 67 | verify v3 |
| 68 | if [ "$status" -ne 2 ]; then |
| 69 | echo "sigverify-e2e: a missing tag gave exit status $status, not 2" >&2 |
| 70 | exit 1 |
| 71 | fi |
| 72 | |
| 73 | echo "sigverify-e2e: a touched tag verified, an untouched one refused" |
| 74 | touch "$out" |