|
libwebsockets
Lightweight C library for HTML5 websockets
|
libwebsockets supports QUIC 0-RTT (Early Data) to allow clients to send data before the TLS 1.3 handshake fully completes, reducing latency for resuming connections.
Because 0-RTT data is susceptible to replay attacks, the implementation uses an explicit opt-in model. Existing applications using QUIC or HTTP/3 will ignore 0-RTT by default and continue operating with the standard LWS_CALLBACK_CLIENT_ESTABLISHED.
When a client connection initiates a handshake with a server it has previously connected to, it can attempt to send 0-RTT data using early TLS secrets.
To enable 0-RTT capabilities on a connection, both the client and server must explicitly allow it using flags and options:
When creating a client connection, set the LCCSCF_ALLOW_EARLY_DATA flag in the ssl_connection member of your struct lws_client_connect_info:
When creating the server vhost, add the LWS_SERVER_OPTION_ALLOW_EARLY_DATA flag to the vhost options:
When early data is possible on a connection, the protocol callback will receive a new reason: LWS_CALLBACK_CLIENT_ESTABLISHED_EARLY.
To opt a specific stream into sending 0-RTT data, your callback must return 1 when handling this reason:
If you return 1, the stream opts into 0-RTT, and LWS will immediately call lws_callback_on_writable(wsi) for that stream so you can send your early data payload.
Since 0-RTT can be rejected by the server (e.g. if the server lost its session ticket keys), the client needs to know if the early data it sent was actually accepted. You can query the status of 0-RTT using the lws_tls_0rtt_status(wsi) API:
Because 0-RTT data can be intercepted and replayed by attackers, servers MUST ensure that any actions taken based on 0-RTT data are strictly idempotent (e.g., HTTP GET requests without side effects).
Servers can check if incoming data was received during the 0-RTT phase by calling lws_rx_is_early_data(wsi):