Launcher and horizon-server update: install only releases whose signed checksums match

The launcher (game installs and its own updates) and `horizon-server update` fetch a release's
SHA256SUMS and SHA256SUMS.sig, check the signature against the keys built in from
crates/horizon-release-sign/release-keys.txt and the archive against the signed SHA-256, and
refuse anything unsigned, signed for another tag or by another key, or that doesn't match, with a
message saying why. Merge only once release-keys.txt lists the key and a signed stable release
exists: until then every download is refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-19 14:25:47 +02:00
parent 4d2e05dda7
commit 36908858a3
12 changed files with 250 additions and 57 deletions
+1
View File
@@ -20,6 +20,7 @@ on:
- 'crates/horizon-mods/**'
- 'crates/horizon-port-pack/**'
- 'crates/horizon-prepare/**'
- 'crates/horizon-release-sign/**'
- 'crates/horizon-telemetry/**'
- 'crates/horizon-theme/**'
- '.github/workflows/launcher.yml'
Generated
+1
View File
@@ -1568,6 +1568,7 @@ version = "0.1.0"
dependencies = [
"chrono",
"horizon-bench",
"horizon-release-sign",
"horizon-server-files",
"libc",
"serde",
+2 -1
View File
@@ -17,8 +17,9 @@ serde_json = "1"
toml = "1.1"
# Edits server.toml in place, keeping the owner's comments and order.
toml_edit = "0.25"
# Updates: the release from GitHub, checked against the SHA-256 GitHub publishes (both already in the
# Updates: the release from GitHub, checked against the SHA-256 in its signed checksums (both already in the
# lockfile, ureq through horizon-server-files).
horizon-release-sign = { path = "../horizon-release-sign" }
sha2 = "0.10"
ureq = { version = "2", default-features = false, features = ["tls"] }
# Backups: one zip anyone can open, Windows included.
+98 -38
View File
@@ -1,8 +1,9 @@
//! Updates and rollbacks (docs/server.md, section 7) for a `horizon-server` installed by install.sh or
//! install.ps1: each release in `<dir>/releases/<tag>`, `<dir>/current` pointing at the one in use, and
//! `<dir>/previous` naming the one before it. An update downloads the newest release from GitHub, checks it
//! against the SHA-256 GitHub publishes for it, unpacks it beside the others and switches `current`; the
//! supervisor then restarts the game on it and switches back by itself if the new game doesn't come up.
//! `<dir>/previous` naming the one before it. An update downloads the newest stable release from GitHub, checks it
//! against the SHA-256 in the release's signed SHA256SUMS (docs/security.md), unpacks it beside the others and
//! switches `current`; the supervisor then restarts the game on it and switches back by itself if the new game
//! doesn't come up.
use crate::{api::Client, backup, config::Config, engine, supervisor};
use serde_json::{Value, json};
@@ -231,27 +232,47 @@ pub struct Release {
pub sha256: String,
}
/// The newest release (or `tag`), from GitHub's API.
/// GitHub's API, or a release asset: the body of `url`.
fn fetch(url: &str) -> Result<Vec<u8>, String> {
let mut body = Vec::new();
ureq::get(url)
.set("Accept", "application/vnd.github+json")
.set("User-Agent", "horizon-server")
.call()
.map_err(|e| match e {
ureq::Error::Status(404, _) => "404".to_string(),
e => format!("GitHub didn't answer: {e}"),
})?
.into_reader()
.take(64 << 20)
.read_to_end(&mut body)
.map_err(|e| format!("GitHub's answer: {e}"))?;
Ok(body)
}
/// The newest stable release (or `tag`), from GitHub's API, with the SHA-256 its signed checksums
/// give for this computer's archive.
pub fn release(tag: Option<&str>) -> Result<Release, String> {
let url = match tag {
Some(tag) => format!("https://api.github.com/repos/{REPO}/releases/tags/{tag}"),
None => format!("https://api.github.com/repos/{REPO}/releases/latest"),
};
let text = ureq::get(&url)
.set("Accept", "application/vnd.github+json")
.set("User-Agent", "horizon-server")
.call()
.map_err(|e| match e {
ureq::Error::Status(404, _) => format!("no release {} on GitHub", tag.unwrap_or("")),
e => format!("GitHub didn't answer: {e}"),
})?
.into_string()
.map_err(|e| format!("GitHub's answer: {e}"))?;
pick(&serde_json::from_str(&text).map_err(|e| format!("GitHub's answer: {e}"))?)
let text = fetch(&url).map_err(|e| match e.as_str() {
"404" => format!("no release {} on GitHub", tag.unwrap_or("")),
_ => e,
})?;
let json = serde_json::from_slice(&text).map_err(|e| format!("GitHub's answer: {e}"))?;
pick(&json, fetch, &horizon_release_sign::trusted_keys())
}
/// The archive for this computer in a release's JSON, with the SHA-256 GitHub publishes for it.
fn pick(release: &Value) -> Result<Release, String> {
/// The archive for this computer in a release's JSON, with the SHA-256 the release's SHA256SUMS
/// gives for it, once its signature checks with one of `keys` (docs/security.md). A release that
/// isn't signed, or not by Horizon's key, is refused.
fn pick(
release: &Value,
fetch: impl Fn(&str) -> Result<Vec<u8>, String>,
keys: &[horizon_release_sign::PublicKey],
) -> Result<Release, String> {
let tag = release["tag_name"]
.as_str()
.ok_or("GitHub's answer has no tag")?;
@@ -266,10 +287,24 @@ fn pick(release: &Value) -> Result<Release, String> {
)
})?;
let name = asset["name"].as_str().unwrap_or_default();
let sha256 = asset["digest"]
.as_str()
.and_then(|d| d.strip_prefix("sha256:"))
.ok_or_else(|| format!("release {tag} publishes no SHA-256 for {name}"))?;
let attached = |file: &str| -> Result<Option<Vec<u8>>, String> {
match assets.iter().find(|a| a["name"] == file) {
Some(a) => fetch(a["browser_download_url"].as_str().unwrap_or_default())
.map(Some)
.map_err(|e| format!("{file} of {tag}: {e}")),
None => Ok(None),
}
};
let sums = attached(horizon_release_sign::SUMS)?;
let signature = attached(horizon_release_sign::SIGNATURE)?
.map(|bytes| String::from_utf8_lossy(&bytes).into_owned());
let sha256 = horizon_release_sign::signed_digest(
tag,
name,
sums.as_deref(),
signature.as_deref(),
keys,
)?;
Ok(Release {
tag: tag.to_owned(),
asset: name.to_owned(),
@@ -277,7 +312,7 @@ fn pick(release: &Value) -> Result<Release, String> {
.as_str()
.unwrap_or_default()
.to_owned(),
sha256: sha256.to_ascii_lowercase(),
sha256,
})
}
@@ -717,31 +752,56 @@ mod tests {
}
#[test]
fn the_archive_for_this_computer_is_picked_with_its_digest() {
let asset = |name: &str| {
json!({
"name": name,
"browser_download_url": format!("https://example.invalid/{name}"),
"digest": "sha256:ABCDEF",
})
fn the_archive_for_this_computer_is_picked_with_its_signed_digest() {
use horizon_release_sign::{SigningKey, sha256_hex, sums_file};
let asset = |name: &str| json!({ "name": name, "browser_download_url": format!("https://example.invalid/{name}") });
let (key, _) = SigningKey::generate().unwrap();
let listed: Vec<(String, String)> = ASSETS
.iter()
.map(|n| (n.to_string(), sha256_hex(n.as_bytes())))
.collect();
let sums = sums_file(&listed);
let signature = key.sign("v2026.10.19", sums.as_bytes());
let files = |url: &str| -> Result<Vec<u8>, String> {
match url.rsplit('/').next() {
Some("SHA256SUMS") => Ok(sums.clone().into_bytes()),
Some("SHA256SUMS.sig") => Ok(signature.clone().into_bytes()),
_ => Err("404".into()),
}
};
let release = json!({
let names = ASSETS.iter().rev().copied().chain(["other.zip"]);
let signed = json!({
"tag_name": "v2026.10.19",
"assets": ASSETS.iter().rev().map(|n| asset(n)).chain([asset("other.zip")]).collect::<Vec<_>>(),
"assets": names.chain(["SHA256SUMS", "SHA256SUMS.sig"]).map(asset).collect::<Vec<_>>(),
});
if let Some(first) = ASSETS.first() {
let picked = pick(&release).unwrap();
let picked = pick(&signed, files, &[key.public()]).unwrap();
assert_eq!(picked.tag, "v2026.10.19");
// The most specific archive (Linux: the server build), even when listed last.
assert_eq!(picked.asset, *first);
assert_eq!(picked.sha256, "abcdef");
let undigested = json!({ "tag_name": "v1", "assets": [{ "name": first, "browser_download_url": "x" }] });
assert!(pick(&undigested).unwrap_err().contains("no SHA-256"));
assert_eq!(picked.sha256, sha256_hex(first.as_bytes()));
// Signed by another key, or not signed at all: refused.
let (other, _) = SigningKey::generate().unwrap();
assert!(pick(&signed, files, &[other.public()]).is_err());
let unsigned = json!({ "tag_name": "v1", "assets": [asset(first)] });
assert!(
pick(&unsigned, files, &[key.public()])
.unwrap_err()
.contains("not signed")
);
// The same signed list under another tag: refused.
let mut replayed = signed.clone();
replayed["tag_name"] = json!("v2026.10.20");
assert!(pick(&replayed, files, &[key.public()]).is_err());
}
assert!(
pick(&json!({ "tag_name": "v1", "assets": [asset("other.zip")] }))
.unwrap_err()
.contains("no archive for this computer")
pick(
&json!({ "tag_name": "v1", "assets": [asset("other.zip")] }),
files,
&[]
)
.unwrap_err()
.contains("no archive for this computer")
);
}
+4 -2
View File
@@ -410,8 +410,10 @@ runtime or new dependency. Server-sent events can replace the polling later if a
newer release a minute after it starts and then every 6 hours, and only says so, in its log, in `status`
and in the panel (`HORIZON_NO_UPDATE_CHECK=1` turns the check off). `update --check` asks GitHub once.
`update`:
1. downloads the release archive for this computer (on Linux the server build) and checks it against the
SHA-256 GitHub publishes for it;
1. downloads the newest stable release's archive for this computer (on Linux the server build; `--version`
picks another, a beta included) and checks it against the release's SHA256SUMS, whose Ed25519 signature
must check with a key built into `horizon-server` (docs/release-flow.md, "Signed checksums"): an unsigned
or tampered release is refused;
2. unpacks it into `<dir>/releases/<tag>`, beside the others, with its game files linked to
`<dir>/game-files` as the installers do;
3. stops the game, backs up the world (`backups/<time>-before-<tag>.zip`), records the release in use in
+9
View File
@@ -2666,6 +2666,7 @@ dependencies = [
"horizon-friends",
"horizon-port-pack",
"horizon-prepare",
"horizon-release-sign",
"horizon-telemetry",
"horizon-theme",
"image",
@@ -2716,6 +2717,14 @@ dependencies = [
"zip",
]
[[package]]
name = "horizon-release-sign"
version = "0.1.0"
dependencies = [
"base64",
"ring",
]
[[package]]
name = "horizon-telemetry"
version = "0.1.0"
+2
View File
@@ -28,6 +28,8 @@ horizon-friends = { path = "../crates/horizon-friends" }
horizon-bench = { path = "../crates/horizon-bench" }
# Import modpack: the porting pipeline, run on the player's own files (docs/modpacks.md).
horizon-port-pack = { path = "../crates/horizon-port-pack" }
# Signed updates: archives are checked against the release's signed checksums (docs/security.md).
horizon-release-sign = { path = "../crates/horizon-release-sign" }
# Opt-in data collection: the consent, the outbox and its upload (docs/telemetry.md).
horizon-telemetry = { path = "../crates/horizon-telemetry" }
# The session file's random name.
+58 -12
View File
@@ -346,21 +346,60 @@ fn installed_in(versions: &Path) -> Vec<String> {
tags
}
fn download(url: &str, size: u64, to: &Path, progress: &impl Fn(f32)) -> Result<(), String> {
/// A small release file (its checksums or their signature), whole; None when it has none.
fn fetch_small(url: &str) -> Result<Option<Vec<u8>>, String> {
let response = match get(url) {
Ok(response) => response,
Err(e) if e.ends_with("answered 404") => return Ok(None),
Err(e) => return Err(e),
};
let mut body = Vec::new();
response
.into_reader()
.take(1 << 20)
.read_to_end(&mut body)
.map_err(|e| format!("Download interrupted: {e}"))?;
Ok(Some(body))
}
/// The SHA-256 the release's signed checksums give for `asset`, or why it must not be installed.
fn signed_digest(tag: &str, asset: &str) -> Result<String, String> {
crate::signed::digest(
tag,
asset,
&horizon_release_sign::trusted_keys(),
fetch_small,
)
}
/// Downloads `url` into `to`; the file is kept only if its SHA-256 is `sha256`, the signed one.
fn download(
url: &str,
size: u64,
sha256: &str,
to: &Path,
progress: &impl Fn(f32),
) -> Result<(), String> {
let mut reader = get(url)?.into_reader();
let mut file = fs::File::create(to).map_err(|e| e.to_string())?;
let mut hash = horizon_release_sign::Sha256::default();
let (mut done, mut buf) = (0u64, vec![0u8; 1 << 16]);
loop {
let n = reader
.read(&mut buf)
.map_err(|e| format!("Download interrupted: {e}"))?;
if n == 0 {
return Ok(());
break;
}
hash.update(&buf[..n]);
file.write_all(&buf[..n]).map_err(|e| e.to_string())?;
done += n as u64;
progress((done as f32 / size.max(1) as f32).min(1.0) * 0.9);
}
let name = url.rsplit('/').next().unwrap_or(url);
horizon_release_sign::check(name, sha256, &hash.hex()).inspect_err(|_| {
let _ = fs::remove_file(to);
})
}
fn unpack(archive: &Path, url: &str, to: &Path) -> Result<(), String> {
@@ -376,19 +415,26 @@ fn unpack(archive: &Path, url: &str, to: &Path) -> Result<(), String> {
}
}
/// Downloads and unpacks one release; `progress` gets the fraction done.
pub fn install(tag: &str, url: &str, size: u64, progress: impl Fn(f32)) -> Result<(), String> {
/// Downloads one release, checks it against its signed checksums and unpacks it; `progress` gets
/// the fraction done.
pub fn install(release: &Release, progress: impl Fn(f32)) -> Result<(), String> {
let tag = release.tag.as_str();
if !is_game_tag(tag) {
return Err(format!("{tag} is not a Horizon release."));
}
let (url, size) = release
.asset
.clone()
.ok_or_else(|| format!("{tag} has no build for this platform."))?;
let sha256 = signed_digest(tag, ASSET.unwrap_or_default())?;
let root = versions_dir();
let partial = root.join(format!(".{tag}.partial"));
let _ = fs::remove_dir_all(&partial);
fs::create_dir_all(&partial).map_err(|e| e.to_string())?;
let archive = partial.join("download");
download(url, size, &archive, &progress)?;
download(&url, size, &sha256, &archive, &progress)?;
let unpacked = partial.join("unpacked");
unpack(&archive, url, &unpacked)?;
unpack(&archive, &url, &unpacked)?;
progress(0.97);
// The archives hold one top folder (horizon-linux-x86_64/...); the version folder is its contents.
let entries: Vec<_> = fs::read_dir(&unpacked)
@@ -1538,12 +1584,11 @@ pub fn install_tag(tag: &str, as_update: bool, progress: impl Fn(f32)) -> Result
.find(|r| r.tag == tag)
.ok_or_else(|| format!("No Horizon release is tagged {tag}."))?
};
let (url, size) = release
.asset
.clone()
.ok_or_else(|| format!("{} has no build for this platform.", release.tag))?;
if release.asset.is_none() {
return Err(format!("{} has no build for this platform.", release.tag));
}
let before = installed();
install(&release.tag, &url, size, progress)?;
install(release, progress)?;
let mut settings = Settings::load();
if !as_update || select_after_update(settings.selected.as_deref(), &before) {
settings.selected = Some(release.tag.clone());
@@ -1702,11 +1747,12 @@ pub fn self_update(release: &Release, progress: impl Fn(f32)) -> Result<(), Stri
progress(1.0);
return Ok(());
}
let sha256 = signed_digest(&release.tag, LAUNCHER_ASSET.unwrap_or_default())?;
let work = data_dir().join(".launcher-update");
let _ = fs::remove_dir_all(&work);
fs::create_dir_all(&work).map_err(|e| e.to_string())?;
let archive = work.join("download");
download(&url, size, &archive, &progress)?;
download(&url, size, &sha256, &archive, &progress)?;
let unpacked = work.join("unpacked");
unpack(&archive, &url, &unpacked)?;
// A launcher inside Horizon.app replaces the whole bundle (its Info.plist, icon and
+1
View File
@@ -6,6 +6,7 @@ pub mod heads;
pub mod modpacks;
pub mod mojang;
pub mod servers;
pub mod signed;
pub mod sources;
pub mod tailscale;
pub mod telemetry;
+5 -4
View File
@@ -643,10 +643,11 @@ impl Launcher {
}
fn install(&mut self, release: &Release) {
let Some((url, size)) = release.asset.clone() else {
if release.asset.is_none() {
return;
};
let (tag, tx) = (release.tag.clone(), self.tx.clone());
}
let (release, tx) = (release.clone(), self.tx.clone());
let tag = release.tag.clone();
self.installing = Some((tag.clone(), 0.0));
self.install_started = Some(Instant::now());
self.bar = (0., 0.);
@@ -655,7 +656,7 @@ impl Launcher {
let progress = |p| {
let _ = tx.send(Msg::Progress(tag.clone(), p));
};
let result = backend::install(&tag, &url, size, progress);
let result = backend::install(&release, progress);
let _ = tx.send(Msg::Installed(tag, result));
});
}
+68
View File
@@ -0,0 +1,68 @@
//! Signed downloads (docs/security.md): a game or launcher archive is installed only when its
//! SHA-256 matches the release's SHA256SUMS and that list is signed by one of the keys built in
//! from crates/horizon-release-sign/release-keys.txt. Anything else is refused with a message
//! saying why.
use crate::backend::REPO;
use horizon_release_sign::{PublicKey, SIGNATURE, SUMS};
/// Where a release's attached file downloads from (GitHub's fixed address for it).
pub fn asset_url(tag: &str, name: &str) -> String {
format!("https://github.com/{REPO}/releases/download/{tag}/{name}")
}
/// The signed SHA-256 of `asset` in release `tag`, fetching its SHA256SUMS and SHA256SUMS.sig
/// with `fetch` (None: the release has no such file), or why the download must be refused.
pub fn digest(
tag: &str,
asset: &str,
keys: &[PublicKey],
fetch: impl Fn(&str) -> Result<Option<Vec<u8>>, String>,
) -> Result<String, String> {
let sums = fetch(&asset_url(tag, SUMS))?;
let signature = fetch(&asset_url(tag, SIGNATURE))?
.map(|bytes| String::from_utf8_lossy(&bytes).into_owned());
horizon_release_sign::signed_digest(tag, asset, sums.as_deref(), signature.as_deref(), keys)
}
#[cfg(test)]
mod tests {
use super::*;
use horizon_release_sign::{sha256_hex, sums_file, SigningKey};
#[test]
fn only_archives_signed_by_a_built_in_key_install() {
let (key, _) = SigningKey::generate().unwrap();
let sums = sums_file(&[("horizon.zip".into(), sha256_hex(b"game"))]);
let signature = key.sign("v2026.10.19", sums.as_bytes());
// GitHub as it answers for a signed release (any tag: the files are what a replay would serve).
let signed = |url: &str| -> Result<Option<Vec<u8>>, String> {
assert!(url.starts_with("https://github.com/ludovic111/horizon/releases/download/"));
Ok(Some(
if url.ends_with(".sig") {
signature.clone()
} else {
sums.clone()
}
.into_bytes(),
))
};
let keys = [key.public()];
assert_eq!(
digest("v2026.10.19", "horizon.zip", &keys, signed),
Ok(sha256_hex(b"game"))
);
// Signed for another tag, by another key, or not listing the archive: refused.
assert!(digest("v2026.10.20", "horizon.zip", &keys, signed).is_err());
let (other, _) = SigningKey::generate().unwrap();
assert!(digest("v2026.10.19", "horizon.zip", &[other.public()], signed).is_err());
assert!(digest("v2026.10.19", "other.zip", &keys, signed).is_err());
// No checksums (a release from before signing): refused, saying so.
let unsigned = |_: &str| -> Result<Option<Vec<u8>>, String> { Ok(None) };
let refused = digest("v2026.10.19", "horizon.zip", &keys, unsigned).unwrap_err();
assert!(refused.contains("not signed"), "{refused}");
// Checksums that can't be fetched are an error too, never a pass.
let offline = |_: &str| -> Result<Option<Vec<u8>>, String> { Err("No connection".into()) };
assert!(digest("v2026.10.19", "horizon.zip", &keys, offline).is_err());
}
}
+1
View File
@@ -50,6 +50,7 @@ LAUNCHER_PATHS = [
"crates/horizon-mods/",
"crates/horizon-port-pack/",
"crates/horizon-prepare/",
"crates/horizon-release-sign/",
"crates/horizon-telemetry/",
"crates/horizon-theme/",
]