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.

Verify Spaces setup Authenticode signature before launch (#5744)

injaneity9bf7e51adb66
diff --git a/.github/scripts/tests/test_spaces_installer_authenticode.py b/.github/scripts/tests/test_spaces_installer_authenticode.py
new file mode 100644
index 0000000000..c3811ab112
--- /dev/null
+++ b/.github/scripts/tests/test_spaces_installer_authenticode.py
@@ -0,0 +1,161 @@
+import json
+import shutil
+import subprocess
+import tempfile
+import unittest
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[3]
+INSTALLER = ROOT / "scripts/install/install.ps1"
+PWSH = shutil.which("pwsh")
+
+HARNESS = r"""
+param([string]$Script, [string]$Scenario)
+$env:CUA_INSTALL_NO_RUN = '1'
+. $Script
+$env:CUA_INSTALL_NO_RUN = $null
+Set-StrictMode -Version 3
+$ErrorActionPreference = 'Stop'
+$VerbosePreference = 'Continue'
+$Installer = if ($Scenario -in @('msi', 'fallback')) { 'msi' } else { 'nsis' }
+$DryRun = $Scenario -eq 'dry-run'
+$Mode = 'client'
+$RequireSignature = $false
+$script:events = [System.Collections.Generic.List[string]]::new()
+$script:launches = @()
+$script:inspected = @()
+$script:certificate = $null
+if ($Scenario -notin @('missing-certificate', 'verifier-error')) {
+ $cn = switch ($Scenario) {
+ 'wrong-publisher' { 'Other Publisher' }
+ 'suffix' { 'Cua AI, Inc. Evil' }
+ 'case' { 'cua AI, Inc.' }
+ default { 'Cua AI, Inc.' }
+ }
+ $key = [System.Security.Cryptography.RSA]::Create(2048)
+ $request = [System.Security.Cryptography.X509Certificates.CertificateRequest]::new(
+ "CN=`"$cn`", O=Test", $key,
+ [System.Security.Cryptography.HashAlgorithmName]::SHA256,
+ [System.Security.Cryptography.RSASignaturePadding]::Pkcs1)
+ $script:certificate = $request.CreateSelfSigned(
+ [DateTimeOffset]::UtcNow.AddDays(-1), [DateTimeOffset]::UtcNow.AddDays(1))
+ $key.Dispose()
+}
+function Confirm-Step { return $true }
+function Find-Artifact {
+ return $Scenario -ne 'fallback'
+}
+function Get-Artifact { return '/tmp/cua-spaces-setup.exe' }
+function Get-AuthenticodeSignature {
+ [CmdletBinding()]
+ param([string]$LiteralPath)
+ $script:inspected += $LiteralPath
+ if ($Scenario -eq 'verifier-error') { throw 'verifier unavailable' }
+ $status = if ($Scenario -in @('NotSigned', 'HashMismatch')) { $Scenario } else { 'Valid' }
+ return [pscustomobject]@{
+ Status = $status
+ StatusMessage = "fixture: $status"
+ SignerCertificate = $script:certificate
+ }
+}
+function Start-Process {
+ param($FilePath, $ArgumentList, [switch]$Wait, [switch]$PassThru)
+ $script:events.Add('launch')
+ $script:launches += @{ file = $FilePath; arguments = @($ArgumentList) }
+ return [pscustomobject]@{ ExitCode = 0 }
+}
+$errorMessage = ''
+try {
+ Install-App @{} 'https://example.com/manifest.json' 'windows-x64' '/tmp' 4>&1 |
+ ForEach-Object { $script:events.Add("$_") }
+} catch { $errorMessage = $_.Exception.Message }
+@{
+ error = $errorMessage
+ errorKind = Get-CuaInstallErrorKind $errorMessage
+ didApp = $script:DidApp
+ inspected = @($script:inspected)
+ launches = @($script:launches)
+ events = $script:events.ToArray()
+} | ConvertTo-Json -Depth 5 -Compress
+"""
+
+
+class SpacesInstallerAuthenticodeTests(unittest.TestCase):
+ @unittest.skipUnless(PWSH, "needs PowerShell 7")
+ def test_app_execution_boundary(self):
+ with tempfile.TemporaryDirectory() as directory:
+ harness = Path(directory) / "harness.ps1"
+ harness.write_text(HARNESS)
+ for scenario in (
+ "wrong-publisher",
+ "valid",
+ "NotSigned",
+ "HashMismatch",
+ "missing-certificate",
+ "suffix",
+ "case",
+ "verifier-error",
+ "dry-run",
+ "msi",
+ "fallback",
+ ):
+ with self.subTest(scenario=scenario):
+ result = subprocess.run(
+ [
+ PWSH,
+ "-NoProfile",
+ "-File",
+ str(harness),
+ "-Script",
+ str(INSTALLER),
+ "-Scenario",
+ scenario,
+ ],
+ capture_output=True,
+ text=True,
+ timeout=30,
+ )
+ self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
+ data = json.loads(result.stdout.splitlines()[-1])
+ if scenario in ("dry-run", "msi"):
+ self.assertEqual(data["inspected"], [])
+ else:
+ self.assertEqual(data["inspected"], ["/tmp/cua-spaces-setup.exe"])
+ if scenario in ("valid", "fallback", "msi"):
+ self.assertEqual(data["error"], "")
+ self.assertTrue(data["didApp"])
+ self.assertEqual(len(data["launches"]), 1)
+ launch = data["launches"][0]
+ if scenario == "msi":
+ self.assertEqual(launch["file"], "msiexec.exe")
+ self.assertIn("/qn", launch["arguments"])
+ else:
+ self.assertEqual(launch["file"], "/tmp/cua-spaces-setup.exe")
+ self.assertIn("/S", launch["arguments"])
+ verified = next(
+ i
+ for i, event in enumerate(data["events"])
+ if "verified the Authenticode signature" in event
+ and "Cua AI, Inc." in event
+ )
+ self.assertLess(verified, data["events"].index("launch"))
+ else:
+ self.assertEqual(data["launches"], [])
+ self.assertFalse(data["didApp"])
+ if scenario == "dry-run":
+ self.assertEqual(data["error"], "")
+ else:
+ self.assertIn("signature", data["error"].lower())
+ self.assertIn("refusing to run installer", data["error"])
+ self.assertEqual(data["errorKind"], "signature")
+
+ @unittest.skipIf(PWSH, "behavioral harness checks ordering with PowerShell")
+ def test_signature_precedes_execution_without_powershell(self):
+ source = INSTALLER.read_text()
+ app = source.split("function Install-App(", 1)[1].split("function Get-DriverBinDir", 1)[0]
+ self.assertLess(app.index("if ($DryRun)"), app.index("Get-AuthenticodeSignature"))
+ self.assertLess(app.index("Get-AuthenticodeSignature"), app.index("Start-Process"))
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/.github/workflows/ci-test-scripts.yml b/.github/workflows/ci-test-scripts.yml
index 91069923c6..ccc5f3fef1 100644
--- a/.github/workflows/ci-test-scripts.yml
+++ b/.github/workflows/ci-test-scripts.yml
@@ -56,6 +56,7 @@ on:
- "libs/cua-driver/tests/manual-e2e-allowlist.txt"
- "libs/cua-driver/rust/crates/cua-driver/tests/**"
- "libs/cua-driver/rust/crates/cua-driver-e2e/tests/**"
+ - "scripts/install/install.ps1"
- "scripts/ci/**"
- "scripts/ci/macos/**"
- "libs/cua-driver/tests/perception-demo/**"
diff --git a/scripts/install/README.md b/scripts/install/README.md
index 59b06c29fd..b5302d9169 100644
--- a/scripts/install/README.md
+++ b/scripts/install/README.md
@@ -72,7 +72,7 @@ Questions read from the terminal, never from the script on stdin, so they work u
|---|---|---|
| macOS | `~/.local/bin/cua` (`/usr/local/bin` as root) | `/Applications` if writable, else `~/Applications` (from the .dmg; the SwiftUI app, macOS 26 or later, skipped on older macOS) |
| Linux | same as macOS | The Electron app: on Debian/Ubuntu (x64, arm64) the .deb via apt-get when run as root or with passwordless sudo; otherwise the AppImage at `~/.local/bin/cua-spaces` plus a desktop entry |
-| Windows | `%LOCALAPPDATA%\Programs\cua\bin\cua.exe` | The Electron app's NSIS `setup.exe` for the machine's architecture (sha256 and cosign checked), run silently (`/S /MODE=`); a silent MSI (`CUA_SPACES_MODE=`) only if a release has one |
+| Windows | `%LOCALAPPDATA%\Programs\cua\bin\cua.exe` | The Electron app's NSIS `setup.exe` for the machine's architecture (sha256 and cosign checked, plus a mandatory Authenticode signature check for signer Cua AI, Inc.), run silently (`/S /MODE=`); a silent MSI (`CUA_SPACES_MODE=`) only if a release has one |
cua-driver lands where its own installer puts it: `~/.local/bin/cua-driver` (or `DIR/bin` with `--prefix`), `%LOCALAPPDATA%\Programs\Cua\cua-driver\bin` on Windows.
diff --git a/scripts/install/install.ps1 b/scripts/install/install.ps1
index a548f54919..432f2caa65 100644
--- a/scripts/install/install.ps1
+++ b/scripts/install/install.ps1
@@ -29,8 +29,8 @@ signature when available), installs `cua` to %LOCALAPPDATA%\Programs\cua\bin
skips it), then runs `cua auth login` when a user is at the console (not
with -CliOnly, -Pair or -NoOnboarding).
-AppOnly, -Mode and the `spaces` item install the Cua Spaces app: its signed
-setup.exe for this machine's architecture, run silently (/S) after the sha256
-(and cosign, when available) check.
+setup.exe for this machine's architecture, run silently (/S) after checking sha256,
+cosign (when available) and its Authenticode signature (signer Cua AI, Inc.).
.PARAMETER Select
Preselect items (comma list: spaces, cua-driver, host); the list still shows.
@@ -604,6 +604,21 @@ function Install-App($Manifest, [string]$ManifestUrl, [string]$Platform, [string
Write-Host "[dry-run] $($cmd.FilePath) $($cmd.ArgumentList -join ' ')"
return
}
+ if ($kind -eq 'nsis') {
+ try {
+ $sig = Get-AuthenticodeSignature -LiteralPath $file -ErrorAction Stop
+ } catch {
+ Stop-Install "Cua Spaces Authenticode signature verification failed: $($_.Exception.Message); refusing to run installer."
+ }
+ if ($sig.Status -ne 'Valid') {
+ Stop-Install "Cua Spaces Authenticode signature is not valid ($($sig.Status): $($sig.StatusMessage)); refusing to run installer."
+ }
+ if (-not $sig.SignerCertificate -or
+ $sig.SignerCertificate.GetNameInfo([System.Security.Cryptography.X509Certificates.X509NameType]::SimpleName, $false) -cne 'Cua AI, Inc.') {
+ Stop-Install 'Cua Spaces Authenticode signature signer is not Cua AI, Inc.; refusing to run installer.'
+ }
+ Write-Info "verified the Authenticode signature of $(Split-Path -Leaf $file) (Cua AI, Inc.)"
+ }
Write-Info "installing Cua Spaces ($kind, silent)"
$proc = Start-Process -FilePath $cmd.FilePath -ArgumentList $cmd.ArgumentList -Wait -PassThru
if ($proc.ExitCode -ne 0 -and $proc.ExitCode -ne 3010) { Stop-Install "Cua Spaces installer exited with $($proc.ExitCode)" }