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 | |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 15 | #include "absl/base/macros.h" |
vasilvv | 89fe24d | 2020-10-26 14:55:28 -0700 | [diff] [blame^] | 16 | #include "absl/strings/match.h" |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 17 | #include "absl/strings/string_view.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 18 | #include "net/third_party/quiche/src/quic/core/crypto/null_decrypter.h" |
| 19 | #include "net/third_party/quiche/src/quic/core/crypto/null_encrypter.h" |
| 20 | #include "net/third_party/quiche/src/quic/core/crypto/quic_decrypter.h" |
| 21 | #include "net/third_party/quiche/src/quic/core/crypto/quic_encrypter.h" |
| 22 | #include "net/third_party/quiche/src/quic/core/quic_connection_id.h" |
dschinazi | cf5b1e2 | 2019-07-17 18:35:17 -0700 | [diff] [blame] | 23 | #include "net/third_party/quiche/src/quic/core/quic_error_codes.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 24 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
| 25 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
| 26 | #include "net/third_party/quiche/src/quic/core/quic_utils.h" |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 27 | #include "net/third_party/quiche/src/quic/core/quic_versions.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 28 | #include "net/third_party/quiche/src/quic/platform/api/quic_expect_bug.h" |
| 29 | #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" |
| 30 | #include "net/third_party/quiche/src/quic/platform/api/quic_logging.h" |
| 31 | #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] | 32 | #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 33 | #include "net/third_party/quiche/src/quic/test_tools/quic_framer_peer.h" |
| 34 | #include "net/third_party/quiche/src/quic/test_tools/quic_test_utils.h" |
| 35 | #include "net/third_party/quiche/src/quic/test_tools/simple_data_producer.h" |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 36 | #include "net/third_party/quiche/src/common/platform/api/quiche_text_utils.h" |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 37 | #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] | 38 | |
| 39 | using testing::_; |
| 40 | using testing::Return; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 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 {} |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 96 | bool SetKey(absl::string_view /*key*/) override { return true; } |
| 97 | bool SetNoncePrefix(absl::string_view /*nonce_prefix*/) override { |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 98 | return true; |
| 99 | } |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 100 | bool SetIV(absl::string_view /*iv*/) override { return true; } |
| 101 | bool SetHeaderProtectionKey(absl::string_view /*key*/) override { |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 102 | return true; |
| 103 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 104 | bool EncryptPacket(uint64_t packet_number, |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 105 | absl::string_view associated_data, |
| 106 | absl::string_view 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( |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 118 | absl::string_view /*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 | } |
mattm | d074485 | 2020-10-16 14:42:01 -0700 | [diff] [blame] | 130 | QuicPacketCount GetConfidentialityLimit() const override { |
| 131 | return std::numeric_limits<QuicPacketCount>::max(); |
| 132 | } |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 133 | absl::string_view GetKey() const override { return absl::string_view(); } |
| 134 | absl::string_view GetNoncePrefix() const override { |
| 135 | return absl::string_view(); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 136 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 137 | |
| 138 | QuicPacketNumber packet_number_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 139 | std::string associated_data_; |
| 140 | std::string plaintext_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | class TestDecrypter : public QuicDecrypter { |
| 144 | public: |
| 145 | ~TestDecrypter() override {} |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 146 | bool SetKey(absl::string_view /*key*/) override { return true; } |
| 147 | bool SetNoncePrefix(absl::string_view /*nonce_prefix*/) override { |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 148 | return true; |
| 149 | } |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 150 | bool SetIV(absl::string_view /*iv*/) override { return true; } |
| 151 | bool SetHeaderProtectionKey(absl::string_view /*key*/) override { |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 152 | return true; |
| 153 | } |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 154 | bool SetPreliminaryKey(absl::string_view /*key*/) override { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 155 | QUIC_BUG << "should not be called"; |
| 156 | return false; |
| 157 | } |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 158 | bool SetDiversificationNonce(const DiversificationNonce& /*key*/) override { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 159 | return true; |
| 160 | } |
| 161 | bool DecryptPacket(uint64_t packet_number, |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 162 | absl::string_view associated_data, |
| 163 | absl::string_view ciphertext, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 164 | char* output, |
| 165 | size_t* output_length, |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 166 | size_t /*max_output_length*/) override { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 167 | packet_number_ = QuicPacketNumber(packet_number); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 168 | associated_data_ = std::string(associated_data); |
| 169 | ciphertext_ = std::string(ciphertext); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 170 | memcpy(output, ciphertext.data(), ciphertext.length()); |
| 171 | *output_length = ciphertext.length(); |
| 172 | return true; |
| 173 | } |
QUICHE team | 2d18797 | 2019-03-19 16:23:47 -0700 | [diff] [blame] | 174 | std::string GenerateHeaderProtectionMask( |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 175 | QuicDataReader* /*sample_reader*/) override { |
QUICHE team | 2d18797 | 2019-03-19 16:23:47 -0700 | [diff] [blame] | 176 | return std::string(5, 0); |
| 177 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 178 | size_t GetKeySize() const override { return 0; } |
nharper | 965e592 | 2019-09-23 22:33:54 -0700 | [diff] [blame] | 179 | size_t GetNoncePrefixSize() const override { return 0; } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 180 | size_t GetIVSize() const override { return 0; } |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 181 | absl::string_view GetKey() const override { return absl::string_view(); } |
| 182 | absl::string_view GetNoncePrefix() const override { |
| 183 | return absl::string_view(); |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 184 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 185 | // Use a distinct value starting with 0xFFFFFF, which is never used by TLS. |
| 186 | uint32_t cipher_id() const override { return 0xFFFFFFF2; } |
mattm | 8238ffb | 2020-10-19 12:42:27 -0700 | [diff] [blame] | 187 | QuicPacketCount GetIntegrityLimit() const override { |
| 188 | return std::numeric_limits<QuicPacketCount>::max(); |
| 189 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 190 | QuicPacketNumber packet_number_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 191 | std::string associated_data_; |
| 192 | std::string ciphertext_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 193 | }; |
| 194 | |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 195 | std::unique_ptr<QuicEncryptedPacket> EncryptPacketWithTagAndPhase( |
| 196 | const QuicPacket& packet, |
| 197 | uint8_t tag, |
| 198 | bool phase) { |
| 199 | std::string packet_data = std::string(packet.AsStringPiece()); |
| 200 | if (phase) { |
| 201 | packet_data[0] |= FLAGS_KEY_PHASE_BIT; |
| 202 | } else { |
| 203 | packet_data[0] &= ~FLAGS_KEY_PHASE_BIT; |
| 204 | } |
| 205 | |
| 206 | TaggingEncrypter crypter(tag); |
| 207 | const size_t packet_size = crypter.GetCiphertextSize(packet_data.size()); |
| 208 | char* buffer = new char[packet_size]; |
| 209 | size_t buf_len = 0; |
vasilvv | b16f796 | 2020-10-13 10:48:38 -0700 | [diff] [blame] | 210 | if (!crypter.EncryptPacket(0, absl::string_view(), packet_data, buffer, |
| 211 | &buf_len, packet_size)) { |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 212 | delete[] buffer; |
| 213 | return nullptr; |
| 214 | } |
| 215 | |
| 216 | return std::make_unique<QuicEncryptedPacket>(buffer, buf_len, |
| 217 | /*owns_buffer=*/true); |
| 218 | } |
| 219 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 220 | class TestQuicVisitor : public QuicFramerVisitorInterface { |
| 221 | public: |
| 222 | TestQuicVisitor() |
| 223 | : error_count_(0), |
| 224 | version_mismatch_(0), |
| 225 | packet_count_(0), |
| 226 | frame_count_(0), |
| 227 | complete_packets_(0), |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 228 | derive_next_key_count_(0), |
| 229 | decrypted_first_packet_in_key_phase_count_(0), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 230 | accept_packet_(true), |
| 231 | accept_public_header_(true) {} |
| 232 | |
| 233 | ~TestQuicVisitor() override {} |
| 234 | |
| 235 | void OnError(QuicFramer* f) override { |
| 236 | QUIC_DLOG(INFO) << "QuicFramer Error: " << QuicErrorCodeToString(f->error()) |
| 237 | << " (" << f->error() << ")"; |
| 238 | ++error_count_; |
| 239 | } |
| 240 | |
| 241 | void OnPacket() override {} |
| 242 | |
| 243 | void OnPublicResetPacket(const QuicPublicResetPacket& packet) override { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 244 | public_reset_packet_ = std::make_unique<QuicPublicResetPacket>((packet)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 245 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | void OnVersionNegotiationPacket( |
| 249 | const QuicVersionNegotiationPacket& packet) override { |
| 250 | version_negotiation_packet_ = |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 251 | std::make_unique<QuicVersionNegotiationPacket>((packet)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 252 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 253 | } |
| 254 | |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 255 | void OnRetryPacket(QuicConnectionId original_connection_id, |
| 256 | QuicConnectionId new_connection_id, |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 257 | absl::string_view retry_token, |
| 258 | absl::string_view retry_integrity_tag, |
| 259 | absl::string_view retry_without_tag) override { |
dschinazi | 2dd75ee | 2020-01-29 09:21:37 -0800 | [diff] [blame] | 260 | on_retry_packet_called_ = true; |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 261 | retry_original_connection_id_ = |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 262 | std::make_unique<QuicConnectionId>(original_connection_id); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 263 | retry_new_connection_id_ = |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 264 | std::make_unique<QuicConnectionId>(new_connection_id); |
| 265 | retry_token_ = std::make_unique<std::string>(std::string(retry_token)); |
dschinazi | 278efae | 2020-01-28 17:03:09 -0800 | [diff] [blame] | 266 | retry_token_integrity_tag_ = |
| 267 | std::make_unique<std::string>(std::string(retry_integrity_tag)); |
| 268 | retry_without_tag_ = |
| 269 | std::make_unique<std::string>(std::string(retry_without_tag)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 270 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 271 | } |
| 272 | |
fayang | 8aba1ff | 2019-06-21 12:00:54 -0700 | [diff] [blame] | 273 | bool OnProtocolVersionMismatch(ParsedQuicVersion received_version) override { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 274 | QUIC_DLOG(INFO) << "QuicFramer Version Mismatch, version: " |
| 275 | << received_version; |
| 276 | ++version_mismatch_; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 277 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 278 | return false; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | bool OnUnauthenticatedPublicHeader(const QuicPacketHeader& header) override { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 282 | header_ = std::make_unique<QuicPacketHeader>((header)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 283 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 284 | return accept_public_header_; |
| 285 | } |
| 286 | |
dschinazi | 17d4242 | 2019-06-18 16:35:07 -0700 | [diff] [blame] | 287 | bool OnUnauthenticatedHeader(const QuicPacketHeader& /*header*/) override { |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 288 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 289 | return true; |
| 290 | } |
| 291 | |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 292 | void OnDecryptedPacket(EncryptionLevel /*level*/) override { |
| 293 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 294 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 295 | |
| 296 | bool OnPacketHeader(const QuicPacketHeader& header) override { |
| 297 | ++packet_count_; |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 298 | header_ = std::make_unique<QuicPacketHeader>((header)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 299 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 300 | return accept_packet_; |
| 301 | } |
| 302 | |
| 303 | void OnCoalescedPacket(const QuicEncryptedPacket& packet) override { |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 304 | coalesced_packets_.push_back(packet.Clone()); |
| 305 | } |
| 306 | |
| 307 | void OnUndecryptablePacket(const QuicEncryptedPacket& packet, |
| 308 | EncryptionLevel decryption_level, |
| 309 | bool has_decryption_key) override { |
| 310 | undecryptable_packets_.push_back(packet.Clone()); |
| 311 | undecryptable_decryption_levels_.push_back(decryption_level); |
| 312 | undecryptable_has_decryption_keys_.push_back(has_decryption_key); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | bool OnStreamFrame(const QuicStreamFrame& frame) override { |
| 316 | ++frame_count_; |
| 317 | // 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] | 318 | std::string* string_data = |
| 319 | new std::string(frame.data_buffer, frame.data_length); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 320 | stream_data_.push_back(QuicWrapUnique(string_data)); |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 321 | stream_frames_.push_back(std::make_unique<QuicStreamFrame>( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 322 | frame.stream_id, frame.fin, frame.offset, *string_data)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 323 | if (VersionHasIetfQuicFrames(transport_version_)) { |
| 324 | // Low order bits of type encode flags, ignore them for this test. |
| 325 | EXPECT_TRUE(IS_IETF_STREAM_FRAME(framer_->current_received_frame_type())); |
| 326 | } else { |
| 327 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 328 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 329 | return true; |
| 330 | } |
| 331 | |
| 332 | bool OnCryptoFrame(const QuicCryptoFrame& frame) override { |
| 333 | ++frame_count_; |
| 334 | // 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] | 335 | std::string* string_data = |
| 336 | new std::string(frame.data_buffer, frame.data_length); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 337 | crypto_data_.push_back(QuicWrapUnique(string_data)); |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 338 | crypto_frames_.push_back(std::make_unique<QuicCryptoFrame>( |
renjietang | 15dfaa8 | 2020-01-03 16:13:38 -0800 | [diff] [blame] | 339 | frame.level, frame.offset, *string_data)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 340 | if (VersionHasIetfQuicFrames(transport_version_)) { |
| 341 | EXPECT_EQ(IETF_CRYPTO, framer_->current_received_frame_type()); |
| 342 | } else { |
| 343 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 344 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 345 | return true; |
| 346 | } |
| 347 | |
| 348 | bool OnAckFrameStart(QuicPacketNumber largest_acked, |
| 349 | QuicTime::Delta ack_delay_time) override { |
| 350 | ++frame_count_; |
| 351 | QuicAckFrame ack_frame; |
| 352 | ack_frame.largest_acked = largest_acked; |
| 353 | ack_frame.ack_delay_time = ack_delay_time; |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 354 | ack_frames_.push_back(std::make_unique<QuicAckFrame>(ack_frame)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 355 | if (VersionHasIetfQuicFrames(transport_version_)) { |
fayang | 91c23d7 | 2020-03-09 12:35:05 -0700 | [diff] [blame] | 356 | EXPECT_TRUE(IETF_ACK == framer_->current_received_frame_type() || |
| 357 | IETF_ACK_ECN == framer_->current_received_frame_type()); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 358 | } else { |
| 359 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 360 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 361 | return true; |
| 362 | } |
| 363 | |
| 364 | bool OnAckRange(QuicPacketNumber start, QuicPacketNumber end) override { |
| 365 | DCHECK(!ack_frames_.empty()); |
| 366 | ack_frames_[ack_frames_.size() - 1]->packets.AddRange(start, end); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 367 | if (VersionHasIetfQuicFrames(transport_version_)) { |
fayang | 91c23d7 | 2020-03-09 12:35:05 -0700 | [diff] [blame] | 368 | EXPECT_TRUE(IETF_ACK == framer_->current_received_frame_type() || |
| 369 | IETF_ACK_ECN == framer_->current_received_frame_type()); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 370 | } else { |
| 371 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 372 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 373 | return true; |
| 374 | } |
| 375 | |
| 376 | bool OnAckTimestamp(QuicPacketNumber packet_number, |
| 377 | QuicTime timestamp) override { |
| 378 | ack_frames_[ack_frames_.size() - 1]->received_packet_times.push_back( |
| 379 | std::make_pair(packet_number, timestamp)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 380 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 381 | return true; |
| 382 | } |
| 383 | |
| 384 | bool OnAckFrameEnd(QuicPacketNumber /*start*/) override { return true; } |
| 385 | |
| 386 | bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override { |
| 387 | ++frame_count_; |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 388 | stop_waiting_frames_.push_back( |
| 389 | std::make_unique<QuicStopWaitingFrame>(frame)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 390 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 391 | return true; |
| 392 | } |
| 393 | |
| 394 | bool OnPaddingFrame(const QuicPaddingFrame& frame) override { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 395 | padding_frames_.push_back(std::make_unique<QuicPaddingFrame>(frame)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 396 | if (VersionHasIetfQuicFrames(transport_version_)) { |
| 397 | EXPECT_EQ(IETF_PADDING, framer_->current_received_frame_type()); |
| 398 | } else { |
| 399 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 400 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 401 | return true; |
| 402 | } |
| 403 | |
| 404 | bool OnPingFrame(const QuicPingFrame& frame) override { |
| 405 | ++frame_count_; |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 406 | ping_frames_.push_back(std::make_unique<QuicPingFrame>(frame)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 407 | if (VersionHasIetfQuicFrames(transport_version_)) { |
| 408 | EXPECT_EQ(IETF_PING, framer_->current_received_frame_type()); |
| 409 | } else { |
| 410 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 411 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 412 | return true; |
| 413 | } |
| 414 | |
| 415 | bool OnMessageFrame(const QuicMessageFrame& frame) override { |
| 416 | ++frame_count_; |
| 417 | message_frames_.push_back( |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 418 | std::make_unique<QuicMessageFrame>(frame.data, frame.message_length)); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 419 | if (VersionHasIetfQuicFrames(transport_version_)) { |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 420 | EXPECT_TRUE(IETF_EXTENSION_MESSAGE_NO_LENGTH_V99 == |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 421 | framer_->current_received_frame_type() || |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 422 | IETF_EXTENSION_MESSAGE_V99 == |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 423 | framer_->current_received_frame_type()); |
| 424 | } else { |
| 425 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 426 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 427 | return true; |
| 428 | } |
| 429 | |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 430 | bool OnHandshakeDoneFrame(const QuicHandshakeDoneFrame& frame) override { |
| 431 | ++frame_count_; |
| 432 | handshake_done_frames_.push_back( |
| 433 | std::make_unique<QuicHandshakeDoneFrame>(frame)); |
| 434 | DCHECK(VersionHasIetfQuicFrames(transport_version_)); |
| 435 | EXPECT_EQ(IETF_HANDSHAKE_DONE, framer_->current_received_frame_type()); |
| 436 | return true; |
| 437 | } |
| 438 | |
haoyuewang | 6a6a0ff | 2020-06-23 16:32:26 -0700 | [diff] [blame] | 439 | bool OnAckFrequencyFrame(const QuicAckFrequencyFrame& frame) override { |
| 440 | ++frame_count_; |
| 441 | ack_frequency_frames_.emplace_back( |
| 442 | std::make_unique<QuicAckFrequencyFrame>(frame)); |
| 443 | DCHECK(VersionHasIetfQuicFrames(transport_version_)); |
| 444 | EXPECT_EQ(IETF_ACK_FREQUENCY, framer_->current_received_frame_type()); |
| 445 | return true; |
| 446 | } |
| 447 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 448 | void OnPacketComplete() override { ++complete_packets_; } |
| 449 | |
| 450 | bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override { |
| 451 | rst_stream_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 452 | if (VersionHasIetfQuicFrames(transport_version_)) { |
| 453 | EXPECT_EQ(IETF_RST_STREAM, framer_->current_received_frame_type()); |
| 454 | } else { |
| 455 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 456 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 457 | return true; |
| 458 | } |
| 459 | |
| 460 | bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override { |
| 461 | connection_close_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 462 | if (VersionHasIetfQuicFrames(transport_version_)) { |
| 463 | EXPECT_NE(GOOGLE_QUIC_CONNECTION_CLOSE, frame.close_type); |
| 464 | if (frame.close_type == IETF_QUIC_TRANSPORT_CONNECTION_CLOSE) { |
| 465 | EXPECT_EQ(IETF_CONNECTION_CLOSE, |
| 466 | framer_->current_received_frame_type()); |
| 467 | } else { |
| 468 | EXPECT_EQ(IETF_APPLICATION_CLOSE, |
| 469 | framer_->current_received_frame_type()); |
| 470 | } |
| 471 | } else { |
| 472 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 473 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 474 | return true; |
| 475 | } |
| 476 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 477 | bool OnStopSendingFrame(const QuicStopSendingFrame& frame) override { |
| 478 | stop_sending_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 479 | EXPECT_EQ(IETF_STOP_SENDING, framer_->current_received_frame_type()); |
| 480 | EXPECT_TRUE(VersionHasIetfQuicFrames(transport_version_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 481 | return true; |
| 482 | } |
| 483 | |
| 484 | bool OnPathChallengeFrame(const QuicPathChallengeFrame& frame) override { |
| 485 | path_challenge_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 486 | EXPECT_EQ(IETF_PATH_CHALLENGE, framer_->current_received_frame_type()); |
| 487 | EXPECT_TRUE(VersionHasIetfQuicFrames(transport_version_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 488 | return true; |
| 489 | } |
| 490 | |
| 491 | bool OnPathResponseFrame(const QuicPathResponseFrame& frame) override { |
| 492 | path_response_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 493 | EXPECT_EQ(IETF_PATH_RESPONSE, framer_->current_received_frame_type()); |
| 494 | EXPECT_TRUE(VersionHasIetfQuicFrames(transport_version_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 495 | return true; |
| 496 | } |
| 497 | |
| 498 | bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override { |
| 499 | goaway_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 500 | EXPECT_FALSE(VersionHasIetfQuicFrames(transport_version_)); |
| 501 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 502 | return true; |
| 503 | } |
| 504 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 505 | bool OnMaxStreamsFrame(const QuicMaxStreamsFrame& frame) override { |
| 506 | max_streams_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 507 | EXPECT_TRUE(VersionHasIetfQuicFrames(transport_version_)); |
| 508 | EXPECT_TRUE(IETF_MAX_STREAMS_UNIDIRECTIONAL == |
| 509 | framer_->current_received_frame_type() || |
| 510 | IETF_MAX_STREAMS_BIDIRECTIONAL == |
| 511 | framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 512 | return true; |
| 513 | } |
| 514 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 515 | bool OnStreamsBlockedFrame(const QuicStreamsBlockedFrame& frame) override { |
| 516 | streams_blocked_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 517 | EXPECT_TRUE(VersionHasIetfQuicFrames(transport_version_)); |
| 518 | EXPECT_TRUE(IETF_STREAMS_BLOCKED_UNIDIRECTIONAL == |
| 519 | framer_->current_received_frame_type() || |
| 520 | IETF_STREAMS_BLOCKED_BIDIRECTIONAL == |
| 521 | framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 522 | return true; |
| 523 | } |
| 524 | |
| 525 | bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override { |
| 526 | window_update_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 527 | if (VersionHasIetfQuicFrames(transport_version_)) { |
| 528 | EXPECT_TRUE(IETF_MAX_DATA == framer_->current_received_frame_type() || |
| 529 | IETF_MAX_STREAM_DATA == |
| 530 | framer_->current_received_frame_type()); |
| 531 | } else { |
| 532 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 533 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 534 | return true; |
| 535 | } |
| 536 | |
| 537 | bool OnBlockedFrame(const QuicBlockedFrame& frame) override { |
| 538 | blocked_frame_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 539 | if (VersionHasIetfQuicFrames(transport_version_)) { |
ianswett | 2f07744 | 2019-12-12 11:51:24 -0800 | [diff] [blame] | 540 | EXPECT_TRUE(IETF_DATA_BLOCKED == framer_->current_received_frame_type() || |
| 541 | IETF_STREAM_DATA_BLOCKED == |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 542 | framer_->current_received_frame_type()); |
| 543 | } else { |
| 544 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 545 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 546 | return true; |
| 547 | } |
| 548 | |
| 549 | bool OnNewConnectionIdFrame(const QuicNewConnectionIdFrame& frame) override { |
| 550 | new_connection_id_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 551 | EXPECT_EQ(IETF_NEW_CONNECTION_ID, framer_->current_received_frame_type()); |
| 552 | EXPECT_TRUE(VersionHasIetfQuicFrames(transport_version_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 553 | return true; |
| 554 | } |
| 555 | |
| 556 | bool OnRetireConnectionIdFrame( |
| 557 | const QuicRetireConnectionIdFrame& frame) override { |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 558 | EXPECT_EQ(IETF_RETIRE_CONNECTION_ID, |
| 559 | framer_->current_received_frame_type()); |
| 560 | EXPECT_TRUE(VersionHasIetfQuicFrames(transport_version_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 561 | retire_connection_id_ = frame; |
| 562 | return true; |
| 563 | } |
| 564 | |
| 565 | bool OnNewTokenFrame(const QuicNewTokenFrame& frame) override { |
| 566 | new_token_ = frame; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 567 | EXPECT_EQ(IETF_NEW_TOKEN, framer_->current_received_frame_type()); |
| 568 | EXPECT_TRUE(VersionHasIetfQuicFrames(transport_version_)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 569 | return true; |
| 570 | } |
| 571 | |
| 572 | bool IsValidStatelessResetToken(QuicUint128 token) const override { |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 573 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 574 | return token == kTestStatelessResetToken; |
| 575 | } |
| 576 | |
| 577 | void OnAuthenticatedIetfStatelessResetPacket( |
| 578 | const QuicIetfStatelessResetPacket& packet) override { |
| 579 | stateless_reset_packet_ = |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 580 | std::make_unique<QuicIetfStatelessResetPacket>(packet); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 581 | EXPECT_EQ(0u, framer_->current_received_frame_type()); |
| 582 | } |
| 583 | |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 584 | void OnKeyUpdate(KeyUpdateReason reason) override { |
| 585 | key_update_reasons_.push_back(reason); |
| 586 | } |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 587 | |
| 588 | void OnDecryptedFirstPacketInKeyPhase() override { |
| 589 | decrypted_first_packet_in_key_phase_count_++; |
| 590 | } |
| 591 | |
| 592 | std::unique_ptr<QuicDecrypter> AdvanceKeysAndCreateCurrentOneRttDecrypter() |
| 593 | override { |
| 594 | derive_next_key_count_++; |
| 595 | return std::make_unique<StrictTaggingDecrypter>(derive_next_key_count_); |
| 596 | } |
| 597 | std::unique_ptr<QuicEncrypter> CreateCurrentOneRttEncrypter() override { |
| 598 | return std::make_unique<TaggingEncrypter>(derive_next_key_count_); |
| 599 | } |
| 600 | |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 601 | void set_framer(QuicFramer* framer) { |
| 602 | framer_ = framer; |
| 603 | transport_version_ = framer->transport_version(); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 604 | } |
| 605 | |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 606 | size_t key_update_count() const { return key_update_reasons_.size(); } |
| 607 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 608 | // Counters from the visitor_ callbacks. |
| 609 | int error_count_; |
| 610 | int version_mismatch_; |
| 611 | int packet_count_; |
| 612 | int frame_count_; |
| 613 | int complete_packets_; |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 614 | std::vector<KeyUpdateReason> key_update_reasons_; |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 615 | int derive_next_key_count_; |
| 616 | int decrypted_first_packet_in_key_phase_count_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 617 | bool accept_packet_; |
| 618 | bool accept_public_header_; |
| 619 | |
| 620 | std::unique_ptr<QuicPacketHeader> header_; |
| 621 | std::unique_ptr<QuicPublicResetPacket> public_reset_packet_; |
| 622 | std::unique_ptr<QuicIetfStatelessResetPacket> stateless_reset_packet_; |
| 623 | std::unique_ptr<QuicVersionNegotiationPacket> version_negotiation_packet_; |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 624 | std::unique_ptr<QuicConnectionId> retry_original_connection_id_; |
| 625 | std::unique_ptr<QuicConnectionId> retry_new_connection_id_; |
| 626 | std::unique_ptr<std::string> retry_token_; |
dschinazi | 278efae | 2020-01-28 17:03:09 -0800 | [diff] [blame] | 627 | std::unique_ptr<std::string> retry_token_integrity_tag_; |
| 628 | std::unique_ptr<std::string> retry_without_tag_; |
dschinazi | 2dd75ee | 2020-01-29 09:21:37 -0800 | [diff] [blame] | 629 | bool on_retry_packet_called_ = false; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 630 | std::vector<std::unique_ptr<QuicStreamFrame>> stream_frames_; |
| 631 | std::vector<std::unique_ptr<QuicCryptoFrame>> crypto_frames_; |
| 632 | std::vector<std::unique_ptr<QuicAckFrame>> ack_frames_; |
| 633 | std::vector<std::unique_ptr<QuicStopWaitingFrame>> stop_waiting_frames_; |
| 634 | std::vector<std::unique_ptr<QuicPaddingFrame>> padding_frames_; |
| 635 | std::vector<std::unique_ptr<QuicPingFrame>> ping_frames_; |
| 636 | std::vector<std::unique_ptr<QuicMessageFrame>> message_frames_; |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 637 | std::vector<std::unique_ptr<QuicHandshakeDoneFrame>> handshake_done_frames_; |
haoyuewang | 6a6a0ff | 2020-06-23 16:32:26 -0700 | [diff] [blame] | 638 | std::vector<std::unique_ptr<QuicAckFrequencyFrame>> ack_frequency_frames_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 639 | std::vector<std::unique_ptr<QuicEncryptedPacket>> coalesced_packets_; |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 640 | std::vector<std::unique_ptr<QuicEncryptedPacket>> undecryptable_packets_; |
| 641 | std::vector<EncryptionLevel> undecryptable_decryption_levels_; |
| 642 | std::vector<bool> undecryptable_has_decryption_keys_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 643 | QuicRstStreamFrame rst_stream_frame_; |
| 644 | QuicConnectionCloseFrame connection_close_frame_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 645 | QuicStopSendingFrame stop_sending_frame_; |
| 646 | QuicGoAwayFrame goaway_frame_; |
| 647 | QuicPathChallengeFrame path_challenge_frame_; |
| 648 | QuicPathResponseFrame path_response_frame_; |
| 649 | QuicWindowUpdateFrame window_update_frame_; |
| 650 | QuicBlockedFrame blocked_frame_; |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 651 | QuicStreamsBlockedFrame streams_blocked_frame_; |
| 652 | QuicMaxStreamsFrame max_streams_frame_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 653 | QuicNewConnectionIdFrame new_connection_id_; |
| 654 | QuicRetireConnectionIdFrame retire_connection_id_; |
| 655 | QuicNewTokenFrame new_token_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 656 | std::vector<std::unique_ptr<std::string>> stream_data_; |
| 657 | std::vector<std::unique_ptr<std::string>> crypto_data_; |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 658 | QuicTransportVersion transport_version_; |
| 659 | QuicFramer* framer_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 660 | }; |
| 661 | |
| 662 | // Simple struct for defining a packet's content, and associated |
| 663 | // parse error. |
| 664 | struct PacketFragment { |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 665 | std::string error_if_missing; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 666 | std::vector<unsigned char> fragment; |
| 667 | }; |
| 668 | |
| 669 | using PacketFragments = std::vector<struct PacketFragment>; |
| 670 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 671 | class QuicFramerTest : public QuicTestWithParam<ParsedQuicVersion> { |
| 672 | public: |
| 673 | QuicFramerTest() |
| 674 | : encrypter_(new test::TestEncrypter()), |
| 675 | decrypter_(new test::TestDecrypter()), |
| 676 | version_(GetParam()), |
| 677 | start_(QuicTime::Zero() + QuicTime::Delta::FromMicroseconds(0x10)), |
nharper | f5e6845 | 2019-05-29 17:24:18 -0700 | [diff] [blame] | 678 | framer_(AllSupportedVersions(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 679 | start_, |
| 680 | Perspective::IS_SERVER, |
| 681 | kQuicDefaultConnectionIdLength) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 682 | framer_.set_version(version_); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 683 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 684 | framer_.InstallDecrypter(ENCRYPTION_INITIAL, |
| 685 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 686 | } else { |
| 687 | framer_.SetDecrypter(ENCRYPTION_INITIAL, |
| 688 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 689 | } |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 690 | framer_.SetEncrypter(ENCRYPTION_INITIAL, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 691 | std::unique_ptr<QuicEncrypter>(encrypter_)); |
| 692 | |
| 693 | framer_.set_visitor(&visitor_); |
| 694 | framer_.InferPacketHeaderTypeFromVersion(); |
fkastenholz | a366010 | 2019-08-28 05:19:24 -0700 | [diff] [blame] | 695 | visitor_.set_framer(&framer_); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 696 | } |
| 697 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 698 | void SetDecrypterLevel(EncryptionLevel level) { |
| 699 | if (!framer_.version().KnowsWhichDecrypterToUse()) { |
| 700 | return; |
| 701 | } |
| 702 | decrypter_ = new TestDecrypter(); |
| 703 | framer_.InstallDecrypter(level, std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 704 | } |
| 705 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 706 | // Helper function to get unsigned char representation of the handshake |
rch | a702be2 | 2019-08-30 15:20:12 -0700 | [diff] [blame] | 707 | // protocol byte at position |pos| of the current QUIC version number. |
| 708 | unsigned char GetQuicVersionByte(int pos) { |
| 709 | return (CreateQuicVersionLabel(version_) >> 8 * (3 - pos)) & 0xff; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | bool CheckEncryption(QuicPacketNumber packet_number, QuicPacket* packet) { |
| 713 | if (packet_number != encrypter_->packet_number_) { |
| 714 | QUIC_LOG(ERROR) << "Encrypted incorrect packet number. expected " |
| 715 | << packet_number |
| 716 | << " actual: " << encrypter_->packet_number_; |
| 717 | return false; |
| 718 | } |
| 719 | if (packet->AssociatedData(framer_.transport_version()) != |
| 720 | encrypter_->associated_data_) { |
| 721 | QUIC_LOG(ERROR) << "Encrypted incorrect associated data. expected " |
| 722 | << packet->AssociatedData(framer_.transport_version()) |
| 723 | << " actual: " << encrypter_->associated_data_; |
| 724 | return false; |
| 725 | } |
| 726 | if (packet->Plaintext(framer_.transport_version()) != |
| 727 | encrypter_->plaintext_) { |
| 728 | QUIC_LOG(ERROR) << "Encrypted incorrect plaintext data. expected " |
| 729 | << packet->Plaintext(framer_.transport_version()) |
| 730 | << " actual: " << encrypter_->plaintext_; |
| 731 | return false; |
| 732 | } |
| 733 | return true; |
| 734 | } |
| 735 | |
| 736 | bool CheckDecryption(const QuicEncryptedPacket& encrypted, |
| 737 | bool includes_version, |
| 738 | bool includes_diversification_nonce, |
| 739 | QuicConnectionIdLength destination_connection_id_length, |
| 740 | QuicConnectionIdLength source_connection_id_length) { |
| 741 | return CheckDecryption( |
| 742 | encrypted, includes_version, includes_diversification_nonce, |
| 743 | destination_connection_id_length, source_connection_id_length, |
| 744 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
| 745 | } |
| 746 | |
| 747 | bool CheckDecryption( |
| 748 | const QuicEncryptedPacket& encrypted, |
| 749 | bool includes_version, |
| 750 | bool includes_diversification_nonce, |
| 751 | QuicConnectionIdLength destination_connection_id_length, |
| 752 | QuicConnectionIdLength source_connection_id_length, |
| 753 | QuicVariableLengthIntegerLength retry_token_length_length, |
| 754 | size_t retry_token_length, |
| 755 | QuicVariableLengthIntegerLength length_length) { |
| 756 | if (visitor_.header_->packet_number != decrypter_->packet_number_) { |
| 757 | QUIC_LOG(ERROR) << "Decrypted incorrect packet number. expected " |
| 758 | << visitor_.header_->packet_number |
| 759 | << " actual: " << decrypter_->packet_number_; |
| 760 | return false; |
| 761 | } |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 762 | absl::string_view associated_data = |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 763 | QuicFramer::GetAssociatedDataFromEncryptedPacket( |
| 764 | framer_.transport_version(), encrypted, |
| 765 | destination_connection_id_length, source_connection_id_length, |
| 766 | includes_version, includes_diversification_nonce, |
| 767 | PACKET_4BYTE_PACKET_NUMBER, retry_token_length_length, |
| 768 | retry_token_length, length_length); |
| 769 | if (associated_data != decrypter_->associated_data_) { |
| 770 | QUIC_LOG(ERROR) << "Decrypted incorrect associated data. expected " |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 771 | << quiche::QuicheTextUtils::HexEncode(associated_data) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 772 | << " actual: " |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 773 | << quiche::QuicheTextUtils::HexEncode( |
| 774 | decrypter_->associated_data_); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 775 | return false; |
| 776 | } |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 777 | absl::string_view ciphertext( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 778 | encrypted.AsStringPiece().substr(GetStartOfEncryptedData( |
| 779 | framer_.transport_version(), destination_connection_id_length, |
| 780 | source_connection_id_length, includes_version, |
| 781 | includes_diversification_nonce, PACKET_4BYTE_PACKET_NUMBER, |
| 782 | retry_token_length_length, retry_token_length, length_length))); |
| 783 | if (ciphertext != decrypter_->ciphertext_) { |
| 784 | QUIC_LOG(ERROR) << "Decrypted incorrect ciphertext data. expected " |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 785 | << quiche::QuicheTextUtils::HexEncode(ciphertext) |
| 786 | << " actual: " |
| 787 | << quiche::QuicheTextUtils::HexEncode( |
| 788 | decrypter_->ciphertext_) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 789 | << " associated data: " |
dmcardle | cf0bfcf | 2019-12-13 08:08:21 -0800 | [diff] [blame] | 790 | << quiche::QuicheTextUtils::HexEncode(associated_data); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 791 | return false; |
| 792 | } |
| 793 | return true; |
| 794 | } |
| 795 | |
| 796 | char* AsChars(unsigned char* data) { return reinterpret_cast<char*>(data); } |
| 797 | |
| 798 | // Creates a new QuicEncryptedPacket by concatenating the various |
| 799 | // packet fragments in |fragments|. |
| 800 | std::unique_ptr<QuicEncryptedPacket> AssemblePacketFromFragments( |
| 801 | const PacketFragments& fragments) { |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 802 | char* buffer = new char[kMaxOutgoingPacketSize + 1]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 803 | size_t len = 0; |
| 804 | for (const auto& fragment : fragments) { |
| 805 | memcpy(buffer + len, fragment.fragment.data(), fragment.fragment.size()); |
| 806 | len += fragment.fragment.size(); |
| 807 | } |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 808 | return std::make_unique<QuicEncryptedPacket>(buffer, len, true); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | void CheckFramingBoundaries(const PacketFragments& fragments, |
| 812 | QuicErrorCode error_code) { |
| 813 | std::unique_ptr<QuicEncryptedPacket> packet( |
| 814 | AssemblePacketFromFragments(fragments)); |
| 815 | // Check all the various prefixes of |packet| for the expected |
| 816 | // parse error and error code. |
| 817 | for (size_t i = 0; i < packet->length(); ++i) { |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 818 | std::string expected_error; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 819 | size_t len = 0; |
| 820 | for (const auto& fragment : fragments) { |
| 821 | len += fragment.fragment.size(); |
| 822 | if (i < len) { |
| 823 | expected_error = fragment.error_if_missing; |
| 824 | break; |
| 825 | } |
| 826 | } |
| 827 | |
| 828 | if (expected_error.empty()) |
| 829 | continue; |
| 830 | |
| 831 | CheckProcessingFails(*packet, i, expected_error, error_code); |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | void CheckProcessingFails(const QuicEncryptedPacket& packet, |
| 836 | size_t len, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 837 | std::string expected_error, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 838 | QuicErrorCode error_code) { |
| 839 | QuicEncryptedPacket encrypted(packet.data(), len, false); |
| 840 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)) << "len: " << len; |
| 841 | EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len; |
| 842 | EXPECT_EQ(error_code, framer_.error()) << "len: " << len; |
| 843 | } |
| 844 | |
| 845 | void CheckProcessingFails(unsigned char* packet, |
| 846 | size_t len, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 847 | std::string expected_error, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 848 | QuicErrorCode error_code) { |
| 849 | QuicEncryptedPacket encrypted(AsChars(packet), len, false); |
| 850 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)) << "len: " << len; |
| 851 | EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len; |
| 852 | EXPECT_EQ(error_code, framer_.error()) << "len: " << len; |
| 853 | } |
| 854 | |
| 855 | // Checks if the supplied string matches data in the supplied StreamFrame. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 856 | void CheckStreamFrameData(std::string str, QuicStreamFrame* frame) { |
| 857 | EXPECT_EQ(str, std::string(frame->data_buffer, frame->data_length)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | void CheckCalculatePacketNumber(uint64_t expected_packet_number, |
| 861 | QuicPacketNumber last_packet_number) { |
| 862 | uint64_t wire_packet_number = expected_packet_number & kMask; |
| 863 | EXPECT_EQ(expected_packet_number, |
| 864 | QuicFramerPeer::CalculatePacketNumberFromWire( |
| 865 | &framer_, PACKET_4BYTE_PACKET_NUMBER, last_packet_number, |
| 866 | wire_packet_number)) |
| 867 | << "last_packet_number: " << last_packet_number |
| 868 | << " wire_packet_number: " << wire_packet_number; |
| 869 | } |
| 870 | |
| 871 | std::unique_ptr<QuicPacket> BuildDataPacket(const QuicPacketHeader& header, |
| 872 | const QuicFrames& frames) { |
| 873 | return BuildUnsizedDataPacket(&framer_, header, frames); |
| 874 | } |
| 875 | |
| 876 | std::unique_ptr<QuicPacket> BuildDataPacket(const QuicPacketHeader& header, |
| 877 | const QuicFrames& frames, |
| 878 | size_t packet_size) { |
| 879 | return BuildUnsizedDataPacket(&framer_, header, frames, packet_size); |
| 880 | } |
| 881 | |
| 882 | // N starts at 1. |
| 883 | QuicStreamId GetNthStreamid(QuicTransportVersion transport_version, |
| 884 | Perspective perspective, |
| 885 | bool bidirectional, |
| 886 | int n) { |
| 887 | if (bidirectional) { |
| 888 | return QuicUtils::GetFirstBidirectionalStreamId(transport_version, |
| 889 | perspective) + |
| 890 | ((n - 1) * QuicUtils::StreamIdDelta(transport_version)); |
| 891 | } |
| 892 | // Unidirectional |
| 893 | return QuicUtils::GetFirstUnidirectionalStreamId(transport_version, |
| 894 | perspective) + |
| 895 | ((n - 1) * QuicUtils::StreamIdDelta(transport_version)); |
| 896 | } |
| 897 | |
| 898 | test::TestEncrypter* encrypter_; |
| 899 | test::TestDecrypter* decrypter_; |
| 900 | ParsedQuicVersion version_; |
| 901 | QuicTime start_; |
| 902 | QuicFramer framer_; |
| 903 | test::TestQuicVisitor visitor_; |
| 904 | SimpleBufferAllocator allocator_; |
| 905 | }; |
| 906 | |
| 907 | // Multiple test cases of QuicFramerTest use byte arrays to define packets for |
| 908 | // testing, and these byte arrays contain the QUIC version. This macro explodes |
| 909 | // the 32-bit version into four bytes in network order. Since it uses methods of |
| 910 | // QuicFramerTest, it is only valid to use this in a QuicFramerTest. |
rch | a702be2 | 2019-08-30 15:20:12 -0700 | [diff] [blame] | 911 | #define QUIC_VERSION_BYTES \ |
| 912 | GetQuicVersionByte(0), GetQuicVersionByte(1), GetQuicVersionByte(2), \ |
| 913 | GetQuicVersionByte(3) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 914 | |
| 915 | // Run all framer tests with all supported versions of QUIC. |
nharper | f5e6845 | 2019-05-29 17:24:18 -0700 | [diff] [blame] | 916 | INSTANTIATE_TEST_SUITE_P(QuicFramerTests, |
| 917 | QuicFramerTest, |
dschinazi | 98fc8d0 | 2019-09-17 23:34:49 -0700 | [diff] [blame] | 918 | ::testing::ValuesIn(AllSupportedVersions()), |
| 919 | ::testing::PrintToStringParamName()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 920 | |
| 921 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochStart) { |
| 922 | // A few quick manual sanity checks. |
| 923 | CheckCalculatePacketNumber(UINT64_C(1), QuicPacketNumber()); |
| 924 | CheckCalculatePacketNumber(kEpoch + 1, QuicPacketNumber(kMask)); |
| 925 | CheckCalculatePacketNumber(kEpoch, QuicPacketNumber(kMask)); |
| 926 | for (uint64_t j = 0; j < 10; j++) { |
| 927 | CheckCalculatePacketNumber(j, QuicPacketNumber()); |
| 928 | CheckCalculatePacketNumber(kEpoch - 1 - j, QuicPacketNumber()); |
| 929 | } |
| 930 | |
| 931 | // Cases where the last number was close to the start of the range. |
| 932 | for (QuicPacketNumber last = QuicPacketNumber(1); last < QuicPacketNumber(10); |
| 933 | last++) { |
| 934 | // Small numbers should not wrap (even if they're out of order). |
| 935 | for (uint64_t j = 0; j < 10; j++) { |
| 936 | CheckCalculatePacketNumber(j, last); |
| 937 | } |
| 938 | |
| 939 | // Large numbers should not wrap either (because we're near 0 already). |
| 940 | for (uint64_t j = 0; j < 10; j++) { |
| 941 | CheckCalculatePacketNumber(kEpoch - 1 - j, last); |
| 942 | } |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochEnd) { |
| 947 | // Cases where the last number was close to the end of the range |
| 948 | for (uint64_t i = 0; i < 10; i++) { |
| 949 | QuicPacketNumber last = QuicPacketNumber(kEpoch - i); |
| 950 | |
| 951 | // Small numbers should wrap. |
| 952 | for (uint64_t j = 0; j < 10; j++) { |
| 953 | CheckCalculatePacketNumber(kEpoch + j, last); |
| 954 | } |
| 955 | |
| 956 | // Large numbers should not (even if they're out of order). |
| 957 | for (uint64_t j = 0; j < 10; j++) { |
| 958 | CheckCalculatePacketNumber(kEpoch - 1 - j, last); |
| 959 | } |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | // Next check where we're in a non-zero epoch to verify we handle |
| 964 | // reverse wrapping, too. |
| 965 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearPrevEpoch) { |
| 966 | const uint64_t prev_epoch = 1 * kEpoch; |
| 967 | const uint64_t cur_epoch = 2 * kEpoch; |
| 968 | // Cases where the last number was close to the start of the range |
| 969 | for (uint64_t i = 0; i < 10; i++) { |
| 970 | QuicPacketNumber last = QuicPacketNumber(cur_epoch + i); |
| 971 | // Small number should not wrap (even if they're out of order). |
| 972 | for (uint64_t j = 0; j < 10; j++) { |
| 973 | CheckCalculatePacketNumber(cur_epoch + j, last); |
| 974 | } |
| 975 | |
| 976 | // But large numbers should reverse wrap. |
| 977 | for (uint64_t j = 0; j < 10; j++) { |
| 978 | uint64_t num = kEpoch - 1 - j; |
| 979 | CheckCalculatePacketNumber(prev_epoch + num, last); |
| 980 | } |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearNextEpoch) { |
| 985 | const uint64_t cur_epoch = 2 * kEpoch; |
| 986 | const uint64_t next_epoch = 3 * kEpoch; |
| 987 | // Cases where the last number was close to the end of the range |
| 988 | for (uint64_t i = 0; i < 10; i++) { |
| 989 | QuicPacketNumber last = QuicPacketNumber(next_epoch - 1 - i); |
| 990 | |
| 991 | // Small numbers should wrap. |
| 992 | for (uint64_t j = 0; j < 10; j++) { |
| 993 | CheckCalculatePacketNumber(next_epoch + j, last); |
| 994 | } |
| 995 | |
| 996 | // but large numbers should not (even if they're out of order). |
| 997 | for (uint64_t j = 0; j < 10; j++) { |
| 998 | uint64_t num = kEpoch - 1 - j; |
| 999 | CheckCalculatePacketNumber(cur_epoch + num, last); |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearNextMax) { |
| 1005 | const uint64_t max_number = std::numeric_limits<uint64_t>::max(); |
| 1006 | const uint64_t max_epoch = max_number & ~kMask; |
| 1007 | |
| 1008 | // Cases where the last number was close to the end of the range |
| 1009 | for (uint64_t i = 0; i < 10; i++) { |
| 1010 | // Subtract 1, because the expected next packet number is 1 more than the |
| 1011 | // last packet number. |
| 1012 | QuicPacketNumber last = QuicPacketNumber(max_number - i - 1); |
| 1013 | |
| 1014 | // Small numbers should not wrap, because they have nowhere to go. |
| 1015 | for (uint64_t j = 0; j < 10; j++) { |
| 1016 | CheckCalculatePacketNumber(max_epoch + j, last); |
| 1017 | } |
| 1018 | |
| 1019 | // Large numbers should not wrap either. |
| 1020 | for (uint64_t j = 0; j < 10; j++) { |
| 1021 | uint64_t num = kEpoch - 1 - j; |
| 1022 | CheckCalculatePacketNumber(max_epoch + num, last); |
| 1023 | } |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | TEST_P(QuicFramerTest, EmptyPacket) { |
| 1028 | char packet[] = {0x00}; |
| 1029 | QuicEncryptedPacket encrypted(packet, 0, false); |
| 1030 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1031 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | TEST_P(QuicFramerTest, LargePacket) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1035 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1036 | // clang-format off |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 1037 | unsigned char packet[kMaxIncomingPacketSize + 1] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1038 | // public flags (8 byte connection_id) |
| 1039 | 0x28, |
| 1040 | // connection_id |
| 1041 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1042 | // packet number |
| 1043 | 0x78, 0x56, 0x34, 0x12, |
| 1044 | // private flags |
| 1045 | 0x00, |
| 1046 | }; |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 1047 | unsigned char packet46[kMaxIncomingPacketSize + 1] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1048 | // type (short header 4 byte packet number) |
| 1049 | 0x43, |
| 1050 | // connection_id |
| 1051 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1052 | // packet number |
| 1053 | 0x78, 0x56, 0x34, 0x12, |
| 1054 | }; |
| 1055 | // clang-format on |
| 1056 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 1057 | size_t p_size = ABSL_ARRAYSIZE(packet); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 1058 | if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1059 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 1060 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | const size_t header_size = GetPacketHeaderSize( |
| 1064 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 1065 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 1066 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 1067 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
| 1068 | |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 1069 | memset(p + header_size, 0, kMaxIncomingPacketSize - header_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1070 | |
| 1071 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 1072 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1073 | |
| 1074 | ASSERT_TRUE(visitor_.header_.get()); |
| 1075 | // Make sure we've parsed the packet header, so we can send an error. |
| 1076 | EXPECT_EQ(FramerTestConnectionId(), |
| 1077 | visitor_.header_->destination_connection_id); |
| 1078 | // Make sure the correct error is propagated. |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1079 | EXPECT_THAT(framer_.error(), IsError(QUIC_PACKET_TOO_LARGE)); |
dschinazi | e8d7fa7 | 2019-04-05 14:44:40 -0700 | [diff] [blame] | 1080 | EXPECT_EQ("Packet too large.", framer_.detailed_error()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | TEST_P(QuicFramerTest, PacketHeader) { |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 1084 | if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1085 | return; |
| 1086 | } |
| 1087 | |
| 1088 | // clang-format off |
| 1089 | PacketFragments packet = { |
| 1090 | // public flags (8 byte connection_id) |
| 1091 | {"Unable to read public flags.", |
| 1092 | {0x28}}, |
| 1093 | // connection_id |
| 1094 | {"Unable to read ConnectionId.", |
| 1095 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1096 | // packet number |
| 1097 | {"Unable to read packet number.", |
| 1098 | {0x12, 0x34, 0x56, 0x78}}, |
| 1099 | }; |
| 1100 | // clang-format on |
| 1101 | |
| 1102 | PacketFragments& fragments = packet; |
| 1103 | |
| 1104 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1105 | AssemblePacketFromFragments(fragments)); |
| 1106 | |
| 1107 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1108 | EXPECT_THAT(framer_.error(), IsError(QUIC_MISSING_PAYLOAD)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1109 | ASSERT_TRUE(visitor_.header_.get()); |
| 1110 | EXPECT_EQ(FramerTestConnectionId(), |
| 1111 | visitor_.header_->destination_connection_id); |
| 1112 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1113 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1114 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1115 | |
| 1116 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1117 | |
| 1118 | PacketHeaderFormat format; |
fayang | e3f2f7b | 2019-09-19 17:01:57 -0700 | [diff] [blame] | 1119 | QuicLongHeaderType long_packet_type = INVALID_PACKET_TYPE; |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1120 | bool version_flag; |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1121 | QuicConnectionId destination_connection_id, source_connection_id; |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1122 | QuicVersionLabel version_label; |
| 1123 | std::string detailed_error; |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1124 | bool retry_token_present, use_length_prefix; |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 1125 | absl::string_view retry_token; |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1126 | ParsedQuicVersion parsed_version = UnsupportedQuicVersion(); |
| 1127 | const QuicErrorCode error_code = QuicFramer::ParsePublicHeaderDispatcher( |
| 1128 | *encrypted, kQuicDefaultConnectionIdLength, &format, &long_packet_type, |
| 1129 | &version_flag, &use_length_prefix, &version_label, &parsed_version, |
| 1130 | &destination_connection_id, &source_connection_id, &retry_token_present, |
| 1131 | &retry_token, &detailed_error); |
| 1132 | EXPECT_FALSE(retry_token_present); |
| 1133 | EXPECT_FALSE(use_length_prefix); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1134 | EXPECT_THAT(error_code, IsQuicNoError()); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1135 | EXPECT_EQ(GOOGLE_QUIC_PACKET, format); |
| 1136 | EXPECT_FALSE(version_flag); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1137 | EXPECT_EQ(kQuicDefaultConnectionIdLength, destination_connection_id.length()); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1138 | EXPECT_EQ(FramerTestConnectionId(), destination_connection_id); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1139 | EXPECT_EQ(EmptyQuicConnectionId(), source_connection_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1140 | } |
| 1141 | |
| 1142 | TEST_P(QuicFramerTest, LongPacketHeader) { |
| 1143 | // clang-format off |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1144 | PacketFragments packet46 = { |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1145 | // type (long header with packet type ZERO_RTT) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1146 | {"Unable to read first byte.", |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1147 | {0xD3}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1148 | // version tag |
| 1149 | {"Unable to read protocol version.", |
| 1150 | {QUIC_VERSION_BYTES}}, |
| 1151 | // connection_id length |
| 1152 | {"Unable to read ConnectionId length.", |
| 1153 | {0x50}}, |
| 1154 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1155 | {"Unable to read destination connection ID.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1156 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1157 | // packet number |
| 1158 | {"Unable to read packet number.", |
| 1159 | {0x12, 0x34, 0x56, 0x78}}, |
| 1160 | }; |
| 1161 | // clang-format on |
| 1162 | |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 1163 | if (!framer_.version().HasIetfInvariantHeader() || |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1164 | QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 1165 | return; |
| 1166 | } |
| 1167 | |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1168 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1169 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 1170 | AssemblePacketFromFragments(packet46)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1171 | |
| 1172 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1173 | EXPECT_THAT(framer_.error(), IsError(QUIC_MISSING_PAYLOAD)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1174 | ASSERT_TRUE(visitor_.header_.get()); |
| 1175 | EXPECT_EQ(FramerTestConnectionId(), |
| 1176 | visitor_.header_->destination_connection_id); |
| 1177 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1178 | EXPECT_TRUE(visitor_.header_->version_flag); |
| 1179 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1180 | |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 1181 | CheckFramingBoundaries(packet46, QUIC_INVALID_PACKET_HEADER); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1182 | |
| 1183 | PacketHeaderFormat format; |
fayang | e3f2f7b | 2019-09-19 17:01:57 -0700 | [diff] [blame] | 1184 | QuicLongHeaderType long_packet_type = INVALID_PACKET_TYPE; |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1185 | bool version_flag; |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1186 | QuicConnectionId destination_connection_id, source_connection_id; |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1187 | QuicVersionLabel version_label; |
| 1188 | std::string detailed_error; |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1189 | bool retry_token_present, use_length_prefix; |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 1190 | absl::string_view retry_token; |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1191 | ParsedQuicVersion parsed_version = UnsupportedQuicVersion(); |
| 1192 | const QuicErrorCode error_code = QuicFramer::ParsePublicHeaderDispatcher( |
| 1193 | *encrypted, kQuicDefaultConnectionIdLength, &format, &long_packet_type, |
| 1194 | &version_flag, &use_length_prefix, &version_label, &parsed_version, |
| 1195 | &destination_connection_id, &source_connection_id, &retry_token_present, |
| 1196 | &retry_token, &detailed_error); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1197 | EXPECT_THAT(error_code, IsQuicNoError()); |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1198 | EXPECT_EQ("", detailed_error); |
| 1199 | EXPECT_FALSE(retry_token_present); |
| 1200 | EXPECT_FALSE(use_length_prefix); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1201 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 1202 | EXPECT_TRUE(version_flag); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1203 | EXPECT_EQ(kQuicDefaultConnectionIdLength, destination_connection_id.length()); |
fayang | ccbab73 | 2019-05-13 10:11:25 -0700 | [diff] [blame] | 1204 | EXPECT_EQ(FramerTestConnectionId(), destination_connection_id); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1205 | EXPECT_EQ(EmptyQuicConnectionId(), source_connection_id); |
| 1206 | } |
| 1207 | |
| 1208 | TEST_P(QuicFramerTest, LongPacketHeaderWithBothConnectionIds) { |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 1209 | if (!framer_.version().HasIetfInvariantHeader()) { |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1210 | // This test requires an IETF long header. |
| 1211 | return; |
| 1212 | } |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1213 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1214 | // clang-format off |
| 1215 | unsigned char packet[] = { |
| 1216 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 1217 | // 4-byte packet number) |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 1218 | 0xD3, |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1219 | // version |
| 1220 | QUIC_VERSION_BYTES, |
| 1221 | // connection ID lengths |
| 1222 | 0x55, |
| 1223 | // destination connection ID |
| 1224 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1225 | // source connection ID |
| 1226 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1227 | // packet number |
| 1228 | 0x12, 0x34, 0x56, 0x00, |
| 1229 | // padding frame |
| 1230 | 0x00, |
| 1231 | }; |
| 1232 | unsigned char packet49[] = { |
| 1233 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 1234 | // 4-byte packet number) |
| 1235 | 0xD3, |
| 1236 | // version |
| 1237 | QUIC_VERSION_BYTES, |
| 1238 | // destination connection ID length |
| 1239 | 0x08, |
| 1240 | // destination connection ID |
| 1241 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1242 | // source connection ID length |
| 1243 | 0x08, |
| 1244 | // source connection ID |
| 1245 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1246 | // long header packet length |
| 1247 | 0x05, |
| 1248 | // packet number |
| 1249 | 0x12, 0x34, 0x56, 0x00, |
| 1250 | // padding frame |
| 1251 | 0x00, |
| 1252 | }; |
| 1253 | // clang-format on |
| 1254 | |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1255 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 1256 | size_t p_length = ABSL_ARRAYSIZE(packet); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 1257 | if (framer_.version().HasLongHeaderLengths()) { |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1258 | p = packet49; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 1259 | p_length = ABSL_ARRAYSIZE(packet49); |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1263 | PacketHeaderFormat format = GOOGLE_QUIC_PACKET; |
fayang | e3f2f7b | 2019-09-19 17:01:57 -0700 | [diff] [blame] | 1264 | QuicLongHeaderType long_packet_type = INVALID_PACKET_TYPE; |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1265 | bool version_flag = false; |
| 1266 | QuicConnectionId destination_connection_id, source_connection_id; |
| 1267 | QuicVersionLabel version_label = 0; |
| 1268 | std::string detailed_error = ""; |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1269 | bool retry_token_present, use_length_prefix; |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 1270 | absl::string_view retry_token; |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1271 | ParsedQuicVersion parsed_version = UnsupportedQuicVersion(); |
| 1272 | const QuicErrorCode error_code = QuicFramer::ParsePublicHeaderDispatcher( |
| 1273 | encrypted, kQuicDefaultConnectionIdLength, &format, &long_packet_type, |
| 1274 | &version_flag, &use_length_prefix, &version_label, &parsed_version, |
| 1275 | &destination_connection_id, &source_connection_id, &retry_token_present, |
| 1276 | &retry_token, &detailed_error); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1277 | EXPECT_THAT(error_code, IsQuicNoError()); |
dschinazi | bf0413d | 2019-10-07 14:19:53 -0700 | [diff] [blame] | 1278 | EXPECT_FALSE(retry_token_present); |
| 1279 | EXPECT_EQ(framer_.version().HasLengthPrefixedConnectionIds(), |
| 1280 | use_length_prefix); |
dschinazi | b42a8c5 | 2019-05-30 09:45:01 -0700 | [diff] [blame] | 1281 | EXPECT_EQ("", detailed_error); |
| 1282 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 1283 | EXPECT_TRUE(version_flag); |
| 1284 | EXPECT_EQ(FramerTestConnectionId(), destination_connection_id); |
| 1285 | EXPECT_EQ(FramerTestConnectionIdPlusOne(), source_connection_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1286 | } |
| 1287 | |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 1288 | TEST_P(QuicFramerTest, ParsePublicHeader) { |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 1289 | // clang-format off |
| 1290 | unsigned char packet[] = { |
| 1291 | // public flags (version included, 8-byte connection ID, |
| 1292 | // 4-byte packet number) |
| 1293 | 0x29, |
| 1294 | // connection_id |
| 1295 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1296 | // version |
| 1297 | QUIC_VERSION_BYTES, |
| 1298 | // packet number |
| 1299 | 0x12, 0x34, 0x56, 0x78, |
| 1300 | // padding frame |
| 1301 | 0x00, |
| 1302 | }; |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 1303 | unsigned char packet46[] = { |
| 1304 | // public flags (long header with packet type HANDSHAKE and |
| 1305 | // 4-byte packet number) |
| 1306 | 0xE3, |
| 1307 | // version |
| 1308 | QUIC_VERSION_BYTES, |
| 1309 | // connection ID lengths |
| 1310 | 0x50, |
| 1311 | // destination connection ID |
| 1312 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1313 | // long header packet length |
| 1314 | 0x05, |
| 1315 | // packet number |
| 1316 | 0x12, 0x34, 0x56, 0x78, |
| 1317 | // padding frame |
| 1318 | 0x00, |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 1319 | }; |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 1320 | unsigned char packet49[] = { |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 1321 | // public flags (long header with packet type HANDSHAKE and |
| 1322 | // 4-byte packet number) |
| 1323 | 0xE3, |
| 1324 | // version |
| 1325 | QUIC_VERSION_BYTES, |
| 1326 | // destination connection ID length |
| 1327 | 0x08, |
| 1328 | // destination connection ID |
| 1329 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1330 | // source connection ID length |
| 1331 | 0x00, |
| 1332 | // long header packet length |
| 1333 | 0x05, |
| 1334 | // packet number |
| 1335 | 0x12, 0x34, 0x56, 0x78, |
| 1336 | // padding frame |
| 1337 | 0x00, |
| 1338 | }; |
| 1339 | // clang-format on |
| 1340 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 1341 | size_t p_length = ABSL_ARRAYSIZE(packet); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 1342 | if (framer_.version().HasLongHeaderLengths()) { |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 1343 | p = packet49; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 1344 | p_length = ABSL_ARRAYSIZE(packet49); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 1345 | } else if (framer_.version().HasIetfInvariantHeader()) { |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 1346 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 1347 | p_length = ABSL_ARRAYSIZE(packet46); |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | uint8_t first_byte = 0x33; |
| 1351 | PacketHeaderFormat format = GOOGLE_QUIC_PACKET; |
| 1352 | bool version_present = false, has_length_prefix = false; |
| 1353 | QuicVersionLabel version_label = 0; |
| 1354 | ParsedQuicVersion parsed_version = UnsupportedQuicVersion(); |
| 1355 | QuicConnectionId destination_connection_id = EmptyQuicConnectionId(), |
| 1356 | source_connection_id = EmptyQuicConnectionId(); |
| 1357 | QuicLongHeaderType long_packet_type = INVALID_PACKET_TYPE; |
| 1358 | QuicVariableLengthIntegerLength retry_token_length_length = |
| 1359 | VARIABLE_LENGTH_INTEGER_LENGTH_4; |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 1360 | absl::string_view retry_token; |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 1361 | std::string detailed_error = "foobar"; |
| 1362 | |
| 1363 | QuicDataReader reader(AsChars(p), p_length); |
| 1364 | const QuicErrorCode parse_error = QuicFramer::ParsePublicHeader( |
| 1365 | &reader, kQuicDefaultConnectionIdLength, |
| 1366 | /*ietf_format=*/ |
| 1367 | VersionHasIetfInvariantHeader(framer_.transport_version()), &first_byte, |
| 1368 | &format, &version_present, &has_length_prefix, &version_label, |
| 1369 | &parsed_version, &destination_connection_id, &source_connection_id, |
| 1370 | &long_packet_type, &retry_token_length_length, &retry_token, |
| 1371 | &detailed_error); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1372 | EXPECT_THAT(parse_error, IsQuicNoError()); |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 1373 | EXPECT_EQ("", detailed_error); |
| 1374 | EXPECT_EQ(p[0], first_byte); |
| 1375 | EXPECT_TRUE(version_present); |
| 1376 | EXPECT_EQ(framer_.version().HasLengthPrefixedConnectionIds(), |
| 1377 | has_length_prefix); |
| 1378 | EXPECT_EQ(CreateQuicVersionLabel(framer_.version()), version_label); |
| 1379 | EXPECT_EQ(framer_.version(), parsed_version); |
| 1380 | EXPECT_EQ(FramerTestConnectionId(), destination_connection_id); |
| 1381 | EXPECT_EQ(EmptyQuicConnectionId(), source_connection_id); |
| 1382 | EXPECT_EQ(VARIABLE_LENGTH_INTEGER_LENGTH_0, retry_token_length_length); |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 1383 | EXPECT_EQ(absl::string_view(), retry_token); |
dschinazi | 243eabc | 2019-08-05 16:15:29 -0700 | [diff] [blame] | 1384 | if (VersionHasIetfInvariantHeader(framer_.transport_version())) { |
| 1385 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 1386 | EXPECT_EQ(HANDSHAKE, long_packet_type); |
| 1387 | } else { |
| 1388 | EXPECT_EQ(GOOGLE_QUIC_PACKET, format); |
| 1389 | } |
| 1390 | } |
| 1391 | |
dschinazi | 81eb4e0 | 2019-09-27 17:12:17 -0700 | [diff] [blame] | 1392 | TEST_P(QuicFramerTest, ParsePublicHeaderProxBadSourceConnectionIdLength) { |
| 1393 | if (!framer_.version().HasLengthPrefixedConnectionIds()) { |
| 1394 | return; |
| 1395 | } |
dschinazi | 81eb4e0 | 2019-09-27 17:12:17 -0700 | [diff] [blame] | 1396 | // clang-format off |
| 1397 | unsigned char packet[] = { |
| 1398 | // public flags (long header with packet type HANDSHAKE and |
| 1399 | // 4-byte packet number) |
| 1400 | 0xE3, |
| 1401 | // version |
| 1402 | 'P', 'R', 'O', 'X', |
| 1403 | // destination connection ID length |
| 1404 | 0x08, |
| 1405 | // destination connection ID |
| 1406 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1407 | // source connection ID length (bogus) |
| 1408 | 0xEE, |
| 1409 | // long header packet length |
| 1410 | 0x05, |
| 1411 | // packet number |
| 1412 | 0x12, 0x34, 0x56, 0x78, |
| 1413 | // padding frame |
| 1414 | 0x00, |
| 1415 | }; |
| 1416 | // clang-format on |
| 1417 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 1418 | size_t p_length = ABSL_ARRAYSIZE(packet); |
dschinazi | 81eb4e0 | 2019-09-27 17:12:17 -0700 | [diff] [blame] | 1419 | |
| 1420 | uint8_t first_byte = 0x33; |
| 1421 | PacketHeaderFormat format = GOOGLE_QUIC_PACKET; |
| 1422 | bool version_present = false, has_length_prefix = false; |
| 1423 | QuicVersionLabel version_label = 0; |
| 1424 | ParsedQuicVersion parsed_version = UnsupportedQuicVersion(); |
| 1425 | QuicConnectionId destination_connection_id = EmptyQuicConnectionId(), |
| 1426 | source_connection_id = EmptyQuicConnectionId(); |
| 1427 | QuicLongHeaderType long_packet_type = INVALID_PACKET_TYPE; |
| 1428 | QuicVariableLengthIntegerLength retry_token_length_length = |
| 1429 | VARIABLE_LENGTH_INTEGER_LENGTH_4; |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 1430 | absl::string_view retry_token; |
dschinazi | 81eb4e0 | 2019-09-27 17:12:17 -0700 | [diff] [blame] | 1431 | std::string detailed_error = "foobar"; |
| 1432 | |
| 1433 | QuicDataReader reader(AsChars(p), p_length); |
| 1434 | const QuicErrorCode parse_error = QuicFramer::ParsePublicHeader( |
| 1435 | &reader, kQuicDefaultConnectionIdLength, |
| 1436 | /*ietf_format=*/true, &first_byte, &format, &version_present, |
| 1437 | &has_length_prefix, &version_label, &parsed_version, |
| 1438 | &destination_connection_id, &source_connection_id, &long_packet_type, |
| 1439 | &retry_token_length_length, &retry_token, &detailed_error); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1440 | EXPECT_THAT(parse_error, IsQuicNoError()); |
dschinazi | 81eb4e0 | 2019-09-27 17:12:17 -0700 | [diff] [blame] | 1441 | EXPECT_EQ("", detailed_error); |
| 1442 | EXPECT_EQ(p[0], first_byte); |
| 1443 | EXPECT_TRUE(version_present); |
| 1444 | EXPECT_TRUE(has_length_prefix); |
| 1445 | EXPECT_EQ(0x50524F58u, version_label); // "PROX" |
| 1446 | EXPECT_EQ(UnsupportedQuicVersion(), parsed_version); |
| 1447 | EXPECT_EQ(FramerTestConnectionId(), destination_connection_id); |
| 1448 | EXPECT_EQ(EmptyQuicConnectionId(), source_connection_id); |
| 1449 | EXPECT_EQ(VARIABLE_LENGTH_INTEGER_LENGTH_0, retry_token_length_length); |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 1450 | EXPECT_EQ(absl::string_view(), retry_token); |
dschinazi | 81eb4e0 | 2019-09-27 17:12:17 -0700 | [diff] [blame] | 1451 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 1452 | } |
| 1453 | |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 1454 | TEST_P(QuicFramerTest, ClientConnectionIdFromShortHeaderToClient) { |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 1455 | if (!framer_.version().SupportsClientConnectionIds()) { |
| 1456 | return; |
| 1457 | } |
| 1458 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 1459 | QuicFramerPeer::SetLastSerializedServerConnectionId(&framer_, |
| 1460 | TestConnectionId(0x33)); |
| 1461 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1462 | framer_.SetExpectedClientConnectionIdLength(kQuicDefaultConnectionIdLength); |
| 1463 | // clang-format off |
| 1464 | unsigned char packet[] = { |
| 1465 | // type (short header, 4 byte packet number) |
| 1466 | 0x43, |
| 1467 | // connection_id |
| 1468 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1469 | // packet number |
| 1470 | 0x13, 0x37, 0x42, 0x33, |
| 1471 | // padding frame |
| 1472 | 0x00, |
| 1473 | }; |
| 1474 | // clang-format on |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 1475 | QuicEncryptedPacket encrypted(AsChars(packet), ABSL_ARRAYSIZE(packet), false); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 1476 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1477 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 1478 | EXPECT_EQ("", framer_.detailed_error()); |
| 1479 | ASSERT_TRUE(visitor_.header_.get()); |
| 1480 | EXPECT_EQ(FramerTestConnectionId(), |
| 1481 | visitor_.header_->destination_connection_id); |
| 1482 | EXPECT_EQ(TestConnectionId(0x33), visitor_.header_->source_connection_id); |
| 1483 | } |
| 1484 | |
| 1485 | // In short header packets from client to server, the client connection ID |
| 1486 | // is omitted, but the framer adds it to the header struct using its |
| 1487 | // last serialized client connection ID. This test ensures that this |
| 1488 | // mechanism behaves as expected. |
| 1489 | TEST_P(QuicFramerTest, ClientConnectionIdFromShortHeaderToServer) { |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 1490 | if (!framer_.version().SupportsClientConnectionIds()) { |
| 1491 | return; |
| 1492 | } |
| 1493 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 1494 | QuicFramerPeer::SetLastSerializedClientConnectionId(&framer_, |
| 1495 | TestConnectionId(0x33)); |
| 1496 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1497 | // clang-format off |
| 1498 | unsigned char packet[] = { |
| 1499 | // type (short header, 4 byte packet number) |
| 1500 | 0x43, |
| 1501 | // connection_id |
| 1502 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1503 | // packet number |
| 1504 | 0x13, 0x37, 0x42, 0x33, |
| 1505 | // padding frame |
| 1506 | 0x00, |
| 1507 | }; |
| 1508 | // clang-format on |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 1509 | QuicEncryptedPacket encrypted(AsChars(packet), ABSL_ARRAYSIZE(packet), false); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 1510 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1511 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 1512 | EXPECT_EQ("", framer_.detailed_error()); |
| 1513 | ASSERT_TRUE(visitor_.header_.get()); |
| 1514 | EXPECT_EQ(FramerTestConnectionId(), |
| 1515 | visitor_.header_->destination_connection_id); |
| 1516 | EXPECT_EQ(TestConnectionId(0x33), visitor_.header_->source_connection_id); |
| 1517 | } |
| 1518 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1519 | TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1520 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
dschinazi | 7b9278c | 2019-05-20 07:36:21 -0700 | [diff] [blame] | 1521 | QuicFramerPeer::SetLastSerializedServerConnectionId(&framer_, |
| 1522 | FramerTestConnectionId()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1523 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1524 | |
| 1525 | // clang-format off |
| 1526 | PacketFragments packet = { |
| 1527 | // public flags (0 byte connection_id) |
| 1528 | {"Unable to read public flags.", |
| 1529 | {0x20}}, |
| 1530 | // connection_id |
| 1531 | // packet number |
| 1532 | {"Unable to read packet number.", |
| 1533 | {0x12, 0x34, 0x56, 0x78}}, |
| 1534 | }; |
| 1535 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1536 | PacketFragments packet46 = { |
| 1537 | // type (short header, 4 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1538 | {"Unable to read first byte.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1539 | {0x43}}, |
| 1540 | // connection_id |
| 1541 | // packet number |
| 1542 | {"Unable to read packet number.", |
| 1543 | {0x12, 0x34, 0x56, 0x78}}, |
| 1544 | }; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1545 | |
| 1546 | PacketFragments packet_hp = { |
| 1547 | // type (short header, 4 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1548 | {"Unable to read first byte.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1549 | {0x43}}, |
| 1550 | // connection_id |
| 1551 | // packet number |
| 1552 | {"", |
| 1553 | {0x12, 0x34, 0x56, 0x78}}, |
| 1554 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1555 | // clang-format on |
| 1556 | |
| 1557 | PacketFragments& fragments = |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1558 | framer_.version().HasHeaderProtection() |
| 1559 | ? packet_hp |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 1560 | : (framer_.version().HasIetfInvariantHeader() ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1561 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1562 | AssemblePacketFromFragments(fragments)); |
| 1563 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1564 | EXPECT_THAT(framer_.error(), IsError(QUIC_MISSING_PAYLOAD)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1565 | ASSERT_TRUE(visitor_.header_.get()); |
dschinazi | 5e1a7b2 | 2019-07-31 12:23:21 -0700 | [diff] [blame] | 1566 | EXPECT_EQ(FramerTestConnectionId(), visitor_.header_->source_connection_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1567 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1568 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1569 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1570 | |
| 1571 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1572 | } |
| 1573 | |
| 1574 | TEST_P(QuicFramerTest, PacketHeaderWithVersionFlag) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1575 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1576 | // clang-format off |
| 1577 | PacketFragments packet = { |
| 1578 | // public flags (0 byte connection_id) |
| 1579 | {"Unable to read public flags.", |
| 1580 | {0x29}}, |
| 1581 | // connection_id |
| 1582 | {"Unable to read ConnectionId.", |
| 1583 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1584 | // version tag |
| 1585 | {"Unable to read protocol version.", |
| 1586 | {QUIC_VERSION_BYTES}}, |
| 1587 | // packet number |
| 1588 | {"Unable to read packet number.", |
| 1589 | {0x12, 0x34, 0x56, 0x78}}, |
| 1590 | }; |
| 1591 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1592 | PacketFragments packet46 = { |
| 1593 | // type (long header with packet type ZERO_RTT_PROTECTED and 4 bytes |
| 1594 | // packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1595 | {"Unable to read first byte.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1596 | {0xD3}}, |
| 1597 | // version tag |
| 1598 | {"Unable to read protocol version.", |
| 1599 | {QUIC_VERSION_BYTES}}, |
| 1600 | // connection_id length |
| 1601 | {"Unable to read ConnectionId length.", |
| 1602 | {0x50}}, |
| 1603 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1604 | {"Unable to read destination connection ID.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1605 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1606 | // packet number |
| 1607 | {"Unable to read packet number.", |
| 1608 | {0x12, 0x34, 0x56, 0x78}}, |
| 1609 | }; |
| 1610 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 1611 | PacketFragments packet49 = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1612 | // type (long header with packet type ZERO_RTT_PROTECTED and 4 bytes |
| 1613 | // packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1614 | {"Unable to read first byte.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1615 | {0xD3}}, |
| 1616 | // version tag |
| 1617 | {"Unable to read protocol version.", |
| 1618 | {QUIC_VERSION_BYTES}}, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1619 | // destination connection ID length |
| 1620 | {"Unable to read destination connection ID.", |
| 1621 | {0x08}}, |
| 1622 | // destination connection ID |
| 1623 | {"Unable to read destination connection ID.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1624 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1625 | // source connection ID length |
| 1626 | {"Unable to read source connection ID.", |
| 1627 | {0x00}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1628 | // long header packet length |
| 1629 | {"Unable to read long header payload length.", |
| 1630 | {0x04}}, |
| 1631 | // packet number |
| 1632 | {"Long header payload length longer than packet.", |
| 1633 | {0x12, 0x34, 0x56, 0x78}}, |
| 1634 | }; |
| 1635 | // clang-format on |
| 1636 | |
| 1637 | PacketFragments& fragments = |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 1638 | framer_.version().HasLongHeaderLengths() |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 1639 | ? packet49 |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 1640 | : (framer_.version().HasIetfInvariantHeader() ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1641 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1642 | AssemblePacketFromFragments(fragments)); |
| 1643 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1644 | EXPECT_THAT(framer_.error(), IsError(QUIC_MISSING_PAYLOAD)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1645 | ASSERT_TRUE(visitor_.header_.get()); |
| 1646 | EXPECT_EQ(FramerTestConnectionId(), |
| 1647 | visitor_.header_->destination_connection_id); |
| 1648 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1649 | EXPECT_TRUE(visitor_.header_->version_flag); |
| 1650 | EXPECT_EQ(GetParam(), visitor_.header_->version); |
| 1651 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1652 | |
| 1653 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1654 | } |
| 1655 | |
| 1656 | TEST_P(QuicFramerTest, PacketHeaderWith4BytePacketNumber) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1657 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1658 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1659 | |
| 1660 | // clang-format off |
| 1661 | PacketFragments packet = { |
| 1662 | // public flags (8 byte connection_id and 4 byte packet number) |
| 1663 | {"Unable to read public flags.", |
| 1664 | {0x28}}, |
| 1665 | // connection_id |
| 1666 | {"Unable to read ConnectionId.", |
| 1667 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1668 | // packet number |
| 1669 | {"Unable to read packet number.", |
| 1670 | {0x12, 0x34, 0x56, 0x78}}, |
| 1671 | }; |
| 1672 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1673 | PacketFragments packet46 = { |
| 1674 | // type (short header, 4 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1675 | {"Unable to read first byte.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1676 | {0x43}}, |
| 1677 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1678 | {"Unable to read destination connection ID.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1679 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1680 | // packet number |
| 1681 | {"Unable to read packet number.", |
| 1682 | {0x12, 0x34, 0x56, 0x78}}, |
| 1683 | }; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1684 | |
| 1685 | PacketFragments packet_hp = { |
| 1686 | // type (short header, 4 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1687 | {"Unable to read first byte.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1688 | {0x43}}, |
| 1689 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1690 | {"Unable to read destination connection ID.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1691 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1692 | // packet number |
| 1693 | {"", |
| 1694 | {0x12, 0x34, 0x56, 0x78}}, |
| 1695 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1696 | // clang-format on |
| 1697 | |
| 1698 | PacketFragments& fragments = |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1699 | framer_.version().HasHeaderProtection() |
| 1700 | ? packet_hp |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 1701 | : (framer_.version().HasIetfInvariantHeader() ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1702 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1703 | AssemblePacketFromFragments(fragments)); |
| 1704 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1705 | EXPECT_THAT(framer_.error(), IsError(QUIC_MISSING_PAYLOAD)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1706 | ASSERT_TRUE(visitor_.header_.get()); |
| 1707 | EXPECT_EQ(FramerTestConnectionId(), |
| 1708 | visitor_.header_->destination_connection_id); |
| 1709 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1710 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1711 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1712 | |
| 1713 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1714 | } |
| 1715 | |
| 1716 | TEST_P(QuicFramerTest, PacketHeaderWith2BytePacketNumber) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1717 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1718 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1719 | |
| 1720 | // clang-format off |
| 1721 | PacketFragments packet = { |
| 1722 | // public flags (8 byte connection_id and 2 byte packet number) |
| 1723 | {"Unable to read public flags.", |
| 1724 | {0x18}}, |
| 1725 | // connection_id |
| 1726 | {"Unable to read ConnectionId.", |
| 1727 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1728 | // packet number |
| 1729 | {"Unable to read packet number.", |
| 1730 | {0x56, 0x78}}, |
| 1731 | }; |
| 1732 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1733 | PacketFragments packet46 = { |
| 1734 | // type (short header, 2 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1735 | {"Unable to read first byte.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1736 | {0x41}}, |
| 1737 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1738 | {"Unable to read destination connection ID.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1739 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1740 | // packet number |
| 1741 | {"Unable to read packet number.", |
| 1742 | {0x56, 0x78}}, |
| 1743 | }; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1744 | |
| 1745 | PacketFragments packet_hp = { |
| 1746 | // type (short header, 2 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1747 | {"Unable to read first byte.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1748 | {0x41}}, |
| 1749 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1750 | {"Unable to read destination connection ID.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1751 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1752 | // packet number |
| 1753 | {"", |
| 1754 | {0x56, 0x78}}, |
| 1755 | // padding |
| 1756 | {"", {0x00, 0x00}}, |
| 1757 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1758 | // clang-format on |
| 1759 | |
| 1760 | PacketFragments& fragments = |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1761 | framer_.version().HasHeaderProtection() |
| 1762 | ? packet_hp |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 1763 | : (framer_.version().HasIetfInvariantHeader() ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1764 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1765 | AssemblePacketFromFragments(fragments)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1766 | if (framer_.version().HasHeaderProtection()) { |
| 1767 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1768 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1769 | } else { |
| 1770 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1771 | EXPECT_THAT(framer_.error(), IsError(QUIC_MISSING_PAYLOAD)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1772 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1773 | ASSERT_TRUE(visitor_.header_.get()); |
| 1774 | EXPECT_EQ(FramerTestConnectionId(), |
| 1775 | visitor_.header_->destination_connection_id); |
| 1776 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1777 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1778 | EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1779 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1780 | |
| 1781 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1782 | } |
| 1783 | |
| 1784 | TEST_P(QuicFramerTest, PacketHeaderWith1BytePacketNumber) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1785 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1786 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1787 | |
| 1788 | // clang-format off |
| 1789 | PacketFragments packet = { |
| 1790 | // public flags (8 byte connection_id and 1 byte packet number) |
| 1791 | {"Unable to read public flags.", |
| 1792 | {0x08}}, |
| 1793 | // connection_id |
| 1794 | {"Unable to read ConnectionId.", |
| 1795 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1796 | // packet number |
| 1797 | {"Unable to read packet number.", |
| 1798 | {0x78}}, |
| 1799 | }; |
| 1800 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1801 | PacketFragments packet46 = { |
| 1802 | // type (8 byte connection_id and 1 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1803 | {"Unable to read first byte.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1804 | {0x40}}, |
| 1805 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1806 | {"Unable to read destination connection ID.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1807 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1808 | // packet number |
| 1809 | {"Unable to read packet number.", |
| 1810 | {0x78}}, |
| 1811 | }; |
| 1812 | |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1813 | PacketFragments packet_hp = { |
| 1814 | // type (8 byte connection_id and 1 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1815 | {"Unable to read first byte.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1816 | {0x40}}, |
| 1817 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1818 | {"Unable to read destination connection ID.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1819 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1820 | // packet number |
| 1821 | {"", |
| 1822 | {0x78}}, |
| 1823 | // padding |
| 1824 | {"", {0x00, 0x00, 0x00}}, |
| 1825 | }; |
| 1826 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1827 | // clang-format on |
| 1828 | |
| 1829 | PacketFragments& fragments = |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1830 | framer_.version().HasHeaderProtection() |
| 1831 | ? packet_hp |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 1832 | : (framer_.version().HasIetfInvariantHeader() ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1833 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1834 | AssemblePacketFromFragments(fragments)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1835 | if (framer_.version().HasHeaderProtection()) { |
| 1836 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1837 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1838 | } else { |
| 1839 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 1840 | EXPECT_THAT(framer_.error(), IsError(QUIC_MISSING_PAYLOAD)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 1841 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1842 | ASSERT_TRUE(visitor_.header_.get()); |
| 1843 | EXPECT_EQ(FramerTestConnectionId(), |
| 1844 | visitor_.header_->destination_connection_id); |
| 1845 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1846 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1847 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1848 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1849 | |
| 1850 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1851 | } |
| 1852 | |
| 1853 | TEST_P(QuicFramerTest, PacketNumberDecreasesThenIncreases) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1854 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1855 | // Test the case when a packet is received from the past and future packet |
| 1856 | // numbers are still calculated relative to the largest received packet. |
| 1857 | QuicPacketHeader header; |
| 1858 | header.destination_connection_id = FramerTestConnectionId(); |
| 1859 | header.reset_flag = false; |
| 1860 | header.version_flag = false; |
| 1861 | header.packet_number = kPacketNumber - 2; |
| 1862 | |
| 1863 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 1864 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1865 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 1866 | ASSERT_TRUE(data != nullptr); |
| 1867 | |
| 1868 | QuicEncryptedPacket encrypted(data->data(), data->length(), false); |
| 1869 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1870 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1871 | ASSERT_TRUE(visitor_.header_.get()); |
| 1872 | EXPECT_EQ(FramerTestConnectionId(), |
| 1873 | visitor_.header_->destination_connection_id); |
| 1874 | EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1875 | EXPECT_EQ(kPacketNumber - 2, visitor_.header_->packet_number); |
| 1876 | |
| 1877 | // Receive a 1 byte packet number. |
| 1878 | header.packet_number = kPacketNumber; |
| 1879 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 1880 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1881 | data = BuildDataPacket(header, frames); |
| 1882 | QuicEncryptedPacket encrypted1(data->data(), data->length(), false); |
| 1883 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1884 | EXPECT_TRUE(framer_.ProcessPacket(encrypted1)); |
| 1885 | ASSERT_TRUE(visitor_.header_.get()); |
| 1886 | EXPECT_EQ(FramerTestConnectionId(), |
| 1887 | visitor_.header_->destination_connection_id); |
| 1888 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1889 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1890 | |
| 1891 | // Process a 2 byte packet number 256 packets ago. |
| 1892 | header.packet_number = kPacketNumber - 256; |
| 1893 | header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER; |
| 1894 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1895 | data = BuildDataPacket(header, frames); |
| 1896 | QuicEncryptedPacket encrypted2(data->data(), data->length(), false); |
| 1897 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1898 | EXPECT_TRUE(framer_.ProcessPacket(encrypted2)); |
| 1899 | ASSERT_TRUE(visitor_.header_.get()); |
| 1900 | EXPECT_EQ(FramerTestConnectionId(), |
| 1901 | visitor_.header_->destination_connection_id); |
| 1902 | EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1903 | EXPECT_EQ(kPacketNumber - 256, visitor_.header_->packet_number); |
| 1904 | |
| 1905 | // Process another 1 byte packet number and ensure it works. |
| 1906 | header.packet_number = kPacketNumber - 1; |
| 1907 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 1908 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1909 | data = BuildDataPacket(header, frames); |
| 1910 | QuicEncryptedPacket encrypted3(data->data(), data->length(), false); |
| 1911 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1912 | EXPECT_TRUE(framer_.ProcessPacket(encrypted3)); |
| 1913 | ASSERT_TRUE(visitor_.header_.get()); |
| 1914 | EXPECT_EQ(FramerTestConnectionId(), |
| 1915 | visitor_.header_->destination_connection_id); |
| 1916 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1917 | EXPECT_EQ(kPacketNumber - 1, visitor_.header_->packet_number); |
| 1918 | } |
| 1919 | |
| 1920 | TEST_P(QuicFramerTest, PacketWithDiversificationNonce) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 1921 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1922 | // clang-format off |
| 1923 | unsigned char packet[] = { |
| 1924 | // public flags: includes nonce flag |
| 1925 | 0x2C, |
| 1926 | // connection_id |
| 1927 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1928 | // nonce |
| 1929 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1930 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1931 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1932 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1933 | // packet number |
| 1934 | 0x12, 0x34, 0x56, 0x78, |
| 1935 | |
| 1936 | // frame type (padding) |
| 1937 | 0x00, |
| 1938 | 0x00, 0x00, 0x00, 0x00 |
| 1939 | }; |
| 1940 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1941 | unsigned char packet46[] = { |
| 1942 | // type: Long header with packet type ZERO_RTT_PROTECTED and 1 byte packet |
| 1943 | // number. |
| 1944 | 0xD0, |
| 1945 | // version tag |
| 1946 | QUIC_VERSION_BYTES, |
| 1947 | // connection_id length |
| 1948 | 0x05, |
| 1949 | // connection_id |
| 1950 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1951 | // packet number |
| 1952 | 0x78, |
| 1953 | // nonce |
| 1954 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1955 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1956 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1957 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1958 | |
| 1959 | // frame type (padding) |
| 1960 | 0x00, |
| 1961 | 0x00, 0x00, 0x00, 0x00 |
| 1962 | }; |
| 1963 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 1964 | unsigned char packet49[] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1965 | // type: Long header with packet type ZERO_RTT_PROTECTED and 1 byte packet |
| 1966 | // number. |
| 1967 | 0xD0, |
| 1968 | // version tag |
| 1969 | QUIC_VERSION_BYTES, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 1970 | // destination connection ID length |
| 1971 | 0x00, |
| 1972 | // source connection ID length |
| 1973 | 0x08, |
| 1974 | // source connection ID |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1975 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1976 | // long header packet length |
| 1977 | 0x26, |
| 1978 | // packet number |
| 1979 | 0x78, |
| 1980 | // nonce |
| 1981 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1982 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1983 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1984 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1985 | |
| 1986 | // frame type (padding) |
| 1987 | 0x00, |
| 1988 | 0x00, 0x00, 0x00, 0x00 |
| 1989 | }; |
| 1990 | // clang-format on |
| 1991 | |
| 1992 | if (framer_.version().handshake_protocol != PROTOCOL_QUIC_CRYPTO) { |
| 1993 | return; |
| 1994 | } |
| 1995 | |
| 1996 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 1997 | size_t p_size = ABSL_ARRAYSIZE(packet); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 1998 | if (framer_.version().HasLongHeaderLengths()) { |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 1999 | p = packet49; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 2000 | p_size = ABSL_ARRAYSIZE(packet49); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 2001 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2002 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 2003 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2004 | } |
| 2005 | |
| 2006 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 2007 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 2008 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 2009 | ASSERT_TRUE(visitor_.header_->nonce != nullptr); |
| 2010 | for (char i = 0; i < 32; ++i) { |
| 2011 | EXPECT_EQ(i, (*visitor_.header_->nonce)[static_cast<size_t>(i)]); |
| 2012 | } |
| 2013 | EXPECT_EQ(1u, visitor_.padding_frames_.size()); |
| 2014 | EXPECT_EQ(5, visitor_.padding_frames_[0]->num_padding_bytes); |
| 2015 | } |
| 2016 | |
| 2017 | TEST_P(QuicFramerTest, LargePublicFlagWithMismatchedVersions) { |
| 2018 | // clang-format off |
| 2019 | unsigned char packet[] = { |
| 2020 | // public flags (8 byte connection_id, version flag and an unknown flag) |
| 2021 | 0x29, |
| 2022 | // connection_id |
| 2023 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2024 | // version tag |
| 2025 | 'Q', '0', '0', '0', |
| 2026 | // packet number |
| 2027 | 0x12, 0x34, 0x56, 0x78, |
| 2028 | |
| 2029 | // frame type (padding frame) |
| 2030 | 0x00, |
| 2031 | 0x00, 0x00, 0x00, 0x00 |
| 2032 | }; |
| 2033 | |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 2034 | unsigned char packet46[] = { |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 2035 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 2036 | 0xD3, |
| 2037 | // version tag |
| 2038 | 'Q', '0', '0', '0', |
| 2039 | // connection_id length |
| 2040 | 0x50, |
| 2041 | // connection_id |
| 2042 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2043 | // packet number |
| 2044 | 0x12, 0x34, 0x56, 0x78, |
| 2045 | |
| 2046 | // frame type (padding frame) |
| 2047 | 0x00, |
| 2048 | 0x00, 0x00, 0x00, 0x00 |
| 2049 | }; |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 2050 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 2051 | unsigned char packet49[] = { |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 2052 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 2053 | 0xD3, |
| 2054 | // version tag |
| 2055 | 'Q', '0', '0', '0', |
| 2056 | // destination connection ID length |
| 2057 | 0x08, |
| 2058 | // destination connection ID |
| 2059 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2060 | // source connection ID length |
| 2061 | 0x00, |
| 2062 | // packet number |
| 2063 | 0x12, 0x34, 0x56, 0x78, |
| 2064 | |
| 2065 | // frame type (padding frame) |
| 2066 | 0x00, |
| 2067 | 0x00, 0x00, 0x00, 0x00 |
| 2068 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2069 | // clang-format on |
| 2070 | |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 2071 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 2072 | size_t p_size = ABSL_ARRAYSIZE(packet); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 2073 | if (framer_.version().HasLongHeaderLengths()) { |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 2074 | p = packet49; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 2075 | p_size = ABSL_ARRAYSIZE(packet49); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 2076 | } else if (framer_.version().HasIetfInvariantHeader()) { |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 2077 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 2078 | p_size = ABSL_ARRAYSIZE(packet46); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 2079 | } |
| 2080 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2081 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2082 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2083 | ASSERT_TRUE(visitor_.header_.get()); |
| 2084 | EXPECT_EQ(0, visitor_.frame_count_); |
| 2085 | EXPECT_EQ(1, visitor_.version_mismatch_); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | TEST_P(QuicFramerTest, PaddingFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2089 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2090 | // clang-format off |
| 2091 | unsigned char packet[] = { |
| 2092 | // public flags (8 byte connection_id) |
| 2093 | 0x28, |
| 2094 | // connection_id |
| 2095 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2096 | // packet number |
| 2097 | 0x12, 0x34, 0x56, 0x78, |
| 2098 | |
| 2099 | // paddings |
| 2100 | 0x00, 0x00, |
| 2101 | // frame type (stream frame with fin) |
| 2102 | 0xFF, |
| 2103 | // stream id |
| 2104 | 0x01, 0x02, 0x03, 0x04, |
| 2105 | // offset |
| 2106 | 0x3A, 0x98, 0xFE, 0xDC, |
| 2107 | 0x32, 0x10, 0x76, 0x54, |
| 2108 | // data length |
| 2109 | 0x00, 0x0c, |
| 2110 | // data |
| 2111 | 'h', 'e', 'l', 'l', |
| 2112 | 'o', ' ', 'w', 'o', |
| 2113 | 'r', 'l', 'd', '!', |
| 2114 | // paddings |
| 2115 | 0x00, 0x00, |
| 2116 | }; |
| 2117 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2118 | unsigned char packet46[] = { |
| 2119 | // type (short header, 4 byte packet number) |
| 2120 | 0x43, |
| 2121 | // connection_id |
| 2122 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2123 | // packet number |
| 2124 | 0x12, 0x34, 0x56, 0x78, |
| 2125 | |
| 2126 | // paddings |
| 2127 | 0x00, 0x00, |
| 2128 | // frame type (stream frame with fin) |
| 2129 | 0xFF, |
| 2130 | // stream id |
| 2131 | 0x01, 0x02, 0x03, 0x04, |
| 2132 | // offset |
| 2133 | 0x3A, 0x98, 0xFE, 0xDC, |
| 2134 | 0x32, 0x10, 0x76, 0x54, |
| 2135 | // data length |
| 2136 | 0x00, 0x0c, |
| 2137 | // data |
| 2138 | 'h', 'e', 'l', 'l', |
| 2139 | 'o', ' ', 'w', 'o', |
| 2140 | 'r', 'l', 'd', '!', |
| 2141 | // paddings |
| 2142 | 0x00, 0x00, |
| 2143 | }; |
| 2144 | |
| 2145 | unsigned char packet99[] = { |
| 2146 | // type (short header, 4 byte packet number) |
| 2147 | 0x43, |
| 2148 | // connection_id |
| 2149 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2150 | // packet number |
| 2151 | 0x12, 0x34, 0x56, 0x78, |
| 2152 | |
| 2153 | // paddings |
| 2154 | 0x00, 0x00, |
| 2155 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 2156 | 0x08 | 0x01 | 0x02 | 0x04, |
| 2157 | |
| 2158 | // stream id |
| 2159 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 2160 | // offset |
| 2161 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2162 | 0x32, 0x10, 0x76, 0x54, |
| 2163 | // data length |
| 2164 | kVarInt62OneByte + 0x0c, |
| 2165 | // data |
| 2166 | 'h', 'e', 'l', 'l', |
| 2167 | 'o', ' ', 'w', 'o', |
| 2168 | 'r', 'l', 'd', '!', |
| 2169 | // paddings |
| 2170 | 0x00, 0x00, |
| 2171 | }; |
| 2172 | // clang-format on |
| 2173 | |
| 2174 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 2175 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 2176 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2177 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 2178 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 2179 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2180 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 2181 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 2185 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2186 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2187 | ASSERT_TRUE(visitor_.header_.get()); |
| 2188 | EXPECT_TRUE(CheckDecryption( |
| 2189 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2190 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2191 | |
| 2192 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2193 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2194 | EXPECT_EQ(2u, visitor_.padding_frames_.size()); |
| 2195 | EXPECT_EQ(2, visitor_.padding_frames_[0]->num_padding_bytes); |
| 2196 | EXPECT_EQ(2, visitor_.padding_frames_[1]->num_padding_bytes); |
| 2197 | EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2198 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2199 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2200 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2201 | } |
| 2202 | |
| 2203 | TEST_P(QuicFramerTest, StreamFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2204 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2205 | // clang-format off |
| 2206 | PacketFragments packet = { |
| 2207 | // public flags (8 byte connection_id) |
| 2208 | {"", |
| 2209 | {0x28}}, |
| 2210 | // connection_id |
| 2211 | {"", |
| 2212 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2213 | // packet number |
| 2214 | {"", |
| 2215 | {0x12, 0x34, 0x56, 0x78}}, |
| 2216 | // frame type (stream frame with fin) |
| 2217 | {"", |
| 2218 | {0xFF}}, |
| 2219 | // stream id |
| 2220 | {"Unable to read stream_id.", |
| 2221 | {0x01, 0x02, 0x03, 0x04}}, |
| 2222 | // offset |
| 2223 | {"Unable to read offset.", |
| 2224 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2225 | 0x32, 0x10, 0x76, 0x54}}, |
| 2226 | {"Unable to read frame data.", |
| 2227 | { |
| 2228 | // data length |
| 2229 | 0x00, 0x0c, |
| 2230 | // data |
| 2231 | 'h', 'e', 'l', 'l', |
| 2232 | 'o', ' ', 'w', 'o', |
| 2233 | 'r', 'l', 'd', '!'}}, |
| 2234 | }; |
| 2235 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2236 | PacketFragments packet46 = { |
| 2237 | // type (short header, 4 byte packet number) |
| 2238 | {"", |
| 2239 | {0x43}}, |
| 2240 | // connection_id |
| 2241 | {"", |
| 2242 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2243 | // packet number |
| 2244 | {"", |
| 2245 | {0x12, 0x34, 0x56, 0x78}}, |
| 2246 | // frame type (stream frame with fin) |
| 2247 | {"", |
| 2248 | {0xFF}}, |
| 2249 | // stream id |
| 2250 | {"Unable to read stream_id.", |
| 2251 | {0x01, 0x02, 0x03, 0x04}}, |
| 2252 | // offset |
| 2253 | {"Unable to read offset.", |
| 2254 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2255 | 0x32, 0x10, 0x76, 0x54}}, |
| 2256 | {"Unable to read frame data.", |
| 2257 | { |
| 2258 | // data length |
| 2259 | 0x00, 0x0c, |
| 2260 | // data |
| 2261 | 'h', 'e', 'l', 'l', |
| 2262 | 'o', ' ', 'w', 'o', |
| 2263 | 'r', 'l', 'd', '!'}}, |
| 2264 | }; |
| 2265 | |
| 2266 | PacketFragments packet99 = { |
| 2267 | // type (short header, 4 byte packet number) |
| 2268 | {"", |
| 2269 | {0x43}}, |
| 2270 | // connection_id |
| 2271 | {"", |
| 2272 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2273 | // packet number |
| 2274 | {"", |
| 2275 | {0x12, 0x34, 0x56, 0x78}}, |
| 2276 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 2277 | {"", |
| 2278 | { 0x08 | 0x01 | 0x02 | 0x04 }}, |
| 2279 | // stream id |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 2280 | {"Unable to read IETF_STREAM frame stream id/count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2281 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 2282 | // offset |
| 2283 | {"Unable to read stream data offset.", |
| 2284 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2285 | 0x32, 0x10, 0x76, 0x54}}, |
| 2286 | // data length |
| 2287 | {"Unable to read stream data length.", |
| 2288 | {kVarInt62OneByte + 0x0c}}, |
| 2289 | // data |
| 2290 | {"Unable to read frame data.", |
| 2291 | { 'h', 'e', 'l', 'l', |
| 2292 | 'o', ' ', 'w', 'o', |
| 2293 | 'r', 'l', 'd', '!'}}, |
| 2294 | }; |
| 2295 | // clang-format on |
| 2296 | |
| 2297 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 2298 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2299 | ? packet99 |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 2300 | : (framer_.version().HasIetfInvariantHeader() ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2301 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2302 | AssemblePacketFromFragments(fragments)); |
| 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 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2317 | |
| 2318 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2319 | } |
| 2320 | |
| 2321 | // Test an empty (no data) stream frame. |
| 2322 | TEST_P(QuicFramerTest, EmptyStreamFrame) { |
| 2323 | // Only the IETF QUIC spec explicitly says that empty |
| 2324 | // stream frames are supported. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 2325 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2326 | return; |
| 2327 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2328 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2329 | // clang-format off |
| 2330 | PacketFragments packet = { |
| 2331 | // type (short header, 4 byte packet number) |
| 2332 | {"", |
| 2333 | {0x43}}, |
| 2334 | // connection_id |
| 2335 | {"", |
| 2336 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2337 | // packet number |
| 2338 | {"", |
| 2339 | {0x12, 0x34, 0x56, 0x78}}, |
| 2340 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 2341 | {"", |
| 2342 | { 0x08 | 0x01 | 0x02 | 0x04 }}, |
| 2343 | // stream id |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 2344 | {"Unable to read IETF_STREAM frame stream id/count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2345 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 2346 | // offset |
| 2347 | {"Unable to read stream data offset.", |
| 2348 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2349 | 0x32, 0x10, 0x76, 0x54}}, |
| 2350 | // data length |
| 2351 | {"Unable to read stream data length.", |
| 2352 | {kVarInt62OneByte + 0x00}}, |
| 2353 | }; |
| 2354 | // clang-format on |
| 2355 | |
| 2356 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2357 | AssemblePacketFromFragments(packet)); |
| 2358 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2359 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2360 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2361 | ASSERT_TRUE(visitor_.header_.get()); |
| 2362 | EXPECT_TRUE(CheckDecryption( |
| 2363 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2364 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2365 | |
| 2366 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2367 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2368 | EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2369 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2370 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2371 | EXPECT_EQ(visitor_.stream_frames_[0].get()->data_length, 0u); |
| 2372 | |
| 2373 | CheckFramingBoundaries(packet, QUIC_INVALID_STREAM_DATA); |
| 2374 | } |
| 2375 | |
| 2376 | TEST_P(QuicFramerTest, MissingDiversificationNonce) { |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2377 | if (framer_.version().handshake_protocol != PROTOCOL_QUIC_CRYPTO) { |
| 2378 | // TLS does not use diversification nonces. |
| 2379 | return; |
| 2380 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2381 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2382 | decrypter_ = new test::TestDecrypter(); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2383 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 2384 | framer_.InstallDecrypter( |
| 2385 | ENCRYPTION_INITIAL, |
| 2386 | std::make_unique<NullDecrypter>(Perspective::IS_CLIENT)); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2387 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 2388 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 2389 | } else { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 2390 | framer_.SetDecrypter(ENCRYPTION_INITIAL, std::make_unique<NullDecrypter>( |
| 2391 | Perspective::IS_CLIENT)); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2392 | framer_.SetAlternativeDecrypter( |
| 2393 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 2394 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2395 | |
| 2396 | // clang-format off |
| 2397 | unsigned char packet[] = { |
| 2398 | // public flags (8 byte connection_id) |
| 2399 | 0x28, |
| 2400 | // connection_id |
| 2401 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 2402 | // packet number |
| 2403 | 0x12, 0x34, 0x56, 0x78, |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2404 | // padding frame |
| 2405 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2406 | }; |
| 2407 | |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2408 | unsigned char packet46[] = { |
| 2409 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 2410 | 0xD3, |
| 2411 | // version tag |
| 2412 | QUIC_VERSION_BYTES, |
| 2413 | // connection_id length |
| 2414 | 0x05, |
| 2415 | // connection_id |
| 2416 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 2417 | // packet number |
| 2418 | 0x12, 0x34, 0x56, 0x78, |
| 2419 | // padding frame |
| 2420 | 0x00, |
| 2421 | }; |
| 2422 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 2423 | unsigned char packet49[] = { |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2424 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 2425 | 0xD3, |
| 2426 | // version tag |
| 2427 | QUIC_VERSION_BYTES, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 2428 | // destination connection ID length |
| 2429 | 0x00, |
| 2430 | // source connection ID length |
| 2431 | 0x08, |
| 2432 | // source connection ID |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2433 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 2434 | // IETF long header payload length |
| 2435 | 0x05, |
| 2436 | // packet number |
| 2437 | 0x12, 0x34, 0x56, 0x78, |
| 2438 | // padding frame |
| 2439 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2440 | }; |
| 2441 | // clang-format on |
| 2442 | |
| 2443 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 2444 | size_t p_length = ABSL_ARRAYSIZE(packet); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 2445 | if (framer_.version().HasLongHeaderLengths()) { |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 2446 | p = packet49; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 2447 | p_length = ABSL_ARRAYSIZE(packet49); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 2448 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2449 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 2450 | p_length = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2451 | } |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2452 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2453 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 2454 | if (framer_.version().HasHeaderProtection()) { |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2455 | EXPECT_THAT(framer_.error(), IsError(QUIC_DECRYPTION_FAILURE)); |
dschinazi | 163bda2 | 2020-04-01 13:34:43 -0700 | [diff] [blame] | 2456 | EXPECT_EQ("Unable to decrypt ENCRYPTION_ZERO_RTT header protection.", |
| 2457 | framer_.detailed_error()); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 2458 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2459 | // Cannot read diversification nonce. |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2460 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 2461 | EXPECT_EQ("Unable to read nonce.", framer_.detailed_error()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2462 | } else { |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2463 | EXPECT_THAT(framer_.error(), IsError(QUIC_DECRYPTION_FAILURE)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2464 | } |
| 2465 | } |
| 2466 | |
| 2467 | TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) { |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 2468 | if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2469 | // This test is nonsensical for IETF Quic. |
| 2470 | return; |
| 2471 | } |
| 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 | {0xFE}}, |
| 2486 | // stream id |
| 2487 | {"Unable to read stream_id.", |
| 2488 | {0x02, 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 | // clang-format on |
| 2503 | |
| 2504 | PacketFragments& fragments = packet; |
| 2505 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2506 | AssemblePacketFromFragments(fragments)); |
| 2507 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2508 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2509 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2510 | ASSERT_TRUE(visitor_.header_.get()); |
| 2511 | EXPECT_TRUE(CheckDecryption( |
| 2512 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2513 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2514 | |
| 2515 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2516 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2517 | // Stream ID should be the last 3 bytes of kStreamId. |
| 2518 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2519 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2520 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2521 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2522 | |
| 2523 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2524 | } |
| 2525 | |
| 2526 | TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2527 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2528 | // clang-format off |
| 2529 | PacketFragments packet = { |
| 2530 | // public flags (8 byte connection_id) |
| 2531 | {"", |
| 2532 | {0x28}}, |
| 2533 | // connection_id |
| 2534 | {"", |
| 2535 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2536 | // packet number |
| 2537 | {"", |
| 2538 | {0x12, 0x34, 0x56, 0x78}}, |
| 2539 | // frame type (stream frame with fin) |
| 2540 | {"", |
| 2541 | {0xFD}}, |
| 2542 | // stream id |
| 2543 | {"Unable to read stream_id.", |
| 2544 | {0x03, 0x04}}, |
| 2545 | // offset |
| 2546 | {"Unable to read offset.", |
| 2547 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2548 | 0x32, 0x10, 0x76, 0x54}}, |
| 2549 | {"Unable to read frame data.", |
| 2550 | { |
| 2551 | // data length |
| 2552 | 0x00, 0x0c, |
| 2553 | // data |
| 2554 | 'h', 'e', 'l', 'l', |
| 2555 | 'o', ' ', 'w', 'o', |
| 2556 | 'r', 'l', 'd', '!'}}, |
| 2557 | }; |
| 2558 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2559 | PacketFragments packet46 = { |
| 2560 | // type (short header, 4 byte packet number) |
| 2561 | {"", |
| 2562 | {0x43}}, |
| 2563 | // connection_id |
| 2564 | {"", |
| 2565 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2566 | // packet number |
| 2567 | {"", |
| 2568 | {0x12, 0x34, 0x56, 0x78}}, |
| 2569 | // frame type (stream frame with fin) |
| 2570 | {"", |
| 2571 | {0xFD}}, |
| 2572 | // stream id |
| 2573 | {"Unable to read stream_id.", |
| 2574 | {0x03, 0x04}}, |
| 2575 | // offset |
| 2576 | {"Unable to read offset.", |
| 2577 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2578 | 0x32, 0x10, 0x76, 0x54}}, |
| 2579 | {"Unable to read frame data.", |
| 2580 | { |
| 2581 | // data length |
| 2582 | 0x00, 0x0c, |
| 2583 | // data |
| 2584 | 'h', 'e', 'l', 'l', |
| 2585 | 'o', ' ', 'w', 'o', |
| 2586 | 'r', 'l', 'd', '!'}}, |
| 2587 | }; |
| 2588 | |
| 2589 | PacketFragments packet99 = { |
| 2590 | // type (short header, 4 byte packet number) |
| 2591 | {"", |
| 2592 | {0x43}}, |
| 2593 | // connection_id |
| 2594 | {"", |
| 2595 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2596 | // packet number |
| 2597 | {"", |
| 2598 | {0x12, 0x34, 0x56, 0x78}}, |
| 2599 | // frame type (IETF_STREAM frame with LEN, FIN, and OFFSET bits set) |
| 2600 | {"", |
| 2601 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2602 | // stream id |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 2603 | {"Unable to read IETF_STREAM frame stream id/count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2604 | {kVarInt62TwoBytes + 0x03, 0x04}}, |
| 2605 | // offset |
| 2606 | {"Unable to read stream data offset.", |
| 2607 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2608 | 0x32, 0x10, 0x76, 0x54}}, |
| 2609 | // data length |
| 2610 | {"Unable to read stream data length.", |
| 2611 | {kVarInt62OneByte + 0x0c}}, |
| 2612 | // data |
| 2613 | {"Unable to read frame data.", |
| 2614 | { 'h', 'e', 'l', 'l', |
| 2615 | 'o', ' ', 'w', 'o', |
| 2616 | 'r', 'l', 'd', '!'}}, |
| 2617 | }; |
| 2618 | // clang-format on |
| 2619 | |
| 2620 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 2621 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2622 | ? packet99 |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 2623 | : (framer_.version().HasIetfInvariantHeader() ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2624 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2625 | AssemblePacketFromFragments(fragments)); |
| 2626 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2627 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2628 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2629 | ASSERT_TRUE(visitor_.header_.get()); |
| 2630 | EXPECT_TRUE(CheckDecryption( |
| 2631 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2632 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2633 | |
| 2634 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2635 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2636 | // Stream ID should be the last 2 bytes of kStreamId. |
| 2637 | EXPECT_EQ(0x0000FFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2638 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2639 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2640 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2641 | |
| 2642 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2643 | } |
| 2644 | |
| 2645 | TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2646 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2647 | // clang-format off |
| 2648 | PacketFragments packet = { |
| 2649 | // public flags (8 byte connection_id) |
| 2650 | {"", |
| 2651 | {0x28}}, |
| 2652 | // connection_id |
| 2653 | {"", |
| 2654 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2655 | // packet number |
| 2656 | {"", |
| 2657 | {0x12, 0x34, 0x56, 0x78}}, |
| 2658 | // frame type (stream frame with fin) |
| 2659 | {"", |
| 2660 | {0xFC}}, |
| 2661 | // stream id |
| 2662 | {"Unable to read stream_id.", |
| 2663 | {0x04}}, |
| 2664 | // offset |
| 2665 | {"Unable to read offset.", |
| 2666 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2667 | 0x32, 0x10, 0x76, 0x54}}, |
| 2668 | {"Unable to read frame data.", |
| 2669 | { |
| 2670 | // data length |
| 2671 | 0x00, 0x0c, |
| 2672 | // data |
| 2673 | 'h', 'e', 'l', 'l', |
| 2674 | 'o', ' ', 'w', 'o', |
| 2675 | 'r', 'l', 'd', '!'}}, |
| 2676 | }; |
| 2677 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2678 | PacketFragments packet46 = { |
| 2679 | // type (short header, 4 byte packet number) |
| 2680 | {"", |
| 2681 | {0x43}}, |
| 2682 | // connection_id |
| 2683 | {"", |
| 2684 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2685 | // packet number |
| 2686 | {"", |
| 2687 | {0x12, 0x34, 0x56, 0x78}}, |
| 2688 | // frame type (stream frame with fin) |
| 2689 | {"", |
| 2690 | {0xFC}}, |
| 2691 | // stream id |
| 2692 | {"Unable to read stream_id.", |
| 2693 | {0x04}}, |
| 2694 | // offset |
| 2695 | {"Unable to read offset.", |
| 2696 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2697 | 0x32, 0x10, 0x76, 0x54}}, |
| 2698 | {"Unable to read frame data.", |
| 2699 | { |
| 2700 | // data length |
| 2701 | 0x00, 0x0c, |
| 2702 | // data |
| 2703 | 'h', 'e', 'l', 'l', |
| 2704 | 'o', ' ', 'w', 'o', |
| 2705 | 'r', 'l', 'd', '!'}}, |
| 2706 | }; |
| 2707 | |
| 2708 | PacketFragments packet99 = { |
| 2709 | // type (short header, 4 byte packet number) |
| 2710 | {"", |
| 2711 | {0x43}}, |
| 2712 | // connection_id |
| 2713 | {"", |
| 2714 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2715 | // packet number |
| 2716 | {"", |
| 2717 | {0x12, 0x34, 0x56, 0x78}}, |
| 2718 | // frame type (IETF_STREAM frame with LEN, FIN, and OFFSET bits set) |
| 2719 | {"", |
| 2720 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2721 | // stream id |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 2722 | {"Unable to read IETF_STREAM frame stream id/count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2723 | {kVarInt62OneByte + 0x04}}, |
| 2724 | // offset |
| 2725 | {"Unable to read stream data offset.", |
| 2726 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2727 | 0x32, 0x10, 0x76, 0x54}}, |
| 2728 | // data length |
| 2729 | {"Unable to read stream data length.", |
| 2730 | {kVarInt62OneByte + 0x0c}}, |
| 2731 | // data |
| 2732 | {"Unable to read frame data.", |
| 2733 | { 'h', 'e', 'l', 'l', |
| 2734 | 'o', ' ', 'w', 'o', |
| 2735 | 'r', 'l', 'd', '!'}}, |
| 2736 | }; |
| 2737 | // clang-format on |
| 2738 | |
| 2739 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 2740 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2741 | ? packet99 |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 2742 | : (framer_.version().HasIetfInvariantHeader() ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2743 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2744 | AssemblePacketFromFragments(fragments)); |
| 2745 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2746 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2747 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2748 | ASSERT_TRUE(visitor_.header_.get()); |
| 2749 | EXPECT_TRUE(CheckDecryption( |
| 2750 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2751 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2752 | |
| 2753 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2754 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2755 | // Stream ID should be the last 1 byte of kStreamId. |
| 2756 | EXPECT_EQ(0x000000FF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2757 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2758 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2759 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2760 | |
| 2761 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2762 | } |
| 2763 | |
| 2764 | TEST_P(QuicFramerTest, StreamFrameWithVersion) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 2765 | // If IETF frames are in use then we must also have the IETF |
| 2766 | // header invariants. |
| 2767 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 2768 | DCHECK(VersionHasIetfInvariantHeader(framer_.transport_version())); |
| 2769 | } |
| 2770 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2771 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2772 | // clang-format off |
| 2773 | PacketFragments packet = { |
| 2774 | // public flags (version, 8 byte connection_id) |
| 2775 | {"", |
| 2776 | {0x29}}, |
| 2777 | // connection_id |
| 2778 | {"", |
| 2779 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2780 | // version tag |
| 2781 | {"", |
| 2782 | {QUIC_VERSION_BYTES}}, |
| 2783 | // packet number |
| 2784 | {"", |
| 2785 | {0x12, 0x34, 0x56, 0x78}}, |
| 2786 | // frame type (stream frame with fin) |
| 2787 | {"", |
| 2788 | {0xFE}}, |
| 2789 | // stream id |
| 2790 | {"Unable to read stream_id.", |
| 2791 | {0x02, 0x03, 0x04}}, |
| 2792 | // offset |
| 2793 | {"Unable to read offset.", |
| 2794 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2795 | 0x32, 0x10, 0x76, 0x54}}, |
| 2796 | {"Unable to read frame data.", |
| 2797 | { |
| 2798 | // data length |
| 2799 | 0x00, 0x0c, |
| 2800 | // data |
| 2801 | 'h', 'e', 'l', 'l', |
| 2802 | 'o', ' ', 'w', 'o', |
| 2803 | 'r', 'l', 'd', '!'}}, |
| 2804 | }; |
| 2805 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2806 | PacketFragments packet46 = { |
| 2807 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 2808 | // 4-byte packet number) |
| 2809 | {"", |
| 2810 | {0xD3}}, |
| 2811 | // version tag |
| 2812 | {"", |
| 2813 | {QUIC_VERSION_BYTES}}, |
| 2814 | // connection_id length |
| 2815 | {"", |
| 2816 | {0x50}}, |
| 2817 | // connection_id |
| 2818 | {"", |
| 2819 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2820 | // packet number |
| 2821 | {"", |
| 2822 | {0x12, 0x34, 0x56, 0x78}}, |
| 2823 | // frame type (stream frame with fin) |
| 2824 | {"", |
| 2825 | {0xFE}}, |
| 2826 | // stream id |
| 2827 | {"Unable to read stream_id.", |
| 2828 | {0x02, 0x03, 0x04}}, |
| 2829 | // offset |
| 2830 | {"Unable to read offset.", |
| 2831 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2832 | 0x32, 0x10, 0x76, 0x54}}, |
| 2833 | {"Unable to read frame data.", |
| 2834 | { |
| 2835 | // data length |
| 2836 | 0x00, 0x0c, |
| 2837 | // data |
| 2838 | 'h', 'e', 'l', 'l', |
| 2839 | 'o', ' ', 'w', 'o', |
| 2840 | 'r', 'l', 'd', '!'}}, |
| 2841 | }; |
| 2842 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 2843 | PacketFragments packet49 = { |
| 2844 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 2845 | // 4-byte packet number) |
| 2846 | {"", |
| 2847 | {0xD3}}, |
| 2848 | // version tag |
| 2849 | {"", |
| 2850 | {QUIC_VERSION_BYTES}}, |
| 2851 | // destination connection ID length |
| 2852 | {"", |
| 2853 | {0x08}}, |
| 2854 | // destination connection ID |
| 2855 | {"", |
| 2856 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2857 | // source connection ID length |
| 2858 | {"", |
| 2859 | {0x00}}, |
| 2860 | // long header packet length |
| 2861 | {"", |
| 2862 | {0x1E}}, |
| 2863 | // packet number |
| 2864 | {"", |
| 2865 | {0x12, 0x34, 0x56, 0x78}}, |
| 2866 | // frame type (stream frame with fin) |
| 2867 | {"", |
| 2868 | {0xFE}}, |
| 2869 | // stream id |
| 2870 | {"Long header payload length longer than packet.", |
| 2871 | {0x02, 0x03, 0x04}}, |
| 2872 | // offset |
| 2873 | {"Long header payload length longer than packet.", |
| 2874 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2875 | 0x32, 0x10, 0x76, 0x54}}, |
| 2876 | {"Long header payload length longer than packet.", |
| 2877 | { |
| 2878 | // data length |
| 2879 | 0x00, 0x0c, |
| 2880 | // data |
| 2881 | 'h', 'e', 'l', 'l', |
| 2882 | 'o', ' ', 'w', 'o', |
| 2883 | 'r', 'l', 'd', '!'}}, |
| 2884 | }; |
| 2885 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2886 | PacketFragments packet99 = { |
| 2887 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 2888 | // 4-byte packet number) |
| 2889 | {"", |
| 2890 | {0xD3}}, |
| 2891 | // version tag |
| 2892 | {"", |
| 2893 | {QUIC_VERSION_BYTES}}, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 2894 | // destination connection ID length |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2895 | {"", |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 2896 | {0x08}}, |
| 2897 | // destination connection ID |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2898 | {"", |
| 2899 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 2900 | // source connection ID length |
| 2901 | {"", |
| 2902 | {0x00}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2903 | // long header packet length |
| 2904 | {"", |
| 2905 | {0x1E}}, |
| 2906 | // packet number |
| 2907 | {"", |
| 2908 | {0x12, 0x34, 0x56, 0x78}}, |
| 2909 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 2910 | {"", |
| 2911 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2912 | // stream id |
| 2913 | {"Long header payload length longer than packet.", |
| 2914 | {kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04}}, |
| 2915 | // offset |
| 2916 | {"Long header payload length longer than packet.", |
| 2917 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2918 | 0x32, 0x10, 0x76, 0x54}}, |
| 2919 | // data length |
| 2920 | {"Long header payload length longer than packet.", |
| 2921 | {kVarInt62OneByte + 0x0c}}, |
| 2922 | // data |
| 2923 | {"Long header payload length longer than packet.", |
| 2924 | { 'h', 'e', 'l', 'l', |
| 2925 | 'o', ' ', 'w', 'o', |
| 2926 | 'r', 'l', 'd', '!'}}, |
| 2927 | }; |
| 2928 | // clang-format on |
| 2929 | |
| 2930 | QuicVariableLengthIntegerLength retry_token_length_length = |
| 2931 | VARIABLE_LENGTH_INTEGER_LENGTH_0; |
| 2932 | size_t retry_token_length = 0; |
| 2933 | QuicVariableLengthIntegerLength length_length = |
| 2934 | QuicVersionHasLongHeaderLengths(framer_.transport_version()) |
| 2935 | ? VARIABLE_LENGTH_INTEGER_LENGTH_1 |
| 2936 | : VARIABLE_LENGTH_INTEGER_LENGTH_0; |
| 2937 | |
| 2938 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 2939 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2940 | ? packet99 |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 2941 | : (framer_.version().HasLongHeaderLengths() |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 2942 | ? packet49 |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 2943 | : (framer_.version().HasIetfInvariantHeader() ? packet46 |
| 2944 | : packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2945 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2946 | AssemblePacketFromFragments(fragments)); |
| 2947 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2948 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 2949 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2950 | ASSERT_TRUE(visitor_.header_.get()); |
| 2951 | EXPECT_TRUE(CheckDecryption( |
| 2952 | *encrypted, kIncludeVersion, !kIncludeDiversificationNonce, |
| 2953 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID, |
| 2954 | retry_token_length_length, retry_token_length, length_length)); |
| 2955 | |
| 2956 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2957 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2958 | // Stream ID should be the last 3 bytes of kStreamId. |
| 2959 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2960 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2961 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2962 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2963 | |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 2964 | CheckFramingBoundaries(fragments, framer_.version().HasLongHeaderLengths() |
| 2965 | ? QUIC_INVALID_PACKET_HEADER |
| 2966 | : QUIC_INVALID_STREAM_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | TEST_P(QuicFramerTest, RejectPacket) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 2970 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2971 | visitor_.accept_packet_ = false; |
| 2972 | |
| 2973 | // clang-format off |
| 2974 | unsigned char packet[] = { |
| 2975 | // public flags (8 byte connection_id) |
| 2976 | 0x28, |
| 2977 | // connection_id |
| 2978 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2979 | // packet number |
| 2980 | 0x12, 0x34, 0x56, 0x78, |
| 2981 | |
| 2982 | // frame type (stream frame with fin) |
| 2983 | 0xFF, |
| 2984 | // stream id |
| 2985 | 0x01, 0x02, 0x03, 0x04, |
| 2986 | // offset |
| 2987 | 0x3A, 0x98, 0xFE, 0xDC, |
| 2988 | 0x32, 0x10, 0x76, 0x54, |
| 2989 | // data length |
| 2990 | 0x00, 0x0c, |
| 2991 | // data |
| 2992 | 'h', 'e', 'l', 'l', |
| 2993 | 'o', ' ', 'w', 'o', |
| 2994 | 'r', 'l', 'd', '!', |
| 2995 | }; |
| 2996 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 2997 | unsigned char packet46[] = { |
| 2998 | // type (short header, 4 byte packet number) |
| 2999 | 0x43, |
| 3000 | // connection_id |
| 3001 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3002 | // packet number |
| 3003 | 0x12, 0x34, 0x56, 0x78, |
| 3004 | |
| 3005 | // frame type (STREAM Frame with FIN, LEN, and OFFSET bits set) |
| 3006 | 0x10 | 0x01 | 0x02 | 0x04, |
| 3007 | // stream id |
| 3008 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 3009 | // offset |
| 3010 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 3011 | 0x32, 0x10, 0x76, 0x54, |
| 3012 | // data length |
| 3013 | kVarInt62OneByte + 0x0c, |
| 3014 | // data |
| 3015 | 'h', 'e', 'l', 'l', |
| 3016 | 'o', ' ', 'w', 'o', |
| 3017 | 'r', 'l', 'd', '!', |
| 3018 | }; |
| 3019 | // clang-format on |
| 3020 | |
| 3021 | unsigned char* p = packet; |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 3022 | if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3023 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3024 | } |
| 3025 | QuicEncryptedPacket encrypted(AsChars(p), |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 3026 | framer_.version().HasIetfInvariantHeader() |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 3027 | ? ABSL_ARRAYSIZE(packet46) |
| 3028 | : ABSL_ARRAYSIZE(packet), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3029 | false); |
| 3030 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 3031 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 3032 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3033 | ASSERT_TRUE(visitor_.header_.get()); |
| 3034 | EXPECT_TRUE(CheckDecryption( |
| 3035 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3036 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3037 | |
| 3038 | ASSERT_EQ(0u, visitor_.stream_frames_.size()); |
| 3039 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 3040 | } |
| 3041 | |
| 3042 | TEST_P(QuicFramerTest, RejectPublicHeader) { |
| 3043 | visitor_.accept_public_header_ = false; |
| 3044 | |
| 3045 | // clang-format off |
| 3046 | unsigned char packet[] = { |
| 3047 | // public flags (8 byte connection_id) |
| 3048 | 0x28, |
| 3049 | // connection_id |
| 3050 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3051 | }; |
| 3052 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3053 | unsigned char packet46[] = { |
| 3054 | // type (short header, 1 byte packet number) |
| 3055 | 0x40, |
| 3056 | // connection_id |
| 3057 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3058 | // packet number |
| 3059 | 0x01, |
| 3060 | }; |
| 3061 | // clang-format on |
| 3062 | |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 3063 | QuicEncryptedPacket encrypted( |
| 3064 | framer_.version().HasIetfInvariantHeader() ? AsChars(packet46) |
| 3065 | : AsChars(packet), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 3066 | framer_.version().HasIetfInvariantHeader() ? ABSL_ARRAYSIZE(packet46) |
| 3067 | : ABSL_ARRAYSIZE(packet), |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 3068 | false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3069 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 3070 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 3071 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3072 | ASSERT_TRUE(visitor_.header_.get()); |
| 3073 | EXPECT_FALSE(visitor_.header_->packet_number.IsInitialized()); |
| 3074 | } |
| 3075 | |
| 3076 | TEST_P(QuicFramerTest, AckFrameOneAckBlock) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3077 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3078 | // clang-format off |
| 3079 | PacketFragments packet = { |
| 3080 | // public flags (8 byte connection_id) |
| 3081 | {"", |
| 3082 | {0x2C}}, |
| 3083 | // connection_id |
| 3084 | {"", |
| 3085 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3086 | // packet number |
| 3087 | {"", |
| 3088 | {0x12, 0x34, 0x56, 0x78}}, |
| 3089 | // frame type (ack frame) |
| 3090 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 3091 | {"", |
| 3092 | {0x45}}, |
| 3093 | // largest acked |
| 3094 | {"Unable to read largest acked.", |
| 3095 | {0x12, 0x34}}, |
| 3096 | // Zero delta time. |
| 3097 | {"Unable to read ack delay time.", |
| 3098 | {0x00, 0x00}}, |
| 3099 | // first ack block length. |
| 3100 | {"Unable to read first ack block length.", |
| 3101 | {0x12, 0x34}}, |
| 3102 | // num timestamps. |
| 3103 | {"Unable to read num received packets.", |
| 3104 | {0x00}} |
| 3105 | }; |
| 3106 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3107 | PacketFragments packet46 = { |
| 3108 | // type (short packet, 4 byte packet number) |
| 3109 | {"", |
| 3110 | {0x43}}, |
| 3111 | // connection_id |
| 3112 | {"", |
| 3113 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3114 | // packet number |
| 3115 | {"", |
| 3116 | {0x12, 0x34, 0x56, 0x78}}, |
| 3117 | // frame type (ack frame) |
| 3118 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 3119 | {"", |
| 3120 | {0x45}}, |
| 3121 | // largest acked |
| 3122 | {"Unable to read largest acked.", |
| 3123 | {0x12, 0x34}}, |
| 3124 | // Zero delta time. |
| 3125 | {"Unable to read ack delay time.", |
| 3126 | {0x00, 0x00}}, |
| 3127 | // first ack block length. |
| 3128 | {"Unable to read first ack block length.", |
| 3129 | {0x12, 0x34}}, |
| 3130 | // num timestamps. |
| 3131 | {"Unable to read num received packets.", |
| 3132 | {0x00}} |
| 3133 | }; |
| 3134 | |
| 3135 | PacketFragments packet99 = { |
| 3136 | // type (short packet, 4 byte packet number) |
| 3137 | {"", |
| 3138 | {0x43}}, |
| 3139 | // connection_id |
| 3140 | {"", |
| 3141 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3142 | // packet number |
| 3143 | {"", |
| 3144 | {0x12, 0x34, 0x56, 0x78}}, |
| 3145 | // frame type (IETF_ACK) |
| 3146 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 3147 | // IETF-Quic ignores the bit-fields in the ack type, all of |
| 3148 | // that information is encoded elsewhere in the frame. |
| 3149 | {"", |
| 3150 | {0x02}}, |
| 3151 | // largest acked |
| 3152 | {"Unable to read largest acked.", |
| 3153 | {kVarInt62TwoBytes + 0x12, 0x34}}, |
| 3154 | // Zero delta time. |
| 3155 | {"Unable to read ack delay time.", |
| 3156 | {kVarInt62OneByte + 0x00}}, |
| 3157 | // Ack block count (0 -- no blocks after the first) |
| 3158 | {"Unable to read ack block count.", |
| 3159 | {kVarInt62OneByte + 0x00}}, |
| 3160 | // first ack block length - 1. |
| 3161 | // IETF Quic defines the ack block's value as the "number of |
| 3162 | // packets that preceed the largest packet number in the block" |
| 3163 | // which for the 1st ack block is the largest acked field, |
| 3164 | // above. This means that if we are acking just packet 0x1234 |
| 3165 | // then the 1st ack block will be 0. |
| 3166 | {"Unable to read first ack block length.", |
| 3167 | {kVarInt62TwoBytes + 0x12, 0x33}} |
| 3168 | }; |
| 3169 | // clang-format on |
| 3170 | |
| 3171 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3172 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3173 | ? packet99 |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 3174 | : (framer_.version().HasIetfInvariantHeader() ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3175 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3176 | AssemblePacketFromFragments(fragments)); |
| 3177 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3178 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 3179 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3180 | ASSERT_TRUE(visitor_.header_.get()); |
| 3181 | EXPECT_TRUE(CheckDecryption( |
| 3182 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3183 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3184 | |
| 3185 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3186 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3187 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3188 | EXPECT_EQ(kSmallLargestObserved, LargestAcked(frame)); |
| 3189 | ASSERT_EQ(4660u, frame.packets.NumPacketsSlow()); |
| 3190 | |
| 3191 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3192 | } |
| 3193 | |
| 3194 | // This test checks that the ack frame processor correctly identifies |
| 3195 | // and handles the case where the first ack block is larger than the |
| 3196 | // largest_acked packet. |
| 3197 | TEST_P(QuicFramerTest, FirstAckFrameUnderflow) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3198 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3199 | // clang-format off |
| 3200 | PacketFragments packet = { |
| 3201 | // public flags (8 byte connection_id) |
| 3202 | {"", |
| 3203 | {0x2C}}, |
| 3204 | // connection_id |
| 3205 | {"", |
| 3206 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3207 | // packet number |
| 3208 | {"", |
| 3209 | {0x12, 0x34, 0x56, 0x78}}, |
| 3210 | // frame type (ack frame) |
| 3211 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 3212 | {"", |
| 3213 | {0x45}}, |
| 3214 | // largest acked |
| 3215 | {"Unable to read largest acked.", |
| 3216 | {0x12, 0x34}}, |
| 3217 | // Zero delta time. |
| 3218 | {"Unable to read ack delay time.", |
| 3219 | {0x00, 0x00}}, |
| 3220 | // first ack block length. |
| 3221 | {"Unable to read first ack block length.", |
| 3222 | {0x88, 0x88}}, |
| 3223 | // num timestamps. |
| 3224 | {"Underflow with first ack block length 34952 largest acked is 4660.", |
| 3225 | {0x00}} |
| 3226 | }; |
| 3227 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3228 | PacketFragments packet46 = { |
| 3229 | // type (short header, 4 byte packet number) |
| 3230 | {"", |
| 3231 | {0x43}}, |
| 3232 | // connection_id |
| 3233 | {"", |
| 3234 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3235 | // packet number |
| 3236 | {"", |
| 3237 | {0x12, 0x34, 0x56, 0x78}}, |
| 3238 | // frame type (ack frame) |
| 3239 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 3240 | {"", |
| 3241 | {0x45}}, |
| 3242 | // largest acked |
| 3243 | {"Unable to read largest acked.", |
| 3244 | {0x12, 0x34}}, |
| 3245 | // Zero delta time. |
| 3246 | {"Unable to read ack delay time.", |
| 3247 | {0x00, 0x00}}, |
| 3248 | // first ack block length. |
| 3249 | {"Unable to read first ack block length.", |
| 3250 | {0x88, 0x88}}, |
| 3251 | // num timestamps. |
| 3252 | {"Underflow with first ack block length 34952 largest acked is 4660.", |
| 3253 | {0x00}} |
| 3254 | }; |
| 3255 | |
| 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) |
| 3267 | {"", |
| 3268 | {0x02}}, |
| 3269 | // largest acked |
| 3270 | {"Unable to read largest acked.", |
| 3271 | {kVarInt62TwoBytes + 0x12, 0x34}}, |
| 3272 | // Zero delta time. |
| 3273 | {"Unable to read ack delay time.", |
| 3274 | {kVarInt62OneByte + 0x00}}, |
| 3275 | // Ack block count (0 -- no blocks after the first) |
| 3276 | {"Unable to read ack block count.", |
| 3277 | {kVarInt62OneByte + 0x00}}, |
| 3278 | // first ack block length. |
| 3279 | {"Unable to read first ack block length.", |
| 3280 | {kVarInt62TwoBytes + 0x28, 0x88}} |
| 3281 | }; |
| 3282 | // clang-format on |
| 3283 | |
| 3284 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3285 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3286 | ? packet99 |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 3287 | : (framer_.version().HasIetfInvariantHeader() ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3288 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3289 | AssemblePacketFromFragments(fragments)); |
| 3290 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3291 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3292 | } |
| 3293 | |
| 3294 | // This test checks that the ack frame processor correctly identifies |
| 3295 | // and handles the case where the third ack block's gap is larger than the |
| 3296 | // available space in the ack range. |
| 3297 | TEST_P(QuicFramerTest, ThirdAckBlockUnderflowGap) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3298 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 3299 | // Test originally written for development of IETF QUIC. The test may |
| 3300 | // also apply to Google QUIC. If so, the test should be extended to |
| 3301 | // include Google QUIC (frame formats, etc). See b/141858819. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3302 | return; |
| 3303 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3304 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3305 | // clang-format off |
| 3306 | PacketFragments packet99 = { |
| 3307 | // type (short header, 4 byte packet number) |
| 3308 | {"", |
| 3309 | {0x43}}, |
| 3310 | // connection_id |
| 3311 | {"", |
| 3312 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3313 | // packet number |
| 3314 | {"", |
| 3315 | {0x12, 0x34, 0x56, 0x78}}, |
| 3316 | // frame type (IETF_ACK frame) |
| 3317 | {"", |
| 3318 | {0x02}}, |
| 3319 | // largest acked |
| 3320 | {"Unable to read largest acked.", |
| 3321 | {kVarInt62OneByte + 63}}, |
| 3322 | // Zero delta time. |
| 3323 | {"Unable to read ack delay time.", |
| 3324 | {kVarInt62OneByte + 0x00}}, |
| 3325 | // Ack block count (2 -- 2 blocks after the first) |
| 3326 | {"Unable to read ack block count.", |
| 3327 | {kVarInt62OneByte + 0x02}}, |
| 3328 | // first ack block length. |
| 3329 | {"Unable to read first ack block length.", |
| 3330 | {kVarInt62OneByte + 13}}, // Ack 14 packets, range 50..63 (inclusive) |
| 3331 | |
| 3332 | {"Unable to read gap block value.", |
| 3333 | {kVarInt62OneByte + 9}}, // Gap 10 packets, 40..49 (inclusive) |
| 3334 | {"Unable to read ack block value.", |
| 3335 | {kVarInt62OneByte + 9}}, // Ack 10 packets, 30..39 (inclusive) |
| 3336 | {"Unable to read gap block value.", |
| 3337 | {kVarInt62OneByte + 29}}, // A gap of 30 packets (0..29 inclusive) |
| 3338 | // should be too big, leaving no room |
| 3339 | // for the ack. |
| 3340 | {"Underflow with gap block length 30 previous ack block start is 30.", |
| 3341 | {kVarInt62OneByte + 10}}, // Don't care |
| 3342 | }; |
| 3343 | // clang-format on |
| 3344 | |
| 3345 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3346 | AssemblePacketFromFragments(packet99)); |
| 3347 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3348 | EXPECT_EQ( |
| 3349 | framer_.detailed_error(), |
| 3350 | "Underflow with gap block length 30 previous ack block start is 30."); |
| 3351 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3352 | } |
| 3353 | |
| 3354 | // This test checks that the ack frame processor correctly identifies |
| 3355 | // and handles the case where the third ack block's length is larger than the |
| 3356 | // available space in the ack range. |
| 3357 | TEST_P(QuicFramerTest, ThirdAckBlockUnderflowAck) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3358 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 3359 | // Test originally written for development of IETF QUIC. The test may |
| 3360 | // also apply to Google QUIC. If so, the test should be extended to |
| 3361 | // include Google QUIC (frame formats, etc). See b/141858819. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3362 | return; |
| 3363 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3364 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3365 | // clang-format off |
| 3366 | PacketFragments packet99 = { |
| 3367 | // type (short header, 4 byte packet number) |
| 3368 | {"", |
| 3369 | {0x43}}, |
| 3370 | // connection_id |
| 3371 | {"", |
| 3372 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3373 | // packet number |
| 3374 | {"", |
| 3375 | {0x12, 0x34, 0x56, 0x78}}, |
| 3376 | // frame type (IETF_ACK frame) |
| 3377 | {"", |
| 3378 | {0x02}}, |
| 3379 | // largest acked |
| 3380 | {"Unable to read largest acked.", |
| 3381 | {kVarInt62OneByte + 63}}, |
| 3382 | // Zero delta time. |
| 3383 | {"Unable to read ack delay time.", |
| 3384 | {kVarInt62OneByte + 0x00}}, |
| 3385 | // Ack block count (2 -- 2 blocks after the first) |
| 3386 | {"Unable to read ack block count.", |
| 3387 | {kVarInt62OneByte + 0x02}}, |
| 3388 | // first ack block length. |
| 3389 | {"Unable to read first ack block length.", |
| 3390 | {kVarInt62OneByte + 13}}, // only 50 packet numbers "left" |
| 3391 | |
| 3392 | {"Unable to read gap block value.", |
| 3393 | {kVarInt62OneByte + 10}}, // Only 40 packet numbers left |
| 3394 | {"Unable to read ack block value.", |
| 3395 | {kVarInt62OneByte + 10}}, // only 30 packet numbers left. |
| 3396 | {"Unable to read gap block value.", |
| 3397 | {kVarInt62OneByte + 1}}, // Gap is OK, 29 packet numbers left |
| 3398 | {"Unable to read ack block value.", |
| 3399 | {kVarInt62OneByte + 30}}, // Use up all 30, should be an error |
| 3400 | }; |
| 3401 | // clang-format on |
| 3402 | |
| 3403 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3404 | AssemblePacketFromFragments(packet99)); |
| 3405 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3406 | EXPECT_EQ(framer_.detailed_error(), |
| 3407 | "Underflow with ack block length 31 latest ack block end is 25."); |
| 3408 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3409 | } |
| 3410 | |
| 3411 | // Tests a variety of ack block wrap scenarios. For example, if the |
| 3412 | // N-1th block causes packet 0 to be acked, then a gap would wrap |
| 3413 | // around to 0x3fffffff ffffffff... Make sure we detect this |
| 3414 | // condition. |
| 3415 | TEST_P(QuicFramerTest, AckBlockUnderflowGapWrap) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3416 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 3417 | // Test originally written for development of IETF QUIC. The test may |
| 3418 | // also apply to Google QUIC. If so, the test should be extended to |
| 3419 | // include Google QUIC (frame formats, etc). See b/141858819. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3420 | return; |
| 3421 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3422 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3423 | // clang-format off |
| 3424 | PacketFragments packet99 = { |
| 3425 | // type (short header, 4 byte packet number) |
| 3426 | {"", |
| 3427 | {0x43}}, |
| 3428 | // connection_id |
| 3429 | {"", |
| 3430 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3431 | // packet number |
| 3432 | {"", |
| 3433 | {0x12, 0x34, 0x56, 0x78}}, |
| 3434 | // frame type (IETF_ACK frame) |
| 3435 | {"", |
| 3436 | {0x02}}, |
| 3437 | // largest acked |
| 3438 | {"Unable to read largest acked.", |
| 3439 | {kVarInt62OneByte + 10}}, |
| 3440 | // Zero delta time. |
| 3441 | {"Unable to read ack delay time.", |
| 3442 | {kVarInt62OneByte + 0x00}}, |
| 3443 | // Ack block count (1 -- 1 blocks after the first) |
| 3444 | {"Unable to read ack block count.", |
| 3445 | {kVarInt62OneByte + 1}}, |
| 3446 | // first ack block length. |
| 3447 | {"Unable to read first ack block length.", |
| 3448 | {kVarInt62OneByte + 9}}, // Ack packets 1..10 (inclusive) |
| 3449 | |
| 3450 | {"Unable to read gap block value.", |
| 3451 | {kVarInt62OneByte + 1}}, // Gap of 2 packets (-1...0), should wrap |
| 3452 | {"Underflow with gap block length 2 previous ack block start is 1.", |
| 3453 | {kVarInt62OneByte + 9}}, // irrelevant |
| 3454 | }; |
| 3455 | // clang-format on |
| 3456 | |
| 3457 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3458 | AssemblePacketFromFragments(packet99)); |
| 3459 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3460 | EXPECT_EQ(framer_.detailed_error(), |
| 3461 | "Underflow with gap block length 2 previous ack block start is 1."); |
| 3462 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3463 | } |
| 3464 | |
| 3465 | // As AckBlockUnderflowGapWrap, but in this test, it's the ack |
| 3466 | // component of the ack-block that causes the wrap, not the gap. |
| 3467 | TEST_P(QuicFramerTest, AckBlockUnderflowAckWrap) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3468 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 3469 | // Test originally written for development of IETF QUIC. The test may |
| 3470 | // also apply to Google QUIC. If so, the test should be extended to |
| 3471 | // include Google QUIC (frame formats, etc). See b/141858819. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3472 | return; |
| 3473 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3474 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3475 | // clang-format off |
| 3476 | PacketFragments packet99 = { |
| 3477 | // type (short header, 4 byte packet number) |
| 3478 | {"", |
| 3479 | {0x43}}, |
| 3480 | // connection_id |
| 3481 | {"", |
| 3482 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3483 | // packet number |
| 3484 | {"", |
| 3485 | {0x12, 0x34, 0x56, 0x78}}, |
| 3486 | // frame type (IETF_ACK frame) |
| 3487 | {"", |
| 3488 | {0x02}}, |
| 3489 | // largest acked |
| 3490 | {"Unable to read largest acked.", |
| 3491 | {kVarInt62OneByte + 10}}, |
| 3492 | // Zero delta time. |
| 3493 | {"Unable to read ack delay time.", |
| 3494 | {kVarInt62OneByte + 0x00}}, |
| 3495 | // Ack block count (1 -- 1 blocks after the first) |
| 3496 | {"Unable to read ack block count.", |
| 3497 | {kVarInt62OneByte + 1}}, |
| 3498 | // first ack block length. |
| 3499 | {"Unable to read first ack block length.", |
| 3500 | {kVarInt62OneByte + 6}}, // Ack packets 4..10 (inclusive) |
| 3501 | |
| 3502 | {"Unable to read gap block value.", |
| 3503 | {kVarInt62OneByte + 1}}, // Gap of 2 packets (2..3) |
| 3504 | {"Unable to read ack block value.", |
| 3505 | {kVarInt62OneByte + 9}}, // Should wrap. |
| 3506 | }; |
| 3507 | // clang-format on |
| 3508 | |
| 3509 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3510 | AssemblePacketFromFragments(packet99)); |
| 3511 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3512 | EXPECT_EQ(framer_.detailed_error(), |
| 3513 | "Underflow with ack block length 10 latest ack block end is 1."); |
| 3514 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3515 | } |
| 3516 | |
| 3517 | // An ack block that acks the entire range, 1...0x3fffffffffffffff |
| 3518 | TEST_P(QuicFramerTest, AckBlockAcksEverything) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3519 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 3520 | // Test originally written for development of IETF QUIC. The test may |
| 3521 | // also apply to Google QUIC. If so, the test should be extended to |
| 3522 | // include Google QUIC (frame formats, etc). See b/141858819. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3523 | return; |
| 3524 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3525 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3526 | // clang-format off |
| 3527 | PacketFragments packet99 = { |
| 3528 | // type (short header, 4 byte packet number) |
| 3529 | {"", |
| 3530 | {0x43}}, |
| 3531 | // connection_id |
| 3532 | {"", |
| 3533 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3534 | // packet number |
| 3535 | {"", |
| 3536 | {0x12, 0x34, 0x56, 0x78}}, |
| 3537 | // frame type (IETF_ACK frame) |
| 3538 | {"", |
| 3539 | {0x02}}, |
| 3540 | // largest acked |
| 3541 | {"Unable to read largest acked.", |
| 3542 | {kVarInt62EightBytes + 0x3f, 0xff, 0xff, 0xff, |
| 3543 | 0xff, 0xff, 0xff, 0xff}}, |
| 3544 | // Zero delta time. |
| 3545 | {"Unable to read ack delay time.", |
| 3546 | {kVarInt62OneByte + 0x00}}, |
| 3547 | // Ack block count No additional blocks |
| 3548 | {"Unable to read ack block count.", |
| 3549 | {kVarInt62OneByte + 0}}, |
| 3550 | // first ack block length. |
| 3551 | {"Unable to read first ack block length.", |
| 3552 | {kVarInt62EightBytes + 0x3f, 0xff, 0xff, 0xff, |
| 3553 | 0xff, 0xff, 0xff, 0xfe}}, |
| 3554 | }; |
| 3555 | // clang-format on |
| 3556 | |
| 3557 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3558 | AssemblePacketFromFragments(packet99)); |
| 3559 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3560 | EXPECT_EQ(1u, visitor_.ack_frames_.size()); |
| 3561 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3562 | EXPECT_EQ(1u, frame.packets.NumIntervals()); |
| 3563 | EXPECT_EQ(kLargestIetfLargestObserved, LargestAcked(frame)); |
| 3564 | EXPECT_EQ(kLargestIetfLargestObserved.ToUint64(), |
| 3565 | frame.packets.NumPacketsSlow()); |
| 3566 | } |
| 3567 | |
| 3568 | // This test looks for a malformed ack where |
| 3569 | // - There is a largest-acked value (that is, the frame is acking |
| 3570 | // something, |
| 3571 | // - But the length of the first ack block is 0 saying that no frames |
| 3572 | // are being acked with the largest-acked value or there are no |
| 3573 | // additional ack blocks. |
| 3574 | // |
| 3575 | TEST_P(QuicFramerTest, AckFrameFirstAckBlockLengthZero) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3576 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3577 | // Not applicable to version 99 -- first ack block contains the |
| 3578 | // number of packets that preceed the largest_acked packet. |
| 3579 | // A value of 0 means no packets preceed --- that the block's |
| 3580 | // length is 1. Therefore the condition that this test checks can |
| 3581 | // not arise. |
| 3582 | return; |
| 3583 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 3584 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3585 | |
| 3586 | // clang-format off |
| 3587 | PacketFragments packet = { |
| 3588 | // public flags (8 byte connection_id) |
| 3589 | {"", |
| 3590 | { 0x2C }}, |
| 3591 | // connection_id |
| 3592 | {"", |
| 3593 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3594 | // packet number |
| 3595 | {"", |
| 3596 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3597 | |
| 3598 | // frame type (ack frame) |
| 3599 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3600 | {"", |
| 3601 | { 0x65 }}, |
| 3602 | // largest acked |
| 3603 | {"Unable to read largest acked.", |
| 3604 | { 0x12, 0x34 }}, |
| 3605 | // Zero delta time. |
| 3606 | {"Unable to read ack delay time.", |
| 3607 | { 0x00, 0x00 }}, |
| 3608 | // num ack blocks ranges. |
| 3609 | {"Unable to read num of ack blocks.", |
| 3610 | { 0x01 }}, |
| 3611 | // first ack block length. |
| 3612 | {"Unable to read first ack block length.", |
| 3613 | { 0x00, 0x00 }}, |
| 3614 | // gap to next block. |
| 3615 | { "First block length is zero.", |
| 3616 | { 0x01 }}, |
| 3617 | // ack block length. |
| 3618 | { "First block length is zero.", |
| 3619 | { 0x0e, 0xaf }}, |
| 3620 | // Number of timestamps. |
| 3621 | { "First block length is zero.", |
| 3622 | { 0x00 }}, |
| 3623 | }; |
| 3624 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3625 | PacketFragments packet46 = { |
| 3626 | // type (short header, 4 byte packet number) |
| 3627 | {"", |
| 3628 | { 0x43 }}, |
| 3629 | // connection_id |
| 3630 | {"", |
| 3631 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3632 | // packet number |
| 3633 | {"", |
| 3634 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3635 | |
| 3636 | // frame type (ack frame) |
| 3637 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3638 | {"", |
| 3639 | { 0x65 }}, |
| 3640 | // largest acked |
| 3641 | {"Unable to read largest acked.", |
| 3642 | { 0x12, 0x34 }}, |
| 3643 | // Zero delta time. |
| 3644 | {"Unable to read ack delay time.", |
| 3645 | { 0x00, 0x00 }}, |
| 3646 | // num ack blocks ranges. |
| 3647 | {"Unable to read num of ack blocks.", |
| 3648 | { 0x01 }}, |
| 3649 | // first ack block length. |
| 3650 | {"Unable to read first ack block length.", |
| 3651 | { 0x00, 0x00 }}, |
| 3652 | // gap to next block. |
| 3653 | { "First block length is zero.", |
| 3654 | { 0x01 }}, |
| 3655 | // ack block length. |
| 3656 | { "First block length is zero.", |
| 3657 | { 0x0e, 0xaf }}, |
| 3658 | // Number of timestamps. |
| 3659 | { "First block length is zero.", |
| 3660 | { 0x00 }}, |
| 3661 | }; |
| 3662 | |
| 3663 | // clang-format on |
| 3664 | PacketFragments& fragments = |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 3665 | framer_.version().HasIetfInvariantHeader() ? packet46 : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3666 | |
| 3667 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3668 | AssemblePacketFromFragments(fragments)); |
| 3669 | |
| 3670 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 3671 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_ACK_DATA)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3672 | |
| 3673 | ASSERT_TRUE(visitor_.header_.get()); |
| 3674 | EXPECT_TRUE(CheckDecryption( |
| 3675 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3676 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3677 | |
| 3678 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3679 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3680 | |
| 3681 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3682 | } |
| 3683 | |
| 3684 | TEST_P(QuicFramerTest, AckFrameOneAckBlockMaxLength) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3685 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3686 | // clang-format off |
| 3687 | PacketFragments packet = { |
| 3688 | // public flags (8 byte connection_id) |
| 3689 | {"", |
| 3690 | {0x2C}}, |
| 3691 | // connection_id |
| 3692 | {"", |
| 3693 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3694 | // packet number |
| 3695 | {"", |
| 3696 | {0x12, 0x34, 0x56, 0x78}}, |
| 3697 | // frame type (ack frame) |
| 3698 | // (one ack block, 4 byte largest observed, 2 byte block length) |
| 3699 | {"", |
| 3700 | {0x49}}, |
| 3701 | // largest acked |
| 3702 | {"Unable to read largest acked.", |
| 3703 | {0x12, 0x34, 0x56, 0x78}}, |
| 3704 | // Zero delta time. |
| 3705 | {"Unable to read ack delay time.", |
| 3706 | {0x00, 0x00}}, |
| 3707 | // first ack block length. |
| 3708 | {"Unable to read first ack block length.", |
| 3709 | {0x12, 0x34}}, |
| 3710 | // num timestamps. |
| 3711 | {"Unable to read num received packets.", |
| 3712 | {0x00}} |
| 3713 | }; |
| 3714 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3715 | PacketFragments packet46 = { |
| 3716 | // type (short header, 4 byte packet number) |
| 3717 | {"", |
| 3718 | {0x43}}, |
| 3719 | // connection_id |
| 3720 | {"", |
| 3721 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3722 | // packet number |
| 3723 | {"", |
| 3724 | {0x56, 0x78, 0x9A, 0xBC}}, |
| 3725 | // frame type (ack frame) |
| 3726 | // (one ack block, 4 byte largest observed, 2 byte block length) |
| 3727 | {"", |
| 3728 | {0x49}}, |
| 3729 | // largest acked |
| 3730 | {"Unable to read largest acked.", |
| 3731 | {0x12, 0x34, 0x56, 0x78}}, |
| 3732 | // Zero delta time. |
| 3733 | {"Unable to read ack delay time.", |
| 3734 | {0x00, 0x00}}, |
| 3735 | // first ack block length. |
| 3736 | {"Unable to read first ack block length.", |
| 3737 | {0x12, 0x34}}, |
| 3738 | // num timestamps. |
| 3739 | {"Unable to read num received packets.", |
| 3740 | {0x00}} |
| 3741 | }; |
| 3742 | |
| 3743 | PacketFragments packet99 = { |
| 3744 | // type (short header, 4 byte packet number) |
| 3745 | {"", |
| 3746 | {0x43}}, |
| 3747 | // connection_id |
| 3748 | {"", |
| 3749 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3750 | // packet number |
| 3751 | {"", |
| 3752 | {0x56, 0x78, 0x9A, 0xBC}}, |
| 3753 | // frame type (IETF_ACK frame) |
| 3754 | {"", |
| 3755 | {0x02}}, |
| 3756 | // largest acked |
| 3757 | {"Unable to read largest acked.", |
| 3758 | {kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78}}, |
| 3759 | // Zero delta time. |
| 3760 | {"Unable to read ack delay time.", |
| 3761 | {kVarInt62OneByte + 0x00}}, |
| 3762 | // Number of ack blocks after first |
| 3763 | {"Unable to read ack block count.", |
| 3764 | {kVarInt62OneByte + 0x00}}, |
| 3765 | // first ack block length. |
| 3766 | {"Unable to read first ack block length.", |
| 3767 | {kVarInt62TwoBytes + 0x12, 0x33}} |
| 3768 | }; |
| 3769 | // clang-format on |
| 3770 | |
| 3771 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3772 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3773 | ? packet99 |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 3774 | : (framer_.version().HasIetfInvariantHeader() ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3775 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3776 | AssemblePacketFromFragments(fragments)); |
| 3777 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3778 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 3779 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3780 | ASSERT_TRUE(visitor_.header_.get()); |
| 3781 | EXPECT_TRUE(CheckDecryption( |
| 3782 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3783 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3784 | |
| 3785 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3786 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3787 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3788 | EXPECT_EQ(kPacketNumber, LargestAcked(frame)); |
| 3789 | ASSERT_EQ(4660u, frame.packets.NumPacketsSlow()); |
| 3790 | |
| 3791 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3792 | } |
| 3793 | |
| 3794 | // Tests ability to handle multiple ackblocks after the first ack |
| 3795 | // block. Non-version-99 tests include multiple timestamps as well. |
| 3796 | TEST_P(QuicFramerTest, AckFrameTwoTimeStampsMultipleAckBlocks) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 3797 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3798 | // clang-format off |
| 3799 | PacketFragments packet = { |
| 3800 | // public flags (8 byte connection_id) |
| 3801 | {"", |
| 3802 | { 0x2C }}, |
| 3803 | // connection_id |
| 3804 | {"", |
| 3805 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3806 | // packet number |
| 3807 | {"", |
| 3808 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3809 | |
| 3810 | // frame type (ack frame) |
| 3811 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3812 | {"", |
| 3813 | { 0x65 }}, |
| 3814 | // largest acked |
| 3815 | {"Unable to read largest acked.", |
| 3816 | { 0x12, 0x34 }}, |
| 3817 | // Zero delta time. |
| 3818 | {"Unable to read ack delay time.", |
| 3819 | { 0x00, 0x00 }}, |
| 3820 | // num ack blocks ranges. |
| 3821 | {"Unable to read num of ack blocks.", |
| 3822 | { 0x04 }}, |
| 3823 | // first ack block length. |
| 3824 | {"Unable to read first ack block length.", |
| 3825 | { 0x00, 0x01 }}, |
| 3826 | // gap to next block. |
| 3827 | { "Unable to read gap to next ack block.", |
| 3828 | { 0x01 }}, |
| 3829 | // ack block length. |
| 3830 | { "Unable to ack block length.", |
| 3831 | { 0x0e, 0xaf }}, |
| 3832 | // gap to next block. |
| 3833 | { "Unable to read gap to next ack block.", |
| 3834 | { 0xff }}, |
| 3835 | // ack block length. |
| 3836 | { "Unable to ack block length.", |
| 3837 | { 0x00, 0x00 }}, |
| 3838 | // gap to next block. |
| 3839 | { "Unable to read gap to next ack block.", |
| 3840 | { 0x91 }}, |
| 3841 | // ack block length. |
| 3842 | { "Unable to ack block length.", |
| 3843 | { 0x01, 0xea }}, |
| 3844 | // gap to next block. |
| 3845 | { "Unable to read gap to next ack block.", |
| 3846 | { 0x05 }}, |
| 3847 | // ack block length. |
| 3848 | { "Unable to ack block length.", |
| 3849 | { 0x00, 0x04 }}, |
| 3850 | // Number of timestamps. |
| 3851 | { "Unable to read num received packets.", |
| 3852 | { 0x02 }}, |
| 3853 | // Delta from largest observed. |
| 3854 | { "Unable to read sequence delta in received packets.", |
| 3855 | { 0x01 }}, |
| 3856 | // Delta time. |
| 3857 | { "Unable to read time delta in received packets.", |
| 3858 | { 0x76, 0x54, 0x32, 0x10 }}, |
| 3859 | // Delta from largest observed. |
| 3860 | { "Unable to read sequence delta in received packets.", |
| 3861 | { 0x02 }}, |
| 3862 | // Delta time. |
| 3863 | { "Unable to read incremental time delta in received packets.", |
| 3864 | { 0x32, 0x10 }}, |
| 3865 | }; |
| 3866 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3867 | PacketFragments packet46 = { |
| 3868 | // type (short header, 4 byte packet number) |
| 3869 | {"", |
| 3870 | { 0x43 }}, |
| 3871 | // connection_id |
| 3872 | {"", |
| 3873 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3874 | // packet number |
| 3875 | {"", |
| 3876 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3877 | |
| 3878 | // frame type (ack frame) |
| 3879 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3880 | {"", |
| 3881 | { 0x65 }}, |
| 3882 | // largest acked |
| 3883 | {"Unable to read largest acked.", |
| 3884 | { 0x12, 0x34 }}, |
| 3885 | // Zero delta time. |
| 3886 | {"Unable to read ack delay time.", |
| 3887 | { 0x00, 0x00 }}, |
| 3888 | // num ack blocks ranges. |
| 3889 | {"Unable to read num of ack blocks.", |
| 3890 | { 0x04 }}, |
| 3891 | // first ack block length. |
| 3892 | {"Unable to read first ack block length.", |
| 3893 | { 0x00, 0x01 }}, |
| 3894 | // gap to next block. |
| 3895 | { "Unable to read gap to next ack block.", |
| 3896 | { 0x01 }}, |
| 3897 | // ack block length. |
| 3898 | { "Unable to ack block length.", |
| 3899 | { 0x0e, 0xaf }}, |
| 3900 | // gap to next block. |
| 3901 | { "Unable to read gap to next ack block.", |
| 3902 | { 0xff }}, |
| 3903 | // ack block length. |
| 3904 | { "Unable to ack block length.", |
| 3905 | { 0x00, 0x00 }}, |
| 3906 | // gap to next block. |
| 3907 | { "Unable to read gap to next ack block.", |
| 3908 | { 0x91 }}, |
| 3909 | // ack block length. |
| 3910 | { "Unable to ack block length.", |
| 3911 | { 0x01, 0xea }}, |
| 3912 | // gap to next block. |
| 3913 | { "Unable to read gap to next ack block.", |
| 3914 | { 0x05 }}, |
| 3915 | // ack block length. |
| 3916 | { "Unable to ack block length.", |
| 3917 | { 0x00, 0x04 }}, |
| 3918 | // Number of timestamps. |
| 3919 | { "Unable to read num received packets.", |
| 3920 | { 0x02 }}, |
| 3921 | // Delta from largest observed. |
| 3922 | { "Unable to read sequence delta in received packets.", |
| 3923 | { 0x01 }}, |
| 3924 | // Delta time. |
| 3925 | { "Unable to read time delta in received packets.", |
| 3926 | { 0x76, 0x54, 0x32, 0x10 }}, |
| 3927 | // Delta from largest observed. |
| 3928 | { "Unable to read sequence delta in received packets.", |
| 3929 | { 0x02 }}, |
| 3930 | // Delta time. |
| 3931 | { "Unable to read incremental time delta in received packets.", |
| 3932 | { 0x32, 0x10 }}, |
| 3933 | }; |
| 3934 | |
| 3935 | PacketFragments packet99 = { |
| 3936 | // type (short header, 4 byte packet number) |
| 3937 | {"", |
| 3938 | { 0x43 }}, |
| 3939 | // connection_id |
| 3940 | {"", |
| 3941 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3942 | // packet number |
| 3943 | {"", |
| 3944 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3945 | |
| 3946 | // frame type (IETF_ACK frame) |
| 3947 | {"", |
| 3948 | { 0x02 }}, |
| 3949 | // largest acked |
| 3950 | {"Unable to read largest acked.", |
| 3951 | { kVarInt62TwoBytes + 0x12, 0x34 }}, // = 4660 |
| 3952 | // Zero delta time. |
| 3953 | {"Unable to read ack delay time.", |
| 3954 | { kVarInt62OneByte + 0x00 }}, |
| 3955 | // number of additional ack blocks |
| 3956 | {"Unable to read ack block count.", |
| 3957 | { kVarInt62OneByte + 0x03 }}, |
| 3958 | // first ack block length. |
| 3959 | {"Unable to read first ack block length.", |
| 3960 | { kVarInt62OneByte + 0x00 }}, // 1st block length = 1 |
| 3961 | |
| 3962 | // Additional ACK Block #1 |
| 3963 | // gap to next block. |
| 3964 | { "Unable to read gap block value.", |
| 3965 | { kVarInt62OneByte + 0x00 }}, // gap of 1 packet |
| 3966 | // ack block length. |
| 3967 | { "Unable to read ack block value.", |
| 3968 | { kVarInt62TwoBytes + 0x0e, 0xae }}, // 3759 |
| 3969 | |
| 3970 | // pre-version-99 test includes an ack block of 0 length. this |
| 3971 | // can not happen in version 99. ergo the second block is not |
| 3972 | // present in the v99 test and the gap length of the next block |
| 3973 | // is the sum of the two gaps in the pre-version-99 tests. |
| 3974 | // Additional ACK Block #2 |
| 3975 | // gap to next block. |
| 3976 | { "Unable to read gap block value.", |
| 3977 | { kVarInt62TwoBytes + 0x01, 0x8f }}, // Gap is 400 (0x190) pkts |
| 3978 | // ack block length. |
| 3979 | { "Unable to read ack block value.", |
| 3980 | { kVarInt62TwoBytes + 0x01, 0xe9 }}, // block is 389 (x1ea) pkts |
| 3981 | |
| 3982 | // Additional ACK Block #3 |
| 3983 | // gap to next block. |
| 3984 | { "Unable to read gap block value.", |
| 3985 | { kVarInt62OneByte + 0x04 }}, // Gap is 5 packets. |
| 3986 | // ack block length. |
| 3987 | { "Unable to read ack block value.", |
| 3988 | { kVarInt62OneByte + 0x03 }}, // block is 3 packets. |
| 3989 | }; |
| 3990 | |
| 3991 | // clang-format on |
| 3992 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 3993 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3994 | ? packet99 |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 3995 | : (framer_.version().HasIetfInvariantHeader() ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 3996 | |
| 3997 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3998 | AssemblePacketFromFragments(fragments)); |
| 3999 | |
| 4000 | framer_.set_process_timestamps(true); |
| 4001 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4002 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4003 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4004 | ASSERT_TRUE(visitor_.header_.get()); |
| 4005 | EXPECT_TRUE(CheckDecryption( |
| 4006 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4007 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4008 | |
| 4009 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 4010 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 4011 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 4012 | EXPECT_EQ(kSmallLargestObserved, LargestAcked(frame)); |
| 4013 | ASSERT_EQ(4254u, frame.packets.NumPacketsSlow()); |
| 4014 | EXPECT_EQ(4u, frame.packets.NumIntervals()); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4015 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4016 | EXPECT_EQ(0u, frame.received_packet_times.size()); |
| 4017 | } else { |
| 4018 | EXPECT_EQ(2u, frame.received_packet_times.size()); |
| 4019 | } |
| 4020 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 4021 | } |
| 4022 | |
| 4023 | TEST_P(QuicFramerTest, AckFrameTimeStampDeltaTooHigh) { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4024 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4025 | // clang-format off |
| 4026 | unsigned char packet[] = { |
| 4027 | // public flags (8 byte connection_id) |
| 4028 | 0x28, |
| 4029 | // connection_id |
| 4030 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4031 | // packet number |
| 4032 | 0x12, 0x34, 0x56, 0x78, |
| 4033 | |
| 4034 | // frame type (ack frame) |
| 4035 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 4036 | 0x40, |
| 4037 | // largest acked |
| 4038 | 0x01, |
| 4039 | // Zero delta time. |
| 4040 | 0x00, 0x00, |
| 4041 | // first ack block length. |
| 4042 | 0x01, |
| 4043 | // num timestamps. |
| 4044 | 0x01, |
| 4045 | // Delta from largest observed. |
| 4046 | 0x01, |
| 4047 | // Delta time. |
| 4048 | 0x10, 0x32, 0x54, 0x76, |
| 4049 | }; |
| 4050 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4051 | unsigned char packet46[] = { |
| 4052 | // type (short header, 4 byte packet number) |
| 4053 | 0x43, |
| 4054 | // connection_id |
| 4055 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4056 | // packet number |
| 4057 | 0x12, 0x34, 0x56, 0x78, |
| 4058 | |
| 4059 | // frame type (ack frame) |
| 4060 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 4061 | 0x40, |
| 4062 | // largest acked |
| 4063 | 0x01, |
| 4064 | // Zero delta time. |
| 4065 | 0x00, 0x00, |
| 4066 | // first ack block length. |
| 4067 | 0x01, |
| 4068 | // num timestamps. |
| 4069 | 0x01, |
| 4070 | // Delta from largest observed. |
| 4071 | 0x01, |
| 4072 | // Delta time. |
| 4073 | 0x10, 0x32, 0x54, 0x76, |
| 4074 | }; |
| 4075 | // clang-format on |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4076 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 4077 | // ACK Timestamp is not a feature of IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4078 | return; |
| 4079 | } |
| 4080 | QuicEncryptedPacket encrypted( |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 4081 | AsChars(framer_.version().HasIetfInvariantHeader() ? packet46 : packet), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 4082 | ABSL_ARRAYSIZE(packet), false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4083 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
vasilvv | 89fe24d | 2020-10-26 14:55:28 -0700 | [diff] [blame^] | 4084 | EXPECT_TRUE(absl::StartsWith(framer_.detailed_error(), |
| 4085 | "delta_from_largest_observed too high")); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4086 | } |
| 4087 | |
| 4088 | TEST_P(QuicFramerTest, AckFrameTimeStampSecondDeltaTooHigh) { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4089 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4090 | // clang-format off |
| 4091 | unsigned char packet[] = { |
| 4092 | // public flags (8 byte connection_id) |
| 4093 | 0x28, |
| 4094 | // connection_id |
| 4095 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4096 | // packet number |
| 4097 | 0x12, 0x34, 0x56, 0x78, |
| 4098 | |
| 4099 | // frame type (ack frame) |
| 4100 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 4101 | 0x40, |
| 4102 | // largest acked |
| 4103 | 0x03, |
| 4104 | // Zero delta time. |
| 4105 | 0x00, 0x00, |
| 4106 | // first ack block length. |
| 4107 | 0x03, |
| 4108 | // num timestamps. |
| 4109 | 0x02, |
| 4110 | // Delta from largest observed. |
| 4111 | 0x01, |
| 4112 | // Delta time. |
| 4113 | 0x10, 0x32, 0x54, 0x76, |
| 4114 | // Delta from largest observed. |
| 4115 | 0x03, |
| 4116 | // Delta time. |
| 4117 | 0x10, 0x32, |
| 4118 | }; |
| 4119 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4120 | unsigned char packet46[] = { |
| 4121 | // type (short header, 4 byte packet number) |
| 4122 | 0x43, |
| 4123 | // connection_id |
| 4124 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4125 | // packet number |
| 4126 | 0x12, 0x34, 0x56, 0x78, |
| 4127 | |
| 4128 | // frame type (ack frame) |
| 4129 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 4130 | 0x40, |
| 4131 | // largest acked |
| 4132 | 0x03, |
| 4133 | // Zero delta time. |
| 4134 | 0x00, 0x00, |
| 4135 | // first ack block length. |
| 4136 | 0x03, |
| 4137 | // num timestamps. |
| 4138 | 0x02, |
| 4139 | // Delta from largest observed. |
| 4140 | 0x01, |
| 4141 | // Delta time. |
| 4142 | 0x10, 0x32, 0x54, 0x76, |
| 4143 | // Delta from largest observed. |
| 4144 | 0x03, |
| 4145 | // Delta time. |
| 4146 | 0x10, 0x32, |
| 4147 | }; |
| 4148 | // clang-format on |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4149 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 4150 | // ACK Timestamp is not a feature of IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4151 | return; |
| 4152 | } |
| 4153 | QuicEncryptedPacket encrypted( |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 4154 | AsChars(framer_.version().HasIetfInvariantHeader() ? packet46 : packet), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 4155 | ABSL_ARRAYSIZE(packet), false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4156 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
vasilvv | 89fe24d | 2020-10-26 14:55:28 -0700 | [diff] [blame^] | 4157 | EXPECT_TRUE(absl::StartsWith(framer_.detailed_error(), |
| 4158 | "delta_from_largest_observed too high")); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4159 | } |
| 4160 | |
| 4161 | TEST_P(QuicFramerTest, NewStopWaitingFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4162 | if (VersionHasIetfQuicFrames(version_.transport_version)) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 4163 | // The Stop Waiting frame is not in IETF QUIC |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4164 | return; |
| 4165 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4166 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4167 | // clang-format off |
| 4168 | PacketFragments packet = { |
| 4169 | // public flags (8 byte connection_id) |
| 4170 | {"", |
| 4171 | {0x2C}}, |
| 4172 | // connection_id |
| 4173 | {"", |
| 4174 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4175 | // packet number |
| 4176 | {"", |
| 4177 | {0x12, 0x34, 0x56, 0x78}}, |
| 4178 | // frame type (stop waiting frame) |
| 4179 | {"", |
| 4180 | {0x06}}, |
| 4181 | // least packet number awaiting an ack, delta from packet number. |
| 4182 | {"Unable to read least unacked delta.", |
| 4183 | {0x00, 0x00, 0x00, 0x08}} |
| 4184 | }; |
| 4185 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4186 | PacketFragments packet46 = { |
| 4187 | // type (short header, 4 byte packet number) |
| 4188 | {"", |
| 4189 | {0x43}}, |
| 4190 | // connection_id |
| 4191 | {"", |
| 4192 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4193 | // packet number |
| 4194 | {"", |
| 4195 | {0x12, 0x34, 0x56, 0x78}}, |
| 4196 | // frame type (stop waiting frame) |
| 4197 | {"", |
| 4198 | {0x06}}, |
| 4199 | // least packet number awaiting an ack, delta from packet number. |
| 4200 | {"Unable to read least unacked delta.", |
| 4201 | {0x00, 0x00, 0x00, 0x08}} |
| 4202 | }; |
| 4203 | // clang-format on |
| 4204 | |
| 4205 | PacketFragments& fragments = |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 4206 | framer_.version().HasIetfInvariantHeader() ? packet46 : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4207 | |
| 4208 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4209 | AssemblePacketFromFragments(fragments)); |
ianswett | 97b690b | 2019-05-02 15:12:43 -0700 | [diff] [blame] | 4210 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4211 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4212 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4213 | ASSERT_TRUE(visitor_.header_.get()); |
| 4214 | EXPECT_TRUE(CheckDecryption( |
| 4215 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4216 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4217 | |
| 4218 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 4219 | ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size()); |
| 4220 | const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0]; |
| 4221 | EXPECT_EQ(kLeastUnacked, frame.least_unacked); |
| 4222 | |
| 4223 | CheckFramingBoundaries(fragments, QUIC_INVALID_STOP_WAITING_DATA); |
| 4224 | } |
| 4225 | |
| 4226 | TEST_P(QuicFramerTest, InvalidNewStopWaitingFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 4227 | // The Stop Waiting frame is not in IETF QUIC |
ianswett | d18fe67 | 2020-09-23 08:06:49 -0700 | [diff] [blame] | 4228 | if (VersionHasIetfQuicFrames(version_.transport_version) && |
| 4229 | framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4230 | return; |
| 4231 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 4232 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4233 | // clang-format off |
| 4234 | unsigned char packet[] = { |
| 4235 | // public flags (8 byte connection_id) |
| 4236 | 0x2C, |
| 4237 | // connection_id |
| 4238 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4239 | // packet number |
| 4240 | 0x12, 0x34, 0x56, 0x78, |
| 4241 | // frame type (stop waiting frame) |
| 4242 | 0x06, |
| 4243 | // least packet number awaiting an ack, delta from packet number. |
| 4244 | 0x13, 0x34, 0x56, 0x78, |
| 4245 | 0x9A, 0xA8, |
| 4246 | }; |
| 4247 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4248 | unsigned char packet46[] = { |
| 4249 | // type (short header, 4 byte packet number) |
| 4250 | 0x43, |
| 4251 | // connection_id |
| 4252 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4253 | // packet number |
| 4254 | 0x12, 0x34, 0x56, 0x78, |
| 4255 | // frame type (stop waiting frame) |
| 4256 | 0x06, |
| 4257 | // least packet number awaiting an ack, delta from packet number. |
| 4258 | 0x57, 0x78, 0x9A, 0xA8, |
| 4259 | }; |
| 4260 | // clang-format on |
| 4261 | |
| 4262 | QuicEncryptedPacket encrypted( |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 4263 | AsChars(framer_.version().HasIetfInvariantHeader() ? packet46 : packet), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 4264 | framer_.version().HasIetfInvariantHeader() ? ABSL_ARRAYSIZE(packet46) |
| 4265 | : ABSL_ARRAYSIZE(packet), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4266 | false); |
| 4267 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4268 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_STOP_WAITING_DATA)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4269 | EXPECT_EQ("Invalid unacked delta.", framer_.detailed_error()); |
| 4270 | } |
| 4271 | |
| 4272 | TEST_P(QuicFramerTest, RstStreamFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4273 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4274 | // clang-format off |
| 4275 | PacketFragments packet = { |
| 4276 | // public flags (8 byte connection_id) |
| 4277 | {"", |
| 4278 | {0x28}}, |
| 4279 | // connection_id |
| 4280 | {"", |
| 4281 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4282 | // packet number |
| 4283 | {"", |
| 4284 | {0x12, 0x34, 0x56, 0x78}}, |
| 4285 | // frame type (rst stream frame) |
| 4286 | {"", |
| 4287 | {0x01}}, |
| 4288 | // stream id |
| 4289 | {"Unable to read stream_id.", |
| 4290 | {0x01, 0x02, 0x03, 0x04}}, |
| 4291 | // sent byte offset |
| 4292 | {"Unable to read rst stream sent byte offset.", |
| 4293 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4294 | 0x32, 0x10, 0x76, 0x54}}, |
bnc | cb0ffbc | 2020-04-13 10:53:11 -0700 | [diff] [blame] | 4295 | // error code QUIC_STREAM_CANCELLED |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4296 | {"Unable to read rst stream error code.", |
bnc | cb0ffbc | 2020-04-13 10:53:11 -0700 | [diff] [blame] | 4297 | {0x00, 0x00, 0x00, 0x06}} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4298 | }; |
| 4299 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4300 | PacketFragments packet46 = { |
| 4301 | // type (short header, 4 byte packet number) |
| 4302 | {"", |
| 4303 | {0x43}}, |
| 4304 | // connection_id |
| 4305 | {"", |
| 4306 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4307 | // packet number |
| 4308 | {"", |
| 4309 | {0x12, 0x34, 0x56, 0x78}}, |
| 4310 | // frame type (rst stream frame) |
| 4311 | {"", |
| 4312 | {0x01}}, |
| 4313 | // stream id |
| 4314 | {"Unable to read stream_id.", |
| 4315 | {0x01, 0x02, 0x03, 0x04}}, |
| 4316 | // sent byte offset |
| 4317 | {"Unable to read rst stream sent byte offset.", |
| 4318 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4319 | 0x32, 0x10, 0x76, 0x54}}, |
bnc | cb0ffbc | 2020-04-13 10:53:11 -0700 | [diff] [blame] | 4320 | // error code QUIC_STREAM_CANCELLED |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4321 | {"Unable to read rst stream error code.", |
bnc | cb0ffbc | 2020-04-13 10:53:11 -0700 | [diff] [blame] | 4322 | {0x00, 0x00, 0x00, 0x06}} |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4323 | }; |
| 4324 | |
| 4325 | PacketFragments packet99 = { |
| 4326 | // type (short header, 4 byte packet number) |
| 4327 | {"", |
| 4328 | {0x43}}, |
| 4329 | // connection_id |
| 4330 | {"", |
| 4331 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4332 | // packet number |
| 4333 | {"", |
| 4334 | {0x12, 0x34, 0x56, 0x78}}, |
| 4335 | // frame type (IETF_RST_STREAM frame) |
| 4336 | {"", |
| 4337 | {0x04}}, |
| 4338 | // stream id |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 4339 | {"Unable to read IETF_RST_STREAM frame stream id/count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4340 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
bnc | cb0ffbc | 2020-04-13 10:53:11 -0700 | [diff] [blame] | 4341 | // application error code H3_REQUEST_CANCELLED gets translated to |
| 4342 | // QuicRstStreamErrorCode::QUIC_STREAM_CANCELLED. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4343 | {"Unable to read rst stream error code.", |
bnc | cb0ffbc | 2020-04-13 10:53:11 -0700 | [diff] [blame] | 4344 | {kVarInt62TwoBytes + 0x01, 0x0c}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4345 | // Final Offset |
| 4346 | {"Unable to read rst stream sent byte offset.", |
| 4347 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}} |
| 4348 | }; |
| 4349 | // clang-format on |
| 4350 | |
| 4351 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4352 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4353 | ? packet99 |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 4354 | : (framer_.version().HasIetfInvariantHeader() ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4355 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4356 | AssemblePacketFromFragments(fragments)); |
| 4357 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4358 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4359 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4360 | ASSERT_TRUE(visitor_.header_.get()); |
| 4361 | EXPECT_TRUE(CheckDecryption( |
| 4362 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4363 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4364 | |
| 4365 | EXPECT_EQ(kStreamId, visitor_.rst_stream_frame_.stream_id); |
bnc | cb0ffbc | 2020-04-13 10:53:11 -0700 | [diff] [blame] | 4366 | EXPECT_EQ(QUIC_STREAM_CANCELLED, visitor_.rst_stream_frame_.error_code); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4367 | EXPECT_EQ(kStreamOffset, visitor_.rst_stream_frame_.byte_offset); |
| 4368 | CheckFramingBoundaries(fragments, QUIC_INVALID_RST_STREAM_DATA); |
| 4369 | } |
| 4370 | |
| 4371 | TEST_P(QuicFramerTest, ConnectionCloseFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4372 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4373 | // clang-format off |
| 4374 | PacketFragments packet = { |
| 4375 | // public flags (8 byte connection_id) |
| 4376 | {"", |
| 4377 | {0x28}}, |
| 4378 | // connection_id |
| 4379 | {"", |
| 4380 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4381 | // packet number |
| 4382 | {"", |
| 4383 | {0x12, 0x34, 0x56, 0x78}}, |
| 4384 | // frame type (connection close frame) |
| 4385 | {"", |
| 4386 | {0x02}}, |
| 4387 | // error code |
| 4388 | {"Unable to read connection close error code.", |
| 4389 | {0x00, 0x00, 0x00, 0x11}}, |
| 4390 | {"Unable to read connection close error details.", |
| 4391 | { |
| 4392 | // error details length |
| 4393 | 0x0, 0x0d, |
| 4394 | // error details |
| 4395 | 'b', 'e', 'c', 'a', |
| 4396 | 'u', 's', 'e', ' ', |
| 4397 | 'I', ' ', 'c', 'a', |
| 4398 | 'n'} |
| 4399 | } |
| 4400 | }; |
| 4401 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4402 | PacketFragments packet46 = { |
| 4403 | // type (short header, 4 byte packet number) |
| 4404 | {"", |
| 4405 | {0x43}}, |
| 4406 | // connection_id |
| 4407 | {"", |
| 4408 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4409 | // packet number |
| 4410 | {"", |
| 4411 | {0x12, 0x34, 0x56, 0x78}}, |
| 4412 | // frame type (connection close frame) |
| 4413 | {"", |
| 4414 | {0x02}}, |
| 4415 | // error code |
| 4416 | {"Unable to read connection close error code.", |
| 4417 | {0x00, 0x00, 0x00, 0x11}}, |
| 4418 | {"Unable to read connection close error details.", |
| 4419 | { |
| 4420 | // error details length |
| 4421 | 0x0, 0x0d, |
| 4422 | // error details |
| 4423 | 'b', 'e', 'c', 'a', |
| 4424 | 'u', 's', 'e', ' ', |
| 4425 | 'I', ' ', 'c', 'a', |
| 4426 | 'n'} |
| 4427 | } |
| 4428 | }; |
| 4429 | |
| 4430 | PacketFragments packet99 = { |
| 4431 | // type (short header, 4 byte packet number) |
| 4432 | {"", |
| 4433 | {0x43}}, |
| 4434 | // connection_id |
| 4435 | {"", |
| 4436 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4437 | // packet number |
| 4438 | {"", |
| 4439 | {0x12, 0x34, 0x56, 0x78}}, |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4440 | // frame type (IETF Transport CONNECTION_CLOSE frame) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4441 | {"", |
| 4442 | {0x1c}}, |
| 4443 | // error code |
| 4444 | {"Unable to read connection close error code.", |
fkastenholz | d57d3f9 | 2019-07-16 09:05:17 -0700 | [diff] [blame] | 4445 | {kVarInt62TwoBytes + 0x00, 0x11}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4446 | {"Unable to read connection close frame type.", |
| 4447 | {kVarInt62TwoBytes + 0x12, 0x34 }}, |
| 4448 | {"Unable to read connection close error details.", |
| 4449 | { |
| 4450 | // error details length |
bnc | 40fa830 | 2020-09-28 08:16:27 -0700 | [diff] [blame] | 4451 | kVarInt62OneByte + 0x11, |
| 4452 | // error details with QuicErrorCode serialized |
| 4453 | '1', '1', '5', ':', |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4454 | 'b', 'e', 'c', 'a', |
| 4455 | 'u', 's', 'e', ' ', |
| 4456 | 'I', ' ', 'c', 'a', |
| 4457 | 'n'} |
| 4458 | } |
| 4459 | }; |
| 4460 | // clang-format on |
| 4461 | |
| 4462 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4463 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4464 | ? packet99 |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 4465 | : (framer_.version().HasIetfInvariantHeader() ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4466 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4467 | AssemblePacketFromFragments(fragments)); |
| 4468 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4469 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4470 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4471 | ASSERT_TRUE(visitor_.header_.get()); |
| 4472 | EXPECT_TRUE(CheckDecryption( |
| 4473 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4474 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4475 | |
| 4476 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
zhongyi | ba6354a | 2019-04-10 16:49:25 -0700 | [diff] [blame] | 4477 | EXPECT_EQ(0x11u, static_cast<unsigned>( |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 4478 | visitor_.connection_close_frame_.wire_error_code)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4479 | EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4480 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | e9d71a8 | 2019-04-09 05:12:13 -0700 | [diff] [blame] | 4481 | EXPECT_EQ(0x1234u, |
| 4482 | visitor_.connection_close_frame_.transport_close_frame_type); |
bnc | 40fa830 | 2020-09-28 08:16:27 -0700 | [diff] [blame] | 4483 | EXPECT_EQ(115u, visitor_.connection_close_frame_.quic_error_code); |
fkastenholz | a14a7ae | 2019-08-07 05:21:22 -0700 | [diff] [blame] | 4484 | } else { |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 4485 | // For Google QUIC frame, |quic_error_code| and |wire_error_code| has the |
| 4486 | // same value. |
| 4487 | EXPECT_EQ(0x11u, static_cast<unsigned>( |
| 4488 | visitor_.connection_close_frame_.quic_error_code)); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 4492 | |
| 4493 | CheckFramingBoundaries(fragments, QUIC_INVALID_CONNECTION_CLOSE_DATA); |
| 4494 | } |
| 4495 | |
bnc | 40fa830 | 2020-09-28 08:16:27 -0700 | [diff] [blame] | 4496 | TEST_P(QuicFramerTest, ConnectionCloseFrameWithUnknownErrorCode) { |
| 4497 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 4498 | // clang-format off |
| 4499 | PacketFragments packet = { |
| 4500 | // public flags (8 byte connection_id) |
| 4501 | {"", |
| 4502 | {0x28}}, |
| 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 larger than QUIC_LAST_ERROR |
| 4513 | {"Unable to read connection close error code.", |
| 4514 | {0x00, 0x00, 0xC0, 0xDE}}, |
| 4515 | {"Unable to read connection close error details.", |
| 4516 | { |
| 4517 | // error details length |
| 4518 | 0x0, 0x0d, |
| 4519 | // error details |
| 4520 | 'b', 'e', 'c', 'a', |
| 4521 | 'u', 's', 'e', ' ', |
| 4522 | 'I', ' ', 'c', 'a', |
| 4523 | 'n'} |
| 4524 | } |
| 4525 | }; |
| 4526 | |
| 4527 | PacketFragments packet46 = { |
| 4528 | // type (short header, 4 byte packet number) |
| 4529 | {"", |
| 4530 | {0x43}}, |
| 4531 | // connection_id |
| 4532 | {"", |
| 4533 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4534 | // packet number |
| 4535 | {"", |
| 4536 | {0x12, 0x34, 0x56, 0x78}}, |
| 4537 | // frame type (connection close frame) |
| 4538 | {"", |
| 4539 | {0x02}}, |
| 4540 | // error code larger than QUIC_LAST_ERROR |
| 4541 | {"Unable to read connection close error code.", |
| 4542 | {0x00, 0x00, 0xC0, 0xDE}}, |
| 4543 | {"Unable to read connection close error details.", |
| 4544 | { |
| 4545 | // error details length |
| 4546 | 0x0, 0x0d, |
| 4547 | // error details |
| 4548 | 'b', 'e', 'c', 'a', |
| 4549 | 'u', 's', 'e', ' ', |
| 4550 | 'I', ' ', 'c', 'a', |
| 4551 | 'n'} |
| 4552 | } |
| 4553 | }; |
| 4554 | |
| 4555 | PacketFragments packet99 = { |
| 4556 | // type (short header, 4 byte packet number) |
| 4557 | {"", |
| 4558 | {0x43}}, |
| 4559 | // connection_id |
| 4560 | {"", |
| 4561 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4562 | // packet number |
| 4563 | {"", |
| 4564 | {0x12, 0x34, 0x56, 0x78}}, |
| 4565 | // frame type (IETF Transport CONNECTION_CLOSE frame) |
| 4566 | {"", |
| 4567 | {0x1c}}, |
| 4568 | // error code |
| 4569 | {"Unable to read connection close error code.", |
| 4570 | {kVarInt62FourBytes + 0x00, 0x00, 0xC0, 0xDE}}, |
| 4571 | {"Unable to read connection close frame type.", |
| 4572 | {kVarInt62TwoBytes + 0x12, 0x34 }}, |
| 4573 | {"Unable to read connection close error details.", |
| 4574 | { |
| 4575 | // error details length |
| 4576 | kVarInt62OneByte + 0x11, |
| 4577 | // error details with QuicErrorCode larger than QUIC_LAST_ERROR |
| 4578 | '8', '4', '9', ':', |
| 4579 | 'b', 'e', 'c', 'a', |
| 4580 | 'u', 's', 'e', ' ', |
| 4581 | 'I', ' ', 'c', 'a', |
| 4582 | 'n'} |
| 4583 | } |
| 4584 | }; |
| 4585 | // clang-format on |
| 4586 | |
| 4587 | PacketFragments& fragments = |
| 4588 | VersionHasIetfQuicFrames(framer_.transport_version()) |
| 4589 | ? packet99 |
| 4590 | : (framer_.version().HasIetfInvariantHeader() ? packet46 : packet); |
| 4591 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4592 | AssemblePacketFromFragments(fragments)); |
| 4593 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4594 | |
| 4595 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
| 4596 | ASSERT_TRUE(visitor_.header_.get()); |
| 4597 | EXPECT_TRUE(CheckDecryption( |
| 4598 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4599 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4600 | |
| 4601 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 4602 | EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
| 4603 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 4604 | EXPECT_EQ(0x1234u, |
| 4605 | visitor_.connection_close_frame_.transport_close_frame_type); |
| 4606 | EXPECT_EQ(0xC0DEu, visitor_.connection_close_frame_.wire_error_code); |
| 4607 | EXPECT_EQ(849u, visitor_.connection_close_frame_.quic_error_code); |
| 4608 | } else { |
| 4609 | // For Google QUIC frame, |quic_error_code| and |wire_error_code| has the |
| 4610 | // same value. |
| 4611 | if (GetQuicReloadableFlag(quic_do_not_clip_received_error_code)) { |
| 4612 | EXPECT_EQ(0xC0DEu, visitor_.connection_close_frame_.wire_error_code); |
| 4613 | EXPECT_EQ(0xC0DEu, visitor_.connection_close_frame_.quic_error_code); |
| 4614 | } else { |
| 4615 | EXPECT_EQ(QUIC_LAST_ERROR, |
| 4616 | visitor_.connection_close_frame_.wire_error_code); |
| 4617 | EXPECT_EQ(QUIC_LAST_ERROR, |
| 4618 | visitor_.connection_close_frame_.quic_error_code); |
| 4619 | } |
| 4620 | } |
| 4621 | |
| 4622 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 4623 | |
| 4624 | CheckFramingBoundaries(fragments, QUIC_INVALID_CONNECTION_CLOSE_DATA); |
| 4625 | } |
| 4626 | |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4627 | // As above, but checks that for Google-QUIC, if there happens |
| 4628 | // to be an ErrorCode string at the start of the details, it is |
| 4629 | // NOT extracted/parsed/folded/spindled/and/mutilated. |
| 4630 | TEST_P(QuicFramerTest, ConnectionCloseFrameWithExtractedInfoIgnoreGCuic) { |
| 4631 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 4632 | |
| 4633 | // clang-format off |
| 4634 | PacketFragments packet = { |
| 4635 | // public flags (8 byte connection_id) |
| 4636 | {"", |
| 4637 | {0x28}}, |
| 4638 | // connection_id |
| 4639 | {"", |
| 4640 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4641 | // packet number |
| 4642 | {"", |
| 4643 | {0x12, 0x34, 0x56, 0x78}}, |
| 4644 | // frame type (connection close frame) |
| 4645 | {"", |
| 4646 | {0x02}}, |
| 4647 | // error code |
| 4648 | {"Unable to read connection close error code.", |
| 4649 | {0x00, 0x00, 0x00, 0x11}}, |
| 4650 | {"Unable to read connection close error details.", |
| 4651 | { |
| 4652 | // error details length |
| 4653 | 0x0, 0x13, |
| 4654 | // error details |
| 4655 | '1', '7', '7', '6', |
| 4656 | '7', ':', 'b', 'e', |
| 4657 | 'c', 'a', 'u', 's', |
| 4658 | 'e', ' ', 'I', ' ', |
| 4659 | 'c', 'a', 'n'} |
| 4660 | } |
| 4661 | }; |
| 4662 | |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4663 | PacketFragments packet46 = { |
| 4664 | // type (short header, 4 byte packet number) |
| 4665 | {"", |
| 4666 | {0x43}}, |
| 4667 | // connection_id |
| 4668 | {"", |
| 4669 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4670 | // packet number |
| 4671 | {"", |
| 4672 | {0x12, 0x34, 0x56, 0x78}}, |
| 4673 | // frame type (connection close frame) |
| 4674 | {"", |
| 4675 | {0x02}}, |
| 4676 | // error code |
| 4677 | {"Unable to read connection close error code.", |
| 4678 | {0x00, 0x00, 0x00, 0x11}}, |
| 4679 | {"Unable to read connection close error details.", |
| 4680 | { |
| 4681 | // error details length |
| 4682 | 0x0, 0x13, |
| 4683 | // error details |
| 4684 | '1', '7', '7', '6', |
| 4685 | '7', ':', 'b', 'e', |
| 4686 | 'c', 'a', 'u', 's', |
| 4687 | 'e', ' ', 'I', ' ', |
| 4688 | 'c', 'a', 'n'} |
| 4689 | } |
| 4690 | }; |
| 4691 | |
| 4692 | PacketFragments packet99 = { |
| 4693 | // type (short header, 4 byte packet number) |
| 4694 | {"", |
| 4695 | {0x43}}, |
| 4696 | // connection_id |
| 4697 | {"", |
| 4698 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4699 | // packet number |
| 4700 | {"", |
| 4701 | {0x12, 0x34, 0x56, 0x78}}, |
| 4702 | // frame type (IETF Transport CONNECTION_CLOSE frame) |
| 4703 | {"", |
| 4704 | {0x1c}}, |
| 4705 | // error code |
| 4706 | {"Unable to read connection close error code.", |
| 4707 | {kVarInt62OneByte + 0x11}}, |
| 4708 | {"Unable to read connection close frame type.", |
| 4709 | {kVarInt62TwoBytes + 0x12, 0x34 }}, |
| 4710 | {"Unable to read connection close error details.", |
| 4711 | { |
| 4712 | // error details length |
| 4713 | kVarInt62OneByte + 0x13, |
| 4714 | // error details |
| 4715 | '1', '7', '7', '6', |
| 4716 | '7', ':', 'b', 'e', |
| 4717 | 'c', 'a', 'u', 's', |
| 4718 | 'e', ' ', 'I', ' ', |
| 4719 | 'c', 'a', 'n'} |
| 4720 | } |
| 4721 | }; |
| 4722 | // clang-format on |
| 4723 | |
| 4724 | PacketFragments& fragments = |
| 4725 | VersionHasIetfQuicFrames(framer_.transport_version()) |
| 4726 | ? packet99 |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 4727 | : (framer_.version().HasIetfInvariantHeader() ? packet46 : packet); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4728 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4729 | AssemblePacketFromFragments(fragments)); |
| 4730 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4731 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4732 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4733 | ASSERT_TRUE(visitor_.header_.get()); |
| 4734 | EXPECT_TRUE(CheckDecryption( |
| 4735 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4736 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4737 | |
| 4738 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 4739 | EXPECT_EQ(0x11u, static_cast<unsigned>( |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 4740 | visitor_.connection_close_frame_.wire_error_code)); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 4741 | |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4742 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 4743 | EXPECT_EQ(0x1234u, |
| 4744 | visitor_.connection_close_frame_.transport_close_frame_type); |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 4745 | EXPECT_EQ(17767u, visitor_.connection_close_frame_.quic_error_code); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 4746 | EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4747 | } else { |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 4748 | EXPECT_EQ(0x11u, visitor_.connection_close_frame_.quic_error_code); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 4749 | // Error code is not prepended in GQUIC, so it is not removed and should |
| 4750 | // remain in the reason phrase. |
| 4751 | EXPECT_EQ("17767:because I can", |
| 4752 | visitor_.connection_close_frame_.error_details); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4753 | } |
| 4754 | |
| 4755 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 4756 | |
| 4757 | CheckFramingBoundaries(fragments, QUIC_INVALID_CONNECTION_CLOSE_DATA); |
| 4758 | } |
| 4759 | |
fkastenholz | 04bd4f3 | 2019-04-16 12:24:38 -0700 | [diff] [blame] | 4760 | // Test the CONNECTION_CLOSE/Application variant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4761 | TEST_P(QuicFramerTest, ApplicationCloseFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 4762 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 4763 | // This frame is only in IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4764 | return; |
| 4765 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 4766 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4767 | |
| 4768 | // clang-format off |
| 4769 | PacketFragments packet99 = { |
| 4770 | // type (short header, 4 byte packet number) |
| 4771 | {"", |
| 4772 | {0x43}}, |
| 4773 | // connection_id |
| 4774 | {"", |
| 4775 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4776 | // packet number |
| 4777 | {"", |
| 4778 | {0x12, 0x34, 0x56, 0x78}}, |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4779 | // frame type (IETF_CONNECTION_CLOSE/Application frame) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4780 | {"", |
| 4781 | {0x1d}}, |
| 4782 | // error code |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4783 | {"Unable to read connection close error code.", |
fkastenholz | d57d3f9 | 2019-07-16 09:05:17 -0700 | [diff] [blame] | 4784 | {kVarInt62TwoBytes + 0x00, 0x11}}, |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4785 | {"Unable to read connection close error details.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4786 | { |
| 4787 | // error details length |
| 4788 | kVarInt62OneByte + 0x0d, |
| 4789 | // error details |
| 4790 | 'b', 'e', 'c', 'a', |
| 4791 | 'u', 's', 'e', ' ', |
| 4792 | 'I', ' ', 'c', 'a', |
| 4793 | 'n'} |
| 4794 | } |
| 4795 | }; |
| 4796 | // clang-format on |
| 4797 | |
| 4798 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4799 | AssemblePacketFromFragments(packet99)); |
| 4800 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4801 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4802 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4803 | ASSERT_TRUE(visitor_.header_.get()); |
| 4804 | EXPECT_TRUE(CheckDecryption( |
| 4805 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4806 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4807 | |
| 4808 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 4809 | |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4810 | EXPECT_EQ(IETF_QUIC_APPLICATION_CONNECTION_CLOSE, |
| 4811 | visitor_.connection_close_frame_.close_type); |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 4812 | EXPECT_EQ(122u, visitor_.connection_close_frame_.quic_error_code); |
| 4813 | EXPECT_EQ(0x11u, visitor_.connection_close_frame_.wire_error_code); |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 4814 | EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4815 | |
| 4816 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 4817 | |
fkastenholz | 04bd4f3 | 2019-04-16 12:24:38 -0700 | [diff] [blame] | 4818 | CheckFramingBoundaries(packet99, QUIC_INVALID_CONNECTION_CLOSE_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4819 | } |
| 4820 | |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4821 | // Check that we can extract an error code from an application close. |
| 4822 | TEST_P(QuicFramerTest, ApplicationCloseFrameExtract) { |
| 4823 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 4824 | // This frame is only in IETF QUIC. |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4825 | return; |
| 4826 | } |
| 4827 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 4828 | |
| 4829 | // clang-format off |
| 4830 | PacketFragments packet99 = { |
| 4831 | // type (short header, 4 byte packet number) |
| 4832 | {"", |
| 4833 | {0x43}}, |
| 4834 | // connection_id |
| 4835 | {"", |
| 4836 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4837 | // packet number |
| 4838 | {"", |
| 4839 | {0x12, 0x34, 0x56, 0x78}}, |
| 4840 | // frame type (IETF_CONNECTION_CLOSE/Application frame) |
| 4841 | {"", |
| 4842 | {0x1d}}, |
| 4843 | // error code |
| 4844 | {"Unable to read connection close error code.", |
| 4845 | {kVarInt62OneByte + 0x11}}, |
| 4846 | {"Unable to read connection close error details.", |
| 4847 | { |
| 4848 | // error details length |
| 4849 | kVarInt62OneByte + 0x13, |
| 4850 | // error details |
| 4851 | '1', '7', '7', '6', |
| 4852 | '7', ':', 'b', 'e', |
| 4853 | 'c', 'a', 'u', 's', |
| 4854 | 'e', ' ', 'I', ' ', |
| 4855 | 'c', 'a', 'n'} |
| 4856 | } |
| 4857 | }; |
| 4858 | // clang-format on |
| 4859 | |
| 4860 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4861 | AssemblePacketFromFragments(packet99)); |
| 4862 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4863 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 4864 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4865 | ASSERT_TRUE(visitor_.header_.get()); |
| 4866 | EXPECT_TRUE(CheckDecryption( |
| 4867 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4868 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4869 | |
| 4870 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 4871 | |
| 4872 | EXPECT_EQ(IETF_QUIC_APPLICATION_CONNECTION_CLOSE, |
| 4873 | visitor_.connection_close_frame_.close_type); |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 4874 | EXPECT_EQ(17767u, visitor_.connection_close_frame_.quic_error_code); |
| 4875 | EXPECT_EQ(0x11u, visitor_.connection_close_frame_.wire_error_code); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 4876 | EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 4877 | |
| 4878 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 4879 | |
| 4880 | CheckFramingBoundaries(packet99, QUIC_INVALID_CONNECTION_CLOSE_DATA); |
| 4881 | } |
| 4882 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4883 | TEST_P(QuicFramerTest, GoAwayFrame) { |
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 not in IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4886 | return; |
| 4887 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -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 packet = { |
| 4891 | // public flags (8 byte connection_id) |
| 4892 | {"", |
| 4893 | {0x28}}, |
| 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 (go away frame) |
| 4901 | {"", |
| 4902 | {0x03}}, |
| 4903 | // error code |
| 4904 | {"Unable to read go away error code.", |
| 4905 | {0x00, 0x00, 0x00, 0x09}}, |
| 4906 | // stream id |
| 4907 | {"Unable to read last good stream id.", |
| 4908 | {0x01, 0x02, 0x03, 0x04}}, |
| 4909 | // stream id |
| 4910 | {"Unable to read goaway reason.", |
| 4911 | { |
| 4912 | // error details length |
| 4913 | 0x0, 0x0d, |
| 4914 | // error details |
| 4915 | 'b', 'e', 'c', 'a', |
| 4916 | 'u', 's', 'e', ' ', |
| 4917 | 'I', ' ', 'c', 'a', |
| 4918 | 'n'} |
| 4919 | } |
| 4920 | }; |
| 4921 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4922 | PacketFragments packet46 = { |
| 4923 | // type (short header, 4 byte packet number) |
| 4924 | {"", |
| 4925 | {0x43}}, |
| 4926 | // connection_id |
| 4927 | {"", |
| 4928 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4929 | // packet number |
| 4930 | {"", |
| 4931 | {0x12, 0x34, 0x56, 0x78}}, |
| 4932 | // frame type (go away frame) |
| 4933 | {"", |
| 4934 | {0x03}}, |
| 4935 | // error code |
| 4936 | {"Unable to read go away error code.", |
| 4937 | {0x00, 0x00, 0x00, 0x09}}, |
| 4938 | // stream id |
| 4939 | {"Unable to read last good stream id.", |
| 4940 | {0x01, 0x02, 0x03, 0x04}}, |
| 4941 | // stream id |
| 4942 | {"Unable to read goaway reason.", |
| 4943 | { |
| 4944 | // error details length |
| 4945 | 0x0, 0x0d, |
| 4946 | // error details |
| 4947 | 'b', 'e', 'c', 'a', |
| 4948 | 'u', 's', 'e', ' ', |
| 4949 | 'I', ' ', 'c', 'a', |
| 4950 | 'n'} |
| 4951 | } |
| 4952 | }; |
| 4953 | // clang-format on |
| 4954 | |
| 4955 | PacketFragments& fragments = |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 4956 | framer_.version().HasIetfInvariantHeader() ? packet46 : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4957 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4958 | AssemblePacketFromFragments(fragments)); |
| 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_.goaway_frame_.last_good_stream_id); |
fkastenholz | 88d08f4 | 2019-09-06 07:38:04 -0700 | [diff] [blame] | 4968 | EXPECT_EQ(0x9u, visitor_.goaway_frame_.error_code); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 4969 | EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase); |
| 4970 | |
| 4971 | CheckFramingBoundaries(fragments, QUIC_INVALID_GOAWAY_DATA); |
| 4972 | } |
| 4973 | |
bnc | 40fa830 | 2020-09-28 08:16:27 -0700 | [diff] [blame] | 4974 | TEST_P(QuicFramerTest, GoAwayFrameWithUnknownErrorCode) { |
| 4975 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 4976 | // This frame is not in IETF QUIC. |
| 4977 | return; |
| 4978 | } |
| 4979 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 4980 | // clang-format off |
| 4981 | PacketFragments packet = { |
| 4982 | // public flags (8 byte connection_id) |
| 4983 | {"", |
| 4984 | {0x28}}, |
| 4985 | // connection_id |
| 4986 | {"", |
| 4987 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4988 | // packet number |
| 4989 | {"", |
| 4990 | {0x12, 0x34, 0x56, 0x78}}, |
| 4991 | // frame type (go away frame) |
| 4992 | {"", |
| 4993 | {0x03}}, |
| 4994 | // error code larger than QUIC_LAST_ERROR |
| 4995 | {"Unable to read go away error code.", |
| 4996 | {0x00, 0x00, 0xC0, 0xDE}}, |
| 4997 | // stream id |
| 4998 | {"Unable to read last good stream id.", |
| 4999 | {0x01, 0x02, 0x03, 0x04}}, |
| 5000 | // stream id |
| 5001 | {"Unable to read goaway reason.", |
| 5002 | { |
| 5003 | // error details length |
| 5004 | 0x0, 0x0d, |
| 5005 | // error details |
| 5006 | 'b', 'e', 'c', 'a', |
| 5007 | 'u', 's', 'e', ' ', |
| 5008 | 'I', ' ', 'c', 'a', |
| 5009 | 'n'} |
| 5010 | } |
| 5011 | }; |
| 5012 | |
| 5013 | PacketFragments packet46 = { |
| 5014 | // type (short header, 4 byte packet number) |
| 5015 | {"", |
| 5016 | {0x43}}, |
| 5017 | // connection_id |
| 5018 | {"", |
| 5019 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5020 | // packet number |
| 5021 | {"", |
| 5022 | {0x12, 0x34, 0x56, 0x78}}, |
| 5023 | // frame type (go away frame) |
| 5024 | {"", |
| 5025 | {0x03}}, |
| 5026 | // error code larger than QUIC_LAST_ERROR |
| 5027 | {"Unable to read go away error code.", |
| 5028 | {0x00, 0x00, 0xC0, 0xDE}}, |
| 5029 | // stream id |
| 5030 | {"Unable to read last good stream id.", |
| 5031 | {0x01, 0x02, 0x03, 0x04}}, |
| 5032 | // stream id |
| 5033 | {"Unable to read goaway reason.", |
| 5034 | { |
| 5035 | // error details length |
| 5036 | 0x0, 0x0d, |
| 5037 | // error details |
| 5038 | 'b', 'e', 'c', 'a', |
| 5039 | 'u', 's', 'e', ' ', |
| 5040 | 'I', ' ', 'c', 'a', |
| 5041 | 'n'} |
| 5042 | } |
| 5043 | }; |
| 5044 | // clang-format on |
| 5045 | |
| 5046 | PacketFragments& fragments = |
| 5047 | framer_.version().HasIetfInvariantHeader() ? packet46 : packet; |
| 5048 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5049 | AssemblePacketFromFragments(fragments)); |
| 5050 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5051 | |
| 5052 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
| 5053 | ASSERT_TRUE(visitor_.header_.get()); |
| 5054 | EXPECT_TRUE(CheckDecryption( |
| 5055 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5056 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5057 | |
| 5058 | EXPECT_EQ(kStreamId, visitor_.goaway_frame_.last_good_stream_id); |
| 5059 | if (GetQuicReloadableFlag(quic_do_not_clip_received_error_code)) { |
| 5060 | EXPECT_EQ(0xC0DE, visitor_.goaway_frame_.error_code); |
| 5061 | } else { |
| 5062 | EXPECT_EQ(QUIC_LAST_ERROR, visitor_.goaway_frame_.error_code); |
| 5063 | } |
| 5064 | EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase); |
| 5065 | |
| 5066 | CheckFramingBoundaries(fragments, QUIC_INVALID_GOAWAY_DATA); |
| 5067 | } |
| 5068 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5069 | TEST_P(QuicFramerTest, WindowUpdateFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 5070 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 5071 | // This frame is not in IETF QUIC, see MaxDataFrame and MaxStreamDataFrame |
| 5072 | // for IETF QUIC equivalents. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5073 | return; |
| 5074 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 5075 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5076 | // clang-format off |
| 5077 | PacketFragments packet = { |
| 5078 | // public flags (8 byte connection_id) |
| 5079 | {"", |
| 5080 | {0x28}}, |
| 5081 | // connection_id |
| 5082 | {"", |
| 5083 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5084 | // packet number |
| 5085 | {"", |
| 5086 | {0x12, 0x34, 0x56, 0x78}}, |
| 5087 | // frame type (window update frame) |
| 5088 | {"", |
| 5089 | {0x04}}, |
| 5090 | // stream id |
| 5091 | {"Unable to read stream_id.", |
| 5092 | {0x01, 0x02, 0x03, 0x04}}, |
| 5093 | // byte offset |
| 5094 | {"Unable to read window byte_offset.", |
| 5095 | {0x3A, 0x98, 0xFE, 0xDC, |
| 5096 | 0x32, 0x10, 0x76, 0x54}}, |
| 5097 | }; |
| 5098 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5099 | PacketFragments packet46 = { |
| 5100 | // type (short header, 4 byte packet number) |
| 5101 | {"", |
| 5102 | {0x43}}, |
| 5103 | // connection_id |
| 5104 | {"", |
| 5105 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5106 | // packet number |
| 5107 | {"", |
| 5108 | {0x12, 0x34, 0x56, 0x78}}, |
| 5109 | // frame type (window update frame) |
| 5110 | {"", |
| 5111 | {0x04}}, |
| 5112 | // stream id |
| 5113 | {"Unable to read stream_id.", |
| 5114 | {0x01, 0x02, 0x03, 0x04}}, |
| 5115 | // byte offset |
| 5116 | {"Unable to read window byte_offset.", |
| 5117 | {0x3A, 0x98, 0xFE, 0xDC, |
| 5118 | 0x32, 0x10, 0x76, 0x54}}, |
| 5119 | }; |
| 5120 | |
| 5121 | // clang-format on |
| 5122 | |
| 5123 | PacketFragments& fragments = |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 5124 | framer_.version().HasIetfInvariantHeader() ? packet46 : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5125 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5126 | AssemblePacketFromFragments(fragments)); |
| 5127 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5128 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5129 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5130 | ASSERT_TRUE(visitor_.header_.get()); |
| 5131 | EXPECT_TRUE(CheckDecryption( |
| 5132 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5133 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5134 | |
| 5135 | EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id); |
renjietang | d088eab | 2019-11-21 14:54:41 -0800 | [diff] [blame] | 5136 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.max_data); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5137 | |
| 5138 | CheckFramingBoundaries(fragments, QUIC_INVALID_WINDOW_UPDATE_DATA); |
| 5139 | } |
| 5140 | |
| 5141 | TEST_P(QuicFramerTest, MaxDataFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 5142 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 5143 | // This frame is available only in IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5144 | return; |
| 5145 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5146 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5147 | // clang-format off |
| 5148 | PacketFragments packet99 = { |
| 5149 | // type (short header, 4 byte packet number) |
| 5150 | {"", |
| 5151 | {0x43}}, |
| 5152 | // connection_id |
| 5153 | {"", |
| 5154 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5155 | // packet number |
| 5156 | {"", |
| 5157 | {0x12, 0x34, 0x56, 0x78}}, |
| 5158 | // frame type (IETF_MAX_DATA frame) |
| 5159 | {"", |
| 5160 | {0x10}}, |
| 5161 | // byte offset |
| 5162 | {"Can not read MAX_DATA byte-offset", |
| 5163 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 5164 | 0x32, 0x10, 0x76, 0x54}}, |
| 5165 | }; |
| 5166 | // clang-format on |
| 5167 | |
| 5168 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5169 | AssemblePacketFromFragments(packet99)); |
| 5170 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5171 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5172 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5173 | ASSERT_TRUE(visitor_.header_.get()); |
| 5174 | EXPECT_TRUE(CheckDecryption( |
| 5175 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5176 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5177 | |
| 5178 | EXPECT_EQ(QuicUtils::GetInvalidStreamId(framer_.transport_version()), |
| 5179 | visitor_.window_update_frame_.stream_id); |
renjietang | d088eab | 2019-11-21 14:54:41 -0800 | [diff] [blame] | 5180 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.max_data); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5181 | |
| 5182 | CheckFramingBoundaries(packet99, QUIC_INVALID_MAX_DATA_FRAME_DATA); |
| 5183 | } |
| 5184 | |
| 5185 | TEST_P(QuicFramerTest, MaxStreamDataFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 5186 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 5187 | // This frame available only in IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5188 | return; |
| 5189 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5190 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5191 | // clang-format off |
| 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 | // frame type (IETF_MAX_STREAM_DATA frame) |
| 5203 | {"", |
| 5204 | {0x11}}, |
| 5205 | // stream id |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 5206 | {"Unable to read IETF_MAX_STREAM_DATA frame stream id/count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5207 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 5208 | // byte offset |
| 5209 | {"Can not read MAX_STREAM_DATA byte-count", |
| 5210 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 5211 | 0x32, 0x10, 0x76, 0x54}}, |
| 5212 | }; |
| 5213 | // clang-format on |
| 5214 | |
| 5215 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5216 | AssemblePacketFromFragments(packet99)); |
| 5217 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5218 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5219 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5220 | ASSERT_TRUE(visitor_.header_.get()); |
| 5221 | EXPECT_TRUE(CheckDecryption( |
| 5222 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5223 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5224 | |
| 5225 | EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id); |
renjietang | d088eab | 2019-11-21 14:54:41 -0800 | [diff] [blame] | 5226 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.max_data); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5227 | |
| 5228 | CheckFramingBoundaries(packet99, QUIC_INVALID_MAX_STREAM_DATA_FRAME_DATA); |
| 5229 | } |
| 5230 | |
| 5231 | TEST_P(QuicFramerTest, BlockedFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5232 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5233 | // clang-format off |
| 5234 | PacketFragments packet = { |
| 5235 | // public flags (8 byte connection_id) |
| 5236 | {"", |
| 5237 | {0x28}}, |
| 5238 | // connection_id |
| 5239 | {"", |
| 5240 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5241 | // packet number |
| 5242 | {"", |
| 5243 | {0x12, 0x34, 0x56, 0x78}}, |
| 5244 | // frame type (blocked frame) |
| 5245 | {"", |
| 5246 | {0x05}}, |
| 5247 | // stream id |
| 5248 | {"Unable to read stream_id.", |
| 5249 | {0x01, 0x02, 0x03, 0x04}}, |
| 5250 | }; |
| 5251 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5252 | PacketFragments packet46 = { |
| 5253 | // type (short header, 4 byte packet number) |
| 5254 | {"", |
| 5255 | {0x43}}, |
| 5256 | // connection_id |
| 5257 | {"", |
| 5258 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5259 | // packet number |
| 5260 | {"", |
| 5261 | {0x12, 0x34, 0x56, 0x78}}, |
| 5262 | // frame type (blocked frame) |
| 5263 | {"", |
| 5264 | {0x05}}, |
| 5265 | // stream id |
| 5266 | {"Unable to read stream_id.", |
| 5267 | {0x01, 0x02, 0x03, 0x04}}, |
| 5268 | }; |
| 5269 | |
| 5270 | PacketFragments packet99 = { |
| 5271 | // type (short header, 4 byte packet number) |
| 5272 | {"", |
| 5273 | {0x43}}, |
| 5274 | // connection_id |
| 5275 | {"", |
| 5276 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5277 | // packet number |
| 5278 | {"", |
| 5279 | {0x12, 0x34, 0x56, 0x78}}, |
| 5280 | // frame type (IETF_STREAM_BLOCKED frame) |
| 5281 | {"", |
| 5282 | {0x15}}, |
| 5283 | // stream id |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 5284 | {"Unable to read IETF_STREAM_DATA_BLOCKED frame stream id/count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5285 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 5286 | // Offset |
| 5287 | {"Can not read stream blocked offset.", |
| 5288 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 5289 | }; |
| 5290 | // clang-format on |
| 5291 | |
| 5292 | PacketFragments& fragments = |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 5293 | VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5294 | ? packet99 |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 5295 | : (framer_.version().HasIetfInvariantHeader() ? packet46 : packet); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5296 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5297 | AssemblePacketFromFragments(fragments)); |
| 5298 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5299 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5300 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5301 | ASSERT_TRUE(visitor_.header_.get()); |
| 5302 | EXPECT_TRUE(CheckDecryption( |
| 5303 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5304 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5305 | |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 5306 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5307 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 5308 | } else { |
| 5309 | EXPECT_EQ(0u, visitor_.blocked_frame_.offset); |
| 5310 | } |
| 5311 | EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id); |
| 5312 | |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 5313 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5314 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_BLOCKED_DATA); |
| 5315 | } else { |
| 5316 | CheckFramingBoundaries(fragments, QUIC_INVALID_BLOCKED_DATA); |
| 5317 | } |
| 5318 | } |
| 5319 | |
| 5320 | TEST_P(QuicFramerTest, PingFrame) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5321 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5322 | // clang-format off |
| 5323 | unsigned char packet[] = { |
| 5324 | // public flags (8 byte connection_id) |
| 5325 | 0x28, |
| 5326 | // connection_id |
| 5327 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5328 | // packet number |
| 5329 | 0x12, 0x34, 0x56, 0x78, |
| 5330 | |
| 5331 | // frame type (ping frame) |
| 5332 | 0x07, |
| 5333 | }; |
| 5334 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5335 | unsigned char packet46[] = { |
| 5336 | // type (short header, 4 byte packet number) |
| 5337 | 0x43, |
| 5338 | // connection_id |
| 5339 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5340 | // packet number |
| 5341 | 0x12, 0x34, 0x56, 0x78, |
| 5342 | |
| 5343 | // frame type |
| 5344 | 0x07, |
| 5345 | }; |
| 5346 | |
| 5347 | unsigned char packet99[] = { |
| 5348 | // type (short header, 4 byte packet number) |
| 5349 | 0x43, |
| 5350 | // connection_id |
| 5351 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5352 | // packet number |
| 5353 | 0x12, 0x34, 0x56, 0x78, |
| 5354 | |
| 5355 | // frame type (IETF_PING frame) |
| 5356 | 0x01, |
| 5357 | }; |
| 5358 | // clang-format on |
| 5359 | |
| 5360 | QuicEncryptedPacket encrypted( |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 5361 | AsChars(VersionHasIetfQuicFrames(framer_.transport_version()) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5362 | ? packet99 |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 5363 | : (framer_.version().HasIetfInvariantHeader() ? packet46 |
| 5364 | : packet)), |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 5365 | VersionHasIetfQuicFrames(framer_.transport_version()) |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 5366 | ? ABSL_ARRAYSIZE(packet99) |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 5367 | : (framer_.version().HasIetfInvariantHeader() |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 5368 | ? ABSL_ARRAYSIZE(packet46) |
| 5369 | : ABSL_ARRAYSIZE(packet)), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5370 | false); |
| 5371 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 5372 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5373 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5374 | ASSERT_TRUE(visitor_.header_.get()); |
| 5375 | EXPECT_TRUE(CheckDecryption( |
| 5376 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5377 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5378 | |
| 5379 | EXPECT_EQ(1u, visitor_.ping_frames_.size()); |
| 5380 | |
| 5381 | // No need to check the PING frame boundaries because it has no payload. |
| 5382 | } |
| 5383 | |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 5384 | TEST_P(QuicFramerTest, HandshakeDoneFrame) { |
| 5385 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 5386 | // clang-format off |
| 5387 | unsigned char packet[] = { |
| 5388 | // type (short header, 4 byte packet number) |
| 5389 | 0x43, |
| 5390 | // connection_id |
| 5391 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5392 | // packet number |
| 5393 | 0x12, 0x34, 0x56, 0x78, |
| 5394 | |
| 5395 | // frame type (Handshake done frame) |
| 5396 | 0x1e, |
| 5397 | }; |
| 5398 | // clang-format on |
| 5399 | |
| 5400 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 5401 | return; |
| 5402 | } |
| 5403 | |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 5404 | QuicEncryptedPacket encrypted(AsChars(packet), ABSL_ARRAYSIZE(packet), false); |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 5405 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 5406 | |
| 5407 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
| 5408 | ASSERT_TRUE(visitor_.header_.get()); |
| 5409 | EXPECT_TRUE(CheckDecryption( |
| 5410 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5411 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5412 | |
| 5413 | EXPECT_EQ(1u, visitor_.handshake_done_frames_.size()); |
| 5414 | } |
| 5415 | |
haoyuewang | 6a6a0ff | 2020-06-23 16:32:26 -0700 | [diff] [blame] | 5416 | TEST_P(QuicFramerTest, ParseAckFrequencyFrame) { |
| 5417 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 5418 | // clang-format off |
| 5419 | unsigned char packet[] = { |
| 5420 | // type (short header, 4 byte packet number) |
| 5421 | 0x43, |
| 5422 | // connection_id |
| 5423 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5424 | // packet number |
| 5425 | 0x12, 0x34, 0x56, 0x78, |
| 5426 | |
| 5427 | // ack frequency frame type (which needs two bytes as it is > 0x3F) |
| 5428 | 0x40, 0xAF, |
| 5429 | // sequence_number |
| 5430 | 0x11, |
| 5431 | // packet_tolerance |
| 5432 | 0x02, |
| 5433 | // max_ack_delay_us = 2'5000 us |
| 5434 | 0x80, 0x00, 0x61, 0xA8, |
| 5435 | // ignore_order |
| 5436 | 0x01 |
| 5437 | }; |
| 5438 | // clang-format on |
| 5439 | |
| 5440 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 5441 | return; |
| 5442 | } |
| 5443 | |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 5444 | QuicEncryptedPacket encrypted(AsChars(packet), ABSL_ARRAYSIZE(packet), false); |
haoyuewang | 6a6a0ff | 2020-06-23 16:32:26 -0700 | [diff] [blame] | 5445 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 5446 | |
| 5447 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
| 5448 | ASSERT_TRUE(visitor_.header_.get()); |
| 5449 | EXPECT_TRUE(CheckDecryption( |
| 5450 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5451 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5452 | |
| 5453 | ASSERT_EQ(1u, visitor_.ack_frequency_frames_.size()); |
| 5454 | const auto& frame = visitor_.ack_frequency_frames_.front(); |
| 5455 | EXPECT_EQ(17u, frame->sequence_number); |
| 5456 | EXPECT_EQ(2u, frame->packet_tolerance); |
| 5457 | EXPECT_EQ(2'5000u, frame->max_ack_delay.ToMicroseconds()); |
| 5458 | EXPECT_EQ(true, frame->ignore_order); |
| 5459 | } |
| 5460 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5461 | TEST_P(QuicFramerTest, MessageFrame) { |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 5462 | if (!VersionSupportsMessageFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5463 | return; |
| 5464 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5465 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5466 | // clang-format off |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5467 | PacketFragments packet46 = { |
| 5468 | // type (short header, 4 byte packet number) |
| 5469 | {"", |
| 5470 | {0x43}}, |
| 5471 | // connection_id |
| 5472 | {"", |
| 5473 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5474 | // packet number |
| 5475 | {"", |
| 5476 | {0x12, 0x34, 0x56, 0x78}}, |
| 5477 | // message frame type. |
| 5478 | {"", |
| 5479 | { 0x21 }}, |
| 5480 | // message length |
| 5481 | {"Unable to read message length", |
| 5482 | {0x07}}, |
| 5483 | // message data |
| 5484 | {"Unable to read message data", |
| 5485 | {'m', 'e', 's', 's', 'a', 'g', 'e'}}, |
| 5486 | // message frame no length. |
| 5487 | {"", |
| 5488 | { 0x20 }}, |
| 5489 | // message data |
| 5490 | {{}, |
| 5491 | {'m', 'e', 's', 's', 'a', 'g', 'e', '2'}}, |
| 5492 | }; |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 5493 | PacketFragments packet99 = { |
| 5494 | // type (short header, 4 byte packet number) |
| 5495 | {"", |
| 5496 | {0x43}}, |
| 5497 | // connection_id |
| 5498 | {"", |
| 5499 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5500 | // packet number |
| 5501 | {"", |
| 5502 | {0x12, 0x34, 0x56, 0x78}}, |
| 5503 | // message frame type. |
| 5504 | {"", |
| 5505 | { 0x31 }}, |
| 5506 | // message length |
| 5507 | {"Unable to read message length", |
| 5508 | {0x07}}, |
| 5509 | // message data |
| 5510 | {"Unable to read message data", |
| 5511 | {'m', 'e', 's', 's', 'a', 'g', 'e'}}, |
| 5512 | // message frame no length. |
| 5513 | {"", |
| 5514 | { 0x30 }}, |
| 5515 | // message data |
| 5516 | {{}, |
| 5517 | {'m', 'e', 's', 's', 'a', 'g', 'e', '2'}}, |
| 5518 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5519 | // clang-format on |
| 5520 | |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 5521 | std::unique_ptr<QuicEncryptedPacket> encrypted; |
| 5522 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 5523 | encrypted = AssemblePacketFromFragments(packet99); |
| 5524 | } else { |
| 5525 | encrypted = AssemblePacketFromFragments(packet46); |
| 5526 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5527 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5528 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5529 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5530 | ASSERT_TRUE(visitor_.header_.get()); |
| 5531 | EXPECT_TRUE(CheckDecryption( |
| 5532 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5533 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5534 | |
| 5535 | ASSERT_EQ(2u, visitor_.message_frames_.size()); |
| 5536 | EXPECT_EQ(7u, visitor_.message_frames_[0]->message_length); |
| 5537 | EXPECT_EQ(8u, visitor_.message_frames_[1]->message_length); |
| 5538 | |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 5539 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 5540 | CheckFramingBoundaries(packet99, QUIC_INVALID_MESSAGE_DATA); |
| 5541 | } else { |
| 5542 | CheckFramingBoundaries(packet46, QUIC_INVALID_MESSAGE_DATA); |
| 5543 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5544 | } |
| 5545 | |
| 5546 | TEST_P(QuicFramerTest, PublicResetPacketV33) { |
| 5547 | // clang-format off |
| 5548 | PacketFragments packet = { |
| 5549 | // public flags (public reset, 8 byte connection_id) |
| 5550 | {"", |
| 5551 | {0x0A}}, |
| 5552 | // connection_id |
| 5553 | {"", |
| 5554 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5555 | {"Unable to read reset message.", |
| 5556 | { |
| 5557 | // message tag (kPRST) |
| 5558 | 'P', 'R', 'S', 'T', |
| 5559 | // num_entries (2) + padding |
| 5560 | 0x02, 0x00, 0x00, 0x00, |
| 5561 | // tag kRNON |
| 5562 | 'R', 'N', 'O', 'N', |
| 5563 | // end offset 8 |
| 5564 | 0x08, 0x00, 0x00, 0x00, |
| 5565 | // tag kRSEQ |
| 5566 | 'R', 'S', 'E', 'Q', |
| 5567 | // end offset 16 |
| 5568 | 0x10, 0x00, 0x00, 0x00, |
| 5569 | // nonce proof |
| 5570 | 0x89, 0x67, 0x45, 0x23, |
| 5571 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5572 | // rejected packet number |
| 5573 | 0xBC, 0x9A, 0x78, 0x56, |
| 5574 | 0x34, 0x12, 0x00, 0x00, |
| 5575 | } |
| 5576 | } |
| 5577 | }; |
| 5578 | // clang-format on |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 5579 | if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5580 | return; |
| 5581 | } |
| 5582 | |
| 5583 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5584 | AssemblePacketFromFragments(packet)); |
| 5585 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5586 | ASSERT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5587 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 5588 | EXPECT_EQ(FramerTestConnectionId(), |
| 5589 | visitor_.public_reset_packet_->connection_id); |
| 5590 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 5591 | EXPECT_EQ( |
| 5592 | IpAddressFamily::IP_UNSPEC, |
| 5593 | visitor_.public_reset_packet_->client_address.host().address_family()); |
| 5594 | |
| 5595 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 5596 | } |
| 5597 | |
| 5598 | TEST_P(QuicFramerTest, PublicResetPacket) { |
| 5599 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5600 | |
| 5601 | // clang-format off |
| 5602 | PacketFragments packet = { |
| 5603 | // public flags (public reset, 8 byte connection_id) |
| 5604 | {"", |
| 5605 | {0x0E}}, |
| 5606 | // connection_id |
| 5607 | {"", |
| 5608 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5609 | {"Unable to read reset message.", |
| 5610 | { |
| 5611 | // message tag (kPRST) |
| 5612 | 'P', 'R', 'S', 'T', |
| 5613 | // num_entries (2) + padding |
| 5614 | 0x02, 0x00, 0x00, 0x00, |
| 5615 | // tag kRNON |
| 5616 | 'R', 'N', 'O', 'N', |
| 5617 | // end offset 8 |
| 5618 | 0x08, 0x00, 0x00, 0x00, |
| 5619 | // tag kRSEQ |
| 5620 | 'R', 'S', 'E', 'Q', |
| 5621 | // end offset 16 |
| 5622 | 0x10, 0x00, 0x00, 0x00, |
| 5623 | // nonce proof |
| 5624 | 0x89, 0x67, 0x45, 0x23, |
| 5625 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5626 | // rejected packet number |
| 5627 | 0xBC, 0x9A, 0x78, 0x56, |
| 5628 | 0x34, 0x12, 0x00, 0x00, |
| 5629 | } |
| 5630 | } |
| 5631 | }; |
| 5632 | // clang-format on |
| 5633 | |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 5634 | if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5635 | return; |
| 5636 | } |
| 5637 | |
| 5638 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5639 | AssemblePacketFromFragments(packet)); |
| 5640 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5641 | ASSERT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5642 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 5643 | EXPECT_EQ(FramerTestConnectionId(), |
| 5644 | visitor_.public_reset_packet_->connection_id); |
| 5645 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 5646 | EXPECT_EQ( |
| 5647 | IpAddressFamily::IP_UNSPEC, |
| 5648 | visitor_.public_reset_packet_->client_address.host().address_family()); |
| 5649 | |
| 5650 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 5651 | } |
| 5652 | |
| 5653 | TEST_P(QuicFramerTest, PublicResetPacketWithTrailingJunk) { |
| 5654 | // clang-format off |
| 5655 | unsigned char packet[] = { |
| 5656 | // public flags (public reset, 8 byte connection_id) |
| 5657 | 0x0A, |
| 5658 | // connection_id |
| 5659 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5660 | // message tag (kPRST) |
| 5661 | 'P', 'R', 'S', 'T', |
| 5662 | // num_entries (2) + padding |
| 5663 | 0x02, 0x00, 0x00, 0x00, |
| 5664 | // tag kRNON |
| 5665 | 'R', 'N', 'O', 'N', |
| 5666 | // end offset 8 |
| 5667 | 0x08, 0x00, 0x00, 0x00, |
| 5668 | // tag kRSEQ |
| 5669 | 'R', 'S', 'E', 'Q', |
| 5670 | // end offset 16 |
| 5671 | 0x10, 0x00, 0x00, 0x00, |
| 5672 | // nonce proof |
| 5673 | 0x89, 0x67, 0x45, 0x23, |
| 5674 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5675 | // rejected packet number |
| 5676 | 0xBC, 0x9A, 0x78, 0x56, |
| 5677 | 0x34, 0x12, 0x00, 0x00, |
| 5678 | // trailing junk |
| 5679 | 'j', 'u', 'n', 'k', |
| 5680 | }; |
| 5681 | // clang-format on |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 5682 | if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5683 | return; |
| 5684 | } |
| 5685 | |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 5686 | QuicEncryptedPacket encrypted(AsChars(packet), ABSL_ARRAYSIZE(packet), false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5687 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
bnc | f54082a | 2019-11-27 10:19:47 -0800 | [diff] [blame] | 5688 | ASSERT_THAT(framer_.error(), IsError(QUIC_INVALID_PUBLIC_RST_PACKET)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5689 | EXPECT_EQ("Unable to read reset message.", framer_.detailed_error()); |
| 5690 | } |
| 5691 | |
| 5692 | TEST_P(QuicFramerTest, PublicResetPacketWithClientAddress) { |
| 5693 | // clang-format off |
| 5694 | PacketFragments packet = { |
| 5695 | // public flags (public reset, 8 byte connection_id) |
| 5696 | {"", |
| 5697 | {0x0A}}, |
| 5698 | // connection_id |
| 5699 | {"", |
| 5700 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5701 | {"Unable to read reset message.", |
| 5702 | { |
| 5703 | // message tag (kPRST) |
| 5704 | 'P', 'R', 'S', 'T', |
| 5705 | // num_entries (2) + padding |
| 5706 | 0x03, 0x00, 0x00, 0x00, |
| 5707 | // tag kRNON |
| 5708 | 'R', 'N', 'O', 'N', |
| 5709 | // end offset 8 |
| 5710 | 0x08, 0x00, 0x00, 0x00, |
| 5711 | // tag kRSEQ |
| 5712 | 'R', 'S', 'E', 'Q', |
| 5713 | // end offset 16 |
| 5714 | 0x10, 0x00, 0x00, 0x00, |
| 5715 | // tag kCADR |
| 5716 | 'C', 'A', 'D', 'R', |
| 5717 | // end offset 24 |
| 5718 | 0x18, 0x00, 0x00, 0x00, |
| 5719 | // nonce proof |
| 5720 | 0x89, 0x67, 0x45, 0x23, |
| 5721 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5722 | // rejected packet number |
| 5723 | 0xBC, 0x9A, 0x78, 0x56, |
| 5724 | 0x34, 0x12, 0x00, 0x00, |
| 5725 | // client address: 4.31.198.44:443 |
| 5726 | 0x02, 0x00, |
| 5727 | 0x04, 0x1F, 0xC6, 0x2C, |
| 5728 | 0xBB, 0x01, |
| 5729 | } |
| 5730 | } |
| 5731 | }; |
| 5732 | // clang-format on |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 5733 | if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5734 | return; |
| 5735 | } |
| 5736 | |
| 5737 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5738 | AssemblePacketFromFragments(packet)); |
| 5739 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5740 | ASSERT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5741 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 5742 | EXPECT_EQ(FramerTestConnectionId(), |
| 5743 | visitor_.public_reset_packet_->connection_id); |
| 5744 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 5745 | EXPECT_EQ("4.31.198.44", |
| 5746 | visitor_.public_reset_packet_->client_address.host().ToString()); |
| 5747 | EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port()); |
| 5748 | |
| 5749 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 5750 | } |
| 5751 | |
| 5752 | TEST_P(QuicFramerTest, IetfStatelessResetPacket) { |
| 5753 | // clang-format off |
| 5754 | unsigned char packet[] = { |
| 5755 | // type (short packet, 1 byte packet number) |
| 5756 | 0x50, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5757 | // Random bytes |
| 5758 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5759 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5760 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5761 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5762 | // stateless reset token |
| 5763 | 0xB5, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5764 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5765 | }; |
| 5766 | // clang-format on |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 5767 | if (!framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5768 | return; |
| 5769 | } |
| 5770 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
dschinazi | b953d02 | 2019-08-01 18:05:58 -0700 | [diff] [blame] | 5771 | QuicFramerPeer::SetLastSerializedServerConnectionId(&framer_, |
| 5772 | TestConnectionId(0x33)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5773 | decrypter_ = new test::TestDecrypter(); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5774 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 5775 | framer_.InstallDecrypter( |
| 5776 | ENCRYPTION_INITIAL, |
| 5777 | std::make_unique<NullDecrypter>(Perspective::IS_CLIENT)); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5778 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 5779 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 5780 | } else { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 5781 | framer_.SetDecrypter(ENCRYPTION_INITIAL, std::make_unique<NullDecrypter>( |
| 5782 | Perspective::IS_CLIENT)); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5783 | framer_.SetAlternativeDecrypter( |
| 5784 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 5785 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5786 | // This packet cannot be decrypted because diversification nonce is missing. |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 5787 | QuicEncryptedPacket encrypted(AsChars(packet), ABSL_ARRAYSIZE(packet), false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5788 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5789 | ASSERT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5790 | ASSERT_TRUE(visitor_.stateless_reset_packet_.get()); |
| 5791 | EXPECT_EQ(kTestStatelessResetToken, |
| 5792 | visitor_.stateless_reset_packet_->stateless_reset_token); |
| 5793 | } |
| 5794 | |
| 5795 | TEST_P(QuicFramerTest, IetfStatelessResetPacketInvalidStatelessResetToken) { |
| 5796 | // clang-format off |
| 5797 | unsigned char packet[] = { |
| 5798 | // type (short packet, 1 byte packet number) |
| 5799 | 0x50, |
dschinazi | b953d02 | 2019-08-01 18:05:58 -0700 | [diff] [blame] | 5800 | // Random bytes |
| 5801 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5802 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5803 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5804 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5805 | // stateless reset token |
| 5806 | 0xB6, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5807 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5808 | }; |
| 5809 | // clang-format on |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 5810 | if (!framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5811 | return; |
| 5812 | } |
dschinazi | b953d02 | 2019-08-01 18:05:58 -0700 | [diff] [blame] | 5813 | QuicFramerPeer::SetLastSerializedServerConnectionId(&framer_, |
| 5814 | TestConnectionId(0x33)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5815 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5816 | decrypter_ = new test::TestDecrypter(); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5817 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 5818 | framer_.InstallDecrypter( |
| 5819 | ENCRYPTION_INITIAL, |
| 5820 | std::make_unique<NullDecrypter>(Perspective::IS_CLIENT)); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5821 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
| 5822 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 5823 | } else { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 5824 | framer_.SetDecrypter(ENCRYPTION_INITIAL, std::make_unique<NullDecrypter>( |
| 5825 | Perspective::IS_CLIENT)); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 5826 | framer_.SetAlternativeDecrypter( |
| 5827 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 5828 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5829 | // This packet cannot be decrypted because diversification nonce is missing. |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 5830 | QuicEncryptedPacket encrypted(AsChars(packet), ABSL_ARRAYSIZE(packet), false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5831 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5832 | EXPECT_THAT(framer_.error(), IsError(QUIC_DECRYPTION_FAILURE)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5833 | ASSERT_FALSE(visitor_.stateless_reset_packet_); |
| 5834 | } |
| 5835 | |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 5836 | TEST_P(QuicFramerTest, VersionNegotiationPacketClient) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5837 | // clang-format off |
| 5838 | PacketFragments packet = { |
| 5839 | // public flags (version, 8 byte connection_id) |
| 5840 | {"", |
| 5841 | {0x29}}, |
| 5842 | // connection_id |
| 5843 | {"", |
| 5844 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5845 | // version tag |
| 5846 | {"Unable to read supported version in negotiation.", |
| 5847 | {QUIC_VERSION_BYTES, |
| 5848 | 'Q', '2', '.', '0'}}, |
| 5849 | }; |
| 5850 | |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 5851 | PacketFragments packet46 = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5852 | // type (long header) |
| 5853 | {"", |
| 5854 | {0x8F}}, |
| 5855 | // version tag |
| 5856 | {"", |
| 5857 | {0x00, 0x00, 0x00, 0x00}}, |
| 5858 | {"", |
| 5859 | {0x05}}, |
| 5860 | // connection_id |
| 5861 | {"", |
| 5862 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5863 | // Supported versions |
| 5864 | {"Unable to read supported version in negotiation.", |
| 5865 | {QUIC_VERSION_BYTES, |
| 5866 | 'Q', '2', '.', '0'}}, |
| 5867 | }; |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 5868 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 5869 | PacketFragments packet49 = { |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 5870 | // type (long header) |
| 5871 | {"", |
| 5872 | {0x8F}}, |
| 5873 | // version tag |
| 5874 | {"", |
| 5875 | {0x00, 0x00, 0x00, 0x00}}, |
| 5876 | {"", |
| 5877 | {0x08}}, |
| 5878 | // connection_id |
| 5879 | {"", |
| 5880 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5881 | {"", |
| 5882 | {0x00}}, |
| 5883 | // Supported versions |
| 5884 | {"Unable to read supported version in negotiation.", |
| 5885 | {QUIC_VERSION_BYTES, |
| 5886 | 'Q', '2', '.', '0'}}, |
| 5887 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5888 | // clang-format on |
| 5889 | |
| 5890 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5891 | |
| 5892 | PacketFragments& fragments = |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 5893 | framer_.version().HasLongHeaderLengths() ? packet49 |
| 5894 | : framer_.version().HasIetfInvariantHeader() ? packet46 |
| 5895 | : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5896 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5897 | AssemblePacketFromFragments(fragments)); |
| 5898 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5899 | ASSERT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5900 | ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); |
nharper | 4fd1105 | 2019-06-04 14:23:22 -0700 | [diff] [blame] | 5901 | EXPECT_EQ(1u, visitor_.version_negotiation_packet_->versions.size()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5902 | EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]); |
| 5903 | |
| 5904 | // Remove the last version from the packet so that every truncated |
| 5905 | // version of the packet is invalid, otherwise checking boundaries |
| 5906 | // is annoyingly complicated. |
| 5907 | for (size_t i = 0; i < 4; ++i) { |
| 5908 | fragments.back().fragment.pop_back(); |
| 5909 | } |
| 5910 | CheckFramingBoundaries(fragments, QUIC_INVALID_VERSION_NEGOTIATION_PACKET); |
| 5911 | } |
| 5912 | |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 5913 | TEST_P(QuicFramerTest, VersionNegotiationPacketServer) { |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 5914 | if (!framer_.version().HasIetfInvariantHeader()) { |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 5915 | return; |
| 5916 | } |
| 5917 | |
| 5918 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 5919 | // clang-format off |
| 5920 | unsigned char packet[] = { |
| 5921 | // public flags (long header with all ignored bits set) |
| 5922 | 0xFF, |
| 5923 | // version |
| 5924 | 0x00, 0x00, 0x00, 0x00, |
| 5925 | // connection ID lengths |
| 5926 | 0x50, |
| 5927 | // destination connection ID |
| 5928 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 5929 | // supported versions |
| 5930 | QUIC_VERSION_BYTES, |
| 5931 | 'Q', '2', '.', '0', |
| 5932 | }; |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 5933 | unsigned char packet2[] = { |
| 5934 | // public flags (long header with all ignored bits set) |
| 5935 | 0xFF, |
| 5936 | // version |
| 5937 | 0x00, 0x00, 0x00, 0x00, |
| 5938 | // destination connection ID length |
| 5939 | 0x08, |
| 5940 | // destination connection ID |
| 5941 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 5942 | // source connection ID length |
| 5943 | 0x00, |
| 5944 | // supported versions |
| 5945 | QUIC_VERSION_BYTES, |
| 5946 | 'Q', '2', '.', '0', |
| 5947 | }; |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 5948 | // clang-format on |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 5949 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 5950 | size_t p_length = ABSL_ARRAYSIZE(packet); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 5951 | if (framer_.version().HasLengthPrefixedConnectionIds()) { |
| 5952 | p = packet2; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 5953 | p_length = ABSL_ARRAYSIZE(packet2); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 5954 | } |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 5955 | |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 5956 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 5957 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5958 | EXPECT_THAT(framer_.error(), |
| 5959 | IsError(QUIC_INVALID_VERSION_NEGOTIATION_PACKET)); |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 5960 | EXPECT_EQ("Server received version negotiation packet.", |
| 5961 | framer_.detailed_error()); |
| 5962 | EXPECT_FALSE(visitor_.version_negotiation_packet_.get()); |
| 5963 | } |
| 5964 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5965 | TEST_P(QuicFramerTest, OldVersionNegotiationPacket) { |
| 5966 | // clang-format off |
| 5967 | PacketFragments packet = { |
| 5968 | // public flags (version, 8 byte connection_id) |
| 5969 | {"", |
| 5970 | {0x2D}}, |
| 5971 | // connection_id |
| 5972 | {"", |
| 5973 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5974 | // version tag |
| 5975 | {"Unable to read supported version in negotiation.", |
| 5976 | {QUIC_VERSION_BYTES, |
| 5977 | 'Q', '2', '.', '0'}}, |
| 5978 | }; |
| 5979 | // clang-format on |
| 5980 | |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 5981 | if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5982 | return; |
| 5983 | } |
| 5984 | |
| 5985 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5986 | |
| 5987 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5988 | AssemblePacketFromFragments(packet)); |
| 5989 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 5990 | ASSERT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5991 | ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); |
nharper | 4fd1105 | 2019-06-04 14:23:22 -0700 | [diff] [blame] | 5992 | EXPECT_EQ(1u, visitor_.version_negotiation_packet_->versions.size()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 5993 | EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]); |
| 5994 | |
| 5995 | // Remove the last version from the packet so that every truncated |
| 5996 | // version of the packet is invalid, otherwise checking boundaries |
| 5997 | // is annoyingly complicated. |
| 5998 | for (size_t i = 0; i < 4; ++i) { |
| 5999 | packet.back().fragment.pop_back(); |
| 6000 | } |
| 6001 | CheckFramingBoundaries(packet, QUIC_INVALID_VERSION_NEGOTIATION_PACKET); |
| 6002 | } |
| 6003 | |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 6004 | TEST_P(QuicFramerTest, ParseIetfRetryPacket) { |
| 6005 | if (!framer_.version().SupportsRetry()) { |
| 6006 | return; |
| 6007 | } |
| 6008 | // IETF RETRY is only sent from client to server. |
| 6009 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 6010 | // clang-format off |
| 6011 | unsigned char packet[] = { |
| 6012 | // public flags (long header with packet type RETRY and ODCIL=8) |
| 6013 | 0xF5, |
| 6014 | // version |
| 6015 | QUIC_VERSION_BYTES, |
| 6016 | // connection ID lengths |
| 6017 | 0x05, |
| 6018 | // source connection ID |
| 6019 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 6020 | // original destination connection ID |
| 6021 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6022 | // retry token |
| 6023 | 'H', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'i', 's', |
| 6024 | ' ', 'i', 's', ' ', 'R', 'E', 'T', 'R', 'Y', '!', |
| 6025 | }; |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 6026 | unsigned char packet49[] = { |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 6027 | // public flags (long header with packet type RETRY) |
| 6028 | 0xF0, |
| 6029 | // version |
| 6030 | QUIC_VERSION_BYTES, |
| 6031 | // destination connection ID length |
| 6032 | 0x00, |
| 6033 | // source connection ID length |
| 6034 | 0x08, |
| 6035 | // source connection ID |
| 6036 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 6037 | // original destination connection ID length |
| 6038 | 0x08, |
| 6039 | // original destination connection ID |
| 6040 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6041 | // retry token |
| 6042 | 'H', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'i', 's', |
| 6043 | ' ', 'i', 's', ' ', 'R', 'E', 'T', 'R', 'Y', '!', |
| 6044 | }; |
dschinazi | 278efae | 2020-01-28 17:03:09 -0800 | [diff] [blame] | 6045 | unsigned char packet_with_tag[] = { |
| 6046 | // public flags (long header with packet type RETRY) |
| 6047 | 0xF0, |
| 6048 | // version |
| 6049 | QUIC_VERSION_BYTES, |
| 6050 | // destination connection ID length |
| 6051 | 0x00, |
| 6052 | // source connection ID length |
| 6053 | 0x08, |
| 6054 | // source connection ID |
| 6055 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 6056 | // retry token |
| 6057 | 'H', 'e', 'l', 'l', 'o', ' ', 't', 'h', 'i', 's', |
| 6058 | ' ', 'i', 's', ' ', 'R', 'E', 'T', 'R', 'Y', '!', |
| 6059 | // retry token integrity tag |
| 6060 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 6061 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 6062 | }; |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 6063 | // clang-format on |
| 6064 | |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 6065 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6066 | size_t p_length = ABSL_ARRAYSIZE(packet); |
dschinazi | 278efae | 2020-01-28 17:03:09 -0800 | [diff] [blame] | 6067 | if (framer_.version().HasRetryIntegrityTag()) { |
| 6068 | p = packet_with_tag; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6069 | p_length = ABSL_ARRAYSIZE(packet_with_tag); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 6070 | } else if (framer_.version().HasLongHeaderLengths()) { |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 6071 | p = packet49; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6072 | p_length = ABSL_ARRAYSIZE(packet49); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 6073 | } |
| 6074 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 6075 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 6076 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 6077 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 6078 | ASSERT_TRUE(visitor_.header_.get()); |
| 6079 | |
dschinazi | 2dd75ee | 2020-01-29 09:21:37 -0800 | [diff] [blame] | 6080 | ASSERT_TRUE(visitor_.on_retry_packet_called_); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 6081 | ASSERT_TRUE(visitor_.retry_new_connection_id_.get()); |
| 6082 | ASSERT_TRUE(visitor_.retry_token_.get()); |
| 6083 | |
dschinazi | 278efae | 2020-01-28 17:03:09 -0800 | [diff] [blame] | 6084 | if (framer_.version().HasRetryIntegrityTag()) { |
| 6085 | ASSERT_TRUE(visitor_.retry_token_integrity_tag_.get()); |
| 6086 | static const unsigned char expected_integrity_tag[16] = { |
| 6087 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 6088 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 6089 | }; |
| 6090 | quiche::test::CompareCharArraysWithHexError( |
| 6091 | "retry integrity tag", visitor_.retry_token_integrity_tag_->data(), |
| 6092 | visitor_.retry_token_integrity_tag_->length(), |
| 6093 | reinterpret_cast<const char*>(expected_integrity_tag), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6094 | ABSL_ARRAYSIZE(expected_integrity_tag)); |
dschinazi | 278efae | 2020-01-28 17:03:09 -0800 | [diff] [blame] | 6095 | ASSERT_TRUE(visitor_.retry_without_tag_.get()); |
| 6096 | quiche::test::CompareCharArraysWithHexError( |
| 6097 | "retry without tag", visitor_.retry_without_tag_->data(), |
| 6098 | visitor_.retry_without_tag_->length(), |
| 6099 | reinterpret_cast<const char*>(packet_with_tag), 35); |
| 6100 | } else { |
| 6101 | ASSERT_TRUE(visitor_.retry_original_connection_id_.get()); |
| 6102 | EXPECT_EQ(FramerTestConnectionId(), |
| 6103 | *visitor_.retry_original_connection_id_.get()); |
| 6104 | } |
| 6105 | |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 6106 | EXPECT_EQ(FramerTestConnectionIdPlusOne(), |
| 6107 | *visitor_.retry_new_connection_id_.get()); |
| 6108 | EXPECT_EQ("Hello this is RETRY!", *visitor_.retry_token_.get()); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 6109 | |
dschinazi | 2dd75ee | 2020-01-29 09:21:37 -0800 | [diff] [blame] | 6110 | // IETF RETRY is only sent from client to server, the rest of this test |
| 6111 | // ensures that the server correctly drops them without acting on them. |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 6112 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
dschinazi | 2dd75ee | 2020-01-29 09:21:37 -0800 | [diff] [blame] | 6113 | // Reset our visitor state to default settings. |
| 6114 | visitor_.retry_original_connection_id_.reset(); |
| 6115 | visitor_.retry_new_connection_id_.reset(); |
| 6116 | visitor_.retry_token_.reset(); |
| 6117 | visitor_.retry_token_integrity_tag_.reset(); |
| 6118 | visitor_.retry_without_tag_.reset(); |
| 6119 | visitor_.on_retry_packet_called_ = false; |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 6120 | |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 6121 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 6122 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 6123 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 6124 | EXPECT_EQ("Client-initiated RETRY is invalid.", framer_.detailed_error()); |
dschinazi | 2dd75ee | 2020-01-29 09:21:37 -0800 | [diff] [blame] | 6125 | |
| 6126 | EXPECT_FALSE(visitor_.on_retry_packet_called_); |
| 6127 | EXPECT_FALSE(visitor_.retry_new_connection_id_.get()); |
| 6128 | EXPECT_FALSE(visitor_.retry_token_.get()); |
| 6129 | EXPECT_FALSE(visitor_.retry_token_integrity_tag_.get()); |
| 6130 | EXPECT_FALSE(visitor_.retry_without_tag_.get()); |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 6131 | } |
| 6132 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6133 | TEST_P(QuicFramerTest, BuildPaddingFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6134 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6135 | QuicPacketHeader header; |
| 6136 | header.destination_connection_id = FramerTestConnectionId(); |
| 6137 | header.reset_flag = false; |
| 6138 | header.version_flag = false; |
| 6139 | header.packet_number = kPacketNumber; |
| 6140 | |
| 6141 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 6142 | |
| 6143 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6144 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6145 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6146 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6147 | // connection_id |
| 6148 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6149 | // packet number |
| 6150 | 0x12, 0x34, 0x56, 0x78, |
| 6151 | |
| 6152 | // frame type (padding frame) |
| 6153 | 0x00, |
| 6154 | 0x00, 0x00, 0x00, 0x00 |
| 6155 | }; |
| 6156 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6157 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6158 | // type (short header, 4 byte packet number) |
| 6159 | 0x43, |
| 6160 | // connection_id |
| 6161 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6162 | // packet number |
| 6163 | 0x12, 0x34, 0x56, 0x78, |
| 6164 | |
| 6165 | // frame type (padding frame) |
| 6166 | 0x00, |
| 6167 | 0x00, 0x00, 0x00, 0x00 |
| 6168 | }; |
| 6169 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6170 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6171 | // type (short header, 4 byte packet number) |
| 6172 | 0x43, |
| 6173 | // connection_id |
| 6174 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6175 | // packet number |
| 6176 | 0x12, 0x34, 0x56, 0x78, |
| 6177 | |
| 6178 | // frame type (padding frame) |
| 6179 | 0x00, |
| 6180 | 0x00, 0x00, 0x00, 0x00 |
| 6181 | }; |
| 6182 | // clang-format on |
| 6183 | |
| 6184 | unsigned char* p = packet; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 6185 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6186 | p = packet99; |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 6187 | } else if (framer_.version().HasIetfInvariantHeader()) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 6188 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6189 | } |
| 6190 | |
| 6191 | uint64_t header_size = GetPacketHeaderSize( |
| 6192 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 6193 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 6194 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 6195 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6196 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6197 | |
| 6198 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6199 | ASSERT_TRUE(data != nullptr); |
| 6200 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6201 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6202 | "constructed packet", data->data(), data->length(), AsChars(p), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6203 | framer_.version().HasIetfInvariantHeader() ? ABSL_ARRAYSIZE(packet46) |
| 6204 | : ABSL_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6205 | } |
| 6206 | |
| 6207 | TEST_P(QuicFramerTest, BuildStreamFramePacketWithNewPaddingFrame) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6208 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6209 | QuicPacketHeader header; |
| 6210 | header.destination_connection_id = FramerTestConnectionId(); |
| 6211 | header.reset_flag = false; |
| 6212 | header.version_flag = false; |
| 6213 | header.packet_number = kPacketNumber; |
| 6214 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 6215 | absl::string_view("hello world!")); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6216 | QuicPaddingFrame padding_frame(2); |
| 6217 | QuicFrames frames = {QuicFrame(padding_frame), QuicFrame(stream_frame), |
| 6218 | QuicFrame(padding_frame)}; |
| 6219 | |
| 6220 | // clang-format off |
| 6221 | unsigned char packet[] = { |
| 6222 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6223 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6224 | // connection_id |
| 6225 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6226 | // packet number |
| 6227 | 0x12, 0x34, 0x56, 0x78, |
| 6228 | |
| 6229 | // paddings |
| 6230 | 0x00, 0x00, |
| 6231 | // frame type (stream frame with fin) |
| 6232 | 0xFF, |
| 6233 | // stream id |
| 6234 | 0x01, 0x02, 0x03, 0x04, |
| 6235 | // offset |
| 6236 | 0x3A, 0x98, 0xFE, 0xDC, |
| 6237 | 0x32, 0x10, 0x76, 0x54, |
| 6238 | // data length |
| 6239 | 0x00, 0x0c, |
| 6240 | // data |
| 6241 | 'h', 'e', 'l', 'l', |
| 6242 | 'o', ' ', 'w', 'o', |
| 6243 | 'r', 'l', 'd', '!', |
| 6244 | // paddings |
| 6245 | 0x00, 0x00, |
| 6246 | }; |
| 6247 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6248 | unsigned char packet46[] = { |
| 6249 | // type (short header, 4 byte packet number) |
| 6250 | 0x43, |
| 6251 | // connection_id |
| 6252 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6253 | // packet number |
| 6254 | 0x12, 0x34, 0x56, 0x78, |
| 6255 | |
| 6256 | // paddings |
| 6257 | 0x00, 0x00, |
| 6258 | // frame type (stream frame with fin) |
| 6259 | 0xFF, |
| 6260 | // stream id |
| 6261 | 0x01, 0x02, 0x03, 0x04, |
| 6262 | // offset |
| 6263 | 0x3A, 0x98, 0xFE, 0xDC, |
| 6264 | 0x32, 0x10, 0x76, 0x54, |
| 6265 | // data length |
| 6266 | 0x00, 0x0c, |
| 6267 | // data |
| 6268 | 'h', 'e', 'l', 'l', |
| 6269 | 'o', ' ', 'w', 'o', |
| 6270 | 'r', 'l', 'd', '!', |
| 6271 | // paddings |
| 6272 | 0x00, 0x00, |
| 6273 | }; |
| 6274 | |
| 6275 | unsigned char packet99[] = { |
| 6276 | // type (short header, 4 byte packet number) |
| 6277 | 0x43, |
| 6278 | // connection_id |
| 6279 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6280 | // packet number |
| 6281 | 0x12, 0x34, 0x56, 0x78, |
| 6282 | |
| 6283 | // paddings |
| 6284 | 0x00, 0x00, |
| 6285 | // frame type (IETF_STREAM with FIN, LEN, and OFFSET bits set) |
| 6286 | 0x08 | 0x01 | 0x02 | 0x04, |
| 6287 | // stream id |
| 6288 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 6289 | // offset |
| 6290 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6291 | 0x32, 0x10, 0x76, 0x54, |
| 6292 | // data length |
| 6293 | kVarInt62OneByte + 0x0c, |
| 6294 | // data |
| 6295 | 'h', 'e', 'l', 'l', |
| 6296 | 'o', ' ', 'w', 'o', |
| 6297 | 'r', 'l', 'd', '!', |
| 6298 | // paddings |
| 6299 | 0x00, 0x00, |
| 6300 | }; |
| 6301 | // clang-format on |
| 6302 | |
| 6303 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6304 | ASSERT_TRUE(data != nullptr); |
| 6305 | |
| 6306 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6307 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 6308 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6309 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6310 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 6311 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6312 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6313 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6314 | } |
| 6315 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 6316 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6317 | quiche::test::CompareCharArraysWithHexError( |
| 6318 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6319 | } |
| 6320 | |
| 6321 | TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6322 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6323 | QuicPacketHeader header; |
| 6324 | header.destination_connection_id = FramerTestConnectionId(); |
| 6325 | header.reset_flag = false; |
| 6326 | header.version_flag = false; |
| 6327 | header.packet_number_length = PACKET_4BYTE_PACKET_NUMBER; |
| 6328 | header.packet_number = kPacketNumber; |
| 6329 | |
| 6330 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 6331 | |
| 6332 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6333 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6334 | // public flags (8 byte connection_id and 4 byte packet number) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6335 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6336 | // connection_id |
| 6337 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6338 | // packet number |
| 6339 | 0x12, 0x34, 0x56, 0x78, |
| 6340 | |
| 6341 | // frame type (padding frame) |
| 6342 | 0x00, |
| 6343 | 0x00, 0x00, 0x00, 0x00 |
| 6344 | }; |
| 6345 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6346 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6347 | // type (short header, 4 byte packet number) |
| 6348 | 0x43, |
| 6349 | // connection_id |
| 6350 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6351 | // packet number |
| 6352 | 0x12, 0x34, 0x56, 0x78, |
| 6353 | |
| 6354 | // frame type (padding frame) |
| 6355 | 0x00, |
| 6356 | 0x00, 0x00, 0x00, 0x00 |
| 6357 | }; |
| 6358 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6359 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6360 | // type (short header, 4 byte packet number) |
| 6361 | 0x43, |
| 6362 | // connection_id |
| 6363 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6364 | // packet number |
| 6365 | 0x12, 0x34, 0x56, 0x78, |
| 6366 | |
| 6367 | // frame type (padding frame) |
| 6368 | 0x00, |
| 6369 | 0x00, 0x00, 0x00, 0x00 |
| 6370 | }; |
| 6371 | // clang-format on |
| 6372 | |
| 6373 | unsigned char* p = packet; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 6374 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6375 | p = packet99; |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 6376 | } else if (framer_.version().HasIetfInvariantHeader()) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 6377 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6378 | } |
| 6379 | |
| 6380 | uint64_t header_size = GetPacketHeaderSize( |
| 6381 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 6382 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 6383 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 6384 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6385 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6386 | |
| 6387 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6388 | ASSERT_TRUE(data != nullptr); |
| 6389 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6390 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6391 | "constructed packet", data->data(), data->length(), AsChars(p), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6392 | framer_.version().HasIetfInvariantHeader() ? ABSL_ARRAYSIZE(packet46) |
| 6393 | : ABSL_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6394 | } |
| 6395 | |
| 6396 | TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6397 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6398 | QuicPacketHeader header; |
| 6399 | header.destination_connection_id = FramerTestConnectionId(); |
| 6400 | header.reset_flag = false; |
| 6401 | header.version_flag = false; |
| 6402 | header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER; |
| 6403 | header.packet_number = kPacketNumber; |
| 6404 | |
| 6405 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 6406 | |
| 6407 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6408 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6409 | // public flags (8 byte connection_id and 2 byte packet number) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6410 | 0x1C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6411 | // connection_id |
| 6412 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6413 | // packet number |
| 6414 | 0x56, 0x78, |
| 6415 | |
| 6416 | // frame type (padding frame) |
| 6417 | 0x00, |
| 6418 | 0x00, 0x00, 0x00, 0x00 |
| 6419 | }; |
| 6420 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6421 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6422 | // type (short header, 2 byte packet number) |
| 6423 | 0x41, |
| 6424 | // connection_id |
| 6425 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6426 | // packet number |
| 6427 | 0x56, 0x78, |
| 6428 | |
| 6429 | // frame type (padding frame) |
| 6430 | 0x00, |
| 6431 | 0x00, 0x00, 0x00, 0x00 |
| 6432 | }; |
| 6433 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6434 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6435 | // type (short header, 2 byte packet number) |
| 6436 | 0x41, |
| 6437 | // connection_id |
| 6438 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6439 | // packet number |
| 6440 | 0x56, 0x78, |
| 6441 | |
| 6442 | // frame type (padding frame) |
| 6443 | 0x00, |
| 6444 | 0x00, 0x00, 0x00, 0x00 |
| 6445 | }; |
| 6446 | // clang-format on |
| 6447 | |
| 6448 | unsigned char* p = packet; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 6449 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6450 | p = packet99; |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 6451 | } else if (framer_.version().HasIetfInvariantHeader()) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 6452 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6453 | } |
| 6454 | |
| 6455 | uint64_t header_size = GetPacketHeaderSize( |
| 6456 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 6457 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 6458 | !kIncludeDiversificationNonce, PACKET_2BYTE_PACKET_NUMBER, |
| 6459 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6460 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6461 | |
| 6462 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6463 | ASSERT_TRUE(data != nullptr); |
| 6464 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6465 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6466 | "constructed packet", data->data(), data->length(), AsChars(p), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6467 | framer_.version().HasIetfInvariantHeader() ? ABSL_ARRAYSIZE(packet46) |
| 6468 | : ABSL_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6469 | } |
| 6470 | |
| 6471 | TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6472 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6473 | QuicPacketHeader header; |
| 6474 | header.destination_connection_id = FramerTestConnectionId(); |
| 6475 | header.reset_flag = false; |
| 6476 | header.version_flag = false; |
| 6477 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 6478 | header.packet_number = kPacketNumber; |
| 6479 | |
| 6480 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 6481 | |
| 6482 | // clang-format off |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6483 | unsigned char packet[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6484 | // public flags (8 byte connection_id and 1 byte packet number) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6485 | 0x0C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6486 | // connection_id |
| 6487 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6488 | // packet number |
| 6489 | 0x78, |
| 6490 | |
| 6491 | // frame type (padding frame) |
| 6492 | 0x00, |
| 6493 | 0x00, 0x00, 0x00, 0x00 |
| 6494 | }; |
| 6495 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6496 | unsigned char packet46[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6497 | // type (short header, 1 byte packet number) |
| 6498 | 0x40, |
| 6499 | // connection_id |
| 6500 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6501 | // packet number |
| 6502 | 0x78, |
| 6503 | |
| 6504 | // frame type (padding frame) |
| 6505 | 0x00, |
| 6506 | 0x00, 0x00, 0x00, 0x00 |
| 6507 | }; |
| 6508 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6509 | unsigned char packet99[kMaxOutgoingPacketSize] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6510 | // type (short header, 1 byte packet number) |
| 6511 | 0x40, |
| 6512 | // connection_id |
| 6513 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6514 | // packet number |
| 6515 | 0x78, |
| 6516 | |
| 6517 | // frame type (padding frame) |
| 6518 | 0x00, |
| 6519 | 0x00, 0x00, 0x00, 0x00 |
| 6520 | }; |
| 6521 | // clang-format on |
| 6522 | |
| 6523 | unsigned char* p = packet; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 6524 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6525 | p = packet99; |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 6526 | } else if (framer_.version().HasIetfInvariantHeader()) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 6527 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6528 | } |
| 6529 | |
| 6530 | uint64_t header_size = GetPacketHeaderSize( |
| 6531 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 6532 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 6533 | !kIncludeDiversificationNonce, PACKET_1BYTE_PACKET_NUMBER, |
| 6534 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 6535 | memset(p + header_size + 1, 0x00, kMaxOutgoingPacketSize - header_size - 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6536 | |
| 6537 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6538 | ASSERT_TRUE(data != nullptr); |
| 6539 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6540 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6541 | "constructed packet", data->data(), data->length(), AsChars(p), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6542 | framer_.version().HasIetfInvariantHeader() ? ABSL_ARRAYSIZE(packet46) |
| 6543 | : ABSL_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6544 | } |
| 6545 | |
| 6546 | TEST_P(QuicFramerTest, BuildStreamFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6547 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6548 | QuicPacketHeader header; |
| 6549 | header.destination_connection_id = FramerTestConnectionId(); |
| 6550 | header.reset_flag = false; |
| 6551 | header.version_flag = false; |
| 6552 | header.packet_number = kPacketNumber; |
| 6553 | if (QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 6554 | header.length_length = VARIABLE_LENGTH_INTEGER_LENGTH_2; |
| 6555 | } |
| 6556 | |
| 6557 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 6558 | absl::string_view("hello world!")); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6559 | |
| 6560 | QuicFrames frames = {QuicFrame(stream_frame)}; |
| 6561 | |
| 6562 | // clang-format off |
| 6563 | unsigned char packet[] = { |
| 6564 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6565 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6566 | // connection_id |
| 6567 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6568 | // packet number |
| 6569 | 0x12, 0x34, 0x56, 0x78, |
| 6570 | |
| 6571 | // frame type (stream frame with fin and no length) |
| 6572 | 0xDF, |
| 6573 | // stream id |
| 6574 | 0x01, 0x02, 0x03, 0x04, |
| 6575 | // offset |
| 6576 | 0x3A, 0x98, 0xFE, 0xDC, |
| 6577 | 0x32, 0x10, 0x76, 0x54, |
| 6578 | // data |
| 6579 | 'h', 'e', 'l', 'l', |
| 6580 | 'o', ' ', 'w', 'o', |
| 6581 | 'r', 'l', 'd', '!', |
| 6582 | }; |
| 6583 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6584 | unsigned char packet46[] = { |
| 6585 | // type (short header, 4 byte packet number) |
| 6586 | 0x43, |
| 6587 | // connection_id |
| 6588 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6589 | // packet number |
| 6590 | 0x12, 0x34, 0x56, 0x78, |
| 6591 | |
| 6592 | // frame type (stream frame with fin and no length) |
| 6593 | 0xDF, |
| 6594 | // stream id |
| 6595 | 0x01, 0x02, 0x03, 0x04, |
| 6596 | // offset |
| 6597 | 0x3A, 0x98, 0xFE, 0xDC, |
| 6598 | 0x32, 0x10, 0x76, 0x54, |
| 6599 | // data |
| 6600 | 'h', 'e', 'l', 'l', |
| 6601 | 'o', ' ', 'w', 'o', |
| 6602 | 'r', 'l', 'd', '!', |
| 6603 | }; |
| 6604 | |
| 6605 | unsigned char packet99[] = { |
| 6606 | // type (short header, 4 byte packet number) |
| 6607 | 0x43, |
| 6608 | // connection_id |
| 6609 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6610 | // packet number |
| 6611 | 0x12, 0x34, 0x56, 0x78, |
| 6612 | |
| 6613 | // frame type (IETF_STREAM frame with FIN and OFFSET, no length) |
| 6614 | 0x08 | 0x01 | 0x04, |
| 6615 | // stream id |
| 6616 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 6617 | // offset |
| 6618 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6619 | 0x32, 0x10, 0x76, 0x54, |
| 6620 | // data |
| 6621 | 'h', 'e', 'l', 'l', |
| 6622 | 'o', ' ', 'w', 'o', |
| 6623 | 'r', 'l', 'd', '!', |
| 6624 | }; |
| 6625 | // clang-format on |
| 6626 | |
| 6627 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6628 | ASSERT_TRUE(data != nullptr); |
| 6629 | |
| 6630 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6631 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 6632 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6633 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6634 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 6635 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6636 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6637 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6638 | } |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6639 | quiche::test::CompareCharArraysWithHexError( |
| 6640 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6641 | } |
| 6642 | |
| 6643 | TEST_P(QuicFramerTest, BuildStreamFramePacketWithVersionFlag) { |
| 6644 | QuicPacketHeader header; |
| 6645 | header.destination_connection_id = FramerTestConnectionId(); |
| 6646 | header.reset_flag = false; |
| 6647 | header.version_flag = true; |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 6648 | if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6649 | header.long_packet_type = ZERO_RTT_PROTECTED; |
| 6650 | } |
| 6651 | header.packet_number = kPacketNumber; |
| 6652 | if (QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 6653 | header.length_length = VARIABLE_LENGTH_INTEGER_LENGTH_2; |
| 6654 | } |
| 6655 | |
| 6656 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 6657 | absl::string_view("hello world!")); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6658 | QuicFrames frames = {QuicFrame(stream_frame)}; |
| 6659 | |
| 6660 | // clang-format off |
| 6661 | unsigned char packet[] = { |
| 6662 | // public flags (version, 8 byte connection_id) |
| 6663 | 0x2D, |
| 6664 | // connection_id |
| 6665 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6666 | // version tag |
| 6667 | QUIC_VERSION_BYTES, |
| 6668 | // packet number |
| 6669 | 0x12, 0x34, 0x56, 0x78, |
| 6670 | |
| 6671 | // frame type (stream frame with fin and no length) |
| 6672 | 0xDF, |
| 6673 | // stream id |
| 6674 | 0x01, 0x02, 0x03, 0x04, |
| 6675 | // offset |
| 6676 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6677 | // data |
| 6678 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6679 | }; |
| 6680 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6681 | unsigned char packet46[] = { |
| 6682 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 6683 | 0xD3, |
| 6684 | // version tag |
| 6685 | QUIC_VERSION_BYTES, |
| 6686 | // connection_id length |
| 6687 | 0x50, |
| 6688 | // connection_id |
| 6689 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6690 | // packet number |
| 6691 | 0x12, 0x34, 0x56, 0x78, |
| 6692 | |
| 6693 | // frame type (stream frame with fin and no length) |
| 6694 | 0xDF, |
| 6695 | // stream id |
| 6696 | 0x01, 0x02, 0x03, 0x04, |
| 6697 | // offset |
| 6698 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6699 | // data |
| 6700 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6701 | }; |
| 6702 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 6703 | unsigned char packet49[] = { |
| 6704 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 6705 | 0xD3, |
| 6706 | // version tag |
| 6707 | QUIC_VERSION_BYTES, |
| 6708 | // destination connection ID length |
| 6709 | 0x08, |
| 6710 | // destination connection ID |
| 6711 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6712 | // source connection ID length |
| 6713 | 0x00, |
| 6714 | // length |
| 6715 | 0x40, 0x1D, |
| 6716 | // packet number |
| 6717 | 0x12, 0x34, 0x56, 0x78, |
| 6718 | |
| 6719 | // frame type (stream frame with fin and no length) |
| 6720 | 0xDF, |
| 6721 | // stream id |
| 6722 | 0x01, 0x02, 0x03, 0x04, |
| 6723 | // offset |
| 6724 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6725 | // data |
| 6726 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6727 | }; |
| 6728 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6729 | unsigned char packet99[] = { |
| 6730 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 6731 | 0xD3, |
| 6732 | // version tag |
| 6733 | QUIC_VERSION_BYTES, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 6734 | // destination connection ID length |
| 6735 | 0x08, |
| 6736 | // destination connection ID |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6737 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 6738 | // source connection ID length |
| 6739 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6740 | // length |
| 6741 | 0x40, 0x1D, |
| 6742 | // packet number |
| 6743 | 0x12, 0x34, 0x56, 0x78, |
| 6744 | |
| 6745 | // frame type (IETF_STREAM frame with fin and offset, no length) |
| 6746 | 0x08 | 0x01 | 0x04, |
| 6747 | // stream id |
| 6748 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 6749 | // offset |
| 6750 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6751 | // data |
| 6752 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6753 | }; |
| 6754 | // clang-format on |
| 6755 | |
| 6756 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 6757 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6758 | ASSERT_TRUE(data != nullptr); |
| 6759 | |
| 6760 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6761 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 6762 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6763 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6764 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 6765 | } else if (framer_.version().HasLongHeaderLengths()) { |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 6766 | p = packet49; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6767 | p_size = ABSL_ARRAYSIZE(packet49); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 6768 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6769 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6770 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6771 | } |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6772 | quiche::test::CompareCharArraysWithHexError( |
| 6773 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6774 | } |
| 6775 | |
| 6776 | TEST_P(QuicFramerTest, BuildCryptoFramePacket) { |
fkastenholz | ceae837 | 2019-06-12 12:22:22 -0700 | [diff] [blame] | 6777 | if (!QuicVersionUsesCryptoFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6778 | return; |
| 6779 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 6780 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6781 | QuicPacketHeader header; |
| 6782 | header.destination_connection_id = FramerTestConnectionId(); |
| 6783 | header.reset_flag = false; |
| 6784 | header.version_flag = false; |
| 6785 | header.packet_number = kPacketNumber; |
| 6786 | |
| 6787 | SimpleDataProducer data_producer; |
| 6788 | framer_.set_data_producer(&data_producer); |
| 6789 | |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 6790 | absl::string_view crypto_frame_contents("hello world!"); |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 6791 | QuicCryptoFrame crypto_frame(ENCRYPTION_INITIAL, kStreamOffset, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6792 | crypto_frame_contents.length()); |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 6793 | data_producer.SaveCryptoData(ENCRYPTION_INITIAL, kStreamOffset, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6794 | crypto_frame_contents); |
| 6795 | |
| 6796 | QuicFrames frames = {QuicFrame(&crypto_frame)}; |
| 6797 | |
| 6798 | // clang-format off |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6799 | unsigned char packet48[] = { |
| 6800 | // type (short header, 4 byte packet number) |
| 6801 | 0x43, |
| 6802 | // connection_id |
| 6803 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6804 | // packet number |
| 6805 | 0x12, 0x34, 0x56, 0x78, |
| 6806 | |
| 6807 | // frame type (QuicFrameType CRYPTO_FRAME) |
| 6808 | 0x08, |
| 6809 | // offset |
| 6810 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6811 | 0x32, 0x10, 0x76, 0x54, |
| 6812 | // length |
| 6813 | kVarInt62OneByte + 12, |
| 6814 | // data |
| 6815 | 'h', 'e', 'l', 'l', |
| 6816 | 'o', ' ', 'w', 'o', |
| 6817 | 'r', 'l', 'd', '!', |
| 6818 | }; |
| 6819 | |
| 6820 | unsigned char packet99[] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6821 | // type (short header, 4 byte packet number) |
| 6822 | 0x43, |
| 6823 | // connection_id |
| 6824 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6825 | // packet number |
| 6826 | 0x12, 0x34, 0x56, 0x78, |
| 6827 | |
| 6828 | // frame type (IETF_CRYPTO frame) |
| 6829 | 0x06, |
| 6830 | // offset |
| 6831 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6832 | 0x32, 0x10, 0x76, 0x54, |
| 6833 | // length |
| 6834 | kVarInt62OneByte + 12, |
| 6835 | // data |
| 6836 | 'h', 'e', 'l', 'l', |
| 6837 | 'o', ' ', 'w', 'o', |
| 6838 | 'r', 'l', 'd', '!', |
| 6839 | }; |
| 6840 | // clang-format on |
| 6841 | |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6842 | unsigned char* packet = packet48; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6843 | size_t packet_size = ABSL_ARRAYSIZE(packet48); |
dschinazi | 40f0b3d | 2020-02-19 17:54:05 -0800 | [diff] [blame] | 6844 | if (framer_.version().HasIetfQuicFrames()) { |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6845 | packet = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6846 | packet_size = ABSL_ARRAYSIZE(packet99); |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6847 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6848 | |
| 6849 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6850 | ASSERT_TRUE(data != nullptr); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6851 | quiche::test::CompareCharArraysWithHexError("constructed packet", |
| 6852 | data->data(), data->length(), |
| 6853 | AsChars(packet), packet_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6854 | } |
| 6855 | |
| 6856 | TEST_P(QuicFramerTest, CryptoFrame) { |
renjietang | 15dfaa8 | 2020-01-03 16:13:38 -0800 | [diff] [blame] | 6857 | if (!QuicVersionUsesCryptoFrames(framer_.transport_version())) { |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6858 | // CRYPTO frames aren't supported prior to v48. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6859 | return; |
| 6860 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 6861 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6862 | |
| 6863 | // clang-format off |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6864 | PacketFragments packet48 = { |
| 6865 | // type (short header, 4 byte packet number) |
| 6866 | {"", |
| 6867 | {0x43}}, |
| 6868 | // connection_id |
| 6869 | {"", |
| 6870 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 6871 | // packet number |
| 6872 | {"", |
| 6873 | {0x12, 0x34, 0x56, 0x78}}, |
| 6874 | // frame type (QuicFrameType CRYPTO_FRAME) |
| 6875 | {"", |
| 6876 | {0x08}}, |
| 6877 | // offset |
| 6878 | {"", |
| 6879 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6880 | 0x32, 0x10, 0x76, 0x54}}, |
| 6881 | // data length |
| 6882 | {"Invalid data length.", |
| 6883 | {kVarInt62OneByte + 12}}, |
| 6884 | // data |
| 6885 | {"Unable to read frame data.", |
| 6886 | {'h', 'e', 'l', 'l', |
| 6887 | 'o', ' ', 'w', 'o', |
| 6888 | 'r', 'l', 'd', '!'}}, |
| 6889 | }; |
| 6890 | |
| 6891 | PacketFragments packet99 = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6892 | // type (short header, 4 byte packet number) |
| 6893 | {"", |
| 6894 | {0x43}}, |
| 6895 | // connection_id |
| 6896 | {"", |
| 6897 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 6898 | // packet number |
| 6899 | {"", |
| 6900 | {0x12, 0x34, 0x56, 0x78}}, |
| 6901 | // frame type (IETF_CRYPTO frame) |
| 6902 | {"", |
| 6903 | {0x06}}, |
| 6904 | // offset |
| 6905 | {"", |
| 6906 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6907 | 0x32, 0x10, 0x76, 0x54}}, |
| 6908 | // data length |
| 6909 | {"Invalid data length.", |
| 6910 | {kVarInt62OneByte + 12}}, |
| 6911 | // data |
| 6912 | {"Unable to read frame data.", |
| 6913 | {'h', 'e', 'l', 'l', |
| 6914 | 'o', ' ', 'w', 'o', |
| 6915 | 'r', 'l', 'd', '!'}}, |
| 6916 | }; |
| 6917 | // clang-format on |
| 6918 | |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6919 | PacketFragments& fragments = |
dschinazi | 40f0b3d | 2020-02-19 17:54:05 -0800 | [diff] [blame] | 6920 | framer_.version().HasIetfQuicFrames() ? packet99 : packet48; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6921 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6922 | AssemblePacketFromFragments(fragments)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6923 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 6924 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 6925 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6926 | ASSERT_TRUE(visitor_.header_.get()); |
| 6927 | EXPECT_TRUE(CheckDecryption( |
| 6928 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 6929 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 6930 | ASSERT_EQ(1u, visitor_.crypto_frames_.size()); |
| 6931 | QuicCryptoFrame* frame = visitor_.crypto_frames_[0].get(); |
renjietang | 15dfaa8 | 2020-01-03 16:13:38 -0800 | [diff] [blame] | 6932 | EXPECT_EQ(ENCRYPTION_FORWARD_SECURE, frame->level); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6933 | EXPECT_EQ(kStreamOffset, frame->offset); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 6934 | EXPECT_EQ("hello world!", |
| 6935 | std::string(frame->data_buffer, frame->data_length)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6936 | |
nharper | 107ba5f | 2019-07-02 21:33:39 -0700 | [diff] [blame] | 6937 | CheckFramingBoundaries(fragments, QUIC_INVALID_FRAME_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6938 | } |
| 6939 | |
| 6940 | TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) { |
dschinazi | 1ac22cc | 2019-06-25 11:47:50 -0700 | [diff] [blame] | 6941 | SetQuicFlag(FLAGS_quic_disable_version_negotiation_grease_randomness, true); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6942 | // clang-format off |
| 6943 | unsigned char packet[] = { |
| 6944 | // public flags (version, 8 byte connection_id) |
| 6945 | 0x0D, |
| 6946 | // connection_id |
| 6947 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 1ac22cc | 2019-06-25 11:47:50 -0700 | [diff] [blame] | 6948 | // supported versions |
| 6949 | 0xDA, 0x5A, 0x3A, 0x3A, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6950 | QUIC_VERSION_BYTES, |
| 6951 | }; |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 6952 | unsigned char packet46[] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6953 | // type (long header) |
dschinazi | 0366de9 | 2019-06-18 20:00:27 -0700 | [diff] [blame] | 6954 | 0xC0, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6955 | // version tag |
| 6956 | 0x00, 0x00, 0x00, 0x00, |
| 6957 | // connection_id length |
| 6958 | 0x05, |
| 6959 | // connection_id |
| 6960 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 1ac22cc | 2019-06-25 11:47:50 -0700 | [diff] [blame] | 6961 | // supported versions |
| 6962 | 0xDA, 0x5A, 0x3A, 0x3A, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6963 | QUIC_VERSION_BYTES, |
| 6964 | }; |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 6965 | unsigned char packet49[] = { |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 6966 | // type (long header) |
| 6967 | 0xC0, |
| 6968 | // version tag |
| 6969 | 0x00, 0x00, 0x00, 0x00, |
| 6970 | // destination connection ID length |
| 6971 | 0x00, |
| 6972 | // source connection ID length |
| 6973 | 0x08, |
| 6974 | // source connection ID |
| 6975 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6976 | // supported versions |
| 6977 | 0xDA, 0x5A, 0x3A, 0x3A, |
| 6978 | QUIC_VERSION_BYTES, |
| 6979 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6980 | // clang-format on |
| 6981 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6982 | size_t p_size = ABSL_ARRAYSIZE(packet); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 6983 | if (framer_.version().HasLongHeaderLengths()) { |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 6984 | p = packet49; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6985 | p_size = ABSL_ARRAYSIZE(packet49); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 6986 | } else if (framer_.version().HasIetfInvariantHeader()) { |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 6987 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 6988 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6989 | } |
| 6990 | |
| 6991 | QuicConnectionId connection_id = FramerTestConnectionId(); |
| 6992 | std::unique_ptr<QuicEncryptedPacket> data( |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 6993 | QuicFramer::BuildVersionNegotiationPacket( |
| 6994 | connection_id, EmptyQuicConnectionId(), |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 6995 | framer_.version().HasIetfInvariantHeader(), |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 6996 | framer_.version().HasLengthPrefixedConnectionIds(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6997 | SupportedVersions(GetParam()))); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 6998 | quiche::test::CompareCharArraysWithHexError( |
| 6999 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7000 | } |
| 7001 | |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 7002 | TEST_P(QuicFramerTest, BuildVersionNegotiationPacketWithClientConnectionId) { |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 7003 | if (!framer_.version().SupportsClientConnectionIds()) { |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 7004 | return; |
| 7005 | } |
| 7006 | |
dschinazi | 1ac22cc | 2019-06-25 11:47:50 -0700 | [diff] [blame] | 7007 | SetQuicFlag(FLAGS_quic_disable_version_negotiation_grease_randomness, true); |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 7008 | |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 7009 | // clang-format off |
| 7010 | unsigned char packet[] = { |
| 7011 | // type (long header) |
dschinazi | 0366de9 | 2019-06-18 20:00:27 -0700 | [diff] [blame] | 7012 | 0xC0, |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 7013 | // version tag |
| 7014 | 0x00, 0x00, 0x00, 0x00, |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 7015 | // client/destination connection ID |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 7016 | 0x08, |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 7017 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 7018 | // server/source connection ID |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 7019 | 0x08, |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 7020 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 1ac22cc | 2019-06-25 11:47:50 -0700 | [diff] [blame] | 7021 | // supported versions |
| 7022 | 0xDA, 0x5A, 0x3A, 0x3A, |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 7023 | QUIC_VERSION_BYTES, |
| 7024 | }; |
| 7025 | // clang-format on |
| 7026 | |
| 7027 | QuicConnectionId server_connection_id = FramerTestConnectionId(); |
| 7028 | QuicConnectionId client_connection_id = FramerTestConnectionIdPlusOne(); |
| 7029 | std::unique_ptr<QuicEncryptedPacket> data( |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 7030 | QuicFramer::BuildVersionNegotiationPacket( |
| 7031 | server_connection_id, client_connection_id, true, true, |
| 7032 | SupportedVersions(GetParam()))); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 7033 | quiche::test::CompareCharArraysWithHexError( |
| 7034 | "constructed packet", data->data(), data->length(), AsChars(packet), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7035 | ABSL_ARRAYSIZE(packet)); |
dschinazi | b417d60 | 2019-05-29 13:08:45 -0700 | [diff] [blame] | 7036 | } |
| 7037 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7038 | TEST_P(QuicFramerTest, BuildAckFramePacketOneAckBlock) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7039 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7040 | QuicPacketHeader header; |
| 7041 | header.destination_connection_id = FramerTestConnectionId(); |
| 7042 | header.reset_flag = false; |
| 7043 | header.version_flag = false; |
| 7044 | header.packet_number = kPacketNumber; |
| 7045 | |
| 7046 | // Use kSmallLargestObserved to make this test finished in a short time. |
| 7047 | QuicAckFrame ack_frame = InitAckFrame(kSmallLargestObserved); |
| 7048 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 7049 | |
| 7050 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 7051 | |
| 7052 | // clang-format off |
| 7053 | unsigned char packet[] = { |
| 7054 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7055 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7056 | // connection_id |
| 7057 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7058 | // packet number |
| 7059 | 0x12, 0x34, 0x56, 0x78, |
| 7060 | |
| 7061 | // frame type (ack frame) |
| 7062 | // (no ack blocks, 2 byte largest observed, 2 byte block length) |
| 7063 | 0x45, |
| 7064 | // largest acked |
| 7065 | 0x12, 0x34, |
| 7066 | // Zero delta time. |
| 7067 | 0x00, 0x00, |
| 7068 | // first ack block length. |
| 7069 | 0x12, 0x34, |
| 7070 | // num timestamps. |
| 7071 | 0x00, |
| 7072 | }; |
| 7073 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7074 | unsigned char packet46[] = { |
| 7075 | // type (short header, 4 byte packet number) |
| 7076 | 0x43, |
| 7077 | // connection_id |
| 7078 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7079 | // packet number |
| 7080 | 0x12, 0x34, 0x56, 0x78, |
| 7081 | |
| 7082 | // frame type (ack frame) |
| 7083 | // (no ack blocks, 2 byte largest observed, 2 byte block length) |
| 7084 | 0x45, |
| 7085 | // largest acked |
| 7086 | 0x12, 0x34, |
| 7087 | // Zero delta time. |
| 7088 | 0x00, 0x00, |
| 7089 | // first ack block length. |
| 7090 | 0x12, 0x34, |
| 7091 | // num timestamps. |
| 7092 | 0x00, |
| 7093 | }; |
| 7094 | |
| 7095 | unsigned char packet99[] = { |
| 7096 | // type (short header, 4 byte packet number) |
| 7097 | 0x43, |
| 7098 | // connection_id |
| 7099 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7100 | // packet number |
| 7101 | 0x12, 0x34, 0x56, 0x78, |
| 7102 | |
| 7103 | // frame type (IETF_ACK frame) |
| 7104 | 0x02, |
| 7105 | // largest acked |
| 7106 | kVarInt62TwoBytes + 0x12, 0x34, |
| 7107 | // Zero delta time. |
| 7108 | kVarInt62OneByte + 0x00, |
| 7109 | // Number of additional ack blocks. |
| 7110 | kVarInt62OneByte + 0x00, |
| 7111 | // first ack block length. |
| 7112 | kVarInt62TwoBytes + 0x12, 0x33, |
| 7113 | }; |
| 7114 | // clang-format on |
| 7115 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7116 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 7117 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7118 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7119 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 7120 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7121 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7122 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7123 | } |
| 7124 | |
| 7125 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7126 | ASSERT_TRUE(data != nullptr); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 7127 | quiche::test::CompareCharArraysWithHexError( |
| 7128 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7129 | } |
| 7130 | |
| 7131 | TEST_P(QuicFramerTest, BuildAckFramePacketOneAckBlockMaxLength) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7132 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7133 | QuicPacketHeader header; |
| 7134 | header.destination_connection_id = FramerTestConnectionId(); |
| 7135 | header.reset_flag = false; |
| 7136 | header.version_flag = false; |
| 7137 | header.packet_number = kPacketNumber; |
| 7138 | |
| 7139 | QuicAckFrame ack_frame = InitAckFrame(kPacketNumber); |
| 7140 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 7141 | |
| 7142 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 7143 | |
| 7144 | // clang-format off |
| 7145 | unsigned char packet[] = { |
| 7146 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7147 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7148 | // connection_id |
| 7149 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7150 | // packet number |
| 7151 | 0x12, 0x34, 0x56, 0x78, |
| 7152 | |
| 7153 | // frame type (ack frame) |
| 7154 | // (no ack blocks, 4 byte largest observed, 4 byte block length) |
| 7155 | 0x4A, |
| 7156 | // largest acked |
| 7157 | 0x12, 0x34, 0x56, 0x78, |
| 7158 | // Zero delta time. |
| 7159 | 0x00, 0x00, |
| 7160 | // first ack block length. |
| 7161 | 0x12, 0x34, 0x56, 0x78, |
| 7162 | // num timestamps. |
| 7163 | 0x00, |
| 7164 | }; |
| 7165 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7166 | unsigned char packet46[] = { |
| 7167 | // type (short header, 4 byte packet number) |
| 7168 | 0x43, |
| 7169 | // connection_id |
| 7170 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7171 | // packet number |
| 7172 | 0x12, 0x34, 0x56, 0x78, |
| 7173 | |
| 7174 | // frame type (ack frame) |
| 7175 | // (no ack blocks, 4 byte largest observed, 4 byte block length) |
| 7176 | 0x4A, |
| 7177 | // largest acked |
| 7178 | 0x12, 0x34, 0x56, 0x78, |
| 7179 | // Zero delta time. |
| 7180 | 0x00, 0x00, |
| 7181 | // first ack block length. |
| 7182 | 0x12, 0x34, 0x56, 0x78, |
| 7183 | // num timestamps. |
| 7184 | 0x00, |
| 7185 | }; |
| 7186 | |
| 7187 | |
| 7188 | unsigned char packet99[] = { |
| 7189 | // type (short header, 4 byte packet number) |
| 7190 | 0x43, |
| 7191 | // connection_id |
| 7192 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7193 | // packet number |
| 7194 | 0x12, 0x34, 0x56, 0x78, |
| 7195 | |
| 7196 | // frame type (IETF_ACK frame) |
| 7197 | 0x02, |
| 7198 | // largest acked |
| 7199 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78, |
| 7200 | // Zero delta time. |
| 7201 | kVarInt62OneByte + 0x00, |
| 7202 | // Nr. of additional ack blocks |
| 7203 | kVarInt62OneByte + 0x00, |
| 7204 | // first ack block length. |
| 7205 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x77, |
| 7206 | }; |
| 7207 | // clang-format on |
| 7208 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7209 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 7210 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7211 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7212 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 7213 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7214 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7215 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7216 | } |
| 7217 | |
| 7218 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7219 | ASSERT_TRUE(data != nullptr); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 7220 | quiche::test::CompareCharArraysWithHexError( |
| 7221 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7222 | } |
| 7223 | |
| 7224 | TEST_P(QuicFramerTest, BuildAckFramePacketMultipleAckBlocks) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7225 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7226 | QuicPacketHeader header; |
| 7227 | header.destination_connection_id = FramerTestConnectionId(); |
| 7228 | header.reset_flag = false; |
| 7229 | header.version_flag = false; |
| 7230 | header.packet_number = kPacketNumber; |
| 7231 | |
| 7232 | // Use kSmallLargestObserved to make this test finished in a short time. |
| 7233 | QuicAckFrame ack_frame = |
| 7234 | InitAckFrame({{QuicPacketNumber(1), QuicPacketNumber(5)}, |
| 7235 | {QuicPacketNumber(10), QuicPacketNumber(500)}, |
| 7236 | {QuicPacketNumber(900), kSmallMissingPacket}, |
| 7237 | {kSmallMissingPacket + 1, kSmallLargestObserved + 1}}); |
| 7238 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 7239 | |
| 7240 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 7241 | |
| 7242 | // clang-format off |
| 7243 | unsigned char packet[] = { |
| 7244 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7245 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7246 | // connection_id |
| 7247 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7248 | // packet number |
| 7249 | 0x12, 0x34, 0x56, 0x78, |
| 7250 | |
| 7251 | // frame type (ack frame) |
| 7252 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 7253 | 0x65, |
| 7254 | // largest acked |
| 7255 | 0x12, 0x34, |
| 7256 | // Zero delta time. |
| 7257 | 0x00, 0x00, |
| 7258 | // num ack blocks ranges. |
| 7259 | 0x04, |
| 7260 | // first ack block length. |
| 7261 | 0x00, 0x01, |
| 7262 | // gap to next block. |
| 7263 | 0x01, |
| 7264 | // ack block length. |
| 7265 | 0x0e, 0xaf, |
| 7266 | // gap to next block. |
| 7267 | 0xff, |
| 7268 | // ack block length. |
| 7269 | 0x00, 0x00, |
| 7270 | // gap to next block. |
| 7271 | 0x91, |
| 7272 | // ack block length. |
| 7273 | 0x01, 0xea, |
| 7274 | // gap to next block. |
| 7275 | 0x05, |
| 7276 | // ack block length. |
| 7277 | 0x00, 0x04, |
| 7278 | // num timestamps. |
| 7279 | 0x00, |
| 7280 | }; |
| 7281 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7282 | unsigned char packet46[] = { |
| 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 | |
| 7290 | // frame type (ack frame) |
| 7291 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 7292 | 0x65, |
| 7293 | // largest acked |
| 7294 | 0x12, 0x34, |
| 7295 | // Zero delta time. |
| 7296 | 0x00, 0x00, |
| 7297 | // num ack blocks ranges. |
| 7298 | 0x04, |
| 7299 | // first ack block length. |
| 7300 | 0x00, 0x01, |
| 7301 | // gap to next block. |
| 7302 | 0x01, |
| 7303 | // ack block length. |
| 7304 | 0x0e, 0xaf, |
| 7305 | // gap to next block. |
| 7306 | 0xff, |
| 7307 | // ack block length. |
| 7308 | 0x00, 0x00, |
| 7309 | // gap to next block. |
| 7310 | 0x91, |
| 7311 | // ack block length. |
| 7312 | 0x01, 0xea, |
| 7313 | // gap to next block. |
| 7314 | 0x05, |
| 7315 | // ack block length. |
| 7316 | 0x00, 0x04, |
| 7317 | // num timestamps. |
| 7318 | 0x00, |
| 7319 | }; |
| 7320 | |
| 7321 | unsigned char packet99[] = { |
| 7322 | // type (short header, 4 byte packet number) |
| 7323 | 0x43, |
| 7324 | // connection_id |
| 7325 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7326 | // packet number |
| 7327 | 0x12, 0x34, 0x56, 0x78, |
| 7328 | |
| 7329 | // frame type (IETF_ACK frame) |
| 7330 | 0x02, |
| 7331 | // largest acked |
| 7332 | kVarInt62TwoBytes + 0x12, 0x34, |
| 7333 | // Zero delta time. |
| 7334 | kVarInt62OneByte + 0x00, |
| 7335 | // num additional ack blocks. |
| 7336 | kVarInt62OneByte + 0x03, |
| 7337 | // first ack block length. |
| 7338 | kVarInt62OneByte + 0x00, |
| 7339 | |
| 7340 | // gap to next block. |
| 7341 | kVarInt62OneByte + 0x00, |
| 7342 | // ack block length. |
| 7343 | kVarInt62TwoBytes + 0x0e, 0xae, |
| 7344 | |
| 7345 | // gap to next block. |
| 7346 | kVarInt62TwoBytes + 0x01, 0x8f, |
| 7347 | // ack block length. |
| 7348 | kVarInt62TwoBytes + 0x01, 0xe9, |
| 7349 | |
| 7350 | // gap to next block. |
| 7351 | kVarInt62OneByte + 0x04, |
| 7352 | // ack block length. |
| 7353 | kVarInt62OneByte + 0x03, |
| 7354 | }; |
| 7355 | // clang-format on |
| 7356 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7357 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 7358 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7359 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7360 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 7361 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7362 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7363 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7364 | } |
| 7365 | |
| 7366 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7367 | ASSERT_TRUE(data != nullptr); |
| 7368 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 7369 | quiche::test::CompareCharArraysWithHexError( |
| 7370 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7371 | } |
| 7372 | |
| 7373 | TEST_P(QuicFramerTest, BuildAckFramePacketMaxAckBlocks) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7374 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7375 | QuicPacketHeader header; |
| 7376 | header.destination_connection_id = FramerTestConnectionId(); |
| 7377 | header.reset_flag = false; |
| 7378 | header.version_flag = false; |
| 7379 | header.packet_number = kPacketNumber; |
| 7380 | |
| 7381 | // Use kSmallLargestObservedto make this test finished in a short time. |
| 7382 | QuicAckFrame ack_frame; |
| 7383 | ack_frame.largest_acked = kSmallLargestObserved; |
| 7384 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 7385 | // 300 ack blocks. |
| 7386 | for (size_t i = 2; i < 2 * 300; i += 2) { |
| 7387 | ack_frame.packets.Add(QuicPacketNumber(i)); |
| 7388 | } |
| 7389 | ack_frame.packets.AddRange(QuicPacketNumber(600), kSmallLargestObserved + 1); |
| 7390 | |
| 7391 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 7392 | |
| 7393 | // clang-format off |
| 7394 | unsigned char packet[] = { |
| 7395 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7396 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7397 | // connection_id |
| 7398 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7399 | // packet number |
| 7400 | 0x12, 0x34, 0x56, 0x78, |
| 7401 | // frame type (ack frame) |
| 7402 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 7403 | 0x65, |
| 7404 | // largest acked |
| 7405 | 0x12, 0x34, |
| 7406 | // Zero delta time. |
| 7407 | 0x00, 0x00, |
| 7408 | // num ack blocks ranges. |
| 7409 | 0xff, |
| 7410 | // first ack block length. |
| 7411 | 0x0f, 0xdd, |
| 7412 | // 255 = 4 * 63 + 3 |
| 7413 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7414 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7415 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7416 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7417 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7418 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7419 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7420 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7421 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7422 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7423 | |
| 7424 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7425 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7426 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7427 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7428 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7429 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7430 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7431 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7432 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7433 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7434 | |
| 7435 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7436 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7437 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7438 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7439 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7440 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7441 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7442 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7443 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7444 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7445 | |
| 7446 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7447 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7448 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7449 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7450 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7451 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7452 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7453 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7454 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7455 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7456 | |
| 7457 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7458 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7459 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7460 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7461 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7462 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7463 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7464 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7465 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7466 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7467 | |
| 7468 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7469 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7470 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7471 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7472 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7473 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7474 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7475 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7476 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7477 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7478 | |
| 7479 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7480 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7481 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7482 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7483 | // num timestamps. |
| 7484 | 0x00, |
| 7485 | }; |
| 7486 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7487 | unsigned char packet46[] = { |
| 7488 | // type (short header, 4 byte packet number) |
| 7489 | 0x43, |
| 7490 | // connection_id |
| 7491 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7492 | // packet number |
| 7493 | 0x12, 0x34, 0x56, 0x78, |
| 7494 | // frame type (ack frame) |
| 7495 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 7496 | 0x65, |
| 7497 | // largest acked |
| 7498 | 0x12, 0x34, |
| 7499 | // Zero delta time. |
| 7500 | 0x00, 0x00, |
| 7501 | // num ack blocks ranges. |
| 7502 | 0xff, |
| 7503 | // first ack block length. |
| 7504 | 0x0f, 0xdd, |
| 7505 | // 255 = 4 * 63 + 3 |
| 7506 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7507 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7508 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7509 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7510 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7511 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7512 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7513 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7514 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7515 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7516 | |
| 7517 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7518 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7519 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7520 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7521 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7522 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7523 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7524 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7525 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7526 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7527 | |
| 7528 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7529 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7530 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7531 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7532 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7533 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7534 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7535 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7536 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7537 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7538 | |
| 7539 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7540 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7541 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7542 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7543 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7544 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7545 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7546 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7547 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7548 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7549 | |
| 7550 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7551 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7552 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7553 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7554 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7555 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7556 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7557 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7558 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7559 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7560 | |
| 7561 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7562 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7563 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7564 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7565 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7566 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7567 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7568 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7569 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7570 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7571 | |
| 7572 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7573 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7574 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7575 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 7576 | // num timestamps. |
| 7577 | 0x00, |
| 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 | // frame type (IETF_ACK frame) |
| 7588 | 0x02, |
| 7589 | // largest acked |
| 7590 | kVarInt62TwoBytes + 0x12, 0x34, |
| 7591 | // Zero delta time. |
| 7592 | kVarInt62OneByte + 0x00, |
| 7593 | // num ack blocks ranges. |
| 7594 | kVarInt62TwoBytes + 0x01, 0x2b, |
| 7595 | // first ack block length. |
| 7596 | kVarInt62TwoBytes + 0x0f, 0xdc, |
| 7597 | // 255 added blocks of gap_size == 1, ack_size == 1 |
| 7598 | #define V99AddedBLOCK kVarInt62OneByte + 0x00, kVarInt62OneByte + 0x00 |
| 7599 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7600 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7601 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7602 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7603 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7604 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7605 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7606 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7607 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7608 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7609 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7610 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7611 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7612 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7613 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7614 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7615 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7616 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7617 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7618 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7619 | |
| 7620 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7621 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7622 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7623 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7624 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7625 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7626 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7627 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7628 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7629 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7630 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7631 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7632 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7633 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7634 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7635 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7636 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7637 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7638 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7639 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7640 | |
| 7641 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7642 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7643 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7644 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7645 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7646 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7647 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7648 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7649 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7650 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7651 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7652 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7653 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7654 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7655 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7656 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7657 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7658 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7659 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7660 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7661 | |
| 7662 | #undef V99AddedBLOCK |
| 7663 | }; |
| 7664 | // clang-format on |
| 7665 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7666 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 7667 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7668 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7669 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 7670 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7671 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7672 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7673 | } |
| 7674 | |
| 7675 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7676 | ASSERT_TRUE(data != nullptr); |
| 7677 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 7678 | quiche::test::CompareCharArraysWithHexError( |
| 7679 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7680 | } |
| 7681 | |
| 7682 | TEST_P(QuicFramerTest, BuildNewStopWaitingPacket) { |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 7683 | if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7684 | return; |
| 7685 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7686 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7687 | QuicPacketHeader header; |
| 7688 | header.destination_connection_id = FramerTestConnectionId(); |
| 7689 | header.reset_flag = false; |
| 7690 | header.version_flag = false; |
| 7691 | header.packet_number = kPacketNumber; |
| 7692 | |
| 7693 | QuicStopWaitingFrame stop_waiting_frame; |
| 7694 | stop_waiting_frame.least_unacked = kLeastUnacked; |
| 7695 | |
| 7696 | QuicFrames frames = {QuicFrame(stop_waiting_frame)}; |
| 7697 | |
| 7698 | // clang-format off |
| 7699 | unsigned char packet[] = { |
| 7700 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7701 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7702 | // connection_id |
| 7703 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7704 | // packet number |
| 7705 | 0x12, 0x34, 0x56, 0x78, |
| 7706 | |
| 7707 | // frame type (stop waiting frame) |
| 7708 | 0x06, |
| 7709 | // least packet number awaiting an ack, delta from packet number. |
| 7710 | 0x00, 0x00, 0x00, 0x08, |
| 7711 | }; |
| 7712 | |
| 7713 | // clang-format on |
| 7714 | |
| 7715 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7716 | ASSERT_TRUE(data != nullptr); |
| 7717 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 7718 | quiche::test::CompareCharArraysWithHexError( |
| 7719 | "constructed packet", data->data(), data->length(), AsChars(packet), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7720 | ABSL_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7721 | } |
| 7722 | |
| 7723 | TEST_P(QuicFramerTest, BuildRstFramePacketQuic) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7724 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7725 | QuicPacketHeader header; |
| 7726 | header.destination_connection_id = FramerTestConnectionId(); |
| 7727 | header.reset_flag = false; |
| 7728 | header.version_flag = false; |
| 7729 | header.packet_number = kPacketNumber; |
| 7730 | |
| 7731 | QuicRstStreamFrame rst_frame; |
| 7732 | rst_frame.stream_id = kStreamId; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 7733 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7734 | rst_frame.ietf_error_code = 0x01; |
| 7735 | } else { |
| 7736 | rst_frame.error_code = static_cast<QuicRstStreamErrorCode>(0x05060708); |
| 7737 | } |
| 7738 | rst_frame.byte_offset = 0x0807060504030201; |
| 7739 | |
| 7740 | // clang-format off |
| 7741 | unsigned char packet[] = { |
| 7742 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7743 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7744 | // connection_id |
| 7745 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7746 | // packet number |
| 7747 | 0x12, 0x34, 0x56, 0x78, |
| 7748 | |
| 7749 | // frame type (rst stream frame) |
| 7750 | 0x01, |
| 7751 | // stream id |
| 7752 | 0x01, 0x02, 0x03, 0x04, |
| 7753 | // sent byte offset |
| 7754 | 0x08, 0x07, 0x06, 0x05, |
| 7755 | 0x04, 0x03, 0x02, 0x01, |
| 7756 | // error code |
| 7757 | 0x05, 0x06, 0x07, 0x08, |
| 7758 | }; |
| 7759 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7760 | unsigned char packet46[] = { |
| 7761 | // type (short packet, 4 byte packet number) |
| 7762 | 0x43, |
| 7763 | // connection_id |
| 7764 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7765 | // packet number |
| 7766 | 0x12, 0x34, 0x56, 0x78, |
| 7767 | |
| 7768 | // frame type (rst stream frame) |
| 7769 | 0x01, |
| 7770 | // stream id |
| 7771 | 0x01, 0x02, 0x03, 0x04, |
| 7772 | // sent byte offset |
| 7773 | 0x08, 0x07, 0x06, 0x05, |
| 7774 | 0x04, 0x03, 0x02, 0x01, |
| 7775 | // error code |
| 7776 | 0x05, 0x06, 0x07, 0x08, |
| 7777 | }; |
| 7778 | |
| 7779 | unsigned char packet99[] = { |
| 7780 | // type (short packet, 4 byte packet number) |
| 7781 | 0x43, |
| 7782 | // connection_id |
| 7783 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7784 | // packet number |
| 7785 | 0x12, 0x34, 0x56, 0x78, |
| 7786 | |
| 7787 | // frame type (IETF_RST_STREAM frame) |
| 7788 | 0x04, |
| 7789 | // stream id |
| 7790 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
fkastenholz | 07300e5 | 2019-07-16 11:51:37 -0700 | [diff] [blame] | 7791 | // error code |
| 7792 | kVarInt62OneByte + 0x01, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7793 | // sent byte offset |
| 7794 | kVarInt62EightBytes + 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 |
| 7795 | }; |
| 7796 | // clang-format on |
| 7797 | |
| 7798 | QuicFrames frames = {QuicFrame(&rst_frame)}; |
| 7799 | |
| 7800 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7801 | ASSERT_TRUE(data != nullptr); |
| 7802 | |
| 7803 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7804 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 7805 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7806 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7807 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 7808 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7809 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7810 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7811 | } |
| 7812 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 7813 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 7814 | quiche::test::CompareCharArraysWithHexError( |
| 7815 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7816 | } |
| 7817 | |
| 7818 | TEST_P(QuicFramerTest, BuildCloseFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7819 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7820 | QuicPacketHeader header; |
| 7821 | header.destination_connection_id = FramerTestConnectionId(); |
| 7822 | header.reset_flag = false; |
| 7823 | header.version_flag = false; |
| 7824 | header.packet_number = kPacketNumber; |
| 7825 | |
fkastenholz | 2d55b91 | 2019-09-10 15:57:17 -0700 | [diff] [blame] | 7826 | QuicConnectionCloseFrame close_frame( |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 7827 | framer_.transport_version(), QUIC_INTERNAL_ERROR, "because I can", 0x05); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7828 | QuicFrames frames = {QuicFrame(&close_frame)}; |
| 7829 | |
| 7830 | // clang-format off |
| 7831 | unsigned char packet[] = { |
| 7832 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 7833 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7834 | // connection_id |
| 7835 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7836 | // packet number |
| 7837 | 0x12, 0x34, 0x56, 0x78, |
| 7838 | |
| 7839 | // frame type (connection close frame) |
| 7840 | 0x02, |
| 7841 | // error code |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 7842 | 0x00, 0x00, 0x00, 0x01, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7843 | // error details length |
| 7844 | 0x00, 0x0d, |
| 7845 | // error details |
| 7846 | 'b', 'e', 'c', 'a', |
| 7847 | 'u', 's', 'e', ' ', |
| 7848 | 'I', ' ', 'c', 'a', |
| 7849 | 'n', |
| 7850 | }; |
| 7851 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7852 | unsigned char packet46[] = { |
| 7853 | // type (short header, 4 byte packet number) |
| 7854 | 0x43, |
| 7855 | // connection_id |
| 7856 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7857 | // packet number |
| 7858 | 0x12, 0x34, 0x56, 0x78, |
| 7859 | |
| 7860 | // frame type (connection close frame) |
| 7861 | 0x02, |
| 7862 | // error code |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 7863 | 0x00, 0x00, 0x00, 0x01, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7864 | // error details length |
| 7865 | 0x00, 0x0d, |
| 7866 | // error details |
| 7867 | 'b', 'e', 'c', 'a', |
| 7868 | 'u', 's', 'e', ' ', |
| 7869 | 'I', ' ', 'c', 'a', |
| 7870 | 'n', |
| 7871 | }; |
| 7872 | |
| 7873 | unsigned char packet99[] = { |
| 7874 | // type (short header, 4 byte packet number) |
| 7875 | 0x43, |
| 7876 | // connection_id |
| 7877 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7878 | // packet number |
| 7879 | 0x12, 0x34, 0x56, 0x78, |
| 7880 | |
| 7881 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 7882 | 0x1c, |
| 7883 | // error code |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 7884 | kVarInt62OneByte + 0x01, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7885 | // Frame type within the CONNECTION_CLOSE frame |
| 7886 | kVarInt62OneByte + 0x05, |
| 7887 | // error details length |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 7888 | kVarInt62OneByte + 0x0f, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7889 | // error details |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 7890 | '1', ':', 'b', 'e', |
| 7891 | 'c', 'a', 'u', 's', |
| 7892 | 'e', ' ', 'I', ' ', |
| 7893 | 'c', 'a', 'n', |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7894 | }; |
| 7895 | // clang-format on |
| 7896 | |
| 7897 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7898 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 7899 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7900 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7901 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 7902 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7903 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 7904 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7905 | } |
| 7906 | |
| 7907 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7908 | ASSERT_TRUE(data != nullptr); |
| 7909 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 7910 | quiche::test::CompareCharArraysWithHexError( |
| 7911 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7912 | } |
| 7913 | |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 7914 | TEST_P(QuicFramerTest, BuildCloseFramePacketExtendedInfo) { |
| 7915 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 7916 | QuicPacketHeader header; |
| 7917 | header.destination_connection_id = FramerTestConnectionId(); |
| 7918 | header.reset_flag = false; |
| 7919 | header.version_flag = false; |
| 7920 | header.packet_number = kPacketNumber; |
| 7921 | |
fkastenholz | 2d55b91 | 2019-09-10 15:57:17 -0700 | [diff] [blame] | 7922 | QuicConnectionCloseFrame close_frame( |
| 7923 | framer_.transport_version(), |
| 7924 | static_cast<QuicErrorCode>( |
bnc | 745c94e | 2020-04-06 06:54:57 -0700 | [diff] [blame] | 7925 | VersionHasIetfQuicFrames(framer_.transport_version()) ? 0x01 |
fkastenholz | 2d55b91 | 2019-09-10 15:57:17 -0700 | [diff] [blame] | 7926 | : 0x05060708), |
| 7927 | "because I can", 0x05); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 7928 | // Set this so that it is "there" for both Google QUIC and IETF QUIC |
| 7929 | // framing. It better not show up for Google QUIC! |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 7930 | close_frame.quic_error_code = static_cast<QuicErrorCode>(0x4567); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 7931 | |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 7932 | QuicFrames frames = {QuicFrame(&close_frame)}; |
| 7933 | |
| 7934 | // clang-format off |
| 7935 | unsigned char packet[] = { |
| 7936 | // public flags (8 byte connection_id) |
| 7937 | 0x2C, |
| 7938 | // connection_id |
| 7939 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7940 | // packet number |
| 7941 | 0x12, 0x34, 0x56, 0x78, |
| 7942 | |
| 7943 | // frame type (connection close frame) |
| 7944 | 0x02, |
| 7945 | // error code |
| 7946 | 0x05, 0x06, 0x07, 0x08, |
| 7947 | // error details length |
| 7948 | 0x00, 0x0d, |
| 7949 | // error details |
| 7950 | 'b', 'e', 'c', 'a', |
| 7951 | 'u', 's', 'e', ' ', |
| 7952 | 'I', ' ', 'c', 'a', |
| 7953 | 'n', |
| 7954 | }; |
| 7955 | |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 7956 | unsigned char packet46[] = { |
| 7957 | // type (short header, 4 byte packet number) |
| 7958 | 0x43, |
| 7959 | // connection_id |
| 7960 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7961 | // packet number |
| 7962 | 0x12, 0x34, 0x56, 0x78, |
| 7963 | |
| 7964 | // frame type (connection close frame) |
| 7965 | 0x02, |
| 7966 | // error code |
| 7967 | 0x05, 0x06, 0x07, 0x08, |
| 7968 | // error details length |
| 7969 | 0x00, 0x0d, |
| 7970 | // error details |
| 7971 | 'b', 'e', 'c', 'a', |
| 7972 | 'u', 's', 'e', ' ', |
| 7973 | 'I', ' ', 'c', 'a', |
| 7974 | 'n', |
| 7975 | }; |
| 7976 | |
| 7977 | unsigned char packet99[] = { |
| 7978 | // type (short header, 4 byte packet number) |
| 7979 | 0x43, |
| 7980 | // connection_id |
| 7981 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7982 | // packet number |
| 7983 | 0x12, 0x34, 0x56, 0x78, |
| 7984 | |
| 7985 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 7986 | 0x1c, |
bnc | 745c94e | 2020-04-06 06:54:57 -0700 | [diff] [blame] | 7987 | // IETF error code INTERNAL_ERROR = 0x01 corresponding to |
| 7988 | // QuicErrorCode::QUIC_INTERNAL_ERROR = 0x01. |
| 7989 | kVarInt62OneByte + 0x01, |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 7990 | // Frame type within the CONNECTION_CLOSE frame |
| 7991 | kVarInt62OneByte + 0x05, |
| 7992 | // error details length |
| 7993 | kVarInt62OneByte + 0x13, |
| 7994 | // error details |
| 7995 | '1', '7', '7', '6', |
| 7996 | '7', ':', 'b', 'e', |
| 7997 | 'c', 'a', 'u', 's', |
| 7998 | 'e', ' ', 'I', ' ', |
| 7999 | 'c', 'a', 'n' |
| 8000 | }; |
| 8001 | // clang-format on |
| 8002 | |
| 8003 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8004 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 8005 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 8006 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8007 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 8008 | } else if (framer_.version().HasIetfInvariantHeader()) { |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 8009 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8010 | p_size = ABSL_ARRAYSIZE(packet46); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 8011 | } |
| 8012 | |
| 8013 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8014 | ASSERT_TRUE(data != nullptr); |
| 8015 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8016 | quiche::test::CompareCharArraysWithHexError( |
| 8017 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 8018 | } |
| 8019 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8020 | TEST_P(QuicFramerTest, BuildTruncatedCloseFramePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8021 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8022 | QuicPacketHeader header; |
| 8023 | header.destination_connection_id = FramerTestConnectionId(); |
| 8024 | header.reset_flag = false; |
| 8025 | header.version_flag = false; |
| 8026 | header.packet_number = kPacketNumber; |
| 8027 | |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 8028 | QuicConnectionCloseFrame close_frame(framer_.transport_version(), |
| 8029 | QUIC_INTERNAL_ERROR, |
| 8030 | std::string(2048, 'A'), 0x05); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8031 | QuicFrames frames = {QuicFrame(&close_frame)}; |
| 8032 | |
| 8033 | // clang-format off |
| 8034 | unsigned char packet[] = { |
| 8035 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8036 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8037 | // connection_id |
| 8038 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8039 | // packet number |
| 8040 | 0x12, 0x34, 0x56, 0x78, |
| 8041 | |
| 8042 | // frame type (connection close frame) |
| 8043 | 0x02, |
| 8044 | // error code |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 8045 | 0x00, 0x00, 0x00, 0x01, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8046 | // error details length |
| 8047 | 0x01, 0x00, |
| 8048 | // error details (truncated to 256 bytes) |
| 8049 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8050 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8051 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8052 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8053 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8054 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8055 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8056 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8057 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8058 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8059 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8060 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8061 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8062 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8063 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8064 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8065 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8066 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8067 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8068 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8069 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8070 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8071 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8072 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8073 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8074 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8075 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8076 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8077 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8078 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8079 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8080 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8081 | }; |
| 8082 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8083 | unsigned char packet46[] = { |
| 8084 | // type (short header, 4 byte packet number) |
| 8085 | 0x43, |
| 8086 | // connection_id |
| 8087 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8088 | // packet number |
| 8089 | 0x12, 0x34, 0x56, 0x78, |
| 8090 | |
| 8091 | // frame type (connection close frame) |
| 8092 | 0x02, |
| 8093 | // error code |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 8094 | 0x00, 0x00, 0x00, 0x01, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8095 | // error details length |
| 8096 | 0x01, 0x00, |
| 8097 | // error details (truncated to 256 bytes) |
| 8098 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8099 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8100 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8101 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8102 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8103 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8104 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8105 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8106 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8107 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8108 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8109 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8110 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8111 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8112 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8113 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8114 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8115 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8116 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8117 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8118 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8119 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8120 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8121 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8122 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8123 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8124 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8125 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8126 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8127 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8128 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8129 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8130 | }; |
| 8131 | |
| 8132 | unsigned char packet99[] = { |
| 8133 | // type (short header, 4 byte packet number) |
| 8134 | 0x43, |
| 8135 | // connection_id |
| 8136 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8137 | // packet number |
| 8138 | 0x12, 0x34, 0x56, 0x78, |
| 8139 | |
| 8140 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 8141 | 0x1c, |
| 8142 | // error code |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 8143 | kVarInt62OneByte + 0x01, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8144 | // Frame type within the CONNECTION_CLOSE frame |
fkastenholz | 2d55b91 | 2019-09-10 15:57:17 -0700 | [diff] [blame] | 8145 | kVarInt62OneByte + 0x05, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8146 | // error details length |
| 8147 | kVarInt62TwoBytes + 0x01, 0x00, |
| 8148 | // error details (truncated to 256 bytes) |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 8149 | '1', ':', 'A', 'A', 'A', 'A', 'A', 'A', |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8150 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8151 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8152 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8153 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8154 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8155 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8156 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8157 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8158 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8159 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8160 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8161 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8162 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8163 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 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 | }; |
| 8182 | // clang-format on |
| 8183 | |
| 8184 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8185 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8186 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8187 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8188 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 8189 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8190 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8191 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8192 | } |
| 8193 | |
| 8194 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8195 | ASSERT_TRUE(data != nullptr); |
| 8196 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8197 | quiche::test::CompareCharArraysWithHexError( |
| 8198 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8199 | } |
| 8200 | |
| 8201 | TEST_P(QuicFramerTest, BuildApplicationCloseFramePacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8202 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 8203 | // This frame is only for IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8204 | return; |
| 8205 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8206 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8207 | QuicPacketHeader header; |
| 8208 | header.destination_connection_id = FramerTestConnectionId(); |
| 8209 | header.reset_flag = false; |
| 8210 | header.version_flag = false; |
| 8211 | header.packet_number = kPacketNumber; |
| 8212 | |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 8213 | QuicConnectionCloseFrame app_close_frame; |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 8214 | app_close_frame.wire_error_code = 0x11; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8215 | app_close_frame.error_details = "because I can"; |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 8216 | app_close_frame.close_type = IETF_QUIC_APPLICATION_CONNECTION_CLOSE; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8217 | |
| 8218 | QuicFrames frames = {QuicFrame(&app_close_frame)}; |
| 8219 | |
| 8220 | // clang-format off |
| 8221 | |
| 8222 | unsigned char packet99[] = { |
| 8223 | // type (short header, 4 byte packet number) |
| 8224 | 0x43, |
| 8225 | // connection_id |
| 8226 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8227 | // packet number |
| 8228 | 0x12, 0x34, 0x56, 0x78, |
| 8229 | |
| 8230 | // frame type (IETF_APPLICATION_CLOSE frame) |
| 8231 | 0x1d, |
| 8232 | // error code |
fkastenholz | d57d3f9 | 2019-07-16 09:05:17 -0700 | [diff] [blame] | 8233 | kVarInt62OneByte + 0x11, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8234 | // error details length |
fkastenholz | 2d55b91 | 2019-09-10 15:57:17 -0700 | [diff] [blame] | 8235 | kVarInt62OneByte + 0x0f, |
| 8236 | // error details, note that it includes an extended error code. |
| 8237 | '0', ':', 'b', 'e', |
| 8238 | 'c', 'a', 'u', 's', |
| 8239 | 'e', ' ', 'I', ' ', |
| 8240 | 'c', 'a', 'n', |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8241 | }; |
| 8242 | // clang-format on |
| 8243 | |
| 8244 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8245 | ASSERT_TRUE(data != nullptr); |
| 8246 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8247 | quiche::test::CompareCharArraysWithHexError( |
| 8248 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8249 | ABSL_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8250 | } |
| 8251 | |
| 8252 | TEST_P(QuicFramerTest, BuildTruncatedApplicationCloseFramePacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8253 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 8254 | // This frame is only for IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8255 | return; |
| 8256 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8257 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8258 | QuicPacketHeader header; |
| 8259 | header.destination_connection_id = FramerTestConnectionId(); |
| 8260 | header.reset_flag = false; |
| 8261 | header.version_flag = false; |
| 8262 | header.packet_number = kPacketNumber; |
| 8263 | |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 8264 | QuicConnectionCloseFrame app_close_frame; |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 8265 | app_close_frame.wire_error_code = 0x11; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 8266 | app_close_frame.error_details = std::string(2048, 'A'); |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 8267 | app_close_frame.close_type = IETF_QUIC_APPLICATION_CONNECTION_CLOSE; |
fkastenholz | 2d55b91 | 2019-09-10 15:57:17 -0700 | [diff] [blame] | 8268 | // Setting to missing ensures that if it is missing, the extended |
| 8269 | // code is not added to the text message. |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 8270 | app_close_frame.quic_error_code = QUIC_IETF_GQUIC_ERROR_MISSING; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8271 | |
| 8272 | QuicFrames frames = {QuicFrame(&app_close_frame)}; |
| 8273 | |
| 8274 | // clang-format off |
| 8275 | unsigned char packet99[] = { |
| 8276 | // type (short header, 4 byte packet number) |
| 8277 | 0x43, |
| 8278 | // connection_id |
| 8279 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8280 | // packet number |
| 8281 | 0x12, 0x34, 0x56, 0x78, |
| 8282 | |
| 8283 | // frame type (IETF_APPLICATION_CLOSE frame) |
| 8284 | 0x1d, |
| 8285 | // error code |
fkastenholz | d57d3f9 | 2019-07-16 09:05:17 -0700 | [diff] [blame] | 8286 | kVarInt62OneByte + 0x11, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8287 | // error details length |
| 8288 | kVarInt62TwoBytes + 0x01, 0x00, |
| 8289 | // error details (truncated to 256 bytes) |
| 8290 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8291 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8292 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8293 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8294 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8295 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8296 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8297 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8298 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8299 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8300 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8301 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8302 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8303 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8304 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8305 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8306 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8307 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8308 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8309 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8310 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8311 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8312 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8313 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8314 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8315 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8316 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8317 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8318 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8319 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8320 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8321 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8322 | }; |
| 8323 | // clang-format on |
| 8324 | |
| 8325 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8326 | ASSERT_TRUE(data != nullptr); |
| 8327 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8328 | quiche::test::CompareCharArraysWithHexError( |
| 8329 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8330 | ABSL_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8331 | } |
| 8332 | |
| 8333 | TEST_P(QuicFramerTest, BuildGoAwayPacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8334 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 8335 | // This frame is only for Google QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8336 | return; |
| 8337 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8338 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8339 | QuicPacketHeader header; |
| 8340 | header.destination_connection_id = FramerTestConnectionId(); |
| 8341 | header.reset_flag = false; |
| 8342 | header.version_flag = false; |
| 8343 | header.packet_number = kPacketNumber; |
| 8344 | |
| 8345 | QuicGoAwayFrame goaway_frame; |
| 8346 | goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 8347 | goaway_frame.last_good_stream_id = kStreamId; |
| 8348 | goaway_frame.reason_phrase = "because I can"; |
| 8349 | |
| 8350 | QuicFrames frames = {QuicFrame(&goaway_frame)}; |
| 8351 | |
| 8352 | // clang-format off |
| 8353 | unsigned char packet[] = { |
| 8354 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8355 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8356 | // connection_id |
| 8357 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8358 | // packet number |
| 8359 | 0x12, 0x34, 0x56, 0x78, |
| 8360 | |
| 8361 | // frame type (go away frame) |
| 8362 | 0x03, |
| 8363 | // error code |
| 8364 | 0x05, 0x06, 0x07, 0x08, |
| 8365 | // stream id |
| 8366 | 0x01, 0x02, 0x03, 0x04, |
| 8367 | // error details length |
| 8368 | 0x00, 0x0d, |
| 8369 | // error details |
| 8370 | 'b', 'e', 'c', 'a', |
| 8371 | 'u', 's', 'e', ' ', |
| 8372 | 'I', ' ', 'c', 'a', |
| 8373 | 'n', |
| 8374 | }; |
| 8375 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8376 | unsigned char packet46[] = { |
| 8377 | // type (short header, 4 byte packet number) |
| 8378 | 0x43, |
| 8379 | // connection_id |
| 8380 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8381 | // packet number |
| 8382 | 0x12, 0x34, 0x56, 0x78, |
| 8383 | |
| 8384 | // frame type (go away frame) |
| 8385 | 0x03, |
| 8386 | // error code |
| 8387 | 0x05, 0x06, 0x07, 0x08, |
| 8388 | // stream id |
| 8389 | 0x01, 0x02, 0x03, 0x04, |
| 8390 | // error details length |
| 8391 | 0x00, 0x0d, |
| 8392 | // error details |
| 8393 | 'b', 'e', 'c', 'a', |
| 8394 | 'u', 's', 'e', ' ', |
| 8395 | 'I', ' ', 'c', 'a', |
| 8396 | 'n', |
| 8397 | }; |
| 8398 | |
| 8399 | // clang-format on |
| 8400 | |
| 8401 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8402 | size_t p_size = ABSL_ARRAYSIZE(packet); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 8403 | if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8404 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8405 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8406 | } |
| 8407 | |
| 8408 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8409 | ASSERT_TRUE(data != nullptr); |
| 8410 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8411 | quiche::test::CompareCharArraysWithHexError( |
| 8412 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8413 | } |
| 8414 | |
| 8415 | TEST_P(QuicFramerTest, BuildTruncatedGoAwayPacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8416 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 8417 | // This frame is only for Google QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8418 | return; |
| 8419 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8420 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8421 | QuicPacketHeader header; |
| 8422 | header.destination_connection_id = FramerTestConnectionId(); |
| 8423 | header.reset_flag = false; |
| 8424 | header.version_flag = false; |
| 8425 | header.packet_number = kPacketNumber; |
| 8426 | |
| 8427 | QuicGoAwayFrame goaway_frame; |
| 8428 | goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 8429 | goaway_frame.last_good_stream_id = kStreamId; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 8430 | goaway_frame.reason_phrase = std::string(2048, 'A'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8431 | |
| 8432 | QuicFrames frames = {QuicFrame(&goaway_frame)}; |
| 8433 | |
| 8434 | // clang-format off |
| 8435 | unsigned char packet[] = { |
| 8436 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8437 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8438 | // connection_id |
| 8439 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8440 | // packet number |
| 8441 | 0x12, 0x34, 0x56, 0x78, |
| 8442 | |
| 8443 | // frame type (go away frame) |
| 8444 | 0x03, |
| 8445 | // error code |
| 8446 | 0x05, 0x06, 0x07, 0x08, |
| 8447 | // stream id |
| 8448 | 0x01, 0x02, 0x03, 0x04, |
| 8449 | // error details length |
| 8450 | 0x01, 0x00, |
| 8451 | // error details (truncated to 256 bytes) |
| 8452 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8453 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8454 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8455 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8456 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8457 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8458 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8459 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8460 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8461 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8462 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8463 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8464 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8465 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8466 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8467 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8468 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8469 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8470 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8471 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8472 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8473 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8474 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8475 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8476 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8477 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8478 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8479 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8480 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8481 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8482 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8483 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8484 | }; |
| 8485 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8486 | unsigned char packet46[] = { |
| 8487 | // type (short header, 4 byte packet number) |
| 8488 | 0x43, |
| 8489 | // connection_id |
| 8490 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8491 | // packet number |
| 8492 | 0x12, 0x34, 0x56, 0x78, |
| 8493 | |
| 8494 | // frame type (go away frame) |
| 8495 | 0x03, |
| 8496 | // error code |
| 8497 | 0x05, 0x06, 0x07, 0x08, |
| 8498 | // stream id |
| 8499 | 0x01, 0x02, 0x03, 0x04, |
| 8500 | // error details length |
| 8501 | 0x01, 0x00, |
| 8502 | // error details (truncated to 256 bytes) |
| 8503 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8504 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8505 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8506 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8507 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8508 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8509 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8510 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8511 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8512 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8513 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8514 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8515 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8516 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8517 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8518 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8519 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8520 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8521 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8522 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8523 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8524 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8525 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8526 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8527 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8528 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8529 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8530 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8531 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8532 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8533 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8534 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8535 | }; |
| 8536 | // clang-format on |
| 8537 | |
| 8538 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8539 | size_t p_size = ABSL_ARRAYSIZE(packet); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 8540 | if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8541 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8542 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8543 | } |
| 8544 | |
| 8545 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8546 | ASSERT_TRUE(data != nullptr); |
| 8547 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8548 | quiche::test::CompareCharArraysWithHexError( |
| 8549 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8550 | } |
| 8551 | |
| 8552 | TEST_P(QuicFramerTest, BuildWindowUpdatePacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8553 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8554 | QuicPacketHeader header; |
| 8555 | header.destination_connection_id = FramerTestConnectionId(); |
| 8556 | header.reset_flag = false; |
| 8557 | header.version_flag = false; |
| 8558 | header.packet_number = kPacketNumber; |
| 8559 | |
| 8560 | QuicWindowUpdateFrame window_update_frame; |
| 8561 | window_update_frame.stream_id = kStreamId; |
renjietang | d088eab | 2019-11-21 14:54:41 -0800 | [diff] [blame] | 8562 | window_update_frame.max_data = 0x1122334455667788; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8563 | |
| 8564 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 8565 | |
| 8566 | // clang-format off |
| 8567 | unsigned char packet[] = { |
| 8568 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8569 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8570 | // connection_id |
| 8571 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8572 | // packet number |
| 8573 | 0x12, 0x34, 0x56, 0x78, |
| 8574 | |
| 8575 | // frame type (window update frame) |
| 8576 | 0x04, |
| 8577 | // stream id |
| 8578 | 0x01, 0x02, 0x03, 0x04, |
| 8579 | // byte offset |
| 8580 | 0x11, 0x22, 0x33, 0x44, |
| 8581 | 0x55, 0x66, 0x77, 0x88, |
| 8582 | }; |
| 8583 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8584 | unsigned char packet46[] = { |
| 8585 | // type (short header, 4 byte packet number) |
| 8586 | 0x43, |
| 8587 | // connection_id |
| 8588 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8589 | // packet number |
| 8590 | 0x12, 0x34, 0x56, 0x78, |
| 8591 | |
| 8592 | // frame type (window update frame) |
| 8593 | 0x04, |
| 8594 | // stream id |
| 8595 | 0x01, 0x02, 0x03, 0x04, |
| 8596 | // byte offset |
| 8597 | 0x11, 0x22, 0x33, 0x44, |
| 8598 | 0x55, 0x66, 0x77, 0x88, |
| 8599 | }; |
| 8600 | |
| 8601 | unsigned char packet99[] = { |
| 8602 | // type (short header, 4 byte packet number) |
| 8603 | 0x43, |
| 8604 | // connection_id |
| 8605 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8606 | // packet number |
| 8607 | 0x12, 0x34, 0x56, 0x78, |
| 8608 | |
| 8609 | // frame type (IETF_MAX_STREAM_DATA frame) |
| 8610 | 0x11, |
| 8611 | // stream id |
| 8612 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 8613 | // byte offset |
| 8614 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 8615 | 0x55, 0x66, 0x77, 0x88, |
| 8616 | }; |
| 8617 | // clang-format on |
| 8618 | |
| 8619 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8620 | ASSERT_TRUE(data != nullptr); |
| 8621 | |
| 8622 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8623 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8624 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8625 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8626 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 8627 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8628 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8629 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8630 | } |
| 8631 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8632 | quiche::test::CompareCharArraysWithHexError( |
| 8633 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8634 | } |
| 8635 | |
| 8636 | TEST_P(QuicFramerTest, BuildMaxStreamDataPacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8637 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 8638 | // This frame is only for IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8639 | return; |
| 8640 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8641 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8642 | QuicPacketHeader header; |
| 8643 | header.destination_connection_id = FramerTestConnectionId(); |
| 8644 | header.reset_flag = false; |
| 8645 | header.version_flag = false; |
| 8646 | header.packet_number = kPacketNumber; |
| 8647 | |
| 8648 | QuicWindowUpdateFrame window_update_frame; |
| 8649 | window_update_frame.stream_id = kStreamId; |
renjietang | d088eab | 2019-11-21 14:54:41 -0800 | [diff] [blame] | 8650 | window_update_frame.max_data = 0x1122334455667788; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8651 | |
| 8652 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 8653 | |
| 8654 | // clang-format off |
| 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_MAX_STREAM_DATA frame) |
| 8664 | 0x11, |
| 8665 | // stream id |
| 8666 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 8667 | // byte offset |
| 8668 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 8669 | 0x55, 0x66, 0x77, 0x88, |
| 8670 | }; |
| 8671 | // clang-format on |
| 8672 | |
| 8673 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8674 | ASSERT_TRUE(data != nullptr); |
| 8675 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8676 | quiche::test::CompareCharArraysWithHexError( |
| 8677 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8678 | ABSL_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8679 | } |
| 8680 | |
| 8681 | TEST_P(QuicFramerTest, BuildMaxDataPacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8682 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 8683 | // This frame is only for IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8684 | return; |
| 8685 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8686 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8687 | QuicPacketHeader header; |
| 8688 | header.destination_connection_id = FramerTestConnectionId(); |
| 8689 | header.reset_flag = false; |
| 8690 | header.version_flag = false; |
| 8691 | header.packet_number = kPacketNumber; |
| 8692 | |
| 8693 | QuicWindowUpdateFrame window_update_frame; |
| 8694 | window_update_frame.stream_id = |
| 8695 | QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
renjietang | d088eab | 2019-11-21 14:54:41 -0800 | [diff] [blame] | 8696 | window_update_frame.max_data = 0x1122334455667788; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8697 | |
| 8698 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 8699 | |
| 8700 | // clang-format off |
| 8701 | unsigned char packet99[] = { |
| 8702 | // type (short header, 4 byte packet number) |
| 8703 | 0x43, |
| 8704 | // connection_id |
| 8705 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8706 | // packet number |
| 8707 | 0x12, 0x34, 0x56, 0x78, |
| 8708 | |
| 8709 | // frame type (IETF_MAX_DATA frame) |
| 8710 | 0x10, |
| 8711 | // byte offset |
| 8712 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 8713 | 0x55, 0x66, 0x77, 0x88, |
| 8714 | }; |
| 8715 | // clang-format on |
| 8716 | |
| 8717 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8718 | ASSERT_TRUE(data != nullptr); |
| 8719 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8720 | quiche::test::CompareCharArraysWithHexError( |
| 8721 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8722 | ABSL_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8723 | } |
| 8724 | |
| 8725 | TEST_P(QuicFramerTest, BuildBlockedPacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8726 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8727 | QuicPacketHeader header; |
| 8728 | header.destination_connection_id = FramerTestConnectionId(); |
| 8729 | header.reset_flag = false; |
| 8730 | header.version_flag = false; |
| 8731 | header.packet_number = kPacketNumber; |
| 8732 | |
| 8733 | QuicBlockedFrame blocked_frame; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8734 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 8735 | // For IETF QUIC, the stream ID must be <invalid> for the frame |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8736 | // to be a BLOCKED frame. if it's valid, it will be a |
| 8737 | // STREAM_BLOCKED frame. |
| 8738 | blocked_frame.stream_id = |
| 8739 | QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
| 8740 | } else { |
| 8741 | blocked_frame.stream_id = kStreamId; |
| 8742 | } |
| 8743 | blocked_frame.offset = kStreamOffset; |
| 8744 | |
| 8745 | QuicFrames frames = {QuicFrame(&blocked_frame)}; |
| 8746 | |
| 8747 | // clang-format off |
| 8748 | unsigned char packet[] = { |
| 8749 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8750 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8751 | // connection_id |
| 8752 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8753 | // packet number |
| 8754 | 0x12, 0x34, 0x56, 0x78, |
| 8755 | |
| 8756 | // frame type (blocked frame) |
| 8757 | 0x05, |
| 8758 | // stream id |
| 8759 | 0x01, 0x02, 0x03, 0x04, |
| 8760 | }; |
| 8761 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8762 | unsigned char packet46[] = { |
| 8763 | // type (short packet, 4 byte packet number) |
| 8764 | 0x43, |
| 8765 | // connection_id |
| 8766 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8767 | // packet number |
| 8768 | 0x12, 0x34, 0x56, 0x78, |
| 8769 | |
| 8770 | // frame type (blocked frame) |
| 8771 | 0x05, |
| 8772 | // stream id |
| 8773 | 0x01, 0x02, 0x03, 0x04, |
| 8774 | }; |
| 8775 | |
| 8776 | unsigned char packet99[] = { |
| 8777 | // type (short packet, 4 byte packet number) |
| 8778 | 0x43, |
| 8779 | // connection_id |
| 8780 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8781 | // packet number |
| 8782 | 0x12, 0x34, 0x56, 0x78, |
| 8783 | |
ianswett | 2f07744 | 2019-12-12 11:51:24 -0800 | [diff] [blame] | 8784 | // frame type (IETF_DATA_BLOCKED frame) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8785 | 0x14, |
| 8786 | // Offset |
| 8787 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 8788 | }; |
| 8789 | // clang-format on |
| 8790 | |
| 8791 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8792 | ASSERT_TRUE(data != nullptr); |
| 8793 | |
| 8794 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8795 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8796 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8797 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8798 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 8799 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8800 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8801 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8802 | } |
| 8803 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8804 | quiche::test::CompareCharArraysWithHexError( |
| 8805 | "constructed packet", data->data(), data->length(), AsChars(p), p_size); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8806 | } |
| 8807 | |
| 8808 | TEST_P(QuicFramerTest, BuildPingPacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8809 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8810 | QuicPacketHeader header; |
| 8811 | header.destination_connection_id = FramerTestConnectionId(); |
| 8812 | header.reset_flag = false; |
| 8813 | header.version_flag = false; |
| 8814 | header.packet_number = kPacketNumber; |
| 8815 | |
| 8816 | QuicFrames frames = {QuicFrame(QuicPingFrame())}; |
| 8817 | |
| 8818 | // clang-format off |
| 8819 | unsigned char packet[] = { |
| 8820 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8821 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8822 | // connection_id |
| 8823 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8824 | // packet number |
| 8825 | 0x12, 0x34, 0x56, 0x78, |
| 8826 | |
| 8827 | // frame type (ping frame) |
| 8828 | 0x07, |
| 8829 | }; |
| 8830 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8831 | unsigned char packet46[] = { |
| 8832 | // type (short header, 4 byte packet number) |
| 8833 | 0x43, |
| 8834 | // connection_id |
| 8835 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8836 | // packet number |
| 8837 | 0x12, 0x34, 0x56, 0x78, |
| 8838 | |
| 8839 | // frame type |
| 8840 | 0x07, |
| 8841 | }; |
| 8842 | |
| 8843 | unsigned char packet99[] = { |
| 8844 | // type (short header, 4 byte packet number) |
| 8845 | 0x43, |
| 8846 | // connection_id |
| 8847 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8848 | // packet number |
| 8849 | 0x12, 0x34, 0x56, 0x78, |
| 8850 | |
| 8851 | // frame type (IETF_PING frame) |
| 8852 | 0x01, |
| 8853 | }; |
| 8854 | // clang-format on |
| 8855 | |
| 8856 | unsigned char* p = packet; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 8857 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8858 | p = packet99; |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 8859 | } else if (framer_.version().HasIetfInvariantHeader()) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 8860 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8861 | } |
| 8862 | |
| 8863 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8864 | ASSERT_TRUE(data != nullptr); |
| 8865 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 8866 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8867 | "constructed packet", data->data(), data->length(), AsChars(p), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8868 | framer_.version().HasIetfInvariantHeader() ? ABSL_ARRAYSIZE(packet46) |
| 8869 | : ABSL_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8870 | } |
| 8871 | |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 8872 | TEST_P(QuicFramerTest, BuildHandshakeDonePacket) { |
| 8873 | QuicPacketHeader header; |
| 8874 | header.destination_connection_id = FramerTestConnectionId(); |
| 8875 | header.reset_flag = false; |
| 8876 | header.version_flag = false; |
| 8877 | header.packet_number = kPacketNumber; |
| 8878 | |
| 8879 | QuicFrames frames = {QuicFrame(QuicHandshakeDoneFrame())}; |
| 8880 | |
| 8881 | // clang-format off |
| 8882 | unsigned char packet[] = { |
| 8883 | // type (short header, 4 byte packet number) |
| 8884 | 0x43, |
| 8885 | // connection_id |
| 8886 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8887 | // packet number |
| 8888 | 0x12, 0x34, 0x56, 0x78, |
| 8889 | |
| 8890 | // frame type (Handshake done frame) |
| 8891 | 0x1e, |
| 8892 | }; |
| 8893 | // clang-format on |
| 8894 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 8895 | return; |
| 8896 | } |
| 8897 | |
| 8898 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8899 | ASSERT_TRUE(data != nullptr); |
| 8900 | |
| 8901 | quiche::test::CompareCharArraysWithHexError( |
| 8902 | "constructed packet", data->data(), data->length(), AsChars(packet), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8903 | ABSL_ARRAYSIZE(packet)); |
fayang | 0106294 | 2020-01-22 07:23:23 -0800 | [diff] [blame] | 8904 | } |
| 8905 | |
haoyuewang | 6a6a0ff | 2020-06-23 16:32:26 -0700 | [diff] [blame] | 8906 | TEST_P(QuicFramerTest, BuildAckFrequencyPacket) { |
| 8907 | QuicPacketHeader header; |
| 8908 | header.destination_connection_id = FramerTestConnectionId(); |
| 8909 | header.reset_flag = false; |
| 8910 | header.version_flag = false; |
| 8911 | header.packet_number = kPacketNumber; |
| 8912 | |
| 8913 | QuicAckFrequencyFrame ack_frequency_frame; |
| 8914 | ack_frequency_frame.sequence_number = 3; |
| 8915 | ack_frequency_frame.packet_tolerance = 5; |
| 8916 | ack_frequency_frame.max_ack_delay = QuicTime::Delta::FromMicroseconds(0x3fff); |
| 8917 | ack_frequency_frame.ignore_order = false; |
| 8918 | QuicFrames frames = {QuicFrame(&ack_frequency_frame)}; |
| 8919 | |
| 8920 | // clang-format off |
| 8921 | unsigned char packet[] = { |
| 8922 | // type (short header, 4 byte packet number) |
| 8923 | 0x43, |
| 8924 | // connection_id |
| 8925 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8926 | // packet number |
| 8927 | 0x12, 0x34, 0x56, 0x78, |
| 8928 | |
| 8929 | // frame type (Ack Frequency frame) |
| 8930 | 0x40, 0xaf, |
| 8931 | // sequence number |
| 8932 | 0x03, |
| 8933 | // packet tolerance |
| 8934 | 0x05, |
| 8935 | // max_ack_delay_us |
| 8936 | 0x7f, 0xff, |
| 8937 | // ignore_oder |
| 8938 | 0x00 |
| 8939 | }; |
| 8940 | // clang-format on |
| 8941 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 8942 | return; |
| 8943 | } |
| 8944 | |
| 8945 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8946 | ASSERT_TRUE(data != nullptr); |
| 8947 | |
| 8948 | quiche::test::CompareCharArraysWithHexError( |
| 8949 | "constructed packet", data->data(), data->length(), AsChars(packet), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 8950 | ABSL_ARRAYSIZE(packet)); |
haoyuewang | 6a6a0ff | 2020-06-23 16:32:26 -0700 | [diff] [blame] | 8951 | } |
| 8952 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8953 | TEST_P(QuicFramerTest, BuildMessagePacket) { |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 8954 | if (!VersionSupportsMessageFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8955 | return; |
| 8956 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 8957 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8958 | QuicPacketHeader header; |
| 8959 | header.destination_connection_id = FramerTestConnectionId(); |
| 8960 | header.reset_flag = false; |
| 8961 | header.version_flag = false; |
| 8962 | header.packet_number = kPacketNumber; |
| 8963 | QuicMemSliceStorage storage(nullptr, 0, nullptr, 0); |
| 8964 | |
wub | 553a966 | 2019-03-28 20:13:23 -0700 | [diff] [blame] | 8965 | QuicMessageFrame frame(1, MakeSpan(&allocator_, "message", &storage)); |
| 8966 | QuicMessageFrame frame2(2, MakeSpan(&allocator_, "message2", &storage)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 8967 | QuicFrames frames = {QuicFrame(&frame), QuicFrame(&frame2)}; |
| 8968 | |
| 8969 | // clang-format off |
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 | // frame type (message frame) |
| 8979 | 0x21, |
| 8980 | // Length |
| 8981 | 0x07, |
| 8982 | // Message Data |
| 8983 | 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 8984 | // frame type (message frame no length) |
| 8985 | 0x20, |
| 8986 | // Message Data |
| 8987 | 'm', 'e', 's', 's', 'a', 'g', 'e', '2' |
| 8988 | }; |
| 8989 | |
| 8990 | unsigned char packet99[] = { |
| 8991 | // type (short header, 4 byte packet number) |
| 8992 | 0x43, |
| 8993 | // connection_id |
| 8994 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8995 | // packet number |
| 8996 | 0x12, 0x34, 0x56, 0x78, |
| 8997 | |
| 8998 | // frame type (IETF_MESSAGE frame) |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 8999 | 0x31, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9000 | // Length |
| 9001 | 0x07, |
| 9002 | // Message Data |
| 9003 | 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 9004 | // frame type (message frame no length) |
dschinazi | cd86dd1 | 2019-11-14 10:11:13 -0800 | [diff] [blame] | 9005 | 0x30, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9006 | // Message Data |
| 9007 | 'm', 'e', 's', 's', 'a', 'g', 'e', '2' |
| 9008 | }; |
| 9009 | // clang-format on |
| 9010 | |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 9011 | unsigned char* p = packet46; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9012 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9013 | p = packet99; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9014 | } |
| 9015 | |
| 9016 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 9017 | ASSERT_TRUE(data != nullptr); |
| 9018 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 9019 | quiche::test::CompareCharArraysWithHexError( |
| 9020 | "constructed packet", data->data(), data->length(), AsChars(p), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 9021 | ABSL_ARRAYSIZE(packet46)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9022 | } |
| 9023 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9024 | // Test that the MTU discovery packet is serialized correctly as a PING packet. |
| 9025 | TEST_P(QuicFramerTest, BuildMtuDiscoveryPacket) { |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 9026 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9027 | QuicPacketHeader header; |
| 9028 | header.destination_connection_id = FramerTestConnectionId(); |
| 9029 | header.reset_flag = false; |
| 9030 | header.version_flag = false; |
| 9031 | header.packet_number = kPacketNumber; |
| 9032 | |
| 9033 | QuicFrames frames = {QuicFrame(QuicMtuDiscoveryFrame())}; |
| 9034 | |
| 9035 | // clang-format off |
| 9036 | unsigned char packet[] = { |
| 9037 | // public flags (8 byte connection_id) |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 9038 | 0x2C, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9039 | // connection_id |
| 9040 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9041 | // packet number |
| 9042 | 0x12, 0x34, 0x56, 0x78, |
| 9043 | |
| 9044 | // frame type (ping frame) |
| 9045 | 0x07, |
| 9046 | }; |
| 9047 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9048 | unsigned char packet46[] = { |
| 9049 | // type (short header, 4 byte packet number) |
| 9050 | 0x43, |
| 9051 | // connection_id |
| 9052 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9053 | // packet number |
| 9054 | 0x12, 0x34, 0x56, 0x78, |
| 9055 | |
| 9056 | // frame type |
| 9057 | 0x07, |
| 9058 | }; |
| 9059 | |
| 9060 | unsigned char packet99[] = { |
| 9061 | // type (short header, 4 byte packet number) |
| 9062 | 0x43, |
| 9063 | // connection_id |
| 9064 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9065 | // packet number |
| 9066 | 0x12, 0x34, 0x56, 0x78, |
| 9067 | |
| 9068 | // frame type (IETF_PING frame) |
| 9069 | 0x01, |
| 9070 | }; |
| 9071 | // clang-format on |
| 9072 | |
| 9073 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 9074 | ASSERT_TRUE(data != nullptr); |
| 9075 | |
| 9076 | unsigned char* p = packet; |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9077 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9078 | p = packet99; |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 9079 | } else if (framer_.version().HasIetfInvariantHeader()) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 9080 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9081 | } |
| 9082 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 9083 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9084 | "constructed packet", data->data(), data->length(), AsChars(p), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 9085 | framer_.version().HasIetfInvariantHeader() ? ABSL_ARRAYSIZE(packet46) |
| 9086 | : ABSL_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9087 | } |
| 9088 | |
| 9089 | TEST_P(QuicFramerTest, BuildPublicResetPacket) { |
| 9090 | QuicPublicResetPacket reset_packet; |
| 9091 | reset_packet.connection_id = FramerTestConnectionId(); |
| 9092 | reset_packet.nonce_proof = kNonceProof; |
| 9093 | |
| 9094 | // clang-format off |
| 9095 | unsigned char packet[] = { |
| 9096 | // public flags (public reset, 8 byte ConnectionId) |
| 9097 | 0x0E, |
| 9098 | // connection_id |
| 9099 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9100 | // message tag (kPRST) |
| 9101 | 'P', 'R', 'S', 'T', |
| 9102 | // num_entries (1) + padding |
| 9103 | 0x01, 0x00, 0x00, 0x00, |
| 9104 | // tag kRNON |
| 9105 | 'R', 'N', 'O', 'N', |
| 9106 | // end offset 8 |
| 9107 | 0x08, 0x00, 0x00, 0x00, |
| 9108 | // nonce proof |
| 9109 | 0x89, 0x67, 0x45, 0x23, |
| 9110 | 0x01, 0xEF, 0xCD, 0xAB, |
| 9111 | }; |
| 9112 | // clang-format on |
| 9113 | |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 9114 | if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9115 | return; |
| 9116 | } |
| 9117 | |
| 9118 | std::unique_ptr<QuicEncryptedPacket> data( |
| 9119 | framer_.BuildPublicResetPacket(reset_packet)); |
| 9120 | ASSERT_TRUE(data != nullptr); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 9121 | quiche::test::CompareCharArraysWithHexError( |
| 9122 | "constructed packet", data->data(), data->length(), AsChars(packet), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 9123 | ABSL_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9124 | } |
| 9125 | |
| 9126 | TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) { |
| 9127 | QuicPublicResetPacket reset_packet; |
| 9128 | reset_packet.connection_id = FramerTestConnectionId(); |
| 9129 | reset_packet.nonce_proof = kNonceProof; |
| 9130 | reset_packet.client_address = |
| 9131 | QuicSocketAddress(QuicIpAddress::Loopback4(), 0x1234); |
| 9132 | |
| 9133 | // clang-format off |
| 9134 | unsigned char packet[] = { |
| 9135 | // public flags (public reset, 8 byte ConnectionId) |
| 9136 | 0x0E, |
| 9137 | // connection_id |
| 9138 | 0xFE, 0xDC, 0xBA, 0x98, |
| 9139 | 0x76, 0x54, 0x32, 0x10, |
| 9140 | // message tag (kPRST) |
| 9141 | 'P', 'R', 'S', 'T', |
| 9142 | // num_entries (2) + padding |
| 9143 | 0x02, 0x00, 0x00, 0x00, |
| 9144 | // tag kRNON |
| 9145 | 'R', 'N', 'O', 'N', |
| 9146 | // end offset 8 |
| 9147 | 0x08, 0x00, 0x00, 0x00, |
| 9148 | // tag kCADR |
| 9149 | 'C', 'A', 'D', 'R', |
| 9150 | // end offset 16 |
| 9151 | 0x10, 0x00, 0x00, 0x00, |
| 9152 | // nonce proof |
| 9153 | 0x89, 0x67, 0x45, 0x23, |
| 9154 | 0x01, 0xEF, 0xCD, 0xAB, |
| 9155 | // client address |
| 9156 | 0x02, 0x00, |
| 9157 | 0x7F, 0x00, 0x00, 0x01, |
| 9158 | 0x34, 0x12, |
| 9159 | }; |
| 9160 | // clang-format on |
| 9161 | |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 9162 | if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9163 | return; |
| 9164 | } |
| 9165 | |
| 9166 | std::unique_ptr<QuicEncryptedPacket> data( |
| 9167 | framer_.BuildPublicResetPacket(reset_packet)); |
| 9168 | ASSERT_TRUE(data != nullptr); |
| 9169 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 9170 | quiche::test::CompareCharArraysWithHexError( |
| 9171 | "constructed packet", data->data(), data->length(), AsChars(packet), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 9172 | ABSL_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9173 | } |
| 9174 | |
| 9175 | TEST_P(QuicFramerTest, BuildPublicResetPacketWithEndpointId) { |
| 9176 | QuicPublicResetPacket reset_packet; |
| 9177 | reset_packet.connection_id = FramerTestConnectionId(); |
| 9178 | reset_packet.nonce_proof = kNonceProof; |
| 9179 | reset_packet.endpoint_id = "FakeServerId"; |
| 9180 | |
| 9181 | // The tag value map in CryptoHandshakeMessage is a std::map, so the two tags |
| 9182 | // in the packet, kRNON and kEPID, have unspecified ordering w.r.t each other. |
| 9183 | // clang-format off |
| 9184 | unsigned char packet_variant1[] = { |
| 9185 | // public flags (public reset, 8 byte ConnectionId) |
| 9186 | 0x0E, |
| 9187 | // connection_id |
| 9188 | 0xFE, 0xDC, 0xBA, 0x98, |
| 9189 | 0x76, 0x54, 0x32, 0x10, |
| 9190 | // message tag (kPRST) |
| 9191 | 'P', 'R', 'S', 'T', |
| 9192 | // num_entries (2) + padding |
| 9193 | 0x02, 0x00, 0x00, 0x00, |
| 9194 | // tag kRNON |
| 9195 | 'R', 'N', 'O', 'N', |
| 9196 | // end offset 8 |
| 9197 | 0x08, 0x00, 0x00, 0x00, |
| 9198 | // tag kEPID |
| 9199 | 'E', 'P', 'I', 'D', |
| 9200 | // end offset 20 |
| 9201 | 0x14, 0x00, 0x00, 0x00, |
| 9202 | // nonce proof |
| 9203 | 0x89, 0x67, 0x45, 0x23, |
| 9204 | 0x01, 0xEF, 0xCD, 0xAB, |
| 9205 | // Endpoint ID |
| 9206 | 'F', 'a', 'k', 'e', 'S', 'e', 'r', 'v', 'e', 'r', 'I', 'd', |
| 9207 | }; |
| 9208 | unsigned char packet_variant2[] = { |
| 9209 | // public flags (public reset, 8 byte ConnectionId) |
| 9210 | 0x0E, |
| 9211 | // connection_id |
| 9212 | 0xFE, 0xDC, 0xBA, 0x98, |
| 9213 | 0x76, 0x54, 0x32, 0x10, |
| 9214 | // message tag (kPRST) |
| 9215 | 'P', 'R', 'S', 'T', |
| 9216 | // num_entries (2) + padding |
| 9217 | 0x02, 0x00, 0x00, 0x00, |
| 9218 | // tag kEPID |
| 9219 | 'E', 'P', 'I', 'D', |
| 9220 | // end offset 12 |
| 9221 | 0x0C, 0x00, 0x00, 0x00, |
| 9222 | // tag kRNON |
| 9223 | 'R', 'N', 'O', 'N', |
| 9224 | // end offset 20 |
| 9225 | 0x14, 0x00, 0x00, 0x00, |
| 9226 | // Endpoint ID |
| 9227 | 'F', 'a', 'k', 'e', 'S', 'e', 'r', 'v', 'e', 'r', 'I', 'd', |
| 9228 | // nonce proof |
| 9229 | 0x89, 0x67, 0x45, 0x23, |
| 9230 | 0x01, 0xEF, 0xCD, 0xAB, |
| 9231 | }; |
| 9232 | // clang-format on |
| 9233 | |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 9234 | if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9235 | return; |
| 9236 | } |
| 9237 | |
| 9238 | std::unique_ptr<QuicEncryptedPacket> data( |
| 9239 | framer_.BuildPublicResetPacket(reset_packet)); |
| 9240 | ASSERT_TRUE(data != nullptr); |
| 9241 | |
| 9242 | // Variant 1 ends with char 'd'. Variant 1 ends with char 0xAB. |
| 9243 | if ('d' == data->data()[data->length() - 1]) { |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 9244 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9245 | "constructed packet", data->data(), data->length(), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 9246 | AsChars(packet_variant1), ABSL_ARRAYSIZE(packet_variant1)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9247 | } else { |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 9248 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9249 | "constructed packet", data->data(), data->length(), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 9250 | AsChars(packet_variant2), ABSL_ARRAYSIZE(packet_variant2)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9251 | } |
| 9252 | } |
| 9253 | |
| 9254 | TEST_P(QuicFramerTest, BuildIetfStatelessResetPacket) { |
| 9255 | // clang-format off |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 9256 | unsigned char packet[] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9257 | // type (short header, 1 byte packet number) |
| 9258 | 0x70, |
| 9259 | // random packet number |
| 9260 | 0xFE, |
| 9261 | // stateless reset token |
| 9262 | 0xB5, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 9263 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 9264 | }; |
| 9265 | // clang-format on |
| 9266 | |
| 9267 | std::unique_ptr<QuicEncryptedPacket> data( |
| 9268 | framer_.BuildIetfStatelessResetPacket(FramerTestConnectionId(), |
| 9269 | kTestStatelessResetToken)); |
| 9270 | ASSERT_TRUE(data != nullptr); |
| 9271 | // Skip packet number byte which is random in stateless reset packet. |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 9272 | quiche::test::CompareCharArraysWithHexError( |
| 9273 | "constructed packet", data->data(), 1, AsChars(packet), 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9274 | const size_t random_bytes_length = |
| 9275 | data->length() - kPacketHeaderTypeSize - sizeof(kTestStatelessResetToken); |
| 9276 | EXPECT_EQ(kMinRandomBytesLengthInStatelessReset, random_bytes_length); |
| 9277 | // Verify stateless reset token is correct. |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 9278 | quiche::test::CompareCharArraysWithHexError( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9279 | "constructed packet", |
| 9280 | data->data() + data->length() - sizeof(kTestStatelessResetToken), |
| 9281 | sizeof(kTestStatelessResetToken), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 9282 | AsChars(packet) + ABSL_ARRAYSIZE(packet) - |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9283 | sizeof(kTestStatelessResetToken), |
| 9284 | sizeof(kTestStatelessResetToken)); |
| 9285 | } |
| 9286 | |
| 9287 | TEST_P(QuicFramerTest, EncryptPacket) { |
| 9288 | QuicPacketNumber packet_number = kPacketNumber; |
| 9289 | // clang-format off |
| 9290 | unsigned char packet[] = { |
| 9291 | // public flags (8 byte connection_id) |
| 9292 | 0x28, |
| 9293 | // connection_id |
| 9294 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9295 | // packet number |
| 9296 | 0x12, 0x34, 0x56, 0x78, |
| 9297 | |
| 9298 | // redundancy |
| 9299 | 'a', 'b', 'c', 'd', |
| 9300 | 'e', 'f', 'g', 'h', |
| 9301 | 'i', 'j', 'k', 'l', |
| 9302 | 'm', 'n', 'o', 'p', |
| 9303 | }; |
| 9304 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9305 | unsigned char packet46[] = { |
| 9306 | // type (short header, 4 byte packet number) |
| 9307 | 0x43, |
| 9308 | // connection_id |
| 9309 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9310 | // packet number |
| 9311 | 0x12, 0x34, 0x56, 0x78, |
| 9312 | |
| 9313 | // redundancy |
| 9314 | 'a', 'b', 'c', 'd', |
| 9315 | 'e', 'f', 'g', 'h', |
| 9316 | 'i', 'j', 'k', 'l', |
| 9317 | 'm', 'n', 'o', 'p', |
| 9318 | }; |
| 9319 | |
nharper | c32d8ab | 2019-10-09 11:09:06 -0700 | [diff] [blame] | 9320 | unsigned char packet50[] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9321 | // type (short header, 4 byte packet number) |
| 9322 | 0x43, |
| 9323 | // connection_id |
| 9324 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9325 | // packet number |
| 9326 | 0x12, 0x34, 0x56, 0x78, |
| 9327 | |
| 9328 | // redundancy |
| 9329 | 'a', 'b', 'c', 'd', |
| 9330 | 'e', 'f', 'g', 'h', |
| 9331 | 'i', 'j', 'k', 'l', |
| 9332 | 'm', 'n', 'o', 'p', |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9333 | 'q', 'r', 's', 't', |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9334 | }; |
| 9335 | // clang-format on |
| 9336 | |
| 9337 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 9338 | size_t p_size = ABSL_ARRAYSIZE(packet); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 9339 | if (framer_.version().HasHeaderProtection()) { |
nharper | c32d8ab | 2019-10-09 11:09:06 -0700 | [diff] [blame] | 9340 | p = packet50; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 9341 | p_size = ABSL_ARRAYSIZE(packet50); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 9342 | } else if (framer_.version().HasIetfInvariantHeader()) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 9343 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9344 | } |
| 9345 | |
| 9346 | std::unique_ptr<QuicPacket> raw(new QuicPacket( |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9347 | AsChars(p), p_size, false, PACKET_8BYTE_CONNECTION_ID, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9348 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 9349 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 9350 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0)); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9351 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9352 | size_t encrypted_length = framer_.EncryptPayload( |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9353 | ENCRYPTION_INITIAL, packet_number, *raw, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9354 | |
| 9355 | ASSERT_NE(0u, encrypted_length); |
| 9356 | EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); |
| 9357 | } |
| 9358 | |
wub | dec17c2 | 2020-06-04 13:13:50 -0700 | [diff] [blame] | 9359 | // Regression test for b/158014497. |
| 9360 | TEST_P(QuicFramerTest, EncryptEmptyPacket) { |
| 9361 | auto packet = std::make_unique<QuicPacket>( |
| 9362 | new char[100], 0, true, PACKET_8BYTE_CONNECTION_ID, |
| 9363 | PACKET_0BYTE_CONNECTION_ID, |
| 9364 | /*includes_version=*/true, |
| 9365 | /*includes_diversification_nonce=*/true, PACKET_1BYTE_PACKET_NUMBER, |
| 9366 | VARIABLE_LENGTH_INTEGER_LENGTH_0, |
| 9367 | /*retry_token_length=*/0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
| 9368 | char buffer[kMaxOutgoingPacketSize]; |
| 9369 | size_t encrypted_length = 1; |
| 9370 | EXPECT_QUIC_BUG(encrypted_length = framer_.EncryptPayload( |
| 9371 | ENCRYPTION_INITIAL, kPacketNumber, *packet, buffer, |
| 9372 | kMaxOutgoingPacketSize), |
| 9373 | "packet is shorter than associated data length"); |
| 9374 | EXPECT_EQ(0u, encrypted_length); |
| 9375 | } |
| 9376 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9377 | TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) { |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9378 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9379 | QuicPacketNumber packet_number = kPacketNumber; |
| 9380 | // clang-format off |
| 9381 | unsigned char packet[] = { |
| 9382 | // public flags (version, 8 byte connection_id) |
| 9383 | 0x29, |
| 9384 | // connection_id |
| 9385 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9386 | // version tag |
| 9387 | 'Q', '.', '1', '0', |
| 9388 | // packet number |
| 9389 | 0x12, 0x34, 0x56, 0x78, |
| 9390 | |
| 9391 | // redundancy |
| 9392 | 'a', 'b', 'c', 'd', |
| 9393 | 'e', 'f', 'g', 'h', |
| 9394 | 'i', 'j', 'k', 'l', |
| 9395 | 'm', 'n', 'o', 'p', |
| 9396 | }; |
| 9397 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9398 | unsigned char packet46[] = { |
| 9399 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 9400 | 0xD3, |
| 9401 | // version tag |
| 9402 | 'Q', '.', '1', '0', |
| 9403 | // connection_id length |
| 9404 | 0x50, |
| 9405 | // connection_id |
| 9406 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9407 | // packet number |
| 9408 | 0x12, 0x34, 0x56, 0x78, |
| 9409 | |
| 9410 | // redundancy |
| 9411 | 'a', 'b', 'c', 'd', |
| 9412 | 'e', 'f', 'g', 'h', |
| 9413 | 'i', 'j', 'k', 'l', |
| 9414 | 'm', 'n', 'o', 'p', |
| 9415 | }; |
| 9416 | |
nharper | c32d8ab | 2019-10-09 11:09:06 -0700 | [diff] [blame] | 9417 | unsigned char packet50[] = { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9418 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 9419 | 0xD3, |
| 9420 | // version tag |
| 9421 | 'Q', '.', '1', '0', |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 9422 | // destination connection ID length |
| 9423 | 0x08, |
| 9424 | // destination connection ID |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9425 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 9426 | // source connection ID length |
| 9427 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9428 | // packet number |
| 9429 | 0x12, 0x34, 0x56, 0x78, |
| 9430 | |
| 9431 | // redundancy |
| 9432 | 'a', 'b', 'c', 'd', |
| 9433 | 'e', 'f', 'g', 'h', |
| 9434 | 'i', 'j', 'k', 'l', |
| 9435 | 'm', 'n', 'o', 'p', |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9436 | 'q', 'r', 's', 't', |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9437 | }; |
| 9438 | // clang-format on |
| 9439 | |
| 9440 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 9441 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9442 | // TODO(ianswett): see todo in previous test. |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 9443 | if (framer_.version().HasHeaderProtection()) { |
nharper | c32d8ab | 2019-10-09 11:09:06 -0700 | [diff] [blame] | 9444 | p = packet50; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 9445 | p_size = ABSL_ARRAYSIZE(packet50); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 9446 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9447 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 9448 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9449 | } |
| 9450 | |
| 9451 | std::unique_ptr<QuicPacket> raw(new QuicPacket( |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 9452 | AsChars(p), p_size, false, PACKET_8BYTE_CONNECTION_ID, |
| 9453 | PACKET_0BYTE_CONNECTION_ID, kIncludeVersion, |
| 9454 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 9455 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0)); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9456 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9457 | size_t encrypted_length = framer_.EncryptPayload( |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9458 | ENCRYPTION_INITIAL, packet_number, *raw, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9459 | |
| 9460 | ASSERT_NE(0u, encrypted_length); |
| 9461 | EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); |
| 9462 | } |
| 9463 | |
| 9464 | TEST_P(QuicFramerTest, AckTruncationLargePacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9465 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9466 | // This test is not applicable to this version; the range count is |
| 9467 | // effectively unlimited |
| 9468 | return; |
| 9469 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 9470 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9471 | |
| 9472 | QuicPacketHeader header; |
| 9473 | header.destination_connection_id = FramerTestConnectionId(); |
| 9474 | header.reset_flag = false; |
| 9475 | header.version_flag = false; |
| 9476 | header.packet_number = kPacketNumber; |
| 9477 | |
| 9478 | QuicAckFrame ack_frame; |
| 9479 | // Create a packet with just the ack. |
| 9480 | ack_frame = MakeAckFrameWithAckBlocks(300, 0u); |
| 9481 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 9482 | |
| 9483 | // Build an ack packet with truncation due to limit in number of nack ranges. |
| 9484 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9485 | std::unique_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); |
| 9486 | ASSERT_TRUE(raw_ack_packet != nullptr); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9487 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9488 | size_t encrypted_length = |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9489 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9490 | *raw_ack_packet, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9491 | ASSERT_NE(0u, encrypted_length); |
| 9492 | // Now make sure we can turn our ack packet back into an ack frame. |
| 9493 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 9494 | ASSERT_TRUE(framer_.ProcessPacket( |
| 9495 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 9496 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 9497 | QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; |
| 9498 | EXPECT_EQ(QuicPacketNumber(600u), LargestAcked(processed_ack_frame)); |
| 9499 | ASSERT_EQ(256u, processed_ack_frame.packets.NumPacketsSlow()); |
| 9500 | EXPECT_EQ(QuicPacketNumber(90u), processed_ack_frame.packets.Min()); |
| 9501 | EXPECT_EQ(QuicPacketNumber(600u), processed_ack_frame.packets.Max()); |
| 9502 | } |
| 9503 | |
fayang | 91c23d7 | 2020-03-09 12:35:05 -0700 | [diff] [blame] | 9504 | // Regression test for b/150386368. |
| 9505 | TEST_P(QuicFramerTest, IetfAckFrameTruncation) { |
| 9506 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 9507 | return; |
| 9508 | } |
| 9509 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 9510 | |
| 9511 | QuicPacketHeader header; |
| 9512 | header.destination_connection_id = FramerTestConnectionId(); |
| 9513 | header.reset_flag = false; |
| 9514 | header.version_flag = false; |
| 9515 | header.packet_number = kPacketNumber; |
| 9516 | |
| 9517 | QuicAckFrame ack_frame; |
| 9518 | // Create a packet with just the ack. |
| 9519 | ack_frame = MakeAckFrameWithGaps(/*gap_size=*/0xffffffff, |
| 9520 | /*max_num_gaps=*/200, |
| 9521 | /*largest_acked=*/kMaxIetfVarInt); |
| 9522 | ack_frame.ecn_counters_populated = true; |
| 9523 | ack_frame.ect_0_count = 100; |
| 9524 | ack_frame.ect_1_count = 10000; |
| 9525 | ack_frame.ecn_ce_count = 1000000; |
| 9526 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 9527 | // Build an ACK packet. |
| 9528 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9529 | std::unique_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); |
| 9530 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9531 | char buffer[kMaxOutgoingPacketSize]; |
| 9532 | size_t encrypted_length = |
| 9533 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, |
| 9534 | *raw_ack_packet, buffer, kMaxOutgoingPacketSize); |
| 9535 | ASSERT_NE(0u, encrypted_length); |
| 9536 | // Now make sure we can turn our ack packet back into an ack frame. |
| 9537 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 9538 | ASSERT_TRUE(framer_.ProcessPacket( |
| 9539 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 9540 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 9541 | QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; |
| 9542 | EXPECT_EQ(QuicPacketNumber(kMaxIetfVarInt), |
| 9543 | LargestAcked(processed_ack_frame)); |
| 9544 | // Verify ACK frame gets truncated. |
| 9545 | ASSERT_LT(processed_ack_frame.packets.NumPacketsSlow(), |
| 9546 | ack_frame.packets.NumIntervals()); |
| 9547 | EXPECT_EQ(157u, processed_ack_frame.packets.NumPacketsSlow()); |
| 9548 | EXPECT_LT(processed_ack_frame.packets.NumIntervals(), |
| 9549 | ack_frame.packets.NumIntervals()); |
| 9550 | EXPECT_EQ(QuicPacketNumber(kMaxIetfVarInt), |
| 9551 | processed_ack_frame.packets.Max()); |
| 9552 | } |
| 9553 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9554 | TEST_P(QuicFramerTest, AckTruncationSmallPacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9555 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9556 | // This test is not applicable to this version; the range count is |
| 9557 | // effectively unlimited |
| 9558 | return; |
| 9559 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 9560 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9561 | |
| 9562 | QuicPacketHeader header; |
| 9563 | header.destination_connection_id = FramerTestConnectionId(); |
| 9564 | header.reset_flag = false; |
| 9565 | header.version_flag = false; |
| 9566 | header.packet_number = kPacketNumber; |
| 9567 | |
| 9568 | // Create a packet with just the ack. |
| 9569 | QuicAckFrame ack_frame; |
| 9570 | ack_frame = MakeAckFrameWithAckBlocks(300, 0u); |
| 9571 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 9572 | |
| 9573 | // Build an ack packet with truncation due to limit in number of nack ranges. |
| 9574 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9575 | std::unique_ptr<QuicPacket> raw_ack_packet( |
| 9576 | BuildDataPacket(header, frames, 500)); |
| 9577 | ASSERT_TRUE(raw_ack_packet != nullptr); |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9578 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9579 | size_t encrypted_length = |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9580 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9581 | *raw_ack_packet, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9582 | ASSERT_NE(0u, encrypted_length); |
| 9583 | // Now make sure we can turn our ack packet back into an ack frame. |
| 9584 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 9585 | ASSERT_TRUE(framer_.ProcessPacket( |
| 9586 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 9587 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 9588 | QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; |
| 9589 | EXPECT_EQ(QuicPacketNumber(600u), LargestAcked(processed_ack_frame)); |
| 9590 | ASSERT_EQ(240u, processed_ack_frame.packets.NumPacketsSlow()); |
| 9591 | EXPECT_EQ(QuicPacketNumber(122u), processed_ack_frame.packets.Min()); |
| 9592 | EXPECT_EQ(QuicPacketNumber(600u), processed_ack_frame.packets.Max()); |
| 9593 | } |
| 9594 | |
| 9595 | TEST_P(QuicFramerTest, CleanTruncation) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9596 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9597 | // This test is not applicable to this version; the range count is |
| 9598 | // effectively unlimited |
| 9599 | return; |
| 9600 | } |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 9601 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9602 | |
| 9603 | QuicPacketHeader header; |
| 9604 | header.destination_connection_id = FramerTestConnectionId(); |
| 9605 | header.reset_flag = false; |
| 9606 | header.version_flag = false; |
| 9607 | header.packet_number = kPacketNumber; |
| 9608 | |
| 9609 | QuicAckFrame ack_frame = InitAckFrame(201); |
| 9610 | |
| 9611 | // Create a packet with just the ack. |
| 9612 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
nharper | c32d8ab | 2019-10-09 11:09:06 -0700 | [diff] [blame] | 9613 | if (framer_.version().HasHeaderProtection()) { |
| 9614 | frames.push_back(QuicFrame(QuicPaddingFrame(12))); |
| 9615 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9616 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9617 | std::unique_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); |
| 9618 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9619 | |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9620 | char buffer[kMaxOutgoingPacketSize]; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9621 | size_t encrypted_length = |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9622 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, |
dschinazi | 66dea07 | 2019-04-09 11:41:06 -0700 | [diff] [blame] | 9623 | *raw_ack_packet, buffer, kMaxOutgoingPacketSize); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9624 | ASSERT_NE(0u, encrypted_length); |
| 9625 | |
| 9626 | // Now make sure we can turn our ack packet back into an ack frame. |
| 9627 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 9628 | ASSERT_TRUE(framer_.ProcessPacket( |
| 9629 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 9630 | |
| 9631 | // Test for clean truncation of the ack by comparing the length of the |
| 9632 | // original packets to the re-serialized packets. |
| 9633 | frames.clear(); |
| 9634 | frames.push_back(QuicFrame(visitor_.ack_frames_[0].get())); |
nharper | c32d8ab | 2019-10-09 11:09:06 -0700 | [diff] [blame] | 9635 | if (framer_.version().HasHeaderProtection()) { |
| 9636 | frames.push_back(QuicFrame(*visitor_.padding_frames_[0].get())); |
| 9637 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9638 | |
| 9639 | size_t original_raw_length = raw_ack_packet->length(); |
| 9640 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9641 | raw_ack_packet = BuildDataPacket(header, frames); |
| 9642 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9643 | EXPECT_EQ(original_raw_length, raw_ack_packet->length()); |
| 9644 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9645 | } |
| 9646 | |
| 9647 | TEST_P(QuicFramerTest, StopPacketProcessing) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9648 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9649 | // clang-format off |
| 9650 | unsigned char packet[] = { |
| 9651 | // public flags (8 byte connection_id) |
| 9652 | 0x28, |
| 9653 | // connection_id |
| 9654 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9655 | // packet number |
| 9656 | 0x12, 0x34, 0x56, 0x78, |
| 9657 | |
| 9658 | // frame type (stream frame with fin) |
| 9659 | 0xFF, |
| 9660 | // stream id |
| 9661 | 0x01, 0x02, 0x03, 0x04, |
| 9662 | // offset |
| 9663 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9664 | 0x32, 0x10, 0x76, 0x54, |
| 9665 | // data length |
| 9666 | 0x00, 0x0c, |
| 9667 | // data |
| 9668 | 'h', 'e', 'l', 'l', |
| 9669 | 'o', ' ', 'w', 'o', |
| 9670 | 'r', 'l', 'd', '!', |
| 9671 | |
| 9672 | // frame type (ack frame) |
| 9673 | 0x40, |
| 9674 | // least packet number awaiting an ack |
| 9675 | 0x12, 0x34, 0x56, 0x78, |
| 9676 | 0x9A, 0xA0, |
| 9677 | // largest observed packet number |
| 9678 | 0x12, 0x34, 0x56, 0x78, |
| 9679 | 0x9A, 0xBF, |
| 9680 | // num missing packets |
| 9681 | 0x01, |
| 9682 | // missing packet |
| 9683 | 0x12, 0x34, 0x56, 0x78, |
| 9684 | 0x9A, 0xBE, |
| 9685 | }; |
| 9686 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9687 | unsigned char packet46[] = { |
| 9688 | // type (short header, 4 byte packet number) |
| 9689 | 0x43, |
| 9690 | // connection_id |
| 9691 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9692 | // packet number |
| 9693 | 0x12, 0x34, 0x56, 0x78, |
| 9694 | |
| 9695 | // frame type (stream frame with fin) |
| 9696 | 0xFF, |
| 9697 | // stream id |
| 9698 | 0x01, 0x02, 0x03, 0x04, |
| 9699 | // offset |
| 9700 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9701 | 0x32, 0x10, 0x76, 0x54, |
| 9702 | // data length |
| 9703 | 0x00, 0x0c, |
| 9704 | // data |
| 9705 | 'h', 'e', 'l', 'l', |
| 9706 | 'o', ' ', 'w', 'o', |
| 9707 | 'r', 'l', 'd', '!', |
| 9708 | |
| 9709 | // frame type (ack frame) |
| 9710 | 0x40, |
| 9711 | // least packet number awaiting an ack |
| 9712 | 0x12, 0x34, 0x56, 0x78, |
| 9713 | 0x9A, 0xA0, |
| 9714 | // largest observed packet number |
| 9715 | 0x12, 0x34, 0x56, 0x78, |
| 9716 | 0x9A, 0xBF, |
| 9717 | // num missing packets |
| 9718 | 0x01, |
| 9719 | // missing packet |
| 9720 | 0x12, 0x34, 0x56, 0x78, |
| 9721 | 0x9A, 0xBE, |
| 9722 | }; |
| 9723 | |
| 9724 | unsigned char packet99[] = { |
| 9725 | // type (short header, 4 byte packet number) |
| 9726 | 0x43, |
| 9727 | // connection_id |
| 9728 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9729 | // packet number |
| 9730 | 0x12, 0x34, 0x56, 0x78, |
| 9731 | |
| 9732 | // frame type (IETF_STREAM frame with fin, length, and offset bits set) |
| 9733 | 0x08 | 0x01 | 0x02 | 0x04, |
| 9734 | // stream id |
| 9735 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 9736 | // offset |
| 9737 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 9738 | 0x32, 0x10, 0x76, 0x54, |
| 9739 | // data length |
| 9740 | kVarInt62TwoBytes + 0x00, 0x0c, |
| 9741 | // data |
| 9742 | 'h', 'e', 'l', 'l', |
| 9743 | 'o', ' ', 'w', 'o', |
| 9744 | 'r', 'l', 'd', '!', |
| 9745 | |
| 9746 | // frame type (ack frame) |
| 9747 | 0x0d, |
| 9748 | // largest observed packet number |
| 9749 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78, |
| 9750 | // Delta time |
| 9751 | kVarInt62OneByte + 0x00, |
| 9752 | // Ack Block count |
| 9753 | kVarInt62OneByte + 0x01, |
| 9754 | // First block size (one packet) |
| 9755 | kVarInt62OneByte + 0x00, |
| 9756 | |
| 9757 | // Next gap size & ack. Missing all preceding packets |
| 9758 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x77, |
| 9759 | kVarInt62OneByte + 0x00, |
| 9760 | }; |
| 9761 | // clang-format on |
| 9762 | |
| 9763 | MockFramerVisitor visitor; |
| 9764 | framer_.set_visitor(&visitor); |
| 9765 | EXPECT_CALL(visitor, OnPacket()); |
| 9766 | EXPECT_CALL(visitor, OnPacketHeader(_)); |
| 9767 | EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false)); |
| 9768 | EXPECT_CALL(visitor, OnPacketComplete()); |
| 9769 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); |
| 9770 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)).WillOnce(Return(true)); |
| 9771 | EXPECT_CALL(visitor, OnDecryptedPacket(_)); |
| 9772 | |
| 9773 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 9774 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9775 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9776 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 9777 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 9778 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9779 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 9780 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9781 | } |
| 9782 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 9783 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 9784 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9785 | } |
| 9786 | |
| 9787 | static char kTestString[] = "At least 20 characters."; |
| 9788 | static QuicStreamId kTestQuicStreamId = 1; |
dschinazi | 38cc1ee | 2020-02-28 14:33:58 -0800 | [diff] [blame] | 9789 | |
| 9790 | MATCHER_P(ExpectedStreamFrame, version, "") { |
| 9791 | return (arg.stream_id == kTestQuicStreamId || |
| 9792 | QuicUtils::IsCryptoStreamId(version.transport_version, |
| 9793 | arg.stream_id)) && |
| 9794 | !arg.fin && arg.offset == 0 && |
| 9795 | std::string(arg.data_buffer, arg.data_length) == kTestString; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9796 | // FIN is hard-coded false in ConstructEncryptedPacket. |
| 9797 | // Offset 0 is hard-coded in ConstructEncryptedPacket. |
| 9798 | } |
| 9799 | |
| 9800 | // Verify that the packet returned by ConstructEncryptedPacket() can be properly |
| 9801 | // parsed by the framer. |
| 9802 | TEST_P(QuicFramerTest, ConstructEncryptedPacket) { |
| 9803 | // Since we are using ConstructEncryptedPacket, we have to set the framer's |
| 9804 | // crypto to be Null. |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9805 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 9806 | framer_.InstallDecrypter( |
| 9807 | ENCRYPTION_FORWARD_SECURE, |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 9808 | std::make_unique<NullDecrypter>(framer_.perspective())); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9809 | } else { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 9810 | framer_.SetDecrypter(ENCRYPTION_INITIAL, std::make_unique<NullDecrypter>( |
| 9811 | framer_.perspective())); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9812 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9813 | ParsedQuicVersionVector versions; |
| 9814 | versions.push_back(framer_.version()); |
| 9815 | std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( |
| 9816 | TestConnectionId(), EmptyQuicConnectionId(), false, false, |
| 9817 | kTestQuicStreamId, kTestString, CONNECTION_ID_PRESENT, |
| 9818 | CONNECTION_ID_ABSENT, PACKET_4BYTE_PACKET_NUMBER, &versions)); |
| 9819 | |
| 9820 | MockFramerVisitor visitor; |
| 9821 | framer_.set_visitor(&visitor); |
| 9822 | EXPECT_CALL(visitor, OnPacket()).Times(1); |
| 9823 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)) |
| 9824 | .Times(1) |
| 9825 | .WillOnce(Return(true)); |
| 9826 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)) |
| 9827 | .Times(1) |
| 9828 | .WillOnce(Return(true)); |
| 9829 | EXPECT_CALL(visitor, OnPacketHeader(_)).Times(1).WillOnce(Return(true)); |
| 9830 | EXPECT_CALL(visitor, OnDecryptedPacket(_)).Times(1); |
| 9831 | EXPECT_CALL(visitor, OnError(_)).Times(0); |
| 9832 | EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0); |
QUICHE team | ea74008 | 2019-03-11 17:58:43 -0700 | [diff] [blame] | 9833 | if (!QuicVersionUsesCryptoFrames(framer_.version().transport_version)) { |
dschinazi | 38cc1ee | 2020-02-28 14:33:58 -0800 | [diff] [blame] | 9834 | EXPECT_CALL(visitor, OnStreamFrame(ExpectedStreamFrame(framer_.version()))) |
| 9835 | .Times(1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9836 | } else { |
| 9837 | EXPECT_CALL(visitor, OnCryptoFrame(_)).Times(1); |
| 9838 | } |
| 9839 | EXPECT_CALL(visitor, OnPacketComplete()).Times(1); |
| 9840 | |
| 9841 | EXPECT_TRUE(framer_.ProcessPacket(*packet)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 9842 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9843 | } |
| 9844 | |
| 9845 | // Verify that the packet returned by ConstructMisFramedEncryptedPacket() |
| 9846 | // does cause the framer to return an error. |
| 9847 | TEST_P(QuicFramerTest, ConstructMisFramedEncryptedPacket) { |
| 9848 | // Since we are using ConstructEncryptedPacket, we have to set the framer's |
| 9849 | // crypto to be Null. |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9850 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 9851 | framer_.InstallDecrypter( |
| 9852 | ENCRYPTION_FORWARD_SECURE, |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 9853 | std::make_unique<NullDecrypter>(framer_.perspective())); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9854 | } else { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 9855 | framer_.SetDecrypter(ENCRYPTION_INITIAL, std::make_unique<NullDecrypter>( |
| 9856 | framer_.perspective())); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9857 | } |
QUICHE team | 6987b4a | 2019-03-15 16:23:04 -0700 | [diff] [blame] | 9858 | framer_.SetEncrypter(ENCRYPTION_INITIAL, |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 9859 | std::make_unique<NullEncrypter>(framer_.perspective())); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9860 | std::unique_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket( |
| 9861 | TestConnectionId(), EmptyQuicConnectionId(), false, false, |
| 9862 | kTestQuicStreamId, kTestString, CONNECTION_ID_PRESENT, |
bnc | 9711a9e | 2019-11-01 06:31:51 -0700 | [diff] [blame] | 9863 | CONNECTION_ID_ABSENT, PACKET_4BYTE_PACKET_NUMBER, framer_.version(), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9864 | Perspective::IS_CLIENT)); |
| 9865 | |
| 9866 | MockFramerVisitor visitor; |
| 9867 | framer_.set_visitor(&visitor); |
| 9868 | EXPECT_CALL(visitor, OnPacket()).Times(1); |
| 9869 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)) |
| 9870 | .Times(1) |
| 9871 | .WillOnce(Return(true)); |
| 9872 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)) |
| 9873 | .Times(1) |
| 9874 | .WillOnce(Return(true)); |
| 9875 | EXPECT_CALL(visitor, OnPacketHeader(_)).Times(1); |
| 9876 | EXPECT_CALL(visitor, OnDecryptedPacket(_)).Times(1); |
| 9877 | EXPECT_CALL(visitor, OnError(_)).Times(1); |
| 9878 | EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0); |
| 9879 | EXPECT_CALL(visitor, OnPacketComplete()).Times(0); |
| 9880 | |
| 9881 | EXPECT_FALSE(framer_.ProcessPacket(*packet)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 9882 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_FRAME_DATA)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9883 | } |
| 9884 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9885 | TEST_P(QuicFramerTest, IetfBlockedFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 9886 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9887 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9888 | return; |
| 9889 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9890 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9891 | |
| 9892 | // clang-format off |
| 9893 | PacketFragments packet99 = { |
| 9894 | // type (short header, 4 byte packet number) |
| 9895 | {"", |
| 9896 | {0x43}}, |
| 9897 | // connection_id |
| 9898 | {"", |
| 9899 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 9900 | // packet number |
| 9901 | {"", |
| 9902 | {0x12, 0x34, 0x9A, 0xBC}}, |
ianswett | 2f07744 | 2019-12-12 11:51:24 -0800 | [diff] [blame] | 9903 | // frame type (IETF_DATA_BLOCKED) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9904 | {"", |
| 9905 | {0x14}}, |
| 9906 | // blocked offset |
| 9907 | {"Can not read blocked offset.", |
| 9908 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 9909 | }; |
| 9910 | // clang-format on |
| 9911 | |
| 9912 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9913 | AssemblePacketFromFragments(packet99)); |
| 9914 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9915 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 9916 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9917 | ASSERT_TRUE(visitor_.header_.get()); |
| 9918 | EXPECT_TRUE(CheckDecryption( |
| 9919 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9920 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9921 | |
| 9922 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 9923 | |
| 9924 | CheckFramingBoundaries(packet99, QUIC_INVALID_BLOCKED_DATA); |
| 9925 | } |
| 9926 | |
| 9927 | TEST_P(QuicFramerTest, BuildIetfBlockedPacket) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 9928 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9929 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9930 | return; |
| 9931 | } |
| 9932 | |
| 9933 | QuicPacketHeader header; |
| 9934 | header.destination_connection_id = FramerTestConnectionId(); |
| 9935 | header.reset_flag = false; |
| 9936 | header.version_flag = false; |
| 9937 | header.packet_number = kPacketNumber; |
| 9938 | |
| 9939 | QuicBlockedFrame frame; |
| 9940 | frame.stream_id = QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
| 9941 | frame.offset = kStreamOffset; |
| 9942 | QuicFrames frames = {QuicFrame(&frame)}; |
| 9943 | |
| 9944 | // clang-format off |
| 9945 | unsigned char packet99[] = { |
| 9946 | // type (short header, 4 byte packet number) |
| 9947 | 0x43, |
| 9948 | // connection_id |
| 9949 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9950 | // packet number |
| 9951 | 0x12, 0x34, 0x56, 0x78, |
| 9952 | |
ianswett | 2f07744 | 2019-12-12 11:51:24 -0800 | [diff] [blame] | 9953 | // frame type (IETF_DATA_BLOCKED) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9954 | 0x14, |
| 9955 | // Offset |
| 9956 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 9957 | }; |
| 9958 | // clang-format on |
| 9959 | |
| 9960 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 9961 | ASSERT_TRUE(data != nullptr); |
| 9962 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 9963 | quiche::test::CompareCharArraysWithHexError( |
| 9964 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 9965 | ABSL_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9966 | } |
| 9967 | |
| 9968 | TEST_P(QuicFramerTest, IetfStreamBlockedFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 9969 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 9970 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9971 | return; |
| 9972 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 9973 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9974 | |
| 9975 | // clang-format off |
| 9976 | PacketFragments packet99 = { |
| 9977 | // type (short header, 4 byte packet number) |
| 9978 | {"", |
| 9979 | {0x43}}, |
| 9980 | // connection_id |
| 9981 | {"", |
| 9982 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 9983 | // packet number |
| 9984 | {"", |
| 9985 | {0x12, 0x34, 0x9A, 0xBC}}, |
ianswett | 2f07744 | 2019-12-12 11:51:24 -0800 | [diff] [blame] | 9986 | // frame type (IETF_STREAM_DATA_BLOCKED) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9987 | {"", |
| 9988 | {0x15}}, |
| 9989 | // blocked offset |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 9990 | {"Unable to read IETF_STREAM_DATA_BLOCKED frame stream id/count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9991 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 9992 | {"Can not read stream blocked offset.", |
| 9993 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 9994 | }; |
| 9995 | // clang-format on |
| 9996 | |
| 9997 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9998 | AssemblePacketFromFragments(packet99)); |
| 9999 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10000 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10001 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10002 | ASSERT_TRUE(visitor_.header_.get()); |
| 10003 | EXPECT_TRUE(CheckDecryption( |
| 10004 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10005 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10006 | |
| 10007 | EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id); |
| 10008 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 10009 | |
| 10010 | CheckFramingBoundaries(packet99, QUIC_INVALID_STREAM_BLOCKED_DATA); |
| 10011 | } |
| 10012 | |
| 10013 | TEST_P(QuicFramerTest, BuildIetfStreamBlockedPacket) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10014 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10015 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10016 | return; |
| 10017 | } |
| 10018 | |
| 10019 | QuicPacketHeader header; |
| 10020 | header.destination_connection_id = FramerTestConnectionId(); |
| 10021 | header.reset_flag = false; |
| 10022 | header.version_flag = false; |
| 10023 | header.packet_number = kPacketNumber; |
| 10024 | |
| 10025 | QuicBlockedFrame frame; |
| 10026 | frame.stream_id = kStreamId; |
| 10027 | frame.offset = kStreamOffset; |
| 10028 | QuicFrames frames = {QuicFrame(&frame)}; |
| 10029 | |
| 10030 | // clang-format off |
| 10031 | unsigned char packet99[] = { |
| 10032 | // type (short header, 4 byte packet number) |
| 10033 | 0x43, |
| 10034 | // connection_id |
| 10035 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10036 | // packet number |
| 10037 | 0x12, 0x34, 0x56, 0x78, |
| 10038 | |
ianswett | 2f07744 | 2019-12-12 11:51:24 -0800 | [diff] [blame] | 10039 | // frame type (IETF_STREAM_DATA_BLOCKED) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10040 | 0x15, |
| 10041 | // Stream ID |
| 10042 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 10043 | // Offset |
| 10044 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 10045 | }; |
| 10046 | // clang-format on |
| 10047 | |
| 10048 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10049 | ASSERT_TRUE(data != nullptr); |
| 10050 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 10051 | quiche::test::CompareCharArraysWithHexError( |
| 10052 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 10053 | ABSL_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10054 | } |
| 10055 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10056 | TEST_P(QuicFramerTest, BiDiMaxStreamsFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10057 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10058 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10059 | return; |
| 10060 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10061 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10062 | |
| 10063 | // clang-format off |
| 10064 | PacketFragments packet99 = { |
| 10065 | // type (short header, 4 byte packet number) |
| 10066 | {"", |
| 10067 | {0x43}}, |
| 10068 | // connection_id |
| 10069 | {"", |
| 10070 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10071 | // packet number |
| 10072 | {"", |
| 10073 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10074 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 10075 | {"", |
| 10076 | {0x12}}, |
| 10077 | // max. streams |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 10078 | {"Unable to read IETF_MAX_STREAMS_BIDIRECTIONAL frame stream id/count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10079 | {kVarInt62OneByte + 0x03}}, |
| 10080 | }; |
| 10081 | // clang-format on |
| 10082 | |
| 10083 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10084 | AssemblePacketFromFragments(packet99)); |
| 10085 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10086 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10087 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10088 | ASSERT_TRUE(visitor_.header_.get()); |
| 10089 | EXPECT_TRUE(CheckDecryption( |
| 10090 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10091 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10092 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10093 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 10094 | EXPECT_FALSE(visitor_.max_streams_frame_.unidirectional); |
| 10095 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10096 | } |
| 10097 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10098 | TEST_P(QuicFramerTest, UniDiMaxStreamsFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10099 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10100 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10101 | return; |
| 10102 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10103 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10104 | |
| 10105 | // clang-format off |
| 10106 | PacketFragments packet99 = { |
| 10107 | // type (short header, 4 byte packet number) |
| 10108 | {"", |
| 10109 | {0x43}}, |
| 10110 | // Test runs in client mode, no connection id |
| 10111 | // packet number |
| 10112 | {"", |
| 10113 | {0x12, 0x34, 0x9A, 0xBC}}, |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10114 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10115 | {"", |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10116 | {0x13}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10117 | // max. streams |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 10118 | {"Unable to read IETF_MAX_STREAMS_UNIDIRECTIONAL frame stream id/count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10119 | {kVarInt62OneByte + 0x03}}, |
| 10120 | }; |
| 10121 | // clang-format on |
| 10122 | |
| 10123 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10124 | AssemblePacketFromFragments(packet99)); |
| 10125 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10126 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10127 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10128 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10129 | ASSERT_TRUE(visitor_.header_.get()); |
| 10130 | EXPECT_TRUE(CheckDecryption( |
| 10131 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10132 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10133 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10134 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 10135 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 10136 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10137 | } |
| 10138 | |
| 10139 | TEST_P(QuicFramerTest, ServerUniDiMaxStreamsFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10140 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10141 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10142 | return; |
| 10143 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10144 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10145 | |
| 10146 | // clang-format off |
| 10147 | PacketFragments packet99 = { |
| 10148 | // type (short header, 4 byte packet number) |
| 10149 | {"", |
| 10150 | {0x43}}, |
| 10151 | // connection_id |
| 10152 | {"", |
| 10153 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10154 | // packet number |
| 10155 | {"", |
| 10156 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10157 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 10158 | {"", |
| 10159 | {0x13}}, |
| 10160 | // max. streams |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 10161 | {"Unable to read IETF_MAX_STREAMS_UNIDIRECTIONAL frame stream id/count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10162 | {kVarInt62OneByte + 0x03}}, |
| 10163 | }; |
| 10164 | // clang-format on |
| 10165 | |
| 10166 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10167 | AssemblePacketFromFragments(packet99)); |
| 10168 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10169 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10170 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10171 | ASSERT_TRUE(visitor_.header_.get()); |
| 10172 | EXPECT_TRUE(CheckDecryption( |
| 10173 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10174 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10175 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10176 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 10177 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 10178 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10179 | } |
| 10180 | |
| 10181 | TEST_P(QuicFramerTest, ClientUniDiMaxStreamsFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10182 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10183 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10184 | return; |
| 10185 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10186 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10187 | |
| 10188 | // clang-format off |
| 10189 | PacketFragments packet99 = { |
| 10190 | // type (short header, 4 byte packet number) |
| 10191 | {"", |
| 10192 | {0x43}}, |
| 10193 | // Test runs in client mode, no connection id |
| 10194 | // packet number |
| 10195 | {"", |
| 10196 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10197 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 10198 | {"", |
| 10199 | {0x13}}, |
| 10200 | // max. streams |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 10201 | {"Unable to read IETF_MAX_STREAMS_UNIDIRECTIONAL frame stream id/count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10202 | {kVarInt62OneByte + 0x03}}, |
| 10203 | }; |
| 10204 | // clang-format on |
| 10205 | |
| 10206 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10207 | AssemblePacketFromFragments(packet99)); |
| 10208 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10209 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10210 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10211 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10212 | ASSERT_TRUE(visitor_.header_.get()); |
| 10213 | EXPECT_TRUE(CheckDecryption( |
| 10214 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10215 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10216 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10217 | EXPECT_EQ(3u, visitor_.max_streams_frame_.stream_count); |
| 10218 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 10219 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10220 | } |
| 10221 | |
| 10222 | // The following four tests ensure that the framer can deserialize a stream |
| 10223 | // count that is large enough to cause the resulting stream ID to exceed the |
| 10224 | // current implementation limit(32 bits). The intent is that when this happens, |
| 10225 | // the stream limit is pegged to the maximum supported value. There are four |
| 10226 | // tests, for the four combinations of uni- and bi-directional, server- and |
| 10227 | // client- initiated. |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10228 | TEST_P(QuicFramerTest, BiDiMaxStreamsFrameTooBig) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10229 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10230 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10231 | return; |
| 10232 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10233 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10234 | |
| 10235 | // clang-format off |
| 10236 | unsigned char packet99[] = { |
| 10237 | // type (short header, 4 byte packet number) |
| 10238 | 0x43, |
| 10239 | // connection_id |
| 10240 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10241 | // packet number |
| 10242 | 0x12, 0x34, 0x9A, 0xBC, |
| 10243 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 10244 | 0x12, |
| 10245 | |
| 10246 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10247 | // This encodes a count of 0x40000000, leading to stream |
| 10248 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10249 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 10250 | }; |
| 10251 | // clang-format on |
| 10252 | |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 10253 | QuicEncryptedPacket encrypted(AsChars(packet99), ABSL_ARRAYSIZE(packet99), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10254 | false); |
| 10255 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10256 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10257 | ASSERT_TRUE(visitor_.header_.get()); |
| 10258 | EXPECT_TRUE(CheckDecryption( |
| 10259 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10260 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10261 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 10262 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10263 | EXPECT_FALSE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10264 | } |
| 10265 | |
| 10266 | TEST_P(QuicFramerTest, ClientBiDiMaxStreamsFrameTooBig) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10267 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10268 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10269 | return; |
| 10270 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10271 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10272 | |
| 10273 | // clang-format off |
| 10274 | unsigned char packet99[] = { |
| 10275 | // type (short header, 4 byte packet number) |
| 10276 | 0x43, |
| 10277 | // Test runs in client mode, no connection id |
| 10278 | // packet number |
| 10279 | 0x12, 0x34, 0x9A, 0xBC, |
| 10280 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 10281 | 0x12, |
| 10282 | |
| 10283 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10284 | // This encodes a count of 0x40000000, leading to stream |
| 10285 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10286 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 10287 | }; |
| 10288 | // clang-format on |
| 10289 | |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 10290 | QuicEncryptedPacket encrypted(AsChars(packet99), ABSL_ARRAYSIZE(packet99), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10291 | false); |
| 10292 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10293 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 10294 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10295 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10296 | ASSERT_TRUE(visitor_.header_.get()); |
| 10297 | EXPECT_TRUE(CheckDecryption( |
| 10298 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10299 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10300 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 10301 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10302 | EXPECT_FALSE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10303 | } |
| 10304 | |
| 10305 | TEST_P(QuicFramerTest, ServerUniDiMaxStreamsFrameTooBig) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10306 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10307 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10308 | return; |
| 10309 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10310 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10311 | |
| 10312 | // clang-format off |
| 10313 | unsigned char packet99[] = { |
| 10314 | // type (short header, 4 byte packet number) |
| 10315 | 0x43, |
| 10316 | // connection_id |
| 10317 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10318 | // packet number |
| 10319 | 0x12, 0x34, 0x9A, 0xBC, |
| 10320 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 10321 | 0x13, |
| 10322 | |
| 10323 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10324 | // This encodes a count of 0x40000000, leading to stream |
| 10325 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10326 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 10327 | }; |
| 10328 | // clang-format on |
| 10329 | |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 10330 | QuicEncryptedPacket encrypted(AsChars(packet99), ABSL_ARRAYSIZE(packet99), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10331 | false); |
| 10332 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 10333 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10334 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10335 | ASSERT_TRUE(visitor_.header_.get()); |
| 10336 | EXPECT_TRUE(CheckDecryption( |
| 10337 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10338 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10339 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 10340 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10341 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10342 | } |
| 10343 | |
| 10344 | TEST_P(QuicFramerTest, ClientUniDiMaxStreamsFrameTooBig) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10345 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10346 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10347 | return; |
| 10348 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10349 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10350 | |
| 10351 | // clang-format off |
| 10352 | unsigned char packet99[] = { |
| 10353 | // type (short header, 4 byte packet number) |
| 10354 | 0x43, |
| 10355 | // Test runs in client mode, no connection id |
| 10356 | // packet number |
| 10357 | 0x12, 0x34, 0x9A, 0xBC, |
| 10358 | // frame type (IETF_MAX_STREAMS_UNDIRECTIONAL) |
| 10359 | 0x13, |
| 10360 | |
| 10361 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10362 | // This encodes a count of 0x40000000, leading to stream |
| 10363 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10364 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 10365 | }; |
| 10366 | // clang-format on |
| 10367 | |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 10368 | QuicEncryptedPacket encrypted(AsChars(packet99), ABSL_ARRAYSIZE(packet99), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10369 | false); |
| 10370 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10371 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 10372 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10373 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10374 | ASSERT_TRUE(visitor_.header_.get()); |
| 10375 | EXPECT_TRUE(CheckDecryption( |
| 10376 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10377 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10378 | |
fkastenholz | 465220f | 2019-04-23 07:56:27 -0700 | [diff] [blame] | 10379 | EXPECT_EQ(0x40000000u, visitor_.max_streams_frame_.stream_count); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10380 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
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 | // Specifically test that count==0 is accepted. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10384 | TEST_P(QuicFramerTest, MaxStreamsFrameZeroCount) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10385 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10386 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10387 | return; |
| 10388 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10389 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10390 | |
| 10391 | // clang-format off |
| 10392 | unsigned char packet99[] = { |
| 10393 | // type (short header, 4 byte packet number) |
| 10394 | 0x43, |
| 10395 | // connection_id |
| 10396 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10397 | // packet number |
| 10398 | 0x12, 0x34, 0x9A, 0xBC, |
| 10399 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 10400 | 0x12, |
| 10401 | // max. streams == 0. |
| 10402 | kVarInt62OneByte + 0x00 |
| 10403 | }; |
| 10404 | // clang-format on |
| 10405 | |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 10406 | QuicEncryptedPacket encrypted(AsChars(packet99), ABSL_ARRAYSIZE(packet99), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10407 | false); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10408 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10409 | } |
| 10410 | |
| 10411 | TEST_P(QuicFramerTest, ServerBiDiStreamsBlockedFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10412 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10413 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10414 | return; |
| 10415 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10416 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10417 | |
| 10418 | // clang-format off |
| 10419 | PacketFragments packet99 = { |
| 10420 | // type (short header, 4 byte packet number) |
| 10421 | {"", |
| 10422 | {0x43}}, |
| 10423 | // connection_id |
| 10424 | {"", |
| 10425 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10426 | // packet number |
| 10427 | {"", |
| 10428 | {0x12, 0x34, 0x9A, 0xBC}}, |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10429 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL frame) |
| 10430 | {"", |
| 10431 | {0x13}}, |
| 10432 | // stream count |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 10433 | {"Unable to read IETF_MAX_STREAMS_UNIDIRECTIONAL frame stream id/count.", |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10434 | {kVarInt62OneByte + 0x00}}, |
| 10435 | }; |
| 10436 | // clang-format on |
| 10437 | |
| 10438 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10439 | AssemblePacketFromFragments(packet99)); |
| 10440 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10441 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10442 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10443 | ASSERT_TRUE(visitor_.header_.get()); |
| 10444 | EXPECT_TRUE(CheckDecryption( |
| 10445 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10446 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10447 | |
| 10448 | EXPECT_EQ(0u, visitor_.max_streams_frame_.stream_count); |
| 10449 | EXPECT_TRUE(visitor_.max_streams_frame_.unidirectional); |
| 10450 | |
| 10451 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAMS_DATA); |
| 10452 | } |
| 10453 | |
| 10454 | TEST_P(QuicFramerTest, BiDiStreamsBlockedFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10455 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10456 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10457 | return; |
| 10458 | } |
| 10459 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 10460 | |
| 10461 | // clang-format off |
| 10462 | PacketFragments packet99 = { |
| 10463 | // type (short header, 4 byte packet number) |
| 10464 | {"", |
| 10465 | {0x43}}, |
| 10466 | // connection_id |
| 10467 | {"", |
| 10468 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10469 | // packet number |
| 10470 | {"", |
| 10471 | {0x12, 0x34, 0x9A, 0xBC}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10472 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL frame) |
| 10473 | {"", |
| 10474 | {0x16}}, |
| 10475 | // stream id |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 10476 | {"Unable to read IETF_STREAMS_BLOCKED_BIDIRECTIONAL " |
| 10477 | "frame stream id/count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10478 | {kVarInt62OneByte + 0x03}}, |
| 10479 | }; |
| 10480 | // clang-format on |
| 10481 | |
| 10482 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10483 | AssemblePacketFromFragments(packet99)); |
| 10484 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10485 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10486 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10487 | ASSERT_TRUE(visitor_.header_.get()); |
| 10488 | EXPECT_TRUE(CheckDecryption( |
| 10489 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10490 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10491 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10492 | EXPECT_EQ(3u, visitor_.streams_blocked_frame_.stream_count); |
| 10493 | EXPECT_FALSE(visitor_.streams_blocked_frame_.unidirectional); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10494 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10495 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10496 | } |
| 10497 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10498 | TEST_P(QuicFramerTest, UniDiStreamsBlockedFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10499 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10500 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10501 | return; |
| 10502 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10503 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10504 | |
| 10505 | // clang-format off |
| 10506 | PacketFragments packet99 = { |
| 10507 | // type (short header, 4 byte packet number) |
| 10508 | {"", |
| 10509 | {0x43}}, |
| 10510 | // connection_id |
| 10511 | {"", |
| 10512 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10513 | // packet number |
| 10514 | {"", |
| 10515 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10516 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10517 | {"", |
| 10518 | {0x17}}, |
| 10519 | // stream id |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 10520 | {"Unable to read IETF_STREAMS_BLOCKED_UNIDIRECTIONAL " |
| 10521 | "frame stream id/count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10522 | {kVarInt62OneByte + 0x03}}, |
| 10523 | }; |
| 10524 | // clang-format on |
| 10525 | |
| 10526 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10527 | AssemblePacketFromFragments(packet99)); |
| 10528 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10529 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10530 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10531 | ASSERT_TRUE(visitor_.header_.get()); |
| 10532 | EXPECT_TRUE(CheckDecryption( |
| 10533 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10534 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10535 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10536 | EXPECT_EQ(3u, visitor_.streams_blocked_frame_.stream_count); |
| 10537 | EXPECT_TRUE(visitor_.streams_blocked_frame_.unidirectional); |
| 10538 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10539 | } |
| 10540 | |
| 10541 | TEST_P(QuicFramerTest, ClientUniDiStreamsBlockedFrame) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10542 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10543 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10544 | return; |
| 10545 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10546 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10547 | |
| 10548 | // clang-format off |
| 10549 | PacketFragments packet99 = { |
| 10550 | // type (short header, 4 byte packet number) |
| 10551 | {"", |
| 10552 | {0x43}}, |
| 10553 | // Test runs in client mode, no connection id |
| 10554 | // packet number |
| 10555 | {"", |
| 10556 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10557 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10558 | {"", |
| 10559 | {0x17}}, |
| 10560 | // stream id |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 10561 | {"Unable to read IETF_STREAMS_BLOCKED_UNIDIRECTIONAL " |
| 10562 | "frame stream id/count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10563 | {kVarInt62OneByte + 0x03}}, |
| 10564 | }; |
| 10565 | // clang-format on |
| 10566 | |
| 10567 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10568 | AssemblePacketFromFragments(packet99)); |
| 10569 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10570 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10571 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10572 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10573 | ASSERT_TRUE(visitor_.header_.get()); |
| 10574 | EXPECT_TRUE(CheckDecryption( |
| 10575 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10576 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10577 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10578 | EXPECT_EQ(3u, visitor_.streams_blocked_frame_.stream_count); |
| 10579 | EXPECT_TRUE(visitor_.streams_blocked_frame_.unidirectional); |
| 10580 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10581 | } |
| 10582 | |
| 10583 | // Check that when we get a STREAMS_BLOCKED frame that specifies too large |
| 10584 | // a stream count, we reject with an appropriate error. There is no need to |
| 10585 | // check for different combinations of Uni/Bi directional and client/server |
| 10586 | // initiated; the logic does not take these into account. |
| 10587 | TEST_P(QuicFramerTest, StreamsBlockedFrameTooBig) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10588 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10589 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10590 | return; |
| 10591 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10592 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10593 | |
| 10594 | // clang-format off |
| 10595 | unsigned char packet99[] = { |
| 10596 | // type (short header, 4 byte packet number) |
| 10597 | 0x43, |
| 10598 | // Test runs in client mode, no connection id |
| 10599 | // packet number |
| 10600 | 0x12, 0x34, 0x9A, 0xBC, |
| 10601 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL) |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10602 | 0x16, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10603 | |
| 10604 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10605 | // This encodes a count of 0x40000000, leading to stream |
| 10606 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10607 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01 |
| 10608 | }; |
| 10609 | // clang-format on |
| 10610 | |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 10611 | QuicEncryptedPacket encrypted(AsChars(packet99), ABSL_ARRAYSIZE(packet99), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10612 | false); |
| 10613 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10614 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 10615 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10616 | EXPECT_THAT(framer_.error(), IsError(QUIC_STREAMS_BLOCKED_DATA)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10617 | EXPECT_EQ(framer_.detailed_error(), |
| 10618 | "STREAMS_BLOCKED stream count exceeds implementation limit."); |
| 10619 | } |
| 10620 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10621 | // Specifically test that count==0 is accepted. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10622 | TEST_P(QuicFramerTest, StreamsBlockedFrameZeroCount) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10623 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10624 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10625 | return; |
| 10626 | } |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10627 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10628 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10629 | |
| 10630 | // clang-format off |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10631 | PacketFragments packet99 = { |
| 10632 | // type (short header, 4 byte packet number) |
| 10633 | {"", |
| 10634 | {0x43}}, |
| 10635 | // connection_id |
| 10636 | {"", |
| 10637 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10638 | // packet number |
| 10639 | {"", |
| 10640 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10641 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10642 | {"", |
| 10643 | {0x17}}, |
| 10644 | // stream id |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 10645 | {"Unable to read IETF_STREAMS_BLOCKED_UNIDIRECTIONAL " |
| 10646 | "frame stream id/count.", |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10647 | {kVarInt62OneByte + 0x00}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10648 | }; |
| 10649 | // clang-format on |
| 10650 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10651 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10652 | AssemblePacketFromFragments(packet99)); |
| 10653 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10654 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10655 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10656 | ASSERT_TRUE(visitor_.header_.get()); |
| 10657 | EXPECT_TRUE(CheckDecryption( |
| 10658 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10659 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10660 | |
| 10661 | EXPECT_EQ(0u, visitor_.streams_blocked_frame_.stream_count); |
| 10662 | EXPECT_TRUE(visitor_.streams_blocked_frame_.unidirectional); |
| 10663 | |
| 10664 | CheckFramingBoundaries(packet99, QUIC_STREAMS_BLOCKED_DATA); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10665 | } |
| 10666 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10667 | TEST_P(QuicFramerTest, BuildBiDiStreamsBlockedPacket) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10668 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10669 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10670 | return; |
| 10671 | } |
| 10672 | |
| 10673 | QuicPacketHeader header; |
| 10674 | header.destination_connection_id = FramerTestConnectionId(); |
| 10675 | header.reset_flag = false; |
| 10676 | header.version_flag = false; |
| 10677 | header.packet_number = kPacketNumber; |
| 10678 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10679 | QuicStreamsBlockedFrame frame; |
| 10680 | frame.stream_count = 3; |
| 10681 | frame.unidirectional = false; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10682 | |
| 10683 | QuicFrames frames = {QuicFrame(frame)}; |
| 10684 | |
| 10685 | // clang-format off |
| 10686 | unsigned char packet99[] = { |
| 10687 | // type (short header, 4 byte packet number) |
| 10688 | 0x43, |
| 10689 | // connection_id |
| 10690 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10691 | // packet number |
| 10692 | 0x12, 0x34, 0x56, 0x78, |
| 10693 | |
| 10694 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL frame) |
| 10695 | 0x16, |
| 10696 | // Stream count |
| 10697 | kVarInt62OneByte + 0x03 |
| 10698 | }; |
| 10699 | // clang-format on |
| 10700 | |
| 10701 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10702 | ASSERT_TRUE(data != nullptr); |
| 10703 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 10704 | quiche::test::CompareCharArraysWithHexError( |
| 10705 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 10706 | ABSL_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10707 | } |
| 10708 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10709 | TEST_P(QuicFramerTest, BuildUniStreamsBlockedPacket) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10710 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10711 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10712 | return; |
| 10713 | } |
| 10714 | |
| 10715 | QuicPacketHeader header; |
| 10716 | header.destination_connection_id = FramerTestConnectionId(); |
| 10717 | header.reset_flag = false; |
| 10718 | header.version_flag = false; |
| 10719 | header.packet_number = kPacketNumber; |
| 10720 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10721 | QuicStreamsBlockedFrame frame; |
| 10722 | frame.stream_count = 3; |
| 10723 | frame.unidirectional = true; |
| 10724 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10725 | QuicFrames frames = {QuicFrame(frame)}; |
| 10726 | |
| 10727 | // clang-format off |
| 10728 | unsigned char packet99[] = { |
| 10729 | // type (short header, 4 byte packet number) |
| 10730 | 0x43, |
| 10731 | // connection_id |
| 10732 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10733 | // packet number |
| 10734 | 0x12, 0x34, 0x56, 0x78, |
| 10735 | |
| 10736 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10737 | 0x17, |
| 10738 | // Stream count |
| 10739 | kVarInt62OneByte + 0x03 |
| 10740 | }; |
| 10741 | // clang-format on |
| 10742 | |
| 10743 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10744 | ASSERT_TRUE(data != nullptr); |
| 10745 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 10746 | quiche::test::CompareCharArraysWithHexError( |
| 10747 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 10748 | ABSL_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10749 | } |
| 10750 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10751 | TEST_P(QuicFramerTest, BuildBiDiMaxStreamsPacket) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10752 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10753 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10754 | return; |
| 10755 | } |
| 10756 | |
| 10757 | QuicPacketHeader header; |
| 10758 | header.destination_connection_id = FramerTestConnectionId(); |
| 10759 | header.reset_flag = false; |
| 10760 | header.version_flag = false; |
| 10761 | header.packet_number = kPacketNumber; |
| 10762 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10763 | QuicMaxStreamsFrame frame; |
| 10764 | frame.stream_count = 3; |
| 10765 | frame.unidirectional = false; |
| 10766 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10767 | QuicFrames frames = {QuicFrame(frame)}; |
| 10768 | |
| 10769 | // clang-format off |
| 10770 | unsigned char packet99[] = { |
| 10771 | // type (short header, 4 byte packet number) |
| 10772 | 0x43, |
| 10773 | // connection_id |
| 10774 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10775 | // packet number |
| 10776 | 0x12, 0x34, 0x56, 0x78, |
| 10777 | |
| 10778 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL frame) |
| 10779 | 0x12, |
| 10780 | // Stream count |
| 10781 | kVarInt62OneByte + 0x03 |
| 10782 | }; |
| 10783 | // clang-format on |
| 10784 | |
| 10785 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10786 | ASSERT_TRUE(data != nullptr); |
| 10787 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 10788 | quiche::test::CompareCharArraysWithHexError( |
| 10789 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 10790 | ABSL_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10791 | } |
| 10792 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10793 | TEST_P(QuicFramerTest, BuildUniDiMaxStreamsPacket) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10794 | // This frame is only for IETF QUIC. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10795 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10796 | return; |
| 10797 | } |
| 10798 | |
| 10799 | // This test runs in client mode. |
| 10800 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10801 | |
| 10802 | QuicPacketHeader header; |
| 10803 | header.destination_connection_id = FramerTestConnectionId(); |
| 10804 | header.reset_flag = false; |
| 10805 | header.version_flag = false; |
| 10806 | header.packet_number = kPacketNumber; |
| 10807 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 10808 | QuicMaxStreamsFrame frame; |
| 10809 | frame.stream_count = 3; |
| 10810 | frame.unidirectional = true; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10811 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10812 | QuicFrames frames = {QuicFrame(frame)}; |
| 10813 | |
| 10814 | // clang-format off |
| 10815 | unsigned char packet99[] = { |
| 10816 | // type (short header, 4 byte packet number) |
| 10817 | 0x43, |
| 10818 | // connection_id |
| 10819 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10820 | // packet number |
| 10821 | 0x12, 0x34, 0x56, 0x78, |
| 10822 | |
| 10823 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL frame) |
| 10824 | 0x13, |
| 10825 | // Stream count |
| 10826 | kVarInt62OneByte + 0x03 |
| 10827 | }; |
| 10828 | // clang-format on |
| 10829 | |
| 10830 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10831 | ASSERT_TRUE(data != nullptr); |
| 10832 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 10833 | quiche::test::CompareCharArraysWithHexError( |
| 10834 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 10835 | ABSL_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10836 | } |
| 10837 | |
| 10838 | TEST_P(QuicFramerTest, NewConnectionIdFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10839 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10840 | // This frame is only for IETF QUIC. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10841 | return; |
| 10842 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10843 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10844 | // clang-format off |
| 10845 | PacketFragments packet99 = { |
| 10846 | // type (short header, 4 byte packet number) |
| 10847 | {"", |
| 10848 | {0x43}}, |
| 10849 | // connection_id |
| 10850 | {"", |
| 10851 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10852 | // packet number |
| 10853 | {"", |
| 10854 | {0x12, 0x34, 0x56, 0x78}}, |
| 10855 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 10856 | {"", |
| 10857 | {0x18}}, |
| 10858 | // error code |
| 10859 | {"Unable to read new connection ID frame sequence number.", |
| 10860 | {kVarInt62OneByte + 0x11}}, |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 10861 | {"Unable to read new connection ID frame retire_prior_to.", |
| 10862 | {kVarInt62OneByte + 0x09}}, |
dschinazi | cf5b1e2 | 2019-07-17 18:35:17 -0700 | [diff] [blame] | 10863 | {"Unable to read new connection ID frame connection id.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10864 | {0x08}}, // connection ID length |
| 10865 | {"Unable to read new connection ID frame connection id.", |
| 10866 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11}}, |
| 10867 | {"Can not read new connection ID frame reset token.", |
| 10868 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 10869 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 10870 | }; |
| 10871 | // clang-format on |
| 10872 | |
| 10873 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10874 | AssemblePacketFromFragments(packet99)); |
| 10875 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10876 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10877 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10878 | ASSERT_TRUE(visitor_.header_.get()); |
| 10879 | EXPECT_TRUE(CheckDecryption( |
| 10880 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10881 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10882 | |
| 10883 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 10884 | |
| 10885 | EXPECT_EQ(FramerTestConnectionIdPlusOne(), |
| 10886 | visitor_.new_connection_id_.connection_id); |
| 10887 | EXPECT_EQ(0x11u, visitor_.new_connection_id_.sequence_number); |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 10888 | EXPECT_EQ(0x09u, visitor_.new_connection_id_.retire_prior_to); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10889 | EXPECT_EQ(kTestStatelessResetToken, |
| 10890 | visitor_.new_connection_id_.stateless_reset_token); |
| 10891 | |
| 10892 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 10893 | |
| 10894 | CheckFramingBoundaries(packet99, QUIC_INVALID_NEW_CONNECTION_ID_DATA); |
| 10895 | } |
| 10896 | |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 10897 | TEST_P(QuicFramerTest, NewConnectionIdFrameVariableLength) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10898 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10899 | // This frame is only for IETF QUIC. |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 10900 | return; |
| 10901 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10902 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 10903 | // clang-format off |
| 10904 | PacketFragments packet99 = { |
| 10905 | // type (short header, 4 byte packet number) |
| 10906 | {"", |
| 10907 | {0x43}}, |
| 10908 | // connection_id |
| 10909 | {"", |
| 10910 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10911 | // packet number |
| 10912 | {"", |
| 10913 | {0x12, 0x34, 0x56, 0x78}}, |
| 10914 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 10915 | {"", |
| 10916 | {0x18}}, |
| 10917 | // error code |
| 10918 | {"Unable to read new connection ID frame sequence number.", |
| 10919 | {kVarInt62OneByte + 0x11}}, |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 10920 | {"Unable to read new connection ID frame retire_prior_to.", |
| 10921 | {kVarInt62OneByte + 0x0a}}, |
dschinazi | cf5b1e2 | 2019-07-17 18:35:17 -0700 | [diff] [blame] | 10922 | {"Unable to read new connection ID frame connection id.", |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 10923 | {0x09}}, // connection ID length |
| 10924 | {"Unable to read new connection ID frame connection id.", |
| 10925 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42}}, |
| 10926 | {"Can not read new connection ID frame reset token.", |
| 10927 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 10928 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 10929 | }; |
| 10930 | // clang-format on |
| 10931 | |
| 10932 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10933 | AssemblePacketFromFragments(packet99)); |
| 10934 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10935 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 10936 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 10937 | ASSERT_TRUE(visitor_.header_.get()); |
| 10938 | EXPECT_TRUE(CheckDecryption( |
| 10939 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10940 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10941 | |
| 10942 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 10943 | |
| 10944 | EXPECT_EQ(FramerTestConnectionIdNineBytes(), |
| 10945 | visitor_.new_connection_id_.connection_id); |
| 10946 | EXPECT_EQ(0x11u, visitor_.new_connection_id_.sequence_number); |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 10947 | EXPECT_EQ(0x0au, visitor_.new_connection_id_.retire_prior_to); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame] | 10948 | EXPECT_EQ(kTestStatelessResetToken, |
| 10949 | visitor_.new_connection_id_.stateless_reset_token); |
| 10950 | |
| 10951 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 10952 | |
| 10953 | CheckFramingBoundaries(packet99, QUIC_INVALID_NEW_CONNECTION_ID_DATA); |
| 10954 | } |
| 10955 | |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 10956 | // Verifies that parsing a NEW_CONNECTION_ID frame with a length above the |
| 10957 | // specified maximum fails. |
| 10958 | TEST_P(QuicFramerTest, InvalidLongNewConnectionIdFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 10959 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 10960 | // The NEW_CONNECTION_ID frame is only for IETF QUIC. |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 10961 | return; |
| 10962 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 10963 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 10964 | // clang-format off |
| 10965 | PacketFragments packet99 = { |
| 10966 | // type (short header, 4 byte packet number) |
| 10967 | {"", |
| 10968 | {0x43}}, |
| 10969 | // connection_id |
| 10970 | {"", |
| 10971 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10972 | // packet number |
| 10973 | {"", |
| 10974 | {0x12, 0x34, 0x56, 0x78}}, |
| 10975 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 10976 | {"", |
| 10977 | {0x18}}, |
| 10978 | // error code |
| 10979 | {"Unable to read new connection ID frame sequence number.", |
| 10980 | {kVarInt62OneByte + 0x11}}, |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 10981 | {"Unable to read new connection ID frame retire_prior_to.", |
| 10982 | {kVarInt62OneByte + 0x0b}}, |
dschinazi | cf5b1e2 | 2019-07-17 18:35:17 -0700 | [diff] [blame] | 10983 | {"Unable to read new connection ID frame connection id.", |
dschinazi | b953d02 | 2019-08-01 18:05:58 -0700 | [diff] [blame] | 10984 | {0x40}}, // connection ID length |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 10985 | {"Unable to read new connection ID frame connection id.", |
| 10986 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10987 | 0xF0, 0xD2, 0xB4, 0x96, 0x78, 0x5A, 0x3C, 0x1E, |
dschinazi | b953d02 | 2019-08-01 18:05:58 -0700 | [diff] [blame] | 10988 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10989 | 0xF0, 0xD2, 0xB4, 0x96, 0x78, 0x5A, 0x3C, 0x1E, |
| 10990 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10991 | 0xF0, 0xD2, 0xB4, 0x96, 0x78, 0x5A, 0x3C, 0x1E, |
| 10992 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10993 | 0xF0, 0xD2, 0xB4, 0x96, 0x78, 0x5A, 0x3C, 0x1E}}, |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 10994 | {"Can not read new connection ID frame reset token.", |
| 10995 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 10996 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 10997 | }; |
| 10998 | // clang-format on |
| 10999 | |
| 11000 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11001 | AssemblePacketFromFragments(packet99)); |
| 11002 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 11003 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_NEW_CONNECTION_ID_DATA)); |
dschinazi | 161bb49 | 2020-02-05 09:59:38 -0800 | [diff] [blame] | 11004 | EXPECT_EQ("Invalid new connection ID length for version.", |
| 11005 | framer_.detailed_error()); |
QUICHE team | 0131a5b | 2019-03-20 15:23:27 -0700 | [diff] [blame] | 11006 | } |
| 11007 | |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 11008 | // Verifies that parsing a NEW_CONNECTION_ID frame with an invalid |
| 11009 | // retire-prior-to fails. |
| 11010 | TEST_P(QuicFramerTest, InvalidRetirePriorToNewConnectionIdFrame) { |
| 11011 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11012 | // This frame is only for IETF QUIC only. |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 11013 | return; |
| 11014 | } |
| 11015 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 11016 | // clang-format off |
| 11017 | PacketFragments packet99 = { |
| 11018 | // type (short header, 4 byte packet number) |
| 11019 | {"", |
| 11020 | {0x43}}, |
| 11021 | // connection_id |
| 11022 | {"", |
| 11023 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11024 | // packet number |
| 11025 | {"", |
| 11026 | {0x12, 0x34, 0x56, 0x78}}, |
| 11027 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 11028 | {"", |
| 11029 | {0x18}}, |
| 11030 | // sequence number |
| 11031 | {"Unable to read new connection ID frame sequence number.", |
| 11032 | {kVarInt62OneByte + 0x11}}, |
| 11033 | {"Unable to read new connection ID frame retire_prior_to.", |
| 11034 | {kVarInt62OneByte + 0x1b}}, |
| 11035 | {"Unable to read new connection ID frame connection id length.", |
| 11036 | {0x08}}, // connection ID length |
| 11037 | {"Unable to read new connection ID frame connection id.", |
| 11038 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11}}, |
| 11039 | {"Can not read new connection ID frame reset token.", |
| 11040 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 11041 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 11042 | }; |
| 11043 | // clang-format on |
| 11044 | |
| 11045 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11046 | AssemblePacketFromFragments(packet99)); |
| 11047 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 11048 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_NEW_CONNECTION_ID_DATA)); |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 11049 | EXPECT_EQ("Retire_prior_to > sequence_number.", framer_.detailed_error()); |
| 11050 | } |
| 11051 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11052 | TEST_P(QuicFramerTest, BuildNewConnectionIdFramePacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11053 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11054 | // This frame is only for IETF QUIC only. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11055 | return; |
| 11056 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 11057 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11058 | QuicPacketHeader header; |
| 11059 | header.destination_connection_id = FramerTestConnectionId(); |
| 11060 | header.reset_flag = false; |
| 11061 | header.version_flag = false; |
| 11062 | header.packet_number = kPacketNumber; |
| 11063 | |
| 11064 | QuicNewConnectionIdFrame frame; |
| 11065 | frame.sequence_number = 0x11; |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 11066 | frame.retire_prior_to = 0x0c; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11067 | // Use this value to force a 4-byte encoded variable length connection ID |
| 11068 | // in the frame. |
| 11069 | frame.connection_id = FramerTestConnectionIdPlusOne(); |
| 11070 | frame.stateless_reset_token = kTestStatelessResetToken; |
| 11071 | |
| 11072 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11073 | |
| 11074 | // clang-format off |
| 11075 | unsigned char packet99[] = { |
| 11076 | // type (short header, 4 byte packet number) |
| 11077 | 0x43, |
| 11078 | // connection_id |
| 11079 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11080 | // packet number |
| 11081 | 0x12, 0x34, 0x56, 0x78, |
| 11082 | |
| 11083 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 11084 | 0x18, |
| 11085 | // sequence number |
| 11086 | kVarInt62OneByte + 0x11, |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 11087 | // retire_prior_to |
| 11088 | kVarInt62OneByte + 0x0c, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11089 | // new connection id length |
| 11090 | 0x08, |
| 11091 | // new connection id |
| 11092 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 11093 | // stateless reset token |
| 11094 | 0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 11095 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 11096 | }; |
| 11097 | // clang-format on |
| 11098 | |
| 11099 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11100 | ASSERT_TRUE(data != nullptr); |
| 11101 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 11102 | quiche::test::CompareCharArraysWithHexError( |
| 11103 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 11104 | ABSL_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11105 | } |
| 11106 | |
| 11107 | TEST_P(QuicFramerTest, NewTokenFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11108 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11109 | // This frame is only for IETF QUIC only. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11110 | return; |
| 11111 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11112 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11113 | // clang-format off |
| 11114 | PacketFragments packet = { |
| 11115 | // type (short header, 4 byte packet number) |
| 11116 | {"", |
| 11117 | {0x43}}, |
| 11118 | // connection_id |
| 11119 | {"", |
| 11120 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11121 | // packet number |
| 11122 | {"", |
| 11123 | {0x12, 0x34, 0x56, 0x78}}, |
| 11124 | // frame type (IETF_NEW_TOKEN frame) |
| 11125 | {"", |
| 11126 | {0x07}}, |
| 11127 | // Length |
| 11128 | {"Unable to read new token length.", |
| 11129 | {kVarInt62OneByte + 0x08}}, |
| 11130 | {"Unable to read new token data.", |
| 11131 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}} |
| 11132 | }; |
| 11133 | // clang-format on |
| 11134 | uint8_t expected_token_value[] = {0x00, 0x01, 0x02, 0x03, |
| 11135 | 0x04, 0x05, 0x06, 0x07}; |
| 11136 | |
| 11137 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11138 | AssemblePacketFromFragments(packet)); |
| 11139 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11140 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 11141 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11142 | ASSERT_TRUE(visitor_.header_.get()); |
| 11143 | EXPECT_TRUE(CheckDecryption( |
| 11144 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11145 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11146 | |
| 11147 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 11148 | |
| 11149 | EXPECT_EQ(sizeof(expected_token_value), visitor_.new_token_.token.length()); |
| 11150 | EXPECT_EQ(0, memcmp(expected_token_value, visitor_.new_token_.token.data(), |
| 11151 | sizeof(expected_token_value))); |
| 11152 | |
| 11153 | CheckFramingBoundaries(packet, QUIC_INVALID_NEW_TOKEN); |
| 11154 | } |
| 11155 | |
| 11156 | TEST_P(QuicFramerTest, BuildNewTokenFramePacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11157 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11158 | // This frame is only for IETF QUIC only. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11159 | return; |
| 11160 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 11161 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11162 | QuicPacketHeader header; |
| 11163 | header.destination_connection_id = FramerTestConnectionId(); |
| 11164 | header.reset_flag = false; |
| 11165 | header.version_flag = false; |
| 11166 | header.packet_number = kPacketNumber; |
| 11167 | |
| 11168 | uint8_t expected_token_value[] = {0x00, 0x01, 0x02, 0x03, |
| 11169 | 0x04, 0x05, 0x06, 0x07}; |
| 11170 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 11171 | QuicNewTokenFrame frame(0, std::string((const char*)(expected_token_value), |
| 11172 | sizeof(expected_token_value))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11173 | |
| 11174 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11175 | |
| 11176 | // clang-format off |
| 11177 | unsigned char packet[] = { |
| 11178 | // type (short header, 4 byte packet number) |
| 11179 | 0x43, |
| 11180 | // connection_id |
| 11181 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11182 | // packet number |
| 11183 | 0x12, 0x34, 0x56, 0x78, |
| 11184 | |
| 11185 | // frame type (IETF_NEW_TOKEN frame) |
| 11186 | 0x07, |
| 11187 | // Length and token |
| 11188 | kVarInt62OneByte + 0x08, |
| 11189 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 11190 | }; |
| 11191 | // clang-format on |
| 11192 | |
| 11193 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11194 | ASSERT_TRUE(data != nullptr); |
| 11195 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 11196 | quiche::test::CompareCharArraysWithHexError( |
| 11197 | "constructed packet", data->data(), data->length(), AsChars(packet), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 11198 | ABSL_ARRAYSIZE(packet)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11199 | } |
| 11200 | |
| 11201 | TEST_P(QuicFramerTest, IetfStopSendingFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11202 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11203 | // Stop sending frame is IETF QUIC only. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11204 | return; |
| 11205 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11206 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11207 | |
| 11208 | // clang-format off |
| 11209 | PacketFragments packet99 = { |
| 11210 | // type (short header, 4 byte packet number) |
| 11211 | {"", |
| 11212 | {0x43}}, |
| 11213 | // connection_id |
| 11214 | {"", |
| 11215 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11216 | // packet number |
| 11217 | {"", |
| 11218 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11219 | // frame type (IETF_STOP_SENDING frame) |
| 11220 | {"", |
| 11221 | {0x05}}, |
| 11222 | // stream id |
renjietang | d077f8c | 2020-03-23 17:22:09 -0700 | [diff] [blame] | 11223 | {"Unable to read IETF_STOP_SENDING frame stream id/count.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11224 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 11225 | {"Unable to read stop sending application error code.", |
fkastenholz | 733552e | 2019-07-16 11:16:58 -0700 | [diff] [blame] | 11226 | {kVarInt62FourBytes + 0x00, 0x00, 0x76, 0x54}}, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11227 | }; |
| 11228 | // clang-format on |
| 11229 | |
| 11230 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11231 | AssemblePacketFromFragments(packet99)); |
| 11232 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11233 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 11234 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11235 | ASSERT_TRUE(visitor_.header_.get()); |
| 11236 | EXPECT_TRUE(CheckDecryption( |
| 11237 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11238 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11239 | |
| 11240 | EXPECT_EQ(kStreamId, visitor_.stop_sending_frame_.stream_id); |
bnc | 4fd6e9b | 2020-09-10 13:06:54 -0700 | [diff] [blame] | 11241 | if (GetQuicReloadableFlag(quic_stop_sending_uses_ietf_error_code)) { |
| 11242 | EXPECT_EQ(QUIC_STREAM_UNKNOWN_APPLICATION_ERROR_CODE, |
| 11243 | visitor_.stop_sending_frame_.error_code); |
| 11244 | } else { |
| 11245 | EXPECT_EQ(0x7654, visitor_.stop_sending_frame_.error_code); |
| 11246 | } |
| 11247 | EXPECT_EQ(static_cast<uint64_t>(0x7654), |
| 11248 | visitor_.stop_sending_frame_.ietf_error_code); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11249 | |
| 11250 | CheckFramingBoundaries(packet99, QUIC_INVALID_STOP_SENDING_FRAME_DATA); |
| 11251 | } |
| 11252 | |
| 11253 | TEST_P(QuicFramerTest, BuildIetfStopSendingPacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11254 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11255 | // Stop sending frame is IETF QUIC only. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11256 | return; |
| 11257 | } |
| 11258 | |
| 11259 | QuicPacketHeader header; |
| 11260 | header.destination_connection_id = FramerTestConnectionId(); |
| 11261 | header.reset_flag = false; |
| 11262 | header.version_flag = false; |
| 11263 | header.packet_number = kPacketNumber; |
| 11264 | |
| 11265 | QuicStopSendingFrame frame; |
| 11266 | frame.stream_id = kStreamId; |
bnc | 4fd6e9b | 2020-09-10 13:06:54 -0700 | [diff] [blame] | 11267 | frame.error_code = QUIC_STREAM_ENCODER_STREAM_ERROR; |
| 11268 | frame.ietf_error_code = |
| 11269 | static_cast<uint64_t>(QuicHttpQpackErrorCode::ENCODER_STREAM_ERROR); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11270 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11271 | |
| 11272 | // clang-format off |
| 11273 | unsigned char packet99[] = { |
| 11274 | // type (short header, 4 byte packet number) |
| 11275 | 0x43, |
| 11276 | // connection_id |
| 11277 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11278 | // packet number |
| 11279 | 0x12, 0x34, 0x56, 0x78, |
| 11280 | |
| 11281 | // frame type (IETF_STOP_SENDING frame) |
| 11282 | 0x05, |
| 11283 | // Stream ID |
| 11284 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 11285 | // Application error code |
bnc | 4fd6e9b | 2020-09-10 13:06:54 -0700 | [diff] [blame] | 11286 | kVarInt62TwoBytes + 0x02, 0x01, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11287 | }; |
| 11288 | // clang-format on |
| 11289 | |
| 11290 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11291 | ASSERT_TRUE(data != nullptr); |
| 11292 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 11293 | quiche::test::CompareCharArraysWithHexError( |
| 11294 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 11295 | ABSL_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11296 | } |
| 11297 | |
| 11298 | TEST_P(QuicFramerTest, IetfPathChallengeFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11299 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11300 | // Path Challenge frame is IETF QUIC only. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11301 | return; |
| 11302 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11303 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11304 | |
| 11305 | // clang-format off |
| 11306 | PacketFragments packet99 = { |
| 11307 | // type (short header, 4 byte packet number) |
| 11308 | {"", |
| 11309 | {0x43}}, |
| 11310 | // connection_id |
| 11311 | {"", |
| 11312 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11313 | // packet number |
| 11314 | {"", |
| 11315 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11316 | // frame type (IETF_PATH_CHALLENGE) |
| 11317 | {"", |
| 11318 | {0x1a}}, |
| 11319 | // data |
| 11320 | {"Can not read path challenge data.", |
| 11321 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}}, |
| 11322 | }; |
| 11323 | // clang-format on |
| 11324 | |
| 11325 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11326 | AssemblePacketFromFragments(packet99)); |
| 11327 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11328 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 11329 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11330 | ASSERT_TRUE(visitor_.header_.get()); |
| 11331 | EXPECT_TRUE(CheckDecryption( |
| 11332 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11333 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11334 | |
| 11335 | EXPECT_EQ(QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}), |
| 11336 | visitor_.path_challenge_frame_.data_buffer); |
| 11337 | |
| 11338 | CheckFramingBoundaries(packet99, QUIC_INVALID_PATH_CHALLENGE_DATA); |
| 11339 | } |
| 11340 | |
| 11341 | TEST_P(QuicFramerTest, BuildIetfPathChallengePacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11342 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11343 | // Path Challenge frame is IETF QUIC only. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11344 | return; |
| 11345 | } |
| 11346 | |
| 11347 | QuicPacketHeader header; |
| 11348 | header.destination_connection_id = FramerTestConnectionId(); |
| 11349 | header.reset_flag = false; |
| 11350 | header.version_flag = false; |
| 11351 | header.packet_number = kPacketNumber; |
| 11352 | |
| 11353 | QuicPathChallengeFrame frame; |
| 11354 | frame.data_buffer = QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}); |
| 11355 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11356 | |
| 11357 | // clang-format off |
| 11358 | unsigned char packet99[] = { |
| 11359 | // type (short header, 4 byte packet number) |
| 11360 | 0x43, |
| 11361 | // connection_id |
| 11362 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11363 | // packet number |
| 11364 | 0x12, 0x34, 0x56, 0x78, |
| 11365 | |
| 11366 | // frame type (IETF_PATH_CHALLENGE) |
| 11367 | 0x1a, |
| 11368 | // Data |
| 11369 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 11370 | }; |
| 11371 | // clang-format on |
| 11372 | |
| 11373 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11374 | ASSERT_TRUE(data != nullptr); |
| 11375 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 11376 | quiche::test::CompareCharArraysWithHexError( |
| 11377 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 11378 | ABSL_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11379 | } |
| 11380 | |
| 11381 | TEST_P(QuicFramerTest, IetfPathResponseFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11382 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11383 | // Path response frame is IETF QUIC only. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11384 | return; |
| 11385 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11386 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11387 | |
| 11388 | // clang-format off |
| 11389 | PacketFragments packet99 = { |
| 11390 | // type (short header, 4 byte packet number) |
| 11391 | {"", |
| 11392 | {0x43}}, |
| 11393 | // connection_id |
| 11394 | {"", |
| 11395 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11396 | // packet number |
| 11397 | {"", |
| 11398 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11399 | // frame type (IETF_PATH_RESPONSE) |
| 11400 | {"", |
| 11401 | {0x1b}}, |
| 11402 | // data |
| 11403 | {"Can not read path response data.", |
| 11404 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}}, |
| 11405 | }; |
| 11406 | // clang-format on |
| 11407 | |
| 11408 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11409 | AssemblePacketFromFragments(packet99)); |
| 11410 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11411 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 11412 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11413 | ASSERT_TRUE(visitor_.header_.get()); |
| 11414 | EXPECT_TRUE(CheckDecryption( |
| 11415 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11416 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11417 | |
| 11418 | EXPECT_EQ(QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}), |
| 11419 | visitor_.path_response_frame_.data_buffer); |
| 11420 | |
| 11421 | CheckFramingBoundaries(packet99, QUIC_INVALID_PATH_RESPONSE_DATA); |
| 11422 | } |
| 11423 | |
| 11424 | TEST_P(QuicFramerTest, BuildIetfPathResponsePacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11425 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11426 | // Path response frame is IETF QUIC only |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11427 | return; |
| 11428 | } |
| 11429 | |
| 11430 | QuicPacketHeader header; |
| 11431 | header.destination_connection_id = FramerTestConnectionId(); |
| 11432 | header.reset_flag = false; |
| 11433 | header.version_flag = false; |
| 11434 | header.packet_number = kPacketNumber; |
| 11435 | |
| 11436 | QuicPathResponseFrame frame; |
| 11437 | frame.data_buffer = QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}); |
| 11438 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11439 | |
| 11440 | // clang-format off |
| 11441 | unsigned char packet99[] = { |
| 11442 | // type (short header, 4 byte packet number) |
| 11443 | 0x43, |
| 11444 | // connection_id |
| 11445 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11446 | // packet number |
| 11447 | 0x12, 0x34, 0x56, 0x78, |
| 11448 | |
| 11449 | // frame type (IETF_PATH_RESPONSE) |
| 11450 | 0x1b, |
| 11451 | // Data |
| 11452 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 11453 | }; |
| 11454 | // clang-format on |
| 11455 | |
| 11456 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11457 | ASSERT_TRUE(data != nullptr); |
| 11458 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 11459 | quiche::test::CompareCharArraysWithHexError( |
| 11460 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 11461 | ABSL_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11462 | } |
| 11463 | |
| 11464 | TEST_P(QuicFramerTest, GetRetransmittableControlFrameSize) { |
| 11465 | QuicRstStreamFrame rst_stream(1, 3, QUIC_STREAM_CANCELLED, 1024); |
| 11466 | EXPECT_EQ(QuicFramer::GetRstStreamFrameSize(framer_.transport_version(), |
| 11467 | rst_stream), |
| 11468 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11469 | framer_.transport_version(), QuicFrame(&rst_stream))); |
| 11470 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 11471 | std::string error_detail(2048, 'e'); |
wub | a0cbbdc | 2019-09-09 06:40:59 -0700 | [diff] [blame] | 11472 | QuicConnectionCloseFrame connection_close( |
| 11473 | framer_.transport_version(), QUIC_NETWORK_IDLE_TIMEOUT, error_detail, |
| 11474 | /*transport_close_frame_type=*/0); |
fkastenholz | 72f509b | 2019-04-10 09:17:49 -0700 | [diff] [blame] | 11475 | |
fkastenholz | a037b8b | 2019-05-07 06:00:05 -0700 | [diff] [blame] | 11476 | EXPECT_EQ(QuicFramer::GetConnectionCloseFrameSize(framer_.transport_version(), |
| 11477 | connection_close), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11478 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11479 | framer_.transport_version(), QuicFrame(&connection_close))); |
| 11480 | |
| 11481 | QuicGoAwayFrame goaway(2, QUIC_PEER_GOING_AWAY, 3, error_detail); |
| 11482 | EXPECT_EQ(QuicFramer::GetMinGoAwayFrameSize() + 256, |
| 11483 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11484 | framer_.transport_version(), QuicFrame(&goaway))); |
| 11485 | |
| 11486 | QuicWindowUpdateFrame window_update(3, 3, 1024); |
| 11487 | EXPECT_EQ(QuicFramer::GetWindowUpdateFrameSize(framer_.transport_version(), |
| 11488 | window_update), |
| 11489 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11490 | framer_.transport_version(), QuicFrame(&window_update))); |
| 11491 | |
| 11492 | QuicBlockedFrame blocked(4, 3, 1024); |
| 11493 | EXPECT_EQ( |
| 11494 | QuicFramer::GetBlockedFrameSize(framer_.transport_version(), blocked), |
| 11495 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11496 | framer_.transport_version(), QuicFrame(&blocked))); |
| 11497 | |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11498 | // Following frames are IETF QUIC frames only. |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11499 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11500 | return; |
| 11501 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11502 | |
fkastenholz | 1c19fc2 | 2019-07-12 11:06:19 -0700 | [diff] [blame] | 11503 | QuicNewConnectionIdFrame new_connection_id(5, TestConnectionId(), 1, 101111, |
| 11504 | 1); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11505 | EXPECT_EQ(QuicFramer::GetNewConnectionIdFrameSize(new_connection_id), |
| 11506 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11507 | framer_.transport_version(), QuicFrame(&new_connection_id))); |
| 11508 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11509 | QuicMaxStreamsFrame max_streams(6, 3, /*unidirectional=*/false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11510 | EXPECT_EQ(QuicFramer::GetMaxStreamsFrameSize(framer_.transport_version(), |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11511 | max_streams), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11512 | QuicFramer::GetRetransmittableControlFrameSize( |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11513 | framer_.transport_version(), QuicFrame(max_streams))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11514 | |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11515 | QuicStreamsBlockedFrame streams_blocked(7, 3, /*unidirectional=*/false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11516 | EXPECT_EQ(QuicFramer::GetStreamsBlockedFrameSize(framer_.transport_version(), |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11517 | streams_blocked), |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11518 | QuicFramer::GetRetransmittableControlFrameSize( |
fkastenholz | 3c4eabf | 2019-04-22 07:49:59 -0700 | [diff] [blame] | 11519 | framer_.transport_version(), QuicFrame(streams_blocked))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11520 | |
| 11521 | QuicPathFrameBuffer buffer = { |
| 11522 | {0x80, 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe5, 0xf7}}; |
| 11523 | QuicPathResponseFrame path_response_frame(8, buffer); |
| 11524 | EXPECT_EQ(QuicFramer::GetPathResponseFrameSize(path_response_frame), |
| 11525 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11526 | framer_.transport_version(), QuicFrame(&path_response_frame))); |
| 11527 | |
| 11528 | QuicPathChallengeFrame path_challenge_frame(9, buffer); |
| 11529 | EXPECT_EQ(QuicFramer::GetPathChallengeFrameSize(path_challenge_frame), |
| 11530 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11531 | framer_.transport_version(), QuicFrame(&path_challenge_frame))); |
| 11532 | |
bnc | 187eea3 | 2020-09-02 12:16:15 -0700 | [diff] [blame] | 11533 | QuicStopSendingFrame stop_sending_frame(10, 3, QUIC_STREAM_CANCELLED); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11534 | EXPECT_EQ(QuicFramer::GetStopSendingFrameSize(stop_sending_frame), |
| 11535 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11536 | framer_.transport_version(), QuicFrame(&stop_sending_frame))); |
| 11537 | } |
| 11538 | |
| 11539 | // A set of tests to ensure that bad frame-type encodings |
| 11540 | // are properly detected and handled. |
| 11541 | // First, four tests to see that unknown frame types generate |
| 11542 | // a QUIC_INVALID_FRAME_DATA error with detailed information |
| 11543 | // "Illegal frame type." This regardless of the encoding of the type |
| 11544 | // (1/2/4/8 bytes). |
| 11545 | // This only for version 99. |
| 11546 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown1Byte) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11547 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11548 | // Only IETF QUIC encodes frame types such that this test is relevant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11549 | return; |
| 11550 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11551 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11552 | // clang-format off |
| 11553 | PacketFragments packet = { |
| 11554 | // type (short header, 4 byte packet number) |
| 11555 | {"", |
| 11556 | {0x43}}, |
| 11557 | // connection_id |
| 11558 | {"", |
| 11559 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11560 | // packet number |
| 11561 | {"", |
| 11562 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11563 | // frame type (unknown value, single-byte encoding) |
| 11564 | {"", |
| 11565 | {0x38}} |
| 11566 | }; |
| 11567 | // clang-format on |
| 11568 | |
| 11569 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11570 | AssemblePacketFromFragments(packet)); |
| 11571 | |
| 11572 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11573 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 11574 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_FRAME_DATA)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11575 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11576 | } |
| 11577 | |
| 11578 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown2Bytes) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11579 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11580 | // Only IETF QUIC encodes frame types such that this test is relevant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11581 | return; |
| 11582 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11583 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11584 | |
| 11585 | // clang-format off |
| 11586 | PacketFragments packet = { |
| 11587 | // type (short header, 4 byte packet number) |
| 11588 | {"", |
| 11589 | {0x43}}, |
| 11590 | // connection_id |
| 11591 | {"", |
| 11592 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11593 | // packet number |
| 11594 | {"", |
| 11595 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11596 | // frame type (unknown value, two-byte encoding) |
| 11597 | {"", |
| 11598 | {kVarInt62TwoBytes + 0x01, 0x38}} |
| 11599 | }; |
| 11600 | // clang-format on |
| 11601 | |
| 11602 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11603 | AssemblePacketFromFragments(packet)); |
| 11604 | |
| 11605 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11606 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 11607 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_FRAME_DATA)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11608 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11609 | } |
| 11610 | |
| 11611 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown4Bytes) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11612 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11613 | // Only IETF QUIC encodes frame types such that this test is relevant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11614 | return; |
| 11615 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11616 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11617 | |
| 11618 | // clang-format off |
| 11619 | PacketFragments packet = { |
| 11620 | // type (short header, 4 byte packet number) |
| 11621 | {"", |
| 11622 | {0x43}}, |
| 11623 | // connection_id |
| 11624 | {"", |
| 11625 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11626 | // packet number |
| 11627 | {"", |
| 11628 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11629 | // frame type (unknown value, four-byte encoding) |
| 11630 | {"", |
| 11631 | {kVarInt62FourBytes + 0x01, 0x00, 0x00, 0x38}} |
| 11632 | }; |
| 11633 | // clang-format on |
| 11634 | |
| 11635 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11636 | AssemblePacketFromFragments(packet)); |
| 11637 | |
| 11638 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11639 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 11640 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_FRAME_DATA)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11641 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11642 | } |
| 11643 | |
| 11644 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown8Bytes) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11645 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11646 | // Only IETF QUIC encodes frame types such that this test is relevant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11647 | return; |
| 11648 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11649 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11650 | // clang-format off |
| 11651 | PacketFragments packet = { |
| 11652 | // type (short header, 4 byte packet number) |
| 11653 | {"", |
| 11654 | {0x43}}, |
| 11655 | // connection_id |
| 11656 | {"", |
| 11657 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11658 | // packet number |
| 11659 | {"", |
| 11660 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11661 | // frame type (unknown value, eight-byte encoding) |
| 11662 | {"", |
| 11663 | {kVarInt62EightBytes + 0x01, 0x00, 0x00, 0x01, 0x02, 0x34, 0x56, 0x38}} |
| 11664 | }; |
| 11665 | // clang-format on |
| 11666 | |
| 11667 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11668 | AssemblePacketFromFragments(packet)); |
| 11669 | |
| 11670 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11671 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 11672 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_FRAME_DATA)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11673 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11674 | } |
| 11675 | |
| 11676 | // Three tests to check that known frame types that are not minimally |
| 11677 | // encoded generate IETF_QUIC_PROTOCOL_VIOLATION errors with detailed |
| 11678 | // information "Frame type not minimally encoded." |
| 11679 | // Look at the frame-type encoded in 2, 4, and 8 bytes. |
| 11680 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown2Bytes) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11681 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11682 | // Only IETF QUIC encodes frame types such that this test is relevant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11683 | return; |
| 11684 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11685 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11686 | |
| 11687 | // clang-format off |
| 11688 | PacketFragments packet = { |
| 11689 | // type (short header, 4 byte packet number) |
| 11690 | {"", |
| 11691 | {0x43}}, |
| 11692 | // connection_id |
| 11693 | {"", |
| 11694 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11695 | // packet number |
| 11696 | {"", |
| 11697 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11698 | // frame type (Blocked, two-byte encoding) |
| 11699 | {"", |
| 11700 | {kVarInt62TwoBytes + 0x00, 0x08}} |
| 11701 | }; |
| 11702 | // clang-format on |
| 11703 | |
| 11704 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11705 | AssemblePacketFromFragments(packet)); |
| 11706 | |
| 11707 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11708 | |
bnc | f54082a | 2019-11-27 10:19:47 -0800 | [diff] [blame] | 11709 | EXPECT_THAT(framer_.error(), IsError(IETF_QUIC_PROTOCOL_VIOLATION)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11710 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 11711 | } |
| 11712 | |
| 11713 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown4Bytes) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11714 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11715 | // Only IETF QUIC encodes frame types such that this test is relevant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11716 | return; |
| 11717 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11718 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11719 | |
| 11720 | // clang-format off |
| 11721 | PacketFragments packet = { |
| 11722 | // type (short header, 4 byte packet number) |
| 11723 | {"", |
| 11724 | {0x43}}, |
| 11725 | // connection_id |
| 11726 | {"", |
| 11727 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11728 | // packet number |
| 11729 | {"", |
| 11730 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11731 | // frame type (Blocked, four-byte encoding) |
| 11732 | {"", |
| 11733 | {kVarInt62FourBytes + 0x00, 0x00, 0x00, 0x08}} |
| 11734 | }; |
| 11735 | // clang-format on |
| 11736 | |
| 11737 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11738 | AssemblePacketFromFragments(packet)); |
| 11739 | |
| 11740 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11741 | |
bnc | f54082a | 2019-11-27 10:19:47 -0800 | [diff] [blame] | 11742 | EXPECT_THAT(framer_.error(), IsError(IETF_QUIC_PROTOCOL_VIOLATION)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11743 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 11744 | } |
| 11745 | |
| 11746 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown8Bytes) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11747 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11748 | // Only IETF QUIC encodes frame types such that this test is relevant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11749 | return; |
| 11750 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11751 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11752 | // clang-format off |
| 11753 | PacketFragments packet = { |
| 11754 | // type (short header, 4 byte packet number) |
| 11755 | {"", |
| 11756 | {0x43}}, |
| 11757 | // connection_id |
| 11758 | {"", |
| 11759 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11760 | // packet number |
| 11761 | {"", |
| 11762 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11763 | // frame type (Blocked, eight-byte encoding) |
| 11764 | {"", |
| 11765 | {kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08}} |
| 11766 | }; |
| 11767 | // clang-format on |
| 11768 | |
| 11769 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11770 | AssemblePacketFromFragments(packet)); |
| 11771 | |
| 11772 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11773 | |
bnc | f54082a | 2019-11-27 10:19:47 -0800 | [diff] [blame] | 11774 | EXPECT_THAT(framer_.error(), IsError(IETF_QUIC_PROTOCOL_VIOLATION)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11775 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 11776 | } |
| 11777 | |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11778 | // 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] | 11779 | // encoded generate IETF_QUIC_PROTOCOL_VIOLATION errors with detailed |
| 11780 | // information "Frame type not minimally encoded." |
| 11781 | // Just look at 2-byte encoding. |
| 11782 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown2BytesAllTypes) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 11783 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 11784 | // Only IETF QUIC encodes frame types such that this test is relevant. |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11785 | return; |
| 11786 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 11787 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11788 | |
| 11789 | // clang-format off |
| 11790 | PacketFragments packets[] = { |
| 11791 | { |
| 11792 | // type (short header, 4 byte packet number) |
| 11793 | {"", |
| 11794 | {0x43}}, |
| 11795 | // connection_id |
| 11796 | {"", |
| 11797 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11798 | // packet number |
| 11799 | {"", |
| 11800 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11801 | // frame type (two-byte encoding) |
| 11802 | {"", |
| 11803 | {kVarInt62TwoBytes + 0x00, 0x00}} |
| 11804 | }, |
| 11805 | { |
| 11806 | // type (short header, 4 byte packet number) |
| 11807 | {"", |
| 11808 | {0x43}}, |
| 11809 | // connection_id |
| 11810 | {"", |
| 11811 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11812 | // packet number |
| 11813 | {"", |
| 11814 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11815 | // frame type (two-byte encoding) |
| 11816 | {"", |
| 11817 | {kVarInt62TwoBytes + 0x00, 0x01}} |
| 11818 | }, |
| 11819 | { |
| 11820 | // type (short header, 4 byte packet number) |
| 11821 | {"", |
| 11822 | {0x43}}, |
| 11823 | // connection_id |
| 11824 | {"", |
| 11825 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11826 | // packet number |
| 11827 | {"", |
| 11828 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11829 | // frame type (two-byte encoding) |
| 11830 | {"", |
| 11831 | {kVarInt62TwoBytes + 0x00, 0x02}} |
| 11832 | }, |
| 11833 | { |
| 11834 | // type (short header, 4 byte packet number) |
| 11835 | {"", |
| 11836 | {0x43}}, |
| 11837 | // connection_id |
| 11838 | {"", |
| 11839 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11840 | // packet number |
| 11841 | {"", |
| 11842 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11843 | // frame type (two-byte encoding) |
| 11844 | {"", |
| 11845 | {kVarInt62TwoBytes + 0x00, 0x03}} |
| 11846 | }, |
| 11847 | { |
| 11848 | // type (short header, 4 byte packet number) |
| 11849 | {"", |
| 11850 | {0x43}}, |
| 11851 | // connection_id |
| 11852 | {"", |
| 11853 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11854 | // packet number |
| 11855 | {"", |
| 11856 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11857 | // frame type (two-byte encoding) |
| 11858 | {"", |
| 11859 | {kVarInt62TwoBytes + 0x00, 0x04}} |
| 11860 | }, |
| 11861 | { |
| 11862 | // type (short header, 4 byte packet number) |
| 11863 | {"", |
| 11864 | {0x43}}, |
| 11865 | // connection_id |
| 11866 | {"", |
| 11867 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11868 | // packet number |
| 11869 | {"", |
| 11870 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11871 | // frame type (two-byte encoding) |
| 11872 | {"", |
| 11873 | {kVarInt62TwoBytes + 0x00, 0x05}} |
| 11874 | }, |
| 11875 | { |
| 11876 | // type (short header, 4 byte packet number) |
| 11877 | {"", |
| 11878 | {0x43}}, |
| 11879 | // connection_id |
| 11880 | {"", |
| 11881 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11882 | // packet number |
| 11883 | {"", |
| 11884 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11885 | // frame type (two-byte encoding) |
| 11886 | {"", |
| 11887 | {kVarInt62TwoBytes + 0x00, 0x06}} |
| 11888 | }, |
| 11889 | { |
| 11890 | // type (short header, 4 byte packet number) |
| 11891 | {"", |
| 11892 | {0x43}}, |
| 11893 | // connection_id |
| 11894 | {"", |
| 11895 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11896 | // packet number |
| 11897 | {"", |
| 11898 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11899 | // frame type (two-byte encoding) |
| 11900 | {"", |
| 11901 | {kVarInt62TwoBytes + 0x00, 0x07}} |
| 11902 | }, |
| 11903 | { |
| 11904 | // type (short header, 4 byte packet number) |
| 11905 | {"", |
| 11906 | {0x43}}, |
| 11907 | // connection_id |
| 11908 | {"", |
| 11909 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11910 | // packet number |
| 11911 | {"", |
| 11912 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11913 | // frame type (two-byte encoding) |
| 11914 | {"", |
| 11915 | {kVarInt62TwoBytes + 0x00, 0x08}} |
| 11916 | }, |
| 11917 | { |
| 11918 | // type (short header, 4 byte packet number) |
| 11919 | {"", |
| 11920 | {0x43}}, |
| 11921 | // connection_id |
| 11922 | {"", |
| 11923 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11924 | // packet number |
| 11925 | {"", |
| 11926 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11927 | // frame type (two-byte encoding) |
| 11928 | {"", |
| 11929 | {kVarInt62TwoBytes + 0x00, 0x09}} |
| 11930 | }, |
| 11931 | { |
| 11932 | // type (short header, 4 byte packet number) |
| 11933 | {"", |
| 11934 | {0x43}}, |
| 11935 | // connection_id |
| 11936 | {"", |
| 11937 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11938 | // packet number |
| 11939 | {"", |
| 11940 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11941 | // frame type (two-byte encoding) |
| 11942 | {"", |
| 11943 | {kVarInt62TwoBytes + 0x00, 0x0a}} |
| 11944 | }, |
| 11945 | { |
| 11946 | // type (short header, 4 byte packet number) |
| 11947 | {"", |
| 11948 | {0x43}}, |
| 11949 | // connection_id |
| 11950 | {"", |
| 11951 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11952 | // packet number |
| 11953 | {"", |
| 11954 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11955 | // frame type (two-byte encoding) |
| 11956 | {"", |
| 11957 | {kVarInt62TwoBytes + 0x00, 0x0b}} |
| 11958 | }, |
| 11959 | { |
| 11960 | // type (short header, 4 byte packet number) |
| 11961 | {"", |
| 11962 | {0x43}}, |
| 11963 | // connection_id |
| 11964 | {"", |
| 11965 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11966 | // packet number |
| 11967 | {"", |
| 11968 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11969 | // frame type (two-byte encoding) |
| 11970 | {"", |
| 11971 | {kVarInt62TwoBytes + 0x00, 0x0c}} |
| 11972 | }, |
| 11973 | { |
| 11974 | // type (short header, 4 byte packet number) |
| 11975 | {"", |
| 11976 | {0x43}}, |
| 11977 | // connection_id |
| 11978 | {"", |
| 11979 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11980 | // packet number |
| 11981 | {"", |
| 11982 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11983 | // frame type (two-byte encoding) |
| 11984 | {"", |
| 11985 | {kVarInt62TwoBytes + 0x00, 0x0d}} |
| 11986 | }, |
| 11987 | { |
| 11988 | // type (short header, 4 byte packet number) |
| 11989 | {"", |
| 11990 | {0x43}}, |
| 11991 | // connection_id |
| 11992 | {"", |
| 11993 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11994 | // packet number |
| 11995 | {"", |
| 11996 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11997 | // frame type (two-byte encoding) |
| 11998 | {"", |
| 11999 | {kVarInt62TwoBytes + 0x00, 0x0e}} |
| 12000 | }, |
| 12001 | { |
| 12002 | // type (short header, 4 byte packet number) |
| 12003 | {"", |
| 12004 | {0x43}}, |
| 12005 | // connection_id |
| 12006 | {"", |
| 12007 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12008 | // packet number |
| 12009 | {"", |
| 12010 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12011 | // frame type (two-byte encoding) |
| 12012 | {"", |
| 12013 | {kVarInt62TwoBytes + 0x00, 0x0f}} |
| 12014 | }, |
| 12015 | { |
| 12016 | // type (short header, 4 byte packet number) |
| 12017 | {"", |
| 12018 | {0x43}}, |
| 12019 | // connection_id |
| 12020 | {"", |
| 12021 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12022 | // packet number |
| 12023 | {"", |
| 12024 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12025 | // frame type (two-byte encoding) |
| 12026 | {"", |
| 12027 | {kVarInt62TwoBytes + 0x00, 0x10}} |
| 12028 | }, |
| 12029 | { |
| 12030 | // type (short header, 4 byte packet number) |
| 12031 | {"", |
| 12032 | {0x43}}, |
| 12033 | // connection_id |
| 12034 | {"", |
| 12035 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12036 | // packet number |
| 12037 | {"", |
| 12038 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12039 | // frame type (two-byte encoding) |
| 12040 | {"", |
| 12041 | {kVarInt62TwoBytes + 0x00, 0x11}} |
| 12042 | }, |
| 12043 | { |
| 12044 | // type (short header, 4 byte packet number) |
| 12045 | {"", |
| 12046 | {0x43}}, |
| 12047 | // connection_id |
| 12048 | {"", |
| 12049 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12050 | // packet number |
| 12051 | {"", |
| 12052 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12053 | // frame type (two-byte encoding) |
| 12054 | {"", |
| 12055 | {kVarInt62TwoBytes + 0x00, 0x12}} |
| 12056 | }, |
| 12057 | { |
| 12058 | // type (short header, 4 byte packet number) |
| 12059 | {"", |
| 12060 | {0x43}}, |
| 12061 | // connection_id |
| 12062 | {"", |
| 12063 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12064 | // packet number |
| 12065 | {"", |
| 12066 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12067 | // frame type (two-byte encoding) |
| 12068 | {"", |
| 12069 | {kVarInt62TwoBytes + 0x00, 0x13}} |
| 12070 | }, |
| 12071 | { |
| 12072 | // type (short header, 4 byte packet number) |
| 12073 | {"", |
| 12074 | {0x43}}, |
| 12075 | // connection_id |
| 12076 | {"", |
| 12077 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12078 | // packet number |
| 12079 | {"", |
| 12080 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12081 | // frame type (two-byte encoding) |
| 12082 | {"", |
| 12083 | {kVarInt62TwoBytes + 0x00, 0x14}} |
| 12084 | }, |
| 12085 | { |
| 12086 | // type (short header, 4 byte packet number) |
| 12087 | {"", |
| 12088 | {0x43}}, |
| 12089 | // connection_id |
| 12090 | {"", |
| 12091 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12092 | // packet number |
| 12093 | {"", |
| 12094 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12095 | // frame type (two-byte encoding) |
| 12096 | {"", |
| 12097 | {kVarInt62TwoBytes + 0x00, 0x15}} |
| 12098 | }, |
| 12099 | { |
| 12100 | // type (short header, 4 byte packet number) |
| 12101 | {"", |
| 12102 | {0x43}}, |
| 12103 | // connection_id |
| 12104 | {"", |
| 12105 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12106 | // packet number |
| 12107 | {"", |
| 12108 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12109 | // frame type (two-byte encoding) |
| 12110 | {"", |
| 12111 | {kVarInt62TwoBytes + 0x00, 0x16}} |
| 12112 | }, |
| 12113 | { |
| 12114 | // type (short header, 4 byte packet number) |
| 12115 | {"", |
| 12116 | {0x43}}, |
| 12117 | // connection_id |
| 12118 | {"", |
| 12119 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12120 | // packet number |
| 12121 | {"", |
| 12122 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12123 | // frame type (two-byte encoding) |
| 12124 | {"", |
| 12125 | {kVarInt62TwoBytes + 0x00, 0x17}} |
| 12126 | }, |
| 12127 | { |
| 12128 | // type (short header, 4 byte packet number) |
| 12129 | {"", |
| 12130 | {0x43}}, |
| 12131 | // connection_id |
| 12132 | {"", |
| 12133 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12134 | // packet number |
| 12135 | {"", |
| 12136 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12137 | // frame type (two-byte encoding) |
| 12138 | {"", |
| 12139 | {kVarInt62TwoBytes + 0x00, 0x18}} |
| 12140 | }, |
| 12141 | { |
| 12142 | // type (short header, 4 byte packet number) |
| 12143 | {"", |
| 12144 | {0x43}}, |
| 12145 | // connection_id |
| 12146 | {"", |
| 12147 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12148 | // packet number |
| 12149 | {"", |
| 12150 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12151 | // frame type (two-byte encoding) |
| 12152 | {"", |
| 12153 | {kVarInt62TwoBytes + 0x00, 0x20}} |
| 12154 | }, |
| 12155 | { |
| 12156 | // type (short header, 4 byte packet number) |
| 12157 | {"", |
| 12158 | {0x43}}, |
| 12159 | // connection_id |
| 12160 | {"", |
| 12161 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12162 | // packet number |
| 12163 | {"", |
| 12164 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12165 | // frame type (two-byte encoding) |
| 12166 | {"", |
| 12167 | {kVarInt62TwoBytes + 0x00, 0x21}} |
| 12168 | }, |
| 12169 | }; |
| 12170 | // clang-format on |
| 12171 | |
| 12172 | for (PacketFragments& packet : packets) { |
| 12173 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 12174 | AssemblePacketFromFragments(packet)); |
| 12175 | |
| 12176 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 12177 | |
bnc | f54082a | 2019-11-27 10:19:47 -0800 | [diff] [blame] | 12178 | EXPECT_THAT(framer_.error(), IsError(IETF_QUIC_PROTOCOL_VIOLATION)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12179 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 12180 | } |
| 12181 | } |
| 12182 | |
| 12183 | TEST_P(QuicFramerTest, RetireConnectionIdFrame) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 12184 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12185 | // This frame is only for version 99. |
| 12186 | return; |
| 12187 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12188 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12189 | // clang-format off |
| 12190 | PacketFragments packet99 = { |
| 12191 | // type (short header, 4 byte packet number) |
| 12192 | {"", |
| 12193 | {0x43}}, |
| 12194 | // connection_id |
| 12195 | {"", |
| 12196 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12197 | // packet number |
| 12198 | {"", |
| 12199 | {0x12, 0x34, 0x56, 0x78}}, |
| 12200 | // frame type (IETF_RETIRE_CONNECTION_ID frame) |
| 12201 | {"", |
| 12202 | {0x19}}, |
| 12203 | // Sequence number |
| 12204 | {"Unable to read retire connection ID frame sequence number.", |
| 12205 | {kVarInt62TwoBytes + 0x11, 0x22}} |
| 12206 | }; |
| 12207 | // clang-format on |
| 12208 | |
| 12209 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 12210 | AssemblePacketFromFragments(packet99)); |
| 12211 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 12212 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 12213 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12214 | ASSERT_TRUE(visitor_.header_.get()); |
| 12215 | EXPECT_TRUE(CheckDecryption( |
| 12216 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 12217 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 12218 | |
| 12219 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 12220 | |
| 12221 | EXPECT_EQ(0x1122u, visitor_.retire_connection_id_.sequence_number); |
| 12222 | |
| 12223 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 12224 | |
| 12225 | CheckFramingBoundaries(packet99, QUIC_INVALID_RETIRE_CONNECTION_ID_DATA); |
| 12226 | } |
| 12227 | |
| 12228 | TEST_P(QuicFramerTest, BuildRetireConnectionIdFramePacket) { |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 12229 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12230 | // This frame is only for version 99. |
| 12231 | return; |
| 12232 | } |
QUICHE team | 2252b70 | 2019-05-14 23:55:14 -0400 | [diff] [blame] | 12233 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12234 | QuicPacketHeader header; |
| 12235 | header.destination_connection_id = FramerTestConnectionId(); |
| 12236 | header.reset_flag = false; |
| 12237 | header.version_flag = false; |
| 12238 | header.packet_number = kPacketNumber; |
| 12239 | |
| 12240 | QuicRetireConnectionIdFrame frame; |
| 12241 | frame.sequence_number = 0x1122; |
| 12242 | |
| 12243 | QuicFrames frames = {QuicFrame(&frame)}; |
| 12244 | |
| 12245 | // clang-format off |
| 12246 | unsigned char packet99[] = { |
| 12247 | // type (short header, 4 byte packet number) |
| 12248 | 0x43, |
| 12249 | // connection_id |
| 12250 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12251 | // packet number |
| 12252 | 0x12, 0x34, 0x56, 0x78, |
| 12253 | |
| 12254 | // frame type (IETF_RETIRE_CONNECTION_ID frame) |
| 12255 | 0x19, |
| 12256 | // sequence number |
| 12257 | kVarInt62TwoBytes + 0x11, 0x22 |
| 12258 | }; |
| 12259 | // clang-format on |
| 12260 | |
| 12261 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 12262 | ASSERT_TRUE(data != nullptr); |
| 12263 | |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 12264 | quiche::test::CompareCharArraysWithHexError( |
| 12265 | "constructed packet", data->data(), data->length(), AsChars(packet99), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 12266 | ABSL_ARRAYSIZE(packet99)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12267 | } |
| 12268 | |
| 12269 | TEST_P(QuicFramerTest, AckFrameWithInvalidLargestObserved) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12270 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12271 | // clang-format off |
| 12272 | unsigned char packet[] = { |
| 12273 | // public flags (8 byte connection_id) |
| 12274 | 0x2C, |
| 12275 | // connection_id |
| 12276 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12277 | // packet number |
| 12278 | 0x12, 0x34, 0x56, 0x78, |
| 12279 | |
| 12280 | // frame type (ack frame) |
| 12281 | 0x45, |
| 12282 | // largest observed |
| 12283 | 0x00, 0x00, |
| 12284 | // Zero delta time. |
| 12285 | 0x00, 0x00, |
| 12286 | // first ack block length. |
| 12287 | 0x00, 0x00, |
| 12288 | // num timestamps. |
| 12289 | 0x00 |
| 12290 | }; |
| 12291 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12292 | unsigned char packet46[] = { |
| 12293 | // type (short header, 4 byte packet number) |
| 12294 | 0x43, |
| 12295 | // connection_id |
| 12296 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12297 | // packet number |
| 12298 | 0x12, 0x34, 0x56, 0x78, |
| 12299 | |
| 12300 | // frame type (ack frame) |
| 12301 | 0x45, |
| 12302 | // largest observed |
| 12303 | 0x00, 0x00, |
| 12304 | // Zero delta time. |
| 12305 | 0x00, 0x00, |
| 12306 | // first ack block length. |
| 12307 | 0x00, 0x00, |
| 12308 | // num timestamps. |
| 12309 | 0x00 |
| 12310 | }; |
| 12311 | |
| 12312 | unsigned char packet99[] = { |
| 12313 | // type (short header, 4 byte packet number) |
| 12314 | 0x43, |
| 12315 | // connection_id |
| 12316 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12317 | // packet number |
| 12318 | 0x12, 0x34, 0x56, 0x78, |
| 12319 | |
| 12320 | // frame type (IETF_ACK frame) |
| 12321 | 0x02, |
| 12322 | // Largest acked |
| 12323 | kVarInt62OneByte + 0x00, |
| 12324 | // Zero delta time. |
| 12325 | kVarInt62OneByte + 0x00, |
| 12326 | // Ack block count 0 |
| 12327 | kVarInt62OneByte + 0x00, |
| 12328 | // First ack block length |
| 12329 | kVarInt62OneByte + 0x00, |
| 12330 | }; |
| 12331 | // clang-format on |
| 12332 | |
| 12333 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 12334 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 12335 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12336 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 12337 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 12338 | } else if (framer_.version().HasIetfInvariantHeader()) { |
fayang | 374888f | 2019-05-31 06:47:21 -0700 | [diff] [blame] | 12339 | p = packet46; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12340 | } |
| 12341 | |
| 12342 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 12343 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 12344 | EXPECT_EQ(framer_.detailed_error(), "Largest acked is 0."); |
| 12345 | } |
| 12346 | |
| 12347 | TEST_P(QuicFramerTest, FirstAckBlockJustUnderFlow) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12348 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12349 | // clang-format off |
| 12350 | unsigned char packet[] = { |
| 12351 | // public flags (8 byte connection_id) |
| 12352 | 0x2C, |
| 12353 | // connection_id |
| 12354 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12355 | // packet number |
| 12356 | 0x12, 0x34, 0x56, 0x78, |
| 12357 | |
| 12358 | // frame type (ack frame) |
| 12359 | 0x45, |
| 12360 | // largest observed |
| 12361 | 0x00, 0x02, |
| 12362 | // Zero delta time. |
| 12363 | 0x00, 0x00, |
| 12364 | // first ack block length. |
| 12365 | 0x00, 0x03, |
| 12366 | // num timestamps. |
| 12367 | 0x00 |
| 12368 | }; |
| 12369 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12370 | unsigned char packet46[] = { |
| 12371 | // type (short header, 4 byte packet number) |
| 12372 | 0x43, |
| 12373 | // connection_id |
| 12374 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12375 | // packet number |
| 12376 | 0x12, 0x34, 0x56, 0x78, |
| 12377 | |
| 12378 | // frame type (ack frame) |
| 12379 | 0x45, |
| 12380 | // largest observed |
| 12381 | 0x00, 0x02, |
| 12382 | // Zero delta time. |
| 12383 | 0x00, 0x00, |
| 12384 | // first ack block length. |
| 12385 | 0x00, 0x03, |
| 12386 | // num timestamps. |
| 12387 | 0x00 |
| 12388 | }; |
| 12389 | |
| 12390 | unsigned char packet99[] = { |
| 12391 | // type (short header, 4 byte packet number) |
| 12392 | 0x43, |
| 12393 | // connection_id |
| 12394 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12395 | // packet number |
| 12396 | 0x12, 0x34, 0x56, 0x78, |
| 12397 | |
| 12398 | // frame type (IETF_ACK frame) |
| 12399 | 0x02, |
| 12400 | // Largest acked |
| 12401 | kVarInt62OneByte + 0x02, |
| 12402 | // Zero delta time. |
| 12403 | kVarInt62OneByte + 0x00, |
| 12404 | // Ack block count 0 |
| 12405 | kVarInt62OneByte + 0x00, |
| 12406 | // First ack block length |
| 12407 | kVarInt62OneByte + 0x02, |
| 12408 | }; |
| 12409 | // clang-format on |
| 12410 | |
| 12411 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 12412 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 12413 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12414 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 12415 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 12416 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12417 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 12418 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12419 | } |
| 12420 | |
| 12421 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 12422 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 12423 | EXPECT_EQ(framer_.detailed_error(), |
| 12424 | "Underflow with first ack block length 3 largest acked is 2."); |
| 12425 | } |
| 12426 | |
| 12427 | TEST_P(QuicFramerTest, ThirdAckBlockJustUnderflow) { |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12428 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12429 | // clang-format off |
| 12430 | unsigned char packet[] = { |
| 12431 | // public flags (8 byte connection_id) |
| 12432 | 0x2C, |
| 12433 | // connection_id |
| 12434 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12435 | // packet number |
| 12436 | 0x12, 0x34, 0x56, 0x78, |
| 12437 | |
| 12438 | // frame type (ack frame) |
| 12439 | 0x60, |
| 12440 | // largest observed |
| 12441 | 0x0A, |
| 12442 | // Zero delta time. |
| 12443 | 0x00, 0x00, |
| 12444 | // Num of ack blocks |
| 12445 | 0x02, |
| 12446 | // first ack block length. |
| 12447 | 0x02, |
| 12448 | // gap to next block |
| 12449 | 0x01, |
| 12450 | // ack block length |
| 12451 | 0x01, |
| 12452 | // gap to next block |
| 12453 | 0x01, |
| 12454 | // ack block length |
| 12455 | 0x06, |
| 12456 | // num timestamps. |
| 12457 | 0x00 |
| 12458 | }; |
| 12459 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12460 | unsigned char packet46[] = { |
| 12461 | // type (short header, 4 byte packet number) |
| 12462 | 0x43, |
| 12463 | // connection_id |
| 12464 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12465 | // packet number |
| 12466 | 0x12, 0x34, 0x56, 0x78, |
| 12467 | |
| 12468 | // frame type (ack frame) |
| 12469 | 0x60, |
| 12470 | // largest observed |
| 12471 | 0x0A, |
| 12472 | // Zero delta time. |
| 12473 | 0x00, 0x00, |
| 12474 | // Num of ack blocks |
| 12475 | 0x02, |
| 12476 | // first ack block length. |
| 12477 | 0x02, |
| 12478 | // gap to next block |
| 12479 | 0x01, |
| 12480 | // ack block length |
| 12481 | 0x01, |
| 12482 | // gap to next block |
| 12483 | 0x01, |
| 12484 | // ack block length |
| 12485 | 0x06, |
| 12486 | // num timestamps. |
| 12487 | 0x00 |
| 12488 | }; |
| 12489 | |
| 12490 | unsigned char packet99[] = { |
| 12491 | // type (short header, 4 byte packet number) |
| 12492 | 0x43, |
| 12493 | // connection_id |
| 12494 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12495 | // packet number |
| 12496 | 0x12, 0x34, 0x56, 0x78, |
| 12497 | |
| 12498 | // frame type (IETF_ACK frame) |
| 12499 | 0x02, |
| 12500 | // Largest acked |
| 12501 | kVarInt62OneByte + 0x0A, |
| 12502 | // Zero delta time. |
| 12503 | kVarInt62OneByte + 0x00, |
| 12504 | // Ack block count 2 |
| 12505 | kVarInt62OneByte + 0x02, |
| 12506 | // First ack block length |
| 12507 | kVarInt62OneByte + 0x01, |
| 12508 | // gap to next block length |
| 12509 | kVarInt62OneByte + 0x00, |
| 12510 | // ack block length |
| 12511 | kVarInt62OneByte + 0x00, |
| 12512 | // gap to next block length |
| 12513 | kVarInt62OneByte + 0x00, |
| 12514 | // ack block length |
| 12515 | kVarInt62OneByte + 0x05, |
| 12516 | }; |
| 12517 | // clang-format on |
| 12518 | |
| 12519 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 12520 | size_t p_size = ABSL_ARRAYSIZE(packet); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 12521 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12522 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 12523 | p_size = ABSL_ARRAYSIZE(packet99); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 12524 | } else if (framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12525 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 12526 | p_size = ABSL_ARRAYSIZE(packet46); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12527 | } |
| 12528 | |
| 12529 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 12530 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
fkastenholz | 305e173 | 2019-06-18 05:01:22 -0700 | [diff] [blame] | 12531 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12532 | EXPECT_EQ(framer_.detailed_error(), |
| 12533 | "Underflow with ack block length 6 latest ack block end is 5."); |
| 12534 | } else { |
| 12535 | EXPECT_EQ(framer_.detailed_error(), |
| 12536 | "Underflow with ack block length 6, end of block is 6."); |
| 12537 | } |
| 12538 | } |
| 12539 | |
| 12540 | TEST_P(QuicFramerTest, CoalescedPacket) { |
| 12541 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 12542 | return; |
| 12543 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 12544 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12545 | // clang-format off |
| 12546 | unsigned char packet[] = { |
| 12547 | // first coalesced packet |
| 12548 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12549 | // 4-byte packet number) |
| 12550 | 0xD3, |
| 12551 | // version |
| 12552 | QUIC_VERSION_BYTES, |
| 12553 | // destination connection ID length |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 12554 | 0x08, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12555 | // destination connection ID |
| 12556 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 12557 | // source connection ID length |
| 12558 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12559 | // long header packet length |
| 12560 | 0x1E, |
| 12561 | // packet number |
| 12562 | 0x12, 0x34, 0x56, 0x78, |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12563 | // frame type (stream frame with fin) |
| 12564 | 0xFE, |
| 12565 | // stream id |
| 12566 | 0x02, 0x03, 0x04, |
| 12567 | // offset |
| 12568 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 12569 | // data length |
| 12570 | 0x00, 0x0c, |
| 12571 | // data |
| 12572 | 'h', 'e', 'l', 'l', |
| 12573 | 'o', ' ', 'w', 'o', |
| 12574 | 'r', 'l', 'd', '!', |
| 12575 | // second coalesced packet |
| 12576 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12577 | // 4-byte packet number) |
| 12578 | 0xD3, |
| 12579 | // version |
| 12580 | QUIC_VERSION_BYTES, |
| 12581 | // destination connection ID length |
| 12582 | 0x08, |
| 12583 | // destination connection ID |
| 12584 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12585 | // source connection ID length |
| 12586 | 0x00, |
| 12587 | // long header packet length |
| 12588 | 0x1E, |
| 12589 | // packet number |
| 12590 | 0x12, 0x34, 0x56, 0x79, |
| 12591 | // frame type (stream frame with fin) |
| 12592 | 0xFE, |
| 12593 | // stream id |
| 12594 | 0x02, 0x03, 0x04, |
| 12595 | // offset |
| 12596 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 12597 | // data length |
| 12598 | 0x00, 0x0c, |
| 12599 | // data |
| 12600 | 'H', 'E', 'L', 'L', |
| 12601 | 'O', '_', 'W', 'O', |
| 12602 | 'R', 'L', 'D', '?', |
| 12603 | }; |
| 12604 | unsigned char packet99[] = { |
| 12605 | // first coalesced packet |
| 12606 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12607 | // 4-byte packet number) |
| 12608 | 0xD3, |
| 12609 | // version |
| 12610 | QUIC_VERSION_BYTES, |
| 12611 | // destination connection ID length |
| 12612 | 0x08, |
| 12613 | // destination connection ID |
| 12614 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12615 | // source connection ID length |
| 12616 | 0x00, |
| 12617 | // long header packet length |
| 12618 | 0x1E, |
| 12619 | // packet number |
| 12620 | 0x12, 0x34, 0x56, 0x78, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12621 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12622 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12623 | // stream id |
| 12624 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12625 | // offset |
| 12626 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12627 | 0x32, 0x10, 0x76, 0x54, |
| 12628 | // data length |
| 12629 | kVarInt62OneByte + 0x0c, |
| 12630 | // data |
| 12631 | 'h', 'e', 'l', 'l', |
| 12632 | 'o', ' ', 'w', 'o', |
| 12633 | 'r', 'l', 'd', '!', |
| 12634 | // second coalesced packet |
| 12635 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12636 | // 4-byte packet number) |
| 12637 | 0xD3, |
| 12638 | // version |
| 12639 | QUIC_VERSION_BYTES, |
| 12640 | // destination connection ID length |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 12641 | 0x08, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12642 | // destination connection ID |
| 12643 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 12644 | // source connection ID length |
| 12645 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12646 | // long header packet length |
| 12647 | 0x1E, |
| 12648 | // packet number |
| 12649 | 0x12, 0x34, 0x56, 0x79, |
| 12650 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12651 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12652 | // stream id |
| 12653 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12654 | // offset |
| 12655 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12656 | 0x32, 0x10, 0x76, 0x54, |
| 12657 | // data length |
| 12658 | kVarInt62OneByte + 0x0c, |
| 12659 | // data |
| 12660 | 'H', 'E', 'L', 'L', |
| 12661 | 'O', '_', 'W', 'O', |
| 12662 | 'R', 'L', 'D', '?', |
| 12663 | }; |
| 12664 | // clang-format on |
| 12665 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12666 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 12667 | size_t p_length = ABSL_ARRAYSIZE(packet); |
dschinazi | 40f0b3d | 2020-02-19 17:54:05 -0800 | [diff] [blame] | 12668 | if (framer_.version().HasIetfQuicFrames()) { |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12669 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 12670 | p_length = ABSL_ARRAYSIZE(packet99); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 12671 | } |
| 12672 | |
| 12673 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12674 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 12675 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 12676 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12677 | ASSERT_TRUE(visitor_.header_.get()); |
| 12678 | |
| 12679 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 12680 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12681 | |
| 12682 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12683 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 12684 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 12685 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 12686 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 12687 | |
| 12688 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 1u); |
| 12689 | EXPECT_TRUE(framer_.ProcessPacket(*visitor_.coalesced_packets_[0].get())); |
| 12690 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 12691 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12692 | ASSERT_TRUE(visitor_.header_.get()); |
| 12693 | |
| 12694 | ASSERT_EQ(2u, visitor_.stream_frames_.size()); |
| 12695 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12696 | |
| 12697 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12698 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[1]->stream_id); |
| 12699 | EXPECT_TRUE(visitor_.stream_frames_[1]->fin); |
| 12700 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[1]->offset); |
| 12701 | CheckStreamFrameData("HELLO_WORLD?", visitor_.stream_frames_[1].get()); |
| 12702 | } |
| 12703 | |
fayang | d1160ff | 2020-02-26 11:57:09 -0800 | [diff] [blame] | 12704 | TEST_P(QuicFramerTest, CoalescedPacketWithUdpPadding) { |
| 12705 | if (!framer_.version().HasLongHeaderLengths()) { |
| 12706 | return; |
| 12707 | } |
| 12708 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
| 12709 | // clang-format off |
| 12710 | unsigned char packet[] = { |
| 12711 | // first coalesced packet |
| 12712 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12713 | // 4-byte packet number) |
| 12714 | 0xD3, |
| 12715 | // version |
| 12716 | QUIC_VERSION_BYTES, |
| 12717 | // destination connection ID length |
| 12718 | 0x08, |
| 12719 | // destination connection ID |
| 12720 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12721 | // source connection ID length |
| 12722 | 0x00, |
| 12723 | // long header packet length |
| 12724 | 0x1E, |
| 12725 | // packet number |
| 12726 | 0x12, 0x34, 0x56, 0x78, |
| 12727 | // frame type (stream frame with fin) |
| 12728 | 0xFE, |
| 12729 | // stream id |
| 12730 | 0x02, 0x03, 0x04, |
| 12731 | // offset |
| 12732 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 12733 | // data length |
| 12734 | 0x00, 0x0c, |
| 12735 | // data |
| 12736 | 'h', 'e', 'l', 'l', |
| 12737 | 'o', ' ', 'w', 'o', |
| 12738 | 'r', 'l', 'd', '!', |
| 12739 | // padding |
| 12740 | 0x00, 0x00, 0x00, 0x00, |
| 12741 | 0x00, 0x00, 0x00, 0x00, |
| 12742 | 0x00, 0x00, 0x00, 0x00, |
| 12743 | 0x00, 0x00, 0x00, 0x00, |
| 12744 | 0x00, 0x00, 0x00, 0x00, |
| 12745 | }; |
| 12746 | unsigned char packet99[] = { |
| 12747 | // first coalesced packet |
| 12748 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12749 | // 4-byte packet number) |
| 12750 | 0xD3, |
| 12751 | // version |
| 12752 | QUIC_VERSION_BYTES, |
| 12753 | // destination connection ID length |
| 12754 | 0x08, |
| 12755 | // destination connection ID |
| 12756 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12757 | // source connection ID length |
| 12758 | 0x00, |
| 12759 | // long header packet length |
| 12760 | 0x1E, |
| 12761 | // packet number |
| 12762 | 0x12, 0x34, 0x56, 0x78, |
| 12763 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12764 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12765 | // stream id |
| 12766 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12767 | // offset |
| 12768 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12769 | 0x32, 0x10, 0x76, 0x54, |
| 12770 | // data length |
| 12771 | kVarInt62OneByte + 0x0c, |
| 12772 | // data |
| 12773 | 'h', 'e', 'l', 'l', |
| 12774 | 'o', ' ', 'w', 'o', |
| 12775 | 'r', 'l', 'd', '!', |
| 12776 | // padding |
| 12777 | 0x00, 0x00, 0x00, 0x00, |
| 12778 | 0x00, 0x00, 0x00, 0x00, |
| 12779 | 0x00, 0x00, 0x00, 0x00, |
| 12780 | 0x00, 0x00, 0x00, 0x00, |
| 12781 | 0x00, 0x00, 0x00, 0x00, |
| 12782 | }; |
| 12783 | // clang-format on |
| 12784 | |
| 12785 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 12786 | size_t p_length = ABSL_ARRAYSIZE(packet); |
fayang | d1160ff | 2020-02-26 11:57:09 -0800 | [diff] [blame] | 12787 | if (framer_.version().HasIetfQuicFrames()) { |
| 12788 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 12789 | p_length = ABSL_ARRAYSIZE(packet99); |
fayang | d1160ff | 2020-02-26 11:57:09 -0800 | [diff] [blame] | 12790 | } |
| 12791 | |
| 12792 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
| 12793 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 12794 | |
| 12795 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
| 12796 | ASSERT_TRUE(visitor_.header_.get()); |
| 12797 | |
| 12798 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 12799 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12800 | |
| 12801 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12802 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 12803 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 12804 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 12805 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 12806 | |
| 12807 | EXPECT_EQ(visitor_.coalesced_packets_.size(), 0u); |
| 12808 | } |
| 12809 | |
| 12810 | TEST_P(QuicFramerTest, CoalescedPacketWithDifferentVersion) { |
| 12811 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 12812 | return; |
| 12813 | } |
fayang | d1160ff | 2020-02-26 11:57:09 -0800 | [diff] [blame] | 12814 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
| 12815 | // clang-format off |
| 12816 | unsigned char packet[] = { |
| 12817 | // first coalesced packet |
| 12818 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12819 | // 4-byte packet number) |
| 12820 | 0xD3, |
| 12821 | // version |
| 12822 | QUIC_VERSION_BYTES, |
| 12823 | // destination connection ID length |
| 12824 | 0x08, |
| 12825 | // destination connection ID |
| 12826 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12827 | // source connection ID length |
| 12828 | 0x00, |
| 12829 | // long header packet length |
| 12830 | 0x1E, |
| 12831 | // packet number |
| 12832 | 0x12, 0x34, 0x56, 0x78, |
| 12833 | // frame type (stream frame with fin) |
| 12834 | 0xFE, |
| 12835 | // stream id |
| 12836 | 0x02, 0x03, 0x04, |
| 12837 | // offset |
| 12838 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 12839 | // data length |
| 12840 | 0x00, 0x0c, |
| 12841 | // data |
| 12842 | 'h', 'e', 'l', 'l', |
| 12843 | 'o', ' ', 'w', 'o', |
| 12844 | 'r', 'l', 'd', '!', |
| 12845 | // second coalesced packet |
| 12846 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12847 | // 4-byte packet number) |
| 12848 | 0xD3, |
| 12849 | // garbage version |
| 12850 | 'G', 'A', 'B', 'G', |
| 12851 | // destination connection ID length |
| 12852 | 0x08, |
| 12853 | // destination connection ID |
| 12854 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12855 | // source connection ID length |
| 12856 | 0x00, |
| 12857 | // long header packet length |
| 12858 | 0x1E, |
| 12859 | // packet number |
| 12860 | 0x12, 0x34, 0x56, 0x79, |
| 12861 | // frame type (stream frame with fin) |
| 12862 | 0xFE, |
| 12863 | // stream id |
| 12864 | 0x02, 0x03, 0x04, |
| 12865 | // offset |
| 12866 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 12867 | // data length |
| 12868 | 0x00, 0x0c, |
| 12869 | // data |
| 12870 | 'H', 'E', 'L', 'L', |
| 12871 | 'O', '_', 'W', 'O', |
| 12872 | 'R', 'L', 'D', '?', |
| 12873 | }; |
| 12874 | unsigned char packet99[] = { |
| 12875 | // first coalesced packet |
| 12876 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12877 | // 4-byte packet number) |
| 12878 | 0xD3, |
| 12879 | // version |
| 12880 | QUIC_VERSION_BYTES, |
| 12881 | // destination connection ID length |
| 12882 | 0x08, |
| 12883 | // destination connection ID |
| 12884 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12885 | // source connection ID length |
| 12886 | 0x00, |
| 12887 | // long header packet length |
| 12888 | 0x1E, |
| 12889 | // packet number |
| 12890 | 0x12, 0x34, 0x56, 0x78, |
| 12891 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12892 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12893 | // stream id |
| 12894 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12895 | // offset |
| 12896 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12897 | 0x32, 0x10, 0x76, 0x54, |
| 12898 | // data length |
| 12899 | kVarInt62OneByte + 0x0c, |
| 12900 | // data |
| 12901 | 'h', 'e', 'l', 'l', |
| 12902 | 'o', ' ', 'w', 'o', |
| 12903 | 'r', 'l', 'd', '!', |
| 12904 | // second coalesced packet |
| 12905 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12906 | // 4-byte packet number) |
| 12907 | 0xD3, |
| 12908 | // garbage version |
| 12909 | 'G', 'A', 'B', 'G', |
| 12910 | // destination connection ID length |
| 12911 | 0x08, |
| 12912 | // destination connection ID |
| 12913 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12914 | // source connection ID length |
| 12915 | 0x00, |
| 12916 | // long header packet length |
| 12917 | 0x1E, |
| 12918 | // packet number |
| 12919 | 0x12, 0x34, 0x56, 0x79, |
| 12920 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12921 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12922 | // stream id |
| 12923 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12924 | // offset |
| 12925 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12926 | 0x32, 0x10, 0x76, 0x54, |
| 12927 | // data length |
| 12928 | kVarInt62OneByte + 0x0c, |
| 12929 | // data |
| 12930 | 'H', 'E', 'L', 'L', |
| 12931 | 'O', '_', 'W', 'O', |
| 12932 | 'R', 'L', 'D', '?', |
| 12933 | }; |
| 12934 | // clang-format on |
| 12935 | |
| 12936 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 12937 | size_t p_length = ABSL_ARRAYSIZE(packet); |
fayang | d1160ff | 2020-02-26 11:57:09 -0800 | [diff] [blame] | 12938 | if (framer_.version().HasIetfQuicFrames()) { |
| 12939 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 12940 | p_length = ABSL_ARRAYSIZE(packet99); |
fayang | d1160ff | 2020-02-26 11:57:09 -0800 | [diff] [blame] | 12941 | } |
| 12942 | |
| 12943 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
| 12944 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 12945 | |
| 12946 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
| 12947 | ASSERT_TRUE(visitor_.header_.get()); |
| 12948 | |
| 12949 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 12950 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12951 | |
| 12952 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12953 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 12954 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 12955 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 12956 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 12957 | |
| 12958 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 1u); |
| 12959 | EXPECT_TRUE(framer_.ProcessPacket(*visitor_.coalesced_packets_[0].get())); |
| 12960 | |
| 12961 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
| 12962 | ASSERT_TRUE(visitor_.header_.get()); |
| 12963 | |
| 12964 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 12965 | // Verify version mismatch gets reported. |
| 12966 | EXPECT_EQ(1, visitor_.version_mismatch_); |
| 12967 | } |
| 12968 | |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12969 | TEST_P(QuicFramerTest, UndecryptablePacketWithoutDecrypter) { |
| 12970 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 12971 | |
| 12972 | if (!framer_.version().KnowsWhichDecrypterToUse()) { |
| 12973 | // We create a bad client decrypter by using initial encryption with a |
| 12974 | // bogus connection ID; it should fail to decrypt everything. |
| 12975 | QuicConnectionId bogus_connection_id = TestConnectionId(0xbad); |
| 12976 | CrypterPair bogus_crypters; |
nharper | c8d9e40 | 2019-09-12 18:30:14 -0700 | [diff] [blame] | 12977 | CryptoUtils::CreateInitialObfuscators(Perspective::IS_CLIENT, |
| 12978 | framer_.version(), |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12979 | bogus_connection_id, &bogus_crypters); |
| 12980 | // This removes all other decrypters. |
| 12981 | framer_.SetDecrypter(ENCRYPTION_FORWARD_SECURE, |
| 12982 | std::move(bogus_crypters.decrypter)); |
| 12983 | } |
| 12984 | |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 12985 | // clang-format off |
| 12986 | unsigned char packet[] = { |
| 12987 | // public flags (version included, 8-byte connection ID, |
| 12988 | // 4-byte packet number) |
| 12989 | 0x28, |
| 12990 | // connection_id |
| 12991 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12992 | // packet number |
| 12993 | 0x12, 0x34, 0x56, 0x00, |
| 12994 | // padding frames |
| 12995 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12996 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12997 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12998 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 12999 | }; |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 13000 | unsigned char packet46[] = { |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 13001 | // public flags (long header with packet type HANDSHAKE and |
| 13002 | // 4-byte packet number) |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 13003 | 0xE3, |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 13004 | // version |
| 13005 | QUIC_VERSION_BYTES, |
| 13006 | // connection ID lengths |
| 13007 | 0x05, |
| 13008 | // source connection ID |
| 13009 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13010 | // long header packet length |
| 13011 | 0x05, |
| 13012 | // packet number |
| 13013 | 0x12, 0x34, 0x56, 0x00, |
| 13014 | // padding frames |
| 13015 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13016 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13017 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13018 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13019 | }; |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13020 | unsigned char packet49[] = { |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 13021 | // public flags (long header with packet type HANDSHAKE and |
| 13022 | // 4-byte packet number) |
| 13023 | 0xE3, |
| 13024 | // version |
| 13025 | QUIC_VERSION_BYTES, |
| 13026 | // destination connection ID length |
| 13027 | 0x00, |
| 13028 | // source connection ID length |
| 13029 | 0x08, |
| 13030 | // source connection ID |
| 13031 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13032 | // long header packet length |
| 13033 | 0x24, |
| 13034 | // packet number |
| 13035 | 0x12, 0x34, 0x56, 0x00, |
| 13036 | // padding frames |
| 13037 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13038 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13039 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13040 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13041 | }; |
| 13042 | // clang-format on |
| 13043 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13044 | size_t p_length = ABSL_ARRAYSIZE(packet); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 13045 | if (framer_.version().HasLongHeaderLengths()) { |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13046 | p = packet49; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13047 | p_length = ABSL_ARRAYSIZE(packet49); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 13048 | } else if (framer_.version().HasIetfInvariantHeader()) { |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 13049 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13050 | p_length = ABSL_ARRAYSIZE(packet46); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 13051 | } |
| 13052 | // First attempt decryption without the handshake crypter. |
| 13053 | EXPECT_FALSE( |
| 13054 | framer_.ProcessPacket(QuicEncryptedPacket(AsChars(p), p_length, false))); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13055 | EXPECT_THAT(framer_.error(), IsError(QUIC_DECRYPTION_FAILURE)); |
| 13056 | ASSERT_EQ(1u, visitor_.undecryptable_packets_.size()); |
| 13057 | ASSERT_EQ(1u, visitor_.undecryptable_decryption_levels_.size()); |
| 13058 | ASSERT_EQ(1u, visitor_.undecryptable_has_decryption_keys_.size()); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 13059 | quiche::test::CompareCharArraysWithHexError( |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13060 | "undecryptable packet", visitor_.undecryptable_packets_[0]->data(), |
| 13061 | visitor_.undecryptable_packets_[0]->length(), AsChars(p), p_length); |
| 13062 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 13063 | EXPECT_EQ(ENCRYPTION_HANDSHAKE, |
| 13064 | visitor_.undecryptable_decryption_levels_[0]); |
| 13065 | } |
| 13066 | EXPECT_FALSE(visitor_.undecryptable_has_decryption_keys_[0]); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 13067 | } |
| 13068 | |
| 13069 | TEST_P(QuicFramerTest, UndecryptablePacketWithDecrypter) { |
| 13070 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 13071 | |
| 13072 | // We create a bad client decrypter by using initial encryption with a |
| 13073 | // bogus connection ID; it should fail to decrypt everything. |
| 13074 | QuicConnectionId bogus_connection_id = TestConnectionId(0xbad); |
| 13075 | CrypterPair bad_handshake_crypters; |
nharper | c8d9e40 | 2019-09-12 18:30:14 -0700 | [diff] [blame] | 13076 | CryptoUtils::CreateInitialObfuscators(Perspective::IS_CLIENT, |
| 13077 | framer_.version(), bogus_connection_id, |
| 13078 | &bad_handshake_crypters); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 13079 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 13080 | framer_.InstallDecrypter(ENCRYPTION_HANDSHAKE, |
| 13081 | std::move(bad_handshake_crypters.decrypter)); |
| 13082 | } else { |
| 13083 | framer_.SetDecrypter(ENCRYPTION_HANDSHAKE, |
| 13084 | std::move(bad_handshake_crypters.decrypter)); |
| 13085 | } |
| 13086 | |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 13087 | // clang-format off |
| 13088 | unsigned char packet[] = { |
| 13089 | // public flags (version included, 8-byte connection ID, |
| 13090 | // 4-byte packet number) |
| 13091 | 0x28, |
| 13092 | // connection_id |
| 13093 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13094 | // packet number |
| 13095 | 0x12, 0x34, 0x56, 0x00, |
| 13096 | // padding frames |
| 13097 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13098 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13099 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13100 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13101 | }; |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 13102 | unsigned char packet46[] = { |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 13103 | // public flags (long header with packet type HANDSHAKE and |
| 13104 | // 4-byte packet number) |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 13105 | 0xE3, |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 13106 | // version |
| 13107 | QUIC_VERSION_BYTES, |
| 13108 | // connection ID lengths |
| 13109 | 0x05, |
| 13110 | // source connection ID |
| 13111 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13112 | // long header packet length |
| 13113 | 0x05, |
| 13114 | // packet number |
| 13115 | 0x12, 0x34, 0x56, 0x00, |
| 13116 | // padding frames |
| 13117 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13118 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13119 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13120 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13121 | }; |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13122 | unsigned char packet49[] = { |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 13123 | // public flags (long header with packet type HANDSHAKE and |
| 13124 | // 4-byte packet number) |
| 13125 | 0xE3, |
| 13126 | // version |
| 13127 | QUIC_VERSION_BYTES, |
| 13128 | // destination connection ID length |
| 13129 | 0x00, |
| 13130 | // source connection ID length |
| 13131 | 0x08, |
| 13132 | // source connection ID |
| 13133 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13134 | // long header packet length |
| 13135 | 0x24, |
| 13136 | // packet number |
| 13137 | 0x12, 0x34, 0x56, 0x00, |
| 13138 | // padding frames |
| 13139 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13140 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13141 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13142 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 13143 | }; |
| 13144 | // clang-format on |
| 13145 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13146 | size_t p_length = ABSL_ARRAYSIZE(packet); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 13147 | if (framer_.version().HasLongHeaderLengths()) { |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13148 | p = packet49; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13149 | p_length = ABSL_ARRAYSIZE(packet49); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 13150 | } else if (framer_.version().HasIetfInvariantHeader()) { |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 13151 | p = packet46; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13152 | p_length = ABSL_ARRAYSIZE(packet46); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 13153 | } |
| 13154 | |
| 13155 | EXPECT_FALSE( |
| 13156 | framer_.ProcessPacket(QuicEncryptedPacket(AsChars(p), p_length, false))); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13157 | EXPECT_THAT(framer_.error(), IsError(QUIC_DECRYPTION_FAILURE)); |
| 13158 | ASSERT_EQ(1u, visitor_.undecryptable_packets_.size()); |
| 13159 | ASSERT_EQ(1u, visitor_.undecryptable_decryption_levels_.size()); |
| 13160 | ASSERT_EQ(1u, visitor_.undecryptable_has_decryption_keys_.size()); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 13161 | quiche::test::CompareCharArraysWithHexError( |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13162 | "undecryptable packet", visitor_.undecryptable_packets_[0]->data(), |
| 13163 | visitor_.undecryptable_packets_[0]->length(), AsChars(p), p_length); |
| 13164 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 13165 | EXPECT_EQ(ENCRYPTION_HANDSHAKE, |
| 13166 | visitor_.undecryptable_decryption_levels_[0]); |
| 13167 | } |
| 13168 | EXPECT_EQ(framer_.version().KnowsWhichDecrypterToUse(), |
| 13169 | visitor_.undecryptable_has_decryption_keys_[0]); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 13170 | } |
| 13171 | |
| 13172 | TEST_P(QuicFramerTest, UndecryptableCoalescedPacket) { |
| 13173 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 13174 | return; |
| 13175 | } |
| 13176 | ASSERT_TRUE(framer_.version().KnowsWhichDecrypterToUse()); |
| 13177 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
| 13178 | // We create a bad client decrypter by using initial encryption with a |
| 13179 | // bogus connection ID; it should fail to decrypt everything. |
| 13180 | QuicConnectionId bogus_connection_id = TestConnectionId(0xbad); |
| 13181 | CrypterPair bad_handshake_crypters; |
nharper | c8d9e40 | 2019-09-12 18:30:14 -0700 | [diff] [blame] | 13182 | CryptoUtils::CreateInitialObfuscators(Perspective::IS_CLIENT, |
| 13183 | framer_.version(), bogus_connection_id, |
| 13184 | &bad_handshake_crypters); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 13185 | framer_.InstallDecrypter(ENCRYPTION_HANDSHAKE, |
| 13186 | std::move(bad_handshake_crypters.decrypter)); |
| 13187 | // clang-format off |
| 13188 | unsigned char packet[] = { |
| 13189 | // first coalesced packet |
| 13190 | // public flags (long header with packet type HANDSHAKE and |
| 13191 | // 4-byte packet number) |
| 13192 | 0xE3, |
| 13193 | // version |
| 13194 | QUIC_VERSION_BYTES, |
| 13195 | // destination connection ID length |
| 13196 | 0x08, |
| 13197 | // destination connection ID |
| 13198 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13199 | // source connection ID length |
| 13200 | 0x00, |
| 13201 | // long header packet length |
| 13202 | 0x1E, |
| 13203 | // packet number |
| 13204 | 0x12, 0x34, 0x56, 0x78, |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13205 | // frame type (stream frame with fin) |
| 13206 | 0xFE, |
| 13207 | // stream id |
| 13208 | 0x02, 0x03, 0x04, |
| 13209 | // offset |
| 13210 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 13211 | // data length |
| 13212 | 0x00, 0x0c, |
| 13213 | // data |
| 13214 | 'h', 'e', 'l', 'l', |
| 13215 | 'o', ' ', 'w', 'o', |
| 13216 | 'r', 'l', 'd', '!', |
| 13217 | // second coalesced packet |
| 13218 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13219 | // 4-byte packet number) |
| 13220 | 0xD3, |
| 13221 | // version |
| 13222 | QUIC_VERSION_BYTES, |
| 13223 | // destination connection ID length |
| 13224 | 0x08, |
| 13225 | // destination connection ID |
| 13226 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13227 | // source connection ID length |
| 13228 | 0x00, |
| 13229 | // long header packet length |
| 13230 | 0x1E, |
| 13231 | // packet number |
| 13232 | 0x12, 0x34, 0x56, 0x79, |
| 13233 | // frame type (stream frame with fin) |
| 13234 | 0xFE, |
| 13235 | // stream id |
| 13236 | 0x02, 0x03, 0x04, |
| 13237 | // offset |
| 13238 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 13239 | // data length |
| 13240 | 0x00, 0x0c, |
| 13241 | // data |
| 13242 | 'H', 'E', 'L', 'L', |
| 13243 | 'O', '_', 'W', 'O', |
| 13244 | 'R', 'L', 'D', '?', |
| 13245 | }; |
| 13246 | unsigned char packet99[] = { |
| 13247 | // first coalesced packet |
| 13248 | // public flags (long header with packet type HANDSHAKE and |
| 13249 | // 4-byte packet number) |
| 13250 | 0xE3, |
| 13251 | // version |
| 13252 | QUIC_VERSION_BYTES, |
| 13253 | // destination connection ID length |
| 13254 | 0x08, |
| 13255 | // destination connection ID |
| 13256 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13257 | // source connection ID length |
| 13258 | 0x00, |
| 13259 | // long header packet length |
| 13260 | 0x1E, |
| 13261 | // packet number |
| 13262 | 0x12, 0x34, 0x56, 0x78, |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 13263 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 13264 | 0x08 | 0x01 | 0x02 | 0x04, |
| 13265 | // stream id |
| 13266 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 13267 | // offset |
| 13268 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 13269 | 0x32, 0x10, 0x76, 0x54, |
| 13270 | // data length |
| 13271 | kVarInt62OneByte + 0x0c, |
| 13272 | // data |
| 13273 | 'h', 'e', 'l', 'l', |
| 13274 | 'o', ' ', 'w', 'o', |
| 13275 | 'r', 'l', 'd', '!', |
| 13276 | // second coalesced packet |
| 13277 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13278 | // 4-byte packet number) |
| 13279 | 0xD3, |
| 13280 | // version |
| 13281 | QUIC_VERSION_BYTES, |
| 13282 | // destination connection ID length |
| 13283 | 0x08, |
| 13284 | // destination connection ID |
| 13285 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13286 | // source connection ID length |
| 13287 | 0x00, |
| 13288 | // long header packet length |
| 13289 | 0x1E, |
| 13290 | // packet number |
| 13291 | 0x12, 0x34, 0x56, 0x79, |
| 13292 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 13293 | 0x08 | 0x01 | 0x02 | 0x04, |
| 13294 | // stream id |
| 13295 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 13296 | // offset |
| 13297 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 13298 | 0x32, 0x10, 0x76, 0x54, |
| 13299 | // data length |
| 13300 | kVarInt62OneByte + 0x0c, |
| 13301 | // data |
| 13302 | 'H', 'E', 'L', 'L', |
| 13303 | 'O', '_', 'W', 'O', |
| 13304 | 'R', 'L', 'D', '?', |
| 13305 | }; |
| 13306 | // clang-format on |
| 13307 | const size_t length_of_first_coalesced_packet = 46; |
| 13308 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13309 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13310 | size_t p_length = ABSL_ARRAYSIZE(packet); |
dschinazi | 40f0b3d | 2020-02-19 17:54:05 -0800 | [diff] [blame] | 13311 | if (framer_.version().HasIetfQuicFrames()) { |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13312 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13313 | p_length = ABSL_ARRAYSIZE(packet99); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13314 | } |
| 13315 | |
| 13316 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
| 13317 | |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 13318 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 13319 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13320 | EXPECT_THAT(framer_.error(), IsError(QUIC_DECRYPTION_FAILURE)); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 13321 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13322 | ASSERT_EQ(1u, visitor_.undecryptable_packets_.size()); |
| 13323 | ASSERT_EQ(1u, visitor_.undecryptable_decryption_levels_.size()); |
| 13324 | ASSERT_EQ(1u, visitor_.undecryptable_has_decryption_keys_.size()); |
| 13325 | // Make sure we only receive the first undecryptable packet and not the |
| 13326 | // full packet including the second coalesced packet. |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 13327 | quiche::test::CompareCharArraysWithHexError( |
| 13328 | "undecryptable packet", visitor_.undecryptable_packets_[0]->data(), |
| 13329 | visitor_.undecryptable_packets_[0]->length(), AsChars(p), |
| 13330 | length_of_first_coalesced_packet); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13331 | EXPECT_EQ(ENCRYPTION_HANDSHAKE, visitor_.undecryptable_decryption_levels_[0]); |
| 13332 | EXPECT_TRUE(visitor_.undecryptable_has_decryption_keys_[0]); |
dschinazi | 4b5a68a | 2019-08-15 15:45:36 -0700 | [diff] [blame] | 13333 | |
| 13334 | // Make sure the second coalesced packet is parsed correctly. |
| 13335 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 1u); |
| 13336 | EXPECT_TRUE(framer_.ProcessPacket(*visitor_.coalesced_packets_[0].get())); |
| 13337 | |
| 13338 | ASSERT_TRUE(visitor_.header_.get()); |
| 13339 | |
| 13340 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 13341 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 13342 | |
| 13343 | // Stream ID should be the last 3 bytes of kStreamId. |
| 13344 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 13345 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 13346 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 13347 | CheckStreamFrameData("HELLO_WORLD?", visitor_.stream_frames_[0].get()); |
| 13348 | } |
| 13349 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13350 | TEST_P(QuicFramerTest, MismatchedCoalescedPacket) { |
| 13351 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 13352 | return; |
| 13353 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13354 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13355 | // clang-format off |
| 13356 | unsigned char packet[] = { |
| 13357 | // first coalesced packet |
| 13358 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13359 | // 4-byte packet number) |
| 13360 | 0xD3, |
| 13361 | // version |
| 13362 | QUIC_VERSION_BYTES, |
| 13363 | // destination connection ID length |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13364 | 0x08, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13365 | // destination connection ID |
| 13366 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13367 | // source connection ID length |
| 13368 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13369 | // long header packet length |
| 13370 | 0x1E, |
| 13371 | // packet number |
| 13372 | 0x12, 0x34, 0x56, 0x78, |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13373 | // frame type (stream frame with fin) |
| 13374 | 0xFE, |
| 13375 | // stream id |
| 13376 | 0x02, 0x03, 0x04, |
| 13377 | // offset |
| 13378 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 13379 | // data length |
| 13380 | 0x00, 0x0c, |
| 13381 | // data |
| 13382 | 'h', 'e', 'l', 'l', |
| 13383 | 'o', ' ', 'w', 'o', |
| 13384 | 'r', 'l', 'd', '!', |
| 13385 | // second coalesced packet |
| 13386 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13387 | // 4-byte packet number) |
| 13388 | 0xD3, |
| 13389 | // version |
| 13390 | QUIC_VERSION_BYTES, |
| 13391 | // destination connection ID length |
| 13392 | 0x08, |
| 13393 | // destination connection ID |
| 13394 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 13395 | // source connection ID length |
| 13396 | 0x00, |
| 13397 | // long header packet length |
| 13398 | 0x1E, |
| 13399 | // packet number |
| 13400 | 0x12, 0x34, 0x56, 0x79, |
| 13401 | // frame type (stream frame with fin) |
| 13402 | 0xFE, |
| 13403 | // stream id |
| 13404 | 0x02, 0x03, 0x04, |
| 13405 | // offset |
| 13406 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 13407 | // data length |
| 13408 | 0x00, 0x0c, |
| 13409 | // data |
| 13410 | 'H', 'E', 'L', 'L', |
| 13411 | 'O', '_', 'W', 'O', |
| 13412 | 'R', 'L', 'D', '?', |
| 13413 | }; |
| 13414 | unsigned char packet99[] = { |
| 13415 | // first coalesced packet |
| 13416 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13417 | // 4-byte packet number) |
| 13418 | 0xD3, |
| 13419 | // version |
| 13420 | QUIC_VERSION_BYTES, |
| 13421 | // destination connection ID length |
| 13422 | 0x08, |
| 13423 | // destination connection ID |
| 13424 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13425 | // source connection ID length |
| 13426 | 0x00, |
| 13427 | // long header packet length |
| 13428 | 0x1E, |
| 13429 | // packet number |
| 13430 | 0x12, 0x34, 0x56, 0x78, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13431 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 13432 | 0x08 | 0x01 | 0x02 | 0x04, |
| 13433 | // stream id |
| 13434 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 13435 | // offset |
| 13436 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 13437 | 0x32, 0x10, 0x76, 0x54, |
| 13438 | // data length |
| 13439 | kVarInt62OneByte + 0x0c, |
| 13440 | // data |
| 13441 | 'h', 'e', 'l', 'l', |
| 13442 | 'o', ' ', 'w', 'o', |
| 13443 | 'r', 'l', 'd', '!', |
| 13444 | // second coalesced packet |
| 13445 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13446 | // 4-byte packet number) |
| 13447 | 0xD3, |
| 13448 | // version |
| 13449 | QUIC_VERSION_BYTES, |
| 13450 | // destination connection ID length |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13451 | 0x08, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13452 | // destination connection ID |
| 13453 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13454 | // source connection ID length |
| 13455 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13456 | // long header packet length |
| 13457 | 0x1E, |
| 13458 | // packet number |
| 13459 | 0x12, 0x34, 0x56, 0x79, |
| 13460 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 13461 | 0x08 | 0x01 | 0x02 | 0x04, |
| 13462 | // stream id |
| 13463 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 13464 | // offset |
| 13465 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 13466 | 0x32, 0x10, 0x76, 0x54, |
| 13467 | // data length |
| 13468 | kVarInt62OneByte + 0x0c, |
| 13469 | // data |
| 13470 | 'H', 'E', 'L', 'L', |
| 13471 | 'O', '_', 'W', 'O', |
| 13472 | 'R', 'L', 'D', '?', |
| 13473 | }; |
| 13474 | // clang-format on |
| 13475 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13476 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13477 | size_t p_length = ABSL_ARRAYSIZE(packet); |
dschinazi | 40f0b3d | 2020-02-19 17:54:05 -0800 | [diff] [blame] | 13478 | if (framer_.version().HasIetfQuicFrames()) { |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13479 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13480 | p_length = ABSL_ARRAYSIZE(packet99); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13481 | } |
| 13482 | |
| 13483 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
| 13484 | |
fayang | 2e44586 | 2020-04-06 08:39:22 -0700 | [diff] [blame] | 13485 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13486 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13487 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13488 | ASSERT_TRUE(visitor_.header_.get()); |
| 13489 | |
| 13490 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 13491 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 13492 | |
| 13493 | // Stream ID should be the last 3 bytes of kStreamId. |
| 13494 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 13495 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 13496 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 13497 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 13498 | |
| 13499 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 0u); |
| 13500 | } |
| 13501 | |
| 13502 | TEST_P(QuicFramerTest, InvalidCoalescedPacket) { |
| 13503 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 13504 | return; |
| 13505 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13506 | SetDecrypterLevel(ENCRYPTION_ZERO_RTT); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13507 | // clang-format off |
| 13508 | unsigned char packet[] = { |
| 13509 | // first coalesced packet |
| 13510 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13511 | // 4-byte packet number) |
| 13512 | 0xD3, |
| 13513 | // version |
| 13514 | QUIC_VERSION_BYTES, |
| 13515 | // destination connection ID length |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13516 | 0x08, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13517 | // destination connection ID |
| 13518 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13519 | // source connection ID length |
| 13520 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13521 | // long header packet length |
| 13522 | 0x1E, |
| 13523 | // packet number |
| 13524 | 0x12, 0x34, 0x56, 0x78, |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13525 | // frame type (stream frame with fin) |
| 13526 | 0xFE, |
| 13527 | // stream id |
| 13528 | 0x02, 0x03, 0x04, |
| 13529 | // offset |
| 13530 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 13531 | // data length |
| 13532 | 0x00, 0x0c, |
| 13533 | // data |
| 13534 | 'h', 'e', 'l', 'l', |
| 13535 | 'o', ' ', 'w', 'o', |
| 13536 | 'r', 'l', 'd', '!', |
| 13537 | // second coalesced packet |
| 13538 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13539 | // 4-byte packet number) |
| 13540 | 0xD3, |
| 13541 | // version would be here but we cut off the invalid coalesced header. |
| 13542 | }; |
| 13543 | unsigned char packet99[] = { |
| 13544 | // first coalesced packet |
| 13545 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13546 | // 4-byte packet number) |
| 13547 | 0xD3, |
| 13548 | // version |
| 13549 | QUIC_VERSION_BYTES, |
| 13550 | // destination connection ID length |
| 13551 | 0x08, |
| 13552 | // destination connection ID |
| 13553 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13554 | // source connection ID length |
| 13555 | 0x00, |
| 13556 | // long header packet length |
| 13557 | 0x1E, |
| 13558 | // packet number |
| 13559 | 0x12, 0x34, 0x56, 0x78, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13560 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 13561 | 0x08 | 0x01 | 0x02 | 0x04, |
| 13562 | // stream id |
| 13563 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 13564 | // offset |
| 13565 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 13566 | 0x32, 0x10, 0x76, 0x54, |
| 13567 | // data length |
| 13568 | kVarInt62OneByte + 0x0c, |
| 13569 | // data |
| 13570 | 'h', 'e', 'l', 'l', |
| 13571 | 'o', ' ', 'w', 'o', |
| 13572 | 'r', 'l', 'd', '!', |
| 13573 | // second coalesced packet |
| 13574 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13575 | // 4-byte packet number) |
| 13576 | 0xD3, |
| 13577 | // version would be here but we cut off the invalid coalesced header. |
| 13578 | }; |
| 13579 | // clang-format on |
| 13580 | |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13581 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13582 | size_t p_length = ABSL_ARRAYSIZE(packet); |
dschinazi | 40f0b3d | 2020-02-19 17:54:05 -0800 | [diff] [blame] | 13583 | if (framer_.version().HasIetfQuicFrames()) { |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13584 | p = packet99; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13585 | p_length = ABSL_ARRAYSIZE(packet99); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 13586 | } |
| 13587 | |
| 13588 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
| 13589 | |
fayang | d1160ff | 2020-02-26 11:57:09 -0800 | [diff] [blame] | 13590 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13591 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13592 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13593 | ASSERT_TRUE(visitor_.header_.get()); |
| 13594 | |
| 13595 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 13596 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 13597 | |
| 13598 | // Stream ID should be the last 3 bytes of kStreamId. |
| 13599 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 13600 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 13601 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 13602 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 13603 | |
| 13604 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 0u); |
| 13605 | } |
| 13606 | |
dschinazi | a484f98 | 2019-05-23 03:54:44 -0700 | [diff] [blame] | 13607 | // Some IETF implementations send an initial followed by zeroes instead of |
| 13608 | // padding inside the initial. We need to make sure that we still process |
| 13609 | // the initial correctly and ignore the zeroes. |
| 13610 | TEST_P(QuicFramerTest, CoalescedPacketWithZeroesRoundTrip) { |
nharper | c8d9e40 | 2019-09-12 18:30:14 -0700 | [diff] [blame] | 13611 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version()) || |
| 13612 | !framer_.version().UsesInitialObfuscators()) { |
dschinazi | a484f98 | 2019-05-23 03:54:44 -0700 | [diff] [blame] | 13613 | return; |
| 13614 | } |
| 13615 | ASSERT_TRUE(framer_.version().KnowsWhichDecrypterToUse()); |
| 13616 | QuicConnectionId connection_id = FramerTestConnectionId(); |
| 13617 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 13618 | |
| 13619 | CrypterPair client_crypters; |
nharper | c8d9e40 | 2019-09-12 18:30:14 -0700 | [diff] [blame] | 13620 | CryptoUtils::CreateInitialObfuscators(Perspective::IS_CLIENT, |
| 13621 | framer_.version(), connection_id, |
| 13622 | &client_crypters); |
dschinazi | a484f98 | 2019-05-23 03:54:44 -0700 | [diff] [blame] | 13623 | framer_.SetEncrypter(ENCRYPTION_INITIAL, |
| 13624 | std::move(client_crypters.encrypter)); |
| 13625 | |
| 13626 | QuicPacketHeader header; |
| 13627 | header.destination_connection_id = connection_id; |
| 13628 | header.version_flag = true; |
| 13629 | header.packet_number = kPacketNumber; |
| 13630 | header.packet_number_length = PACKET_4BYTE_PACKET_NUMBER; |
| 13631 | header.long_packet_type = INITIAL; |
| 13632 | header.length_length = VARIABLE_LENGTH_INTEGER_LENGTH_2; |
| 13633 | header.retry_token_length_length = VARIABLE_LENGTH_INTEGER_LENGTH_1; |
nharper | 965e592 | 2019-09-23 22:33:54 -0700 | [diff] [blame] | 13634 | QuicFrames frames = {QuicFrame(QuicPingFrame()), |
| 13635 | QuicFrame(QuicPaddingFrame(3))}; |
dschinazi | a484f98 | 2019-05-23 03:54:44 -0700 | [diff] [blame] | 13636 | |
| 13637 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 13638 | ASSERT_NE(nullptr, data); |
| 13639 | |
| 13640 | // Add zeroes after the valid initial packet. |
| 13641 | unsigned char packet[kMaxOutgoingPacketSize] = {}; |
| 13642 | size_t encrypted_length = |
| 13643 | framer_.EncryptPayload(ENCRYPTION_INITIAL, header.packet_number, *data, |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13644 | AsChars(packet), ABSL_ARRAYSIZE(packet)); |
dschinazi | a484f98 | 2019-05-23 03:54:44 -0700 | [diff] [blame] | 13645 | ASSERT_NE(0u, encrypted_length); |
| 13646 | |
| 13647 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 13648 | CrypterPair server_crypters; |
nharper | c8d9e40 | 2019-09-12 18:30:14 -0700 | [diff] [blame] | 13649 | CryptoUtils::CreateInitialObfuscators(Perspective::IS_SERVER, |
| 13650 | framer_.version(), connection_id, |
| 13651 | &server_crypters); |
dschinazi | a484f98 | 2019-05-23 03:54:44 -0700 | [diff] [blame] | 13652 | framer_.InstallDecrypter(ENCRYPTION_INITIAL, |
| 13653 | std::move(server_crypters.decrypter)); |
| 13654 | |
| 13655 | // Make sure the first long header initial packet parses correctly. |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13656 | QuicEncryptedPacket encrypted(AsChars(packet), ABSL_ARRAYSIZE(packet), false); |
dschinazi | a484f98 | 2019-05-23 03:54:44 -0700 | [diff] [blame] | 13657 | |
| 13658 | // Make sure we discard the subsequent zeroes. |
fayang | d1160ff | 2020-02-26 11:57:09 -0800 | [diff] [blame] | 13659 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 13660 | EXPECT_TRUE(visitor_.coalesced_packets_.empty()); |
dschinazi | a484f98 | 2019-05-23 03:54:44 -0700 | [diff] [blame] | 13661 | } |
| 13662 | |
dschinazi | e0df3f7 | 2019-05-06 16:37:51 -0700 | [diff] [blame] | 13663 | TEST_P(QuicFramerTest, ClientReceivesInvalidVersion) { |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 13664 | if (!framer_.version().HasIetfInvariantHeader()) { |
dschinazi | e0df3f7 | 2019-05-06 16:37:51 -0700 | [diff] [blame] | 13665 | return; |
| 13666 | } |
| 13667 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 13668 | |
| 13669 | // clang-format off |
| 13670 | unsigned char packet[] = { |
| 13671 | // public flags (long header with packet type INITIAL) |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 13672 | 0xC3, |
dschinazi | e0df3f7 | 2019-05-06 16:37:51 -0700 | [diff] [blame] | 13673 | // version that is different from the framer's version |
| 13674 | 'Q', '0', '4', '3', |
| 13675 | // connection ID lengths |
| 13676 | 0x05, |
| 13677 | // source connection ID |
| 13678 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 13679 | // packet number |
| 13680 | 0x01, |
| 13681 | // padding frame |
| 13682 | 0x00, |
| 13683 | }; |
| 13684 | // clang-format on |
| 13685 | |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13686 | QuicEncryptedPacket encrypted(AsChars(packet), ABSL_ARRAYSIZE(packet), false); |
dschinazi | e0df3f7 | 2019-05-06 16:37:51 -0700 | [diff] [blame] | 13687 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 13688 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13689 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_VERSION)); |
dschinazi | e0df3f7 | 2019-05-06 16:37:51 -0700 | [diff] [blame] | 13690 | EXPECT_EQ("Client received unexpected version.", framer_.detailed_error()); |
| 13691 | } |
| 13692 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13693 | TEST_P(QuicFramerTest, PacketHeaderWithVariableLengthConnectionId) { |
dschinazi | 97da52b | 2020-01-13 15:44:43 -0800 | [diff] [blame] | 13694 | if (!framer_.version().AllowsVariableLengthConnectionIds()) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13695 | return; |
| 13696 | } |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13697 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13698 | char connection_id_bytes[9] = {0xFE, 0xDC, 0xBA, 0x98, 0x76, |
| 13699 | 0x54, 0x32, 0x10, 0x42}; |
| 13700 | QuicConnectionId connection_id(connection_id_bytes, |
| 13701 | sizeof(connection_id_bytes)); |
| 13702 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
dschinazi | 8ff7482 | 2019-05-28 16:37:20 -0700 | [diff] [blame] | 13703 | QuicFramerPeer::SetExpectedServerConnectionIDLength(&framer_, |
| 13704 | connection_id.length()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13705 | |
| 13706 | // clang-format off |
| 13707 | PacketFragments packet = { |
| 13708 | // type (8 byte connection_id and 1 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13709 | {"Unable to read first byte.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13710 | {0x40}}, |
| 13711 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13712 | {"Unable to read destination connection ID.", |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13713 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42}}, |
| 13714 | // packet number |
| 13715 | {"Unable to read packet number.", |
| 13716 | {0x78}}, |
| 13717 | }; |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13718 | |
| 13719 | PacketFragments packet_with_padding = { |
| 13720 | // type (8 byte connection_id and 1 byte packet number) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13721 | {"Unable to read first byte.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13722 | {0x40}}, |
| 13723 | // connection_id |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13724 | {"Unable to read destination connection ID.", |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13725 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42}}, |
| 13726 | // packet number |
| 13727 | {"", |
| 13728 | {0x78}}, |
| 13729 | // padding |
| 13730 | {"", {0x00, 0x00, 0x00}}, |
| 13731 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13732 | // clang-format on |
| 13733 | |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13734 | PacketFragments& fragments = |
| 13735 | framer_.version().HasHeaderProtection() ? packet_with_padding : packet; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13736 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13737 | AssemblePacketFromFragments(fragments)); |
| 13738 | if (framer_.version().HasHeaderProtection()) { |
| 13739 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13740 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13741 | } else { |
| 13742 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13743 | EXPECT_THAT(framer_.error(), IsError(QUIC_MISSING_PAYLOAD)); |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13744 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13745 | ASSERT_TRUE(visitor_.header_.get()); |
| 13746 | EXPECT_EQ(connection_id, visitor_.header_->destination_connection_id); |
| 13747 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 13748 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 13749 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 13750 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 13751 | |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13752 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13753 | } |
| 13754 | |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13755 | TEST_P(QuicFramerTest, MultiplePacketNumberSpaces) { |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 13756 | if (!framer_.version().HasIetfInvariantHeader()) { |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13757 | return; |
| 13758 | } |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13759 | framer_.EnableMultiplePacketNumberSpacesSupport(); |
| 13760 | |
| 13761 | // clang-format off |
| 13762 | unsigned char long_header_packet[] = { |
| 13763 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13764 | // 4-byte packet number) |
| 13765 | 0xD3, |
| 13766 | // version |
| 13767 | QUIC_VERSION_BYTES, |
| 13768 | // destination connection ID length |
fayang | 91475c4 | 2019-06-19 08:04:26 -0700 | [diff] [blame] | 13769 | 0x50, |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13770 | // destination connection ID |
fayang | 91475c4 | 2019-06-19 08:04:26 -0700 | [diff] [blame] | 13771 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13772 | // packet number |
| 13773 | 0x12, 0x34, 0x56, 0x78, |
| 13774 | // padding frame |
| 13775 | 0x00, |
| 13776 | }; |
| 13777 | unsigned char long_header_packet99[] = { |
| 13778 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13779 | // 4-byte packet number) |
| 13780 | 0xD3, |
| 13781 | // version |
| 13782 | QUIC_VERSION_BYTES, |
| 13783 | // destination connection ID length |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13784 | 0x08, |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13785 | // destination connection ID |
fayang | 91475c4 | 2019-06-19 08:04:26 -0700 | [diff] [blame] | 13786 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13787 | // source connection ID length |
| 13788 | 0x00, |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13789 | // long header packet length |
| 13790 | 0x05, |
| 13791 | // packet number |
| 13792 | 0x12, 0x34, 0x56, 0x78, |
| 13793 | // padding frame |
| 13794 | 0x00, |
| 13795 | }; |
| 13796 | // clang-format on |
| 13797 | |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13798 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 13799 | framer_.InstallDecrypter(ENCRYPTION_ZERO_RTT, |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 13800 | std::make_unique<TestDecrypter>()); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13801 | framer_.RemoveDecrypter(ENCRYPTION_INITIAL); |
| 13802 | } else { |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 13803 | framer_.SetDecrypter(ENCRYPTION_ZERO_RTT, |
| 13804 | std::make_unique<TestDecrypter>()); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13805 | } |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13806 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 13807 | EXPECT_TRUE(framer_.ProcessPacket( |
| 13808 | QuicEncryptedPacket(AsChars(long_header_packet), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13809 | ABSL_ARRAYSIZE(long_header_packet), false))); |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13810 | } else { |
| 13811 | EXPECT_TRUE(framer_.ProcessPacket( |
| 13812 | QuicEncryptedPacket(AsChars(long_header_packet99), |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13813 | ABSL_ARRAYSIZE(long_header_packet99), false))); |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13814 | } |
| 13815 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13816 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13817 | EXPECT_FALSE( |
| 13818 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, INITIAL_DATA) |
| 13819 | .IsInitialized()); |
| 13820 | EXPECT_FALSE( |
| 13821 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, HANDSHAKE_DATA) |
| 13822 | .IsInitialized()); |
| 13823 | EXPECT_EQ(kPacketNumber, QuicFramerPeer::GetLargestDecryptedPacketNumber( |
| 13824 | &framer_, APPLICATION_DATA)); |
| 13825 | |
| 13826 | // clang-format off |
| 13827 | unsigned char short_header_packet[] = { |
| 13828 | // type (short header, 1 byte packet number) |
| 13829 | 0x40, |
| 13830 | // connection_id |
fayang | 91475c4 | 2019-06-19 08:04:26 -0700 | [diff] [blame] | 13831 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13832 | // packet number |
| 13833 | 0x79, |
| 13834 | // padding frame |
nharper | 55fa613 | 2019-05-07 19:37:21 -0700 | [diff] [blame] | 13835 | 0x00, 0x00, 0x00, |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13836 | }; |
| 13837 | // clang-format on |
| 13838 | |
| 13839 | QuicEncryptedPacket short_header_encrypted( |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 13840 | AsChars(short_header_packet), ABSL_ARRAYSIZE(short_header_packet), false); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13841 | if (framer_.version().KnowsWhichDecrypterToUse()) { |
| 13842 | framer_.InstallDecrypter(ENCRYPTION_FORWARD_SECURE, |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 13843 | std::make_unique<TestDecrypter>()); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13844 | framer_.RemoveDecrypter(ENCRYPTION_ZERO_RTT); |
| 13845 | } else { |
| 13846 | framer_.SetDecrypter(ENCRYPTION_FORWARD_SECURE, |
vasilvv | 0fc587f | 2019-09-06 13:33:08 -0700 | [diff] [blame] | 13847 | std::make_unique<TestDecrypter>()); |
zhongyi | 546cc45 | 2019-04-12 15:27:49 -0700 | [diff] [blame] | 13848 | } |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13849 | EXPECT_TRUE(framer_.ProcessPacket(short_header_encrypted)); |
| 13850 | |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13851 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
QUICHE team | 10b22a1 | 2019-03-21 15:31:42 -0700 | [diff] [blame] | 13852 | EXPECT_FALSE( |
| 13853 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, INITIAL_DATA) |
| 13854 | .IsInitialized()); |
| 13855 | EXPECT_FALSE( |
| 13856 | QuicFramerPeer::GetLargestDecryptedPacketNumber(&framer_, HANDSHAKE_DATA) |
| 13857 | .IsInitialized()); |
| 13858 | EXPECT_EQ(kPacketNumber + 1, QuicFramerPeer::GetLargestDecryptedPacketNumber( |
| 13859 | &framer_, APPLICATION_DATA)); |
| 13860 | } |
| 13861 | |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13862 | TEST_P(QuicFramerTest, IetfRetryPacketRejected) { |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 13863 | if (!framer_.version().KnowsWhichDecrypterToUse() || |
| 13864 | framer_.version().SupportsRetry()) { |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13865 | return; |
| 13866 | } |
| 13867 | |
| 13868 | // clang-format off |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 13869 | PacketFragments packet46 = { |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 13870 | // public flags (IETF Retry packet, 0-length original destination CID) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13871 | {"Unable to read first byte.", |
nharper | 9bb8346 | 2019-05-01 10:53:22 -0700 | [diff] [blame] | 13872 | {0xf0}}, |
| 13873 | // version tag |
| 13874 | {"Unable to read protocol version.", |
| 13875 | {QUIC_VERSION_BYTES}}, |
| 13876 | // connection_id length |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 13877 | {"RETRY not supported in this version.", |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13878 | {0x00}}, |
| 13879 | }; |
| 13880 | // clang-format on |
| 13881 | |
| 13882 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 13883 | AssemblePacketFromFragments(packet46)); |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13884 | |
| 13885 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13886 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 13887 | CheckFramingBoundaries(packet46, QUIC_INVALID_PACKET_HEADER); |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13888 | } |
| 13889 | |
| 13890 | TEST_P(QuicFramerTest, RetryPacketRejectedWithMultiplePacketNumberSpaces) { |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 13891 | if (!framer_.version().HasIetfInvariantHeader() || |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 13892 | framer_.version().SupportsRetry()) { |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13893 | return; |
| 13894 | } |
| 13895 | framer_.EnableMultiplePacketNumberSpacesSupport(); |
| 13896 | |
| 13897 | // clang-format off |
| 13898 | PacketFragments packet = { |
| 13899 | // public flags (IETF Retry packet, 0-length original destination CID) |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13900 | {"Unable to read first byte.", |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13901 | {0xf0}}, |
| 13902 | // version tag |
| 13903 | {"Unable to read protocol version.", |
| 13904 | {QUIC_VERSION_BYTES}}, |
| 13905 | // connection_id length |
dschinazi | 244f6dc | 2019-05-06 15:45:16 -0700 | [diff] [blame] | 13906 | {"RETRY not supported in this version.", |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13907 | {0x00}}, |
| 13908 | }; |
| 13909 | // clang-format on |
| 13910 | |
| 13911 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 13912 | AssemblePacketFromFragments(packet)); |
| 13913 | |
| 13914 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13915 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
nharper | 2ceb97c | 2019-04-19 11:38:59 -0700 | [diff] [blame] | 13916 | CheckFramingBoundaries(packet, QUIC_INVALID_PACKET_HEADER); |
| 13917 | } |
| 13918 | |
nharper | a745e39 | 2019-04-19 12:05:15 -0700 | [diff] [blame] | 13919 | TEST_P(QuicFramerTest, ProcessPublicHeaderNoVersionInferredType) { |
| 13920 | // The framer needs to have Perspective::IS_SERVER and configured to infer the |
| 13921 | // packet header type from the packet (not the version). The framer's version |
| 13922 | // needs to be one that uses the IETF packet format. |
| 13923 | if (!framer_.version().KnowsWhichDecrypterToUse()) { |
| 13924 | return; |
| 13925 | } |
| 13926 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 13927 | |
| 13928 | // Prepare a packet that uses the Google QUIC packet header but has no version |
| 13929 | // field. |
| 13930 | |
| 13931 | // clang-format off |
| 13932 | PacketFragments packet = { |
| 13933 | // public flags (1-byte packet number, 8-byte connection_id, no version) |
| 13934 | {"Unable to read public flags.", |
| 13935 | {0x08}}, |
| 13936 | // connection_id |
| 13937 | {"Unable to read ConnectionId.", |
| 13938 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 13939 | // packet number |
| 13940 | {"Unable to read packet number.", |
| 13941 | {0x01}}, |
| 13942 | // padding |
| 13943 | {"Invalid public header type for expected version.", |
| 13944 | {0x00}}, |
| 13945 | }; |
| 13946 | // clang-format on |
| 13947 | |
| 13948 | PacketFragments& fragments = packet; |
| 13949 | |
| 13950 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 13951 | AssemblePacketFromFragments(fragments)); |
| 13952 | |
| 13953 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13954 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
nharper | 8b6d63a | 2019-05-03 10:34:53 -0700 | [diff] [blame] | 13955 | EXPECT_EQ("Invalid public header type for expected version.", |
| 13956 | framer_.detailed_error()); |
nharper | a745e39 | 2019-04-19 12:05:15 -0700 | [diff] [blame] | 13957 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 13958 | } |
| 13959 | |
nharper | 3f28356 | 2019-05-02 16:37:12 -0700 | [diff] [blame] | 13960 | TEST_P(QuicFramerTest, ProcessMismatchedHeaderVersion) { |
| 13961 | // The framer needs to have Perspective::IS_SERVER and configured to infer the |
| 13962 | // packet header type from the packet (not the version). The framer's version |
| 13963 | // needs to be one that uses the IETF packet format. |
| 13964 | if (!framer_.version().KnowsWhichDecrypterToUse()) { |
| 13965 | return; |
| 13966 | } |
| 13967 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 13968 | |
| 13969 | // clang-format off |
| 13970 | PacketFragments packet = { |
dschinazi | 072da7c | 2019-05-07 17:57:42 -0700 | [diff] [blame] | 13971 | // public flags (Google QUIC header with version present) |
nharper | 3f28356 | 2019-05-02 16:37:12 -0700 | [diff] [blame] | 13972 | {"Unable to read public flags.", |
| 13973 | {0x09}}, |
| 13974 | // connection_id |
| 13975 | {"Unable to read ConnectionId.", |
| 13976 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 13977 | // version tag |
| 13978 | {"Unable to read protocol version.", |
| 13979 | {QUIC_VERSION_BYTES}}, |
| 13980 | // packet number |
| 13981 | {"Unable to read packet number.", |
| 13982 | {0x01}}, |
| 13983 | }; |
| 13984 | // clang-format on |
| 13985 | |
| 13986 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 13987 | AssemblePacketFromFragments(packet)); |
| 13988 | framer_.ProcessPacket(*encrypted); |
| 13989 | |
| 13990 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 13991 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
nharper | 8b6d63a | 2019-05-03 10:34:53 -0700 | [diff] [blame] | 13992 | EXPECT_EQ("Invalid public header type for expected version.", |
| 13993 | framer_.detailed_error()); |
nharper | 3f28356 | 2019-05-02 16:37:12 -0700 | [diff] [blame] | 13994 | CheckFramingBoundaries(packet, QUIC_INVALID_PACKET_HEADER); |
| 13995 | } |
| 13996 | |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13997 | TEST_P(QuicFramerTest, WriteClientVersionNegotiationProbePacket) { |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 13998 | // clang-format off |
| 13999 | static const char expected_packet[1200] = { |
| 14000 | // IETF long header with fixed bit set, type initial, all-0 encrypted bits. |
| 14001 | 0xc0, |
| 14002 | // Version, part of the IETF space reserved for negotiation. |
| 14003 | 0xca, 0xba, 0xda, 0xda, |
| 14004 | // Destination connection ID length 8. |
| 14005 | 0x08, |
| 14006 | // 8-byte destination connection ID. |
| 14007 | 0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21, |
| 14008 | // Source connection ID length 0. |
| 14009 | 0x00, |
| 14010 | // 8 bytes of zeroes followed by 8 bytes of ones to ensure that this does |
| 14011 | // not parse with any known version. |
| 14012 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 14013 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 14014 | // zeroes to pad to 16 byte boundary. |
| 14015 | 0x00, |
| 14016 | // A polite greeting in case a human sees this in tcpdump. |
| 14017 | 0x54, 0x68, 0x69, 0x73, 0x20, 0x70, 0x61, 0x63, |
| 14018 | 0x6b, 0x65, 0x74, 0x20, 0x6f, 0x6e, 0x6c, 0x79, |
| 14019 | 0x20, 0x65, 0x78, 0x69, 0x73, 0x74, 0x73, 0x20, |
| 14020 | 0x74, 0x6f, 0x20, 0x74, 0x72, 0x69, 0x67, 0x67, |
| 14021 | 0x65, 0x72, 0x20, 0x49, 0x45, 0x54, 0x46, 0x20, |
| 14022 | 0x51, 0x55, 0x49, 0x43, 0x20, 0x76, 0x65, 0x72, |
| 14023 | 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x65, 0x67, |
| 14024 | 0x6f, 0x74, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, |
| 14025 | 0x2e, 0x20, 0x50, 0x6c, 0x65, 0x61, 0x73, 0x65, |
| 14026 | 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, |
| 14027 | 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x20, |
| 14028 | 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, |
| 14029 | 0x4e, 0x65, 0x67, 0x6f, 0x74, 0x69, 0x61, 0x74, |
| 14030 | 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, 0x63, 0x6b, |
| 14031 | 0x65, 0x74, 0x20, 0x69, 0x6e, 0x64, 0x69, 0x63, |
| 14032 | 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x77, 0x68, |
| 14033 | 0x61, 0x74, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, |
| 14034 | 0x6f, 0x6e, 0x73, 0x20, 0x79, 0x6f, 0x75, 0x20, |
| 14035 | 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x2e, |
| 14036 | 0x20, 0x54, 0x68, 0x61, 0x6e, 0x6b, 0x20, 0x79, |
| 14037 | 0x6f, 0x75, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x68, |
| 14038 | 0x61, 0x76, 0x65, 0x20, 0x61, 0x20, 0x6e, 0x69, |
| 14039 | 0x63, 0x65, 0x20, 0x64, 0x61, 0x79, 0x2e, 0x00, |
| 14040 | }; |
| 14041 | // clang-format on |
| 14042 | char packet[1200]; |
| 14043 | char destination_connection_id_bytes[] = {0x56, 0x4e, 0x20, 0x70, |
| 14044 | 0x6c, 0x7a, 0x20, 0x21}; |
| 14045 | EXPECT_TRUE(QuicFramer::WriteClientVersionNegotiationProbePacket( |
| 14046 | packet, sizeof(packet), destination_connection_id_bytes, |
| 14047 | sizeof(destination_connection_id_bytes))); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 14048 | quiche::test::CompareCharArraysWithHexError("constructed packet", packet, |
| 14049 | sizeof(packet), expected_packet, |
| 14050 | sizeof(expected_packet)); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14051 | QuicEncryptedPacket encrypted(reinterpret_cast<const char*>(packet), |
| 14052 | sizeof(packet), false); |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 14053 | if (!framer_.version().HasLengthPrefixedConnectionIds()) { |
| 14054 | // We can only parse the connection ID with a parser expecting |
| 14055 | // length-prefixed connection IDs. |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14056 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 14057 | return; |
| 14058 | } |
| 14059 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 14060 | ASSERT_TRUE(visitor_.header_.get()); |
| 14061 | QuicConnectionId probe_payload_connection_id( |
| 14062 | reinterpret_cast<const char*>(destination_connection_id_bytes), |
| 14063 | sizeof(destination_connection_id_bytes)); |
| 14064 | EXPECT_EQ(probe_payload_connection_id, |
| 14065 | visitor_.header_.get()->destination_connection_id); |
| 14066 | } |
| 14067 | |
| 14068 | TEST_P(QuicFramerTest, DispatcherParseOldClientVersionNegotiationProbePacket) { |
| 14069 | // clang-format off |
| 14070 | static const char packet[1200] = { |
| 14071 | // IETF long header with fixed bit set, type initial, all-0 encrypted bits. |
| 14072 | 0xc0, |
| 14073 | // Version, part of the IETF space reserved for negotiation. |
| 14074 | 0xca, 0xba, 0xda, 0xba, |
| 14075 | // Destination connection ID length 8, source connection ID length 0. |
| 14076 | 0x50, |
| 14077 | // 8-byte destination connection ID. |
| 14078 | 0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21, |
| 14079 | // 8 bytes of zeroes followed by 8 bytes of ones to ensure that this does |
| 14080 | // not parse with any known version. |
| 14081 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 14082 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 14083 | // 2 bytes of zeroes to pad to 16 byte boundary. |
| 14084 | 0x00, 0x00, |
| 14085 | // A polite greeting in case a human sees this in tcpdump. |
| 14086 | 0x54, 0x68, 0x69, 0x73, 0x20, 0x70, 0x61, 0x63, |
| 14087 | 0x6b, 0x65, 0x74, 0x20, 0x6f, 0x6e, 0x6c, 0x79, |
| 14088 | 0x20, 0x65, 0x78, 0x69, 0x73, 0x74, 0x73, 0x20, |
| 14089 | 0x74, 0x6f, 0x20, 0x74, 0x72, 0x69, 0x67, 0x67, |
| 14090 | 0x65, 0x72, 0x20, 0x49, 0x45, 0x54, 0x46, 0x20, |
| 14091 | 0x51, 0x55, 0x49, 0x43, 0x20, 0x76, 0x65, 0x72, |
| 14092 | 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x65, 0x67, |
| 14093 | 0x6f, 0x74, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, |
| 14094 | 0x2e, 0x20, 0x50, 0x6c, 0x65, 0x61, 0x73, 0x65, |
| 14095 | 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, |
| 14096 | 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x20, |
| 14097 | 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, |
| 14098 | 0x4e, 0x65, 0x67, 0x6f, 0x74, 0x69, 0x61, 0x74, |
| 14099 | 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, 0x63, 0x6b, |
| 14100 | 0x65, 0x74, 0x20, 0x69, 0x6e, 0x64, 0x69, 0x63, |
| 14101 | 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x77, 0x68, |
| 14102 | 0x61, 0x74, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, |
| 14103 | 0x6f, 0x6e, 0x73, 0x20, 0x79, 0x6f, 0x75, 0x20, |
| 14104 | 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x2e, |
| 14105 | 0x20, 0x54, 0x68, 0x61, 0x6e, 0x6b, 0x20, 0x79, |
| 14106 | 0x6f, 0x75, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x68, |
| 14107 | 0x61, 0x76, 0x65, 0x20, 0x61, 0x20, 0x6e, 0x69, |
| 14108 | 0x63, 0x65, 0x20, 0x64, 0x61, 0x79, 0x2e, 0x00, |
| 14109 | }; |
| 14110 | // clang-format on |
| 14111 | char expected_destination_connection_id_bytes[] = {0x56, 0x4e, 0x20, 0x70, |
| 14112 | 0x6c, 0x7a, 0x20, 0x21}; |
| 14113 | QuicConnectionId expected_destination_connection_id( |
| 14114 | reinterpret_cast<const char*>(expected_destination_connection_id_bytes), |
| 14115 | sizeof(expected_destination_connection_id_bytes)); |
| 14116 | |
| 14117 | QuicEncryptedPacket encrypted(reinterpret_cast<const char*>(packet), |
| 14118 | sizeof(packet)); |
| 14119 | PacketHeaderFormat format = GOOGLE_QUIC_PACKET; |
fayang | e3f2f7b | 2019-09-19 17:01:57 -0700 | [diff] [blame] | 14120 | QuicLongHeaderType long_packet_type = INVALID_PACKET_TYPE; |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14121 | bool version_present = false, has_length_prefix = true; |
| 14122 | QuicVersionLabel version_label = 33; |
| 14123 | ParsedQuicVersion parsed_version = UnsupportedQuicVersion(); |
| 14124 | QuicConnectionId destination_connection_id = TestConnectionId(1); |
| 14125 | QuicConnectionId source_connection_id = TestConnectionId(2); |
| 14126 | bool retry_token_present = true; |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 14127 | absl::string_view retry_token; |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14128 | std::string detailed_error = "foobar"; |
| 14129 | QuicErrorCode header_parse_result = QuicFramer::ParsePublicHeaderDispatcher( |
fayang | e3f2f7b | 2019-09-19 17:01:57 -0700 | [diff] [blame] | 14130 | encrypted, kQuicDefaultConnectionIdLength, &format, &long_packet_type, |
| 14131 | &version_present, &has_length_prefix, &version_label, &parsed_version, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14132 | &destination_connection_id, &source_connection_id, &retry_token_present, |
| 14133 | &retry_token, &detailed_error); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 14134 | EXPECT_THAT(header_parse_result, IsQuicNoError()); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14135 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 14136 | EXPECT_TRUE(version_present); |
| 14137 | EXPECT_FALSE(has_length_prefix); |
| 14138 | EXPECT_EQ(0xcabadaba, version_label); |
| 14139 | EXPECT_EQ(expected_destination_connection_id, destination_connection_id); |
| 14140 | EXPECT_EQ(EmptyQuicConnectionId(), source_connection_id); |
| 14141 | EXPECT_FALSE(retry_token_present); |
| 14142 | EXPECT_EQ("", detailed_error); |
| 14143 | } |
| 14144 | |
| 14145 | TEST_P(QuicFramerTest, DispatcherParseClientVersionNegotiationProbePacket) { |
| 14146 | // clang-format off |
| 14147 | static const char packet[1200] = { |
| 14148 | // IETF long header with fixed bit set, type initial, all-0 encrypted bits. |
| 14149 | 0xc0, |
| 14150 | // Version, part of the IETF space reserved for negotiation. |
| 14151 | 0xca, 0xba, 0xda, 0xba, |
| 14152 | // Destination connection ID length 8. |
| 14153 | 0x08, |
| 14154 | // 8-byte destination connection ID. |
| 14155 | 0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21, |
| 14156 | // Source connection ID length 0. |
| 14157 | 0x00, |
| 14158 | // 8 bytes of zeroes followed by 8 bytes of ones to ensure that this does |
| 14159 | // not parse with any known version. |
| 14160 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 14161 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, |
| 14162 | // 1 byte of zeroes to pad to 16 byte boundary. |
| 14163 | 0x00, |
| 14164 | // A polite greeting in case a human sees this in tcpdump. |
| 14165 | 0x54, 0x68, 0x69, 0x73, 0x20, 0x70, 0x61, 0x63, |
| 14166 | 0x6b, 0x65, 0x74, 0x20, 0x6f, 0x6e, 0x6c, 0x79, |
| 14167 | 0x20, 0x65, 0x78, 0x69, 0x73, 0x74, 0x73, 0x20, |
| 14168 | 0x74, 0x6f, 0x20, 0x74, 0x72, 0x69, 0x67, 0x67, |
| 14169 | 0x65, 0x72, 0x20, 0x49, 0x45, 0x54, 0x46, 0x20, |
| 14170 | 0x51, 0x55, 0x49, 0x43, 0x20, 0x76, 0x65, 0x72, |
| 14171 | 0x73, 0x69, 0x6f, 0x6e, 0x20, 0x6e, 0x65, 0x67, |
| 14172 | 0x6f, 0x74, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, |
| 14173 | 0x2e, 0x20, 0x50, 0x6c, 0x65, 0x61, 0x73, 0x65, |
| 14174 | 0x20, 0x72, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x64, |
| 14175 | 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x61, 0x20, |
| 14176 | 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x20, |
| 14177 | 0x4e, 0x65, 0x67, 0x6f, 0x74, 0x69, 0x61, 0x74, |
| 14178 | 0x69, 0x6f, 0x6e, 0x20, 0x70, 0x61, 0x63, 0x6b, |
| 14179 | 0x65, 0x74, 0x20, 0x69, 0x6e, 0x64, 0x69, 0x63, |
| 14180 | 0x61, 0x74, 0x69, 0x6e, 0x67, 0x20, 0x77, 0x68, |
| 14181 | 0x61, 0x74, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, |
| 14182 | 0x6f, 0x6e, 0x73, 0x20, 0x79, 0x6f, 0x75, 0x20, |
| 14183 | 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x2e, |
| 14184 | 0x20, 0x54, 0x68, 0x61, 0x6e, 0x6b, 0x20, 0x79, |
| 14185 | 0x6f, 0x75, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x68, |
| 14186 | 0x61, 0x76, 0x65, 0x20, 0x61, 0x20, 0x6e, 0x69, |
| 14187 | 0x63, 0x65, 0x20, 0x64, 0x61, 0x79, 0x2e, 0x00, |
| 14188 | }; |
| 14189 | // clang-format on |
| 14190 | char expected_destination_connection_id_bytes[] = {0x56, 0x4e, 0x20, 0x70, |
| 14191 | 0x6c, 0x7a, 0x20, 0x21}; |
| 14192 | QuicConnectionId expected_destination_connection_id( |
| 14193 | reinterpret_cast<const char*>(expected_destination_connection_id_bytes), |
| 14194 | sizeof(expected_destination_connection_id_bytes)); |
| 14195 | |
| 14196 | QuicEncryptedPacket encrypted(reinterpret_cast<const char*>(packet), |
| 14197 | sizeof(packet)); |
| 14198 | PacketHeaderFormat format = GOOGLE_QUIC_PACKET; |
fayang | e3f2f7b | 2019-09-19 17:01:57 -0700 | [diff] [blame] | 14199 | QuicLongHeaderType long_packet_type = INVALID_PACKET_TYPE; |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14200 | bool version_present = false, has_length_prefix = false; |
| 14201 | QuicVersionLabel version_label = 33; |
| 14202 | ParsedQuicVersion parsed_version = UnsupportedQuicVersion(); |
| 14203 | QuicConnectionId destination_connection_id = TestConnectionId(1); |
| 14204 | QuicConnectionId source_connection_id = TestConnectionId(2); |
| 14205 | bool retry_token_present = true; |
vasilvv | c872ee4 | 2020-10-07 19:50:22 -0700 | [diff] [blame] | 14206 | absl::string_view retry_token; |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14207 | std::string detailed_error = "foobar"; |
| 14208 | QuicErrorCode header_parse_result = QuicFramer::ParsePublicHeaderDispatcher( |
fayang | e3f2f7b | 2019-09-19 17:01:57 -0700 | [diff] [blame] | 14209 | encrypted, kQuicDefaultConnectionIdLength, &format, &long_packet_type, |
| 14210 | &version_present, &has_length_prefix, &version_label, &parsed_version, |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14211 | &destination_connection_id, &source_connection_id, &retry_token_present, |
| 14212 | &retry_token, &detailed_error); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 14213 | EXPECT_THAT(header_parse_result, IsQuicNoError()); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14214 | EXPECT_EQ(IETF_QUIC_LONG_HEADER_PACKET, format); |
| 14215 | EXPECT_TRUE(version_present); |
| 14216 | EXPECT_TRUE(has_length_prefix); |
| 14217 | EXPECT_EQ(0xcabadaba, version_label); |
| 14218 | EXPECT_EQ(expected_destination_connection_id, destination_connection_id); |
| 14219 | EXPECT_EQ(EmptyQuicConnectionId(), source_connection_id); |
| 14220 | EXPECT_EQ("", detailed_error); |
| 14221 | } |
| 14222 | |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14223 | TEST_P(QuicFramerTest, ParseServerVersionNegotiationProbeResponse) { |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14224 | // clang-format off |
| 14225 | const char packet[] = { |
| 14226 | // IETF long header with fixed bit set, type initial, all-0 encrypted bits. |
| 14227 | 0xc0, |
| 14228 | // Version of 0, indicating version negotiation. |
| 14229 | 0x00, 0x00, 0x00, 0x00, |
| 14230 | // Destination connection ID length 0, source connection ID length 8. |
| 14231 | 0x00, 0x08, |
| 14232 | // 8-byte source connection ID. |
| 14233 | 0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21, |
| 14234 | // A few supported versions. |
| 14235 | 0xaa, 0xaa, 0xaa, 0xaa, |
| 14236 | QUIC_VERSION_BYTES, |
| 14237 | }; |
| 14238 | // clang-format on |
| 14239 | char probe_payload_bytes[] = {0x56, 0x4e, 0x20, 0x70, 0x6c, 0x7a, 0x20, 0x21}; |
dschinazi | b012d21 | 2019-08-01 18:07:26 -0700 | [diff] [blame] | 14240 | char parsed_probe_payload_bytes[255] = {}; |
dschinazi | 9d3ba8d | 2020-10-07 16:18:07 -0700 | [diff] [blame] | 14241 | uint8_t parsed_probe_payload_length = sizeof(parsed_probe_payload_bytes); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14242 | std::string parse_detailed_error = ""; |
| 14243 | EXPECT_TRUE(QuicFramer::ParseServerVersionNegotiationProbeResponse( |
| 14244 | reinterpret_cast<const char*>(packet), sizeof(packet), |
| 14245 | reinterpret_cast<char*>(parsed_probe_payload_bytes), |
| 14246 | &parsed_probe_payload_length, &parse_detailed_error)); |
| 14247 | EXPECT_EQ("", parse_detailed_error); |
dmcardle | 8f7df53 | 2020-01-07 13:28:57 -0800 | [diff] [blame] | 14248 | quiche::test::CompareCharArraysWithHexError( |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14249 | "parsed probe", parsed_probe_payload_bytes, parsed_probe_payload_length, |
| 14250 | probe_payload_bytes, sizeof(probe_payload_bytes)); |
dschinazi | de0f6dc | 2019-05-15 16:10:11 -0700 | [diff] [blame] | 14251 | } |
| 14252 | |
dschinazi | 9d3ba8d | 2020-10-07 16:18:07 -0700 | [diff] [blame] | 14253 | TEST_P(QuicFramerTest, ParseClientVersionNegotiationProbePacket) { |
dschinazi | 9d3ba8d | 2020-10-07 16:18:07 -0700 | [diff] [blame] | 14254 | char packet[1200]; |
| 14255 | char input_destination_connection_id_bytes[] = {0x56, 0x4e, 0x20, 0x70, |
| 14256 | 0x6c, 0x7a, 0x20, 0x21}; |
| 14257 | ASSERT_TRUE(QuicFramer::WriteClientVersionNegotiationProbePacket( |
| 14258 | packet, sizeof(packet), input_destination_connection_id_bytes, |
| 14259 | sizeof(input_destination_connection_id_bytes))); |
| 14260 | char parsed_destination_connection_id_bytes[255] = {0}; |
| 14261 | uint8_t parsed_destination_connection_id_length = |
| 14262 | sizeof(parsed_destination_connection_id_bytes); |
| 14263 | ASSERT_TRUE(ParseClientVersionNegotiationProbePacket( |
| 14264 | packet, sizeof(packet), parsed_destination_connection_id_bytes, |
| 14265 | &parsed_destination_connection_id_length)); |
| 14266 | quiche::test::CompareCharArraysWithHexError( |
| 14267 | "parsed destination connection ID", |
| 14268 | parsed_destination_connection_id_bytes, |
| 14269 | parsed_destination_connection_id_length, |
| 14270 | input_destination_connection_id_bytes, |
| 14271 | sizeof(input_destination_connection_id_bytes)); |
| 14272 | } |
| 14273 | |
| 14274 | TEST_P(QuicFramerTest, WriteServerVersionNegotiationProbeResponse) { |
dschinazi | 9d3ba8d | 2020-10-07 16:18:07 -0700 | [diff] [blame] | 14275 | char packet[1200]; |
| 14276 | size_t packet_length = sizeof(packet); |
| 14277 | char input_source_connection_id_bytes[] = {0x56, 0x4e, 0x20, 0x70, |
| 14278 | 0x6c, 0x7a, 0x20, 0x21}; |
| 14279 | ASSERT_TRUE(WriteServerVersionNegotiationProbeResponse( |
| 14280 | packet, &packet_length, input_source_connection_id_bytes, |
| 14281 | sizeof(input_source_connection_id_bytes))); |
| 14282 | char parsed_source_connection_id_bytes[255] = {0}; |
| 14283 | uint8_t parsed_source_connection_id_length = |
| 14284 | sizeof(parsed_source_connection_id_bytes); |
| 14285 | std::string detailed_error; |
| 14286 | ASSERT_TRUE(QuicFramer::ParseServerVersionNegotiationProbeResponse( |
| 14287 | packet, packet_length, parsed_source_connection_id_bytes, |
| 14288 | &parsed_source_connection_id_length, &detailed_error)) |
| 14289 | << detailed_error; |
| 14290 | quiche::test::CompareCharArraysWithHexError( |
| 14291 | "parsed destination connection ID", parsed_source_connection_id_bytes, |
| 14292 | parsed_source_connection_id_length, input_source_connection_id_bytes, |
| 14293 | sizeof(input_source_connection_id_bytes)); |
| 14294 | } |
| 14295 | |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 14296 | TEST_P(QuicFramerTest, ClientConnectionIdFromLongHeaderToClient) { |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 14297 | if (!framer_.version().HasIetfInvariantHeader()) { |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 14298 | // This test requires an IETF long header. |
| 14299 | return; |
| 14300 | } |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 14301 | SetDecrypterLevel(ENCRYPTION_HANDSHAKE); |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 14302 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 14303 | // clang-format off |
| 14304 | unsigned char packet[] = { |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 14305 | // public flags (long header with packet type HANDSHAKE and |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 14306 | // 4-byte packet number) |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 14307 | 0xE3, |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 14308 | // version |
| 14309 | QUIC_VERSION_BYTES, |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 14310 | // connection ID lengths |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 14311 | 0x50, |
| 14312 | // destination connection ID |
| 14313 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 14314 | // long header packet length |
| 14315 | 0x05, |
| 14316 | // packet number |
| 14317 | 0x12, 0x34, 0x56, 0x00, |
| 14318 | // padding frame |
| 14319 | 0x00, |
| 14320 | }; |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 14321 | unsigned char packet49[] = { |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14322 | // public flags (long header with packet type HANDSHAKE and |
| 14323 | // 4-byte packet number) |
| 14324 | 0xE3, |
| 14325 | // version |
| 14326 | QUIC_VERSION_BYTES, |
| 14327 | // destination connection ID length |
| 14328 | 0x08, |
| 14329 | // destination connection ID |
| 14330 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 14331 | // source connection ID length |
| 14332 | 0x00, |
| 14333 | // long header packet length |
| 14334 | 0x05, |
| 14335 | // packet number |
| 14336 | 0x12, 0x34, 0x56, 0x00, |
| 14337 | // padding frame |
| 14338 | 0x00, |
| 14339 | }; |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 14340 | // clang-format on |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14341 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 14342 | size_t p_length = ABSL_ARRAYSIZE(packet); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 14343 | if (framer_.version().HasLongHeaderLengths()) { |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 14344 | p = packet49; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 14345 | p_length = ABSL_ARRAYSIZE(packet49); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14346 | } |
| 14347 | const bool parse_success = |
| 14348 | framer_.ProcessPacket(QuicEncryptedPacket(AsChars(p), p_length, false)); |
dschinazi | 97da52b | 2020-01-13 15:44:43 -0800 | [diff] [blame] | 14349 | if (!framer_.version().AllowsVariableLengthConnectionIds()) { |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 14350 | EXPECT_FALSE(parse_success); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 14351 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 14352 | EXPECT_EQ("Invalid ConnectionId length.", framer_.detailed_error()); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 14353 | return; |
| 14354 | } |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 14355 | EXPECT_TRUE(parse_success); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 14356 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 14357 | EXPECT_EQ("", framer_.detailed_error()); |
| 14358 | ASSERT_TRUE(visitor_.header_.get()); |
| 14359 | EXPECT_EQ(FramerTestConnectionId(), |
| 14360 | visitor_.header_.get()->destination_connection_id); |
| 14361 | } |
| 14362 | |
| 14363 | TEST_P(QuicFramerTest, ClientConnectionIdFromLongHeaderToServer) { |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 14364 | if (!framer_.version().HasIetfInvariantHeader()) { |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 14365 | // This test requires an IETF long header. |
| 14366 | return; |
| 14367 | } |
| 14368 | SetDecrypterLevel(ENCRYPTION_HANDSHAKE); |
| 14369 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14370 | // clang-format off |
| 14371 | unsigned char packet[] = { |
| 14372 | // public flags (long header with packet type HANDSHAKE and |
| 14373 | // 4-byte packet number) |
fayang | 36825da | 2019-08-21 14:01:27 -0700 | [diff] [blame] | 14374 | 0xE3, |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 14375 | // version |
| 14376 | QUIC_VERSION_BYTES, |
| 14377 | // connection ID lengths |
| 14378 | 0x05, |
| 14379 | // source connection ID |
| 14380 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 14381 | // long header packet length |
| 14382 | 0x05, |
| 14383 | // packet number |
| 14384 | 0x12, 0x34, 0x56, 0x00, |
| 14385 | // padding frame |
| 14386 | 0x00, |
| 14387 | }; |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 14388 | unsigned char packet49[] = { |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14389 | // public flags (long header with packet type HANDSHAKE and |
| 14390 | // 4-byte packet number) |
| 14391 | 0xE3, |
| 14392 | // version |
| 14393 | QUIC_VERSION_BYTES, |
| 14394 | // connection ID lengths |
| 14395 | 0x00, 0x08, |
| 14396 | // source connection ID |
| 14397 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 14398 | // long header packet length |
| 14399 | 0x05, |
| 14400 | // packet number |
| 14401 | 0x12, 0x34, 0x56, 0x00, |
| 14402 | // padding frame |
| 14403 | 0x00, |
| 14404 | }; |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 14405 | // clang-format on |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14406 | unsigned char* p = packet; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 14407 | size_t p_length = ABSL_ARRAYSIZE(packet); |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 14408 | if (framer_.version().HasLongHeaderLengths()) { |
dschinazi | c73506e | 2019-09-20 13:26:46 -0700 | [diff] [blame] | 14409 | p = packet49; |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 14410 | p_length = ABSL_ARRAYSIZE(packet49); |
dschinazi | 48ac919 | 2019-07-31 00:07:26 -0700 | [diff] [blame] | 14411 | } |
| 14412 | const bool parse_success = |
| 14413 | framer_.ProcessPacket(QuicEncryptedPacket(AsChars(p), p_length, false)); |
dschinazi | 97da52b | 2020-01-13 15:44:43 -0800 | [diff] [blame] | 14414 | if (!framer_.version().AllowsVariableLengthConnectionIds()) { |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 14415 | EXPECT_FALSE(parse_success); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 14416 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 14417 | EXPECT_EQ("Invalid ConnectionId length.", framer_.detailed_error()); |
| 14418 | return; |
| 14419 | } |
dschinazi | 5e1a7b2 | 2019-07-31 12:23:21 -0700 | [diff] [blame] | 14420 | if (!framer_.version().SupportsClientConnectionIds()) { |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 14421 | EXPECT_FALSE(parse_success); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 14422 | EXPECT_THAT(framer_.error(), IsError(QUIC_INVALID_PACKET_HEADER)); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 14423 | EXPECT_EQ("Client connection ID not supported in this version.", |
| 14424 | framer_.detailed_error()); |
| 14425 | return; |
| 14426 | } |
| 14427 | EXPECT_TRUE(parse_success); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 14428 | EXPECT_THAT(framer_.error(), IsQuicNoError()); |
dschinazi | 346b7ce | 2019-06-05 01:38:18 -0700 | [diff] [blame] | 14429 | EXPECT_EQ("", framer_.detailed_error()); |
| 14430 | ASSERT_TRUE(visitor_.header_.get()); |
| 14431 | EXPECT_EQ(FramerTestConnectionId(), |
| 14432 | visitor_.header_.get()->source_connection_id); |
dschinazi | 7d066ca | 2019-05-15 17:59:49 -0700 | [diff] [blame] | 14433 | } |
| 14434 | |
dschinazi | 334f023 | 2019-05-29 16:08:53 -0700 | [diff] [blame] | 14435 | TEST_P(QuicFramerTest, ProcessAndValidateIetfConnectionIdLengthClient) { |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 14436 | if (!framer_.version().HasIetfInvariantHeader()) { |
dschinazi | 334f023 | 2019-05-29 16:08:53 -0700 | [diff] [blame] | 14437 | // This test requires an IETF long header. |
| 14438 | return; |
| 14439 | } |
| 14440 | char connection_id_lengths = 0x05; |
| 14441 | QuicDataReader reader(&connection_id_lengths, 1); |
| 14442 | |
| 14443 | bool should_update_expected_server_connection_id_length = false; |
| 14444 | uint8_t expected_server_connection_id_length = 8; |
| 14445 | uint8_t destination_connection_id_length = 0; |
| 14446 | uint8_t source_connection_id_length = 8; |
| 14447 | std::string detailed_error = ""; |
| 14448 | |
| 14449 | EXPECT_TRUE(QuicFramerPeer::ProcessAndValidateIetfConnectionIdLength( |
| 14450 | &reader, framer_.version(), Perspective::IS_CLIENT, |
| 14451 | should_update_expected_server_connection_id_length, |
| 14452 | &expected_server_connection_id_length, &destination_connection_id_length, |
| 14453 | &source_connection_id_length, &detailed_error)); |
| 14454 | EXPECT_EQ(8, expected_server_connection_id_length); |
| 14455 | EXPECT_EQ(0, destination_connection_id_length); |
| 14456 | EXPECT_EQ(8, source_connection_id_length); |
| 14457 | EXPECT_EQ("", detailed_error); |
| 14458 | |
| 14459 | QuicDataReader reader2(&connection_id_lengths, 1); |
| 14460 | should_update_expected_server_connection_id_length = true; |
| 14461 | expected_server_connection_id_length = 33; |
| 14462 | EXPECT_TRUE(QuicFramerPeer::ProcessAndValidateIetfConnectionIdLength( |
| 14463 | &reader2, framer_.version(), Perspective::IS_CLIENT, |
| 14464 | should_update_expected_server_connection_id_length, |
| 14465 | &expected_server_connection_id_length, &destination_connection_id_length, |
| 14466 | &source_connection_id_length, &detailed_error)); |
| 14467 | EXPECT_EQ(8, expected_server_connection_id_length); |
| 14468 | EXPECT_EQ(0, destination_connection_id_length); |
| 14469 | EXPECT_EQ(8, source_connection_id_length); |
| 14470 | EXPECT_EQ("", detailed_error); |
| 14471 | } |
| 14472 | |
| 14473 | TEST_P(QuicFramerTest, ProcessAndValidateIetfConnectionIdLengthServer) { |
dschinazi | ceed866 | 2020-07-14 09:37:05 -0700 | [diff] [blame] | 14474 | if (!framer_.version().HasIetfInvariantHeader()) { |
dschinazi | 334f023 | 2019-05-29 16:08:53 -0700 | [diff] [blame] | 14475 | // This test requires an IETF long header. |
| 14476 | return; |
| 14477 | } |
| 14478 | char connection_id_lengths = 0x50; |
| 14479 | QuicDataReader reader(&connection_id_lengths, 1); |
| 14480 | |
| 14481 | bool should_update_expected_server_connection_id_length = false; |
| 14482 | uint8_t expected_server_connection_id_length = 8; |
| 14483 | uint8_t destination_connection_id_length = 8; |
| 14484 | uint8_t source_connection_id_length = 0; |
| 14485 | std::string detailed_error = ""; |
| 14486 | |
| 14487 | EXPECT_TRUE(QuicFramerPeer::ProcessAndValidateIetfConnectionIdLength( |
| 14488 | &reader, framer_.version(), Perspective::IS_SERVER, |
| 14489 | should_update_expected_server_connection_id_length, |
| 14490 | &expected_server_connection_id_length, &destination_connection_id_length, |
| 14491 | &source_connection_id_length, &detailed_error)); |
| 14492 | EXPECT_EQ(8, expected_server_connection_id_length); |
| 14493 | EXPECT_EQ(8, destination_connection_id_length); |
| 14494 | EXPECT_EQ(0, source_connection_id_length); |
| 14495 | EXPECT_EQ("", detailed_error); |
| 14496 | |
| 14497 | QuicDataReader reader2(&connection_id_lengths, 1); |
| 14498 | should_update_expected_server_connection_id_length = true; |
| 14499 | expected_server_connection_id_length = 33; |
| 14500 | EXPECT_TRUE(QuicFramerPeer::ProcessAndValidateIetfConnectionIdLength( |
| 14501 | &reader2, framer_.version(), Perspective::IS_SERVER, |
| 14502 | should_update_expected_server_connection_id_length, |
| 14503 | &expected_server_connection_id_length, &destination_connection_id_length, |
| 14504 | &source_connection_id_length, &detailed_error)); |
| 14505 | EXPECT_EQ(8, expected_server_connection_id_length); |
| 14506 | EXPECT_EQ(8, destination_connection_id_length); |
| 14507 | EXPECT_EQ(0, source_connection_id_length); |
| 14508 | EXPECT_EQ("", detailed_error); |
| 14509 | } |
| 14510 | |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 14511 | TEST_P(QuicFramerTest, TestExtendedErrorCodeParser) { |
| 14512 | if (VersionHasIetfQuicFrames(framer_.transport_version())) { |
fkastenholz | c5e0c8c | 2019-09-30 10:16:30 -0700 | [diff] [blame] | 14513 | // Extended error codes only in IETF QUIC |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 14514 | return; |
| 14515 | } |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 14516 | QuicConnectionCloseFrame frame; |
| 14517 | |
| 14518 | frame.error_details = "this has no error code info in it"; |
| 14519 | MaybeExtractQuicErrorCode(&frame); |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 14520 | EXPECT_THAT(frame.quic_error_code, IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 14521 | EXPECT_EQ("this has no error code info in it", frame.error_details); |
| 14522 | |
| 14523 | frame.error_details = "1234this does not have the colon in it"; |
| 14524 | MaybeExtractQuicErrorCode(&frame); |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 14525 | EXPECT_THAT(frame.quic_error_code, IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 14526 | EXPECT_EQ("1234this does not have the colon in it", frame.error_details); |
| 14527 | |
| 14528 | frame.error_details = "1a234:this has a colon, but a malformed error number"; |
| 14529 | MaybeExtractQuicErrorCode(&frame); |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 14530 | EXPECT_THAT(frame.quic_error_code, IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 14531 | EXPECT_EQ("1a234:this has a colon, but a malformed error number", |
| 14532 | frame.error_details); |
| 14533 | |
| 14534 | frame.error_details = "1234:this is good"; |
| 14535 | MaybeExtractQuicErrorCode(&frame); |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 14536 | EXPECT_EQ(1234u, frame.quic_error_code); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 14537 | EXPECT_EQ("this is good", frame.error_details); |
| 14538 | |
| 14539 | frame.error_details = |
| 14540 | "1234 :this is not good, space between last digit and colon"; |
| 14541 | MaybeExtractQuicErrorCode(&frame); |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 14542 | EXPECT_THAT(frame.quic_error_code, IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 14543 | EXPECT_EQ("1234 :this is not good, space between last digit and colon", |
| 14544 | frame.error_details); |
| 14545 | |
| 14546 | frame.error_details = "123456789"; |
| 14547 | MaybeExtractQuicErrorCode(&frame); |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 14548 | EXPECT_THAT( |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 14549 | frame.quic_error_code, |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 14550 | IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); // Not good, all numbers, no : |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 14551 | EXPECT_EQ("123456789", frame.error_details); |
| 14552 | |
| 14553 | frame.error_details = "1234:"; |
| 14554 | MaybeExtractQuicErrorCode(&frame); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 14555 | EXPECT_EQ(1234u, |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 14556 | frame.quic_error_code); // corner case. |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 14557 | EXPECT_EQ("", frame.error_details); |
| 14558 | |
| 14559 | frame.error_details = "1234:5678"; |
| 14560 | MaybeExtractQuicErrorCode(&frame); |
| 14561 | EXPECT_EQ(1234u, |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 14562 | frame.quic_error_code); // another corner case. |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 14563 | EXPECT_EQ("5678", frame.error_details); |
| 14564 | |
| 14565 | frame.error_details = "12345 6789:"; |
| 14566 | MaybeExtractQuicErrorCode(&frame); |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 14567 | EXPECT_THAT(frame.quic_error_code, |
bnc | f6f82b1 | 2019-10-30 07:01:01 -0700 | [diff] [blame] | 14568 | IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); // Not good |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 14569 | EXPECT_EQ("12345 6789:", frame.error_details); |
| 14570 | |
| 14571 | frame.error_details = ":no numbers, is not good"; |
| 14572 | MaybeExtractQuicErrorCode(&frame); |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 14573 | EXPECT_THAT(frame.quic_error_code, IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 14574 | EXPECT_EQ(":no numbers, is not good", frame.error_details); |
| 14575 | |
| 14576 | frame.error_details = "qwer:also no numbers, is not good"; |
| 14577 | MaybeExtractQuicErrorCode(&frame); |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 14578 | EXPECT_THAT(frame.quic_error_code, IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 14579 | EXPECT_EQ("qwer:also no numbers, is not good", frame.error_details); |
| 14580 | |
| 14581 | frame.error_details = " 1234:this is not good, space before first digit"; |
| 14582 | MaybeExtractQuicErrorCode(&frame); |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 14583 | EXPECT_THAT(frame.quic_error_code, IsError(QUIC_IETF_GQUIC_ERROR_MISSING)); |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 14584 | EXPECT_EQ(" 1234:this is not good, space before first digit", |
| 14585 | frame.error_details); |
| 14586 | |
| 14587 | frame.error_details = "1234:"; |
| 14588 | MaybeExtractQuicErrorCode(&frame); |
| 14589 | EXPECT_EQ(1234u, |
bnc | 77e77b8 | 2020-04-05 10:36:49 -0700 | [diff] [blame] | 14590 | frame.quic_error_code); // this is good |
fkastenholz | 488a462 | 2019-08-26 06:24:46 -0700 | [diff] [blame] | 14591 | EXPECT_EQ("", frame.error_details); |
fkastenholz | b4dade7 | 2019-08-05 06:54:20 -0700 | [diff] [blame] | 14592 | } |
| 14593 | |
fayang | 3371b09 | 2019-12-04 07:08:52 -0800 | [diff] [blame] | 14594 | // Regression test for crbug/1029636. |
| 14595 | TEST_P(QuicFramerTest, OverlyLargeAckDelay) { |
| 14596 | if (!VersionHasIetfQuicFrames(framer_.transport_version())) { |
| 14597 | return; |
| 14598 | } |
| 14599 | SetDecrypterLevel(ENCRYPTION_FORWARD_SECURE); |
| 14600 | // clang-format off |
| 14601 | unsigned char packet99[] = { |
| 14602 | // type (short header, 4 byte packet number) |
| 14603 | 0x43, |
| 14604 | // connection_id |
| 14605 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 14606 | // packet number |
| 14607 | 0x12, 0x34, 0x56, 0x78, |
| 14608 | |
| 14609 | // frame type (IETF_ACK frame) |
| 14610 | 0x02, |
| 14611 | // largest acked |
| 14612 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78, |
| 14613 | // ack delay time. |
| 14614 | kVarInt62EightBytes + 0x31, 0x00, 0x00, 0x00, 0xF3, 0xA0, 0x81, 0xE0, |
| 14615 | // Nr. of additional ack blocks |
| 14616 | kVarInt62OneByte + 0x00, |
| 14617 | // first ack block length. |
| 14618 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x77, |
| 14619 | }; |
| 14620 | // clang-format on |
| 14621 | |
vasilvv | bed67c6 | 2020-10-20 06:38:43 -0700 | [diff] [blame] | 14622 | framer_.ProcessPacket( |
| 14623 | QuicEncryptedPacket(AsChars(packet99), ABSL_ARRAYSIZE(packet99), false)); |
fayang | 3371b09 | 2019-12-04 07:08:52 -0800 | [diff] [blame] | 14624 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 14625 | // Verify ack_delay_time is set correctly. |
| 14626 | EXPECT_EQ(QuicTime::Delta::Infinite(), |
| 14627 | visitor_.ack_frames_[0]->ack_delay_time); |
| 14628 | } |
| 14629 | |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14630 | TEST_P(QuicFramerTest, KeyUpdate) { |
| 14631 | if (!framer_.version().UsesTls()) { |
| 14632 | // Key update is only used in QUIC+TLS. |
| 14633 | return; |
| 14634 | } |
| 14635 | ASSERT_TRUE(framer_.version().KnowsWhichDecrypterToUse()); |
| 14636 | // Doesn't use SetDecrypterLevel since we want to use StrictTaggingDecrypter |
| 14637 | // instead of TestDecrypter. |
| 14638 | framer_.InstallDecrypter(ENCRYPTION_FORWARD_SECURE, |
| 14639 | std::make_unique<StrictTaggingDecrypter>(/*key=*/0)); |
| 14640 | framer_.SetKeyUpdateSupportForConnection(true); |
| 14641 | |
| 14642 | QuicPacketHeader header; |
| 14643 | header.destination_connection_id = FramerTestConnectionId(); |
| 14644 | header.reset_flag = false; |
| 14645 | header.version_flag = false; |
| 14646 | header.packet_number = kPacketNumber; |
| 14647 | |
| 14648 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 14649 | |
| 14650 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14651 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 14652 | ASSERT_TRUE(data != nullptr); |
| 14653 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 14654 | EncryptPacketWithTagAndPhase(*data, 0, false)); |
| 14655 | ASSERT_TRUE(encrypted); |
| 14656 | |
| 14657 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14658 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 14659 | // Processed valid packet with phase=0, key=1: no key update. |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 14660 | EXPECT_EQ(0u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14661 | EXPECT_EQ(0, visitor_.derive_next_key_count_); |
| 14662 | EXPECT_EQ(1, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 14663 | |
| 14664 | header.packet_number += 1; |
| 14665 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14666 | data = BuildDataPacket(header, frames); |
| 14667 | ASSERT_TRUE(data != nullptr); |
| 14668 | encrypted = EncryptPacketWithTagAndPhase(*data, 1, true); |
| 14669 | ASSERT_TRUE(encrypted); |
| 14670 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14671 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 14672 | // Processed valid packet with phase=1, key=2: key update should have |
| 14673 | // occurred. |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 14674 | ASSERT_EQ(1u, visitor_.key_update_count()); |
| 14675 | EXPECT_EQ(KeyUpdateReason::kRemote, visitor_.key_update_reasons_[0]); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14676 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 14677 | EXPECT_EQ(2, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 14678 | |
| 14679 | header.packet_number += 1; |
| 14680 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14681 | data = BuildDataPacket(header, frames); |
| 14682 | ASSERT_TRUE(data != nullptr); |
| 14683 | encrypted = EncryptPacketWithTagAndPhase(*data, 1, true); |
| 14684 | ASSERT_TRUE(encrypted); |
| 14685 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14686 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 14687 | // Processed another valid packet with phase=1, key=2: no key update. |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 14688 | EXPECT_EQ(1u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14689 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 14690 | EXPECT_EQ(2, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 14691 | |
| 14692 | // Process another key update. |
| 14693 | header.packet_number += 1; |
| 14694 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14695 | data = BuildDataPacket(header, frames); |
| 14696 | ASSERT_TRUE(data != nullptr); |
| 14697 | encrypted = EncryptPacketWithTagAndPhase(*data, 2, false); |
| 14698 | ASSERT_TRUE(encrypted); |
| 14699 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14700 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 14701 | ASSERT_EQ(2u, visitor_.key_update_count()); |
| 14702 | EXPECT_EQ(KeyUpdateReason::kRemote, visitor_.key_update_reasons_[1]); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14703 | EXPECT_EQ(2, visitor_.derive_next_key_count_); |
| 14704 | EXPECT_EQ(3, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 14705 | } |
| 14706 | |
| 14707 | TEST_P(QuicFramerTest, KeyUpdateOldPacketAfterUpdate) { |
| 14708 | if (!framer_.version().UsesTls()) { |
| 14709 | // Key update is only used in QUIC+TLS. |
| 14710 | return; |
| 14711 | } |
| 14712 | ASSERT_TRUE(framer_.version().KnowsWhichDecrypterToUse()); |
| 14713 | // Doesn't use SetDecrypterLevel since we want to use StrictTaggingDecrypter |
| 14714 | // instead of TestDecrypter. |
| 14715 | framer_.InstallDecrypter(ENCRYPTION_FORWARD_SECURE, |
| 14716 | std::make_unique<StrictTaggingDecrypter>(/*key=*/0)); |
| 14717 | framer_.SetKeyUpdateSupportForConnection(true); |
| 14718 | |
| 14719 | QuicPacketHeader header; |
| 14720 | header.destination_connection_id = FramerTestConnectionId(); |
| 14721 | header.reset_flag = false; |
| 14722 | header.version_flag = false; |
| 14723 | header.packet_number = kPacketNumber; |
| 14724 | |
| 14725 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 14726 | |
| 14727 | // Process packet N with phase 0. |
| 14728 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14729 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 14730 | ASSERT_TRUE(data != nullptr); |
| 14731 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 14732 | EncryptPacketWithTagAndPhase(*data, 0, false)); |
| 14733 | ASSERT_TRUE(encrypted); |
| 14734 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14735 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 14736 | EXPECT_EQ(0u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14737 | EXPECT_EQ(0, visitor_.derive_next_key_count_); |
| 14738 | EXPECT_EQ(1, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 14739 | |
| 14740 | // Process packet N+2 with phase 1. |
| 14741 | header.packet_number = kPacketNumber + 2; |
| 14742 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14743 | data = BuildDataPacket(header, frames); |
| 14744 | ASSERT_TRUE(data != nullptr); |
| 14745 | encrypted = EncryptPacketWithTagAndPhase(*data, 1, true); |
| 14746 | ASSERT_TRUE(encrypted); |
| 14747 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14748 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 14749 | EXPECT_EQ(1u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14750 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 14751 | EXPECT_EQ(2, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 14752 | |
| 14753 | // Process packet N+1 with phase 0. (Receiving packet from previous phase |
| 14754 | // after packet from new phase was received.) |
| 14755 | header.packet_number = kPacketNumber + 1; |
| 14756 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14757 | data = BuildDataPacket(header, frames); |
| 14758 | ASSERT_TRUE(data != nullptr); |
| 14759 | encrypted = EncryptPacketWithTagAndPhase(*data, 0, false); |
| 14760 | ASSERT_TRUE(encrypted); |
| 14761 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14762 | // Packet should decrypt and key update count should not change. |
| 14763 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 14764 | EXPECT_EQ(1u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14765 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 14766 | EXPECT_EQ(2, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 14767 | } |
| 14768 | |
| 14769 | TEST_P(QuicFramerTest, KeyUpdateOldPacketAfterDiscardPreviousOneRttKeys) { |
| 14770 | if (!framer_.version().UsesTls()) { |
| 14771 | // Key update is only used in QUIC+TLS. |
| 14772 | return; |
| 14773 | } |
| 14774 | ASSERT_TRUE(framer_.version().KnowsWhichDecrypterToUse()); |
| 14775 | // Doesn't use SetDecrypterLevel since we want to use StrictTaggingDecrypter |
| 14776 | // instead of TestDecrypter. |
| 14777 | framer_.InstallDecrypter(ENCRYPTION_FORWARD_SECURE, |
| 14778 | std::make_unique<StrictTaggingDecrypter>(/*key=*/0)); |
| 14779 | framer_.SetKeyUpdateSupportForConnection(true); |
| 14780 | |
| 14781 | QuicPacketHeader header; |
| 14782 | header.destination_connection_id = FramerTestConnectionId(); |
| 14783 | header.reset_flag = false; |
| 14784 | header.version_flag = false; |
| 14785 | header.packet_number = kPacketNumber; |
| 14786 | |
| 14787 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 14788 | |
| 14789 | // Process packet N with phase 0. |
| 14790 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14791 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 14792 | ASSERT_TRUE(data != nullptr); |
| 14793 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 14794 | EncryptPacketWithTagAndPhase(*data, 0, false)); |
| 14795 | ASSERT_TRUE(encrypted); |
| 14796 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14797 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 14798 | EXPECT_EQ(0u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14799 | EXPECT_EQ(0, visitor_.derive_next_key_count_); |
| 14800 | EXPECT_EQ(1, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 14801 | |
| 14802 | // Process packet N+2 with phase 1. |
| 14803 | header.packet_number = kPacketNumber + 2; |
| 14804 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14805 | data = BuildDataPacket(header, frames); |
| 14806 | ASSERT_TRUE(data != nullptr); |
| 14807 | encrypted = EncryptPacketWithTagAndPhase(*data, 1, true); |
| 14808 | ASSERT_TRUE(encrypted); |
| 14809 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14810 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 14811 | EXPECT_EQ(1u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14812 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 14813 | EXPECT_EQ(2, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 14814 | |
| 14815 | // Discard keys for previous key phase. |
| 14816 | framer_.DiscardPreviousOneRttKeys(); |
| 14817 | |
| 14818 | // Process packet N+1 with phase 0. (Receiving packet from previous phase |
| 14819 | // after packet from new phase was received.) |
| 14820 | header.packet_number = kPacketNumber + 1; |
| 14821 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14822 | data = BuildDataPacket(header, frames); |
| 14823 | ASSERT_TRUE(data != nullptr); |
| 14824 | encrypted = EncryptPacketWithTagAndPhase(*data, 0, false); |
| 14825 | ASSERT_TRUE(encrypted); |
| 14826 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14827 | // Packet should not decrypt and key update count should not change. |
| 14828 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 14829 | EXPECT_EQ(1u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14830 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 14831 | EXPECT_EQ(2, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 14832 | } |
| 14833 | |
| 14834 | TEST_P(QuicFramerTest, KeyUpdatePacketsOutOfOrder) { |
| 14835 | if (!framer_.version().UsesTls()) { |
| 14836 | // Key update is only used in QUIC+TLS. |
| 14837 | return; |
| 14838 | } |
| 14839 | ASSERT_TRUE(framer_.version().KnowsWhichDecrypterToUse()); |
| 14840 | // Doesn't use SetDecrypterLevel since we want to use StrictTaggingDecrypter |
| 14841 | // instead of TestDecrypter. |
| 14842 | framer_.InstallDecrypter(ENCRYPTION_FORWARD_SECURE, |
| 14843 | std::make_unique<StrictTaggingDecrypter>(/*key=*/0)); |
| 14844 | framer_.SetKeyUpdateSupportForConnection(true); |
| 14845 | |
| 14846 | QuicPacketHeader header; |
| 14847 | header.destination_connection_id = FramerTestConnectionId(); |
| 14848 | header.reset_flag = false; |
| 14849 | header.version_flag = false; |
| 14850 | header.packet_number = kPacketNumber; |
| 14851 | |
| 14852 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 14853 | |
| 14854 | // Process packet N with phase 0. |
| 14855 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14856 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 14857 | ASSERT_TRUE(data != nullptr); |
| 14858 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 14859 | EncryptPacketWithTagAndPhase(*data, 0, false)); |
| 14860 | ASSERT_TRUE(encrypted); |
| 14861 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14862 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 14863 | EXPECT_EQ(0u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14864 | EXPECT_EQ(0, visitor_.derive_next_key_count_); |
| 14865 | EXPECT_EQ(1, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 14866 | |
| 14867 | // Process packet N+2 with phase 1. |
| 14868 | header.packet_number = kPacketNumber + 2; |
| 14869 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14870 | data = BuildDataPacket(header, frames); |
| 14871 | ASSERT_TRUE(data != nullptr); |
| 14872 | encrypted = EncryptPacketWithTagAndPhase(*data, 1, true); |
| 14873 | ASSERT_TRUE(encrypted); |
| 14874 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14875 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 14876 | EXPECT_EQ(1u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14877 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 14878 | EXPECT_EQ(2, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 14879 | |
| 14880 | // Process packet N+1 with phase 1. (Receiving packet from new phase out of |
| 14881 | // order.) |
| 14882 | header.packet_number = kPacketNumber + 1; |
| 14883 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14884 | data = BuildDataPacket(header, frames); |
| 14885 | ASSERT_TRUE(data != nullptr); |
| 14886 | encrypted = EncryptPacketWithTagAndPhase(*data, 1, true); |
| 14887 | ASSERT_TRUE(encrypted); |
| 14888 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14889 | // Packet should decrypt and key update count should not change. |
| 14890 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 14891 | EXPECT_EQ(1u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14892 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 14893 | EXPECT_EQ(2, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 14894 | } |
| 14895 | |
| 14896 | TEST_P(QuicFramerTest, KeyUpdateWrongKey) { |
| 14897 | if (!framer_.version().UsesTls()) { |
| 14898 | // Key update is only used in QUIC+TLS. |
| 14899 | return; |
| 14900 | } |
| 14901 | ASSERT_TRUE(framer_.version().KnowsWhichDecrypterToUse()); |
| 14902 | // Doesn't use SetDecrypterLevel since we want to use StrictTaggingDecrypter |
| 14903 | // instead of TestDecrypter. |
| 14904 | framer_.InstallDecrypter(ENCRYPTION_FORWARD_SECURE, |
| 14905 | std::make_unique<StrictTaggingDecrypter>(/*key=*/0)); |
| 14906 | framer_.SetKeyUpdateSupportForConnection(true); |
| 14907 | |
| 14908 | QuicPacketHeader header; |
| 14909 | header.destination_connection_id = FramerTestConnectionId(); |
| 14910 | header.reset_flag = false; |
| 14911 | header.version_flag = false; |
| 14912 | header.packet_number = kPacketNumber; |
| 14913 | |
| 14914 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 14915 | |
| 14916 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14917 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 14918 | ASSERT_TRUE(data != nullptr); |
| 14919 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 14920 | EncryptPacketWithTagAndPhase(*data, 0, false)); |
| 14921 | ASSERT_TRUE(encrypted); |
| 14922 | |
| 14923 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14924 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 14925 | // Processed valid packet with phase=0, key=1: no key update. |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 14926 | EXPECT_EQ(0u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14927 | EXPECT_EQ(0, visitor_.derive_next_key_count_); |
| 14928 | EXPECT_EQ(1, visitor_.decrypted_first_packet_in_key_phase_count_); |
mattm | d061ef1 | 2020-10-23 11:21:31 -0700 | [diff] [blame] | 14929 | EXPECT_EQ(0u, framer_.PotentialPeerKeyUpdateAttemptCount()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14930 | |
| 14931 | header.packet_number += 1; |
| 14932 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14933 | data = BuildDataPacket(header, frames); |
| 14934 | ASSERT_TRUE(data != nullptr); |
| 14935 | encrypted = EncryptPacketWithTagAndPhase(*data, 2, true); |
| 14936 | ASSERT_TRUE(encrypted); |
| 14937 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14938 | // Packet with phase=1 but key=3, should not process and should not cause key |
| 14939 | // update, but next decrypter key should have been created to attempt to |
| 14940 | // decode it. |
| 14941 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 14942 | EXPECT_EQ(0u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14943 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 14944 | EXPECT_EQ(1, visitor_.decrypted_first_packet_in_key_phase_count_); |
mattm | d061ef1 | 2020-10-23 11:21:31 -0700 | [diff] [blame] | 14945 | EXPECT_EQ(1u, framer_.PotentialPeerKeyUpdateAttemptCount()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14946 | |
| 14947 | header.packet_number += 1; |
| 14948 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14949 | data = BuildDataPacket(header, frames); |
| 14950 | ASSERT_TRUE(data != nullptr); |
| 14951 | encrypted = EncryptPacketWithTagAndPhase(*data, 0, true); |
| 14952 | ASSERT_TRUE(encrypted); |
| 14953 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14954 | // Packet with phase=1 but key=1, should not process and should not cause key |
| 14955 | // update. |
| 14956 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 14957 | EXPECT_EQ(0u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14958 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 14959 | EXPECT_EQ(1, visitor_.decrypted_first_packet_in_key_phase_count_); |
mattm | d061ef1 | 2020-10-23 11:21:31 -0700 | [diff] [blame] | 14960 | EXPECT_EQ(2u, framer_.PotentialPeerKeyUpdateAttemptCount()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14961 | |
| 14962 | header.packet_number += 1; |
| 14963 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14964 | data = BuildDataPacket(header, frames); |
| 14965 | ASSERT_TRUE(data != nullptr); |
| 14966 | encrypted = EncryptPacketWithTagAndPhase(*data, 1, false); |
| 14967 | ASSERT_TRUE(encrypted); |
| 14968 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14969 | // Packet with phase=0 but key=2, should not process and should not cause key |
| 14970 | // update. |
| 14971 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 14972 | EXPECT_EQ(0u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14973 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 14974 | EXPECT_EQ(1, visitor_.decrypted_first_packet_in_key_phase_count_); |
mattm | d061ef1 | 2020-10-23 11:21:31 -0700 | [diff] [blame] | 14975 | EXPECT_EQ(2u, framer_.PotentialPeerKeyUpdateAttemptCount()); |
| 14976 | |
| 14977 | header.packet_number += 1; |
| 14978 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 14979 | data = BuildDataPacket(header, frames); |
| 14980 | ASSERT_TRUE(data != nullptr); |
| 14981 | encrypted = EncryptPacketWithTagAndPhase(*data, 0, false); |
| 14982 | ASSERT_TRUE(encrypted); |
| 14983 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 14984 | // Packet with phase=0 and key=0, should process and reset |
| 14985 | // potential_peer_key_update_attempt_count_. |
| 14986 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 14987 | EXPECT_EQ(0u, visitor_.key_update_count()); |
| 14988 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 14989 | EXPECT_EQ(1, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 14990 | EXPECT_EQ(0u, framer_.PotentialPeerKeyUpdateAttemptCount()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 14991 | } |
| 14992 | |
| 14993 | TEST_P(QuicFramerTest, KeyUpdateReceivedWhenNotEnabled) { |
| 14994 | if (!framer_.version().UsesTls()) { |
| 14995 | // Key update is only used in QUIC+TLS. |
| 14996 | return; |
| 14997 | } |
| 14998 | ASSERT_TRUE(framer_.version().KnowsWhichDecrypterToUse()); |
| 14999 | // Doesn't use SetDecrypterLevel since we want to use StrictTaggingDecrypter |
| 15000 | // instead of TestDecrypter. |
| 15001 | framer_.InstallDecrypter(ENCRYPTION_FORWARD_SECURE, |
| 15002 | std::make_unique<StrictTaggingDecrypter>(/*key=*/0)); |
| 15003 | |
| 15004 | QuicPacketHeader header; |
| 15005 | header.destination_connection_id = FramerTestConnectionId(); |
| 15006 | header.reset_flag = false; |
| 15007 | header.version_flag = false; |
| 15008 | header.packet_number = kPacketNumber; |
| 15009 | |
| 15010 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 15011 | |
| 15012 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 15013 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 15014 | ASSERT_TRUE(data != nullptr); |
| 15015 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 15016 | EncryptPacketWithTagAndPhase(*data, 1, true)); |
| 15017 | ASSERT_TRUE(encrypted); |
| 15018 | |
| 15019 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 15020 | // Received a packet with key phase updated even though framer hasn't had key |
| 15021 | // update enabled (SetNextOneRttCrypters never called). Should fail to |
| 15022 | // process. |
| 15023 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 15024 | EXPECT_EQ(0u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 15025 | EXPECT_EQ(0, visitor_.derive_next_key_count_); |
| 15026 | EXPECT_EQ(0, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 15027 | } |
| 15028 | |
| 15029 | TEST_P(QuicFramerTest, KeyUpdateLocallyInitiated) { |
| 15030 | if (!framer_.version().UsesTls()) { |
| 15031 | // Key update is only used in QUIC+TLS. |
| 15032 | return; |
| 15033 | } |
| 15034 | ASSERT_TRUE(framer_.version().KnowsWhichDecrypterToUse()); |
| 15035 | // Doesn't use SetDecrypterLevel since we want to use StrictTaggingDecrypter |
| 15036 | // instead of TestDecrypter. |
| 15037 | framer_.InstallDecrypter(ENCRYPTION_FORWARD_SECURE, |
| 15038 | std::make_unique<StrictTaggingDecrypter>(/*key=*/0)); |
| 15039 | framer_.SetKeyUpdateSupportForConnection(true); |
| 15040 | |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 15041 | EXPECT_TRUE(framer_.DoKeyUpdate(KeyUpdateReason::kLocalForTests)); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 15042 | // Key update count should be updated, but haven't received packet from peer |
| 15043 | // with new key phase. |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 15044 | ASSERT_EQ(1u, visitor_.key_update_count()); |
| 15045 | EXPECT_EQ(KeyUpdateReason::kLocalForTests, visitor_.key_update_reasons_[0]); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 15046 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 15047 | EXPECT_EQ(0, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 15048 | |
| 15049 | QuicPacketHeader header; |
| 15050 | header.destination_connection_id = FramerTestConnectionId(); |
| 15051 | header.reset_flag = false; |
| 15052 | header.version_flag = false; |
| 15053 | header.packet_number = kPacketNumber; |
| 15054 | |
| 15055 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 15056 | |
| 15057 | // Process packet N with phase 1. |
| 15058 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 15059 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 15060 | ASSERT_TRUE(data != nullptr); |
| 15061 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 15062 | EncryptPacketWithTagAndPhase(*data, 1, true)); |
| 15063 | ASSERT_TRUE(encrypted); |
| 15064 | |
| 15065 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 15066 | // Packet should decrypt and key update count should not change and |
| 15067 | // OnDecryptedFirstPacketInKeyPhase should have been called. |
| 15068 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 15069 | EXPECT_EQ(1u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 15070 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 15071 | EXPECT_EQ(1, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 15072 | |
| 15073 | // Process packet N-1 with phase 0. (Receiving packet from previous phase |
| 15074 | // after packet from new phase was received.) |
| 15075 | header.packet_number = kPacketNumber - 1; |
| 15076 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 15077 | data = BuildDataPacket(header, frames); |
| 15078 | ASSERT_TRUE(data != nullptr); |
| 15079 | encrypted = EncryptPacketWithTagAndPhase(*data, 0, false); |
| 15080 | ASSERT_TRUE(encrypted); |
| 15081 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 15082 | // Packet should decrypt and key update count should not change. |
| 15083 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 15084 | EXPECT_EQ(1u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 15085 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 15086 | EXPECT_EQ(1, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 15087 | |
| 15088 | // Process packet N+1 with phase 0 and key 1. This should not decrypt even |
| 15089 | // though it's using the previous key, since the packet number is higher than |
| 15090 | // a packet number received using the current key. |
| 15091 | header.packet_number = kPacketNumber + 1; |
| 15092 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 15093 | data = BuildDataPacket(header, frames); |
| 15094 | ASSERT_TRUE(data != nullptr); |
| 15095 | encrypted = EncryptPacketWithTagAndPhase(*data, 0, false); |
| 15096 | ASSERT_TRUE(encrypted); |
| 15097 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 15098 | // Packet should not decrypt and key update count should not change. |
| 15099 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 15100 | EXPECT_EQ(1u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 15101 | EXPECT_EQ(2, visitor_.derive_next_key_count_); |
| 15102 | EXPECT_EQ(1, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 15103 | } |
| 15104 | |
| 15105 | TEST_P(QuicFramerTest, KeyUpdateLocallyInitiatedReceivedOldPacket) { |
| 15106 | if (!framer_.version().UsesTls()) { |
| 15107 | // Key update is only used in QUIC+TLS. |
| 15108 | return; |
| 15109 | } |
| 15110 | ASSERT_TRUE(framer_.version().KnowsWhichDecrypterToUse()); |
| 15111 | // Doesn't use SetDecrypterLevel since we want to use StrictTaggingDecrypter |
| 15112 | // instead of TestDecrypter. |
| 15113 | framer_.InstallDecrypter(ENCRYPTION_FORWARD_SECURE, |
| 15114 | std::make_unique<StrictTaggingDecrypter>(/*key=*/0)); |
| 15115 | framer_.SetKeyUpdateSupportForConnection(true); |
| 15116 | |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 15117 | EXPECT_TRUE(framer_.DoKeyUpdate(KeyUpdateReason::kLocalForTests)); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 15118 | // Key update count should be updated, but haven't received packet |
| 15119 | // from peer with new key phase. |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 15120 | EXPECT_EQ(1u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 15121 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 15122 | EXPECT_EQ(0, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 15123 | |
| 15124 | QuicPacketHeader header; |
| 15125 | header.destination_connection_id = FramerTestConnectionId(); |
| 15126 | header.reset_flag = false; |
| 15127 | header.version_flag = false; |
| 15128 | header.packet_number = kPacketNumber; |
| 15129 | |
| 15130 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 15131 | |
| 15132 | // Process packet N with phase 0. (Receiving packet from previous phase |
| 15133 | // after locally initiated key update, but before any packet from new phase |
| 15134 | // was received.) |
| 15135 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 15136 | std::unique_ptr<QuicPacket> data = BuildDataPacket(header, frames); |
| 15137 | ASSERT_TRUE(data != nullptr); |
| 15138 | std::unique_ptr<QuicEncryptedPacket> encrypted = |
| 15139 | EncryptPacketWithTagAndPhase(*data, 0, false); |
| 15140 | ASSERT_TRUE(encrypted); |
| 15141 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 15142 | // Packet should decrypt and key update count should not change and |
| 15143 | // OnDecryptedFirstPacketInKeyPhase should not have been called since the |
| 15144 | // packet was from the previous key phase. |
| 15145 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 15146 | EXPECT_EQ(1u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 15147 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 15148 | EXPECT_EQ(0, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 15149 | |
| 15150 | // Process packet N+1 with phase 1. |
| 15151 | header.packet_number = kPacketNumber + 1; |
| 15152 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 15153 | data = BuildDataPacket(header, frames); |
| 15154 | ASSERT_TRUE(data != nullptr); |
| 15155 | encrypted = EncryptPacketWithTagAndPhase(*data, 1, true); |
| 15156 | ASSERT_TRUE(encrypted); |
| 15157 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 15158 | // Packet should decrypt and key update count should not change, but |
| 15159 | // OnDecryptedFirstPacketInKeyPhase should have been called. |
| 15160 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 15161 | EXPECT_EQ(1u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 15162 | EXPECT_EQ(1, visitor_.derive_next_key_count_); |
| 15163 | EXPECT_EQ(1, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 15164 | |
| 15165 | // Process packet N+2 with phase 0 and key 1. This should not decrypt even |
| 15166 | // though it's using the previous key, since the packet number is higher than |
| 15167 | // a packet number received using the current key. |
| 15168 | header.packet_number = kPacketNumber + 2; |
| 15169 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 15170 | data = BuildDataPacket(header, frames); |
| 15171 | ASSERT_TRUE(data != nullptr); |
| 15172 | encrypted = EncryptPacketWithTagAndPhase(*data, 0, false); |
| 15173 | ASSERT_TRUE(encrypted); |
| 15174 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 15175 | // Packet should not decrypt and key update count should not change. |
| 15176 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
mattm | 5c7090d | 2020-10-19 10:36:43 -0700 | [diff] [blame] | 15177 | EXPECT_EQ(1u, visitor_.key_update_count()); |
mattm | 072a7e3 | 2020-10-09 16:16:56 -0700 | [diff] [blame] | 15178 | EXPECT_EQ(2, visitor_.derive_next_key_count_); |
| 15179 | EXPECT_EQ(1, visitor_.decrypted_first_packet_in_key_phase_count_); |
| 15180 | } |
| 15181 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 15182 | } // namespace |
| 15183 | } // namespace test |
| 15184 | } // namespace quic |