[agent] Tests: a TLS 1.3 client-certificate refusal may arrive as the alert or the reset after it
This commit is contained in:
+24
-14
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user