[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:
2026-11-07 22:55:37 +01:00
parent 3d8f524d00
commit a5190acc3b
7 changed files with 213 additions and 16 deletions
+24 -3
View File
@@ -220,9 +220,10 @@ impl ClientCertVerifier for DeviceVerifier {
}
fn client_auth_mandatory(&self) -> bool {
// A missing certificate is a 403 from the proxy, like Caddy's route, not a failed
// handshake.
false
// Only asked when a certificate was requested, i.e. on a device host: there a
// handshake without one fails, as with Caddy (its allow-list check refuses an empty
// certificate list in the handshake too).
self.current().is_some()
}
fn root_hint_subjects(&self) -> &[rustls::DistinguishedName] {
@@ -276,3 +277,23 @@ impl ClientCertVerifier for DeviceVerifier {
fn same_names(a: &[rustls::DistinguishedName], b: &[rustls::DistinguishedName]) -> bool {
a.len() == b.len() && a.iter().zip(b).all(|(x, y)| x.as_ref() == y.as_ref())
}
/// The server name a TLS connection was opened for, kept in the connection's digest so the
/// proxy can compare it with the `Host` header.
#[derive(Debug, Clone)]
pub struct ConnSni(pub Option<String>);
/// Records [`ConnSni`] when a handshake completes.
pub struct SniRecorder;
#[async_trait::async_trait]
impl pingora::listeners::TlsAccept for SniRecorder {
async fn handshake_complete_callback(
&self,
tls: &pingora::protocols::tls::TlsRef,
) -> Option<Arc<dyn std::any::Any + Send + Sync>> {
Some(Arc::new(ConnSni(
tls.server_name().map(|s| s.to_ascii_lowercase()),
)))
}
}