diff --git a/.github/workflows/launcher.yml b/.github/workflows/launcher.yml
index e7b55c64b..dbd1c3571 100644
--- a/.github/workflows/launcher.yml
+++ b/.github/workflows/launcher.yml
@@ -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'
diff --git a/Cargo.lock b/Cargo.lock
index 4100e167f..25c705b23 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1568,6 +1568,7 @@ version = "0.1.0"
dependencies = [
"chrono",
"horizon-bench",
+ "horizon-release-sign",
"horizon-server-files",
"libc",
"serde",
diff --git a/crates/horizon-server/Cargo.toml b/crates/horizon-server/Cargo.toml
index ec3b9bbc4..747b041df 100644
--- a/crates/horizon-server/Cargo.toml
+++ b/crates/horizon-server/Cargo.toml
@@ -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.
diff --git a/crates/horizon-server/src/update.rs b/crates/horizon-server/src/update.rs
index f1f60a061..ea24b6a84 100644
--- a/crates/horizon-server/src/update.rs
+++ b/crates/horizon-server/src/update.rs
@@ -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 `
/releases/`, `/current` pointing at the one in use, and
-//! `/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.
+//! `/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, 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 {
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 {
+/// 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, String>,
+ keys: &[horizon_release_sign::PublicKey],
+) -> Result {
let tag = release["tag_name"]
.as_str()
.ok_or("GitHub's answer has no tag")?;
@@ -266,10 +287,24 @@ fn pick(release: &Value) -> Result {
)
})?;
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