6#include "tls/ext/salpn/negotiate.h"
7#include "tls/ext/salpn/sni_check.h"
8#include "tls/ext/stp/server_tp.h"
13#include "tls/keys/ticket/ticket.h"
RFC 8446 4.4.2/4.4.3: the Certificate and CertificateVerify handshake messages.
#define TLS_CERT_CHAIN_MAX
Longest certificate_list this SDK walks (leaf + up to 9 issuers — public web chains are typically 2-3...
Definition cert.h:35
RFC 5869 HKDF over HMAC-SHA-256, plus the TLS 1.3 / QUIC HKDF-Expand-Label construction (RFC 8446 7....
RFC 9001 5.2: Initial packet protection keys derived from the client's Destination Connection ID.
int sdrv_handshake_secret(const sdrv *s, const u8 **secret)
Point *secret at the derived Handshake Secret (verification aid).
int sdrv_set_cids_retried(sdrv *s, wired_span odcid, wired_span iscid, wired_span true_odcid)
RFC 9000 7.3, post-Retry accept: odcid is the Initial-key derivation input (the Retry's own SCID – th...
int sdrv_early_keys(const sdrv *s, initial_keys *out)
RFC 8446 4.2.10 / RFC 9001 4.6.1: the 0-RTT packet-protection keys (client_early_traffic_secret's key...
int sdrv_set_retry_scid(sdrv *s, wired_span rscid)
Record the Retry packet's SCID for the retry_source_connection_id transport parameter (RFC 9000 7....
salpn_sni_outcome sdrv_sni_outcome(const sdrv *s)
RFC 6066 3: the outcome of checking the last ClientHello's server_name against this driver's own cert...
void sdrv_set_preferred_address(sdrv *s, const sdrv_pref_addr *p)
RFC 9000 9.6: arm the preferred_address transport parameter for this connection's flight.
int sdrv_set_cids(sdrv *s, wired_span odcid, wired_span iscid)
RFC 9000 7.3: record the ODCID (the DCID of the client's first Initial) and the ISCID (the server's s...
int sdrv_recv_client_hello(sdrv *s, const u8 *ch_msg, usz ch_len)
RFC 8446 4.4.1: fold the ClientHello into the transcript and take the client's x25519 key_share.
void sdrv_set_ticket_key_prev(sdrv *s, const u8 *prev)
Key rotation: also open presented tickets under prev (TICKET_KEY_LEN bytes, copied),...
int sdrv_build_server_flight(sdrv *s, const u8 *server_random, const sdrv_flight_out *out)
RFC 8446 4.4: build the full server flight into out->sh / out->hs.
int sdrv_build_hrr(sdrv *s, wired_obuf *out)
RFC 8446 4.1.4 / 4.4.1: build the HelloRetryRequest (requesting x25519, this driver's only supported ...
int sdrv_early_allowed(const sdrv *s)
0-RTT is ever admitted under the negotiated ALPN: never on a raw-QUIC id (draft-ietf-moq-transport-18...
void sdrv_discard_early_keys(sdrv *s)
RFC 9001 4.9.3: zero the cached 0-RTT keys and mark them unusable once the connection has switched to...
void sdrv_set_raw_alpns(sdrv *s, const char *raw_alpns)
RFC 7301 3.2: also select the raw-QUIC application ids in raw_alpns (see wired_srvboot_id....
int sdrv_enforce_sni(sdrv *s)
RFC 6066 3: opt-in enforcement of the last checked SNI outcome.
void sdrv_set_client_version(sdrv *s, u32 version)
RFC 9368 2.2: record the QUIC version the client's Initial arrived in, so sdrv_recv_client_hello can ...
u64 sdrv_last_error(const sdrv *s)
RFC 9001 8.2 / RFC 9000 20.1: the CRYPTO_ERROR recorded by the last sdrv_recv_client_hello call,...
int sdrv_hrr_pending(const sdrv *s)
RFC 8446 4.1.4: 1 when the last sdrv_recv_client_hello call found no x25519 key_share and a HelloRetr...
u32 sdrv_wire_version(const sdrv *s)
RFC 9368 2.3: the QUIC version every packet of this server's flight (and everything after it) must be...
void sdrv_set_group(sdrv *s, u16 group)
RFC 8446 4.2.7: select the NamedGroup for the ECDHE key_share (GROUP_X25519 or GROUP_SECP256R1).
void sdrv_init(sdrv *s, const sdrv_init_in *in)
Hold the server key material.
Value-type views that fold the SDK's recurring argument shapes into single parameters,...
One direction's packet protection keys (RFC 9001 5.1/5.2).
Definition initial.h:28
Destination for sdrv_build_server_flight: sh receives the ServerHello, hs the EncryptedExtensions || ...
Definition sdrv.h:457
wired_obuf * sh
receives the ServerHello
Definition sdrv.h:458
wired_obuf * hs
receives EncryptedExtensions || Certificate || CertificateVerify || Finished
Definition sdrv.h:459
Inputs to sdrv_init.
Definition sdrv.h:280
const u8 * ticket_key
RFC 8446 4.6.1: this server's session-ticket encryption key (TICKET_KEY_LEN bytes),...
Definition sdrv.h:297
const u8 * server_pub_x25519
ECDHE x25519 public (32 bytes).
Definition sdrv.h:282
const u8 * server_priv_x25519
ECDHE x25519 private (32 bytes).
Definition sdrv.h:281
u64 now_secs
RFC 5280 4.1.2.5.1: see wired_srvboot_id.now_secs's doc.
Definition sdrv.h:293
const wired_span * chain
external chain, leaf first; NULL for self-signed mode (caller keeps the views alive through the hands...
Definition sdrv.h:284
usz chain_count
entries in chain; 0 = self-signed mode
Definition sdrv.h:287
const u8 * san_ipv4
RFC 5280 4.2.1.6: see wired_srvboot_id.san_ipv4's doc.
Definition sdrv.h:289
const u8 * sign_priv
ECDSA P-256 signing scalar (32 bytes).
Definition sdrv.h:283
Inputs to sdrv_set_preferred_address: both addresses in network byte order, the CID the migrating cli...
Definition sdrv.h:246
const u8 * token
16 bytes
Definition sdrv.h:253
const u8 * v4
4 bytes
Definition sdrv.h:247
u8 cid_len
1..20
Definition sdrv.h:252
const u8 * cid
cid_len bytes
Definition sdrv.h:251
const u8 * v6
16 bytes
Definition sdrv.h:249
u16 v6_port
host byte order; encoded big-endian
Definition sdrv.h:250
u16 v4_port
host byte order; encoded big-endian
Definition sdrv.h:248
Server-side handshake driver state.
Definition sdrv.h:23
u8 client_sid[32]
RFC 8446 4.1.2 legacy_session_id.
Definition sdrv.h:162
u8 rscid_len
bytes used in rscid; 0 = no Retry
Definition sdrv.h:206
stp_limits limits
advertised tunable limits (0 = defaults)
Definition sdrv.h:30
u32 client_version
RFC 9368 2.2: the QUIC version the client's Initial actually arrived in, recorded via sdrv_set_client...
Definition sdrv.h:124
u64 last_error
RFC 9001 8.2: the CRYPTO_ERROR (0x0100 | TLS alert) recorded when sdrv_recv_client_hello rejects the ...
Definition sdrv.h:74
u8 sreset_token[16]
stateless_reset_token (RFC 9000 10.3.1/18.2) for iscid, advertised in the EncryptedExtensions transpo...
Definition sdrv.h:212
u8 client_sid_len
0..32
Definition sdrv.h:163
u16 pref_v4_port
Port of the advertised IPv4 address, host byte order (encoded big-endian on the wire).
Definition sdrv.h:228
u64 peer_initial_max_stream_data_bidi_remote
peer's initial_max_stream_data_bidi_remote (0x06, RFC 9000 18.2): the per-stream credit for bidi stre...
Definition sdrv.h:53
salpn_sni_outcome sni_outcome
RFC 6066 3: the ClientHello's server_name extension checked against this driver's own certificate (sa...
Definition sdrv.h:119
u8 iscid_len
bytes used in iscid (0..20)
Definition sdrv.h:196
u64 peer_initial_max_stream_data_bidi_local
peer's initial_max_stream_data_bidi_local (0x05, RFC 9000 18.2): the TP sender's own locally-initiate...
Definition sdrv.h:41
int hrr_sent
1 once sdrv_build_hrr has emitted a HelloRetryRequest for this connection; the next sdrv_recv_client_...
Definition sdrv.h:110
u64 peer_initial_max_stream_data_uni
peer's initial_max_stream_data_uni (0x07, RFC 9000 18.2): the per-stream credit for uni streams this ...
Definition sdrv.h:57
u8 pref_cid[20]
The connection ID embedded in the parameter (sequence number 1).
Definition sdrv.h:236
u64 peer_initial_max_streams_uni
peer's initial_max_streams_uni (0x09, RFC 9000 18.2): how many uni streams THIS endpoint may open tow...
Definition sdrv.h:62
salpn_choice alpn
RFC 7301 3.1/3.2: this server's negotiated ALPN protocol – the first entry of the client's list that ...
Definition sdrv.h:100
u8 ticket_key_prev[TICKET_KEY_LEN]
The previous-generation ticket key (key rotation): a ticket that does not open under ticket_key is tr...
Definition sdrv.h:172
int hrr_needed
RFC 8446 4.1.4: set by sdrv_recv_client_hello when the ClientHello carried no x25519 key_share,...
Definition sdrv.h:105
u8 odcid_len
bytes used in odcid (0..20)
Definition sdrv.h:194
u8 pref_token[16]
Stateless reset token paired with the embedded CID.
Definition sdrv.h:240
u8 san_ipv4[4]
RFC 5280 4.2.1.6: see wired_srvboot_id.san_ipv4's doc.
Definition sdrv.h:160
const char * raw_alpns
Configured raw-QUIC ids (sdrv_set_raw_alpns), or 0 for none.
Definition sdrv.h:68
u8 pref_v6[16]
IPv6 address of the preferred_address parameter, network byte order.
Definition sdrv.h:231
u8 tp_odcid_len
bytes used in tp_odcid (0..20)
Definition sdrv.h:202
u8 tp_odcid[20]
RFC 9000 7.3 original_destination_connection_id transport parameter value: the true first Initial's D...
Definition sdrv.h:201
u8 ecdhe_secret[32]
RFC 8446 7.1: the ECDHE shared secret the flight derivation computed (x25519 output,...
Definition sdrv.h:187
u8 s_hs_traffic[TLS_HASH_MAX]
RFC 8446 7.1 server hs traffic secret (Hash.length bytes).
Definition sdrv.h:182
u16 cipher_suite
RFC 8446 B.4 / RFC 9001 9.3: this server's negotiated TLS 1.3 cipher suite (AES_128_GCM_ SHA256 prefe...
Definition sdrv.h:136
u8 cert_buf[512]
self-signed P-256 cert DER (owned)
Definition sdrv.h:156
u8 psk_secret[TICKET_SECRET_LEN]
The opened ticket's resumption secret; meaningful when psk_accepted.
Definition sdrv.h:174
u8 server_pub[65]
ECDHE public key_share: 32-byte RFC 7748 x25519, or 65-byte SEC1 uncompressed P-256 (RFC 8446 4....
Definition sdrv.h:151
u16 hrr_cipher_suite
The cipher_suite negotiated from ClientHello1, recorded when hrr_sent becomes 1 so ClientHello2 can b...
Definition sdrv.h:147
int psk_accepted
RFC 8446 4.2.11/4.2.11.2: set by sdrv_recv_client_hello when the ClientHello's pre_shared_key ticket ...
Definition sdrv.h:81
int early_data_accepted
RFC 8446 4.2.10 / RFC 9001 4.6.1/9.2: set by sdrv_recv_client_hello when the ClientHello carries earl...
Definition sdrv.h:89
u8 p256_priv[32]
RFC 5480 ECDSA P-256 signing scalar; also the TBS signer for a self-built certificate.
Definition sdrv.h:154
u8 server_priv[32]
ECDHE private scalar (RFC 7748 x25519 or the P-256 SEC1 scalar, per group); always 32 bytes for eithe...
Definition sdrv.h:148
u8 pref_v4[4]
RFC 9000 9.6/18.2: the preferred_address transport parameter this flight advertises,...
Definition sdrv.h:225
u8 client_pub[65]
RFC 8446 4.2.8 client key_share, group above.
Definition sdrv.h:161
u64 peer_max_datagram_frame_size
peer's max_datagram_frame_size (0x20, RFC 9221 3) from the ClientHello transport parameters; 0 = not ...
Definition sdrv.h:34
wired_span certs[TLS_CERT_CHAIN_MAX]
RFC 8446 4.4.2 certificate_list, leaf first (caller-owned views in external-chain mode).
Definition sdrv.h:24
u16 group
RFC 8446 4.2.7 NamedGroup negotiated for the ECDHE key_share (GROUP_X25519 or GROUP_SECP256R1); GROUP...
Definition sdrv.h:135
u16 pref_v6_port
Port of the advertised IPv6 address, host byte order (encoded big-endian on the wire).
Definition sdrv.h:234
u8 pref_cid_len
Length of pref_cid in bytes; 0 omits the whole parameter.
Definition sdrv.h:238
transcript tr
RFC 8446 4.4.1 Transcript-Hash.
Definition sdrv.h:29
u8 odcid[20]
RFC 9001 5.2 Initial-key derivation input: the DCID of the Initial packet actually being processed ri...
Definition sdrv.h:193
u64 peer_initial_max_data
peer's initial_max_data (0x04, RFC 9000 18.2) from the ClientHello transport parameters – the connect...
Definition sdrv.h:35
int hs_ready
hs_secret derived
Definition sdrv.h:95
u8 rscid[20]
RFC 9000 7.3 retry_source_connection_id – the Retry packet's SCID, advertised only when a Retry prece...
Definition sdrv.h:203
int early_keys_dropped
RFC 9001 4.9.3: set (with early_keys zeroed) by sdrv_discard_early_keys once 1-RTT keys are installed...
Definition sdrv.h:94
usz cert_count
0 = nothing to send (flight build fails)
Definition sdrv.h:28
u8 sreset_token_set
1 once sreset_token holds a real token
Definition sdrv.h:213
int has_ticket_key
1 when ticket_key is set; 0 disables resumption.
Definition sdrv.h:76
u8 hs_secret[TLS_HASH_MAX]
RFC 8446 7.1 Handshake Secret (Hash.length bytes).
Definition sdrv.h:180
initial_keys early_keys
RFC 8446 4.2.10 / RFC 9001 4.6.1: the 0-RTT packet-protection keys, meaningful only when early_data_a...
Definition sdrv.h:178
u8 ticket_key[TICKET_KEY_LEN]
RFC 8446 4.6.1: this server's session-ticket encryption key, or has_ticket_key 0 to disable resumptio...
Definition sdrv.h:168
wired_span alpn_tok
The raw protocol id when alpn is SALPN_RAW (e.g.
Definition sdrv.h:66
u8 iscid[20]
RFC 9000 7.3 server SCID.
Definition sdrv.h:195
u32 negotiated_version
RFC 9368 2.3: the compatible version this server selected from the ClientHello's version_information ...
Definition sdrv.h:130
u8 ch1_hash[TLS_HASH_MAX]
RFC 8446 4.4.1: Hash(ClientHello1) under the negotiated suite's hash (Hash.length bytes),...
Definition sdrv.h:218
RFC 9000 18.2: the operator-tunable integer limits this server advertises; a zero field falls back to...
Definition server_tp.h:61
Cumulative Transcript-Hash state.
Definition transcript.h:11
Growing output buffer view for variable-length results.
Definition span.h:54
Read-only view of a byte range.
Definition span.h:30
RFC 8446 B.4 / 7.1: the hash a TLS 1.3 cipher suite runs its key schedule, transcript and Finished MA...
#define TLS_HASH_MAX
Largest Hash.length of any supported suite (SHA-384).
Definition suitehash.h:12
RFC 8446 4.4.1: cumulative Transcript-Hash over handshake messages.
unsigned int u32
unsigned 32-bit integer
Definition types.h:15
u64 usz
unsigned size (size_t equivalent)
Definition types.h:20
unsigned short u16
unsigned 16-bit integer
Definition types.h:17
unsigned char u8
unsigned 8-bit integer / byte
Definition types.h:18
unsigned long u64
unsigned 64-bit integer
Definition types.h:13