Guide
TLS and HTTP/3
TLS and HTTP/3
module main
import pooka/http
import pooka/otp
import whiplash
main() {
let tls = whiplash.Tls("cert.pem", "key.pem")
let assert Ok(_) = whiplash.start_tls(whiplash.options(8443), tls, fn(request: http.Request) {
http.text(200, "Hello over " + request.scheme)
})
otp.sleep_forever()
}
start_tls (and start_tls_application) listens on TCP with OTP's TLS 1.2
and 1.3, choosing HTTP/2 or HTTP/1.1 by ALPN (HTTP/1.1 when the client offers
none), and on UDP, on the same port number, with HTTP/3 over QUIC. The
certificate may be RSA (PSS signatures) or ECDSA P-256. request.scheme is
https on all of them.
TCP responses carry alt-svc: h3=":port"; ma=86400, so browsers try HTTP/3
on their next requests; a handler that sets its own Alt-Svc keeps it.
HTTP/3
QUIC runs in Pooka: a native TLS 1.3 handshake (x25519, AES-128-GCM), flow control both ways, loss recovery and probe timeouts from measured round trips, NewReno congestion control with pacing, and HTTP/3 with QPACK, dynamic table included. Streamed responses, uploads and WebSockets work as on the other protocols. h3spec passes every test.
Clients can change address mid-connection, as a phone moving between networks or a NAT rebinding does: the server validates the new address and carries on there. Keys are updated whenever the client asks, and by the server itself long before AES-GCM's limits.
Resumption and 0-RTT
After each handshake the server gives the client a session ticket, valid for a day. A client that comes back with it skips the certificate, and may send its first requests in 0-RTT, before the handshake completes. 0-RTT data can be replayed by anyone who captured it, so each ticket opens 0-RTT once: a second use still resumes, without early data. Tickets are sealed with a key drawn when the server starts, so they do not outlive it or travel to other servers.
Retry
with_retry makes every new HTTP/3 client prove its address before the
server does any handshake work, at the cost of one round trip:
let settings = whiplash.options(443).with_address("::").with_retry()
Without it, the server still sends no more than three times what an unproven address sent it.
A client that proved its address gets a NEW_TOKEN token, and with it skips the Retry on its next connection, for a day.
Datagrams start at 1,200 bytes and grow to 1,452 or 1,472 once the path is seen to carry them (path MTU discovery). The server does not offer a preferred address.
Trying it
curl -k --http2 https://127.0.0.1:8443/ speaks HTTP/2, and a curl built
with HTTP/3 support speaks HTTP/3 with --http3. aioquic's example client
does too:
python3 -m venv /tmp/quic-venv && /tmp/quic-venv/bin/pip install aioquic
/tmp/quic-venv/bin/python http3_client.py --insecure https://127.0.0.1:8443/
(http3_client.py is in aioquic's examples folder.) The test certificate
in test/support is for localhost and protects nothing.