Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tls debugging diff viewer #2

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ debug = true

[profile.release]
debug = true

[patch.crates-io]
rustls = { path = "./patches/rustls/rustls" }
Empty file added log
Empty file.
1 change: 1 addition & 0 deletions patches/rustls
Submodule rustls added at cf6aa8
12 changes: 10 additions & 2 deletions quinn-proto/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1867,13 +1867,21 @@ impl Connection {
}

fn init_0rtt(&mut self) {
eprintln!("call to init_0rtt");
let (header, packet) = match self.crypto.early_crypto() {
Some(x) => x,
None => return,
Some(x) => {
eprintln!("early crypto found");
x
},
None => {
eprintln!("early crypto not found");
return
},
};
if self.side.is_client() {
match self.crypto.transport_parameters() {
Ok(params) => {
eprintln!("init_0rtt, params = {:#?}", params);
let params = params
.expect("crypto layer didn't supply transport parameters with ticket");
// Certain values must not be cached
Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! Note that usage of any protocol (version) other than TLS 1.3 does not conform to any
//! published versions of the specification, and will not be supported in QUIC v1.

use std::{any::Any, str, sync::Arc};
use std::{any::Any, str, sync::Arc, fmt::Debug};

use bytes::BytesMut;

Expand Down
2 changes: 2 additions & 0 deletions quinn-proto/src/crypto/rustls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ impl crypto::Session for TlsSession {
}

fn early_crypto(&self) -> Option<(Box<dyn HeaderKey>, Box<dyn crypto::PacketKey>)> {
eprintln!("rustls::early_crypto");
let keys = self.inner.zero_rtt_keys()?;
eprintln!("rustls::early_crypto proceeding with Some path");
Some((Box::new(keys.header), Box::new(keys.packet)))
}

Expand Down
2 changes: 1 addition & 1 deletion quinn-proto/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ fn zero_rtt_happypath() {
let mut pair = Pair::new(
Default::default(),
ServerConfig {
use_retry: true,
use_retry: false,
..server_config()
},
);
Expand Down
1 change: 1 addition & 0 deletions quinn/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ tokio = { version = "1.28.1", features = ["rt", "rt-multi-thread", "time", "macr
tracing-subscriber = { version = "0.3.0", default-features = false, features = ["env-filter", "fmt", "ansi", "time", "local-time"] }
tracing-futures = { version = "0.2.0", default-features = false, features = ["std-future"] }
url = "2"
backtrace = "0.3"

[[example]]
name = "server"
Expand Down
174 changes: 130 additions & 44 deletions quinn/examples/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
//!
//! Checkout the `README.md` for guidance.

#[macro_use]
extern crate tracing;

use std::{
fs,
io::{self, Write},
Expand Down Expand Up @@ -42,12 +45,13 @@ struct Opt {
}

fn main() {
tracing::subscriber::set_global_default(
tracing_subscriber::FmtSubscriber::builder()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.finish(),
)
.unwrap();
logging::init_logging();
//tracing::subscriber::set_global_default(
// tracing_subscriber::FmtSubscriber::builder()
// .with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
// .finish(),
//)
//.unwrap();
let opt = Opt::parse();
let code = {
if let Err(e) = run(opt) {
Expand Down Expand Up @@ -95,54 +99,69 @@ async fn run(options: Opt) -> Result<()> {
if options.keylog {
client_crypto.key_log = Arc::new(rustls::KeyLogFile::new());
}
client_crypto.enable_early_data = true;

let client_config = quinn::ClientConfig::new(Arc::new(client_crypto));
let mut endpoint = quinn::Endpoint::client("[::]:0".parse().unwrap())?;
let mut endpoint = quinn::Endpoint::client("127.0.0.1:0".parse().unwrap())?;
endpoint.set_default_client_config(client_config);

let request = format!("GET {}\r\n", url.path());
let start = Instant::now();
let rebind = options.rebind;
let host = options.host.as_deref().unwrap_or(url_host);

eprintln!("connecting to {host} at {remote}");
let conn = endpoint
.connect(remote, host)?
.await
.map_err(|e| anyhow!("failed to connect: {}", e))?;
eprintln!("connected at {:?}", start.elapsed());
let (mut send, mut recv) = conn
.open_bi()
.await
.map_err(|e| anyhow!("failed to open stream: {}", e))?;
if rebind {
let socket = std::net::UdpSocket::bind("[::]:0").unwrap();
let addr = socket.local_addr().unwrap();
eprintln!("rebinding to {addr}");
endpoint.rebind(socket).expect("rebind failed");
}
for i in 1..=2 {
eprintln!("round {}", i);
eprintln!("connecting to {host} at {remote}");
let conn = match endpoint.connect(remote, host)?.into_0rtt() {
Ok((conn, _)) => {
eprintln!("0-rtt accepted");
conn
},
Err(connecting) => {
eprintln!("0-rtt rejected");
connecting.await.map_err(|e| anyhow!("failed to connect: {}", e))?
},
};
/*let conn = endpoint
.connect(remote, host)?
.await
.map_err(|e| anyhow!("failed to connect: {}", e))?;*/
eprintln!("connected at {:?}", start.elapsed());
let (mut send, mut recv) = conn
.open_bi()
.await
.map_err(|e| anyhow!("failed to open stream: {}", e))?;
if rebind {
let socket = std::net::UdpSocket::bind("[::]:0").unwrap();
let addr = socket.local_addr().unwrap();
eprintln!("rebinding to {addr}");
endpoint.rebind(socket).expect("rebind failed");
}

send.write_all(request.as_bytes())
.await
.map_err(|e| anyhow!("failed to send request: {}", e))?;
send.finish()
.await
.map_err(|e| anyhow!("failed to shutdown stream: {}", e))?;
let response_start = Instant::now();
eprintln!("request sent at {:?}", response_start - start);
let resp = recv
.read_to_end(usize::max_value())
.await
.map_err(|e| anyhow!("failed to read response: {}", e))?;
let duration = response_start.elapsed();
eprintln!(
"response received in {:?} - {} KiB/s",
duration,
resp.len() as f32 / (duration_secs(&duration) * 1024.0)
);
io::stdout().write_all(&resp).unwrap();
io::stdout().flush().unwrap();
conn.close(0u32.into(), b"done");
send.write_all(request.as_bytes())
.await
.map_err(|e| anyhow!("failed to send request: {}", e))?;
send.finish()
.await
.map_err(|e| anyhow!("failed to shutdown stream: {}", e))?;
let response_start = Instant::now();
eprintln!("request sent at {:?}", response_start - start);
let resp = recv
.read_to_end(usize::max_value())
.await
.map_err(|e| anyhow!("failed to read response: {}", e))?;
let duration = response_start.elapsed();
eprintln!(
"response received in {:?} - {} KiB/s",
duration,
resp.len() as f32 / (duration_secs(&duration) * 1024.0)
);
io::stdout().write_all(&resp).unwrap();
io::stdout().flush().unwrap();
conn.close(0u32.into(), b"done");
eprintln!("");
}

// Give the server a fair chance to receive the close packet
endpoint.wait_idle().await;
Expand All @@ -163,3 +182,70 @@ fn strip_ipv6_brackets(host: &str) -> &str {
fn duration_secs(x: &Duration) -> f32 {
x.as_secs() as f32 + x.subsec_nanos() as f32 * 1e-9
}


mod logging {
//! Global logging system.

use std::{
fs::File,
sync::Arc,
env,
panic,
};
use backtrace::Backtrace;
use tracing_subscriber::{
fmt::{
self,
time::uptime,
},
prelude::*,
Registry,
EnvFilter,
};


/// Default logging environment filter. Our crates are debug, everything else is warn.
const DEFAULT_FILTER: &'static str = "warn";

/// Initializes a `tracing` logging backend which outputs to stdout and also a `log` file. Accepts
/// ecosystem-standard `RUST_LOG` env filters. Configures some other logging tweaks too.
pub fn init_logging() {
// initialize and install logging system
let format = fmt::format()
.compact()
.with_timer(uptime())
.with_line_number(true);
let stdout_log = fmt::layer()
.event_format(format);

let log_file = File::create("log")
.expect("unable to create log file");
let log_file_log = tracing_subscriber::fmt::layer()
.with_ansi(false)
.with_line_number(true)
.with_writer(Arc::new(log_file));

let mut filter = DEFAULT_FILTER.to_owned();
if let Ok(env_filter) = env::var(EnvFilter::DEFAULT_ENV) {
filter.push(',');
filter.push_str(&env_filter);
}

let subscriber = Registry::default()
.with(EnvFilter::new(filter))
.with(stdout_log)
.with(log_file_log);
tracing::subscriber::set_global_default(subscriber)
.expect("unable to install log subscriber");

// make panic messages and backtrace go through logging system
panic::set_hook(Box::new(|info| {
error!("{}", info);
if env::var("RUST_BACKTRACE").map(|val| val == "1").unwrap_or(true) {
error!("{:?}", Backtrace::new());
}
}));
}

}
3 changes: 1 addition & 2 deletions quinn/examples/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,13 @@ async fn run(options: Opt) -> Result<()> {
if options.keylog {
server_crypto.key_log = Arc::new(rustls::KeyLogFile::new());
}

server_crypto.max_early_data_size = u32::MAX;
let mut server_config = quinn::ServerConfig::with_crypto(Arc::new(server_crypto));
let transport_config = Arc::get_mut(&mut server_config.transport).unwrap();
transport_config.max_concurrent_uni_streams(0_u8.into());
if options.stateless_retry {
server_config.use_retry(true);
}

let root = Arc::<Path>::from(options.root.clone());
if !root.exists() {
bail!("root path does not exist");
Expand Down
Loading