Skip to content
Open
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
56 changes: 49 additions & 7 deletions lanes/dev1/repair_overlay/packaging/build_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,13 @@ Assert-NativeSuccess "packaged payload manifest generation"

$Sep = ";"
$Name = "ScriptureArchive-R06-DEV01"
$UpdaterName = "$Name-Updater"
$Out = Join-Path $Dist "$Name.exe"
if (Test-Path -LiteralPath $Out) {
Remove-Item -LiteralPath $Out -Force
$UpdaterOut = Join-Path $Dist "$UpdaterName.exe"
foreach ($artifact in @($Out, $UpdaterOut)) {
if (Test-Path -LiteralPath $artifact) {
Remove-Item -LiteralPath $artifact -Force
}
}
try {
& (Join-Path $Venv "Scripts\pyinstaller.exe") --noconfirm --clean --onefile --windowed `
Expand All @@ -98,14 +102,24 @@ try {
--paths $PlatformRoot --paths $Repo `
--distpath $Dist --workpath $Work --specpath $Spec `
(Join-Path $PlatformRoot "run_windows.py")
Assert-NativeSuccess "PyInstaller build"
Assert-NativeSuccess "PyInstaller application build"

& (Join-Path $Venv "Scripts\pyinstaller.exe") --noconfirm --clean --onefile --windowed `
--name $UpdaterName `
--paths $PlatformRoot --paths $Repo `
--distpath $Dist --workpath $Work --specpath $Spec `
(Join-Path $PlatformRoot "scripture_archive_platform\desktop_host\updater_main.py")
Assert-NativeSuccess "PyInstaller updater build"
} finally {
Remove-Item -LiteralPath $BuildIdentityDir -Recurse -Force -ErrorAction SilentlyContinue
}

if (-not (Test-Path -LiteralPath $Out -PathType Leaf)) {
throw "Expected executable not produced: $Out"
}
if (-not (Test-Path -LiteralPath $UpdaterOut -PathType Leaf)) {
throw "Expected updater executable not produced: $UpdaterOut"
}

$PayloadReadback = Join-Path $Dist "packaged_payload_fidelity.json"
& $Python $FidelityTool verify `
Expand All @@ -116,6 +130,8 @@ Assert-NativeSuccess "embedded packaged payload fidelity verification"

$hash = (Get-FileHash -Algorithm SHA256 $Out).Hash.ToLowerInvariant()
$size = (Get-Item $Out).Length
$updaterHash = (Get-FileHash -Algorithm SHA256 $UpdaterOut).Hash.ToLowerInvariant()
$updaterSize = (Get-Item $UpdaterOut).Length
$payloadEvidenceHash = (Get-FileHash -Algorithm SHA256 $PayloadReadback).Hash.ToLowerInvariant()
$pythonVersion = (& $Python --version 2>&1 | Out-String).Trim()
Assert-NativeSuccess "Python version query"
Expand All @@ -126,6 +142,10 @@ $manifest = [ordered]@{
artifact_path = $Out
size_bytes = $size
sha256 = $hash
updater_artifact_name = (Split-Path -Leaf $UpdaterOut)
updater_artifact_path = $UpdaterOut
updater_size_bytes = $updaterSize
updater_sha256 = $updaterHash
built_utc = (Get-Date).ToUniversalTime().ToString("o")
git_sha = $actualGitSha
github_event_sha = $env:GITHUB_SHA
Expand All @@ -137,31 +157,53 @@ $manifest = [ordered]@{
packaged_payload_fidelity_file = (Split-Path -Leaf $PayloadReadback)
packaged_payload_fidelity_sha256 = $payloadEvidenceHash
proof_scope = @(
"PyInstaller build completed",
"artifact size/hash readback verified",
"PyInstaller application and standalone updater builds completed",
"application and updater artifact size/hash readback verified",
"embedded frontend/campaign/build-identity bytes verified against exact staged manifest",
"Git-tracked embedded frontend overlay/campaign bytes verified against exact checkout Git blob IDs",
"WebView2 runtime presence probed before build",
"packaged diagnostics build identity bound to exact checkout SHA"
)
not_proven = @(
"production Authenticode signing identity is configured",
"Python module bytecode identity inside PYZ",
"human NVDA acceptance",
"full application functional acceptance",
"visual correctness",
"recovery execution"
"post-restart health commit"
)
}
$ManifestPath = Join-Path $Dist "build_manifest.json"
$manifest | ConvertTo-Json -Depth 6 | Set-Content -Encoding utf8 $ManifestPath

"SHA256=$hash" | Set-Content -Encoding utf8 (Join-Path $Dist "$Name.sha256.txt")
"SIZE=$size" | Add-Content -Encoding utf8 (Join-Path $Dist "$Name.sha256.txt")
"SHA256=$updaterHash" | Set-Content -Encoding utf8 (Join-Path $Dist "$UpdaterName.sha256.txt")
"SIZE=$updaterSize" | Add-Content -Encoding utf8 (Join-Path $Dist "$UpdaterName.sha256.txt")

& $Python (Join-Path $PSScriptRoot "windows_release.py") verify-artifact `
--artifact $Out `
--manifest $ManifestPath `
--output (Join-Path $Dist "artifact_readback.json")
Assert-NativeSuccess "artifact verification"
Assert-NativeSuccess "application artifact verification"

$UpdaterManifestPath = Join-Path $Dist "updater_build_manifest.json"
$updaterManifest = [ordered]@{
schema_version = 1
artifact_name = (Split-Path -Leaf $UpdaterOut)
artifact_path = $UpdaterOut
size_bytes = $updaterSize
sha256 = $updaterHash
git_sha = $actualGitSha
application_version_authority = "scripture_archive_platform.desktop_host.version.CURRENT_APPLICATION_VERSION"
authenticode_authority = "scripture_archive_platform.desktop_host.authenticode.verify_same_publisher_authenticode"
}
$updaterManifest | ConvertTo-Json -Depth 4 | Set-Content -Encoding utf8 $UpdaterManifestPath
& $Python (Join-Path $PSScriptRoot "windows_release.py") verify-artifact `
--artifact $UpdaterOut `
--manifest $UpdaterManifestPath `
--output (Join-Path $Dist "updater_artifact_readback.json")
Assert-NativeSuccess "updater artifact verification"

Write-Output "Built $Out ($size bytes) SHA256=$hash"
Write-Output "Built $UpdaterOut ($updaterSize bytes) SHA256=$updaterHash"
55 changes: 50 additions & 5 deletions lanes/dev1/repair_overlay/packaging/run_windows_release_gate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ $OverlayTests = Join-Path $Repo "lanes\dev1\repair_overlay\tests"
$Dist = Join-Path $PlatformRoot "dist"
$Name = "ScriptureArchive-R06-DEV01"
$Exe = Join-Path $Dist "$Name.exe"
$UpdaterExe = Join-Path $Dist "$Name-Updater.exe"
$BuildManifest = Join-Path $Dist "build_manifest.json"
$UpdaterBuildManifest = Join-Path $Dist "updater_build_manifest.json"
$Diagnostics = Join-Path $Dist "windows_release_diagnostics.json"
$WebView2Probe = Join-Path $Dist "webview2_host_probe.json"
$StartupProbe = Join-Path $Dist "packaged_startup_probe.json"
$ArtifactReadback = Join-Path $Dist "artifact_readback.json"
$UpdaterArtifactReadback = Join-Path $Dist "updater_artifact_readback.json"
if (-not $OutputJson) { $OutputJson = Join-Path $Dist "release_gate.json" }

$result = [ordered]@{
Expand All @@ -31,15 +35,21 @@ $result = [ordered]@{
tools_smoke = $false
build = $false
artifact_readback = $false
updater_artifact_readback = $false
webview2_detected = $false
webview2_host_probe = $false
process_liveness = $false
per_user_state_writable = $false
running_without_admin = $false
artifact_sha256 = $null
artifact_size_bytes = $null
updater_artifact_sha256 = $null
updater_artifact_size_bytes = $null
status = "RUNNING"
not_proven = @(
"production Authenticode signing identity/private key",
"host launch/shutdown handoff to standalone updater",
"post-restart health commit/rollback cleanup",
"human NVDA acceptance",
"complete functional WebView UI acceptance",
"packaged application's own WebView2 content-ready signal",
Expand Down Expand Up @@ -105,19 +115,54 @@ try {
}

& (Join-Path $PSScriptRoot "build_windows.ps1")
if (-not (Test-Path $Exe) -or -not (Test-Path $BuildManifest) -or -not (Test-Path $Diagnostics)) {
throw "Build did not produce the complete expected evidence set"
if (
-not (Test-Path -LiteralPath $Exe -PathType Leaf) -or
-not (Test-Path -LiteralPath $UpdaterExe -PathType Leaf) -or
-not (Test-Path -LiteralPath $BuildManifest -PathType Leaf) -or
-not (Test-Path -LiteralPath $UpdaterBuildManifest -PathType Leaf) -or
-not (Test-Path -LiteralPath $ArtifactReadback -PathType Leaf) -or
-not (Test-Path -LiteralPath $UpdaterArtifactReadback -PathType Leaf) -or
-not (Test-Path -LiteralPath $Diagnostics -PathType Leaf)
) {
throw "Build did not produce the complete application + updater evidence set"
}
$result.build = $true

$build = Get-Content -Raw -Encoding utf8 $BuildManifest | ConvertFrom-Json
$updaterBuild = Get-Content -Raw -Encoding utf8 $UpdaterBuildManifest | ConvertFrom-Json
$diag = Get-Content -Raw -Encoding utf8 $Diagnostics | ConvertFrom-Json
$readbackPath = Join-Path $Dist "artifact_readback.json"
$readback = Get-Content -Raw -Encoding utf8 $readbackPath | ConvertFrom-Json
if (-not $readback.ok) { throw "Artifact hash/size readback did not pass" }
$readback = Get-Content -Raw -Encoding utf8 $ArtifactReadback | ConvertFrom-Json
$updaterReadback = Get-Content -Raw -Encoding utf8 $UpdaterArtifactReadback | ConvertFrom-Json
if (-not $readback.ok) { throw "Application artifact hash/size readback did not pass" }
if (-not $updaterReadback.ok) { throw "Updater artifact hash/size readback did not pass" }

$actualUpdaterHash = (Get-FileHash -LiteralPath $UpdaterExe -Algorithm SHA256).Hash.ToLowerInvariant()
$actualUpdaterSize = (Get-Item -LiteralPath $UpdaterExe).Length
if ($build.updater_artifact_name -ne (Split-Path -Leaf $UpdaterExe)) {
throw "Main build manifest updater artifact name does not match packaged updater"
}
if ([string]$build.updater_sha256 -ne [string]$updaterBuild.sha256) {
throw "Updater SHA differs between build manifests"
}
if ([long]$build.updater_size_bytes -ne [long]$updaterBuild.size_bytes) {
throw "Updater size differs between build manifests"
}
if ([string]$updaterBuild.sha256 -ne $actualUpdaterHash) {
throw "Updater SHA manifest does not match exact packaged updater bytes"
}
if ([long]$updaterBuild.size_bytes -ne [long]$actualUpdaterSize) {
throw "Updater size manifest does not match exact packaged updater bytes"
}
if ([string]$updaterReadback.actual_sha256 -ne $actualUpdaterHash -or [long]$updaterReadback.actual_size_bytes -ne [long]$actualUpdaterSize) {
throw "Updater artifact readback evidence is detached from exact packaged updater bytes"
}

$result.artifact_readback = $true
$result.updater_artifact_readback = $true
$result.artifact_sha256 = $build.sha256
$result.artifact_size_bytes = $build.size_bytes
$result.updater_artifact_sha256 = $actualUpdaterHash
$result.updater_artifact_size_bytes = $actualUpdaterSize
$result.webview2_detected = @($diag.webview2_candidates).Count -gt 0
$result.per_user_state_writable = [bool]$diag.state_write_probe.writable
$result.running_without_admin = ($diag.is_admin -eq $false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
NativeApplicationUpdateLayer,
NativeUpdateFileSelector,
)

# Semantic compatibility version for the current R06-3DEV-A packaged lineage.
# It is deliberately host-owned rather than supplied by an update manifest/web payload.
CURRENT_APPLICATION_VERSION = "0.6.0-r06.3dev.a"
from scripture_archive_platform.desktop_host.version import CURRENT_APPLICATION_VERSION


def _runtime_root() -> Path:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from __future__ import annotations

from collections.abc import Callable, Sequence
import sys
from typing import Any

from scripture_archive_platform.desktop_host.authenticode import (
verify_same_publisher_authenticode,
)
from scripture_archive_platform.desktop_host.version import CURRENT_APPLICATION_VERSION
from runtime_engine.scripture_archive_runtime.application_update_runner import (
execute_trusted_updater,
)


UPDATER_OK = 0
UPDATER_FAILED = 2


def run_updater(
argv: Sequence[str],
*,
execute: Callable[..., Any] = execute_trusted_updater,
verifier: Callable[..., bool] = verify_same_publisher_authenticode,
) -> int:
"""Run one fixed updater command with packaged trust authorities.

The semantic current version and Authenticode verifier are imported from the
packaged native host. No browser/web payload can select either authority. Error
details are intentionally not echoed because argv contains local filesystem paths.
"""

if not callable(execute) or not callable(verifier):
return UPDATER_FAILED
try:
execute(
tuple(argv),
current_version=CURRENT_APPLICATION_VERSION,
verify_same_publisher=verifier,
)
except Exception:
return UPDATER_FAILED
return UPDATER_OK


def main() -> int:
return run_updater(sys.argv[1:])


if __name__ == "__main__":
raise SystemExit(main())
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from __future__ import annotations

# Semantic compatibility version for the current R06-3DEV-A packaged lineage.
# This is host-owned release identity. Update manifests/browser payloads must never
# select or override it.
CURRENT_APPLICATION_VERSION = "0.6.0-r06.3dev.a"
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from __future__ import annotations

import unittest

from scripture_archive_platform.desktop_host.authenticode import (
verify_same_publisher_authenticode,
)
from scripture_archive_platform.desktop_host.updater_main import (
UPDATER_FAILED,
UPDATER_OK,
run_updater,
)
from scripture_archive_platform.desktop_host.version import CURRENT_APPLICATION_VERSION


class PackagedUpdaterEntrypointTests(unittest.TestCase):
def test_forwards_fixed_argv_with_host_owned_version_and_canonical_authenticode(self) -> None:
calls: list[tuple[tuple[str, ...], dict[str, object]]] = []

def execute(argv, **kwargs):
calls.append((tuple(argv), dict(kwargs)))
return object()

argv = (
"--scripture-archive-apply",
"--wait-pid",
"41",
"--installed-executable",
r"C:\Program Files\Scripture Archive\ScriptureArchive-R06-DEV01.exe",
"--staging-root",
r"C:\Users\user\AppData\Local\ScriptureArchive\application-updates",
)
result = run_updater(argv, execute=execute)

self.assertEqual(result, UPDATER_OK)
self.assertEqual(len(calls), 1)
forwarded, kwargs = calls[0]
self.assertEqual(forwarded, argv)
self.assertEqual(kwargs["current_version"], CURRENT_APPLICATION_VERSION)
self.assertIs(kwargs["verify_same_publisher"], verify_same_publisher_authenticode)

def test_failure_is_fail_closed_without_retrying_or_rewriting_argv(self) -> None:
calls = 0

def execute(argv, **kwargs):
nonlocal calls
calls += 1
raise ValueError("local path detail must not escape through entrypoint")

self.assertEqual(run_updater(("bad",), execute=execute), UPDATER_FAILED)
self.assertEqual(calls, 1)

def test_requires_callable_execution_and_verifier_authorities(self) -> None:
self.assertEqual(run_updater((), execute=None), UPDATER_FAILED) # type: ignore[arg-type]
self.assertEqual(run_updater((), verifier=None), UPDATER_FAILED) # type: ignore[arg-type]


if __name__ == "__main__":
unittest.main()
Loading