Sign the app update feed with Ed25519 and verify it in the app
Each installation generates a private Ed25519 key once (0600, under ~/.config/pipelines), signs version.json with a detached version.json.sig when publishing APK and desktop builds, and embeds its own and listed trusted public keys in app builds. The app verifies the feed signature before trusting the artifact sha256, refuses unsigned or foreign feeds when it has keys, and requires the sha256 and Android signer in signed feeds.
This commit is contained in:
+13
-6
@@ -27,6 +27,9 @@ from urllib.parse import urlsplit
|
||||
REPO = Path(__file__).resolve().parents[1]
|
||||
APP = REPO / "app"
|
||||
DEFAULT_PREFIX = Path.home() / ".local/share/pipelines"
|
||||
_signing_spec = importlib.util.spec_from_file_location("pipelines_update_signing", Path(__file__).with_name("update_signing.py"))
|
||||
update_signing = importlib.util.module_from_spec(_signing_spec)
|
||||
_signing_spec.loader.exec_module(update_signing)
|
||||
|
||||
def default_cache():
|
||||
return Path(os.environ.get("PIPELINES_APP_CACHE") or Path.home() / ".cache/pipelines/app-builds")
|
||||
@@ -346,7 +349,10 @@ def build_apk(prefix, server_url=None, notes="", runner=subprocess.run, log=prin
|
||||
server = server_url or phone_server_url(manifest)
|
||||
# The build number is the source key's build date, so the same sources
|
||||
# reuse one APK and every rebuild is newer than the last.
|
||||
arguments = (f"--dart-define=PIPELINES_SERVER_URL={server}",)
|
||||
# The feed is signed and the app embeds the keys it trusts (see
|
||||
# scripts/update_signing.py), so a server cannot hand phones another APK.
|
||||
signer = update_signing.Signer()
|
||||
arguments = (f"--dart-define=PIPELINES_SERVER_URL={server}", *update_signing.dart_defines())
|
||||
host_flutter, sdk = native_flutter(flutter), android_sdk_dir()
|
||||
use_native = native if native is not None else bool(host_flutter and sdk)
|
||||
if use_native:
|
||||
@@ -365,9 +371,9 @@ def build_apk(prefix, server_url=None, notes="", runner=subprocess.run, log=prin
|
||||
target.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copyfile(output / "pipelines.apk", target / "pipelines.apk.next")
|
||||
os.replace(target / "pipelines.apk.next", target / "pipelines.apk")
|
||||
(target / "version.json").write_text(json.dumps({
|
||||
update_signing.publish_feed(target, {
|
||||
"versionCode": code, "versionName": f"0.1.{code}", "apk": "pipelines.apk", "notes": notes,
|
||||
"signingCertificateSha256": fingerprint, "sha256": apk_sha256}) + "\n")
|
||||
"signingCertificateSha256": fingerprint, "sha256": apk_sha256}, signer)
|
||||
log(f"APK ready: {target / 'pipelines.apk'} (build {code}, server {server}).")
|
||||
log("Phones get it from Settings → App updates → Check for updates, or download "
|
||||
f"{server.replace('wss://', 'https://').replace('ws://', 'http://').removesuffix('/connect')}/updates/pipelines.apk")
|
||||
@@ -416,13 +422,14 @@ def main(argv=None):
|
||||
bundle, archive = desktop.build_desktop(args.kind, app=APP, cache=default_cache(), runner=subprocess.run,
|
||||
source_digest=digest, docker_build=build, docker_ready=docker_available,
|
||||
server_url=args.server_url, flutter=args.flutter, output=args.output,
|
||||
prune_cache=prune)
|
||||
prune_cache=prune, update_keys=update_signing.dart_defines())
|
||||
if args.publish:
|
||||
manifest = load_manifest(args.prefix)
|
||||
updates = (manifest.get("web") or {}).get("updates")
|
||||
if not updates:
|
||||
raise ValueError("This installation has no app update directory; rerun ./install")
|
||||
desktop.publish_desktop(args.kind, bundle, archive, Path(updates), notes=args.notes)
|
||||
desktop.publish_desktop(args.kind, bundle, archive, Path(updates), notes=args.notes,
|
||||
signer=update_signing.Signer())
|
||||
return
|
||||
if args.kind == "apk":
|
||||
build_apk(args.prefix, args.server_url, args.notes, flutter=args.flutter, native=args.native)
|
||||
@@ -434,7 +441,7 @@ def main(argv=None):
|
||||
web = manifest.get("web") or {}
|
||||
if not web.get("root"):
|
||||
raise ValueError("This installation does not serve the app; rerun ./install")
|
||||
install_tree(build("web"), Path(web["root"]))
|
||||
install_tree(build("web", arguments=update_signing.dart_defines()), Path(web["root"]))
|
||||
print(f"Web app installed at {web['root']}; reload the page.")
|
||||
print_web_urls(manifest)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user