Module
whiplash/quic/tls
src/whiplash/quic/tls.pookaA TLS 1.3 server handshake, as QUIC carries it in CRYPTO frames (RFC 8446; RFC 9001 section 4).
QUIC uses TLS for its handshake and keys only: no records, no ChangeCipherSpec, no middlebox compatibility. This module reads the client's hello, writes the server's flight, keeps the transcript, and runs the key schedule. The cryptographic primitives come from OTP; the messages, the transcript and the schedule are here.
Supported: TLS_AES_128_GCM_SHA256 with x25519, certificates signed with rsa_pss_rsae_sha256 or ecdsa_secp256r1_sha256, and resumption with the server's own session tickets (psk_dhe_ke), with 0-RTT data. A client offering no x25519 key share would need a HelloRetryRequest, which is not supported; it is refused.
API reference
- classSigningKey
- classTlsError
- classClientHello
- classOffer
- classIdentity
- classFlight
- functionversion
- functioncipher_suite
- functiongroup
- functionload_identity
- functionnext_message
- functionparse_client_hello
- functionserver_hello
- functionencrypted_extensions
- functioncertificate
- functioncertificate_verify
- functionfinished
- functioncertificate_verify_content
- functiontranscript_hash
- functionhandshake_secret
- functionearly_secret
- functionmaster_secret
- functionderive_secret
- functionfinished_key
- functionverify_data
- functionshared_secret
- functionkey_pair
- functionrespond
- functionanti_replay
- functionnew_session_ticket
- functionclient_finished
- functionverify_signature
class SigningKey
A private key, as OTP holds it.
class TlsError(alert: Int, message: String)
Why a handshake failed: the TLS alert to send (RFC 8446 section 6), which QUIC carries as CRYPTO_ERROR 0x100 + alert.
alert: Int
Intmessage: String
String
fn(Int, String) -> whiplash/quic/tls.TlsErrorclass ClientHello(
random: BitArray,
session_id: BitArray,
ciphers: List(Int),
server_name: Option(String),
protocols: List(String),
groups: List(Int),
key_shares: List(#(Int, BitArray)),
signatures: List(Int),
versions: List(Int),
transport_parameters: Option(BitArray),
psk_modes: List(Int),
early_data: Bool,
offer: Option(Offer)
)
What the client offered.
random: BitArray
BitArraysession_id: BitArray
BitArrayciphers: List(Int)
List(Int)server_name: Option(String)
Option(String)protocols: List(String)
List(String)groups: List(Int)
List(Int)signatures: List(Int)
List(Int)versions: List(Int)
List(Int)transport_parameters: Option(BitArray)
Option(BitArray)psk_modes: List(Int)
List(Int)early_data: Bool
Booloffer: Option(Offer)
Option(whiplash/quic/tls.Offer)
fn(BitArray, BitArray, List(Int), Option(String), List(String), List(Int), List(#(Int, BitArray)), List(Int), List(Int), Option(BitArray), List(Int), Bool, Option(whiplash/quic/tls.Offer)) -> whiplash/quic/tls.ClientHelloclass Offer(
identities: List(#(BitArray, Int)),
binders: List(BitArray),
binders_size: Int
)
A pre_shared_key offer (RFC 8446 section 4.2.11): each identity with its obfuscated ticket age, each binder, and the size of the binders list with its length prefix, which ends the ClientHello.
identities: List(#(BitArray, Int))
List(#(BitArray, Int))binders: List(BitArray)
List(BitArray)binders_size: Int
Int
fn(List(#(BitArray, Int)), List(BitArray), Int) -> whiplash/quic/tls.Offerclass Identity(
chain: List(BitArray),
key: SigningKey,
scheme: Int,
ticket_key: BitArray
)
A certificate chain, leaf first, its private key, and the key that seals this server's session tickets, drawn afresh when the identity is loaded.
chain: List(BitArray)
List(BitArray)key: SigningKey
whiplash/quic/tls.SigningKeyscheme: Int
Intticket_key: BitArray
BitArray
fn(List(BitArray), whiplash/quic/tls.SigningKey, Int, BitArray) -> whiplash/quic/tls.Identityclass Flight(
initial: BitArray,
handshake: BitArray,
client_handshake: BitArray,
server_handshake: BitArray,
client_application: BitArray,
server_application: BitArray,
client_finished: BitArray,
protocol: String,
signed_hash: BitArray,
resumption: BitArray,
resumed: Bool,
early: Option(BitArray)
)
The server's flight and the secrets it leads to. initial is the
ServerHello, sent in Initial packets; handshake is EncryptedExtensions,
Certificate, CertificateVerify and Finished, sent in Handshake packets
(no Certificate or CertificateVerify when a session is resumed). Also the
resumption master secret, whether a ticket resumed the session, and the
client's early traffic secret when its 0-RTT data is accepted.
initial: BitArray
BitArrayhandshake: BitArray
BitArrayclient_handshake: BitArray
BitArrayserver_handshake: BitArray
BitArrayclient_application: BitArray
BitArrayserver_application: BitArray
BitArrayclient_finished: BitArray
BitArrayprotocol: String
Stringsigned_hash: BitArray
BitArrayresumption: BitArray
BitArrayresumed: Bool
Boolearly: Option(BitArray)
Option(BitArray)
fn(BitArray, BitArray, BitArray, BitArray, BitArray, BitArray, BitArray, String, BitArray, BitArray, Bool, Option(BitArray)) -> whiplash/quic/tls.Flightversion() -> Int
fn() -> IntTLS 1.3, TLS_AES_128_GCM_SHA256, x25519.
cipher_suite() -> Int
fn() -> Intgroup() -> Int
fn() -> Intload_identity(certificate: String, key: String) -> Result(Identity, String)
fn(String, String) -> Result(whiplash/quic/tls.Identity, String)A certificate chain and key from PEM files.
next_message(bytes: BitArray) -> Option(#(Int, BitArray, BitArray))
fn(BitArray) -> Option(#(Int, BitArray, BitArray))One handshake message from the front of the bytes: its type, the whole message as the transcript needs it, and the bytes after it. None while it has not fully arrived.
parse_client_hello(message: BitArray) -> Result(ClientHello, TlsError)
fn(BitArray) -> Result(whiplash/quic/tls.ClientHello, whiplash/quic/tls.TlsError)A ClientHello handshake message, type and length included.
server_hello(random: BitArray, session_id: BitArray, public: BitArray) -> BitArray
fn(BitArray, BitArray, BitArray) -> BitArrayA ServerHello choosing TLS 1.3, TLS_AES_128_GCM_SHA256 and x25519.
encrypted_extensions(protocol: String, transport_parameters: BitArray) -> BitArray
fn(String, BitArray) -> BitArrayEncryptedExtensions with the chosen application protocol and QUIC's transport parameters.
certificate(chain: List(BitArray)) -> BitArray
fn(List(BitArray)) -> BitArrayA Certificate message for a chain, leaf first, without extensions.
certificate_verify(scheme: Int, signature: BitArray) -> BitArray
fn(Int, BitArray) -> BitArrayfinished(verify_data: BitArray) -> BitArray
fn(BitArray) -> BitArraycertificate_verify_content(transcript_hash: BitArray) -> BitArray
fn(BitArray) -> BitArrayWhat a server signs in CertificateVerify (RFC 8446 section 4.4.3).
transcript_hash(messages: BitArray) -> BitArray
fn(BitArray) -> BitArraySHA-256 of the transcript so far.
handshake_secret(shared: BitArray) -> BitArray
fn(BitArray) -> BitArrayThe handshake secret from the x25519 shared secret.
early_secret(psk: BitArray) -> BitArray
fn(BitArray) -> BitArrayThe early secret from a pre-shared key; 32 zero bytes when there is none.
master_secret(handshake: BitArray) -> BitArray
fn(BitArray) -> BitArrayThe master secret that follows a handshake secret.
derive_secret(secret: BitArray, label: String, transcript_hash: BitArray) -> BitArray
fn(BitArray, String, BitArray) -> BitArrayDerive-Secret: a labelled secret over a transcript hash.
finished_key(traffic_secret: BitArray) -> BitArray
fn(BitArray) -> BitArrayverify_data(traffic_secret: BitArray, transcript_hash: BitArray) -> BitArray
fn(BitArray, BitArray) -> BitArrayA Finished message's verify_data over a transcript hash.
key_pair(private: BitArray) -> #(BitArray, BitArray)
fn(BitArray) -> #(BitArray, BitArray)A key pair, #(public, private); give a private key for a known pair, or an empty one for a fresh pair.
respond(
message: BitArray,
identity: Identity,
protocols: List(String),
transport_parameters: BitArray,
now: Int
) -> Result(Flight, TlsError)
fn(BitArray, whiplash/quic/tls.Identity, List(String), BitArray, Int) -> Result(whiplash/quic/tls.Flight, whiplash/quic/tls.TlsError)Answer a ClientHello: check what it offers, then write the whole server
flight and derive every secret up to the application keys. A ticket this
identity issued resumes the session: no certificate is sent, and if the
client sends 0-RTT data, the ticket is fresh and not used before, the
flight's early secret opens it.
anti_replay() -> Nil
fn() -> NilCreate the table that lets each ticket open 0-RTT only once. The process that calls it owns the table and should live as long as the listener; without it 0-RTT is refused.
new_session_ticket(flight: Flight, identity: Identity, now: Int) -> BitArray
fn(whiplash/quic/tls.Flight, whiplash/quic/tls.Identity, Int) -> BitArrayA NewSessionTicket message for after the handshake (RFC 8446 section 4.6.1): a ticket valid for a day, sealed under the identity's ticket key, that lets the client resume and send 0-RTT data, as much as it likes (QUIC requires 0xffffffff, RFC 9001 section 4.6.1).
client_finished(flight: Flight, message: BitArray) -> Bool
fn(whiplash/quic/tls.Flight, BitArray) -> BoolWhether the client's Finished message is the one the flight expects.
verify_signature(
scheme: Int,
certificate: BitArray,
transcript_hash: BitArray,
signature: BitArray
) -> Bool
fn(Int, BitArray, BitArray, BitArray) -> BoolWhether a CertificateVerify signature over a transcript hash is valid for a DER certificate.