Skip to content

QUIC-TLS (RFC 9001): packet protection and a sans-IO server handshake - #67

Draft
crimson-knight wants to merge 5 commits into
mainfrom
h3/quic-tls
Draft

crimson-knight wants to merge 5 commits into
mainfrom
h3/quic-tls

Conversation

@crimson-knight

Copy link
Copy Markdown
Member

Adds Beryl::QUIC, the cryptographic half of QUIC version 1 (RFC 9001), for the HTTP/3 work (Mica's QUIC transport, hosted by Amber).

What it adds

  • PacketProtection: one direction of one encryption level. initial_pair_for_server(client_destination_connection_id) (v1 salt), packet protection under quic key/quic iv (allocating and into: forms of seal and open), the 5-byte header protection mask (AES-ECB or ChaCha20 under quic hp), next_generation for key update under quic ku (keeps the header protection key), wipe.
  • ServerHandshake: the TLS 1.3 server handshake over CRYPTO data per encryption level, sans-IO. One HelloRetryRequest when needed; ALPN required (no_application_protocol); the client's quic_transport_parameters required (missing_extension) and exposed unparsed; a non-empty legacy_session_id is a PROTOCOL_VIOLATION (§8.4); a KeyUpdate message is refused (§6); no 0-RTT, resumption or tickets; one incomplete message per level, bounded by Limits#largest_handshake_message_bytesize; every derived secret wiped.
  • HandshakeError < TLS::Error: the alert plus transport_error_code (CRYPTO_ERROR 0x0100 + alert, or PROTOCOL_VIOLATION 0x0a).
  • QUIC.retry_integrity_tag (§5.8).

Shared with the TLS server

The ClientHello checks and the choice of suite, group, ALPN and server name moved from TLS::ServerHandshake into TLS::NegotiateParametersFromClientHello; both servers call it, so they choose alike. TLS behavior is unchanged.

Evidence

  • RFC 9001 Appendix A.1 (keys), A.2 (client Initial both ways), A.3 (server Initial both ways), A.4 (Retry tag), A.5 (ChaCha20 short header, mask, key update secret), also under -Dberyl_portable_ciphers.
  • Handshake end to end on all three suites against a client built from Beryl's codecs, with key interop checks; HRR; one byte at a time; missing ALPN; missing transport parameters; legacy_session_id; duplicate extension; early_data ignored; KeyUpdate; bad Finished; oversized message; unread data at a key change.

Move check_client_hello, check_second_client_hello and the choice of
cipher suite, group, ALPN protocol and server name out of
TLS::ServerHandshake into TLS::NegotiateParametersFromClientHello, so the
QUIC server handshake can call the same code. The TLS server applies the
client's record_size_limit itself, as before; its behavior is unchanged.
…shake

- PacketProtection: initial secrets from the client's Destination
  Connection ID, packet protection under quic key/quic iv with into:
  forms, header protection masks (AES-ECB and ChaCha20 under quic hp),
  and key update under quic ku sharing the header protection key.
- ServerHandshake: the TLS 1.3 server handshake over CRYPTO data per
  encryption level, with one HelloRetryRequest, ALPN required, the
  quic_transport_parameters extension both ways, an empty
  legacy_session_id, no 0-RTT, tickets or KeyUpdate, bounded buffering
  per level, and every derived secret wiped.
- HandshakeError carries the alert and the QUIC error code.
- QUIC.retry_integrity_tag for Retry packets.
- Specs: every RFC 9001 Appendix A vector, key update, tampering, and the
  handshake end to end against a client built from Beryl's codecs.
PacketProtection#header_protection_mask(sample, into: mask) writes the
5-byte mask into the caller's storage, so a transport's per-packet path
allocates nothing; the allocating form stays.
NegotiateParametersFromClientHello now takes the transport it serves
(Transport::TCP or Transport::QUIC). Over TCP a ClientHello carrying
quic_transport_parameters (0x39) ends with unsupported_extension; the QUIC
server handshake passes Transport::QUIC and still requires the extension
itself, as before. A new handshake spec sends the client's own ClientHello
with 0x39 added and checks the alert on the wire.
spec/probes/secret_flow.cr gains header_protection_keying (the quic hp key
from a secret traffic secret) and header_protection_mask (the mask the
check follows out of the key), run under every suite; secret_taint.cr
runs the same under Memcheck. check_secret_flow.rb analyzes
Beryl::QUIC::HeaderProtectionKey as a cipher object, and now treats the
buffers of a cipher object passed to a probe entry point as key material:
the mask was inlined into the probe, so the self-only rule missed a
branch planted on the ChaCha20 key; with this change the planted branch
is reported and the real code passes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant