Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/shared/src/popup/views/install-helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ describe("renderInstallFlow", () => {

const primary = root.querySelector<HTMLElement>(".helper-install-primary")!;
expect(primary.textContent).toContain("without administrator access");
const alternatives = root.querySelector<HTMLDetailsElement>("details")!;
expect(alternatives.querySelector("code")!.textContent).not.toContain("-AllowUnsigned");
expect(alternatives.textContent).toContain("again with -AllowUnsigned added at the end");
expect(primary.querySelector<HTMLAnchorElement>("a")?.href).toBe(
`${release}/download/${version}/tailchrome-helper-windows-x64.msi`,
);
Expand All @@ -188,6 +191,8 @@ describe("renderInstallFlow", () => {
expect(command).toContain(`${release}/download/${version}/tailchrome-install.ps1`);
expect(command).toContain(`-Version '${version}'`);
expect(primary.textContent).toContain("native ARM64");
expect(command).not.toContain("-AllowUnsigned");
expect(primary.textContent).toContain("again with -AllowUnsigned added at the end");
const alternatives = root.querySelector<HTMLDetailsElement>("details")!;
expect(alternatives.open).toBe(false);
expect(alternatives.textContent).toContain("x64 package (runs under emulation)");
Expand Down
22 changes: 21 additions & 1 deletion packages/shared/src/popup/views/install-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ function createPrimaryInstall(
platform === "linux" ? unixInstallCommand() : powershellInstallCommand();
if (command) {
card.appendChild(createCodeBlock(command));
if (platform === "windows") {
card.appendChild(createUnsignedPowerShellHint());
}
} else {
card.appendChild(createReleaseLink());
}
Expand Down Expand Up @@ -431,7 +434,11 @@ function createAlternativeInstallDetails(

if (platform === "windows" && architecture === "amd64") {
appendAlternativeHeading(details, "PowerShell option");
appendCommandIfAvailable(details, powershellInstallCommand());
const command = powershellInstallCommand();
appendCommandIfAvailable(details, command);
if (command) {
details.appendChild(createUnsignedPowerShellHint());
}
appendAdvancedDocs(details);
return details;
}
Expand Down Expand Up @@ -482,6 +489,19 @@ function appendCommandIfAvailable(
}
}

/**
* The PowerShell installer requires an Authenticode signature unless the user
* explicitly opts in. Explain that opt-in here instead of baking it into the
* command, so signed releases keep rejecting an unsigned substitute (#151).
*/
function createUnsignedPowerShellHint(): HTMLElement {
const hint = document.createElement("p");
hint.className = "install-step-hint";
hint.textContent =
"If PowerShell stops at “Release is unsigned”, check the release notes. If they say this release's Windows helper is unsigned, run the command again with -AllowUnsigned added at the end.";
return hint;
}

function appendAdvancedDocs(container: HTMLElement): void {
const docs = document.createElement("a");
docs.className = "install-advanced-docs";
Expand Down
26 changes: 17 additions & 9 deletions scripts/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -164,29 +164,36 @@ function Invoke-Download([string]$Uri, [string]$Path) {
Invoke-WebRequest -UseBasicParsing -Uri $Uri -OutFile $Path
}

function Invoke-NativeProbe([string]$Command, [string[]]$Arguments) {
# Windows PowerShell 5.1 turns redirected native stderr into a terminating
# NativeCommandError when ErrorActionPreference is Stop, so a probe that
# merely reports failure on stderr would abort the installer (#151). Probes
# report through their exit code; scope Continue to this call only.
$ErrorActionPreference = 'Continue'
& $Command @Arguments *> $null
return $LASTEXITCODE
}

function Test-AvailableAttestation([string]$ArtifactPath) {
$gh = Get-Command gh -ErrorAction SilentlyContinue
if (-not $gh) {
Write-Warning 'GitHub CLI attestation verification is unavailable; the checksum and artifact share the GitHub Release trust boundary.'
return
}
& $gh.Source attestation verify --help *> $null
if ($LASTEXITCODE -ne 0) {
if ((Invoke-NativeProbe $gh.Source @('attestation', 'verify', '--help')) -ne 0) {
Write-Warning 'GitHub CLI attestation verification is unavailable; the checksum and artifact share the GitHub Release trust boundary.'
return
}
& $gh.Source auth status --hostname github.com *> $null
if ($LASTEXITCODE -ne 0) {
if ((Invoke-NativeProbe $gh.Source @('auth', 'status', '--hostname', 'github.com')) -ne 0) {
Write-Warning 'GitHub CLI is not authenticated; the checksum and artifact share the GitHub Release trust boundary.'
return
}
& $gh.Source attestation verify $ArtifactPath --hostname github.com --repo $Repository *> $null
if ($LASTEXITCODE -ne 0) {
if ((Invoke-NativeProbe $gh.Source @('attestation', 'verify', $ArtifactPath, '--hostname', 'github.com', '--repo', $Repository)) -ne 0) {
Fail 'GitHub artifact attestation verification failed.'
}
}

function Test-Authenticode([string]$ArtifactPath) {
function Test-Authenticode([string]$ArtifactPath, [string]$Version) {
$signatureCommand = Get-Command Get-AuthenticodeSignature -ErrorAction SilentlyContinue
if (-not $signatureCommand) {
if ($AllowUnsigned -or $env:TAILCHROME_ALLOW_UNSIGNED_RELEASE -eq '1') {
Expand All @@ -204,7 +211,8 @@ function Test-Authenticode([string]$ArtifactPath) {
return
}
if ($signature.Status -eq 'NotSigned') {
Fail 'Release is unsigned; use -AllowUnsigned only for an explicitly approved unsigned release.'
$notes = if ($Version) { " Review the release notes at https://github.com/$Repository/releases/tag/$Version; if they approve this unsigned release, run the same command again with -AllowUnsigned added at the end." } else { '' }
Fail ('Release is unsigned; use -AllowUnsigned only for an explicitly approved unsigned release.' + $notes)
}
Fail "Windows signature verification failed: $($signature.Status)."
}
Expand Down Expand Up @@ -347,7 +355,7 @@ $releaseBase = "$ReleaseBaseDefault/$Version"
Fail 'SHA-256 checksum verification failed.'
}
Test-AvailableAttestation $artifactPath
Test-Authenticode $artifactPath
Test-Authenticode $artifactPath $Version

$stagePath = Join-Path $targetDirectory ('.tailchrome-stage-' + [guid]::NewGuid().ToString('N') + '.tmp')
Copy-VerifiedStage $artifactPath $stagePath
Expand Down
85 changes: 85 additions & 0 deletions scripts/install.test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ $Installer = Join-Path $Root 'scripts/install.ps1'
. $Installer
$ProductionInvokeInstalledHelper = (Get-Command Invoke-InstalledHelper -CommandType Function).ScriptBlock
$ProductionGetNativeArchitecture = (Get-Command Get-NativeArchitecture -CommandType Function).ScriptBlock
$ProductionTestAvailableAttestation = (Get-Command Test-AvailableAttestation -CommandType Function).ScriptBlock

$TestsRun = 0
$TestsFailed = 0
Expand Down Expand Up @@ -146,6 +147,89 @@ if ($helperSuccess -eq 0 -and $helperFailure -eq 7) {
FailTest 'keeps helper stdout out of Invoke-InstalledHelper exit-code results' ("success=[$helperSuccess] failure=[$helperFailure]")
}

# A real native gh that reports failure on stderr. Under stock Windows
# PowerShell 5.1 with ErrorActionPreference=Stop, redirected stderr used to
# abort the installer before the exit-code check (#151).
$fakeGhDir = Join-Path ([IO.Path]::GetTempPath()) ('tailchrome-fake-gh-' + [guid]::NewGuid().ToString('N'))
New-Item -ItemType Directory -Path $fakeGhDir | Out-Null
if ($WindowsTest) {
@'
@echo off
if "%1"=="auth" (
if "%TAILCHROME_FAKE_GH_MODE%"=="unauthenticated" (
echo You are not logged into any GitHub hosts. 1>&2
exit /b 1
)
exit /b 0
)
if "%3"=="--help" exit /b 0
if "%TAILCHROME_FAKE_GH_MODE%"=="verify-fails" (
echo attestation verification failed 1>&2
exit /b 1
)
exit /b 0
'@ | Set-Content -LiteralPath (Join-Path $fakeGhDir 'gh.cmd')
} else {
@'
#!/bin/sh
if [ "$1" = "auth" ]; then
if [ "$TAILCHROME_FAKE_GH_MODE" = "unauthenticated" ]; then
echo "You are not logged into any GitHub hosts." >&2
exit 1
fi
exit 0
fi
if [ "$3" = "--help" ]; then exit 0; fi
if [ "$TAILCHROME_FAKE_GH_MODE" = "verify-fails" ]; then
echo "attestation verification failed" >&2
exit 1
fi
exit 0
'@ | Set-Content -LiteralPath (Join-Path $fakeGhDir 'gh')
& chmod +x (Join-Path $fakeGhDir 'gh')
}
$savedPath = $env:PATH
$env:PATH = $fakeGhDir + [IO.Path]::PathSeparator + $env:PATH
try {
$env:TAILCHROME_FAKE_GH_MODE = 'unauthenticated'
try {
$probeOutput = (& $ProductionTestAvailableAttestation (Join-Path $fakeGhDir 'artifact') 3>&1 | Out-String)
if ($probeOutput -like '*GitHub CLI is not authenticated*') {
Pass 'warns instead of aborting when gh is installed but not authenticated'
} else {
FailTest 'warns instead of aborting when gh is installed but not authenticated' ("output=[$probeOutput]")
}
} catch {
FailTest 'warns instead of aborting when gh is installed but not authenticated' $_.Exception.Message
}

$env:TAILCHROME_FAKE_GH_MODE = 'verify-fails'
Expect-Failure 'fails closed when gh attestation verification fails' 'GitHub artifact attestation verification failed' {
try {
& $ProductionTestAvailableAttestation (Join-Path $fakeGhDir 'artifact') 3>&1 | Out-Null
return ''
} catch {
return $_.Exception.Message
}
}

$env:TAILCHROME_FAKE_GH_MODE = 'verified'
try {
$probeOutput = (& $ProductionTestAvailableAttestation (Join-Path $fakeGhDir 'artifact') 3>&1 | Out-String)
if (-not $probeOutput.Trim()) {
Pass 'accepts a verified gh attestation silently'
} else {
FailTest 'accepts a verified gh attestation silently' ("output=[$probeOutput]")
}
} catch {
FailTest 'accepts a verified gh attestation silently' $_.Exception.Message
}
} finally {
$env:PATH = $savedPath
Remove-Item Env:\TAILCHROME_FAKE_GH_MODE -ErrorAction SilentlyContinue
Remove-Item -LiteralPath $fakeGhDir -Recurse -Force -ErrorAction SilentlyContinue
}

New-Fixture
$popupBin = Join-Path $script:Fixture "scriptblock bin/owner's helper"
New-Item -ItemType Directory -Path $popupBin -Force | Out-Null
Expand Down Expand Up @@ -249,6 +333,7 @@ $script:SignatureStatus = 'Invalid'
Expect-Failure 'rejects invalid signature with unsigned opt-in' 'signature verification failed' { Invoke-Main -AllowUnsigned }
New-Fixture
Expect-Failure 'rejects unsigned release without opt-in' 'use -AllowUnsigned' { Invoke-Main }
Expect-Failure 'points unsigned-release failures at the pinned release notes' 'releases/tag/v1.2.3; if they approve this unsigned release, run the same command again with -AllowUnsigned' { Invoke-Main }
New-Fixture
$message = Invoke-Main -AllowUnsigned
$destination = Join-Path $env:LOCALAPPDATA 'Tailchrome/tailchrome.exe'
Expand Down
Loading