blob: 5f983456fb5ce45a92212be32e927dac08227910 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef QUICHE_QUIC_CORE_CRYPTO_CRYPTO_PROTOCOL_H_
6#define QUICHE_QUIC_CORE_CRYPTO_CRYPTO_PROTOCOL_H_
7
8#include <cstddef>
vasilvv872e7a32019-03-12 16:42:44 -07009#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -050010
11#include "net/third_party/quiche/src/quic/core/quic_tag.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050012
13// Version and Crypto tags are written to the wire with a big-endian
14// representation of the name of the tag. For example
15// the client hello tag (CHLO) will be written as the
16// following 4 bytes: 'C' 'H' 'L' 'O'. Since it is
17// stored in memory as a little endian uint32_t, we need
18// to reverse the order of the bytes.
19//
20// We use a macro to ensure that no static initialisers are created. Use the
21// MakeQuicTag function in normal code.
22#define TAG(a, b, c, d) \
23 static_cast<QuicTag>((d << 24) + (c << 16) + (b << 8) + a)
24
25namespace quic {
26
vasilvvc48c8712019-03-11 13:38:16 -070027typedef std::string ServerConfigID;
QUICHE teama6ef0a62019-03-07 20:34:33 -050028
wub5b352f12019-05-07 11:45:26 -070029// The following tags have been deprecated and should not be reused:
wub722bad42019-07-15 11:27:57 -070030// "1CON", "BBQ4", "NCON", "RCID", "SREJ", "TBKP", "TB10"
wub5b352f12019-05-07 11:45:26 -070031
QUICHE teama6ef0a62019-03-07 20:34:33 -050032// clang-format off
33const QuicTag kCHLO = TAG('C', 'H', 'L', 'O'); // Client hello
34const QuicTag kSHLO = TAG('S', 'H', 'L', 'O'); // Server hello
35const QuicTag kSCFG = TAG('S', 'C', 'F', 'G'); // Server config
36const QuicTag kREJ = TAG('R', 'E', 'J', '\0'); // Reject
QUICHE teama6ef0a62019-03-07 20:34:33 -050037const QuicTag kCETV = TAG('C', 'E', 'T', 'V'); // Client encrypted tag-value
38 // pairs
39const QuicTag kPRST = TAG('P', 'R', 'S', 'T'); // Public reset
40const QuicTag kSCUP = TAG('S', 'C', 'U', 'P'); // Server config update
41const QuicTag kALPN = TAG('A', 'L', 'P', 'N'); // Application-layer protocol
42
43// Key exchange methods
44const QuicTag kP256 = TAG('P', '2', '5', '6'); // ECDH, Curve P-256
45const QuicTag kC255 = TAG('C', '2', '5', '5'); // ECDH, Curve25519
46
47// AEAD algorithms
48const QuicTag kAESG = TAG('A', 'E', 'S', 'G'); // AES128 + GCM-12
49const QuicTag kCC20 = TAG('C', 'C', '2', '0'); // ChaCha20 + Poly1305 RFC7539
50
51// Congestion control feedback types
52const QuicTag kQBIC = TAG('Q', 'B', 'I', 'C'); // TCP cubic
53
54// Connection options (COPT) values
55const QuicTag kAFCW = TAG('A', 'F', 'C', 'W'); // Auto-tune flow control
56 // receive windows.
57const QuicTag kIFW5 = TAG('I', 'F', 'W', '5'); // Set initial size
58 // of stream flow control
59 // receive window to
60 // 32KB. (2^5 KB).
61const QuicTag kIFW6 = TAG('I', 'F', 'W', '6'); // Set initial size
62 // of stream flow control
63 // receive window to
64 // 64KB. (2^6 KB).
65const QuicTag kIFW7 = TAG('I', 'F', 'W', '7'); // Set initial size
66 // of stream flow control
67 // receive window to
68 // 128KB. (2^7 KB).
69const QuicTag kIFW8 = TAG('I', 'F', 'W', '8'); // Set initial size
70 // of stream flow control
71 // receive window to
72 // 256KB. (2^8 KB).
73const QuicTag kIFW9 = TAG('I', 'F', 'W', '9'); // Set initial size
74 // of stream flow control
75 // receive window to
76 // 512KB. (2^9 KB).
77const QuicTag kIFWA = TAG('I', 'F', 'W', 'a'); // Set initial size
78 // of stream flow control
79 // receive window to
80 // 1MB. (2^0xa KB).
81const QuicTag kTBBR = TAG('T', 'B', 'B', 'R'); // Reduced Buffer Bloat TCP
82const QuicTag k1RTT = TAG('1', 'R', 'T', 'T'); // STARTUP in BBR for 1 RTT
83const QuicTag k2RTT = TAG('2', 'R', 'T', 'T'); // STARTUP in BBR for 2 RTTs
84const QuicTag kLRTT = TAG('L', 'R', 'T', 'T'); // Exit STARTUP in BBR on loss
85const QuicTag kBBS1 = TAG('B', 'B', 'S', '1'); // Rate-based recovery in
86 // BBR STARTUP
87const QuicTag kBBS2 = TAG('B', 'B', 'S', '2'); // More aggressive packet
88 // conservation in BBR STARTUP
89const QuicTag kBBS3 = TAG('B', 'B', 'S', '3'); // Slowstart packet
90 // conservation in BBR STARTUP
91const QuicTag kBBS4 = TAG('B', 'B', 'S', '4'); // Reduce rate in STARTUP by
92 // bytes_lost / CWND.
93const QuicTag kBBS5 = TAG('B', 'B', 'S', '5'); // Reduce rate in STARTUP by
94 // 2 * bytes_lost / CWND.
95const QuicTag kBBRR = TAG('B', 'B', 'R', 'R'); // Rate-based recovery in BBR
96const QuicTag kBBR1 = TAG('B', 'B', 'R', '1'); // DEPRECATED
97const QuicTag kBBR2 = TAG('B', 'B', 'R', '2'); // DEPRECATED
98const QuicTag kBBR3 = TAG('B', 'B', 'R', '3'); // Fully drain the queue once
99 // per cycle
100const QuicTag kBBR4 = TAG('B', 'B', 'R', '4'); // 20 RTT ack aggregation
101const QuicTag kBBR5 = TAG('B', 'B', 'R', '5'); // 40 RTT ack aggregation
102const QuicTag kBBR6 = TAG('B', 'B', 'R', '6'); // PROBE_RTT with 0.75 * BDP
103const QuicTag kBBR7 = TAG('B', 'B', 'R', '7'); // Skip PROBE_RTT if rtt has
104 // not changed 12.5%
105const QuicTag kBBR8 = TAG('B', 'B', 'R', '8'); // Disable PROBE_RTT when
106 // recently app-limited
107const QuicTag kBBR9 = TAG('B', 'B', 'R', '9'); // Ignore app-limited calls in
108 // BBR if enough inflight.
109const QuicTag kBBRS = TAG('B', 'B', 'R', 'S'); // Use 1.5x pacing in startup
110 // after a loss has occurred.
111const QuicTag kBBQ1 = TAG('B', 'B', 'Q', '1'); // BBR with lower 2.77 STARTUP
112 // pacing and CWND gain.
113const QuicTag kBBQ2 = TAG('B', 'B', 'Q', '2'); // BBR with lower 2.0 STARTUP
114 // CWND gain.
115const QuicTag kBBQ3 = TAG('B', 'B', 'Q', '3'); // BBR with ack aggregation
116 // compensation in STARTUP.
QUICHE teama6ef0a62019-03-07 20:34:33 -0500117const QuicTag kBBQ5 = TAG('B', 'B', 'Q', '5'); // Expire ack aggregation upon
118 // bandwidth increase in
119 // STARTUP.
120const QuicTag kRENO = TAG('R', 'E', 'N', 'O'); // Reno Congestion Control
121const QuicTag kTPCC = TAG('P', 'C', 'C', '\0'); // Performance-Oriented
122 // Congestion Control
123const QuicTag kBYTE = TAG('B', 'Y', 'T', 'E'); // TCP cubic or reno in bytes
124const QuicTag kIW03 = TAG('I', 'W', '0', '3'); // Force ICWND to 3
125const QuicTag kIW10 = TAG('I', 'W', '1', '0'); // Force ICWND to 10
126const QuicTag kIW20 = TAG('I', 'W', '2', '0'); // Force ICWND to 20
127const QuicTag kIW50 = TAG('I', 'W', '5', '0'); // Force ICWND to 50
wuba9a43cb2019-07-17 15:22:42 -0700128const QuicTag kB2ON = TAG('B', '2', 'O', 'N'); // Enable BBRv2
QUICHE teama6ef0a62019-03-07 20:34:33 -0500129const QuicTag kNTLP = TAG('N', 'T', 'L', 'P'); // No tail loss probe
130const QuicTag k1TLP = TAG('1', 'T', 'L', 'P'); // 1 tail loss probe
131const QuicTag k1RTO = TAG('1', 'R', 'T', 'O'); // Send 1 packet upon RTO
132const QuicTag kNRTO = TAG('N', 'R', 'T', 'O'); // CWND reduction on loss
133const QuicTag kTIME = TAG('T', 'I', 'M', 'E'); // Time based loss detection
134const QuicTag kATIM = TAG('A', 'T', 'I', 'M'); // Adaptive time loss detection
135const QuicTag kMIN1 = TAG('M', 'I', 'N', '1'); // Min CWND of 1 packet
136const QuicTag kMIN4 = TAG('M', 'I', 'N', '4'); // Min CWND of 4 packets,
137 // with a min rate of 1 BDP.
138const QuicTag kTLPR = TAG('T', 'L', 'P', 'R'); // Tail loss probe delay of
139 // 0.5RTT.
140const QuicTag kMAD0 = TAG('M', 'A', 'D', '0'); // Ignore ack delay
141const QuicTag kMAD1 = TAG('M', 'A', 'D', '1'); // 25ms initial max ack delay
142const QuicTag kMAD2 = TAG('M', 'A', 'D', '2'); // No min TLP
143const QuicTag kMAD3 = TAG('M', 'A', 'D', '3'); // No min RTO
144const QuicTag kMAD4 = TAG('M', 'A', 'D', '4'); // IETF style TLP
145const QuicTag kMAD5 = TAG('M', 'A', 'D', '5'); // IETF style TLP with 2x mult
146const QuicTag kACD0 = TAG('A', 'D', 'D', '0'); // Disable ack decimation
147const QuicTag kACKD = TAG('A', 'C', 'K', 'D'); // Ack decimation style acking.
148const QuicTag kAKD2 = TAG('A', 'K', 'D', '2'); // Ack decimation tolerating
149 // out of order packets.
150const QuicTag kAKD3 = TAG('A', 'K', 'D', '3'); // Ack decimation style acking
151 // with 1/8 RTT acks.
152const QuicTag kAKD4 = TAG('A', 'K', 'D', '4'); // Ack decimation with 1/8 RTT
153 // tolerating out of order.
154const QuicTag kAKDU = TAG('A', 'K', 'D', 'U'); // Unlimited number of packets
155 // received before acking
156const QuicTag kACKQ = TAG('A', 'C', 'K', 'Q'); // Send an immediate ack after
157 // 1 RTT of not receiving.
158const QuicTag kSSLR = TAG('S', 'S', 'L', 'R'); // Slow Start Large Reduction.
159const QuicTag kNPRR = TAG('N', 'P', 'R', 'R'); // Pace at unity instead of PRR
160const QuicTag k5RTO = TAG('5', 'R', 'T', 'O'); // Close connection on 5 RTOs
161const QuicTag kCONH = TAG('C', 'O', 'N', 'H'); // Conservative Handshake
162 // Retransmissions.
163const QuicTag kLFAK = TAG('L', 'F', 'A', 'K'); // Don't invoke FACK on the
164 // first ack.
165const QuicTag kSTMP = TAG('S', 'T', 'M', 'P'); // Send and process timestamps
fayangb0c7b4b2019-09-12 06:45:24 -0700166
167const QuicTag kILD0 = TAG('I', 'L', 'D', '0'); // IETF style loss detection
168 // (default with 1/8 RTT time
169 // threshold)
170const QuicTag kILD1 = TAG('I', 'L', 'D', '1'); // IETF style loss detection
171 // with 1/4 RTT time threshold
172const QuicTag kILD2 = TAG('I', 'L', 'D', '2'); // IETF style loss detection
173 // with adaptive packet
174 // threshold
175const QuicTag kILD3 = TAG('I', 'L', 'D', '3'); // IETF style loss detection
176 // with 1/4 RTT time threshold
177 // and adaptive packet
178 // threshold
QUICHE teama6ef0a62019-03-07 20:34:33 -0500179// TODO(fayang): Remove this connection option when QUIC_VERSION_35, is removed
180// Since MAX_HEADER_LIST_SIZE settings frame is supported instead.
181const QuicTag kSMHL = TAG('S', 'M', 'H', 'L'); // Support MAX_HEADER_LIST_SIZE
182 // settings frame.
183const QuicTag kNSTP = TAG('N', 'S', 'T', 'P'); // No stop waiting frames.
184const QuicTag kNRTT = TAG('N', 'R', 'T', 'T'); // Ignore initial RTT
185
fayangce0a3162019-08-15 09:05:36 -0700186const QuicTag k1PTO = TAG('1', 'P', 'T', 'O'); // Send 1 packet upon PTO.
187const QuicTag k2PTO = TAG('2', 'P', 'T', 'O'); // Send 2 packets upon PTO.
188
189const QuicTag k7PTO = TAG('7', 'P', 'T', 'O'); // Closes connection on 7
190 // consecutive PTOs.
191const QuicTag k8PTO = TAG('8', 'P', 'T', 'O'); // Closes connection on 8
192 // consecutive PTOs.
fayang4c1c2362019-09-13 07:20:01 -0700193const QuicTag kPTOS = TAG('P', 'T', 'O', 'S'); // Skip packet number before
194 // sending the last PTO.
fayangce0a3162019-08-15 09:05:36 -0700195
QUICHE teama6ef0a62019-03-07 20:34:33 -0500196// Optional support of truncated Connection IDs. If sent by a peer, the value
197// is the minimum number of bytes allowed for the connection ID sent to the
198// peer.
199const QuicTag kTCID = TAG('T', 'C', 'I', 'D'); // Connection ID truncation.
200
201// Multipath option.
202const QuicTag kMPTH = TAG('M', 'P', 'T', 'H'); // Enable multipath.
203
204const QuicTag kNCMR = TAG('N', 'C', 'M', 'R'); // Do not attempt connection
205 // migration.
206
207// Disable Pacing offload option.
208const QuicTag kNPCO = TAG('N', 'P', 'C', 'O'); // No pacing offload.
209
210// Enable bandwidth resumption experiment.
211const QuicTag kBWRE = TAG('B', 'W', 'R', 'E'); // Bandwidth resumption.
212const QuicTag kBWMX = TAG('B', 'W', 'M', 'X'); // Max bandwidth resumption.
213const QuicTag kBWRS = TAG('B', 'W', 'R', 'S'); // Server bandwidth resumption.
214const QuicTag kBWS2 = TAG('B', 'W', 'S', '2'); // Server bw resumption v2.
wub5377f612019-04-29 12:55:36 -0700215const QuicTag kBWS3 = TAG('B', 'W', 'S', '3'); // QUIC Initial CWND - Control.
216const QuicTag kBWS4 = TAG('B', 'W', 'S', '4'); // QUIC Initial CWND - Enabled.
fayangf1b99dc2019-05-14 06:29:18 -0700217const QuicTag kBWS5 = TAG('B', 'W', 'S', '5'); // QUIC Initial CWND up and down
QUICHE teama6ef0a62019-03-07 20:34:33 -0500218
219// Enable path MTU discovery experiment.
220const QuicTag kMTUH = TAG('M', 'T', 'U', 'H'); // High-target MTU discovery.
221const QuicTag kMTUL = TAG('M', 'T', 'U', 'L'); // Low-target MTU discovery.
222
fayang944cfbc2019-07-31 09:15:00 -0700223// Enable Priority scheme experiment.
224const QuicTag kH2PR = TAG('H', '2', 'P', 'R'); // HTTP2 priorities.
fayange606e0c2019-08-05 06:56:05 -0700225const QuicTag kFIFO = TAG('F', 'I', 'F', 'O'); // Stream with the smallest ID
226 // has the highest priority.
fayangae266342019-08-05 12:19:59 -0700227const QuicTag kLIFO = TAG('L', 'I', 'F', 'O'); // Stream with the largest ID
228 // has the highest priority.
fayang1b11b962019-09-16 14:01:48 -0700229const QuicTag kRRWS = TAG('R', 'R', 'W', 'S'); // Round robin write scheduling.
fayang944cfbc2019-07-31 09:15:00 -0700230
QUICHE teama6ef0a62019-03-07 20:34:33 -0500231// Proof types (i.e. certificate types)
232// NOTE: although it would be silly to do so, specifying both kX509 and kX59R
233// is allowed and is equivalent to specifying only kX509.
234const QuicTag kX509 = TAG('X', '5', '0', '9'); // X.509 certificate, all key
235 // types
236const QuicTag kX59R = TAG('X', '5', '9', 'R'); // X.509 certificate, RSA keys
237 // only
238const QuicTag kCHID = TAG('C', 'H', 'I', 'D'); // Channel ID.
239
240// Client hello tags
241const QuicTag kVER = TAG('V', 'E', 'R', '\0'); // Version
242const QuicTag kNONC = TAG('N', 'O', 'N', 'C'); // The client's nonce
243const QuicTag kNONP = TAG('N', 'O', 'N', 'P'); // The client's proof nonce
244const QuicTag kKEXS = TAG('K', 'E', 'X', 'S'); // Key exchange methods
245const QuicTag kAEAD = TAG('A', 'E', 'A', 'D'); // Authenticated
246 // encryption algorithms
247const QuicTag kCOPT = TAG('C', 'O', 'P', 'T'); // Connection options
248const QuicTag kCLOP = TAG('C', 'L', 'O', 'P'); // Client connection options
249const QuicTag kICSL = TAG('I', 'C', 'S', 'L'); // Idle network timeout
250const QuicTag kSCLS = TAG('S', 'C', 'L', 'S'); // Silently close on timeout
fkastenholzd3a1de92019-05-15 07:00:07 -0700251const QuicTag kMIBS = TAG('M', 'I', 'D', 'S'); // Max incoming bidi streams
252const QuicTag kMIUS = TAG('M', 'I', 'U', 'S'); // Max incoming unidi streams
fkastenholz4dc4ba32019-07-30 09:55:25 -0700253const QuicTag kADE = TAG('A', 'D', 'E', 0); // Ack Delay Exponent (IETF
254 // QUIC ACK Frame Only).
QUICHE teama6ef0a62019-03-07 20:34:33 -0500255const QuicTag kIRTT = TAG('I', 'R', 'T', 'T'); // Estimated initial RTT in us.
256const QuicTag kSNI = TAG('S', 'N', 'I', '\0'); // Server name
257 // indication
258const QuicTag kPUBS = TAG('P', 'U', 'B', 'S'); // Public key values
259const QuicTag kSCID = TAG('S', 'C', 'I', 'D'); // Server config id
260const QuicTag kORBT = TAG('O', 'B', 'I', 'T'); // Server orbit.
261const QuicTag kPDMD = TAG('P', 'D', 'M', 'D'); // Proof demand.
262const QuicTag kPROF = TAG('P', 'R', 'O', 'F'); // Proof (signature).
263const QuicTag kCCS = TAG('C', 'C', 'S', 0); // Common certificate set
264const QuicTag kCCRT = TAG('C', 'C', 'R', 'T'); // Cached certificate
265const QuicTag kEXPY = TAG('E', 'X', 'P', 'Y'); // Expiry
266const QuicTag kSTTL = TAG('S', 'T', 'T', 'L'); // Server Config TTL
267const QuicTag kSFCW = TAG('S', 'F', 'C', 'W'); // Initial stream flow control
268 // receive window.
269const QuicTag kCFCW = TAG('C', 'F', 'C', 'W'); // Initial session/connection
270 // flow control receive window.
271const QuicTag kUAID = TAG('U', 'A', 'I', 'D'); // Client's User Agent ID.
272const QuicTag kXLCT = TAG('X', 'L', 'C', 'T'); // Expected leaf certificate.
QUICHE teama6ef0a62019-03-07 20:34:33 -0500273
fkastenholz4c7303c2019-07-29 08:17:07 -0700274const QuicTag kMAD = TAG('M', 'A', 'D', 0); // Max Ack Delay (IETF QUIC)
275
QUICHE teama6ef0a62019-03-07 20:34:33 -0500276// Rejection tags
277const QuicTag kRREJ = TAG('R', 'R', 'E', 'J'); // Reasons for server sending
wub0a4b9c52019-05-28 13:18:58 -0700278
QUICHE teama6ef0a62019-03-07 20:34:33 -0500279// Server hello tags
280const QuicTag kCADR = TAG('C', 'A', 'D', 'R'); // Client IP address and port
281const QuicTag kASAD = TAG('A', 'S', 'A', 'D'); // Alternate Server IP address
282 // and port.
283const QuicTag kSRST = TAG('S', 'R', 'S', 'T'); // Stateless reset token used
284 // in IETF public reset packet
285
286// CETV tags
287const QuicTag kCIDK = TAG('C', 'I', 'D', 'K'); // ChannelID key
288const QuicTag kCIDS = TAG('C', 'I', 'D', 'S'); // ChannelID signature
289
290// Public reset tags
291const QuicTag kRNON = TAG('R', 'N', 'O', 'N'); // Public reset nonce proof
292const QuicTag kRSEQ = TAG('R', 'S', 'E', 'Q'); // Rejected packet number
293
294// Universal tags
295const QuicTag kPAD = TAG('P', 'A', 'D', '\0'); // Padding
296
297// Stats collection tags
298const QuicTag kEPID = TAG('E', 'P', 'I', 'D'); // Endpoint identifier.
299
300// clang-format on
301
302// These tags have a special form so that they appear either at the beginning
303// or the end of a handshake message. Since handshake messages are sorted by
304// tag value, the tags with 0 at the end will sort first and those with 255 at
305// the end will sort last.
306//
307// The certificate chain should have a tag that will cause it to be sorted at
308// the end of any handshake messages because it's likely to be large and the
309// client might be able to get everything that it needs from the small values at
310// the beginning.
311//
312// Likewise tags with random values should be towards the beginning of the
313// message because the server mightn't hold state for a rejected client hello
314// and therefore the client may have issues reassembling the rejection message
315// in the event that it sent two client hellos.
316const QuicTag kServerNonceTag = TAG('S', 'N', 'O', 0); // The server's nonce
317const QuicTag kSourceAddressTokenTag =
318 TAG('S', 'T', 'K', 0); // Source-address token
319const QuicTag kCertificateTag = TAG('C', 'R', 'T', 255); // Certificate chain
320const QuicTag kCertificateSCTTag =
321 TAG('C', 'S', 'C', 'T'); // Signed cert timestamp (RFC6962) of leaf cert.
322
323#undef TAG
324
325const size_t kMaxEntries = 128; // Max number of entries in a message.
326
327const size_t kNonceSize = 32; // Size in bytes of the connection nonce.
328
329const size_t kOrbitSize = 8; // Number of bytes in an orbit value.
330
331// kProofSignatureLabel is prepended to the CHLO hash and server configs before
332// signing to avoid any cross-protocol attacks on the signature.
333const char kProofSignatureLabel[] = "QUIC CHLO and server config signature";
334
335// kClientHelloMinimumSize is the minimum size of a client hello. Client hellos
336// will have PAD tags added in order to ensure this minimum is met and client
337// hellos smaller than this will be an error. This minimum size reduces the
338// amplification factor of any mirror DoS attack.
339//
340// A client may pad an inchoate client hello to a size larger than
341// kClientHelloMinimumSize to make it more likely to receive a complete
342// rejection message.
343const size_t kClientHelloMinimumSize = 1024;
344
345} // namespace quic
346
347#endif // QUICHE_QUIC_CORE_CRYPTO_CRYPTO_PROTOCOL_H_