[edge] Device certificates: mTLS on hosts with device_certs only (asked per SNI), chain to the Domi CA bundle and the allow list in the handshake, checked again per request; 403 without one
This commit is contained in:
@@ -137,6 +137,13 @@ impl ProxyHttp for EdgeProxy {
|
||||
};
|
||||
ctx.host = Some(host.clone());
|
||||
|
||||
if host.cfg.device_certs && !has_allowed_device_cert(session, &rt) {
|
||||
// No certificate on this connection (one that is presented but not allowed never
|
||||
// gets here: the handshake fails). Same as Caddy's route: 403, nothing upstream.
|
||||
respond_empty(session, 403).await?;
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
let mut shared_access = false;
|
||||
if !host.cfg.share_links {
|
||||
share::strip_any_token(session)?;
|
||||
@@ -412,6 +419,19 @@ impl EdgeProxy {
|
||||
}
|
||||
}
|
||||
|
||||
/// 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.
|
||||
fn has_allowed_device_cert(session: &Session, rt: &crate::runtime::Runtime) -> bool {
|
||||
let Some(trust) = rt.device_trust.as_ref() else {
|
||||
return false;
|
||||
};
|
||||
session
|
||||
.digest()
|
||||
.and_then(|d| d.ssl_digest.as_ref())
|
||||
.is_some_and(|s| !s.cert_digest.is_empty() && trust.allows(&s.cert_digest))
|
||||
}
|
||||
|
||||
pub fn contains(hay: &[u8], needle: &[u8]) -> bool {
|
||||
!needle.is_empty() && hay.windows(needle.len()).any(|w| w == needle)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user