netio/tls/session.rs#
Source: lib/netio/tls/session.rs
session -- TLS 1.3 resumption (RFC 8446 2.2, 4.6.1): a server's tickets, a client's sessions,
and the anti-replay register of 0-RTT (RFC 8446 8)
Tickets::new() a server's tickets: stateless, sealed with XChaCha20-Poly1305 under
keys that are made and rotated by themselves (or set_keys, for
servers that share them); lifetime, tickets per handshake, the
replay check of 0-RTT
Sessions::new(servers) a client's tickets, per server: the name, the trust and the client
identity of the connection that got them; each is used once
A ticket holds the resumption PSK and what the server must check before it takes it again:
the suite, the server name, the ALPN protocol, when the handshake that authenticated the
client ran, the client's certificates (which a resumption checks again) and the trust that
checked them. A session lasts at
most 7 days from that handshake, however often its tickets are renewed (RFC 8446 4.6.1).
/// the longest a ticket is valid and a session lasts from the handshake that authenticated the
/// peer: 7 days (RFC 8446 4.6.1)
MAX_LIFETIME: u32 = 604_800
/// how far the client's age of a ticket and the server's may differ for 0-RTT (RFC 8446 8.3)
FRESH_WINDOW_MS: i64 = 10_000
struct Sessionsa client's tickets (ClientConfig::sessions): per server, a connection takes the newest and the server sends new ones. The key of a server is its name, the trust of the connection and its client identity, so a ticket a connection with Trust::Any got is never offered by one that checks certificates, nor one of a client certificate by a connection without it; and its revocation check, so one of Revocation::Off is never offered by a connection that checks. A ticket whose handshake checked a stapled OCSP response goes when that response does: 5 minutes (ocsp::SKEW) after its Response::expires, as a full handshake would still take it, at the end of a delegated responder's certificate at the latest. Shared by threads; in memory only
impl Sessions
fn new(servers: usize) -> Sessionsthe tickets of up toserversservers (the least recently used go first), 8 eachfn clear(&self)forget every ticketfn len(&self) -> usizethe tickets kept (all servers)fn is_empty(&self) -> boolno ticket keptfn test_shift(&self, ms: i64)(tests) move this cache's clock bymsfn test_max_early(&self, n: u32)(tests) the 0-RTT limit of every kept ticket, as a client that sends more than its ticket allows would believetype ReplayCheck = Arc<dyn Fn(&[u8]) -> bool + Send + Sync>the replay check of 0-RTT (Tickets::replay_check): a value unique to a ClientHello with early data (16 bytes of its PSK binder, which the PSK authenticates) -> true the first time it is seen, false when it was seen in the last 20 seconds (the client's 0-RTT is refused then, not the connection)struct Ticketsa server's session tickets (ServerConfig::tickets). A ticket is the session's state, sealed with XChaCha20-Poly1305: the server keeps nothing per client. Its keys are made at random and replaced every lifetime, the previous one still opening the tickets it sealed; servers that share tickets (behind a load balancer) set the same keys with set_keys. Shared by threads
impl Tickets
fn new() -> Ticketstickets valid for a day, two per handshake, keys of their ownfn lifetime(mut self, secs: u32) -> Ticketshow long a ticket is valid (seconds, 1 to 7 days); the keys change at this intervalfn per_handshake(mut self, n: u8) -> Ticketsthe tickets a handshake gets (1 to 8): a client uses each once, so one that opens connections in parallel wants severalfn replay_check(mut self, f: ReplayCheck) -> Ticketsthe replay check of 0-RTT instead of this process's register: servers that share tickets must share it too, or a ClientHello replayed to another of them gets its 0-RTT taken again (RFC 8446 8.2)fn set_keys(&self, keys: &[[u8; 32]])the keys of servers that share tickets: the first seals, all open (the previous ones, while tickets they sealed may still come); they no longer change by themselves. Empty: keys of their own againfn rotate(&self)a new key now (keys of their own): the tickets of the previous one are taken for one more lifetime, older ones no longerfn test_shift(&self, ms: i64)(tests) move these tickets' clock byms