[edge] Device certificates as Caddy does them: no certificate on a device host fails the handshake, a Host other than the SNI name is 421; diff corpus gains six device cases
This commit is contained in:
@@ -131,6 +131,13 @@ impl ProxyHttp for EdgeProxy {
|
||||
let rt = self.shared.current();
|
||||
ctx.rt = Some(rt.clone());
|
||||
ctx.host_header = host_header(session.req_header());
|
||||
if rt.device_trust.is_some() && sni_mismatch(session, &hostname(&ctx.host_header)) {
|
||||
// Like Caddy once client certificates are configured: a request for another host
|
||||
// than the one the TLS connection was opened for is refused, so a connection
|
||||
// that was never asked for a certificate cannot reach a device host.
|
||||
respond_empty(session, 421).await?;
|
||||
return Ok(true);
|
||||
}
|
||||
let Some(host) = rt.host(&hostname(&ctx.host_header)).cloned() else {
|
||||
respond_empty(session, 404).await?;
|
||||
return Ok(true);
|
||||
@@ -419,6 +426,18 @@ impl EdgeProxy {
|
||||
}
|
||||
}
|
||||
|
||||
/// Was this TLS connection opened (by SNI) for another host than the request names?
|
||||
fn sni_mismatch(session: &Session, host: &str) -> bool {
|
||||
let Some(s) = session.digest().and_then(|d| d.ssl_digest.as_ref()) else {
|
||||
return false;
|
||||
};
|
||||
match s.extension.get::<crate::tls::ConnSni>() {
|
||||
Some(crate::tls::ConnSni(Some(sni))) => sni != host,
|
||||
// TLS without a recorded name: refuse rather than guess.
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// Did this connection present a device certificate that the current config allows? The
|
||||
/// handshake already checked the chain and the list; this checks again against the runtime
|
||||
/// serving the request, so a revocation also ends requests on connections made before it.
|
||||
|
||||
Reference in New Issue
Block a user