QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // 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 | #include "net/third_party/quiche/src/quic/core/quic_framer.h" |
| 6 | |
| 7 | #include <algorithm> |
| 8 | #include <cstdint> |
| 9 | #include <map> |
| 10 | #include <memory> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 11 | #include <string> |
bnc | 463f235 | 2019-10-10 04:49:34 -0700 | [diff] [blame] | 12 | #include <utility> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13 | #include <vector> |
| 14 | |
| 15 | #include "net/third_party/quiche/src/quic/core/crypto/null_decrypter.h" |
| 16 | #include "net/third_party/quiche/src/quic/core/crypto/null_encrypter.h" |
| 17 | #include "net/third_party/quiche/src/quic/core/crypto/quic_decrypter.h" |
| 18 | #include "net/third_party/quiche/src/quic/core/crypto/quic_encrypter.h" |
| 19 | #include "net/third_party/quiche/src/quic/core/quic_connection_id.h" |
dschinazi | cf5b1e2 | 2019-07-17 18:35:17 -0700 | [diff] [blame] | 20 | #include "net/third_party/quiche/src/quic/core/quic_error_codes.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 21 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
| 22 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
| 23 | #include "net/third_party/quiche/src/quic/core/quic_utils.h" |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 24 | #include "net/third_party/quiche/src/quic/core/quic_versions.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 25 | #include "net/third_party/quiche/src/quic/platform/api/quic_expect_bug.h" |
| 26 | #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" |
| 27 | #include "net/third_party/quiche/src/quic/platform/api/quic_logging.h" |
| 28 | #include "net/third_party/quiche/src/quic/platform/api/quic_ptr_util.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 29 | #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 30 | #include "net/third_party/quiche/src/quic/test_tools/quic_framer_peer.h" |
| 31 | #include "net/third_party/quiche/src/quic/test_tools/quic_test_utils.h" |
| 32 | #include "net/third_party/quiche/src/quic/test_tools/simple_data_producer.h" |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 33 | #include "net/third_party/quiche/src/common/platform/api/quiche_arraysize.h" |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 34 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" |
| 35 | #include "net/third_party/quiche/src/common/platform/api/quiche_text_utils.h" |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 36 | #include "net/third_party/quiche/src/common/test_tools/quiche_test_utils.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 37 | |
| 38 | using testing::_; |
| 39 | using testing::Return; |
| 40 | using testing::Truly; |
| 41 | |
| 42 | namespace quic { |
| 43 | namespace test { |
| 44 | namespace { |
| 45 | |
| 46 | const uint64_t kEpoch = UINT64_C(1) << 32; |
| 47 | const uint64_t kMask = kEpoch - 1; |
| 48 | |
| 49 | const QuicUint128 kTestStatelessResetToken = 1010101; // 0x0F69B5 |
| 50 | |
| 51 | // Use fields in which each byte is distinct to ensure that every byte is |
| 52 | // framed correctly. The values are otherwise arbitrary. |
| 53 | QuicConnectionId FramerTestConnectionId() { |
| 54 | return TestConnectionId(UINT64_C(0xFEDCBA9876543210)); |
| 55 | } |
| 56 | |
| 57 | QuicConnectionId FramerTestConnectionIdPlusOne() { |
| 58 | return TestConnectionId(UINT64_C(0xFEDCBA9876543211)); |
| 59 | } |
| 60 | |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 61 | QuicConnectionId FramerTestConnectionIdNineBytes() { |
| 62 | char connection_id_bytes[9] = {0xFE, 0xDC, 0xBA, 0x98, 0x76, |
| 63 | 0x54, 0x32, 0x10, 0x42}; |
| 64 | return QuicConnectionId(connection_id_bytes, sizeof(connection_id_bytes)); |
| 65 | } |
| 66 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 67 | const QuicPacketNumber kPacketNumber = QuicPacketNumber(UINT64_C(0x12345678)); |
| 68 | const QuicPacketNumber kSmallLargestObserved = |
| 69 | QuicPacketNumber(UINT16_C(0x1234)); |
| 70 | const QuicPacketNumber kSmallMissingPacket = QuicPacketNumber(UINT16_C(0x1233)); |
| 71 | const QuicPacketNumber kLeastUnacked = QuicPacketNumber(UINT64_C(0x012345670)); |
| 72 | const QuicStreamId kStreamId = UINT64_C(0x01020304); |
| 73 | // Note that the high 4 bits of the stream offset must be less than 0x40 |
| 74 | // in order to ensure that the value can be encoded using VarInt62 encoding. |
| 75 | const QuicStreamOffset kStreamOffset = UINT64_C(0x3A98FEDC32107654); |
| 76 | const QuicPublicResetNonceProof kNonceProof = UINT64_C(0xABCDEF0123456789); |
| 77 | |
| 78 | // In testing that we can ack the full range of packets... |
| 79 | // This is the largest packet number that can be represented in IETF QUIC |
| 80 | // varint62 format. |
| 81 | const QuicPacketNumber kLargestIetfLargestObserved = |
| 82 | QuicPacketNumber(UINT64_C(0x3fffffffffffffff)); |
| 83 | // Encodings for the two bits in a VarInt62 that |
| 84 | // describe the length of the VarInt61. For binary packet |
| 85 | // formats in this file, the convention is to code the |
| 86 | // first byte as |
| 87 | // kVarInt62FourBytes + 0x<value_in_that_byte> |
| 88 | const uint8_t kVarInt62OneByte = 0x00; |
| 89 | const uint8_t kVarInt62TwoBytes = 0x40; |
| 90 | const uint8_t kVarInt62FourBytes = 0x80; |
| 91 | const uint8_t kVarInt62EightBytes = 0xc0; |
| 92 | |
| 93 | class TestEncrypter : public QuicEncrypter { |
| 94 | public: |
| 95 | ~TestEncrypter() override {} |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 96 | bool SetKey(quiche::QuicheStringPiece /*key*/) override { return true; } |
| 97 | bool SetNoncePrefix(quiche::QuicheStringPiece /*nonce_prefix*/) override { |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 98 | return true; |
| 99 | } |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 100 | bool SetIV(quiche::QuicheStringPiece /*iv*/) override { return true; } |
| 101 | bool SetHeaderProtectionKey(quiche::QuicheStringPiece /*key*/) override { |
| 102 | return true; |
| 103 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 104 | bool EncryptPacket(uint64_t packet_number, |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 105 | quiche::QuicheStringPiece associated_data, |
| 106 | quiche::QuicheStringPiece plaintext, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 107 | char* output, |
| 108 | size_t* output_length, |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 109 | size_t /*max_output_length*/) override { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 110 | packet_number_ = QuicPacketNumber(packet_number); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 111 | associated_data_ = std::string(associated_data); |
| 112 | plaintext_ = std::string(plaintext); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 113 | memcpy(output, plaintext.data(), plaintext.length()); |
| 114 | *output_length = plaintext.length(); |
| 115 | return true; |
| 116 | } |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 117 | std::string GenerateHeaderProtectionMask( |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 118 | quiche::QuicheStringPiece /*sample*/) override { |
QUICHE team | 2d18797 | 2019-03-19 16:23:47 -0700 | [diff] [blame] | 119 | return std::string(5, 0); |
| 120 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 121 | size_t GetKeySize() const override { return 0; } |
| 122 | size_t GetNoncePrefixSize() const override { return 0; } |
| 123 | size_t GetIVSize() const override { return 0; } |
| 124 | size_t GetMaxPlaintextSize(size_t ciphertext_size) const override { |
| 125 | return ciphertext_size; |
| 126 | } |
| 127 | size_t GetCiphertextSize(size_t plaintext_size) const override { |
| 128 | return plaintext_size; |
| 129 | } |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 130 | quiche::QuicheStringPiece GetKey() const override { |
| 131 | return quiche::QuicheStringPiece(); |
| 132 | } |
| 133 | quiche::QuicheStringPiece GetNoncePrefix() const override { |
| 134 | return quiche::QuicheStringPiece(); |
| 135 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 136 | |
| 137 | QuicPacketNumber packet_number_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 138 | std::string associated_data_; |
| 139 | std::string plaintext_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 140 | }; |
| 141 | |
| 142 | class TestDecrypter : public QuicDecrypter { |
| 143 | public: |
| 144 | ~TestDecrypter() override {} |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 145 | bool SetKey(quiche::QuicheStringPiece /*key*/) override { return true; } |
| 146 | bool SetNoncePrefix(quiche::QuicheStringPiece /*nonce_prefix*/) override { |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 147 | return true; |
| 148 | } |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 149 | bool SetIV(quiche::QuicheStringPiece /*iv*/) override { return true; } |
| 150 | bool SetHeaderProtectionKey(quiche::QuicheStringPiece /*key*/) override { |
| 151 | return true; |
| 152 | } |
| 153 | bool SetPreliminaryKey(quiche::QuicheStringPiece /*key*/) override { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 154 | QUIC_BUG << "should not be called"; |
| 155 | return false; |
| 156 | } |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 157 | bool SetDiversificationNonce(const DiversificationNonce& /*key*/) override { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 158 | return true; |
| 159 | } |
| 160 | bool DecryptPacket(uint64_t packet_number, |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 161 | quiche::QuicheStringPiece associated_data, |
| 162 | quiche::QuicheStringPiece ciphertext, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 163 | char* output, |
| 164 | size_t* output_length, |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 165 | size_t /*max_output_length*/) override { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 166 | packet_number_ = QuicPacketNumber(packet_number); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 167 | associated_data_ = std::string(associated_data); |
| 168 | ciphertext_ = std::string(ciphertext); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 169 | memcpy(output, ciphertext.data(), ciphertext.length()); |
| 170 | *output_length = ciphertext.length(); |
| 171 | return true; |
| 172 | } |
QUICHE team | 2d18797 | 2019-03-19 16:23:47 -0700 | [diff] [blame] | 173 | std::string GenerateHeaderProtectionMask( |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 174 | QuicDataReader* /*sample_reader*/) override { |
QUICHE team | 2d18797 | 2019-03-19 16:23:47 -0700 | [diff] [blame] | 175 | return std::string(5, 0); |
| 176 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 177 | size_t GetKeySize() const override { return 0; } |
nharper | 965e592 | 2019-09-23 22:33:54 -0700 | [diff] [blame] | 178 | size_t GetNoncePrefixSize() const override { return 0; } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 179 | size_t GetIVSize() const override { return 0; } |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 180 | quiche::QuicheStringPiece GetKey() const override { |
| 181 | return quiche::QuicheStringPiece(); |
| 182 | } |
| 183 | quiche::QuicheStringPiece GetNoncePrefix() const override { |
| 184 | return quiche::QuicheStringPiece(); |
| 185 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 186 | // Use a distinct value starting with 0xFFFFFF, which is never used by TLS. |
| 187 | uint32_t cipher_id() const override { return 0xFFFFFFF2; } |
| 188 | QuicPacketNumber packet_number_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 189 | std::string associated_data_; |
| 190 | std::string ciphertext_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | class TestQuicVisitor : public QuicFramerVisitorInterface { |
| 194 | public: |
| 195 | TestQuicVisitor() |
| 196 | : error_count_(0), |
| 197 | version_mismatch_(0), |
| 198 | packet_count_(0), |
| 199 | frame_count_(0), |
| 200 | complete_packets_(0), |
| 201 | accept_packet_(true), |
| 202 | accept_public_header_(true) {} |
| 203 | |
| 204 | ~TestQuicVisitor() override {} |
| 205 | |
| 206 | void OnError(QuicFramer* f) override { |
| 207 | QUIC_DLOG(INFO) << "QuicFramer Error: " << QuicErrorCodeToString(f->error()) |
| 208 | << " (" << f->error() << ")"; |
| 209 | ++error_count_; |
| 210 | } |
| 211 | |
| 212 | void OnPacket() override {} |
| 213 | |
| 214 | void OnPublicResetPacket(const QuicPublicResetPacket& packet) override { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 215 | public_reset_packet_ = std::make_unique<QuicPublicResetPacket>((packet)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 216 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | void OnVersionNegotiationPacket( |
| 220 | const QuicVersionNegotiationPacket& packet) override { |
| 221 | version_negotiation_packet_ = |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 222 | std::make_unique<QuicVersionNegotiationPacket>((packet)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 223 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 224 | } |
| 225 | |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 226 | void OnRetryPacket(QuicConnectionId original_connection_id, |
| 227 | QuicConnectionId new_connection_id, |
dschinazi | 278efae | 2020-01-28 17:03:09 -0800 | [diff] [blame] | 228 | quiche::QuicheStringPiece retry_token, |
| 229 | quiche::QuicheStringPiece retry_integrity_tag, |
| 230 | quiche::QuicheStringPiece retry_without_tag) override { |
dschinazi | 2dd75ee | 2020-01-29 09:21:37 -0800 | [diff] [blame] | 231 | on_retry_packet_called_ = true; |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 232 | retry_original_connection_id_ = |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 233 | std::make_unique<QuicConnectionId>(original_connection_id); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 234 | retry_new_connection_id_ = |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 235 | std::make_unique<QuicConnectionId>(new_connection_id); |
| 236 | retry_token_ = std::make_unique<std::string>(std::string(retry_token)); |
dschinazi | 278efae | 2020-01-28 17:03:09 -0800 | [diff] [blame] | 237 | retry_token_integrity_tag_ = |
| 238 | std::make_unique<std::string>(std::string(retry_integrity_tag)); |
| 239 | retry_without_tag_ = |
| 240 | std::make_unique<std::string>(std::string(retry_without_tag)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 241 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 242 | } |
| 243 | |
fayang | 8aba1ff | 2019-06-21 12:00:54 -0700 | [diff] [blame] | 244 | bool OnProtocolVersionMismatch(ParsedQuicVersion received_version) override { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 245 | QUIC_DLOG(INFO) << "QuicFramer Version Mismatch, version: " |
| 246 | << received_version; |
| 247 | ++version_mismatch_; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 248 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 249 | return false; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | bool OnUnauthenticatedPublicHeader(const QuicPacketHeader& header) override { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 253 | header_ = std::make_unique<QuicPacketHeader>((header)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 254 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 255 | return accept_public_header_; |
| 256 | } |
| 257 | |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 258 | bool OnUnauthenticatedHeader(const QuicPacketHeader& /*header*/) override { |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 259 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 260 | return true; |
| 261 | } |
| 262 | |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 263 | void OnDecryptedPacket(EncryptionLevel /*level*/) override { |
| 264 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 265 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 266 | |
| 267 | bool OnPacketHeader(const QuicPacketHeader& header) override { |
| 268 | ++packet_count_; |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 269 | header_ = std::make_unique<QuicPacketHeader>((header)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 270 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 271 | return accept_packet_; |
| 272 | } |
| 273 | |
| 274 | void OnCoalescedPacket(const QuicEncryptedPacket& packet) override { |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 275 | coalesced_packets_.push_back(packet.Clone()); |
| 276 | } |
| 277 | |
| 278 | void OnUndecryptablePacket(const QuicEncryptedPacket& packet, |
| 279 | EncryptionLevel decryption_level, |
| 280 | bool has_decryption_key) override { |
| 281 | undecryptable_packets_.push_back(packet.Clone()); |
| 282 | undecryptable_decryption_levels_.push_back(decryption_level); |
| 283 | undecryptable_has_decryption_keys_.push_back(has_decryption_key); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | bool OnStreamFrame(const QuicStreamFrame& frame) override { |
| 287 | ++frame_count_; |
| 288 | // Save a copy of the data so it is valid after the packet is processed. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 289 | std::string* string_data = |
| 290 | new std::string(frame.data_buffer, frame.data_length); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 291 | stream_data_.push_back(QuicWrapUnique(string_data)); |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 292 | stream_frames_.push_back(std::make_unique<QuicStreamFrame>( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 293 | frame.stream_id, frame.fin, frame.offset, *string_data)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 294 | if (VersionHasIetfQuicFrames(transport_version_)) { |
| 295 | // Low order bits of type encode flags, ignore them for this test. |
| 296 | EXPECT_TRUE(IS_IETF_STREAM_FRAME(framer_->current_received_frame_type())); |
| 297 | } else { |
| 298 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 299 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 300 | return true; |
| 301 | } |
| 302 | |
| 303 | bool OnCryptoFrame(const QuicCryptoFrame& frame) override { |
| 304 | ++frame_count_; |
| 305 | // Save a copy of the data so it is valid after the packet is processed. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 306 | std::string* string_data = |
| 307 | new std::string(frame.data_buffer, frame.data_length); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 308 | crypto_data_.push_back(QuicWrapUnique(string_data)); |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 309 | crypto_frames_.push_back(std::make_unique<QuicCryptoFrame>( |
renjietang | 15dfaa8 | 2020-01-03 16:13:38 -0800 | [diff] [blame] | 310 | frame.level, frame.offset, *string_data)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 311 | if (VersionHasIetfQuicFrames(transport_version_)) { |
| 312 | EXPECT_EQ(IETF_CRYPTO, framer_->current_received_frame_type()); |
| 313 | } else { |
| 314 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 315 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 316 | return true; |
| 317 | } |
| 318 | |
| 319 | bool OnAckFrameStart(QuicPacketNumber largest_acked, |
| 320 | QuicTime::Delta ack_delay_time) override { |
| 321 | ++frame_count_; |
| 322 | QuicAckFrame ack_frame; |
| 323 | ack_frame.largest_acked = largest_acked; |
| 324 | ack_frame.ack_delay_time = ack_delay_time; |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 325 | ack_frames_.push_back(std::make_unique<QuicAckFrame>(ack_frame)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 326 | if (VersionHasIetfQuicFrames(transport_version_)) { |
| 327 | EXPECT_EQ(IETF_ACK, framer_->current_received_frame_type()); |
| 328 | } else { |
| 329 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 330 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 331 | return true; |
| 332 | } |
| 333 | |
| 334 | bool OnAckRange(QuicPacketNumber start, QuicPacketNumber end) override { |
| 335 | DCHECK(!ack_frames_.empty()); |
| 336 | ack_frames_[ack_frames_.size() - 1]->packets.AddRange(start, end); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 337 | if (VersionHasIetfQuicFrames(transport_version_)) { |
| 338 | EXPECT_EQ(IETF_ACK, framer_->current_received_frame_type()); |
| 339 | } else { |
| 340 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 341 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 342 | return true; |
| 343 | } |
| 344 | |
| 345 | bool OnAckTimestamp(QuicPacketNumber packet_number, |
| 346 | QuicTime timestamp) override { |
| 347 | ack_frames_[ack_frames_.size() - 1]->received_packet_times.push_back( |
| 348 | std::make_pair(packet_number, timestamp)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 349 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 350 | return true; |
| 351 | } |
| 352 | |
| 353 | bool OnAckFrameEnd(QuicPacketNumber /*start*/) override { return true; } |
| 354 | |
| 355 | bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override { |
| 356 | ++frame_count_; |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 357 | stop_waiting_frames_.push_back( |
| 358 | std::make_unique<QuicStopWaitingFrame>(frame)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 359 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 360 | return true; |
| 361 | } |
| 362 | |
| 363 | bool OnPaddingFrame(const QuicPaddingFrame& frame) override { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 364 | padding_frames_.push_back(std::make_unique<QuicPaddingFrame>(frame)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 365 | if (VersionHasIetfQuicFrames(transport_version_)) { |
| 366 | EXPECT_EQ(IETF_PADDING, framer_->current_received_frame_type()); |
| 367 | } else { |
| 368 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 369 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 370 | return true; |
| 371 | } |
| 372 | |
| 373 | bool OnPingFrame(const QuicPingFrame& frame) override { |
| 374 | ++frame_count_; |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 375 | ping_frames_.push_back(std::make_unique<QuicPingFrame>(frame)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 376 | if (VersionHasIetfQuicFrames(transport_version_)) { |
| 377 | EXPECT_EQ(IETF_PING, framer_->current_received_frame_type()); |
| 378 | } else { |
| 379 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 380 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 381 | return true; |
| 382 | } |
| 383 | |
| 384 | bool OnMessageFrame(const QuicMessageFrame& frame) override { |
| 385 | ++frame_count_; |
| 386 | message_frames_.push_back( |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 387 | std::make_unique<QuicMessageFrame>(frame.data, frame.message_length)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 388 | if (VersionHasIetfQuicFrames(transport_version_)) { |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 389 | EXPECT_TRUE(IETF_EXTENSION_MESSAGE_NO_LENGTH_V99 == |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 390 | framer_->current_received_frame_type() || |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 391 | IETF_EXTENSION_MESSAGE_V99 == |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 392 | framer_->current_received_frame_type()); |
| 393 | } else { |
| 394 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 395 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 396 | return true; |
| 397 | } |
| 398 | |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 399 | bool OnHandshakeDoneFrame(const QuicHandshakeDoneFrame& frame) override { |
| 400 | ++frame_count_; |
| 401 | handshake_done_frames_.push_back( |
| 402 | std::make_unique<QuicHandshakeDoneFrame>(frame)); |
| 403 | DCHECK(VersionHasIetfQuicFrames(transport_version_)); |
| 404 | EXPECT_EQ(IETF_HANDSHAKE_DONE, framer_->current_received_frame_type()); |
| 405 | return true; |
| 406 | } |
| 407 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 408 | void OnPacketComplete() override { ++complete_packets_; } |
| 409 | |
| 410 | bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override { |
| 411 | rst_stream_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 412 | if (VersionHasIetfQuicFrames(transport_version_)) { |
| 413 | EXPECT_EQ(IETF_RST_STREAM, framer_->current_received_frame_type()); |
| 414 | } else { |
| 415 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 416 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 417 | return true; |
| 418 | } |
| 419 | |
| 420 | bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override { |
| 421 | connection_close_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 422 | if (VersionHasIetfQuicFrames(transport_version_)) { |
| 423 | EXPECT_NE(GOOGLE_QUIC_CONNECTION_CLOSE, frame.close_type); |
| 424 | if (frame.close_type == IETF_QUIC_TRANSPORT_CONNECTION_CLOSE) { |
| 425 | EXPECT_EQ(IETF_CONNECTION_CLOSE, |
| 426 | framer_->current_received_frame_type()); |
| 427 | } else { |
| 428 | EXPECT_EQ(IETF_APPLICATION_CLOSE, |
| 429 | framer_->current_received_frame_type()); |
| 430 | } |
| 431 | } else { |
| 432 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 433 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 434 | return true; |
| 435 | } |
| 436 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 437 | bool OnStopSendingFrame(const QuicStopSendingFrame& frame) override { |
| 438 | stop_sending_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 439 | EXPECT_EQ(IETF_STOP_SENDING, framer_->current_received_frame_type()); |
| 440 | EXPECT_TRUE(VersionHasIetfQuicFrames(transport_version_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 441 | return true; |
| 442 | } |
| 443 | |
| 444 | bool OnPathChallengeFrame(const QuicPathChallengeFrame& frame) override { |
| 445 | path_challenge_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 446 | EXPECT_EQ(IETF_PATH_CHALLENGE, framer_->current_received_frame_type()); |
| 447 | EXPECT_TRUE(VersionHasIetfQuicFrames(transport_version_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 448 | return true; |
| 449 | } |
| 450 | |
| 451 | bool OnPathResponseFrame(const QuicPathResponseFrame& frame) override { |
| 452 | path_response_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 453 | EXPECT_EQ(IETF_PATH_RESPONSE, framer_->current_received_frame_type()); |
| 454 | EXPECT_TRUE(VersionHasIetfQuicFrames(transport_version_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 455 | return true; |
| 456 | } |
| 457 | |
| 458 | bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override { |
| 459 | goaway_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 460 | EXPECT_FALSE(VersionHasIetfQuicFrames(transport_version_)); |
| 461 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 462 | return true; |
| 463 | } |
| 464 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 465 | bool OnMaxStreamsFrame(const QuicMaxStreamsFrame& frame) override { |
| 466 | max_streams_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 467 | EXPECT_TRUE(VersionHasIetfQuicFrames(transport_version_)); |
| 468 | EXPECT_TRUE(IETF_MAX_STREAMS_UNIDIRECTIONAL == |
| 469 | framer_->current_received_frame_type() || |
| 470 | IETF_MAX_STREAMS_BIDIRECTIONAL == |
| 471 | framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 472 | return true; |
| 473 | } |
| 474 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 475 | bool OnStreamsBlockedFrame(const QuicStreamsBlockedFrame& frame) override { |
| 476 | streams_blocked_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 477 | EXPECT_TRUE(VersionHasIetfQuicFrames(transport_version_)); |
| 478 | EXPECT_TRUE(IETF_STREAMS_BLOCKED_UNIDIRECTIONAL == |
| 479 | framer_->current_received_frame_type() || |
| 480 | IETF_STREAMS_BLOCKED_BIDIRECTIONAL == |
| 481 | framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 482 | return true; |
| 483 | } |
| 484 | |
| 485 | bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override { |
| 486 | window_update_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 487 | if (VersionHasIetfQuicFrames(transport_version_)) { |
| 488 | EXPECT_TRUE(IETF_MAX_DATA == framer_->current_received_frame_type() || |
| 489 | IETF_MAX_STREAM_DATA == |
| 490 | framer_->current_received_frame_type()); |
| 491 | } else { |
| 492 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 493 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 494 | return true; |
| 495 | } |
| 496 | |
| 497 | bool OnBlockedFrame(const QuicBlockedFrame& frame) override { |
| 498 | blocked_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 499 | if (VersionHasIetfQuicFrames(transport_version_)) { |
ianswett | 2f07744 | 2019-12-12 11:51:24 -0800 | [diff] [blame] | 500 | EXPECT_TRUE(IETF_DATA_BLOCKED == framer_->current_received_frame_type() || |
| 501 | IETF_STREAM_DATA_BLOCKED == |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 502 | framer_->current_received_frame_type()); |
| 503 | } else { |
| 504 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 505 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 506 | return true; |
| 507 | } |
| 508 | |
| 509 | bool OnNewConnectionIdFrame(const QuicNewConnectionIdFrame& frame) override { |
| 510 | new_connection_id_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 511 | EXPECT_EQ(IETF_NEW_CONNECTION_ID, framer_->current_received_frame_type()); |
| 512 | EXPECT_TRUE(VersionHasIetfQuicFrames(transport_version_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 513 | return true; |
| 514 | } |
| 515 | |
| 516 | bool OnRetireConnectionIdFrame( |
| 517 | const QuicRetireConnectionIdFrame& frame) override { |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 518 | EXPECT_EQ(IETF_RETIRE_CONNECTION_ID, |
| 519 | framer_->current_received_frame_type()); |
| 520 | EXPECT_TRUE(VersionHasIetfQuicFrames(transport_version_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 521 | retire_connection_id_ = frame; |
| 522 | return true; |
| 523 | } |
| 524 | |
| 525 | bool OnNewTokenFrame(const QuicNewTokenFrame& frame) override { |
| 526 | new_token_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 527 | EXPECT_EQ(IETF_NEW_TOKEN, framer_->current_received_frame_type()); |
| 528 | EXPECT_TRUE(VersionHasIetfQuicFrames(transport_version_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 529 | return true; |
| 530 | } |
| 531 | |
| 532 | bool IsValidStatelessResetToken(QuicUint128 token) const override { |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 533 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 534 | return token == kTestStatelessResetToken; |
| 535 | } |
| 536 | |
| 537 | void OnAuthenticatedIetfStatelessResetPacket( |
| 538 | const QuicIetfStatelessResetPacket& packet) override { |
| 539 | stateless_reset_packet_ = |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 540 | std::make_unique<QuicIetfStatelessResetPacket>(packet); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 541 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 542 | } |
| 543 | |
| 544 | void set_framer(QuicFramer* framer) { |
| 545 | framer_ = framer; |
| 546 | transport_version_ = framer->transport_version(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | // Counters from the visitor_ callbacks. |
| 550 | int error_count_; |
| 551 | int version_mismatch_; |
| 552 | int packet_count_; |
| 553 | int frame_count_; |
| 554 | int complete_packets_; |
| 555 | bool accept_packet_; |
| 556 | bool accept_public_header_; |
| 557 | |
| 558 | std::unique_ptr<QuicPacketHeader> header_; |
| 559 | std::unique_ptr<QuicPublicResetPacket> public_reset_packet_; |
| 560 | std::unique_ptr<QuicIetfStatelessResetPacket> stateless_reset_packet_; |
| 561 | std::unique_ptr<QuicVersionNegotiationPacket> version_negotiation_packet_; |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 562 | std::unique_ptr<QuicConnectionId> retry_original_connection_id_; |
| 563 | std::unique_ptr<QuicConnectionId> retry_new_connection_id_; |
| 564 | std::unique_ptr<std::string> retry_token_; |
dschinazi | 278efae | 2020-01-28 17:03:09 -0800 | [diff] [blame] | 565 | std::unique_ptr<std::string> retry_token_integrity_tag_; |
| 566 | std::unique_ptr<std::string> retry_without_tag_; |
dschinazi | 2dd75ee | 2020-01-29 09:21:37 -0800 | [diff] [blame] | 567 | bool on_retry_packet_called_ = false; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 568 | std::vector<std::unique_ptr<QuicStreamFrame>> stream_frames_; |
| 569 | std::vector<std::unique_ptr<QuicCryptoFrame>> crypto_frames_; |
| 570 | std::vector<std::unique_ptr<QuicAckFrame>> ack_frames_; |
| 571 | std::vector<std::unique_ptr<QuicStopWaitingFrame>> stop_waiting_frames_; |
| 572 | std::vector<std::unique_ptr<QuicPaddingFrame>> padding_frames_; |
| 573 | std::vector<std::unique_ptr<QuicPingFrame>> ping_frames_; |
| 574 | std::vector<std::unique_ptr<QuicMessageFrame>> message_frames_; |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 575 | std::vector<std::unique_ptr<QuicHandshakeDoneFrame>> handshake_done_frames_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 576 | std::vector<std::unique_ptr<QuicEncryptedPacket>> coalesced_packets_; |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 577 | std::vector<std::unique_ptr<QuicEncryptedPacket>> undecryptable_packets_; |
| 578 | std::vector<EncryptionLevel> undecryptable_decryption_levels_; |
| 579 | std::vector<bool> undecryptable_has_decryption_keys_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 580 | QuicRstStreamFrame rst_stream_frame_; |
| 581 | QuicConnectionCloseFrame connection_close_frame_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 582 | QuicStopSendingFrame stop_sending_frame_; |
| 583 | QuicGoAwayFrame goaway_frame_; |
| 584 | QuicPathChallengeFrame path_challenge_frame_; |
| 585 | QuicPathResponseFrame path_response_frame_; |
| 586 | QuicWindowUpdateFrame window_update_frame_; |
| 587 | QuicBlockedFrame blocked_frame_; |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 588 | QuicStreamsBlockedFrame streams_blocked_frame_; |
| 589 | QuicMaxStreamsFrame max_streams_frame_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 590 | QuicNewConnectionIdFrame new_connection_id_; |
| 591 | QuicRetireConnectionIdFrame retire_connection_id_; |
| 592 | QuicNewTokenFrame new_token_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 593 | std::vector<std::unique_ptr<std::string>> stream_data_; |
| 594 | std::vector<std::unique_ptr<std::string>> crypto_data_; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 595 | QuicTransportVersion transport_version_; |
| 596 | QuicFramer* framer_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 597 | }; |
| 598 | |
| 599 | // Simple struct for defining a packet's content, and associated |
| 600 | // parse error. |
| 601 | struct PacketFragment { |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 602 | std::string error_if_missing; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 603 | std::vector<unsigned char> fragment; |
| 604 | }; |
| 605 | |
| 606 | using PacketFragments = std::vector<struct PacketFragment>; |
| 607 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 608 | class QuicFramerTest : public QuicTestWithParam<ParsedQuicVersion> { |
| 609 | public: |
| 610 | QuicFramerTest() |
| 611 | : encrypter_(new test::TestEncrypter()), |
| 612 | decrypter_(new test::TestDecrypter()), |
| 613 | version_(GetParam()), |
| 614 | start_(QuicTime::Zero() + QuicTime::Delta::FromMicroseconds(0x10)), |
nharper | f5e6845 | 2019-05-29 17:24:18 -0700 | [diff] [blame] | 615 | framer_(AllSupportedVersions(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 616 | start_, |
| 617 | Perspective::IS_SERVER, |
| 618 | kQuicDefaultConnectionIdLength) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 619 | framer_.set_version(version_); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 620 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 621 | framer_.InstallDecrypter(ENCRYPTION_INITIAL, |
| 622 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 623 | } else { |
| 624 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 625 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 626 | } |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 627 | framer_.SetEncrypter(ENCRYPTION_INITIAL, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 628 | std::unique_ptr<QuicEncrypter>(encrypter_)); |
| 629 | |
| 630 | framer_.set_visitor(&visitor_); |
| 631 | framer_.InferPacketHeaderTypeFromVersion(); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 632 | visitor_.set_framer(&framer_); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 633 | } |
| 634 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 635 | void SetDecrypterLevel(EncryptionLevel level) { |
| 636 | if (!framer_.version().KnowsWhichDecrypterToUse()) { |
| 637 | return; |
| 638 | } |
| 639 | decrypter_ = new TestDecrypter(); |
| 640 | framer_.InstallDecrypter(level, std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 641 | } |
| 642 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 643 | // Helper function to get unsigned char representation of the handshake |
rch | a702be2 | 2019-08-30 15:20:12 -0700 | [diff] [blame] | 644 | // protocol byte at position |pos| of the current QUIC version number. |
| 645 | unsigned char GetQuicVersionByte(int pos) { |
| 646 | return (CreateQuicVersionLabel(version_) >> 8 * (3 - pos)) & 0xff; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | bool CheckEncryption(QuicPacketNumber packet_number, QuicPacket* packet) { |
| 650 | if (packet_number != encrypter_->packet_number_) { |
| 651 | QUIC_LOG(ERROR) << "Encrypted incorrect packet number. expected " |
| 652 | << packet_number |
| 653 | << " actual: " << encrypter_->packet_number_; |
| 654 | return false; |
| 655 | } |
| 656 | if (packet->AssociatedData(framer_.transport_version()) != |
| 657 | encrypter_->associated_data_) { |
| 658 | QUIC_LOG(ERROR) << "Encrypted incorrect associated data. expected " |
| 659 | << packet->AssociatedData(framer_.transport_version()) |
| 660 | << " actual: " << encrypter_->associated_data_; |
| 661 | return false; |
| 662 | } |
| 663 | if (packet->Plaintext(framer_.transport_version()) != |
| 664 | encrypter_->plaintext_) { |
| 665 | QUIC_LOG(ERROR) << "Encrypted incorrect plaintext data. expected " |
| 666 | << packet->Plaintext(framer_.transport_version()) |
| 667 | << " actual: " << encrypter_->plaintext_; |
| 668 | return false; |
| 669 | } |
| 670 | return true; |
| 671 | } |
| 672 | |
| 673 | bool CheckDecryption(const QuicEncryptedPacket& encrypted, |
| 674 | bool includes_version, |
| 675 | bool includes_diversification_nonce, |
| 676 | QuicConnectionIdLength destination_connection_id_length, |
| 677 | QuicConnectionIdLength source_connection_id_length) { |
| 678 | return CheckDecryption( |
| 679 | encrypted, includes_version, includes_diversification_nonce, |
| 680 | destination_connection_id_length, source_connection_id_length, |
| 681 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
| 682 | } |
| 683 | |
| 684 | bool CheckDecryption( |
| 685 | const QuicEncryptedPacket& encrypted, |
| 686 | bool includes_version, |
| 687 | bool includes_diversification_nonce, |
| 688 | QuicConnectionIdLength destination_connection_id_length, |
| 689 | QuicConnectionIdLength source_connection_id_length, |
| 690 | QuicVariableLengthIntegerLength retry_token_length_length, |
| 691 | size_t retry_token_length, |
| 692 | QuicVariableLengthIntegerLength length_length) { |
| 693 | if (visitor_.header_->packet_number != decrypter_->packet_number_) { |
| 694 | QUIC_LOG(ERROR) << "Decrypted incorrect packet number. expected " |
| 695 | << visitor_.header_->packet_number |
| 696 | << " actual: " << decrypter_->packet_number_; |
| 697 | return false; |
| 698 | } |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 699 | quiche::QuicheStringPiece associated_data = |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 700 | QuicFramer::GetAssociatedDataFromEncryptedPacket( |
| 701 | framer_.transport_version(), encrypted, |
| 702 | destination_connection_id_length, source_connection_id_length, |
| 703 | includes_version, includes_diversification_nonce, |
| 704 | PACKET_4BYTE_PACKET_NUMBER, retry_token_length_length, |
| 705 | retry_token_length, length_length); |
| 706 | if (associated_data != decrypter_->associated_data_) { |
| 707 | QUIC_LOG(ERROR) << "Decrypted incorrect associated data. expected " |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 708 | << quiche::QuicheTextUtils::HexEncode(associated_data) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 709 | << " actual: " |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 710 | << quiche::QuicheTextUtils::HexEncode( |
| 711 | decrypter_->associated_data_); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 712 | return false; |
| 713 | } |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 714 | quiche::QuicheStringPiece ciphertext( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 715 | encrypted.AsStringPiece().substr(GetStartOfEncryptedData( |
| 716 | framer_.transport_version(), destination_connection_id_length, |
| 717 | source_connection_id_length, includes_version, |
| 718 | includes_diversification_nonce, PACKET_4BYTE_PACKET_NUMBER, |
| 719 | retry_token_length_length, retry_token_length, length_length))); |
| 720 | if (ciphertext != decrypter_->ciphertext_) { |
| 721 | QUIC_LOG(ERROR) << "Decrypted incorrect ciphertext data. expected " |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 722 | << quiche::QuicheTextUtils::HexEncode(ciphertext) |
| 723 | << " actual: " |
| 724 | << quiche::QuicheTextUtils::HexEncode( |
| 725 | decrypter_->ciphertext_) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 726 | << " associated data: " |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 727 | << quiche::QuicheTextUtils::HexEncode(associated_data); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 728 | return false; |
| 729 | } |
| 730 | return true; |
| 731 | } |
| 732 | |
| 733 | char* AsChars(unsigned char* data) { return reinterpret_cast<char*>(data); } |
| 734 | |
| 735 | // Creates a new QuicEncryptedPacket by concatenating the various |
| 736 | // packet fragments in |fragments|. |
| 737 | std::unique_ptr<QuicEncryptedPacket> AssemblePacketFromFragments( |
| 738 | const PacketFragments& fragments) { |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 739 | char* buffer = new char[kMaxOutgoingPacketSize + 1]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 740 | size_t len = 0; |
| 741 | for (const auto& fragment : fragments) { |
| 742 | memcpy(buffer + len, fragment.fragment.data(), fragment.fragment.size()); |
| 743 | len += fragment.fragment.size(); |
| 744 | } |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 745 | return std::make_unique<QuicEncryptedPacket>(buffer, len, true); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | void CheckFramingBoundaries(const PacketFragments& fragments, |
| 749 | QuicErrorCode error_code) { |
| 750 | std::unique_ptr<QuicEncryptedPacket> packet( |
| 751 | AssemblePacketFromFragments(fragments)); |
| 752 | // Check all the various prefixes of |packet| for the expected |
| 753 | // parse error and error code. |
| 754 | for (size_t i = 0; i < packet->length(); ++i) { |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 755 | std::string expected_error; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 756 | size_t len = 0; |
| 757 | for (const auto& fragment : fragments) { |
| 758 | len += fragment.fragment.size(); |
| 759 | if (i < len) { |
| 760 | expected_error = fragment.error_if_missing; |
| 761 | break; |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | if (expected_error.empty()) |
| 766 | continue; |
| 767 | |
| 768 | CheckProcessingFails(*packet, i, expected_error, error_code); |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | void CheckProcessingFails(const QuicEncryptedPacket& packet, |
| 773 | size_t len, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 774 | std::string expected_error, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 775 | QuicErrorCode error_code) { |
| 776 | QuicEncryptedPacket encrypted(packet.data(), len, false); |
| 777 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)) << "len: " << len; |
| 778 | EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len; |
| 779 | EXPECT_EQ(error_code, framer_.error()) << "len: " << len; |
| 780 | } |
| 781 | |
| 782 | void CheckProcessingFails(unsigned char* packet, |
| 783 | size_t len, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 784 | std::string expected_error, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 785 | QuicErrorCode error_code) { |
| 786 | QuicEncryptedPacket encrypted(AsChars(packet), len, false); |
| 787 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)) << "len: " << len; |
| 788 | EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len; |
| 789 | EXPECT_EQ(error_code, framer_.error()) << "len: " << len; |
| 790 | } |
| 791 | |
| 792 | // Checks if the supplied string matches data in the supplied StreamFrame. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 793 | void CheckStreamFrameData(std::string str, QuicStreamFrame* frame) { |
| 794 | EXPECT_EQ(str, std::string(frame->data_buffer, frame->data_length)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | void CheckCalculatePacketNumber(uint64_t expected_packet_number, |
| 798 | QuicPacketNumber last_packet_number) { |
| 799 | uint64_t wire_packet_number = expected_packet_number & kMask; |
| 800 | EXPECT_EQ(expected_packet_number, |
| 801 | QuicFramerPeer::CalculatePacketNumberFromWire( |
| 802 | &framer_, PACKET_4BYTE_PACKET_NUMBER, last_packet_number, |
| 803 | wire_packet_number)) |
| 804 | << "last_packet_number: " << last_packet_number |
| 805 | << " wire_packet_number: " << wire_packet_number; |
| 806 | } |
| 807 | |
| 808 | std::unique_ptr<QuicPacket> BuildDataPacket(const QuicPacketHeader& header, |
| 809 | const QuicFrames& frames) { |
| 810 | return BuildUnsizedDataPacket(&framer_, header, frames); |
| 811 | } |
| 812 | |
| 813 | std::unique_ptr<QuicPacket> BuildDataPacket(const QuicPacketHeader& header, |
| 814 | const QuicFrames& frames, |
| 815 | size_t packet_size) { |
| 816 | return BuildUnsizedDataPacket(&framer_, header, frames, packet_size); |
| 817 | } |
| 818 | |
| 819 | // N starts at 1. |
| 820 | QuicStreamId GetNthStreamid(QuicTransportVersion transport_version, |
| 821 | Perspective perspective, |
| 822 | bool bidirectional, |
| 823 | int n) { |
| 824 | if (bidirectional) { |
| 825 | return QuicUtils::GetFirstBidirectionalStreamId(transport_version, |
| 826 | perspective) + |
| 827 | ((n - 1) * QuicUtils::StreamIdDelta(transport_version)); |
| 828 | } |
| 829 | // Unidirectional |
| 830 | return QuicUtils::GetFirstUnidirectionalStreamId(transport_version, |
| 831 | perspective) + |
| 832 | ((n - 1) * QuicUtils::StreamIdDelta(transport_version)); |
| 833 | } |
| 834 | |
| 835 | test::TestEncrypter* encrypter_; |
| 836 | test::TestDecrypter* decrypter_; |
| 837 | ParsedQuicVersion version_; |
| 838 | QuicTime start_; |
| 839 | QuicFramer framer_; |
| 840 | test::TestQuicVisitor visitor_; |
| 841 | SimpleBufferAllocator allocator_; |
| 842 | }; |
| 843 | |
| 844 | // Multiple test cases of QuicFramerTest use byte arrays to define packets for |
| 845 | // testing, and these byte arrays contain the QUIC version. This macro explodes |
| 846 | // the 32-bit version into four bytes in network order. Since it uses methods of |
| 847 | // QuicFramerTest, it is only valid to use this in a QuicFramerTest. |
rch | a702be2 | 2019-08-30 15:20:12 -0700 | [diff] [blame] | 848 | #define QUIC_VERSION_BYTES \ |
| 849 | GetQuicVersionByte(0), GetQuicVersionByte(1), GetQuicVersionByte(2), \ |
| 850 | GetQuicVersionByte(3) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 851 | |
| 852 | // Run all framer tests with all supported versions of QUIC. |
nharper | f5e6845 | 2019-05-29 17:24:18 -0700 | [diff] [blame] | 853 | INSTANTIATE_TEST_SUITE_P(QuicFramerTests, |
| 854 | QuicFramerTest, |
dschinazi | 98fc8d0 | 2019-09-17 23:34:49 -0700 | [diff] [blame] | 855 | ::testing::ValuesIn(AllSupportedVersions()), |
| 856 | ::testing::PrintToStringParamName()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 857 | |
| 858 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochStart) { |
| 859 | // A few quick manual sanity checks. |
| 860 | CheckCalculatePacketNumber(UINT64_C(1), QuicPacketNumber()); |
| 861 | CheckCalculatePacketNumber(kEpoch + 1, QuicPacketNumber(kMask)); |
| 862 | CheckCalculatePacketNumber(kEpoch, QuicPacketNumber(kMask)); |
| 863 | for (uint64_t j = 0; j < 10; j++) { |
| 864 | CheckCalculatePacketNumber(j, QuicPacketNumber()); |
| 865 | CheckCalculatePacketNumber(kEpoch - 1 - j, QuicPacketNumber()); |
| 866 | } |
| 867 | |
| 868 | // Cases where the last number was close to the start of the range. |
| 869 | for (QuicPacketNumber last = QuicPacketNumber(1); last < QuicPacketNumber(10); |
| 870 | last++) { |
| 871 | // Small numbers should not wrap (even if they're out of order). |
| 872 | for (uint64_t j = 0; j < 10; j++) { |
| 873 | CheckCalculatePacketNumber(j, last); |
| 874 | } |
| 875 | |
| 876 | // Large numbers should not wrap either (because we're near 0 already). |
| 877 | for (uint64_t j = 0; j < 10; j++) { |
| 878 | CheckCalculatePacketNumber(kEpoch - 1 - j, last); |
| 879 | } |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochEnd) { |
| 884 | // Cases where the last number was close to the end of the range |
| 885 | for (uint64_t i = 0; i < 10; i++) { |
| 886 | QuicPacketNumber last = QuicPacketNumber(kEpoch - i); |
| 887 | |
| 888 | // Small numbers should wrap. |
| 889 | for (uint64_t j = 0; j < 10; j++) { |
| 890 | CheckCalculatePacketNumber(kEpoch + j, last); |
| 891 | } |
| 892 | |
| 893 | // Large numbers should not (even if they're out of order). |
| 894 | for (uint64_t j = 0; j < 10; j++) { |
| 895 | CheckCalculatePacketNumber(kEpoch - 1 - j, last); |
| 896 | } |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | // Next check where we're in a non-zero epoch to verify we handle |
| 901 | // reverse wrapping, too. |
| 902 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearPrevEpoch) { |
| 903 | const uint64_t prev_epoch = 1 * kEpoch; |
| 904 | const uint64_t cur_epoch = 2 * kEpoch; |
| 905 | // Cases where the last number was close to the start of the range |
| 906 | for (uint64_t i = 0; i < 10; i++) { |
| 907 | QuicPacketNumber last = QuicPacketNumber(cur_epoch + i); |
| 908 | // Small number should not wrap (even if they're out of order). |
| 909 | for (uint64_t j = 0; j < 10; j++) { |
| 910 | CheckCalculatePacketNumber(cur_epoch + j, last); |
| 911 | } |
| 912 | |
| 913 | // But large numbers should reverse wrap. |
| 914 | for (uint64_t j = 0; j < 10; j++) { |
| 915 | uint64_t num = kEpoch - 1 - j; |
| 916 | CheckCalculatePacketNumber(prev_epoch + num, last); |
| 917 | } |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearNextEpoch) { |
| 922 | const uint64_t cur_epoch = 2 * kEpoch; |
| 923 | const uint64_t next_epoch = 3 * kEpoch; |
| 924 | // Cases where the last number was close to the end of the range |
| 925 | for (uint64_t i = 0; i < 10; i++) { |
| 926 | QuicPacketNumber last = QuicPacketNumber(next_epoch - 1 - i); |
| 927 | |
| 928 | // Small numbers should wrap. |
| 929 | for (uint64_t j = 0; j < 10; j++) { |
| 930 | CheckCalculatePacketNumber(next_epoch + j, last); |
| 931 | } |
| 932 | |
| 933 | // but large numbers should not (even if they're out of order). |
| 934 | for (uint64_t j = 0; j < 10; j++) { |
| 935 | uint64_t num = kEpoch - 1 - j; |
| 936 | CheckCalculatePacketNumber(cur_epoch + num, last); |
| 937 | } |
| 938 | } |
| 939 | } |
| 940 | |
| 941 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearNextMax) { |
| 942 | const uint64_t max_number = std::numeric_limits<uint64_t>::max(); |
| 943 | const uint64_t max_epoch = max_number & ~kMask; |
| 944 | |
| 945 | // Cases where the last number was close to the end of the range |
| 946 | for (uint64_t i = 0; i < 10; i++) { |
| 947 | // Subtract 1, because the expected next packet number is 1 more than the |
| 948 | // last packet number. |
| 949 | QuicPacketNumber last = QuicPacketNumber(max_number - i - 1); |
| 950 | |
| 951 | // Small numbers should not wrap, because they have nowhere to go. |
| 952 | for (uint64_t j = 0; j < 10; j++) { |
| 953 | CheckCalculatePacketNumber(max_epoch + j, last); |
| 954 | } |
| 955 | |
| 956 | // Large numbers should not wrap either. |
| 957 | for (uint64_t j = 0; j < 10; j++) { |
| 958 | uint64_t num = kEpoch - 1 - j; |
| 959 | CheckCalculatePacketNumber(max_epoch + num, last); |
| 960 | } |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | TEST_P(QuicFramerTest, EmptyPacket) { |
| 965 | char packet[] = {0x00}; |
| 966 | QuicEncryptedPacket encrypted(packet, 0, false); |
| 967 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 968 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | TEST_P(QuicFramerTest, LargePacket) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 972 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 973 | // clang-format off |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 974 | unsigned char packet[kMaxIncomingPacketSize + 1] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 975 | // public flags (8 byte connection_id) |
| 976 | 0x28, |
| 977 | // connection_id |
| 978 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 979 | // packet number |
| 980 | 0x78, 0x56, 0x34, 0x12, |
| 981 | // private flags |
| 982 | 0x00, |
| 983 | }; |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 984 | unsigned char packet46[kMaxIncomingPacketSize + 1] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 985 | // type (short header 4 byte packet number) |
| 986 | 0x43, |
| 987 | // connection_id |
| 988 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 989 | // packet number |
| 990 | 0x78, 0x56, 0x34, 0x12, |
| 991 | }; |
| 992 | // clang-format on |
| 993 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 994 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 995 | if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 996 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 997 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | const size_t header_size = GetPacketHeaderSize( |
| 1001 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 1002 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 1003 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 1004 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
| 1005 | |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 1006 | memset(p + header_size, 0, kMaxIncomingPacketSize - header_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1007 | |
| 1008 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 1009 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1010 | |
| 1011 | ASSERT_TRUE(visitor_.header_.get()); |
| 1012 | // Make sure we've parsed the packet header, so we can send an error. |
| 1013 | EXPECT_EQ(FramerTestConnectionId(), |
| 1014 | visitor_.header_->destination_connection_id); |
| 1015 | // Make sure the correct error is propagated. |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1016 | EXPECT_THAT(framer_.error(), IsError(QUIC_PACKET_TOO_LARGE)); |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 1017 | EXPECT_EQ("Packet too large.", framer_.detailed_error()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | TEST_P(QuicFramerTest, PacketHeader) { |
| 1021 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 1022 | return; |
| 1023 | } |
| 1024 | |
| 1025 | // clang-format off |
| 1026 | PacketFragments packet = { |
| 1027 | // public flags (8 byte connection_id) |
| 1028 | {"Unable to read public flags.", |
| 1029 | {0x28}}, |
| 1030 | // connection_id |
| 1031 | {"Unable to read ConnectionId.", |
| 1032 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1033 | // packet number |
| 1034 | {"Unable to read packet number.", |
| 1035 | {0x12, 0x34, 0x56, 0x78}}, |
| 1036 | }; |
| 1037 | // clang-format on |
| 1038 | |
| 1039 | PacketFragments& fragments = packet; |
| 1040 | |
| 1041 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1042 | AssemblePacketFromFragments(fragments)); |
| 1043 | |
| 1044 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1045 | EXPECT_THAT(framer_.error(), IsError(QUIC_MISSING_PAYLOAD)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1046 | ASSERT_TRUE(visitor_.header_.get()); |
| 1047 | EXPECT_EQ(FramerTestConnectionId(), |
| 1048 | visitor_.header_->destination_connection_id); |
| 1049 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1050 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1051 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1052 | |
| 1053 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1054 | |
| 1055 | PacketHeaderFormat format; |
fayang | e3f2f7b | 2019-09-19 17:01:57 -0700 | [diff] [blame] | 1056 | QuicLongHeaderType long_packet_type = INVALID_PACKET_TYPE; |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1057 | bool version_flag; |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1058 | QuicConnectionId destination_connection_id, source_connection_id; |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1059 | QuicVersionLabel version_label; |
| 1060 | std::string detailed_error; |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1061 | bool retry_token_present, use_length_prefix; |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 1062 | quiche::QuicheStringPiece retry_token; |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1063 | ParsedQuicVersion parsed_version = UnsupportedQuicVersion(); |
| 1064 | const QuicErrorCode error_code = QuicFramer::ParsePublicHeaderDispatcher( |
| 1065 | *encrypted, kQuicDefaultConnectionIdLength, &format, &long_packet_type, |
| 1066 | &version_flag, &use_length_prefix, &version_label, &parsed_version, |
| 1067 | &destination_connection_id, &source_connection_id, &retry_token_present, |
| 1068 | &retry_token, &detailed_error); |
| 1069 | EXPECT_FALSE(retry_token_present); |
| 1070 | EXPECT_FALSE(use_length_prefix); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1071 | EXPECT_THAT(error_code, IsQuicNoError()); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1072 | EXPECT_EQ(GOOGLE_QUIC_PACKET, format); |
| 1073 | EXPECT_FALSE(version_flag); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1074 | EXPECT_EQ(kQuicDefaultConnectionIdLength, destination_connection_id.length()); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1075 | EXPECT_EQ(FramerTestConnectionId(), destination_connection_id); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1076 | EXPECT_EQ(EmptyQuicConnectionId(), source_connection_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | TEST_P(QuicFramerTest, LongPacketHeader) { |
| 1080 | // clang-format off |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1081 | PacketFragments packet46 = { |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1082 | // type (long header with packet type ZERO_RTT) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1083 | {"Unable to read first byte.", |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1084 | {0xD3}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1085 | // version tag |
| 1086 | {"Unable to read protocol version.", |
| 1087 | {QUIC_VERSION_BYTES}}, |
| 1088 | // connection_id length |
| 1089 | {"Unable to read ConnectionId length.", |
| 1090 | {0x50}}, |
| 1091 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1092 | {"Unable to read destination connection ID.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1093 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1094 | // packet number |
| 1095 | {"Unable to read packet number.", |
| 1096 | {0x12, 0x34, 0x56, 0x78}}, |
| 1097 | }; |
| 1098 | // clang-format on |
| 1099 | |
| 1100 | if (framer_.transport_version() <= QUIC_VERSION_43 || |
| 1101 | QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 1102 | return; |
| 1103 | } |
| 1104 | |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1105 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1106 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 1107 | AssemblePacketFromFragments(packet46)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1108 | |
| 1109 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1110 | EXPECT_THAT(framer_.error(), IsError(QUIC_MISSING_PAYLOAD)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1111 | ASSERT_TRUE(visitor_.header_.get()); |
| 1112 | EXPECT_EQ(FramerTestConnectionId(), |
| 1113 | visitor_.header_->destination_connection_id); |
| 1114 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1115 | EXPECT_TRUE(visitor_.header_->version_flag); |
| 1116 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1117 | |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 1118 | CheckFramingBoundaries(packet46, QUIC_INVALID_PACKET_HEADER); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1119 | |
| 1120 | PacketHeaderFormat format; |
fayang | e3f2f7b | 2019-09-19 17:01:57 -0700 | [diff] [blame] | 1121 | QuicLongHeaderType long_packet_type = INVALID_PACKET_TYPE; |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1122 | bool version_flag; |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1123 | QuicConnectionId destination_connection_id, source_connection_id; |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1124 | QuicVersionLabel version_label; |
| 1125 | std::string detailed_error; |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1126 | bool retry_token_present, use_length_prefix; |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 1127 | quiche::QuicheStringPiece retry_token; |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1128 | ParsedQuicVersion parsed_version = UnsupportedQuicVersion(); |
| 1129 | const QuicErrorCode error_code = QuicFramer::ParsePublicHeaderDispatcher( |
| 1130 | *encrypted, kQuicDefaultConnectionIdLength, &format, &long_packet_type, |
| 1131 | &version_flag, &use_length_prefix, &version_label, &parsed_version, |
| 1132 | &destination_connection_id, &source_connection_id, &retry_token_present, |
| 1133 | &retry_token, &detailed_error); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1134 | EXPECT_THAT(error_code, IsQuicNoError()); |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1135 | EXPECT_EQ("", detailed_error); |
| 1136 | EXPECT_FALSE(retry_token_present); |
| 1137 | EXPECT_FALSE(use_length_prefix); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1138 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 1139 | EXPECT_TRUE(version_flag); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1140 | EXPECT_EQ(kQuicDefaultConnectionIdLength, destination_connection_id.length()); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1141 | EXPECT_EQ(FramerTestConnectionId(), destination_connection_id); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1142 | EXPECT_EQ(EmptyQuicConnectionId(), source_connection_id); |
| 1143 | } |
| 1144 | |
| 1145 | TEST_P(QuicFramerTest, LongPacketHeaderWithBothConnectionIds) { |
| 1146 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 1147 | // This test requires an IETF long header. |
| 1148 | return; |
| 1149 | } |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1150 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1151 | // clang-format off |
| 1152 | unsigned char packet[] = { |
| 1153 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 1154 | // 4-byte packet number) |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 1155 | 0xD3, |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1156 | // version |
| 1157 | QUIC_VERSION_BYTES, |
| 1158 | // connection ID lengths |
| 1159 | 0x55, |
| 1160 | // destination connection ID |
| 1161 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1162 | // source connection ID |
| 1163 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1164 | // packet number |
| 1165 | 0x12, 0x34, 0x56, 0x00, |
| 1166 | // padding frame |
| 1167 | 0x00, |
| 1168 | }; |
| 1169 | unsigned char packet49[] = { |
| 1170 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 1171 | // 4-byte packet number) |
| 1172 | 0xD3, |
| 1173 | // version |
| 1174 | QUIC_VERSION_BYTES, |
| 1175 | // destination connection ID length |
| 1176 | 0x08, |
| 1177 | // destination connection ID |
| 1178 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1179 | // source connection ID length |
| 1180 | 0x08, |
| 1181 | // source connection ID |
| 1182 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1183 | // long header packet length |
| 1184 | 0x05, |
| 1185 | // packet number |
| 1186 | 0x12, 0x34, 0x56, 0x00, |
| 1187 | // padding frame |
| 1188 | 0x00, |
| 1189 | }; |
| 1190 | // clang-format on |
| 1191 | |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1192 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1193 | size_t p_length = QUICHE_ARRAYSIZE(packet); |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1194 | if (framer_.transport_version() >= QUIC_VERSION_49) { |
| 1195 | p = packet49; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1196 | p_length = QUICHE_ARRAYSIZE(packet49); |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1200 | PacketHeaderFormat format = GOOGLE_QUIC_PACKET; |
fayang | e3f2f7b | 2019-09-19 17:01:57 -0700 | [diff] [blame] | 1201 | QuicLongHeaderType long_packet_type = INVALID_PACKET_TYPE; |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1202 | bool version_flag = false; |
| 1203 | QuicConnectionId destination_connection_id, source_connection_id; |
| 1204 | QuicVersionLabel version_label = 0; |
| 1205 | std::string detailed_error = ""; |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1206 | bool retry_token_present, use_length_prefix; |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 1207 | quiche::QuicheStringPiece retry_token; |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1208 | ParsedQuicVersion parsed_version = UnsupportedQuicVersion(); |
| 1209 | const QuicErrorCode error_code = QuicFramer::ParsePublicHeaderDispatcher( |
| 1210 | encrypted, kQuicDefaultConnectionIdLength, &format, &long_packet_type, |
| 1211 | &version_flag, &use_length_prefix, &version_label, &parsed_version, |
| 1212 | &destination_connection_id, &source_connection_id, &retry_token_present, |
| 1213 | &retry_token, &detailed_error); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1214 | EXPECT_THAT(error_code, IsQuicNoError()); |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1215 | EXPECT_FALSE(retry_token_present); |
| 1216 | EXPECT_EQ(framer_.version().HasLengthPrefixedConnectionIds(), |
| 1217 | use_length_prefix); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1218 | EXPECT_EQ("", detailed_error); |
| 1219 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 1220 | EXPECT_TRUE(version_flag); |
| 1221 | EXPECT_EQ(FramerTestConnectionId(), destination_connection_id); |
| 1222 | EXPECT_EQ(FramerTestConnectionIdPlusOne(), source_connection_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1223 | } |
| 1224 | |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 1225 | TEST_P(QuicFramerTest, ParsePublicHeader) { |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 1226 | // clang-format off |
| 1227 | unsigned char packet[] = { |
| 1228 | // public flags (version included, 8-byte connection ID, |
| 1229 | // 4-byte packet number) |
| 1230 | 0x29, |
| 1231 | // connection_id |
| 1232 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1233 | // version |
| 1234 | QUIC_VERSION_BYTES, |
| 1235 | // packet number |
| 1236 | 0x12, 0x34, 0x56, 0x78, |
| 1237 | // padding frame |
| 1238 | 0x00, |
| 1239 | }; |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 1240 | unsigned char packet46[] = { |
| 1241 | // public flags (long header with packet type HANDSHAKE and |
| 1242 | // 4-byte packet number) |
| 1243 | 0xE3, |
| 1244 | // version |
| 1245 | QUIC_VERSION_BYTES, |
| 1246 | // connection ID lengths |
| 1247 | 0x50, |
| 1248 | // destination connection ID |
| 1249 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1250 | // long header packet length |
| 1251 | 0x05, |
| 1252 | // packet number |
| 1253 | 0x12, 0x34, 0x56, 0x78, |
| 1254 | // padding frame |
| 1255 | 0x00, |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 1256 | }; |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 1257 | unsigned char packet49[] = { |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 1258 | // public flags (long header with packet type HANDSHAKE and |
| 1259 | // 4-byte packet number) |
| 1260 | 0xE3, |
| 1261 | // version |
| 1262 | QUIC_VERSION_BYTES, |
| 1263 | // destination connection ID length |
| 1264 | 0x08, |
| 1265 | // destination connection ID |
| 1266 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1267 | // source connection ID length |
| 1268 | 0x00, |
| 1269 | // long header packet length |
| 1270 | 0x05, |
| 1271 | // packet number |
| 1272 | 0x12, 0x34, 0x56, 0x78, |
| 1273 | // padding frame |
| 1274 | 0x00, |
| 1275 | }; |
| 1276 | // clang-format on |
| 1277 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1278 | size_t p_length = QUICHE_ARRAYSIZE(packet); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 1279 | if (framer_.transport_version() >= QUIC_VERSION_49) { |
| 1280 | p = packet49; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1281 | p_length = QUICHE_ARRAYSIZE(packet49); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 1282 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
| 1283 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1284 | p_length = QUICHE_ARRAYSIZE(packet46); |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | uint8_t first_byte = 0x33; |
| 1288 | PacketHeaderFormat format = GOOGLE_QUIC_PACKET; |
| 1289 | bool version_present = false, has_length_prefix = false; |
| 1290 | QuicVersionLabel version_label = 0; |
| 1291 | ParsedQuicVersion parsed_version = UnsupportedQuicVersion(); |
| 1292 | QuicConnectionId destination_connection_id = EmptyQuicConnectionId(), |
| 1293 | source_connection_id = EmptyQuicConnectionId(); |
| 1294 | QuicLongHeaderType long_packet_type = INVALID_PACKET_TYPE; |
| 1295 | QuicVariableLengthIntegerLength retry_token_length_length = |
| 1296 | VARIABLE_LENGTH_INTEGER_LENGTH_4; |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 1297 | quiche::QuicheStringPiece retry_token; |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 1298 | std::string detailed_error = "foobar"; |
| 1299 | |
| 1300 | QuicDataReader reader(AsChars(p), p_length); |
| 1301 | const QuicErrorCode parse_error = QuicFramer::ParsePublicHeader( |
| 1302 | &reader, kQuicDefaultConnectionIdLength, |
| 1303 | /*ietf_format=*/ |
| 1304 | VersionHasIetfInvariantHeader(framer_.transport_version()), &first_byte, |
| 1305 | &format, &version_present, &has_length_prefix, &version_label, |
| 1306 | &parsed_version, &destination_connection_id, &source_connection_id, |
| 1307 | &long_packet_type, &retry_token_length_length, &retry_token, |
| 1308 | &detailed_error); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1309 | EXPECT_THAT(parse_error, IsQuicNoError()); |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 1310 | EXPECT_EQ("", detailed_error); |
| 1311 | EXPECT_EQ(p[0], first_byte); |
| 1312 | EXPECT_TRUE(version_present); |
| 1313 | EXPECT_EQ(framer_.version().HasLengthPrefixedConnectionIds(), |
| 1314 | has_length_prefix); |
| 1315 | EXPECT_EQ(CreateQuicVersionLabel(framer_.version()), version_label); |
| 1316 | EXPECT_EQ(framer_.version(), parsed_version); |
| 1317 | EXPECT_EQ(FramerTestConnectionId(), destination_connection_id); |
| 1318 | EXPECT_EQ(EmptyQuicConnectionId(), source_connection_id); |
| 1319 | EXPECT_EQ(VARIABLE_LENGTH_INTEGER_LENGTH_0, retry_token_length_length); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 1320 | EXPECT_EQ(quiche::QuicheStringPiece(), retry_token); |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 1321 | if (VersionHasIetfInvariantHeader(framer_.transport_version())) { |
| 1322 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 1323 | EXPECT_EQ(HANDSHAKE, long_packet_type); |
| 1324 | } else { |
| 1325 | EXPECT_EQ(GOOGLE_QUIC_PACKET, format); |
| 1326 | } |
| 1327 | } |
| 1328 | |
dschinazi | 81eb4e0 | 2019-09-27 17:12:17 -0700 | [diff] [blame] | 1329 | TEST_P(QuicFramerTest, ParsePublicHeaderProxBadSourceConnectionIdLength) { |
| 1330 | if (!framer_.version().HasLengthPrefixedConnectionIds()) { |
| 1331 | return; |
| 1332 | } |
dschinazi | 81eb4e0 | 2019-09-27 17:12:17 -0700 | [diff] [blame] | 1333 | // clang-format off |
| 1334 | unsigned char packet[] = { |
| 1335 | // public flags (long header with packet type HANDSHAKE and |
| 1336 | // 4-byte packet number) |
| 1337 | 0xE3, |
| 1338 | // version |
| 1339 | 'P', 'R', 'O', 'X', |
| 1340 | // destination connection ID length |
| 1341 | 0x08, |
| 1342 | // destination connection ID |
| 1343 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1344 | // source connection ID length (bogus) |
| 1345 | 0xEE, |
| 1346 | // long header packet length |
| 1347 | 0x05, |
| 1348 | // packet number |
| 1349 | 0x12, 0x34, 0x56, 0x78, |
| 1350 | // padding frame |
| 1351 | 0x00, |
| 1352 | }; |
| 1353 | // clang-format on |
| 1354 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1355 | size_t p_length = QUICHE_ARRAYSIZE(packet); |
dschinazi | 81eb4e0 | 2019-09-27 17:12:17 -0700 | [diff] [blame] | 1356 | |
| 1357 | uint8_t first_byte = 0x33; |
| 1358 | PacketHeaderFormat format = GOOGLE_QUIC_PACKET; |
| 1359 | bool version_present = false, has_length_prefix = false; |
| 1360 | QuicVersionLabel version_label = 0; |
| 1361 | ParsedQuicVersion parsed_version = UnsupportedQuicVersion(); |
| 1362 | QuicConnectionId destination_connection_id = EmptyQuicConnectionId(), |
| 1363 | source_connection_id = EmptyQuicConnectionId(); |
| 1364 | QuicLongHeaderType long_packet_type = INVALID_PACKET_TYPE; |
| 1365 | QuicVariableLengthIntegerLength retry_token_length_length = |
| 1366 | VARIABLE_LENGTH_INTEGER_LENGTH_4; |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 1367 | quiche::QuicheStringPiece retry_token; |
dschinazi | 81eb4e0 | 2019-09-27 17:12:17 -0700 | [diff] [blame] | 1368 | std::string detailed_error = "foobar"; |
| 1369 | |
| 1370 | QuicDataReader reader(AsChars(p), p_length); |
| 1371 | const QuicErrorCode parse_error = QuicFramer::ParsePublicHeader( |
| 1372 | &reader, kQuicDefaultConnectionIdLength, |
| 1373 | /*ietf_format=*/true, &first_byte, &format, &version_present, |
| 1374 | &has_length_prefix, &version_label, &parsed_version, |
| 1375 | &destination_connection_id, &source_connection_id, &long_packet_type, |
| 1376 | &retry_token_length_length, &retry_token, &detailed_error); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1377 | EXPECT_THAT(parse_error, IsQuicNoError()); |
dschinazi | 81eb4e0 | 2019-09-27 17:12:17 -0700 | [diff] [blame] | 1378 | EXPECT_EQ("", detailed_error); |
| 1379 | EXPECT_EQ(p[0], first_byte); |
| 1380 | EXPECT_TRUE(version_present); |
| 1381 | EXPECT_TRUE(has_length_prefix); |
| 1382 | EXPECT_EQ(0x50524F58u, version_label); // "PROX" |
| 1383 | EXPECT_EQ(UnsupportedQuicVersion(), parsed_version); |
| 1384 | EXPECT_EQ(FramerTestConnectionId(), destination_connection_id); |
| 1385 | EXPECT_EQ(EmptyQuicConnectionId(), source_connection_id); |
| 1386 | EXPECT_EQ(VARIABLE_LENGTH_INTEGER_LENGTH_0, retry_token_length_length); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 1387 | EXPECT_EQ(quiche::QuicheStringPiece(), retry_token); |
dschinazi | 81eb4e0 | 2019-09-27 17:12:17 -0700 | [diff] [blame] | 1388 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 1389 | } |
| 1390 | |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 1391 | TEST_P(QuicFramerTest, ClientConnectionIdFromShortHeaderToClient) { |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 1392 | if (!framer_.version().SupportsClientConnectionIds()) { |
| 1393 | return; |
| 1394 | } |
| 1395 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 1396 | QuicFramerPeer::SetLastSerializedServerConnectionId(&framer_, |
| 1397 | TestConnectionId(0x33)); |
| 1398 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1399 | framer_.SetExpectedClientConnectionIdLength(kQuicDefaultConnectionIdLength); |
| 1400 | // clang-format off |
| 1401 | unsigned char packet[] = { |
| 1402 | // type (short header, 4 byte packet number) |
| 1403 | 0x43, |
| 1404 | // connection_id |
| 1405 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1406 | // packet number |
| 1407 | 0x13, 0x37, 0x42, 0x33, |
| 1408 | // padding frame |
| 1409 | 0x00, |
| 1410 | }; |
| 1411 | // clang-format on |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1412 | QuicEncryptedPacket encrypted(AsChars(packet), QUICHE_ARRAYSIZE(packet), |
| 1413 | false); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 1414 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1415 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 1416 | EXPECT_EQ("", framer_.detailed_error()); |
| 1417 | ASSERT_TRUE(visitor_.header_.get()); |
| 1418 | EXPECT_EQ(FramerTestConnectionId(), |
| 1419 | visitor_.header_->destination_connection_id); |
| 1420 | EXPECT_EQ(TestConnectionId(0x33), visitor_.header_->source_connection_id); |
| 1421 | } |
| 1422 | |
| 1423 | // In short header packets from client to server, the client connection ID |
| 1424 | // is omitted, but the framer adds it to the header struct using its |
| 1425 | // last serialized client connection ID. This test ensures that this |
| 1426 | // mechanism behaves as expected. |
| 1427 | TEST_P(QuicFramerTest, ClientConnectionIdFromShortHeaderToServer) { |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 1428 | if (!framer_.version().SupportsClientConnectionIds()) { |
| 1429 | return; |
| 1430 | } |
| 1431 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 1432 | QuicFramerPeer::SetLastSerializedClientConnectionId(&framer_, |
| 1433 | TestConnectionId(0x33)); |
| 1434 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1435 | // clang-format off |
| 1436 | unsigned char packet[] = { |
| 1437 | // type (short header, 4 byte packet number) |
| 1438 | 0x43, |
| 1439 | // connection_id |
| 1440 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1441 | // packet number |
| 1442 | 0x13, 0x37, 0x42, 0x33, |
| 1443 | // padding frame |
| 1444 | 0x00, |
| 1445 | }; |
| 1446 | // clang-format on |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1447 | QuicEncryptedPacket encrypted(AsChars(packet), QUICHE_ARRAYSIZE(packet), |
| 1448 | false); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 1449 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1450 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 1451 | EXPECT_EQ("", framer_.detailed_error()); |
| 1452 | ASSERT_TRUE(visitor_.header_.get()); |
| 1453 | EXPECT_EQ(FramerTestConnectionId(), |
| 1454 | visitor_.header_->destination_connection_id); |
| 1455 | EXPECT_EQ(TestConnectionId(0x33), visitor_.header_->source_connection_id); |
| 1456 | } |
| 1457 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1458 | TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1459 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
dschinazi | 7b9278c | 2019-05-20 07:36:21 -0700 | [diff] [blame] | 1460 | QuicFramerPeer::SetLastSerializedServerConnectionId(&framer_, |
| 1461 | FramerTestConnectionId()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1462 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1463 | |
| 1464 | // clang-format off |
| 1465 | PacketFragments packet = { |
| 1466 | // public flags (0 byte connection_id) |
| 1467 | {"Unable to read public flags.", |
| 1468 | {0x20}}, |
| 1469 | // connection_id |
| 1470 | // packet number |
| 1471 | {"Unable to read packet number.", |
| 1472 | {0x12, 0x34, 0x56, 0x78}}, |
| 1473 | }; |
| 1474 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1475 | PacketFragments packet46 = { |
| 1476 | // type (short header, 4 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1477 | {"Unable to read first byte.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1478 | {0x43}}, |
| 1479 | // connection_id |
| 1480 | // packet number |
| 1481 | {"Unable to read packet number.", |
| 1482 | {0x12, 0x34, 0x56, 0x78}}, |
| 1483 | }; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1484 | |
| 1485 | PacketFragments packet_hp = { |
| 1486 | // type (short header, 4 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1487 | {"Unable to read first byte.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1488 | {0x43}}, |
| 1489 | // connection_id |
| 1490 | // packet number |
| 1491 | {"", |
| 1492 | {0x12, 0x34, 0x56, 0x78}}, |
| 1493 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1494 | // clang-format on |
| 1495 | |
| 1496 | PacketFragments& fragments = |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1497 | framer_.version().HasHeaderProtection() |
| 1498 | ? packet_hp |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 1499 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 1500 | : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1501 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1502 | AssemblePacketFromFragments(fragments)); |
| 1503 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1504 | EXPECT_THAT(framer_.error(), IsError(QUIC_MISSING_PAYLOAD)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1505 | ASSERT_TRUE(visitor_.header_.get()); |
dschinazi | 5e1a7b2 | 2019-07-31 12:23:21 -0700 | [diff] [blame] | 1506 | EXPECT_EQ(FramerTestConnectionId(), visitor_.header_->source_connection_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1507 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1508 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1509 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1510 | |
| 1511 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1512 | } |
| 1513 | |
| 1514 | TEST_P(QuicFramerTest, PacketHeaderWithVersionFlag) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1515 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1516 | // clang-format off |
| 1517 | PacketFragments packet = { |
| 1518 | // public flags (0 byte connection_id) |
| 1519 | {"Unable to read public flags.", |
| 1520 | {0x29}}, |
| 1521 | // connection_id |
| 1522 | {"Unable to read ConnectionId.", |
| 1523 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1524 | // version tag |
| 1525 | {"Unable to read protocol version.", |
| 1526 | {QUIC_VERSION_BYTES}}, |
| 1527 | // packet number |
| 1528 | {"Unable to read packet number.", |
| 1529 | {0x12, 0x34, 0x56, 0x78}}, |
| 1530 | }; |
| 1531 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1532 | PacketFragments packet46 = { |
| 1533 | // type (long header with packet type ZERO_RTT_PROTECTED and 4 bytes |
| 1534 | // packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1535 | {"Unable to read first byte.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1536 | {0xD3}}, |
| 1537 | // version tag |
| 1538 | {"Unable to read protocol version.", |
| 1539 | {QUIC_VERSION_BYTES}}, |
| 1540 | // connection_id length |
| 1541 | {"Unable to read ConnectionId length.", |
| 1542 | {0x50}}, |
| 1543 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1544 | {"Unable to read destination connection ID.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1545 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1546 | // packet number |
| 1547 | {"Unable to read packet number.", |
| 1548 | {0x12, 0x34, 0x56, 0x78}}, |
| 1549 | }; |
| 1550 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 1551 | PacketFragments packet49 = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1552 | // type (long header with packet type ZERO_RTT_PROTECTED and 4 bytes |
| 1553 | // packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1554 | {"Unable to read first byte.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1555 | {0xD3}}, |
| 1556 | // version tag |
| 1557 | {"Unable to read protocol version.", |
| 1558 | {QUIC_VERSION_BYTES}}, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1559 | // destination connection ID length |
| 1560 | {"Unable to read destination connection ID.", |
| 1561 | {0x08}}, |
| 1562 | // destination connection ID |
| 1563 | {"Unable to read destination connection ID.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1564 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1565 | // source connection ID length |
| 1566 | {"Unable to read source connection ID.", |
| 1567 | {0x00}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1568 | // long header packet length |
| 1569 | {"Unable to read long header payload length.", |
| 1570 | {0x04}}, |
| 1571 | // packet number |
| 1572 | {"Long header payload length longer than packet.", |
| 1573 | {0x12, 0x34, 0x56, 0x78}}, |
| 1574 | }; |
| 1575 | // clang-format on |
| 1576 | |
| 1577 | PacketFragments& fragments = |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 1578 | framer_.transport_version() >= QUIC_VERSION_49 |
| 1579 | ? packet49 |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 1580 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 1581 | : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1582 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1583 | AssemblePacketFromFragments(fragments)); |
| 1584 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1585 | EXPECT_THAT(framer_.error(), IsError(QUIC_MISSING_PAYLOAD)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1586 | ASSERT_TRUE(visitor_.header_.get()); |
| 1587 | EXPECT_EQ(FramerTestConnectionId(), |
| 1588 | visitor_.header_->destination_connection_id); |
| 1589 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1590 | EXPECT_TRUE(visitor_.header_->version_flag); |
| 1591 | EXPECT_EQ(GetParam(), visitor_.header_->version); |
| 1592 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1593 | |
| 1594 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1595 | } |
| 1596 | |
| 1597 | TEST_P(QuicFramerTest, PacketHeaderWith4BytePacketNumber) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1598 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1599 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1600 | |
| 1601 | // clang-format off |
| 1602 | PacketFragments packet = { |
| 1603 | // public flags (8 byte connection_id and 4 byte packet number) |
| 1604 | {"Unable to read public flags.", |
| 1605 | {0x28}}, |
| 1606 | // connection_id |
| 1607 | {"Unable to read ConnectionId.", |
| 1608 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1609 | // packet number |
| 1610 | {"Unable to read packet number.", |
| 1611 | {0x12, 0x34, 0x56, 0x78}}, |
| 1612 | }; |
| 1613 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1614 | PacketFragments packet46 = { |
| 1615 | // type (short header, 4 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1616 | {"Unable to read first byte.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1617 | {0x43}}, |
| 1618 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1619 | {"Unable to read destination connection ID.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1620 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1621 | // packet number |
| 1622 | {"Unable to read packet number.", |
| 1623 | {0x12, 0x34, 0x56, 0x78}}, |
| 1624 | }; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1625 | |
| 1626 | PacketFragments packet_hp = { |
| 1627 | // type (short header, 4 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1628 | {"Unable to read first byte.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1629 | {0x43}}, |
| 1630 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1631 | {"Unable to read destination connection ID.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1632 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1633 | // packet number |
| 1634 | {"", |
| 1635 | {0x12, 0x34, 0x56, 0x78}}, |
| 1636 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1637 | // clang-format on |
| 1638 | |
| 1639 | PacketFragments& fragments = |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1640 | framer_.version().HasHeaderProtection() |
| 1641 | ? packet_hp |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 1642 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 1643 | : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1644 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1645 | AssemblePacketFromFragments(fragments)); |
| 1646 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1647 | EXPECT_THAT(framer_.error(), IsError(QUIC_MISSING_PAYLOAD)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1648 | ASSERT_TRUE(visitor_.header_.get()); |
| 1649 | EXPECT_EQ(FramerTestConnectionId(), |
| 1650 | visitor_.header_->destination_connection_id); |
| 1651 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1652 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1653 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1654 | |
| 1655 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1656 | } |
| 1657 | |
| 1658 | TEST_P(QuicFramerTest, PacketHeaderWith2BytePacketNumber) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1659 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1660 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1661 | |
| 1662 | // clang-format off |
| 1663 | PacketFragments packet = { |
| 1664 | // public flags (8 byte connection_id and 2 byte packet number) |
| 1665 | {"Unable to read public flags.", |
| 1666 | {0x18}}, |
| 1667 | // connection_id |
| 1668 | {"Unable to read ConnectionId.", |
| 1669 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1670 | // packet number |
| 1671 | {"Unable to read packet number.", |
| 1672 | {0x56, 0x78}}, |
| 1673 | }; |
| 1674 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1675 | PacketFragments packet46 = { |
| 1676 | // type (short header, 2 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1677 | {"Unable to read first byte.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1678 | {0x41}}, |
| 1679 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1680 | {"Unable to read destination connection ID.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1681 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1682 | // packet number |
| 1683 | {"Unable to read packet number.", |
| 1684 | {0x56, 0x78}}, |
| 1685 | }; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1686 | |
| 1687 | PacketFragments packet_hp = { |
| 1688 | // type (short header, 2 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1689 | {"Unable to read first byte.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1690 | {0x41}}, |
| 1691 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1692 | {"Unable to read destination connection ID.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1693 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1694 | // packet number |
| 1695 | {"", |
| 1696 | {0x56, 0x78}}, |
| 1697 | // padding |
| 1698 | {"", {0x00, 0x00}}, |
| 1699 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1700 | // clang-format on |
| 1701 | |
| 1702 | PacketFragments& fragments = |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1703 | framer_.version().HasHeaderProtection() |
| 1704 | ? packet_hp |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 1705 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 1706 | : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1707 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1708 | AssemblePacketFromFragments(fragments)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1709 | if (framer_.version().HasHeaderProtection()) { |
| 1710 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1711 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1712 | } else { |
| 1713 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1714 | EXPECT_THAT(framer_.error(), IsError(QUIC_MISSING_PAYLOAD)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1715 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1716 | ASSERT_TRUE(visitor_.header_.get()); |
| 1717 | EXPECT_EQ(FramerTestConnectionId(), |
| 1718 | visitor_.header_->destination_connection_id); |
| 1719 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1720 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1721 | EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1722 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1723 | |
| 1724 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1725 | } |
| 1726 | |
| 1727 | TEST_P(QuicFramerTest, PacketHeaderWith1BytePacketNumber) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1728 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1729 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1730 | |
| 1731 | // clang-format off |
| 1732 | PacketFragments packet = { |
| 1733 | // public flags (8 byte connection_id and 1 byte packet number) |
| 1734 | {"Unable to read public flags.", |
| 1735 | {0x08}}, |
| 1736 | // connection_id |
| 1737 | {"Unable to read ConnectionId.", |
| 1738 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1739 | // packet number |
| 1740 | {"Unable to read packet number.", |
| 1741 | {0x78}}, |
| 1742 | }; |
| 1743 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1744 | PacketFragments packet46 = { |
| 1745 | // type (8 byte connection_id and 1 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1746 | {"Unable to read first byte.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1747 | {0x40}}, |
| 1748 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1749 | {"Unable to read destination connection ID.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1750 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1751 | // packet number |
| 1752 | {"Unable to read packet number.", |
| 1753 | {0x78}}, |
| 1754 | }; |
| 1755 | |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1756 | PacketFragments packet_hp = { |
| 1757 | // type (8 byte connection_id and 1 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1758 | {"Unable to read first byte.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1759 | {0x40}}, |
| 1760 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1761 | {"Unable to read destination connection ID.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1762 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1763 | // packet number |
| 1764 | {"", |
| 1765 | {0x78}}, |
| 1766 | // padding |
| 1767 | {"", {0x00, 0x00, 0x00}}, |
| 1768 | }; |
| 1769 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1770 | // clang-format on |
| 1771 | |
| 1772 | PacketFragments& fragments = |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1773 | framer_.version().HasHeaderProtection() |
| 1774 | ? packet_hp |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 1775 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 1776 | : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1777 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1778 | AssemblePacketFromFragments(fragments)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1779 | if (framer_.version().HasHeaderProtection()) { |
| 1780 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1781 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1782 | } else { |
| 1783 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1784 | EXPECT_THAT(framer_.error(), IsError(QUIC_MISSING_PAYLOAD)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1785 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1786 | ASSERT_TRUE(visitor_.header_.get()); |
| 1787 | EXPECT_EQ(FramerTestConnectionId(), |
| 1788 | visitor_.header_->destination_connection_id); |
| 1789 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1790 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1791 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1792 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1793 | |
| 1794 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1795 | } |
| 1796 | |
| 1797 | TEST_P(QuicFramerTest, PacketNumberDecreasesThenIncreases) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1798 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1799 | // Test the case when a packet is received from the past and future packet |
| 1800 | // numbers are still calculated relative to the largest received packet. |
| 1801 | QuicPacketHeader header; |
| 1802 | header.destination_connection_id = FramerTestConnectionId(); |
| 1803 | header.reset_flag = false; |
| 1804 | header.version_flag = false; |
| 1805 | header.packet_number = kPacketNumber - 2; |
| 1806 | |
| 1807 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 1808 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1809 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 1810 | ASSERT_TRUE(data != nullptr); |
| 1811 | |
| 1812 | QuicEncryptedPacket encrypted(data->data(), data->length(), false); |
| 1813 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1814 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1815 | ASSERT_TRUE(visitor_.header_.get()); |
| 1816 | EXPECT_EQ(FramerTestConnectionId(), |
| 1817 | visitor_.header_->destination_connection_id); |
| 1818 | EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1819 | EXPECT_EQ(kPacketNumber - 2, visitor_.header_->packet_number); |
| 1820 | |
| 1821 | // Receive a 1 byte packet number. |
| 1822 | header.packet_number = kPacketNumber; |
| 1823 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 1824 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1825 | data = BuildDataPacket(header, frames); |
| 1826 | QuicEncryptedPacket encrypted1(data->data(), data->length(), false); |
| 1827 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1828 | EXPECT_TRUE(framer_.ProcessPacket(encrypted1)); |
| 1829 | ASSERT_TRUE(visitor_.header_.get()); |
| 1830 | EXPECT_EQ(FramerTestConnectionId(), |
| 1831 | visitor_.header_->destination_connection_id); |
| 1832 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1833 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1834 | |
| 1835 | // Process a 2 byte packet number 256 packets ago. |
| 1836 | header.packet_number = kPacketNumber - 256; |
| 1837 | header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER; |
| 1838 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1839 | data = BuildDataPacket(header, frames); |
| 1840 | QuicEncryptedPacket encrypted2(data->data(), data->length(), false); |
| 1841 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1842 | EXPECT_TRUE(framer_.ProcessPacket(encrypted2)); |
| 1843 | ASSERT_TRUE(visitor_.header_.get()); |
| 1844 | EXPECT_EQ(FramerTestConnectionId(), |
| 1845 | visitor_.header_->destination_connection_id); |
| 1846 | EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1847 | EXPECT_EQ(kPacketNumber - 256, visitor_.header_->packet_number); |
| 1848 | |
| 1849 | // Process another 1 byte packet number and ensure it works. |
| 1850 | header.packet_number = kPacketNumber - 1; |
| 1851 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 1852 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1853 | data = BuildDataPacket(header, frames); |
| 1854 | QuicEncryptedPacket encrypted3(data->data(), data->length(), false); |
| 1855 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1856 | EXPECT_TRUE(framer_.ProcessPacket(encrypted3)); |
| 1857 | ASSERT_TRUE(visitor_.header_.get()); |
| 1858 | EXPECT_EQ(FramerTestConnectionId(), |
| 1859 | visitor_.header_->destination_connection_id); |
| 1860 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1861 | EXPECT_EQ(kPacketNumber - 1, visitor_.header_->packet_number); |
| 1862 | } |
| 1863 | |
| 1864 | TEST_P(QuicFramerTest, PacketWithDiversificationNonce) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1865 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1866 | // clang-format off |
| 1867 | unsigned char packet[] = { |
| 1868 | // public flags: includes nonce flag |
| 1869 | 0x2C, |
| 1870 | // connection_id |
| 1871 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1872 | // nonce |
| 1873 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1874 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1875 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1876 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1877 | // packet number |
| 1878 | 0x12, 0x34, 0x56, 0x78, |
| 1879 | |
| 1880 | // frame type (padding) |
| 1881 | 0x00, |
| 1882 | 0x00, 0x00, 0x00, 0x00 |
| 1883 | }; |
| 1884 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1885 | unsigned char packet46[] = { |
| 1886 | // type: Long header with packet type ZERO_RTT_PROTECTED and 1 byte packet |
| 1887 | // number. |
| 1888 | 0xD0, |
| 1889 | // version tag |
| 1890 | QUIC_VERSION_BYTES, |
| 1891 | // connection_id length |
| 1892 | 0x05, |
| 1893 | // connection_id |
| 1894 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1895 | // packet number |
| 1896 | 0x78, |
| 1897 | // nonce |
| 1898 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1899 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1900 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1901 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1902 | |
| 1903 | // frame type (padding) |
| 1904 | 0x00, |
| 1905 | 0x00, 0x00, 0x00, 0x00 |
| 1906 | }; |
| 1907 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 1908 | unsigned char packet49[] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1909 | // type: Long header with packet type ZERO_RTT_PROTECTED and 1 byte packet |
| 1910 | // number. |
| 1911 | 0xD0, |
| 1912 | // version tag |
| 1913 | QUIC_VERSION_BYTES, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1914 | // destination connection ID length |
| 1915 | 0x00, |
| 1916 | // source connection ID length |
| 1917 | 0x08, |
| 1918 | // source connection ID |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1919 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1920 | // long header packet length |
| 1921 | 0x26, |
| 1922 | // packet number |
| 1923 | 0x78, |
| 1924 | // nonce |
| 1925 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1926 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1927 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1928 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1929 | |
| 1930 | // frame type (padding) |
| 1931 | 0x00, |
| 1932 | 0x00, 0x00, 0x00, 0x00 |
| 1933 | }; |
| 1934 | // clang-format on |
| 1935 | |
| 1936 | if (framer_.version().handshake_protocol != PROTOCOL_QUIC_CRYPTO) { |
| 1937 | return; |
| 1938 | } |
| 1939 | |
| 1940 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1941 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 1942 | if (framer_.transport_version() >= QUIC_VERSION_49) { |
| 1943 | p = packet49; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1944 | p_size = QUICHE_ARRAYSIZE(packet49); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 1945 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1946 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 1947 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1948 | } |
| 1949 | |
| 1950 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 1951 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1952 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1953 | ASSERT_TRUE(visitor_.header_->nonce != nullptr); |
| 1954 | for (char i = 0; i < 32; ++i) { |
| 1955 | EXPECT_EQ(i, (*visitor_.header_->nonce)[static_cast<size_t>(i)]); |
| 1956 | } |
| 1957 | EXPECT_EQ(1u, visitor_.padding_frames_.size()); |
| 1958 | EXPECT_EQ(5, visitor_.padding_frames_[0]->num_padding_bytes); |
| 1959 | } |
| 1960 | |
| 1961 | TEST_P(QuicFramerTest, LargePublicFlagWithMismatchedVersions) { |
| 1962 | // clang-format off |
| 1963 | unsigned char packet[] = { |
| 1964 | // public flags (8 byte connection_id, version flag and an unknown flag) |
| 1965 | 0x29, |
| 1966 | // connection_id |
| 1967 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1968 | // version tag |
| 1969 | 'Q', '0', '0', '0', |
| 1970 | // packet number |
| 1971 | 0x12, 0x34, 0x56, 0x78, |
| 1972 | |
| 1973 | // frame type (padding frame) |
| 1974 | 0x00, |
| 1975 | 0x00, 0x00, 0x00, 0x00 |
| 1976 | }; |
| 1977 | |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 1978 | unsigned char packet46[] = { |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1979 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 1980 | 0xD3, |
| 1981 | // version tag |
| 1982 | 'Q', '0', '0', '0', |
| 1983 | // connection_id length |
| 1984 | 0x50, |
| 1985 | // connection_id |
| 1986 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1987 | // packet number |
| 1988 | 0x12, 0x34, 0x56, 0x78, |
| 1989 | |
| 1990 | // frame type (padding frame) |
| 1991 | 0x00, |
| 1992 | 0x00, 0x00, 0x00, 0x00 |
| 1993 | }; |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1994 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 1995 | unsigned char packet49[] = { |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1996 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 1997 | 0xD3, |
| 1998 | // version tag |
| 1999 | 'Q', '0', '0', '0', |
| 2000 | // destination connection ID length |
| 2001 | 0x08, |
| 2002 | // destination connection ID |
| 2003 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2004 | // source connection ID length |
| 2005 | 0x00, |
| 2006 | // packet number |
| 2007 | 0x12, 0x34, 0x56, 0x78, |
| 2008 | |
| 2009 | // frame type (padding frame) |
| 2010 | 0x00, |
| 2011 | 0x00, 0x00, 0x00, 0x00 |
| 2012 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2013 | // clang-format on |
| 2014 | |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 2015 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2016 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 2017 | if (framer_.transport_version() >= QUIC_VERSION_49) { |
| 2018 | p = packet49; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2019 | p_size = QUICHE_ARRAYSIZE(packet49); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 2020 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
| 2021 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2022 | p_size = QUICHE_ARRAYSIZE(packet46); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 2023 | } |
| 2024 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2025 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2026 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2027 | ASSERT_TRUE(visitor_.header_.get()); |
| 2028 | EXPECT_EQ(0, visitor_.frame_count_); |
| 2029 | EXPECT_EQ(1, visitor_.version_mismatch_); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | TEST_P(QuicFramerTest, PaddingFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2033 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2034 | // clang-format off |
| 2035 | unsigned char packet[] = { |
| 2036 | // public flags (8 byte connection_id) |
| 2037 | 0x28, |
| 2038 | // connection_id |
| 2039 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2040 | // packet number |
| 2041 | 0x12, 0x34, 0x56, 0x78, |
| 2042 | |
| 2043 | // paddings |
| 2044 | 0x00, 0x00, |
| 2045 | // frame type (stream frame with fin) |
| 2046 | 0xFF, |
| 2047 | // stream id |
| 2048 | 0x01, 0x02, 0x03, 0x04, |
| 2049 | // offset |
| 2050 | 0x3A, 0x98, 0xFE, 0xDC, |
| 2051 | 0x32, 0x10, 0x76, 0x54, |
| 2052 | // data length |
| 2053 | 0x00, 0x0c, |
| 2054 | // data |
| 2055 | 'h', 'e', 'l', 'l', |
| 2056 | 'o', ' ', 'w', 'o', |
| 2057 | 'r', 'l', 'd', '!', |
| 2058 | // paddings |
| 2059 | 0x00, 0x00, |
| 2060 | }; |
| 2061 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2062 | unsigned char packet46[] = { |
| 2063 | // type (short header, 4 byte packet number) |
| 2064 | 0x43, |
| 2065 | // connection_id |
| 2066 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2067 | // packet number |
| 2068 | 0x12, 0x34, 0x56, 0x78, |
| 2069 | |
| 2070 | // paddings |
| 2071 | 0x00, 0x00, |
| 2072 | // frame type (stream frame with fin) |
| 2073 | 0xFF, |
| 2074 | // stream id |
| 2075 | 0x01, 0x02, 0x03, 0x04, |
| 2076 | // offset |
| 2077 | 0x3A, 0x98, 0xFE, 0xDC, |
| 2078 | 0x32, 0x10, 0x76, 0x54, |
| 2079 | // data length |
| 2080 | 0x00, 0x0c, |
| 2081 | // data |
| 2082 | 'h', 'e', 'l', 'l', |
| 2083 | 'o', ' ', 'w', 'o', |
| 2084 | 'r', 'l', 'd', '!', |
| 2085 | // paddings |
| 2086 | 0x00, 0x00, |
| 2087 | }; |
| 2088 | |
| 2089 | unsigned char packet99[] = { |
| 2090 | // type (short header, 4 byte packet number) |
| 2091 | 0x43, |
| 2092 | // connection_id |
| 2093 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2094 | // packet number |
| 2095 | 0x12, 0x34, 0x56, 0x78, |
| 2096 | |
| 2097 | // paddings |
| 2098 | 0x00, 0x00, |
| 2099 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 2100 | 0x08 | 0x01 | 0x02 | 0x04, |
| 2101 | |
| 2102 | // stream id |
| 2103 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 2104 | // offset |
| 2105 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2106 | 0x32, 0x10, 0x76, 0x54, |
| 2107 | // data length |
| 2108 | kVarInt62OneByte + 0x0c, |
| 2109 | // data |
| 2110 | 'h', 'e', 'l', 'l', |
| 2111 | 'o', ' ', 'w', 'o', |
| 2112 | 'r', 'l', 'd', '!', |
| 2113 | // paddings |
| 2114 | 0x00, 0x00, |
| 2115 | }; |
| 2116 | // clang-format on |
| 2117 | |
| 2118 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2119 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 2120 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2121 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2122 | p_size = QUICHE_ARRAYSIZE(packet99); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 2123 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2124 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2125 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2126 | } |
| 2127 | |
| 2128 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 2129 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2130 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2131 | ASSERT_TRUE(visitor_.header_.get()); |
| 2132 | EXPECT_TRUE(CheckDecryption( |
| 2133 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2134 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2135 | |
| 2136 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2137 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2138 | EXPECT_EQ(2u, visitor_.padding_frames_.size()); |
| 2139 | EXPECT_EQ(2, visitor_.padding_frames_[0]->num_padding_bytes); |
| 2140 | EXPECT_EQ(2, visitor_.padding_frames_[1]->num_padding_bytes); |
| 2141 | EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2142 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2143 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2144 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2145 | } |
| 2146 | |
| 2147 | TEST_P(QuicFramerTest, StreamFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2148 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2149 | // clang-format off |
| 2150 | PacketFragments packet = { |
| 2151 | // public flags (8 byte connection_id) |
| 2152 | {"", |
| 2153 | {0x28}}, |
| 2154 | // connection_id |
| 2155 | {"", |
| 2156 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2157 | // packet number |
| 2158 | {"", |
| 2159 | {0x12, 0x34, 0x56, 0x78}}, |
| 2160 | // frame type (stream frame with fin) |
| 2161 | {"", |
| 2162 | {0xFF}}, |
| 2163 | // stream id |
| 2164 | {"Unable to read stream_id.", |
| 2165 | {0x01, 0x02, 0x03, 0x04}}, |
| 2166 | // offset |
| 2167 | {"Unable to read offset.", |
| 2168 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2169 | 0x32, 0x10, 0x76, 0x54}}, |
| 2170 | {"Unable to read frame data.", |
| 2171 | { |
| 2172 | // data length |
| 2173 | 0x00, 0x0c, |
| 2174 | // data |
| 2175 | 'h', 'e', 'l', 'l', |
| 2176 | 'o', ' ', 'w', 'o', |
| 2177 | 'r', 'l', 'd', '!'}}, |
| 2178 | }; |
| 2179 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2180 | PacketFragments packet46 = { |
| 2181 | // type (short header, 4 byte packet number) |
| 2182 | {"", |
| 2183 | {0x43}}, |
| 2184 | // connection_id |
| 2185 | {"", |
| 2186 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2187 | // packet number |
| 2188 | {"", |
| 2189 | {0x12, 0x34, 0x56, 0x78}}, |
| 2190 | // frame type (stream frame with fin) |
| 2191 | {"", |
| 2192 | {0xFF}}, |
| 2193 | // stream id |
| 2194 | {"Unable to read stream_id.", |
| 2195 | {0x01, 0x02, 0x03, 0x04}}, |
| 2196 | // offset |
| 2197 | {"Unable to read offset.", |
| 2198 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2199 | 0x32, 0x10, 0x76, 0x54}}, |
| 2200 | {"Unable to read frame data.", |
| 2201 | { |
| 2202 | // data length |
| 2203 | 0x00, 0x0c, |
| 2204 | // data |
| 2205 | 'h', 'e', 'l', 'l', |
| 2206 | 'o', ' ', 'w', 'o', |
| 2207 | 'r', 'l', 'd', '!'}}, |
| 2208 | }; |
| 2209 | |
| 2210 | PacketFragments packet99 = { |
| 2211 | // type (short header, 4 byte packet number) |
| 2212 | {"", |
| 2213 | {0x43}}, |
| 2214 | // connection_id |
| 2215 | {"", |
| 2216 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2217 | // packet number |
| 2218 | {"", |
| 2219 | {0x12, 0x34, 0x56, 0x78}}, |
| 2220 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 2221 | {"", |
| 2222 | { 0x08 | 0x01 | 0x02 | 0x04 }}, |
| 2223 | // stream id |
| 2224 | {"Unable to read stream_id.", |
| 2225 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 2226 | // offset |
| 2227 | {"Unable to read stream data offset.", |
| 2228 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2229 | 0x32, 0x10, 0x76, 0x54}}, |
| 2230 | // data length |
| 2231 | {"Unable to read stream data length.", |
| 2232 | {kVarInt62OneByte + 0x0c}}, |
| 2233 | // data |
| 2234 | {"Unable to read frame data.", |
| 2235 | { 'h', 'e', 'l', 'l', |
| 2236 | 'o', ' ', 'w', 'o', |
| 2237 | 'r', 'l', 'd', '!'}}, |
| 2238 | }; |
| 2239 | // clang-format on |
| 2240 | |
| 2241 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 2242 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2243 | ? packet99 |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 2244 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 2245 | : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2246 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2247 | AssemblePacketFromFragments(fragments)); |
| 2248 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2249 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2250 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2251 | ASSERT_TRUE(visitor_.header_.get()); |
| 2252 | EXPECT_TRUE(CheckDecryption( |
| 2253 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2254 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2255 | |
| 2256 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2257 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2258 | EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2259 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2260 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2261 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2262 | |
| 2263 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2264 | } |
| 2265 | |
| 2266 | // Test an empty (no data) stream frame. |
| 2267 | TEST_P(QuicFramerTest, EmptyStreamFrame) { |
| 2268 | // Only the IETF QUIC spec explicitly says that empty |
| 2269 | // stream frames are supported. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 2270 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2271 | return; |
| 2272 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2273 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2274 | // clang-format off |
| 2275 | PacketFragments packet = { |
| 2276 | // type (short header, 4 byte packet number) |
| 2277 | {"", |
| 2278 | {0x43}}, |
| 2279 | // connection_id |
| 2280 | {"", |
| 2281 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2282 | // packet number |
| 2283 | {"", |
| 2284 | {0x12, 0x34, 0x56, 0x78}}, |
| 2285 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 2286 | {"", |
| 2287 | { 0x08 | 0x01 | 0x02 | 0x04 }}, |
| 2288 | // stream id |
| 2289 | {"Unable to read stream_id.", |
| 2290 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 2291 | // offset |
| 2292 | {"Unable to read stream data offset.", |
| 2293 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2294 | 0x32, 0x10, 0x76, 0x54}}, |
| 2295 | // data length |
| 2296 | {"Unable to read stream data length.", |
| 2297 | {kVarInt62OneByte + 0x00}}, |
| 2298 | }; |
| 2299 | // clang-format on |
| 2300 | |
| 2301 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2302 | AssemblePacketFromFragments(packet)); |
| 2303 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2304 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2305 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2306 | ASSERT_TRUE(visitor_.header_.get()); |
| 2307 | EXPECT_TRUE(CheckDecryption( |
| 2308 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2309 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2310 | |
| 2311 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2312 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2313 | EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2314 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2315 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2316 | EXPECT_EQ(visitor_.stream_frames_[0].get()->data_length, 0u); |
| 2317 | |
| 2318 | CheckFramingBoundaries(packet, QUIC_INVALID_STREAM_DATA); |
| 2319 | } |
| 2320 | |
| 2321 | TEST_P(QuicFramerTest, MissingDiversificationNonce) { |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2322 | if (framer_.version().handshake_protocol != PROTOCOL_QUIC_CRYPTO) { |
| 2323 | // TLS does not use diversification nonces. |
| 2324 | return; |
| 2325 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2326 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2327 | decrypter_ = new test::TestDecrypter(); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2328 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 2329 | framer_.InstallDecrypter( |
| 2330 | ENCRYPTION_INITIAL, |
| 2331 | std::make_unique<NullDecrypter>(Perspective::IS_CLIENT)); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2332 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 2333 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 2334 | } else { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 2335 | framer_.SetDecrypter(ENCRYPTION_INITIAL, std::make_unique<NullDecrypter>( |
| 2336 | Perspective::IS_CLIENT)); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2337 | framer_.SetAlternativeDecrypter( |
| 2338 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 2339 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2340 | |
| 2341 | // clang-format off |
| 2342 | unsigned char packet[] = { |
| 2343 | // public flags (8 byte connection_id) |
| 2344 | 0x28, |
| 2345 | // connection_id |
| 2346 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 2347 | // packet number |
| 2348 | 0x12, 0x34, 0x56, 0x78, |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2349 | // padding frame |
| 2350 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2351 | }; |
| 2352 | |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2353 | unsigned char packet46[] = { |
| 2354 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 2355 | 0xD3, |
| 2356 | // version tag |
| 2357 | QUIC_VERSION_BYTES, |
| 2358 | // connection_id length |
| 2359 | 0x05, |
| 2360 | // connection_id |
| 2361 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 2362 | // packet number |
| 2363 | 0x12, 0x34, 0x56, 0x78, |
| 2364 | // padding frame |
| 2365 | 0x00, |
| 2366 | }; |
| 2367 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 2368 | unsigned char packet49[] = { |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2369 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 2370 | 0xD3, |
| 2371 | // version tag |
| 2372 | QUIC_VERSION_BYTES, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 2373 | // destination connection ID length |
| 2374 | 0x00, |
| 2375 | // source connection ID length |
| 2376 | 0x08, |
| 2377 | // source connection ID |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2378 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 2379 | // IETF long header payload length |
| 2380 | 0x05, |
| 2381 | // packet number |
| 2382 | 0x12, 0x34, 0x56, 0x78, |
| 2383 | // padding frame |
| 2384 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2385 | }; |
| 2386 | // clang-format on |
| 2387 | |
| 2388 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2389 | size_t p_length = QUICHE_ARRAYSIZE(packet); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 2390 | if (framer_.transport_version() >= QUIC_VERSION_49) { |
| 2391 | p = packet49; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2392 | p_length = QUICHE_ARRAYSIZE(packet49); |
fayang | f36e29d | 2019-06-06 14:03:40 -0700 | [diff] [blame] | 2393 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2394 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2395 | p_length = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2396 | } |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2397 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2398 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 2399 | if (framer_.version().HasHeaderProtection()) { |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2400 | EXPECT_THAT(framer_.error(), IsError(QUIC_DECRYPTION_FAILURE)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 2401 | EXPECT_EQ("Unable to decrypt header protection.", framer_.detailed_error()); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 2402 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2403 | // Cannot read diversification nonce. |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2404 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2405 | EXPECT_EQ("Unable to read nonce.", framer_.detailed_error()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2406 | } else { |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2407 | EXPECT_THAT(framer_.error(), IsError(QUIC_DECRYPTION_FAILURE)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2408 | } |
| 2409 | } |
| 2410 | |
| 2411 | TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) { |
| 2412 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 2413 | // This test is nonsensical for IETF Quic. |
| 2414 | return; |
| 2415 | } |
| 2416 | // clang-format off |
| 2417 | PacketFragments packet = { |
| 2418 | // public flags (8 byte connection_id) |
| 2419 | {"", |
| 2420 | {0x28}}, |
| 2421 | // connection_id |
| 2422 | {"", |
| 2423 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2424 | // packet number |
| 2425 | {"", |
| 2426 | {0x12, 0x34, 0x56, 0x78}}, |
| 2427 | // frame type (stream frame with fin) |
| 2428 | {"", |
| 2429 | {0xFE}}, |
| 2430 | // stream id |
| 2431 | {"Unable to read stream_id.", |
| 2432 | {0x02, 0x03, 0x04}}, |
| 2433 | // offset |
| 2434 | {"Unable to read offset.", |
| 2435 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2436 | 0x32, 0x10, 0x76, 0x54}}, |
| 2437 | {"Unable to read frame data.", |
| 2438 | { |
| 2439 | // data length |
| 2440 | 0x00, 0x0c, |
| 2441 | // data |
| 2442 | 'h', 'e', 'l', 'l', |
| 2443 | 'o', ' ', 'w', 'o', |
| 2444 | 'r', 'l', 'd', '!'}}, |
| 2445 | }; |
| 2446 | // clang-format on |
| 2447 | |
| 2448 | PacketFragments& fragments = packet; |
| 2449 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2450 | AssemblePacketFromFragments(fragments)); |
| 2451 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2452 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2453 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2454 | ASSERT_TRUE(visitor_.header_.get()); |
| 2455 | EXPECT_TRUE(CheckDecryption( |
| 2456 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2457 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2458 | |
| 2459 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2460 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2461 | // Stream ID should be the last 3 bytes of kStreamId. |
| 2462 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2463 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2464 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2465 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2466 | |
| 2467 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2468 | } |
| 2469 | |
| 2470 | TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2471 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2472 | // clang-format off |
| 2473 | PacketFragments packet = { |
| 2474 | // public flags (8 byte connection_id) |
| 2475 | {"", |
| 2476 | {0x28}}, |
| 2477 | // connection_id |
| 2478 | {"", |
| 2479 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2480 | // packet number |
| 2481 | {"", |
| 2482 | {0x12, 0x34, 0x56, 0x78}}, |
| 2483 | // frame type (stream frame with fin) |
| 2484 | {"", |
| 2485 | {0xFD}}, |
| 2486 | // stream id |
| 2487 | {"Unable to read stream_id.", |
| 2488 | {0x03, 0x04}}, |
| 2489 | // offset |
| 2490 | {"Unable to read offset.", |
| 2491 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2492 | 0x32, 0x10, 0x76, 0x54}}, |
| 2493 | {"Unable to read frame data.", |
| 2494 | { |
| 2495 | // data length |
| 2496 | 0x00, 0x0c, |
| 2497 | // data |
| 2498 | 'h', 'e', 'l', 'l', |
| 2499 | 'o', ' ', 'w', 'o', |
| 2500 | 'r', 'l', 'd', '!'}}, |
| 2501 | }; |
| 2502 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2503 | PacketFragments packet46 = { |
| 2504 | // type (short header, 4 byte packet number) |
| 2505 | {"", |
| 2506 | {0x43}}, |
| 2507 | // connection_id |
| 2508 | {"", |
| 2509 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2510 | // packet number |
| 2511 | {"", |
| 2512 | {0x12, 0x34, 0x56, 0x78}}, |
| 2513 | // frame type (stream frame with fin) |
| 2514 | {"", |
| 2515 | {0xFD}}, |
| 2516 | // stream id |
| 2517 | {"Unable to read stream_id.", |
| 2518 | {0x03, 0x04}}, |
| 2519 | // offset |
| 2520 | {"Unable to read offset.", |
| 2521 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2522 | 0x32, 0x10, 0x76, 0x54}}, |
| 2523 | {"Unable to read frame data.", |
| 2524 | { |
| 2525 | // data length |
| 2526 | 0x00, 0x0c, |
| 2527 | // data |
| 2528 | 'h', 'e', 'l', 'l', |
| 2529 | 'o', ' ', 'w', 'o', |
| 2530 | 'r', 'l', 'd', '!'}}, |
| 2531 | }; |
| 2532 | |
| 2533 | PacketFragments packet99 = { |
| 2534 | // type (short header, 4 byte packet number) |
| 2535 | {"", |
| 2536 | {0x43}}, |
| 2537 | // connection_id |
| 2538 | {"", |
| 2539 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2540 | // packet number |
| 2541 | {"", |
| 2542 | {0x12, 0x34, 0x56, 0x78}}, |
| 2543 | // frame type (IETF_STREAM frame with LEN, FIN, and OFFSET bits set) |
| 2544 | {"", |
| 2545 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2546 | // stream id |
| 2547 | {"Unable to read stream_id.", |
| 2548 | {kVarInt62TwoBytes + 0x03, 0x04}}, |
| 2549 | // offset |
| 2550 | {"Unable to read stream data offset.", |
| 2551 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2552 | 0x32, 0x10, 0x76, 0x54}}, |
| 2553 | // data length |
| 2554 | {"Unable to read stream data length.", |
| 2555 | {kVarInt62OneByte + 0x0c}}, |
| 2556 | // data |
| 2557 | {"Unable to read frame data.", |
| 2558 | { 'h', 'e', 'l', 'l', |
| 2559 | 'o', ' ', 'w', 'o', |
| 2560 | 'r', 'l', 'd', '!'}}, |
| 2561 | }; |
| 2562 | // clang-format on |
| 2563 | |
| 2564 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 2565 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2566 | ? packet99 |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 2567 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 2568 | : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2569 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2570 | AssemblePacketFromFragments(fragments)); |
| 2571 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2572 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2573 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2574 | ASSERT_TRUE(visitor_.header_.get()); |
| 2575 | EXPECT_TRUE(CheckDecryption( |
| 2576 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2577 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2578 | |
| 2579 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2580 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2581 | // Stream ID should be the last 2 bytes of kStreamId. |
| 2582 | EXPECT_EQ(0x0000FFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2583 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2584 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2585 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2586 | |
| 2587 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2588 | } |
| 2589 | |
| 2590 | TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2591 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2592 | // clang-format off |
| 2593 | PacketFragments packet = { |
| 2594 | // public flags (8 byte connection_id) |
| 2595 | {"", |
| 2596 | {0x28}}, |
| 2597 | // connection_id |
| 2598 | {"", |
| 2599 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2600 | // packet number |
| 2601 | {"", |
| 2602 | {0x12, 0x34, 0x56, 0x78}}, |
| 2603 | // frame type (stream frame with fin) |
| 2604 | {"", |
| 2605 | {0xFC}}, |
| 2606 | // stream id |
| 2607 | {"Unable to read stream_id.", |
| 2608 | {0x04}}, |
| 2609 | // offset |
| 2610 | {"Unable to read offset.", |
| 2611 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2612 | 0x32, 0x10, 0x76, 0x54}}, |
| 2613 | {"Unable to read frame data.", |
| 2614 | { |
| 2615 | // data length |
| 2616 | 0x00, 0x0c, |
| 2617 | // data |
| 2618 | 'h', 'e', 'l', 'l', |
| 2619 | 'o', ' ', 'w', 'o', |
| 2620 | 'r', 'l', 'd', '!'}}, |
| 2621 | }; |
| 2622 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2623 | PacketFragments packet46 = { |
| 2624 | // type (short header, 4 byte packet number) |
| 2625 | {"", |
| 2626 | {0x43}}, |
| 2627 | // connection_id |
| 2628 | {"", |
| 2629 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2630 | // packet number |
| 2631 | {"", |
| 2632 | {0x12, 0x34, 0x56, 0x78}}, |
| 2633 | // frame type (stream frame with fin) |
| 2634 | {"", |
| 2635 | {0xFC}}, |
| 2636 | // stream id |
| 2637 | {"Unable to read stream_id.", |
| 2638 | {0x04}}, |
| 2639 | // offset |
| 2640 | {"Unable to read offset.", |
| 2641 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2642 | 0x32, 0x10, 0x76, 0x54}}, |
| 2643 | {"Unable to read frame data.", |
| 2644 | { |
| 2645 | // data length |
| 2646 | 0x00, 0x0c, |
| 2647 | // data |
| 2648 | 'h', 'e', 'l', 'l', |
| 2649 | 'o', ' ', 'w', 'o', |
| 2650 | 'r', 'l', 'd', '!'}}, |
| 2651 | }; |
| 2652 | |
| 2653 | PacketFragments packet99 = { |
| 2654 | // type (short header, 4 byte packet number) |
| 2655 | {"", |
| 2656 | {0x43}}, |
| 2657 | // connection_id |
| 2658 | {"", |
| 2659 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2660 | // packet number |
| 2661 | {"", |
| 2662 | {0x12, 0x34, 0x56, 0x78}}, |
| 2663 | // frame type (IETF_STREAM frame with LEN, FIN, and OFFSET bits set) |
| 2664 | {"", |
| 2665 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2666 | // stream id |
| 2667 | {"Unable to read stream_id.", |
| 2668 | {kVarInt62OneByte + 0x04}}, |
| 2669 | // offset |
| 2670 | {"Unable to read stream data offset.", |
| 2671 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2672 | 0x32, 0x10, 0x76, 0x54}}, |
| 2673 | // data length |
| 2674 | {"Unable to read stream data length.", |
| 2675 | {kVarInt62OneByte + 0x0c}}, |
| 2676 | // data |
| 2677 | {"Unable to read frame data.", |
| 2678 | { 'h', 'e', 'l', 'l', |
| 2679 | 'o', ' ', 'w', 'o', |
| 2680 | 'r', 'l', 'd', '!'}}, |
| 2681 | }; |
| 2682 | // clang-format on |
| 2683 | |
| 2684 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 2685 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2686 | ? packet99 |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 2687 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 2688 | : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2689 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2690 | AssemblePacketFromFragments(fragments)); |
| 2691 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2692 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2693 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2694 | ASSERT_TRUE(visitor_.header_.get()); |
| 2695 | EXPECT_TRUE(CheckDecryption( |
| 2696 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2697 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2698 | |
| 2699 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2700 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2701 | // Stream ID should be the last 1 byte of kStreamId. |
| 2702 | EXPECT_EQ(0x000000FF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2703 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2704 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2705 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2706 | |
| 2707 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2708 | } |
| 2709 | |
| 2710 | TEST_P(QuicFramerTest, StreamFrameWithVersion) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 2711 | // If IETF frames are in use then we must also have the IETF |
| 2712 | // header invariants. |
| 2713 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 2714 | DCHECK(VersionHasIetfInvariantHeader(framer_.transport_version())); |
| 2715 | } |
| 2716 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2717 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2718 | // clang-format off |
| 2719 | PacketFragments packet = { |
| 2720 | // public flags (version, 8 byte connection_id) |
| 2721 | {"", |
| 2722 | {0x29}}, |
| 2723 | // connection_id |
| 2724 | {"", |
| 2725 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2726 | // version tag |
| 2727 | {"", |
| 2728 | {QUIC_VERSION_BYTES}}, |
| 2729 | // packet number |
| 2730 | {"", |
| 2731 | {0x12, 0x34, 0x56, 0x78}}, |
| 2732 | // frame type (stream frame with fin) |
| 2733 | {"", |
| 2734 | {0xFE}}, |
| 2735 | // stream id |
| 2736 | {"Unable to read stream_id.", |
| 2737 | {0x02, 0x03, 0x04}}, |
| 2738 | // offset |
| 2739 | {"Unable to read offset.", |
| 2740 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2741 | 0x32, 0x10, 0x76, 0x54}}, |
| 2742 | {"Unable to read frame data.", |
| 2743 | { |
| 2744 | // data length |
| 2745 | 0x00, 0x0c, |
| 2746 | // data |
| 2747 | 'h', 'e', 'l', 'l', |
| 2748 | 'o', ' ', 'w', 'o', |
| 2749 | 'r', 'l', 'd', '!'}}, |
| 2750 | }; |
| 2751 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2752 | PacketFragments packet46 = { |
| 2753 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 2754 | // 4-byte packet number) |
| 2755 | {"", |
| 2756 | {0xD3}}, |
| 2757 | // version tag |
| 2758 | {"", |
| 2759 | {QUIC_VERSION_BYTES}}, |
| 2760 | // connection_id length |
| 2761 | {"", |
| 2762 | {0x50}}, |
| 2763 | // connection_id |
| 2764 | {"", |
| 2765 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2766 | // packet number |
| 2767 | {"", |
| 2768 | {0x12, 0x34, 0x56, 0x78}}, |
| 2769 | // frame type (stream frame with fin) |
| 2770 | {"", |
| 2771 | {0xFE}}, |
| 2772 | // stream id |
| 2773 | {"Unable to read stream_id.", |
| 2774 | {0x02, 0x03, 0x04}}, |
| 2775 | // offset |
| 2776 | {"Unable to read offset.", |
| 2777 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2778 | 0x32, 0x10, 0x76, 0x54}}, |
| 2779 | {"Unable to read frame data.", |
| 2780 | { |
| 2781 | // data length |
| 2782 | 0x00, 0x0c, |
| 2783 | // data |
| 2784 | 'h', 'e', 'l', 'l', |
| 2785 | 'o', ' ', 'w', 'o', |
| 2786 | 'r', 'l', 'd', '!'}}, |
| 2787 | }; |
| 2788 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 2789 | PacketFragments packet49 = { |
| 2790 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 2791 | // 4-byte packet number) |
| 2792 | {"", |
| 2793 | {0xD3}}, |
| 2794 | // version tag |
| 2795 | {"", |
| 2796 | {QUIC_VERSION_BYTES}}, |
| 2797 | // destination connection ID length |
| 2798 | {"", |
| 2799 | {0x08}}, |
| 2800 | // destination connection ID |
| 2801 | {"", |
| 2802 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2803 | // source connection ID length |
| 2804 | {"", |
| 2805 | {0x00}}, |
| 2806 | // long header packet length |
| 2807 | {"", |
| 2808 | {0x1E}}, |
| 2809 | // packet number |
| 2810 | {"", |
| 2811 | {0x12, 0x34, 0x56, 0x78}}, |
| 2812 | // frame type (stream frame with fin) |
| 2813 | {"", |
| 2814 | {0xFE}}, |
| 2815 | // stream id |
| 2816 | {"Long header payload length longer than packet.", |
| 2817 | {0x02, 0x03, 0x04}}, |
| 2818 | // offset |
| 2819 | {"Long header payload length longer than packet.", |
| 2820 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2821 | 0x32, 0x10, 0x76, 0x54}}, |
| 2822 | {"Long header payload length longer than packet.", |
| 2823 | { |
| 2824 | // data length |
| 2825 | 0x00, 0x0c, |
| 2826 | // data |
| 2827 | 'h', 'e', 'l', 'l', |
| 2828 | 'o', ' ', 'w', 'o', |
| 2829 | 'r', 'l', 'd', '!'}}, |
| 2830 | }; |
| 2831 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2832 | PacketFragments packet99 = { |
| 2833 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 2834 | // 4-byte packet number) |
| 2835 | {"", |
| 2836 | {0xD3}}, |
| 2837 | // version tag |
| 2838 | {"", |
| 2839 | {QUIC_VERSION_BYTES}}, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 2840 | // destination connection ID length |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2841 | {"", |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 2842 | {0x08}}, |
| 2843 | // destination connection ID |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2844 | {"", |
| 2845 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 2846 | // source connection ID length |
| 2847 | {"", |
| 2848 | {0x00}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2849 | // long header packet length |
| 2850 | {"", |
| 2851 | {0x1E}}, |
| 2852 | // packet number |
| 2853 | {"", |
| 2854 | {0x12, 0x34, 0x56, 0x78}}, |
| 2855 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 2856 | {"", |
| 2857 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2858 | // stream id |
| 2859 | {"Long header payload length longer than packet.", |
| 2860 | {kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04}}, |
| 2861 | // offset |
| 2862 | {"Long header payload length longer than packet.", |
| 2863 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2864 | 0x32, 0x10, 0x76, 0x54}}, |
| 2865 | // data length |
| 2866 | {"Long header payload length longer than packet.", |
| 2867 | {kVarInt62OneByte + 0x0c}}, |
| 2868 | // data |
| 2869 | {"Long header payload length longer than packet.", |
| 2870 | { 'h', 'e', 'l', 'l', |
| 2871 | 'o', ' ', 'w', 'o', |
| 2872 | 'r', 'l', 'd', '!'}}, |
| 2873 | }; |
| 2874 | // clang-format on |
| 2875 | |
| 2876 | QuicVariableLengthIntegerLength retry_token_length_length = |
| 2877 | VARIABLE_LENGTH_INTEGER_LENGTH_0; |
| 2878 | size_t retry_token_length = 0; |
| 2879 | QuicVariableLengthIntegerLength length_length = |
| 2880 | QuicVersionHasLongHeaderLengths(framer_.transport_version()) |
| 2881 | ? VARIABLE_LENGTH_INTEGER_LENGTH_1 |
| 2882 | : VARIABLE_LENGTH_INTEGER_LENGTH_0; |
| 2883 | |
| 2884 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 2885 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2886 | ? packet99 |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 2887 | : (framer_.transport_version() >= QUIC_VERSION_49 |
| 2888 | ? packet49 |
| 2889 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 2890 | : packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2891 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2892 | AssemblePacketFromFragments(fragments)); |
| 2893 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2894 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2895 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2896 | ASSERT_TRUE(visitor_.header_.get()); |
| 2897 | EXPECT_TRUE(CheckDecryption( |
| 2898 | *encrypted, kIncludeVersion, !kIncludeDiversificationNonce, |
| 2899 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID, |
| 2900 | retry_token_length_length, retry_token_length, length_length)); |
| 2901 | |
| 2902 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2903 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2904 | // Stream ID should be the last 3 bytes of kStreamId. |
| 2905 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2906 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2907 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2908 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2909 | |
| 2910 | CheckFramingBoundaries(fragments, |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 2911 | framer_.transport_version() >= QUIC_VERSION_49 |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2912 | ? QUIC_INVALID_PACKET_HEADER |
| 2913 | : QUIC_INVALID_STREAM_DATA); |
| 2914 | } |
| 2915 | |
| 2916 | TEST_P(QuicFramerTest, RejectPacket) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2917 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2918 | visitor_.accept_packet_ = false; |
| 2919 | |
| 2920 | // clang-format off |
| 2921 | unsigned char packet[] = { |
| 2922 | // public flags (8 byte connection_id) |
| 2923 | 0x28, |
| 2924 | // connection_id |
| 2925 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2926 | // packet number |
| 2927 | 0x12, 0x34, 0x56, 0x78, |
| 2928 | |
| 2929 | // frame type (stream frame with fin) |
| 2930 | 0xFF, |
| 2931 | // stream id |
| 2932 | 0x01, 0x02, 0x03, 0x04, |
| 2933 | // offset |
| 2934 | 0x3A, 0x98, 0xFE, 0xDC, |
| 2935 | 0x32, 0x10, 0x76, 0x54, |
| 2936 | // data length |
| 2937 | 0x00, 0x0c, |
| 2938 | // data |
| 2939 | 'h', 'e', 'l', 'l', |
| 2940 | 'o', ' ', 'w', 'o', |
| 2941 | 'r', 'l', 'd', '!', |
| 2942 | }; |
| 2943 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2944 | unsigned char packet46[] = { |
| 2945 | // type (short header, 4 byte packet number) |
| 2946 | 0x43, |
| 2947 | // connection_id |
| 2948 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2949 | // packet number |
| 2950 | 0x12, 0x34, 0x56, 0x78, |
| 2951 | |
| 2952 | // frame type (STREAM Frame with FIN, LEN, and OFFSET bits set) |
| 2953 | 0x10 | 0x01 | 0x02 | 0x04, |
| 2954 | // stream id |
| 2955 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 2956 | // offset |
| 2957 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2958 | 0x32, 0x10, 0x76, 0x54, |
| 2959 | // data length |
| 2960 | kVarInt62OneByte + 0x0c, |
| 2961 | // data |
| 2962 | 'h', 'e', 'l', 'l', |
| 2963 | 'o', ' ', 'w', 'o', |
| 2964 | 'r', 'l', 'd', '!', |
| 2965 | }; |
| 2966 | // clang-format on |
| 2967 | |
| 2968 | unsigned char* p = packet; |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 2969 | if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2970 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2971 | } |
| 2972 | QuicEncryptedPacket encrypted(AsChars(p), |
| 2973 | framer_.transport_version() > QUIC_VERSION_43 |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 2974 | ? QUICHE_ARRAYSIZE(packet46) |
| 2975 | : QUICHE_ARRAYSIZE(packet), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2976 | false); |
| 2977 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 2978 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2979 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2980 | ASSERT_TRUE(visitor_.header_.get()); |
| 2981 | EXPECT_TRUE(CheckDecryption( |
| 2982 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2983 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2984 | |
| 2985 | ASSERT_EQ(0u, visitor_.stream_frames_.size()); |
| 2986 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2987 | } |
| 2988 | |
| 2989 | TEST_P(QuicFramerTest, RejectPublicHeader) { |
| 2990 | visitor_.accept_public_header_ = false; |
| 2991 | |
| 2992 | // clang-format off |
| 2993 | unsigned char packet[] = { |
| 2994 | // public flags (8 byte connection_id) |
| 2995 | 0x28, |
| 2996 | // connection_id |
| 2997 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2998 | }; |
| 2999 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3000 | unsigned char packet46[] = { |
| 3001 | // type (short header, 1 byte packet number) |
| 3002 | 0x40, |
| 3003 | // connection_id |
| 3004 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3005 | // packet number |
| 3006 | 0x01, |
| 3007 | }; |
| 3008 | // clang-format on |
| 3009 | |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 3010 | QuicEncryptedPacket encrypted(framer_.transport_version() >= QUIC_VERSION_46 |
| 3011 | ? AsChars(packet46) |
| 3012 | : AsChars(packet), |
| 3013 | framer_.transport_version() >= QUIC_VERSION_46 |
| 3014 | ? QUICHE_ARRAYSIZE(packet46) |
| 3015 | : QUICHE_ARRAYSIZE(packet), |
| 3016 | false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3017 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 3018 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 3019 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3020 | ASSERT_TRUE(visitor_.header_.get()); |
| 3021 | EXPECT_FALSE(visitor_.header_->packet_number.IsInitialized()); |
| 3022 | } |
| 3023 | |
| 3024 | TEST_P(QuicFramerTest, AckFrameOneAckBlock) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3025 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3026 | // clang-format off |
| 3027 | PacketFragments packet = { |
| 3028 | // public flags (8 byte connection_id) |
| 3029 | {"", |
| 3030 | {0x2C}}, |
| 3031 | // connection_id |
| 3032 | {"", |
| 3033 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3034 | // packet number |
| 3035 | {"", |
| 3036 | {0x12, 0x34, 0x56, 0x78}}, |
| 3037 | // frame type (ack frame) |
| 3038 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 3039 | {"", |
| 3040 | {0x45}}, |
| 3041 | // largest acked |
| 3042 | {"Unable to read largest acked.", |
| 3043 | {0x12, 0x34}}, |
| 3044 | // Zero delta time. |
| 3045 | {"Unable to read ack delay time.", |
| 3046 | {0x00, 0x00}}, |
| 3047 | // first ack block length. |
| 3048 | {"Unable to read first ack block length.", |
| 3049 | {0x12, 0x34}}, |
| 3050 | // num timestamps. |
| 3051 | {"Unable to read num received packets.", |
| 3052 | {0x00}} |
| 3053 | }; |
| 3054 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3055 | PacketFragments packet46 = { |
| 3056 | // type (short packet, 4 byte packet number) |
| 3057 | {"", |
| 3058 | {0x43}}, |
| 3059 | // connection_id |
| 3060 | {"", |
| 3061 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3062 | // packet number |
| 3063 | {"", |
| 3064 | {0x12, 0x34, 0x56, 0x78}}, |
| 3065 | // frame type (ack frame) |
| 3066 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 3067 | {"", |
| 3068 | {0x45}}, |
| 3069 | // largest acked |
| 3070 | {"Unable to read largest acked.", |
| 3071 | {0x12, 0x34}}, |
| 3072 | // Zero delta time. |
| 3073 | {"Unable to read ack delay time.", |
| 3074 | {0x00, 0x00}}, |
| 3075 | // first ack block length. |
| 3076 | {"Unable to read first ack block length.", |
| 3077 | {0x12, 0x34}}, |
| 3078 | // num timestamps. |
| 3079 | {"Unable to read num received packets.", |
| 3080 | {0x00}} |
| 3081 | }; |
| 3082 | |
| 3083 | PacketFragments packet99 = { |
| 3084 | // type (short packet, 4 byte packet number) |
| 3085 | {"", |
| 3086 | {0x43}}, |
| 3087 | // connection_id |
| 3088 | {"", |
| 3089 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3090 | // packet number |
| 3091 | {"", |
| 3092 | {0x12, 0x34, 0x56, 0x78}}, |
| 3093 | // frame type (IETF_ACK) |
| 3094 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 3095 | // IETF-Quic ignores the bit-fields in the ack type, all of |
| 3096 | // that information is encoded elsewhere in the frame. |
| 3097 | {"", |
| 3098 | {0x02}}, |
| 3099 | // largest acked |
| 3100 | {"Unable to read largest acked.", |
| 3101 | {kVarInt62TwoBytes + 0x12, 0x34}}, |
| 3102 | // Zero delta time. |
| 3103 | {"Unable to read ack delay time.", |
| 3104 | {kVarInt62OneByte + 0x00}}, |
| 3105 | // Ack block count (0 -- no blocks after the first) |
| 3106 | {"Unable to read ack block count.", |
| 3107 | {kVarInt62OneByte + 0x00}}, |
| 3108 | // first ack block length - 1. |
| 3109 | // IETF Quic defines the ack block's value as the "number of |
| 3110 | // packets that preceed the largest packet number in the block" |
| 3111 | // which for the 1st ack block is the largest acked field, |
| 3112 | // above. This means that if we are acking just packet 0x1234 |
| 3113 | // then the 1st ack block will be 0. |
| 3114 | {"Unable to read first ack block length.", |
| 3115 | {kVarInt62TwoBytes + 0x12, 0x33}} |
| 3116 | }; |
| 3117 | // clang-format on |
| 3118 | |
| 3119 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3120 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3121 | ? packet99 |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 3122 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 3123 | : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3124 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3125 | AssemblePacketFromFragments(fragments)); |
| 3126 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3127 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 3128 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3129 | ASSERT_TRUE(visitor_.header_.get()); |
| 3130 | EXPECT_TRUE(CheckDecryption( |
| 3131 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3132 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3133 | |
| 3134 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3135 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3136 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3137 | EXPECT_EQ(kSmallLargestObserved, LargestAcked(frame)); |
| 3138 | ASSERT_EQ(4660u, frame.packets.NumPacketsSlow()); |
| 3139 | |
| 3140 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3141 | } |
| 3142 | |
| 3143 | // This test checks that the ack frame processor correctly identifies |
| 3144 | // and handles the case where the first ack block is larger than the |
| 3145 | // largest_acked packet. |
| 3146 | TEST_P(QuicFramerTest, FirstAckFrameUnderflow) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3147 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3148 | // clang-format off |
| 3149 | PacketFragments packet = { |
| 3150 | // public flags (8 byte connection_id) |
| 3151 | {"", |
| 3152 | {0x2C}}, |
| 3153 | // connection_id |
| 3154 | {"", |
| 3155 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3156 | // packet number |
| 3157 | {"", |
| 3158 | {0x12, 0x34, 0x56, 0x78}}, |
| 3159 | // frame type (ack frame) |
| 3160 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 3161 | {"", |
| 3162 | {0x45}}, |
| 3163 | // largest acked |
| 3164 | {"Unable to read largest acked.", |
| 3165 | {0x12, 0x34}}, |
| 3166 | // Zero delta time. |
| 3167 | {"Unable to read ack delay time.", |
| 3168 | {0x00, 0x00}}, |
| 3169 | // first ack block length. |
| 3170 | {"Unable to read first ack block length.", |
| 3171 | {0x88, 0x88}}, |
| 3172 | // num timestamps. |
| 3173 | {"Underflow with first ack block length 34952 largest acked is 4660.", |
| 3174 | {0x00}} |
| 3175 | }; |
| 3176 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3177 | PacketFragments packet46 = { |
| 3178 | // type (short header, 4 byte packet number) |
| 3179 | {"", |
| 3180 | {0x43}}, |
| 3181 | // connection_id |
| 3182 | {"", |
| 3183 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3184 | // packet number |
| 3185 | {"", |
| 3186 | {0x12, 0x34, 0x56, 0x78}}, |
| 3187 | // frame type (ack frame) |
| 3188 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 3189 | {"", |
| 3190 | {0x45}}, |
| 3191 | // largest acked |
| 3192 | {"Unable to read largest acked.", |
| 3193 | {0x12, 0x34}}, |
| 3194 | // Zero delta time. |
| 3195 | {"Unable to read ack delay time.", |
| 3196 | {0x00, 0x00}}, |
| 3197 | // first ack block length. |
| 3198 | {"Unable to read first ack block length.", |
| 3199 | {0x88, 0x88}}, |
| 3200 | // num timestamps. |
| 3201 | {"Underflow with first ack block length 34952 largest acked is 4660.", |
| 3202 | {0x00}} |
| 3203 | }; |
| 3204 | |
| 3205 | PacketFragments packet99 = { |
| 3206 | // type (short header, 4 byte packet number) |
| 3207 | {"", |
| 3208 | {0x43}}, |
| 3209 | // connection_id |
| 3210 | {"", |
| 3211 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3212 | // packet number |
| 3213 | {"", |
| 3214 | {0x12, 0x34, 0x56, 0x78}}, |
| 3215 | // frame type (IETF_ACK) |
| 3216 | {"", |
| 3217 | {0x02}}, |
| 3218 | // largest acked |
| 3219 | {"Unable to read largest acked.", |
| 3220 | {kVarInt62TwoBytes + 0x12, 0x34}}, |
| 3221 | // Zero delta time. |
| 3222 | {"Unable to read ack delay time.", |
| 3223 | {kVarInt62OneByte + 0x00}}, |
| 3224 | // Ack block count (0 -- no blocks after the first) |
| 3225 | {"Unable to read ack block count.", |
| 3226 | {kVarInt62OneByte + 0x00}}, |
| 3227 | // first ack block length. |
| 3228 | {"Unable to read first ack block length.", |
| 3229 | {kVarInt62TwoBytes + 0x28, 0x88}} |
| 3230 | }; |
| 3231 | // clang-format on |
| 3232 | |
| 3233 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3234 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3235 | ? packet99 |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 3236 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 3237 | : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3238 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3239 | AssemblePacketFromFragments(fragments)); |
| 3240 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3241 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3242 | } |
| 3243 | |
| 3244 | // This test checks that the ack frame processor correctly identifies |
| 3245 | // and handles the case where the third ack block's gap is larger than the |
| 3246 | // available space in the ack range. |
| 3247 | TEST_P(QuicFramerTest, ThirdAckBlockUnderflowGap) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3248 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 3249 | // Test originally written for development of IETF QUIC. The test may |
| 3250 | // also apply to Google QUIC. If so, the test should be extended to |
| 3251 | // include Google QUIC (frame formats, etc). See b/141858819. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3252 | return; |
| 3253 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3254 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3255 | // clang-format off |
| 3256 | PacketFragments packet99 = { |
| 3257 | // type (short header, 4 byte packet number) |
| 3258 | {"", |
| 3259 | {0x43}}, |
| 3260 | // connection_id |
| 3261 | {"", |
| 3262 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3263 | // packet number |
| 3264 | {"", |
| 3265 | {0x12, 0x34, 0x56, 0x78}}, |
| 3266 | // frame type (IETF_ACK frame) |
| 3267 | {"", |
| 3268 | {0x02}}, |
| 3269 | // largest acked |
| 3270 | {"Unable to read largest acked.", |
| 3271 | {kVarInt62OneByte + 63}}, |
| 3272 | // Zero delta time. |
| 3273 | {"Unable to read ack delay time.", |
| 3274 | {kVarInt62OneByte + 0x00}}, |
| 3275 | // Ack block count (2 -- 2 blocks after the first) |
| 3276 | {"Unable to read ack block count.", |
| 3277 | {kVarInt62OneByte + 0x02}}, |
| 3278 | // first ack block length. |
| 3279 | {"Unable to read first ack block length.", |
| 3280 | {kVarInt62OneByte + 13}}, // Ack 14 packets, range 50..63 (inclusive) |
| 3281 | |
| 3282 | {"Unable to read gap block value.", |
| 3283 | {kVarInt62OneByte + 9}}, // Gap 10 packets, 40..49 (inclusive) |
| 3284 | {"Unable to read ack block value.", |
| 3285 | {kVarInt62OneByte + 9}}, // Ack 10 packets, 30..39 (inclusive) |
| 3286 | {"Unable to read gap block value.", |
| 3287 | {kVarInt62OneByte + 29}}, // A gap of 30 packets (0..29 inclusive) |
| 3288 | // should be too big, leaving no room |
| 3289 | // for the ack. |
| 3290 | {"Underflow with gap block length 30 previous ack block start is 30.", |
| 3291 | {kVarInt62OneByte + 10}}, // Don't care |
| 3292 | }; |
| 3293 | // clang-format on |
| 3294 | |
| 3295 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3296 | AssemblePacketFromFragments(packet99)); |
| 3297 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3298 | EXPECT_EQ( |
| 3299 | framer_.detailed_error(), |
| 3300 | "Underflow with gap block length 30 previous ack block start is 30."); |
| 3301 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3302 | } |
| 3303 | |
| 3304 | // This test checks that the ack frame processor correctly identifies |
| 3305 | // and handles the case where the third ack block's length is larger than the |
| 3306 | // available space in the ack range. |
| 3307 | TEST_P(QuicFramerTest, ThirdAckBlockUnderflowAck) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3308 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 3309 | // Test originally written for development of IETF QUIC. The test may |
| 3310 | // also apply to Google QUIC. If so, the test should be extended to |
| 3311 | // include Google QUIC (frame formats, etc). See b/141858819. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3312 | return; |
| 3313 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3314 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3315 | // clang-format off |
| 3316 | PacketFragments packet99 = { |
| 3317 | // type (short header, 4 byte packet number) |
| 3318 | {"", |
| 3319 | {0x43}}, |
| 3320 | // connection_id |
| 3321 | {"", |
| 3322 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3323 | // packet number |
| 3324 | {"", |
| 3325 | {0x12, 0x34, 0x56, 0x78}}, |
| 3326 | // frame type (IETF_ACK frame) |
| 3327 | {"", |
| 3328 | {0x02}}, |
| 3329 | // largest acked |
| 3330 | {"Unable to read largest acked.", |
| 3331 | {kVarInt62OneByte + 63}}, |
| 3332 | // Zero delta time. |
| 3333 | {"Unable to read ack delay time.", |
| 3334 | {kVarInt62OneByte + 0x00}}, |
| 3335 | // Ack block count (2 -- 2 blocks after the first) |
| 3336 | {"Unable to read ack block count.", |
| 3337 | {kVarInt62OneByte + 0x02}}, |
| 3338 | // first ack block length. |
| 3339 | {"Unable to read first ack block length.", |
| 3340 | {kVarInt62OneByte + 13}}, // only 50 packet numbers "left" |
| 3341 | |
| 3342 | {"Unable to read gap block value.", |
| 3343 | {kVarInt62OneByte + 10}}, // Only 40 packet numbers left |
| 3344 | {"Unable to read ack block value.", |
| 3345 | {kVarInt62OneByte + 10}}, // only 30 packet numbers left. |
| 3346 | {"Unable to read gap block value.", |
| 3347 | {kVarInt62OneByte + 1}}, // Gap is OK, 29 packet numbers left |
| 3348 | {"Unable to read ack block value.", |
| 3349 | {kVarInt62OneByte + 30}}, // Use up all 30, should be an error |
| 3350 | }; |
| 3351 | // clang-format on |
| 3352 | |
| 3353 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3354 | AssemblePacketFromFragments(packet99)); |
| 3355 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3356 | EXPECT_EQ(framer_.detailed_error(), |
| 3357 | "Underflow with ack block length 31 latest ack block end is 25."); |
| 3358 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3359 | } |
| 3360 | |
| 3361 | // Tests a variety of ack block wrap scenarios. For example, if the |
| 3362 | // N-1th block causes packet 0 to be acked, then a gap would wrap |
| 3363 | // around to 0x3fffffff ffffffff... Make sure we detect this |
| 3364 | // condition. |
| 3365 | TEST_P(QuicFramerTest, AckBlockUnderflowGapWrap) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3366 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 3367 | // Test originally written for development of IETF QUIC. The test may |
| 3368 | // also apply to Google QUIC. If so, the test should be extended to |
| 3369 | // include Google QUIC (frame formats, etc). See b/141858819. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3370 | return; |
| 3371 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3372 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3373 | // clang-format off |
| 3374 | PacketFragments packet99 = { |
| 3375 | // type (short header, 4 byte packet number) |
| 3376 | {"", |
| 3377 | {0x43}}, |
| 3378 | // connection_id |
| 3379 | {"", |
| 3380 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3381 | // packet number |
| 3382 | {"", |
| 3383 | {0x12, 0x34, 0x56, 0x78}}, |
| 3384 | // frame type (IETF_ACK frame) |
| 3385 | {"", |
| 3386 | {0x02}}, |
| 3387 | // largest acked |
| 3388 | {"Unable to read largest acked.", |
| 3389 | {kVarInt62OneByte + 10}}, |
| 3390 | // Zero delta time. |
| 3391 | {"Unable to read ack delay time.", |
| 3392 | {kVarInt62OneByte + 0x00}}, |
| 3393 | // Ack block count (1 -- 1 blocks after the first) |
| 3394 | {"Unable to read ack block count.", |
| 3395 | {kVarInt62OneByte + 1}}, |
| 3396 | // first ack block length. |
| 3397 | {"Unable to read first ack block length.", |
| 3398 | {kVarInt62OneByte + 9}}, // Ack packets 1..10 (inclusive) |
| 3399 | |
| 3400 | {"Unable to read gap block value.", |
| 3401 | {kVarInt62OneByte + 1}}, // Gap of 2 packets (-1...0), should wrap |
| 3402 | {"Underflow with gap block length 2 previous ack block start is 1.", |
| 3403 | {kVarInt62OneByte + 9}}, // irrelevant |
| 3404 | }; |
| 3405 | // clang-format on |
| 3406 | |
| 3407 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3408 | AssemblePacketFromFragments(packet99)); |
| 3409 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3410 | EXPECT_EQ(framer_.detailed_error(), |
| 3411 | "Underflow with gap block length 2 previous ack block start is 1."); |
| 3412 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3413 | } |
| 3414 | |
| 3415 | // As AckBlockUnderflowGapWrap, but in this test, it's the ack |
| 3416 | // component of the ack-block that causes the wrap, not the gap. |
| 3417 | TEST_P(QuicFramerTest, AckBlockUnderflowAckWrap) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3418 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 3419 | // Test originally written for development of IETF QUIC. The test may |
| 3420 | // also apply to Google QUIC. If so, the test should be extended to |
| 3421 | // include Google QUIC (frame formats, etc). See b/141858819. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3422 | return; |
| 3423 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3424 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3425 | // clang-format off |
| 3426 | PacketFragments packet99 = { |
| 3427 | // type (short header, 4 byte packet number) |
| 3428 | {"", |
| 3429 | {0x43}}, |
| 3430 | // connection_id |
| 3431 | {"", |
| 3432 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3433 | // packet number |
| 3434 | {"", |
| 3435 | {0x12, 0x34, 0x56, 0x78}}, |
| 3436 | // frame type (IETF_ACK frame) |
| 3437 | {"", |
| 3438 | {0x02}}, |
| 3439 | // largest acked |
| 3440 | {"Unable to read largest acked.", |
| 3441 | {kVarInt62OneByte + 10}}, |
| 3442 | // Zero delta time. |
| 3443 | {"Unable to read ack delay time.", |
| 3444 | {kVarInt62OneByte + 0x00}}, |
| 3445 | // Ack block count (1 -- 1 blocks after the first) |
| 3446 | {"Unable to read ack block count.", |
| 3447 | {kVarInt62OneByte + 1}}, |
| 3448 | // first ack block length. |
| 3449 | {"Unable to read first ack block length.", |
| 3450 | {kVarInt62OneByte + 6}}, // Ack packets 4..10 (inclusive) |
| 3451 | |
| 3452 | {"Unable to read gap block value.", |
| 3453 | {kVarInt62OneByte + 1}}, // Gap of 2 packets (2..3) |
| 3454 | {"Unable to read ack block value.", |
| 3455 | {kVarInt62OneByte + 9}}, // Should wrap. |
| 3456 | }; |
| 3457 | // clang-format on |
| 3458 | |
| 3459 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3460 | AssemblePacketFromFragments(packet99)); |
| 3461 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3462 | EXPECT_EQ(framer_.detailed_error(), |
| 3463 | "Underflow with ack block length 10 latest ack block end is 1."); |
| 3464 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3465 | } |
| 3466 | |
| 3467 | // An ack block that acks the entire range, 1...0x3fffffffffffffff |
| 3468 | TEST_P(QuicFramerTest, AckBlockAcksEverything) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3469 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 3470 | // Test originally written for development of IETF QUIC. The test may |
| 3471 | // also apply to Google QUIC. If so, the test should be extended to |
| 3472 | // include Google QUIC (frame formats, etc). See b/141858819. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3473 | return; |
| 3474 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3475 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3476 | // clang-format off |
| 3477 | PacketFragments packet99 = { |
| 3478 | // type (short header, 4 byte packet number) |
| 3479 | {"", |
| 3480 | {0x43}}, |
| 3481 | // connection_id |
| 3482 | {"", |
| 3483 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3484 | // packet number |
| 3485 | {"", |
| 3486 | {0x12, 0x34, 0x56, 0x78}}, |
| 3487 | // frame type (IETF_ACK frame) |
| 3488 | {"", |
| 3489 | {0x02}}, |
| 3490 | // largest acked |
| 3491 | {"Unable to read largest acked.", |
| 3492 | {kVarInt62EightBytes + 0x3f, 0xff, 0xff, 0xff, |
| 3493 | 0xff, 0xff, 0xff, 0xff}}, |
| 3494 | // Zero delta time. |
| 3495 | {"Unable to read ack delay time.", |
| 3496 | {kVarInt62OneByte + 0x00}}, |
| 3497 | // Ack block count No additional blocks |
| 3498 | {"Unable to read ack block count.", |
| 3499 | {kVarInt62OneByte + 0}}, |
| 3500 | // first ack block length. |
| 3501 | {"Unable to read first ack block length.", |
| 3502 | {kVarInt62EightBytes + 0x3f, 0xff, 0xff, 0xff, |
| 3503 | 0xff, 0xff, 0xff, 0xfe}}, |
| 3504 | }; |
| 3505 | // clang-format on |
| 3506 | |
| 3507 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3508 | AssemblePacketFromFragments(packet99)); |
| 3509 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3510 | EXPECT_EQ(1u, visitor_.ack_frames_.size()); |
| 3511 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3512 | EXPECT_EQ(1u, frame.packets.NumIntervals()); |
| 3513 | EXPECT_EQ(kLargestIetfLargestObserved, LargestAcked(frame)); |
| 3514 | EXPECT_EQ(kLargestIetfLargestObserved.ToUint64(), |
| 3515 | frame.packets.NumPacketsSlow()); |
| 3516 | } |
| 3517 | |
| 3518 | // This test looks for a malformed ack where |
| 3519 | // - There is a largest-acked value (that is, the frame is acking |
| 3520 | // something, |
| 3521 | // - But the length of the first ack block is 0 saying that no frames |
| 3522 | // are being acked with the largest-acked value or there are no |
| 3523 | // additional ack blocks. |
| 3524 | // |
| 3525 | TEST_P(QuicFramerTest, AckFrameFirstAckBlockLengthZero) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3526 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3527 | // Not applicable to version 99 -- first ack block contains the |
| 3528 | // number of packets that preceed the largest_acked packet. |
| 3529 | // A value of 0 means no packets preceed --- that the block's |
| 3530 | // length is 1. Therefore the condition that this test checks can |
| 3531 | // not arise. |
| 3532 | return; |
| 3533 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 3534 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3535 | |
| 3536 | // clang-format off |
| 3537 | PacketFragments packet = { |
| 3538 | // public flags (8 byte connection_id) |
| 3539 | {"", |
| 3540 | { 0x2C }}, |
| 3541 | // connection_id |
| 3542 | {"", |
| 3543 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3544 | // packet number |
| 3545 | {"", |
| 3546 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3547 | |
| 3548 | // frame type (ack frame) |
| 3549 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3550 | {"", |
| 3551 | { 0x65 }}, |
| 3552 | // largest acked |
| 3553 | {"Unable to read largest acked.", |
| 3554 | { 0x12, 0x34 }}, |
| 3555 | // Zero delta time. |
| 3556 | {"Unable to read ack delay time.", |
| 3557 | { 0x00, 0x00 }}, |
| 3558 | // num ack blocks ranges. |
| 3559 | {"Unable to read num of ack blocks.", |
| 3560 | { 0x01 }}, |
| 3561 | // first ack block length. |
| 3562 | {"Unable to read first ack block length.", |
| 3563 | { 0x00, 0x00 }}, |
| 3564 | // gap to next block. |
| 3565 | { "First block length is zero.", |
| 3566 | { 0x01 }}, |
| 3567 | // ack block length. |
| 3568 | { "First block length is zero.", |
| 3569 | { 0x0e, 0xaf }}, |
| 3570 | // Number of timestamps. |
| 3571 | { "First block length is zero.", |
| 3572 | { 0x00 }}, |
| 3573 | }; |
| 3574 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3575 | PacketFragments packet46 = { |
| 3576 | // type (short header, 4 byte packet number) |
| 3577 | {"", |
| 3578 | { 0x43 }}, |
| 3579 | // connection_id |
| 3580 | {"", |
| 3581 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3582 | // packet number |
| 3583 | {"", |
| 3584 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3585 | |
| 3586 | // frame type (ack frame) |
| 3587 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3588 | {"", |
| 3589 | { 0x65 }}, |
| 3590 | // largest acked |
| 3591 | {"Unable to read largest acked.", |
| 3592 | { 0x12, 0x34 }}, |
| 3593 | // Zero delta time. |
| 3594 | {"Unable to read ack delay time.", |
| 3595 | { 0x00, 0x00 }}, |
| 3596 | // num ack blocks ranges. |
| 3597 | {"Unable to read num of ack blocks.", |
| 3598 | { 0x01 }}, |
| 3599 | // first ack block length. |
| 3600 | {"Unable to read first ack block length.", |
| 3601 | { 0x00, 0x00 }}, |
| 3602 | // gap to next block. |
| 3603 | { "First block length is zero.", |
| 3604 | { 0x01 }}, |
| 3605 | // ack block length. |
| 3606 | { "First block length is zero.", |
| 3607 | { 0x0e, 0xaf }}, |
| 3608 | // Number of timestamps. |
| 3609 | { "First block length is zero.", |
| 3610 | { 0x00 }}, |
| 3611 | }; |
| 3612 | |
| 3613 | // clang-format on |
| 3614 | PacketFragments& fragments = |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 3615 | framer_.transport_version() >= QUIC_VERSION_46 ? packet46 : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3616 | |
| 3617 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3618 | AssemblePacketFromFragments(fragments)); |
| 3619 | |
| 3620 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 3621 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_ACK_DATA)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3622 | |
| 3623 | ASSERT_TRUE(visitor_.header_.get()); |
| 3624 | EXPECT_TRUE(CheckDecryption( |
| 3625 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3626 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3627 | |
| 3628 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3629 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3630 | |
| 3631 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3632 | } |
| 3633 | |
| 3634 | TEST_P(QuicFramerTest, AckFrameOneAckBlockMaxLength) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3635 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3636 | // clang-format off |
| 3637 | PacketFragments packet = { |
| 3638 | // public flags (8 byte connection_id) |
| 3639 | {"", |
| 3640 | {0x2C}}, |
| 3641 | // connection_id |
| 3642 | {"", |
| 3643 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3644 | // packet number |
| 3645 | {"", |
| 3646 | {0x12, 0x34, 0x56, 0x78}}, |
| 3647 | // frame type (ack frame) |
| 3648 | // (one ack block, 4 byte largest observed, 2 byte block length) |
| 3649 | {"", |
| 3650 | {0x49}}, |
| 3651 | // largest acked |
| 3652 | {"Unable to read largest acked.", |
| 3653 | {0x12, 0x34, 0x56, 0x78}}, |
| 3654 | // Zero delta time. |
| 3655 | {"Unable to read ack delay time.", |
| 3656 | {0x00, 0x00}}, |
| 3657 | // first ack block length. |
| 3658 | {"Unable to read first ack block length.", |
| 3659 | {0x12, 0x34}}, |
| 3660 | // num timestamps. |
| 3661 | {"Unable to read num received packets.", |
| 3662 | {0x00}} |
| 3663 | }; |
| 3664 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3665 | PacketFragments packet46 = { |
| 3666 | // type (short header, 4 byte packet number) |
| 3667 | {"", |
| 3668 | {0x43}}, |
| 3669 | // connection_id |
| 3670 | {"", |
| 3671 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3672 | // packet number |
| 3673 | {"", |
| 3674 | {0x56, 0x78, 0x9A, 0xBC}}, |
| 3675 | // frame type (ack frame) |
| 3676 | // (one ack block, 4 byte largest observed, 2 byte block length) |
| 3677 | {"", |
| 3678 | {0x49}}, |
| 3679 | // largest acked |
| 3680 | {"Unable to read largest acked.", |
| 3681 | {0x12, 0x34, 0x56, 0x78}}, |
| 3682 | // Zero delta time. |
| 3683 | {"Unable to read ack delay time.", |
| 3684 | {0x00, 0x00}}, |
| 3685 | // first ack block length. |
| 3686 | {"Unable to read first ack block length.", |
| 3687 | {0x12, 0x34}}, |
| 3688 | // num timestamps. |
| 3689 | {"Unable to read num received packets.", |
| 3690 | {0x00}} |
| 3691 | }; |
| 3692 | |
| 3693 | PacketFragments packet99 = { |
| 3694 | // type (short header, 4 byte packet number) |
| 3695 | {"", |
| 3696 | {0x43}}, |
| 3697 | // connection_id |
| 3698 | {"", |
| 3699 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3700 | // packet number |
| 3701 | {"", |
| 3702 | {0x56, 0x78, 0x9A, 0xBC}}, |
| 3703 | // frame type (IETF_ACK frame) |
| 3704 | {"", |
| 3705 | {0x02}}, |
| 3706 | // largest acked |
| 3707 | {"Unable to read largest acked.", |
| 3708 | {kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78}}, |
| 3709 | // Zero delta time. |
| 3710 | {"Unable to read ack delay time.", |
| 3711 | {kVarInt62OneByte + 0x00}}, |
| 3712 | // Number of ack blocks after first |
| 3713 | {"Unable to read ack block count.", |
| 3714 | {kVarInt62OneByte + 0x00}}, |
| 3715 | // first ack block length. |
| 3716 | {"Unable to read first ack block length.", |
| 3717 | {kVarInt62TwoBytes + 0x12, 0x33}} |
| 3718 | }; |
| 3719 | // clang-format on |
| 3720 | |
| 3721 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3722 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3723 | ? packet99 |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 3724 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 3725 | : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3726 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3727 | AssemblePacketFromFragments(fragments)); |
| 3728 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3729 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 3730 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3731 | ASSERT_TRUE(visitor_.header_.get()); |
| 3732 | EXPECT_TRUE(CheckDecryption( |
| 3733 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3734 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3735 | |
| 3736 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3737 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3738 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3739 | EXPECT_EQ(kPacketNumber, LargestAcked(frame)); |
| 3740 | ASSERT_EQ(4660u, frame.packets.NumPacketsSlow()); |
| 3741 | |
| 3742 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3743 | } |
| 3744 | |
| 3745 | // Tests ability to handle multiple ackblocks after the first ack |
| 3746 | // block. Non-version-99 tests include multiple timestamps as well. |
| 3747 | TEST_P(QuicFramerTest, AckFrameTwoTimeStampsMultipleAckBlocks) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3748 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3749 | // clang-format off |
| 3750 | PacketFragments packet = { |
| 3751 | // public flags (8 byte connection_id) |
| 3752 | {"", |
| 3753 | { 0x2C }}, |
| 3754 | // connection_id |
| 3755 | {"", |
| 3756 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3757 | // packet number |
| 3758 | {"", |
| 3759 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3760 | |
| 3761 | // frame type (ack frame) |
| 3762 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3763 | {"", |
| 3764 | { 0x65 }}, |
| 3765 | // largest acked |
| 3766 | {"Unable to read largest acked.", |
| 3767 | { 0x12, 0x34 }}, |
| 3768 | // Zero delta time. |
| 3769 | {"Unable to read ack delay time.", |
| 3770 | { 0x00, 0x00 }}, |
| 3771 | // num ack blocks ranges. |
| 3772 | {"Unable to read num of ack blocks.", |
| 3773 | { 0x04 }}, |
| 3774 | // first ack block length. |
| 3775 | {"Unable to read first ack block length.", |
| 3776 | { 0x00, 0x01 }}, |
| 3777 | // gap to next block. |
| 3778 | { "Unable to read gap to next ack block.", |
| 3779 | { 0x01 }}, |
| 3780 | // ack block length. |
| 3781 | { "Unable to ack block length.", |
| 3782 | { 0x0e, 0xaf }}, |
| 3783 | // gap to next block. |
| 3784 | { "Unable to read gap to next ack block.", |
| 3785 | { 0xff }}, |
| 3786 | // ack block length. |
| 3787 | { "Unable to ack block length.", |
| 3788 | { 0x00, 0x00 }}, |
| 3789 | // gap to next block. |
| 3790 | { "Unable to read gap to next ack block.", |
| 3791 | { 0x91 }}, |
| 3792 | // ack block length. |
| 3793 | { "Unable to ack block length.", |
| 3794 | { 0x01, 0xea }}, |
| 3795 | // gap to next block. |
| 3796 | { "Unable to read gap to next ack block.", |
| 3797 | { 0x05 }}, |
| 3798 | // ack block length. |
| 3799 | { "Unable to ack block length.", |
| 3800 | { 0x00, 0x04 }}, |
| 3801 | // Number of timestamps. |
| 3802 | { "Unable to read num received packets.", |
| 3803 | { 0x02 }}, |
| 3804 | // Delta from largest observed. |
| 3805 | { "Unable to read sequence delta in received packets.", |
| 3806 | { 0x01 }}, |
| 3807 | // Delta time. |
| 3808 | { "Unable to read time delta in received packets.", |
| 3809 | { 0x76, 0x54, 0x32, 0x10 }}, |
| 3810 | // Delta from largest observed. |
| 3811 | { "Unable to read sequence delta in received packets.", |
| 3812 | { 0x02 }}, |
| 3813 | // Delta time. |
| 3814 | { "Unable to read incremental time delta in received packets.", |
| 3815 | { 0x32, 0x10 }}, |
| 3816 | }; |
| 3817 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3818 | PacketFragments packet46 = { |
| 3819 | // type (short header, 4 byte packet number) |
| 3820 | {"", |
| 3821 | { 0x43 }}, |
| 3822 | // connection_id |
| 3823 | {"", |
| 3824 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3825 | // packet number |
| 3826 | {"", |
| 3827 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3828 | |
| 3829 | // frame type (ack frame) |
| 3830 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3831 | {"", |
| 3832 | { 0x65 }}, |
| 3833 | // largest acked |
| 3834 | {"Unable to read largest acked.", |
| 3835 | { 0x12, 0x34 }}, |
| 3836 | // Zero delta time. |
| 3837 | {"Unable to read ack delay time.", |
| 3838 | { 0x00, 0x00 }}, |
| 3839 | // num ack blocks ranges. |
| 3840 | {"Unable to read num of ack blocks.", |
| 3841 | { 0x04 }}, |
| 3842 | // first ack block length. |
| 3843 | {"Unable to read first ack block length.", |
| 3844 | { 0x00, 0x01 }}, |
| 3845 | // gap to next block. |
| 3846 | { "Unable to read gap to next ack block.", |
| 3847 | { 0x01 }}, |
| 3848 | // ack block length. |
| 3849 | { "Unable to ack block length.", |
| 3850 | { 0x0e, 0xaf }}, |
| 3851 | // gap to next block. |
| 3852 | { "Unable to read gap to next ack block.", |
| 3853 | { 0xff }}, |
| 3854 | // ack block length. |
| 3855 | { "Unable to ack block length.", |
| 3856 | { 0x00, 0x00 }}, |
| 3857 | // gap to next block. |
| 3858 | { "Unable to read gap to next ack block.", |
| 3859 | { 0x91 }}, |
| 3860 | // ack block length. |
| 3861 | { "Unable to ack block length.", |
| 3862 | { 0x01, 0xea }}, |
| 3863 | // gap to next block. |
| 3864 | { "Unable to read gap to next ack block.", |
| 3865 | { 0x05 }}, |
| 3866 | // ack block length. |
| 3867 | { "Unable to ack block length.", |
| 3868 | { 0x00, 0x04 }}, |
| 3869 | // Number of timestamps. |
| 3870 | { "Unable to read num received packets.", |
| 3871 | { 0x02 }}, |
| 3872 | // Delta from largest observed. |
| 3873 | { "Unable to read sequence delta in received packets.", |
| 3874 | { 0x01 }}, |
| 3875 | // Delta time. |
| 3876 | { "Unable to read time delta in received packets.", |
| 3877 | { 0x76, 0x54, 0x32, 0x10 }}, |
| 3878 | // Delta from largest observed. |
| 3879 | { "Unable to read sequence delta in received packets.", |
| 3880 | { 0x02 }}, |
| 3881 | // Delta time. |
| 3882 | { "Unable to read incremental time delta in received packets.", |
| 3883 | { 0x32, 0x10 }}, |
| 3884 | }; |
| 3885 | |
| 3886 | PacketFragments packet99 = { |
| 3887 | // type (short header, 4 byte packet number) |
| 3888 | {"", |
| 3889 | { 0x43 }}, |
| 3890 | // connection_id |
| 3891 | {"", |
| 3892 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3893 | // packet number |
| 3894 | {"", |
| 3895 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3896 | |
| 3897 | // frame type (IETF_ACK frame) |
| 3898 | {"", |
| 3899 | { 0x02 }}, |
| 3900 | // largest acked |
| 3901 | {"Unable to read largest acked.", |
| 3902 | { kVarInt62TwoBytes + 0x12, 0x34 }}, // = 4660 |
| 3903 | // Zero delta time. |
| 3904 | {"Unable to read ack delay time.", |
| 3905 | { kVarInt62OneByte + 0x00 }}, |
| 3906 | // number of additional ack blocks |
| 3907 | {"Unable to read ack block count.", |
| 3908 | { kVarInt62OneByte + 0x03 }}, |
| 3909 | // first ack block length. |
| 3910 | {"Unable to read first ack block length.", |
| 3911 | { kVarInt62OneByte + 0x00 }}, // 1st block length = 1 |
| 3912 | |
| 3913 | // Additional ACK Block #1 |
| 3914 | // gap to next block. |
| 3915 | { "Unable to read gap block value.", |
| 3916 | { kVarInt62OneByte + 0x00 }}, // gap of 1 packet |
| 3917 | // ack block length. |
| 3918 | { "Unable to read ack block value.", |
| 3919 | { kVarInt62TwoBytes + 0x0e, 0xae }}, // 3759 |
| 3920 | |
| 3921 | // pre-version-99 test includes an ack block of 0 length. this |
| 3922 | // can not happen in version 99. ergo the second block is not |
| 3923 | // present in the v99 test and the gap length of the next block |
| 3924 | // is the sum of the two gaps in the pre-version-99 tests. |
| 3925 | // Additional ACK Block #2 |
| 3926 | // gap to next block. |
| 3927 | { "Unable to read gap block value.", |
| 3928 | { kVarInt62TwoBytes + 0x01, 0x8f }}, // Gap is 400 (0x190) pkts |
| 3929 | // ack block length. |
| 3930 | { "Unable to read ack block value.", |
| 3931 | { kVarInt62TwoBytes + 0x01, 0xe9 }}, // block is 389 (x1ea) pkts |
| 3932 | |
| 3933 | // Additional ACK Block #3 |
| 3934 | // gap to next block. |
| 3935 | { "Unable to read gap block value.", |
| 3936 | { kVarInt62OneByte + 0x04 }}, // Gap is 5 packets. |
| 3937 | // ack block length. |
| 3938 | { "Unable to read ack block value.", |
| 3939 | { kVarInt62OneByte + 0x03 }}, // block is 3 packets. |
| 3940 | }; |
| 3941 | |
| 3942 | // clang-format on |
| 3943 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3944 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3945 | ? packet99 |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 3946 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 3947 | : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3948 | |
| 3949 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3950 | AssemblePacketFromFragments(fragments)); |
| 3951 | |
| 3952 | framer_.set_process_timestamps(true); |
| 3953 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3954 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 3955 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3956 | ASSERT_TRUE(visitor_.header_.get()); |
| 3957 | EXPECT_TRUE(CheckDecryption( |
| 3958 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3959 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3960 | |
| 3961 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3962 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3963 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3964 | EXPECT_EQ(kSmallLargestObserved, LargestAcked(frame)); |
| 3965 | ASSERT_EQ(4254u, frame.packets.NumPacketsSlow()); |
| 3966 | EXPECT_EQ(4u, frame.packets.NumIntervals()); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3967 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3968 | EXPECT_EQ(0u, frame.received_packet_times.size()); |
| 3969 | } else { |
| 3970 | EXPECT_EQ(2u, frame.received_packet_times.size()); |
| 3971 | } |
| 3972 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3973 | } |
| 3974 | |
| 3975 | TEST_P(QuicFramerTest, AckFrameTimeStampDeltaTooHigh) { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 3976 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3977 | // clang-format off |
| 3978 | unsigned char packet[] = { |
| 3979 | // public flags (8 byte connection_id) |
| 3980 | 0x28, |
| 3981 | // connection_id |
| 3982 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3983 | // packet number |
| 3984 | 0x12, 0x34, 0x56, 0x78, |
| 3985 | |
| 3986 | // frame type (ack frame) |
| 3987 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 3988 | 0x40, |
| 3989 | // largest acked |
| 3990 | 0x01, |
| 3991 | // Zero delta time. |
| 3992 | 0x00, 0x00, |
| 3993 | // first ack block length. |
| 3994 | 0x01, |
| 3995 | // num timestamps. |
| 3996 | 0x01, |
| 3997 | // Delta from largest observed. |
| 3998 | 0x01, |
| 3999 | // Delta time. |
| 4000 | 0x10, 0x32, 0x54, 0x76, |
| 4001 | }; |
| 4002 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4003 | unsigned char packet46[] = { |
| 4004 | // type (short header, 4 byte packet number) |
| 4005 | 0x43, |
| 4006 | // connection_id |
| 4007 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4008 | // packet number |
| 4009 | 0x12, 0x34, 0x56, 0x78, |
| 4010 | |
| 4011 | // frame type (ack frame) |
| 4012 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 4013 | 0x40, |
| 4014 | // largest acked |
| 4015 | 0x01, |
| 4016 | // Zero delta time. |
| 4017 | 0x00, 0x00, |
| 4018 | // first ack block length. |
| 4019 | 0x01, |
| 4020 | // num timestamps. |
| 4021 | 0x01, |
| 4022 | // Delta from largest observed. |
| 4023 | 0x01, |
| 4024 | // Delta time. |
| 4025 | 0x10, 0x32, 0x54, 0x76, |
| 4026 | }; |
| 4027 | // clang-format on |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4028 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 4029 | // ACK Timestamp is not a feature of IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4030 | return; |
| 4031 | } |
| 4032 | QuicEncryptedPacket encrypted( |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 4033 | AsChars(framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 4034 | : packet), |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 4035 | QUICHE_ARRAYSIZE(packet), false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4036 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 4037 | EXPECT_TRUE(quiche::QuicheTextUtils::StartsWith( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4038 | framer_.detailed_error(), "delta_from_largest_observed too high")); |
| 4039 | } |
| 4040 | |
| 4041 | TEST_P(QuicFramerTest, AckFrameTimeStampSecondDeltaTooHigh) { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4042 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4043 | // clang-format off |
| 4044 | unsigned char packet[] = { |
| 4045 | // public flags (8 byte connection_id) |
| 4046 | 0x28, |
| 4047 | // connection_id |
| 4048 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4049 | // packet number |
| 4050 | 0x12, 0x34, 0x56, 0x78, |
| 4051 | |
| 4052 | // frame type (ack frame) |
| 4053 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 4054 | 0x40, |
| 4055 | // largest acked |
| 4056 | 0x03, |
| 4057 | // Zero delta time. |
| 4058 | 0x00, 0x00, |
| 4059 | // first ack block length. |
| 4060 | 0x03, |
| 4061 | // num timestamps. |
| 4062 | 0x02, |
| 4063 | // Delta from largest observed. |
| 4064 | 0x01, |
| 4065 | // Delta time. |
| 4066 | 0x10, 0x32, 0x54, 0x76, |
| 4067 | // Delta from largest observed. |
| 4068 | 0x03, |
| 4069 | // Delta time. |
| 4070 | 0x10, 0x32, |
| 4071 | }; |
| 4072 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4073 | unsigned char packet46[] = { |
| 4074 | // type (short header, 4 byte packet number) |
| 4075 | 0x43, |
| 4076 | // connection_id |
| 4077 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4078 | // packet number |
| 4079 | 0x12, 0x34, 0x56, 0x78, |
| 4080 | |
| 4081 | // frame type (ack frame) |
| 4082 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 4083 | 0x40, |
| 4084 | // largest acked |
| 4085 | 0x03, |
| 4086 | // Zero delta time. |
| 4087 | 0x00, 0x00, |
| 4088 | // first ack block length. |
| 4089 | 0x03, |
| 4090 | // num timestamps. |
| 4091 | 0x02, |
| 4092 | // Delta from largest observed. |
| 4093 | 0x01, |
| 4094 | // Delta time. |
| 4095 | 0x10, 0x32, 0x54, 0x76, |
| 4096 | // Delta from largest observed. |
| 4097 | 0x03, |
| 4098 | // Delta time. |
| 4099 | 0x10, 0x32, |
| 4100 | }; |
| 4101 | // clang-format on |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4102 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 4103 | // ACK Timestamp is not a feature of IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4104 | return; |
| 4105 | } |
| 4106 | QuicEncryptedPacket encrypted( |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 4107 | AsChars(framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 4108 | : packet), |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 4109 | QUICHE_ARRAYSIZE(packet), false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4110 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 4111 | EXPECT_TRUE(quiche::QuicheTextUtils::StartsWith( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4112 | framer_.detailed_error(), "delta_from_largest_observed too high")); |
| 4113 | } |
| 4114 | |
| 4115 | TEST_P(QuicFramerTest, NewStopWaitingFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4116 | if (VersionHasIetfQuicFrames(version_.transport_version)) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 4117 | // The Stop Waiting frame is not in IETF QUIC |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4118 | return; |
| 4119 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4120 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4121 | // clang-format off |
| 4122 | PacketFragments packet = { |
| 4123 | // public flags (8 byte connection_id) |
| 4124 | {"", |
| 4125 | {0x2C}}, |
| 4126 | // connection_id |
| 4127 | {"", |
| 4128 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4129 | // packet number |
| 4130 | {"", |
| 4131 | {0x12, 0x34, 0x56, 0x78}}, |
| 4132 | // frame type (stop waiting frame) |
| 4133 | {"", |
| 4134 | {0x06}}, |
| 4135 | // least packet number awaiting an ack, delta from packet number. |
| 4136 | {"Unable to read least unacked delta.", |
| 4137 | {0x00, 0x00, 0x00, 0x08}} |
| 4138 | }; |
| 4139 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4140 | PacketFragments packet46 = { |
| 4141 | // type (short header, 4 byte packet number) |
| 4142 | {"", |
| 4143 | {0x43}}, |
| 4144 | // connection_id |
| 4145 | {"", |
| 4146 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4147 | // packet number |
| 4148 | {"", |
| 4149 | {0x12, 0x34, 0x56, 0x78}}, |
| 4150 | // frame type (stop waiting frame) |
| 4151 | {"", |
| 4152 | {0x06}}, |
| 4153 | // least packet number awaiting an ack, delta from packet number. |
| 4154 | {"Unable to read least unacked delta.", |
| 4155 | {0x00, 0x00, 0x00, 0x08}} |
| 4156 | }; |
| 4157 | // clang-format on |
| 4158 | |
| 4159 | PacketFragments& fragments = |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 4160 | framer_.transport_version() >= QUIC_VERSION_46 ? packet46 : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4161 | |
| 4162 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4163 | AssemblePacketFromFragments(fragments)); |
ianswett | 97b690b | 2019-05-02 15:12:43 -0700 | [diff] [blame] | 4164 | if (GetQuicReloadableFlag(quic_do_not_accept_stop_waiting) && |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 4165 | version_.transport_version >= QUIC_VERSION_46) { |
ianswett | 97b690b | 2019-05-02 15:12:43 -0700 | [diff] [blame] | 4166 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4167 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_STOP_WAITING_DATA)); |
ianswett | 97b690b | 2019-05-02 15:12:43 -0700 | [diff] [blame] | 4168 | EXPECT_EQ("STOP WAITING not supported in version 44+.", |
| 4169 | framer_.detailed_error()); |
| 4170 | return; |
| 4171 | } |
| 4172 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4173 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4174 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4175 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4176 | ASSERT_TRUE(visitor_.header_.get()); |
| 4177 | EXPECT_TRUE(CheckDecryption( |
| 4178 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4179 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4180 | |
| 4181 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 4182 | ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size()); |
| 4183 | const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0]; |
| 4184 | EXPECT_EQ(kLeastUnacked, frame.least_unacked); |
| 4185 | |
| 4186 | CheckFramingBoundaries(fragments, QUIC_INVALID_STOP_WAITING_DATA); |
| 4187 | } |
| 4188 | |
| 4189 | TEST_P(QuicFramerTest, InvalidNewStopWaitingFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 4190 | // The Stop Waiting frame is not in IETF QUIC |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4191 | if (VersionHasIetfQuicFrames(version_.transport_version) || |
ianswett | 97b690b | 2019-05-02 15:12:43 -0700 | [diff] [blame] | 4192 | (GetQuicReloadableFlag(quic_do_not_accept_stop_waiting) && |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 4193 | version_.transport_version >= QUIC_VERSION_46)) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4194 | return; |
| 4195 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4196 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4197 | // clang-format off |
| 4198 | unsigned char packet[] = { |
| 4199 | // public flags (8 byte connection_id) |
| 4200 | 0x2C, |
| 4201 | // connection_id |
| 4202 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4203 | // packet number |
| 4204 | 0x12, 0x34, 0x56, 0x78, |
| 4205 | // frame type (stop waiting frame) |
| 4206 | 0x06, |
| 4207 | // least packet number awaiting an ack, delta from packet number. |
| 4208 | 0x13, 0x34, 0x56, 0x78, |
| 4209 | 0x9A, 0xA8, |
| 4210 | }; |
| 4211 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4212 | unsigned char packet46[] = { |
| 4213 | // type (short header, 4 byte packet number) |
| 4214 | 0x43, |
| 4215 | // connection_id |
| 4216 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4217 | // packet number |
| 4218 | 0x12, 0x34, 0x56, 0x78, |
| 4219 | // frame type (stop waiting frame) |
| 4220 | 0x06, |
| 4221 | // least packet number awaiting an ack, delta from packet number. |
| 4222 | 0x57, 0x78, 0x9A, 0xA8, |
| 4223 | }; |
| 4224 | // clang-format on |
| 4225 | |
| 4226 | QuicEncryptedPacket encrypted( |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 4227 | AsChars(framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 4228 | : packet), |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 4229 | framer_.transport_version() > QUIC_VERSION_43 ? QUICHE_ARRAYSIZE(packet46) |
| 4230 | : QUICHE_ARRAYSIZE(packet), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4231 | false); |
| 4232 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4233 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_STOP_WAITING_DATA)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4234 | EXPECT_EQ("Invalid unacked delta.", framer_.detailed_error()); |
| 4235 | } |
| 4236 | |
| 4237 | TEST_P(QuicFramerTest, RstStreamFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4238 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4239 | // clang-format off |
| 4240 | PacketFragments packet = { |
| 4241 | // public flags (8 byte connection_id) |
| 4242 | {"", |
| 4243 | {0x28}}, |
| 4244 | // connection_id |
| 4245 | {"", |
| 4246 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4247 | // packet number |
| 4248 | {"", |
| 4249 | {0x12, 0x34, 0x56, 0x78}}, |
| 4250 | // frame type (rst stream frame) |
| 4251 | {"", |
| 4252 | {0x01}}, |
| 4253 | // stream id |
| 4254 | {"Unable to read stream_id.", |
| 4255 | {0x01, 0x02, 0x03, 0x04}}, |
| 4256 | // sent byte offset |
| 4257 | {"Unable to read rst stream sent byte offset.", |
| 4258 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4259 | 0x32, 0x10, 0x76, 0x54}}, |
| 4260 | // error code |
| 4261 | {"Unable to read rst stream error code.", |
| 4262 | {0x00, 0x00, 0x00, 0x01}} |
| 4263 | }; |
| 4264 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4265 | PacketFragments packet46 = { |
| 4266 | // type (short header, 4 byte packet number) |
| 4267 | {"", |
| 4268 | {0x43}}, |
| 4269 | // connection_id |
| 4270 | {"", |
| 4271 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4272 | // packet number |
| 4273 | {"", |
| 4274 | {0x12, 0x34, 0x56, 0x78}}, |
| 4275 | // frame type (rst stream frame) |
| 4276 | {"", |
| 4277 | {0x01}}, |
| 4278 | // stream id |
| 4279 | {"Unable to read stream_id.", |
| 4280 | {0x01, 0x02, 0x03, 0x04}}, |
| 4281 | // sent byte offset |
| 4282 | {"Unable to read rst stream sent byte offset.", |
| 4283 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4284 | 0x32, 0x10, 0x76, 0x54}}, |
| 4285 | // error code |
| 4286 | {"Unable to read rst stream error code.", |
| 4287 | {0x00, 0x00, 0x00, 0x01}} |
| 4288 | }; |
| 4289 | |
| 4290 | PacketFragments packet99 = { |
| 4291 | // type (short header, 4 byte packet number) |
| 4292 | {"", |
| 4293 | {0x43}}, |
| 4294 | // connection_id |
| 4295 | {"", |
| 4296 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4297 | // packet number |
| 4298 | {"", |
| 4299 | {0x12, 0x34, 0x56, 0x78}}, |
| 4300 | // frame type (IETF_RST_STREAM frame) |
| 4301 | {"", |
| 4302 | {0x04}}, |
| 4303 | // stream id |
| 4304 | {"Unable to read rst stream stream id.", |
| 4305 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 4306 | // application error code |
| 4307 | {"Unable to read rst stream error code.", |
fkastenholz | 07300e5 | 2019-07-16 11:51:37 -0700 | [diff] [blame] | 4308 | {kVarInt62OneByte + 0x01}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4309 | // Final Offset |
| 4310 | {"Unable to read rst stream sent byte offset.", |
| 4311 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}} |
| 4312 | }; |
| 4313 | // clang-format on |
| 4314 | |
| 4315 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4316 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4317 | ? packet99 |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 4318 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 4319 | : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4320 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4321 | AssemblePacketFromFragments(fragments)); |
| 4322 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4323 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4324 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4325 | ASSERT_TRUE(visitor_.header_.get()); |
| 4326 | EXPECT_TRUE(CheckDecryption( |
| 4327 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4328 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4329 | |
| 4330 | EXPECT_EQ(kStreamId, visitor_.rst_stream_frame_.stream_id); |
| 4331 | EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code); |
| 4332 | EXPECT_EQ(kStreamOffset, visitor_.rst_stream_frame_.byte_offset); |
| 4333 | CheckFramingBoundaries(fragments, QUIC_INVALID_RST_STREAM_DATA); |
| 4334 | } |
| 4335 | |
| 4336 | TEST_P(QuicFramerTest, ConnectionCloseFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4337 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4338 | // clang-format off |
| 4339 | PacketFragments packet = { |
| 4340 | // public flags (8 byte connection_id) |
| 4341 | {"", |
| 4342 | {0x28}}, |
| 4343 | // connection_id |
| 4344 | {"", |
| 4345 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4346 | // packet number |
| 4347 | {"", |
| 4348 | {0x12, 0x34, 0x56, 0x78}}, |
| 4349 | // frame type (connection close frame) |
| 4350 | {"", |
| 4351 | {0x02}}, |
| 4352 | // error code |
| 4353 | {"Unable to read connection close error code.", |
| 4354 | {0x00, 0x00, 0x00, 0x11}}, |
| 4355 | {"Unable to read connection close error details.", |
| 4356 | { |
| 4357 | // error details length |
| 4358 | 0x0, 0x0d, |
| 4359 | // error details |
| 4360 | 'b', 'e', 'c', 'a', |
| 4361 | 'u', 's', 'e', ' ', |
| 4362 | 'I', ' ', 'c', 'a', |
| 4363 | 'n'} |
| 4364 | } |
| 4365 | }; |
| 4366 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4367 | PacketFragments packet46 = { |
| 4368 | // type (short header, 4 byte packet number) |
| 4369 | {"", |
| 4370 | {0x43}}, |
| 4371 | // connection_id |
| 4372 | {"", |
| 4373 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4374 | // packet number |
| 4375 | {"", |
| 4376 | {0x12, 0x34, 0x56, 0x78}}, |
| 4377 | // frame type (connection close frame) |
| 4378 | {"", |
| 4379 | {0x02}}, |
| 4380 | // error code |
| 4381 | {"Unable to read connection close error code.", |
| 4382 | {0x00, 0x00, 0x00, 0x11}}, |
| 4383 | {"Unable to read connection close error details.", |
| 4384 | { |
| 4385 | // error details length |
| 4386 | 0x0, 0x0d, |
| 4387 | // error details |
| 4388 | 'b', 'e', 'c', 'a', |
| 4389 | 'u', 's', 'e', ' ', |
| 4390 | 'I', ' ', 'c', 'a', |
| 4391 | 'n'} |
| 4392 | } |
| 4393 | }; |
| 4394 | |
| 4395 | PacketFragments packet99 = { |
| 4396 | // type (short header, 4 byte packet number) |
| 4397 | {"", |
| 4398 | {0x43}}, |
| 4399 | // connection_id |
| 4400 | {"", |
| 4401 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4402 | // packet number |
| 4403 | {"", |
| 4404 | {0x12, 0x34, 0x56, 0x78}}, |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4405 | // frame type (IETF Transport CONNECTION_CLOSE frame) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4406 | {"", |
| 4407 | {0x1c}}, |
| 4408 | // error code |
| 4409 | {"Unable to read connection close error code.", |
fkastenholz | d57d3f9 | 2019-07-16 09:05:17 -0700 | [diff] [blame] | 4410 | {kVarInt62TwoBytes + 0x00, 0x11}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4411 | {"Unable to read connection close frame type.", |
| 4412 | {kVarInt62TwoBytes + 0x12, 0x34 }}, |
| 4413 | {"Unable to read connection close error details.", |
| 4414 | { |
| 4415 | // error details length |
| 4416 | kVarInt62OneByte + 0x0d, |
| 4417 | // error details |
| 4418 | 'b', 'e', 'c', 'a', |
| 4419 | 'u', 's', 'e', ' ', |
| 4420 | 'I', ' ', 'c', 'a', |
| 4421 | 'n'} |
| 4422 | } |
| 4423 | }; |
| 4424 | // clang-format on |
| 4425 | |
| 4426 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4427 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4428 | ? packet99 |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 4429 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 4430 | : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4431 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4432 | AssemblePacketFromFragments(fragments)); |
| 4433 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4434 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4435 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4436 | ASSERT_TRUE(visitor_.header_.get()); |
| 4437 | EXPECT_TRUE(CheckDecryption( |
| 4438 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4439 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4440 | |
| 4441 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
zhongyi | ba6354a | 2019-04-10 16:49:25 -0700 | [diff] [blame] | 4442 | EXPECT_EQ(0x11u, static_cast<unsigned>( |
| 4443 | visitor_.connection_close_frame_.quic_error_code)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4444 | EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4445 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 4446 | EXPECT_EQ(0x1234u, |
| 4447 | visitor_.connection_close_frame_.transport_close_frame_type); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4448 | EXPECT_THAT(visitor_.connection_close_frame_.extracted_error_code, |
| 4449 | IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); |
fkastenholz | a14a7ae | 2019-08-07 05:21:22 -0700 | [diff] [blame] | 4450 | } else { |
| 4451 | // For Google QUIC closes, the error code is copied into |
| 4452 | // extracted_error_code. |
| 4453 | EXPECT_EQ(0x11u, |
| 4454 | static_cast<unsigned>( |
| 4455 | visitor_.connection_close_frame_.extracted_error_code)); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4456 | } |
| 4457 | |
| 4458 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 4459 | |
| 4460 | CheckFramingBoundaries(fragments, QUIC_INVALID_CONNECTION_CLOSE_DATA); |
| 4461 | } |
| 4462 | |
| 4463 | // As above, but checks that for Google-QUIC, if there happens |
| 4464 | // to be an ErrorCode string at the start of the details, it is |
| 4465 | // NOT extracted/parsed/folded/spindled/and/mutilated. |
| 4466 | TEST_P(QuicFramerTest, ConnectionCloseFrameWithExtractedInfoIgnoreGCuic) { |
| 4467 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 4468 | |
| 4469 | // clang-format off |
| 4470 | PacketFragments packet = { |
| 4471 | // public flags (8 byte connection_id) |
| 4472 | {"", |
| 4473 | {0x28}}, |
| 4474 | // connection_id |
| 4475 | {"", |
| 4476 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4477 | // packet number |
| 4478 | {"", |
| 4479 | {0x12, 0x34, 0x56, 0x78}}, |
| 4480 | // frame type (connection close frame) |
| 4481 | {"", |
| 4482 | {0x02}}, |
| 4483 | // error code |
| 4484 | {"Unable to read connection close error code.", |
| 4485 | {0x00, 0x00, 0x00, 0x11}}, |
| 4486 | {"Unable to read connection close error details.", |
| 4487 | { |
| 4488 | // error details length |
| 4489 | 0x0, 0x13, |
| 4490 | // error details |
| 4491 | '1', '7', '7', '6', |
| 4492 | '7', ':', 'b', 'e', |
| 4493 | 'c', 'a', 'u', 's', |
| 4494 | 'e', ' ', 'I', ' ', |
| 4495 | 'c', 'a', 'n'} |
| 4496 | } |
| 4497 | }; |
| 4498 | |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4499 | PacketFragments packet46 = { |
| 4500 | // type (short header, 4 byte packet number) |
| 4501 | {"", |
| 4502 | {0x43}}, |
| 4503 | // connection_id |
| 4504 | {"", |
| 4505 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4506 | // packet number |
| 4507 | {"", |
| 4508 | {0x12, 0x34, 0x56, 0x78}}, |
| 4509 | // frame type (connection close frame) |
| 4510 | {"", |
| 4511 | {0x02}}, |
| 4512 | // error code |
| 4513 | {"Unable to read connection close error code.", |
| 4514 | {0x00, 0x00, 0x00, 0x11}}, |
| 4515 | {"Unable to read connection close error details.", |
| 4516 | { |
| 4517 | // error details length |
| 4518 | 0x0, 0x13, |
| 4519 | // error details |
| 4520 | '1', '7', '7', '6', |
| 4521 | '7', ':', 'b', 'e', |
| 4522 | 'c', 'a', 'u', 's', |
| 4523 | 'e', ' ', 'I', ' ', |
| 4524 | 'c', 'a', 'n'} |
| 4525 | } |
| 4526 | }; |
| 4527 | |
| 4528 | PacketFragments packet99 = { |
| 4529 | // type (short header, 4 byte packet number) |
| 4530 | {"", |
| 4531 | {0x43}}, |
| 4532 | // connection_id |
| 4533 | {"", |
| 4534 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4535 | // packet number |
| 4536 | {"", |
| 4537 | {0x12, 0x34, 0x56, 0x78}}, |
| 4538 | // frame type (IETF Transport CONNECTION_CLOSE frame) |
| 4539 | {"", |
| 4540 | {0x1c}}, |
| 4541 | // error code |
| 4542 | {"Unable to read connection close error code.", |
| 4543 | {kVarInt62OneByte + 0x11}}, |
| 4544 | {"Unable to read connection close frame type.", |
| 4545 | {kVarInt62TwoBytes + 0x12, 0x34 }}, |
| 4546 | {"Unable to read connection close error details.", |
| 4547 | { |
| 4548 | // error details length |
| 4549 | kVarInt62OneByte + 0x13, |
| 4550 | // error details |
| 4551 | '1', '7', '7', '6', |
| 4552 | '7', ':', 'b', 'e', |
| 4553 | 'c', 'a', 'u', 's', |
| 4554 | 'e', ' ', 'I', ' ', |
| 4555 | 'c', 'a', 'n'} |
| 4556 | } |
| 4557 | }; |
| 4558 | // clang-format on |
| 4559 | |
| 4560 | PacketFragments& fragments = |
| 4561 | VersionHasIetfQuicFrames(framer_.transport_version()) |
| 4562 | ? packet99 |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 4563 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 4564 | : packet); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4565 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4566 | AssemblePacketFromFragments(fragments)); |
| 4567 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4568 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4569 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4570 | ASSERT_TRUE(visitor_.header_.get()); |
| 4571 | EXPECT_TRUE(CheckDecryption( |
| 4572 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4573 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4574 | |
| 4575 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 4576 | EXPECT_EQ(0x11u, static_cast<unsigned>( |
| 4577 | visitor_.connection_close_frame_.quic_error_code)); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 4578 | |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4579 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 4580 | EXPECT_EQ(0x1234u, |
| 4581 | visitor_.connection_close_frame_.transport_close_frame_type); |
| 4582 | EXPECT_EQ(17767u, visitor_.connection_close_frame_.extracted_error_code); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 4583 | EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4584 | } else { |
fkastenholz | a14a7ae | 2019-08-07 05:21:22 -0700 | [diff] [blame] | 4585 | EXPECT_EQ(0x11u, visitor_.connection_close_frame_.extracted_error_code); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 4586 | // Error code is not prepended in GQUIC, so it is not removed and should |
| 4587 | // remain in the reason phrase. |
| 4588 | EXPECT_EQ("17767:because I can", |
| 4589 | visitor_.connection_close_frame_.error_details); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4590 | } |
| 4591 | |
| 4592 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 4593 | |
| 4594 | CheckFramingBoundaries(fragments, QUIC_INVALID_CONNECTION_CLOSE_DATA); |
| 4595 | } |
| 4596 | |
fkastenholz | 04bd4f3 | 2019-04-16 12:24:38 -0700 | [diff] [blame] | 4597 | // Test the CONNECTION_CLOSE/Application variant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4598 | TEST_P(QuicFramerTest, ApplicationCloseFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4599 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 4600 | // This frame is only in IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4601 | return; |
| 4602 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4603 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4604 | |
| 4605 | // clang-format off |
| 4606 | PacketFragments packet99 = { |
| 4607 | // type (short header, 4 byte packet number) |
| 4608 | {"", |
| 4609 | {0x43}}, |
| 4610 | // connection_id |
| 4611 | {"", |
| 4612 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4613 | // packet number |
| 4614 | {"", |
| 4615 | {0x12, 0x34, 0x56, 0x78}}, |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4616 | // frame type (IETF_CONNECTION_CLOSE/Application frame) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4617 | {"", |
| 4618 | {0x1d}}, |
| 4619 | // error code |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4620 | {"Unable to read connection close error code.", |
fkastenholz | d57d3f9 | 2019-07-16 09:05:17 -0700 | [diff] [blame] | 4621 | {kVarInt62TwoBytes + 0x00, 0x11}}, |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4622 | {"Unable to read connection close error details.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4623 | { |
| 4624 | // error details length |
| 4625 | kVarInt62OneByte + 0x0d, |
| 4626 | // error details |
| 4627 | 'b', 'e', 'c', 'a', |
| 4628 | 'u', 's', 'e', ' ', |
| 4629 | 'I', ' ', 'c', 'a', |
| 4630 | 'n'} |
| 4631 | } |
| 4632 | }; |
| 4633 | // clang-format on |
| 4634 | |
| 4635 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4636 | AssemblePacketFromFragments(packet99)); |
| 4637 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4638 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4639 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4640 | ASSERT_TRUE(visitor_.header_.get()); |
| 4641 | EXPECT_TRUE(CheckDecryption( |
| 4642 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4643 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4644 | |
| 4645 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 4646 | |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4647 | EXPECT_EQ(IETF_QUIC_APPLICATION_CONNECTION_CLOSE, |
| 4648 | visitor_.connection_close_frame_.close_type); |
| 4649 | EXPECT_EQ(122u, visitor_.connection_close_frame_.extracted_error_code); |
fkastenholz | 88d08f4 | 2019-09-06 07:38:04 -0700 | [diff] [blame] | 4650 | EXPECT_EQ(0x11u, visitor_.connection_close_frame_.quic_error_code); |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4651 | EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4652 | |
| 4653 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 4654 | |
fkastenholz | 04bd4f3 | 2019-04-16 12:24:38 -0700 | [diff] [blame] | 4655 | CheckFramingBoundaries(packet99, QUIC_INVALID_CONNECTION_CLOSE_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4656 | } |
| 4657 | |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4658 | // Check that we can extract an error code from an application close. |
| 4659 | TEST_P(QuicFramerTest, ApplicationCloseFrameExtract) { |
| 4660 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 4661 | // This frame is only in IETF QUIC. |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4662 | return; |
| 4663 | } |
| 4664 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 4665 | |
| 4666 | // clang-format off |
| 4667 | PacketFragments packet99 = { |
| 4668 | // type (short header, 4 byte packet number) |
| 4669 | {"", |
| 4670 | {0x43}}, |
| 4671 | // connection_id |
| 4672 | {"", |
| 4673 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4674 | // packet number |
| 4675 | {"", |
| 4676 | {0x12, 0x34, 0x56, 0x78}}, |
| 4677 | // frame type (IETF_CONNECTION_CLOSE/Application frame) |
| 4678 | {"", |
| 4679 | {0x1d}}, |
| 4680 | // error code |
| 4681 | {"Unable to read connection close error code.", |
| 4682 | {kVarInt62OneByte + 0x11}}, |
| 4683 | {"Unable to read connection close error details.", |
| 4684 | { |
| 4685 | // error details length |
| 4686 | kVarInt62OneByte + 0x13, |
| 4687 | // error details |
| 4688 | '1', '7', '7', '6', |
| 4689 | '7', ':', 'b', 'e', |
| 4690 | 'c', 'a', 'u', 's', |
| 4691 | 'e', ' ', 'I', ' ', |
| 4692 | 'c', 'a', 'n'} |
| 4693 | } |
| 4694 | }; |
| 4695 | // clang-format on |
| 4696 | |
| 4697 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4698 | AssemblePacketFromFragments(packet99)); |
| 4699 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4700 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4701 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4702 | ASSERT_TRUE(visitor_.header_.get()); |
| 4703 | EXPECT_TRUE(CheckDecryption( |
| 4704 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4705 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4706 | |
| 4707 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 4708 | |
| 4709 | EXPECT_EQ(IETF_QUIC_APPLICATION_CONNECTION_CLOSE, |
| 4710 | visitor_.connection_close_frame_.close_type); |
| 4711 | EXPECT_EQ(17767u, visitor_.connection_close_frame_.extracted_error_code); |
| 4712 | EXPECT_EQ(0x11u, visitor_.connection_close_frame_.quic_error_code); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 4713 | EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4714 | |
| 4715 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 4716 | |
| 4717 | CheckFramingBoundaries(packet99, QUIC_INVALID_CONNECTION_CLOSE_DATA); |
| 4718 | } |
| 4719 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4720 | TEST_P(QuicFramerTest, GoAwayFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4721 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 4722 | // This frame is not in IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4723 | return; |
| 4724 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4725 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4726 | // clang-format off |
| 4727 | PacketFragments packet = { |
| 4728 | // public flags (8 byte connection_id) |
| 4729 | {"", |
| 4730 | {0x28}}, |
| 4731 | // connection_id |
| 4732 | {"", |
| 4733 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4734 | // packet number |
| 4735 | {"", |
| 4736 | {0x12, 0x34, 0x56, 0x78}}, |
| 4737 | // frame type (go away frame) |
| 4738 | {"", |
| 4739 | {0x03}}, |
| 4740 | // error code |
| 4741 | {"Unable to read go away error code.", |
| 4742 | {0x00, 0x00, 0x00, 0x09}}, |
| 4743 | // stream id |
| 4744 | {"Unable to read last good stream id.", |
| 4745 | {0x01, 0x02, 0x03, 0x04}}, |
| 4746 | // stream id |
| 4747 | {"Unable to read goaway reason.", |
| 4748 | { |
| 4749 | // error details length |
| 4750 | 0x0, 0x0d, |
| 4751 | // error details |
| 4752 | 'b', 'e', 'c', 'a', |
| 4753 | 'u', 's', 'e', ' ', |
| 4754 | 'I', ' ', 'c', 'a', |
| 4755 | 'n'} |
| 4756 | } |
| 4757 | }; |
| 4758 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4759 | PacketFragments packet46 = { |
| 4760 | // type (short header, 4 byte packet number) |
| 4761 | {"", |
| 4762 | {0x43}}, |
| 4763 | // connection_id |
| 4764 | {"", |
| 4765 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4766 | // packet number |
| 4767 | {"", |
| 4768 | {0x12, 0x34, 0x56, 0x78}}, |
| 4769 | // frame type (go away frame) |
| 4770 | {"", |
| 4771 | {0x03}}, |
| 4772 | // error code |
| 4773 | {"Unable to read go away error code.", |
| 4774 | {0x00, 0x00, 0x00, 0x09}}, |
| 4775 | // stream id |
| 4776 | {"Unable to read last good stream id.", |
| 4777 | {0x01, 0x02, 0x03, 0x04}}, |
| 4778 | // stream id |
| 4779 | {"Unable to read goaway reason.", |
| 4780 | { |
| 4781 | // error details length |
| 4782 | 0x0, 0x0d, |
| 4783 | // error details |
| 4784 | 'b', 'e', 'c', 'a', |
| 4785 | 'u', 's', 'e', ' ', |
| 4786 | 'I', ' ', 'c', 'a', |
| 4787 | 'n'} |
| 4788 | } |
| 4789 | }; |
| 4790 | // clang-format on |
| 4791 | |
| 4792 | PacketFragments& fragments = |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 4793 | framer_.transport_version() >= QUIC_VERSION_46 ? packet46 : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4794 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4795 | AssemblePacketFromFragments(fragments)); |
| 4796 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4797 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4798 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4799 | ASSERT_TRUE(visitor_.header_.get()); |
| 4800 | EXPECT_TRUE(CheckDecryption( |
| 4801 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4802 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4803 | |
| 4804 | EXPECT_EQ(kStreamId, visitor_.goaway_frame_.last_good_stream_id); |
fkastenholz | 88d08f4 | 2019-09-06 07:38:04 -0700 | [diff] [blame] | 4805 | EXPECT_EQ(0x9u, visitor_.goaway_frame_.error_code); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4806 | EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase); |
| 4807 | |
| 4808 | CheckFramingBoundaries(fragments, QUIC_INVALID_GOAWAY_DATA); |
| 4809 | } |
| 4810 | |
| 4811 | TEST_P(QuicFramerTest, WindowUpdateFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4812 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 4813 | // This frame is not in IETF QUIC, see MaxDataFrame and MaxStreamDataFrame |
| 4814 | // for IETF QUIC equivalents. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4815 | return; |
| 4816 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4817 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4818 | // clang-format off |
| 4819 | PacketFragments packet = { |
| 4820 | // public flags (8 byte connection_id) |
| 4821 | {"", |
| 4822 | {0x28}}, |
| 4823 | // connection_id |
| 4824 | {"", |
| 4825 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4826 | // packet number |
| 4827 | {"", |
| 4828 | {0x12, 0x34, 0x56, 0x78}}, |
| 4829 | // frame type (window update frame) |
| 4830 | {"", |
| 4831 | {0x04}}, |
| 4832 | // stream id |
| 4833 | {"Unable to read stream_id.", |
| 4834 | {0x01, 0x02, 0x03, 0x04}}, |
| 4835 | // byte offset |
| 4836 | {"Unable to read window byte_offset.", |
| 4837 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4838 | 0x32, 0x10, 0x76, 0x54}}, |
| 4839 | }; |
| 4840 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4841 | PacketFragments packet46 = { |
| 4842 | // type (short header, 4 byte packet number) |
| 4843 | {"", |
| 4844 | {0x43}}, |
| 4845 | // connection_id |
| 4846 | {"", |
| 4847 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4848 | // packet number |
| 4849 | {"", |
| 4850 | {0x12, 0x34, 0x56, 0x78}}, |
| 4851 | // frame type (window update frame) |
| 4852 | {"", |
| 4853 | {0x04}}, |
| 4854 | // stream id |
| 4855 | {"Unable to read stream_id.", |
| 4856 | {0x01, 0x02, 0x03, 0x04}}, |
| 4857 | // byte offset |
| 4858 | {"Unable to read window byte_offset.", |
| 4859 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4860 | 0x32, 0x10, 0x76, 0x54}}, |
| 4861 | }; |
| 4862 | |
| 4863 | // clang-format on |
| 4864 | |
| 4865 | PacketFragments& fragments = |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 4866 | framer_.transport_version() >= QUIC_VERSION_46 ? packet46 : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4867 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4868 | AssemblePacketFromFragments(fragments)); |
| 4869 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4870 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4871 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4872 | ASSERT_TRUE(visitor_.header_.get()); |
| 4873 | EXPECT_TRUE(CheckDecryption( |
| 4874 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4875 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4876 | |
| 4877 | EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id); |
renjietang | d088eab | 2019-11-21 14:54:41 -0800 | [diff] [blame] | 4878 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.max_data); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4879 | |
| 4880 | CheckFramingBoundaries(fragments, QUIC_INVALID_WINDOW_UPDATE_DATA); |
| 4881 | } |
| 4882 | |
| 4883 | TEST_P(QuicFramerTest, MaxDataFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4884 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 4885 | // This frame is available only in IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4886 | return; |
| 4887 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4888 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4889 | // clang-format off |
| 4890 | PacketFragments packet99 = { |
| 4891 | // type (short header, 4 byte packet number) |
| 4892 | {"", |
| 4893 | {0x43}}, |
| 4894 | // connection_id |
| 4895 | {"", |
| 4896 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4897 | // packet number |
| 4898 | {"", |
| 4899 | {0x12, 0x34, 0x56, 0x78}}, |
| 4900 | // frame type (IETF_MAX_DATA frame) |
| 4901 | {"", |
| 4902 | {0x10}}, |
| 4903 | // byte offset |
| 4904 | {"Can not read MAX_DATA byte-offset", |
| 4905 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 4906 | 0x32, 0x10, 0x76, 0x54}}, |
| 4907 | }; |
| 4908 | // clang-format on |
| 4909 | |
| 4910 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4911 | AssemblePacketFromFragments(packet99)); |
| 4912 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4913 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4914 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4915 | ASSERT_TRUE(visitor_.header_.get()); |
| 4916 | EXPECT_TRUE(CheckDecryption( |
| 4917 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4918 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4919 | |
| 4920 | EXPECT_EQ(QuicUtils::GetInvalidStreamId(framer_.transport_version()), |
| 4921 | visitor_.window_update_frame_.stream_id); |
renjietang | d088eab | 2019-11-21 14:54:41 -0800 | [diff] [blame] | 4922 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.max_data); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4923 | |
| 4924 | CheckFramingBoundaries(packet99, QUIC_INVALID_MAX_DATA_FRAME_DATA); |
| 4925 | } |
| 4926 | |
| 4927 | TEST_P(QuicFramerTest, MaxStreamDataFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4928 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 4929 | // This frame available only in IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4930 | return; |
| 4931 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4932 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4933 | // clang-format off |
| 4934 | PacketFragments packet99 = { |
| 4935 | // type (short header, 4 byte packet number) |
| 4936 | {"", |
| 4937 | {0x43}}, |
| 4938 | // connection_id |
| 4939 | {"", |
| 4940 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4941 | // packet number |
| 4942 | {"", |
| 4943 | {0x12, 0x34, 0x56, 0x78}}, |
| 4944 | // frame type (IETF_MAX_STREAM_DATA frame) |
| 4945 | {"", |
| 4946 | {0x11}}, |
| 4947 | // stream id |
| 4948 | {"Can not read MAX_STREAM_DATA stream id", |
| 4949 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 4950 | // byte offset |
| 4951 | {"Can not read MAX_STREAM_DATA byte-count", |
| 4952 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 4953 | 0x32, 0x10, 0x76, 0x54}}, |
| 4954 | }; |
| 4955 | // clang-format on |
| 4956 | |
| 4957 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4958 | AssemblePacketFromFragments(packet99)); |
| 4959 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4960 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4961 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4962 | ASSERT_TRUE(visitor_.header_.get()); |
| 4963 | EXPECT_TRUE(CheckDecryption( |
| 4964 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4965 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4966 | |
| 4967 | EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id); |
renjietang | d088eab | 2019-11-21 14:54:41 -0800 | [diff] [blame] | 4968 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.max_data); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4969 | |
| 4970 | CheckFramingBoundaries(packet99, QUIC_INVALID_MAX_STREAM_DATA_FRAME_DATA); |
| 4971 | } |
| 4972 | |
| 4973 | TEST_P(QuicFramerTest, BlockedFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4974 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4975 | // clang-format off |
| 4976 | PacketFragments packet = { |
| 4977 | // public flags (8 byte connection_id) |
| 4978 | {"", |
| 4979 | {0x28}}, |
| 4980 | // connection_id |
| 4981 | {"", |
| 4982 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4983 | // packet number |
| 4984 | {"", |
| 4985 | {0x12, 0x34, 0x56, 0x78}}, |
| 4986 | // frame type (blocked frame) |
| 4987 | {"", |
| 4988 | {0x05}}, |
| 4989 | // stream id |
| 4990 | {"Unable to read stream_id.", |
| 4991 | {0x01, 0x02, 0x03, 0x04}}, |
| 4992 | }; |
| 4993 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4994 | PacketFragments packet46 = { |
| 4995 | // type (short header, 4 byte packet number) |
| 4996 | {"", |
| 4997 | {0x43}}, |
| 4998 | // connection_id |
| 4999 | {"", |
| 5000 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5001 | // packet number |
| 5002 | {"", |
| 5003 | {0x12, 0x34, 0x56, 0x78}}, |
| 5004 | // frame type (blocked frame) |
| 5005 | {"", |
| 5006 | {0x05}}, |
| 5007 | // stream id |
| 5008 | {"Unable to read stream_id.", |
| 5009 | {0x01, 0x02, 0x03, 0x04}}, |
| 5010 | }; |
| 5011 | |
| 5012 | PacketFragments packet99 = { |
| 5013 | // type (short header, 4 byte packet number) |
| 5014 | {"", |
| 5015 | {0x43}}, |
| 5016 | // connection_id |
| 5017 | {"", |
| 5018 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5019 | // packet number |
| 5020 | {"", |
| 5021 | {0x12, 0x34, 0x56, 0x78}}, |
| 5022 | // frame type (IETF_STREAM_BLOCKED frame) |
| 5023 | {"", |
| 5024 | {0x15}}, |
| 5025 | // stream id |
| 5026 | {"Can not read stream blocked stream id.", |
| 5027 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 5028 | // Offset |
| 5029 | {"Can not read stream blocked offset.", |
| 5030 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 5031 | }; |
| 5032 | // clang-format on |
| 5033 | |
| 5034 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 5035 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5036 | ? packet99 |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 5037 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 5038 | : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5039 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5040 | AssemblePacketFromFragments(fragments)); |
| 5041 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5042 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5043 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5044 | ASSERT_TRUE(visitor_.header_.get()); |
| 5045 | EXPECT_TRUE(CheckDecryption( |
| 5046 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5047 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5048 | |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 5049 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5050 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 5051 | } else { |
| 5052 | EXPECT_EQ(0u, visitor_.blocked_frame_.offset); |
| 5053 | } |
| 5054 | EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id); |
| 5055 | |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 5056 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5057 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_BLOCKED_DATA); |
| 5058 | } else { |
| 5059 | CheckFramingBoundaries(fragments, QUIC_INVALID_BLOCKED_DATA); |
| 5060 | } |
| 5061 | } |
| 5062 | |
| 5063 | TEST_P(QuicFramerTest, PingFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5064 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5065 | // clang-format off |
| 5066 | unsigned char packet[] = { |
| 5067 | // public flags (8 byte connection_id) |
| 5068 | 0x28, |
| 5069 | // connection_id |
| 5070 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5071 | // packet number |
| 5072 | 0x12, 0x34, 0x56, 0x78, |
| 5073 | |
| 5074 | // frame type (ping frame) |
| 5075 | 0x07, |
| 5076 | }; |
| 5077 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5078 | unsigned char packet46[] = { |
| 5079 | // type (short header, 4 byte packet number) |
| 5080 | 0x43, |
| 5081 | // connection_id |
| 5082 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5083 | // packet number |
| 5084 | 0x12, 0x34, 0x56, 0x78, |
| 5085 | |
| 5086 | // frame type |
| 5087 | 0x07, |
| 5088 | }; |
| 5089 | |
| 5090 | unsigned char packet99[] = { |
| 5091 | // type (short header, 4 byte packet number) |
| 5092 | 0x43, |
| 5093 | // connection_id |
| 5094 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5095 | // packet number |
| 5096 | 0x12, 0x34, 0x56, 0x78, |
| 5097 | |
| 5098 | // frame type (IETF_PING frame) |
| 5099 | 0x01, |
| 5100 | }; |
| 5101 | // clang-format on |
| 5102 | |
| 5103 | QuicEncryptedPacket encrypted( |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 5104 | AsChars(VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5105 | ? packet99 |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 5106 | : (framer_.transport_version() >= QUIC_VERSION_46 ? packet46 |
| 5107 | : packet)), |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 5108 | VersionHasIetfQuicFrames(framer_.transport_version()) |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 5109 | ? QUICHE_ARRAYSIZE(packet99) |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 5110 | : (framer_.transport_version() >= QUIC_VERSION_46 |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 5111 | ? QUICHE_ARRAYSIZE(packet46) |
| 5112 | : QUICHE_ARRAYSIZE(packet)), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5113 | false); |
| 5114 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 5115 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5116 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5117 | ASSERT_TRUE(visitor_.header_.get()); |
| 5118 | EXPECT_TRUE(CheckDecryption( |
| 5119 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5120 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5121 | |
| 5122 | EXPECT_EQ(1u, visitor_.ping_frames_.size()); |
| 5123 | |
| 5124 | // No need to check the PING frame boundaries because it has no payload. |
| 5125 | } |
| 5126 | |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 5127 | TEST_P(QuicFramerTest, HandshakeDoneFrame) { |
| 5128 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 5129 | // clang-format off |
| 5130 | unsigned char packet[] = { |
| 5131 | // type (short header, 4 byte packet number) |
| 5132 | 0x43, |
| 5133 | // connection_id |
| 5134 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5135 | // packet number |
| 5136 | 0x12, 0x34, 0x56, 0x78, |
| 5137 | |
| 5138 | // frame type (Handshake done frame) |
| 5139 | 0x1e, |
| 5140 | }; |
| 5141 | // clang-format on |
| 5142 | |
| 5143 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 5144 | return; |
| 5145 | } |
| 5146 | |
| 5147 | QuicEncryptedPacket encrypted(AsChars(packet), QUICHE_ARRAYSIZE(packet), |
| 5148 | false); |
| 5149 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 5150 | |
| 5151 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
| 5152 | ASSERT_TRUE(visitor_.header_.get()); |
| 5153 | EXPECT_TRUE(CheckDecryption( |
| 5154 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5155 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5156 | |
| 5157 | EXPECT_EQ(1u, visitor_.handshake_done_frames_.size()); |
| 5158 | } |
| 5159 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5160 | TEST_P(QuicFramerTest, MessageFrame) { |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 5161 | if (!VersionSupportsMessageFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5162 | return; |
| 5163 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5164 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5165 | // clang-format off |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5166 | PacketFragments packet46 = { |
| 5167 | // type (short header, 4 byte packet number) |
| 5168 | {"", |
| 5169 | {0x43}}, |
| 5170 | // connection_id |
| 5171 | {"", |
| 5172 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5173 | // packet number |
| 5174 | {"", |
| 5175 | {0x12, 0x34, 0x56, 0x78}}, |
| 5176 | // message frame type. |
| 5177 | {"", |
| 5178 | { 0x21 }}, |
| 5179 | // message length |
| 5180 | {"Unable to read message length", |
| 5181 | {0x07}}, |
| 5182 | // message data |
| 5183 | {"Unable to read message data", |
| 5184 | {'m', 'e', 's', 's', 'a', 'g', 'e'}}, |
| 5185 | // message frame no length. |
| 5186 | {"", |
| 5187 | { 0x20 }}, |
| 5188 | // message data |
| 5189 | {{}, |
| 5190 | {'m', 'e', 's', 's', 'a', 'g', 'e', '2'}}, |
| 5191 | }; |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 5192 | PacketFragments packet99 = { |
| 5193 | // type (short header, 4 byte packet number) |
| 5194 | {"", |
| 5195 | {0x43}}, |
| 5196 | // connection_id |
| 5197 | {"", |
| 5198 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5199 | // packet number |
| 5200 | {"", |
| 5201 | {0x12, 0x34, 0x56, 0x78}}, |
| 5202 | // message frame type. |
| 5203 | {"", |
| 5204 | { 0x31 }}, |
| 5205 | // message length |
| 5206 | {"Unable to read message length", |
| 5207 | {0x07}}, |
| 5208 | // message data |
| 5209 | {"Unable to read message data", |
| 5210 | {'m', 'e', 's', 's', 'a', 'g', 'e'}}, |
| 5211 | // message frame no length. |
| 5212 | {"", |
| 5213 | { 0x30 }}, |
| 5214 | // message data |
| 5215 | {{}, |
| 5216 | {'m', 'e', 's', 's', 'a', 'g', 'e', '2'}}, |
| 5217 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5218 | // clang-format on |
| 5219 | |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 5220 | std::unique_ptr<QuicEncryptedPacket> encrypted; |
| 5221 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 5222 | encrypted = AssemblePacketFromFragments(packet99); |
| 5223 | } else { |
| 5224 | encrypted = AssemblePacketFromFragments(packet46); |
| 5225 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5226 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5227 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5228 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5229 | ASSERT_TRUE(visitor_.header_.get()); |
| 5230 | EXPECT_TRUE(CheckDecryption( |
| 5231 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5232 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5233 | |
| 5234 | ASSERT_EQ(2u, visitor_.message_frames_.size()); |
| 5235 | EXPECT_EQ(7u, visitor_.message_frames_[0]->message_length); |
| 5236 | EXPECT_EQ(8u, visitor_.message_frames_[1]->message_length); |
| 5237 | |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 5238 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 5239 | CheckFramingBoundaries(packet99, QUIC_INVALID_MESSAGE_DATA); |
| 5240 | } else { |
| 5241 | CheckFramingBoundaries(packet46, QUIC_INVALID_MESSAGE_DATA); |
| 5242 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5243 | } |
| 5244 | |
| 5245 | TEST_P(QuicFramerTest, PublicResetPacketV33) { |
| 5246 | // clang-format off |
| 5247 | PacketFragments packet = { |
| 5248 | // public flags (public reset, 8 byte connection_id) |
| 5249 | {"", |
| 5250 | {0x0A}}, |
| 5251 | // connection_id |
| 5252 | {"", |
| 5253 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5254 | {"Unable to read reset message.", |
| 5255 | { |
| 5256 | // message tag (kPRST) |
| 5257 | 'P', 'R', 'S', 'T', |
| 5258 | // num_entries (2) + padding |
| 5259 | 0x02, 0x00, 0x00, 0x00, |
| 5260 | // tag kRNON |
| 5261 | 'R', 'N', 'O', 'N', |
| 5262 | // end offset 8 |
| 5263 | 0x08, 0x00, 0x00, 0x00, |
| 5264 | // tag kRSEQ |
| 5265 | 'R', 'S', 'E', 'Q', |
| 5266 | // end offset 16 |
| 5267 | 0x10, 0x00, 0x00, 0x00, |
| 5268 | // nonce proof |
| 5269 | 0x89, 0x67, 0x45, 0x23, |
| 5270 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5271 | // rejected packet number |
| 5272 | 0xBC, 0x9A, 0x78, 0x56, |
| 5273 | 0x34, 0x12, 0x00, 0x00, |
| 5274 | } |
| 5275 | } |
| 5276 | }; |
| 5277 | // clang-format on |
| 5278 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5279 | return; |
| 5280 | } |
| 5281 | |
| 5282 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5283 | AssemblePacketFromFragments(packet)); |
| 5284 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5285 | ASSERT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5286 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 5287 | EXPECT_EQ(FramerTestConnectionId(), |
| 5288 | visitor_.public_reset_packet_->connection_id); |
| 5289 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 5290 | EXPECT_EQ( |
| 5291 | IpAddressFamily::IP_UNSPEC, |
| 5292 | visitor_.public_reset_packet_->client_address.host().address_family()); |
| 5293 | |
| 5294 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 5295 | } |
| 5296 | |
| 5297 | TEST_P(QuicFramerTest, PublicResetPacket) { |
| 5298 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5299 | |
| 5300 | // clang-format off |
| 5301 | PacketFragments packet = { |
| 5302 | // public flags (public reset, 8 byte connection_id) |
| 5303 | {"", |
| 5304 | {0x0E}}, |
| 5305 | // connection_id |
| 5306 | {"", |
| 5307 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5308 | {"Unable to read reset message.", |
| 5309 | { |
| 5310 | // message tag (kPRST) |
| 5311 | 'P', 'R', 'S', 'T', |
| 5312 | // num_entries (2) + padding |
| 5313 | 0x02, 0x00, 0x00, 0x00, |
| 5314 | // tag kRNON |
| 5315 | 'R', 'N', 'O', 'N', |
| 5316 | // end offset 8 |
| 5317 | 0x08, 0x00, 0x00, 0x00, |
| 5318 | // tag kRSEQ |
| 5319 | 'R', 'S', 'E', 'Q', |
| 5320 | // end offset 16 |
| 5321 | 0x10, 0x00, 0x00, 0x00, |
| 5322 | // nonce proof |
| 5323 | 0x89, 0x67, 0x45, 0x23, |
| 5324 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5325 | // rejected packet number |
| 5326 | 0xBC, 0x9A, 0x78, 0x56, |
| 5327 | 0x34, 0x12, 0x00, 0x00, |
| 5328 | } |
| 5329 | } |
| 5330 | }; |
| 5331 | // clang-format on |
| 5332 | |
| 5333 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5334 | return; |
| 5335 | } |
| 5336 | |
| 5337 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5338 | AssemblePacketFromFragments(packet)); |
| 5339 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5340 | ASSERT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5341 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 5342 | EXPECT_EQ(FramerTestConnectionId(), |
| 5343 | visitor_.public_reset_packet_->connection_id); |
| 5344 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 5345 | EXPECT_EQ( |
| 5346 | IpAddressFamily::IP_UNSPEC, |
| 5347 | visitor_.public_reset_packet_->client_address.host().address_family()); |
| 5348 | |
| 5349 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 5350 | } |
| 5351 | |
| 5352 | TEST_P(QuicFramerTest, PublicResetPacketWithTrailingJunk) { |
| 5353 | // clang-format off |
| 5354 | unsigned char packet[] = { |
| 5355 | // public flags (public reset, 8 byte connection_id) |
| 5356 | 0x0A, |
| 5357 | // connection_id |
| 5358 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5359 | // message tag (kPRST) |
| 5360 | 'P', 'R', 'S', 'T', |
| 5361 | // num_entries (2) + padding |
| 5362 | 0x02, 0x00, 0x00, 0x00, |
| 5363 | // tag kRNON |
| 5364 | 'R', 'N', 'O', 'N', |
| 5365 | // end offset 8 |
| 5366 | 0x08, 0x00, 0x00, 0x00, |
| 5367 | // tag kRSEQ |
| 5368 | 'R', 'S', 'E', 'Q', |
| 5369 | // end offset 16 |
| 5370 | 0x10, 0x00, 0x00, 0x00, |
| 5371 | // nonce proof |
| 5372 | 0x89, 0x67, 0x45, 0x23, |
| 5373 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5374 | // rejected packet number |
| 5375 | 0xBC, 0x9A, 0x78, 0x56, |
| 5376 | 0x34, 0x12, 0x00, 0x00, |
| 5377 | // trailing junk |
| 5378 | 'j', 'u', 'n', 'k', |
| 5379 | }; |
| 5380 | // clang-format on |
| 5381 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5382 | return; |
| 5383 | } |
| 5384 | |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 5385 | QuicEncryptedPacket encrypted(AsChars(packet), QUICHE_ARRAYSIZE(packet), |
| 5386 | false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5387 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
bnc | f54082a | 2019-11-27 10:19:47 -0800 | [diff] [blame] | 5388 | ASSERT_THAT(framer_.error(), IsError(QUIC_INVALID_PUBLIC_RST_PACKET)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5389 | EXPECT_EQ("Unable to read reset message.", framer_.detailed_error()); |
| 5390 | } |
| 5391 | |
| 5392 | TEST_P(QuicFramerTest, PublicResetPacketWithClientAddress) { |
| 5393 | // clang-format off |
| 5394 | PacketFragments packet = { |
| 5395 | // public flags (public reset, 8 byte connection_id) |
| 5396 | {"", |
| 5397 | {0x0A}}, |
| 5398 | // connection_id |
| 5399 | {"", |
| 5400 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5401 | {"Unable to read reset message.", |
| 5402 | { |
| 5403 | // message tag (kPRST) |
| 5404 | 'P', 'R', 'S', 'T', |
| 5405 | // num_entries (2) + padding |
| 5406 | 0x03, 0x00, 0x00, 0x00, |
| 5407 | // tag kRNON |
| 5408 | 'R', 'N', 'O', 'N', |
| 5409 | // end offset 8 |
| 5410 | 0x08, 0x00, 0x00, 0x00, |
| 5411 | // tag kRSEQ |
| 5412 | 'R', 'S', 'E', 'Q', |
| 5413 | // end offset 16 |
| 5414 | 0x10, 0x00, 0x00, 0x00, |
| 5415 | // tag kCADR |
| 5416 | 'C', 'A', 'D', 'R', |
| 5417 | // end offset 24 |
| 5418 | 0x18, 0x00, 0x00, 0x00, |
| 5419 | // nonce proof |
| 5420 | 0x89, 0x67, 0x45, 0x23, |
| 5421 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5422 | // rejected packet number |
| 5423 | 0xBC, 0x9A, 0x78, 0x56, |
| 5424 | 0x34, 0x12, 0x00, 0x00, |
| 5425 | // client address: 4.31.198.44:443 |
| 5426 | 0x02, 0x00, |
| 5427 | 0x04, 0x1F, 0xC6, 0x2C, |
| 5428 | 0xBB, 0x01, |
| 5429 | } |
| 5430 | } |
| 5431 | }; |
| 5432 | // clang-format on |
| 5433 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5434 | return; |
| 5435 | } |
| 5436 | |
| 5437 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5438 | AssemblePacketFromFragments(packet)); |
| 5439 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5440 | ASSERT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5441 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 5442 | EXPECT_EQ(FramerTestConnectionId(), |
| 5443 | visitor_.public_reset_packet_->connection_id); |
| 5444 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 5445 | EXPECT_EQ("4.31.198.44", |
| 5446 | visitor_.public_reset_packet_->client_address.host().ToString()); |
| 5447 | EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port()); |
| 5448 | |
| 5449 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 5450 | } |
| 5451 | |
| 5452 | TEST_P(QuicFramerTest, IetfStatelessResetPacket) { |
| 5453 | // clang-format off |
| 5454 | unsigned char packet[] = { |
| 5455 | // type (short packet, 1 byte packet number) |
| 5456 | 0x50, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5457 | // Random bytes |
| 5458 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5459 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5460 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5461 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5462 | // stateless reset token |
| 5463 | 0xB5, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5464 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5465 | }; |
| 5466 | // clang-format on |
| 5467 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 5468 | return; |
| 5469 | } |
| 5470 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
dschinazi | b953d02 | 2019-08-01 18:05:58 -0700 | [diff] [blame] | 5471 | QuicFramerPeer::SetLastSerializedServerConnectionId(&framer_, |
| 5472 | TestConnectionId(0x33)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5473 | decrypter_ = new test::TestDecrypter(); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5474 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 5475 | framer_.InstallDecrypter( |
| 5476 | ENCRYPTION_INITIAL, |
| 5477 | std::make_unique<NullDecrypter>(Perspective::IS_CLIENT)); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5478 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 5479 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 5480 | } else { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 5481 | framer_.SetDecrypter(ENCRYPTION_INITIAL, std::make_unique<NullDecrypter>( |
| 5482 | Perspective::IS_CLIENT)); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5483 | framer_.SetAlternativeDecrypter( |
| 5484 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 5485 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5486 | // This packet cannot be decrypted because diversification nonce is missing. |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 5487 | QuicEncryptedPacket encrypted(AsChars(packet), QUICHE_ARRAYSIZE(packet), |
| 5488 | false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5489 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5490 | ASSERT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5491 | ASSERT_TRUE(visitor_.stateless_reset_packet_.get()); |
| 5492 | EXPECT_EQ(kTestStatelessResetToken, |
| 5493 | visitor_.stateless_reset_packet_->stateless_reset_token); |
| 5494 | } |
| 5495 | |
| 5496 | TEST_P(QuicFramerTest, IetfStatelessResetPacketInvalidStatelessResetToken) { |
| 5497 | // clang-format off |
| 5498 | unsigned char packet[] = { |
| 5499 | // type (short packet, 1 byte packet number) |
| 5500 | 0x50, |
dschinazi | b953d02 | 2019-08-01 18:05:58 -0700 | [diff] [blame] | 5501 | // Random bytes |
| 5502 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5503 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5504 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5505 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5506 | // stateless reset token |
| 5507 | 0xB6, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5508 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5509 | }; |
| 5510 | // clang-format on |
| 5511 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 5512 | return; |
| 5513 | } |
dschinazi | b953d02 | 2019-08-01 18:05:58 -0700 | [diff] [blame] | 5514 | QuicFramerPeer::SetLastSerializedServerConnectionId(&framer_, |
| 5515 | TestConnectionId(0x33)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5516 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5517 | decrypter_ = new test::TestDecrypter(); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5518 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 5519 | framer_.InstallDecrypter( |
| 5520 | ENCRYPTION_INITIAL, |
| 5521 | std::make_unique<NullDecrypter>(Perspective::IS_CLIENT)); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5522 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 5523 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 5524 | } else { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 5525 | framer_.SetDecrypter(ENCRYPTION_INITIAL, std::make_unique<NullDecrypter>( |
| 5526 | Perspective::IS_CLIENT)); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5527 | framer_.SetAlternativeDecrypter( |
| 5528 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 5529 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5530 | // This packet cannot be decrypted because diversification nonce is missing. |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 5531 | QuicEncryptedPacket encrypted(AsChars(packet), QUICHE_ARRAYSIZE(packet), |
| 5532 | false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5533 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5534 | EXPECT_THAT(framer_.error(), IsError(QUIC_DECRYPTION_FAILURE)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5535 | ASSERT_FALSE(visitor_.stateless_reset_packet_); |
| 5536 | } |
| 5537 | |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 5538 | TEST_P(QuicFramerTest, VersionNegotiationPacketClient) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5539 | // clang-format off |
| 5540 | PacketFragments packet = { |
| 5541 | // public flags (version, 8 byte connection_id) |
| 5542 | {"", |
| 5543 | {0x29}}, |
| 5544 | // connection_id |
| 5545 | {"", |
| 5546 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5547 | // version tag |
| 5548 | {"Unable to read supported version in negotiation.", |
| 5549 | {QUIC_VERSION_BYTES, |
| 5550 | 'Q', '2', '.', '0'}}, |
| 5551 | }; |
| 5552 | |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 5553 | PacketFragments packet46 = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5554 | // type (long header) |
| 5555 | {"", |
| 5556 | {0x8F}}, |
| 5557 | // version tag |
| 5558 | {"", |
| 5559 | {0x00, 0x00, 0x00, 0x00}}, |
| 5560 | {"", |
| 5561 | {0x05}}, |
| 5562 | // connection_id |
| 5563 | {"", |
| 5564 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5565 | // Supported versions |
| 5566 | {"Unable to read supported version in negotiation.", |
| 5567 | {QUIC_VERSION_BYTES, |
| 5568 | 'Q', '2', '.', '0'}}, |
| 5569 | }; |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 5570 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 5571 | PacketFragments packet49 = { |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 5572 | // type (long header) |
| 5573 | {"", |
| 5574 | {0x8F}}, |
| 5575 | // version tag |
| 5576 | {"", |
| 5577 | {0x00, 0x00, 0x00, 0x00}}, |
| 5578 | {"", |
| 5579 | {0x08}}, |
| 5580 | // connection_id |
| 5581 | {"", |
| 5582 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5583 | {"", |
| 5584 | {0x00}}, |
| 5585 | // Supported versions |
| 5586 | {"Unable to read supported version in negotiation.", |
| 5587 | {QUIC_VERSION_BYTES, |
| 5588 | 'Q', '2', '.', '0'}}, |
| 5589 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5590 | // clang-format on |
| 5591 | |
| 5592 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5593 | |
| 5594 | PacketFragments& fragments = |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 5595 | framer_.transport_version() >= QUIC_VERSION_49 |
| 5596 | ? packet49 |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 5597 | : framer_.transport_version() > QUIC_VERSION_43 ? packet46 : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5598 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5599 | AssemblePacketFromFragments(fragments)); |
| 5600 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5601 | ASSERT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5602 | ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); |
nharper | 4fd1105 | 2019-06-04 14:23:22 -0700 | [diff] [blame] | 5603 | EXPECT_EQ(1u, visitor_.version_negotiation_packet_->versions.size()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5604 | EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]); |
| 5605 | |
| 5606 | // Remove the last version from the packet so that every truncated |
| 5607 | // version of the packet is invalid, otherwise checking boundaries |
| 5608 | // is annoyingly complicated. |
| 5609 | for (size_t i = 0; i < 4; ++i) { |
| 5610 | fragments.back().fragment.pop_back(); |
| 5611 | } |
| 5612 | CheckFramingBoundaries(fragments, QUIC_INVALID_VERSION_NEGOTIATION_PACKET); |
| 5613 | } |
| 5614 | |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 5615 | TEST_P(QuicFramerTest, VersionNegotiationPacketServer) { |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 5616 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 5617 | return; |
| 5618 | } |
| 5619 | |
| 5620 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 5621 | // clang-format off |
| 5622 | unsigned char packet[] = { |
| 5623 | // public flags (long header with all ignored bits set) |
| 5624 | 0xFF, |
| 5625 | // version |
| 5626 | 0x00, 0x00, 0x00, 0x00, |
| 5627 | // connection ID lengths |
| 5628 | 0x50, |
| 5629 | // destination connection ID |
| 5630 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 5631 | // supported versions |
| 5632 | QUIC_VERSION_BYTES, |
| 5633 | 'Q', '2', '.', '0', |
| 5634 | }; |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 5635 | unsigned char packet2[] = { |
| 5636 | // public flags (long header with all ignored bits set) |
| 5637 | 0xFF, |
| 5638 | // version |
| 5639 | 0x00, 0x00, 0x00, 0x00, |
| 5640 | // destination connection ID length |
| 5641 | 0x08, |
| 5642 | // destination connection ID |
| 5643 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 5644 | // source connection ID length |
| 5645 | 0x00, |
| 5646 | // supported versions |
| 5647 | QUIC_VERSION_BYTES, |
| 5648 | 'Q', '2', '.', '0', |
| 5649 | }; |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 5650 | // clang-format on |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 5651 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 5652 | size_t p_length = QUICHE_ARRAYSIZE(packet); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 5653 | if (framer_.version().HasLengthPrefixedConnectionIds()) { |
| 5654 | p = packet2; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 5655 | p_length = QUICHE_ARRAYSIZE(packet2); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 5656 | } |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 5657 | |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 5658 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 5659 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5660 | EXPECT_THAT(framer_.error(), |
| 5661 | IsError(QUIC_INVALID_VERSION_NEGOTIATION_PACKET)); |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 5662 | EXPECT_EQ("Server received version negotiation packet.", |
| 5663 | framer_.detailed_error()); |
| 5664 | EXPECT_FALSE(visitor_.version_negotiation_packet_.get()); |
| 5665 | } |
| 5666 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5667 | TEST_P(QuicFramerTest, OldVersionNegotiationPacket) { |
| 5668 | // clang-format off |
| 5669 | PacketFragments packet = { |
| 5670 | // public flags (version, 8 byte connection_id) |
| 5671 | {"", |
| 5672 | {0x2D}}, |
| 5673 | // connection_id |
| 5674 | {"", |
| 5675 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5676 | // version tag |
| 5677 | {"Unable to read supported version in negotiation.", |
| 5678 | {QUIC_VERSION_BYTES, |
| 5679 | 'Q', '2', '.', '0'}}, |
| 5680 | }; |
| 5681 | // clang-format on |
| 5682 | |
| 5683 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5684 | return; |
| 5685 | } |
| 5686 | |
| 5687 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5688 | |
| 5689 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5690 | AssemblePacketFromFragments(packet)); |
| 5691 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5692 | ASSERT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5693 | ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); |
nharper | 4fd1105 | 2019-06-04 14:23:22 -0700 | [diff] [blame] | 5694 | EXPECT_EQ(1u, visitor_.version_negotiation_packet_->versions.size()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5695 | EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]); |
| 5696 | |
| 5697 | // Remove the last version from the packet so that every truncated |
| 5698 | // version of the packet is invalid, otherwise checking boundaries |
| 5699 | // is annoyingly complicated. |
| 5700 | for (size_t i = 0; i < 4; ++i) { |
| 5701 | packet.back().fragment.pop_back(); |
| 5702 | } |
| 5703 | CheckFramingBoundaries(packet, QUIC_INVALID_VERSION_NEGOTIATION_PACKET); |
| 5704 | } |
| 5705 | |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 5706 | TEST_P(QuicFramerTest, ParseIetfRetryPacket) { |
| 5707 | if (!framer_.version().SupportsRetry()) { |
| 5708 | return; |
| 5709 | } |
| 5710 | // IETF RETRY is only sent from client to server. |
| 5711 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5712 | // clang-format off |
| 5713 | unsigned char packet[] = { |
| 5714 | // public flags (long header with packet type RETRY and ODCIL=8) |
| 5715 | 0xF5, |
| 5716 | // version |
| 5717 | QUIC_VERSION_BYTES, |
| 5718 | // connection ID lengths |
| 5719 | 0x05, |
| 5720 | // source connection ID |
| 5721 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 5722 | // original destination connection ID |
| 5723 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5724 | // retry token |
| 5725 | 'H', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'i', 's', |
| 5726 | ' ', 'i', 's', ' ', 'R', 'E', 'T', 'R', 'Y', '!', |
| 5727 | }; |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 5728 | unsigned char packet49[] = { |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 5729 | // public flags (long header with packet type RETRY) |
| 5730 | 0xF0, |
| 5731 | // version |
| 5732 | QUIC_VERSION_BYTES, |
| 5733 | // destination connection ID length |
| 5734 | 0x00, |
| 5735 | // source connection ID length |
| 5736 | 0x08, |
| 5737 | // source connection ID |
| 5738 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 5739 | // original destination connection ID length |
| 5740 | 0x08, |
| 5741 | // original destination connection ID |
| 5742 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5743 | // retry token |
| 5744 | 'H', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'i', 's', |
| 5745 | ' ', 'i', 's', ' ', 'R', 'E', 'T', 'R', 'Y', '!', |
| 5746 | }; |
dschinazi | 278efae | 2020-01-28 17:03:09 -0800 | [diff] [blame] | 5747 | unsigned char packet_with_tag[] = { |
| 5748 | // public flags (long header with packet type RETRY) |
| 5749 | 0xF0, |
| 5750 | // version |
| 5751 | QUIC_VERSION_BYTES, |
| 5752 | // destination connection ID length |
| 5753 | 0x00, |
| 5754 | // source connection ID length |
| 5755 | 0x08, |
| 5756 | // source connection ID |
| 5757 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 5758 | // retry token |
| 5759 | 'H', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'i', 's', |
| 5760 | ' ', 'i', 's', ' ', 'R', 'E', 'T', 'R', 'Y', '!', |
| 5761 | // retry token integrity tag |
| 5762 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 5763 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 5764 | }; |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 5765 | // clang-format on |
| 5766 | |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 5767 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 5768 | size_t p_length = QUICHE_ARRAYSIZE(packet); |
dschinazi | 278efae | 2020-01-28 17:03:09 -0800 | [diff] [blame] | 5769 | if (framer_.version().HasRetryIntegrityTag()) { |
| 5770 | p = packet_with_tag; |
| 5771 | p_length = QUICHE_ARRAYSIZE(packet_with_tag); |
| 5772 | } else if (framer_.transport_version() >= QUIC_VERSION_49) { |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 5773 | p = packet49; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 5774 | p_length = QUICHE_ARRAYSIZE(packet49); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 5775 | } |
| 5776 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 5777 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 5778 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5779 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 5780 | ASSERT_TRUE(visitor_.header_.get()); |
| 5781 | |
dschinazi | 2dd75ee | 2020-01-29 09:21:37 -0800 | [diff] [blame] | 5782 | ASSERT_TRUE(visitor_.on_retry_packet_called_); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 5783 | ASSERT_TRUE(visitor_.retry_new_connection_id_.get()); |
| 5784 | ASSERT_TRUE(visitor_.retry_token_.get()); |
| 5785 | |
dschinazi | 278efae | 2020-01-28 17:03:09 -0800 | [diff] [blame] | 5786 | if (framer_.version().HasRetryIntegrityTag()) { |
| 5787 | ASSERT_TRUE(visitor_.retry_token_integrity_tag_.get()); |
| 5788 | static const unsigned char expected_integrity_tag[16] = { |
| 5789 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 5790 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 5791 | }; |
| 5792 | quiche::test::CompareCharArraysWithHexError( |
| 5793 | "retry integrity tag", visitor_.retry_token_integrity_tag_->data(), |
| 5794 | visitor_.retry_token_integrity_tag_->length(), |
| 5795 | reinterpret_cast<const char*>(expected_integrity_tag), |
| 5796 | QUICHE_ARRAYSIZE(expected_integrity_tag)); |
| 5797 | ASSERT_TRUE(visitor_.retry_without_tag_.get()); |
| 5798 | quiche::test::CompareCharArraysWithHexError( |
| 5799 | "retry without tag", visitor_.retry_without_tag_->data(), |
| 5800 | visitor_.retry_without_tag_->length(), |
| 5801 | reinterpret_cast<const char*>(packet_with_tag), 35); |
| 5802 | } else { |
| 5803 | ASSERT_TRUE(visitor_.retry_original_connection_id_.get()); |
| 5804 | EXPECT_EQ(FramerTestConnectionId(), |
| 5805 | *visitor_.retry_original_connection_id_.get()); |
| 5806 | } |
| 5807 | |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 5808 | EXPECT_EQ(FramerTestConnectionIdPlusOne(), |
| 5809 | *visitor_.retry_new_connection_id_.get()); |
| 5810 | EXPECT_EQ("Hello this is RETRY!", *visitor_.retry_token_.get()); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 5811 | |
dschinazi | 2dd75ee | 2020-01-29 09:21:37 -0800 | [diff] [blame] | 5812 | // IETF RETRY is only sent from client to server, the rest of this test |
| 5813 | // ensures that the server correctly drops them without acting on them. |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 5814 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
dschinazi | 2dd75ee | 2020-01-29 09:21:37 -0800 | [diff] [blame] | 5815 | // Reset our visitor state to default settings. |
| 5816 | visitor_.retry_original_connection_id_.reset(); |
| 5817 | visitor_.retry_new_connection_id_.reset(); |
| 5818 | visitor_.retry_token_.reset(); |
| 5819 | visitor_.retry_token_integrity_tag_.reset(); |
| 5820 | visitor_.retry_without_tag_.reset(); |
| 5821 | visitor_.on_retry_packet_called_ = false; |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 5822 | |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 5823 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 5824 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5825 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 5826 | EXPECT_EQ("Client-initiated RETRY is invalid.", framer_.detailed_error()); |
dschinazi | 2dd75ee | 2020-01-29 09:21:37 -0800 | [diff] [blame] | 5827 | |
| 5828 | EXPECT_FALSE(visitor_.on_retry_packet_called_); |
| 5829 | EXPECT_FALSE(visitor_.retry_new_connection_id_.get()); |
| 5830 | EXPECT_FALSE(visitor_.retry_token_.get()); |
| 5831 | EXPECT_FALSE(visitor_.retry_token_integrity_tag_.get()); |
| 5832 | EXPECT_FALSE(visitor_.retry_without_tag_.get()); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 5833 | } |
| 5834 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5835 | TEST_P(QuicFramerTest, BuildPaddingFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5836 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5837 | QuicPacketHeader header; |
| 5838 | header.destination_connection_id = FramerTestConnectionId(); |
| 5839 | header.reset_flag = false; |
| 5840 | header.version_flag = false; |
| 5841 | header.packet_number = kPacketNumber; |
| 5842 | |
| 5843 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 5844 | |
| 5845 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5846 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5847 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5848 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5849 | // connection_id |
| 5850 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5851 | // packet number |
| 5852 | 0x12, 0x34, 0x56, 0x78, |
| 5853 | |
| 5854 | // frame type (padding frame) |
| 5855 | 0x00, |
| 5856 | 0x00, 0x00, 0x00, 0x00 |
| 5857 | }; |
| 5858 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5859 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5860 | // type (short header, 4 byte packet number) |
| 5861 | 0x43, |
| 5862 | // connection_id |
| 5863 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5864 | // packet number |
| 5865 | 0x12, 0x34, 0x56, 0x78, |
| 5866 | |
| 5867 | // frame type (padding frame) |
| 5868 | 0x00, |
| 5869 | 0x00, 0x00, 0x00, 0x00 |
| 5870 | }; |
| 5871 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5872 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5873 | // type (short header, 4 byte packet number) |
| 5874 | 0x43, |
| 5875 | // connection_id |
| 5876 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5877 | // packet number |
| 5878 | 0x12, 0x34, 0x56, 0x78, |
| 5879 | |
| 5880 | // frame type (padding frame) |
| 5881 | 0x00, |
| 5882 | 0x00, 0x00, 0x00, 0x00 |
| 5883 | }; |
| 5884 | // clang-format on |
| 5885 | |
| 5886 | unsigned char* p = packet; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 5887 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5888 | p = packet99; |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 5889 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 5890 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5891 | } |
| 5892 | |
| 5893 | uint64_t header_size = GetPacketHeaderSize( |
| 5894 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 5895 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 5896 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 5897 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 5898 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5899 | |
| 5900 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5901 | ASSERT_TRUE(data != nullptr); |
| 5902 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 5903 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5904 | "constructed packet", data->data(), data->length(), AsChars(p), |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 5905 | framer_.transport_version() > QUIC_VERSION_43 ? QUICHE_ARRAYSIZE(packet46) |
| 5906 | : QUICHE_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5907 | } |
| 5908 | |
| 5909 | TEST_P(QuicFramerTest, BuildStreamFramePacketWithNewPaddingFrame) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5910 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5911 | QuicPacketHeader header; |
| 5912 | header.destination_connection_id = FramerTestConnectionId(); |
| 5913 | header.reset_flag = false; |
| 5914 | header.version_flag = false; |
| 5915 | header.packet_number = kPacketNumber; |
| 5916 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 5917 | quiche::QuicheStringPiece("hello world!")); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5918 | QuicPaddingFrame padding_frame(2); |
| 5919 | QuicFrames frames = {QuicFrame(padding_frame), QuicFrame(stream_frame), |
| 5920 | QuicFrame(padding_frame)}; |
| 5921 | |
| 5922 | // clang-format off |
| 5923 | unsigned char packet[] = { |
| 5924 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 5925 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5926 | // connection_id |
| 5927 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5928 | // packet number |
| 5929 | 0x12, 0x34, 0x56, 0x78, |
| 5930 | |
| 5931 | // paddings |
| 5932 | 0x00, 0x00, |
| 5933 | // frame type (stream frame with fin) |
| 5934 | 0xFF, |
| 5935 | // stream id |
| 5936 | 0x01, 0x02, 0x03, 0x04, |
| 5937 | // offset |
| 5938 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5939 | 0x32, 0x10, 0x76, 0x54, |
| 5940 | // data length |
| 5941 | 0x00, 0x0c, |
| 5942 | // data |
| 5943 | 'h', 'e', 'l', 'l', |
| 5944 | 'o', ' ', 'w', 'o', |
| 5945 | 'r', 'l', 'd', '!', |
| 5946 | // paddings |
| 5947 | 0x00, 0x00, |
| 5948 | }; |
| 5949 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5950 | unsigned char packet46[] = { |
| 5951 | // type (short header, 4 byte packet number) |
| 5952 | 0x43, |
| 5953 | // connection_id |
| 5954 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5955 | // packet number |
| 5956 | 0x12, 0x34, 0x56, 0x78, |
| 5957 | |
| 5958 | // paddings |
| 5959 | 0x00, 0x00, |
| 5960 | // frame type (stream frame with fin) |
| 5961 | 0xFF, |
| 5962 | // stream id |
| 5963 | 0x01, 0x02, 0x03, 0x04, |
| 5964 | // offset |
| 5965 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5966 | 0x32, 0x10, 0x76, 0x54, |
| 5967 | // data length |
| 5968 | 0x00, 0x0c, |
| 5969 | // data |
| 5970 | 'h', 'e', 'l', 'l', |
| 5971 | 'o', ' ', 'w', 'o', |
| 5972 | 'r', 'l', 'd', '!', |
| 5973 | // paddings |
| 5974 | 0x00, 0x00, |
| 5975 | }; |
| 5976 | |
| 5977 | unsigned char packet99[] = { |
| 5978 | // type (short header, 4 byte packet number) |
| 5979 | 0x43, |
| 5980 | // connection_id |
| 5981 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5982 | // packet number |
| 5983 | 0x12, 0x34, 0x56, 0x78, |
| 5984 | |
| 5985 | // paddings |
| 5986 | 0x00, 0x00, |
| 5987 | // frame type (IETF_STREAM with FIN, LEN, and OFFSET bits set) |
| 5988 | 0x08 | 0x01 | 0x02 | 0x04, |
| 5989 | // stream id |
| 5990 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 5991 | // offset |
| 5992 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 5993 | 0x32, 0x10, 0x76, 0x54, |
| 5994 | // data length |
| 5995 | kVarInt62OneByte + 0x0c, |
| 5996 | // data |
| 5997 | 'h', 'e', 'l', 'l', |
| 5998 | 'o', ' ', 'w', 'o', |
| 5999 | 'r', 'l', 'd', '!', |
| 6000 | // paddings |
| 6001 | 0x00, 0x00, |
| 6002 | }; |
| 6003 | // clang-format on |
| 6004 | |
| 6005 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6006 | ASSERT_TRUE(data != nullptr); |
| 6007 | |
| 6008 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6009 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 6010 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6011 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6012 | p_size = QUICHE_ARRAYSIZE(packet99); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 6013 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6014 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6015 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6016 | } |
| 6017 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 6018 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6019 | quiche::test::CompareCharArraysWithHexError( |
| 6020 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6021 | } |
| 6022 | |
| 6023 | TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6024 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6025 | QuicPacketHeader header; |
| 6026 | header.destination_connection_id = FramerTestConnectionId(); |
| 6027 | header.reset_flag = false; |
| 6028 | header.version_flag = false; |
| 6029 | header.packet_number_length = PACKET_4BYTE_PACKET_NUMBER; |
| 6030 | header.packet_number = kPacketNumber; |
| 6031 | |
| 6032 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 6033 | |
| 6034 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6035 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6036 | // public flags (8 byte connection_id and 4 byte packet number) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6037 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6038 | // connection_id |
| 6039 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6040 | // packet number |
| 6041 | 0x12, 0x34, 0x56, 0x78, |
| 6042 | |
| 6043 | // frame type (padding frame) |
| 6044 | 0x00, |
| 6045 | 0x00, 0x00, 0x00, 0x00 |
| 6046 | }; |
| 6047 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6048 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6049 | // type (short header, 4 byte packet number) |
| 6050 | 0x43, |
| 6051 | // connection_id |
| 6052 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6053 | // packet number |
| 6054 | 0x12, 0x34, 0x56, 0x78, |
| 6055 | |
| 6056 | // frame type (padding frame) |
| 6057 | 0x00, |
| 6058 | 0x00, 0x00, 0x00, 0x00 |
| 6059 | }; |
| 6060 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6061 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6062 | // type (short header, 4 byte packet number) |
| 6063 | 0x43, |
| 6064 | // connection_id |
| 6065 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6066 | // packet number |
| 6067 | 0x12, 0x34, 0x56, 0x78, |
| 6068 | |
| 6069 | // frame type (padding frame) |
| 6070 | 0x00, |
| 6071 | 0x00, 0x00, 0x00, 0x00 |
| 6072 | }; |
| 6073 | // clang-format on |
| 6074 | |
| 6075 | unsigned char* p = packet; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 6076 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6077 | p = packet99; |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 6078 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 6079 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6080 | } |
| 6081 | |
| 6082 | uint64_t header_size = GetPacketHeaderSize( |
| 6083 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 6084 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 6085 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 6086 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6087 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6088 | |
| 6089 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6090 | ASSERT_TRUE(data != nullptr); |
| 6091 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6092 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6093 | "constructed packet", data->data(), data->length(), AsChars(p), |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6094 | framer_.transport_version() > QUIC_VERSION_43 ? QUICHE_ARRAYSIZE(packet46) |
| 6095 | : QUICHE_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6096 | } |
| 6097 | |
| 6098 | TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6099 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6100 | QuicPacketHeader header; |
| 6101 | header.destination_connection_id = FramerTestConnectionId(); |
| 6102 | header.reset_flag = false; |
| 6103 | header.version_flag = false; |
| 6104 | header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER; |
| 6105 | header.packet_number = kPacketNumber; |
| 6106 | |
| 6107 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 6108 | |
| 6109 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6110 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6111 | // public flags (8 byte connection_id and 2 byte packet number) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6112 | 0x1C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6113 | // connection_id |
| 6114 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6115 | // packet number |
| 6116 | 0x56, 0x78, |
| 6117 | |
| 6118 | // frame type (padding frame) |
| 6119 | 0x00, |
| 6120 | 0x00, 0x00, 0x00, 0x00 |
| 6121 | }; |
| 6122 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6123 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6124 | // type (short header, 2 byte packet number) |
| 6125 | 0x41, |
| 6126 | // connection_id |
| 6127 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6128 | // packet number |
| 6129 | 0x56, 0x78, |
| 6130 | |
| 6131 | // frame type (padding frame) |
| 6132 | 0x00, |
| 6133 | 0x00, 0x00, 0x00, 0x00 |
| 6134 | }; |
| 6135 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6136 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6137 | // type (short header, 2 byte packet number) |
| 6138 | 0x41, |
| 6139 | // connection_id |
| 6140 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6141 | // packet number |
| 6142 | 0x56, 0x78, |
| 6143 | |
| 6144 | // frame type (padding frame) |
| 6145 | 0x00, |
| 6146 | 0x00, 0x00, 0x00, 0x00 |
| 6147 | }; |
| 6148 | // clang-format on |
| 6149 | |
| 6150 | unsigned char* p = packet; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 6151 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6152 | p = packet99; |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 6153 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 6154 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6155 | } |
| 6156 | |
| 6157 | uint64_t header_size = GetPacketHeaderSize( |
| 6158 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 6159 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 6160 | !kIncludeDiversificationNonce, PACKET_2BYTE_PACKET_NUMBER, |
| 6161 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6162 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6163 | |
| 6164 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6165 | ASSERT_TRUE(data != nullptr); |
| 6166 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6167 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6168 | "constructed packet", data->data(), data->length(), AsChars(p), |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6169 | framer_.transport_version() > QUIC_VERSION_43 ? QUICHE_ARRAYSIZE(packet46) |
| 6170 | : QUICHE_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6171 | } |
| 6172 | |
| 6173 | TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6174 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6175 | QuicPacketHeader header; |
| 6176 | header.destination_connection_id = FramerTestConnectionId(); |
| 6177 | header.reset_flag = false; |
| 6178 | header.version_flag = false; |
| 6179 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 6180 | header.packet_number = kPacketNumber; |
| 6181 | |
| 6182 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 6183 | |
| 6184 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6185 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6186 | // public flags (8 byte connection_id and 1 byte packet number) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6187 | 0x0C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6188 | // connection_id |
| 6189 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6190 | // packet number |
| 6191 | 0x78, |
| 6192 | |
| 6193 | // frame type (padding frame) |
| 6194 | 0x00, |
| 6195 | 0x00, 0x00, 0x00, 0x00 |
| 6196 | }; |
| 6197 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6198 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6199 | // type (short header, 1 byte packet number) |
| 6200 | 0x40, |
| 6201 | // connection_id |
| 6202 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6203 | // packet number |
| 6204 | 0x78, |
| 6205 | |
| 6206 | // frame type (padding frame) |
| 6207 | 0x00, |
| 6208 | 0x00, 0x00, 0x00, 0x00 |
| 6209 | }; |
| 6210 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6211 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6212 | // type (short header, 1 byte packet number) |
| 6213 | 0x40, |
| 6214 | // connection_id |
| 6215 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6216 | // packet number |
| 6217 | 0x78, |
| 6218 | |
| 6219 | // frame type (padding frame) |
| 6220 | 0x00, |
| 6221 | 0x00, 0x00, 0x00, 0x00 |
| 6222 | }; |
| 6223 | // clang-format on |
| 6224 | |
| 6225 | unsigned char* p = packet; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 6226 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6227 | p = packet99; |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 6228 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 6229 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6230 | } |
| 6231 | |
| 6232 | uint64_t header_size = GetPacketHeaderSize( |
| 6233 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 6234 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 6235 | !kIncludeDiversificationNonce, PACKET_1BYTE_PACKET_NUMBER, |
| 6236 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6237 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6238 | |
| 6239 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6240 | ASSERT_TRUE(data != nullptr); |
| 6241 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6242 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6243 | "constructed packet", data->data(), data->length(), AsChars(p), |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6244 | framer_.transport_version() > QUIC_VERSION_43 ? QUICHE_ARRAYSIZE(packet46) |
| 6245 | : QUICHE_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6246 | } |
| 6247 | |
| 6248 | TEST_P(QuicFramerTest, BuildStreamFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6249 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6250 | QuicPacketHeader header; |
| 6251 | header.destination_connection_id = FramerTestConnectionId(); |
| 6252 | header.reset_flag = false; |
| 6253 | header.version_flag = false; |
| 6254 | header.packet_number = kPacketNumber; |
| 6255 | if (QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 6256 | header.length_length = VARIABLE_LENGTH_INTEGER_LENGTH_2; |
| 6257 | } |
| 6258 | |
| 6259 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 6260 | quiche::QuicheStringPiece("hello world!")); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6261 | |
| 6262 | QuicFrames frames = {QuicFrame(stream_frame)}; |
| 6263 | |
| 6264 | // clang-format off |
| 6265 | unsigned char packet[] = { |
| 6266 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6267 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6268 | // connection_id |
| 6269 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6270 | // packet number |
| 6271 | 0x12, 0x34, 0x56, 0x78, |
| 6272 | |
| 6273 | // frame type (stream frame with fin and no length) |
| 6274 | 0xDF, |
| 6275 | // stream id |
| 6276 | 0x01, 0x02, 0x03, 0x04, |
| 6277 | // offset |
| 6278 | 0x3A, 0x98, 0xFE, 0xDC, |
| 6279 | 0x32, 0x10, 0x76, 0x54, |
| 6280 | // data |
| 6281 | 'h', 'e', 'l', 'l', |
| 6282 | 'o', ' ', 'w', 'o', |
| 6283 | 'r', 'l', 'd', '!', |
| 6284 | }; |
| 6285 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6286 | unsigned char packet46[] = { |
| 6287 | // type (short header, 4 byte packet number) |
| 6288 | 0x43, |
| 6289 | // connection_id |
| 6290 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6291 | // packet number |
| 6292 | 0x12, 0x34, 0x56, 0x78, |
| 6293 | |
| 6294 | // frame type (stream frame with fin and no length) |
| 6295 | 0xDF, |
| 6296 | // stream id |
| 6297 | 0x01, 0x02, 0x03, 0x04, |
| 6298 | // offset |
| 6299 | 0x3A, 0x98, 0xFE, 0xDC, |
| 6300 | 0x32, 0x10, 0x76, 0x54, |
| 6301 | // data |
| 6302 | 'h', 'e', 'l', 'l', |
| 6303 | 'o', ' ', 'w', 'o', |
| 6304 | 'r', 'l', 'd', '!', |
| 6305 | }; |
| 6306 | |
| 6307 | unsigned char packet99[] = { |
| 6308 | // type (short header, 4 byte packet number) |
| 6309 | 0x43, |
| 6310 | // connection_id |
| 6311 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6312 | // packet number |
| 6313 | 0x12, 0x34, 0x56, 0x78, |
| 6314 | |
| 6315 | // frame type (IETF_STREAM frame with FIN and OFFSET, no length) |
| 6316 | 0x08 | 0x01 | 0x04, |
| 6317 | // stream id |
| 6318 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 6319 | // offset |
| 6320 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6321 | 0x32, 0x10, 0x76, 0x54, |
| 6322 | // data |
| 6323 | 'h', 'e', 'l', 'l', |
| 6324 | 'o', ' ', 'w', 'o', |
| 6325 | 'r', 'l', 'd', '!', |
| 6326 | }; |
| 6327 | // clang-format on |
| 6328 | |
| 6329 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6330 | ASSERT_TRUE(data != nullptr); |
| 6331 | |
| 6332 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6333 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 6334 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6335 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6336 | p_size = QUICHE_ARRAYSIZE(packet99); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 6337 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6338 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6339 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6340 | } |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6341 | quiche::test::CompareCharArraysWithHexError( |
| 6342 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6343 | } |
| 6344 | |
| 6345 | TEST_P(QuicFramerTest, BuildStreamFramePacketWithVersionFlag) { |
| 6346 | QuicPacketHeader header; |
| 6347 | header.destination_connection_id = FramerTestConnectionId(); |
| 6348 | header.reset_flag = false; |
| 6349 | header.version_flag = true; |
| 6350 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6351 | header.long_packet_type = ZERO_RTT_PROTECTED; |
| 6352 | } |
| 6353 | header.packet_number = kPacketNumber; |
| 6354 | if (QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 6355 | header.length_length = VARIABLE_LENGTH_INTEGER_LENGTH_2; |
| 6356 | } |
| 6357 | |
| 6358 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 6359 | quiche::QuicheStringPiece("hello world!")); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6360 | QuicFrames frames = {QuicFrame(stream_frame)}; |
| 6361 | |
| 6362 | // clang-format off |
| 6363 | unsigned char packet[] = { |
| 6364 | // public flags (version, 8 byte connection_id) |
| 6365 | 0x2D, |
| 6366 | // connection_id |
| 6367 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6368 | // version tag |
| 6369 | QUIC_VERSION_BYTES, |
| 6370 | // packet number |
| 6371 | 0x12, 0x34, 0x56, 0x78, |
| 6372 | |
| 6373 | // frame type (stream frame with fin and no length) |
| 6374 | 0xDF, |
| 6375 | // stream id |
| 6376 | 0x01, 0x02, 0x03, 0x04, |
| 6377 | // offset |
| 6378 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6379 | // data |
| 6380 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6381 | }; |
| 6382 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6383 | unsigned char packet46[] = { |
| 6384 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 6385 | 0xD3, |
| 6386 | // version tag |
| 6387 | QUIC_VERSION_BYTES, |
| 6388 | // connection_id length |
| 6389 | 0x50, |
| 6390 | // connection_id |
| 6391 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6392 | // packet number |
| 6393 | 0x12, 0x34, 0x56, 0x78, |
| 6394 | |
| 6395 | // frame type (stream frame with fin and no length) |
| 6396 | 0xDF, |
| 6397 | // stream id |
| 6398 | 0x01, 0x02, 0x03, 0x04, |
| 6399 | // offset |
| 6400 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6401 | // data |
| 6402 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6403 | }; |
| 6404 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 6405 | unsigned char packet49[] = { |
| 6406 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 6407 | 0xD3, |
| 6408 | // version tag |
| 6409 | QUIC_VERSION_BYTES, |
| 6410 | // destination connection ID length |
| 6411 | 0x08, |
| 6412 | // destination connection ID |
| 6413 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6414 | // source connection ID length |
| 6415 | 0x00, |
| 6416 | // length |
| 6417 | 0x40, 0x1D, |
| 6418 | // packet number |
| 6419 | 0x12, 0x34, 0x56, 0x78, |
| 6420 | |
| 6421 | // frame type (stream frame with fin and no length) |
| 6422 | 0xDF, |
| 6423 | // stream id |
| 6424 | 0x01, 0x02, 0x03, 0x04, |
| 6425 | // offset |
| 6426 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6427 | // data |
| 6428 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6429 | }; |
| 6430 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6431 | unsigned char packet99[] = { |
| 6432 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 6433 | 0xD3, |
| 6434 | // version tag |
| 6435 | QUIC_VERSION_BYTES, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 6436 | // destination connection ID length |
| 6437 | 0x08, |
| 6438 | // destination connection ID |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6439 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 6440 | // source connection ID length |
| 6441 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6442 | // length |
| 6443 | 0x40, 0x1D, |
| 6444 | // packet number |
| 6445 | 0x12, 0x34, 0x56, 0x78, |
| 6446 | |
| 6447 | // frame type (IETF_STREAM frame with fin and offset, no length) |
| 6448 | 0x08 | 0x01 | 0x04, |
| 6449 | // stream id |
| 6450 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 6451 | // offset |
| 6452 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6453 | // data |
| 6454 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6455 | }; |
| 6456 | // clang-format on |
| 6457 | |
| 6458 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 6459 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6460 | ASSERT_TRUE(data != nullptr); |
| 6461 | |
| 6462 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6463 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 6464 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6465 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6466 | p_size = QUICHE_ARRAYSIZE(packet99); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 6467 | } else if (framer_.transport_version() >= QUIC_VERSION_49) { |
| 6468 | p = packet49; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6469 | p_size = QUICHE_ARRAYSIZE(packet49); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 6470 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6471 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6472 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6473 | } |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6474 | quiche::test::CompareCharArraysWithHexError( |
| 6475 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6476 | } |
| 6477 | |
| 6478 | TEST_P(QuicFramerTest, BuildCryptoFramePacket) { |
fkastenholz | ceae837 | 2019-06-12 12:22:22 -0700 | [diff] [blame] | 6479 | if (!QuicVersionUsesCryptoFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6480 | return; |
| 6481 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6482 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6483 | QuicPacketHeader header; |
| 6484 | header.destination_connection_id = FramerTestConnectionId(); |
| 6485 | header.reset_flag = false; |
| 6486 | header.version_flag = false; |
| 6487 | header.packet_number = kPacketNumber; |
| 6488 | |
| 6489 | SimpleDataProducer data_producer; |
| 6490 | framer_.set_data_producer(&data_producer); |
| 6491 | |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 6492 | quiche::QuicheStringPiece crypto_frame_contents("hello world!"); |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 6493 | QuicCryptoFrame crypto_frame(ENCRYPTION_INITIAL, kStreamOffset, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6494 | crypto_frame_contents.length()); |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 6495 | data_producer.SaveCryptoData(ENCRYPTION_INITIAL, kStreamOffset, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6496 | crypto_frame_contents); |
| 6497 | |
| 6498 | QuicFrames frames = {QuicFrame(&crypto_frame)}; |
| 6499 | |
| 6500 | // clang-format off |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6501 | unsigned char packet48[] = { |
| 6502 | // type (short header, 4 byte packet number) |
| 6503 | 0x43, |
| 6504 | // connection_id |
| 6505 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6506 | // packet number |
| 6507 | 0x12, 0x34, 0x56, 0x78, |
| 6508 | |
| 6509 | // frame type (QuicFrameType CRYPTO_FRAME) |
| 6510 | 0x08, |
| 6511 | // offset |
| 6512 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6513 | 0x32, 0x10, 0x76, 0x54, |
| 6514 | // length |
| 6515 | kVarInt62OneByte + 12, |
| 6516 | // data |
| 6517 | 'h', 'e', 'l', 'l', |
| 6518 | 'o', ' ', 'w', 'o', |
| 6519 | 'r', 'l', 'd', '!', |
| 6520 | }; |
| 6521 | |
| 6522 | unsigned char packet99[] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6523 | // type (short header, 4 byte packet number) |
| 6524 | 0x43, |
| 6525 | // connection_id |
| 6526 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6527 | // packet number |
| 6528 | 0x12, 0x34, 0x56, 0x78, |
| 6529 | |
| 6530 | // frame type (IETF_CRYPTO frame) |
| 6531 | 0x06, |
| 6532 | // offset |
| 6533 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6534 | 0x32, 0x10, 0x76, 0x54, |
| 6535 | // length |
| 6536 | kVarInt62OneByte + 12, |
| 6537 | // data |
| 6538 | 'h', 'e', 'l', 'l', |
| 6539 | 'o', ' ', 'w', 'o', |
| 6540 | 'r', 'l', 'd', '!', |
| 6541 | }; |
| 6542 | // clang-format on |
| 6543 | |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6544 | unsigned char* packet = packet48; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6545 | size_t packet_size = QUICHE_ARRAYSIZE(packet48); |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6546 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6547 | packet = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6548 | packet_size = QUICHE_ARRAYSIZE(packet99); |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6549 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6550 | |
| 6551 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6552 | ASSERT_TRUE(data != nullptr); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6553 | quiche::test::CompareCharArraysWithHexError("constructed packet", |
| 6554 | data->data(), data->length(), |
| 6555 | AsChars(packet), packet_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6556 | } |
| 6557 | |
| 6558 | TEST_P(QuicFramerTest, CryptoFrame) { |
renjietang | 15dfaa8 | 2020-01-03 16:13:38 -0800 | [diff] [blame] | 6559 | if (!QuicVersionUsesCryptoFrames(framer_.transport_version())) { |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6560 | // CRYPTO frames aren't supported prior to v48. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6561 | return; |
| 6562 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 6563 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6564 | |
| 6565 | // clang-format off |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6566 | PacketFragments packet48 = { |
| 6567 | // type (short header, 4 byte packet number) |
| 6568 | {"", |
| 6569 | {0x43}}, |
| 6570 | // connection_id |
| 6571 | {"", |
| 6572 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 6573 | // packet number |
| 6574 | {"", |
| 6575 | {0x12, 0x34, 0x56, 0x78}}, |
| 6576 | // frame type (QuicFrameType CRYPTO_FRAME) |
| 6577 | {"", |
| 6578 | {0x08}}, |
| 6579 | // offset |
| 6580 | {"", |
| 6581 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6582 | 0x32, 0x10, 0x76, 0x54}}, |
| 6583 | // data length |
| 6584 | {"Invalid data length.", |
| 6585 | {kVarInt62OneByte + 12}}, |
| 6586 | // data |
| 6587 | {"Unable to read frame data.", |
| 6588 | {'h', 'e', 'l', 'l', |
| 6589 | 'o', ' ', 'w', 'o', |
| 6590 | 'r', 'l', 'd', '!'}}, |
| 6591 | }; |
| 6592 | |
| 6593 | PacketFragments packet99 = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6594 | // type (short header, 4 byte packet number) |
| 6595 | {"", |
| 6596 | {0x43}}, |
| 6597 | // connection_id |
| 6598 | {"", |
| 6599 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 6600 | // packet number |
| 6601 | {"", |
| 6602 | {0x12, 0x34, 0x56, 0x78}}, |
| 6603 | // frame type (IETF_CRYPTO frame) |
| 6604 | {"", |
| 6605 | {0x06}}, |
| 6606 | // offset |
| 6607 | {"", |
| 6608 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6609 | 0x32, 0x10, 0x76, 0x54}}, |
| 6610 | // data length |
| 6611 | {"Invalid data length.", |
| 6612 | {kVarInt62OneByte + 12}}, |
| 6613 | // data |
| 6614 | {"Unable to read frame data.", |
| 6615 | {'h', 'e', 'l', 'l', |
| 6616 | 'o', ' ', 'w', 'o', |
| 6617 | 'r', 'l', 'd', '!'}}, |
| 6618 | }; |
| 6619 | // clang-format on |
| 6620 | |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6621 | PacketFragments& fragments = |
| 6622 | framer_.transport_version() == QUIC_VERSION_99 ? packet99 : packet48; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6623 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6624 | AssemblePacketFromFragments(fragments)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6625 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 6626 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 6627 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6628 | ASSERT_TRUE(visitor_.header_.get()); |
| 6629 | EXPECT_TRUE(CheckDecryption( |
| 6630 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 6631 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 6632 | ASSERT_EQ(1u, visitor_.crypto_frames_.size()); |
| 6633 | QuicCryptoFrame* frame = visitor_.crypto_frames_[0].get(); |
renjietang | 15dfaa8 | 2020-01-03 16:13:38 -0800 | [diff] [blame] | 6634 | EXPECT_EQ(ENCRYPTION_FORWARD_SECURE, frame->level); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6635 | EXPECT_EQ(kStreamOffset, frame->offset); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 6636 | EXPECT_EQ("hello world!", |
| 6637 | std::string(frame->data_buffer, frame->data_length)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6638 | |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6639 | CheckFramingBoundaries(fragments, QUIC_INVALID_FRAME_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6640 | } |
| 6641 | |
| 6642 | TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) { |
dschinazi | 1ac22cc | 2019-06-25 11:47:50 -0700 | [diff] [blame] | 6643 | SetQuicFlag(FLAGS_quic_disable_version_negotiation_grease_randomness, true); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6644 | // clang-format off |
| 6645 | unsigned char packet[] = { |
| 6646 | // public flags (version, 8 byte connection_id) |
| 6647 | 0x0D, |
| 6648 | // connection_id |
| 6649 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 1ac22cc | 2019-06-25 11:47:50 -0700 | [diff] [blame] | 6650 | // supported versions |
| 6651 | 0xDA, 0x5A, 0x3A, 0x3A, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6652 | QUIC_VERSION_BYTES, |
| 6653 | }; |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 6654 | unsigned char packet46[] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6655 | // type (long header) |
dschinazi | 0366de9 | 2019-06-18 20:00:27 -0700 | [diff] [blame] | 6656 | 0xC0, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6657 | // version tag |
| 6658 | 0x00, 0x00, 0x00, 0x00, |
| 6659 | // connection_id length |
| 6660 | 0x05, |
| 6661 | // connection_id |
| 6662 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 1ac22cc | 2019-06-25 11:47:50 -0700 | [diff] [blame] | 6663 | // supported versions |
| 6664 | 0xDA, 0x5A, 0x3A, 0x3A, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6665 | QUIC_VERSION_BYTES, |
| 6666 | }; |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 6667 | unsigned char packet49[] = { |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 6668 | // type (long header) |
| 6669 | 0xC0, |
| 6670 | // version tag |
| 6671 | 0x00, 0x00, 0x00, 0x00, |
| 6672 | // destination connection ID length |
| 6673 | 0x00, |
| 6674 | // source connection ID length |
| 6675 | 0x08, |
| 6676 | // source connection ID |
| 6677 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6678 | // supported versions |
| 6679 | 0xDA, 0x5A, 0x3A, 0x3A, |
| 6680 | QUIC_VERSION_BYTES, |
| 6681 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6682 | // clang-format on |
| 6683 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6684 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 6685 | if (framer_.transport_version() >= QUIC_VERSION_49) { |
| 6686 | p = packet49; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6687 | p_size = QUICHE_ARRAYSIZE(packet49); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 6688 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 6689 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6690 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6691 | } |
| 6692 | |
| 6693 | QuicConnectionId connection_id = FramerTestConnectionId(); |
| 6694 | std::unique_ptr<QuicEncryptedPacket> data( |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 6695 | QuicFramer::BuildVersionNegotiationPacket( |
| 6696 | connection_id, EmptyQuicConnectionId(), |
| 6697 | framer_.transport_version() > QUIC_VERSION_43, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 6698 | framer_.version().HasLengthPrefixedConnectionIds(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6699 | SupportedVersions(GetParam()))); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6700 | quiche::test::CompareCharArraysWithHexError( |
| 6701 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6702 | } |
| 6703 | |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 6704 | TEST_P(QuicFramerTest, BuildVersionNegotiationPacketWithClientConnectionId) { |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 6705 | if (!framer_.version().SupportsClientConnectionIds()) { |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 6706 | return; |
| 6707 | } |
| 6708 | |
dschinazi | 1ac22cc | 2019-06-25 11:47:50 -0700 | [diff] [blame] | 6709 | SetQuicFlag(FLAGS_quic_disable_version_negotiation_grease_randomness, true); |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 6710 | |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 6711 | // clang-format off |
| 6712 | unsigned char packet[] = { |
| 6713 | // type (long header) |
dschinazi | 0366de9 | 2019-06-18 20:00:27 -0700 | [diff] [blame] | 6714 | 0xC0, |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 6715 | // version tag |
| 6716 | 0x00, 0x00, 0x00, 0x00, |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 6717 | // client/destination connection ID |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 6718 | 0x08, |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 6719 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 6720 | // server/source connection ID |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 6721 | 0x08, |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 6722 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 1ac22cc | 2019-06-25 11:47:50 -0700 | [diff] [blame] | 6723 | // supported versions |
| 6724 | 0xDA, 0x5A, 0x3A, 0x3A, |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 6725 | QUIC_VERSION_BYTES, |
| 6726 | }; |
| 6727 | // clang-format on |
| 6728 | |
| 6729 | QuicConnectionId server_connection_id = FramerTestConnectionId(); |
| 6730 | QuicConnectionId client_connection_id = FramerTestConnectionIdPlusOne(); |
| 6731 | std::unique_ptr<QuicEncryptedPacket> data( |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 6732 | QuicFramer::BuildVersionNegotiationPacket( |
| 6733 | server_connection_id, client_connection_id, true, true, |
| 6734 | SupportedVersions(GetParam()))); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6735 | quiche::test::CompareCharArraysWithHexError( |
| 6736 | "constructed packet", data->data(), data->length(), AsChars(packet), |
| 6737 | QUICHE_ARRAYSIZE(packet)); |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 6738 | } |
| 6739 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6740 | TEST_P(QuicFramerTest, BuildAckFramePacketOneAckBlock) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6741 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6742 | QuicPacketHeader header; |
| 6743 | header.destination_connection_id = FramerTestConnectionId(); |
| 6744 | header.reset_flag = false; |
| 6745 | header.version_flag = false; |
| 6746 | header.packet_number = kPacketNumber; |
| 6747 | |
| 6748 | // Use kSmallLargestObserved to make this test finished in a short time. |
| 6749 | QuicAckFrame ack_frame = InitAckFrame(kSmallLargestObserved); |
| 6750 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 6751 | |
| 6752 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 6753 | |
| 6754 | // clang-format off |
| 6755 | unsigned char packet[] = { |
| 6756 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6757 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6758 | // connection_id |
| 6759 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6760 | // packet number |
| 6761 | 0x12, 0x34, 0x56, 0x78, |
| 6762 | |
| 6763 | // frame type (ack frame) |
| 6764 | // (no ack blocks, 2 byte largest observed, 2 byte block length) |
| 6765 | 0x45, |
| 6766 | // largest acked |
| 6767 | 0x12, 0x34, |
| 6768 | // Zero delta time. |
| 6769 | 0x00, 0x00, |
| 6770 | // first ack block length. |
| 6771 | 0x12, 0x34, |
| 6772 | // num timestamps. |
| 6773 | 0x00, |
| 6774 | }; |
| 6775 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6776 | unsigned char packet46[] = { |
| 6777 | // type (short header, 4 byte packet number) |
| 6778 | 0x43, |
| 6779 | // connection_id |
| 6780 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6781 | // packet number |
| 6782 | 0x12, 0x34, 0x56, 0x78, |
| 6783 | |
| 6784 | // frame type (ack frame) |
| 6785 | // (no ack blocks, 2 byte largest observed, 2 byte block length) |
| 6786 | 0x45, |
| 6787 | // largest acked |
| 6788 | 0x12, 0x34, |
| 6789 | // Zero delta time. |
| 6790 | 0x00, 0x00, |
| 6791 | // first ack block length. |
| 6792 | 0x12, 0x34, |
| 6793 | // num timestamps. |
| 6794 | 0x00, |
| 6795 | }; |
| 6796 | |
| 6797 | unsigned char packet99[] = { |
| 6798 | // type (short header, 4 byte packet number) |
| 6799 | 0x43, |
| 6800 | // connection_id |
| 6801 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6802 | // packet number |
| 6803 | 0x12, 0x34, 0x56, 0x78, |
| 6804 | |
| 6805 | // frame type (IETF_ACK frame) |
| 6806 | 0x02, |
| 6807 | // largest acked |
| 6808 | kVarInt62TwoBytes + 0x12, 0x34, |
| 6809 | // Zero delta time. |
| 6810 | kVarInt62OneByte + 0x00, |
| 6811 | // Number of additional ack blocks. |
| 6812 | kVarInt62OneByte + 0x00, |
| 6813 | // first ack block length. |
| 6814 | kVarInt62TwoBytes + 0x12, 0x33, |
| 6815 | }; |
| 6816 | // clang-format on |
| 6817 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6818 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 6819 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6820 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6821 | p_size = QUICHE_ARRAYSIZE(packet99); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 6822 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6823 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6824 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6825 | } |
| 6826 | |
| 6827 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6828 | ASSERT_TRUE(data != nullptr); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6829 | quiche::test::CompareCharArraysWithHexError( |
| 6830 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6831 | } |
| 6832 | |
| 6833 | TEST_P(QuicFramerTest, BuildAckFramePacketOneAckBlockMaxLength) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6834 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6835 | QuicPacketHeader header; |
| 6836 | header.destination_connection_id = FramerTestConnectionId(); |
| 6837 | header.reset_flag = false; |
| 6838 | header.version_flag = false; |
| 6839 | header.packet_number = kPacketNumber; |
| 6840 | |
| 6841 | QuicAckFrame ack_frame = InitAckFrame(kPacketNumber); |
| 6842 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 6843 | |
| 6844 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 6845 | |
| 6846 | // clang-format off |
| 6847 | unsigned char packet[] = { |
| 6848 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6849 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6850 | // connection_id |
| 6851 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6852 | // packet number |
| 6853 | 0x12, 0x34, 0x56, 0x78, |
| 6854 | |
| 6855 | // frame type (ack frame) |
| 6856 | // (no ack blocks, 4 byte largest observed, 4 byte block length) |
| 6857 | 0x4A, |
| 6858 | // largest acked |
| 6859 | 0x12, 0x34, 0x56, 0x78, |
| 6860 | // Zero delta time. |
| 6861 | 0x00, 0x00, |
| 6862 | // first ack block length. |
| 6863 | 0x12, 0x34, 0x56, 0x78, |
| 6864 | // num timestamps. |
| 6865 | 0x00, |
| 6866 | }; |
| 6867 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6868 | unsigned char packet46[] = { |
| 6869 | // type (short header, 4 byte packet number) |
| 6870 | 0x43, |
| 6871 | // connection_id |
| 6872 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6873 | // packet number |
| 6874 | 0x12, 0x34, 0x56, 0x78, |
| 6875 | |
| 6876 | // frame type (ack frame) |
| 6877 | // (no ack blocks, 4 byte largest observed, 4 byte block length) |
| 6878 | 0x4A, |
| 6879 | // largest acked |
| 6880 | 0x12, 0x34, 0x56, 0x78, |
| 6881 | // Zero delta time. |
| 6882 | 0x00, 0x00, |
| 6883 | // first ack block length. |
| 6884 | 0x12, 0x34, 0x56, 0x78, |
| 6885 | // num timestamps. |
| 6886 | 0x00, |
| 6887 | }; |
| 6888 | |
| 6889 | |
| 6890 | unsigned char packet99[] = { |
| 6891 | // type (short header, 4 byte packet number) |
| 6892 | 0x43, |
| 6893 | // connection_id |
| 6894 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6895 | // packet number |
| 6896 | 0x12, 0x34, 0x56, 0x78, |
| 6897 | |
| 6898 | // frame type (IETF_ACK frame) |
| 6899 | 0x02, |
| 6900 | // largest acked |
| 6901 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78, |
| 6902 | // Zero delta time. |
| 6903 | kVarInt62OneByte + 0x00, |
| 6904 | // Nr. of additional ack blocks |
| 6905 | kVarInt62OneByte + 0x00, |
| 6906 | // first ack block length. |
| 6907 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x77, |
| 6908 | }; |
| 6909 | // clang-format on |
| 6910 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6911 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 6912 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6913 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6914 | p_size = QUICHE_ARRAYSIZE(packet99); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 6915 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6916 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 6917 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6918 | } |
| 6919 | |
| 6920 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6921 | ASSERT_TRUE(data != nullptr); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6922 | quiche::test::CompareCharArraysWithHexError( |
| 6923 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6924 | } |
| 6925 | |
| 6926 | TEST_P(QuicFramerTest, BuildAckFramePacketMultipleAckBlocks) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6927 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6928 | QuicPacketHeader header; |
| 6929 | header.destination_connection_id = FramerTestConnectionId(); |
| 6930 | header.reset_flag = false; |
| 6931 | header.version_flag = false; |
| 6932 | header.packet_number = kPacketNumber; |
| 6933 | |
| 6934 | // Use kSmallLargestObserved to make this test finished in a short time. |
| 6935 | QuicAckFrame ack_frame = |
| 6936 | InitAckFrame({{QuicPacketNumber(1), QuicPacketNumber(5)}, |
| 6937 | {QuicPacketNumber(10), QuicPacketNumber(500)}, |
| 6938 | {QuicPacketNumber(900), kSmallMissingPacket}, |
| 6939 | {kSmallMissingPacket + 1, kSmallLargestObserved + 1}}); |
| 6940 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 6941 | |
| 6942 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 6943 | |
| 6944 | // clang-format off |
| 6945 | unsigned char packet[] = { |
| 6946 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6947 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6948 | // connection_id |
| 6949 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6950 | // packet number |
| 6951 | 0x12, 0x34, 0x56, 0x78, |
| 6952 | |
| 6953 | // frame type (ack frame) |
| 6954 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 6955 | 0x65, |
| 6956 | // largest acked |
| 6957 | 0x12, 0x34, |
| 6958 | // Zero delta time. |
| 6959 | 0x00, 0x00, |
| 6960 | // num ack blocks ranges. |
| 6961 | 0x04, |
| 6962 | // first ack block length. |
| 6963 | 0x00, 0x01, |
| 6964 | // gap to next block. |
| 6965 | 0x01, |
| 6966 | // ack block length. |
| 6967 | 0x0e, 0xaf, |
| 6968 | // gap to next block. |
| 6969 | 0xff, |
| 6970 | // ack block length. |
| 6971 | 0x00, 0x00, |
| 6972 | // gap to next block. |
| 6973 | 0x91, |
| 6974 | // ack block length. |
| 6975 | 0x01, 0xea, |
| 6976 | // gap to next block. |
| 6977 | 0x05, |
| 6978 | // ack block length. |
| 6979 | 0x00, 0x04, |
| 6980 | // num timestamps. |
| 6981 | 0x00, |
| 6982 | }; |
| 6983 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6984 | unsigned char packet46[] = { |
| 6985 | // type (short header, 4 byte packet number) |
| 6986 | 0x43, |
| 6987 | // connection_id |
| 6988 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6989 | // packet number |
| 6990 | 0x12, 0x34, 0x56, 0x78, |
| 6991 | |
| 6992 | // frame type (ack frame) |
| 6993 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 6994 | 0x65, |
| 6995 | // largest acked |
| 6996 | 0x12, 0x34, |
| 6997 | // Zero delta time. |
| 6998 | 0x00, 0x00, |
| 6999 | // num ack blocks ranges. |
| 7000 | 0x04, |
| 7001 | // first ack block length. |
| 7002 | 0x00, 0x01, |
| 7003 | // gap to next block. |
| 7004 | 0x01, |
| 7005 | // ack block length. |
| 7006 | 0x0e, 0xaf, |
| 7007 | // gap to next block. |
| 7008 | 0xff, |
| 7009 | // ack block length. |
| 7010 | 0x00, 0x00, |
| 7011 | // gap to next block. |
| 7012 | 0x91, |
| 7013 | // ack block length. |
| 7014 | 0x01, 0xea, |
| 7015 | // gap to next block. |
| 7016 | 0x05, |
| 7017 | // ack block length. |
| 7018 | 0x00, 0x04, |
| 7019 | // num timestamps. |
| 7020 | 0x00, |
| 7021 | }; |
| 7022 | |
| 7023 | unsigned char packet99[] = { |
| 7024 | // type (short header, 4 byte packet number) |
| 7025 | 0x43, |
| 7026 | // connection_id |
| 7027 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7028 | // packet number |
| 7029 | 0x12, 0x34, 0x56, 0x78, |
| 7030 | |
| 7031 | // frame type (IETF_ACK frame) |
| 7032 | 0x02, |
| 7033 | // largest acked |
| 7034 | kVarInt62TwoBytes + 0x12, 0x34, |
| 7035 | // Zero delta time. |
| 7036 | kVarInt62OneByte + 0x00, |
| 7037 | // num additional ack blocks. |
| 7038 | kVarInt62OneByte + 0x03, |
| 7039 | // first ack block length. |
| 7040 | kVarInt62OneByte + 0x00, |
| 7041 | |
| 7042 | // gap to next block. |
| 7043 | kVarInt62OneByte + 0x00, |
| 7044 | // ack block length. |
| 7045 | kVarInt62TwoBytes + 0x0e, 0xae, |
| 7046 | |
| 7047 | // gap to next block. |
| 7048 | kVarInt62TwoBytes + 0x01, 0x8f, |
| 7049 | // ack block length. |
| 7050 | kVarInt62TwoBytes + 0x01, 0xe9, |
| 7051 | |
| 7052 | // gap to next block. |
| 7053 | kVarInt62OneByte + 0x04, |
| 7054 | // ack block length. |
| 7055 | kVarInt62OneByte + 0x03, |
| 7056 | }; |
| 7057 | // clang-format on |
| 7058 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7059 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 7060 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7061 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7062 | p_size = QUICHE_ARRAYSIZE(packet99); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 7063 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7064 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7065 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7066 | } |
| 7067 | |
| 7068 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7069 | ASSERT_TRUE(data != nullptr); |
| 7070 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 7071 | quiche::test::CompareCharArraysWithHexError( |
| 7072 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7073 | } |
| 7074 | |
| 7075 | TEST_P(QuicFramerTest, BuildAckFramePacketMaxAckBlocks) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7076 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7077 | QuicPacketHeader header; |
| 7078 | header.destination_connection_id = FramerTestConnectionId(); |
| 7079 | header.reset_flag = false; |
| 7080 | header.version_flag = false; |
| 7081 | header.packet_number = kPacketNumber; |
| 7082 | |
| 7083 | // Use kSmallLargestObservedto make this test finished in a short time. |
| 7084 | QuicAckFrame ack_frame; |
| 7085 | ack_frame.largest_acked = kSmallLargestObserved; |
| 7086 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 7087 | // 300 ack blocks. |
| 7088 | for (size_t i = 2; i < 2 * 300; i += 2) { |
| 7089 | ack_frame.packets.Add(QuicPacketNumber(i)); |
| 7090 | } |
| 7091 | ack_frame.packets.AddRange(QuicPacketNumber(600), kSmallLargestObserved + 1); |
| 7092 | |
| 7093 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 7094 | |
| 7095 | // clang-format off |
| 7096 | unsigned char packet[] = { |
| 7097 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7098 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7099 | // connection_id |
| 7100 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7101 | // packet number |
| 7102 | 0x12, 0x34, 0x56, 0x78, |
| 7103 | // frame type (ack frame) |
| 7104 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 7105 | 0x65, |
| 7106 | // largest acked |
| 7107 | 0x12, 0x34, |
| 7108 | // Zero delta time. |
| 7109 | 0x00, 0x00, |
| 7110 | // num ack blocks ranges. |
| 7111 | 0xff, |
| 7112 | // first ack block length. |
| 7113 | 0x0f, 0xdd, |
| 7114 | // 255 = 4 * 63 + 3 |
| 7115 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7116 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7117 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7118 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7119 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7120 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7121 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7122 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7123 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7124 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7125 | |
| 7126 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7127 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7128 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7129 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7130 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7131 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7132 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7133 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7134 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7135 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7136 | |
| 7137 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7138 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7139 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7140 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7141 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7142 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7143 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7144 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7145 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7146 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7147 | |
| 7148 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7149 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7150 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7151 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7152 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7153 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7154 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7155 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7156 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7157 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7158 | |
| 7159 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7160 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7161 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7162 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7163 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7164 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7165 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7166 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7167 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7168 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7169 | |
| 7170 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7171 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7172 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7173 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7174 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7175 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7176 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7177 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7178 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7179 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7180 | |
| 7181 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7182 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7183 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7184 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7185 | // num timestamps. |
| 7186 | 0x00, |
| 7187 | }; |
| 7188 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7189 | unsigned char packet46[] = { |
| 7190 | // type (short header, 4 byte packet number) |
| 7191 | 0x43, |
| 7192 | // connection_id |
| 7193 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7194 | // packet number |
| 7195 | 0x12, 0x34, 0x56, 0x78, |
| 7196 | // frame type (ack frame) |
| 7197 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 7198 | 0x65, |
| 7199 | // largest acked |
| 7200 | 0x12, 0x34, |
| 7201 | // Zero delta time. |
| 7202 | 0x00, 0x00, |
| 7203 | // num ack blocks ranges. |
| 7204 | 0xff, |
| 7205 | // first ack block length. |
| 7206 | 0x0f, 0xdd, |
| 7207 | // 255 = 4 * 63 + 3 |
| 7208 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7209 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7210 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7211 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7212 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7213 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7214 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7215 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7216 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7217 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7218 | |
| 7219 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7220 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7221 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7222 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7223 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7224 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7225 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7226 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7227 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7228 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7229 | |
| 7230 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7231 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7232 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7233 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7234 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7235 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7236 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7237 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7238 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7239 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7240 | |
| 7241 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7242 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7243 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7244 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7245 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7246 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7247 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7248 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7249 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7250 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7251 | |
| 7252 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7253 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7254 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7255 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7256 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7257 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7258 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7259 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7260 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7261 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7262 | |
| 7263 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7264 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7265 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7266 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7267 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7268 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7269 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7270 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7271 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7272 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7273 | |
| 7274 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7275 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7276 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7277 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7278 | // num timestamps. |
| 7279 | 0x00, |
| 7280 | }; |
| 7281 | |
| 7282 | unsigned char packet99[] = { |
| 7283 | // type (short header, 4 byte packet number) |
| 7284 | 0x43, |
| 7285 | // connection_id |
| 7286 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7287 | // packet number |
| 7288 | 0x12, 0x34, 0x56, 0x78, |
| 7289 | // frame type (IETF_ACK frame) |
| 7290 | 0x02, |
| 7291 | // largest acked |
| 7292 | kVarInt62TwoBytes + 0x12, 0x34, |
| 7293 | // Zero delta time. |
| 7294 | kVarInt62OneByte + 0x00, |
| 7295 | // num ack blocks ranges. |
| 7296 | kVarInt62TwoBytes + 0x01, 0x2b, |
| 7297 | // first ack block length. |
| 7298 | kVarInt62TwoBytes + 0x0f, 0xdc, |
| 7299 | // 255 added blocks of gap_size == 1, ack_size == 1 |
| 7300 | #define V99AddedBLOCK kVarInt62OneByte + 0x00, kVarInt62OneByte + 0x00 |
| 7301 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7302 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7303 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7304 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7305 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7306 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7307 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7308 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7309 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7310 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7311 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7312 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7313 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7314 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7315 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7316 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7317 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7318 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7319 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7320 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7321 | |
| 7322 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7323 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7324 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7325 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7326 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7327 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7328 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7329 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7330 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7331 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7332 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7333 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7334 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7335 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7336 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7337 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7338 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7339 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7340 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7341 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7342 | |
| 7343 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7344 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7345 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7346 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7347 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7348 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7349 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7350 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7351 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7352 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7353 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7354 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7355 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7356 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7357 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7358 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7359 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7360 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7361 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7362 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7363 | |
| 7364 | #undef V99AddedBLOCK |
| 7365 | }; |
| 7366 | // clang-format on |
| 7367 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7368 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 7369 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7370 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7371 | p_size = QUICHE_ARRAYSIZE(packet99); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 7372 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7373 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7374 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7375 | } |
| 7376 | |
| 7377 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7378 | ASSERT_TRUE(data != nullptr); |
| 7379 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 7380 | quiche::test::CompareCharArraysWithHexError( |
| 7381 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7382 | } |
| 7383 | |
| 7384 | TEST_P(QuicFramerTest, BuildNewStopWaitingPacket) { |
| 7385 | if (version_.transport_version > QUIC_VERSION_43) { |
| 7386 | return; |
| 7387 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7388 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7389 | QuicPacketHeader header; |
| 7390 | header.destination_connection_id = FramerTestConnectionId(); |
| 7391 | header.reset_flag = false; |
| 7392 | header.version_flag = false; |
| 7393 | header.packet_number = kPacketNumber; |
| 7394 | |
| 7395 | QuicStopWaitingFrame stop_waiting_frame; |
| 7396 | stop_waiting_frame.least_unacked = kLeastUnacked; |
| 7397 | |
| 7398 | QuicFrames frames = {QuicFrame(stop_waiting_frame)}; |
| 7399 | |
| 7400 | // clang-format off |
| 7401 | unsigned char packet[] = { |
| 7402 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7403 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7404 | // connection_id |
| 7405 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7406 | // packet number |
| 7407 | 0x12, 0x34, 0x56, 0x78, |
| 7408 | |
| 7409 | // frame type (stop waiting frame) |
| 7410 | 0x06, |
| 7411 | // least packet number awaiting an ack, delta from packet number. |
| 7412 | 0x00, 0x00, 0x00, 0x08, |
| 7413 | }; |
| 7414 | |
| 7415 | // clang-format on |
| 7416 | |
| 7417 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7418 | ASSERT_TRUE(data != nullptr); |
| 7419 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 7420 | quiche::test::CompareCharArraysWithHexError( |
| 7421 | "constructed packet", data->data(), data->length(), AsChars(packet), |
| 7422 | QUICHE_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7423 | } |
| 7424 | |
| 7425 | TEST_P(QuicFramerTest, BuildRstFramePacketQuic) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7426 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7427 | QuicPacketHeader header; |
| 7428 | header.destination_connection_id = FramerTestConnectionId(); |
| 7429 | header.reset_flag = false; |
| 7430 | header.version_flag = false; |
| 7431 | header.packet_number = kPacketNumber; |
| 7432 | |
| 7433 | QuicRstStreamFrame rst_frame; |
| 7434 | rst_frame.stream_id = kStreamId; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 7435 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7436 | rst_frame.ietf_error_code = 0x01; |
| 7437 | } else { |
| 7438 | rst_frame.error_code = static_cast<QuicRstStreamErrorCode>(0x05060708); |
| 7439 | } |
| 7440 | rst_frame.byte_offset = 0x0807060504030201; |
| 7441 | |
| 7442 | // clang-format off |
| 7443 | unsigned char packet[] = { |
| 7444 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7445 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7446 | // connection_id |
| 7447 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7448 | // packet number |
| 7449 | 0x12, 0x34, 0x56, 0x78, |
| 7450 | |
| 7451 | // frame type (rst stream frame) |
| 7452 | 0x01, |
| 7453 | // stream id |
| 7454 | 0x01, 0x02, 0x03, 0x04, |
| 7455 | // sent byte offset |
| 7456 | 0x08, 0x07, 0x06, 0x05, |
| 7457 | 0x04, 0x03, 0x02, 0x01, |
| 7458 | // error code |
| 7459 | 0x05, 0x06, 0x07, 0x08, |
| 7460 | }; |
| 7461 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7462 | unsigned char packet46[] = { |
| 7463 | // type (short packet, 4 byte packet number) |
| 7464 | 0x43, |
| 7465 | // connection_id |
| 7466 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7467 | // packet number |
| 7468 | 0x12, 0x34, 0x56, 0x78, |
| 7469 | |
| 7470 | // frame type (rst stream frame) |
| 7471 | 0x01, |
| 7472 | // stream id |
| 7473 | 0x01, 0x02, 0x03, 0x04, |
| 7474 | // sent byte offset |
| 7475 | 0x08, 0x07, 0x06, 0x05, |
| 7476 | 0x04, 0x03, 0x02, 0x01, |
| 7477 | // error code |
| 7478 | 0x05, 0x06, 0x07, 0x08, |
| 7479 | }; |
| 7480 | |
| 7481 | unsigned char packet99[] = { |
| 7482 | // type (short packet, 4 byte packet number) |
| 7483 | 0x43, |
| 7484 | // connection_id |
| 7485 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7486 | // packet number |
| 7487 | 0x12, 0x34, 0x56, 0x78, |
| 7488 | |
| 7489 | // frame type (IETF_RST_STREAM frame) |
| 7490 | 0x04, |
| 7491 | // stream id |
| 7492 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
fkastenholz | 07300e5 | 2019-07-16 11:51:37 -0700 | [diff] [blame] | 7493 | // error code |
| 7494 | kVarInt62OneByte + 0x01, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7495 | // sent byte offset |
| 7496 | kVarInt62EightBytes + 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 |
| 7497 | }; |
| 7498 | // clang-format on |
| 7499 | |
| 7500 | QuicFrames frames = {QuicFrame(&rst_frame)}; |
| 7501 | |
| 7502 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7503 | ASSERT_TRUE(data != nullptr); |
| 7504 | |
| 7505 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7506 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 7507 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7508 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7509 | p_size = QUICHE_ARRAYSIZE(packet99); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 7510 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7511 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7512 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7513 | } |
| 7514 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 7515 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 7516 | quiche::test::CompareCharArraysWithHexError( |
| 7517 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7518 | } |
| 7519 | |
| 7520 | TEST_P(QuicFramerTest, BuildCloseFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7521 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7522 | QuicPacketHeader header; |
| 7523 | header.destination_connection_id = FramerTestConnectionId(); |
| 7524 | header.reset_flag = false; |
| 7525 | header.version_flag = false; |
| 7526 | header.packet_number = kPacketNumber; |
| 7527 | |
fkastenholz | 2d55b91 | 2019-09-10 15:57:17 -0700 | [diff] [blame] | 7528 | QuicConnectionCloseFrame close_frame( |
| 7529 | framer_.transport_version(), |
| 7530 | static_cast<QuicErrorCode>( |
| 7531 | VersionHasIetfQuicFrames(framer_.transport_version()) ? 0x11 |
| 7532 | : 0x05060708), |
| 7533 | "because I can", 0x05); |
| 7534 | close_frame.extracted_error_code = QUIC_IETF_GQUIC_ERROR_MISSING; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7535 | QuicFrames frames = {QuicFrame(&close_frame)}; |
| 7536 | |
| 7537 | // clang-format off |
| 7538 | unsigned char packet[] = { |
| 7539 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7540 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7541 | // connection_id |
| 7542 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7543 | // packet number |
| 7544 | 0x12, 0x34, 0x56, 0x78, |
| 7545 | |
| 7546 | // frame type (connection close frame) |
| 7547 | 0x02, |
| 7548 | // error code |
| 7549 | 0x05, 0x06, 0x07, 0x08, |
| 7550 | // error details length |
| 7551 | 0x00, 0x0d, |
| 7552 | // error details |
| 7553 | 'b', 'e', 'c', 'a', |
| 7554 | 'u', 's', 'e', ' ', |
| 7555 | 'I', ' ', 'c', 'a', |
| 7556 | 'n', |
| 7557 | }; |
| 7558 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7559 | unsigned char packet46[] = { |
| 7560 | // type (short header, 4 byte packet number) |
| 7561 | 0x43, |
| 7562 | // connection_id |
| 7563 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7564 | // packet number |
| 7565 | 0x12, 0x34, 0x56, 0x78, |
| 7566 | |
| 7567 | // frame type (connection close frame) |
| 7568 | 0x02, |
| 7569 | // error code |
| 7570 | 0x05, 0x06, 0x07, 0x08, |
| 7571 | // error details length |
| 7572 | 0x00, 0x0d, |
| 7573 | // error details |
| 7574 | 'b', 'e', 'c', 'a', |
| 7575 | 'u', 's', 'e', ' ', |
| 7576 | 'I', ' ', 'c', 'a', |
| 7577 | 'n', |
| 7578 | }; |
| 7579 | |
| 7580 | unsigned char packet99[] = { |
| 7581 | // type (short header, 4 byte packet number) |
| 7582 | 0x43, |
| 7583 | // connection_id |
| 7584 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7585 | // packet number |
| 7586 | 0x12, 0x34, 0x56, 0x78, |
| 7587 | |
| 7588 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 7589 | 0x1c, |
| 7590 | // error code |
fkastenholz | d57d3f9 | 2019-07-16 09:05:17 -0700 | [diff] [blame] | 7591 | kVarInt62OneByte + 0x11, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7592 | // Frame type within the CONNECTION_CLOSE frame |
| 7593 | kVarInt62OneByte + 0x05, |
| 7594 | // error details length |
| 7595 | kVarInt62OneByte + 0x0d, |
| 7596 | // error details |
| 7597 | 'b', 'e', 'c', 'a', |
| 7598 | 'u', 's', 'e', ' ', |
| 7599 | 'I', ' ', 'c', 'a', |
| 7600 | 'n', |
| 7601 | }; |
| 7602 | // clang-format on |
| 7603 | |
| 7604 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7605 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 7606 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7607 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7608 | p_size = QUICHE_ARRAYSIZE(packet99); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 7609 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7610 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7611 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7612 | } |
| 7613 | |
| 7614 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7615 | ASSERT_TRUE(data != nullptr); |
| 7616 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 7617 | quiche::test::CompareCharArraysWithHexError( |
| 7618 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7619 | } |
| 7620 | |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 7621 | TEST_P(QuicFramerTest, BuildCloseFramePacketExtendedInfo) { |
| 7622 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 7623 | QuicPacketHeader header; |
| 7624 | header.destination_connection_id = FramerTestConnectionId(); |
| 7625 | header.reset_flag = false; |
| 7626 | header.version_flag = false; |
| 7627 | header.packet_number = kPacketNumber; |
| 7628 | |
fkastenholz | 2d55b91 | 2019-09-10 15:57:17 -0700 | [diff] [blame] | 7629 | QuicConnectionCloseFrame close_frame( |
| 7630 | framer_.transport_version(), |
| 7631 | static_cast<QuicErrorCode>( |
| 7632 | VersionHasIetfQuicFrames(framer_.transport_version()) ? 0x11 |
| 7633 | : 0x05060708), |
| 7634 | "because I can", 0x05); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 7635 | // Set this so that it is "there" for both Google QUIC and IETF QUIC |
| 7636 | // framing. It better not show up for Google QUIC! |
| 7637 | close_frame.extracted_error_code = static_cast<QuicErrorCode>(0x4567); |
| 7638 | |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 7639 | QuicFrames frames = {QuicFrame(&close_frame)}; |
| 7640 | |
| 7641 | // clang-format off |
| 7642 | unsigned char packet[] = { |
| 7643 | // public flags (8 byte connection_id) |
| 7644 | 0x2C, |
| 7645 | // connection_id |
| 7646 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7647 | // packet number |
| 7648 | 0x12, 0x34, 0x56, 0x78, |
| 7649 | |
| 7650 | // frame type (connection close frame) |
| 7651 | 0x02, |
| 7652 | // error code |
| 7653 | 0x05, 0x06, 0x07, 0x08, |
| 7654 | // error details length |
| 7655 | 0x00, 0x0d, |
| 7656 | // error details |
| 7657 | 'b', 'e', 'c', 'a', |
| 7658 | 'u', 's', 'e', ' ', |
| 7659 | 'I', ' ', 'c', 'a', |
| 7660 | 'n', |
| 7661 | }; |
| 7662 | |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 7663 | unsigned char packet46[] = { |
| 7664 | // type (short header, 4 byte packet number) |
| 7665 | 0x43, |
| 7666 | // connection_id |
| 7667 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7668 | // packet number |
| 7669 | 0x12, 0x34, 0x56, 0x78, |
| 7670 | |
| 7671 | // frame type (connection close frame) |
| 7672 | 0x02, |
| 7673 | // error code |
| 7674 | 0x05, 0x06, 0x07, 0x08, |
| 7675 | // error details length |
| 7676 | 0x00, 0x0d, |
| 7677 | // error details |
| 7678 | 'b', 'e', 'c', 'a', |
| 7679 | 'u', 's', 'e', ' ', |
| 7680 | 'I', ' ', 'c', 'a', |
| 7681 | 'n', |
| 7682 | }; |
| 7683 | |
| 7684 | unsigned char packet99[] = { |
| 7685 | // type (short header, 4 byte packet number) |
| 7686 | 0x43, |
| 7687 | // connection_id |
| 7688 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7689 | // packet number |
| 7690 | 0x12, 0x34, 0x56, 0x78, |
| 7691 | |
| 7692 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 7693 | 0x1c, |
| 7694 | // error code |
| 7695 | kVarInt62OneByte + 0x11, |
| 7696 | // Frame type within the CONNECTION_CLOSE frame |
| 7697 | kVarInt62OneByte + 0x05, |
| 7698 | // error details length |
| 7699 | kVarInt62OneByte + 0x13, |
| 7700 | // error details |
| 7701 | '1', '7', '7', '6', |
| 7702 | '7', ':', 'b', 'e', |
| 7703 | 'c', 'a', 'u', 's', |
| 7704 | 'e', ' ', 'I', ' ', |
| 7705 | 'c', 'a', 'n' |
| 7706 | }; |
| 7707 | // clang-format on |
| 7708 | |
| 7709 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7710 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 7711 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 7712 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7713 | p_size = QUICHE_ARRAYSIZE(packet99); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 7714 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 7715 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7716 | p_size = QUICHE_ARRAYSIZE(packet46); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 7717 | } |
| 7718 | |
| 7719 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7720 | ASSERT_TRUE(data != nullptr); |
| 7721 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 7722 | quiche::test::CompareCharArraysWithHexError( |
| 7723 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 7724 | } |
| 7725 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7726 | TEST_P(QuicFramerTest, BuildTruncatedCloseFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7727 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7728 | QuicPacketHeader header; |
| 7729 | header.destination_connection_id = FramerTestConnectionId(); |
| 7730 | header.reset_flag = false; |
| 7731 | header.version_flag = false; |
| 7732 | header.packet_number = kPacketNumber; |
| 7733 | |
fkastenholz | 2d55b91 | 2019-09-10 15:57:17 -0700 | [diff] [blame] | 7734 | QuicConnectionCloseFrame close_frame( |
| 7735 | framer_.transport_version(), |
| 7736 | static_cast<QuicErrorCode>( |
| 7737 | VersionHasIetfQuicFrames(framer_.transport_version()) ? 0xa |
| 7738 | : 0x05060708), |
| 7739 | std::string(2048, 'A'), 0x05); |
| 7740 | close_frame.extracted_error_code = QUIC_IETF_GQUIC_ERROR_MISSING; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7741 | QuicFrames frames = {QuicFrame(&close_frame)}; |
| 7742 | |
| 7743 | // clang-format off |
| 7744 | unsigned char packet[] = { |
| 7745 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7746 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7747 | // connection_id |
| 7748 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7749 | // packet number |
| 7750 | 0x12, 0x34, 0x56, 0x78, |
| 7751 | |
| 7752 | // frame type (connection close frame) |
| 7753 | 0x02, |
| 7754 | // error code |
| 7755 | 0x05, 0x06, 0x07, 0x08, |
| 7756 | // error details length |
| 7757 | 0x01, 0x00, |
| 7758 | // error details (truncated to 256 bytes) |
| 7759 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7760 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7761 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7762 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7763 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7764 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7765 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7766 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7767 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7768 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7769 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7770 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7771 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7772 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7773 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7774 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7775 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7776 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7777 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7778 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7779 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7780 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7781 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7782 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7783 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7784 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7785 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7786 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7787 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7788 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7789 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7790 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7791 | }; |
| 7792 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7793 | unsigned char packet46[] = { |
| 7794 | // type (short header, 4 byte packet number) |
| 7795 | 0x43, |
| 7796 | // connection_id |
| 7797 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7798 | // packet number |
| 7799 | 0x12, 0x34, 0x56, 0x78, |
| 7800 | |
| 7801 | // frame type (connection close frame) |
| 7802 | 0x02, |
| 7803 | // error code |
| 7804 | 0x05, 0x06, 0x07, 0x08, |
| 7805 | // error details length |
| 7806 | 0x01, 0x00, |
| 7807 | // error details (truncated to 256 bytes) |
| 7808 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7809 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7810 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7811 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7812 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7813 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7814 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7815 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7816 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7817 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7818 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7819 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7820 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7821 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7822 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7823 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7824 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7825 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7826 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7827 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7828 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7829 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7830 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7831 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7832 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7833 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7834 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7835 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7836 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7837 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7838 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7839 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7840 | }; |
| 7841 | |
| 7842 | unsigned char packet99[] = { |
| 7843 | // type (short header, 4 byte packet number) |
| 7844 | 0x43, |
| 7845 | // connection_id |
| 7846 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7847 | // packet number |
| 7848 | 0x12, 0x34, 0x56, 0x78, |
| 7849 | |
| 7850 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 7851 | 0x1c, |
| 7852 | // error code |
fkastenholz | d57d3f9 | 2019-07-16 09:05:17 -0700 | [diff] [blame] | 7853 | kVarInt62OneByte + 0x0a, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7854 | // Frame type within the CONNECTION_CLOSE frame |
fkastenholz | 2d55b91 | 2019-09-10 15:57:17 -0700 | [diff] [blame] | 7855 | kVarInt62OneByte + 0x05, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7856 | // error details length |
| 7857 | kVarInt62TwoBytes + 0x01, 0x00, |
| 7858 | // error details (truncated to 256 bytes) |
| 7859 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7860 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7861 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7862 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7863 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7864 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7865 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7866 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7867 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7868 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7869 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7870 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7871 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7872 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7873 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7874 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7875 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7876 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7877 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7878 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7879 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7880 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7881 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7882 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7883 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7884 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7885 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7886 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7887 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7888 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7889 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7890 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7891 | }; |
| 7892 | // clang-format on |
| 7893 | |
| 7894 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7895 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 7896 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7897 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7898 | p_size = QUICHE_ARRAYSIZE(packet99); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 7899 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7900 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 7901 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7902 | } |
| 7903 | |
| 7904 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7905 | ASSERT_TRUE(data != nullptr); |
| 7906 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 7907 | quiche::test::CompareCharArraysWithHexError( |
| 7908 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7909 | } |
| 7910 | |
| 7911 | TEST_P(QuicFramerTest, BuildApplicationCloseFramePacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 7912 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 7913 | // This frame is only for IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7914 | return; |
| 7915 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7916 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7917 | QuicPacketHeader header; |
| 7918 | header.destination_connection_id = FramerTestConnectionId(); |
| 7919 | header.reset_flag = false; |
| 7920 | header.version_flag = false; |
| 7921 | header.packet_number = kPacketNumber; |
| 7922 | |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 7923 | QuicConnectionCloseFrame app_close_frame; |
fkastenholz | d57d3f9 | 2019-07-16 09:05:17 -0700 | [diff] [blame] | 7924 | app_close_frame.application_error_code = |
| 7925 | static_cast<uint64_t>(QUIC_INVALID_STREAM_ID); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7926 | app_close_frame.error_details = "because I can"; |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 7927 | app_close_frame.close_type = IETF_QUIC_APPLICATION_CONNECTION_CLOSE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7928 | |
| 7929 | QuicFrames frames = {QuicFrame(&app_close_frame)}; |
| 7930 | |
| 7931 | // clang-format off |
| 7932 | |
| 7933 | unsigned char packet99[] = { |
| 7934 | // type (short header, 4 byte packet number) |
| 7935 | 0x43, |
| 7936 | // connection_id |
| 7937 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7938 | // packet number |
| 7939 | 0x12, 0x34, 0x56, 0x78, |
| 7940 | |
| 7941 | // frame type (IETF_APPLICATION_CLOSE frame) |
| 7942 | 0x1d, |
| 7943 | // error code |
fkastenholz | d57d3f9 | 2019-07-16 09:05:17 -0700 | [diff] [blame] | 7944 | kVarInt62OneByte + 0x11, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7945 | // error details length |
fkastenholz | 2d55b91 | 2019-09-10 15:57:17 -0700 | [diff] [blame] | 7946 | kVarInt62OneByte + 0x0f, |
| 7947 | // error details, note that it includes an extended error code. |
| 7948 | '0', ':', 'b', 'e', |
| 7949 | 'c', 'a', 'u', 's', |
| 7950 | 'e', ' ', 'I', ' ', |
| 7951 | 'c', 'a', 'n', |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7952 | }; |
| 7953 | // clang-format on |
| 7954 | |
| 7955 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7956 | ASSERT_TRUE(data != nullptr); |
| 7957 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 7958 | quiche::test::CompareCharArraysWithHexError( |
| 7959 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
| 7960 | QUICHE_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7961 | } |
| 7962 | |
| 7963 | TEST_P(QuicFramerTest, BuildTruncatedApplicationCloseFramePacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 7964 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 7965 | // This frame is only for IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7966 | return; |
| 7967 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7968 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7969 | QuicPacketHeader header; |
| 7970 | header.destination_connection_id = FramerTestConnectionId(); |
| 7971 | header.reset_flag = false; |
| 7972 | header.version_flag = false; |
| 7973 | header.packet_number = kPacketNumber; |
| 7974 | |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 7975 | QuicConnectionCloseFrame app_close_frame; |
fkastenholz | d57d3f9 | 2019-07-16 09:05:17 -0700 | [diff] [blame] | 7976 | app_close_frame.application_error_code = |
| 7977 | static_cast<uint64_t>(QUIC_INVALID_STREAM_ID); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 7978 | app_close_frame.error_details = std::string(2048, 'A'); |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 7979 | app_close_frame.close_type = IETF_QUIC_APPLICATION_CONNECTION_CLOSE; |
fkastenholz | 2d55b91 | 2019-09-10 15:57:17 -0700 | [diff] [blame] | 7980 | // Setting to missing ensures that if it is missing, the extended |
| 7981 | // code is not added to the text message. |
| 7982 | app_close_frame.extracted_error_code = QUIC_IETF_GQUIC_ERROR_MISSING; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7983 | |
| 7984 | QuicFrames frames = {QuicFrame(&app_close_frame)}; |
| 7985 | |
| 7986 | // clang-format off |
| 7987 | unsigned char packet99[] = { |
| 7988 | // type (short header, 4 byte packet number) |
| 7989 | 0x43, |
| 7990 | // connection_id |
| 7991 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7992 | // packet number |
| 7993 | 0x12, 0x34, 0x56, 0x78, |
| 7994 | |
| 7995 | // frame type (IETF_APPLICATION_CLOSE frame) |
| 7996 | 0x1d, |
| 7997 | // error code |
fkastenholz | d57d3f9 | 2019-07-16 09:05:17 -0700 | [diff] [blame] | 7998 | kVarInt62OneByte + 0x11, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7999 | // error details length |
| 8000 | kVarInt62TwoBytes + 0x01, 0x00, |
| 8001 | // error details (truncated to 256 bytes) |
| 8002 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8003 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8004 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8005 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8006 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8007 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8008 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8009 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8010 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8011 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8012 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8013 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8014 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8015 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8016 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8017 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8018 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8019 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8020 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8021 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8022 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8023 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8024 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8025 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8026 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8027 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8028 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8029 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8030 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8031 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8032 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8033 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8034 | }; |
| 8035 | // clang-format on |
| 8036 | |
| 8037 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8038 | ASSERT_TRUE(data != nullptr); |
| 8039 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8040 | quiche::test::CompareCharArraysWithHexError( |
| 8041 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
| 8042 | QUICHE_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8043 | } |
| 8044 | |
| 8045 | TEST_P(QuicFramerTest, BuildGoAwayPacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8046 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 8047 | // This frame is only for Google QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8048 | return; |
| 8049 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8050 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8051 | QuicPacketHeader header; |
| 8052 | header.destination_connection_id = FramerTestConnectionId(); |
| 8053 | header.reset_flag = false; |
| 8054 | header.version_flag = false; |
| 8055 | header.packet_number = kPacketNumber; |
| 8056 | |
| 8057 | QuicGoAwayFrame goaway_frame; |
| 8058 | goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 8059 | goaway_frame.last_good_stream_id = kStreamId; |
| 8060 | goaway_frame.reason_phrase = "because I can"; |
| 8061 | |
| 8062 | QuicFrames frames = {QuicFrame(&goaway_frame)}; |
| 8063 | |
| 8064 | // clang-format off |
| 8065 | unsigned char packet[] = { |
| 8066 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8067 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8068 | // connection_id |
| 8069 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8070 | // packet number |
| 8071 | 0x12, 0x34, 0x56, 0x78, |
| 8072 | |
| 8073 | // frame type (go away frame) |
| 8074 | 0x03, |
| 8075 | // error code |
| 8076 | 0x05, 0x06, 0x07, 0x08, |
| 8077 | // stream id |
| 8078 | 0x01, 0x02, 0x03, 0x04, |
| 8079 | // error details length |
| 8080 | 0x00, 0x0d, |
| 8081 | // error details |
| 8082 | 'b', 'e', 'c', 'a', |
| 8083 | 'u', 's', 'e', ' ', |
| 8084 | 'I', ' ', 'c', 'a', |
| 8085 | 'n', |
| 8086 | }; |
| 8087 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8088 | unsigned char packet46[] = { |
| 8089 | // type (short header, 4 byte packet number) |
| 8090 | 0x43, |
| 8091 | // connection_id |
| 8092 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8093 | // packet number |
| 8094 | 0x12, 0x34, 0x56, 0x78, |
| 8095 | |
| 8096 | // frame type (go away frame) |
| 8097 | 0x03, |
| 8098 | // error code |
| 8099 | 0x05, 0x06, 0x07, 0x08, |
| 8100 | // stream id |
| 8101 | 0x01, 0x02, 0x03, 0x04, |
| 8102 | // error details length |
| 8103 | 0x00, 0x0d, |
| 8104 | // error details |
| 8105 | 'b', 'e', 'c', 'a', |
| 8106 | 'u', 's', 'e', ' ', |
| 8107 | 'I', ' ', 'c', 'a', |
| 8108 | 'n', |
| 8109 | }; |
| 8110 | |
| 8111 | // clang-format on |
| 8112 | |
| 8113 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 8114 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 8115 | if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8116 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 8117 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8118 | } |
| 8119 | |
| 8120 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8121 | ASSERT_TRUE(data != nullptr); |
| 8122 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8123 | quiche::test::CompareCharArraysWithHexError( |
| 8124 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8125 | } |
| 8126 | |
| 8127 | TEST_P(QuicFramerTest, BuildTruncatedGoAwayPacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8128 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 8129 | // This frame is only for Google QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8130 | return; |
| 8131 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8132 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8133 | QuicPacketHeader header; |
| 8134 | header.destination_connection_id = FramerTestConnectionId(); |
| 8135 | header.reset_flag = false; |
| 8136 | header.version_flag = false; |
| 8137 | header.packet_number = kPacketNumber; |
| 8138 | |
| 8139 | QuicGoAwayFrame goaway_frame; |
| 8140 | goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 8141 | goaway_frame.last_good_stream_id = kStreamId; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 8142 | goaway_frame.reason_phrase = std::string(2048, 'A'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8143 | |
| 8144 | QuicFrames frames = {QuicFrame(&goaway_frame)}; |
| 8145 | |
| 8146 | // clang-format off |
| 8147 | unsigned char packet[] = { |
| 8148 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8149 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8150 | // connection_id |
| 8151 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8152 | // packet number |
| 8153 | 0x12, 0x34, 0x56, 0x78, |
| 8154 | |
| 8155 | // frame type (go away frame) |
| 8156 | 0x03, |
| 8157 | // error code |
| 8158 | 0x05, 0x06, 0x07, 0x08, |
| 8159 | // stream id |
| 8160 | 0x01, 0x02, 0x03, 0x04, |
| 8161 | // error details length |
| 8162 | 0x01, 0x00, |
| 8163 | // error details (truncated to 256 bytes) |
| 8164 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8165 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8166 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8167 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8168 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8169 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8170 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8171 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8172 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8173 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8174 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8175 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8176 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8177 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8178 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8179 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8180 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8181 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8182 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8183 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8184 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8185 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8186 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8187 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8188 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8189 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8190 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8191 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8192 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8193 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8194 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8195 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8196 | }; |
| 8197 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8198 | unsigned char packet46[] = { |
| 8199 | // type (short header, 4 byte packet number) |
| 8200 | 0x43, |
| 8201 | // connection_id |
| 8202 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8203 | // packet number |
| 8204 | 0x12, 0x34, 0x56, 0x78, |
| 8205 | |
| 8206 | // frame type (go away frame) |
| 8207 | 0x03, |
| 8208 | // error code |
| 8209 | 0x05, 0x06, 0x07, 0x08, |
| 8210 | // stream id |
| 8211 | 0x01, 0x02, 0x03, 0x04, |
| 8212 | // error details length |
| 8213 | 0x01, 0x00, |
| 8214 | // error details (truncated to 256 bytes) |
| 8215 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8216 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8217 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8218 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8219 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8220 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8221 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8222 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8223 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8224 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8225 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8226 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8227 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8228 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8229 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8230 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8231 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8232 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8233 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8234 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8235 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8236 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8237 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8238 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8239 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8240 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8241 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8242 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8243 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8244 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8245 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8246 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8247 | }; |
| 8248 | // clang-format on |
| 8249 | |
| 8250 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 8251 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 8252 | if (framer_.transport_version() > QUIC_VERSION_43) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8253 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 8254 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8255 | } |
| 8256 | |
| 8257 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8258 | ASSERT_TRUE(data != nullptr); |
| 8259 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8260 | quiche::test::CompareCharArraysWithHexError( |
| 8261 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8262 | } |
| 8263 | |
| 8264 | TEST_P(QuicFramerTest, BuildWindowUpdatePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8265 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8266 | QuicPacketHeader header; |
| 8267 | header.destination_connection_id = FramerTestConnectionId(); |
| 8268 | header.reset_flag = false; |
| 8269 | header.version_flag = false; |
| 8270 | header.packet_number = kPacketNumber; |
| 8271 | |
| 8272 | QuicWindowUpdateFrame window_update_frame; |
| 8273 | window_update_frame.stream_id = kStreamId; |
renjietang | d088eab | 2019-11-21 14:54:41 -0800 | [diff] [blame] | 8274 | window_update_frame.max_data = 0x1122334455667788; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8275 | |
| 8276 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 8277 | |
| 8278 | // clang-format off |
| 8279 | unsigned char packet[] = { |
| 8280 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8281 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8282 | // connection_id |
| 8283 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8284 | // packet number |
| 8285 | 0x12, 0x34, 0x56, 0x78, |
| 8286 | |
| 8287 | // frame type (window update frame) |
| 8288 | 0x04, |
| 8289 | // stream id |
| 8290 | 0x01, 0x02, 0x03, 0x04, |
| 8291 | // byte offset |
| 8292 | 0x11, 0x22, 0x33, 0x44, |
| 8293 | 0x55, 0x66, 0x77, 0x88, |
| 8294 | }; |
| 8295 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8296 | unsigned char packet46[] = { |
| 8297 | // type (short header, 4 byte packet number) |
| 8298 | 0x43, |
| 8299 | // connection_id |
| 8300 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8301 | // packet number |
| 8302 | 0x12, 0x34, 0x56, 0x78, |
| 8303 | |
| 8304 | // frame type (window update frame) |
| 8305 | 0x04, |
| 8306 | // stream id |
| 8307 | 0x01, 0x02, 0x03, 0x04, |
| 8308 | // byte offset |
| 8309 | 0x11, 0x22, 0x33, 0x44, |
| 8310 | 0x55, 0x66, 0x77, 0x88, |
| 8311 | }; |
| 8312 | |
| 8313 | unsigned char packet99[] = { |
| 8314 | // type (short header, 4 byte packet number) |
| 8315 | 0x43, |
| 8316 | // connection_id |
| 8317 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8318 | // packet number |
| 8319 | 0x12, 0x34, 0x56, 0x78, |
| 8320 | |
| 8321 | // frame type (IETF_MAX_STREAM_DATA frame) |
| 8322 | 0x11, |
| 8323 | // stream id |
| 8324 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 8325 | // byte offset |
| 8326 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 8327 | 0x55, 0x66, 0x77, 0x88, |
| 8328 | }; |
| 8329 | // clang-format on |
| 8330 | |
| 8331 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8332 | ASSERT_TRUE(data != nullptr); |
| 8333 | |
| 8334 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 8335 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8336 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8337 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 8338 | p_size = QUICHE_ARRAYSIZE(packet99); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 8339 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8340 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 8341 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8342 | } |
| 8343 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8344 | quiche::test::CompareCharArraysWithHexError( |
| 8345 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8346 | } |
| 8347 | |
| 8348 | TEST_P(QuicFramerTest, BuildMaxStreamDataPacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8349 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 8350 | // This frame is only for IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8351 | return; |
| 8352 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8353 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8354 | QuicPacketHeader header; |
| 8355 | header.destination_connection_id = FramerTestConnectionId(); |
| 8356 | header.reset_flag = false; |
| 8357 | header.version_flag = false; |
| 8358 | header.packet_number = kPacketNumber; |
| 8359 | |
| 8360 | QuicWindowUpdateFrame window_update_frame; |
| 8361 | window_update_frame.stream_id = kStreamId; |
renjietang | d088eab | 2019-11-21 14:54:41 -0800 | [diff] [blame] | 8362 | window_update_frame.max_data = 0x1122334455667788; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8363 | |
| 8364 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 8365 | |
| 8366 | // clang-format off |
| 8367 | unsigned char packet99[] = { |
| 8368 | // type (short header, 4 byte packet number) |
| 8369 | 0x43, |
| 8370 | // connection_id |
| 8371 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8372 | // packet number |
| 8373 | 0x12, 0x34, 0x56, 0x78, |
| 8374 | |
| 8375 | // frame type (IETF_MAX_STREAM_DATA frame) |
| 8376 | 0x11, |
| 8377 | // stream id |
| 8378 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 8379 | // byte offset |
| 8380 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 8381 | 0x55, 0x66, 0x77, 0x88, |
| 8382 | }; |
| 8383 | // clang-format on |
| 8384 | |
| 8385 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8386 | ASSERT_TRUE(data != nullptr); |
| 8387 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8388 | quiche::test::CompareCharArraysWithHexError( |
| 8389 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
| 8390 | QUICHE_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8391 | } |
| 8392 | |
| 8393 | TEST_P(QuicFramerTest, BuildMaxDataPacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8394 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 8395 | // This frame is only for IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8396 | return; |
| 8397 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8398 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8399 | QuicPacketHeader header; |
| 8400 | header.destination_connection_id = FramerTestConnectionId(); |
| 8401 | header.reset_flag = false; |
| 8402 | header.version_flag = false; |
| 8403 | header.packet_number = kPacketNumber; |
| 8404 | |
| 8405 | QuicWindowUpdateFrame window_update_frame; |
| 8406 | window_update_frame.stream_id = |
| 8407 | QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
renjietang | d088eab | 2019-11-21 14:54:41 -0800 | [diff] [blame] | 8408 | window_update_frame.max_data = 0x1122334455667788; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8409 | |
| 8410 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 8411 | |
| 8412 | // clang-format off |
| 8413 | unsigned char packet99[] = { |
| 8414 | // type (short header, 4 byte packet number) |
| 8415 | 0x43, |
| 8416 | // connection_id |
| 8417 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8418 | // packet number |
| 8419 | 0x12, 0x34, 0x56, 0x78, |
| 8420 | |
| 8421 | // frame type (IETF_MAX_DATA frame) |
| 8422 | 0x10, |
| 8423 | // byte offset |
| 8424 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 8425 | 0x55, 0x66, 0x77, 0x88, |
| 8426 | }; |
| 8427 | // clang-format on |
| 8428 | |
| 8429 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8430 | ASSERT_TRUE(data != nullptr); |
| 8431 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8432 | quiche::test::CompareCharArraysWithHexError( |
| 8433 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
| 8434 | QUICHE_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8435 | } |
| 8436 | |
| 8437 | TEST_P(QuicFramerTest, BuildBlockedPacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8438 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8439 | QuicPacketHeader header; |
| 8440 | header.destination_connection_id = FramerTestConnectionId(); |
| 8441 | header.reset_flag = false; |
| 8442 | header.version_flag = false; |
| 8443 | header.packet_number = kPacketNumber; |
| 8444 | |
| 8445 | QuicBlockedFrame blocked_frame; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8446 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 8447 | // For IETF QUIC, the stream ID must be <invalid> for the frame |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8448 | // to be a BLOCKED frame. if it's valid, it will be a |
| 8449 | // STREAM_BLOCKED frame. |
| 8450 | blocked_frame.stream_id = |
| 8451 | QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
| 8452 | } else { |
| 8453 | blocked_frame.stream_id = kStreamId; |
| 8454 | } |
| 8455 | blocked_frame.offset = kStreamOffset; |
| 8456 | |
| 8457 | QuicFrames frames = {QuicFrame(&blocked_frame)}; |
| 8458 | |
| 8459 | // clang-format off |
| 8460 | unsigned char packet[] = { |
| 8461 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8462 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8463 | // connection_id |
| 8464 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8465 | // packet number |
| 8466 | 0x12, 0x34, 0x56, 0x78, |
| 8467 | |
| 8468 | // frame type (blocked frame) |
| 8469 | 0x05, |
| 8470 | // stream id |
| 8471 | 0x01, 0x02, 0x03, 0x04, |
| 8472 | }; |
| 8473 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8474 | unsigned char packet46[] = { |
| 8475 | // type (short packet, 4 byte packet number) |
| 8476 | 0x43, |
| 8477 | // connection_id |
| 8478 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8479 | // packet number |
| 8480 | 0x12, 0x34, 0x56, 0x78, |
| 8481 | |
| 8482 | // frame type (blocked frame) |
| 8483 | 0x05, |
| 8484 | // stream id |
| 8485 | 0x01, 0x02, 0x03, 0x04, |
| 8486 | }; |
| 8487 | |
| 8488 | unsigned char packet99[] = { |
| 8489 | // type (short packet, 4 byte packet number) |
| 8490 | 0x43, |
| 8491 | // connection_id |
| 8492 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8493 | // packet number |
| 8494 | 0x12, 0x34, 0x56, 0x78, |
| 8495 | |
ianswett | 2f07744 | 2019-12-12 11:51:24 -0800 | [diff] [blame] | 8496 | // frame type (IETF_DATA_BLOCKED frame) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8497 | 0x14, |
| 8498 | // Offset |
| 8499 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 8500 | }; |
| 8501 | // clang-format on |
| 8502 | |
| 8503 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8504 | ASSERT_TRUE(data != nullptr); |
| 8505 | |
| 8506 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 8507 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8508 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8509 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 8510 | p_size = QUICHE_ARRAYSIZE(packet99); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 8511 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8512 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 8513 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8514 | } |
| 8515 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8516 | quiche::test::CompareCharArraysWithHexError( |
| 8517 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8518 | } |
| 8519 | |
| 8520 | TEST_P(QuicFramerTest, BuildPingPacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8521 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8522 | QuicPacketHeader header; |
| 8523 | header.destination_connection_id = FramerTestConnectionId(); |
| 8524 | header.reset_flag = false; |
| 8525 | header.version_flag = false; |
| 8526 | header.packet_number = kPacketNumber; |
| 8527 | |
| 8528 | QuicFrames frames = {QuicFrame(QuicPingFrame())}; |
| 8529 | |
| 8530 | // clang-format off |
| 8531 | unsigned char packet[] = { |
| 8532 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8533 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8534 | // connection_id |
| 8535 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8536 | // packet number |
| 8537 | 0x12, 0x34, 0x56, 0x78, |
| 8538 | |
| 8539 | // frame type (ping frame) |
| 8540 | 0x07, |
| 8541 | }; |
| 8542 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8543 | unsigned char packet46[] = { |
| 8544 | // type (short header, 4 byte packet number) |
| 8545 | 0x43, |
| 8546 | // connection_id |
| 8547 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8548 | // packet number |
| 8549 | 0x12, 0x34, 0x56, 0x78, |
| 8550 | |
| 8551 | // frame type |
| 8552 | 0x07, |
| 8553 | }; |
| 8554 | |
| 8555 | unsigned char packet99[] = { |
| 8556 | // type (short header, 4 byte packet number) |
| 8557 | 0x43, |
| 8558 | // connection_id |
| 8559 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8560 | // packet number |
| 8561 | 0x12, 0x34, 0x56, 0x78, |
| 8562 | |
| 8563 | // frame type (IETF_PING frame) |
| 8564 | 0x01, |
| 8565 | }; |
| 8566 | // clang-format on |
| 8567 | |
| 8568 | unsigned char* p = packet; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8569 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8570 | p = packet99; |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 8571 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 8572 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8573 | } |
| 8574 | |
| 8575 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8576 | ASSERT_TRUE(data != nullptr); |
| 8577 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8578 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8579 | "constructed packet", data->data(), data->length(), AsChars(p), |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 8580 | framer_.transport_version() > QUIC_VERSION_43 ? QUICHE_ARRAYSIZE(packet46) |
| 8581 | : QUICHE_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8582 | } |
| 8583 | |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 8584 | TEST_P(QuicFramerTest, BuildHandshakeDonePacket) { |
| 8585 | QuicPacketHeader header; |
| 8586 | header.destination_connection_id = FramerTestConnectionId(); |
| 8587 | header.reset_flag = false; |
| 8588 | header.version_flag = false; |
| 8589 | header.packet_number = kPacketNumber; |
| 8590 | |
| 8591 | QuicFrames frames = {QuicFrame(QuicHandshakeDoneFrame())}; |
| 8592 | |
| 8593 | // clang-format off |
| 8594 | unsigned char packet[] = { |
| 8595 | // type (short header, 4 byte packet number) |
| 8596 | 0x43, |
| 8597 | // connection_id |
| 8598 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8599 | // packet number |
| 8600 | 0x12, 0x34, 0x56, 0x78, |
| 8601 | |
| 8602 | // frame type (Handshake done frame) |
| 8603 | 0x1e, |
| 8604 | }; |
| 8605 | // clang-format on |
| 8606 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 8607 | return; |
| 8608 | } |
| 8609 | |
| 8610 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8611 | ASSERT_TRUE(data != nullptr); |
| 8612 | |
| 8613 | quiche::test::CompareCharArraysWithHexError( |
| 8614 | "constructed packet", data->data(), data->length(), AsChars(packet), |
| 8615 | QUICHE_ARRAYSIZE(packet)); |
| 8616 | } |
| 8617 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8618 | TEST_P(QuicFramerTest, BuildMessagePacket) { |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 8619 | if (!VersionSupportsMessageFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8620 | return; |
| 8621 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8622 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8623 | QuicPacketHeader header; |
| 8624 | header.destination_connection_id = FramerTestConnectionId(); |
| 8625 | header.reset_flag = false; |
| 8626 | header.version_flag = false; |
| 8627 | header.packet_number = kPacketNumber; |
| 8628 | QuicMemSliceStorage storage(nullptr, 0, nullptr, 0); |
| 8629 | |
wub | 553a966 | 2019-03-28 20:13:23 -0700 | [diff] [blame] | 8630 | QuicMessageFrame frame(1, MakeSpan(&allocator_, "message", &storage)); |
| 8631 | QuicMessageFrame frame2(2, MakeSpan(&allocator_, "message2", &storage)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8632 | QuicFrames frames = {QuicFrame(&frame), QuicFrame(&frame2)}; |
| 8633 | |
| 8634 | // clang-format off |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8635 | unsigned char packet46[] = { |
| 8636 | // type (short header, 4 byte packet number) |
| 8637 | 0x43, |
| 8638 | // connection_id |
| 8639 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8640 | // packet number |
| 8641 | 0x12, 0x34, 0x56, 0x78, |
| 8642 | |
| 8643 | // frame type (message frame) |
| 8644 | 0x21, |
| 8645 | // Length |
| 8646 | 0x07, |
| 8647 | // Message Data |
| 8648 | 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 8649 | // frame type (message frame no length) |
| 8650 | 0x20, |
| 8651 | // Message Data |
| 8652 | 'm', 'e', 's', 's', 'a', 'g', 'e', '2' |
| 8653 | }; |
| 8654 | |
| 8655 | unsigned char packet99[] = { |
| 8656 | // type (short header, 4 byte packet number) |
| 8657 | 0x43, |
| 8658 | // connection_id |
| 8659 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8660 | // packet number |
| 8661 | 0x12, 0x34, 0x56, 0x78, |
| 8662 | |
| 8663 | // frame type (IETF_MESSAGE frame) |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 8664 | 0x31, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8665 | // Length |
| 8666 | 0x07, |
| 8667 | // Message Data |
| 8668 | 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 8669 | // frame type (message frame no length) |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 8670 | 0x30, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8671 | // Message Data |
| 8672 | 'm', 'e', 's', 's', 'a', 'g', 'e', '2' |
| 8673 | }; |
| 8674 | // clang-format on |
| 8675 | |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 8676 | unsigned char* p = packet46; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8677 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8678 | p = packet99; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8679 | } |
| 8680 | |
| 8681 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8682 | ASSERT_TRUE(data != nullptr); |
| 8683 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8684 | quiche::test::CompareCharArraysWithHexError( |
| 8685 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 8686 | QUICHE_ARRAYSIZE(packet46)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8687 | } |
| 8688 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8689 | // Test that the MTU discovery packet is serialized correctly as a PING packet. |
| 8690 | TEST_P(QuicFramerTest, BuildMtuDiscoveryPacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8691 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8692 | QuicPacketHeader header; |
| 8693 | header.destination_connection_id = FramerTestConnectionId(); |
| 8694 | header.reset_flag = false; |
| 8695 | header.version_flag = false; |
| 8696 | header.packet_number = kPacketNumber; |
| 8697 | |
| 8698 | QuicFrames frames = {QuicFrame(QuicMtuDiscoveryFrame())}; |
| 8699 | |
| 8700 | // clang-format off |
| 8701 | unsigned char packet[] = { |
| 8702 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8703 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8704 | // connection_id |
| 8705 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8706 | // packet number |
| 8707 | 0x12, 0x34, 0x56, 0x78, |
| 8708 | |
| 8709 | // frame type (ping frame) |
| 8710 | 0x07, |
| 8711 | }; |
| 8712 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8713 | unsigned char packet46[] = { |
| 8714 | // type (short header, 4 byte packet number) |
| 8715 | 0x43, |
| 8716 | // connection_id |
| 8717 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8718 | // packet number |
| 8719 | 0x12, 0x34, 0x56, 0x78, |
| 8720 | |
| 8721 | // frame type |
| 8722 | 0x07, |
| 8723 | }; |
| 8724 | |
| 8725 | unsigned char packet99[] = { |
| 8726 | // type (short header, 4 byte packet number) |
| 8727 | 0x43, |
| 8728 | // connection_id |
| 8729 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8730 | // packet number |
| 8731 | 0x12, 0x34, 0x56, 0x78, |
| 8732 | |
| 8733 | // frame type (IETF_PING frame) |
| 8734 | 0x01, |
| 8735 | }; |
| 8736 | // clang-format on |
| 8737 | |
| 8738 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8739 | ASSERT_TRUE(data != nullptr); |
| 8740 | |
| 8741 | unsigned char* p = packet; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8742 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8743 | p = packet99; |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 8744 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 8745 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8746 | } |
| 8747 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8748 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8749 | "constructed packet", data->data(), data->length(), AsChars(p), |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 8750 | framer_.transport_version() > QUIC_VERSION_43 ? QUICHE_ARRAYSIZE(packet46) |
| 8751 | : QUICHE_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8752 | } |
| 8753 | |
| 8754 | TEST_P(QuicFramerTest, BuildPublicResetPacket) { |
| 8755 | QuicPublicResetPacket reset_packet; |
| 8756 | reset_packet.connection_id = FramerTestConnectionId(); |
| 8757 | reset_packet.nonce_proof = kNonceProof; |
| 8758 | |
| 8759 | // clang-format off |
| 8760 | unsigned char packet[] = { |
| 8761 | // public flags (public reset, 8 byte ConnectionId) |
| 8762 | 0x0E, |
| 8763 | // connection_id |
| 8764 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8765 | // message tag (kPRST) |
| 8766 | 'P', 'R', 'S', 'T', |
| 8767 | // num_entries (1) + padding |
| 8768 | 0x01, 0x00, 0x00, 0x00, |
| 8769 | // tag kRNON |
| 8770 | 'R', 'N', 'O', 'N', |
| 8771 | // end offset 8 |
| 8772 | 0x08, 0x00, 0x00, 0x00, |
| 8773 | // nonce proof |
| 8774 | 0x89, 0x67, 0x45, 0x23, |
| 8775 | 0x01, 0xEF, 0xCD, 0xAB, |
| 8776 | }; |
| 8777 | // clang-format on |
| 8778 | |
| 8779 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8780 | return; |
| 8781 | } |
| 8782 | |
| 8783 | std::unique_ptr<QuicEncryptedPacket> data( |
| 8784 | framer_.BuildPublicResetPacket(reset_packet)); |
| 8785 | ASSERT_TRUE(data != nullptr); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8786 | quiche::test::CompareCharArraysWithHexError( |
| 8787 | "constructed packet", data->data(), data->length(), AsChars(packet), |
| 8788 | QUICHE_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8789 | } |
| 8790 | |
| 8791 | TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) { |
| 8792 | QuicPublicResetPacket reset_packet; |
| 8793 | reset_packet.connection_id = FramerTestConnectionId(); |
| 8794 | reset_packet.nonce_proof = kNonceProof; |
| 8795 | reset_packet.client_address = |
| 8796 | QuicSocketAddress(QuicIpAddress::Loopback4(), 0x1234); |
| 8797 | |
| 8798 | // clang-format off |
| 8799 | unsigned char packet[] = { |
| 8800 | // public flags (public reset, 8 byte ConnectionId) |
| 8801 | 0x0E, |
| 8802 | // connection_id |
| 8803 | 0xFE, 0xDC, 0xBA, 0x98, |
| 8804 | 0x76, 0x54, 0x32, 0x10, |
| 8805 | // message tag (kPRST) |
| 8806 | 'P', 'R', 'S', 'T', |
| 8807 | // num_entries (2) + padding |
| 8808 | 0x02, 0x00, 0x00, 0x00, |
| 8809 | // tag kRNON |
| 8810 | 'R', 'N', 'O', 'N', |
| 8811 | // end offset 8 |
| 8812 | 0x08, 0x00, 0x00, 0x00, |
| 8813 | // tag kCADR |
| 8814 | 'C', 'A', 'D', 'R', |
| 8815 | // end offset 16 |
| 8816 | 0x10, 0x00, 0x00, 0x00, |
| 8817 | // nonce proof |
| 8818 | 0x89, 0x67, 0x45, 0x23, |
| 8819 | 0x01, 0xEF, 0xCD, 0xAB, |
| 8820 | // client address |
| 8821 | 0x02, 0x00, |
| 8822 | 0x7F, 0x00, 0x00, 0x01, |
| 8823 | 0x34, 0x12, |
| 8824 | }; |
| 8825 | // clang-format on |
| 8826 | |
| 8827 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8828 | return; |
| 8829 | } |
| 8830 | |
| 8831 | std::unique_ptr<QuicEncryptedPacket> data( |
| 8832 | framer_.BuildPublicResetPacket(reset_packet)); |
| 8833 | ASSERT_TRUE(data != nullptr); |
| 8834 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8835 | quiche::test::CompareCharArraysWithHexError( |
| 8836 | "constructed packet", data->data(), data->length(), AsChars(packet), |
| 8837 | QUICHE_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8838 | } |
| 8839 | |
| 8840 | TEST_P(QuicFramerTest, BuildPublicResetPacketWithEndpointId) { |
| 8841 | QuicPublicResetPacket reset_packet; |
| 8842 | reset_packet.connection_id = FramerTestConnectionId(); |
| 8843 | reset_packet.nonce_proof = kNonceProof; |
| 8844 | reset_packet.endpoint_id = "FakeServerId"; |
| 8845 | |
| 8846 | // The tag value map in CryptoHandshakeMessage is a std::map, so the two tags |
| 8847 | // in the packet, kRNON and kEPID, have unspecified ordering w.r.t each other. |
| 8848 | // clang-format off |
| 8849 | unsigned char packet_variant1[] = { |
| 8850 | // public flags (public reset, 8 byte ConnectionId) |
| 8851 | 0x0E, |
| 8852 | // connection_id |
| 8853 | 0xFE, 0xDC, 0xBA, 0x98, |
| 8854 | 0x76, 0x54, 0x32, 0x10, |
| 8855 | // message tag (kPRST) |
| 8856 | 'P', 'R', 'S', 'T', |
| 8857 | // num_entries (2) + padding |
| 8858 | 0x02, 0x00, 0x00, 0x00, |
| 8859 | // tag kRNON |
| 8860 | 'R', 'N', 'O', 'N', |
| 8861 | // end offset 8 |
| 8862 | 0x08, 0x00, 0x00, 0x00, |
| 8863 | // tag kEPID |
| 8864 | 'E', 'P', 'I', 'D', |
| 8865 | // end offset 20 |
| 8866 | 0x14, 0x00, 0x00, 0x00, |
| 8867 | // nonce proof |
| 8868 | 0x89, 0x67, 0x45, 0x23, |
| 8869 | 0x01, 0xEF, 0xCD, 0xAB, |
| 8870 | // Endpoint ID |
| 8871 | 'F', 'a', 'k', 'e', 'S', 'e', 'r', 'v', 'e', 'r', 'I', 'd', |
| 8872 | }; |
| 8873 | unsigned char packet_variant2[] = { |
| 8874 | // public flags (public reset, 8 byte ConnectionId) |
| 8875 | 0x0E, |
| 8876 | // connection_id |
| 8877 | 0xFE, 0xDC, 0xBA, 0x98, |
| 8878 | 0x76, 0x54, 0x32, 0x10, |
| 8879 | // message tag (kPRST) |
| 8880 | 'P', 'R', 'S', 'T', |
| 8881 | // num_entries (2) + padding |
| 8882 | 0x02, 0x00, 0x00, 0x00, |
| 8883 | // tag kEPID |
| 8884 | 'E', 'P', 'I', 'D', |
| 8885 | // end offset 12 |
| 8886 | 0x0C, 0x00, 0x00, 0x00, |
| 8887 | // tag kRNON |
| 8888 | 'R', 'N', 'O', 'N', |
| 8889 | // end offset 20 |
| 8890 | 0x14, 0x00, 0x00, 0x00, |
| 8891 | // Endpoint ID |
| 8892 | 'F', 'a', 'k', 'e', 'S', 'e', 'r', 'v', 'e', 'r', 'I', 'd', |
| 8893 | // nonce proof |
| 8894 | 0x89, 0x67, 0x45, 0x23, |
| 8895 | 0x01, 0xEF, 0xCD, 0xAB, |
| 8896 | }; |
| 8897 | // clang-format on |
| 8898 | |
| 8899 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8900 | return; |
| 8901 | } |
| 8902 | |
| 8903 | std::unique_ptr<QuicEncryptedPacket> data( |
| 8904 | framer_.BuildPublicResetPacket(reset_packet)); |
| 8905 | ASSERT_TRUE(data != nullptr); |
| 8906 | |
| 8907 | // Variant 1 ends with char 'd'. Variant 1 ends with char 0xAB. |
| 8908 | if ('d' == data->data()[data->length() - 1]) { |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8909 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8910 | "constructed packet", data->data(), data->length(), |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 8911 | AsChars(packet_variant1), QUICHE_ARRAYSIZE(packet_variant1)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8912 | } else { |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8913 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8914 | "constructed packet", data->data(), data->length(), |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 8915 | AsChars(packet_variant2), QUICHE_ARRAYSIZE(packet_variant2)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8916 | } |
| 8917 | } |
| 8918 | |
| 8919 | TEST_P(QuicFramerTest, BuildIetfStatelessResetPacket) { |
| 8920 | // clang-format off |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 8921 | unsigned char packet[] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8922 | // type (short header, 1 byte packet number) |
| 8923 | 0x70, |
| 8924 | // random packet number |
| 8925 | 0xFE, |
| 8926 | // stateless reset token |
| 8927 | 0xB5, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 8928 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 8929 | }; |
| 8930 | // clang-format on |
| 8931 | |
| 8932 | std::unique_ptr<QuicEncryptedPacket> data( |
| 8933 | framer_.BuildIetfStatelessResetPacket(FramerTestConnectionId(), |
| 8934 | kTestStatelessResetToken)); |
| 8935 | ASSERT_TRUE(data != nullptr); |
| 8936 | // Skip packet number byte which is random in stateless reset packet. |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8937 | quiche::test::CompareCharArraysWithHexError( |
| 8938 | "constructed packet", data->data(), 1, AsChars(packet), 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8939 | const size_t random_bytes_length = |
| 8940 | data->length() - kPacketHeaderTypeSize - sizeof(kTestStatelessResetToken); |
| 8941 | EXPECT_EQ(kMinRandomBytesLengthInStatelessReset, random_bytes_length); |
| 8942 | // Verify stateless reset token is correct. |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8943 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8944 | "constructed packet", |
| 8945 | data->data() + data->length() - sizeof(kTestStatelessResetToken), |
| 8946 | sizeof(kTestStatelessResetToken), |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 8947 | AsChars(packet) + QUICHE_ARRAYSIZE(packet) - |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8948 | sizeof(kTestStatelessResetToken), |
| 8949 | sizeof(kTestStatelessResetToken)); |
| 8950 | } |
| 8951 | |
| 8952 | TEST_P(QuicFramerTest, EncryptPacket) { |
| 8953 | QuicPacketNumber packet_number = kPacketNumber; |
| 8954 | // clang-format off |
| 8955 | unsigned char packet[] = { |
| 8956 | // public flags (8 byte connection_id) |
| 8957 | 0x28, |
| 8958 | // connection_id |
| 8959 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8960 | // packet number |
| 8961 | 0x12, 0x34, 0x56, 0x78, |
| 8962 | |
| 8963 | // redundancy |
| 8964 | 'a', 'b', 'c', 'd', |
| 8965 | 'e', 'f', 'g', 'h', |
| 8966 | 'i', 'j', 'k', 'l', |
| 8967 | 'm', 'n', 'o', 'p', |
| 8968 | }; |
| 8969 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8970 | unsigned char packet46[] = { |
| 8971 | // type (short header, 4 byte packet number) |
| 8972 | 0x43, |
| 8973 | // connection_id |
| 8974 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8975 | // packet number |
| 8976 | 0x12, 0x34, 0x56, 0x78, |
| 8977 | |
| 8978 | // redundancy |
| 8979 | 'a', 'b', 'c', 'd', |
| 8980 | 'e', 'f', 'g', 'h', |
| 8981 | 'i', 'j', 'k', 'l', |
| 8982 | 'm', 'n', 'o', 'p', |
| 8983 | }; |
| 8984 | |
nharper | c32d8ab | 2019-10-09 11:09:06 -0700 | [diff] [blame] | 8985 | unsigned char packet50[] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8986 | // type (short header, 4 byte packet number) |
| 8987 | 0x43, |
| 8988 | // connection_id |
| 8989 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8990 | // packet number |
| 8991 | 0x12, 0x34, 0x56, 0x78, |
| 8992 | |
| 8993 | // redundancy |
| 8994 | 'a', 'b', 'c', 'd', |
| 8995 | 'e', 'f', 'g', 'h', |
| 8996 | 'i', 'j', 'k', 'l', |
| 8997 | 'm', 'n', 'o', 'p', |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 8998 | 'q', 'r', 's', 't', |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8999 | }; |
| 9000 | // clang-format on |
| 9001 | |
| 9002 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 9003 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
nharper | c32d8ab | 2019-10-09 11:09:06 -0700 | [diff] [blame] | 9004 | if (framer_.transport_version() >= QUIC_VERSION_50) { |
| 9005 | p = packet50; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 9006 | p_size = QUICHE_ARRAYSIZE(packet50); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 9007 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 9008 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9009 | } |
| 9010 | |
| 9011 | std::unique_ptr<QuicPacket> raw(new QuicPacket( |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9012 | AsChars(p), p_size, false, PACKET_8BYTE_CONNECTION_ID, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9013 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 9014 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 9015 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0)); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9016 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9017 | size_t encrypted_length = framer_.EncryptPayload( |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9018 | ENCRYPTION_INITIAL, packet_number, *raw, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9019 | |
| 9020 | ASSERT_NE(0u, encrypted_length); |
| 9021 | EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); |
| 9022 | } |
| 9023 | |
| 9024 | TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) { |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9025 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9026 | QuicPacketNumber packet_number = kPacketNumber; |
| 9027 | // clang-format off |
| 9028 | unsigned char packet[] = { |
| 9029 | // public flags (version, 8 byte connection_id) |
| 9030 | 0x29, |
| 9031 | // connection_id |
| 9032 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9033 | // version tag |
| 9034 | 'Q', '.', '1', '0', |
| 9035 | // packet number |
| 9036 | 0x12, 0x34, 0x56, 0x78, |
| 9037 | |
| 9038 | // redundancy |
| 9039 | 'a', 'b', 'c', 'd', |
| 9040 | 'e', 'f', 'g', 'h', |
| 9041 | 'i', 'j', 'k', 'l', |
| 9042 | 'm', 'n', 'o', 'p', |
| 9043 | }; |
| 9044 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9045 | unsigned char packet46[] = { |
| 9046 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 9047 | 0xD3, |
| 9048 | // version tag |
| 9049 | 'Q', '.', '1', '0', |
| 9050 | // connection_id length |
| 9051 | 0x50, |
| 9052 | // connection_id |
| 9053 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9054 | // packet number |
| 9055 | 0x12, 0x34, 0x56, 0x78, |
| 9056 | |
| 9057 | // redundancy |
| 9058 | 'a', 'b', 'c', 'd', |
| 9059 | 'e', 'f', 'g', 'h', |
| 9060 | 'i', 'j', 'k', 'l', |
| 9061 | 'm', 'n', 'o', 'p', |
| 9062 | }; |
| 9063 | |
nharper | c32d8ab | 2019-10-09 11:09:06 -0700 | [diff] [blame] | 9064 | unsigned char packet50[] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9065 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 9066 | 0xD3, |
| 9067 | // version tag |
| 9068 | 'Q', '.', '1', '0', |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 9069 | // destination connection ID length |
| 9070 | 0x08, |
| 9071 | // destination connection ID |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9072 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 9073 | // source connection ID length |
| 9074 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9075 | // packet number |
| 9076 | 0x12, 0x34, 0x56, 0x78, |
| 9077 | |
| 9078 | // redundancy |
| 9079 | 'a', 'b', 'c', 'd', |
| 9080 | 'e', 'f', 'g', 'h', |
| 9081 | 'i', 'j', 'k', 'l', |
| 9082 | 'm', 'n', 'o', 'p', |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9083 | 'q', 'r', 's', 't', |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9084 | }; |
| 9085 | // clang-format on |
| 9086 | |
| 9087 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 9088 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9089 | // TODO(ianswett): see todo in previous test. |
nharper | c32d8ab | 2019-10-09 11:09:06 -0700 | [diff] [blame] | 9090 | if (framer_.transport_version() >= QUIC_VERSION_50) { |
| 9091 | p = packet50; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 9092 | p_size = QUICHE_ARRAYSIZE(packet50); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 9093 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9094 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 9095 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9096 | } |
| 9097 | |
| 9098 | std::unique_ptr<QuicPacket> raw(new QuicPacket( |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9099 | AsChars(p), p_size, false, PACKET_8BYTE_CONNECTION_ID, |
| 9100 | PACKET_0BYTE_CONNECTION_ID, kIncludeVersion, |
| 9101 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 9102 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0)); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9103 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9104 | size_t encrypted_length = framer_.EncryptPayload( |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9105 | ENCRYPTION_INITIAL, packet_number, *raw, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9106 | |
| 9107 | ASSERT_NE(0u, encrypted_length); |
| 9108 | EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); |
| 9109 | } |
| 9110 | |
| 9111 | TEST_P(QuicFramerTest, AckTruncationLargePacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9112 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9113 | // This test is not applicable to this version; the range count is |
| 9114 | // effectively unlimited |
| 9115 | return; |
| 9116 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 9117 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9118 | |
| 9119 | QuicPacketHeader header; |
| 9120 | header.destination_connection_id = FramerTestConnectionId(); |
| 9121 | header.reset_flag = false; |
| 9122 | header.version_flag = false; |
| 9123 | header.packet_number = kPacketNumber; |
| 9124 | |
| 9125 | QuicAckFrame ack_frame; |
| 9126 | // Create a packet with just the ack. |
| 9127 | ack_frame = MakeAckFrameWithAckBlocks(300, 0u); |
| 9128 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 9129 | |
| 9130 | // Build an ack packet with truncation due to limit in number of nack ranges. |
| 9131 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9132 | std::unique_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); |
| 9133 | ASSERT_TRUE(raw_ack_packet != nullptr); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9134 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9135 | size_t encrypted_length = |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9136 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9137 | *raw_ack_packet, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9138 | ASSERT_NE(0u, encrypted_length); |
| 9139 | // Now make sure we can turn our ack packet back into an ack frame. |
| 9140 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 9141 | ASSERT_TRUE(framer_.ProcessPacket( |
| 9142 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 9143 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 9144 | QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; |
| 9145 | EXPECT_EQ(QuicPacketNumber(600u), LargestAcked(processed_ack_frame)); |
| 9146 | ASSERT_EQ(256u, processed_ack_frame.packets.NumPacketsSlow()); |
| 9147 | EXPECT_EQ(QuicPacketNumber(90u), processed_ack_frame.packets.Min()); |
| 9148 | EXPECT_EQ(QuicPacketNumber(600u), processed_ack_frame.packets.Max()); |
| 9149 | } |
| 9150 | |
| 9151 | TEST_P(QuicFramerTest, AckTruncationSmallPacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9152 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9153 | // This test is not applicable to this version; the range count is |
| 9154 | // effectively unlimited |
| 9155 | return; |
| 9156 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 9157 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9158 | |
| 9159 | QuicPacketHeader header; |
| 9160 | header.destination_connection_id = FramerTestConnectionId(); |
| 9161 | header.reset_flag = false; |
| 9162 | header.version_flag = false; |
| 9163 | header.packet_number = kPacketNumber; |
| 9164 | |
| 9165 | // Create a packet with just the ack. |
| 9166 | QuicAckFrame ack_frame; |
| 9167 | ack_frame = MakeAckFrameWithAckBlocks(300, 0u); |
| 9168 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 9169 | |
| 9170 | // Build an ack packet with truncation due to limit in number of nack ranges. |
| 9171 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9172 | std::unique_ptr<QuicPacket> raw_ack_packet( |
| 9173 | BuildDataPacket(header, frames, 500)); |
| 9174 | ASSERT_TRUE(raw_ack_packet != nullptr); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9175 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9176 | size_t encrypted_length = |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9177 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9178 | *raw_ack_packet, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9179 | ASSERT_NE(0u, encrypted_length); |
| 9180 | // Now make sure we can turn our ack packet back into an ack frame. |
| 9181 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 9182 | ASSERT_TRUE(framer_.ProcessPacket( |
| 9183 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 9184 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 9185 | QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; |
| 9186 | EXPECT_EQ(QuicPacketNumber(600u), LargestAcked(processed_ack_frame)); |
| 9187 | ASSERT_EQ(240u, processed_ack_frame.packets.NumPacketsSlow()); |
| 9188 | EXPECT_EQ(QuicPacketNumber(122u), processed_ack_frame.packets.Min()); |
| 9189 | EXPECT_EQ(QuicPacketNumber(600u), processed_ack_frame.packets.Max()); |
| 9190 | } |
| 9191 | |
| 9192 | TEST_P(QuicFramerTest, CleanTruncation) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9193 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9194 | // This test is not applicable to this version; the range count is |
| 9195 | // effectively unlimited |
| 9196 | return; |
| 9197 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 9198 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9199 | |
| 9200 | QuicPacketHeader header; |
| 9201 | header.destination_connection_id = FramerTestConnectionId(); |
| 9202 | header.reset_flag = false; |
| 9203 | header.version_flag = false; |
| 9204 | header.packet_number = kPacketNumber; |
| 9205 | |
| 9206 | QuicAckFrame ack_frame = InitAckFrame(201); |
| 9207 | |
| 9208 | // Create a packet with just the ack. |
| 9209 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
nharper | c32d8ab | 2019-10-09 11:09:06 -0700 | [diff] [blame] | 9210 | if (framer_.version().HasHeaderProtection()) { |
| 9211 | frames.push_back(QuicFrame(QuicPaddingFrame(12))); |
| 9212 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9213 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9214 | std::unique_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); |
| 9215 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9216 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9217 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9218 | size_t encrypted_length = |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9219 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9220 | *raw_ack_packet, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9221 | ASSERT_NE(0u, encrypted_length); |
| 9222 | |
| 9223 | // Now make sure we can turn our ack packet back into an ack frame. |
| 9224 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 9225 | ASSERT_TRUE(framer_.ProcessPacket( |
| 9226 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 9227 | |
| 9228 | // Test for clean truncation of the ack by comparing the length of the |
| 9229 | // original packets to the re-serialized packets. |
| 9230 | frames.clear(); |
| 9231 | frames.push_back(QuicFrame(visitor_.ack_frames_[0].get())); |
nharper | c32d8ab | 2019-10-09 11:09:06 -0700 | [diff] [blame] | 9232 | if (framer_.version().HasHeaderProtection()) { |
| 9233 | frames.push_back(QuicFrame(*visitor_.padding_frames_[0].get())); |
| 9234 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9235 | |
| 9236 | size_t original_raw_length = raw_ack_packet->length(); |
| 9237 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9238 | raw_ack_packet = BuildDataPacket(header, frames); |
| 9239 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9240 | EXPECT_EQ(original_raw_length, raw_ack_packet->length()); |
| 9241 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9242 | } |
| 9243 | |
| 9244 | TEST_P(QuicFramerTest, StopPacketProcessing) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9245 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9246 | // clang-format off |
| 9247 | unsigned char packet[] = { |
| 9248 | // public flags (8 byte connection_id) |
| 9249 | 0x28, |
| 9250 | // connection_id |
| 9251 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9252 | // packet number |
| 9253 | 0x12, 0x34, 0x56, 0x78, |
| 9254 | |
| 9255 | // frame type (stream frame with fin) |
| 9256 | 0xFF, |
| 9257 | // stream id |
| 9258 | 0x01, 0x02, 0x03, 0x04, |
| 9259 | // offset |
| 9260 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9261 | 0x32, 0x10, 0x76, 0x54, |
| 9262 | // data length |
| 9263 | 0x00, 0x0c, |
| 9264 | // data |
| 9265 | 'h', 'e', 'l', 'l', |
| 9266 | 'o', ' ', 'w', 'o', |
| 9267 | 'r', 'l', 'd', '!', |
| 9268 | |
| 9269 | // frame type (ack frame) |
| 9270 | 0x40, |
| 9271 | // least packet number awaiting an ack |
| 9272 | 0x12, 0x34, 0x56, 0x78, |
| 9273 | 0x9A, 0xA0, |
| 9274 | // largest observed packet number |
| 9275 | 0x12, 0x34, 0x56, 0x78, |
| 9276 | 0x9A, 0xBF, |
| 9277 | // num missing packets |
| 9278 | 0x01, |
| 9279 | // missing packet |
| 9280 | 0x12, 0x34, 0x56, 0x78, |
| 9281 | 0x9A, 0xBE, |
| 9282 | }; |
| 9283 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9284 | unsigned char packet46[] = { |
| 9285 | // type (short header, 4 byte packet number) |
| 9286 | 0x43, |
| 9287 | // connection_id |
| 9288 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9289 | // packet number |
| 9290 | 0x12, 0x34, 0x56, 0x78, |
| 9291 | |
| 9292 | // frame type (stream frame with fin) |
| 9293 | 0xFF, |
| 9294 | // stream id |
| 9295 | 0x01, 0x02, 0x03, 0x04, |
| 9296 | // offset |
| 9297 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9298 | 0x32, 0x10, 0x76, 0x54, |
| 9299 | // data length |
| 9300 | 0x00, 0x0c, |
| 9301 | // data |
| 9302 | 'h', 'e', 'l', 'l', |
| 9303 | 'o', ' ', 'w', 'o', |
| 9304 | 'r', 'l', 'd', '!', |
| 9305 | |
| 9306 | // frame type (ack frame) |
| 9307 | 0x40, |
| 9308 | // least packet number awaiting an ack |
| 9309 | 0x12, 0x34, 0x56, 0x78, |
| 9310 | 0x9A, 0xA0, |
| 9311 | // largest observed packet number |
| 9312 | 0x12, 0x34, 0x56, 0x78, |
| 9313 | 0x9A, 0xBF, |
| 9314 | // num missing packets |
| 9315 | 0x01, |
| 9316 | // missing packet |
| 9317 | 0x12, 0x34, 0x56, 0x78, |
| 9318 | 0x9A, 0xBE, |
| 9319 | }; |
| 9320 | |
| 9321 | unsigned char packet99[] = { |
| 9322 | // type (short header, 4 byte packet number) |
| 9323 | 0x43, |
| 9324 | // connection_id |
| 9325 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9326 | // packet number |
| 9327 | 0x12, 0x34, 0x56, 0x78, |
| 9328 | |
| 9329 | // frame type (IETF_STREAM frame with fin, length, and offset bits set) |
| 9330 | 0x08 | 0x01 | 0x02 | 0x04, |
| 9331 | // stream id |
| 9332 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 9333 | // offset |
| 9334 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 9335 | 0x32, 0x10, 0x76, 0x54, |
| 9336 | // data length |
| 9337 | kVarInt62TwoBytes + 0x00, 0x0c, |
| 9338 | // data |
| 9339 | 'h', 'e', 'l', 'l', |
| 9340 | 'o', ' ', 'w', 'o', |
| 9341 | 'r', 'l', 'd', '!', |
| 9342 | |
| 9343 | // frame type (ack frame) |
| 9344 | 0x0d, |
| 9345 | // largest observed packet number |
| 9346 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78, |
| 9347 | // Delta time |
| 9348 | kVarInt62OneByte + 0x00, |
| 9349 | // Ack Block count |
| 9350 | kVarInt62OneByte + 0x01, |
| 9351 | // First block size (one packet) |
| 9352 | kVarInt62OneByte + 0x00, |
| 9353 | |
| 9354 | // Next gap size & ack. Missing all preceding packets |
| 9355 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x77, |
| 9356 | kVarInt62OneByte + 0x00, |
| 9357 | }; |
| 9358 | // clang-format on |
| 9359 | |
| 9360 | MockFramerVisitor visitor; |
| 9361 | framer_.set_visitor(&visitor); |
| 9362 | EXPECT_CALL(visitor, OnPacket()); |
| 9363 | EXPECT_CALL(visitor, OnPacketHeader(_)); |
| 9364 | EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false)); |
| 9365 | EXPECT_CALL(visitor, OnPacketComplete()); |
| 9366 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); |
| 9367 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)).WillOnce(Return(true)); |
| 9368 | EXPECT_CALL(visitor, OnDecryptedPacket(_)); |
| 9369 | |
| 9370 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 9371 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9372 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9373 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 9374 | p_size = QUICHE_ARRAYSIZE(packet99); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 9375 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9376 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 9377 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9378 | } |
| 9379 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 9380 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 9381 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9382 | } |
| 9383 | |
| 9384 | static char kTestString[] = "At least 20 characters."; |
| 9385 | static QuicStreamId kTestQuicStreamId = 1; |
| 9386 | static bool ExpectedStreamFrame(const QuicStreamFrame& frame) { |
| 9387 | return (frame.stream_id == kTestQuicStreamId || |
nharper | 46833c3 | 2019-05-15 21:33:05 -0700 | [diff] [blame] | 9388 | QuicUtils::IsCryptoStreamId(QUIC_VERSION_99, frame.stream_id)) && |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9389 | !frame.fin && frame.offset == 0 && |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 9390 | std::string(frame.data_buffer, frame.data_length) == kTestString; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9391 | // FIN is hard-coded false in ConstructEncryptedPacket. |
| 9392 | // Offset 0 is hard-coded in ConstructEncryptedPacket. |
| 9393 | } |
| 9394 | |
| 9395 | // Verify that the packet returned by ConstructEncryptedPacket() can be properly |
| 9396 | // parsed by the framer. |
| 9397 | TEST_P(QuicFramerTest, ConstructEncryptedPacket) { |
| 9398 | // Since we are using ConstructEncryptedPacket, we have to set the framer's |
| 9399 | // crypto to be Null. |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9400 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 9401 | framer_.InstallDecrypter( |
| 9402 | ENCRYPTION_FORWARD_SECURE, |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 9403 | std::make_unique<NullDecrypter>(framer_.perspective())); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9404 | } else { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 9405 | framer_.SetDecrypter(ENCRYPTION_INITIAL, std::make_unique<NullDecrypter>( |
| 9406 | framer_.perspective())); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9407 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9408 | ParsedQuicVersionVector versions; |
| 9409 | versions.push_back(framer_.version()); |
| 9410 | std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( |
| 9411 | TestConnectionId(), EmptyQuicConnectionId(), false, false, |
| 9412 | kTestQuicStreamId, kTestString, CONNECTION_ID_PRESENT, |
| 9413 | CONNECTION_ID_ABSENT, PACKET_4BYTE_PACKET_NUMBER, &versions)); |
| 9414 | |
| 9415 | MockFramerVisitor visitor; |
| 9416 | framer_.set_visitor(&visitor); |
| 9417 | EXPECT_CALL(visitor, OnPacket()).Times(1); |
| 9418 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)) |
| 9419 | .Times(1) |
| 9420 | .WillOnce(Return(true)); |
| 9421 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)) |
| 9422 | .Times(1) |
| 9423 | .WillOnce(Return(true)); |
| 9424 | EXPECT_CALL(visitor, OnPacketHeader(_)).Times(1).WillOnce(Return(true)); |
| 9425 | EXPECT_CALL(visitor, OnDecryptedPacket(_)).Times(1); |
| 9426 | EXPECT_CALL(visitor, OnError(_)).Times(0); |
| 9427 | EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0); |
QUICHE team | ea74008 | 2019-03-11 17:58:43 -0700 | [diff] [blame] | 9428 | if (!QuicVersionUsesCryptoFrames(framer_.version().transport_version)) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9429 | EXPECT_CALL(visitor, OnStreamFrame(Truly(ExpectedStreamFrame))).Times(1); |
| 9430 | } else { |
| 9431 | EXPECT_CALL(visitor, OnCryptoFrame(_)).Times(1); |
| 9432 | } |
| 9433 | EXPECT_CALL(visitor, OnPacketComplete()).Times(1); |
| 9434 | |
| 9435 | EXPECT_TRUE(framer_.ProcessPacket(*packet)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 9436 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9437 | } |
| 9438 | |
| 9439 | // Verify that the packet returned by ConstructMisFramedEncryptedPacket() |
| 9440 | // does cause the framer to return an error. |
| 9441 | TEST_P(QuicFramerTest, ConstructMisFramedEncryptedPacket) { |
| 9442 | // Since we are using ConstructEncryptedPacket, we have to set the framer's |
| 9443 | // crypto to be Null. |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9444 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 9445 | framer_.InstallDecrypter( |
| 9446 | ENCRYPTION_FORWARD_SECURE, |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 9447 | std::make_unique<NullDecrypter>(framer_.perspective())); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9448 | } else { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 9449 | framer_.SetDecrypter(ENCRYPTION_INITIAL, std::make_unique<NullDecrypter>( |
| 9450 | framer_.perspective())); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9451 | } |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9452 | framer_.SetEncrypter(ENCRYPTION_INITIAL, |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 9453 | std::make_unique<NullEncrypter>(framer_.perspective())); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9454 | std::unique_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket( |
| 9455 | TestConnectionId(), EmptyQuicConnectionId(), false, false, |
| 9456 | kTestQuicStreamId, kTestString, CONNECTION_ID_PRESENT, |
bnc | 9711a9e | 2019-11-01 06:31:51 -0700 | [diff] [blame] | 9457 | CONNECTION_ID_ABSENT, PACKET_4BYTE_PACKET_NUMBER, framer_.version(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9458 | Perspective::IS_CLIENT)); |
| 9459 | |
| 9460 | MockFramerVisitor visitor; |
| 9461 | framer_.set_visitor(&visitor); |
| 9462 | EXPECT_CALL(visitor, OnPacket()).Times(1); |
| 9463 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)) |
| 9464 | .Times(1) |
| 9465 | .WillOnce(Return(true)); |
| 9466 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)) |
| 9467 | .Times(1) |
| 9468 | .WillOnce(Return(true)); |
| 9469 | EXPECT_CALL(visitor, OnPacketHeader(_)).Times(1); |
| 9470 | EXPECT_CALL(visitor, OnDecryptedPacket(_)).Times(1); |
| 9471 | EXPECT_CALL(visitor, OnError(_)).Times(1); |
| 9472 | EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0); |
| 9473 | EXPECT_CALL(visitor, OnPacketComplete()).Times(0); |
| 9474 | |
| 9475 | EXPECT_FALSE(framer_.ProcessPacket(*packet)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 9476 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_FRAME_DATA)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9477 | } |
| 9478 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9479 | TEST_P(QuicFramerTest, IetfBlockedFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 9480 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9481 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9482 | return; |
| 9483 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9484 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9485 | |
| 9486 | // clang-format off |
| 9487 | PacketFragments packet99 = { |
| 9488 | // type (short header, 4 byte packet number) |
| 9489 | {"", |
| 9490 | {0x43}}, |
| 9491 | // connection_id |
| 9492 | {"", |
| 9493 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 9494 | // packet number |
| 9495 | {"", |
| 9496 | {0x12, 0x34, 0x9A, 0xBC}}, |
ianswett | 2f07744 | 2019-12-12 11:51:24 -0800 | [diff] [blame] | 9497 | // frame type (IETF_DATA_BLOCKED) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9498 | {"", |
| 9499 | {0x14}}, |
| 9500 | // blocked offset |
| 9501 | {"Can not read blocked offset.", |
| 9502 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 9503 | }; |
| 9504 | // clang-format on |
| 9505 | |
| 9506 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9507 | AssemblePacketFromFragments(packet99)); |
| 9508 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9509 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 9510 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9511 | ASSERT_TRUE(visitor_.header_.get()); |
| 9512 | EXPECT_TRUE(CheckDecryption( |
| 9513 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9514 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9515 | |
| 9516 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 9517 | |
| 9518 | CheckFramingBoundaries(packet99, QUIC_INVALID_BLOCKED_DATA); |
| 9519 | } |
| 9520 | |
| 9521 | TEST_P(QuicFramerTest, BuildIetfBlockedPacket) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 9522 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9523 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9524 | return; |
| 9525 | } |
| 9526 | |
| 9527 | QuicPacketHeader header; |
| 9528 | header.destination_connection_id = FramerTestConnectionId(); |
| 9529 | header.reset_flag = false; |
| 9530 | header.version_flag = false; |
| 9531 | header.packet_number = kPacketNumber; |
| 9532 | |
| 9533 | QuicBlockedFrame frame; |
| 9534 | frame.stream_id = QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
| 9535 | frame.offset = kStreamOffset; |
| 9536 | QuicFrames frames = {QuicFrame(&frame)}; |
| 9537 | |
| 9538 | // clang-format off |
| 9539 | unsigned char packet99[] = { |
| 9540 | // type (short header, 4 byte packet number) |
| 9541 | 0x43, |
| 9542 | // connection_id |
| 9543 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9544 | // packet number |
| 9545 | 0x12, 0x34, 0x56, 0x78, |
| 9546 | |
ianswett | 2f07744 | 2019-12-12 11:51:24 -0800 | [diff] [blame] | 9547 | // frame type (IETF_DATA_BLOCKED) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9548 | 0x14, |
| 9549 | // Offset |
| 9550 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 9551 | }; |
| 9552 | // clang-format on |
| 9553 | |
| 9554 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 9555 | ASSERT_TRUE(data != nullptr); |
| 9556 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 9557 | quiche::test::CompareCharArraysWithHexError( |
| 9558 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
| 9559 | QUICHE_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9560 | } |
| 9561 | |
| 9562 | TEST_P(QuicFramerTest, IetfStreamBlockedFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 9563 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9564 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9565 | return; |
| 9566 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9567 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9568 | |
| 9569 | // clang-format off |
| 9570 | PacketFragments packet99 = { |
| 9571 | // type (short header, 4 byte packet number) |
| 9572 | {"", |
| 9573 | {0x43}}, |
| 9574 | // connection_id |
| 9575 | {"", |
| 9576 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 9577 | // packet number |
| 9578 | {"", |
| 9579 | {0x12, 0x34, 0x9A, 0xBC}}, |
ianswett | 2f07744 | 2019-12-12 11:51:24 -0800 | [diff] [blame] | 9580 | // frame type (IETF_STREAM_DATA_BLOCKED) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9581 | {"", |
| 9582 | {0x15}}, |
| 9583 | // blocked offset |
| 9584 | {"Can not read stream blocked stream id.", |
| 9585 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 9586 | {"Can not read stream blocked offset.", |
| 9587 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 9588 | }; |
| 9589 | // clang-format on |
| 9590 | |
| 9591 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9592 | AssemblePacketFromFragments(packet99)); |
| 9593 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9594 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 9595 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9596 | ASSERT_TRUE(visitor_.header_.get()); |
| 9597 | EXPECT_TRUE(CheckDecryption( |
| 9598 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9599 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9600 | |
| 9601 | EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id); |
| 9602 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 9603 | |
| 9604 | CheckFramingBoundaries(packet99, QUIC_INVALID_STREAM_BLOCKED_DATA); |
| 9605 | } |
| 9606 | |
| 9607 | TEST_P(QuicFramerTest, BuildIetfStreamBlockedPacket) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 9608 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9609 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9610 | return; |
| 9611 | } |
| 9612 | |
| 9613 | QuicPacketHeader header; |
| 9614 | header.destination_connection_id = FramerTestConnectionId(); |
| 9615 | header.reset_flag = false; |
| 9616 | header.version_flag = false; |
| 9617 | header.packet_number = kPacketNumber; |
| 9618 | |
| 9619 | QuicBlockedFrame frame; |
| 9620 | frame.stream_id = kStreamId; |
| 9621 | frame.offset = kStreamOffset; |
| 9622 | QuicFrames frames = {QuicFrame(&frame)}; |
| 9623 | |
| 9624 | // clang-format off |
| 9625 | unsigned char packet99[] = { |
| 9626 | // type (short header, 4 byte packet number) |
| 9627 | 0x43, |
| 9628 | // connection_id |
| 9629 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9630 | // packet number |
| 9631 | 0x12, 0x34, 0x56, 0x78, |
| 9632 | |
ianswett | 2f07744 | 2019-12-12 11:51:24 -0800 | [diff] [blame] | 9633 | // frame type (IETF_STREAM_DATA_BLOCKED) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9634 | 0x15, |
| 9635 | // Stream ID |
| 9636 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 9637 | // Offset |
| 9638 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 9639 | }; |
| 9640 | // clang-format on |
| 9641 | |
| 9642 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 9643 | ASSERT_TRUE(data != nullptr); |
| 9644 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 9645 | quiche::test::CompareCharArraysWithHexError( |
| 9646 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
| 9647 | QUICHE_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9648 | } |
| 9649 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9650 | TEST_P(QuicFramerTest, BiDiMaxStreamsFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 9651 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9652 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9653 | return; |
| 9654 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9655 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9656 | |
| 9657 | // clang-format off |
| 9658 | PacketFragments packet99 = { |
| 9659 | // type (short header, 4 byte packet number) |
| 9660 | {"", |
| 9661 | {0x43}}, |
| 9662 | // connection_id |
| 9663 | {"", |
| 9664 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 9665 | // packet number |
| 9666 | {"", |
| 9667 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 9668 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 9669 | {"", |
| 9670 | {0x12}}, |
| 9671 | // max. streams |
| 9672 | {"Can not read MAX_STREAMS stream count.", |
| 9673 | {kVarInt62OneByte + 0x03}}, |
| 9674 | }; |
| 9675 | // clang-format on |
| 9676 | |
| 9677 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9678 | AssemblePacketFromFragments(packet99)); |
| 9679 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9680 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 9681 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9682 | ASSERT_TRUE(visitor_.header_.get()); |
| 9683 | EXPECT_TRUE(CheckDecryption( |
| 9684 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9685 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9686 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9687 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 9688 | EXPECT_FALSE(visitor_.max_streams_frame_.unidirectional); |
| 9689 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9690 | } |
| 9691 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9692 | TEST_P(QuicFramerTest, UniDiMaxStreamsFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 9693 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9694 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9695 | return; |
| 9696 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9697 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9698 | |
| 9699 | // clang-format off |
| 9700 | PacketFragments packet99 = { |
| 9701 | // type (short header, 4 byte packet number) |
| 9702 | {"", |
| 9703 | {0x43}}, |
| 9704 | // Test runs in client mode, no connection id |
| 9705 | // packet number |
| 9706 | {"", |
| 9707 | {0x12, 0x34, 0x9A, 0xBC}}, |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9708 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9709 | {"", |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9710 | {0x13}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9711 | // max. streams |
| 9712 | {"Can not read MAX_STREAMS stream count.", |
| 9713 | {kVarInt62OneByte + 0x03}}, |
| 9714 | }; |
| 9715 | // clang-format on |
| 9716 | |
| 9717 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9718 | AssemblePacketFromFragments(packet99)); |
| 9719 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9720 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9721 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 9722 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9723 | ASSERT_TRUE(visitor_.header_.get()); |
| 9724 | EXPECT_TRUE(CheckDecryption( |
| 9725 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9726 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9727 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9728 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 9729 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 9730 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9731 | } |
| 9732 | |
| 9733 | TEST_P(QuicFramerTest, ServerUniDiMaxStreamsFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 9734 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9735 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9736 | return; |
| 9737 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9738 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9739 | |
| 9740 | // clang-format off |
| 9741 | PacketFragments packet99 = { |
| 9742 | // type (short header, 4 byte packet number) |
| 9743 | {"", |
| 9744 | {0x43}}, |
| 9745 | // connection_id |
| 9746 | {"", |
| 9747 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 9748 | // packet number |
| 9749 | {"", |
| 9750 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 9751 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 9752 | {"", |
| 9753 | {0x13}}, |
| 9754 | // max. streams |
| 9755 | {"Can not read MAX_STREAMS stream count.", |
| 9756 | {kVarInt62OneByte + 0x03}}, |
| 9757 | }; |
| 9758 | // clang-format on |
| 9759 | |
| 9760 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9761 | AssemblePacketFromFragments(packet99)); |
| 9762 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9763 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 9764 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9765 | ASSERT_TRUE(visitor_.header_.get()); |
| 9766 | EXPECT_TRUE(CheckDecryption( |
| 9767 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9768 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9769 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9770 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 9771 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 9772 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9773 | } |
| 9774 | |
| 9775 | TEST_P(QuicFramerTest, ClientUniDiMaxStreamsFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 9776 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9777 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9778 | return; |
| 9779 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9780 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9781 | |
| 9782 | // clang-format off |
| 9783 | PacketFragments packet99 = { |
| 9784 | // type (short header, 4 byte packet number) |
| 9785 | {"", |
| 9786 | {0x43}}, |
| 9787 | // Test runs in client mode, no connection id |
| 9788 | // packet number |
| 9789 | {"", |
| 9790 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 9791 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 9792 | {"", |
| 9793 | {0x13}}, |
| 9794 | // max. streams |
| 9795 | {"Can not read MAX_STREAMS stream count.", |
| 9796 | {kVarInt62OneByte + 0x03}}, |
| 9797 | }; |
| 9798 | // clang-format on |
| 9799 | |
| 9800 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9801 | AssemblePacketFromFragments(packet99)); |
| 9802 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9803 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9804 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 9805 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9806 | ASSERT_TRUE(visitor_.header_.get()); |
| 9807 | EXPECT_TRUE(CheckDecryption( |
| 9808 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9809 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9810 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9811 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 9812 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 9813 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9814 | } |
| 9815 | |
| 9816 | // The following four tests ensure that the framer can deserialize a stream |
| 9817 | // count that is large enough to cause the resulting stream ID to exceed the |
| 9818 | // current implementation limit(32 bits). The intent is that when this happens, |
| 9819 | // the stream limit is pegged to the maximum supported value. There are four |
| 9820 | // tests, for the four combinations of uni- and bi-directional, server- and |
| 9821 | // client- initiated. |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9822 | TEST_P(QuicFramerTest, BiDiMaxStreamsFrameTooBig) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 9823 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9824 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9825 | return; |
| 9826 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9827 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9828 | |
| 9829 | // clang-format off |
| 9830 | unsigned char packet99[] = { |
| 9831 | // type (short header, 4 byte packet number) |
| 9832 | 0x43, |
| 9833 | // connection_id |
| 9834 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9835 | // packet number |
| 9836 | 0x12, 0x34, 0x9A, 0xBC, |
| 9837 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 9838 | 0x12, |
| 9839 | |
| 9840 | // max. streams. Max stream ID allowed is 0xffffffff |
| 9841 | // This encodes a count of 0x40000000, leading to stream |
| 9842 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 9843 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 9844 | }; |
| 9845 | // clang-format on |
| 9846 | |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 9847 | QuicEncryptedPacket encrypted(AsChars(packet99), QUICHE_ARRAYSIZE(packet99), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9848 | false); |
| 9849 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 9850 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9851 | ASSERT_TRUE(visitor_.header_.get()); |
| 9852 | EXPECT_TRUE(CheckDecryption( |
| 9853 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9854 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9855 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 9856 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9857 | EXPECT_FALSE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9858 | } |
| 9859 | |
| 9860 | TEST_P(QuicFramerTest, ClientBiDiMaxStreamsFrameTooBig) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 9861 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9862 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9863 | return; |
| 9864 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9865 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9866 | |
| 9867 | // clang-format off |
| 9868 | unsigned char packet99[] = { |
| 9869 | // type (short header, 4 byte packet number) |
| 9870 | 0x43, |
| 9871 | // Test runs in client mode, no connection id |
| 9872 | // packet number |
| 9873 | 0x12, 0x34, 0x9A, 0xBC, |
| 9874 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 9875 | 0x12, |
| 9876 | |
| 9877 | // max. streams. Max stream ID allowed is 0xffffffff |
| 9878 | // This encodes a count of 0x40000000, leading to stream |
| 9879 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 9880 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 9881 | }; |
| 9882 | // clang-format on |
| 9883 | |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 9884 | QuicEncryptedPacket encrypted(AsChars(packet99), QUICHE_ARRAYSIZE(packet99), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9885 | false); |
| 9886 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9887 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 9888 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 9889 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9890 | ASSERT_TRUE(visitor_.header_.get()); |
| 9891 | EXPECT_TRUE(CheckDecryption( |
| 9892 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9893 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9894 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 9895 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9896 | EXPECT_FALSE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9897 | } |
| 9898 | |
| 9899 | TEST_P(QuicFramerTest, ServerUniDiMaxStreamsFrameTooBig) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 9900 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9901 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9902 | return; |
| 9903 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9904 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9905 | |
| 9906 | // clang-format off |
| 9907 | unsigned char packet99[] = { |
| 9908 | // type (short header, 4 byte packet number) |
| 9909 | 0x43, |
| 9910 | // connection_id |
| 9911 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9912 | // packet number |
| 9913 | 0x12, 0x34, 0x9A, 0xBC, |
| 9914 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 9915 | 0x13, |
| 9916 | |
| 9917 | // max. streams. Max stream ID allowed is 0xffffffff |
| 9918 | // This encodes a count of 0x40000000, leading to stream |
| 9919 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 9920 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 9921 | }; |
| 9922 | // clang-format on |
| 9923 | |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 9924 | QuicEncryptedPacket encrypted(AsChars(packet99), QUICHE_ARRAYSIZE(packet99), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9925 | false); |
| 9926 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 9927 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 9928 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9929 | ASSERT_TRUE(visitor_.header_.get()); |
| 9930 | EXPECT_TRUE(CheckDecryption( |
| 9931 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9932 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9933 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 9934 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9935 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9936 | } |
| 9937 | |
| 9938 | TEST_P(QuicFramerTest, ClientUniDiMaxStreamsFrameTooBig) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 9939 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9940 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9941 | return; |
| 9942 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9943 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9944 | |
| 9945 | // clang-format off |
| 9946 | unsigned char packet99[] = { |
| 9947 | // type (short header, 4 byte packet number) |
| 9948 | 0x43, |
| 9949 | // Test runs in client mode, no connection id |
| 9950 | // packet number |
| 9951 | 0x12, 0x34, 0x9A, 0xBC, |
| 9952 | // frame type (IETF_MAX_STREAMS_UNDIRECTIONAL) |
| 9953 | 0x13, |
| 9954 | |
| 9955 | // max. streams. Max stream ID allowed is 0xffffffff |
| 9956 | // This encodes a count of 0x40000000, leading to stream |
| 9957 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 9958 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 9959 | }; |
| 9960 | // clang-format on |
| 9961 | |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 9962 | QuicEncryptedPacket encrypted(AsChars(packet99), QUICHE_ARRAYSIZE(packet99), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9963 | false); |
| 9964 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9965 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 9966 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 9967 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9968 | ASSERT_TRUE(visitor_.header_.get()); |
| 9969 | EXPECT_TRUE(CheckDecryption( |
| 9970 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9971 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9972 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 9973 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9974 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9975 | } |
| 9976 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 9977 | // Specifically test that count==0 is accepted. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9978 | TEST_P(QuicFramerTest, MaxStreamsFrameZeroCount) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 9979 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9980 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9981 | return; |
| 9982 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9983 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9984 | |
| 9985 | // clang-format off |
| 9986 | unsigned char packet99[] = { |
| 9987 | // type (short header, 4 byte packet number) |
| 9988 | 0x43, |
| 9989 | // connection_id |
| 9990 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9991 | // packet number |
| 9992 | 0x12, 0x34, 0x9A, 0xBC, |
| 9993 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 9994 | 0x12, |
| 9995 | // max. streams == 0. |
| 9996 | kVarInt62OneByte + 0x00 |
| 9997 | }; |
| 9998 | // clang-format on |
| 9999 | |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 10000 | QuicEncryptedPacket encrypted(AsChars(packet99), QUICHE_ARRAYSIZE(packet99), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10001 | false); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10002 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10003 | } |
| 10004 | |
| 10005 | TEST_P(QuicFramerTest, ServerBiDiStreamsBlockedFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10006 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10007 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10008 | return; |
| 10009 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10010 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10011 | |
| 10012 | // clang-format off |
| 10013 | PacketFragments packet99 = { |
| 10014 | // type (short header, 4 byte packet number) |
| 10015 | {"", |
| 10016 | {0x43}}, |
| 10017 | // connection_id |
| 10018 | {"", |
| 10019 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10020 | // packet number |
| 10021 | {"", |
| 10022 | {0x12, 0x34, 0x9A, 0xBC}}, |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10023 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL frame) |
| 10024 | {"", |
| 10025 | {0x13}}, |
| 10026 | // stream count |
| 10027 | {"Can not read MAX_STREAMS stream count.", |
| 10028 | {kVarInt62OneByte + 0x00}}, |
| 10029 | }; |
| 10030 | // clang-format on |
| 10031 | |
| 10032 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10033 | AssemblePacketFromFragments(packet99)); |
| 10034 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10035 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10036 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10037 | ASSERT_TRUE(visitor_.header_.get()); |
| 10038 | EXPECT_TRUE(CheckDecryption( |
| 10039 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10040 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10041 | |
| 10042 | EXPECT_EQ(0u, visitor_.max_streams_frame_.stream_count); |
| 10043 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 10044 | |
| 10045 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
| 10046 | } |
| 10047 | |
| 10048 | TEST_P(QuicFramerTest, BiDiStreamsBlockedFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10049 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10050 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10051 | return; |
| 10052 | } |
| 10053 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 10054 | |
| 10055 | // clang-format off |
| 10056 | PacketFragments packet99 = { |
| 10057 | // type (short header, 4 byte packet number) |
| 10058 | {"", |
| 10059 | {0x43}}, |
| 10060 | // connection_id |
| 10061 | {"", |
| 10062 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10063 | // packet number |
| 10064 | {"", |
| 10065 | {0x12, 0x34, 0x9A, 0xBC}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10066 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL frame) |
| 10067 | {"", |
| 10068 | {0x16}}, |
| 10069 | // stream id |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10070 | {"Can not read STREAMS_BLOCKED stream count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10071 | {kVarInt62OneByte + 0x03}}, |
| 10072 | }; |
| 10073 | // clang-format on |
| 10074 | |
| 10075 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10076 | AssemblePacketFromFragments(packet99)); |
| 10077 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10078 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10079 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10080 | ASSERT_TRUE(visitor_.header_.get()); |
| 10081 | EXPECT_TRUE(CheckDecryption( |
| 10082 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10083 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10084 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10085 | EXPECT_EQ(3u, visitor_.streams_blocked_frame_.stream_count); |
| 10086 | EXPECT_FALSE(visitor_.streams_blocked_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10087 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10088 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10089 | } |
| 10090 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10091 | TEST_P(QuicFramerTest, UniDiStreamsBlockedFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10092 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10093 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10094 | return; |
| 10095 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10096 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10097 | |
| 10098 | // clang-format off |
| 10099 | PacketFragments packet99 = { |
| 10100 | // type (short header, 4 byte packet number) |
| 10101 | {"", |
| 10102 | {0x43}}, |
| 10103 | // connection_id |
| 10104 | {"", |
| 10105 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10106 | // packet number |
| 10107 | {"", |
| 10108 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10109 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10110 | {"", |
| 10111 | {0x17}}, |
| 10112 | // stream id |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10113 | {"Can not read STREAMS_BLOCKED stream count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10114 | {kVarInt62OneByte + 0x03}}, |
| 10115 | }; |
| 10116 | // clang-format on |
| 10117 | |
| 10118 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10119 | AssemblePacketFromFragments(packet99)); |
| 10120 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10121 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10122 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10123 | ASSERT_TRUE(visitor_.header_.get()); |
| 10124 | EXPECT_TRUE(CheckDecryption( |
| 10125 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10126 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10127 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10128 | EXPECT_EQ(3u, visitor_.streams_blocked_frame_.stream_count); |
| 10129 | EXPECT_TRUE(visitor_.streams_blocked_frame_.unidirectional); |
| 10130 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10131 | } |
| 10132 | |
| 10133 | TEST_P(QuicFramerTest, ClientUniDiStreamsBlockedFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10134 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10135 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10136 | return; |
| 10137 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10138 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10139 | |
| 10140 | // clang-format off |
| 10141 | PacketFragments packet99 = { |
| 10142 | // type (short header, 4 byte packet number) |
| 10143 | {"", |
| 10144 | {0x43}}, |
| 10145 | // Test runs in client mode, no connection id |
| 10146 | // packet number |
| 10147 | {"", |
| 10148 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10149 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10150 | {"", |
| 10151 | {0x17}}, |
| 10152 | // stream id |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10153 | {"Can not read STREAMS_BLOCKED stream count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10154 | {kVarInt62OneByte + 0x03}}, |
| 10155 | }; |
| 10156 | // clang-format on |
| 10157 | |
| 10158 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10159 | AssemblePacketFromFragments(packet99)); |
| 10160 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10161 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10162 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10163 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10164 | ASSERT_TRUE(visitor_.header_.get()); |
| 10165 | EXPECT_TRUE(CheckDecryption( |
| 10166 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10167 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10168 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10169 | EXPECT_EQ(3u, visitor_.streams_blocked_frame_.stream_count); |
| 10170 | EXPECT_TRUE(visitor_.streams_blocked_frame_.unidirectional); |
| 10171 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10172 | } |
| 10173 | |
| 10174 | // Check that when we get a STREAMS_BLOCKED frame that specifies too large |
| 10175 | // a stream count, we reject with an appropriate error. There is no need to |
| 10176 | // check for different combinations of Uni/Bi directional and client/server |
| 10177 | // initiated; the logic does not take these into account. |
| 10178 | TEST_P(QuicFramerTest, StreamsBlockedFrameTooBig) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10179 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10180 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10181 | return; |
| 10182 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10183 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10184 | |
| 10185 | // clang-format off |
| 10186 | unsigned char packet99[] = { |
| 10187 | // type (short header, 4 byte packet number) |
| 10188 | 0x43, |
| 10189 | // Test runs in client mode, no connection id |
| 10190 | // packet number |
| 10191 | 0x12, 0x34, 0x9A, 0xBC, |
| 10192 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL) |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10193 | 0x16, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10194 | |
| 10195 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10196 | // This encodes a count of 0x40000000, leading to stream |
| 10197 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10198 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01 |
| 10199 | }; |
| 10200 | // clang-format on |
| 10201 | |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 10202 | QuicEncryptedPacket encrypted(AsChars(packet99), QUICHE_ARRAYSIZE(packet99), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10203 | false); |
| 10204 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10205 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 10206 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10207 | EXPECT_THAT(framer_.error(), IsError(QUIC_STREAMS_BLOCKED_DATA)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10208 | EXPECT_EQ(framer_.detailed_error(), |
| 10209 | "STREAMS_BLOCKED stream count exceeds implementation limit."); |
| 10210 | } |
| 10211 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10212 | // Specifically test that count==0 is accepted. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10213 | TEST_P(QuicFramerTest, StreamsBlockedFrameZeroCount) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10214 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10215 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10216 | return; |
| 10217 | } |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10218 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10219 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10220 | |
| 10221 | // clang-format off |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10222 | PacketFragments packet99 = { |
| 10223 | // type (short header, 4 byte packet number) |
| 10224 | {"", |
| 10225 | {0x43}}, |
| 10226 | // connection_id |
| 10227 | {"", |
| 10228 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10229 | // packet number |
| 10230 | {"", |
| 10231 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10232 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10233 | {"", |
| 10234 | {0x17}}, |
| 10235 | // stream id |
| 10236 | {"Can not read STREAMS_BLOCKED stream count.", |
| 10237 | {kVarInt62OneByte + 0x00}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10238 | }; |
| 10239 | // clang-format on |
| 10240 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10241 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10242 | AssemblePacketFromFragments(packet99)); |
| 10243 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10244 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10245 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10246 | ASSERT_TRUE(visitor_.header_.get()); |
| 10247 | EXPECT_TRUE(CheckDecryption( |
| 10248 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10249 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10250 | |
| 10251 | EXPECT_EQ(0u, visitor_.streams_blocked_frame_.stream_count); |
| 10252 | EXPECT_TRUE(visitor_.streams_blocked_frame_.unidirectional); |
| 10253 | |
| 10254 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10255 | } |
| 10256 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10257 | TEST_P(QuicFramerTest, BuildBiDiStreamsBlockedPacket) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10258 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10259 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10260 | return; |
| 10261 | } |
| 10262 | |
| 10263 | QuicPacketHeader header; |
| 10264 | header.destination_connection_id = FramerTestConnectionId(); |
| 10265 | header.reset_flag = false; |
| 10266 | header.version_flag = false; |
| 10267 | header.packet_number = kPacketNumber; |
| 10268 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10269 | QuicStreamsBlockedFrame frame; |
| 10270 | frame.stream_count = 3; |
| 10271 | frame.unidirectional = false; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10272 | |
| 10273 | QuicFrames frames = {QuicFrame(frame)}; |
| 10274 | |
| 10275 | // clang-format off |
| 10276 | unsigned char packet99[] = { |
| 10277 | // type (short header, 4 byte packet number) |
| 10278 | 0x43, |
| 10279 | // connection_id |
| 10280 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10281 | // packet number |
| 10282 | 0x12, 0x34, 0x56, 0x78, |
| 10283 | |
| 10284 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL frame) |
| 10285 | 0x16, |
| 10286 | // Stream count |
| 10287 | kVarInt62OneByte + 0x03 |
| 10288 | }; |
| 10289 | // clang-format on |
| 10290 | |
| 10291 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10292 | ASSERT_TRUE(data != nullptr); |
| 10293 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 10294 | quiche::test::CompareCharArraysWithHexError( |
| 10295 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
| 10296 | QUICHE_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10297 | } |
| 10298 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10299 | TEST_P(QuicFramerTest, BuildUniStreamsBlockedPacket) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10300 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10301 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10302 | return; |
| 10303 | } |
| 10304 | |
| 10305 | QuicPacketHeader header; |
| 10306 | header.destination_connection_id = FramerTestConnectionId(); |
| 10307 | header.reset_flag = false; |
| 10308 | header.version_flag = false; |
| 10309 | header.packet_number = kPacketNumber; |
| 10310 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10311 | QuicStreamsBlockedFrame frame; |
| 10312 | frame.stream_count = 3; |
| 10313 | frame.unidirectional = true; |
| 10314 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10315 | QuicFrames frames = {QuicFrame(frame)}; |
| 10316 | |
| 10317 | // clang-format off |
| 10318 | unsigned char packet99[] = { |
| 10319 | // type (short header, 4 byte packet number) |
| 10320 | 0x43, |
| 10321 | // connection_id |
| 10322 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10323 | // packet number |
| 10324 | 0x12, 0x34, 0x56, 0x78, |
| 10325 | |
| 10326 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10327 | 0x17, |
| 10328 | // Stream count |
| 10329 | kVarInt62OneByte + 0x03 |
| 10330 | }; |
| 10331 | // clang-format on |
| 10332 | |
| 10333 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10334 | ASSERT_TRUE(data != nullptr); |
| 10335 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 10336 | quiche::test::CompareCharArraysWithHexError( |
| 10337 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
| 10338 | QUICHE_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10339 | } |
| 10340 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10341 | TEST_P(QuicFramerTest, BuildBiDiMaxStreamsPacket) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10342 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10343 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10344 | return; |
| 10345 | } |
| 10346 | |
| 10347 | QuicPacketHeader header; |
| 10348 | header.destination_connection_id = FramerTestConnectionId(); |
| 10349 | header.reset_flag = false; |
| 10350 | header.version_flag = false; |
| 10351 | header.packet_number = kPacketNumber; |
| 10352 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10353 | QuicMaxStreamsFrame frame; |
| 10354 | frame.stream_count = 3; |
| 10355 | frame.unidirectional = false; |
| 10356 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10357 | QuicFrames frames = {QuicFrame(frame)}; |
| 10358 | |
| 10359 | // clang-format off |
| 10360 | unsigned char packet99[] = { |
| 10361 | // type (short header, 4 byte packet number) |
| 10362 | 0x43, |
| 10363 | // connection_id |
| 10364 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10365 | // packet number |
| 10366 | 0x12, 0x34, 0x56, 0x78, |
| 10367 | |
| 10368 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL frame) |
| 10369 | 0x12, |
| 10370 | // Stream count |
| 10371 | kVarInt62OneByte + 0x03 |
| 10372 | }; |
| 10373 | // clang-format on |
| 10374 | |
| 10375 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10376 | ASSERT_TRUE(data != nullptr); |
| 10377 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 10378 | quiche::test::CompareCharArraysWithHexError( |
| 10379 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
| 10380 | QUICHE_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10381 | } |
| 10382 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10383 | TEST_P(QuicFramerTest, BuildUniDiMaxStreamsPacket) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10384 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10385 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10386 | return; |
| 10387 | } |
| 10388 | |
| 10389 | // This test runs in client mode. |
| 10390 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10391 | |
| 10392 | QuicPacketHeader header; |
| 10393 | header.destination_connection_id = FramerTestConnectionId(); |
| 10394 | header.reset_flag = false; |
| 10395 | header.version_flag = false; |
| 10396 | header.packet_number = kPacketNumber; |
| 10397 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10398 | QuicMaxStreamsFrame frame; |
| 10399 | frame.stream_count = 3; |
| 10400 | frame.unidirectional = true; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10401 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10402 | QuicFrames frames = {QuicFrame(frame)}; |
| 10403 | |
| 10404 | // clang-format off |
| 10405 | unsigned char packet99[] = { |
| 10406 | // type (short header, 4 byte packet number) |
| 10407 | 0x43, |
| 10408 | // connection_id |
| 10409 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10410 | // packet number |
| 10411 | 0x12, 0x34, 0x56, 0x78, |
| 10412 | |
| 10413 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL frame) |
| 10414 | 0x13, |
| 10415 | // Stream count |
| 10416 | kVarInt62OneByte + 0x03 |
| 10417 | }; |
| 10418 | // clang-format on |
| 10419 | |
| 10420 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10421 | ASSERT_TRUE(data != nullptr); |
| 10422 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 10423 | quiche::test::CompareCharArraysWithHexError( |
| 10424 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
| 10425 | QUICHE_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10426 | } |
| 10427 | |
| 10428 | TEST_P(QuicFramerTest, NewConnectionIdFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10429 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10430 | // This frame is only for IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10431 | return; |
| 10432 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10433 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10434 | // clang-format off |
| 10435 | PacketFragments packet99 = { |
| 10436 | // type (short header, 4 byte packet number) |
| 10437 | {"", |
| 10438 | {0x43}}, |
| 10439 | // connection_id |
| 10440 | {"", |
| 10441 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10442 | // packet number |
| 10443 | {"", |
| 10444 | {0x12, 0x34, 0x56, 0x78}}, |
| 10445 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 10446 | {"", |
| 10447 | {0x18}}, |
| 10448 | // error code |
| 10449 | {"Unable to read new connection ID frame sequence number.", |
| 10450 | {kVarInt62OneByte + 0x11}}, |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 10451 | {"Unable to read new connection ID frame retire_prior_to.", |
| 10452 | {kVarInt62OneByte + 0x09}}, |
dschinazi | cf5b1e2 | 2019-07-17 18:35:17 -0700 | [diff] [blame] | 10453 | {"Unable to read new connection ID frame connection id.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10454 | {0x08}}, // connection ID length |
| 10455 | {"Unable to read new connection ID frame connection id.", |
| 10456 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11}}, |
| 10457 | {"Can not read new connection ID frame reset token.", |
| 10458 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 10459 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 10460 | }; |
| 10461 | // clang-format on |
| 10462 | |
| 10463 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10464 | AssemblePacketFromFragments(packet99)); |
| 10465 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10466 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10467 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10468 | ASSERT_TRUE(visitor_.header_.get()); |
| 10469 | EXPECT_TRUE(CheckDecryption( |
| 10470 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10471 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10472 | |
| 10473 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 10474 | |
| 10475 | EXPECT_EQ(FramerTestConnectionIdPlusOne(), |
| 10476 | visitor_.new_connection_id_.connection_id); |
| 10477 | EXPECT_EQ(0x11u, visitor_.new_connection_id_.sequence_number); |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 10478 | EXPECT_EQ(0x09u, visitor_.new_connection_id_.retire_prior_to); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10479 | EXPECT_EQ(kTestStatelessResetToken, |
| 10480 | visitor_.new_connection_id_.stateless_reset_token); |
| 10481 | |
| 10482 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 10483 | |
| 10484 | CheckFramingBoundaries(packet99, QUIC_INVALID_NEW_CONNECTION_ID_DATA); |
| 10485 | } |
| 10486 | |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 10487 | TEST_P(QuicFramerTest, NewConnectionIdFrameVariableLength) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10488 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10489 | // This frame is only for IETF QUIC. |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 10490 | return; |
| 10491 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10492 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 10493 | // clang-format off |
| 10494 | PacketFragments packet99 = { |
| 10495 | // type (short header, 4 byte packet number) |
| 10496 | {"", |
| 10497 | {0x43}}, |
| 10498 | // connection_id |
| 10499 | {"", |
| 10500 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10501 | // packet number |
| 10502 | {"", |
| 10503 | {0x12, 0x34, 0x56, 0x78}}, |
| 10504 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 10505 | {"", |
| 10506 | {0x18}}, |
| 10507 | // error code |
| 10508 | {"Unable to read new connection ID frame sequence number.", |
| 10509 | {kVarInt62OneByte + 0x11}}, |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 10510 | {"Unable to read new connection ID frame retire_prior_to.", |
| 10511 | {kVarInt62OneByte + 0x0a}}, |
dschinazi | cf5b1e2 | 2019-07-17 18:35:17 -0700 | [diff] [blame] | 10512 | {"Unable to read new connection ID frame connection id.", |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 10513 | {0x09}}, // connection ID length |
| 10514 | {"Unable to read new connection ID frame connection id.", |
| 10515 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42}}, |
| 10516 | {"Can not read new connection ID frame reset token.", |
| 10517 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 10518 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 10519 | }; |
| 10520 | // clang-format on |
| 10521 | |
| 10522 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10523 | AssemblePacketFromFragments(packet99)); |
| 10524 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10525 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10526 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 10527 | ASSERT_TRUE(visitor_.header_.get()); |
| 10528 | EXPECT_TRUE(CheckDecryption( |
| 10529 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10530 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10531 | |
| 10532 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 10533 | |
| 10534 | EXPECT_EQ(FramerTestConnectionIdNineBytes(), |
| 10535 | visitor_.new_connection_id_.connection_id); |
| 10536 | EXPECT_EQ(0x11u, visitor_.new_connection_id_.sequence_number); |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 10537 | EXPECT_EQ(0x0au, visitor_.new_connection_id_.retire_prior_to); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 10538 | EXPECT_EQ(kTestStatelessResetToken, |
| 10539 | visitor_.new_connection_id_.stateless_reset_token); |
| 10540 | |
| 10541 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 10542 | |
| 10543 | CheckFramingBoundaries(packet99, QUIC_INVALID_NEW_CONNECTION_ID_DATA); |
| 10544 | } |
| 10545 | |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 10546 | // Verifies that parsing a NEW_CONNECTION_ID frame with a length above the |
| 10547 | // specified maximum fails. |
| 10548 | TEST_P(QuicFramerTest, InvalidLongNewConnectionIdFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10549 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10550 | // The NEW_CONNECTION_ID frame is only for IETF QUIC. |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 10551 | return; |
| 10552 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10553 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 10554 | // clang-format off |
| 10555 | PacketFragments packet99 = { |
| 10556 | // type (short header, 4 byte packet number) |
| 10557 | {"", |
| 10558 | {0x43}}, |
| 10559 | // connection_id |
| 10560 | {"", |
| 10561 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10562 | // packet number |
| 10563 | {"", |
| 10564 | {0x12, 0x34, 0x56, 0x78}}, |
| 10565 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 10566 | {"", |
| 10567 | {0x18}}, |
| 10568 | // error code |
| 10569 | {"Unable to read new connection ID frame sequence number.", |
| 10570 | {kVarInt62OneByte + 0x11}}, |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 10571 | {"Unable to read new connection ID frame retire_prior_to.", |
| 10572 | {kVarInt62OneByte + 0x0b}}, |
dschinazi | cf5b1e2 | 2019-07-17 18:35:17 -0700 | [diff] [blame] | 10573 | {"Unable to read new connection ID frame connection id.", |
dschinazi | b953d02 | 2019-08-01 18:05:58 -0700 | [diff] [blame] | 10574 | {0x40}}, // connection ID length |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 10575 | {"Unable to read new connection ID frame connection id.", |
| 10576 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10577 | 0xF0, 0xD2, 0xB4, 0x96, 0x78, 0x5A, 0x3C, 0x1E, |
dschinazi | b953d02 | 2019-08-01 18:05:58 -0700 | [diff] [blame] | 10578 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10579 | 0xF0, 0xD2, 0xB4, 0x96, 0x78, 0x5A, 0x3C, 0x1E, |
| 10580 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10581 | 0xF0, 0xD2, 0xB4, 0x96, 0x78, 0x5A, 0x3C, 0x1E, |
| 10582 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10583 | 0xF0, 0xD2, 0xB4, 0x96, 0x78, 0x5A, 0x3C, 0x1E}}, |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 10584 | {"Can not read new connection ID frame reset token.", |
| 10585 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 10586 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 10587 | }; |
| 10588 | // clang-format on |
| 10589 | |
| 10590 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10591 | AssemblePacketFromFragments(packet99)); |
| 10592 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10593 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_NEW_CONNECTION_ID_DATA)); |
dschinazi | 161bb49 | 2020-02-05 09:59:38 -0800 | [diff] [blame] | 10594 | EXPECT_EQ("Invalid new connection ID length for version.", |
| 10595 | framer_.detailed_error()); |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 10596 | } |
| 10597 | |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 10598 | // Verifies that parsing a NEW_CONNECTION_ID frame with an invalid |
| 10599 | // retire-prior-to fails. |
| 10600 | TEST_P(QuicFramerTest, InvalidRetirePriorToNewConnectionIdFrame) { |
| 10601 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10602 | // This frame is only for IETF QUIC only. |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 10603 | return; |
| 10604 | } |
| 10605 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 10606 | // clang-format off |
| 10607 | PacketFragments packet99 = { |
| 10608 | // type (short header, 4 byte packet number) |
| 10609 | {"", |
| 10610 | {0x43}}, |
| 10611 | // connection_id |
| 10612 | {"", |
| 10613 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10614 | // packet number |
| 10615 | {"", |
| 10616 | {0x12, 0x34, 0x56, 0x78}}, |
| 10617 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 10618 | {"", |
| 10619 | {0x18}}, |
| 10620 | // sequence number |
| 10621 | {"Unable to read new connection ID frame sequence number.", |
| 10622 | {kVarInt62OneByte + 0x11}}, |
| 10623 | {"Unable to read new connection ID frame retire_prior_to.", |
| 10624 | {kVarInt62OneByte + 0x1b}}, |
| 10625 | {"Unable to read new connection ID frame connection id length.", |
| 10626 | {0x08}}, // connection ID length |
| 10627 | {"Unable to read new connection ID frame connection id.", |
| 10628 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11}}, |
| 10629 | {"Can not read new connection ID frame reset token.", |
| 10630 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 10631 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 10632 | }; |
| 10633 | // clang-format on |
| 10634 | |
| 10635 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10636 | AssemblePacketFromFragments(packet99)); |
| 10637 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10638 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_NEW_CONNECTION_ID_DATA)); |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 10639 | EXPECT_EQ("Retire_prior_to > sequence_number.", framer_.detailed_error()); |
| 10640 | } |
| 10641 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10642 | TEST_P(QuicFramerTest, BuildNewConnectionIdFramePacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10643 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10644 | // This frame is only for IETF QUIC only. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10645 | return; |
| 10646 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 10647 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10648 | QuicPacketHeader header; |
| 10649 | header.destination_connection_id = FramerTestConnectionId(); |
| 10650 | header.reset_flag = false; |
| 10651 | header.version_flag = false; |
| 10652 | header.packet_number = kPacketNumber; |
| 10653 | |
| 10654 | QuicNewConnectionIdFrame frame; |
| 10655 | frame.sequence_number = 0x11; |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 10656 | frame.retire_prior_to = 0x0c; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10657 | // Use this value to force a 4-byte encoded variable length connection ID |
| 10658 | // in the frame. |
| 10659 | frame.connection_id = FramerTestConnectionIdPlusOne(); |
| 10660 | frame.stateless_reset_token = kTestStatelessResetToken; |
| 10661 | |
| 10662 | QuicFrames frames = {QuicFrame(&frame)}; |
| 10663 | |
| 10664 | // clang-format off |
| 10665 | unsigned char packet99[] = { |
| 10666 | // type (short header, 4 byte packet number) |
| 10667 | 0x43, |
| 10668 | // connection_id |
| 10669 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10670 | // packet number |
| 10671 | 0x12, 0x34, 0x56, 0x78, |
| 10672 | |
| 10673 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 10674 | 0x18, |
| 10675 | // sequence number |
| 10676 | kVarInt62OneByte + 0x11, |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 10677 | // retire_prior_to |
| 10678 | kVarInt62OneByte + 0x0c, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10679 | // new connection id length |
| 10680 | 0x08, |
| 10681 | // new connection id |
| 10682 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 10683 | // stateless reset token |
| 10684 | 0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 10685 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 10686 | }; |
| 10687 | // clang-format on |
| 10688 | |
| 10689 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10690 | ASSERT_TRUE(data != nullptr); |
| 10691 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 10692 | quiche::test::CompareCharArraysWithHexError( |
| 10693 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
| 10694 | QUICHE_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10695 | } |
| 10696 | |
| 10697 | TEST_P(QuicFramerTest, NewTokenFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10698 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10699 | // This frame is only for IETF QUIC only. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10700 | return; |
| 10701 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10702 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10703 | // clang-format off |
| 10704 | PacketFragments packet = { |
| 10705 | // type (short header, 4 byte packet number) |
| 10706 | {"", |
| 10707 | {0x43}}, |
| 10708 | // connection_id |
| 10709 | {"", |
| 10710 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10711 | // packet number |
| 10712 | {"", |
| 10713 | {0x12, 0x34, 0x56, 0x78}}, |
| 10714 | // frame type (IETF_NEW_TOKEN frame) |
| 10715 | {"", |
| 10716 | {0x07}}, |
| 10717 | // Length |
| 10718 | {"Unable to read new token length.", |
| 10719 | {kVarInt62OneByte + 0x08}}, |
| 10720 | {"Unable to read new token data.", |
| 10721 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}} |
| 10722 | }; |
| 10723 | // clang-format on |
| 10724 | uint8_t expected_token_value[] = {0x00, 0x01, 0x02, 0x03, |
| 10725 | 0x04, 0x05, 0x06, 0x07}; |
| 10726 | |
| 10727 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10728 | AssemblePacketFromFragments(packet)); |
| 10729 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10730 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10731 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10732 | ASSERT_TRUE(visitor_.header_.get()); |
| 10733 | EXPECT_TRUE(CheckDecryption( |
| 10734 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10735 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10736 | |
| 10737 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 10738 | |
| 10739 | EXPECT_EQ(sizeof(expected_token_value), visitor_.new_token_.token.length()); |
| 10740 | EXPECT_EQ(0, memcmp(expected_token_value, visitor_.new_token_.token.data(), |
| 10741 | sizeof(expected_token_value))); |
| 10742 | |
| 10743 | CheckFramingBoundaries(packet, QUIC_INVALID_NEW_TOKEN); |
| 10744 | } |
| 10745 | |
| 10746 | TEST_P(QuicFramerTest, BuildNewTokenFramePacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10747 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10748 | // This frame is only for IETF QUIC only. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10749 | return; |
| 10750 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 10751 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10752 | QuicPacketHeader header; |
| 10753 | header.destination_connection_id = FramerTestConnectionId(); |
| 10754 | header.reset_flag = false; |
| 10755 | header.version_flag = false; |
| 10756 | header.packet_number = kPacketNumber; |
| 10757 | |
| 10758 | uint8_t expected_token_value[] = {0x00, 0x01, 0x02, 0x03, |
| 10759 | 0x04, 0x05, 0x06, 0x07}; |
| 10760 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 10761 | QuicNewTokenFrame frame(0, std::string((const char*)(expected_token_value), |
| 10762 | sizeof(expected_token_value))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10763 | |
| 10764 | QuicFrames frames = {QuicFrame(&frame)}; |
| 10765 | |
| 10766 | // clang-format off |
| 10767 | unsigned char packet[] = { |
| 10768 | // type (short header, 4 byte packet number) |
| 10769 | 0x43, |
| 10770 | // connection_id |
| 10771 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10772 | // packet number |
| 10773 | 0x12, 0x34, 0x56, 0x78, |
| 10774 | |
| 10775 | // frame type (IETF_NEW_TOKEN frame) |
| 10776 | 0x07, |
| 10777 | // Length and token |
| 10778 | kVarInt62OneByte + 0x08, |
| 10779 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 10780 | }; |
| 10781 | // clang-format on |
| 10782 | |
| 10783 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10784 | ASSERT_TRUE(data != nullptr); |
| 10785 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 10786 | quiche::test::CompareCharArraysWithHexError( |
| 10787 | "constructed packet", data->data(), data->length(), AsChars(packet), |
| 10788 | QUICHE_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10789 | } |
| 10790 | |
| 10791 | TEST_P(QuicFramerTest, IetfStopSendingFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10792 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10793 | // Stop sending frame is IETF QUIC only. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10794 | return; |
| 10795 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10796 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10797 | |
| 10798 | // clang-format off |
| 10799 | PacketFragments packet99 = { |
| 10800 | // type (short header, 4 byte packet number) |
| 10801 | {"", |
| 10802 | {0x43}}, |
| 10803 | // connection_id |
| 10804 | {"", |
| 10805 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10806 | // packet number |
| 10807 | {"", |
| 10808 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10809 | // frame type (IETF_STOP_SENDING frame) |
| 10810 | {"", |
| 10811 | {0x05}}, |
| 10812 | // stream id |
| 10813 | {"Unable to read stop sending stream id.", |
| 10814 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 10815 | {"Unable to read stop sending application error code.", |
fkastenholz | 733552e | 2019-07-16 11:16:58 -0700 | [diff] [blame] | 10816 | {kVarInt62FourBytes + 0x00, 0x00, 0x76, 0x54}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10817 | }; |
| 10818 | // clang-format on |
| 10819 | |
| 10820 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10821 | AssemblePacketFromFragments(packet99)); |
| 10822 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10823 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10824 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10825 | ASSERT_TRUE(visitor_.header_.get()); |
| 10826 | EXPECT_TRUE(CheckDecryption( |
| 10827 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10828 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10829 | |
| 10830 | EXPECT_EQ(kStreamId, visitor_.stop_sending_frame_.stream_id); |
| 10831 | EXPECT_EQ(0x7654, visitor_.stop_sending_frame_.application_error_code); |
| 10832 | |
| 10833 | CheckFramingBoundaries(packet99, QUIC_INVALID_STOP_SENDING_FRAME_DATA); |
| 10834 | } |
| 10835 | |
| 10836 | TEST_P(QuicFramerTest, BuildIetfStopSendingPacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10837 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10838 | // Stop sending frame is IETF QUIC only. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10839 | return; |
| 10840 | } |
| 10841 | |
| 10842 | QuicPacketHeader header; |
| 10843 | header.destination_connection_id = FramerTestConnectionId(); |
| 10844 | header.reset_flag = false; |
| 10845 | header.version_flag = false; |
| 10846 | header.packet_number = kPacketNumber; |
| 10847 | |
| 10848 | QuicStopSendingFrame frame; |
| 10849 | frame.stream_id = kStreamId; |
| 10850 | frame.application_error_code = 0xffff; |
| 10851 | QuicFrames frames = {QuicFrame(&frame)}; |
| 10852 | |
| 10853 | // clang-format off |
| 10854 | unsigned char packet99[] = { |
| 10855 | // type (short header, 4 byte packet number) |
| 10856 | 0x43, |
| 10857 | // connection_id |
| 10858 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10859 | // packet number |
| 10860 | 0x12, 0x34, 0x56, 0x78, |
| 10861 | |
| 10862 | // frame type (IETF_STOP_SENDING frame) |
| 10863 | 0x05, |
| 10864 | // Stream ID |
| 10865 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 10866 | // Application error code |
fkastenholz | 733552e | 2019-07-16 11:16:58 -0700 | [diff] [blame] | 10867 | kVarInt62FourBytes + 0x00, 0x00, 0xff, 0xff |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10868 | }; |
| 10869 | // clang-format on |
| 10870 | |
| 10871 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10872 | ASSERT_TRUE(data != nullptr); |
| 10873 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 10874 | quiche::test::CompareCharArraysWithHexError( |
| 10875 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
| 10876 | QUICHE_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10877 | } |
| 10878 | |
| 10879 | TEST_P(QuicFramerTest, IetfPathChallengeFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10880 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10881 | // Path Challenge frame is IETF QUIC only. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10882 | return; |
| 10883 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10884 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10885 | |
| 10886 | // clang-format off |
| 10887 | PacketFragments packet99 = { |
| 10888 | // type (short header, 4 byte packet number) |
| 10889 | {"", |
| 10890 | {0x43}}, |
| 10891 | // connection_id |
| 10892 | {"", |
| 10893 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10894 | // packet number |
| 10895 | {"", |
| 10896 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10897 | // frame type (IETF_PATH_CHALLENGE) |
| 10898 | {"", |
| 10899 | {0x1a}}, |
| 10900 | // data |
| 10901 | {"Can not read path challenge data.", |
| 10902 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}}, |
| 10903 | }; |
| 10904 | // clang-format on |
| 10905 | |
| 10906 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10907 | AssemblePacketFromFragments(packet99)); |
| 10908 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10909 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10910 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10911 | ASSERT_TRUE(visitor_.header_.get()); |
| 10912 | EXPECT_TRUE(CheckDecryption( |
| 10913 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10914 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10915 | |
| 10916 | EXPECT_EQ(QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}), |
| 10917 | visitor_.path_challenge_frame_.data_buffer); |
| 10918 | |
| 10919 | CheckFramingBoundaries(packet99, QUIC_INVALID_PATH_CHALLENGE_DATA); |
| 10920 | } |
| 10921 | |
| 10922 | TEST_P(QuicFramerTest, BuildIetfPathChallengePacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10923 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10924 | // Path Challenge frame is IETF QUIC only. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10925 | return; |
| 10926 | } |
| 10927 | |
| 10928 | QuicPacketHeader header; |
| 10929 | header.destination_connection_id = FramerTestConnectionId(); |
| 10930 | header.reset_flag = false; |
| 10931 | header.version_flag = false; |
| 10932 | header.packet_number = kPacketNumber; |
| 10933 | |
| 10934 | QuicPathChallengeFrame frame; |
| 10935 | frame.data_buffer = QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}); |
| 10936 | QuicFrames frames = {QuicFrame(&frame)}; |
| 10937 | |
| 10938 | // clang-format off |
| 10939 | unsigned char packet99[] = { |
| 10940 | // type (short header, 4 byte packet number) |
| 10941 | 0x43, |
| 10942 | // connection_id |
| 10943 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10944 | // packet number |
| 10945 | 0x12, 0x34, 0x56, 0x78, |
| 10946 | |
| 10947 | // frame type (IETF_PATH_CHALLENGE) |
| 10948 | 0x1a, |
| 10949 | // Data |
| 10950 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 10951 | }; |
| 10952 | // clang-format on |
| 10953 | |
| 10954 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10955 | ASSERT_TRUE(data != nullptr); |
| 10956 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 10957 | quiche::test::CompareCharArraysWithHexError( |
| 10958 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
| 10959 | QUICHE_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10960 | } |
| 10961 | |
| 10962 | TEST_P(QuicFramerTest, IetfPathResponseFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10963 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10964 | // Path response frame is IETF QUIC only. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10965 | return; |
| 10966 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10967 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10968 | |
| 10969 | // clang-format off |
| 10970 | PacketFragments packet99 = { |
| 10971 | // type (short header, 4 byte packet number) |
| 10972 | {"", |
| 10973 | {0x43}}, |
| 10974 | // connection_id |
| 10975 | {"", |
| 10976 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10977 | // packet number |
| 10978 | {"", |
| 10979 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10980 | // frame type (IETF_PATH_RESPONSE) |
| 10981 | {"", |
| 10982 | {0x1b}}, |
| 10983 | // data |
| 10984 | {"Can not read path response data.", |
| 10985 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}}, |
| 10986 | }; |
| 10987 | // clang-format on |
| 10988 | |
| 10989 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10990 | AssemblePacketFromFragments(packet99)); |
| 10991 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10992 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10993 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10994 | ASSERT_TRUE(visitor_.header_.get()); |
| 10995 | EXPECT_TRUE(CheckDecryption( |
| 10996 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10997 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10998 | |
| 10999 | EXPECT_EQ(QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}), |
| 11000 | visitor_.path_response_frame_.data_buffer); |
| 11001 | |
| 11002 | CheckFramingBoundaries(packet99, QUIC_INVALID_PATH_RESPONSE_DATA); |
| 11003 | } |
| 11004 | |
| 11005 | TEST_P(QuicFramerTest, BuildIetfPathResponsePacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11006 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11007 | // Path response frame is IETF QUIC only |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11008 | return; |
| 11009 | } |
| 11010 | |
| 11011 | QuicPacketHeader header; |
| 11012 | header.destination_connection_id = FramerTestConnectionId(); |
| 11013 | header.reset_flag = false; |
| 11014 | header.version_flag = false; |
| 11015 | header.packet_number = kPacketNumber; |
| 11016 | |
| 11017 | QuicPathResponseFrame frame; |
| 11018 | frame.data_buffer = QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}); |
| 11019 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11020 | |
| 11021 | // clang-format off |
| 11022 | unsigned char packet99[] = { |
| 11023 | // type (short header, 4 byte packet number) |
| 11024 | 0x43, |
| 11025 | // connection_id |
| 11026 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11027 | // packet number |
| 11028 | 0x12, 0x34, 0x56, 0x78, |
| 11029 | |
| 11030 | // frame type (IETF_PATH_RESPONSE) |
| 11031 | 0x1b, |
| 11032 | // Data |
| 11033 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 11034 | }; |
| 11035 | // clang-format on |
| 11036 | |
| 11037 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11038 | ASSERT_TRUE(data != nullptr); |
| 11039 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 11040 | quiche::test::CompareCharArraysWithHexError( |
| 11041 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
| 11042 | QUICHE_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11043 | } |
| 11044 | |
| 11045 | TEST_P(QuicFramerTest, GetRetransmittableControlFrameSize) { |
| 11046 | QuicRstStreamFrame rst_stream(1, 3, QUIC_STREAM_CANCELLED, 1024); |
| 11047 | EXPECT_EQ(QuicFramer::GetRstStreamFrameSize(framer_.transport_version(), |
| 11048 | rst_stream), |
| 11049 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11050 | framer_.transport_version(), QuicFrame(&rst_stream))); |
| 11051 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 11052 | std::string error_detail(2048, 'e'); |
wub | a0cbbdc | 2019-09-09 06:40:59 -0700 | [diff] [blame] | 11053 | QuicConnectionCloseFrame connection_close( |
| 11054 | framer_.transport_version(), QUIC_NETWORK_IDLE_TIMEOUT, error_detail, |
| 11055 | /*transport_close_frame_type=*/0); |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 11056 | |
fkastenholz | a037b8b | 2019-05-07 06:00:05 -0700 | [diff] [blame] | 11057 | EXPECT_EQ(QuicFramer::GetConnectionCloseFrameSize(framer_.transport_version(), |
| 11058 | connection_close), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11059 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11060 | framer_.transport_version(), QuicFrame(&connection_close))); |
| 11061 | |
| 11062 | QuicGoAwayFrame goaway(2, QUIC_PEER_GOING_AWAY, 3, error_detail); |
| 11063 | EXPECT_EQ(QuicFramer::GetMinGoAwayFrameSize() + 256, |
| 11064 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11065 | framer_.transport_version(), QuicFrame(&goaway))); |
| 11066 | |
| 11067 | QuicWindowUpdateFrame window_update(3, 3, 1024); |
| 11068 | EXPECT_EQ(QuicFramer::GetWindowUpdateFrameSize(framer_.transport_version(), |
| 11069 | window_update), |
| 11070 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11071 | framer_.transport_version(), QuicFrame(&window_update))); |
| 11072 | |
| 11073 | QuicBlockedFrame blocked(4, 3, 1024); |
| 11074 | EXPECT_EQ( |
| 11075 | QuicFramer::GetBlockedFrameSize(framer_.transport_version(), blocked), |
| 11076 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11077 | framer_.transport_version(), QuicFrame(&blocked))); |
| 11078 | |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11079 | // Following frames are IETF QUIC frames only. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11080 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11081 | return; |
| 11082 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11083 | |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 11084 | QuicNewConnectionIdFrame new_connection_id(5, TestConnectionId(), 1, 101111, |
| 11085 | 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11086 | EXPECT_EQ(QuicFramer::GetNewConnectionIdFrameSize(new_connection_id), |
| 11087 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11088 | framer_.transport_version(), QuicFrame(&new_connection_id))); |
| 11089 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11090 | QuicMaxStreamsFrame max_streams(6, 3, /*unidirectional=*/false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11091 | EXPECT_EQ(QuicFramer::GetMaxStreamsFrameSize(framer_.transport_version(), |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11092 | max_streams), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11093 | QuicFramer::GetRetransmittableControlFrameSize( |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11094 | framer_.transport_version(), QuicFrame(max_streams))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11095 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11096 | QuicStreamsBlockedFrame streams_blocked(7, 3, /*unidirectional=*/false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11097 | EXPECT_EQ(QuicFramer::GetStreamsBlockedFrameSize(framer_.transport_version(), |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11098 | streams_blocked), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11099 | QuicFramer::GetRetransmittableControlFrameSize( |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11100 | framer_.transport_version(), QuicFrame(streams_blocked))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11101 | |
| 11102 | QuicPathFrameBuffer buffer = { |
| 11103 | {0x80, 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe5, 0xf7}}; |
| 11104 | QuicPathResponseFrame path_response_frame(8, buffer); |
| 11105 | EXPECT_EQ(QuicFramer::GetPathResponseFrameSize(path_response_frame), |
| 11106 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11107 | framer_.transport_version(), QuicFrame(&path_response_frame))); |
| 11108 | |
| 11109 | QuicPathChallengeFrame path_challenge_frame(9, buffer); |
| 11110 | EXPECT_EQ(QuicFramer::GetPathChallengeFrameSize(path_challenge_frame), |
| 11111 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11112 | framer_.transport_version(), QuicFrame(&path_challenge_frame))); |
| 11113 | |
| 11114 | QuicStopSendingFrame stop_sending_frame(10, 3, 20); |
| 11115 | EXPECT_EQ(QuicFramer::GetStopSendingFrameSize(stop_sending_frame), |
| 11116 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11117 | framer_.transport_version(), QuicFrame(&stop_sending_frame))); |
| 11118 | } |
| 11119 | |
| 11120 | // A set of tests to ensure that bad frame-type encodings |
| 11121 | // are properly detected and handled. |
| 11122 | // First, four tests to see that unknown frame types generate |
| 11123 | // a QUIC_INVALID_FRAME_DATA error with detailed information |
| 11124 | // "Illegal frame type." This regardless of the encoding of the type |
| 11125 | // (1/2/4/8 bytes). |
| 11126 | // This only for version 99. |
| 11127 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown1Byte) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11128 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11129 | // Only IETF QUIC encodes frame types such that this test is relevant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11130 | return; |
| 11131 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11132 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11133 | // clang-format off |
| 11134 | PacketFragments packet = { |
| 11135 | // type (short header, 4 byte packet number) |
| 11136 | {"", |
| 11137 | {0x43}}, |
| 11138 | // connection_id |
| 11139 | {"", |
| 11140 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11141 | // packet number |
| 11142 | {"", |
| 11143 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11144 | // frame type (unknown value, single-byte encoding) |
| 11145 | {"", |
| 11146 | {0x38}} |
| 11147 | }; |
| 11148 | // clang-format on |
| 11149 | |
| 11150 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11151 | AssemblePacketFromFragments(packet)); |
| 11152 | |
| 11153 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11154 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 11155 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_FRAME_DATA)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11156 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11157 | } |
| 11158 | |
| 11159 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown2Bytes) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11160 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11161 | // Only IETF QUIC encodes frame types such that this test is relevant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11162 | return; |
| 11163 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11164 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11165 | |
| 11166 | // clang-format off |
| 11167 | PacketFragments packet = { |
| 11168 | // type (short header, 4 byte packet number) |
| 11169 | {"", |
| 11170 | {0x43}}, |
| 11171 | // connection_id |
| 11172 | {"", |
| 11173 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11174 | // packet number |
| 11175 | {"", |
| 11176 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11177 | // frame type (unknown value, two-byte encoding) |
| 11178 | {"", |
| 11179 | {kVarInt62TwoBytes + 0x01, 0x38}} |
| 11180 | }; |
| 11181 | // clang-format on |
| 11182 | |
| 11183 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11184 | AssemblePacketFromFragments(packet)); |
| 11185 | |
| 11186 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11187 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 11188 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_FRAME_DATA)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11189 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11190 | } |
| 11191 | |
| 11192 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown4Bytes) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11193 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11194 | // Only IETF QUIC encodes frame types such that this test is relevant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11195 | return; |
| 11196 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11197 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11198 | |
| 11199 | // clang-format off |
| 11200 | PacketFragments packet = { |
| 11201 | // type (short header, 4 byte packet number) |
| 11202 | {"", |
| 11203 | {0x43}}, |
| 11204 | // connection_id |
| 11205 | {"", |
| 11206 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11207 | // packet number |
| 11208 | {"", |
| 11209 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11210 | // frame type (unknown value, four-byte encoding) |
| 11211 | {"", |
| 11212 | {kVarInt62FourBytes + 0x01, 0x00, 0x00, 0x38}} |
| 11213 | }; |
| 11214 | // clang-format on |
| 11215 | |
| 11216 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11217 | AssemblePacketFromFragments(packet)); |
| 11218 | |
| 11219 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11220 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 11221 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_FRAME_DATA)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11222 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11223 | } |
| 11224 | |
| 11225 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown8Bytes) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11226 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11227 | // Only IETF QUIC encodes frame types such that this test is relevant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11228 | return; |
| 11229 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11230 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11231 | // clang-format off |
| 11232 | PacketFragments packet = { |
| 11233 | // type (short header, 4 byte packet number) |
| 11234 | {"", |
| 11235 | {0x43}}, |
| 11236 | // connection_id |
| 11237 | {"", |
| 11238 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11239 | // packet number |
| 11240 | {"", |
| 11241 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11242 | // frame type (unknown value, eight-byte encoding) |
| 11243 | {"", |
| 11244 | {kVarInt62EightBytes + 0x01, 0x00, 0x00, 0x01, 0x02, 0x34, 0x56, 0x38}} |
| 11245 | }; |
| 11246 | // clang-format on |
| 11247 | |
| 11248 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11249 | AssemblePacketFromFragments(packet)); |
| 11250 | |
| 11251 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11252 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 11253 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_FRAME_DATA)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11254 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11255 | } |
| 11256 | |
| 11257 | // Three tests to check that known frame types that are not minimally |
| 11258 | // encoded generate IETF_QUIC_PROTOCOL_VIOLATION errors with detailed |
| 11259 | // information "Frame type not minimally encoded." |
| 11260 | // Look at the frame-type encoded in 2, 4, and 8 bytes. |
| 11261 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown2Bytes) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11262 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11263 | // Only IETF QUIC encodes frame types such that this test is relevant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11264 | return; |
| 11265 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11266 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11267 | |
| 11268 | // clang-format off |
| 11269 | PacketFragments packet = { |
| 11270 | // type (short header, 4 byte packet number) |
| 11271 | {"", |
| 11272 | {0x43}}, |
| 11273 | // connection_id |
| 11274 | {"", |
| 11275 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11276 | // packet number |
| 11277 | {"", |
| 11278 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11279 | // frame type (Blocked, two-byte encoding) |
| 11280 | {"", |
| 11281 | {kVarInt62TwoBytes + 0x00, 0x08}} |
| 11282 | }; |
| 11283 | // clang-format on |
| 11284 | |
| 11285 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11286 | AssemblePacketFromFragments(packet)); |
| 11287 | |
| 11288 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11289 | |
bnc | f54082a | 2019-11-27 10:19:47 -0800 | [diff] [blame] | 11290 | EXPECT_THAT(framer_.error(), IsError(IETF_QUIC_PROTOCOL_VIOLATION)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11291 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 11292 | } |
| 11293 | |
| 11294 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown4Bytes) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11295 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11296 | // Only IETF QUIC encodes frame types such that this test is relevant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11297 | return; |
| 11298 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11299 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11300 | |
| 11301 | // clang-format off |
| 11302 | PacketFragments packet = { |
| 11303 | // type (short header, 4 byte packet number) |
| 11304 | {"", |
| 11305 | {0x43}}, |
| 11306 | // connection_id |
| 11307 | {"", |
| 11308 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11309 | // packet number |
| 11310 | {"", |
| 11311 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11312 | // frame type (Blocked, four-byte encoding) |
| 11313 | {"", |
| 11314 | {kVarInt62FourBytes + 0x00, 0x00, 0x00, 0x08}} |
| 11315 | }; |
| 11316 | // clang-format on |
| 11317 | |
| 11318 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11319 | AssemblePacketFromFragments(packet)); |
| 11320 | |
| 11321 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11322 | |
bnc | f54082a | 2019-11-27 10:19:47 -0800 | [diff] [blame] | 11323 | EXPECT_THAT(framer_.error(), IsError(IETF_QUIC_PROTOCOL_VIOLATION)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11324 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 11325 | } |
| 11326 | |
| 11327 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown8Bytes) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11328 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11329 | // Only IETF QUIC encodes frame types such that this test is relevant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11330 | return; |
| 11331 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11332 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11333 | // clang-format off |
| 11334 | PacketFragments packet = { |
| 11335 | // type (short header, 4 byte packet number) |
| 11336 | {"", |
| 11337 | {0x43}}, |
| 11338 | // connection_id |
| 11339 | {"", |
| 11340 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11341 | // packet number |
| 11342 | {"", |
| 11343 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11344 | // frame type (Blocked, eight-byte encoding) |
| 11345 | {"", |
| 11346 | {kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08}} |
| 11347 | }; |
| 11348 | // clang-format on |
| 11349 | |
| 11350 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11351 | AssemblePacketFromFragments(packet)); |
| 11352 | |
| 11353 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11354 | |
bnc | f54082a | 2019-11-27 10:19:47 -0800 | [diff] [blame] | 11355 | EXPECT_THAT(framer_.error(), IsError(IETF_QUIC_PROTOCOL_VIOLATION)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11356 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 11357 | } |
| 11358 | |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11359 | // Tests to check that all known IETF frame types that are not minimally |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11360 | // encoded generate IETF_QUIC_PROTOCOL_VIOLATION errors with detailed |
| 11361 | // information "Frame type not minimally encoded." |
| 11362 | // Just look at 2-byte encoding. |
| 11363 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown2BytesAllTypes) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11364 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11365 | // Only IETF QUIC encodes frame types such that this test is relevant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11366 | return; |
| 11367 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11368 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11369 | |
| 11370 | // clang-format off |
| 11371 | PacketFragments packets[] = { |
| 11372 | { |
| 11373 | // type (short header, 4 byte packet number) |
| 11374 | {"", |
| 11375 | {0x43}}, |
| 11376 | // connection_id |
| 11377 | {"", |
| 11378 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11379 | // packet number |
| 11380 | {"", |
| 11381 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11382 | // frame type (two-byte encoding) |
| 11383 | {"", |
| 11384 | {kVarInt62TwoBytes + 0x00, 0x00}} |
| 11385 | }, |
| 11386 | { |
| 11387 | // type (short header, 4 byte packet number) |
| 11388 | {"", |
| 11389 | {0x43}}, |
| 11390 | // connection_id |
| 11391 | {"", |
| 11392 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11393 | // packet number |
| 11394 | {"", |
| 11395 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11396 | // frame type (two-byte encoding) |
| 11397 | {"", |
| 11398 | {kVarInt62TwoBytes + 0x00, 0x01}} |
| 11399 | }, |
| 11400 | { |
| 11401 | // type (short header, 4 byte packet number) |
| 11402 | {"", |
| 11403 | {0x43}}, |
| 11404 | // connection_id |
| 11405 | {"", |
| 11406 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11407 | // packet number |
| 11408 | {"", |
| 11409 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11410 | // frame type (two-byte encoding) |
| 11411 | {"", |
| 11412 | {kVarInt62TwoBytes + 0x00, 0x02}} |
| 11413 | }, |
| 11414 | { |
| 11415 | // type (short header, 4 byte packet number) |
| 11416 | {"", |
| 11417 | {0x43}}, |
| 11418 | // connection_id |
| 11419 | {"", |
| 11420 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11421 | // packet number |
| 11422 | {"", |
| 11423 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11424 | // frame type (two-byte encoding) |
| 11425 | {"", |
| 11426 | {kVarInt62TwoBytes + 0x00, 0x03}} |
| 11427 | }, |
| 11428 | { |
| 11429 | // type (short header, 4 byte packet number) |
| 11430 | {"", |
| 11431 | {0x43}}, |
| 11432 | // connection_id |
| 11433 | {"", |
| 11434 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11435 | // packet number |
| 11436 | {"", |
| 11437 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11438 | // frame type (two-byte encoding) |
| 11439 | {"", |
| 11440 | {kVarInt62TwoBytes + 0x00, 0x04}} |
| 11441 | }, |
| 11442 | { |
| 11443 | // type (short header, 4 byte packet number) |
| 11444 | {"", |
| 11445 | {0x43}}, |
| 11446 | // connection_id |
| 11447 | {"", |
| 11448 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11449 | // packet number |
| 11450 | {"", |
| 11451 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11452 | // frame type (two-byte encoding) |
| 11453 | {"", |
| 11454 | {kVarInt62TwoBytes + 0x00, 0x05}} |
| 11455 | }, |
| 11456 | { |
| 11457 | // type (short header, 4 byte packet number) |
| 11458 | {"", |
| 11459 | {0x43}}, |
| 11460 | // connection_id |
| 11461 | {"", |
| 11462 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11463 | // packet number |
| 11464 | {"", |
| 11465 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11466 | // frame type (two-byte encoding) |
| 11467 | {"", |
| 11468 | {kVarInt62TwoBytes + 0x00, 0x06}} |
| 11469 | }, |
| 11470 | { |
| 11471 | // type (short header, 4 byte packet number) |
| 11472 | {"", |
| 11473 | {0x43}}, |
| 11474 | // connection_id |
| 11475 | {"", |
| 11476 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11477 | // packet number |
| 11478 | {"", |
| 11479 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11480 | // frame type (two-byte encoding) |
| 11481 | {"", |
| 11482 | {kVarInt62TwoBytes + 0x00, 0x07}} |
| 11483 | }, |
| 11484 | { |
| 11485 | // type (short header, 4 byte packet number) |
| 11486 | {"", |
| 11487 | {0x43}}, |
| 11488 | // connection_id |
| 11489 | {"", |
| 11490 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11491 | // packet number |
| 11492 | {"", |
| 11493 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11494 | // frame type (two-byte encoding) |
| 11495 | {"", |
| 11496 | {kVarInt62TwoBytes + 0x00, 0x08}} |
| 11497 | }, |
| 11498 | { |
| 11499 | // type (short header, 4 byte packet number) |
| 11500 | {"", |
| 11501 | {0x43}}, |
| 11502 | // connection_id |
| 11503 | {"", |
| 11504 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11505 | // packet number |
| 11506 | {"", |
| 11507 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11508 | // frame type (two-byte encoding) |
| 11509 | {"", |
| 11510 | {kVarInt62TwoBytes + 0x00, 0x09}} |
| 11511 | }, |
| 11512 | { |
| 11513 | // type (short header, 4 byte packet number) |
| 11514 | {"", |
| 11515 | {0x43}}, |
| 11516 | // connection_id |
| 11517 | {"", |
| 11518 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11519 | // packet number |
| 11520 | {"", |
| 11521 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11522 | // frame type (two-byte encoding) |
| 11523 | {"", |
| 11524 | {kVarInt62TwoBytes + 0x00, 0x0a}} |
| 11525 | }, |
| 11526 | { |
| 11527 | // type (short header, 4 byte packet number) |
| 11528 | {"", |
| 11529 | {0x43}}, |
| 11530 | // connection_id |
| 11531 | {"", |
| 11532 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11533 | // packet number |
| 11534 | {"", |
| 11535 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11536 | // frame type (two-byte encoding) |
| 11537 | {"", |
| 11538 | {kVarInt62TwoBytes + 0x00, 0x0b}} |
| 11539 | }, |
| 11540 | { |
| 11541 | // type (short header, 4 byte packet number) |
| 11542 | {"", |
| 11543 | {0x43}}, |
| 11544 | // connection_id |
| 11545 | {"", |
| 11546 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11547 | // packet number |
| 11548 | {"", |
| 11549 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11550 | // frame type (two-byte encoding) |
| 11551 | {"", |
| 11552 | {kVarInt62TwoBytes + 0x00, 0x0c}} |
| 11553 | }, |
| 11554 | { |
| 11555 | // type (short header, 4 byte packet number) |
| 11556 | {"", |
| 11557 | {0x43}}, |
| 11558 | // connection_id |
| 11559 | {"", |
| 11560 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11561 | // packet number |
| 11562 | {"", |
| 11563 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11564 | // frame type (two-byte encoding) |
| 11565 | {"", |
| 11566 | {kVarInt62TwoBytes + 0x00, 0x0d}} |
| 11567 | }, |
| 11568 | { |
| 11569 | // type (short header, 4 byte packet number) |
| 11570 | {"", |
| 11571 | {0x43}}, |
| 11572 | // connection_id |
| 11573 | {"", |
| 11574 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11575 | // packet number |
| 11576 | {"", |
| 11577 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11578 | // frame type (two-byte encoding) |
| 11579 | {"", |
| 11580 | {kVarInt62TwoBytes + 0x00, 0x0e}} |
| 11581 | }, |
| 11582 | { |
| 11583 | // type (short header, 4 byte packet number) |
| 11584 | {"", |
| 11585 | {0x43}}, |
| 11586 | // connection_id |
| 11587 | {"", |
| 11588 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11589 | // packet number |
| 11590 | {"", |
| 11591 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11592 | // frame type (two-byte encoding) |
| 11593 | {"", |
| 11594 | {kVarInt62TwoBytes + 0x00, 0x0f}} |
| 11595 | }, |
| 11596 | { |
| 11597 | // type (short header, 4 byte packet number) |
| 11598 | {"", |
| 11599 | {0x43}}, |
| 11600 | // connection_id |
| 11601 | {"", |
| 11602 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11603 | // packet number |
| 11604 | {"", |
| 11605 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11606 | // frame type (two-byte encoding) |
| 11607 | {"", |
| 11608 | {kVarInt62TwoBytes + 0x00, 0x10}} |
| 11609 | }, |
| 11610 | { |
| 11611 | // type (short header, 4 byte packet number) |
| 11612 | {"", |
| 11613 | {0x43}}, |
| 11614 | // connection_id |
| 11615 | {"", |
| 11616 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11617 | // packet number |
| 11618 | {"", |
| 11619 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11620 | // frame type (two-byte encoding) |
| 11621 | {"", |
| 11622 | {kVarInt62TwoBytes + 0x00, 0x11}} |
| 11623 | }, |
| 11624 | { |
| 11625 | // type (short header, 4 byte packet number) |
| 11626 | {"", |
| 11627 | {0x43}}, |
| 11628 | // connection_id |
| 11629 | {"", |
| 11630 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11631 | // packet number |
| 11632 | {"", |
| 11633 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11634 | // frame type (two-byte encoding) |
| 11635 | {"", |
| 11636 | {kVarInt62TwoBytes + 0x00, 0x12}} |
| 11637 | }, |
| 11638 | { |
| 11639 | // type (short header, 4 byte packet number) |
| 11640 | {"", |
| 11641 | {0x43}}, |
| 11642 | // connection_id |
| 11643 | {"", |
| 11644 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11645 | // packet number |
| 11646 | {"", |
| 11647 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11648 | // frame type (two-byte encoding) |
| 11649 | {"", |
| 11650 | {kVarInt62TwoBytes + 0x00, 0x13}} |
| 11651 | }, |
| 11652 | { |
| 11653 | // type (short header, 4 byte packet number) |
| 11654 | {"", |
| 11655 | {0x43}}, |
| 11656 | // connection_id |
| 11657 | {"", |
| 11658 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11659 | // packet number |
| 11660 | {"", |
| 11661 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11662 | // frame type (two-byte encoding) |
| 11663 | {"", |
| 11664 | {kVarInt62TwoBytes + 0x00, 0x14}} |
| 11665 | }, |
| 11666 | { |
| 11667 | // type (short header, 4 byte packet number) |
| 11668 | {"", |
| 11669 | {0x43}}, |
| 11670 | // connection_id |
| 11671 | {"", |
| 11672 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11673 | // packet number |
| 11674 | {"", |
| 11675 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11676 | // frame type (two-byte encoding) |
| 11677 | {"", |
| 11678 | {kVarInt62TwoBytes + 0x00, 0x15}} |
| 11679 | }, |
| 11680 | { |
| 11681 | // type (short header, 4 byte packet number) |
| 11682 | {"", |
| 11683 | {0x43}}, |
| 11684 | // connection_id |
| 11685 | {"", |
| 11686 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11687 | // packet number |
| 11688 | {"", |
| 11689 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11690 | // frame type (two-byte encoding) |
| 11691 | {"", |
| 11692 | {kVarInt62TwoBytes + 0x00, 0x16}} |
| 11693 | }, |
| 11694 | { |
| 11695 | // type (short header, 4 byte packet number) |
| 11696 | {"", |
| 11697 | {0x43}}, |
| 11698 | // connection_id |
| 11699 | {"", |
| 11700 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11701 | // packet number |
| 11702 | {"", |
| 11703 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11704 | // frame type (two-byte encoding) |
| 11705 | {"", |
| 11706 | {kVarInt62TwoBytes + 0x00, 0x17}} |
| 11707 | }, |
| 11708 | { |
| 11709 | // type (short header, 4 byte packet number) |
| 11710 | {"", |
| 11711 | {0x43}}, |
| 11712 | // connection_id |
| 11713 | {"", |
| 11714 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11715 | // packet number |
| 11716 | {"", |
| 11717 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11718 | // frame type (two-byte encoding) |
| 11719 | {"", |
| 11720 | {kVarInt62TwoBytes + 0x00, 0x18}} |
| 11721 | }, |
| 11722 | { |
| 11723 | // type (short header, 4 byte packet number) |
| 11724 | {"", |
| 11725 | {0x43}}, |
| 11726 | // connection_id |
| 11727 | {"", |
| 11728 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11729 | // packet number |
| 11730 | {"", |
| 11731 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11732 | // frame type (two-byte encoding) |
| 11733 | {"", |
| 11734 | {kVarInt62TwoBytes + 0x00, 0x20}} |
| 11735 | }, |
| 11736 | { |
| 11737 | // type (short header, 4 byte packet number) |
| 11738 | {"", |
| 11739 | {0x43}}, |
| 11740 | // connection_id |
| 11741 | {"", |
| 11742 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11743 | // packet number |
| 11744 | {"", |
| 11745 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11746 | // frame type (two-byte encoding) |
| 11747 | {"", |
| 11748 | {kVarInt62TwoBytes + 0x00, 0x21}} |
| 11749 | }, |
| 11750 | }; |
| 11751 | // clang-format on |
| 11752 | |
| 11753 | for (PacketFragments& packet : packets) { |
| 11754 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11755 | AssemblePacketFromFragments(packet)); |
| 11756 | |
| 11757 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11758 | |
bnc | f54082a | 2019-11-27 10:19:47 -0800 | [diff] [blame] | 11759 | EXPECT_THAT(framer_.error(), IsError(IETF_QUIC_PROTOCOL_VIOLATION)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11760 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 11761 | } |
| 11762 | } |
| 11763 | |
| 11764 | TEST_P(QuicFramerTest, RetireConnectionIdFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11765 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11766 | // This frame is only for version 99. |
| 11767 | return; |
| 11768 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11769 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11770 | // clang-format off |
| 11771 | PacketFragments packet99 = { |
| 11772 | // type (short header, 4 byte packet number) |
| 11773 | {"", |
| 11774 | {0x43}}, |
| 11775 | // connection_id |
| 11776 | {"", |
| 11777 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11778 | // packet number |
| 11779 | {"", |
| 11780 | {0x12, 0x34, 0x56, 0x78}}, |
| 11781 | // frame type (IETF_RETIRE_CONNECTION_ID frame) |
| 11782 | {"", |
| 11783 | {0x19}}, |
| 11784 | // Sequence number |
| 11785 | {"Unable to read retire connection ID frame sequence number.", |
| 11786 | {kVarInt62TwoBytes + 0x11, 0x22}} |
| 11787 | }; |
| 11788 | // clang-format on |
| 11789 | |
| 11790 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11791 | AssemblePacketFromFragments(packet99)); |
| 11792 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11793 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 11794 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11795 | ASSERT_TRUE(visitor_.header_.get()); |
| 11796 | EXPECT_TRUE(CheckDecryption( |
| 11797 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11798 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11799 | |
| 11800 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 11801 | |
| 11802 | EXPECT_EQ(0x1122u, visitor_.retire_connection_id_.sequence_number); |
| 11803 | |
| 11804 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 11805 | |
| 11806 | CheckFramingBoundaries(packet99, QUIC_INVALID_RETIRE_CONNECTION_ID_DATA); |
| 11807 | } |
| 11808 | |
| 11809 | TEST_P(QuicFramerTest, BuildRetireConnectionIdFramePacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11810 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11811 | // This frame is only for version 99. |
| 11812 | return; |
| 11813 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 11814 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11815 | QuicPacketHeader header; |
| 11816 | header.destination_connection_id = FramerTestConnectionId(); |
| 11817 | header.reset_flag = false; |
| 11818 | header.version_flag = false; |
| 11819 | header.packet_number = kPacketNumber; |
| 11820 | |
| 11821 | QuicRetireConnectionIdFrame frame; |
| 11822 | frame.sequence_number = 0x1122; |
| 11823 | |
| 11824 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11825 | |
| 11826 | // clang-format off |
| 11827 | unsigned char packet99[] = { |
| 11828 | // type (short header, 4 byte packet number) |
| 11829 | 0x43, |
| 11830 | // connection_id |
| 11831 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11832 | // packet number |
| 11833 | 0x12, 0x34, 0x56, 0x78, |
| 11834 | |
| 11835 | // frame type (IETF_RETIRE_CONNECTION_ID frame) |
| 11836 | 0x19, |
| 11837 | // sequence number |
| 11838 | kVarInt62TwoBytes + 0x11, 0x22 |
| 11839 | }; |
| 11840 | // clang-format on |
| 11841 | |
| 11842 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11843 | ASSERT_TRUE(data != nullptr); |
| 11844 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 11845 | quiche::test::CompareCharArraysWithHexError( |
| 11846 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
| 11847 | QUICHE_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11848 | } |
| 11849 | |
| 11850 | TEST_P(QuicFramerTest, AckFrameWithInvalidLargestObserved) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11851 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11852 | // clang-format off |
| 11853 | unsigned char packet[] = { |
| 11854 | // public flags (8 byte connection_id) |
| 11855 | 0x2C, |
| 11856 | // connection_id |
| 11857 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11858 | // packet number |
| 11859 | 0x12, 0x34, 0x56, 0x78, |
| 11860 | |
| 11861 | // frame type (ack frame) |
| 11862 | 0x45, |
| 11863 | // largest observed |
| 11864 | 0x00, 0x00, |
| 11865 | // Zero delta time. |
| 11866 | 0x00, 0x00, |
| 11867 | // first ack block length. |
| 11868 | 0x00, 0x00, |
| 11869 | // num timestamps. |
| 11870 | 0x00 |
| 11871 | }; |
| 11872 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11873 | unsigned char packet46[] = { |
| 11874 | // type (short header, 4 byte packet number) |
| 11875 | 0x43, |
| 11876 | // connection_id |
| 11877 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11878 | // packet number |
| 11879 | 0x12, 0x34, 0x56, 0x78, |
| 11880 | |
| 11881 | // frame type (ack frame) |
| 11882 | 0x45, |
| 11883 | // largest observed |
| 11884 | 0x00, 0x00, |
| 11885 | // Zero delta time. |
| 11886 | 0x00, 0x00, |
| 11887 | // first ack block length. |
| 11888 | 0x00, 0x00, |
| 11889 | // num timestamps. |
| 11890 | 0x00 |
| 11891 | }; |
| 11892 | |
| 11893 | unsigned char packet99[] = { |
| 11894 | // type (short header, 4 byte packet number) |
| 11895 | 0x43, |
| 11896 | // connection_id |
| 11897 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11898 | // packet number |
| 11899 | 0x12, 0x34, 0x56, 0x78, |
| 11900 | |
| 11901 | // frame type (IETF_ACK frame) |
| 11902 | 0x02, |
| 11903 | // Largest acked |
| 11904 | kVarInt62OneByte + 0x00, |
| 11905 | // Zero delta time. |
| 11906 | kVarInt62OneByte + 0x00, |
| 11907 | // Ack block count 0 |
| 11908 | kVarInt62OneByte + 0x00, |
| 11909 | // First ack block length |
| 11910 | kVarInt62OneByte + 0x00, |
| 11911 | }; |
| 11912 | // clang-format on |
| 11913 | |
| 11914 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 11915 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11916 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11917 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 11918 | p_size = QUICHE_ARRAYSIZE(packet99); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 11919 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 11920 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11921 | } |
| 11922 | |
| 11923 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 11924 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 11925 | EXPECT_EQ(framer_.detailed_error(), "Largest acked is 0."); |
| 11926 | } |
| 11927 | |
| 11928 | TEST_P(QuicFramerTest, FirstAckBlockJustUnderFlow) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11929 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11930 | // clang-format off |
| 11931 | unsigned char packet[] = { |
| 11932 | // public flags (8 byte connection_id) |
| 11933 | 0x2C, |
| 11934 | // connection_id |
| 11935 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11936 | // packet number |
| 11937 | 0x12, 0x34, 0x56, 0x78, |
| 11938 | |
| 11939 | // frame type (ack frame) |
| 11940 | 0x45, |
| 11941 | // largest observed |
| 11942 | 0x00, 0x02, |
| 11943 | // Zero delta time. |
| 11944 | 0x00, 0x00, |
| 11945 | // first ack block length. |
| 11946 | 0x00, 0x03, |
| 11947 | // num timestamps. |
| 11948 | 0x00 |
| 11949 | }; |
| 11950 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11951 | unsigned char packet46[] = { |
| 11952 | // type (short header, 4 byte packet number) |
| 11953 | 0x43, |
| 11954 | // connection_id |
| 11955 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11956 | // packet number |
| 11957 | 0x12, 0x34, 0x56, 0x78, |
| 11958 | |
| 11959 | // frame type (ack frame) |
| 11960 | 0x45, |
| 11961 | // largest observed |
| 11962 | 0x00, 0x02, |
| 11963 | // Zero delta time. |
| 11964 | 0x00, 0x00, |
| 11965 | // first ack block length. |
| 11966 | 0x00, 0x03, |
| 11967 | // num timestamps. |
| 11968 | 0x00 |
| 11969 | }; |
| 11970 | |
| 11971 | unsigned char packet99[] = { |
| 11972 | // type (short header, 4 byte packet number) |
| 11973 | 0x43, |
| 11974 | // connection_id |
| 11975 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11976 | // packet number |
| 11977 | 0x12, 0x34, 0x56, 0x78, |
| 11978 | |
| 11979 | // frame type (IETF_ACK frame) |
| 11980 | 0x02, |
| 11981 | // Largest acked |
| 11982 | kVarInt62OneByte + 0x02, |
| 11983 | // Zero delta time. |
| 11984 | kVarInt62OneByte + 0x00, |
| 11985 | // Ack block count 0 |
| 11986 | kVarInt62OneByte + 0x00, |
| 11987 | // First ack block length |
| 11988 | kVarInt62OneByte + 0x02, |
| 11989 | }; |
| 11990 | // clang-format on |
| 11991 | |
| 11992 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 11993 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11994 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11995 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 11996 | p_size = QUICHE_ARRAYSIZE(packet99); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 11997 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11998 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 11999 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12000 | } |
| 12001 | |
| 12002 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 12003 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 12004 | EXPECT_EQ(framer_.detailed_error(), |
| 12005 | "Underflow with first ack block length 3 largest acked is 2."); |
| 12006 | } |
| 12007 | |
| 12008 | TEST_P(QuicFramerTest, ThirdAckBlockJustUnderflow) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12009 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12010 | // clang-format off |
| 12011 | unsigned char packet[] = { |
| 12012 | // public flags (8 byte connection_id) |
| 12013 | 0x2C, |
| 12014 | // connection_id |
| 12015 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12016 | // packet number |
| 12017 | 0x12, 0x34, 0x56, 0x78, |
| 12018 | |
| 12019 | // frame type (ack frame) |
| 12020 | 0x60, |
| 12021 | // largest observed |
| 12022 | 0x0A, |
| 12023 | // Zero delta time. |
| 12024 | 0x00, 0x00, |
| 12025 | // Num of ack blocks |
| 12026 | 0x02, |
| 12027 | // first ack block length. |
| 12028 | 0x02, |
| 12029 | // gap to next block |
| 12030 | 0x01, |
| 12031 | // ack block length |
| 12032 | 0x01, |
| 12033 | // gap to next block |
| 12034 | 0x01, |
| 12035 | // ack block length |
| 12036 | 0x06, |
| 12037 | // num timestamps. |
| 12038 | 0x00 |
| 12039 | }; |
| 12040 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12041 | unsigned char packet46[] = { |
| 12042 | // type (short header, 4 byte packet number) |
| 12043 | 0x43, |
| 12044 | // connection_id |
| 12045 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12046 | // packet number |
| 12047 | 0x12, 0x34, 0x56, 0x78, |
| 12048 | |
| 12049 | // frame type (ack frame) |
| 12050 | 0x60, |
| 12051 | // largest observed |
| 12052 | 0x0A, |
| 12053 | // Zero delta time. |
| 12054 | 0x00, 0x00, |
| 12055 | // Num of ack blocks |
| 12056 | 0x02, |
| 12057 | // first ack block length. |
| 12058 | 0x02, |
| 12059 | // gap to next block |
| 12060 | 0x01, |
| 12061 | // ack block length |
| 12062 | 0x01, |
| 12063 | // gap to next block |
| 12064 | 0x01, |
| 12065 | // ack block length |
| 12066 | 0x06, |
| 12067 | // num timestamps. |
| 12068 | 0x00 |
| 12069 | }; |
| 12070 | |
| 12071 | unsigned char packet99[] = { |
| 12072 | // type (short header, 4 byte packet number) |
| 12073 | 0x43, |
| 12074 | // connection_id |
| 12075 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12076 | // packet number |
| 12077 | 0x12, 0x34, 0x56, 0x78, |
| 12078 | |
| 12079 | // frame type (IETF_ACK frame) |
| 12080 | 0x02, |
| 12081 | // Largest acked |
| 12082 | kVarInt62OneByte + 0x0A, |
| 12083 | // Zero delta time. |
| 12084 | kVarInt62OneByte + 0x00, |
| 12085 | // Ack block count 2 |
| 12086 | kVarInt62OneByte + 0x02, |
| 12087 | // First ack block length |
| 12088 | kVarInt62OneByte + 0x01, |
| 12089 | // gap to next block length |
| 12090 | kVarInt62OneByte + 0x00, |
| 12091 | // ack block length |
| 12092 | kVarInt62OneByte + 0x00, |
| 12093 | // gap to next block length |
| 12094 | kVarInt62OneByte + 0x00, |
| 12095 | // ack block length |
| 12096 | kVarInt62OneByte + 0x05, |
| 12097 | }; |
| 12098 | // clang-format on |
| 12099 | |
| 12100 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12101 | size_t p_size = QUICHE_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 12102 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12103 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12104 | p_size = QUICHE_ARRAYSIZE(packet99); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 12105 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12106 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12107 | p_size = QUICHE_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12108 | } |
| 12109 | |
| 12110 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 12111 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 12112 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12113 | EXPECT_EQ(framer_.detailed_error(), |
| 12114 | "Underflow with ack block length 6 latest ack block end is 5."); |
| 12115 | } else { |
| 12116 | EXPECT_EQ(framer_.detailed_error(), |
| 12117 | "Underflow with ack block length 6, end of block is 6."); |
| 12118 | } |
| 12119 | } |
| 12120 | |
| 12121 | TEST_P(QuicFramerTest, CoalescedPacket) { |
| 12122 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 12123 | return; |
| 12124 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12125 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12126 | // clang-format off |
| 12127 | unsigned char packet[] = { |
| 12128 | // first coalesced packet |
| 12129 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12130 | // 4-byte packet number) |
| 12131 | 0xD3, |
| 12132 | // version |
| 12133 | QUIC_VERSION_BYTES, |
| 12134 | // destination connection ID length |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 12135 | 0x08, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12136 | // destination connection ID |
| 12137 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 12138 | // source connection ID length |
| 12139 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12140 | // long header packet length |
| 12141 | 0x1E, |
| 12142 | // packet number |
| 12143 | 0x12, 0x34, 0x56, 0x78, |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12144 | // frame type (stream frame with fin) |
| 12145 | 0xFE, |
| 12146 | // stream id |
| 12147 | 0x02, 0x03, 0x04, |
| 12148 | // offset |
| 12149 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 12150 | // data length |
| 12151 | 0x00, 0x0c, |
| 12152 | // data |
| 12153 | 'h', 'e', 'l', 'l', |
| 12154 | 'o', ' ', 'w', 'o', |
| 12155 | 'r', 'l', 'd', '!', |
| 12156 | // second coalesced packet |
| 12157 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12158 | // 4-byte packet number) |
| 12159 | 0xD3, |
| 12160 | // version |
| 12161 | QUIC_VERSION_BYTES, |
| 12162 | // destination connection ID length |
| 12163 | 0x08, |
| 12164 | // destination connection ID |
| 12165 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12166 | // source connection ID length |
| 12167 | 0x00, |
| 12168 | // long header packet length |
| 12169 | 0x1E, |
| 12170 | // packet number |
| 12171 | 0x12, 0x34, 0x56, 0x79, |
| 12172 | // frame type (stream frame with fin) |
| 12173 | 0xFE, |
| 12174 | // stream id |
| 12175 | 0x02, 0x03, 0x04, |
| 12176 | // offset |
| 12177 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 12178 | // data length |
| 12179 | 0x00, 0x0c, |
| 12180 | // data |
| 12181 | 'H', 'E', 'L', 'L', |
| 12182 | 'O', '_', 'W', 'O', |
| 12183 | 'R', 'L', 'D', '?', |
| 12184 | }; |
| 12185 | unsigned char packet99[] = { |
| 12186 | // first coalesced packet |
| 12187 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12188 | // 4-byte packet number) |
| 12189 | 0xD3, |
| 12190 | // version |
| 12191 | QUIC_VERSION_BYTES, |
| 12192 | // destination connection ID length |
| 12193 | 0x08, |
| 12194 | // destination connection ID |
| 12195 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12196 | // source connection ID length |
| 12197 | 0x00, |
| 12198 | // long header packet length |
| 12199 | 0x1E, |
| 12200 | // packet number |
| 12201 | 0x12, 0x34, 0x56, 0x78, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12202 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12203 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12204 | // stream id |
| 12205 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12206 | // offset |
| 12207 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12208 | 0x32, 0x10, 0x76, 0x54, |
| 12209 | // data length |
| 12210 | kVarInt62OneByte + 0x0c, |
| 12211 | // data |
| 12212 | 'h', 'e', 'l', 'l', |
| 12213 | 'o', ' ', 'w', 'o', |
| 12214 | 'r', 'l', 'd', '!', |
| 12215 | // second coalesced packet |
| 12216 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12217 | // 4-byte packet number) |
| 12218 | 0xD3, |
| 12219 | // version |
| 12220 | QUIC_VERSION_BYTES, |
| 12221 | // destination connection ID length |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 12222 | 0x08, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12223 | // destination connection ID |
| 12224 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 12225 | // source connection ID length |
| 12226 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12227 | // long header packet length |
| 12228 | 0x1E, |
| 12229 | // packet number |
| 12230 | 0x12, 0x34, 0x56, 0x79, |
| 12231 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12232 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12233 | // stream id |
| 12234 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12235 | // offset |
| 12236 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12237 | 0x32, 0x10, 0x76, 0x54, |
| 12238 | // data length |
| 12239 | kVarInt62OneByte + 0x0c, |
| 12240 | // data |
| 12241 | 'H', 'E', 'L', 'L', |
| 12242 | 'O', '_', 'W', 'O', |
| 12243 | 'R', 'L', 'D', '?', |
| 12244 | }; |
| 12245 | // clang-format on |
| 12246 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12247 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12248 | size_t p_length = QUICHE_ARRAYSIZE(packet); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12249 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 12250 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12251 | p_length = QUICHE_ARRAYSIZE(packet99); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12252 | } |
| 12253 | |
| 12254 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12255 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 12256 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 12257 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12258 | ASSERT_TRUE(visitor_.header_.get()); |
| 12259 | |
| 12260 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 12261 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12262 | |
| 12263 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12264 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 12265 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 12266 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 12267 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 12268 | |
| 12269 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 1u); |
| 12270 | EXPECT_TRUE(framer_.ProcessPacket(*visitor_.coalesced_packets_[0].get())); |
| 12271 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 12272 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12273 | ASSERT_TRUE(visitor_.header_.get()); |
| 12274 | |
| 12275 | ASSERT_EQ(2u, visitor_.stream_frames_.size()); |
| 12276 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12277 | |
| 12278 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12279 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[1]->stream_id); |
| 12280 | EXPECT_TRUE(visitor_.stream_frames_[1]->fin); |
| 12281 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[1]->offset); |
| 12282 | CheckStreamFrameData("HELLO_WORLD?", visitor_.stream_frames_[1].get()); |
| 12283 | } |
| 12284 | |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12285 | TEST_P(QuicFramerTest, UndecryptablePacketWithoutDecrypter) { |
| 12286 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 12287 | |
| 12288 | if (!framer_.version().KnowsWhichDecrypterToUse()) { |
| 12289 | // We create a bad client decrypter by using initial encryption with a |
| 12290 | // bogus connection ID; it should fail to decrypt everything. |
| 12291 | QuicConnectionId bogus_connection_id = TestConnectionId(0xbad); |
| 12292 | CrypterPair bogus_crypters; |
nharper | c8d9e40 | 2019-09-12 18:30:14 -0700 | [diff] [blame] | 12293 | CryptoUtils::CreateInitialObfuscators(Perspective::IS_CLIENT, |
| 12294 | framer_.version(), |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12295 | bogus_connection_id, &bogus_crypters); |
| 12296 | // This removes all other decrypters. |
| 12297 | framer_.SetDecrypter(ENCRYPTION_FORWARD_SECURE, |
| 12298 | std::move(bogus_crypters.decrypter)); |
| 12299 | } |
| 12300 | |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12301 | // clang-format off |
| 12302 | unsigned char packet[] = { |
| 12303 | // public flags (version included, 8-byte connection ID, |
| 12304 | // 4-byte packet number) |
| 12305 | 0x28, |
| 12306 | // connection_id |
| 12307 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12308 | // packet number |
| 12309 | 0x12, 0x34, 0x56, 0x00, |
| 12310 | // padding frames |
| 12311 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12312 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12313 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12314 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12315 | }; |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 12316 | unsigned char packet46[] = { |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12317 | // public flags (long header with packet type HANDSHAKE and |
| 12318 | // 4-byte packet number) |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 12319 | 0xE3, |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12320 | // version |
| 12321 | QUIC_VERSION_BYTES, |
| 12322 | // connection ID lengths |
| 12323 | 0x05, |
| 12324 | // source connection ID |
| 12325 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12326 | // long header packet length |
| 12327 | 0x05, |
| 12328 | // packet number |
| 12329 | 0x12, 0x34, 0x56, 0x00, |
| 12330 | // padding frames |
| 12331 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12332 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12333 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12334 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12335 | }; |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12336 | unsigned char packet49[] = { |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12337 | // public flags (long header with packet type HANDSHAKE and |
| 12338 | // 4-byte packet number) |
| 12339 | 0xE3, |
| 12340 | // version |
| 12341 | QUIC_VERSION_BYTES, |
| 12342 | // destination connection ID length |
| 12343 | 0x00, |
| 12344 | // source connection ID length |
| 12345 | 0x08, |
| 12346 | // source connection ID |
| 12347 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12348 | // long header packet length |
| 12349 | 0x24, |
| 12350 | // packet number |
| 12351 | 0x12, 0x34, 0x56, 0x00, |
| 12352 | // padding frames |
| 12353 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12354 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12355 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12356 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12357 | }; |
| 12358 | // clang-format on |
| 12359 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12360 | size_t p_length = QUICHE_ARRAYSIZE(packet); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12361 | if (framer_.transport_version() >= QUIC_VERSION_49) { |
| 12362 | p = packet49; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12363 | p_length = QUICHE_ARRAYSIZE(packet49); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 12364 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
| 12365 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12366 | p_length = QUICHE_ARRAYSIZE(packet46); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12367 | } |
| 12368 | // First attempt decryption without the handshake crypter. |
| 12369 | EXPECT_FALSE( |
| 12370 | framer_.ProcessPacket(QuicEncryptedPacket(AsChars(p), p_length, false))); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 12371 | EXPECT_THAT(framer_.error(), IsError(QUIC_DECRYPTION_FAILURE)); |
| 12372 | ASSERT_EQ(1u, visitor_.undecryptable_packets_.size()); |
| 12373 | ASSERT_EQ(1u, visitor_.undecryptable_decryption_levels_.size()); |
| 12374 | ASSERT_EQ(1u, visitor_.undecryptable_has_decryption_keys_.size()); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 12375 | quiche::test::CompareCharArraysWithHexError( |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 12376 | "undecryptable packet", visitor_.undecryptable_packets_[0]->data(), |
| 12377 | visitor_.undecryptable_packets_[0]->length(), AsChars(p), p_length); |
| 12378 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 12379 | EXPECT_EQ(ENCRYPTION_HANDSHAKE, |
| 12380 | visitor_.undecryptable_decryption_levels_[0]); |
| 12381 | } |
| 12382 | EXPECT_FALSE(visitor_.undecryptable_has_decryption_keys_[0]); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12383 | } |
| 12384 | |
| 12385 | TEST_P(QuicFramerTest, UndecryptablePacketWithDecrypter) { |
| 12386 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 12387 | |
| 12388 | // We create a bad client decrypter by using initial encryption with a |
| 12389 | // bogus connection ID; it should fail to decrypt everything. |
| 12390 | QuicConnectionId bogus_connection_id = TestConnectionId(0xbad); |
| 12391 | CrypterPair bad_handshake_crypters; |
nharper | c8d9e40 | 2019-09-12 18:30:14 -0700 | [diff] [blame] | 12392 | CryptoUtils::CreateInitialObfuscators(Perspective::IS_CLIENT, |
| 12393 | framer_.version(), bogus_connection_id, |
| 12394 | &bad_handshake_crypters); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12395 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 12396 | framer_.InstallDecrypter(ENCRYPTION_HANDSHAKE, |
| 12397 | std::move(bad_handshake_crypters.decrypter)); |
| 12398 | } else { |
| 12399 | framer_.SetDecrypter(ENCRYPTION_HANDSHAKE, |
| 12400 | std::move(bad_handshake_crypters.decrypter)); |
| 12401 | } |
| 12402 | |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12403 | // clang-format off |
| 12404 | unsigned char packet[] = { |
| 12405 | // public flags (version included, 8-byte connection ID, |
| 12406 | // 4-byte packet number) |
| 12407 | 0x28, |
| 12408 | // connection_id |
| 12409 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12410 | // packet number |
| 12411 | 0x12, 0x34, 0x56, 0x00, |
| 12412 | // padding frames |
| 12413 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12414 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12415 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12416 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12417 | }; |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 12418 | unsigned char packet46[] = { |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12419 | // public flags (long header with packet type HANDSHAKE and |
| 12420 | // 4-byte packet number) |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 12421 | 0xE3, |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12422 | // version |
| 12423 | QUIC_VERSION_BYTES, |
| 12424 | // connection ID lengths |
| 12425 | 0x05, |
| 12426 | // source connection ID |
| 12427 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12428 | // long header packet length |
| 12429 | 0x05, |
| 12430 | // packet number |
| 12431 | 0x12, 0x34, 0x56, 0x00, |
| 12432 | // padding frames |
| 12433 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12434 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12435 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12436 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12437 | }; |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12438 | unsigned char packet49[] = { |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12439 | // public flags (long header with packet type HANDSHAKE and |
| 12440 | // 4-byte packet number) |
| 12441 | 0xE3, |
| 12442 | // version |
| 12443 | QUIC_VERSION_BYTES, |
| 12444 | // destination connection ID length |
| 12445 | 0x00, |
| 12446 | // source connection ID length |
| 12447 | 0x08, |
| 12448 | // source connection ID |
| 12449 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12450 | // long header packet length |
| 12451 | 0x24, |
| 12452 | // packet number |
| 12453 | 0x12, 0x34, 0x56, 0x00, |
| 12454 | // padding frames |
| 12455 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12456 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12457 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12458 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12459 | }; |
| 12460 | // clang-format on |
| 12461 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12462 | size_t p_length = QUICHE_ARRAYSIZE(packet); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12463 | if (framer_.transport_version() >= QUIC_VERSION_49) { |
| 12464 | p = packet49; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12465 | p_length = QUICHE_ARRAYSIZE(packet49); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 12466 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
| 12467 | p = packet46; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12468 | p_length = QUICHE_ARRAYSIZE(packet46); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12469 | } |
| 12470 | |
| 12471 | EXPECT_FALSE( |
| 12472 | framer_.ProcessPacket(QuicEncryptedPacket(AsChars(p), p_length, false))); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 12473 | EXPECT_THAT(framer_.error(), IsError(QUIC_DECRYPTION_FAILURE)); |
| 12474 | ASSERT_EQ(1u, visitor_.undecryptable_packets_.size()); |
| 12475 | ASSERT_EQ(1u, visitor_.undecryptable_decryption_levels_.size()); |
| 12476 | ASSERT_EQ(1u, visitor_.undecryptable_has_decryption_keys_.size()); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 12477 | quiche::test::CompareCharArraysWithHexError( |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 12478 | "undecryptable packet", visitor_.undecryptable_packets_[0]->data(), |
| 12479 | visitor_.undecryptable_packets_[0]->length(), AsChars(p), p_length); |
| 12480 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 12481 | EXPECT_EQ(ENCRYPTION_HANDSHAKE, |
| 12482 | visitor_.undecryptable_decryption_levels_[0]); |
| 12483 | } |
| 12484 | EXPECT_EQ(framer_.version().KnowsWhichDecrypterToUse(), |
| 12485 | visitor_.undecryptable_has_decryption_keys_[0]); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12486 | } |
| 12487 | |
| 12488 | TEST_P(QuicFramerTest, UndecryptableCoalescedPacket) { |
| 12489 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 12490 | return; |
| 12491 | } |
| 12492 | ASSERT_TRUE(framer_.version().KnowsWhichDecrypterToUse()); |
| 12493 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
| 12494 | // We create a bad client decrypter by using initial encryption with a |
| 12495 | // bogus connection ID; it should fail to decrypt everything. |
| 12496 | QuicConnectionId bogus_connection_id = TestConnectionId(0xbad); |
| 12497 | CrypterPair bad_handshake_crypters; |
nharper | c8d9e40 | 2019-09-12 18:30:14 -0700 | [diff] [blame] | 12498 | CryptoUtils::CreateInitialObfuscators(Perspective::IS_CLIENT, |
| 12499 | framer_.version(), bogus_connection_id, |
| 12500 | &bad_handshake_crypters); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12501 | framer_.InstallDecrypter(ENCRYPTION_HANDSHAKE, |
| 12502 | std::move(bad_handshake_crypters.decrypter)); |
| 12503 | // clang-format off |
| 12504 | unsigned char packet[] = { |
| 12505 | // first coalesced packet |
| 12506 | // public flags (long header with packet type HANDSHAKE and |
| 12507 | // 4-byte packet number) |
| 12508 | 0xE3, |
| 12509 | // version |
| 12510 | QUIC_VERSION_BYTES, |
| 12511 | // destination connection ID length |
| 12512 | 0x08, |
| 12513 | // destination connection ID |
| 12514 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12515 | // source connection ID length |
| 12516 | 0x00, |
| 12517 | // long header packet length |
| 12518 | 0x1E, |
| 12519 | // packet number |
| 12520 | 0x12, 0x34, 0x56, 0x78, |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12521 | // frame type (stream frame with fin) |
| 12522 | 0xFE, |
| 12523 | // stream id |
| 12524 | 0x02, 0x03, 0x04, |
| 12525 | // offset |
| 12526 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 12527 | // data length |
| 12528 | 0x00, 0x0c, |
| 12529 | // data |
| 12530 | 'h', 'e', 'l', 'l', |
| 12531 | 'o', ' ', 'w', 'o', |
| 12532 | 'r', 'l', 'd', '!', |
| 12533 | // second coalesced packet |
| 12534 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12535 | // 4-byte packet number) |
| 12536 | 0xD3, |
| 12537 | // version |
| 12538 | QUIC_VERSION_BYTES, |
| 12539 | // destination connection ID length |
| 12540 | 0x08, |
| 12541 | // destination connection ID |
| 12542 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12543 | // source connection ID length |
| 12544 | 0x00, |
| 12545 | // long header packet length |
| 12546 | 0x1E, |
| 12547 | // packet number |
| 12548 | 0x12, 0x34, 0x56, 0x79, |
| 12549 | // frame type (stream frame with fin) |
| 12550 | 0xFE, |
| 12551 | // stream id |
| 12552 | 0x02, 0x03, 0x04, |
| 12553 | // offset |
| 12554 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 12555 | // data length |
| 12556 | 0x00, 0x0c, |
| 12557 | // data |
| 12558 | 'H', 'E', 'L', 'L', |
| 12559 | 'O', '_', 'W', 'O', |
| 12560 | 'R', 'L', 'D', '?', |
| 12561 | }; |
| 12562 | unsigned char packet99[] = { |
| 12563 | // first coalesced packet |
| 12564 | // public flags (long header with packet type HANDSHAKE and |
| 12565 | // 4-byte packet number) |
| 12566 | 0xE3, |
| 12567 | // version |
| 12568 | QUIC_VERSION_BYTES, |
| 12569 | // destination connection ID length |
| 12570 | 0x08, |
| 12571 | // destination connection ID |
| 12572 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12573 | // source connection ID length |
| 12574 | 0x00, |
| 12575 | // long header packet length |
| 12576 | 0x1E, |
| 12577 | // packet number |
| 12578 | 0x12, 0x34, 0x56, 0x78, |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12579 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12580 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12581 | // stream id |
| 12582 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12583 | // offset |
| 12584 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12585 | 0x32, 0x10, 0x76, 0x54, |
| 12586 | // data length |
| 12587 | kVarInt62OneByte + 0x0c, |
| 12588 | // data |
| 12589 | 'h', 'e', 'l', 'l', |
| 12590 | 'o', ' ', 'w', 'o', |
| 12591 | 'r', 'l', 'd', '!', |
| 12592 | // second coalesced packet |
| 12593 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12594 | // 4-byte packet number) |
| 12595 | 0xD3, |
| 12596 | // version |
| 12597 | QUIC_VERSION_BYTES, |
| 12598 | // destination connection ID length |
| 12599 | 0x08, |
| 12600 | // destination connection ID |
| 12601 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12602 | // source connection ID length |
| 12603 | 0x00, |
| 12604 | // long header packet length |
| 12605 | 0x1E, |
| 12606 | // packet number |
| 12607 | 0x12, 0x34, 0x56, 0x79, |
| 12608 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12609 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12610 | // stream id |
| 12611 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12612 | // offset |
| 12613 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12614 | 0x32, 0x10, 0x76, 0x54, |
| 12615 | // data length |
| 12616 | kVarInt62OneByte + 0x0c, |
| 12617 | // data |
| 12618 | 'H', 'E', 'L', 'L', |
| 12619 | 'O', '_', 'W', 'O', |
| 12620 | 'R', 'L', 'D', '?', |
| 12621 | }; |
| 12622 | // clang-format on |
| 12623 | const size_t length_of_first_coalesced_packet = 46; |
| 12624 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12625 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12626 | size_t p_length = QUICHE_ARRAYSIZE(packet); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12627 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 12628 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12629 | p_length = QUICHE_ARRAYSIZE(packet99); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12630 | } |
| 12631 | |
| 12632 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
| 12633 | |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12634 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 12635 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 12636 | EXPECT_THAT(framer_.error(), IsError(QUIC_DECRYPTION_FAILURE)); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12637 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 12638 | ASSERT_EQ(1u, visitor_.undecryptable_packets_.size()); |
| 12639 | ASSERT_EQ(1u, visitor_.undecryptable_decryption_levels_.size()); |
| 12640 | ASSERT_EQ(1u, visitor_.undecryptable_has_decryption_keys_.size()); |
| 12641 | // Make sure we only receive the first undecryptable packet and not the |
| 12642 | // full packet including the second coalesced packet. |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 12643 | quiche::test::CompareCharArraysWithHexError( |
| 12644 | "undecryptable packet", visitor_.undecryptable_packets_[0]->data(), |
| 12645 | visitor_.undecryptable_packets_[0]->length(), AsChars(p), |
| 12646 | length_of_first_coalesced_packet); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 12647 | EXPECT_EQ(ENCRYPTION_HANDSHAKE, visitor_.undecryptable_decryption_levels_[0]); |
| 12648 | EXPECT_TRUE(visitor_.undecryptable_has_decryption_keys_[0]); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12649 | |
| 12650 | // Make sure the second coalesced packet is parsed correctly. |
| 12651 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 1u); |
| 12652 | EXPECT_TRUE(framer_.ProcessPacket(*visitor_.coalesced_packets_[0].get())); |
| 12653 | |
| 12654 | ASSERT_TRUE(visitor_.header_.get()); |
| 12655 | |
| 12656 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 12657 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12658 | |
| 12659 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12660 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 12661 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 12662 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 12663 | CheckStreamFrameData("HELLO_WORLD?", visitor_.stream_frames_[0].get()); |
| 12664 | } |
| 12665 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12666 | TEST_P(QuicFramerTest, MismatchedCoalescedPacket) { |
| 12667 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 12668 | return; |
| 12669 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12670 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12671 | // clang-format off |
| 12672 | unsigned char packet[] = { |
| 12673 | // first coalesced packet |
| 12674 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12675 | // 4-byte packet number) |
| 12676 | 0xD3, |
| 12677 | // version |
| 12678 | QUIC_VERSION_BYTES, |
| 12679 | // destination connection ID length |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 12680 | 0x08, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12681 | // destination connection ID |
| 12682 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 12683 | // source connection ID length |
| 12684 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12685 | // long header packet length |
| 12686 | 0x1E, |
| 12687 | // packet number |
| 12688 | 0x12, 0x34, 0x56, 0x78, |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12689 | // frame type (stream frame with fin) |
| 12690 | 0xFE, |
| 12691 | // stream id |
| 12692 | 0x02, 0x03, 0x04, |
| 12693 | // offset |
| 12694 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 12695 | // data length |
| 12696 | 0x00, 0x0c, |
| 12697 | // data |
| 12698 | 'h', 'e', 'l', 'l', |
| 12699 | 'o', ' ', 'w', 'o', |
| 12700 | 'r', 'l', 'd', '!', |
| 12701 | // second coalesced packet |
| 12702 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12703 | // 4-byte packet number) |
| 12704 | 0xD3, |
| 12705 | // version |
| 12706 | QUIC_VERSION_BYTES, |
| 12707 | // destination connection ID length |
| 12708 | 0x08, |
| 12709 | // destination connection ID |
| 12710 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 12711 | // source connection ID length |
| 12712 | 0x00, |
| 12713 | // long header packet length |
| 12714 | 0x1E, |
| 12715 | // packet number |
| 12716 | 0x12, 0x34, 0x56, 0x79, |
| 12717 | // frame type (stream frame with fin) |
| 12718 | 0xFE, |
| 12719 | // stream id |
| 12720 | 0x02, 0x03, 0x04, |
| 12721 | // offset |
| 12722 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 12723 | // data length |
| 12724 | 0x00, 0x0c, |
| 12725 | // data |
| 12726 | 'H', 'E', 'L', 'L', |
| 12727 | 'O', '_', 'W', 'O', |
| 12728 | 'R', 'L', 'D', '?', |
| 12729 | }; |
| 12730 | unsigned char packet99[] = { |
| 12731 | // first coalesced packet |
| 12732 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12733 | // 4-byte packet number) |
| 12734 | 0xD3, |
| 12735 | // version |
| 12736 | QUIC_VERSION_BYTES, |
| 12737 | // destination connection ID length |
| 12738 | 0x08, |
| 12739 | // destination connection ID |
| 12740 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12741 | // source connection ID length |
| 12742 | 0x00, |
| 12743 | // long header packet length |
| 12744 | 0x1E, |
| 12745 | // packet number |
| 12746 | 0x12, 0x34, 0x56, 0x78, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12747 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12748 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12749 | // stream id |
| 12750 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12751 | // offset |
| 12752 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12753 | 0x32, 0x10, 0x76, 0x54, |
| 12754 | // data length |
| 12755 | kVarInt62OneByte + 0x0c, |
| 12756 | // data |
| 12757 | 'h', 'e', 'l', 'l', |
| 12758 | 'o', ' ', 'w', 'o', |
| 12759 | 'r', 'l', 'd', '!', |
| 12760 | // second coalesced packet |
| 12761 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12762 | // 4-byte packet number) |
| 12763 | 0xD3, |
| 12764 | // version |
| 12765 | QUIC_VERSION_BYTES, |
| 12766 | // destination connection ID length |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 12767 | 0x08, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12768 | // destination connection ID |
| 12769 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 12770 | // source connection ID length |
| 12771 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12772 | // long header packet length |
| 12773 | 0x1E, |
| 12774 | // packet number |
| 12775 | 0x12, 0x34, 0x56, 0x79, |
| 12776 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12777 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12778 | // stream id |
| 12779 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12780 | // offset |
| 12781 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12782 | 0x32, 0x10, 0x76, 0x54, |
| 12783 | // data length |
| 12784 | kVarInt62OneByte + 0x0c, |
| 12785 | // data |
| 12786 | 'H', 'E', 'L', 'L', |
| 12787 | 'O', '_', 'W', 'O', |
| 12788 | 'R', 'L', 'D', '?', |
| 12789 | }; |
| 12790 | // clang-format on |
| 12791 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12792 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12793 | size_t p_length = QUICHE_ARRAYSIZE(packet); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12794 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 12795 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12796 | p_length = QUICHE_ARRAYSIZE(packet99); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12797 | } |
| 12798 | |
| 12799 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
| 12800 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12801 | EXPECT_QUIC_PEER_BUG(EXPECT_TRUE(framer_.ProcessPacket(encrypted)), |
| 12802 | "Server: Received mismatched coalesced header.*"); |
| 12803 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 12804 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12805 | ASSERT_TRUE(visitor_.header_.get()); |
| 12806 | |
| 12807 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 12808 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12809 | |
| 12810 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12811 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 12812 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 12813 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 12814 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 12815 | |
| 12816 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 0u); |
| 12817 | } |
| 12818 | |
| 12819 | TEST_P(QuicFramerTest, InvalidCoalescedPacket) { |
| 12820 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 12821 | return; |
| 12822 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12823 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12824 | // clang-format off |
| 12825 | unsigned char packet[] = { |
| 12826 | // first coalesced packet |
| 12827 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12828 | // 4-byte packet number) |
| 12829 | 0xD3, |
| 12830 | // version |
| 12831 | QUIC_VERSION_BYTES, |
| 12832 | // destination connection ID length |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 12833 | 0x08, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12834 | // destination connection ID |
| 12835 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 12836 | // source connection ID length |
| 12837 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12838 | // long header packet length |
| 12839 | 0x1E, |
| 12840 | // packet number |
| 12841 | 0x12, 0x34, 0x56, 0x78, |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12842 | // frame type (stream frame with fin) |
| 12843 | 0xFE, |
| 12844 | // stream id |
| 12845 | 0x02, 0x03, 0x04, |
| 12846 | // offset |
| 12847 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 12848 | // data length |
| 12849 | 0x00, 0x0c, |
| 12850 | // data |
| 12851 | 'h', 'e', 'l', 'l', |
| 12852 | 'o', ' ', 'w', 'o', |
| 12853 | 'r', 'l', 'd', '!', |
| 12854 | // second coalesced packet |
| 12855 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12856 | // 4-byte packet number) |
| 12857 | 0xD3, |
| 12858 | // version would be here but we cut off the invalid coalesced header. |
| 12859 | }; |
| 12860 | unsigned char packet99[] = { |
| 12861 | // first coalesced packet |
| 12862 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12863 | // 4-byte packet number) |
| 12864 | 0xD3, |
| 12865 | // version |
| 12866 | QUIC_VERSION_BYTES, |
| 12867 | // destination connection ID length |
| 12868 | 0x08, |
| 12869 | // destination connection ID |
| 12870 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12871 | // source connection ID length |
| 12872 | 0x00, |
| 12873 | // long header packet length |
| 12874 | 0x1E, |
| 12875 | // packet number |
| 12876 | 0x12, 0x34, 0x56, 0x78, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12877 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12878 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12879 | // stream id |
| 12880 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12881 | // offset |
| 12882 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12883 | 0x32, 0x10, 0x76, 0x54, |
| 12884 | // data length |
| 12885 | kVarInt62OneByte + 0x0c, |
| 12886 | // data |
| 12887 | 'h', 'e', 'l', 'l', |
| 12888 | 'o', ' ', 'w', 'o', |
| 12889 | 'r', 'l', 'd', '!', |
| 12890 | // second coalesced packet |
| 12891 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12892 | // 4-byte packet number) |
| 12893 | 0xD3, |
| 12894 | // version would be here but we cut off the invalid coalesced header. |
| 12895 | }; |
| 12896 | // clang-format on |
| 12897 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12898 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12899 | size_t p_length = QUICHE_ARRAYSIZE(packet); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12900 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 12901 | p = packet99; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12902 | p_length = QUICHE_ARRAYSIZE(packet99); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12903 | } |
| 12904 | |
| 12905 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
| 12906 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12907 | EXPECT_QUIC_PEER_BUG(EXPECT_TRUE(framer_.ProcessPacket(encrypted)), |
| 12908 | "Server: Failed to parse received coalesced header.*"); |
| 12909 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 12910 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12911 | ASSERT_TRUE(visitor_.header_.get()); |
| 12912 | |
| 12913 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 12914 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12915 | |
| 12916 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12917 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 12918 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 12919 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 12920 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 12921 | |
| 12922 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 0u); |
| 12923 | } |
| 12924 | |
dschinazi | a484f98 | 2019-05-23 03:54:44 -0700 | [diff] [blame] | 12925 | // Some IETF implementations send an initial followed by zeroes instead of |
| 12926 | // padding inside the initial. We need to make sure that we still process |
| 12927 | // the initial correctly and ignore the zeroes. |
| 12928 | TEST_P(QuicFramerTest, CoalescedPacketWithZeroesRoundTrip) { |
nharper | c8d9e40 | 2019-09-12 18:30:14 -0700 | [diff] [blame] | 12929 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version()) || |
| 12930 | !framer_.version().UsesInitialObfuscators()) { |
dschinazi | a484f98 | 2019-05-23 03:54:44 -0700 | [diff] [blame] | 12931 | return; |
| 12932 | } |
| 12933 | ASSERT_TRUE(framer_.version().KnowsWhichDecrypterToUse()); |
| 12934 | QuicConnectionId connection_id = FramerTestConnectionId(); |
| 12935 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 12936 | |
| 12937 | CrypterPair client_crypters; |
nharper | c8d9e40 | 2019-09-12 18:30:14 -0700 | [diff] [blame] | 12938 | CryptoUtils::CreateInitialObfuscators(Perspective::IS_CLIENT, |
| 12939 | framer_.version(), connection_id, |
| 12940 | &client_crypters); |
dschinazi | a484f98 | 2019-05-23 03:54:44 -0700 | [diff] [blame] | 12941 | framer_.SetEncrypter(ENCRYPTION_INITIAL, |
| 12942 | std::move(client_crypters.encrypter)); |
| 12943 | |
| 12944 | QuicPacketHeader header; |
| 12945 | header.destination_connection_id = connection_id; |
| 12946 | header.version_flag = true; |
| 12947 | header.packet_number = kPacketNumber; |
| 12948 | header.packet_number_length = PACKET_4BYTE_PACKET_NUMBER; |
| 12949 | header.long_packet_type = INITIAL; |
| 12950 | header.length_length = VARIABLE_LENGTH_INTEGER_LENGTH_2; |
| 12951 | header.retry_token_length_length = VARIABLE_LENGTH_INTEGER_LENGTH_1; |
nharper | 965e592 | 2019-09-23 22:33:54 -0700 | [diff] [blame] | 12952 | QuicFrames frames = {QuicFrame(QuicPingFrame()), |
| 12953 | QuicFrame(QuicPaddingFrame(3))}; |
dschinazi | a484f98 | 2019-05-23 03:54:44 -0700 | [diff] [blame] | 12954 | |
| 12955 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 12956 | ASSERT_NE(nullptr, data); |
| 12957 | |
| 12958 | // Add zeroes after the valid initial packet. |
| 12959 | unsigned char packet[kMaxOutgoingPacketSize] = {}; |
| 12960 | size_t encrypted_length = |
| 12961 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, *data, |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12962 | AsChars(packet), QUICHE_ARRAYSIZE(packet)); |
dschinazi | a484f98 | 2019-05-23 03:54:44 -0700 | [diff] [blame] | 12963 | ASSERT_NE(0u, encrypted_length); |
| 12964 | |
| 12965 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 12966 | CrypterPair server_crypters; |
nharper | c8d9e40 | 2019-09-12 18:30:14 -0700 | [diff] [blame] | 12967 | CryptoUtils::CreateInitialObfuscators(Perspective::IS_SERVER, |
| 12968 | framer_.version(), connection_id, |
| 12969 | &server_crypters); |
dschinazi | a484f98 | 2019-05-23 03:54:44 -0700 | [diff] [blame] | 12970 | framer_.InstallDecrypter(ENCRYPTION_INITIAL, |
| 12971 | std::move(server_crypters.decrypter)); |
| 12972 | |
| 12973 | // Make sure the first long header initial packet parses correctly. |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 12974 | QuicEncryptedPacket encrypted(AsChars(packet), QUICHE_ARRAYSIZE(packet), |
| 12975 | false); |
dschinazi | a484f98 | 2019-05-23 03:54:44 -0700 | [diff] [blame] | 12976 | |
| 12977 | // Make sure we discard the subsequent zeroes. |
| 12978 | EXPECT_QUIC_PEER_BUG(EXPECT_TRUE(framer_.ProcessPacket(encrypted)), |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 12979 | "Server: (Failed to parse received|Received mismatched) " |
| 12980 | "coalesced header.*"); |
dschinazi | a484f98 | 2019-05-23 03:54:44 -0700 | [diff] [blame] | 12981 | } |
| 12982 | |
dschinazi | e0df3f7 | 2019-05-06 16:37:51 -0700 | [diff] [blame] | 12983 | TEST_P(QuicFramerTest, ClientReceivesInvalidVersion) { |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 12984 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
dschinazi | e0df3f7 | 2019-05-06 16:37:51 -0700 | [diff] [blame] | 12985 | return; |
| 12986 | } |
| 12987 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 12988 | |
| 12989 | // clang-format off |
| 12990 | unsigned char packet[] = { |
| 12991 | // public flags (long header with packet type INITIAL) |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 12992 | 0xC3, |
dschinazi | e0df3f7 | 2019-05-06 16:37:51 -0700 | [diff] [blame] | 12993 | // version that is different from the framer's version |
| 12994 | 'Q', '0', '4', '3', |
| 12995 | // connection ID lengths |
| 12996 | 0x05, |
| 12997 | // source connection ID |
| 12998 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12999 | // packet number |
| 13000 | 0x01, |
| 13001 | // padding frame |
| 13002 | 0x00, |
| 13003 | }; |
| 13004 | // clang-format on |
| 13005 | |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 13006 | QuicEncryptedPacket encrypted(AsChars(packet), QUICHE_ARRAYSIZE(packet), |
| 13007 | false); |
dschinazi | e0df3f7 | 2019-05-06 16:37:51 -0700 | [diff] [blame] | 13008 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 13009 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13010 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_VERSION)); |
dschinazi | e0df3f7 | 2019-05-06 16:37:51 -0700 | [diff] [blame] | 13011 | EXPECT_EQ("Client received unexpected version.", framer_.detailed_error()); |
| 13012 | } |
| 13013 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13014 | TEST_P(QuicFramerTest, PacketHeaderWithVariableLengthConnectionId) { |
dschinazi | 97da52b | 2020-01-13 15:44:43 -0800 | [diff] [blame] | 13015 | if (!framer_.version().AllowsVariableLengthConnectionIds()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13016 | return; |
| 13017 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13018 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13019 | char connection_id_bytes[9] = {0xFE, 0xDC, 0xBA, 0x98, 0x76, |
| 13020 | 0x54, 0x32, 0x10, 0x42}; |
| 13021 | QuicConnectionId connection_id(connection_id_bytes, |
| 13022 | sizeof(connection_id_bytes)); |
| 13023 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
dschinazi | 8ff7482 | 2019-05-28 16:37:20 -0700 | [diff] [blame] | 13024 | QuicFramerPeer::SetExpectedServerConnectionIDLength(&framer_, |
| 13025 | connection_id.length()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13026 | |
| 13027 | // clang-format off |
| 13028 | PacketFragments packet = { |
| 13029 | // type (8 byte connection_id and 1 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13030 | {"Unable to read first byte.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13031 | {0x40}}, |
| 13032 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13033 | {"Unable to read destination connection ID.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13034 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42}}, |
| 13035 | // packet number |
| 13036 | {"Unable to read packet number.", |
| 13037 | {0x78}}, |
| 13038 | }; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13039 | |
| 13040 | PacketFragments packet_with_padding = { |
| 13041 | // type (8 byte connection_id and 1 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13042 | {"Unable to read first byte.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13043 | {0x40}}, |
| 13044 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13045 | {"Unable to read destination connection ID.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13046 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42}}, |
| 13047 | // packet number |
| 13048 | {"", |
| 13049 | {0x78}}, |
| 13050 | // padding |
| 13051 | {"", {0x00, 0x00, 0x00}}, |
| 13052 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13053 | // clang-format on |
| 13054 | |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13055 | PacketFragments& fragments = |
| 13056 | framer_.version().HasHeaderProtection() ? packet_with_padding : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13057 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13058 | AssemblePacketFromFragments(fragments)); |
| 13059 | if (framer_.version().HasHeaderProtection()) { |
| 13060 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13061 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13062 | } else { |
| 13063 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13064 | EXPECT_THAT(framer_.error(), IsError(QUIC_MISSING_PAYLOAD)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13065 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13066 | ASSERT_TRUE(visitor_.header_.get()); |
| 13067 | EXPECT_EQ(connection_id, visitor_.header_->destination_connection_id); |
| 13068 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 13069 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 13070 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 13071 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 13072 | |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13073 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13074 | } |
| 13075 | |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13076 | TEST_P(QuicFramerTest, MultiplePacketNumberSpaces) { |
| 13077 | if (framer_.transport_version() < QUIC_VERSION_46) { |
| 13078 | return; |
| 13079 | } |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13080 | framer_.EnableMultiplePacketNumberSpacesSupport(); |
| 13081 | |
| 13082 | // clang-format off |
| 13083 | unsigned char long_header_packet[] = { |
| 13084 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13085 | // 4-byte packet number) |
| 13086 | 0xD3, |
| 13087 | // version |
| 13088 | QUIC_VERSION_BYTES, |
| 13089 | // destination connection ID length |
fayang | 91475c4 | 2019-06-19 08:04:26 -0700 | [diff] [blame] | 13090 | 0x50, |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13091 | // destination connection ID |
fayang | 91475c4 | 2019-06-19 08:04:26 -0700 | [diff] [blame] | 13092 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13093 | // packet number |
| 13094 | 0x12, 0x34, 0x56, 0x78, |
| 13095 | // padding frame |
| 13096 | 0x00, |
| 13097 | }; |
| 13098 | unsigned char long_header_packet99[] = { |
| 13099 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13100 | // 4-byte packet number) |
| 13101 | 0xD3, |
| 13102 | // version |
| 13103 | QUIC_VERSION_BYTES, |
| 13104 | // destination connection ID length |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13105 | 0x08, |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13106 | // destination connection ID |
fayang | 91475c4 | 2019-06-19 08:04:26 -0700 | [diff] [blame] | 13107 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13108 | // source connection ID length |
| 13109 | 0x00, |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13110 | // long header packet length |
| 13111 | 0x05, |
| 13112 | // packet number |
| 13113 | 0x12, 0x34, 0x56, 0x78, |
| 13114 | // padding frame |
| 13115 | 0x00, |
| 13116 | }; |
| 13117 | // clang-format on |
| 13118 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13119 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 13120 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 13121 | std::make_unique<TestDecrypter>()); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13122 | framer_.RemoveDecrypter(ENCRYPTION_INITIAL); |
| 13123 | } else { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 13124 | framer_.SetDecrypter(ENCRYPTION_ZERO_RTT, |
| 13125 | std::make_unique<TestDecrypter>()); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13126 | } |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13127 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 13128 | EXPECT_TRUE(framer_.ProcessPacket( |
| 13129 | QuicEncryptedPacket(AsChars(long_header_packet), |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 13130 | QUICHE_ARRAYSIZE(long_header_packet), false))); |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13131 | } else { |
| 13132 | EXPECT_TRUE(framer_.ProcessPacket( |
| 13133 | QuicEncryptedPacket(AsChars(long_header_packet99), |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 13134 | QUICHE_ARRAYSIZE(long_header_packet99), false))); |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13135 | } |
| 13136 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13137 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13138 | EXPECT_FALSE( |
| 13139 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, INITIAL_DATA) |
| 13140 | .IsInitialized()); |
| 13141 | EXPECT_FALSE( |
| 13142 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, HANDSHAKE_DATA) |
| 13143 | .IsInitialized()); |
| 13144 | EXPECT_EQ(kPacketNumber, QuicFramerPeer::GetLargestDecryptedPacketNumber( |
| 13145 | &framer_, APPLICATION_DATA)); |
| 13146 | |
| 13147 | // clang-format off |
| 13148 | unsigned char short_header_packet[] = { |
| 13149 | // type (short header, 1 byte packet number) |
| 13150 | 0x40, |
| 13151 | // connection_id |
fayang | 91475c4 | 2019-06-19 08:04:26 -0700 | [diff] [blame] | 13152 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13153 | // packet number |
| 13154 | 0x79, |
| 13155 | // padding frame |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13156 | 0x00, 0x00, 0x00, |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13157 | }; |
| 13158 | // clang-format on |
| 13159 | |
| 13160 | QuicEncryptedPacket short_header_encrypted( |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 13161 | AsChars(short_header_packet), QUICHE_ARRAYSIZE(short_header_packet), |
| 13162 | false); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13163 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 13164 | framer_.InstallDecrypter(ENCRYPTION_FORWARD_SECURE, |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 13165 | std::make_unique<TestDecrypter>()); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13166 | framer_.RemoveDecrypter(ENCRYPTION_ZERO_RTT); |
| 13167 | } else { |
| 13168 | framer_.SetDecrypter(ENCRYPTION_FORWARD_SECURE, |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 13169 | std::make_unique<TestDecrypter>()); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13170 | } |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13171 | EXPECT_TRUE(framer_.ProcessPacket(short_header_encrypted)); |
| 13172 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13173 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13174 | EXPECT_FALSE( |
| 13175 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, INITIAL_DATA) |
| 13176 | .IsInitialized()); |
| 13177 | EXPECT_FALSE( |
| 13178 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, HANDSHAKE_DATA) |
| 13179 | .IsInitialized()); |
| 13180 | EXPECT_EQ(kPacketNumber + 1, QuicFramerPeer::GetLargestDecryptedPacketNumber( |
| 13181 | &framer_, APPLICATION_DATA)); |
| 13182 | } |
| 13183 | |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13184 | TEST_P(QuicFramerTest, IetfRetryPacketRejected) { |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 13185 | if (!framer_.version().KnowsWhichDecrypterToUse() || |
| 13186 | framer_.version().SupportsRetry()) { |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13187 | return; |
| 13188 | } |
| 13189 | |
| 13190 | // clang-format off |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 13191 | PacketFragments packet46 = { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 13192 | // public flags (IETF Retry packet, 0-length original destination CID) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13193 | {"Unable to read first byte.", |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 13194 | {0xf0}}, |
| 13195 | // version tag |
| 13196 | {"Unable to read protocol version.", |
| 13197 | {QUIC_VERSION_BYTES}}, |
| 13198 | // connection_id length |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 13199 | {"RETRY not supported in this version.", |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13200 | {0x00}}, |
| 13201 | }; |
| 13202 | // clang-format on |
| 13203 | |
| 13204 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 13205 | AssemblePacketFromFragments(packet46)); |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13206 | |
| 13207 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13208 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 13209 | CheckFramingBoundaries(packet46, QUIC_INVALID_PACKET_HEADER); |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13210 | } |
| 13211 | |
| 13212 | TEST_P(QuicFramerTest, RetryPacketRejectedWithMultiplePacketNumberSpaces) { |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 13213 | if (framer_.transport_version() < QUIC_VERSION_46 || |
| 13214 | framer_.version().SupportsRetry()) { |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13215 | return; |
| 13216 | } |
| 13217 | framer_.EnableMultiplePacketNumberSpacesSupport(); |
| 13218 | |
| 13219 | // clang-format off |
| 13220 | PacketFragments packet = { |
| 13221 | // public flags (IETF Retry packet, 0-length original destination CID) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13222 | {"Unable to read first byte.", |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13223 | {0xf0}}, |
| 13224 | // version tag |
| 13225 | {"Unable to read protocol version.", |
| 13226 | {QUIC_VERSION_BYTES}}, |
| 13227 | // connection_id length |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 13228 | {"RETRY not supported in this version.", |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13229 | {0x00}}, |
| 13230 | }; |
| 13231 | // clang-format on |
| 13232 | |
| 13233 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 13234 | AssemblePacketFromFragments(packet)); |
| 13235 | |
| 13236 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13237 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13238 | CheckFramingBoundaries(packet, QUIC_INVALID_PACKET_HEADER); |
| 13239 | } |
| 13240 | |
nharper | a745e39 | 2019-04-19 12:05:15 -0700 | [diff] [blame] | 13241 | TEST_P(QuicFramerTest, ProcessPublicHeaderNoVersionInferredType) { |
| 13242 | // The framer needs to have Perspective::IS_SERVER and configured to infer the |
| 13243 | // packet header type from the packet (not the version). The framer's version |
| 13244 | // needs to be one that uses the IETF packet format. |
| 13245 | if (!framer_.version().KnowsWhichDecrypterToUse()) { |
| 13246 | return; |
| 13247 | } |
| 13248 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 13249 | |
| 13250 | // Prepare a packet that uses the Google QUIC packet header but has no version |
| 13251 | // field. |
| 13252 | |
| 13253 | // clang-format off |
| 13254 | PacketFragments packet = { |
| 13255 | // public flags (1-byte packet number, 8-byte connection_id, no version) |
| 13256 | {"Unable to read public flags.", |
| 13257 | {0x08}}, |
| 13258 | // connection_id |
| 13259 | {"Unable to read ConnectionId.", |
| 13260 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 13261 | // packet number |
| 13262 | {"Unable to read packet number.", |
| 13263 | {0x01}}, |
| 13264 | // padding |
| 13265 | {"Invalid public header type for expected version.", |
| 13266 | {0x00}}, |
| 13267 | }; |
| 13268 | // clang-format on |
| 13269 | |
| 13270 | PacketFragments& fragments = packet; |
| 13271 | |
| 13272 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 13273 | AssemblePacketFromFragments(fragments)); |
| 13274 | |
| 13275 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13276 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
nharper | 8b6d63a | 2019-05-03 10:34:53 -0700 | [diff] [blame] | 13277 | EXPECT_EQ("Invalid public header type for expected version.", |
| 13278 | framer_.detailed_error()); |
nharper | a745e39 | 2019-04-19 12:05:15 -0700 | [diff] [blame] | 13279 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 13280 | } |
| 13281 | |
nharper | 3f28356 | 2019-05-02 16:37:12 -0700 | [diff] [blame] | 13282 | TEST_P(QuicFramerTest, ProcessMismatchedHeaderVersion) { |
| 13283 | // The framer needs to have Perspective::IS_SERVER and configured to infer the |
| 13284 | // packet header type from the packet (not the version). The framer's version |
| 13285 | // needs to be one that uses the IETF packet format. |
| 13286 | if (!framer_.version().KnowsWhichDecrypterToUse()) { |
| 13287 | return; |
| 13288 | } |
| 13289 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 13290 | |
| 13291 | // clang-format off |
| 13292 | PacketFragments packet = { |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 13293 | // public flags (Google QUIC header with version present) |
nharper | 3f28356 | 2019-05-02 16:37:12 -0700 | [diff] [blame] | 13294 | {"Unable to read public flags.", |
| 13295 | {0x09}}, |
| 13296 | // connection_id |
| 13297 | {"Unable to read ConnectionId.", |
| 13298 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 13299 | // version tag |
| 13300 | {"Unable to read protocol version.", |
| 13301 | {QUIC_VERSION_BYTES}}, |
| 13302 | // packet number |
| 13303 | {"Unable to read packet number.", |
| 13304 | {0x01}}, |
| 13305 | }; |
| 13306 | // clang-format on |
| 13307 | |
| 13308 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 13309 | AssemblePacketFromFragments(packet)); |
| 13310 | framer_.ProcessPacket(*encrypted); |
| 13311 | |
| 13312 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13313 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
nharper | 8b6d63a | 2019-05-03 10:34:53 -0700 | [diff] [blame] | 13314 | EXPECT_EQ("Invalid public header type for expected version.", |
| 13315 | framer_.detailed_error()); |
nharper | 3f28356 | 2019-05-02 16:37:12 -0700 | [diff] [blame] | 13316 | CheckFramingBoundaries(packet, QUIC_INVALID_PACKET_HEADER); |
| 13317 | } |
| 13318 | |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13319 | TEST_P(QuicFramerTest, WriteClientVersionNegotiationProbePacketOld) { |
| 13320 | SetQuicFlag(FLAGS_quic_prober_uses_length_prefixed_connection_ids, false); |
dschinazi | de0f6dc | 2019-05-15 16:10:11 -0700 | [diff] [blame] | 13321 | // clang-format off |
| 13322 | static const char expected_packet[1200] = { |
| 13323 | // IETF long header with fixed bit set, type initial, all-0 encrypted bits. |
| 13324 | 0xc0, |
| 13325 | // Version, part of the IETF space reserved for negotiation. |
| 13326 | 0xca, 0xba, 0xda, 0xba, |
| 13327 | // Destination connection ID length 8, source connection ID length 0. |
| 13328 | 0x50, |
| 13329 | // 8-byte destination connection ID. |
| 13330 | 0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21, |
| 13331 | // 8 bytes of zeroes followed by 8 bytes of ones to ensure that this does |
| 13332 | // not parse with any known version. |
| 13333 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13334 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 13335 | // 2 bytes of zeroes to pad to 16 byte boundary. |
| 13336 | 0x00, 0x00, |
| 13337 | // A polite greeting in case a human sees this in tcpdump. |
| 13338 | 0x54, 0x68, 0x69, 0x73, 0x20, 0x70, 0x61, 0x63, |
| 13339 | 0x6b, 0x65, 0x74, 0x20, 0x6f, 0x6e, 0x6c, 0x79, |
| 13340 | 0x20, 0x65, 0x78, 0x69, 0x73, 0x74, 0x73, 0x20, |
| 13341 | 0x74, 0x6f, 0x20, 0x74, 0x72, 0x69, 0x67, 0x67, |
| 13342 | 0x65, 0x72, 0x20, 0x49, 0x45, 0x54, 0x46, 0x20, |
| 13343 | 0x51, 0x55, 0x49, 0x43, 0x20, 0x76, 0x65, 0x72, |
| 13344 | 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x65, 0x67, |
| 13345 | 0x6f, 0x74, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, |
| 13346 | 0x2e, 0x20, 0x50, 0x6c, 0x65, 0x61, 0x73, 0x65, |
| 13347 | 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, |
| 13348 | 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x20, |
| 13349 | 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, |
| 13350 | 0x4e, 0x65, 0x67, 0x6f, 0x74, 0x69, 0x61, 0x74, |
| 13351 | 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, 0x63, 0x6b, |
| 13352 | 0x65, 0x74, 0x20, 0x69, 0x6e, 0x64, 0x69, 0x63, |
| 13353 | 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x77, 0x68, |
| 13354 | 0x61, 0x74, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, |
| 13355 | 0x6f, 0x6e, 0x73, 0x20, 0x79, 0x6f, 0x75, 0x20, |
| 13356 | 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x2e, |
| 13357 | 0x20, 0x54, 0x68, 0x61, 0x6e, 0x6b, 0x20, 0x79, |
| 13358 | 0x6f, 0x75, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x68, |
| 13359 | 0x61, 0x76, 0x65, 0x20, 0x61, 0x20, 0x6e, 0x69, |
| 13360 | 0x63, 0x65, 0x20, 0x64, 0x61, 0x79, 0x2e, 0x00, |
| 13361 | }; |
| 13362 | // clang-format on |
| 13363 | char packet[1200]; |
| 13364 | char destination_connection_id_bytes[] = {0x56, 0x4e, 0x20, 0x70, |
| 13365 | 0x6c, 0x7a, 0x20, 0x21}; |
| 13366 | EXPECT_TRUE(QuicFramer::WriteClientVersionNegotiationProbePacket( |
| 13367 | packet, sizeof(packet), destination_connection_id_bytes, |
| 13368 | sizeof(destination_connection_id_bytes))); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 13369 | quiche::test::CompareCharArraysWithHexError("constructed packet", packet, |
| 13370 | sizeof(packet), expected_packet, |
| 13371 | sizeof(expected_packet)); |
dschinazi | de0f6dc | 2019-05-15 16:10:11 -0700 | [diff] [blame] | 13372 | QuicEncryptedPacket encrypted(reinterpret_cast<const char*>(packet), |
| 13373 | sizeof(packet), false); |
| 13374 | // Make sure we fail to parse this packet for the version under test. |
dschinazi | de0f6dc | 2019-05-15 16:10:11 -0700 | [diff] [blame] | 13375 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 13376 | // We can only parse the connection ID with an IETF parser. |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13377 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
dschinazi | de0f6dc | 2019-05-15 16:10:11 -0700 | [diff] [blame] | 13378 | return; |
| 13379 | } |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13380 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
dschinazi | de0f6dc | 2019-05-15 16:10:11 -0700 | [diff] [blame] | 13381 | ASSERT_TRUE(visitor_.header_.get()); |
| 13382 | QuicConnectionId probe_payload_connection_id( |
| 13383 | reinterpret_cast<const char*>(destination_connection_id_bytes), |
| 13384 | sizeof(destination_connection_id_bytes)); |
| 13385 | EXPECT_EQ(probe_payload_connection_id, |
| 13386 | visitor_.header_.get()->destination_connection_id); |
dschinazi | 30ab6db | 2019-08-13 14:43:32 -0700 | [diff] [blame] | 13387 | |
| 13388 | PacketHeaderFormat format = GOOGLE_QUIC_PACKET; |
fayang | e3f2f7b | 2019-09-19 17:01:57 -0700 | [diff] [blame] | 13389 | QuicLongHeaderType long_packet_type = INVALID_PACKET_TYPE; |
dschinazi | 30ab6db | 2019-08-13 14:43:32 -0700 | [diff] [blame] | 13390 | bool version_present = false, has_length_prefix = false; |
| 13391 | QuicVersionLabel version_label = 0; |
| 13392 | ParsedQuicVersion parsed_version = QuicVersionReservedForNegotiation(); |
| 13393 | QuicConnectionId destination_connection_id = TestConnectionId(0x33); |
| 13394 | QuicConnectionId source_connection_id = TestConnectionId(0x34); |
| 13395 | bool retry_token_present = true; |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 13396 | quiche::QuicheStringPiece retry_token; |
dschinazi | 30ab6db | 2019-08-13 14:43:32 -0700 | [diff] [blame] | 13397 | std::string detailed_error = "foobar"; |
| 13398 | |
| 13399 | QuicErrorCode parse_result = QuicFramer::ParsePublicHeaderDispatcher( |
fayang | e3f2f7b | 2019-09-19 17:01:57 -0700 | [diff] [blame] | 13400 | encrypted, kQuicDefaultConnectionIdLength, &format, &long_packet_type, |
| 13401 | &version_present, &has_length_prefix, &version_label, &parsed_version, |
dschinazi | 30ab6db | 2019-08-13 14:43:32 -0700 | [diff] [blame] | 13402 | &destination_connection_id, &source_connection_id, &retry_token_present, |
| 13403 | &retry_token, &detailed_error); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13404 | EXPECT_THAT(parse_result, IsQuicNoError()); |
dschinazi | 30ab6db | 2019-08-13 14:43:32 -0700 | [diff] [blame] | 13405 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 13406 | EXPECT_TRUE(version_present); |
| 13407 | EXPECT_FALSE(has_length_prefix); |
| 13408 | EXPECT_EQ(0xcabadaba, version_label); |
| 13409 | EXPECT_EQ(QUIC_VERSION_UNSUPPORTED, parsed_version.transport_version); |
| 13410 | EXPECT_EQ(probe_payload_connection_id, destination_connection_id); |
| 13411 | EXPECT_EQ(EmptyQuicConnectionId(), source_connection_id); |
| 13412 | EXPECT_FALSE(retry_token_present); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 13413 | EXPECT_EQ(quiche::QuicheStringPiece(), retry_token); |
dschinazi | 30ab6db | 2019-08-13 14:43:32 -0700 | [diff] [blame] | 13414 | EXPECT_EQ("", detailed_error); |
dschinazi | de0f6dc | 2019-05-15 16:10:11 -0700 | [diff] [blame] | 13415 | } |
| 13416 | |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13417 | TEST_P(QuicFramerTest, WriteClientVersionNegotiationProbePacket) { |
| 13418 | SetQuicFlag(FLAGS_quic_prober_uses_length_prefixed_connection_ids, true); |
| 13419 | // clang-format off |
| 13420 | static const char expected_packet[1200] = { |
| 13421 | // IETF long header with fixed bit set, type initial, all-0 encrypted bits. |
| 13422 | 0xc0, |
| 13423 | // Version, part of the IETF space reserved for negotiation. |
| 13424 | 0xca, 0xba, 0xda, 0xda, |
| 13425 | // Destination connection ID length 8. |
| 13426 | 0x08, |
| 13427 | // 8-byte destination connection ID. |
| 13428 | 0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21, |
| 13429 | // Source connection ID length 0. |
| 13430 | 0x00, |
| 13431 | // 8 bytes of zeroes followed by 8 bytes of ones to ensure that this does |
| 13432 | // not parse with any known version. |
| 13433 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13434 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 13435 | // zeroes to pad to 16 byte boundary. |
| 13436 | 0x00, |
| 13437 | // A polite greeting in case a human sees this in tcpdump. |
| 13438 | 0x54, 0x68, 0x69, 0x73, 0x20, 0x70, 0x61, 0x63, |
| 13439 | 0x6b, 0x65, 0x74, 0x20, 0x6f, 0x6e, 0x6c, 0x79, |
| 13440 | 0x20, 0x65, 0x78, 0x69, 0x73, 0x74, 0x73, 0x20, |
| 13441 | 0x74, 0x6f, 0x20, 0x74, 0x72, 0x69, 0x67, 0x67, |
| 13442 | 0x65, 0x72, 0x20, 0x49, 0x45, 0x54, 0x46, 0x20, |
| 13443 | 0x51, 0x55, 0x49, 0x43, 0x20, 0x76, 0x65, 0x72, |
| 13444 | 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x65, 0x67, |
| 13445 | 0x6f, 0x74, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, |
| 13446 | 0x2e, 0x20, 0x50, 0x6c, 0x65, 0x61, 0x73, 0x65, |
| 13447 | 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, |
| 13448 | 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x20, |
| 13449 | 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, |
| 13450 | 0x4e, 0x65, 0x67, 0x6f, 0x74, 0x69, 0x61, 0x74, |
| 13451 | 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, 0x63, 0x6b, |
| 13452 | 0x65, 0x74, 0x20, 0x69, 0x6e, 0x64, 0x69, 0x63, |
| 13453 | 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x77, 0x68, |
| 13454 | 0x61, 0x74, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, |
| 13455 | 0x6f, 0x6e, 0x73, 0x20, 0x79, 0x6f, 0x75, 0x20, |
| 13456 | 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x2e, |
| 13457 | 0x20, 0x54, 0x68, 0x61, 0x6e, 0x6b, 0x20, 0x79, |
| 13458 | 0x6f, 0x75, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x68, |
| 13459 | 0x61, 0x76, 0x65, 0x20, 0x61, 0x20, 0x6e, 0x69, |
| 13460 | 0x63, 0x65, 0x20, 0x64, 0x61, 0x79, 0x2e, 0x00, |
| 13461 | }; |
| 13462 | // clang-format on |
| 13463 | char packet[1200]; |
| 13464 | char destination_connection_id_bytes[] = {0x56, 0x4e, 0x20, 0x70, |
| 13465 | 0x6c, 0x7a, 0x20, 0x21}; |
| 13466 | EXPECT_TRUE(QuicFramer::WriteClientVersionNegotiationProbePacket( |
| 13467 | packet, sizeof(packet), destination_connection_id_bytes, |
| 13468 | sizeof(destination_connection_id_bytes))); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 13469 | quiche::test::CompareCharArraysWithHexError("constructed packet", packet, |
| 13470 | sizeof(packet), expected_packet, |
| 13471 | sizeof(expected_packet)); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13472 | QuicEncryptedPacket encrypted(reinterpret_cast<const char*>(packet), |
| 13473 | sizeof(packet), false); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13474 | if (!framer_.version().HasLengthPrefixedConnectionIds()) { |
| 13475 | // We can only parse the connection ID with a parser expecting |
| 13476 | // length-prefixed connection IDs. |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13477 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 13478 | return; |
| 13479 | } |
| 13480 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 13481 | ASSERT_TRUE(visitor_.header_.get()); |
| 13482 | QuicConnectionId probe_payload_connection_id( |
| 13483 | reinterpret_cast<const char*>(destination_connection_id_bytes), |
| 13484 | sizeof(destination_connection_id_bytes)); |
| 13485 | EXPECT_EQ(probe_payload_connection_id, |
| 13486 | visitor_.header_.get()->destination_connection_id); |
| 13487 | } |
| 13488 | |
| 13489 | TEST_P(QuicFramerTest, DispatcherParseOldClientVersionNegotiationProbePacket) { |
| 13490 | // clang-format off |
| 13491 | static const char packet[1200] = { |
| 13492 | // IETF long header with fixed bit set, type initial, all-0 encrypted bits. |
| 13493 | 0xc0, |
| 13494 | // Version, part of the IETF space reserved for negotiation. |
| 13495 | 0xca, 0xba, 0xda, 0xba, |
| 13496 | // Destination connection ID length 8, source connection ID length 0. |
| 13497 | 0x50, |
| 13498 | // 8-byte destination connection ID. |
| 13499 | 0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21, |
| 13500 | // 8 bytes of zeroes followed by 8 bytes of ones to ensure that this does |
| 13501 | // not parse with any known version. |
| 13502 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13503 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 13504 | // 2 bytes of zeroes to pad to 16 byte boundary. |
| 13505 | 0x00, 0x00, |
| 13506 | // A polite greeting in case a human sees this in tcpdump. |
| 13507 | 0x54, 0x68, 0x69, 0x73, 0x20, 0x70, 0x61, 0x63, |
| 13508 | 0x6b, 0x65, 0x74, 0x20, 0x6f, 0x6e, 0x6c, 0x79, |
| 13509 | 0x20, 0x65, 0x78, 0x69, 0x73, 0x74, 0x73, 0x20, |
| 13510 | 0x74, 0x6f, 0x20, 0x74, 0x72, 0x69, 0x67, 0x67, |
| 13511 | 0x65, 0x72, 0x20, 0x49, 0x45, 0x54, 0x46, 0x20, |
| 13512 | 0x51, 0x55, 0x49, 0x43, 0x20, 0x76, 0x65, 0x72, |
| 13513 | 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x65, 0x67, |
| 13514 | 0x6f, 0x74, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, |
| 13515 | 0x2e, 0x20, 0x50, 0x6c, 0x65, 0x61, 0x73, 0x65, |
| 13516 | 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, |
| 13517 | 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x20, |
| 13518 | 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, |
| 13519 | 0x4e, 0x65, 0x67, 0x6f, 0x74, 0x69, 0x61, 0x74, |
| 13520 | 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, 0x63, 0x6b, |
| 13521 | 0x65, 0x74, 0x20, 0x69, 0x6e, 0x64, 0x69, 0x63, |
| 13522 | 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x77, 0x68, |
| 13523 | 0x61, 0x74, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, |
| 13524 | 0x6f, 0x6e, 0x73, 0x20, 0x79, 0x6f, 0x75, 0x20, |
| 13525 | 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x2e, |
| 13526 | 0x20, 0x54, 0x68, 0x61, 0x6e, 0x6b, 0x20, 0x79, |
| 13527 | 0x6f, 0x75, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x68, |
| 13528 | 0x61, 0x76, 0x65, 0x20, 0x61, 0x20, 0x6e, 0x69, |
| 13529 | 0x63, 0x65, 0x20, 0x64, 0x61, 0x79, 0x2e, 0x00, |
| 13530 | }; |
| 13531 | // clang-format on |
| 13532 | char expected_destination_connection_id_bytes[] = {0x56, 0x4e, 0x20, 0x70, |
| 13533 | 0x6c, 0x7a, 0x20, 0x21}; |
| 13534 | QuicConnectionId expected_destination_connection_id( |
| 13535 | reinterpret_cast<const char*>(expected_destination_connection_id_bytes), |
| 13536 | sizeof(expected_destination_connection_id_bytes)); |
| 13537 | |
| 13538 | QuicEncryptedPacket encrypted(reinterpret_cast<const char*>(packet), |
| 13539 | sizeof(packet)); |
| 13540 | PacketHeaderFormat format = GOOGLE_QUIC_PACKET; |
fayang | e3f2f7b | 2019-09-19 17:01:57 -0700 | [diff] [blame] | 13541 | QuicLongHeaderType long_packet_type = INVALID_PACKET_TYPE; |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13542 | bool version_present = false, has_length_prefix = true; |
| 13543 | QuicVersionLabel version_label = 33; |
| 13544 | ParsedQuicVersion parsed_version = UnsupportedQuicVersion(); |
| 13545 | QuicConnectionId destination_connection_id = TestConnectionId(1); |
| 13546 | QuicConnectionId source_connection_id = TestConnectionId(2); |
| 13547 | bool retry_token_present = true; |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 13548 | quiche::QuicheStringPiece retry_token; |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13549 | std::string detailed_error = "foobar"; |
| 13550 | QuicErrorCode header_parse_result = QuicFramer::ParsePublicHeaderDispatcher( |
fayang | e3f2f7b | 2019-09-19 17:01:57 -0700 | [diff] [blame] | 13551 | encrypted, kQuicDefaultConnectionIdLength, &format, &long_packet_type, |
| 13552 | &version_present, &has_length_prefix, &version_label, &parsed_version, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13553 | &destination_connection_id, &source_connection_id, &retry_token_present, |
| 13554 | &retry_token, &detailed_error); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13555 | EXPECT_THAT(header_parse_result, IsQuicNoError()); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13556 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 13557 | EXPECT_TRUE(version_present); |
| 13558 | EXPECT_FALSE(has_length_prefix); |
| 13559 | EXPECT_EQ(0xcabadaba, version_label); |
| 13560 | EXPECT_EQ(expected_destination_connection_id, destination_connection_id); |
| 13561 | EXPECT_EQ(EmptyQuicConnectionId(), source_connection_id); |
| 13562 | EXPECT_FALSE(retry_token_present); |
| 13563 | EXPECT_EQ("", detailed_error); |
| 13564 | } |
| 13565 | |
| 13566 | TEST_P(QuicFramerTest, DispatcherParseClientVersionNegotiationProbePacket) { |
| 13567 | // clang-format off |
| 13568 | static const char packet[1200] = { |
| 13569 | // IETF long header with fixed bit set, type initial, all-0 encrypted bits. |
| 13570 | 0xc0, |
| 13571 | // Version, part of the IETF space reserved for negotiation. |
| 13572 | 0xca, 0xba, 0xda, 0xba, |
| 13573 | // Destination connection ID length 8. |
| 13574 | 0x08, |
| 13575 | // 8-byte destination connection ID. |
| 13576 | 0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21, |
| 13577 | // Source connection ID length 0. |
| 13578 | 0x00, |
| 13579 | // 8 bytes of zeroes followed by 8 bytes of ones to ensure that this does |
| 13580 | // not parse with any known version. |
| 13581 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13582 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 13583 | // 1 byte of zeroes to pad to 16 byte boundary. |
| 13584 | 0x00, |
| 13585 | // A polite greeting in case a human sees this in tcpdump. |
| 13586 | 0x54, 0x68, 0x69, 0x73, 0x20, 0x70, 0x61, 0x63, |
| 13587 | 0x6b, 0x65, 0x74, 0x20, 0x6f, 0x6e, 0x6c, 0x79, |
| 13588 | 0x20, 0x65, 0x78, 0x69, 0x73, 0x74, 0x73, 0x20, |
| 13589 | 0x74, 0x6f, 0x20, 0x74, 0x72, 0x69, 0x67, 0x67, |
| 13590 | 0x65, 0x72, 0x20, 0x49, 0x45, 0x54, 0x46, 0x20, |
| 13591 | 0x51, 0x55, 0x49, 0x43, 0x20, 0x76, 0x65, 0x72, |
| 13592 | 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x65, 0x67, |
| 13593 | 0x6f, 0x74, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, |
| 13594 | 0x2e, 0x20, 0x50, 0x6c, 0x65, 0x61, 0x73, 0x65, |
| 13595 | 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, |
| 13596 | 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x20, |
| 13597 | 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, |
| 13598 | 0x4e, 0x65, 0x67, 0x6f, 0x74, 0x69, 0x61, 0x74, |
| 13599 | 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, 0x63, 0x6b, |
| 13600 | 0x65, 0x74, 0x20, 0x69, 0x6e, 0x64, 0x69, 0x63, |
| 13601 | 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x77, 0x68, |
| 13602 | 0x61, 0x74, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, |
| 13603 | 0x6f, 0x6e, 0x73, 0x20, 0x79, 0x6f, 0x75, 0x20, |
| 13604 | 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x2e, |
| 13605 | 0x20, 0x54, 0x68, 0x61, 0x6e, 0x6b, 0x20, 0x79, |
| 13606 | 0x6f, 0x75, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x68, |
| 13607 | 0x61, 0x76, 0x65, 0x20, 0x61, 0x20, 0x6e, 0x69, |
| 13608 | 0x63, 0x65, 0x20, 0x64, 0x61, 0x79, 0x2e, 0x00, |
| 13609 | }; |
| 13610 | // clang-format on |
| 13611 | char expected_destination_connection_id_bytes[] = {0x56, 0x4e, 0x20, 0x70, |
| 13612 | 0x6c, 0x7a, 0x20, 0x21}; |
| 13613 | QuicConnectionId expected_destination_connection_id( |
| 13614 | reinterpret_cast<const char*>(expected_destination_connection_id_bytes), |
| 13615 | sizeof(expected_destination_connection_id_bytes)); |
| 13616 | |
| 13617 | QuicEncryptedPacket encrypted(reinterpret_cast<const char*>(packet), |
| 13618 | sizeof(packet)); |
| 13619 | PacketHeaderFormat format = GOOGLE_QUIC_PACKET; |
fayang | e3f2f7b | 2019-09-19 17:01:57 -0700 | [diff] [blame] | 13620 | QuicLongHeaderType long_packet_type = INVALID_PACKET_TYPE; |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13621 | bool version_present = false, has_length_prefix = false; |
| 13622 | QuicVersionLabel version_label = 33; |
| 13623 | ParsedQuicVersion parsed_version = UnsupportedQuicVersion(); |
| 13624 | QuicConnectionId destination_connection_id = TestConnectionId(1); |
| 13625 | QuicConnectionId source_connection_id = TestConnectionId(2); |
| 13626 | bool retry_token_present = true; |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 13627 | quiche::QuicheStringPiece retry_token; |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13628 | std::string detailed_error = "foobar"; |
| 13629 | QuicErrorCode header_parse_result = QuicFramer::ParsePublicHeaderDispatcher( |
fayang | e3f2f7b | 2019-09-19 17:01:57 -0700 | [diff] [blame] | 13630 | encrypted, kQuicDefaultConnectionIdLength, &format, &long_packet_type, |
| 13631 | &version_present, &has_length_prefix, &version_label, &parsed_version, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13632 | &destination_connection_id, &source_connection_id, &retry_token_present, |
| 13633 | &retry_token, &detailed_error); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13634 | EXPECT_THAT(header_parse_result, IsQuicNoError()); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13635 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 13636 | EXPECT_TRUE(version_present); |
| 13637 | EXPECT_TRUE(has_length_prefix); |
| 13638 | EXPECT_EQ(0xcabadaba, version_label); |
| 13639 | EXPECT_EQ(expected_destination_connection_id, destination_connection_id); |
| 13640 | EXPECT_EQ(EmptyQuicConnectionId(), source_connection_id); |
| 13641 | EXPECT_EQ("", detailed_error); |
| 13642 | } |
| 13643 | |
| 13644 | TEST_P(QuicFramerTest, ParseServerVersionNegotiationProbeResponseOld) { |
| 13645 | SetQuicFlag(FLAGS_quic_prober_uses_length_prefixed_connection_ids, false); |
dschinazi | de0f6dc | 2019-05-15 16:10:11 -0700 | [diff] [blame] | 13646 | // clang-format off |
| 13647 | const char packet[] = { |
| 13648 | // IETF long header with fixed bit set, type initial, all-0 encrypted bits. |
| 13649 | 0xc0, |
| 13650 | // Version of 0, indicating version negotiation. |
| 13651 | 0x00, 0x00, 0x00, 0x00, |
| 13652 | // Destination connection ID length 0, source connection ID length 8. |
| 13653 | 0x05, |
| 13654 | // 8-byte source connection ID. |
| 13655 | 0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21, |
| 13656 | // A few supported versions. |
| 13657 | 0xaa, 0xaa, 0xaa, 0xaa, |
| 13658 | QUIC_VERSION_BYTES, |
| 13659 | }; |
| 13660 | // clang-format on |
| 13661 | char probe_payload_bytes[] = {0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21}; |
dschinazi | b012d21 | 2019-08-01 18:07:26 -0700 | [diff] [blame] | 13662 | char parsed_probe_payload_bytes[255] = {}; |
dschinazi | de0f6dc | 2019-05-15 16:10:11 -0700 | [diff] [blame] | 13663 | uint8_t parsed_probe_payload_length = 0; |
| 13664 | std::string parse_detailed_error = ""; |
| 13665 | EXPECT_TRUE(QuicFramer::ParseServerVersionNegotiationProbeResponse( |
| 13666 | reinterpret_cast<const char*>(packet), sizeof(packet), |
| 13667 | reinterpret_cast<char*>(parsed_probe_payload_bytes), |
| 13668 | &parsed_probe_payload_length, &parse_detailed_error)); |
| 13669 | EXPECT_EQ("", parse_detailed_error); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 13670 | quiche::test::CompareCharArraysWithHexError( |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13671 | "parsed probe", parsed_probe_payload_bytes, parsed_probe_payload_length, |
| 13672 | probe_payload_bytes, sizeof(probe_payload_bytes)); |
| 13673 | } |
| 13674 | |
| 13675 | TEST_P(QuicFramerTest, ParseServerVersionNegotiationProbeResponse) { |
| 13676 | SetQuicFlag(FLAGS_quic_prober_uses_length_prefixed_connection_ids, true); |
| 13677 | // clang-format off |
| 13678 | const char packet[] = { |
| 13679 | // IETF long header with fixed bit set, type initial, all-0 encrypted bits. |
| 13680 | 0xc0, |
| 13681 | // Version of 0, indicating version negotiation. |
| 13682 | 0x00, 0x00, 0x00, 0x00, |
| 13683 | // Destination connection ID length 0, source connection ID length 8. |
| 13684 | 0x00, 0x08, |
| 13685 | // 8-byte source connection ID. |
| 13686 | 0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21, |
| 13687 | // A few supported versions. |
| 13688 | 0xaa, 0xaa, 0xaa, 0xaa, |
| 13689 | QUIC_VERSION_BYTES, |
| 13690 | }; |
| 13691 | // clang-format on |
| 13692 | char probe_payload_bytes[] = {0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21}; |
dschinazi | b012d21 | 2019-08-01 18:07:26 -0700 | [diff] [blame] | 13693 | char parsed_probe_payload_bytes[255] = {}; |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13694 | uint8_t parsed_probe_payload_length = 0; |
| 13695 | std::string parse_detailed_error = ""; |
| 13696 | EXPECT_TRUE(QuicFramer::ParseServerVersionNegotiationProbeResponse( |
| 13697 | reinterpret_cast<const char*>(packet), sizeof(packet), |
| 13698 | reinterpret_cast<char*>(parsed_probe_payload_bytes), |
| 13699 | &parsed_probe_payload_length, &parse_detailed_error)); |
| 13700 | EXPECT_EQ("", parse_detailed_error); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 13701 | quiche::test::CompareCharArraysWithHexError( |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13702 | "parsed probe", parsed_probe_payload_bytes, parsed_probe_payload_length, |
| 13703 | probe_payload_bytes, sizeof(probe_payload_bytes)); |
dschinazi | de0f6dc | 2019-05-15 16:10:11 -0700 | [diff] [blame] | 13704 | } |
| 13705 | |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 13706 | TEST_P(QuicFramerTest, ClientConnectionIdFromLongHeaderToClient) { |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 13707 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 13708 | // This test requires an IETF long header. |
| 13709 | return; |
| 13710 | } |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 13711 | SetDecrypterLevel(ENCRYPTION_HANDSHAKE); |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 13712 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 13713 | // clang-format off |
| 13714 | unsigned char packet[] = { |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 13715 | // public flags (long header with packet type HANDSHAKE and |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 13716 | // 4-byte packet number) |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 13717 | 0xE3, |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 13718 | // version |
| 13719 | QUIC_VERSION_BYTES, |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 13720 | // connection ID lengths |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 13721 | 0x50, |
| 13722 | // destination connection ID |
| 13723 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13724 | // long header packet length |
| 13725 | 0x05, |
| 13726 | // packet number |
| 13727 | 0x12, 0x34, 0x56, 0x00, |
| 13728 | // padding frame |
| 13729 | 0x00, |
| 13730 | }; |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13731 | unsigned char packet49[] = { |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13732 | // public flags (long header with packet type HANDSHAKE and |
| 13733 | // 4-byte packet number) |
| 13734 | 0xE3, |
| 13735 | // version |
| 13736 | QUIC_VERSION_BYTES, |
| 13737 | // destination connection ID length |
| 13738 | 0x08, |
| 13739 | // destination connection ID |
| 13740 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13741 | // source connection ID length |
| 13742 | 0x00, |
| 13743 | // long header packet length |
| 13744 | 0x05, |
| 13745 | // packet number |
| 13746 | 0x12, 0x34, 0x56, 0x00, |
| 13747 | // padding frame |
| 13748 | 0x00, |
| 13749 | }; |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 13750 | // clang-format on |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13751 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 13752 | size_t p_length = QUICHE_ARRAYSIZE(packet); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13753 | if (framer_.transport_version() >= QUIC_VERSION_49) { |
| 13754 | p = packet49; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 13755 | p_length = QUICHE_ARRAYSIZE(packet49); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13756 | } |
| 13757 | const bool parse_success = |
| 13758 | framer_.ProcessPacket(QuicEncryptedPacket(AsChars(p), p_length, false)); |
dschinazi | 97da52b | 2020-01-13 15:44:43 -0800 | [diff] [blame] | 13759 | if (!framer_.version().AllowsVariableLengthConnectionIds()) { |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 13760 | EXPECT_FALSE(parse_success); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13761 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 13762 | EXPECT_EQ("Invalid ConnectionId length.", framer_.detailed_error()); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 13763 | return; |
| 13764 | } |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 13765 | EXPECT_TRUE(parse_success); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13766 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 13767 | EXPECT_EQ("", framer_.detailed_error()); |
| 13768 | ASSERT_TRUE(visitor_.header_.get()); |
| 13769 | EXPECT_EQ(FramerTestConnectionId(), |
| 13770 | visitor_.header_.get()->destination_connection_id); |
| 13771 | } |
| 13772 | |
| 13773 | TEST_P(QuicFramerTest, ClientConnectionIdFromLongHeaderToServer) { |
| 13774 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 13775 | // This test requires an IETF long header. |
| 13776 | return; |
| 13777 | } |
| 13778 | SetDecrypterLevel(ENCRYPTION_HANDSHAKE); |
| 13779 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 13780 | // clang-format off |
| 13781 | unsigned char packet[] = { |
| 13782 | // public flags (long header with packet type HANDSHAKE and |
| 13783 | // 4-byte packet number) |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 13784 | 0xE3, |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 13785 | // version |
| 13786 | QUIC_VERSION_BYTES, |
| 13787 | // connection ID lengths |
| 13788 | 0x05, |
| 13789 | // source connection ID |
| 13790 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13791 | // long header packet length |
| 13792 | 0x05, |
| 13793 | // packet number |
| 13794 | 0x12, 0x34, 0x56, 0x00, |
| 13795 | // padding frame |
| 13796 | 0x00, |
| 13797 | }; |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13798 | unsigned char packet49[] = { |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13799 | // public flags (long header with packet type HANDSHAKE and |
| 13800 | // 4-byte packet number) |
| 13801 | 0xE3, |
| 13802 | // version |
| 13803 | QUIC_VERSION_BYTES, |
| 13804 | // connection ID lengths |
| 13805 | 0x00, 0x08, |
| 13806 | // source connection ID |
| 13807 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13808 | // long header packet length |
| 13809 | 0x05, |
| 13810 | // packet number |
| 13811 | 0x12, 0x34, 0x56, 0x00, |
| 13812 | // padding frame |
| 13813 | 0x00, |
| 13814 | }; |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 13815 | // clang-format on |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13816 | unsigned char* p = packet; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 13817 | size_t p_length = QUICHE_ARRAYSIZE(packet); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13818 | if (framer_.transport_version() >= QUIC_VERSION_49) { |
| 13819 | p = packet49; |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 13820 | p_length = QUICHE_ARRAYSIZE(packet49); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13821 | } |
| 13822 | const bool parse_success = |
| 13823 | framer_.ProcessPacket(QuicEncryptedPacket(AsChars(p), p_length, false)); |
dschinazi | 97da52b | 2020-01-13 15:44:43 -0800 | [diff] [blame] | 13824 | if (!framer_.version().AllowsVariableLengthConnectionIds()) { |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 13825 | EXPECT_FALSE(parse_success); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13826 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 13827 | EXPECT_EQ("Invalid ConnectionId length.", framer_.detailed_error()); |
| 13828 | return; |
| 13829 | } |
dschinazi | 5e1a7b2 | 2019-07-31 12:23:21 -0700 | [diff] [blame] | 13830 | if (!framer_.version().SupportsClientConnectionIds()) { |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 13831 | EXPECT_FALSE(parse_success); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13832 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 13833 | EXPECT_EQ("Client connection ID not supported in this version.", |
| 13834 | framer_.detailed_error()); |
| 13835 | return; |
| 13836 | } |
| 13837 | EXPECT_TRUE(parse_success); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13838 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 13839 | EXPECT_EQ("", framer_.detailed_error()); |
| 13840 | ASSERT_TRUE(visitor_.header_.get()); |
| 13841 | EXPECT_EQ(FramerTestConnectionId(), |
| 13842 | visitor_.header_.get()->source_connection_id); |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 13843 | } |
| 13844 | |
dschinazi | 334f023 | 2019-05-29 16:08:53 -0700 | [diff] [blame] | 13845 | TEST_P(QuicFramerTest, ProcessAndValidateIetfConnectionIdLengthClient) { |
| 13846 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 13847 | // This test requires an IETF long header. |
| 13848 | return; |
| 13849 | } |
| 13850 | char connection_id_lengths = 0x05; |
| 13851 | QuicDataReader reader(&connection_id_lengths, 1); |
| 13852 | |
| 13853 | bool should_update_expected_server_connection_id_length = false; |
| 13854 | uint8_t expected_server_connection_id_length = 8; |
| 13855 | uint8_t destination_connection_id_length = 0; |
| 13856 | uint8_t source_connection_id_length = 8; |
| 13857 | std::string detailed_error = ""; |
| 13858 | |
| 13859 | EXPECT_TRUE(QuicFramerPeer::ProcessAndValidateIetfConnectionIdLength( |
| 13860 | &reader, framer_.version(), Perspective::IS_CLIENT, |
| 13861 | should_update_expected_server_connection_id_length, |
| 13862 | &expected_server_connection_id_length, &destination_connection_id_length, |
| 13863 | &source_connection_id_length, &detailed_error)); |
| 13864 | EXPECT_EQ(8, expected_server_connection_id_length); |
| 13865 | EXPECT_EQ(0, destination_connection_id_length); |
| 13866 | EXPECT_EQ(8, source_connection_id_length); |
| 13867 | EXPECT_EQ("", detailed_error); |
| 13868 | |
| 13869 | QuicDataReader reader2(&connection_id_lengths, 1); |
| 13870 | should_update_expected_server_connection_id_length = true; |
| 13871 | expected_server_connection_id_length = 33; |
| 13872 | EXPECT_TRUE(QuicFramerPeer::ProcessAndValidateIetfConnectionIdLength( |
| 13873 | &reader2, framer_.version(), Perspective::IS_CLIENT, |
| 13874 | should_update_expected_server_connection_id_length, |
| 13875 | &expected_server_connection_id_length, &destination_connection_id_length, |
| 13876 | &source_connection_id_length, &detailed_error)); |
| 13877 | EXPECT_EQ(8, expected_server_connection_id_length); |
| 13878 | EXPECT_EQ(0, destination_connection_id_length); |
| 13879 | EXPECT_EQ(8, source_connection_id_length); |
| 13880 | EXPECT_EQ("", detailed_error); |
| 13881 | } |
| 13882 | |
| 13883 | TEST_P(QuicFramerTest, ProcessAndValidateIetfConnectionIdLengthServer) { |
| 13884 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 13885 | // This test requires an IETF long header. |
| 13886 | return; |
| 13887 | } |
| 13888 | char connection_id_lengths = 0x50; |
| 13889 | QuicDataReader reader(&connection_id_lengths, 1); |
| 13890 | |
| 13891 | bool should_update_expected_server_connection_id_length = false; |
| 13892 | uint8_t expected_server_connection_id_length = 8; |
| 13893 | uint8_t destination_connection_id_length = 8; |
| 13894 | uint8_t source_connection_id_length = 0; |
| 13895 | std::string detailed_error = ""; |
| 13896 | |
| 13897 | EXPECT_TRUE(QuicFramerPeer::ProcessAndValidateIetfConnectionIdLength( |
| 13898 | &reader, framer_.version(), Perspective::IS_SERVER, |
| 13899 | should_update_expected_server_connection_id_length, |
| 13900 | &expected_server_connection_id_length, &destination_connection_id_length, |
| 13901 | &source_connection_id_length, &detailed_error)); |
| 13902 | EXPECT_EQ(8, expected_server_connection_id_length); |
| 13903 | EXPECT_EQ(8, destination_connection_id_length); |
| 13904 | EXPECT_EQ(0, source_connection_id_length); |
| 13905 | EXPECT_EQ("", detailed_error); |
| 13906 | |
| 13907 | QuicDataReader reader2(&connection_id_lengths, 1); |
| 13908 | should_update_expected_server_connection_id_length = true; |
| 13909 | expected_server_connection_id_length = 33; |
| 13910 | EXPECT_TRUE(QuicFramerPeer::ProcessAndValidateIetfConnectionIdLength( |
| 13911 | &reader2, framer_.version(), Perspective::IS_SERVER, |
| 13912 | should_update_expected_server_connection_id_length, |
| 13913 | &expected_server_connection_id_length, &destination_connection_id_length, |
| 13914 | &source_connection_id_length, &detailed_error)); |
| 13915 | EXPECT_EQ(8, expected_server_connection_id_length); |
| 13916 | EXPECT_EQ(8, destination_connection_id_length); |
| 13917 | EXPECT_EQ(0, source_connection_id_length); |
| 13918 | EXPECT_EQ("", detailed_error); |
| 13919 | } |
| 13920 | |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 13921 | TEST_P(QuicFramerTest, TestExtendedErrorCodeParser) { |
| 13922 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 13923 | // Extended error codes only in IETF QUIC |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 13924 | return; |
| 13925 | } |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 13926 | QuicConnectionCloseFrame frame; |
| 13927 | |
| 13928 | frame.error_details = "this has no error code info in it"; |
| 13929 | MaybeExtractQuicErrorCode(&frame); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13930 | EXPECT_THAT(frame.extracted_error_code, |
| 13931 | IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 13932 | EXPECT_EQ("this has no error code info in it", frame.error_details); |
| 13933 | |
| 13934 | frame.error_details = "1234this does not have the colon in it"; |
| 13935 | MaybeExtractQuicErrorCode(&frame); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13936 | EXPECT_THAT(frame.extracted_error_code, |
| 13937 | IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 13938 | EXPECT_EQ("1234this does not have the colon in it", frame.error_details); |
| 13939 | |
| 13940 | frame.error_details = "1a234:this has a colon, but a malformed error number"; |
| 13941 | MaybeExtractQuicErrorCode(&frame); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13942 | EXPECT_THAT(frame.extracted_error_code, |
| 13943 | IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 13944 | EXPECT_EQ("1a234:this has a colon, but a malformed error number", |
| 13945 | frame.error_details); |
| 13946 | |
| 13947 | frame.error_details = "1234:this is good"; |
| 13948 | MaybeExtractQuicErrorCode(&frame); |
| 13949 | EXPECT_EQ(1234u, frame.extracted_error_code); |
| 13950 | EXPECT_EQ("this is good", frame.error_details); |
| 13951 | |
| 13952 | frame.error_details = |
| 13953 | "1234 :this is not good, space between last digit and colon"; |
| 13954 | MaybeExtractQuicErrorCode(&frame); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13955 | EXPECT_THAT(frame.extracted_error_code, |
| 13956 | IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 13957 | EXPECT_EQ("1234 :this is not good, space between last digit and colon", |
| 13958 | frame.error_details); |
| 13959 | |
| 13960 | frame.error_details = "123456789"; |
| 13961 | MaybeExtractQuicErrorCode(&frame); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13962 | EXPECT_THAT( |
| 13963 | frame.extracted_error_code, |
| 13964 | IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); // Not good, all numbers, no : |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 13965 | EXPECT_EQ("123456789", frame.error_details); |
| 13966 | |
| 13967 | frame.error_details = "1234:"; |
| 13968 | MaybeExtractQuicErrorCode(&frame); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 13969 | EXPECT_EQ(1234u, |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 13970 | frame.extracted_error_code); // corner case. |
| 13971 | EXPECT_EQ("", frame.error_details); |
| 13972 | |
| 13973 | frame.error_details = "1234:5678"; |
| 13974 | MaybeExtractQuicErrorCode(&frame); |
| 13975 | EXPECT_EQ(1234u, |
| 13976 | frame.extracted_error_code); // another corner case. |
| 13977 | EXPECT_EQ("5678", frame.error_details); |
| 13978 | |
| 13979 | frame.error_details = "12345 6789:"; |
| 13980 | MaybeExtractQuicErrorCode(&frame); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13981 | EXPECT_THAT(frame.extracted_error_code, |
| 13982 | IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); // Not good |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 13983 | EXPECT_EQ("12345 6789:", frame.error_details); |
| 13984 | |
| 13985 | frame.error_details = ":no numbers, is not good"; |
| 13986 | MaybeExtractQuicErrorCode(&frame); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13987 | EXPECT_THAT(frame.extracted_error_code, |
| 13988 | IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 13989 | EXPECT_EQ(":no numbers, is not good", frame.error_details); |
| 13990 | |
| 13991 | frame.error_details = "qwer:also no numbers, is not good"; |
| 13992 | MaybeExtractQuicErrorCode(&frame); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13993 | EXPECT_THAT(frame.extracted_error_code, |
| 13994 | IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 13995 | EXPECT_EQ("qwer:also no numbers, is not good", frame.error_details); |
| 13996 | |
| 13997 | frame.error_details = " 1234:this is not good, space before first digit"; |
| 13998 | MaybeExtractQuicErrorCode(&frame); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13999 | EXPECT_THAT(frame.extracted_error_code, |
| 14000 | IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 14001 | EXPECT_EQ(" 1234:this is not good, space before first digit", |
| 14002 | frame.error_details); |
| 14003 | |
| 14004 | frame.error_details = "1234:"; |
| 14005 | MaybeExtractQuicErrorCode(&frame); |
| 14006 | EXPECT_EQ(1234u, |
| 14007 | frame.extracted_error_code); // this is good |
| 14008 | EXPECT_EQ("", frame.error_details); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 14009 | } |
| 14010 | |
fayang | 3371b09 | 2019-12-04 07:08:52 -0800 | [diff] [blame] | 14011 | // Regression test for crbug/1029636. |
| 14012 | TEST_P(QuicFramerTest, OverlyLargeAckDelay) { |
| 14013 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 14014 | return; |
| 14015 | } |
| 14016 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 14017 | // clang-format off |
| 14018 | unsigned char packet99[] = { |
| 14019 | // type (short header, 4 byte packet number) |
| 14020 | 0x43, |
| 14021 | // connection_id |
| 14022 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 14023 | // packet number |
| 14024 | 0x12, 0x34, 0x56, 0x78, |
| 14025 | |
| 14026 | // frame type (IETF_ACK frame) |
| 14027 | 0x02, |
| 14028 | // largest acked |
| 14029 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78, |
| 14030 | // ack delay time. |
| 14031 | kVarInt62EightBytes + 0x31, 0x00, 0x00, 0x00, 0xF3, 0xA0, 0x81, 0xE0, |
| 14032 | // Nr. of additional ack blocks |
| 14033 | kVarInt62OneByte + 0x00, |
| 14034 | // first ack block length. |
| 14035 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x77, |
| 14036 | }; |
| 14037 | // clang-format on |
| 14038 | |
bnc | 4e9283d | 2019-12-17 07:08:57 -0800 | [diff] [blame] | 14039 | framer_.ProcessPacket(QuicEncryptedPacket(AsChars(packet99), |
| 14040 | QUICHE_ARRAYSIZE(packet99), false)); |
fayang | 3371b09 | 2019-12-04 07:08:52 -0800 | [diff] [blame] | 14041 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 14042 | // Verify ack_delay_time is set correctly. |
| 14043 | EXPECT_EQ(QuicTime::Delta::Infinite(), |
| 14044 | visitor_.ack_frames_[0]->ack_delay_time); |
| 14045 | } |
| 14046 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 14047 | } // namespace |
| 14048 | } // namespace test |
| 14049 | } // namespace quic |