Files
rustdesk/res/update/update_metadata_policy.py
fufesou 0921a7432f feat(update): verify signed update metadata (#15914)
* feat(update): verify signed update metadata

* fix(update): harden metadata publishing and app names

- share strict app-name validation across Windows and macOS
- preserve published sidecars until replacements are ready
- select macOS test features by target architecture
- update the signing dependency and URL validation coverage

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(update): prevent replacing published release assets

- block reruns after signed update metadata is published
- clarify the security rationale for app-name validation

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(update): cache TLS responses and avoid double translations

Signed-off-by: fufesou <linlong1266@gmail.com>

* refact: reduce the diffs

Signed-off-by: fufesou <linlong1266@gmail.com>

* refact(update): remove obsolete update paths

- remove unused FFI update branches
- delete legacy Windows and macOS update helpers
- simplify macOS daemon updates and redundant gating

Signed-off-by: fufesou <linlong1266@gmail.com>

* feat(update): secure same-identity macOS offline updates

- verify DMGs using signed metadata, size, and SHA-256
- enforce package and bundle identity plus macOS signature checks
- support custom release policies and propagate manual update failures

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(update): verify Windows installers with Authenticode

Reject unsigned or untrusted EXE/MSI updates
before elevation, clean up failed verified copies,
and fix the macOS manual updater logging import.

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(update): clear stale URL on response body errors

Keep body-read failures in the common cleanup path and document the
cache-only Authenticode verification policy.

Signed-off-by: fufesou <linlong1266@gmail.com>

* refactor(update): remove OS signature sanity checks

Remove Windows Authenticode and macOS codesign/Gatekeeper verification.
Keep metadata, artifact integrity, bundle identity, and transaction checks.

Signed-off-by: fufesou <linlong1266@gmail.com>

* refact(update): move update scripts into res/update

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(update): secure Windows MSI handoff against junction races

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(update): secure Windows EXE handoff against junction races

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(update): preserve legacy custom client app names

- allow names starting with digits or underscores
- preserve leading hyphens on Windows for compatibility
- reject leading hyphens on macOS to avoid pgrep option parsing

Signed-off-by: fufesou <linlong1266@gmail.com>

* refact(update): remove some simple wrappers

Signed-off-by: fufesou <linlong1266@gmail.com>

* refact(update): simple refactor

* refact(update): comments on update.scpt

Signed-off-by: fufesou <linlong1266@gmail.com>

* refact(update): comments

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(update): create download destinations exclusively

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(macos): roll back updates when final readiness checks fail

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(msi): propagate MSI installation failures

Signed-off-by: fufesou <linlong1266@gmail.com>

* chore

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(macos): reject stale IPC sockets during updates

Require open IPC sockets in addition to launchd running state before committing the privileged update transaction. Inspect sockets with lsof to avoid triggering IPC authentication.

Add native socket regression coverage to macOS CI. Remove the unused Windows helper, combine offline metadata exports, and restore unrelated formatting changed by the PR.

Signed-off-by: fufesou <linlong1266@gmail.com>

* fix(macos): allow offline updates without an installed bundle

Validate app-only updates against the running client's bundle identifier and check the destination identity when it exists. Replace source-text assertions with behavioral identity tests and run the macOS update tests in CI.

Signed-off-by: fufesou <linlong1266@gmail.com>

* ci, gate test with PUBLISH_UPDATE_METADATA == 'true'

Signed-off-by: fufesou <linlong1266@gmail.com>

---------

Signed-off-by: fufesou <linlong1266@gmail.com>
2026-10-12 10:56:50 +08:00

101 lines
3.1 KiB
Python

import re
from datetime import datetime
from string import ascii_letters, digits
from urllib.parse import urlsplit
PACKAGE_ID_CHARACTERS = frozenset(ascii_letters + digits + ".-")
RFC3339_TIMESTAMP = re.compile(
r"[0-9]{4}-[0-9]{2}-[0-9]{2}[Tt][0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]+)?(?:[Zz]|[+-][0-9]{2}:[0-9]{2})"
)
ARTIFACT_FILE_NAME_PATTERN = re.compile(r"[A-Za-z0-9._-]+")
def validate_release(release_id, version):
if (
not release_id
or not release_id.isascii()
or release_id in {".", ".."}
or any(
char.isspace() or not char.isprintable() or char in "/\\?%#"
for char in release_id
)
):
raise ValueError(f"invalid release id: {release_id}")
match = re.fullmatch(r"v?([0-9]+)\.([0-9]+)\.([0-9]+)", release_id)
if not match:
return
segments = [int(part) for part in match.groups()]
if any(part > 65535 for part in segments) or not any(segments):
raise ValueError(f"invalid release version: {release_id}")
display_version = ".".join(match.groups())
if display_version != version:
raise ValueError(
f"release id {release_id} maps to {display_version}, not {version}"
)
def validate_published_at(value):
if not RFC3339_TIMESTAMP.fullmatch(value):
raise ValueError("published_at must be an RFC 3339 timestamp")
normalized = value[:-1] + "+00:00" if value[-1] in "Zz" else value
try:
datetime.fromisoformat(normalized)
except ValueError as error:
raise ValueError(
"published_at must be an RFC 3339 timestamp"
) from error
def validate_artifact_file_name(file_name):
if (
not isinstance(file_name, str)
or file_name in {".", ".."}
or not ARTIFACT_FILE_NAME_PATTERN.fullmatch(file_name)
):
raise ValueError(f"invalid artifact file name: {file_name}")
def validate_package_id(value):
if (
not isinstance(value, str)
or not value
or not value.isascii()
or any(char not in PACKAGE_ID_CHARACTERS for char in value)
or not any(char.isalnum() for char in value)
):
raise ValueError(f"invalid package id: {value}")
return value
def validate_release_base_url(value):
if (
not isinstance(value, str)
or not value
or not value.isascii()
or any(char.isspace() or not char.isprintable() for char in value)
or value.endswith("/")
or "\\" in value
or "?" in value
or "#" in value
):
raise ValueError(f"invalid release base URL: {value}")
try:
parsed = urlsplit(value)
parsed.port
except ValueError as error:
raise ValueError(f"invalid release base URL: {value}") from error
if (
parsed.scheme != "https"
or parsed.hostname is None
or parsed.username is not None
or parsed.password is not None
):
raise ValueError(
"release base URL must be HTTPS and must not contain credentials"
)
return value
def release_artifact_url(release_base_url, release_id, file_name):
return f"{release_base_url}/{release_id}/{file_name}"