Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
ee299c0
R06: carry host current version in updater process handoff
Oleksii-debug Sep 30, 2026
eda092c
R06: bind updater runner version to fixed host handoff
Oleksii-debug Sep 30, 2026
0130964
R06: pass packaged host version to updater plan
Oleksii-debug Sep 30, 2026
5acf1e5
R06: bind updater launch to running host version
Oleksii-debug Sep 30, 2026
e5788e3
R06: use running host version in updater entrypoint
Oleksii-debug Sep 30, 2026
0e6d1df
R06: regress fixed updater current-version process contract
Oleksii-debug Sep 30, 2026
21bde90
R06: regress updater runner version-handoff consistency
Oleksii-debug Sep 30, 2026
6cd04e8
R06: regress packaged host-owned updater version handoff
Oleksii-debug Sep 30, 2026
1c0c1fe
R06: prove updater survives main-app version advancement
Oleksii-debug Sep 30, 2026
e73d678
R06: correct updater build version-authority evidence
Oleksii-debug Sep 30, 2026
ef20242
R06: reconverge updater version handoff onto current composition
Oleksii-debug Sep 30, 2026
7e1ac3b
R06: complete updater process-plan regression call sites
Oleksii-debug Sep 30, 2026
0d6626c
R06: supply host version in negative updater-launch regressions
Oleksii-debug Sep 30, 2026
e447e26
R06: reconcile host version handoff with launch-authority hardening
Oleksii-debug Sep 30, 2026
24b80ce
R06: regress version authority across hardened updater launch
Oleksii-debug Sep 30, 2026
5804dad
R06: converge version handoff with current launch hardening
Oleksii-debug Sep 30, 2026
767c1da
R06: complete hardened updater launch version call sites
Oleksii-debug Sep 30, 2026
4554ac6
R06: regress browser cannot inject updater version authority
Oleksii-debug Sep 30, 2026
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
2 changes: 1 addition & 1 deletion lanes/dev1/repair_overlay/packaging/build_windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ $updaterManifest = [ordered]@{
size_bytes = $updaterSize
sha256 = $updaterHash
git_sha = $actualGitSha
application_version_authority = "scripture_archive_platform.desktop_host.version.CURRENT_APPLICATION_VERSION"
application_version_authority = "host-owned UpdaterProcessPlan.current_version + runner exact-handoff equality"
authenticode_authority = "scripture_archive_platform.desktop_host.authenticode.verify_same_publisher_authenticode"
}
$updaterManifest | ConvertTo-Json -Depth 4 | Set-Content -Encoding utf8 $UpdaterManifestPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,10 @@ def main() -> int:
)
selector.bind_window(window)
pending_layer.bind_apply_execution(
lambda: launch_packaged_updater(staging_root),
lambda: launch_packaged_updater(
staging_root,
current_version=CURRENT_APPLICATION_VERSION,
),
window.destroy,
)
logging.info("Starting EdgeChromium WebView; frontend=%s log=%s", front, log_path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ def packaged_updater_path(installed_executable: Path) -> Path:
def launch_packaged_updater(
staging_root: str | os.PathLike[str],
*,
current_version: str,
current_executable: str | os.PathLike[str] | None = None,
verify_same_publisher: PublisherVerifier = verify_same_publisher_authenticode,
build_plan: PlanBuilder = build_updater_process_plan,
launch_process: ProcessLauncher = launch_updater_process,
) -> int:
"""Verify and launch only the canonical same-publisher sibling updater.

The browser supplies none of these values. The installed executable defaults to
The browser supplies none of these values, including ``current_version``. The installed executable defaults to
the currently running packaged process, the updater path is mechanically derived
beside it, and the existing Authenticode authority must positively prove that
current host and updater share a valid signer before #245's fixed process plan is
Expand Down Expand Up @@ -68,6 +69,7 @@ def launch_packaged_updater(
updater_executable=updater,
installed_executable=installed,
staging_root=requested_staging,
current_version=current_version,
)
if not isinstance(plan, UpdaterProcessPlan):
raise UpdateProcessError("updater process-plan builder returned an invalid plan")
Expand All @@ -81,6 +83,7 @@ def launch_packaged_updater(
plan.updater_executable != expected_updater
or plan.installed_executable != expected_installed
or plan.staging_root != expected_staging
or plan.current_version != current_version
):
raise UpdateProcessError("updater process plan changed host-owned launch authority")
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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_process import (
parse_trusted_updater_argv,
)
Expand All @@ -27,10 +26,10 @@ def _resolve_packaged_installed_sibling(
argv: Sequence[str],
*,
updater_executable: Path,
) -> tuple[Path, Path]:
) -> tuple[Path, Path, str]:
"""Bind direct invocation to the exact app sibling of this updater executable."""

_, installed_argument, _ = parse_trusted_updater_argv(tuple(argv))
_, installed_argument, _, current_version = parse_trusted_updater_argv(tuple(argv))
updater = Path(updater_executable)
updater_meta = updater.lstat()
if stat.S_ISLNK(updater_meta.st_mode) or not stat.S_ISREG(updater_meta.st_mode):
Expand All @@ -47,7 +46,7 @@ def _resolve_packaged_installed_sibling(
installed = installed_argument.resolve(strict=True)
if installed != expected_installed:
raise ValueError("installed application is not the canonical updater sibling")
return installed, updater
return installed, updater, current_version


def run_updater(
Expand All @@ -62,21 +61,23 @@ def run_updater(
Direct invocation is bound to the exact application sibling mechanically derived
from this updater's own executable identity. That installed app and this updater
must also share a valid publisher before the runner can consume any apply handoff.
The runner independently verifies installed app versus staged candidate again.
The running host carries its current semantic version in the fixed process handoff,
so an older same-publisher sibling updater remains usable after the app executable updates.
The runner independently revalidates that handoff version and the staged candidate.
"""

if not callable(execute) or not callable(verifier):
return UPDATER_FAILED
try:
installed, updater = _resolve_packaged_installed_sibling(
installed, updater, current_version = _resolve_packaged_installed_sibling(
tuple(argv),
updater_executable=Path(sys.executable if updater_executable is None else updater_executable),
)
if not verifier(installed, updater):
return UPDATER_FAILED
execute(
tuple(argv),
current_version=CURRENT_APPLICATION_VERSION,
current_version=current_version,
verify_same_publisher=verifier,
)
except Exception:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
UPDATER_OK,
run_updater,
)
from scripture_archive_platform.desktop_host.version import CURRENT_APPLICATION_VERSION
HOST_CURRENT_VERSION = "0.6.2"


class PackagedUpdaterEntrypointTests(unittest.TestCase):
Expand All @@ -28,11 +28,13 @@ def setUp(self) -> None:
def tearDown(self) -> None:
self.temp.cleanup()

def argv(self, installed: Path | None = None) -> tuple[str, ...]:
def argv(self, installed: Path | None = None, current_version: str = HOST_CURRENT_VERSION) -> tuple[str, ...]:
return (
"--scripture-archive-apply",
"--wait-pid",
"41",
"--current-version",
current_version,
"--installed-executable",
str(self.installed if installed is None else installed),
"--staging-root",
Expand Down Expand Up @@ -64,9 +66,33 @@ def verifier(installed: Path, updater: Path) -> bool:
self.assertEqual(len(execute_calls), 1)
forwarded, kwargs = execute_calls[0]
self.assertEqual(forwarded, argv)
self.assertEqual(kwargs["current_version"], CURRENT_APPLICATION_VERSION)
self.assertEqual(kwargs["current_version"], HOST_CURRENT_VERSION)
self.assertIs(kwargs["verify_same_publisher"], verifier)

def test_entrypoint_forwards_newer_running_host_version_without_embedded_version_authority(self) -> None:
calls = []
result = run_updater(
self.argv(current_version="0.7.0"),
execute=lambda argv, **kwargs: calls.append((tuple(argv), kwargs)),
verifier=lambda installed, updater: True,
updater_executable=self.updater,
)
self.assertEqual(result, UPDATER_OK)
self.assertEqual("0.7.0", calls[0][1]["current_version"])

def test_invalid_handoff_version_fails_before_verifier_or_executor(self) -> None:
verified = []
executed = []
result = run_updater(
self.argv(current_version="0.7"),
execute=lambda *args, **kwargs: executed.append((args, kwargs)),
verifier=lambda *args: verified.append(args) or True,
updater_executable=self.updater,
)
self.assertEqual(result, UPDATER_FAILED)
self.assertEqual([], verified)
self.assertEqual([], executed)

def test_existing_noncanonical_installed_target_never_reaches_verifier_or_executor(self) -> None:
other = self.install / "Other.exe"
other.write_bytes(b"other")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def build_plan(**kwargs):
updater_executable=kwargs["updater_executable"].resolve(strict=True),
installed_executable=kwargs["installed_executable"].resolve(strict=True),
staging_root=kwargs["staging_root"].resolve(strict=True),
current_version=kwargs["current_version"],
parent_pid=41,
)

Expand All @@ -91,6 +92,7 @@ def launch(plan):

pid = launch_packaged_updater(
self.staging,
current_version=CURRENT_VERSION,
current_executable=self.current,
verify_same_publisher=verify,
build_plan=build_plan,
Expand All @@ -102,6 +104,7 @@ def launch(plan):
self.assertEqual(self.updater, events[1][1]["updater_executable"])
self.assertEqual(self.current, events[1][1]["installed_executable"])
self.assertEqual(self.staging, events[1][1]["staging_root"])
self.assertEqual(CURRENT_VERSION, events[1][1]["current_version"])
self.assertEqual(("verify", self.current.resolve(), self.updater.resolve()), events[2])
self.assertEqual("launch", events[3][0])

Expand All @@ -115,12 +118,37 @@ def substituted_plan(**kwargs):
updater_executable=external,
installed_executable=kwargs["installed_executable"].resolve(),
staging_root=kwargs["staging_root"].resolve(),
current_version=kwargs["current_version"],
parent_pid=41,
)

with self.assertRaisesRegex(UpdateProcessError, "changed host-owned launch authority"):
launch_packaged_updater(
self.staging,
current_version=CURRENT_VERSION,
current_executable=self.current,
verify_same_publisher=lambda _current, _updater: True,
build_plan=substituted_plan,
launch_process=lambda plan: launched.append(plan) or 1,
)
self.assertEqual([], launched)

def test_process_plan_cannot_substitute_host_owned_current_version(self):
launched = []

def substituted_plan(**kwargs):
return UpdaterProcessPlan(
updater_executable=kwargs["updater_executable"].resolve(),
installed_executable=kwargs["installed_executable"].resolve(),
staging_root=kwargs["staging_root"].resolve(),
current_version="9.9.9",
parent_pid=41,
)

with self.assertRaisesRegex(UpdateProcessError, "changed host-owned launch authority"):
launch_packaged_updater(
self.staging,
current_version=CURRENT_VERSION,
current_executable=self.current,
verify_same_publisher=lambda _current, _updater: True,
build_plan=substituted_plan,
Expand All @@ -140,6 +168,7 @@ def verify(current, updater):
with self.assertRaisesRegex(UpdateProcessError, "changed before launch"):
launch_packaged_updater(
self.staging,
current_version=CURRENT_VERSION,
current_executable=self.current,
verify_same_publisher=verify,
launch_process=lambda plan: launched.append(plan) or 1,
Expand All @@ -156,6 +185,7 @@ def test_negative_or_failed_publisher_proof_never_builds_process_plan(self):
with self.subTest(verifier=verifier), self.assertRaises(UpdateProcessError):
launch_packaged_updater(
self.staging,
current_version=CURRENT_VERSION,
current_executable=self.current,
verify_same_publisher=verifier,
build_plan=lambda **kwargs: built.append(kwargs),
Expand Down Expand Up @@ -251,7 +281,7 @@ def test_browser_payload_cannot_supply_process_or_path_authority(self):
response = layer.handle(
request(
APPLY_AND_RESTART_COMMAND,
{"pid": 1, "updater": r"C:\attacker.exe"},
{"pid": 1, "updater": r"C:\attacker.exe", "current_version": "0.0.0"},
)
)
self.assertFalse(response["ok"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import subprocess
from typing import Callable, Sequence

from .application_update import ApplicationUpdateError, SemVer


class UpdateProcessError(RuntimeError):
"""Fail-closed updater process orchestration error."""
Expand All @@ -24,6 +26,7 @@ class UpdaterProcessPlan:
updater_executable: Path
installed_executable: Path
staging_root: Path
current_version: str
parent_pid: int

def argv(self) -> tuple[str, ...]:
Expand All @@ -32,6 +35,8 @@ def argv(self) -> tuple[str, ...]:
"--scripture-archive-apply",
"--wait-pid",
str(self.parent_pid),
"--current-version",
self.current_version,
"--installed-executable",
str(self.installed_executable),
"--staging-root",
Expand Down Expand Up @@ -76,6 +81,7 @@ def build_updater_process_plan(
updater_executable: Path,
installed_executable: Path,
staging_root: Path,
current_version: str,
parent_pid: int | None = None,
) -> UpdaterProcessPlan:
"""Build a fixed host-side process handoff.
Expand All @@ -91,6 +97,10 @@ def build_updater_process_plan(
updater = _require_plain_file(Path(updater_executable), label="updater executable")
installed = _require_plain_file(Path(installed_executable), label="installed executable")
staging = _require_plain_directory(Path(staging_root), label="staging root")
try:
SemVer.parse(current_version)
except ApplicationUpdateError as exc:
raise UpdateProcessError("current version must be valid semantic version") from exc

if updater.parent != installed.parent:
raise UpdateProcessError("updater executable must be packaged beside the installed application")
Expand All @@ -110,6 +120,7 @@ def build_updater_process_plan(
updater_executable=updater,
installed_executable=installed,
staging_root=staging,
current_version=current_version,
parent_pid=effective_parent_pid,
)

Expand Down Expand Up @@ -155,23 +166,38 @@ def launch_updater_process(
return pid


def parse_trusted_updater_argv(argv: Sequence[str]) -> tuple[int, Path, Path]:
"""Parse only the fixed updater command generated by ``UpdaterProcessPlan``.
def parse_trusted_updater_argv(argv: Sequence[str]) -> tuple[int, Path, Path, str]:
"""Parse only the fixed updater command generated by UpdaterProcessPlan.

This is intentionally not a general CLI parser. Exact positional shape,
marker and flag order are part of the host/updater contract; extra flags or
duplicated options fail closed. The updater must subsequently apply the
same filesystem validation and durable-authority verification as its core.
Exact positional shape, marker and flag order are part of the host/updater
contract. The current version is supplied only by the running packaged host;
extra flags, duplicate options, and malformed semantic versions fail closed.
"""

values = tuple(argv)
if len(values) != 7:
if len(values) != 9:
raise UpdateProcessError("invalid updater command shape")
marker, wait_flag, wait_value, installed_flag, installed_value, staging_flag, staging_value = values
(
marker,
wait_flag,
wait_value,
version_flag,
current_version,
installed_flag,
installed_value,
staging_flag,
staging_value,
) = values
if marker != "--scripture-archive-apply":
raise UpdateProcessError("invalid updater command marker")
if wait_flag != "--wait-pid":
raise UpdateProcessError("invalid updater wait flag")
if version_flag != "--current-version":
raise UpdateProcessError("invalid updater current-version flag")
try:
SemVer.parse(current_version)
except ApplicationUpdateError as exc:
raise UpdateProcessError("invalid updater current version") from exc
if installed_flag != "--installed-executable":
raise UpdateProcessError("invalid installed executable flag")
if staging_flag != "--staging-root":
Expand All @@ -186,4 +212,4 @@ def parse_trusted_updater_argv(argv: Sequence[str]) -> tuple[int, Path, Path]:
raise UpdateProcessError("invalid installed executable path")
if not staging_value or "\x00" in staging_value:
raise UpdateProcessError("invalid staging root path")
return parent_pid, Path(installed_value), Path(staging_value)
return parent_pid, Path(installed_value), Path(staging_value), current_version
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ def execute_trusted_updater(
if not callable(dependency):
raise ApplicationUpdateError(f"{label} is required")

parent_pid, installed_executable, staging_root = parse_trusted_updater_argv(argv)
parent_pid, installed_executable, staging_root, handoff_version = parse_trusted_updater_argv(argv)
if handoff_version != current_version:
raise ApplicationUpdateError("trusted updater current version does not match host handoff")
wait_for_exit(parent_pid)

result = consume(
Expand Down
Loading
Loading