[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());
|
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
|
/// Replace the agent's certificate and key in its state (what an attacker with old or foreign
|
||||||
/// credentials would present).
|
/// credentials would present).
|
||||||
fn swap_identity(st: &State, chain: &str, key: &str) {
|
fn swap_identity(st: &State, chain: &str, key: &str) {
|
||||||
@@ -218,13 +240,7 @@ fn a_foreign_client_certificate_is_refused() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.hello(&target)
|
.hello(&target)
|
||||||
.unwrap_err();
|
.unwrap_err();
|
||||||
assert!(
|
assert!(handshake_refused(&e), "{e:?}");
|
||||||
matches!(
|
|
||||||
e,
|
|
||||||
AgentError::Client(ClientError::Http(legatus::http::HttpError::Tls(_)))
|
|
||||||
),
|
|
||||||
"{e:?}"
|
|
||||||
);
|
|
||||||
// A phone's device certificate from our own root: through TLS, refused by the registry.
|
// 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();
|
let dev = domi_pki::issue_device(&s.ca.ianitor, "phone", now()).unwrap();
|
||||||
swap_identity(&st, &dev.chain_pem, &dev.key_pem);
|
swap_identity(&st, &dev.chain_pem, &dev.key_pem);
|
||||||
@@ -250,13 +266,7 @@ fn an_expired_client_certificate_is_refused() {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.hello(&FakeTarget::new())
|
.hello(&FakeTarget::new())
|
||||||
.unwrap_err();
|
.unwrap_err();
|
||||||
assert!(
|
assert!(handshake_refused(&e), "{e:?}");
|
||||||
matches!(
|
|
||||||
e,
|
|
||||||
AgentError::Client(ClientError::Http(legatus::http::HttpError::Tls(_)))
|
|
||||||
),
|
|
||||||
"{e:?}"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
Reference in New Issue
Block a user