Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
feat(host): decide before downloading, and update once the app is live
leepokai8bf02b0cd5f2
diff --git a/.github/workflows/host.yml b/.github/workflows/host.ymlindex 27f9cfbd..32f11a46 100644--- a/.github/workflows/host.yml+++ b/.github/workflows/host.yml@@ -138,6 +138,8 @@ jobs:codync-host-*.tar.gz.sha256codync-host-*.update.jsoncodync-host-*.update.json.sig+ codync-host-*.compat.json+ codync-host-*.compat.json.sighomebrew:# Keeps `brew install leepokai/codync/codync-host` (Linux, headless Macs) in step with releases.diff --git a/host/src/update/install.rs b/host/src/update/install.rsindex 69465213..8d37249d 100644--- a/host/src/update/install.rs+++ b/host/src/update/install.rs@@ -138,6 +138,16 @@ async fn staged_min_app(stage: &Path) -> Result<String> {compat["minApp"].as_str().map(str::to_owned).context("the downloaded host reported no minimum app version")}+/// Whether a release needing `new_min_app` waits for the App Store (only if it raises the floor).+async fn app_store_gate(new_min_app: &str, port: u16) -> crate::compat::Gate {+ if !crate::compat::below(crate::compat::MIN_APP, new_min_app) {+ return crate::compat::Gate::Proceed;+ }+ let iphones = iphones_paired(port).await;+ let store = if iphones { crate::compat::app_store_version().await } else { Ok(None) };+ crate::compat::gate(crate::compat::MIN_APP, new_min_app, iphones, &store)+}+pub async fn apply(release: &release::Release,target: &Path,@@ -146,6 +156,15 @@ pub async fn apply(skip_app_check: bool,) -> Result<crate::compat::Gate> {require_standalone(target)?;+ // The release's signed compat file answers before anything is downloaded; releases+ // without one are asked after download (below).+ let early_min_app = if skip_app_check { None } else { release::min_app(release).await.ok() };+ if let Some(min_app) = &early_min_app {+ let gate = app_store_gate(min_app, port).await;+ if gate != crate::compat::Gate::Proceed {+ return Ok(gate);+ }+ }let managed = service::installed();if managed {service::require_executable(target)?;@@ -173,15 +192,10 @@ pub async fn apply();// Before anything stops: a release that needs a newer iPhone app than the App Store// has waits, so paired iPhones aren't asked for an update they can't get yet.- if !skip_app_check {- let new_min_app = staged_min_app(&stage).await?;- if crate::compat::below(crate::compat::MIN_APP, &new_min_app) {- let iphones = iphones_paired(port).await;- let store = if iphones { crate::compat::app_store_version().await } else { Ok(None) };- let gate = crate::compat::gate(crate::compat::MIN_APP, &new_min_app, iphones, &store);- if gate != crate::compat::Gate::Proceed {- return Ok(gate);- }+ if !skip_app_check && early_min_app.is_none() {+ let gate = app_store_gate(&staged_min_app(&stage).await?, port).await;+ if gate != crate::compat::Gate::Proceed {+ return Ok(gate);}}let old_hash = release::sha256(&std::fs::read(target)?);diff --git a/host/src/update/mod.rs b/host/src/update/mod.rsindex 2fd87e69..3982382c 100644--- a/host/src/update/mod.rs+++ b/host/src/update/mod.rs@@ -235,12 +235,27 @@ fn spawn_job(executable: &Path, args: &[String]) -> Result<()> {pub async fn automatic_loop(hub: Arc<Hub>) {let mut last_check = None;+ let mut last_store_probe = None;loop {tokio::time::sleep(Duration::from_secs(60)).await;let enabled = read::<Config>("update-config.json").is_ok_and(|c| c.automatic);if !enabled || hub.busy() {continue;}+ // Waiting for the iPhone app: look at the App Store hourly and update as soon as it's+ // there, instead of at the next daily check.+ if let Ok(state) = read::<State>("update-state.json")+ && state.phase == "waitingForApp"+ && let Some(required) = state.required_app+ && last_store_probe.is_none_or(|at: tokio::time::Instant| at.elapsed() >= Duration::from_secs(60 * 60))+ {+ last_store_probe = Some(tokio::time::Instant::now());+ if let Ok(Some(store)) = crate::compat::app_store_version().await+ && !crate::compat::below(&store, &required)+ {+ last_check = None;+ }+ }if last_check.is_some_and(|at: tokio::time::Instant| at.elapsed() < Duration::from_secs(24 * 60 * 60)) {continue;}diff --git a/host/src/update/release.rs b/host/src/update/release.rsindex 03b9fcbf..93bfac23 100644--- a/host/src/update/release.rs+++ b/host/src/update/release.rs@@ -62,6 +62,28 @@ pub fn verify_manifest(bytes: &[u8], signature: &str, public_key: &str, platformOk(release)}+/// The signed compat file published beside a release: the iPhone app version it needs,+/// readable before downloading the release (docs/reference/compatibility.md).+pub fn verify_compat(bytes: &[u8], signature: &str, public_key: &str, version: &str) -> Result<String> {+ let key: [u8; 32] =+ B64.decode(public_key.trim())?.try_into().map_err(|_| anyhow::anyhow!("invalid update public key"))?;+ let signature = Signature::from_slice(&B64.decode(signature.trim())?)?;+ VerifyingKey::from_bytes(&key)?.verify_strict(bytes, &signature).context("compat signature is invalid")?;+ let compat: serde_json::Value = serde_json::from_slice(bytes).context("reading the signed compat file")?;+ ensure!(compat["version"] == version, "compat file is for another release");+ let min_app = compat["minApp"].as_str().context("compat file has no minApp")?;+ ensure!(crate::compat::parse(min_app).is_some(), "compat file has an invalid minApp");+ Ok(min_app.to_owned())+}++/// `release`'s `minApp` from its signed compat file (releases before 2.5.0 have none).+pub async fn min_app(release: &Release) -> Result<String> {+ let url = format!("{RELEASES}/download/v{}/codync-host-{}.compat.json", release.version, release.platform);+ let bytes = download(&url, 4 * 1024).await?;+ let signature = download(&format!("{url}.sig"), 1024).await?;+ verify_compat(&bytes, std::str::from_utf8(&signature)?, PUBLIC_KEY, &release.version)+}+pub async fn download(url: &str, limit: usize) -> Result<Vec<u8>> {let mut response = crate::http().get(url)diff --git a/host/src/update/tests.rs b/host/src/update/tests.rsindex e3d9a93f..89d8e9db 100644--- a/host/src/update/tests.rs+++ b/host/src/update/tests.rs@@ -50,6 +50,27 @@ fn only_signed_platform_matched_manifests_are_accepted() {assert!(release::verify_manifest(&redirected, &signature, &public, "linux-arm64").is_err());}+#[test]+fn only_signed_compat_files_for_the_release_are_accepted() {+ let key = SigningKey::from_bytes(&[17; 32]);+ let public = B64.encode(key.verifying_key().as_bytes());+ let sign = |bytes: &[u8]| B64.encode(key.sign(bytes).to_bytes());+ let compat = br#"{"version": "3.0.0", "minApp": "2.9.0"}"#;+ assert_eq!(release::verify_compat(compat, &sign(compat), &public, "3.0.0").unwrap(), "2.9.0");+ // Another release's file, a forged one, or one without a readable minApp is refused.+ assert!(release::verify_compat(compat, &sign(compat), &public, "3.0.1").is_err());+ let other = B64.encode(SigningKey::from_bytes(&[18; 32]).verifying_key().as_bytes());+ assert!(release::verify_compat(compat, &sign(compat), &other, "3.0.0").is_err());+ let mut altered = compat.to_vec();+ altered[30] = b'8';+ assert!(release::verify_compat(&altered, &sign(compat), &public, "3.0.0").is_err());+ let bad = br#"{"version": "3.0.0", "minApp": "soon"}"#;+ assert!(release::verify_compat(bad, &sign(bad), &public, "3.0.0").is_err());+ // A signed release manifest isn't a compat file.+ let manifest = serde_json::to_vec(&manifest()).unwrap();+ assert!(release::verify_compat(&manifest, &sign(&manifest), &public, "3.0.0").is_err());+}+fn archive(symlink: bool) -> Vec<u8> {let gzip = flate2::write::GzEncoder::new(Vec::new(), flate2::Compression::default());let mut tar = tar::Builder::new(gzip);diff --git a/packaging/updates/sign-host-release.py b/packaging/updates/sign-host-release.pyindex d4320dfd..a427d9cd 100644--- a/packaging/updates/sign-host-release.py+++ b/packaging/updates/sign-host-release.py@@ -1,5 +1,7 @@#!/usr/bin/env python3-"""Create a signed manifest for one standalone host release archive.+"""Create a signed manifest for one standalone host release archive, and a signed+compat file (the iPhone app version the release needs) that updaters read before+downloading anything (docs/reference/compatibility.md).HOST_UPDATE_SIGNING_KEY contains a base64 Ed25519 seed. Only the public key iscommitted. Requires cryptography (installed by the release workflow).@@ -46,6 +48,15 @@ def main():output.write_bytes(data)output.with_suffix(output.suffix + ".sig").write_text(base64.b64encode(key.sign(data)).decode() + "\n")print(f"Signed {output.name}")+ source = Path(__file__).parents[2].joinpath("host/src/compat.rs").read_text()+ min_app = re.search(r'pub const MIN_APP: &str = "([0-9]+\.[0-9]+\.[0-9]+)";', source)+ if not min_app:+ raise SystemExit("MIN_APP not found in host/src/compat.rs")+ data = (json.dumps({"version": version, "minApp": min_app[1]}, indent=2) + "\n").encode()+ output = args.archive.with_name(f"codync-host-{args.platform}.compat.json")+ output.write_bytes(data)+ output.with_suffix(output.suffix + ".sig").write_text(base64.b64encode(key.sign(data)).decode() + "\n")+ print(f"Signed {output.name}")if __name__ == "__main__":