From 30c92efc72b1cb34a4d74359294ac3c05aa95732 Mon Sep 17 00:00:00 2001 From: mnovak Date: Tue, 17 Nov 2026 12:27:33 +0100 Subject: [PATCH] [agent] Tests: a TLS 1.3 client-certificate refusal may arrive as the alert or the reset after it --- crates/agent/tests/e2e.rs | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/crates/agent/tests/e2e.rs b/crates/agent/tests/e2e.rs index fc43ca5..c9142f0 100644 --- a/crates/agent/tests/e2e.rs +++ b/crates/agent/tests/e2e.rs @@ -199,6 +199,28 @@ fn an_expired_server_certificate_is_refused() { assert!(old.world.lock().unwrap().requests.is_empty()); } +/// The server refused our client certificate in the TLS handshake. With TLS 1.3 the client may +/// already have sent its request, so it sees either the alert or the reset that follows it. +fn handshake_refused(e: &AgentError) -> bool { + use legatus::http::HttpError; + match e { + AgentError::Client(ClientError::Http(HttpError::Tls(_))) => true, + AgentError::Client(ClientError::Http(HttpError::Protocol(m))) => { + let m = m.to_lowercase(); + [ + "reset", + "forcibly closed", + "closed early", + "broken pipe", + "aborted", + ] + .iter() + .any(|w| m.contains(w)) + } + _ => false, + } +} + /// Replace the agent's certificate and key in its state (what an attacker with old or foreign /// credentials would present). fn swap_identity(st: &State, chain: &str, key: &str) { @@ -218,13 +240,7 @@ fn a_foreign_client_certificate_is_refused() { .unwrap() .hello(&target) .unwrap_err(); - assert!( - matches!( - e, - AgentError::Client(ClientError::Http(legatus::http::HttpError::Tls(_))) - ), - "{e:?}" - ); + assert!(handshake_refused(&e), "{e:?}"); // A phone's device certificate from our own root: through TLS, refused by the registry. let dev = domi_pki::issue_device(&s.ca.ianitor, "phone", now()).unwrap(); swap_identity(&st, &dev.chain_pem, &dev.key_pem); @@ -250,13 +266,7 @@ fn an_expired_client_certificate_is_refused() { .unwrap() .hello(&FakeTarget::new()) .unwrap_err(); - assert!( - matches!( - e, - AgentError::Client(ClientError::Http(legatus::http::HttpError::Tls(_))) - ), - "{e:?}" - ); + assert!(handshake_refused(&e), "{e:?}"); } #[test]