diff --git a/installer/ArSonMix.iss b/installer/ArSonMix.iss index 4d29b4330..b07b020b6 100644 --- a/installer/ArSonMix.iss +++ b/installer/ArSonMix.iss @@ -63,6 +63,8 @@ Type: files; Name: "{app}\README.md" Source: "{#SourceRoot}\VBCABLE_Driver_Pack45.zip"; DestDir: "{app}\ThirdParty\VB-Audio"; Flags: ignoreversion Source: "{#SourceRoot}\VB-CABLE-NOTICE.txt"; DestDir: "{app}\ThirdParty\VB-Audio"; Flags: ignoreversion Source: "ArSonMixVBCableInstall.ps1"; DestDir: "{app}\ThirdParty\VB-Audio"; Flags: ignoreversion +; Microsoft-signed WebView2 Evergreen prerequisite, no bundled old runtime. +Source: "ArSonMixWebView2Prerequisite.ps1"; DestDir: "{app}"; Flags: ignoreversion ; The shutdown helper is EMBEDDED TEMPORARILY in Setup, never installed. ; It handles installed legacy builds that do not implement the new event. Source: "ArSonMixUpdateShutdown.ps1"; Flags: dontcopy @@ -94,6 +96,9 @@ Name: "{autoprograms}\Start ArSonMix with Recovery Profile"; Filename: "{app}\Ar ; one new executable only after a successful interactive install/update. ; Silent enterprise/FAT installs deliberately do not launch desktop audio. [Run] +; WebView2 is a real GUI prerequisite. Check/install only when missing; +; silent/enterprise/auto-update installs never fetch or alter OS components. +Filename: "{sys}\WindowsPowerShell\v1.0\powershell.exe"; Parameters: "-NoLogo -NoProfile -ExecutionPolicy Bypass -File ""{app}\ArSonMixWebView2Prerequisite.ps1"""; WorkingDir: "{app}"; StatusMsg: "Checking Microsoft WebView2 for ArSonMix..."; Flags: runasoriginaluser skipifsilent waituntilterminated runhidden ; Interactive Setup automatically checks installed and pending VB-CABLE devices. ; Only a missing driver can reach the verified vendor installer and Windows UAC. ; The next entry opens ArSonMix even if the driver needs a restart or is declined. diff --git a/installer/ArSonMixStartupDiagnostics.ps1 b/installer/ArSonMixStartupDiagnostics.ps1 index fc05367f9..d9efb89f8 100644 --- a/installer/ArSonMixStartupDiagnostics.ps1 +++ b/installer/ArSonMixStartupDiagnostics.ps1 @@ -36,6 +36,18 @@ if ($registrations) { } else { $lines += 'WebView2 Evergreen registration absent. Download or repair the Microsoft WebView2 Runtime.' } +$preflight = Join-Path $folder 'webview2-prerequisite.json' +if (Test-Path -LiteralPath $preflight -PathType Leaf) { + try { + $prereqStatus = Get-Content -LiteralPath $preflight -Raw | ConvertFrom-Json -ErrorAction Stop + $lines += "Installer WebView2 prerequisite: $($prereqStatus.state)" + if ($prereqStatus.state -eq 'NEEDS_ATTENTION') { + $lines += "Installer dependency detail: $($prereqStatus.detail)" + } + } catch { + $lines += 'Installer WebView2 prerequisite status unreadable.' + } +} $startupLog = Join-Path $folder 'startup-failure.txt' if (Test-Path -LiteralPath $startupLog -PathType Leaf) { $lines += '' diff --git a/installer/ArSonMixWebView2Prerequisite.ps1 b/installer/ArSonMixWebView2Prerequisite.ps1 new file mode 100644 index 000000000..5df8d0e12 --- /dev/null +++ b/installer/ArSonMixWebView2Prerequisite.ps1 @@ -0,0 +1,135 @@ +# SPDX-License-Identifier: AGPL-3.0-only +# Interactive installer dependency preflight, never a realtime audio callback. +[CmdletBinding()]param([switch]$PolicySelfTest) +Set-StrictMode -Version Latest +$ErrorActionPreference='Stop' +$official='https://go.microsoft.com/fwlink/p/?LinkId=2124703' +$guid='{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}' +function Valid-Version([string]$value) { + if($value -notmatch '^\d+\.\d+\.\d+\.\d+$'){return $false} + try {return ([version]$value) -ge [version]'109.0.0.0'}catch{return $false} +} +function Microsoft-Uri([uri]$uri) { + if($null -eq $uri -or $uri.Scheme -cne 'https'){return $false} + $hostName=$uri.DnsSafeHost.ToLowerInvariant() + return $hostName -eq 'microsoft.com' -or $hostName.EndsWith('.microsoft.com') +} +function Microsoft-Signer($signature) { + if($null -eq $signature -or [string]$signature.Status -cne 'Valid' -or + $null -eq $signature.SignerCertificate){return $false} + return [string]$signature.SignerCertificate.Subject -match '(?i)(^|,\s*)(CN|O)=Microsoft Corporation(,|$)' +} +if($PolicySelfTest) { + $good=[pscustomobject]@{Status='Valid';SignerCertificate=[pscustomobject]@{Subject='CN=Microsoft Corporation, O=Microsoft Corporation'}} + $bad=[pscustomobject]@{Status='NotTrusted';SignerCertificate=[pscustomobject]@{Subject='CN=Microsoft Corporation'}} + if(-not (Valid-Version '120.0.0.1') -or (Valid-Version '0.0.0.0') -or + (Valid-Version 'bogus') -or (Valid-Version '108.0.0.1') -or + -not (Microsoft-Uri ([uri]$official)) -or + (Microsoft-Uri ([uri]'http://go.microsoft.com/setup.exe')) -or + (Microsoft-Uri ([uri]'https://malicious-microsoft.com/setup.exe')) -or + -not (Microsoft-Signer $good) -or (Microsoft-Signer $bad)){ + throw 'ARSONMIX_WEBVIEW2_PREREQUISITE_POLICY_FAIL' + } + Write-Output 'ARSONMIX_WEBVIEW2_PREREQUISITE_POLICY_PASS' + exit 0 +} +$folder=Join-Path $env:LOCALAPPDATA 'ArSonMix\diagnostics' +$report=Join-Path $folder 'webview2-prerequisite.json' +function Record([string]$state,[string]$detail) { + try { + [IO.Directory]::CreateDirectory($folder)|Out-Null + $temp=$report+'.'+[guid]::NewGuid().ToString('N')+'.tmp' + [ordered]@{schema='arsonmix.webview2-prerequisite.v1';state=$state;detail=$detail;utc=[DateTime]::UtcNow.ToString('o')} | + ConvertTo-Json -Compress | Set-Content -LiteralPath $temp -Encoding UTF8 + Move-Item -LiteralPath $temp -Destination $report -Force + }catch{Write-Warning ('Unable to save WebView2 diagnostic: '+$_.Exception.Message)} +} +function Find-EvergreenRuntime { + $keys=@( + "HKLM:\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\$guid", + "HKLM:\SOFTWARE\Microsoft\EdgeUpdate\Clients\$guid", + "HKCU:\SOFTWARE\Microsoft\EdgeUpdate\Clients\$guid", + "HKCU:\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\$guid" + ) + $roots=@( + (Join-Path $env:LOCALAPPDATA 'Microsoft\EdgeWebView\Application'), + (Join-Path ([Environment]::GetFolderPath('ProgramFilesX86')) 'Microsoft\EdgeWebView\Application'), + (Join-Path $env:ProgramFiles 'Microsoft\EdgeWebView\Application') + ) | Select-Object -Unique + foreach($key in $keys){ + try { + $pv=[string](Get-ItemProperty -LiteralPath $key -Name pv -ErrorAction Stop).pv + if(-not (Valid-Version $pv)){continue} + foreach($root in $roots){ + if(Test-Path -LiteralPath (Join-Path (Join-Path $root $pv) 'msedgewebview2.exe') -PathType Leaf){return $pv} + } + }catch{Write-Verbose ('WebView2 registration query: '+$_.Exception.Message)} + } + return '' +} +$work=$null +try { + $os=Get-ItemProperty -LiteralPath 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -ErrorAction Stop + if(-not [Environment]::Is64BitOperatingSystem -or [int]$os.CurrentBuildNumber -lt 17763){ + Record 'UNSUPPORTED_OS' 'ArSonMix requires Windows 10 build 17763+ x64 or Windows 11 x64' + exit 3 + } + $installed=Find-EvergreenRuntime + if($installed){ + Record 'ALREADY_PRESENT' ('WebView2 '+$installed+' is installed; no changes needed') + Write-Output 'ARSONMIX_WEBVIEW2_ALREADY_PRESENT' + exit 0 + } + # Download only when missing. Final HTTPS host and Microsoft Authenticode + # must both validate. No package from third-party mirrors is ever executed. + $work=Join-Path $env:TEMP ('arsonmix-webview2-'+[guid]::NewGuid().ToString('N')) + [IO.Directory]::CreateDirectory($work)|Out-Null + $file=Join-Path $work 'MicrosoftEdgeWebView2Setup.exe' + [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12 + $request=[Net.HttpWebRequest]::Create($official) + $request.AllowAutoRedirect=$true + $request.MaximumAutomaticRedirections=8 + $request.Timeout=20000 + $request.ReadWriteTimeout=20000 + $response=$request.GetResponse() + try { + if(-not (Microsoft-Uri $response.ResponseUri)){throw 'Unapproved Microsoft bootstrapper redirect host'} + $stream=$response.GetResponseStream() + $output=[IO.File]::Open($file,[IO.FileMode]::CreateNew,[IO.FileAccess]::Write) + try { + $bytes=New-Object byte[] 65536 + $total=0 + while(($n=$stream.Read($bytes,0,$bytes.Length)) -gt 0){ + $total+=$n + if($total -gt 16777216){throw 'Oversized WebView2 bootstrapper'} + $output.Write($bytes,0,$n) + } + if($total -lt 32768){throw 'Incomplete WebView2 download'} + }finally{$output.Dispose();$stream.Dispose()} + }finally{$response.Dispose()} + $signature=Get-AuthenticodeSignature -LiteralPath $file -ErrorAction Stop + if(-not (Microsoft-Signer $signature)){throw 'Untrusted WebView2 bootstrapper (not executed)'} + # Official supported Evergreen installer switches; respects Windows policy. + $process=Start-Process -FilePath $file -ArgumentList @('/silent','/install') -Wait -PassThru -ErrorAction Stop + if($process.ExitCode -ne 0){throw ('Microsoft WebView2 setup failed: '+$process.ExitCode)} + $installed='' + for($i=0;$i -lt 5;$i++){ + $installed=Find-EvergreenRuntime + if($installed){break} + Start-Sleep -Seconds 2 + } + if(-not $installed){throw 'WebView2 setup finished but runtime was not detected'} + Record 'INSTALLED' ('WebView2 '+$installed+' verified') + Write-Output 'ARSONMIX_WEBVIEW2_INSTALLED' + exit 0 +}catch{ + # Offline, group-policy, restricted permissions and failed downloads are + # recoverable. Do not loop, claim success, or delete user session data. + Record 'NEEDS_ATTENTION' $_.Exception.Message + Write-Warning ('WebView2 installation incomplete: '+$_.Exception.Message) + exit 2 +}finally{ + if($work -and (Test-Path -LiteralPath $work)){ + Remove-Item -LiteralPath $work -Recurse -Force -ErrorAction SilentlyContinue + } +} diff --git a/scripts/test_inno_graceful_update_windows.ps1 b/scripts/test_inno_graceful_update_windows.ps1 index 1fbb99eee..f9898df1f 100644 --- a/scripts/test_inno_graceful_update_windows.ps1 +++ b/scripts/test_inno_graceful_update_windows.ps1 @@ -16,6 +16,14 @@ if($LASTEXITCODE -ne 0 -or $policyOutput -notcontains 'ARSONMIX_UPDATER_POLICY_P } Write-Host "ARSONMIX_UPDATER_POLICY_PASS" +# Check the exact shipped WebView2 helper in a pure non-network policy mode. +$webviewPolicy=Join-Path (Resolve-Path .).Path "installer/ArSonMixWebView2Prerequisite.ps1" +$webviewOutput=& "$env:WINDIR\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -File $webviewPolicy -PolicySelfTest +if($LASTEXITCODE -ne 0 -or $webviewOutput -notcontains 'ARSONMIX_WEBVIEW2_PREREQUISITE_POLICY_PASS') { + throw "WebView2 secure bootstrapper policy failed: $webviewOutput" +} +Write-Host "ARSONMIX_WEBVIEW2_PREREQUISITE_POLICY_PASS" + $ErrorActionPreference="Stop" $root=(Resolve-Path .).Path $work=Join-Path $env:RUNNER_TEMP ("arsonmix-inno-smoke-"+[guid]::NewGuid().ToString("N")) diff --git a/tests/windows_installer_contract_test.mjs b/tests/windows_installer_contract_test.mjs index 721fa469d..8572bef68 100644 --- a/tests/windows_installer_contract_test.mjs +++ b/tests/windows_installer_contract_test.mjs @@ -47,10 +47,12 @@ test('interactive Setup automatically checks for signed VB-CABLE while mixer lau assert.match(iss, /VBCABLE_Driver_Pack45\.zip/); const run = iss.slice(iss.indexOf('[Run]'), iss.indexOf('[Code]')); const entries = run.split('\n').filter(line => line.startsWith('Filename:')); - assert.equal(entries.length, 2); - assert.match(entries[0], /ArSonMixVBCableInstall\.ps1/); + assert.equal(entries.length, 3); + assert.match(entries[0], /ArSonMixWebView2Prerequisite\.ps1/); assert.match(entries[0], /Flags: runasoriginaluser skipifsilent waituntilterminated runhidden/); - assert.match(entries[1], /^Filename: "\{app\}\\ArSonMix\.exe"/); + assert.match(entries[1], /ArSonMixVBCableInstall\.ps1/); + assert.match(entries[1], /Flags: runasoriginaluser skipifsilent waituntilterminated runhidden/); + assert.match(entries[2], /^Filename: "\{app\}\\ArSonMix\.exe"/); for (const entry of entries) assert.doesNotMatch(entry, /;\s*(Check|Tasks):/i); assert.match(iss, /^RestartIfNeededByRun=no$/m); assert.doesNotMatch(iss + bootstrap, /VBCableRestart|RestartMarker|CanLaunchMixer|function NeedRestart/); @@ -104,6 +106,24 @@ test('interactive Setup automatically checks for signed VB-CABLE while mixer lau assert.match(iss, /Flags: runasoriginaluser skipifsilent waituntilterminated/); }); +test('WebView2 GUI prerequisite runs only on interactive setup from Microsoft-signed bootstrapper', () => { + const helper=read('installer/ArSonMixWebView2Prerequisite.ps1'); + assert.match(iss, /Source: "ArSonMixWebView2Prerequisite\.ps1"; DestDir: "\{app\}"/); + assert.match(helper, /ARSONMIX_WEBVIEW2_PREREQUISITE_POLICY_PASS/); + assert.match(helper, /go\.microsoft\.com\/fwlink\/p\/\?LinkId=2124703/); + assert.match(helper, /Get-AuthenticodeSignature/); + assert.match(helper, /Microsoft-Signer/); + assert.match(helper, /Microsoft-Uri \$response\.ResponseUri/); + assert.match(helper, /-ArgumentList @\('\/silent','\/install'\)/); + assert.match(helper, /ARSONMIX_WEBVIEW2_ALREADY_PRESENT/); + assert.match(helper, /ARSONMIX_WEBVIEW2_INSTALLED/); + assert.match(helper, /NEEDS_ATTENTION/); + assert.ok(helper.indexOf('if($installed)') < helper.indexOf('$request.GetResponse()')); + assert.ok(helper.indexOf('Get-AuthenticodeSignature') < helper.indexOf('Start-Process -FilePath $file')); + assert.doesNotMatch(helper, /vcredist|vc_redist|TrustedPublisher|SetDefaultEndpoint|--safe-webview-profile/i); + assert.match(read('scripts/test_inno_graceful_update_windows.ps1'), /ARSONMIX_WEBVIEW2_PREREQUISITE_POLICY_PASS/); +}); + test('single installer preflight requests graceful shutdown; Restart Manager cannot force old mixer', () => { assert.match(iss, /^CloseApplications=no$/m); assert.doesNotMatch(iss, /^CloseApplicationsFilter=/m);