Session Resumption Protocol
On this page
Session resumption enables low-latency reconnection by bypassing the full X25519 handshake. It allows clients to re-establish a secure session using previously negotiated symmetric secrets and a valid session token.
Source Mapping
src/Nalix.Codec/ProtocolFrames/Session/SessionResume.cssrc/Nalix.Runtime/Handlers/SessionHandlers.cssrc/Nalix.Runtime/Sessions/SessionService.cssrc/Nalix.Abstractions/Networking/Sessions/ISessionService.cssrc/Nalix.Abstractions/Networking/Sessions/ISessionFactory.cssrc/Nalix.Abstractions/Networking/Sessions/ISessionStore.cssrc/Nalix.SDK/Transport/Extensions/ResumeExtensions.cs
1. Design & Rationale
Nalix uses the SessionResume packet with a Stage state machine to manage session state. The packet supports REQUEST and RESPONSE stages so the server can restore or reject a session in a single round-trip.
- Atomic Resumption: The server applies the restored session snapshot and returns a fresh response token in a single round-trip.
- Stateless Re-entry: A session can be resumed immediately as long as the 8-byte
SessionTokenand its associatedSecretare valid. - Token Rotation: The server can return a rotated
SessionTokenin a successful response.
2. Handshake vs. Resumption
sequenceDiagram
participant C as Client (SDK)
participant S as Server (Runtime)
Note over C, S: Option A: Full Handshake (Standard)
C->>S: SessionInit (PublicKey, Nonce)
S->>C: SessionChallenge (PublicKey, Nonce, Proof)
C->>S: SessionProof (Proof)
S->>C: SessionEstablished (Proof, SessionToken)
Note over C, S: Option B: Session Resume (Fast)
C->>S: SessionResume [Stage=REQUEST, Token=T1]
S->>C: SessionResume [Stage=RESPONSE, Token=T2, Reason=NONE]3. Protocol Specification
Packet Shape
SessionResume is a fixed-size signal packet carrying the stage, session token, proof, and result reason needed for resumption.
4. Implementation Details
Server Handling Logic (SessionHandlers.HandleAsync)
When a SessionResume (0x0002, SESSION_SIGNAL) request arrives at SessionHandlers.HandleAsync:
- The incoming packet is validated to ensure the
Stage(SessionResumeStage.REQUEST),SessionToken, andProoffields are structurally sound. - The server calls
ISessionService.ConsumeAsync(packet.SessionToken, entry => ...)to atomically validate and consume the storedSessionEntry. - Inside the predicate, it verifies
Proofin constant time usingHmacKeccak256.Computeover the 16-byte bufferSessionToken (8B LE) || TimeWindow (8B LE, UnixSeconds / 30)across the[t - 1, t, t + 1]time windows (30-second buckets). - If validation succeeds, the runtime restores the connection’s
Secret,Algorithm,Level, and saved state, and marks the handshake state as established. - The runtime persists the live connection under its new
ConnectionId(newToken) viaISessionService.SaveSessionAsync(connection), computes a server response proof (HmacKeccak256overnewToken (8B LE) || TimeWindow (8B LE)), and sendsSessionResume(Stage = RESPONSE,SessionToken = newToken,Reason = ProtocolReason.NONE,Proof = responseProof). - If validation, token lookup, or proof verification fails, the server sends a
SessionResume(Stage = RESPONSE) with the failureProtocolReasonand closes the connection.
5. Security & Operations
- Token Confidentiality: While the token is not a replacement for the symmetric secret, it should be treated as sensitive material as it identifies an active session.
- Rotation Policy: Clients must update their local
session.State.SessionTokenimmediately upon receiving a successfulRESPONSE. The SDK already does this insrc/Nalix.SDK/Transport/Extensions/ResumeExtensions.cs. - Invalidation: Sessions are invalidated upon explicit disconnect or after the configured session-store TTL (Time-To-Live) expires.