Skip to content

Commit

Permalink
fork tls-parser into code needed to parse boring client hello
Browse files Browse the repository at this point in the history
Closes #281
  • Loading branch information
GlenDC committed Aug 18, 2024
1 parent 255121b commit d981548
Show file tree
Hide file tree
Showing 11 changed files with 669 additions and 664 deletions.
203 changes: 27 additions & 176 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ hyper = "1.4"
hyper-util = "0.1.6"
boring = "4.9.1"
tokio-boring = "4.9.1"
tls-parser = { git = "https://github.com/glendc/tls-parser.git", branch = "feat/more-public-parsers" }
ipnet = "2.9.0"
itertools = "0.13.0"
mime = "0.3.17"
Expand All @@ -48,6 +47,7 @@ proc-macro2 = "1.0"
opentelemetry = { version = "0.24", default-features = false, features = [
"trace",
] }
nom = "7.1.3"
opentelemetry-otlp = { version = "0.17", features = [ "tokio" ] }
opentelemetry_sdk = { version = "0.24", default-features = false, features = [
"trace",
Expand Down Expand Up @@ -126,7 +126,7 @@ telemetry = [
]
compression = ["dep:async-compression"]
rustls-ring = ["tokio-rustls/ring", "rustls/ring"]
boring = ["dep:boring", "dep:tokio-boring", "dep:tls-parser"]
boring = ["dep:boring", "dep:tokio-boring"]

[build-dependencies]
rustversion = { workspace = true }
Expand Down Expand Up @@ -162,6 +162,7 @@ ipnet = { workspace = true }
iri-string = { workspace = true }
mime = { workspace = true }
mime_guess = { workspace = true }
nom = { workspace = true }
opentelemetry = { workspace = true, optional = true }
opentelemetry-semantic-conventions = { workspace = true, optional = true }
opentelemetry_sdk = { workspace = true, optional = true }
Expand All @@ -181,7 +182,6 @@ serde = { workspace = true, features = ["derive"] }
serde_html_form = { workspace = true }
serde_json = { workspace = true }
sync_wrapper = { workspace = true }
tls-parser = { workspace = true, optional = true }
tokio = { workspace = true, features = ["macros", "fs", "io-std"] }
tokio-boring = { workspace = true, optional = true }
tokio-graceful = { workspace = true }
Expand Down
27 changes: 10 additions & 17 deletions rama-cli/src/cmd/fp/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,13 @@ pub(super) fn get_http_info(req: &Request) -> HttpInfo {
#[derive(Debug, Clone, Serialize)]
pub(super) struct TlsDisplayInfo {
pub(super) cipher_suites: Vec<String>,
pub(super) compression_algorithms: Vec<String>,
pub(super) extensions: Vec<TlsDisplayInfoExtension>,
}

#[derive(Debug, Clone, Serialize)]
pub(super) struct TlsDisplayInfoExtension {
pub(super) id: String,
pub(super) name: Option<&'static str>,
pub(super) name_alt: Option<&'static str>,
pub(super) data: TlsDisplayInfoExtensionData,
}

Expand All @@ -233,62 +232,56 @@ pub(super) fn get_tls_display_info(ctx: &Context<State>) -> Option<TlsDisplayInf
.iter()
.map(|s| s.to_string())
.collect::<Vec<_>>(),
compression_algorithms: hello
.compression_algorithms()
.iter()
.map(|s| s.to_string())
.collect::<Vec<_>>(),
extensions: hello
.extensions()
.iter()
.map(|extension| match extension {
ClientHelloExtension::ServerName(domain) => TlsDisplayInfoExtension {
id: extension.id().to_string(),
name: Some("servername"),
name_alt: Some("SNI"),
data: TlsDisplayInfoExtensionData::Single(domain.to_string()),
data: TlsDisplayInfoExtensionData::Single(match domain {
Some(domain) => domain.to_string(),
None => "".to_owned(),
}),
},
ClientHelloExtension::SignatureAlgorithms(v) => TlsDisplayInfoExtension {
id: extension.id().to_string(),
name: Some("signature algorithms"),
name_alt: None,
data: TlsDisplayInfoExtensionData::Multi(
v.iter().map(|s| s.to_string()).collect(),
),
},
ClientHelloExtension::SupportedVersions(v) => TlsDisplayInfoExtension {
id: extension.id().to_string(),
name: Some("supported versions"),
name_alt: None,
data: TlsDisplayInfoExtensionData::Multi(
v.iter().map(|s| s.to_string()).collect(),
),
},
ClientHelloExtension::ApplicationLayerProtocolNegotiation(v) => {
TlsDisplayInfoExtension {
id: extension.id().to_string(),
name: Some("application layer protocol negotation"),
name_alt: Some("ALPN"),
data: TlsDisplayInfoExtensionData::Multi(
v.iter().map(|s| s.to_string()).collect(),
),
}
}
ClientHelloExtension::SupportedGroups(v) => TlsDisplayInfoExtension {
id: extension.id().to_string(),
name: Some("supported groups"),
name_alt: None,
data: TlsDisplayInfoExtensionData::Multi(
v.iter().map(|s| s.to_string()).collect(),
),
},
ClientHelloExtension::ECPointFormats(v) => TlsDisplayInfoExtension {
id: extension.id().to_string(),
name: Some("EC point formats"),
name_alt: None,
data: TlsDisplayInfoExtensionData::Multi(
v.iter().map(|s| s.to_string()).collect(),
),
},
ClientHelloExtension::Opaque { id, data } => TlsDisplayInfoExtension {
id: id.to_string(),
name: None,
name_alt: None,
data: TlsDisplayInfoExtensionData::Single(if data.is_empty() {
"EMPTY".to_owned()
} else {
Expand Down
34 changes: 17 additions & 17 deletions rama-cli/src/cmd/fp/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,27 +473,27 @@ impl From<TlsDisplayInfo> for Vec<Table> {
let mut vec = Vec::with_capacity(info.extensions.len() + 1);
vec.push(Table {
title: "🔒 TLS Client Hello — Header".to_owned(),
rows: vec![("Cipher Suites".to_owned(), info.cipher_suites.join(", "))],
rows: vec![
("Cipher Suites".to_owned(), info.cipher_suites.join(", ")),
(
"Compression Algorithms".to_owned(),
info.compression_algorithms.join(", "),
),
],
});
for extension in info.extensions {
let mut rows = Vec::with_capacity(4);
rows.push(("ID".to_owned(), extension.id));
if let Some(name) = extension.name {
rows.push(("Name".to_owned(), name.to_owned()));
}
if let Some(name_alt) = extension.name_alt {
rows.push(("Name (Alt)".to_owned(), name_alt.to_owned()));
}
rows.push((
"Data".to_owned(),
match extension.data {
TlsDisplayInfoExtensionData::Single(s) => s,
TlsDisplayInfoExtensionData::Multi(v) => v.join(", "),
},
));
vec.push(Table {
title: "🔒 TLS Client Hello — Extension".to_owned(),
rows,
rows: vec![
("ID".to_owned(), extension.id),
(
"Data".to_owned(),
match extension.data {
TlsDisplayInfoExtensionData::Single(s) => s,
TlsDisplayInfoExtensionData::Multi(v) => v.join(", "),
},
),
],
});
}
vec
Expand Down
2 changes: 2 additions & 0 deletions src/cli/service/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ impl Service<(), Request> for EchoService {
json!({
"cipher_suites": hello
.cipher_suites().iter().map(|s| s.to_string()).collect::<Vec<_>>(),
"compression_algorithms": hello
.compression_algorithms().iter().map(|s| s.to_string()).collect::<Vec<_>>(),
"extensions": hello.extensions().iter().map(|extension| match extension {
ClientHelloExtension::ServerName(domain) => json!({
"id": extension.id().to_string(),
Expand Down
Loading

0 comments on commit d981548

Please sign in to comment.