blob: 77b33594f79b08e9b0be8e3234e4c8081c1243b6 [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// Definitions and utility functions related to handling of QUIC versions.
6//
dschinazia98acdf2020-05-21 15:34:16 -07007// QUIC versions are encoded over the wire as an opaque 32bit field. The wire
8// encoding is represented in memory as a QuicVersionLabel type (which is an
9// alias to uint32_t). Conceptual versions are represented in memory as
10// ParsedQuicVersion.
11//
12// We currently support two kinds of QUIC versions, GoogleQUIC and IETF QUIC.
13//
14// All GoogleQUIC versions use a wire encoding that matches the following regex
15// when converted to ASCII: "[QT]0\d\d" (e.g. Q050). Q or T distinguishes the
16// type of handshake used (Q for the QUIC_CRYPTO handshake, T for the QUIC+TLS
17// handshake), and the two digits at the end contain the numeric value of
18// the transport version used.
19//
20// All IETF QUIC versions use the wire encoding described in:
21// https://tools.ietf.org/html/draft-ietf-quic-transport
QUICHE teama6ef0a62019-03-07 20:34:33 -050022
23#ifndef QUICHE_QUIC_CORE_QUIC_VERSIONS_H_
24#define QUICHE_QUIC_CORE_QUIC_VERSIONS_H_
25
vasilvv872e7a32019-03-12 16:42:44 -070026#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -050027#include <vector>
28
29#include "net/third_party/quiche/src/quic/core/quic_tag.h"
30#include "net/third_party/quiche/src/quic/core/quic_types.h"
31#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
dschinazicee73cd2020-03-05 18:20:50 -080032#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050033
34namespace quic {
35
dschinazia98acdf2020-05-21 15:34:16 -070036// The list of existing QUIC transport versions. Note that QUIC versions are
37// sent over the wire as an encoding of ParsedQuicVersion, which requires a
38// QUIC transport version and handshake protocol. For transport versions of the
39// form QUIC_VERSION_XX where XX is decimal, the enum numeric value is
40// guaranteed to match the name. Older deprecated transport versions are
41// documented in comments below.
QUICHE teama6ef0a62019-03-07 20:34:33 -050042enum QuicTransportVersion {
43 // Special case to indicate unknown/unsupported QUIC version.
44 QUIC_VERSION_UNSUPPORTED = 0,
45
46 // Version 1 was the first version of QUIC that supported versioning.
47 // Version 2 decoupled versioning of non-cryptographic parameters from the
48 // SCFG.
49 // Version 3 moved public flags into the beginning of the packet.
50 // Version 4 added support for variable-length connection IDs.
51 // Version 5 made specifying FEC groups optional.
52 // Version 6 introduced variable-length packet numbers.
53 // Version 7 introduced a lower-overhead encoding for stream frames.
54 // Version 8 made salt length equal to digest length for the RSA-PSS
55 // signatures.
56 // Version 9 added stream priority.
57 // Version 10 redid the frame type numbering.
58 // Version 11 reduced the length of null encryption authentication tag
59 // from 16 to 12 bytes.
60 // Version 12 made the sequence numbers in the ACK frames variable-sized.
61 // Version 13 added the dedicated header stream.
62 // Version 14 added byte_offset to RST_STREAM frame.
63 // Version 15 added a list of packets recovered using FEC to the ACK frame.
64 // Version 16 added STOP_WAITING frame.
65 // Version 17 added per-stream flow control.
66 // Version 18 added PING frame.
67 // Version 19 added connection-level flow control
68 // Version 20 allowed to set stream- and connection-level flow control windows
69 // to different values.
70 // Version 21 made header and crypto streams flow-controlled.
71 // Version 22 added support for SCUP (server config update) messages.
72 // Version 23 added timestamps into the ACK frame.
73 // Version 24 added SPDY/4 header compression.
74 // Version 25 added support for SPDY/4 header keys and removed error_details
75 // from RST_STREAM frame.
76 // Version 26 added XLCT (expected leaf certificate) tag into CHLO.
77 // Version 27 added a nonce into SHLO.
78 // Version 28 allowed receiver to refuse creating a requested stream.
79 // Version 29 added support for QUIC_STREAM_NO_ERROR.
80 // Version 30 added server-side support for certificate transparency.
81 // Version 31 incorporated the hash of CHLO into the crypto proof supplied by
82 // the server.
83 // Version 32 removed FEC-related fields from wire format.
84 // Version 33 added diversification nonces.
85 // Version 34 removed entropy bits from packets and ACK frames, removed
86 // private flag from packet header and changed the ACK format to
87 // specify ranges of packets acknowledged rather than missing
88 // ranges.
89 // Version 35 allows endpoints to independently set stream limit.
90 // Version 36 added support for forced head-of-line blocking experiments.
91 // Version 37 added perspective into null encryption.
92 // Version 38 switched to IETF padding frame format and support for NSTP (no
93 // stop waiting frame) connection option.
94
fayang8265a2a2019-10-16 11:23:51 -070095 // Version 39 writes integers and floating numbers in big endian, stops acking
96 // acks, sends a connection level WINDOW_UPDATE every 20 sent packets which do
97 // not contain retransmittable frames.
QUICHE teama6ef0a62019-03-07 20:34:33 -050098
99 // Version 40 was an attempt to convert QUIC to IETF frame format; it was
100 // never shipped due to a bug.
101 // Version 41 was a bugfix for version 40. The working group changed the wire
102 // format before it shipped, which caused it to be never shipped
103 // and all the changes from it to be reverted. No changes from v40
104 // or v41 are present in subsequent versions.
105 // Version 42 allowed receiving overlapping stream data.
106
107 QUIC_VERSION_43 = 43, // PRIORITY frames are sent by client and accepted by
108 // server.
fayang36825da2019-08-21 14:01:27 -0700109 // Version 44 used IETF header format from draft-ietf-quic-invariants-05.
QUICHE teama6ef0a62019-03-07 20:34:33 -0500110
111 // Version 45 added MESSAGE frame.
112
113 QUIC_VERSION_46 = 46, // Use IETF draft-17 header format with demultiplexing
114 // bit.
dschinazi8b1c45a2019-10-17 08:48:13 -0700115 // Version 47 added variable-length QUIC server connection IDs.
dschinaziceed8662020-07-14 09:37:05 -0700116 // Version 48 added CRYPTO frames for the handshake.
117 // Version 49 added client connection IDs, long header lengths, and the IETF
118 // header format from draft-ietf-quic-invariants-06
nharperc32d8ab2019-10-09 11:09:06 -0700119 QUIC_VERSION_50 = 50, // Header protection and initial obfuscators.
dschinazi47692202020-07-30 11:09:42 -0700120 QUIC_VERSION_51 = 51, // draft-29 features but with GoogleQUIC frames.
dschinazifddd4ee2020-08-10 14:24:28 -0700121 // Number 70 used to represent draft-ietf-quic-transport-25.
dschinazic3316f32020-03-05 14:34:36 -0800122 QUIC_VERSION_IETF_DRAFT_27 = 71, // draft-ietf-quic-transport-27.
dschinazi6ab45242020-06-23 00:20:37 -0700123 // Number 72 used to represent draft-ietf-quic-transport-28.
dschinazib3fed9e2020-06-11 11:59:33 -0700124 QUIC_VERSION_IETF_DRAFT_29 = 73, // draft-ietf-quic-transport-29.
dschinazic3316f32020-03-05 14:34:36 -0800125 // Version 99 was a dumping ground for IETF QUIC changes which were not yet
126 // yet ready for production between 2018-02 and 2020-02.
127
dschinazi1ac22cc2019-06-25 11:47:50 -0700128 // QUIC_VERSION_RESERVED_FOR_NEGOTIATION is sent over the wire as ?a?a?a?a
dschinazi5a354c92019-05-09 12:18:53 -0700129 // which is part of a range reserved by the IETF for version negotiation
dschinazi1ac22cc2019-06-25 11:47:50 -0700130 // testing (see the "Versions" section of draft-ietf-quic-transport).
131 // This version is intentionally meant to never be supported to trigger
132 // version negotiation when proposed by clients and to prevent client
133 // ossification when sent by servers.
dschinazi5a354c92019-05-09 12:18:53 -0700134 QUIC_VERSION_RESERVED_FOR_NEGOTIATION = 999,
QUICHE teama6ef0a62019-03-07 20:34:33 -0500135};
136
dschinazia0b4d2e2020-03-16 16:22:08 -0700137// This array contains QUIC transport versions which we currently support.
dschinazia98acdf2020-05-21 15:34:16 -0700138// DEPRECATED. Use SupportedVersions() instead.
dschinazifddd4ee2020-08-10 14:24:28 -0700139constexpr std::array<QuicTransportVersion, 6> SupportedTransportVersions() {
dschinazib3fed9e2020-06-11 11:59:33 -0700140 return {QUIC_VERSION_IETF_DRAFT_29,
dschinazi2c78aac2020-05-21 17:21:58 -0700141 QUIC_VERSION_IETF_DRAFT_27,
dschinazi47692202020-07-30 11:09:42 -0700142 QUIC_VERSION_51,
dschinazia0b4d2e2020-03-16 16:22:08 -0700143 QUIC_VERSION_50,
dschinazia0b4d2e2020-03-16 16:22:08 -0700144 QUIC_VERSION_46,
145 QUIC_VERSION_43};
146}
147
dschinazidc770fc2020-01-13 15:42:41 -0800148// Helper function which translates from a QuicTransportVersion to a string.
149// Returns strings corresponding to enum names (e.g. QUIC_VERSION_6).
150QUIC_EXPORT_PRIVATE std::string QuicVersionToString(
151 QuicTransportVersion transport_version);
152
QUICHE teama6ef0a62019-03-07 20:34:33 -0500153// The crypto handshake protocols that can be used with QUIC.
154enum HandshakeProtocol {
155 PROTOCOL_UNSUPPORTED,
156 PROTOCOL_QUIC_CRYPTO,
157 PROTOCOL_TLS1_3,
158};
159
dschinazidc770fc2020-01-13 15:42:41 -0800160// Helper function which translates from a HandshakeProtocol to a string.
161QUIC_EXPORT_PRIVATE std::string HandshakeProtocolToString(
162 HandshakeProtocol handshake_protocol);
163
dschinazi0da43902020-01-17 15:26:14 -0800164// Returns whether |transport_version| uses CRYPTO frames for the handshake
165// instead of stream 1.
166QUIC_EXPORT_PRIVATE constexpr bool QuicVersionUsesCryptoFrames(
167 QuicTransportVersion transport_version) {
dschinaziceed8662020-07-14 09:37:05 -0700168 // CRYPTO frames were added in version 48.
169 return transport_version > QUIC_VERSION_46;
dschinazi0da43902020-01-17 15:26:14 -0800170}
171
dschinazidc770fc2020-01-13 15:42:41 -0800172// Returns whether this combination of handshake protocol and transport
173// version is allowed. For example, {PROTOCOL_TLS1_3, QUIC_VERSION_43} is NOT
174// allowed as TLS requires crypto frames which v43 does not support. Note that
175// UnsupportedQuicVersion is a valid version.
dschinazi0da43902020-01-17 15:26:14 -0800176QUIC_EXPORT_PRIVATE constexpr bool ParsedQuicVersionIsValid(
dschinazidc770fc2020-01-13 15:42:41 -0800177 HandshakeProtocol handshake_protocol,
dschinazi0da43902020-01-17 15:26:14 -0800178 QuicTransportVersion transport_version) {
dschinazia0b4d2e2020-03-16 16:22:08 -0700179 bool transport_version_is_valid =
180 transport_version == QUIC_VERSION_UNSUPPORTED ||
181 transport_version == QUIC_VERSION_RESERVED_FOR_NEGOTIATION;
182 if (!transport_version_is_valid) {
dschinazi5efb9652020-03-17 10:16:45 -0700183 // Iterators are not constexpr in C++14 which Chrome uses.
184 constexpr auto supported_transport_versions = SupportedTransportVersions();
185 for (size_t i = 0; i < supported_transport_versions.size(); ++i) {
186 const QuicTransportVersion& trans_vers = supported_transport_versions[i];
dschinazia0b4d2e2020-03-16 16:22:08 -0700187 if (trans_vers == transport_version) {
188 transport_version_is_valid = true;
189 break;
190 }
191 }
192 }
193 if (!transport_version_is_valid) {
194 return false;
195 }
dschinazi0da43902020-01-17 15:26:14 -0800196 switch (handshake_protocol) {
197 case PROTOCOL_UNSUPPORTED:
198 return transport_version == QUIC_VERSION_UNSUPPORTED;
199 case PROTOCOL_QUIC_CRYPTO:
dschinazi41616842020-01-21 15:46:11 -0800200 return transport_version != QUIC_VERSION_UNSUPPORTED &&
dschinazi47692202020-07-30 11:09:42 -0700201 transport_version != QUIC_VERSION_51 &&
dschinazi2c78aac2020-05-21 17:21:58 -0700202 transport_version != QUIC_VERSION_IETF_DRAFT_27 &&
dschinazib3fed9e2020-06-11 11:59:33 -0700203 transport_version != QUIC_VERSION_IETF_DRAFT_29;
dschinazi0da43902020-01-17 15:26:14 -0800204 case PROTOCOL_TLS1_3:
dschinazia0b4d2e2020-03-16 16:22:08 -0700205 return transport_version != QUIC_VERSION_UNSUPPORTED &&
dschinaziceed8662020-07-14 09:37:05 -0700206 QuicVersionUsesCryptoFrames(transport_version);
dschinazi0da43902020-01-17 15:26:14 -0800207 }
208 return false;
209}
dschinazidc770fc2020-01-13 15:42:41 -0800210
QUICHE teama6ef0a62019-03-07 20:34:33 -0500211// A parsed QUIC version label which determines that handshake protocol
212// and the transport version.
213struct QUIC_EXPORT_PRIVATE ParsedQuicVersion {
214 HandshakeProtocol handshake_protocol;
215 QuicTransportVersion transport_version;
216
dschinazi3f6ccf42019-10-25 16:58:37 -0700217 constexpr ParsedQuicVersion(HandshakeProtocol handshake_protocol,
218 QuicTransportVersion transport_version)
219 : handshake_protocol(handshake_protocol),
dschinazi0da43902020-01-17 15:26:14 -0800220 transport_version(transport_version) {
221 DCHECK(ParsedQuicVersionIsValid(handshake_protocol, transport_version))
222 << QuicVersionToString(transport_version) << " "
223 << HandshakeProtocolToString(handshake_protocol);
224 }
QUICHE teama6ef0a62019-03-07 20:34:33 -0500225
dschinazi3f6ccf42019-10-25 16:58:37 -0700226 constexpr ParsedQuicVersion(const ParsedQuicVersion& other)
dschinazi97da52b2020-01-13 15:44:43 -0800227 : ParsedQuicVersion(other.handshake_protocol, other.transport_version) {}
QUICHE teama6ef0a62019-03-07 20:34:33 -0500228
229 ParsedQuicVersion& operator=(const ParsedQuicVersion& other) {
dschinazi0da43902020-01-17 15:26:14 -0800230 DCHECK(ParsedQuicVersionIsValid(other.handshake_protocol,
231 other.transport_version))
232 << QuicVersionToString(other.transport_version) << " "
233 << HandshakeProtocolToString(other.handshake_protocol);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500234 if (this != &other) {
235 handshake_protocol = other.handshake_protocol;
236 transport_version = other.transport_version;
237 }
238 return *this;
239 }
240
241 bool operator==(const ParsedQuicVersion& other) const {
242 return handshake_protocol == other.handshake_protocol &&
243 transport_version == other.transport_version;
244 }
245
246 bool operator!=(const ParsedQuicVersion& other) const {
247 return handshake_protocol != other.handshake_protocol ||
248 transport_version != other.transport_version;
249 }
zhongyi546cc452019-04-12 15:27:49 -0700250
dschinazib3fed9e2020-06-11 11:59:33 -0700251 static constexpr ParsedQuicVersion Draft29() {
252 return ParsedQuicVersion(PROTOCOL_TLS1_3, QUIC_VERSION_IETF_DRAFT_29);
253 }
254
dschinazi2be3a022020-05-29 13:52:19 -0700255 static constexpr ParsedQuicVersion Draft27() {
256 return ParsedQuicVersion(PROTOCOL_TLS1_3, QUIC_VERSION_IETF_DRAFT_27);
257 }
258
dschinazi47692202020-07-30 11:09:42 -0700259 static constexpr ParsedQuicVersion T051() {
260 return ParsedQuicVersion(PROTOCOL_TLS1_3, QUIC_VERSION_51);
261 }
262
dschinazi2be3a022020-05-29 13:52:19 -0700263 static constexpr ParsedQuicVersion T050() {
264 return ParsedQuicVersion(PROTOCOL_TLS1_3, QUIC_VERSION_50);
265 }
266
267 static constexpr ParsedQuicVersion Q050() {
268 return ParsedQuicVersion(PROTOCOL_QUIC_CRYPTO, QUIC_VERSION_50);
269 }
270
dschinazi2be3a022020-05-29 13:52:19 -0700271 static constexpr ParsedQuicVersion Q046() {
272 return ParsedQuicVersion(PROTOCOL_QUIC_CRYPTO, QUIC_VERSION_46);
273 }
274
275 static constexpr ParsedQuicVersion Q043() {
276 return ParsedQuicVersion(PROTOCOL_QUIC_CRYPTO, QUIC_VERSION_43);
277 }
278
279 static constexpr ParsedQuicVersion Unsupported() {
280 return ParsedQuicVersion(PROTOCOL_UNSUPPORTED, QUIC_VERSION_UNSUPPORTED);
281 }
282
283 static constexpr ParsedQuicVersion ReservedForNegotiation() {
284 return ParsedQuicVersion(PROTOCOL_QUIC_CRYPTO,
285 QUIC_VERSION_RESERVED_FOR_NEGOTIATION);
286 }
287
dschinazidc770fc2020-01-13 15:42:41 -0800288 // Returns whether our codebase understands this version. This should only be
289 // called on valid versions, see ParsedQuicVersionIsValid. Assuming the
290 // version is valid, IsKnown returns whether the version is not
291 // UnsupportedQuicVersion.
292 bool IsKnown() const;
293
zhongyi546cc452019-04-12 15:27:49 -0700294 bool KnowsWhichDecrypterToUse() const;
dschinazic7036122019-04-30 12:46:34 -0700295
nharperc8d9e402019-09-12 18:30:14 -0700296 // Returns whether this version uses keys derived from the Connection ID for
297 // ENCRYPTION_INITIAL keys (instead of NullEncrypter/NullDecrypter).
298 bool UsesInitialObfuscators() const;
299
dschinazic7036122019-04-30 12:46:34 -0700300 // Indicates that this QUIC version does not have an enforced minimum value
301 // for flow control values negotiated during the handshake.
302 bool AllowsLowFlowControlLimits() const;
nharpercfafed72019-05-01 13:43:55 -0700303
304 // Returns whether header protection is used in this version of QUIC.
305 bool HasHeaderProtection() const;
dschinazi244f6dc2019-05-06 15:45:16 -0700306
307 // Returns whether this version supports IETF RETRY packets.
308 bool SupportsRetry() const;
dschinazib417d602019-05-29 13:08:45 -0700309
dschinazi278efae2020-01-28 17:03:09 -0800310 // Returns whether RETRY packets carry the Retry Integrity Tag field.
311 bool HasRetryIntegrityTag() const;
312
fayang3ac15c12019-06-14 14:04:51 -0700313 // Returns true if this version sends variable length packet number in long
314 // header.
315 bool SendsVariableLengthPacketNumberInLongHeader() const;
316
dschinazi97da52b2020-01-13 15:44:43 -0800317 // Returns whether this version allows server connection ID lengths
318 // that are not 64 bits.
319 bool AllowsVariableLengthConnectionIds() const;
320
dschinazib417d602019-05-29 13:08:45 -0700321 // Returns whether this version supports client connection ID.
322 bool SupportsClientConnectionIds() const;
dschinazi48ac9192019-07-31 00:07:26 -0700323
324 // Returns whether this version supports long header 8-bit encoded
325 // connection ID lengths as described in draft-ietf-quic-invariants-06 and
326 // draft-ietf-quic-transport-22.
327 bool HasLengthPrefixedConnectionIds() const;
fayang5f135052019-08-22 17:59:40 -0700328
329 // Returns whether this version supports IETF style anti-amplification limit,
330 // i.e., server will send no more than FLAGS_quic_anti_amplification_factor
331 // times received bytes until address can be validated.
332 bool SupportsAntiAmplificationLimit() const;
fayang58f71072019-11-05 08:47:02 -0800333
334 // Returns true if this version can send coalesced packets.
335 bool CanSendCoalescedPackets() const;
dschinazi97da52b2020-01-13 15:44:43 -0800336
337 // Returns true if this version supports the old Google-style Alt-Svc
338 // advertisement format.
339 bool SupportsGoogleAltSvcFormat() const;
340
341 // Returns true if |transport_version| uses IETF invariant headers.
342 bool HasIetfInvariantHeader() const;
343
344 // Returns true if |transport_version| supports MESSAGE frames.
345 bool SupportsMessageFrames() const;
346
347 // If true, HTTP/3 instead of gQUIC will be used at the HTTP layer.
348 // Notable changes are:
349 // * Headers stream no longer exists.
350 // * PRIORITY, HEADERS are moved from headers stream to HTTP/3 control stream.
351 // * PUSH_PROMISE is moved to request stream.
352 // * Unidirectional streams will have their first byte as a stream type.
353 // * HEADERS frames are compressed using QPACK.
354 // * DATA frame has frame headers.
355 // * GOAWAY is moved to HTTP layer.
356 bool UsesHttp3() const;
357
358 // Returns whether the transport_version supports the variable length integer
359 // length field as defined by IETF QUIC draft-13 and later.
360 bool HasLongHeaderLengths() const;
361
362 // Returns whether |transport_version| uses CRYPTO frames for the handshake
363 // instead of stream 1.
364 bool UsesCryptoFrames() const;
365
366 // Returns whether |transport_version| makes use of IETF QUIC
367 // frames or not.
368 bool HasIetfQuicFrames() const;
fayang01062942020-01-22 07:23:23 -0800369
370 // Returns true if this parsed version supports handshake done.
371 bool HasHandshakeDone() const;
dschinazi7b8f0c72020-03-02 13:17:57 -0800372
373 // Returns true if this version uses variable-length integers when
374 // encoding transport parameter types and lengths.
375 bool HasVarIntTransportParams() const;
dschinazi67507492020-04-24 12:10:39 -0700376
dschinazi2c78aac2020-05-21 17:21:58 -0700377 // Returns true if this version uses transport parameters to authenticate all
378 // the connection IDs used during the handshake.
379 bool AuthenticatesHandshakeConnectionIds() const;
380
dschinazi67507492020-04-24 12:10:39 -0700381 // Returns whether this version uses PROTOCOL_TLS1_3.
382 bool UsesTls() const;
383
384 // Returns whether this version uses PROTOCOL_QUIC_CRYPTO.
385 bool UsesQuicCrypto() const;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500386};
387
388QUIC_EXPORT_PRIVATE ParsedQuicVersion UnsupportedQuicVersion();
389
dschinazi5a354c92019-05-09 12:18:53 -0700390QUIC_EXPORT_PRIVATE ParsedQuicVersion QuicVersionReservedForNegotiation();
391
dschinazi6458eb32020-06-23 12:38:41 -0700392// Outer version used when encapsulating other packets using the Legacy Version
393// Encapsulation feature.
394QUIC_EXPORT_PRIVATE ParsedQuicVersion LegacyVersionForEncapsulation();
395
QUICHE teama6ef0a62019-03-07 20:34:33 -0500396QUIC_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
397 const ParsedQuicVersion& version);
398
399using ParsedQuicVersionVector = std::vector<ParsedQuicVersion>;
400
dschinazi1ac7f012020-04-06 13:08:56 -0700401QUIC_EXPORT_PRIVATE std::ostream& operator<<(
402 std::ostream& os,
403 const ParsedQuicVersionVector& versions);
404
QUICHE teama6ef0a62019-03-07 20:34:33 -0500405// Representation of the on-the-wire QUIC version number. Will be written/read
406// to the wire in network-byte-order.
407using QuicVersionLabel = uint32_t;
408using QuicVersionLabelVector = std::vector<QuicVersionLabel>;
409
dschinazi1ac7f012020-04-06 13:08:56 -0700410QUIC_EXPORT_PRIVATE std::ostream& operator<<(
411 std::ostream& os,
412 const QuicVersionLabelVector& version_labels);
413
QUICHE teama6ef0a62019-03-07 20:34:33 -0500414// This vector contains all crypto handshake protocols that are supported.
vasilvv228602e2020-02-06 01:11:49 -0800415constexpr std::array<HandshakeProtocol, 2> SupportedHandshakeProtocols() {
dschinazi0a9c20d2020-04-07 14:04:55 -0700416 return {PROTOCOL_TLS1_3, PROTOCOL_QUIC_CRYPTO};
vasilvv228602e2020-02-06 01:11:49 -0800417}
QUICHE teama6ef0a62019-03-07 20:34:33 -0500418
dschinazifddd4ee2020-08-10 14:24:28 -0700419constexpr std::array<ParsedQuicVersion, 7> SupportedVersions() {
dschinazic4c0e392020-03-16 11:22:09 -0700420 return {
dschinazi6ab45242020-06-23 00:20:37 -0700421 ParsedQuicVersion::Draft29(), ParsedQuicVersion::Draft27(),
dschinazifddd4ee2020-08-10 14:24:28 -0700422 ParsedQuicVersion::T051(), ParsedQuicVersion::T050(),
423 ParsedQuicVersion::Q050(), ParsedQuicVersion::Q046(),
424 ParsedQuicVersion::Q043(),
dschinazic4c0e392020-03-16 11:22:09 -0700425 };
vasilvv228602e2020-02-06 01:11:49 -0800426}
nharper2891b2d2020-01-14 16:46:07 -0800427
vasilvv228602e2020-02-06 01:11:49 -0800428using QuicTransportVersionVector = std::vector<QuicTransportVersion>;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500429
dschinazi1ac7f012020-04-06 13:08:56 -0700430QUIC_EXPORT_PRIVATE std::ostream& operator<<(
431 std::ostream& os,
432 const QuicTransportVersionVector& transport_versions);
433
QUICHE teama6ef0a62019-03-07 20:34:33 -0500434// Returns a vector of QUIC versions in kSupportedTransportVersions.
435QUIC_EXPORT_PRIVATE QuicTransportVersionVector AllSupportedTransportVersions();
436
437// Returns a vector of QUIC versions that is the cartesian product of
438// kSupportedTransportVersions and kSupportedHandshakeProtocols.
439QUIC_EXPORT_PRIVATE ParsedQuicVersionVector AllSupportedVersions();
440
QUICHE teama6ef0a62019-03-07 20:34:33 -0500441// Returns a vector of QUIC versions that is the cartesian product of
442// kSupportedTransportVersions and kSupportedHandshakeProtocols, with any
443// versions disabled by flags excluded.
444QUIC_EXPORT_PRIVATE ParsedQuicVersionVector CurrentSupportedVersions();
445
446// Returns a vector of QUIC versions from |versions| which exclude any versions
447// which are disabled by flags.
QUICHE teama6ef0a62019-03-07 20:34:33 -0500448QUIC_EXPORT_PRIVATE ParsedQuicVersionVector
449FilterSupportedVersions(ParsedQuicVersionVector versions);
450
bnc36b7a032020-03-04 10:27:23 -0800451// Returns a subset of AllSupportedVersions() with
452// handshake_protocol == PROTOCOL_QUIC_CRYPTO, in the same order.
453// Deprecated; only to be used in components that do not yet support
454// PROTOCOL_TLS1_3.
dschinazi75448772020-03-05 05:09:55 -0800455QUIC_EXPORT_PRIVATE ParsedQuicVersionVector
456AllSupportedVersionsWithQuicCrypto();
bnc36b7a032020-03-04 10:27:23 -0800457
458// Returns a subset of CurrentSupportedVersions() with
459// handshake_protocol == PROTOCOL_QUIC_CRYPTO, in the same order.
dschinazi75448772020-03-05 05:09:55 -0800460QUIC_EXPORT_PRIVATE ParsedQuicVersionVector
461CurrentSupportedVersionsWithQuicCrypto();
bnc36b7a032020-03-04 10:27:23 -0800462
dschinazi8c628f22020-04-09 16:40:11 -0700463// Returns a subset of AllSupportedVersions() with
464// handshake_protocol == PROTOCOL_TLS1_3, in the same order.
465QUIC_EXPORT_PRIVATE ParsedQuicVersionVector AllSupportedVersionsWithTls();
466
fayang3b3e3012020-03-26 10:31:13 -0700467// Returns a subset of CurrentSupportedVersions() with handshake_protocol ==
468// PROTOCOL_TLS1_3.
469QUIC_EXPORT_PRIVATE ParsedQuicVersionVector CurrentSupportedVersionsWithTls();
470
QUICHE teama6ef0a62019-03-07 20:34:33 -0500471// Returns QUIC version of |index| in result of |versions|. Returns
472// QUIC_VERSION_UNSUPPORTED if |index| is out of bounds.
473QUIC_EXPORT_PRIVATE QuicTransportVersionVector
474VersionOfIndex(const QuicTransportVersionVector& versions, int index);
475
476// Returns QUIC version of |index| in result of |versions|. Returns
477// UnsupportedQuicVersion() if |index| is out of bounds.
478QUIC_EXPORT_PRIVATE ParsedQuicVersionVector
479ParsedVersionOfIndex(const ParsedQuicVersionVector& versions, int index);
480
481// Returns a vector of QuicTransportVersions corresponding to just the transport
482// versions in |versions|. If the input vector contains multiple parsed versions
483// with different handshake protocols (but the same transport version), that
484// transport version will appear in the resulting vector multiple times.
485QUIC_EXPORT_PRIVATE QuicTransportVersionVector
486ParsedVersionsToTransportVersions(const ParsedQuicVersionVector& versions);
487
488// QuicVersionLabel is written to and read from the wire, but we prefer to use
489// the more readable ParsedQuicVersion at other levels.
490// Helper function which translates from a QuicVersionLabel to a
491// ParsedQuicVersion.
492QUIC_EXPORT_PRIVATE ParsedQuicVersion
493ParseQuicVersionLabel(QuicVersionLabel version_label);
494
dschinazicee73cd2020-03-05 18:20:50 -0800495// Parses a QUIC version string such as "Q043" or "T050". Also supports parsing
dschinazifddd4ee2020-08-10 14:24:28 -0700496// ALPN such as "h3-29" or "h3-Q050". For PROTOCOL_QUIC_CRYPTO versions, also
dschinazicee73cd2020-03-05 18:20:50 -0800497// supports parsing numbers such as "46".
dschinazi8ae60012019-04-04 18:07:27 -0700498QUIC_EXPORT_PRIVATE ParsedQuicVersion
dschinazicee73cd2020-03-05 18:20:50 -0800499ParseQuicVersionString(quiche::QuicheStringPiece version_string);
500
501// Parses a comma-separated list of QUIC version strings. Supports parsing by
502// label, ALPN and numbers for PROTOCOL_QUIC_CRYPTO. Skips unknown versions.
dschinazifddd4ee2020-08-10 14:24:28 -0700503// For example: "h3-29,Q050,46".
dschinazicee73cd2020-03-05 18:20:50 -0800504QUIC_EXPORT_PRIVATE ParsedQuicVersionVector
505ParseQuicVersionVectorString(quiche::QuicheStringPiece versions_string);
dschinazi8ae60012019-04-04 18:07:27 -0700506
QUICHE teama6ef0a62019-03-07 20:34:33 -0500507// Constructs a QuicVersionLabel from the provided ParsedQuicVersion.
508QUIC_EXPORT_PRIVATE QuicVersionLabel
509CreateQuicVersionLabel(ParsedQuicVersion parsed_version);
510
511// Constructs a QuicVersionLabelVector from the provided
512// ParsedQuicVersionVector.
513QUIC_EXPORT_PRIVATE QuicVersionLabelVector
514CreateQuicVersionLabelVector(const ParsedQuicVersionVector& versions);
515
516// QuicVersionLabel is written to and read from the wire, but we prefer to use
517// the more readable QuicTransportVersion at other levels.
518// Helper function which translates from a QuicTransportVersion to a
519// QuicVersionLabel. Returns 0 if |version| is unsupported.
520QUIC_EXPORT_PRIVATE QuicVersionLabel
521QuicVersionToQuicVersionLabel(QuicTransportVersion transport_version);
522
523// Helper function which translates from a QuicVersionLabel to a string.
vasilvvc48c8712019-03-11 13:38:16 -0700524QUIC_EXPORT_PRIVATE std::string QuicVersionLabelToString(
525 QuicVersionLabel version_label);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500526
527// Returns |separator|-separated list of string representations of
528// QuicVersionLabel values in the supplied |version_labels| vector. The values
529// after the (0-based) |skip_after_nth_version|'th are skipped.
vasilvvc48c8712019-03-11 13:38:16 -0700530QUIC_EXPORT_PRIVATE std::string QuicVersionLabelVectorToString(
531 const QuicVersionLabelVector& version_labels,
532 const std::string& separator,
533 size_t skip_after_nth_version);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500534
535// Returns comma separated list of string representations of QuicVersionLabel
536// values in the supplied |version_labels| vector.
vasilvvc48c8712019-03-11 13:38:16 -0700537QUIC_EXPORT_PRIVATE inline std::string QuicVersionLabelVectorToString(
QUICHE teama6ef0a62019-03-07 20:34:33 -0500538 const QuicVersionLabelVector& version_labels) {
539 return QuicVersionLabelVectorToString(version_labels, ",",
540 std::numeric_limits<size_t>::max());
541}
542
543// Returns appropriate QuicTransportVersion from a QuicVersionLabel.
544// Returns QUIC_VERSION_UNSUPPORTED if |version_label| cannot be understood.
545QUIC_EXPORT_PRIVATE QuicTransportVersion
546QuicVersionLabelToQuicVersion(QuicVersionLabel version_label);
547
548// Returns the HandshakeProtocol used with the given |version_label|, returning
549// PROTOCOL_UNSUPPORTED if it is unknown.
550QUIC_EXPORT_PRIVATE HandshakeProtocol
551QuicVersionLabelToHandshakeProtocol(QuicVersionLabel version_label);
552
QUICHE teama6ef0a62019-03-07 20:34:33 -0500553// Helper function which translates from a ParsedQuicVersion to a string.
554// Returns strings corresponding to the on-the-wire tag.
vasilvvc48c8712019-03-11 13:38:16 -0700555QUIC_EXPORT_PRIVATE std::string ParsedQuicVersionToString(
556 ParsedQuicVersion version);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500557
558// Returns comma separated list of string representations of
559// QuicTransportVersion enum values in the supplied |versions| vector.
vasilvvc48c8712019-03-11 13:38:16 -0700560QUIC_EXPORT_PRIVATE std::string QuicTransportVersionVectorToString(
561 const QuicTransportVersionVector& versions);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500562
563// Returns comma separated list of string representations of ParsedQuicVersion
564// values in the supplied |versions| vector.
vasilvvc48c8712019-03-11 13:38:16 -0700565QUIC_EXPORT_PRIVATE std::string ParsedQuicVersionVectorToString(
566 const ParsedQuicVersionVector& versions);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500567
568// Returns |separator|-separated list of string representations of
569// ParsedQuicVersion values in the supplied |versions| vector. The values after
570// the (0-based) |skip_after_nth_version|'th are skipped.
vasilvvc48c8712019-03-11 13:38:16 -0700571QUIC_EXPORT_PRIVATE std::string ParsedQuicVersionVectorToString(
572 const ParsedQuicVersionVector& versions,
573 const std::string& separator,
574 size_t skip_after_nth_version);
QUICHE teama6ef0a62019-03-07 20:34:33 -0500575
576// Returns comma separated list of string representations of ParsedQuicVersion
577// values in the supplied |versions| vector.
vasilvvc48c8712019-03-11 13:38:16 -0700578QUIC_EXPORT_PRIVATE inline std::string ParsedQuicVersionVectorToString(
QUICHE teama6ef0a62019-03-07 20:34:33 -0500579 const ParsedQuicVersionVector& versions) {
580 return ParsedQuicVersionVectorToString(versions, ",",
581 std::numeric_limits<size_t>::max());
582}
583
fayangd4291e42019-05-30 10:31:21 -0700584// Returns true if |transport_version| uses IETF invariant headers.
dschinazi0da43902020-01-17 15:26:14 -0800585QUIC_EXPORT_PRIVATE constexpr bool VersionHasIetfInvariantHeader(
fayangd4291e42019-05-30 10:31:21 -0700586 QuicTransportVersion transport_version) {
587 return transport_version > QUIC_VERSION_43;
588}
589
590// Returns true if |transport_version| supports MESSAGE frames.
dschinazi0da43902020-01-17 15:26:14 -0800591QUIC_EXPORT_PRIVATE constexpr bool VersionSupportsMessageFrames(
fayangd4291e42019-05-30 10:31:21 -0700592 QuicTransportVersion transport_version) {
dschinaziceed8662020-07-14 09:37:05 -0700593 // MESSAGE frames were added in version 45.
594 return transport_version > QUIC_VERSION_43;
fayangd4291e42019-05-30 10:31:21 -0700595}
596
renjietanga29a96a2019-10-10 12:47:50 -0700597// If true, HTTP/3 instead of gQUIC will be used at the HTTP layer.
598// Notable changes are:
599// * Headers stream no longer exists.
600// * PRIORITY, HEADERS are moved from headers stream to HTTP/3 control stream.
601// * PUSH_PROMISE is moved to request stream.
602// * Unidirectional streams will have their first byte as a stream type.
603// * HEADERS frames are compressed using QPACK.
604// * DATA frame has frame headers.
605// * GOAWAY is moved to HTTP layer.
dschinazi0da43902020-01-17 15:26:14 -0800606QUIC_EXPORT_PRIVATE constexpr bool VersionUsesHttp3(
QUICHE teama6ef0a62019-03-07 20:34:33 -0500607 QuicTransportVersion transport_version) {
dschinazi47692202020-07-30 11:09:42 -0700608 return transport_version > QUIC_VERSION_51;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500609}
610
QUICHE teama6ef0a62019-03-07 20:34:33 -0500611// Returns whether the transport_version supports the variable length integer
612// length field as defined by IETF QUIC draft-13 and later.
dschinazi0da43902020-01-17 15:26:14 -0800613QUIC_EXPORT_PRIVATE constexpr bool QuicVersionHasLongHeaderLengths(
QUICHE teama6ef0a62019-03-07 20:34:33 -0500614 QuicTransportVersion transport_version) {
dschinaziceed8662020-07-14 09:37:05 -0700615 // Long header lengths were added in version 49.
616 return transport_version > QUIC_VERSION_46;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500617}
618
fkastenholz305e1732019-06-18 05:01:22 -0700619// Returns whether |transport_version| makes use of IETF QUIC
620// frames or not.
dschinazi0da43902020-01-17 15:26:14 -0800621QUIC_EXPORT_PRIVATE constexpr bool VersionHasIetfQuicFrames(
fkastenholz305e1732019-06-18 05:01:22 -0700622 QuicTransportVersion transport_version) {
dschinaziceed8662020-07-14 09:37:05 -0700623 return VersionUsesHttp3(transport_version);
fkastenholz305e1732019-06-18 05:01:22 -0700624}
625
dschinazi48ac9192019-07-31 00:07:26 -0700626// Returns whether this version supports long header 8-bit encoded
627// connection ID lengths as described in draft-ietf-quic-invariants-06 and
628// draft-ietf-quic-transport-22.
629QUIC_EXPORT_PRIVATE bool VersionHasLengthPrefixedConnectionIds(
630 QuicTransportVersion transport_version);
631
rcheb78dbb2019-10-26 08:37:15 -0700632// Returns true if this version supports the old Google-style Alt-Svc
633// advertisement format.
634QUIC_EXPORT_PRIVATE bool VersionSupportsGoogleAltSvcFormat(
635 QuicTransportVersion transport_version);
636
dschinazi97da52b2020-01-13 15:44:43 -0800637// Returns whether this version allows server connection ID lengths that are
638// not 64 bits.
639QUIC_EXPORT_PRIVATE bool VersionAllowsVariableLengthConnectionIds(
640 QuicTransportVersion transport_version);
641
dschinazi48ac9192019-07-31 00:07:26 -0700642// Returns whether this version label supports long header 4-bit encoded
643// connection ID lengths as described in draft-ietf-quic-invariants-05 and
644// draft-ietf-quic-transport-21.
645QUIC_EXPORT_PRIVATE bool QuicVersionLabelUses4BitConnectionIdLength(
646 QuicVersionLabel version_label);
647
dschinazi35e749e2019-04-09 09:36:04 -0700648// Returns the ALPN string to use in TLS for this version of QUIC.
649QUIC_EXPORT_PRIVATE std::string AlpnForVersion(
650 ParsedQuicVersion parsed_version);
651
rcha702be22019-08-30 15:20:12 -0700652// Initializes support for the provided IETF draft version by setting the
653// correct flags.
654QUIC_EXPORT_PRIVATE void QuicVersionInitializeSupportForIetfDraft();
dschinazi8ae60012019-04-04 18:07:27 -0700655
dschinazi5a50d932020-06-17 12:43:36 -0700656// Configures the flags required to enable support for this version of QUIC.
657QUIC_EXPORT_PRIVATE void QuicEnableVersion(const ParsedQuicVersion& version);
658
659// Configures the flags required to disable support for this version of QUIC.
660QUIC_EXPORT_PRIVATE void QuicDisableVersion(const ParsedQuicVersion& version);
661
662// Returns whether support for this version of QUIC is currently enabled.
663QUIC_EXPORT_PRIVATE bool QuicVersionIsEnabled(const ParsedQuicVersion& version);
dschinazi8ae60012019-04-04 18:07:27 -0700664
QUICHE teama6ef0a62019-03-07 20:34:33 -0500665} // namespace quic
666
667#endif // QUICHE_QUIC_CORE_QUIC_VERSIONS_H_