Skip to content

Commit 7f8d895

Browse files
nesquenaclaude
andauthored
Probes: trust OS-installed CAs — union webpki baseline with the native trust store (#73)
Test Connection (and every conn/health probe) verified TLS against the bundled Mozilla roots only, so servers behind enterprise/internal CAs (corporate PKI, Caddy Local Authority) that the OS trusts reported 'Unreachable' even though the system webview loads them fine (#60). health.rs now builds the probe agent from a cached rustls ClientConfig whose root store is the UNION of the webpki baseline and the OS trust store (rustls-native-certs). Strictly additive: everything that verified before still verifies, a broken/empty OS store degrades to exactly the old behavior (unlike ureq's own native-certs feature, which substitutes and can fail open to an empty store), and verification is never skipped (the declined PR #59 approach). Provider/protocol construction mirrors ureq's rtls.rs (explicit ring provider). Tests: union-property guard (roots never below webpki baseline), config build guard, and an #[ignore]d live-network round-trip for manual runs. Closes #60 Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 1d8c80f commit 7f8d895

4 files changed

Lines changed: 108 additions & 9 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Changelog
22

3+
## [v0.6.9]
4+
5+
### Fixed
6+
7+
- **"Test Connection" (and all connection probes) now trust enterprise and
8+
internal CAs installed in the OS trust store.** The Rust-side probes
9+
verified TLS against the bundled Mozilla root store only, so a server
10+
behind a corporate PKI or an internal CA (e.g. Caddy Local Authority) that
11+
the OS trusts — and that the webview itself happily loads — reported
12+
"✗ Unreachable". Probes now verify against the union of the bundled roots
13+
and the OS trust store: strictly additive, so every certificate that
14+
verified before still does, and certificate verification is never skipped
15+
or weakened. (#60, reported by ycj; supersedes the declined
16+
disable-verification approach from PR #59.)
17+
318
## [v0.6.8] — 2026-06-30
419

520
### Fixed

‎src-tauri/Cargo.lock‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src-tauri/Cargo.toml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ serde = { version = "1", features = ["derive"] }
2525
serde_json = "1"
2626
log = "0.4"
2727
ureq = "2"
28+
# Probe TLS trust (issue #60): health.rs unions the webpki baseline with the
29+
# OS trust store so enterprise/internal CAs verify like they do in the system
30+
# webview. Versions/features track what ureq 2.x already pulls in.
31+
rustls = { version = "0.23", default-features = false, features = ["ring", "logging", "std", "tls12"] }
32+
webpki-roots = "0.26"
33+
rustls-native-certs = "0.8"
2834
arboard = "3"
2935
image = { version = "0.25", default-features = false, features = ["png"] }
3036
base64 = "0.22"

‎src-tauri/src/health.rs‎

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,62 @@
22
//! GET (never HEAD — servers may 405/501 it), and ANY HTTP response —
33
//! including 4xx/5xx — counts as reachable; only transport errors fail.
44
5+
use std::sync::{Arc, OnceLock};
56
use std::time::Duration;
67

7-
pub fn http_reachable(url: &str, timeout: Duration) -> bool {
8-
let agent = ureq::AgentBuilder::new()
8+
/// Probe TLS roots: the bundled Mozilla store UNIONed with the OS trust
9+
/// store. ureq's default is webpki-roots alone, which rejects
10+
/// enterprise/internal CAs the user's OS trusts — the system webview
11+
/// (WKWebView/WebView2/WebKitGTK) verifies against the OS store, so the page
12+
/// loads fine while Test Connection said "Unreachable" (issue #60). The union
13+
/// is deliberately additive-only: everything that verified before still
14+
/// verifies, and a broken/empty OS store can never make things worse than
15+
/// the webpki baseline (ureq's own `native-certs` feature REPLACES the
16+
/// baseline and fails open to an empty store — not acceptable here).
17+
/// Certificate verification itself is never skipped (the closed PR #59
18+
/// approach).
19+
fn probe_roots() -> rustls::RootCertStore {
20+
let mut roots = rustls::RootCertStore {
21+
roots: webpki_roots::TLS_SERVER_ROOTS.to_vec(),
22+
};
23+
let baseline = roots.roots.len();
24+
let native = rustls_native_certs::load_native_certs();
25+
for e in &native.errors {
26+
log::warn!("probe tls: OS trust store: {e}");
27+
}
28+
let (added, unparsable) = roots.add_parsable_certificates(native.certs);
29+
log::info!("probe tls: {baseline} webpki roots + {added} OS roots ({unparsable} unparsable)");
30+
roots
31+
}
32+
33+
fn probe_tls_config() -> Arc<rustls::ClientConfig> {
34+
static CONFIG: OnceLock<Arc<rustls::ClientConfig>> = OnceLock::new();
35+
CONFIG
36+
.get_or_init(|| {
37+
// Mirror ureq's own construction (rtls.rs): explicit ring provider
38+
// so an ambiguous process-wide default can never panic the build.
39+
let config = rustls::ClientConfig::builder_with_provider(
40+
rustls::crypto::ring::default_provider().into(),
41+
)
42+
.with_protocol_versions(&[&rustls::version::TLS12, &rustls::version::TLS13])
43+
.expect("ring provider supports TLS 1.2 + 1.3")
44+
.with_root_certificates(probe_roots())
45+
.with_no_client_auth();
46+
Arc::new(config)
47+
})
48+
.clone()
49+
}
50+
51+
fn agent(timeout: Duration) -> ureq::Agent {
52+
ureq::AgentBuilder::new()
53+
.tls_config(probe_tls_config())
954
.timeout_connect(timeout)
1055
.timeout(timeout)
11-
.build();
12-
match agent.get(url).call() {
56+
.build()
57+
}
58+
59+
pub fn http_reachable(url: &str, timeout: Duration) -> bool {
60+
match agent(timeout).get(url).call() {
1361
Ok(_) => true,
1462
// An HTTP status error still means the round-trip completed.
1563
Err(ureq::Error::Status(_, _)) => true,
@@ -30,11 +78,7 @@ pub fn http_reachable(url: &str, timeout: Duration) -> bool {
3078
/// upstream-unavailable gateway codes are rejected. Transport errors = not
3179
/// ready, as before.
3280
pub fn http_ready(url: &str, timeout: Duration) -> bool {
33-
let agent = ureq::AgentBuilder::new()
34-
.timeout_connect(timeout)
35-
.timeout(timeout)
36-
.build();
37-
match agent.get(url).call() {
81+
match agent(timeout).get(url).call() {
3882
Ok(_) => true,
3983
Err(ureq::Error::Status(code, _)) => ready_from_status(code),
4084
Err(_) => false,
@@ -90,4 +134,35 @@ mod tests {
90134
assert_eq!(health_url("http://h:8787"), "http://h:8787/health");
91135
assert_eq!(health_url("http://h:8787/"), "http://h:8787/health");
92136
}
137+
138+
#[test]
139+
fn probe_roots_never_shrink_below_webpki_baseline() {
140+
// The union property behind the issue-#60 fix: OS roots are ADDED to
141+
// the webpki baseline, never substituted for it. A broken/empty OS
142+
// store must degrade to exactly the old behavior, not to no roots
143+
// (which is ureq's own `native-certs` failure mode).
144+
let roots = probe_roots();
145+
assert!(
146+
roots.roots.len() >= webpki_roots::TLS_SERVER_ROOTS.len(),
147+
"probe roots ({}) fell below the webpki baseline ({})",
148+
roots.roots.len(),
149+
webpki_roots::TLS_SERVER_ROOTS.len()
150+
);
151+
}
152+
153+
#[test]
154+
fn probe_tls_config_builds() {
155+
// Guards the provider/protocol construction (would panic here, not in
156+
// a user's Test Connection click).
157+
let _ = probe_tls_config();
158+
}
159+
160+
#[test]
161+
#[ignore = "network: manual sanity check that the union store verifies a live public host"]
162+
fn probe_live_https_roundtrip() {
163+
assert!(http_reachable(
164+
"https://github.com",
165+
Duration::from_secs(10)
166+
));
167+
}
93168
}

0 commit comments

Comments
 (0)