Skip to content

Commit b7fa502

Browse files
committed
feat(tls): add SNI to SslDigest
This adds the SNI (Server Name Indication) to the SslDigest struct, making it accessible in the HTTP filter context via session.digest(). The SNI is extracted during TLS handshake for the boringssl/openssl backend. The rustls and s2n backends pass None for now and can be extended in future work. Users can now access the SNI in their request_filter callback: if let Some(digest) = session.digest() { if let Some(ssl_digest) = &digest.ssl_digest { if let Some(sni) = &ssl_digest.sni { // Use SNI for routing/validation logic } } } Fixes #547
1 parent c0845a8 commit b7fa502

4 files changed

Lines changed: 17 additions & 2 deletions

File tree

pingora-core/src/protocols/tls/boringssl_openssl/stream.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,11 @@ impl SslDigest {
209209
None => (Vec::new(), None, None),
210210
};
211211

212-
SslDigest::new(cipher, ssl.version_str(), org, sn, cert_digest)
212+
let sni = ssl
213+
.servername(ssl::NameType::HOST_NAME)
214+
.map(ToOwned::to_owned);
215+
216+
SslDigest::new(cipher, ssl.version_str(), org, sn, cert_digest, sni)
213217
}
214218
}
215219

pingora-core/src/protocols/tls/digest.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ pub struct SslDigest {
3131
pub serial_number: Option<String>,
3232
/// The digest of the peer's certificate
3333
pub cert_digest: Vec<u8>,
34+
/// The SNI used during the TLS handshake
35+
pub sni: Option<String>,
3436
/// The user-defined TLS data
3537
pub extension: SslDigestExtension,
3638
}
@@ -43,6 +45,7 @@ impl SslDigest {
4345
organization: Option<String>,
4446
serial_number: Option<String>,
4547
cert_digest: Vec<u8>,
48+
sni: Option<String>,
4649
) -> Self
4750
where
4851
S: Into<Cow<'static, str>>,
@@ -53,6 +56,7 @@ impl SslDigest {
5356
organization,
5457
serial_number,
5558
cert_digest,
59+
sni,
5660
extension: SslDigestExtension::default(),
5761
}
5862
}

pingora-core/src/protocols/tls/rustls/stream.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,10 @@ impl SslDigest {
390390
.map(|(organization, serial)| (organization, Some(serial)))
391391
.unwrap_or_default();
392392

393-
SslDigest::new(cipher, version, organization, serial_number, cert_digest)
393+
// SNI extraction not yet implemented for rustls
394+
let sni = None;
395+
396+
SslDigest::new(cipher, version, organization, serial_number, cert_digest, sni)
394397
}
395398
}
396399

pingora-core/src/protocols/tls/s2n/stream.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,16 @@ impl SslDigest {
307307
}
308308
}
309309

310+
// SNI extraction not yet implemented for s2n
311+
let sni = None;
312+
310313
SslDigest::new(
311314
cipher,
312315
version,
313316
organization,
314317
serial_number,
315318
cert_digest.unwrap_or_default(),
319+
sni,
316320
)
317321
}
318322
}

0 commit comments

Comments
 (0)