Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix: sign and verify every Windows release executable

Richie McIlroy8d49546d9474
diff --git a/.github/workflows/desktop-release.yml b/.github/workflows/desktop-release.yml
index 97728444e..beb54916f 100644
--- a/.github/workflows/desktop-release.yml
+++ b/.github/workflows/desktop-release.yml
@@ -359,6 +359,55 @@ jobs:
TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
RUST_TARGET_TRIPLE: ${{ matrix.settings.target }}
+ # Tauri patches Cap.exe with the NSIS marker during the first bundle.
+ # Sign those patched bytes, then rebundle with the same package type.
+ - name: Stage Windows payload for Authenticode signing
+ if: ${{ runner.os == 'Windows' }}
+ shell: pwsh
+ run: |
+ ./scripts/windows-release-signing.ps1 -Operation Stage -Target "${{ matrix.settings.target }}" -WorkspaceRoot "$env:GITHUB_WORKSPACE"
+
+ - name: Upload unsigned Windows payload
+ if: ${{ runner.os == 'Windows' }}
+ id: upload_unsigned_windows_payload
+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
+ with:
+ name: unsigned-windows-payload
+ path: target/${{ matrix.settings.target }}/release/windows-signing/payload
+ if-no-files-found: error
+
+ - name: Submit SignPath payload signing request
+ if: ${{ runner.os == 'Windows' }}
+ timeout-minutes: 90
+ id: submit_signpath_payload_signing_request
+ uses: signpath/github-action-submit-signing-request@ced31329c0317e779dad2eec2a7c3bb46ea1343e # v1
+ with:
+ api-token: ${{ secrets.SIGNPATH_API_TOKEN }}
+ organization-id: ${{ secrets.SIGNPATH_ORGANIZATION_ID }}
+ project-slug: ${{ secrets.SIGNPATH_PROJECT_SLUG }}
+ signing-policy-slug: ${{ secrets.SIGNPATH_SIGNING_POLICY_SLUG }}
+ artifact-configuration-slug: ${{ secrets.SIGNPATH_ARTIFACT_CONFIGURATION_SLUG }}
+ github-artifact-id: ${{ steps.upload_unsigned_windows_payload.outputs.artifact-id }}
+ wait-for-completion: true
+ wait-for-completion-timeout-in-seconds: 5400
+ service-unavailable-timeout-in-seconds: 5400
+ output-artifact-directory: signed-windows-payload
+
+ - name: Restore and verify signed Windows payload
+ if: ${{ runner.os == 'Windows' }}
+ shell: pwsh
+ run: |
+ ./scripts/windows-release-signing.ps1 -Operation Restore -Target "${{ matrix.settings.target }}" -WorkspaceRoot "$env:GITHUB_WORKSPACE"
+
+ - name: Bundle Windows installer
+ if: ${{ runner.os == 'Windows' }}
+ working-directory: apps/desktop
+ shell: bash
+ run: pnpm tauri bundle --target ${{ matrix.settings.target }} --bundles nsis --config src-tauri/tauri.prod.conf.json
+ env:
+ TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
+ TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
+
- name: Verify macOS app contents and signing
if: ${{ runner.os == 'macOS' }}
shell: bash
@@ -659,8 +708,9 @@ jobs:
- name: Submit SignPath signing request
if: ${{ runner.os == 'Windows' }}
+ timeout-minutes: 90
id: submit_signpath_signing_request
- uses: signpath/github-action-submit-signing-request@v1
+ uses: signpath/github-action-submit-signing-request@ced31329c0317e779dad2eec2a7c3bb46ea1343e # v1
with:
api-token: ${{ secrets.SIGNPATH_API_TOKEN }}
organization-id: ${{ secrets.SIGNPATH_ORGANIZATION_ID }}
@@ -669,20 +719,11 @@ jobs:
artifact-configuration-slug: ${{ secrets.SIGNPATH_ARTIFACT_CONFIGURATION_SLUG }}
github-artifact-id: ${{ steps.upload_unsigned_windows_installer.outputs.artifact-id }}
wait-for-completion: true
- # SignPath Foundation requires a human to approve each signing
- # request, so this step blocks until someone clicks approve. Raising
- # wait-for-completion-timeout-in-seconds alone did NOT extend the
- # window: while a request sits "WaitingForApproval" the action's
- # per-call retry budget (service-unavailable-timeout-in-seconds,
- # default 600s) is what expires and fails the job at ~10 min, so both
- # must be raised. GitHub-hosted jobs are hard-capped at 6h total and
- # the Windows build already consumes part of that, so ~4h is the
- # practical ceiling for a blocking wait; the action times out cleanly
- # here rather than letting GitHub kill the runner mid-build. For a
- # genuinely longer (12h+) window the signing has to be decoupled from
- # the build job (submit without waiting, finalise in a later job).
- wait-for-completion-timeout-in-seconds: 14400
- service-unavailable-timeout-in-seconds: 14400
+ # Both signing stages share the six-hour job budget with the build.
+ # Match the approval and retry budgets so waiting for approval does
+ # not expire at the action's shorter default retry timeout.
+ wait-for-completion-timeout-in-seconds: 5400
+ service-unavailable-timeout-in-seconds: 5400
output-artifact-directory: signed-windows-installer
- name: Restore signed Windows installer
@@ -722,6 +763,18 @@ jobs:
}
}
+ - name: Verify extracted Windows payload signatures and hashes
+ if: ${{ runner.os == 'Windows' }}
+ shell: pwsh
+ run: |
+ $installers = Get-ChildItem -Path "target/${{ matrix.settings.target }}/release/bundle/nsis" -Filter *.exe
+ if (-not $installers) {
+ throw "No Windows installer exists for extracted payload verification."
+ }
+ foreach ($installer in $installers) {
+ ./scripts/windows-release-signing.ps1 -Operation VerifyInstaller -Target "${{ matrix.settings.target }}" -WorkspaceRoot "$env:GITHUB_WORKSPACE" -InstallerPath $installer.FullName
+ }
+
- name: Re-sign Windows installer for Tauri updater
if: ${{ runner.os == 'Windows' }}
shell: bash
@@ -751,6 +804,7 @@ jobs:
target/${{ matrix.settings.target }}/release/bundle/dmg/*.dmg
target/${{ matrix.settings.target }}/release/bundle/nsis/*.exe
target/${{ matrix.settings.target }}/release/bundle/nsis/*.sig
+ target/${{ matrix.settings.target }}/release/windows-signing/payload-manifest.json
target/${{ matrix.settings.target }}/release/bundle/deb/*.deb
target/${{ matrix.settings.target }}/release/bundle/deb/*.sig
target/${{ matrix.settings.target }}/release/bundle/appimage/*.AppImage
diff --git a/scripts/windows-release-signing.ps1 b/scripts/windows-release-signing.ps1
new file mode 100644
index 000000000..467cd65a2
--- /dev/null
+++ b/scripts/windows-release-signing.ps1
@@ -0,0 +1,210 @@
+[CmdletBinding()]
+param(
+ [Parameter(Mandatory = $true)]
+ [ValidateSet("Stage", "Restore", "VerifyInstaller")]
+ [string] $Operation,
+ [string] $Target = $env:RUST_TARGET_TRIPLE,
+ [string] $WorkspaceRoot = $env:GITHUB_WORKSPACE,
+ [string] $InstallerPath
+)
+
+Set-StrictMode -Version Latest
+$ErrorActionPreference = "Stop"
+
+if ([string]::IsNullOrWhiteSpace($WorkspaceRoot)) {
+ $WorkspaceRoot = (Get-Location).Path
+}
+
+$WorkspaceRoot = (Resolve-Path -LiteralPath $WorkspaceRoot).Path
+if ([string]::IsNullOrWhiteSpace($Target)) {
+ throw "A Windows target triple is required."
+}
+
+$releaseRoot = Join-Path $WorkspaceRoot "target/$Target/release"
+$signingRoot = Join-Path $releaseRoot "windows-signing"
+$payloadRoot = Join-Path $signingRoot "payload"
+$manifestPath = Join-Path $signingRoot "payload-manifest.json"
+
+function Get-PayloadDefinitions {
+ return @(
+ [pscustomobject]@{
+ Name = "Cap.exe"
+ Path = Join-Path $releaseRoot "Cap.exe"
+ },
+ [pscustomobject]@{
+ Name = "cap-gpui.exe"
+ Path = Join-Path $WorkspaceRoot "apps/desktop/src-tauri/binaries/cap-gpui-$Target.exe"
+ },
+ [pscustomobject]@{
+ Name = "cap-cli.exe"
+ Path = Join-Path $WorkspaceRoot "apps/desktop/src-tauri/binaries/cap-cli-$Target.exe"
+ },
+ [pscustomobject]@{
+ Name = "cap-exporter.exe"
+ Path = Join-Path $WorkspaceRoot "apps/desktop/src-tauri/binaries/cap-exporter-$Target.exe"
+ },
+ [pscustomobject]@{
+ Name = "cap-muxer.exe"
+ Path = Join-Path $WorkspaceRoot "apps/desktop/src-tauri/binaries/cap-muxer-$Target.exe"
+ }
+ )
+}
+
+function Get-PayloadDefinition([string] $Name) {
+ $definition = @(Get-PayloadDefinitions | Where-Object Name -eq $Name)
+ if ($definition.Count -ne 1) {
+ throw "Unknown or duplicate payload file '$Name'."
+ }
+ return $definition[0]
+}
+
+function Get-Sha256([string] $Path) {
+ return (Get-FileHash -LiteralPath $Path -Algorithm SHA256).Hash.ToLowerInvariant()
+}
+
+function Write-Manifest($Manifest) {
+ $encoding = [System.Text.UTF8Encoding]::new($false)
+ [System.IO.File]::WriteAllText(
+ $manifestPath,
+ ($Manifest | ConvertTo-Json -Depth 8),
+ $encoding
+ )
+}
+
+function Read-Manifest {
+ if (-not (Test-Path -LiteralPath $manifestPath -PathType Leaf)) {
+ throw "Payload manifest '$manifestPath' does not exist."
+ }
+ $manifest = Get-Content -LiteralPath $manifestPath -Raw | ConvertFrom-Json
+ if ($manifest.schemaVersion -ne 1 -or $manifest.target -ne $Target -or @($manifest.entries).Count -ne 5) {
+ throw "Payload manifest '$manifestPath' has an unexpected schema."
+ }
+ $expectedNames = @(Get-PayloadDefinitions | ForEach-Object Name | Sort-Object)
+ $actualNames = @($manifest.entries | ForEach-Object name | Sort-Object)
+ if (Compare-Object $expectedNames $actualNames) {
+ throw "Payload manifest '$manifestPath' has unexpected executable names."
+ }
+ return $manifest
+}
+
+function Find-UniqueFile([string] $Root, [string] $Name) {
+ $matches = @(Get-ChildItem -LiteralPath $Root -Recurse -File | Where-Object Name -eq $Name)
+ if ($matches.Count -ne 1) {
+ throw "Expected exactly one '$Name' under '$Root', found $($matches.Count)."
+ }
+ return $matches[0]
+}
+
+function Assert-Authenticode([string] $Path) {
+ $signature = Get-AuthenticodeSignature -FilePath $Path
+ if ($signature.Status -ne "Valid" -or $null -eq $signature.SignerCertificate) {
+ throw "Authenticode verification failed for '$Path': $($signature.Status)."
+ }
+ return $signature
+}
+
+function Stage-Payload {
+ if (Test-Path -LiteralPath $signingRoot) {
+ Remove-Item -LiteralPath $signingRoot -Recurse -Force
+ }
+ $null = New-Item -ItemType Directory -Path $payloadRoot -Force
+ $entries = foreach ($definition in Get-PayloadDefinitions) {
+ if (-not (Test-Path -LiteralPath $definition.Path -PathType Leaf)) {
+ throw "Required payload executable '$($definition.Path)' does not exist."
+ }
+ $destination = Join-Path $payloadRoot $definition.Name
+ $null = Copy-Item -LiteralPath $definition.Path -Destination $destination -Force -PassThru
+ [ordered]@{
+ name = $definition.Name
+ bytes = (Get-Item -LiteralPath $definition.Path).Length
+ preSignSha256 = Get-Sha256 $definition.Path
+ signedSha256 = $null
+ signedBytes = $null
+ signerThumbprint = $null
+ signerSubject = $null
+ }
+ }
+ Write-Manifest ([ordered]@{
+ schemaVersion = 1
+ target = $Target
+ entries = @($entries)
+ verifiedInstallers = @()
+ })
+ Write-Host "Staged $($entries.Count) first-party Windows payload executables."
+}
+
+function Restore-Payload {
+ $manifest = Read-Manifest
+ $signedRoot = Join-Path $WorkspaceRoot "signed-windows-payload"
+ if (-not (Test-Path -LiteralPath $signedRoot -PathType Container)) {
+ throw "Signed payload directory '$signedRoot' does not exist."
+ }
+
+ foreach ($entry in $manifest.entries) {
+ $definition = Get-PayloadDefinition $entry.name
+ if ((Get-Sha256 $definition.Path) -ne $entry.preSignSha256) {
+ throw "Unsigned payload '$($entry.name)' changed after staging."
+ }
+ $signedFile = Find-UniqueFile $signedRoot $entry.name
+ $signature = Assert-Authenticode $signedFile.FullName
+ $null = Copy-Item -LiteralPath $signedFile.FullName -Destination $definition.Path -Force -PassThru
+ $null = Assert-Authenticode $definition.Path
+ $entry.signedSha256 = Get-Sha256 $definition.Path
+ $entry.signedBytes = (Get-Item -LiteralPath $definition.Path).Length
+ $entry.signerThumbprint = $signature.SignerCertificate.Thumbprint
+ $entry.signerSubject = $signature.SignerCertificate.Subject
+ }
+ Write-Manifest $manifest
+ Write-Host "Restored and Authenticode-verified signed Windows payload executables."
+}
+
+function Verify-Installer {
+ if ([string]::IsNullOrWhiteSpace($InstallerPath)) {
+ throw "-InstallerPath is required for VerifyInstaller."
+ }
+ $installer = (Resolve-Path -LiteralPath $InstallerPath).Path
+ $installerSignature = Assert-Authenticode $installer
+ $manifest = Read-Manifest
+ $extractRoot = Join-Path $signingRoot "installer-extract"
+ if (Test-Path -LiteralPath $extractRoot) {
+ Remove-Item -LiteralPath $extractRoot -Recurse -Force
+ }
+ $null = New-Item -ItemType Directory -Path $extractRoot -Force
+ try {
+ $sevenZip = Get-Command 7z -ErrorAction Stop
+ & $sevenZip.Source x $installer "-o$extractRoot" -y | Out-Host
+ if ($LASTEXITCODE -ne 0) {
+ throw "Could not extract Windows installer '$installer'."
+ }
+ foreach ($entry in $manifest.entries) {
+ if ([string]::IsNullOrWhiteSpace($entry.signedSha256)) {
+ throw "Manifest entry '$($entry.name)' has no signed hash."
+ }
+ $extracted = Find-UniqueFile $extractRoot $entry.name
+ $signature = Assert-Authenticode $extracted.FullName
+ $actualHash = Get-Sha256 $extracted.FullName
+ if ($actualHash -ne $entry.signedSha256 -or $signature.SignerCertificate.Thumbprint -ne $entry.signerThumbprint) {
+ throw "Installer payload '$($entry.name)' hash differs from the signed payload manifest."
+ }
+ }
+ $manifest.verifiedInstallers = @($manifest.verifiedInstallers) + @([ordered]@{
+ name = [System.IO.Path]::GetFileName($installer)
+ sha256 = Get-Sha256 $installer
+ signerThumbprint = $installerSignature.SignerCertificate.Thumbprint
+ signerSubject = $installerSignature.SignerCertificate.Subject
+ })
+ Write-Manifest $manifest
+ Write-Host "Verified installer Authenticode and signed payload hashes."
+ }
+ finally {
+ if (Test-Path -LiteralPath $extractRoot) {
+ Remove-Item -LiteralPath $extractRoot -Recurse -Force
+ }
+ }
+}
+
+switch ($Operation) {
+ "Stage" { Stage-Payload }
+ "Restore" { Restore-Payload }
+ "VerifyInstaller" { Verify-Installer }
+}