From 91322d87bdd983ed7c5ddd8dce9c013e07626ac3 Mon Sep 17 00:00:00 2001 From: kanywst <45947799+kanywst@users.noreply.github.com> Date: Sun, 15 Nov 2026 23:24:24 +0900 Subject: [PATCH 1/4] feat(wan): blame a clock that is behind instead of the network --- Cargo.lock | 1 + Cargo.toml | 2 + README.md | 2 +- src/diagnose.rs | 22 +++++++++ src/model/path.rs | 5 +++ src/probe/wan.rs | 112 +++++++++++++++++++++++++++++++++++++++------- 6 files changed, 126 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d5a2193..d2f141e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3239,6 +3239,7 @@ dependencies = [ "objc2-foundation", "ratatui", "reqwest", + "rustls", "serde", "serde_json", "tokio", diff --git a/Cargo.toml b/Cargo.toml index 36dbf3d..26f701c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,8 @@ color-eyre = "0.6" # probes hickory-resolver = "0.26" reqwest = { version = "0.12", default-features = false, features = ["rustls-tls"] } +# only to read the certificate error out of a failed reqwest request +rustls = { version = "0.23", default-features = false } # cli + serialization clap = { version = "4", features = ["derive"] } serde = { version = "1", features = ["derive"] } diff --git a/README.md b/README.md index 0db5c79..1436db7 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ complete: rate, graded into a signal quality. 3. **L3 Gateway** — resolves the default route and sends a short ICMP burst to the router, measuring RTT, packet loss and jitter, and flagging VPN/tunnel interfaces and sub-1500 MTU. 4. **Uplink** — when, and only when, something upstream is already broken, a bounded ICMP TTL sweep turns the single edge between your gateway and the internet back into hops. Where the replies stop decides whether the break is on your own line (modem/ONU, WAN cable) or inside your ISP's network — and names the last address that answered, so you have something to quote. -5. **WAN** — real TCP handshakes to three independent anycast operators (Cloudflare, Google, Quad9) over IPv4 and IPv6, which exposes asymmetric blackholing without needing raw ICMP and separates "the internet is unreachable" from "this network blocks that address". It then repeats the handshake against the quickest one to measure loss and jitter on the uplink itself. +5. **WAN** — real TCP handshakes to three independent anycast operators (Cloudflare, Google, Quad9) over IPv4 and IPv6, which exposes asymmetric blackholing without needing raw ICMP and separates "the internet is unreachable" from "this network blocks that address". It then repeats the handshake against the quickest one to measure loss and jitter on the uplink itself. One real HTTPS request checks that the handshakes carry traffic; when it is refused because the certificate isn't valid yet, the verdict blames this machine's clock instead of the network. 6. **DNS** — benchmarks the system resolver against Cloudflare and Google to separate "DNS is down" from "your resolver is just slow". 7. **Captive portal** — a plain-HTTP hotspot check that catches login-page diff --git a/src/diagnose.rs b/src/diagnose.rs index ccb8efc..e22b702 100644 --- a/src/diagnose.rs +++ b/src/diagnose.rs @@ -484,6 +484,11 @@ fn explain_warn(path: &Path, id: HopId) -> Verdict { // diagram cannot show you, so the verdict has to say it in words. // Ahead of both arms below: "the path carries nothing" outranks "the // path is lossy" and "the path is filtered". + HopId::Wan if path.get(id).and_then(|h| h.fault) == Some(Fault::ClockBehind) => ( + "Your clock is behind", + format!("{summary}. Every HTTPS site will refuse to connect until the date and time are right; the network itself is fine."), + Some("Turn on automatic date and time (NTP) and run again. Devices without a battery-backed clock, like a Raspberry Pi, lose the time on every power cut.".to_string()), + ), HopId::Wan if path.get(id).and_then(|h| h.fault) == Some(Fault::HandshakeOnly) => ( "Something is answering for the internet", "Every connection completes, but no real request does. A device on the path is replying to handshakes without carrying the traffic — an interception appliance, a misbehaving proxy, or a portal you haven't signed in to.".to_string(), @@ -963,6 +968,23 @@ mod tests { assert!(v.fix.as_deref().unwrap().contains("sign-in page")); } + #[test] + fn a_clock_behind_is_blamed_on_the_clock_not_the_network() { + let mut wan = hop(HopId::Wan, Layer::Internet, Status::Warn); + wan.fault = Some(Fault::ClockBehind); + let p = Path { + hops: vec![ + hop(HopId::Host, Layer::Link, Status::Ok), + hop(HopId::Link, Layer::Link, Status::Ok), + hop(HopId::Gateway, Layer::Network, Status::Ok), + wan, + ], + }; + let v = diagnose(&p); + assert!(v.headline.contains("clock"), "{}", v.headline); + assert!(v.fix.as_deref().unwrap().contains("NTP")); + } + /// The verdict this whole hop exists to replace. "Your ISP / uplink is /// down — check the modem lights" is the part the reader already knew; /// once the sweep has located the break, the verdict has to use it. diff --git a/src/model/path.rs b/src/model/path.rs index 20e2b7b..179232b 100644 --- a/src/model/path.rs +++ b/src/model/path.rs @@ -92,6 +92,9 @@ pub enum Fault { /// Every TCP handshake completes, but no real request does — something on /// the path answers connections without carrying them. HandshakeOnly, + /// The HTTPS certificate is not yet valid by this machine's clock: the + /// clock is behind, so every TLS connection fails. + ClockBehind, /// The system resolver returned no answer. ResolverDead, /// The system resolver answers, but not truthfully — it synthesises @@ -121,6 +124,7 @@ impl Fault { Fault::NoInternet => "no_internet", Fault::TargetBlocked => "target_blocked", Fault::HandshakeOnly => "handshake_only", + Fault::ClockBehind => "clock_behind", Fault::ResolverDead => "resolver_dead", Fault::ResolverHijacked => "resolver_hijacked", Fault::PortalIntercept => "portal_intercept", @@ -467,6 +471,7 @@ mod tests { Fault::NoInternet, Fault::TargetBlocked, Fault::HandshakeOnly, + Fault::ClockBehind, Fault::ResolverDead, Fault::ResolverHijacked, Fault::PortalIntercept, diff --git a/src/probe/wan.rs b/src/probe/wan.rs index 47f8e29..1adb80f 100644 --- a/src/probe/wan.rs +++ b/src/probe/wan.rs @@ -119,6 +119,8 @@ struct Egress { /// works". A middlebox can complete a handshake to anything; it cannot /// produce Cloudflare's certificate. verified: bool, + /// The certificate was rejected as not yet valid, so this machine's clock is behind. + clock_behind: bool, } /// One family's results: which targets answered, and how fast. @@ -201,10 +203,7 @@ pub async fn probe() -> Hop { } } - hop.evidence = Some(evidence( - v4.reached.len() + v6.reached.len(), - egress.verified, - )); + hop.evidence = Some(evidence(v4.reached.len() + v6.reached.len(), &egress)); match (v4.any_up(), v6.any_up()) { (true, dual_stack) => { @@ -218,15 +217,25 @@ pub async fn probe() -> Hop { let quality = apply_quality(&mut hop, &q, JITTER_WARN_MS); let blocked = blocked_targets(&v4, &v6); let handshake_only = handshake_only(&v4, &v6, &egress); - hop.status = quality.max(block_status(&blocked)).max(if handshake_only { - Status::Warn - } else { - Status::Ok - }); + let clock_behind = !egress.verified && egress.clock_behind; + hop.status = + quality + .max(block_status(&blocked)) + .max(if handshake_only || clock_behind { + Status::Warn + } else { + Status::Ok + }); // Whichever finding is the more serious owns the code; a path that // answers handshakes but carries nothing is worse news than one // operator being filtered. - if handshake_only { + if clock_behind { + hop.fault = Some(Fault::ClockBehind); + hop.summary = Some(format!( + "The internet answers, but its HTTPS certificate isn't valid yet by this machine's clock ({})", + crate::history::utc(now_secs()) + )); + } else if handshake_only { hop.fault = Some(Fault::HandshakeOnly); hop.summary = Some( "Every handshake completes but no real request does — something is answering connections on the path without carrying them".into(), @@ -318,9 +327,10 @@ fn handshake_only(v4: &Family, v6: &Family, egress: &Egress) -> bool { /// One complete request through the uplink: the check that makes a green hop /// mean something, and the only place a public address can come from. async fn verify_egress() -> Egress { - let unverified = Egress { + let mut unverified = Egress { public_ip: None, verified: false, + clock_behind: false, }; let Ok(client) = reqwest::Client::builder().build() else { return unverified; @@ -337,8 +347,14 @@ async fn verify_egress() -> Egress { if left < MIN_TRACE { break; } - let Ok(resp) = client.get(url).timeout(left).send().await else { - continue; + let resp = match client.get(url).timeout(left).send().await { + Ok(resp) => resp, + Err(e) if not_yet_valid(&e) => { + // The by-name retry would be judged by the same clock. + unverified.clock_behind = true; + break; + } + Err(_) => continue, }; if !resp.status().is_success() { continue; @@ -352,12 +368,42 @@ async fn verify_egress() -> Egress { return Egress { public_ip: Some(ip), verified: true, + clock_behind: false, }; } } unverified } +/// Whether a failed request was refused because the certificate isn't valid yet. +fn not_yet_valid(err: &(dyn std::error::Error + 'static)) -> bool { + use rustls::{CertificateError, Error as TlsError}; + let mut cur = Some(err); + while let Some(e) = cur { + if let Some(TlsError::InvalidCertificate( + CertificateError::NotValidYet | CertificateError::NotValidYetContext { .. }, + )) = e.downcast_ref::() + { + return true; + } + // io::Error::source() skips the error it wraps, and hyper nests rustls two io::Errors deep. + cur = match e + .downcast_ref::() + .and_then(|io| io.get_ref()) + { + Some(inner) => Some(inner as &(dyn std::error::Error + 'static)), + None => e.source(), + }; + } + false +} + +fn now_secs() -> u64 { + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .map_or(0, |d| d.as_secs()) +} + /// Pull the `ip=` line out of a `cdn-cgi/trace` response. fn parse_trace(body: &str) -> Option { body.lines() @@ -402,12 +448,14 @@ fn block_status(blocked: &[&str]) -> Status { /// HTTPS request" was guaranteed to contradict the cause printed beside it /// whenever `HandshakeOnly` fired — in exactly the case the evidence matters /// most. -fn evidence(addresses: usize, verified: bool) -> String { +fn evidence(addresses: usize, egress: &Egress) -> String { format!( "{addresses} handshakes to :{PORT} across {} independent networks, and one HTTPS request that {}", operator_count(), - if verified { + if egress.verified { "completed" + } else if egress.clock_behind { + "was refused: certificate not yet valid" } else { "did not complete" } @@ -667,9 +715,39 @@ mod tests { Egress { public_ip: None, verified, + clock_behind: false, } } + #[test] + fn a_not_yet_valid_certificate_is_found_inside_the_io_error() { + use rustls::{CertificateError, Error as TlsError}; + let wrap = |c| { + std::io::Error::new( + std::io::ErrorKind::InvalidData, + TlsError::InvalidCertificate(c), + ) + }; + assert!(not_yet_valid(&wrap(CertificateError::NotValidYet))); + // The shape hyper actually returns: io::Error(Other) around io::Error(InvalidData) around rustls. + let nested = std::io::Error::other(wrap(CertificateError::NotValidYet)); + assert!(not_yet_valid(&nested)); + // Expired could be a real stale certificate on an interception box, not our clock. + assert!(!not_yet_valid(&wrap(CertificateError::Expired))); + assert!(!not_yet_valid(&wrap(CertificateError::UnknownIssuer))); + assert!(!not_yet_valid(&std::io::Error::other("timed out"))); + } + + #[test] + fn a_refused_certificate_is_said_so_in_the_evidence() { + let e = Egress { + public_ip: None, + verified: false, + clock_behind: true, + }; + assert!(evidence(5, &e).contains("not yet valid")); + } + fn all_up() -> Family { family(&[ ("Cloudflare", Some(12)), @@ -756,13 +834,13 @@ mod tests { let v6 = family(&[("Cloudflare v6", None), ("Google v6", None)]); assert!(handshake_only(&all_up(), &v6, &egress(false))); - let unverified = evidence(5, false); + let unverified = evidence(5, &egress(false)); assert!(unverified.contains("did not complete"), "got: {unverified}"); assert!( !unverified.contains("verified"), "must not read as a completed request: {unverified}" ); - assert!(evidence(5, true).contains("completed")); + assert!(evidence(5, &egress(true)).contains("completed")); } #[test] From 8c1d70edf5e4ef3caf6104dca1b17627119436e2 Mon Sep 17 00:00:00 2001 From: kanywst <45947799+kanywst@users.noreply.github.com> Date: Sun, 15 Nov 2026 23:27:01 +0900 Subject: [PATCH 2/4] fix(wan): report a behind clock on IPv6-only paths too --- src/probe/wan.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/probe/wan.rs b/src/probe/wan.rs index 1adb80f..06d0450 100644 --- a/src/probe/wan.rs +++ b/src/probe/wan.rs @@ -217,7 +217,7 @@ pub async fn probe() -> Hop { let quality = apply_quality(&mut hop, &q, JITTER_WARN_MS); let blocked = blocked_targets(&v4, &v6); let handshake_only = handshake_only(&v4, &v6, &egress); - let clock_behind = !egress.verified && egress.clock_behind; + let clock_behind = egress.clock_behind; hop.status = quality .max(block_status(&blocked)) @@ -231,10 +231,7 @@ pub async fn probe() -> Hop { // operator being filtered. if clock_behind { hop.fault = Some(Fault::ClockBehind); - hop.summary = Some(format!( - "The internet answers, but its HTTPS certificate isn't valid yet by this machine's clock ({})", - crate::history::utc(now_secs()) - )); + hop.summary = Some(clock_summary()); } else if handshake_only { hop.fault = Some(Fault::HandshakeOnly); hop.summary = Some( @@ -256,10 +253,15 @@ pub async fn probe() -> Hop { (false, true) => { hop.status = Status::Warn; hop.latency_ms = v6.best().and_then(|(_, _, p)| p.ms()); - hop.summary = Some(format!( - "IPv6-only reachable — all {} IPv4 targets are blackholed", - V4.len() - )); + if egress.clock_behind { + hop.fault = Some(Fault::ClockBehind); + hop.summary = Some(clock_summary()); + } else { + hop.summary = Some(format!( + "IPv6-only reachable — all {} IPv4 targets are blackholed", + V4.len() + )); + } } (false, false) => { // Every operator, on every family, independently silent. That is @@ -398,6 +400,13 @@ fn not_yet_valid(err: &(dyn std::error::Error + 'static)) -> bool { false } +fn clock_summary() -> String { + format!( + "The internet answers, but its HTTPS certificate isn't valid yet by this machine's clock ({})", + crate::history::utc(now_secs()) + ) +} + fn now_secs() -> u64 { std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) From c793521a5833494c9ce7f3be13ece794dd0e25e4 Mon Sep 17 00:00:00 2001 From: kanywst <45947799+kanywst@users.noreply.github.com> Date: Sun, 15 Nov 2026 23:30:34 +0900 Subject: [PATCH 3/4] fix(wan): require a day of clock lag and keep the IPv4 finding --- src/diagnose.rs | 2 +- src/probe/wan.rs | 92 +++++++++++++++++++++++++++++------------------- 2 files changed, 56 insertions(+), 38 deletions(-) diff --git a/src/diagnose.rs b/src/diagnose.rs index e22b702..7b203a4 100644 --- a/src/diagnose.rs +++ b/src/diagnose.rs @@ -486,7 +486,7 @@ fn explain_warn(path: &Path, id: HopId) -> Verdict { // path is lossy" and "the path is filtered". HopId::Wan if path.get(id).and_then(|h| h.fault) == Some(Fault::ClockBehind) => ( "Your clock is behind", - format!("{summary}. Every HTTPS site will refuse to connect until the date and time are right; the network itself is fine."), + format!("{summary}. Every HTTPS site will refuse to connect until the date and time are right."), Some("Turn on automatic date and time (NTP) and run again. Devices without a battery-backed clock, like a Raspberry Pi, lose the time on every power cut.".to_string()), ), HopId::Wan if path.get(id).and_then(|h| h.fault) == Some(Fault::HandshakeOnly) => ( diff --git a/src/probe/wan.rs b/src/probe/wan.rs index 06d0450..3f6e1ae 100644 --- a/src/probe/wan.rs +++ b/src/probe/wan.rs @@ -119,8 +119,8 @@ struct Egress { /// works". A middlebox can complete a handshake to anything; it cannot /// produce Cloudflare's certificate. verified: bool, - /// The certificate was rejected as not yet valid, so this machine's clock is behind. - clock_behind: bool, + /// How far behind this machine's clock is, when a certificate was refused as not yet valid. + clock_lag: Option, } /// One family's results: which targets answered, and how fast. @@ -217,7 +217,7 @@ pub async fn probe() -> Hop { let quality = apply_quality(&mut hop, &q, JITTER_WARN_MS); let blocked = blocked_targets(&v4, &v6); let handshake_only = handshake_only(&v4, &v6, &egress); - let clock_behind = egress.clock_behind; + let clock_behind = egress.clock_lag.is_some(); hop.status = quality .max(block_status(&blocked)) @@ -231,7 +231,7 @@ pub async fn probe() -> Hop { // operator being filtered. if clock_behind { hop.fault = Some(Fault::ClockBehind); - hop.summary = Some(clock_summary()); + hop.summary = Some(clock_summary(egress.clock_lag.unwrap_or_default())); } else if handshake_only { hop.fault = Some(Fault::HandshakeOnly); hop.summary = Some( @@ -253,15 +253,17 @@ pub async fn probe() -> Hop { (false, true) => { hop.status = Status::Warn; hop.latency_ms = v6.best().and_then(|(_, _, p)| p.ms()); - if egress.clock_behind { - hop.fault = Some(Fault::ClockBehind); - hop.summary = Some(clock_summary()); - } else { - hop.summary = Some(format!( - "IPv6-only reachable — all {} IPv4 targets are blackholed", - V4.len() - )); - } + let blackholed = format!( + "IPv6-only reachable — all {} IPv4 targets are blackholed", + V4.len() + ); + hop.summary = Some(match egress.clock_lag { + Some(lag) => { + hop.fault = Some(Fault::ClockBehind); + format!("{}; separately, {blackholed}", clock_summary(lag)) + } + None => blackholed, + }); } (false, false) => { // Every operator, on every family, independently silent. That is @@ -332,7 +334,7 @@ async fn verify_egress() -> Egress { let mut unverified = Egress { public_ip: None, verified: false, - clock_behind: false, + clock_lag: None, }; let Ok(client) = reqwest::Client::builder().build() else { return unverified; @@ -351,12 +353,14 @@ async fn verify_egress() -> Egress { } let resp = match client.get(url).timeout(left).send().await { Ok(resp) => resp, - Err(e) if not_yet_valid(&e) => { + Err(e) => { + unverified.clock_lag = clock_lag(&e); // The by-name retry would be judged by the same clock. - unverified.clock_behind = true; - break; + if unverified.clock_lag.is_some() { + break; + } + continue; } - Err(_) => continue, }; if !resp.status().is_success() { continue; @@ -370,23 +374,28 @@ async fn verify_egress() -> Egress { return Egress { public_ip: Some(ip), verified: true, - clock_behind: false, + clock_lag: None, }; } } unverified } -/// Whether a failed request was refused because the certificate isn't valid yet. -fn not_yet_valid(err: &(dyn std::error::Error + 'static)) -> bool { +/// A certificate only this far ahead of the clock is more likely freshly minted by an interceptor. +const MIN_CLOCK_LAG: u64 = 86_400; + +/// How far behind the clock is, when a request was refused for a certificate not yet valid. +fn clock_lag(err: &(dyn std::error::Error + 'static)) -> Option { use rustls::{CertificateError, Error as TlsError}; let mut cur = Some(err); while let Some(e) = cur { - if let Some(TlsError::InvalidCertificate( - CertificateError::NotValidYet | CertificateError::NotValidYetContext { .. }, - )) = e.downcast_ref::() + if let Some(TlsError::InvalidCertificate(CertificateError::NotValidYetContext { + time, + not_before, + })) = e.downcast_ref::() { - return true; + let lag = not_before.as_secs().saturating_sub(time.as_secs()); + return (lag >= MIN_CLOCK_LAG).then_some(lag); } // io::Error::source() skips the error it wraps, and hyper nests rustls two io::Errors deep. cur = match e @@ -397,12 +406,13 @@ fn not_yet_valid(err: &(dyn std::error::Error + 'static)) -> bool { None => e.source(), }; } - false + None } -fn clock_summary() -> String { +fn clock_summary(lag: u64) -> String { format!( - "The internet answers, but its HTTPS certificate isn't valid yet by this machine's clock ({})", + "The internet answers, but its HTTPS certificate isn't valid for another {} days by this machine's clock ({})", + lag.div_ceil(86_400), crate::history::utc(now_secs()) ) } @@ -463,7 +473,7 @@ fn evidence(addresses: usize, egress: &Egress) -> String { operator_count(), if egress.verified { "completed" - } else if egress.clock_behind { + } else if egress.clock_lag.is_some() { "was refused: certificate not yet valid" } else { "did not complete" @@ -724,12 +734,13 @@ mod tests { Egress { public_ip: None, verified, - clock_behind: false, + clock_lag: None, } } #[test] fn a_not_yet_valid_certificate_is_found_inside_the_io_error() { + use rustls::pki_types::UnixTime; use rustls::{CertificateError, Error as TlsError}; let wrap = |c| { std::io::Error::new( @@ -737,14 +748,21 @@ mod tests { TlsError::InvalidCertificate(c), ) }; - assert!(not_yet_valid(&wrap(CertificateError::NotValidYet))); + let at = |s: u64| UnixTime::since_unix_epoch(Duration::from_secs(s)); + let ahead = |lag: u64| CertificateError::NotValidYetContext { + time: at(1_000_000_000), + not_before: at(1_000_000_000 + lag), + }; // The shape hyper actually returns: io::Error(Other) around io::Error(InvalidData) around rustls. - let nested = std::io::Error::other(wrap(CertificateError::NotValidYet)); - assert!(not_yet_valid(&nested)); + let nested = std::io::Error::other(wrap(ahead(3 * 86_400))); + assert_eq!(clock_lag(&nested), Some(3 * 86_400)); + // Minutes ahead is an interceptor minting certificates, not our clock. + assert_eq!(clock_lag(&wrap(ahead(600))), None); + assert_eq!(clock_lag(&wrap(CertificateError::NotValidYet)), None); // Expired could be a real stale certificate on an interception box, not our clock. - assert!(!not_yet_valid(&wrap(CertificateError::Expired))); - assert!(!not_yet_valid(&wrap(CertificateError::UnknownIssuer))); - assert!(!not_yet_valid(&std::io::Error::other("timed out"))); + assert_eq!(clock_lag(&wrap(CertificateError::Expired)), None); + assert_eq!(clock_lag(&wrap(CertificateError::UnknownIssuer)), None); + assert_eq!(clock_lag(&std::io::Error::other("timed out")), None); } #[test] @@ -752,7 +770,7 @@ mod tests { let e = Egress { public_ip: None, verified: false, - clock_behind: true, + clock_lag: Some(86_400), }; assert!(evidence(5, &e).contains("not yet valid")); } From 0fa7993b11eb0f19679b53f298cff8df70fa155b Mon Sep 17 00:00:00 2001 From: kanywst <45947799+kanywst@users.noreply.github.com> Date: Sun, 15 Nov 2026 23:42:38 +0900 Subject: [PATCH 4/4] fix(wan): count an hour of clock lag, not a day --- src/probe/wan.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/probe/wan.rs b/src/probe/wan.rs index 3f6e1ae..d6f4627 100644 --- a/src/probe/wan.rs +++ b/src/probe/wan.rs @@ -382,7 +382,7 @@ async fn verify_egress() -> Egress { } /// A certificate only this far ahead of the clock is more likely freshly minted by an interceptor. -const MIN_CLOCK_LAG: u64 = 86_400; +const MIN_CLOCK_LAG: u64 = 3_600; /// How far behind the clock is, when a request was refused for a certificate not yet valid. fn clock_lag(err: &(dyn std::error::Error + 'static)) -> Option { @@ -411,8 +411,12 @@ fn clock_lag(err: &(dyn std::error::Error + 'static)) -> Option { fn clock_summary(lag: u64) -> String { format!( - "The internet answers, but its HTTPS certificate isn't valid for another {} days by this machine's clock ({})", - lag.div_ceil(86_400), + "The internet answers, but its HTTPS certificate isn't valid for another {} by this machine's clock ({})", + if lag >= 86_400 { + format!("{} days", lag.div_ceil(86_400)) + } else { + format!("{} hours", lag.div_ceil(3_600)) + }, crate::history::utc(now_secs()) ) } @@ -756,6 +760,8 @@ mod tests { // The shape hyper actually returns: io::Error(Other) around io::Error(InvalidData) around rustls. let nested = std::io::Error::other(wrap(ahead(3 * 86_400))); assert_eq!(clock_lag(&nested), Some(3 * 86_400)); + // An RTC kept in local time is hours off, not days. + assert_eq!(clock_lag(&wrap(ahead(9 * 3_600))), Some(9 * 3_600)); // Minutes ahead is an interceptor minting certificates, not our clock. assert_eq!(clock_lag(&wrap(ahead(600))), None); assert_eq!(clock_lag(&wrap(CertificateError::NotValidYet)), None);