Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

fix(net): downloads trust the system's root certificates beside the shipped ones (#517)

Jareer46af73ced057
diff --git a/src/Cargo.lock b/src/Cargo.lock
index 4f8fcafd..91c6ddc8 100644
--- a/src/Cargo.lock
+++ b/src/Cargo.lock
@@ -1257,11 +1257,14 @@ dependencies = [
"log",
"memmap2",
"png 0.17.16",
+ "rustls",
+ "rustls-native-certs",
"serde",
"serde_json",
"sha2",
"tempfile",
"ureq 2.12.1",
+ "webpki-roots 0.26.11",
"windows-sys 0.61.2",
]
@@ -1803,7 +1806,7 @@ dependencies = [
"libc",
"option-ext",
"redox_users",
- "windows-sys 0.61.2",
+ "windows-sys 0.59.0",
]
[[package]]
@@ -1988,7 +1991,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb"
dependencies = [
"libc",
- "windows-sys 0.61.2",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -4854,7 +4857,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967"
dependencies = [
"libc",
- "windows-sys 0.61.2",
+ "windows-sys 0.45.0",
]
[[package]]
@@ -5726,7 +5729,7 @@ dependencies = [
"errno",
"libc",
"linux-raw-sys 0.12.1",
- "windows-sys 0.61.2",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -5744,6 +5747,18 @@ dependencies = [
"zeroize",
]
+[[package]]
+name = "rustls-native-certs"
+version = "0.8.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dab5152771c58876a2146916e53e35057e1a4dfa2b9df0f0305b07f611fdea4d"
+dependencies = [
+ "openssl-probe",
+ "rustls-pki-types",
+ "schannel",
+ "security-framework",
+]
+
[[package]]
name = "rustls-pki-types"
version = "1.15.1"
@@ -6500,7 +6515,7 @@ dependencies = [
"getrandom 0.4.3",
"once_cell",
"rustix 1.1.4",
- "windows-sys 0.61.2",
+ "windows-sys 0.52.0",
]
[[package]]
@@ -7748,7 +7763,7 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22"
dependencies = [
- "windows-sys 0.61.2",
+ "windows-sys 0.48.0",
]
[[package]]
diff --git a/src/crates/concat-host/Cargo.toml b/src/crates/concat-host/Cargo.toml
index e9db5a02..b1d4ad3b 100644
--- a/src/crates/concat-host/Cargo.toml
+++ b/src/crates/concat-host/Cargo.toml
@@ -28,6 +28,12 @@ concat-vision = { workspace = true, features = ["infer"] }
# the detail.
png = "0.17"
ureq = "2"
+# The TLS ureq speaks, configured here to trust the system's roots beside
+# the shipped ones; see net.rs. The same rustls, ring and webpki-roots as
+# ureq's, so nothing is built twice.
+rustls = { version = "0.23", default-features = false, features = ["ring", "logging", "std", "tls12"] }
+webpki-roots = "0.26"
+rustls-native-certs = "0.8"
# A finished download is checked against the digest its table carries
# before anything is allowed to call it installed; see models.rs.
sha2 = "0.10"
diff --git a/src/crates/concat-host/src/lib.rs b/src/crates/concat-host/src/lib.rs
index 948a58aa..b9de87ff 100644
--- a/src/crates/concat-host/src/lib.rs
+++ b/src/crates/concat-host/src/lib.rs
@@ -34,6 +34,7 @@ pub mod machine;
pub mod media;
pub mod memory;
pub mod models;
+pub mod net;
pub mod playback;
pub mod preview;
pub mod projects;
diff --git a/src/crates/concat-host/src/models.rs b/src/crates/concat-host/src/models.rs
index 79654234..ca157adb 100644
--- a/src/crates/concat-host/src/models.rs
+++ b/src/crates/concat-host/src/models.rs
@@ -239,10 +239,10 @@ pub fn download(
// A read timeout: a stalled connection blocks in `read` with the
// cancel flag unreachable, and thirty seconds without a byte means
// the download is dead.
- let agent = ureq::AgentBuilder::new()
- .timeout_connect(std::time::Duration::from_secs(20))
- .timeout_read(std::time::Duration::from_secs(30))
- .build();
+ let agent = crate::net::agent(
+ std::time::Duration::from_secs(20),
+ std::time::Duration::from_secs(30),
+ );
let mut request = agent.get(url);
if already > 0 {
request = request.set("Range", &format!("bytes={already}-"));
diff --git a/src/crates/concat-host/src/net.rs b/src/crates/concat-host/src/net.rs
new file mode 100644
index 00000000..2228e71b
--- /dev/null
+++ b/src/crates/concat-host/src/net.rs
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// SPDX-FileCopyrightText: 2026 Jareer Abdullah and Concat contributors
+
+//! The one way the host reaches the network: models, sounds and update
+//! checks all go through [`agent`].
+//!
+//! An HTTPS connection is trusted when its certificate chains to a root
+//! Concat ships (Mozilla's list, as webpki-roots carries it) or to a root
+//! the system trusts. ureq trusted the shipped list alone, so a network that
+//! re-signs HTTPS with a root of its own - a proxy or a GitHub accelerator
+//! in China, an antivirus that scans HTTPS, a company's gateway - failed
+//! every download with "invalid peer certificate: UnknownIssuer", while
+//! the browser on the same machine, which trusts that root, worked (#517).
+//! ureq's own `native-certs` swaps the shipped list for the system's rather
+//! than adding to it, and Android gives a process no system store to read,
+//! so that would have failed every download on a phone instead.
+
+use std::sync::{Arc, OnceLock};
+use std::time::Duration;
+
+/// An agent with these timeouts that trusts the shipped roots and the
+/// system's.
+pub fn agent(connect: Duration, read: Duration) -> ureq::Agent {
+ ureq::AgentBuilder::new()
+ .timeout_connect(connect)
+ .timeout_read(read)
+ .tls_config(Arc::clone(tls()))
+ .build()
+}
+
+/// The TLS configuration every agent shares. Built once: reading the
+/// system's store takes a keychain query on macOS and a registry walk on
+/// Windows, which is not worth paying per request.
+fn tls() -> &'static Arc<rustls::ClientConfig> {
+ static CONFIG: OnceLock<Arc<rustls::ClientConfig>> = OnceLock::new();
+ CONFIG.get_or_init(|| {
+ // ring, as ureq builds its own default with: ureq turns that
+ // provider on, and naming it here does not depend on which
+ // provider the process installed as its default, if any.
+ let config = rustls::ClientConfig::builder_with_provider(
+ rustls::crypto::ring::default_provider().into(),
+ )
+ .with_protocol_versions(&[&rustls::version::TLS12, &rustls::version::TLS13])
+ .expect("ring offers cipher suites for TLS 1.2 and 1.3")
+ .with_root_certificates(roots())
+ .with_no_client_auth();
+ Arc::new(config)
+ })
+}
+
+/// The shipped roots, and the system's beside them.
+fn roots() -> rustls::RootCertStore {
+ let mut roots = rustls::RootCertStore {
+ roots: webpki_roots::TLS_SERVER_ROOTS.to_vec(),
+ };
+ let system = rustls_native_certs::load_native_certs();
+ // A store that cannot be read, in whole or part, leaves the shipped
+ // roots, which is where every download stood before.
+ if let Some(error) = system.errors.first() {
+ log::debug!("network: the system's root certificates were not all read: {error}");
+ }
+ let (added, _) = roots.add_parsable_certificates(system.certs);
+ log::debug!("network: {added} of the system's root certificates trusted beside Concat's");
+ roots
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// The shipped roots are always there, whatever the system's store
+ /// gave: a machine whose store is empty or unreadable is no worse off
+ /// than before.
+ #[test]
+ fn the_shipped_roots_are_always_trusted() {
+ assert!(roots().len() >= webpki_roots::TLS_SERVER_ROOTS.len());
+ // The configuration is whole: a connection can be started on it.
+ // The name is never looked up.
+ let name = rustls::pki_types::ServerName::try_from("github.com").expect("a valid name");
+ assert!(rustls::ClientConnection::new(Arc::clone(tls()), name).is_ok());
+ }
+}
diff --git a/src/crates/concat-host/src/sounds.rs b/src/crates/concat-host/src/sounds.rs
index 41b625ea..7e3814be 100644
--- a/src/crates/concat-host/src/sounds.rs
+++ b/src/crates/concat-host/src/sounds.rs
@@ -382,10 +382,10 @@ pub fn cached_catalogue(dirs: &AppDirs) -> Option<Catalogue> {
/// error.
pub fn fetch_catalogue(dirs: &AppDirs) -> Result<Option<Catalogue>, String> {
use std::io::Read;
- let agent = ureq::AgentBuilder::new()
- .timeout_connect(std::time::Duration::from_secs(15))
- .timeout_read(std::time::Duration::from_secs(30))
- .build();
+ let agent = crate::net::agent(
+ std::time::Duration::from_secs(15),
+ std::time::Duration::from_secs(30),
+ );
let response = match agent.get(crate::models::SOUNDS_MANIFEST).call() {
Ok(response) => response,
Err(ureq::Error::Status(404, _)) => return Ok(None),
diff --git a/src/crates/concat-host/src/updates.rs b/src/crates/concat-host/src/updates.rs
index 714ca6ad..8901bf84 100644
--- a/src/crates/concat-host/src/updates.rs
+++ b/src/crates/concat-host/src/updates.rs
@@ -669,10 +669,10 @@ fn detach(command: &mut Command) -> Result<(), String> {
/// One GET, read whole as text. GitHub wants a user agent and says so with
/// a 403 otherwise.
fn get_text(url: &str) -> Result<String, String> {
- let agent = ureq::AgentBuilder::new()
- .timeout_connect(std::time::Duration::from_secs(20))
- .timeout_read(std::time::Duration::from_secs(30))
- .build();
+ let agent = crate::net::agent(
+ std::time::Duration::from_secs(20),
+ std::time::Duration::from_secs(30),
+ );
let response = agent
.get(url)
.set("User-Agent", &format!("Concat/{}", Version::current()))