From df4a97bff21c9ec693edaf6f2dfe9aa1ea3c673c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Thu, 5 Nov 2026 16:00:02 +0500 Subject: [PATCH] Preview update channel with its own signing key - keys/preview-signing.pub: preview packages and the preview pointer are signed with a separate key, so a stable Manager (stable key only) can never accept them. The preview Manager trusts both keys for packages (it starts from stable servers and stable base packages); each channel pointer must carry its own key's signature. - Channel 'preview': pointer preview.json on the preview-channels branch, releases preview-server-. The app resolves it first and falls back to stable until a preview release exists. - coa-release public-key prints the public half of the signing key; sign-channel writes the channel's own release tag. Co-Authored-By: Claude Opus 5.5 --- .../20261105-preview-update-channel.md | 7 ++ crates/coa-core/src/channels.rs | 77 ++++++++++++++++--- crates/coa-core/src/signing.rs | 24 ++++++ crates/coa-release/src/main.rs | 9 ++- keys/preview-signing.pub | 1 + src-tauri/src/lib.rs | 10 ++- 6 files changed, 115 insertions(+), 13 deletions(-) create mode 100644 changelog.d/20261105-preview-update-channel.md create mode 100644 keys/preview-signing.pub diff --git a/changelog.d/20261105-preview-update-channel.md b/changelog.d/20261105-preview-update-channel.md new file mode 100644 index 0000000..85953af --- /dev/null +++ b/changelog.d/20261105-preview-update-channel.md @@ -0,0 +1,7 @@ +--- +area: manager +type: added +audience: admins +title: The Modules Preview follows its own signed update channel +--- +The Modules Preview Manager gets server updates from a separate preview channel, signed with a key of its own, and falls back to the stable channel until the first preview release exists. A stable Manager never accepts preview packages. diff --git a/crates/coa-core/src/channels.rs b/crates/coa-core/src/channels.rs index db5ac3e..4dc5271 100644 --- a/crates/coa-core/src/channels.rs +++ b/crates/coa-core/src/channels.rs @@ -21,14 +21,19 @@ pub struct Envelope { } pub fn verify(bytes: &[u8], channel: &str, key: &str) -> Result { + verify_with(bytes, channel, key) +} + +/// A pointer must carry its own channel key's signature, never the other one. +fn verify_with(bytes: &[u8], channel: &str, key: &str) -> Result { let envelope: Envelope = serde_json::from_slice(bytes).map_err(|e| Error::InvalidManifest(e.to_string()))?; - crate::signing::verify(envelope.payload.as_bytes(), &envelope.signature, key)?; + crate::signing::verify_exact(envelope.payload.as_bytes(), &envelope.signature, key)?; let pointer: Pointer = serde_json::from_str(&envelope.payload) .map_err(|e| Error::InvalidManifest(e.to_string()))?; if pointer.schema != 1 || pointer.channel != channel - || pointer.release_tag != format!("server-{}", pointer.version) + || pointer.release_tag != release_tag(channel, &pointer.version) || pointer.version.is_empty() || !pointer .version @@ -42,14 +47,31 @@ pub fn verify(bytes: &[u8], channel: &str, key: &str) -> Result { Ok(pointer) } -pub fn resolve(channel: &str) -> Result { - if channel != "stable" && channel != "edge" { - return Err(Error::InvalidManifest("Unknown release channel".into())); +/// The release a channel's packages are published under: `server-`, or `preview-server-` for the +/// Modules Preview (pre-releases that never become the repository's latest release). +pub fn release_tag(channel: &str, version: &str) -> String { + if channel == "preview" { + format!("preview-server-{version}") + } else { + format!("server-{version}") } - let source = - Source::Url("https://raw.githubusercontent.com/Corfirean/coa-server-build/channels".into()); +} + +/// Where a channel's pointer lives and which key signs it. The preview channel has its own branch and +/// key, so publishing it can never move a stable or edge pointer. +fn channel_home(channel: &str) -> Result<(&'static str, &'static str)> { + match channel { + "stable" | "edge" => Ok(("channels", crate::signing::EMBEDDED_PUBLIC_KEY)), + "preview" => Ok(("preview-channels", crate::signing::PREVIEW_PUBLIC_KEY)), + _ => Err(Error::InvalidManifest("Unknown release channel".into())), + } +} + +pub fn resolve(channel: &str) -> Result { + let (branch, key) = channel_home(channel)?; + let source = Source::Url(format!("https://raw.githubusercontent.com/Corfirean/coa-server-build/{branch}")); let bytes = fetch_small(&source, &format!("{channel}.json"))?; - let pointer = verify(&bytes, channel, crate::signing::EMBEDDED_PUBLIC_KEY)?; + let pointer = verify_with(&bytes, channel, key)?; Ok(Source::Url(format!( "https://github.com/Corfirean/coa-server-build/releases/download/{}", pointer.release_tag @@ -75,7 +97,7 @@ pub fn sign(pointer: &Pointer, seed: &str) -> Result> { verify( &bytes, &pointer.channel, - crate::signing::EMBEDDED_PUBLIC_KEY, + channel_home(&pointer.channel)?.1, )?; Ok(bytes) } @@ -115,4 +137,41 @@ mod tests { let (bytes, key) = signed(&p); assert!(verify(&bytes, "stable", &key).is_err()); } + + #[test] + fn preview_pointers_name_preview_releases_and_live_apart_from_stable() { + let p = Pointer { + schema: 1, + channel: "preview".into(), + version: "0.261105.1".into(), + release_tag: "preview-server-0.261105.1".into(), + snapshot: "b".repeat(64), + }; + let (bytes, key) = signed(&p); + assert_eq!(verify(&bytes, "preview", &key).unwrap().release_tag, "preview-server-0.261105.1"); + // A preview pointer is not a stable one, and a stable-style tag is not a preview release. + assert!(verify(&bytes, "stable", &key).is_err()); + let stable_tag = Pointer { release_tag: "server-0.261105.1".into(), ..p }; + let (bytes, key) = signed(&stable_tag); + assert!(verify(&bytes, "preview", &key).is_err()); + assert_eq!(channel_home("preview").unwrap().0, "preview-channels"); + assert_eq!(channel_home("stable").unwrap().0, "channels"); + assert!(channel_home("nightly").is_err()); + } + + #[test] + fn each_channel_pointer_needs_its_own_key() { + // A pointer signed by some other key (here: not the embedded stable key) fails under the stable key + // even though the app also trusts the preview key for packages. + let p = Pointer { + schema: 1, + channel: "stable".into(), + version: "0.261105.2".into(), + release_tag: "server-0.261105.2".into(), + snapshot: "c".repeat(64), + }; + let (bytes, _) = signed(&p); + assert!(verify_with(&bytes, "stable", crate::signing::EMBEDDED_PUBLIC_KEY).is_err()); + assert!(verify_with(&bytes, "preview", crate::signing::PREVIEW_PUBLIC_KEY).is_err()); + } } diff --git a/crates/coa-core/src/signing.rs b/crates/coa-core/src/signing.rs index 863a0ad..f331c18 100644 --- a/crates/coa-core/src/signing.rs +++ b/crates/coa-core/src/signing.rs @@ -9,7 +9,31 @@ use crate::error::{Error, Result}; /// Public key baked into the application (private half lives only with the release maintainer / CI secret). pub const EMBEDDED_PUBLIC_KEY: &str = include_str!("../../../keys/manifest-signing.pub"); +/// The Modules Preview's own key: preview packages and the preview channel are signed with it, so a +/// stable Manager (which knows only the key above) never accepts them. The preview Manager trusts both, +/// because it starts from stable servers and stable packages. +pub const PREVIEW_PUBLIC_KEY: &str = include_str!("../../../keys/preview-signing.pub"); + +/// Checks `sig_b64` against `public_key_b64`; the embedded key stands for both keys this app trusts. pub fn verify(manifest_bytes: &[u8], sig_b64: &str, public_key_b64: &str) -> Result<()> { + let first = verify_exact(manifest_bytes, sig_b64, public_key_b64); + if first.is_err() && public_key_b64.trim() == EMBEDDED_PUBLIC_KEY.trim() { + return verify_exact(manifest_bytes, sig_b64, PREVIEW_PUBLIC_KEY).map_err(|_| first.unwrap_err()); + } + first +} + +/// The public half (base64) of a base64 Ed25519 seed. +pub fn public_key_of(seed_b64: &str) -> Result { + let seed: [u8; 32] = STANDARD + .decode(seed_b64.trim()) + .map_err(|_| Error::Invalid("signing key is not base64".into()))? + .try_into() + .map_err(|_| Error::Invalid("signing key has the wrong length".into()))?; + Ok(STANDARD.encode(ed25519_dalek::SigningKey::from_bytes(&seed).verifying_key().to_bytes())) +} + +pub fn verify_exact(manifest_bytes: &[u8], sig_b64: &str, public_key_b64: &str) -> Result<()> { let bad = |m: &str| Error::InvalidManifest(format!("signature: {m}")); let key: [u8; 32] = STANDARD .decode(public_key_b64.trim()) diff --git a/crates/coa-release/src/main.rs b/crates/coa-release/src/main.rs index cd9a302..e791ce4 100644 --- a/crates/coa-release/src/main.rs +++ b/crates/coa-release/src/main.rs @@ -8,7 +8,8 @@ //! coa-release clean-base --repack DIR --core DIR --tree DIR --out DIR [--bots DIR] [--data DIR] //! coa-release export-baseline --server DIR --out DIR (the three databases of a prepared server, for a Linux package) //! coa-release sign --dir DIR (key: env COA_SIGNING_KEY, or ~/.coa-manager/signing/manifest-signing.key) -//! coa-release verify --dir DIR (against the public key built into this tool) +//! coa-release verify --dir DIR (against the public keys built into this tool) +//! coa-release public-key (public half of the signing key, to embed in the app) use std::collections::HashMap; use std::path::PathBuf; @@ -297,12 +298,16 @@ fn run() -> Result<(), String> { .map_err(e)?; println!("signature, archive contents and database schema contract OK"); } + "public-key" => { + // The public half of the signing key (COA_SIGNING_KEY or the key file), for the app to embed. + println!("{}", coa_core::signing::public_key_of(&signing_key()?).map_err(e)?); + } "sign-channel" => { let pointer = coa_core::channels::Pointer { schema: 1, channel: need(&a, "channel")?.clone(), version: need(&a, "version")?.clone(), - release_tag: format!("server-{}", need(&a, "version")?), + release_tag: coa_core::channels::release_tag(need(&a, "channel")?, need(&a, "version")?), snapshot: need(&a, "snapshot")?.clone(), }; let bytes = coa_core::channels::sign(&pointer, &signing_key()?).map_err(e)?; diff --git a/keys/preview-signing.pub b/keys/preview-signing.pub new file mode 100644 index 0000000..98756f9 --- /dev/null +++ b/keys/preview-signing.pub @@ -0,0 +1 @@ +KASc8Nx8HKDW6DycDfqGgMgZaU1n9M8P20vBfNszgfA= diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 36bcf09..a779bb0 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -275,9 +275,15 @@ fn update_source(custom: Option) -> Result { match pick { Some(p) if p.to_ascii_lowercase().starts_with("http") => Ok(Source::Url(p)), Some(p) => Ok(Source::Dir(PathBuf::from(p))), - None => match coa_core::channels::resolve("stable") { + // The Modules Preview follows its own signed channel; until the first preview release exists it + // falls back to the stable channel (a stable server is where every preview server starts). + None => match coa_core::channels::resolve("preview") { Ok(source) => Ok(source), - Err(Error::PackageNotPublished(_)) => Ok(Source::Url(DEFAULT_UPDATE_URL.into())), + Err(Error::PackageNotPublished(_)) => match coa_core::channels::resolve("stable") { + Ok(source) => Ok(source), + Err(Error::PackageNotPublished(_)) => Ok(Source::Url(DEFAULT_UPDATE_URL.into())), + Err(error) => Err(error), + }, Err(error) => Err(error), }, }