Module

whiplash/quic/tls

src/whiplash/quic/tls.pooka

A 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

class

SigningKey

src/whiplash/quic/tls.pooka:56
class SigningKey

A private key, as OTP holds it.

class

TlsError

src/whiplash/quic/tls.pooka:60
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.

field

alert

src/whiplash/quic/tls.pooka:60
alert: Int
INFERREDInt
field

message

src/whiplash/quic/tls.pooka:60
message: String
INFERREDString
constructor

new

src/whiplash/quic/tls.pooka:60
INFERREDfn(Int, String) -> whiplash/quic/tls.TlsError
class

ClientHello

src/whiplash/quic/tls.pooka:63
class 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.

field

random

src/whiplash/quic/tls.pooka:64
random: BitArray
INFERREDBitArray
field

session_id

src/whiplash/quic/tls.pooka:65
session_id: BitArray
INFERREDBitArray
field

ciphers

src/whiplash/quic/tls.pooka:66
ciphers: List(Int)
INFERREDList(Int)
field

server_name

src/whiplash/quic/tls.pooka:67
server_name: Option(String)
INFERREDOption(String)
field

protocols

src/whiplash/quic/tls.pooka:68
protocols: List(String)
INFERREDList(String)
field

groups

src/whiplash/quic/tls.pooka:69
groups: List(Int)
INFERREDList(Int)
field

key_shares

