Skip to content
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
4 changes: 2 additions & 2 deletions neqo-bin/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use neqo_http3::Header;
use neqo_transport::{AppError, CloseReason, ConnectionId, OutputBatch, Version};
use neqo_udp::RecvBuf;
use nss::{
Cipher, ResumptionToken,
Cipher, ResumptionToken, TokenKind,
constants::{TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256},
init,
};
Expand Down Expand Up @@ -618,7 +618,7 @@ pub async fn client(mut args: Args) -> Res<()> {
.as_ref()
.map(|path| -> Res<_> {
Ok(ResumptionToken::new(
std::fs::read(path)?,
TokenKind::Encrypted(std::fs::read(path)?),
// Expiry is a client-side hint only; the TLS ticket itself
// carries its own lifetime enforced by the server.
now() + std::time::Duration::from_hours(24),
Expand Down
8 changes: 3 additions & 5 deletions neqo-http3/src/connection_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ use std::{
};

use neqo_common::{
Datagram, Decoder, Encoder, Header, Role,
event::Provider as EventProvider,
hex::{Hex, HexWithLen},
Datagram, Decoder, Encoder, Header, Role, event::Provider as EventProvider, hex::HexWithLen,
qlog::Qlog,
};
use neqo_qpack::Stats as QpackStats;
Expand Down Expand Up @@ -422,7 +420,7 @@ impl Http3Client {
let mut enc = Encoder::default();
settings.encode_frame_contents(&mut enc);
enc.encode(token.as_ref());
ResumptionToken::new(enc.into(), token.expiration_time())
token.clone_with_bytes(enc.into())
})
}

Expand Down Expand Up @@ -455,7 +453,7 @@ impl Http3Client {
Error::InvalidResumptionToken,
)?;
let tok = dec.decode_remainder();
trace!("[{self}] Transport token {}", Hex::new(tok));
trace!("[{self}] Transport token [{}]", tok.len());
self.conn.enable_resumption(now, tok)?;
if self.conn.state().closed() {
let state = self.conn.state().clone();
Expand Down
2 changes: 1 addition & 1 deletion neqo-transport/src/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ impl Connection {
trace!("[{self}] Initial token {}", Hex::new(init_token));

let tok = dec.decode_remainder();
trace!("[{self}] TLS token {}", Hex::new(tok));
trace!("[{self}] TLS token [{}]", tok.len());

match self.crypto.tls_mut() {
Agent::Client(c) => {
Expand Down
14 changes: 14 additions & 0 deletions neqo-transport/src/connection/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ pub struct ConnectionParameters {
/// Whether to use Alternative Backoff with ECN (RFC 8511), i.e. a smaller multiplicative
/// decrease on ECN-CE congestion events than on loss. Only affects CUBIC.
abe: bool,
/// Whether to ask NSS for resumption tokens that carry the secret in cleartext.
plaintext_resumption_export: bool,
}

impl Default for ConnectionParameters {
Expand Down Expand Up @@ -213,6 +215,7 @@ impl Default for ConnectionParameters {
reliable_stream_reset: true,
spurious_recovery: true,
abe: true,
plaintext_resumption_export: false,
}
}
}
Expand Down Expand Up @@ -556,6 +559,17 @@ impl ConnectionParameters {
self
}

#[must_use]
pub const fn plaintext_resumption_export_enabled(&self) -> bool {
self.plaintext_resumption_export
}

#[must_use]
pub const fn plaintext_resumption_export(mut self, plaintext_resumption_export: bool) -> Self {
self.plaintext_resumption_export = plaintext_resumption_export;
self
}

/// # Errors
/// When a connection ID cannot be obtained.
/// # Panics
Expand Down
19 changes: 19 additions & 0 deletions neqo-transport/src/connection/tests/resumption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ fn resume() {
connect(&mut client, &mut server);

let token = exchange_ticket(&mut client, &mut server, now());
assert!(!token.is_plaintext());
let mut client = default_client();
client
.enable_resumption(now(), token)
.expect("should set token");
let mut server = resumed_server(&client);
connect(&mut client, &mut server);
assert!(client.tls_info().unwrap().resumed());
assert!(server.tls_info().unwrap().resumed());
}

#[test]
fn resume_plaintext() {
let mut client = new_client(ConnectionParameters::default().plaintext_resumption_export(true));
let mut server = default_server();
connect(&mut client, &mut server);

let token = exchange_ticket(&mut client, &mut server, now());
assert!(token.is_plaintext());
let mut client = default_client();
client
.enable_resumption(now(), token)
Expand Down
17 changes: 9 additions & 8 deletions neqo-transport/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ use std::{
};

use enum_map::{Enum as _, EnumMap};
use neqo_common::{
Buffer, Encoder, Role,
hex::{Hex, HexSnipMiddle},
to_u64,
};
use neqo_common::{Buffer, Encoder, Role, hex::Hex, to_u64};
pub use nss::Epoch;
use nss::{
Agent, AntiReplay, Cipher, Error as CryptoError, HandshakeState, Mode, PrivateKey, PublicKey,
Expand Down Expand Up @@ -120,6 +116,10 @@ impl Crypto {
// Always enable 0-RTT on the client, but the server needs
// more configuration passed to server_enable_0rtt.
c.enable_0rtt()?;

if conn_params.plaintext_resumption_export_enabled() {
c.enable_plaintext_resumption_export(true)?;
}
}
agent.set_alpn(&protocols)?;
agent.disable_end_of_early_data()?;
Expand Down Expand Up @@ -424,7 +424,7 @@ impl Crypto {
) -> Option<ResumptionToken> {
if let Agent::Client(ref mut c) = self.tls {
c.resumption_token().as_ref().map(|t| {
trace!("TLS token {}", Hex::new(t.as_ref()));
trace!("TLS token {t:?}");
let mut enc = Encoder::default();
enc.encode_uint(4, version.wire_version());
enc.encode_varint(rtt);
Expand All @@ -433,8 +433,9 @@ impl Crypto {
});
enc.encode_vvec(new_token.unwrap_or(&[]));
enc.encode(t.as_ref());
debug!("resumption token {}", HexSnipMiddle::new(enc.as_ref()));
ResumptionToken::new(enc.into(), t.expiration_time())
let token = t.clone_with_bytes(enc.into());
debug!("resumption token {token:?}");
token
})
} else {
unreachable!("It is a server");
Expand Down
Loading