QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2018 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_TRANSPORT_PARAMETERS_H_ |
| 6 | #define QUICHE_QUIC_CORE_CRYPTO_TRANSPORT_PARAMETERS_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "net/third_party/quiche/src/quic/core/crypto/crypto_handshake_message.h" |
| 12 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
| 13 | #include "net/third_party/quiche/src/quic/core/quic_versions.h" |
| 14 | |
| 15 | namespace quic { |
| 16 | |
| 17 | // TransportParameters contains parameters for QUIC's transport layer that are |
| 18 | // indicated during the TLS handshake. This struct is a mirror of the struct in |
| 19 | // section 6.4 of draft-ietf-quic-transport-11. |
| 20 | struct QUIC_EXPORT_PRIVATE TransportParameters { |
| 21 | TransportParameters(); |
| 22 | ~TransportParameters(); |
| 23 | |
| 24 | // When |perspective| is Perspective::IS_CLIENT, this struct is being used in |
| 25 | // the client_hello handshake message; when it is Perspective::IS_SERVER, it |
| 26 | // is being used in the encrypted_extensions handshake message. |
| 27 | Perspective perspective; |
| 28 | |
| 29 | // When Perspective::IS_CLIENT, |version| is the initial version offered by |
| 30 | // the client (before any version negotiation packets) for this connection. |
| 31 | // When Perspective::IS_SERVER, |version| is the version that is in use. |
| 32 | QuicVersionLabel version = 0; |
| 33 | |
| 34 | // Server-only parameters: |
| 35 | |
| 36 | // |supported_versions| contains a list of all versions that the server would |
| 37 | // send in a version negotiation packet. It is not used if |perspective == |
| 38 | // Perspective::IS_CLIENT|. |
| 39 | QuicVersionLabelVector supported_versions; |
| 40 | |
| 41 | // See section 6.4.1 of draft-ietf-quic-transport-11 for definition. |
| 42 | std::vector<uint8_t> stateless_reset_token; |
| 43 | |
| 44 | // Required parameters. See section 6.4.1 of draft-ietf-quic-transport-11 for |
| 45 | // definitions. |
| 46 | uint32_t initial_max_stream_data = 0; |
| 47 | uint32_t initial_max_data = 0; |
| 48 | uint16_t idle_timeout = 0; |
| 49 | |
| 50 | template <typename T> |
| 51 | struct OptionalParam { |
| 52 | bool present = false; |
| 53 | T value; |
| 54 | }; |
| 55 | |
| 56 | // Optional parameters. See section 6.4.1 of draft-ietf-quic-transport-11 for |
| 57 | // definitions. |
| 58 | OptionalParam<uint16_t> initial_max_bidi_streams; |
| 59 | OptionalParam<uint16_t> initial_max_uni_streams; |
| 60 | OptionalParam<uint16_t> max_packet_size; |
| 61 | OptionalParam<uint8_t> ack_delay_exponent; |
| 62 | |
| 63 | // Transport parameters used by Google QUIC but not IETF QUIC. This is |
| 64 | // serialized into a TransportParameter struct with a TransportParameterId of |
| 65 | // 18257. |
| 66 | std::unique_ptr<CryptoHandshakeMessage> google_quic_params; |
| 67 | |
| 68 | // Returns true if the contents of this struct are valid. |
| 69 | bool is_valid() const; |
| 70 | }; |
| 71 | |
| 72 | // Serializes a TransportParameters struct into the format for sending it in a |
| 73 | // TLS extension. The serialized bytes are put in |*out|, and this function |
| 74 | // returns true on success or false if |TransportParameters::is_valid| returns |
| 75 | // false. |
| 76 | QUIC_EXPORT_PRIVATE bool SerializeTransportParameters( |
| 77 | const TransportParameters& in, |
| 78 | std::vector<uint8_t>* out); |
| 79 | |
| 80 | // Parses bytes from the quic_transport_parameters TLS extension and writes the |
| 81 | // parsed parameters into |*out|. Input is read from |in| for |in_len| bytes. |
| 82 | // |perspective| indicates whether the input came from a client or a server. |
| 83 | // This method returns true if the input was successfully parsed, and false if |
| 84 | // it could not be parsed. |
| 85 | // TODO(nharper): Write fuzz tests for this method. |
| 86 | QUIC_EXPORT_PRIVATE bool ParseTransportParameters(const uint8_t* in, |
| 87 | size_t in_len, |
| 88 | Perspective perspective, |
| 89 | TransportParameters* out); |
| 90 | |
| 91 | } // namespace quic |
| 92 | |
| 93 | #endif // QUICHE_QUIC_CORE_CRYPTO_TRANSPORT_PARAMETERS_H_ |