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(cua-driver): refuse with 'did not verify' when cosign cannot start in install.ps1 (#6483)

injaneity23404c7f51ed
diff --git a/libs/cua-driver/scripts/install.ps1 b/libs/cua-driver/scripts/install.ps1
index fc4b5ae506..91567f4e84 100644
--- a/libs/cua-driver/scripts/install.ps1
+++ b/libs/cua-driver/scripts/install.ps1
@@ -1398,11 +1398,23 @@ function Assert-ReleaseZipIntegrity([string]$zipPath, [string]$version) {
$cosign = Get-Command cosign -ErrorAction SilentlyContinue
if ($cosign) {
$identity = "https://github.com/$Repo/.github/workflows/cd-rust-cua-driver.yml@refs/tags/$tag"
- & $cosign verify-blob --bundle $bundlePath `
- --certificate-identity $identity `
- --certificate-oidc-issuer $CosignOidcIssuer $zipPath *> $null
- if ($LASTEXITCODE -ne 0) {
- Write-ErrorStep "the Sigstore signature of $zipName did not verify for $tag; refusing to install it."
+ $prevEAP = $ErrorActionPreference
+ $ErrorActionPreference = 'Continue'
+ $verified = $false
+ $why = ''
+ try {
+ & $cosign verify-blob --bundle $bundlePath `
+ --certificate-identity $identity `
+ --certificate-oidc-issuer $CosignOidcIssuer $zipPath 2>&1 | Out-Null
+ $verified = $LASTEXITCODE -eq 0
+ } catch {
+ # A cosign that cannot start throws instead of setting $LASTEXITCODE.
+ $why = ' (cosign could not start)'
+ } finally {
+ $ErrorActionPreference = $prevEAP
+ }
+ if (-not $verified) {
+ Write-ErrorStep "the Sigstore signature of $zipName did not verify for $tag$why; refusing to install it."
exit 1
}
Write-Step "verified the Sigstore signature of $zipName"
diff --git a/libs/cua-driver/scripts/tests/install-common-windows-regression.ps1 b/libs/cua-driver/scripts/tests/install-common-windows-regression.ps1
index 9207dac91e..dd2e75ce83 100644
--- a/libs/cua-driver/scripts/tests/install-common-windows-regression.ps1
+++ b/libs/cua-driver/scripts/tests/install-common-windows-regression.ps1
@@ -150,3 +150,77 @@ finally {
Stop-Process -Force -ErrorAction SilentlyContinue
Remove-Item -LiteralPath $root -Recurse -Force -ErrorAction SilentlyContinue
}
+
+$installScript = Join-Path (Split-Path -Parent $PSScriptRoot) 'install.ps1'
+$tokens = $null
+$parseErrors = $null
+$installAst = [System.Management.Automation.Language.Parser]::ParseFile($installScript, [ref]$tokens, [ref]$parseErrors)
+Assert-True ($parseErrors.Count -eq 0) "install.ps1 parse errors: $($parseErrors -join '; ')"
+$integrityCheck = $installAst.Find({
+ param($node)
+ $node -is [System.Management.Automation.Language.FunctionDefinitionAst] -and
+ $node.Name -eq 'Assert-ReleaseZipIntegrity'
+}, $true)
+Assert-True ($null -ne $integrityCheck) 'Assert-ReleaseZipIntegrity not found in install.ps1'
+. ([scriptblock]::Create($integrityCheck.Extent.Text))
+
+$Repo = 'trycua/cua'
+$TagPrefix = 'cua-driver-rs-v'
+$ChecksumsRequiredFrom = [version]'0.31.0'
+$SigstoreRequiredFrom = [version]'0.32.0'
+$CosignOidcIssuer = 'https://token.actions.githubusercontent.com'
+$RequireSignature = $true
+$Script:CuaDriverRsReleaseTag = 'cua-driver-rs-v0.30.0'
+$zipName = 'cua-driver-rs-0.30.0-windows-x86_64.zip'
+$steps = New-Object System.Collections.Generic.List[string]
+
+function Get-BaseVersion([string]$version) { return [version]$version }
+function Get-ReleaseFile([string]$name, [string]$destPath) { return $name.EndsWith('.sigstore.json') }
+function Write-Step($message) { $steps.Add($message) }
+function Write-WarningStep($message) { }
+function Write-ErrorStep($message) { throw $message }
+
+function Invoke-IntegrityCheck {
+ param([string[]]$StandInLines)
+ Set-Content -LiteralPath (Join-Path $cosignRoot 'cosign.cmd') -Value (@('@echo off') + $StandInLines) -Encoding Ascii
+ $steps.Clear()
+ try {
+ Assert-ReleaseZipIntegrity (Join-Path $cosignRoot $zipName) '0.30.0'
+ return $null
+ }
+ catch {
+ return $_.Exception.Message
+ }
+}
+
+$cosignRoot = Join-Path ([System.IO.Path]::GetTempPath()) ('cua-driver-cosign-' + [guid]::NewGuid().ToString('N'))
+New-Item -ItemType Directory -Path $cosignRoot | Out-Null
+$savedPath = $env:PATH
+try {
+ $env:PATH = "$cosignRoot;$savedPath"
+
+ $failure = Invoke-IntegrityCheck @('echo Error: none of the expected identities matched 1>&2', 'exit /b 1')
+ Assert-True ("$failure" -like '*did not verify*') "a failed cosign check was not refused: $failure"
+ Assert-True (@($steps | Where-Object { $_ -like '*Sigstore signature*' }).Count -eq 0) `
+ 'a failed cosign check logged the Sigstore success step'
+
+ $failure = Invoke-IntegrityCheck @('echo Verified OK 1>&2', 'exit /b 0')
+ Assert-True ($null -eq $failure) "a successful cosign check aborted the install: $failure"
+ Assert-True ($steps -contains "verified the Sigstore signature of $zipName") `
+ 'a successful cosign check did not log the Sigstore success step'
+
+ # A cosign.exe that is not a valid program throws when started instead of setting $LASTEXITCODE.
+ Remove-Item -LiteralPath (Join-Path $cosignRoot 'cosign.cmd')
+ [System.IO.File]::WriteAllBytes((Join-Path $cosignRoot 'cosign.exe'), [byte[]](0, 1, 2, 3))
+ $steps.Clear()
+ $failure = $null
+ try { Assert-ReleaseZipIntegrity (Join-Path $cosignRoot $zipName) '0.30.0' }
+ catch { $failure = $_.Exception.Message }
+ Assert-True ("$failure" -like '*did not verify*could not start*') "a cosign that could not start was not refused: $failure"
+
+ Write-Host 'Windows installer cosign check accepted a verified zip and refused an unverified one.'
+}
+finally {
+ $env:PATH = $savedPath
+ Remove-Item -LiteralPath $cosignRoot -Recurse -Force -ErrorAction SilentlyContinue
+}