src/whiplash/quic/tls.pooka:70
key_shares: List(#(Int, BitArray))
INFERREDList(#(Int, BitArray))
field

signatures

src/whiplash/quic/tls.pooka:71
signatures: List(Int)
INFERREDList(Int)
field

versions

src/whiplash/quic/tls.pooka:72
versions: List(Int)
INFERREDList(Int)
field

transport_parameters

src/whiplash/quic/tls.pooka:73
transport_parameters: Option(BitArray)
INFERREDOption(BitArray)
field

psk_modes

src/whiplash/quic/tls.pooka:74
psk_modes: List(Int)
INFERREDList(Int)
field

early_data

src/whiplash/quic/tls.pooka:75
early_data: Bool
INFERREDBool
field

offer

src/whiplash/quic/tls.pooka:76
offer: Option(Offer)
INFERREDOption(whiplash/quic/tls.Offer)
constructor

new

src/whiplash/quic/tls.pooka:64
INFERREDfn(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.ClientHello
class

Offer

src/whiplash/quic/tls.pooka:82
class 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.

field

identities

src/whiplash/quic/tls.pooka:83
identities: List(#(BitArray, Int))
INFERREDList(#(BitArray, Int))
field

binders

src/whiplash/quic/tls.pooka:84
binders: List(BitArray)
INFERREDList(BitArray)
field

binders_size

src/whiplash/quic/tls.pooka:85
binders_size: Int
INFERREDInt
constructor

new

src/whiplash/quic/tls.pooka:83
INFERREDfn(List(#(BitArray, Int)), List(BitArray), Int) -> whiplash/quic/tls.Offer
class

Identity

src/whiplash/quic/tls.pooka:90
class 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.

field

chain

src/whiplash/quic/tls.pooka:91
chain: List(BitArray)
INFERREDList(BitArray)
field

key

src/whiplash/quic/tls.pooka:92
key: SigningKey
field

scheme

src/whiplash/quic/tls.pooka:93
scheme: Int
INFERREDInt
field

ticket_key

src/whiplash/quic/tls.pooka:94
ticket_key: BitArray
INFERREDBitArray
constructor

new

src/whiplash/quic/tls.pooka:91
INFERREDfn(List(BitArray), whiplash/quic/tls.SigningKey, Int, BitArray) -> whiplash/quic/tls.Identity
class

Flight

src/whiplash/quic/tls.pooka:103
class 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.

field

initial

src/whiplash/quic/tls.pooka:104
initial: BitArray
INFERREDBitArray
field

handshake

src/whiplash/quic/tls.pooka:105
handshake: BitArray
INFERREDBitArray
field

client_handshake

src/whiplash/quic/tls.pooka:106
client_handshake: BitArray
INFERREDBitArray
field

server_handshake

src/whiplash/quic/tls.pooka:107
server_handshake: BitArray
INFERREDBitArray
field

client_application

src/whiplash/quic/tls.pooka:108
client_application: BitArray
INFERREDBitArray
field

server_application

src/whiplash/quic/tls.pooka:109
server_application: BitArray
INFERREDBitArray
field

client_finished

src/whiplash/quic/tls.pooka:110
client_finished: BitArray
INFERREDBitArray
field

protocol

src/whiplash/quic/tls.pooka:111
protocol: String
INFERREDString
field

signed_hash

src/whiplash/quic/tls.pooka:112
signed_hash: BitArray
INFERREDBitArray
field

resumption

src/whiplash/quic/tls.pooka:113
resumption: BitArray
INFERREDBitArray
field

resumed

src/whiplash/quic/tls.pooka:114
resumed: Bool
INFERREDBool
field

early

src/whiplash/quic/tls.pooka:115
early: Option(BitArray)
INFERREDOption(BitArray)
constructor

new

src/whiplash/quic/tls.pooka:104
INFERREDfn(BitArray, BitArray, BitArray, BitArray, BitArray, BitArray, BitArray, String, BitArray, BitArray, Bool, Option(BitArray)) -> whiplash/quic/tls.Flight
function

version

src/whiplash/quic/tls.pooka:119
version() -> Int
INFERREDfn() -> Int

TLS 1.3, TLS_AES_128_GCM_SHA256, x25519.

function

cipher_suite

src/whiplash/quic/tls.pooka:123
cipher_suite() -> Int
INFERREDfn() -> Int
function

group

src/whiplash/quic/tls.pooka:127
group() -> Int
INFERREDfn() -> Int
function

load_identity

src/whiplash/quic/tls.pooka:132
load_identity(certificate: String, key: String) -> Result(Identity, String)
INFERREDfn(String, String) -> Result(whiplash/quic/tls.Identity, String)

A certificate chain and key from PEM files.

function

next_message

src/whiplash/quic/tls.pooka:146
next_message(bytes: BitArray) -> Option(#(Int, BitArray, BitArray))
INFERREDfn(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.

function

parse_client_hello

src/whiplash/quic/tls.pooka:156
parse_client_hello(message: BitArray) -> Result(ClientHello, TlsError)

A ClientHello handshake message, type and length included.

function

server_hello

src/whiplash/quic/tls.pooka:479
server_hello(random: BitArray, session_id: BitArray, public: BitArray) -> BitArray
INFERREDfn(BitArray, BitArray, BitArray) -> BitArray

A ServerHello choosing TLS 1.3, TLS_AES_128_GCM_SHA256 and x25519.

function

encrypted_extensions

src/whiplash/quic/tls.pooka:509
encrypted_extensions(protocol: String, transport_parameters: BitArray) -> BitArray
INFERREDfn(String, BitArray) -> BitArray

EncryptedExtensions with the chosen application protocol and QUIC's transport parameters.

function

certificate

src/whiplash/quic/tls.pooka:535
certificate(chain: List(BitArray)) -> BitArray
INFERREDfn(List(BitArray)) -> BitArray

A Certificate message for a chain, leaf first, without extensions.

function

certificate_verify

src/whiplash/quic/tls.pooka:542
certificate_verify(scheme: Int, signature: BitArray) -> BitArray
INFERREDfn(Int, BitArray) -> BitArray
function

finished

src/whiplash/quic/tls.pooka:549
finished(verify_data: BitArray) -> BitArray
INFERREDfn(BitArray) -> BitArray
function

certificate_verify_content

src/whiplash/quic/tls.pooka:554
certificate_verify_content(transcript_hash: BitArray) -> BitArray
INFERREDfn(BitArray) -> BitArray

What a server signs in CertificateVerify (RFC 8446 section 4.4.3).

function

transcript_hash

src/whiplash/quic/tls.pooka:569
transcript_hash(messages: BitArray) -> BitArray
INFERREDfn(BitArray) -> BitArray

SHA-256 of the transcript so far.

function

handshake_secret

src/whiplash/quic/tls.pooka:574
handshake_secret(shared: BitArray) -> BitArray
INFERREDfn(BitArray) -> BitArray

The handshake secret from the x25519 shared secret.

function

early_secret

src/whiplash/quic/tls.pooka:579
early_secret(psk: BitArray) -> BitArray
INFERREDfn(BitArray) -> BitArray

The early secret from a pre-shared key; 32 zero bytes when there is none.

function

master_secret

src/whiplash/quic/tls.pooka:594
master_secret(handshake: BitArray) -> BitArray
INFERREDfn(BitArray) -> BitArray

The master secret that follows a handshake secret.

function

derive_secret

src/whiplash/quic/tls.pooka:605
derive_secret(secret: BitArray, label: String, transcript_hash: BitArray) -> BitArray
INFERREDfn(BitArray, String, BitArray) -> BitArray

Derive-Secret: a labelled secret over a transcript hash.

function

finished_key

src/whiplash/quic/tls.pooka:609
finished_key(traffic_secret: BitArray) -> BitArray
INFERREDfn(BitArray) -> BitArray
function

verify_data

src/whiplash/quic/tls.pooka:614
verify_data(traffic_secret: BitArray, transcript_hash: BitArray) -> BitArray
INFERREDfn(BitArray, BitArray) -> BitArray

A Finished message's verify_data over a transcript hash.

function

shared_secret

src/whiplash/quic/tls.pooka:619
shared_secret(peer: BitArray, private: BitArray) -> Result(BitArray, TlsError)
INFERREDfn(BitArray, BitArray) -> Result(BitArray, whiplash/quic/tls.TlsError)

The x25519 shared secret with a peer, from this side's private key.

function

key_pair

src/whiplash/quic/tls.pooka:628
key_pair(private: BitArray) -> #(BitArray, BitArray)
INFERREDfn(BitArray) -> #(BitArray, BitArray)

A key pair, #(public, private); give a private key for a known pair, or an empty one for a fresh pair.

function

respond

src/whiplash/quic/tls.pooka:639
respond(
  message: BitArray,
  identity: Identity,
  protocols: List(String),
  transport_parameters: BitArray,
  now: Int
) -> Result(Flight, TlsError)
INFERREDfn(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.

function

anti_replay

src/whiplash/quic/tls.pooka:815
anti_replay() -> Nil
INFERREDfn() -> Nil

Create 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.

function

new_session_ticket

src/whiplash/quic/tls.pooka:823
new_session_ticket(flight: Flight, identity: Identity, now: Int) -> BitArray

A 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).

function

client_finished

src/whiplash/quic/tls.pooka:844
client_finished(flight: Flight, message: BitArray) -> Bool
INFERREDfn(whiplash/quic/tls.Flight, BitArray) -> Bool

Whether the client's Finished message is the one the flight expects.

function

verify_signature

src/whiplash/quic/tls.pooka:896
verify_signature(
  scheme: Int,
  certificate: BitArray,
  transcript_hash: BitArray,
  signature: BitArray
) -> Bool
INFERREDfn(Int, BitArray, BitArray, BitArray) -> Bool

Whether a CertificateVerify signature over a transcript hash is valid for a DER certificate.