Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(installers): accept a rebuilt Cua Spaces release only with a signed claim for its tag (#6663)

Francesco Bonacci7b83fa29c408
diff --git a/.github/workflows/cd-cua-spaces.yml b/.github/workflows/cd-cua-spaces.yml
index 0b81d325c6..1259c5c832 100644
--- a/.github/workflows/cd-cua-spaces.yml
+++ b/.github/workflows/cd-cua-spaces.yml
@@ -102,8 +102,9 @@ name: "CD: Cua Spaces"
# it builds the tagged commit with main's workflow files, refuses a release
# that is already published, and runs every gate (signing, notarization,
# staging smoke, verify-release, staged rollout) exactly as the tag push does.
-# Its Sigstore identity is this workflow at refs/heads/main, which the
-# installers accept for the app next to the tag identity. The macOS app takes the tag's version:
+# Its Sigstore identity is this workflow at refs/heads/main, which names no
+# tag, so it also signs rebuild-claim.txt (the tag and every asset's sha256);
+# the installers accept that identity only with the claim. The macOS app takes the tag's version:
# CFBundleShortVersionString X.Y.Z, CFBundleVersion X.Y.Z.<run number>, and
# the full version (with any -suffix) as CuaVersion.
#
@@ -2313,6 +2314,7 @@ jobs:
TAG: ${{ steps.version.outputs.tag }}
TAURI: ${{ needs.build-linux-windows.result }}
PARTIAL: ${{ needs.electron-plan.outputs.partial }}
+ REBUILD_SHA: ${{ inputs.rebuild_sha }}
run: |
set -euo pipefail
BASE="https://github.com/$GITHUB_REPOSITORY/releases/download/$TAG"
@@ -2322,13 +2324,31 @@ jobs:
# installer-named copies (electron-publish).
. "$GITHUB_WORKSPACE/.github/scripts/retry.sh"
retry gh release download "$TAG" --dir assets --repo "$GITHUB_REPOSITORY"
- rm -f assets/checksums.txt assets/release-artifacts.json assets/latest.json assets/*.sigstore.json
+ rm -f assets/checksums.txt assets/release-artifacts.json assets/latest.json assets/*.sigstore.json assets/rebuild-claim.txt
# Keyless Sigstore bundles next to each installer (install.sh and
# install.ps1 verify them with cosign when it is installed).
for f in assets/*; do
case "$f" in *.sig|*.blockmap) continue ;; esac
cosign sign-blob --yes --bundle "$f.sigstore.json" "$f" >/dev/null
done
+ # A rebuild is signed by this workflow at refs/heads/main, which does
+ # not name the tag. The claim does, under the same signature: the tag
+ # and the sha256 of every signed asset. The installers require it.
+ # It stays out of assets/ so the manifest never lists it.
+ claim=()
+ if [ -n "${REBUILD_TAG:-}" ]; then
+ {
+ echo "tag $TAG"
+ echo "sha $REBUILD_SHA"
+ for f in assets/*; do
+ case "$f" in *.sig|*.blockmap|*.sigstore.json) continue ;; esac
+ (cd assets && sha256sum -- "${f#assets/}")
+ done
+ } > "$RUNNER_TEMP/rebuild-claim.txt"
+ cosign sign-blob --yes --bundle "$RUNNER_TEMP/rebuild-claim.txt.sigstore.json" \
+ "$RUNNER_TEMP/rebuild-claim.txt" >/dev/null
+ claim=("$RUNNER_TEMP/rebuild-claim.txt" "$RUNNER_TEMP/rebuild-claim.txt.sigstore.json")
+ fi
# Every asset of the release, signatures included.
(cd assets && find . -maxdepth 1 -type f -printf '%f\n' | LC_ALL=C sort \
| xargs -d '\n' sha256sum > "$RUNNER_TEMP/checksums.txt")
@@ -2362,7 +2382,7 @@ jobs:
else
echo "::notice::no Tauri build in this release, so no latest.json"
fi
- gh release upload "$TAG" "${upload[@]}" --clobber --repo "$GITHUB_REPOSITORY"
+ gh release upload "$TAG" "${upload[@]}" ${claim[@]+"${claim[@]}"} --clobber --repo "$GITHUB_REPOSITORY"
- name: Publish the release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
diff --git a/docs/contributing/releasing-cua-spaces.md b/docs/contributing/releasing-cua-spaces.md
index 5936d9c214..af9def67fd 100644
--- a/docs/contributing/releasing-cua-spaces.md
+++ b/docs/contributing/releasing-cua-spaces.md
@@ -76,5 +76,11 @@ non-stable tag, and a dispatch from any other branch. Every gate runs exactly
as on a tag push: signing, notarization, the staging smoke for that commit,
`verify-release`, the cua.ai check and the staged rollout. `electron_dry_run`,
`sparkle_electron`, `skip_staging_gate` and `platforms` are refused. Its
-Sigstore identity is the workflow at `refs/heads/main`, which the installers
-accept for the app next to the usual tag identity.
+Sigstore identity is the workflow at `refs/heads/main`, which says nothing
+about the tag, so the installers accept it only with a signed claim: the run
+signs `rebuild-claim.txt` (a `tag cua-spaces-vX.Y.Z` line and the sha256 of
+every asset) and uploads it with its bundle next to the assets. The installers
+check the claim and the artifact under that identity, the `workflow_dispatch`
+trigger and the `main` ref, then require the claim to name the tag being
+installed and list the artifact's sha256. A release rebuilt by a workflow
+without the claim step (before this check) does not verify.
diff --git a/scripts/install/install.ps1 b/scripts/install/install.ps1
index 1df7bf2bfb..62def23f24 100644
--- a/scripts/install/install.ps1
+++ b/scripts/install/install.ps1
@@ -477,23 +477,54 @@ function Find-Artifact($Manifest, [string]$Component, [string]$Platform, [string
return $hit[0]
}
-# The exact Sigstore identities, one of which must have signed a manifest
-# entry: the CLI by cd-cua-sdk.yml at refs/tags/cua-sdk-v<version>, the app by
-# cd-cua-spaces.yml at refs/tags/cua-spaces-v<version>, or at refs/heads/main
-# for a release rebuilt from main (rebuild_tag; only a run that passed every
-# release gate signs).
+# The exact Sigstore identity that must have signed a manifest entry: the CLI
+# by cd-cua-sdk.yml at refs/tags/cua-sdk-v<version>, the app by
+# cd-cua-spaces.yml at refs/tags/cua-spaces-v<version>.
function Get-CosignIdentity($Entry) {
$v = [string]$Entry.version
if ($v -notmatch '^[0-9A-Za-z.+-]+$') { return $null }
switch ([string]$Entry.component) {
- 'cli' { return @("https://github.com/$Repo/.github/workflows/cd-cua-sdk.yml@refs/tags/cua-sdk-v$v") }
- 'app' { return @(
- "https://github.com/$Repo/.github/workflows/cd-cua-spaces.yml@refs/tags/cua-spaces-v$v",
- "https://github.com/$Repo/.github/workflows/cd-cua-spaces.yml@refs/heads/main") }
+ 'cli' { return "https://github.com/$Repo/.github/workflows/cd-cua-sdk.yml@refs/tags/cua-sdk-v$v" }
+ 'app' { return "https://github.com/$Repo/.github/workflows/cd-cua-spaces.yml@refs/tags/cua-spaces-v$v" }
default { return $null }
}
}
+# The app's identity for a release rebuilt from an existing tag (rebuild_tag):
+# cd-cua-spaces.yml at refs/heads/main. That ref says nothing about which tag
+# was built, so it is only accepted with a signed claim for this tag and file
+# (Test-RebuildClaim) and the workflow_dispatch trigger.
+function Get-RebuiltIdentity { return "https://github.com/$Repo/.github/workflows/cd-cua-spaces.yml@refs/heads/main" }
+
+function Test-CosignBundle([string]$Cosign, [string]$File, [string]$Bundle, [string]$Identity, [bool]$Rebuilt) {
+ $cosignArgs = @('verify-blob', '--bundle', $Bundle, '--certificate-identity', $Identity,
+ '--certificate-oidc-issuer', 'https://token.actions.githubusercontent.com')
+ if ($Rebuilt) {
+ # A push, schedule or pull_request run of the same workflow never passes.
+ $cosignArgs += @('--certificate-github-workflow-repository', $Repo,
+ '--certificate-github-workflow-ref', 'refs/heads/main',
+ '--certificate-github-workflow-trigger', 'workflow_dispatch')
+ }
+ & $Cosign @cosignArgs $File *> $null
+ return ($LASTEXITCODE -eq 0)
+}
+
+# rebuild-claim.txt, next to the artifact and signed by the same run, ties a
+# main-branch signature to a tag: a "tag cua-spaces-v<version>" line and
+# "<sha256> <name>" for every asset. It must verify under the rebuilt
+# identity, name this tag and list this file's sha256 under its name.
+function Test-RebuildClaim([string]$Cosign, [string]$File, [string]$BundleUrl, [string]$Version, [string]$ManifestUrl) {
+ $claim = "$File.rebuild-claim.txt"
+ $dir = $BundleUrl.Substring(0, $BundleUrl.LastIndexOf('/'))
+ Get-Remote "$dir/rebuild-claim.txt" $claim $ManifestUrl
+ Get-Remote "$dir/rebuild-claim.txt.sigstore.json" "$claim.sigstore.json" $ManifestUrl
+ if (-not (Test-CosignBundle $Cosign $claim "$claim.sigstore.json" (Get-RebuiltIdentity) $true)) { return $false }
+ $lines = @(Get-Content -LiteralPath $claim)
+ if ($lines -cnotcontains "tag cua-spaces-v$Version") { return $false }
+ $sha = (Get-FileHash -LiteralPath $File -Algorithm SHA256).Hash.ToLowerInvariant()
+ return ($lines -ccontains "$sha $(Split-Path -Leaf $File)")
+}
+
function Test-Signature([string]$File, $Entry, [string]$ManifestUrl) {
$ok = $false
$minisign = Get-Command minisign -ErrorAction SilentlyContinue
@@ -506,14 +537,14 @@ function Test-Signature([string]$File, $Entry, [string]$ManifestUrl) {
$cosign = Get-Command cosign -ErrorAction SilentlyContinue
if (-not $ok -and $Entry.PSObject.Properties['cosign_bundle'] -and $cosign) {
Get-Remote (Resolve-ArtifactUrl $Entry.cosign_bundle $ManifestUrl) "$File.sigstore.json" $ManifestUrl
- $identities = Get-CosignIdentity $Entry
- if (-not $identities) { Stop-Install "no release identity for $(Split-Path -Leaf $File) in the manifest" }
- $verified = $false
- foreach ($identity in $identities) {
- & $cosign.Source verify-blob --bundle "$File.sigstore.json" `
- --certificate-identity $identity `
- --certificate-oidc-issuer 'https://token.actions.githubusercontent.com' $File *> $null
- if ($LASTEXITCODE -eq 0) { $verified = $true; break }
+ $identity = Get-CosignIdentity $Entry
+ if (-not $identity) { Stop-Install "no release identity for $(Split-Path -Leaf $File) in the manifest" }
+ $bundlePath = "$File.sigstore.json"
+ $verified = Test-CosignBundle $cosign.Source $File $bundlePath $identity $false
+ if (-not $verified -and [string]$Entry.component -eq 'app' -and
+ (Test-CosignBundle $cosign.Source $File $bundlePath (Get-RebuiltIdentity) $true)) {
+ $bundleUrl = Resolve-ArtifactUrl $Entry.cosign_bundle $ManifestUrl
+ $verified = Test-RebuildClaim $cosign.Source $File $bundleUrl ([string]$Entry.version) $ManifestUrl
}
if (-not $verified) { Stop-Install "cosign signature check failed for $(Split-Path -Leaf $File)" }
$ok = $true
diff --git a/scripts/install/install.sh b/scripts/install/install.sh
index 4ec0fb288f..9d9216c8b6 100755
--- a/scripts/install/install.sh
+++ b/scripts/install/install.sh
@@ -79,8 +79,9 @@ LATEST_TAG="cua-install-latest"
MINISIGN_PUBKEY="${CUA_INSTALL_MINISIGN_PUBKEY:-}"
# Only the release workflows may sign, each at its own release tag: the CLI
# by cd-cua-sdk.yml at refs/tags/cua-sdk-v<version>, the app by
-# cd-cua-spaces.yml at refs/tags/cua-spaces-v<version>, or at refs/heads/main for
-# a release rebuilt from main (cosign_identity).
+# cd-cua-spaces.yml at refs/tags/cua-spaces-v<version>; a release rebuilt from
+# main (rebuild_tag) is accepted only with a signed claim for its tag
+# (verify_rebuild_claim).
COSIGN_ISSUER="https://token.actions.githubusercontent.com"
want_cli=1
@@ -896,11 +897,8 @@ resolve_url() {
esac
}
-# cosign_identity ENTRY: the exact Sigstore certificate identities (workflow
-# at its release tag), one per line, one of which must have signed this
-# manifest entry's artifact. The app also accepts cd-cua-spaces.yml at
-# refs/heads/main: a release rebuilt by a dispatch from main (rebuild_tag)
-# is signed by that run, and only a run that passed every release gate signs.
+# cosign_identity ENTRY: the Sigstore certificate identity (workflow at its
+# release tag) that must have signed this manifest entry's artifact.
cosign_identity() {
c="$(json_field "$1" component)"
v="$(json_field "$1" version)"
@@ -909,14 +907,54 @@ cosign_identity() {
esac
case "$c" in
cli) printf 'https://github.com/%s/.github/workflows/cd-cua-sdk.yml@refs/tags/cua-sdk-v%s\n' "$REPO" "$v" ;;
- app)
- printf 'https://github.com/%s/.github/workflows/cd-cua-spaces.yml@refs/tags/cua-spaces-v%s\n' "$REPO" "$v"
- printf 'https://github.com/%s/.github/workflows/cd-cua-spaces.yml@refs/heads/main\n' "$REPO"
- ;;
+ app) printf 'https://github.com/%s/.github/workflows/cd-cua-spaces.yml@refs/tags/cua-spaces-v%s\n' "$REPO" "$v" ;;
*) return 1 ;;
esac
}
+# rebuilt_identity: the app's identity for a release rebuilt from an
+# existing tag (rebuild_tag): cd-cua-spaces.yml at refs/heads/main. That ref
+# alone says nothing about which tag was built, so it is only ever accepted
+# together with a signed claim naming this tag and this file's sha256
+# (verify_rebuild_claim) and the workflow_dispatch trigger.
+rebuilt_identity() {
+ printf 'https://github.com/%s/.github/workflows/cd-cua-spaces.yml@refs/heads/main\n' "$REPO"
+}
+
+# cosign_verify FILE BUNDLE IDENTITY [REBUILT]: one cosign check. A rebuilt
+# identity also pins the repository, the main ref and the dispatch trigger,
+# so a push, schedule or pull_request run of the same workflow never passes.
+cosign_verify() {
+ if [ "${4:-}" = rebuilt ]; then
+ cosign verify-blob --bundle "$2" \
+ --certificate-identity "$3" \
+ --certificate-oidc-issuer "$COSIGN_ISSUER" \
+ --certificate-github-workflow-repository "$REPO" \
+ --certificate-github-workflow-ref refs/heads/main \
+ --certificate-github-workflow-trigger workflow_dispatch "$1" >/dev/null 2>&1
+ else
+ cosign verify-blob --bundle "$2" \
+ --certificate-identity "$3" \
+ --certificate-oidc-issuer "$COSIGN_ISSUER" "$1" >/dev/null 2>&1
+ fi
+}
+
+# verify_rebuild_claim FILE BUNDLE_URL VERSION: a rebuild's main-branch
+# signature proves "the release workflow signed this", not "for this tag".
+# The tie to the tag is rebuild-claim.txt next to the artifact, signed by the
+# same run: a "tag cua-spaces-v<version>" line and "<sha256> <name>" for
+# every asset. It must verify under the rebuilt identity, name this tag and
+# list this file's sha256 under its name.
+verify_rebuild_claim() {
+ claim="$1.rebuild-claim.txt"
+ # fetch dies on a missing file; a release without a claim is a failed check.
+ (fetch "$(dirname "$2")/rebuild-claim.txt" "$claim") >/dev/null 2>&1 || return 1
+ (fetch "$(dirname "$2")/rebuild-claim.txt.sigstore.json" "$claim.sigstore.json") >/dev/null 2>&1 || return 1
+ cosign_verify "$claim" "$claim.sigstore.json" "$(rebuilt_identity)" rebuilt || return 1
+ grep -Fx "tag cua-spaces-v$3" "$claim" >/dev/null || return 1
+ grep -Fx "$(sha256_of "$1") ${1##*/}" "$claim" >/dev/null || return 1
+}
+
verify_signature() { # file entry
sig_ok=0
minisig="$(json_field "$2" minisig)"
@@ -929,17 +967,16 @@ verify_signature() { # file entry
bundle="$(json_field "$2" cosign_bundle)"
if [ "$sig_ok" = 0 ] && [ -n "$bundle" ] && has cosign; then
fetch "$(resolve_url "$bundle")" "$1.sigstore.json"
- identities="$(cosign_identity "$2")" ||
+ identity="$(cosign_identity "$2")" ||
die "no release identity for ${1##*/} in the manifest"
cosign_ok=0
- for identity in $identities; do
- if cosign verify-blob --bundle "$1.sigstore.json" \
- --certificate-identity "$identity" \
- --certificate-oidc-issuer "$COSIGN_ISSUER" "$1" >/dev/null 2>&1; then
- cosign_ok=1
- break
- fi
- done
+ if cosign_verify "$1" "$1.sigstore.json" "$identity"; then
+ cosign_ok=1
+ elif [ "$(json_field "$2" component)" = app ] &&
+ cosign_verify "$1" "$1.sigstore.json" "$(rebuilt_identity)" rebuilt &&
+ verify_rebuild_claim "$1" "$(resolve_url "$bundle")" "$(json_field "$2" version)"; then
+ cosign_ok=1
+ fi
[ "$cosign_ok" = 1 ] || die "cosign signature check failed for ${1##*/}"
sig_ok=1
fi
diff --git a/scripts/install/tests/install.Tests.ps1 b/scripts/install/tests/install.Tests.ps1
index b72b3f00b2..ee279a7b27 100644
--- a/scripts/install/tests/install.Tests.ps1
+++ b/scripts/install/tests/install.Tests.ps1
@@ -64,6 +64,39 @@ Describe 'functions' {
{ Assert-DownloadUrl 'file:///tmp/a.zip' 'file:///tmp/r.json' } | Should -Not -Throw
}
+ It 'accepts a main-branch app signature only with the tag identity or a signed claim for the tag' {
+ Get-CosignIdentity ([pscustomobject]@{ component = 'app'; version = '1.2.3' }) |
+ Should -Be 'https://github.com/trycua/cua/.github/workflows/cd-cua-spaces.yml@refs/tags/cua-spaces-v1.2.3'
+ Get-RebuiltIdentity | Should -Be 'https://github.com/trycua/cua/.github/workflows/cd-cua-spaces.yml@refs/heads/main'
+ }
+
+ # A POSIX shell script stands in for cosign: it passes only the main
+ # identity pinned to the repository, the main ref and workflow_dispatch.
+ It 'a rebuild claim must name this tag and list the artifact sha256' -Skip:($IsWindows) {
+ $dir = Join-Path $env:CUA_TEST_ROOT 'claim'
+ New-Item -ItemType Directory -Force -Path $dir | Out-Null
+ $cosign = Join-Path $dir 'cosign'
+ $main = Get-RebuiltIdentity
+ Set-Content -LiteralPath $cosign -Value "#!/bin/sh`nid=; repo=; ref=; trig=; prev=`nfor a in `"`$@`"; do case `"`$prev`" in --certificate-identity) id=`$a;; --certificate-github-workflow-repository) repo=`$a;; --certificate-github-workflow-ref) ref=`$a;; --certificate-github-workflow-trigger) trig=`$a;; esac; prev=`$a; done`n[ `"`$id`" = '$main' ] && [ `"`$repo`" = trycua/cua ] && [ `"`$ref`" = refs/heads/main ] && [ `"`$trig`" = workflow_dispatch ] && exit 0`nexit 1"
+ chmod +x $cosign
+ $file = Join-Path $dir 'cua-spaces-1.2.3-windows-x64-setup.exe'
+ Set-Content -LiteralPath $file -Value 'nsis'
+ $sha = (Get-FileHash -LiteralPath $file -Algorithm SHA256).Hash.ToLowerInvariant()
+ Set-Content -LiteralPath (Join-Path $dir 'rebuild-claim.txt.sigstore.json') -Value '{}'
+ $bundleUrl = (ConvertTo-FileUrl $dir) + '/cua-spaces-1.2.3-windows-x64-setup.exe.sigstore.json'
+ $manifestUrl = (ConvertTo-FileUrl $dir) + '/release-artifacts.json'
+ $name = Split-Path -Leaf $file
+
+ Set-Content -LiteralPath (Join-Path $dir 'rebuild-claim.txt') -Value @('tag cua-spaces-v1.2.3', "$sha $name")
+ Test-RebuildClaim $cosign $file $bundleUrl '1.2.3' $manifestUrl | Should -BeTrue
+
+ Set-Content -LiteralPath (Join-Path $dir 'rebuild-claim.txt') -Value @('tag cua-spaces-v0.0.1', "$sha $name")
+ Test-RebuildClaim $cosign $file $bundleUrl '1.2.3' $manifestUrl | Should -BeFalse
+
+ Set-Content -LiteralPath (Join-Path $dir 'rebuild-claim.txt') -Value @('tag cua-spaces-v1.2.3', ('0' * 64) + " $name")
+ Test-RebuildClaim $cosign $file $bundleUrl '1.2.3' $manifestUrl | Should -BeFalse
+ }
+
It 'orders cua versions as semver, a dev build older than its release' {
Test-CuaVersionNewer '0.7.99' '0.7.0' | Should -BeTrue
Test-CuaVersionNewer '0.10.0' '0.9.9' | Should -BeTrue
diff --git a/scripts/install/tests/run.sh b/scripts/install/tests/run.sh
index 6d1aea8faf..a7c408dc2d 100755
--- a/scripts/install/tests/run.sh
+++ b/scripts/install/tests/run.sh
@@ -580,8 +580,9 @@ inst CUA_INSTALL_MANIFEST_URL="$base/sig2/release-artifacts.json" -- --yes --no-
check "--require-signature still fails without minisign or cosign" sh -c "[ $status != 0 ] && grep -q 'no verifiable signature' '$work/out'"
# cosign, app: a release rebuilt by a dispatch from main is signed by
-# cd-cua-spaces.yml at refs/heads/main; the installer accepts that identity
-# next to the tag one, and still refuses any other.
+# cd-cua-spaces.yml at refs/heads/main, which names no tag. The installer
+# accepts that identity only with the dispatch trigger, the main ref and a
+# signed rebuild-claim.txt naming this tag and the artifact's sha256.
sig3="$release/sig3"
mkdir -p "$sig3" "$work/fakebin-cosign3"
cp "$tag_dir"/cua-cli-* "$tag_dir"/cua-spaces-"$version"-linux-x64.AppImage "$sig3/"
@@ -590,21 +591,44 @@ python3 "$manifest_tool" --component cli --version "$version" --dir "$sig3" --ou
python3 "$manifest_tool" --component app --version "$version" --dir "$sig3" --merge "$sig3/cli.json" --out "$sig3/release-artifacts.json"
cli_identity="https://github.com/trycua/cua/.github/workflows/cd-cua-sdk.yml@refs/tags/cua-sdk-v$version"
main_identity="https://github.com/trycua/cua/.github/workflows/cd-cua-spaces.yml@refs/heads/main"
+appimage="$(basename "$sig3"/*.AppImage)"
+appsum="$(sha256sum "$sig3/$appimage" | cut -d' ' -f1)"
+# The fake cosign knows only the CLI tag identity, and the app's main identity
+# when the call also pins the repository, the main ref and workflow_dispatch.
cat >"$work/fakebin-cosign3/cosign" <<COSIGN
#!/bin/sh
-prev=""
+printf '%s\n' "\$*" >>"$work/cosign3.log"
+id=""; repo=""; ref=""; trig=""; prev=""
for a in "\$@"; do
- if [ "\$prev" = --certificate-identity ]; then
- [ "\$a" = "$cli_identity" ] && exit 0
- [ "\$a" = "$main_identity" ] && exit 0
- fi
+ case "\$prev" in
+ --certificate-identity) id="\$a" ;;
+ --certificate-github-workflow-repository) repo="\$a" ;;
+ --certificate-github-workflow-ref) ref="\$a" ;;
+ --certificate-github-workflow-trigger) trig="\$a" ;;
+ esac
prev="\$a"
done
+[ "\$id" = "$cli_identity" ] && exit 0
+[ "\$id" = "$main_identity" ] && [ "\$repo" = trycua/cua ] && [ "\$ref" = refs/heads/main ] && [ "\$trig" = workflow_dispatch ] && exit 0
exit 1
COSIGN
chmod +x "$work/fakebin-cosign3/cosign"
+# No claim: the main-branch signature alone is refused.
+inst PATH="$work/fakebin-cosign3:$PATH" CUA_INSTALL_MANIFEST_URL="$base/sig3/release-artifacts.json" -- --yes --no-onboarding --select spaces --require-signature --prefix "$work/sg3"
+check "cosign: a main-branch app signature without a rebuild claim aborts" sh -c "[ $status != 0 ] && grep -q 'cosign signature check failed' '$work/out'"
+# A claim for this tag and this file, signed by the same identity.
+printf 'tag cua-spaces-v%s\nsha 0000000000000000000000000000000000000000\n%s %s\n' "$version" "$appsum" "$appimage" >"$sig3/rebuild-claim.txt"
+printf '{}\n' >"$sig3/rebuild-claim.txt.sigstore.json"
inst PATH="$work/fakebin-cosign3:$PATH" CUA_INSTALL_MANIFEST_URL="$base/sig3/release-artifacts.json" -- --yes --no-onboarding --select spaces --require-signature --prefix "$work/sg4"
-check "cosign accepts the app signed by cd-cua-spaces.yml at refs/heads/main (rebuilt release)" sh -c "[ $status = 0 ] && [ -x '$work/sg4/bin/cua-spaces' ]"
+check "cosign accepts a rebuilt app: main identity, dispatch trigger and a claim for this tag" sh -c "[ $status = 0 ] && [ -x '$work/sg4/bin/cua-spaces' ] && grep -q -- '--certificate-github-workflow-trigger workflow_dispatch' '$work/cosign3.log'"
+# A claim for a different tag (a build of another release) is refused.
+printf 'tag cua-spaces-v0.0.1\n%s %s\n' "$appsum" "$appimage" >"$sig3/rebuild-claim.txt"
+inst PATH="$work/fakebin-cosign3:$PATH" CUA_INSTALL_MANIFEST_URL="$base/sig3/release-artifacts.json" -- --yes --no-onboarding --select spaces --prefix "$work/sg6"
+check "cosign: a rebuild claim for another tag aborts" sh -c "[ $status != 0 ] && grep -q 'cosign signature check failed' '$work/out'"
+# A claim that does not list this file's sha256 is refused.
+printf 'tag cua-spaces-v%s\n%s %s\n' "$version" "0000000000000000000000000000000000000000000000000000000000000000" "$appimage" >"$sig3/rebuild-claim.txt"
+inst PATH="$work/fakebin-cosign3:$PATH" CUA_INSTALL_MANIFEST_URL="$base/sig3/release-artifacts.json" -- --yes --no-onboarding --select spaces --prefix "$work/sg7"
+check "cosign: a rebuild claim without this artifact's sha256 aborts" sh -c "[ $status != 0 ] && grep -q 'cosign signature check failed' '$work/out'"
printf '#!/bin/sh\nexit 1\n' >"$work/fakebin-cosign3/cosign"
inst PATH="$work/fakebin-cosign3:$PATH" CUA_INSTALL_MANIFEST_URL="$base/sig3/release-artifacts.json" -- --yes --no-onboarding --select spaces --prefix "$work/sg5"
check "cosign: an app bundle from any other identity aborts" sh -c "[ $status != 0 ] && grep -q 'cosign signature check failed' '$work/out'"