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> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 12 | #include <vector> |
| 13 | |
| 14 | #include "net/third_party/quiche/src/quic/core/crypto/null_decrypter.h" |
| 15 | #include "net/third_party/quiche/src/quic/core/crypto/null_encrypter.h" |
| 16 | #include "net/third_party/quiche/src/quic/core/crypto/quic_decrypter.h" |
| 17 | #include "net/third_party/quiche/src/quic/core/crypto/quic_encrypter.h" |
| 18 | #include "net/third_party/quiche/src/quic/core/quic_connection_id.h" |
| 19 | #include "net/third_party/quiche/src/quic/core/quic_packets.h" |
| 20 | #include "net/third_party/quiche/src/quic/core/quic_types.h" |
| 21 | #include "net/third_party/quiche/src/quic/core/quic_utils.h" |
| 22 | #include "net/third_party/quiche/src/quic/platform/api/quic_arraysize.h" |
| 23 | #include "net/third_party/quiche/src/quic/platform/api/quic_expect_bug.h" |
| 24 | #include "net/third_party/quiche/src/quic/platform/api/quic_flags.h" |
| 25 | #include "net/third_party/quiche/src/quic/platform/api/quic_logging.h" |
| 26 | #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] | 27 | #include "net/third_party/quiche/src/quic/platform/api/quic_test.h" |
| 28 | #include "net/third_party/quiche/src/quic/platform/api/quic_text_utils.h" |
| 29 | #include "net/third_party/quiche/src/quic/test_tools/quic_framer_peer.h" |
| 30 | #include "net/third_party/quiche/src/quic/test_tools/quic_test_utils.h" |
| 31 | #include "net/third_party/quiche/src/quic/test_tools/simple_data_producer.h" |
| 32 | |
| 33 | using testing::_; |
| 34 | using testing::Return; |
| 35 | using testing::Truly; |
| 36 | |
| 37 | namespace quic { |
| 38 | namespace test { |
| 39 | namespace { |
| 40 | |
| 41 | const uint64_t kEpoch = UINT64_C(1) << 32; |
| 42 | const uint64_t kMask = kEpoch - 1; |
| 43 | |
| 44 | const QuicUint128 kTestStatelessResetToken = 1010101; // 0x0F69B5 |
| 45 | |
| 46 | // Use fields in which each byte is distinct to ensure that every byte is |
| 47 | // framed correctly. The values are otherwise arbitrary. |
| 48 | QuicConnectionId FramerTestConnectionId() { |
| 49 | return TestConnectionId(UINT64_C(0xFEDCBA9876543210)); |
| 50 | } |
| 51 | |
| 52 | QuicConnectionId FramerTestConnectionIdPlusOne() { |
| 53 | return TestConnectionId(UINT64_C(0xFEDCBA9876543211)); |
| 54 | } |
| 55 | |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame^] | 56 | QuicConnectionId FramerTestConnectionIdNineBytes() { |
| 57 | char connection_id_bytes[9] = {0xFE, 0xDC, 0xBA, 0x98, 0x76, |
| 58 | 0x54, 0x32, 0x10, 0x42}; |
| 59 | return QuicConnectionId(connection_id_bytes, sizeof(connection_id_bytes)); |
| 60 | } |
| 61 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 62 | const QuicPacketNumber kPacketNumber = QuicPacketNumber(UINT64_C(0x12345678)); |
| 63 | const QuicPacketNumber kSmallLargestObserved = |
| 64 | QuicPacketNumber(UINT16_C(0x1234)); |
| 65 | const QuicPacketNumber kSmallMissingPacket = QuicPacketNumber(UINT16_C(0x1233)); |
| 66 | const QuicPacketNumber kLeastUnacked = QuicPacketNumber(UINT64_C(0x012345670)); |
| 67 | const QuicStreamId kStreamId = UINT64_C(0x01020304); |
| 68 | // Note that the high 4 bits of the stream offset must be less than 0x40 |
| 69 | // in order to ensure that the value can be encoded using VarInt62 encoding. |
| 70 | const QuicStreamOffset kStreamOffset = UINT64_C(0x3A98FEDC32107654); |
| 71 | const QuicPublicResetNonceProof kNonceProof = UINT64_C(0xABCDEF0123456789); |
| 72 | |
| 73 | // In testing that we can ack the full range of packets... |
| 74 | // This is the largest packet number that can be represented in IETF QUIC |
| 75 | // varint62 format. |
| 76 | const QuicPacketNumber kLargestIetfLargestObserved = |
| 77 | QuicPacketNumber(UINT64_C(0x3fffffffffffffff)); |
| 78 | // Encodings for the two bits in a VarInt62 that |
| 79 | // describe the length of the VarInt61. For binary packet |
| 80 | // formats in this file, the convention is to code the |
| 81 | // first byte as |
| 82 | // kVarInt62FourBytes + 0x<value_in_that_byte> |
| 83 | const uint8_t kVarInt62OneByte = 0x00; |
| 84 | const uint8_t kVarInt62TwoBytes = 0x40; |
| 85 | const uint8_t kVarInt62FourBytes = 0x80; |
| 86 | const uint8_t kVarInt62EightBytes = 0xc0; |
| 87 | |
| 88 | class TestEncrypter : public QuicEncrypter { |
| 89 | public: |
| 90 | ~TestEncrypter() override {} |
| 91 | bool SetKey(QuicStringPiece key) override { return true; } |
| 92 | bool SetNoncePrefix(QuicStringPiece nonce_prefix) override { return true; } |
| 93 | bool SetIV(QuicStringPiece iv) override { return true; } |
| 94 | bool EncryptPacket(uint64_t packet_number, |
| 95 | QuicStringPiece associated_data, |
| 96 | QuicStringPiece plaintext, |
| 97 | char* output, |
| 98 | size_t* output_length, |
| 99 | size_t max_output_length) override { |
| 100 | packet_number_ = QuicPacketNumber(packet_number); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 101 | associated_data_ = std::string(associated_data); |
| 102 | plaintext_ = std::string(plaintext); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 103 | memcpy(output, plaintext.data(), plaintext.length()); |
| 104 | *output_length = plaintext.length(); |
| 105 | return true; |
| 106 | } |
| 107 | size_t GetKeySize() const override { return 0; } |
| 108 | size_t GetNoncePrefixSize() const override { return 0; } |
| 109 | size_t GetIVSize() const override { return 0; } |
| 110 | size_t GetMaxPlaintextSize(size_t ciphertext_size) const override { |
| 111 | return ciphertext_size; |
| 112 | } |
| 113 | size_t GetCiphertextSize(size_t plaintext_size) const override { |
| 114 | return plaintext_size; |
| 115 | } |
| 116 | QuicStringPiece GetKey() const override { return QuicStringPiece(); } |
| 117 | QuicStringPiece GetNoncePrefix() const override { return QuicStringPiece(); } |
| 118 | |
| 119 | QuicPacketNumber packet_number_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 120 | std::string associated_data_; |
| 121 | std::string plaintext_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | class TestDecrypter : public QuicDecrypter { |
| 125 | public: |
| 126 | ~TestDecrypter() override {} |
| 127 | bool SetKey(QuicStringPiece key) override { return true; } |
| 128 | bool SetNoncePrefix(QuicStringPiece nonce_prefix) override { return true; } |
| 129 | bool SetIV(QuicStringPiece iv) override { return true; } |
| 130 | bool SetPreliminaryKey(QuicStringPiece key) override { |
| 131 | QUIC_BUG << "should not be called"; |
| 132 | return false; |
| 133 | } |
| 134 | bool SetDiversificationNonce(const DiversificationNonce& key) override { |
| 135 | return true; |
| 136 | } |
| 137 | bool DecryptPacket(uint64_t packet_number, |
| 138 | QuicStringPiece associated_data, |
| 139 | QuicStringPiece ciphertext, |
| 140 | char* output, |
| 141 | size_t* output_length, |
| 142 | size_t max_output_length) override { |
| 143 | packet_number_ = QuicPacketNumber(packet_number); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 144 | associated_data_ = std::string(associated_data); |
| 145 | ciphertext_ = std::string(ciphertext); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 146 | memcpy(output, ciphertext.data(), ciphertext.length()); |
| 147 | *output_length = ciphertext.length(); |
| 148 | return true; |
| 149 | } |
| 150 | size_t GetKeySize() const override { return 0; } |
| 151 | size_t GetIVSize() const override { return 0; } |
| 152 | QuicStringPiece GetKey() const override { return QuicStringPiece(); } |
| 153 | QuicStringPiece GetNoncePrefix() const override { return QuicStringPiece(); } |
| 154 | // Use a distinct value starting with 0xFFFFFF, which is never used by TLS. |
| 155 | uint32_t cipher_id() const override { return 0xFFFFFFF2; } |
| 156 | QuicPacketNumber packet_number_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 157 | std::string associated_data_; |
| 158 | std::string ciphertext_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | class TestQuicVisitor : public QuicFramerVisitorInterface { |
| 162 | public: |
| 163 | TestQuicVisitor() |
| 164 | : error_count_(0), |
| 165 | version_mismatch_(0), |
| 166 | packet_count_(0), |
| 167 | frame_count_(0), |
| 168 | complete_packets_(0), |
| 169 | accept_packet_(true), |
| 170 | accept_public_header_(true) {} |
| 171 | |
| 172 | ~TestQuicVisitor() override {} |
| 173 | |
| 174 | void OnError(QuicFramer* f) override { |
| 175 | QUIC_DLOG(INFO) << "QuicFramer Error: " << QuicErrorCodeToString(f->error()) |
| 176 | << " (" << f->error() << ")"; |
| 177 | ++error_count_; |
| 178 | } |
| 179 | |
| 180 | void OnPacket() override {} |
| 181 | |
| 182 | void OnPublicResetPacket(const QuicPublicResetPacket& packet) override { |
| 183 | public_reset_packet_ = QuicMakeUnique<QuicPublicResetPacket>((packet)); |
| 184 | } |
| 185 | |
| 186 | void OnVersionNegotiationPacket( |
| 187 | const QuicVersionNegotiationPacket& packet) override { |
| 188 | version_negotiation_packet_ = |
| 189 | QuicMakeUnique<QuicVersionNegotiationPacket>((packet)); |
| 190 | } |
| 191 | |
| 192 | bool OnProtocolVersionMismatch(ParsedQuicVersion received_version, |
| 193 | PacketHeaderFormat /*form*/) override { |
| 194 | QUIC_DLOG(INFO) << "QuicFramer Version Mismatch, version: " |
| 195 | << received_version; |
| 196 | ++version_mismatch_; |
| 197 | return true; |
| 198 | } |
| 199 | |
| 200 | bool OnUnauthenticatedPublicHeader(const QuicPacketHeader& header) override { |
| 201 | header_ = QuicMakeUnique<QuicPacketHeader>((header)); |
| 202 | return accept_public_header_; |
| 203 | } |
| 204 | |
| 205 | bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override { |
| 206 | return true; |
| 207 | } |
| 208 | |
| 209 | void OnDecryptedPacket(EncryptionLevel level) override {} |
| 210 | |
| 211 | bool OnPacketHeader(const QuicPacketHeader& header) override { |
| 212 | ++packet_count_; |
| 213 | header_ = QuicMakeUnique<QuicPacketHeader>((header)); |
| 214 | return accept_packet_; |
| 215 | } |
| 216 | |
| 217 | void OnCoalescedPacket(const QuicEncryptedPacket& packet) override { |
| 218 | size_t coalesced_data_length = packet.length(); |
| 219 | char* coalesced_data = new char[coalesced_data_length]; |
| 220 | memcpy(coalesced_data, packet.data(), coalesced_data_length); |
| 221 | coalesced_packets_.push_back(QuicMakeUnique<QuicEncryptedPacket>( |
| 222 | coalesced_data, coalesced_data_length, |
| 223 | /*owns_buffer=*/true)); |
| 224 | } |
| 225 | |
| 226 | bool OnStreamFrame(const QuicStreamFrame& frame) override { |
| 227 | ++frame_count_; |
| 228 | // 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] | 229 | std::string* string_data = |
| 230 | new std::string(frame.data_buffer, frame.data_length); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 231 | stream_data_.push_back(QuicWrapUnique(string_data)); |
| 232 | stream_frames_.push_back(QuicMakeUnique<QuicStreamFrame>( |
| 233 | frame.stream_id, frame.fin, frame.offset, *string_data)); |
| 234 | return true; |
| 235 | } |
| 236 | |
| 237 | bool OnCryptoFrame(const QuicCryptoFrame& frame) override { |
| 238 | ++frame_count_; |
| 239 | // 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] | 240 | std::string* string_data = |
| 241 | new std::string(frame.data_buffer, frame.data_length); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 242 | crypto_data_.push_back(QuicWrapUnique(string_data)); |
| 243 | crypto_frames_.push_back(QuicMakeUnique<QuicCryptoFrame>( |
| 244 | ENCRYPTION_NONE, frame.offset, *string_data)); |
| 245 | return true; |
| 246 | } |
| 247 | |
| 248 | bool OnAckFrameStart(QuicPacketNumber largest_acked, |
| 249 | QuicTime::Delta ack_delay_time) override { |
| 250 | ++frame_count_; |
| 251 | QuicAckFrame ack_frame; |
| 252 | ack_frame.largest_acked = largest_acked; |
| 253 | ack_frame.ack_delay_time = ack_delay_time; |
| 254 | ack_frames_.push_back(QuicMakeUnique<QuicAckFrame>(ack_frame)); |
| 255 | return true; |
| 256 | } |
| 257 | |
| 258 | bool OnAckRange(QuicPacketNumber start, QuicPacketNumber end) override { |
| 259 | DCHECK(!ack_frames_.empty()); |
| 260 | ack_frames_[ack_frames_.size() - 1]->packets.AddRange(start, end); |
| 261 | return true; |
| 262 | } |
| 263 | |
| 264 | bool OnAckTimestamp(QuicPacketNumber packet_number, |
| 265 | QuicTime timestamp) override { |
| 266 | ack_frames_[ack_frames_.size() - 1]->received_packet_times.push_back( |
| 267 | std::make_pair(packet_number, timestamp)); |
| 268 | return true; |
| 269 | } |
| 270 | |
| 271 | bool OnAckFrameEnd(QuicPacketNumber /*start*/) override { return true; } |
| 272 | |
| 273 | bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override { |
| 274 | ++frame_count_; |
| 275 | stop_waiting_frames_.push_back(QuicMakeUnique<QuicStopWaitingFrame>(frame)); |
| 276 | return true; |
| 277 | } |
| 278 | |
| 279 | bool OnPaddingFrame(const QuicPaddingFrame& frame) override { |
| 280 | padding_frames_.push_back(QuicMakeUnique<QuicPaddingFrame>(frame)); |
| 281 | return true; |
| 282 | } |
| 283 | |
| 284 | bool OnPingFrame(const QuicPingFrame& frame) override { |
| 285 | ++frame_count_; |
| 286 | ping_frames_.push_back(QuicMakeUnique<QuicPingFrame>(frame)); |
| 287 | return true; |
| 288 | } |
| 289 | |
| 290 | bool OnMessageFrame(const QuicMessageFrame& frame) override { |
| 291 | ++frame_count_; |
| 292 | message_frames_.push_back( |
| 293 | QuicMakeUnique<QuicMessageFrame>(frame.data, frame.message_length)); |
| 294 | return true; |
| 295 | } |
| 296 | |
| 297 | void OnPacketComplete() override { ++complete_packets_; } |
| 298 | |
| 299 | bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override { |
| 300 | rst_stream_frame_ = frame; |
| 301 | return true; |
| 302 | } |
| 303 | |
| 304 | bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override { |
| 305 | connection_close_frame_ = frame; |
| 306 | return true; |
| 307 | } |
| 308 | |
| 309 | bool OnApplicationCloseFrame( |
| 310 | const QuicApplicationCloseFrame& frame) override { |
| 311 | application_close_frame_ = frame; |
| 312 | return true; |
| 313 | } |
| 314 | |
| 315 | bool OnStopSendingFrame(const QuicStopSendingFrame& frame) override { |
| 316 | stop_sending_frame_ = frame; |
| 317 | return true; |
| 318 | } |
| 319 | |
| 320 | bool OnPathChallengeFrame(const QuicPathChallengeFrame& frame) override { |
| 321 | path_challenge_frame_ = frame; |
| 322 | return true; |
| 323 | } |
| 324 | |
| 325 | bool OnPathResponseFrame(const QuicPathResponseFrame& frame) override { |
| 326 | path_response_frame_ = frame; |
| 327 | return true; |
| 328 | } |
| 329 | |
| 330 | bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override { |
| 331 | goaway_frame_ = frame; |
| 332 | return true; |
| 333 | } |
| 334 | |
| 335 | bool OnMaxStreamIdFrame(const QuicMaxStreamIdFrame& frame) override { |
| 336 | max_stream_id_frame_ = frame; |
| 337 | return true; |
| 338 | } |
| 339 | |
| 340 | bool OnStreamIdBlockedFrame(const QuicStreamIdBlockedFrame& frame) override { |
| 341 | stream_id_blocked_frame_ = frame; |
| 342 | return true; |
| 343 | } |
| 344 | |
| 345 | bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override { |
| 346 | window_update_frame_ = frame; |
| 347 | return true; |
| 348 | } |
| 349 | |
| 350 | bool OnBlockedFrame(const QuicBlockedFrame& frame) override { |
| 351 | blocked_frame_ = frame; |
| 352 | return true; |
| 353 | } |
| 354 | |
| 355 | bool OnNewConnectionIdFrame(const QuicNewConnectionIdFrame& frame) override { |
| 356 | new_connection_id_ = frame; |
| 357 | return true; |
| 358 | } |
| 359 | |
| 360 | bool OnRetireConnectionIdFrame( |
| 361 | const QuicRetireConnectionIdFrame& frame) override { |
| 362 | retire_connection_id_ = frame; |
| 363 | return true; |
| 364 | } |
| 365 | |
| 366 | bool OnNewTokenFrame(const QuicNewTokenFrame& frame) override { |
| 367 | new_token_ = frame; |
| 368 | return true; |
| 369 | } |
| 370 | |
| 371 | bool IsValidStatelessResetToken(QuicUint128 token) const override { |
| 372 | return token == kTestStatelessResetToken; |
| 373 | } |
| 374 | |
| 375 | void OnAuthenticatedIetfStatelessResetPacket( |
| 376 | const QuicIetfStatelessResetPacket& packet) override { |
| 377 | stateless_reset_packet_ = |
| 378 | QuicMakeUnique<QuicIetfStatelessResetPacket>(packet); |
| 379 | } |
| 380 | |
| 381 | // Counters from the visitor_ callbacks. |
| 382 | int error_count_; |
| 383 | int version_mismatch_; |
| 384 | int packet_count_; |
| 385 | int frame_count_; |
| 386 | int complete_packets_; |
| 387 | bool accept_packet_; |
| 388 | bool accept_public_header_; |
| 389 | |
| 390 | std::unique_ptr<QuicPacketHeader> header_; |
| 391 | std::unique_ptr<QuicPublicResetPacket> public_reset_packet_; |
| 392 | std::unique_ptr<QuicIetfStatelessResetPacket> stateless_reset_packet_; |
| 393 | std::unique_ptr<QuicVersionNegotiationPacket> version_negotiation_packet_; |
| 394 | std::vector<std::unique_ptr<QuicStreamFrame>> stream_frames_; |
| 395 | std::vector<std::unique_ptr<QuicCryptoFrame>> crypto_frames_; |
| 396 | std::vector<std::unique_ptr<QuicAckFrame>> ack_frames_; |
| 397 | std::vector<std::unique_ptr<QuicStopWaitingFrame>> stop_waiting_frames_; |
| 398 | std::vector<std::unique_ptr<QuicPaddingFrame>> padding_frames_; |
| 399 | std::vector<std::unique_ptr<QuicPingFrame>> ping_frames_; |
| 400 | std::vector<std::unique_ptr<QuicMessageFrame>> message_frames_; |
| 401 | std::vector<std::unique_ptr<QuicEncryptedPacket>> coalesced_packets_; |
| 402 | QuicRstStreamFrame rst_stream_frame_; |
| 403 | QuicConnectionCloseFrame connection_close_frame_; |
| 404 | QuicApplicationCloseFrame application_close_frame_; |
| 405 | QuicStopSendingFrame stop_sending_frame_; |
| 406 | QuicGoAwayFrame goaway_frame_; |
| 407 | QuicPathChallengeFrame path_challenge_frame_; |
| 408 | QuicPathResponseFrame path_response_frame_; |
| 409 | QuicWindowUpdateFrame window_update_frame_; |
| 410 | QuicBlockedFrame blocked_frame_; |
| 411 | QuicStreamIdBlockedFrame stream_id_blocked_frame_; |
| 412 | QuicMaxStreamIdFrame max_stream_id_frame_; |
| 413 | QuicNewConnectionIdFrame new_connection_id_; |
| 414 | QuicRetireConnectionIdFrame retire_connection_id_; |
| 415 | QuicNewTokenFrame new_token_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 416 | std::vector<std::unique_ptr<std::string>> stream_data_; |
| 417 | std::vector<std::unique_ptr<std::string>> crypto_data_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 418 | }; |
| 419 | |
| 420 | // Simple struct for defining a packet's content, and associated |
| 421 | // parse error. |
| 422 | struct PacketFragment { |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 423 | std::string error_if_missing; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 424 | std::vector<unsigned char> fragment; |
| 425 | }; |
| 426 | |
| 427 | using PacketFragments = std::vector<struct PacketFragment>; |
| 428 | |
| 429 | ParsedQuicVersionVector AllSupportedVersionsIncludingTls() { |
| 430 | QuicFlagSaver flags; |
| 431 | SetQuicFlag(&FLAGS_quic_supports_tls_handshake, true); |
| 432 | return AllSupportedVersions(); |
| 433 | } |
| 434 | |
| 435 | class QuicFramerTest : public QuicTestWithParam<ParsedQuicVersion> { |
| 436 | public: |
| 437 | QuicFramerTest() |
| 438 | : encrypter_(new test::TestEncrypter()), |
| 439 | decrypter_(new test::TestDecrypter()), |
| 440 | version_(GetParam()), |
| 441 | start_(QuicTime::Zero() + QuicTime::Delta::FromMicroseconds(0x10)), |
| 442 | framer_(AllSupportedVersionsIncludingTls(), |
| 443 | start_, |
| 444 | Perspective::IS_SERVER, |
| 445 | kQuicDefaultConnectionIdLength) { |
| 446 | SetQuicFlag(&FLAGS_quic_supports_tls_handshake, true); |
| 447 | framer_.set_version(version_); |
| 448 | framer_.SetDecrypter(ENCRYPTION_NONE, |
| 449 | std::unique_ptr<QuicDecrypter>(decrypter_)); |
| 450 | framer_.SetEncrypter(ENCRYPTION_NONE, |
| 451 | std::unique_ptr<QuicEncrypter>(encrypter_)); |
| 452 | |
| 453 | framer_.set_visitor(&visitor_); |
| 454 | framer_.InferPacketHeaderTypeFromVersion(); |
| 455 | } |
| 456 | |
| 457 | // Helper function to get unsigned char representation of the handshake |
| 458 | // protocol byte of the current QUIC version number. |
| 459 | unsigned char GetQuicVersionProtocolByte() { |
| 460 | return (CreateQuicVersionLabel(version_) >> 24) & 0xff; |
| 461 | } |
| 462 | |
| 463 | // Helper function to get unsigned char representation of digit in the |
| 464 | // units place of the current QUIC version number. |
| 465 | unsigned char GetQuicVersionDigitOnes() { |
| 466 | return CreateQuicVersionLabel(version_) & 0xff; |
| 467 | } |
| 468 | |
| 469 | // Helper function to get unsigned char representation of digit in the |
| 470 | // tens place of the current QUIC version number. |
| 471 | unsigned char GetQuicVersionDigitTens() { |
| 472 | return (CreateQuicVersionLabel(version_) >> 8) & 0xff; |
| 473 | } |
| 474 | |
| 475 | bool CheckEncryption(QuicPacketNumber packet_number, QuicPacket* packet) { |
| 476 | if (packet_number != encrypter_->packet_number_) { |
| 477 | QUIC_LOG(ERROR) << "Encrypted incorrect packet number. expected " |
| 478 | << packet_number |
| 479 | << " actual: " << encrypter_->packet_number_; |
| 480 | return false; |
| 481 | } |
| 482 | if (packet->AssociatedData(framer_.transport_version()) != |
| 483 | encrypter_->associated_data_) { |
| 484 | QUIC_LOG(ERROR) << "Encrypted incorrect associated data. expected " |
| 485 | << packet->AssociatedData(framer_.transport_version()) |
| 486 | << " actual: " << encrypter_->associated_data_; |
| 487 | return false; |
| 488 | } |
| 489 | if (packet->Plaintext(framer_.transport_version()) != |
| 490 | encrypter_->plaintext_) { |
| 491 | QUIC_LOG(ERROR) << "Encrypted incorrect plaintext data. expected " |
| 492 | << packet->Plaintext(framer_.transport_version()) |
| 493 | << " actual: " << encrypter_->plaintext_; |
| 494 | return false; |
| 495 | } |
| 496 | return true; |
| 497 | } |
| 498 | |
| 499 | bool CheckDecryption(const QuicEncryptedPacket& encrypted, |
| 500 | bool includes_version, |
| 501 | bool includes_diversification_nonce, |
| 502 | QuicConnectionIdLength destination_connection_id_length, |
| 503 | QuicConnectionIdLength source_connection_id_length) { |
| 504 | return CheckDecryption( |
| 505 | encrypted, includes_version, includes_diversification_nonce, |
| 506 | destination_connection_id_length, source_connection_id_length, |
| 507 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
| 508 | } |
| 509 | |
| 510 | bool CheckDecryption( |
| 511 | const QuicEncryptedPacket& encrypted, |
| 512 | bool includes_version, |
| 513 | bool includes_diversification_nonce, |
| 514 | QuicConnectionIdLength destination_connection_id_length, |
| 515 | QuicConnectionIdLength source_connection_id_length, |
| 516 | QuicVariableLengthIntegerLength retry_token_length_length, |
| 517 | size_t retry_token_length, |
| 518 | QuicVariableLengthIntegerLength length_length) { |
| 519 | if (visitor_.header_->packet_number != decrypter_->packet_number_) { |
| 520 | QUIC_LOG(ERROR) << "Decrypted incorrect packet number. expected " |
| 521 | << visitor_.header_->packet_number |
| 522 | << " actual: " << decrypter_->packet_number_; |
| 523 | return false; |
| 524 | } |
| 525 | QuicStringPiece associated_data = |
| 526 | QuicFramer::GetAssociatedDataFromEncryptedPacket( |
| 527 | framer_.transport_version(), encrypted, |
| 528 | destination_connection_id_length, source_connection_id_length, |
| 529 | includes_version, includes_diversification_nonce, |
| 530 | PACKET_4BYTE_PACKET_NUMBER, retry_token_length_length, |
| 531 | retry_token_length, length_length); |
| 532 | if (associated_data != decrypter_->associated_data_) { |
| 533 | QUIC_LOG(ERROR) << "Decrypted incorrect associated data. expected " |
| 534 | << QuicTextUtils::HexEncode(associated_data) |
| 535 | << " actual: " |
| 536 | << QuicTextUtils::HexEncode(decrypter_->associated_data_); |
| 537 | return false; |
| 538 | } |
| 539 | QuicStringPiece ciphertext( |
| 540 | encrypted.AsStringPiece().substr(GetStartOfEncryptedData( |
| 541 | framer_.transport_version(), destination_connection_id_length, |
| 542 | source_connection_id_length, includes_version, |
| 543 | includes_diversification_nonce, PACKET_4BYTE_PACKET_NUMBER, |
| 544 | retry_token_length_length, retry_token_length, length_length))); |
| 545 | if (ciphertext != decrypter_->ciphertext_) { |
| 546 | QUIC_LOG(ERROR) << "Decrypted incorrect ciphertext data. expected " |
| 547 | << QuicTextUtils::HexEncode(ciphertext) << " actual: " |
| 548 | << QuicTextUtils::HexEncode(decrypter_->ciphertext_) |
| 549 | << " associated data: " |
| 550 | << QuicTextUtils::HexEncode(associated_data); |
| 551 | return false; |
| 552 | } |
| 553 | return true; |
| 554 | } |
| 555 | |
| 556 | char* AsChars(unsigned char* data) { return reinterpret_cast<char*>(data); } |
| 557 | |
| 558 | // Creates a new QuicEncryptedPacket by concatenating the various |
| 559 | // packet fragments in |fragments|. |
| 560 | std::unique_ptr<QuicEncryptedPacket> AssemblePacketFromFragments( |
| 561 | const PacketFragments& fragments) { |
| 562 | char* buffer = new char[kMaxPacketSize + 1]; |
| 563 | size_t len = 0; |
| 564 | for (const auto& fragment : fragments) { |
| 565 | memcpy(buffer + len, fragment.fragment.data(), fragment.fragment.size()); |
| 566 | len += fragment.fragment.size(); |
| 567 | } |
| 568 | return QuicMakeUnique<QuicEncryptedPacket>(buffer, len, true); |
| 569 | } |
| 570 | |
| 571 | void CheckFramingBoundaries(const PacketFragments& fragments, |
| 572 | QuicErrorCode error_code) { |
| 573 | std::unique_ptr<QuicEncryptedPacket> packet( |
| 574 | AssemblePacketFromFragments(fragments)); |
| 575 | // Check all the various prefixes of |packet| for the expected |
| 576 | // parse error and error code. |
| 577 | for (size_t i = 0; i < packet->length(); ++i) { |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 578 | std::string expected_error; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 579 | size_t len = 0; |
| 580 | for (const auto& fragment : fragments) { |
| 581 | len += fragment.fragment.size(); |
| 582 | if (i < len) { |
| 583 | expected_error = fragment.error_if_missing; |
| 584 | break; |
| 585 | } |
| 586 | } |
| 587 | |
| 588 | if (expected_error.empty()) |
| 589 | continue; |
| 590 | |
| 591 | CheckProcessingFails(*packet, i, expected_error, error_code); |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | void CheckProcessingFails(const QuicEncryptedPacket& packet, |
| 596 | size_t len, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 597 | std::string expected_error, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 598 | QuicErrorCode error_code) { |
| 599 | QuicEncryptedPacket encrypted(packet.data(), len, false); |
| 600 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)) << "len: " << len; |
| 601 | EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len; |
| 602 | EXPECT_EQ(error_code, framer_.error()) << "len: " << len; |
| 603 | } |
| 604 | |
| 605 | void CheckProcessingFails(unsigned char* packet, |
| 606 | size_t len, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 607 | std::string expected_error, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 608 | QuicErrorCode error_code) { |
| 609 | QuicEncryptedPacket encrypted(AsChars(packet), len, false); |
| 610 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)) << "len: " << len; |
| 611 | EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len; |
| 612 | EXPECT_EQ(error_code, framer_.error()) << "len: " << len; |
| 613 | } |
| 614 | |
| 615 | // Checks if the supplied string matches data in the supplied StreamFrame. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 616 | void CheckStreamFrameData(std::string str, QuicStreamFrame* frame) { |
| 617 | EXPECT_EQ(str, std::string(frame->data_buffer, frame->data_length)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | void CheckCalculatePacketNumber(uint64_t expected_packet_number, |
| 621 | QuicPacketNumber last_packet_number) { |
| 622 | uint64_t wire_packet_number = expected_packet_number & kMask; |
| 623 | EXPECT_EQ(expected_packet_number, |
| 624 | QuicFramerPeer::CalculatePacketNumberFromWire( |
| 625 | &framer_, PACKET_4BYTE_PACKET_NUMBER, last_packet_number, |
| 626 | wire_packet_number)) |
| 627 | << "last_packet_number: " << last_packet_number |
| 628 | << " wire_packet_number: " << wire_packet_number; |
| 629 | } |
| 630 | |
| 631 | std::unique_ptr<QuicPacket> BuildDataPacket(const QuicPacketHeader& header, |
| 632 | const QuicFrames& frames) { |
| 633 | return BuildUnsizedDataPacket(&framer_, header, frames); |
| 634 | } |
| 635 | |
| 636 | std::unique_ptr<QuicPacket> BuildDataPacket(const QuicPacketHeader& header, |
| 637 | const QuicFrames& frames, |
| 638 | size_t packet_size) { |
| 639 | return BuildUnsizedDataPacket(&framer_, header, frames, packet_size); |
| 640 | } |
| 641 | |
| 642 | // N starts at 1. |
| 643 | QuicStreamId GetNthStreamid(QuicTransportVersion transport_version, |
| 644 | Perspective perspective, |
| 645 | bool bidirectional, |
| 646 | int n) { |
| 647 | if (bidirectional) { |
| 648 | return QuicUtils::GetFirstBidirectionalStreamId(transport_version, |
| 649 | perspective) + |
| 650 | ((n - 1) * QuicUtils::StreamIdDelta(transport_version)); |
| 651 | } |
| 652 | // Unidirectional |
| 653 | return QuicUtils::GetFirstUnidirectionalStreamId(transport_version, |
| 654 | perspective) + |
| 655 | ((n - 1) * QuicUtils::StreamIdDelta(transport_version)); |
| 656 | } |
| 657 | |
| 658 | test::TestEncrypter* encrypter_; |
| 659 | test::TestDecrypter* decrypter_; |
| 660 | ParsedQuicVersion version_; |
| 661 | QuicTime start_; |
| 662 | QuicFramer framer_; |
| 663 | test::TestQuicVisitor visitor_; |
| 664 | SimpleBufferAllocator allocator_; |
| 665 | }; |
| 666 | |
| 667 | // Multiple test cases of QuicFramerTest use byte arrays to define packets for |
| 668 | // testing, and these byte arrays contain the QUIC version. This macro explodes |
| 669 | // the 32-bit version into four bytes in network order. Since it uses methods of |
| 670 | // QuicFramerTest, it is only valid to use this in a QuicFramerTest. |
| 671 | #define QUIC_VERSION_BYTES \ |
| 672 | GetQuicVersionProtocolByte(), '0', GetQuicVersionDigitTens(), \ |
| 673 | GetQuicVersionDigitOnes() |
| 674 | |
| 675 | // Run all framer tests with all supported versions of QUIC. |
| 676 | INSTANTIATE_TEST_SUITE_P( |
| 677 | QuicFramerTests, |
| 678 | QuicFramerTest, |
| 679 | ::testing::ValuesIn(AllSupportedVersionsIncludingTls())); |
| 680 | |
| 681 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochStart) { |
| 682 | // A few quick manual sanity checks. |
| 683 | CheckCalculatePacketNumber(UINT64_C(1), QuicPacketNumber()); |
| 684 | CheckCalculatePacketNumber(kEpoch + 1, QuicPacketNumber(kMask)); |
| 685 | CheckCalculatePacketNumber(kEpoch, QuicPacketNumber(kMask)); |
| 686 | for (uint64_t j = 0; j < 10; j++) { |
| 687 | CheckCalculatePacketNumber(j, QuicPacketNumber()); |
| 688 | CheckCalculatePacketNumber(kEpoch - 1 - j, QuicPacketNumber()); |
| 689 | } |
| 690 | |
| 691 | // Cases where the last number was close to the start of the range. |
| 692 | for (QuicPacketNumber last = QuicPacketNumber(1); last < QuicPacketNumber(10); |
| 693 | last++) { |
| 694 | // Small numbers should not wrap (even if they're out of order). |
| 695 | for (uint64_t j = 0; j < 10; j++) { |
| 696 | CheckCalculatePacketNumber(j, last); |
| 697 | } |
| 698 | |
| 699 | // Large numbers should not wrap either (because we're near 0 already). |
| 700 | for (uint64_t j = 0; j < 10; j++) { |
| 701 | CheckCalculatePacketNumber(kEpoch - 1 - j, last); |
| 702 | } |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochEnd) { |
| 707 | // Cases where the last number was close to the end of the range |
| 708 | for (uint64_t i = 0; i < 10; i++) { |
| 709 | QuicPacketNumber last = QuicPacketNumber(kEpoch - i); |
| 710 | |
| 711 | // Small numbers should wrap. |
| 712 | for (uint64_t j = 0; j < 10; j++) { |
| 713 | CheckCalculatePacketNumber(kEpoch + j, last); |
| 714 | } |
| 715 | |
| 716 | // Large numbers should not (even if they're out of order). |
| 717 | for (uint64_t j = 0; j < 10; j++) { |
| 718 | CheckCalculatePacketNumber(kEpoch - 1 - j, last); |
| 719 | } |
| 720 | } |
| 721 | } |
| 722 | |
| 723 | // Next check where we're in a non-zero epoch to verify we handle |
| 724 | // reverse wrapping, too. |
| 725 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearPrevEpoch) { |
| 726 | const uint64_t prev_epoch = 1 * kEpoch; |
| 727 | const uint64_t cur_epoch = 2 * kEpoch; |
| 728 | // Cases where the last number was close to the start of the range |
| 729 | for (uint64_t i = 0; i < 10; i++) { |
| 730 | QuicPacketNumber last = QuicPacketNumber(cur_epoch + i); |
| 731 | // Small number should not wrap (even if they're out of order). |
| 732 | for (uint64_t j = 0; j < 10; j++) { |
| 733 | CheckCalculatePacketNumber(cur_epoch + j, last); |
| 734 | } |
| 735 | |
| 736 | // But large numbers should reverse wrap. |
| 737 | for (uint64_t j = 0; j < 10; j++) { |
| 738 | uint64_t num = kEpoch - 1 - j; |
| 739 | CheckCalculatePacketNumber(prev_epoch + num, last); |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearNextEpoch) { |
| 745 | const uint64_t cur_epoch = 2 * kEpoch; |
| 746 | const uint64_t next_epoch = 3 * kEpoch; |
| 747 | // Cases where the last number was close to the end of the range |
| 748 | for (uint64_t i = 0; i < 10; i++) { |
| 749 | QuicPacketNumber last = QuicPacketNumber(next_epoch - 1 - i); |
| 750 | |
| 751 | // Small numbers should wrap. |
| 752 | for (uint64_t j = 0; j < 10; j++) { |
| 753 | CheckCalculatePacketNumber(next_epoch + j, last); |
| 754 | } |
| 755 | |
| 756 | // but large numbers should not (even if they're out of order). |
| 757 | for (uint64_t j = 0; j < 10; j++) { |
| 758 | uint64_t num = kEpoch - 1 - j; |
| 759 | CheckCalculatePacketNumber(cur_epoch + num, last); |
| 760 | } |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearNextMax) { |
| 765 | const uint64_t max_number = std::numeric_limits<uint64_t>::max(); |
| 766 | const uint64_t max_epoch = max_number & ~kMask; |
| 767 | |
| 768 | // Cases where the last number was close to the end of the range |
| 769 | for (uint64_t i = 0; i < 10; i++) { |
| 770 | // Subtract 1, because the expected next packet number is 1 more than the |
| 771 | // last packet number. |
| 772 | QuicPacketNumber last = QuicPacketNumber(max_number - i - 1); |
| 773 | |
| 774 | // Small numbers should not wrap, because they have nowhere to go. |
| 775 | for (uint64_t j = 0; j < 10; j++) { |
| 776 | CheckCalculatePacketNumber(max_epoch + j, last); |
| 777 | } |
| 778 | |
| 779 | // Large numbers should not wrap either. |
| 780 | for (uint64_t j = 0; j < 10; j++) { |
| 781 | uint64_t num = kEpoch - 1 - j; |
| 782 | CheckCalculatePacketNumber(max_epoch + num, last); |
| 783 | } |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | TEST_P(QuicFramerTest, EmptyPacket) { |
| 788 | char packet[] = {0x00}; |
| 789 | QuicEncryptedPacket encrypted(packet, 0, false); |
| 790 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 791 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
| 792 | } |
| 793 | |
| 794 | TEST_P(QuicFramerTest, LargePacket) { |
| 795 | // clang-format off |
| 796 | unsigned char packet[kMaxPacketSize + 1] = { |
| 797 | // public flags (8 byte connection_id) |
| 798 | 0x28, |
| 799 | // connection_id |
| 800 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 801 | // packet number |
| 802 | 0x78, 0x56, 0x34, 0x12, |
| 803 | // private flags |
| 804 | 0x00, |
| 805 | }; |
| 806 | unsigned char packet44[kMaxPacketSize + 1] = { |
| 807 | // type (short header 4 byte packet number) |
| 808 | 0x32, |
| 809 | // connection_id |
| 810 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 811 | // packet number |
| 812 | 0x78, 0x56, 0x34, 0x12, |
| 813 | }; |
| 814 | unsigned char packet46[kMaxPacketSize + 1] = { |
| 815 | // type (short header 4 byte packet number) |
| 816 | 0x43, |
| 817 | // connection_id |
| 818 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 819 | // packet number |
| 820 | 0x78, 0x56, 0x34, 0x12, |
| 821 | }; |
| 822 | // clang-format on |
| 823 | unsigned char* p = packet; |
| 824 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 825 | if (framer_.transport_version() > QUIC_VERSION_44) { |
| 826 | p = packet46; |
| 827 | p_size = QUIC_ARRAYSIZE(packet46); |
| 828 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 829 | p = packet44; |
| 830 | p_size = QUIC_ARRAYSIZE(packet44); |
| 831 | } |
| 832 | |
| 833 | const size_t header_size = GetPacketHeaderSize( |
| 834 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 835 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 836 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 837 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
| 838 | |
| 839 | memset(p + header_size, 0, kMaxPacketSize - header_size); |
| 840 | |
| 841 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 842 | EXPECT_QUIC_BUG(framer_.ProcessPacket(encrypted), "Packet too large:1"); |
| 843 | |
| 844 | ASSERT_TRUE(visitor_.header_.get()); |
| 845 | // Make sure we've parsed the packet header, so we can send an error. |
| 846 | EXPECT_EQ(FramerTestConnectionId(), |
| 847 | visitor_.header_->destination_connection_id); |
| 848 | // Make sure the correct error is propagated. |
| 849 | EXPECT_EQ(QUIC_PACKET_TOO_LARGE, framer_.error()); |
| 850 | } |
| 851 | |
| 852 | TEST_P(QuicFramerTest, PacketHeader) { |
| 853 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 854 | return; |
| 855 | } |
| 856 | |
| 857 | // clang-format off |
| 858 | PacketFragments packet = { |
| 859 | // public flags (8 byte connection_id) |
| 860 | {"Unable to read public flags.", |
| 861 | {0x28}}, |
| 862 | // connection_id |
| 863 | {"Unable to read ConnectionId.", |
| 864 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 865 | // packet number |
| 866 | {"Unable to read packet number.", |
| 867 | {0x12, 0x34, 0x56, 0x78}}, |
| 868 | }; |
| 869 | // clang-format on |
| 870 | |
| 871 | PacketFragments& fragments = packet; |
| 872 | |
| 873 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 874 | AssemblePacketFromFragments(fragments)); |
| 875 | |
| 876 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 877 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 878 | ASSERT_TRUE(visitor_.header_.get()); |
| 879 | EXPECT_EQ(FramerTestConnectionId(), |
| 880 | visitor_.header_->destination_connection_id); |
| 881 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 882 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 883 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 884 | |
| 885 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 886 | } |
| 887 | |
| 888 | TEST_P(QuicFramerTest, LongPacketHeader) { |
| 889 | // clang-format off |
| 890 | PacketFragments packet44 = { |
| 891 | // type (long header with packet type INITIAL) |
| 892 | {"Unable to read type.", |
| 893 | {0xFF}}, |
| 894 | // version tag |
| 895 | {"Unable to read protocol version.", |
| 896 | {QUIC_VERSION_BYTES}}, |
| 897 | // connection_id length |
| 898 | {"Unable to read ConnectionId length.", |
| 899 | {0x50}}, |
| 900 | // connection_id |
| 901 | {"Unable to read Destination ConnectionId.", |
| 902 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 903 | // packet number |
| 904 | {"Unable to read packet number.", |
| 905 | {0x12, 0x34, 0x56, 0x78}}, |
| 906 | }; |
| 907 | PacketFragments packet46 = { |
| 908 | // type (long header with packet type INITIAL) |
| 909 | {"Unable to read type.", |
| 910 | {0xC3}}, |
| 911 | // version tag |
| 912 | {"Unable to read protocol version.", |
| 913 | {QUIC_VERSION_BYTES}}, |
| 914 | // connection_id length |
| 915 | {"Unable to read ConnectionId length.", |
| 916 | {0x50}}, |
| 917 | // connection_id |
| 918 | {"Unable to read Destination ConnectionId.", |
| 919 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 920 | // packet number |
| 921 | {"Unable to read packet number.", |
| 922 | {0x12, 0x34, 0x56, 0x78}}, |
| 923 | }; |
| 924 | // clang-format on |
| 925 | |
| 926 | if (framer_.transport_version() <= QUIC_VERSION_43 || |
| 927 | QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 928 | return; |
| 929 | } |
| 930 | |
| 931 | PacketFragments& fragments = |
| 932 | framer_.transport_version() > QUIC_VERSION_44 ? packet46 : packet44; |
| 933 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 934 | AssemblePacketFromFragments(fragments)); |
| 935 | |
| 936 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 937 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 938 | ASSERT_TRUE(visitor_.header_.get()); |
| 939 | EXPECT_EQ(FramerTestConnectionId(), |
| 940 | visitor_.header_->destination_connection_id); |
| 941 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 942 | EXPECT_TRUE(visitor_.header_->version_flag); |
| 943 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 944 | |
| 945 | CheckFramingBoundaries( |
| 946 | framer_.transport_version() > QUIC_VERSION_44 ? packet46 : packet44, |
| 947 | QUIC_INVALID_PACKET_HEADER); |
| 948 | } |
| 949 | |
| 950 | TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) { |
| 951 | QuicFramerPeer::SetLastSerializedConnectionId(&framer_, |
| 952 | FramerTestConnectionId()); |
| 953 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 954 | |
| 955 | // clang-format off |
| 956 | PacketFragments packet = { |
| 957 | // public flags (0 byte connection_id) |
| 958 | {"Unable to read public flags.", |
| 959 | {0x20}}, |
| 960 | // connection_id |
| 961 | // packet number |
| 962 | {"Unable to read packet number.", |
| 963 | {0x12, 0x34, 0x56, 0x78}}, |
| 964 | }; |
| 965 | |
| 966 | PacketFragments packet44 = { |
| 967 | // type (short header, 4 byte packet number) |
| 968 | {"Unable to read type.", |
| 969 | {0x32}}, |
| 970 | // connection_id |
| 971 | // packet number |
| 972 | {"Unable to read packet number.", |
| 973 | {0x12, 0x34, 0x56, 0x78}}, |
| 974 | }; |
| 975 | |
| 976 | PacketFragments packet46 = { |
| 977 | // type (short header, 4 byte packet number) |
| 978 | {"Unable to read type.", |
| 979 | {0x43}}, |
| 980 | // connection_id |
| 981 | // packet number |
| 982 | {"Unable to read packet number.", |
| 983 | {0x12, 0x34, 0x56, 0x78}}, |
| 984 | }; |
| 985 | // clang-format on |
| 986 | |
| 987 | PacketFragments& fragments = |
| 988 | framer_.transport_version() > QUIC_VERSION_44 |
| 989 | ? packet46 |
| 990 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 991 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 992 | AssemblePacketFromFragments(fragments)); |
| 993 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 994 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 995 | ASSERT_TRUE(visitor_.header_.get()); |
| 996 | EXPECT_EQ(FramerTestConnectionId(), |
| 997 | visitor_.header_->destination_connection_id); |
| 998 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 999 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1000 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1001 | |
| 1002 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1003 | } |
| 1004 | |
| 1005 | TEST_P(QuicFramerTest, PacketHeaderWithVersionFlag) { |
| 1006 | // clang-format off |
| 1007 | PacketFragments packet = { |
| 1008 | // public flags (0 byte connection_id) |
| 1009 | {"Unable to read public flags.", |
| 1010 | {0x29}}, |
| 1011 | // connection_id |
| 1012 | {"Unable to read ConnectionId.", |
| 1013 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1014 | // version tag |
| 1015 | {"Unable to read protocol version.", |
| 1016 | {QUIC_VERSION_BYTES}}, |
| 1017 | // packet number |
| 1018 | {"Unable to read packet number.", |
| 1019 | {0x12, 0x34, 0x56, 0x78}}, |
| 1020 | }; |
| 1021 | |
| 1022 | PacketFragments packet44 = { |
| 1023 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 1024 | {"Unable to read type.", |
| 1025 | {0xFC}}, |
| 1026 | // version tag |
| 1027 | {"Unable to read protocol version.", |
| 1028 | {QUIC_VERSION_BYTES}}, |
| 1029 | // connection_id length |
| 1030 | {"Unable to read ConnectionId length.", |
| 1031 | {0x50}}, |
| 1032 | // connection_id |
| 1033 | {"Unable to read Destination ConnectionId.", |
| 1034 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1035 | // packet number |
| 1036 | {"Unable to read packet number.", |
| 1037 | {0x12, 0x34, 0x56, 0x78}}, |
| 1038 | }; |
| 1039 | |
| 1040 | PacketFragments packet46 = { |
| 1041 | // type (long header with packet type ZERO_RTT_PROTECTED and 4 bytes |
| 1042 | // packet number) |
| 1043 | {"Unable to read type.", |
| 1044 | {0xD3}}, |
| 1045 | // version tag |
| 1046 | {"Unable to read protocol version.", |
| 1047 | {QUIC_VERSION_BYTES}}, |
| 1048 | // connection_id length |
| 1049 | {"Unable to read ConnectionId length.", |
| 1050 | {0x50}}, |
| 1051 | // connection_id |
| 1052 | {"Unable to read Destination ConnectionId.", |
| 1053 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1054 | // packet number |
| 1055 | {"Unable to read packet number.", |
| 1056 | {0x12, 0x34, 0x56, 0x78}}, |
| 1057 | }; |
| 1058 | |
| 1059 | PacketFragments packet99 = { |
| 1060 | // type (long header with packet type ZERO_RTT_PROTECTED and 4 bytes |
| 1061 | // packet number) |
| 1062 | {"Unable to read type.", |
| 1063 | {0xD3}}, |
| 1064 | // version tag |
| 1065 | {"Unable to read protocol version.", |
| 1066 | {QUIC_VERSION_BYTES}}, |
| 1067 | // connection_id length |
| 1068 | {"Unable to read ConnectionId length.", |
| 1069 | {0x50}}, |
| 1070 | // connection_id |
| 1071 | {"Unable to read Destination ConnectionId.", |
| 1072 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1073 | // long header packet length |
| 1074 | {"Unable to read long header payload length.", |
| 1075 | {0x04}}, |
| 1076 | // packet number |
| 1077 | {"Long header payload length longer than packet.", |
| 1078 | {0x12, 0x34, 0x56, 0x78}}, |
| 1079 | }; |
| 1080 | // clang-format on |
| 1081 | |
| 1082 | PacketFragments& fragments = |
| 1083 | framer_.transport_version() == QUIC_VERSION_99 |
| 1084 | ? packet99 |
| 1085 | : framer_.transport_version() > QUIC_VERSION_44 |
| 1086 | ? packet46 |
| 1087 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 1088 | : packet); |
| 1089 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1090 | AssemblePacketFromFragments(fragments)); |
| 1091 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1092 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1093 | ASSERT_TRUE(visitor_.header_.get()); |
| 1094 | EXPECT_EQ(FramerTestConnectionId(), |
| 1095 | visitor_.header_->destination_connection_id); |
| 1096 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1097 | EXPECT_TRUE(visitor_.header_->version_flag); |
| 1098 | EXPECT_EQ(GetParam(), visitor_.header_->version); |
| 1099 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1100 | |
| 1101 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1102 | } |
| 1103 | |
| 1104 | TEST_P(QuicFramerTest, PacketHeaderWith4BytePacketNumber) { |
| 1105 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1106 | |
| 1107 | // clang-format off |
| 1108 | PacketFragments packet = { |
| 1109 | // public flags (8 byte connection_id and 4 byte packet number) |
| 1110 | {"Unable to read public flags.", |
| 1111 | {0x28}}, |
| 1112 | // connection_id |
| 1113 | {"Unable to read ConnectionId.", |
| 1114 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1115 | // packet number |
| 1116 | {"Unable to read packet number.", |
| 1117 | {0x12, 0x34, 0x56, 0x78}}, |
| 1118 | }; |
| 1119 | |
| 1120 | PacketFragments packet44 = { |
| 1121 | // type (short header, 4 byte packet number) |
| 1122 | {"Unable to read type.", |
| 1123 | {0x32}}, |
| 1124 | // connection_id |
| 1125 | {"Unable to read Destination ConnectionId.", |
| 1126 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1127 | // packet number |
| 1128 | {"Unable to read packet number.", |
| 1129 | {0x12, 0x34, 0x56, 0x78}}, |
| 1130 | }; |
| 1131 | |
| 1132 | PacketFragments packet46 = { |
| 1133 | // type (short header, 4 byte packet number) |
| 1134 | {"Unable to read type.", |
| 1135 | {0x43}}, |
| 1136 | // connection_id |
| 1137 | {"Unable to read Destination ConnectionId.", |
| 1138 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1139 | // packet number |
| 1140 | {"Unable to read packet number.", |
| 1141 | {0x12, 0x34, 0x56, 0x78}}, |
| 1142 | }; |
| 1143 | // clang-format on |
| 1144 | |
| 1145 | PacketFragments& fragments = |
| 1146 | framer_.transport_version() > QUIC_VERSION_44 |
| 1147 | ? packet46 |
| 1148 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 1149 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1150 | AssemblePacketFromFragments(fragments)); |
| 1151 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1152 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1153 | ASSERT_TRUE(visitor_.header_.get()); |
| 1154 | EXPECT_EQ(FramerTestConnectionId(), |
| 1155 | visitor_.header_->destination_connection_id); |
| 1156 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1157 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1158 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1159 | |
| 1160 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1161 | } |
| 1162 | |
| 1163 | TEST_P(QuicFramerTest, PacketHeaderWith2BytePacketNumber) { |
| 1164 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1165 | |
| 1166 | // clang-format off |
| 1167 | PacketFragments packet = { |
| 1168 | // public flags (8 byte connection_id and 2 byte packet number) |
| 1169 | {"Unable to read public flags.", |
| 1170 | {0x18}}, |
| 1171 | // connection_id |
| 1172 | {"Unable to read ConnectionId.", |
| 1173 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1174 | // packet number |
| 1175 | {"Unable to read packet number.", |
| 1176 | {0x56, 0x78}}, |
| 1177 | }; |
| 1178 | |
| 1179 | PacketFragments packet44 = { |
| 1180 | // type (short header, 2 byte packet number) |
| 1181 | {"Unable to read type.", |
| 1182 | {0x31}}, |
| 1183 | // connection_id |
| 1184 | {"Unable to read Destination ConnectionId.", |
| 1185 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1186 | // packet number |
| 1187 | {"Unable to read packet number.", |
| 1188 | {0x56, 0x78}}, |
| 1189 | }; |
| 1190 | |
| 1191 | PacketFragments packet46 = { |
| 1192 | // type (short header, 2 byte packet number) |
| 1193 | {"Unable to read type.", |
| 1194 | {0x41}}, |
| 1195 | // connection_id |
| 1196 | {"Unable to read Destination ConnectionId.", |
| 1197 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1198 | // packet number |
| 1199 | {"Unable to read packet number.", |
| 1200 | {0x56, 0x78}}, |
| 1201 | }; |
| 1202 | // clang-format on |
| 1203 | |
| 1204 | PacketFragments& fragments = |
| 1205 | framer_.transport_version() > QUIC_VERSION_44 |
| 1206 | ? packet46 |
| 1207 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 1208 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1209 | AssemblePacketFromFragments(fragments)); |
| 1210 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1211 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1212 | ASSERT_TRUE(visitor_.header_.get()); |
| 1213 | EXPECT_EQ(FramerTestConnectionId(), |
| 1214 | visitor_.header_->destination_connection_id); |
| 1215 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1216 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1217 | EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1218 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1219 | |
| 1220 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1221 | } |
| 1222 | |
| 1223 | TEST_P(QuicFramerTest, PacketHeaderWith1BytePacketNumber) { |
| 1224 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 1225 | |
| 1226 | // clang-format off |
| 1227 | PacketFragments packet = { |
| 1228 | // public flags (8 byte connection_id and 1 byte packet number) |
| 1229 | {"Unable to read public flags.", |
| 1230 | {0x08}}, |
| 1231 | // connection_id |
| 1232 | {"Unable to read ConnectionId.", |
| 1233 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1234 | // packet number |
| 1235 | {"Unable to read packet number.", |
| 1236 | {0x78}}, |
| 1237 | }; |
| 1238 | |
| 1239 | PacketFragments packet44 = { |
| 1240 | // type (8 byte connection_id and 1 byte packet number) |
| 1241 | {"Unable to read type.", |
| 1242 | {0x30}}, |
| 1243 | // connection_id |
| 1244 | {"Unable to read Destination ConnectionId.", |
| 1245 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1246 | // packet number |
| 1247 | {"Unable to read packet number.", |
| 1248 | {0x78}}, |
| 1249 | }; |
| 1250 | |
| 1251 | PacketFragments packet46 = { |
| 1252 | // type (8 byte connection_id and 1 byte packet number) |
| 1253 | {"Unable to read type.", |
| 1254 | {0x40}}, |
| 1255 | // connection_id |
| 1256 | {"Unable to read Destination ConnectionId.", |
| 1257 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1258 | // packet number |
| 1259 | {"Unable to read packet number.", |
| 1260 | {0x78}}, |
| 1261 | }; |
| 1262 | |
| 1263 | // clang-format on |
| 1264 | |
| 1265 | PacketFragments& fragments = |
| 1266 | framer_.transport_version() > QUIC_VERSION_44 |
| 1267 | ? packet46 |
| 1268 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 1269 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1270 | AssemblePacketFromFragments(fragments)); |
| 1271 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 1272 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 1273 | ASSERT_TRUE(visitor_.header_.get()); |
| 1274 | EXPECT_EQ(FramerTestConnectionId(), |
| 1275 | visitor_.header_->destination_connection_id); |
| 1276 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 1277 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 1278 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1279 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1280 | |
| 1281 | CheckFramingBoundaries(fragments, QUIC_INVALID_PACKET_HEADER); |
| 1282 | } |
| 1283 | |
| 1284 | TEST_P(QuicFramerTest, PacketNumberDecreasesThenIncreases) { |
| 1285 | // Test the case when a packet is received from the past and future packet |
| 1286 | // numbers are still calculated relative to the largest received packet. |
| 1287 | QuicPacketHeader header; |
| 1288 | header.destination_connection_id = FramerTestConnectionId(); |
| 1289 | header.reset_flag = false; |
| 1290 | header.version_flag = false; |
| 1291 | header.packet_number = kPacketNumber - 2; |
| 1292 | |
| 1293 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 1294 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1295 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 1296 | ASSERT_TRUE(data != nullptr); |
| 1297 | |
| 1298 | QuicEncryptedPacket encrypted(data->data(), data->length(), false); |
| 1299 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1300 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1301 | ASSERT_TRUE(visitor_.header_.get()); |
| 1302 | EXPECT_EQ(FramerTestConnectionId(), |
| 1303 | visitor_.header_->destination_connection_id); |
| 1304 | EXPECT_EQ(PACKET_4BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1305 | EXPECT_EQ(kPacketNumber - 2, visitor_.header_->packet_number); |
| 1306 | |
| 1307 | // Receive a 1 byte packet number. |
| 1308 | header.packet_number = kPacketNumber; |
| 1309 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 1310 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1311 | data = BuildDataPacket(header, frames); |
| 1312 | QuicEncryptedPacket encrypted1(data->data(), data->length(), false); |
| 1313 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1314 | EXPECT_TRUE(framer_.ProcessPacket(encrypted1)); |
| 1315 | ASSERT_TRUE(visitor_.header_.get()); |
| 1316 | EXPECT_EQ(FramerTestConnectionId(), |
| 1317 | visitor_.header_->destination_connection_id); |
| 1318 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1319 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 1320 | |
| 1321 | // Process a 2 byte packet number 256 packets ago. |
| 1322 | header.packet_number = kPacketNumber - 256; |
| 1323 | header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER; |
| 1324 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1325 | data = BuildDataPacket(header, frames); |
| 1326 | QuicEncryptedPacket encrypted2(data->data(), data->length(), false); |
| 1327 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1328 | EXPECT_TRUE(framer_.ProcessPacket(encrypted2)); |
| 1329 | ASSERT_TRUE(visitor_.header_.get()); |
| 1330 | EXPECT_EQ(FramerTestConnectionId(), |
| 1331 | visitor_.header_->destination_connection_id); |
| 1332 | EXPECT_EQ(PACKET_2BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1333 | EXPECT_EQ(kPacketNumber - 256, visitor_.header_->packet_number); |
| 1334 | |
| 1335 | // Process another 1 byte packet number and ensure it works. |
| 1336 | header.packet_number = kPacketNumber - 1; |
| 1337 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 1338 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1339 | data = BuildDataPacket(header, frames); |
| 1340 | QuicEncryptedPacket encrypted3(data->data(), data->length(), false); |
| 1341 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 1342 | EXPECT_TRUE(framer_.ProcessPacket(encrypted3)); |
| 1343 | ASSERT_TRUE(visitor_.header_.get()); |
| 1344 | EXPECT_EQ(FramerTestConnectionId(), |
| 1345 | visitor_.header_->destination_connection_id); |
| 1346 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 1347 | EXPECT_EQ(kPacketNumber - 1, visitor_.header_->packet_number); |
| 1348 | } |
| 1349 | |
| 1350 | TEST_P(QuicFramerTest, PacketWithDiversificationNonce) { |
| 1351 | // clang-format off |
| 1352 | unsigned char packet[] = { |
| 1353 | // public flags: includes nonce flag |
| 1354 | 0x2C, |
| 1355 | // connection_id |
| 1356 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1357 | // nonce |
| 1358 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1359 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1360 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1361 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1362 | // packet number |
| 1363 | 0x12, 0x34, 0x56, 0x78, |
| 1364 | |
| 1365 | // frame type (padding) |
| 1366 | 0x00, |
| 1367 | 0x00, 0x00, 0x00, 0x00 |
| 1368 | }; |
| 1369 | |
| 1370 | unsigned char packet44[] = { |
| 1371 | // type: Long header with packet type ZERO_RTT_PROTECTED |
| 1372 | 0xFC, |
| 1373 | // version tag |
| 1374 | QUIC_VERSION_BYTES, |
| 1375 | // connection_id length |
| 1376 | 0x05, |
| 1377 | // connection_id |
| 1378 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1379 | // packet number |
| 1380 | 0x12, 0x34, 0x56, 0x78, |
| 1381 | // nonce |
| 1382 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1383 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1384 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1385 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1386 | |
| 1387 | // frame type (padding) |
| 1388 | 0x00, |
| 1389 | 0x00, 0x00, 0x00, 0x00 |
| 1390 | }; |
| 1391 | |
| 1392 | unsigned char packet46[] = { |
| 1393 | // type: Long header with packet type ZERO_RTT_PROTECTED and 1 byte packet |
| 1394 | // number. |
| 1395 | 0xD0, |
| 1396 | // version tag |
| 1397 | QUIC_VERSION_BYTES, |
| 1398 | // connection_id length |
| 1399 | 0x05, |
| 1400 | // connection_id |
| 1401 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1402 | // packet number |
| 1403 | 0x78, |
| 1404 | // nonce |
| 1405 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1406 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1407 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1408 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1409 | |
| 1410 | // frame type (padding) |
| 1411 | 0x00, |
| 1412 | 0x00, 0x00, 0x00, 0x00 |
| 1413 | }; |
| 1414 | |
| 1415 | unsigned char packet99[] = { |
| 1416 | // type: Long header with packet type ZERO_RTT_PROTECTED and 1 byte packet |
| 1417 | // number. |
| 1418 | 0xD0, |
| 1419 | // version tag |
| 1420 | QUIC_VERSION_BYTES, |
| 1421 | // connection_id length |
| 1422 | 0x05, |
| 1423 | // connection_id |
| 1424 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1425 | // long header packet length |
| 1426 | 0x26, |
| 1427 | // packet number |
| 1428 | 0x78, |
| 1429 | // nonce |
| 1430 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1431 | 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1432 | 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1433 | 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1434 | |
| 1435 | // frame type (padding) |
| 1436 | 0x00, |
| 1437 | 0x00, 0x00, 0x00, 0x00 |
| 1438 | }; |
| 1439 | // clang-format on |
| 1440 | |
| 1441 | if (framer_.version().handshake_protocol != PROTOCOL_QUIC_CRYPTO) { |
| 1442 | return; |
| 1443 | } |
| 1444 | |
| 1445 | unsigned char* p = packet; |
| 1446 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 1447 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 1448 | p = packet99; |
| 1449 | p_size = QUIC_ARRAYSIZE(packet99); |
| 1450 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 1451 | p = packet46; |
| 1452 | p_size = QUIC_ARRAYSIZE(packet46); |
| 1453 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 1454 | p = packet44; |
| 1455 | p_size = QUIC_ARRAYSIZE(packet44); |
| 1456 | } |
| 1457 | |
| 1458 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 1459 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1460 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1461 | ASSERT_TRUE(visitor_.header_->nonce != nullptr); |
| 1462 | for (char i = 0; i < 32; ++i) { |
| 1463 | EXPECT_EQ(i, (*visitor_.header_->nonce)[static_cast<size_t>(i)]); |
| 1464 | } |
| 1465 | EXPECT_EQ(1u, visitor_.padding_frames_.size()); |
| 1466 | EXPECT_EQ(5, visitor_.padding_frames_[0]->num_padding_bytes); |
| 1467 | } |
| 1468 | |
| 1469 | TEST_P(QuicFramerTest, LargePublicFlagWithMismatchedVersions) { |
| 1470 | // clang-format off |
| 1471 | unsigned char packet[] = { |
| 1472 | // public flags (8 byte connection_id, version flag and an unknown flag) |
| 1473 | 0x29, |
| 1474 | // connection_id |
| 1475 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1476 | // version tag |
| 1477 | 'Q', '0', '0', '0', |
| 1478 | // packet number |
| 1479 | 0x12, 0x34, 0x56, 0x78, |
| 1480 | |
| 1481 | // frame type (padding frame) |
| 1482 | 0x00, |
| 1483 | 0x00, 0x00, 0x00, 0x00 |
| 1484 | }; |
| 1485 | |
| 1486 | unsigned char packet44[] = { |
| 1487 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 1488 | 0xFC, |
| 1489 | // version tag |
| 1490 | 'Q', '0', '0', '0', |
| 1491 | // connection_id length |
| 1492 | 0x50, |
| 1493 | // connection_id |
| 1494 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1495 | // packet number |
| 1496 | 0x12, 0x34, 0x56, 0x78, |
| 1497 | |
| 1498 | // frame type (padding frame) |
| 1499 | 0x00, |
| 1500 | 0x00, 0x00, 0x00, 0x00 |
| 1501 | }; |
| 1502 | // clang-format on |
| 1503 | |
| 1504 | QuicEncryptedPacket encrypted( |
| 1505 | AsChars(framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 1506 | : packet), |
| 1507 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 1508 | : QUIC_ARRAYSIZE(packet), |
| 1509 | false); |
| 1510 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1511 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1512 | ASSERT_TRUE(visitor_.header_.get()); |
| 1513 | EXPECT_EQ(0, visitor_.frame_count_); |
| 1514 | EXPECT_EQ(1, visitor_.version_mismatch_); |
| 1515 | EXPECT_EQ(1u, visitor_.padding_frames_.size()); |
| 1516 | EXPECT_EQ(5, visitor_.padding_frames_[0]->num_padding_bytes); |
| 1517 | } |
| 1518 | |
| 1519 | TEST_P(QuicFramerTest, PaddingFrame) { |
| 1520 | // clang-format off |
| 1521 | unsigned char packet[] = { |
| 1522 | // public flags (8 byte connection_id) |
| 1523 | 0x28, |
| 1524 | // connection_id |
| 1525 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1526 | // packet number |
| 1527 | 0x12, 0x34, 0x56, 0x78, |
| 1528 | |
| 1529 | // paddings |
| 1530 | 0x00, 0x00, |
| 1531 | // frame type (stream frame with fin) |
| 1532 | 0xFF, |
| 1533 | // stream id |
| 1534 | 0x01, 0x02, 0x03, 0x04, |
| 1535 | // offset |
| 1536 | 0x3A, 0x98, 0xFE, 0xDC, |
| 1537 | 0x32, 0x10, 0x76, 0x54, |
| 1538 | // data length |
| 1539 | 0x00, 0x0c, |
| 1540 | // data |
| 1541 | 'h', 'e', 'l', 'l', |
| 1542 | 'o', ' ', 'w', 'o', |
| 1543 | 'r', 'l', 'd', '!', |
| 1544 | // paddings |
| 1545 | 0x00, 0x00, |
| 1546 | }; |
| 1547 | |
| 1548 | unsigned char packet44[] = { |
| 1549 | // type (short header, 4 byte packet number) |
| 1550 | 0x32, |
| 1551 | // connection_id |
| 1552 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1553 | // packet number |
| 1554 | 0x12, 0x34, 0x56, 0x78, |
| 1555 | |
| 1556 | // paddings |
| 1557 | 0x00, 0x00, |
| 1558 | // frame type (stream frame with fin) |
| 1559 | 0xFF, |
| 1560 | // stream id |
| 1561 | 0x01, 0x02, 0x03, 0x04, |
| 1562 | // offset |
| 1563 | 0x3A, 0x98, 0xFE, 0xDC, |
| 1564 | 0x32, 0x10, 0x76, 0x54, |
| 1565 | // data length |
| 1566 | 0x00, 0x0c, |
| 1567 | // data |
| 1568 | 'h', 'e', 'l', 'l', |
| 1569 | 'o', ' ', 'w', 'o', |
| 1570 | 'r', 'l', 'd', '!', |
| 1571 | // paddings |
| 1572 | 0x00, 0x00, |
| 1573 | }; |
| 1574 | |
| 1575 | unsigned char packet46[] = { |
| 1576 | // type (short header, 4 byte packet number) |
| 1577 | 0x43, |
| 1578 | // connection_id |
| 1579 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1580 | // packet number |
| 1581 | 0x12, 0x34, 0x56, 0x78, |
| 1582 | |
| 1583 | // paddings |
| 1584 | 0x00, 0x00, |
| 1585 | // frame type (stream frame with fin) |
| 1586 | 0xFF, |
| 1587 | // stream id |
| 1588 | 0x01, 0x02, 0x03, 0x04, |
| 1589 | // offset |
| 1590 | 0x3A, 0x98, 0xFE, 0xDC, |
| 1591 | 0x32, 0x10, 0x76, 0x54, |
| 1592 | // data length |
| 1593 | 0x00, 0x0c, |
| 1594 | // data |
| 1595 | 'h', 'e', 'l', 'l', |
| 1596 | 'o', ' ', 'w', 'o', |
| 1597 | 'r', 'l', 'd', '!', |
| 1598 | // paddings |
| 1599 | 0x00, 0x00, |
| 1600 | }; |
| 1601 | |
| 1602 | unsigned char packet99[] = { |
| 1603 | // type (short header, 4 byte packet number) |
| 1604 | 0x43, |
| 1605 | // connection_id |
| 1606 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 1607 | // packet number |
| 1608 | 0x12, 0x34, 0x56, 0x78, |
| 1609 | |
| 1610 | // paddings |
| 1611 | 0x00, 0x00, |
| 1612 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 1613 | 0x08 | 0x01 | 0x02 | 0x04, |
| 1614 | |
| 1615 | // stream id |
| 1616 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 1617 | // offset |
| 1618 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 1619 | 0x32, 0x10, 0x76, 0x54, |
| 1620 | // data length |
| 1621 | kVarInt62OneByte + 0x0c, |
| 1622 | // data |
| 1623 | 'h', 'e', 'l', 'l', |
| 1624 | 'o', ' ', 'w', 'o', |
| 1625 | 'r', 'l', 'd', '!', |
| 1626 | // paddings |
| 1627 | 0x00, 0x00, |
| 1628 | }; |
| 1629 | // clang-format on |
| 1630 | |
| 1631 | unsigned char* p = packet; |
| 1632 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 1633 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 1634 | p = packet99; |
| 1635 | p_size = QUIC_ARRAYSIZE(packet99); |
| 1636 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 1637 | p = packet46; |
| 1638 | p_size = QUIC_ARRAYSIZE(packet46); |
| 1639 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 1640 | p = packet44; |
| 1641 | p_size = QUIC_ARRAYSIZE(packet44); |
| 1642 | } |
| 1643 | |
| 1644 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 1645 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1646 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1647 | ASSERT_TRUE(visitor_.header_.get()); |
| 1648 | EXPECT_TRUE(CheckDecryption( |
| 1649 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 1650 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 1651 | |
| 1652 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1653 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1654 | EXPECT_EQ(2u, visitor_.padding_frames_.size()); |
| 1655 | EXPECT_EQ(2, visitor_.padding_frames_[0]->num_padding_bytes); |
| 1656 | EXPECT_EQ(2, visitor_.padding_frames_[1]->num_padding_bytes); |
| 1657 | EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 1658 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1659 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 1660 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 1661 | } |
| 1662 | |
| 1663 | TEST_P(QuicFramerTest, StreamFrame) { |
| 1664 | // clang-format off |
| 1665 | PacketFragments packet = { |
| 1666 | // public flags (8 byte connection_id) |
| 1667 | {"", |
| 1668 | {0x28}}, |
| 1669 | // connection_id |
| 1670 | {"", |
| 1671 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1672 | // packet number |
| 1673 | {"", |
| 1674 | {0x12, 0x34, 0x56, 0x78}}, |
| 1675 | // frame type (stream frame with fin) |
| 1676 | {"", |
| 1677 | {0xFF}}, |
| 1678 | // stream id |
| 1679 | {"Unable to read stream_id.", |
| 1680 | {0x01, 0x02, 0x03, 0x04}}, |
| 1681 | // offset |
| 1682 | {"Unable to read offset.", |
| 1683 | {0x3A, 0x98, 0xFE, 0xDC, |
| 1684 | 0x32, 0x10, 0x76, 0x54}}, |
| 1685 | {"Unable to read frame data.", |
| 1686 | { |
| 1687 | // data length |
| 1688 | 0x00, 0x0c, |
| 1689 | // data |
| 1690 | 'h', 'e', 'l', 'l', |
| 1691 | 'o', ' ', 'w', 'o', |
| 1692 | 'r', 'l', 'd', '!'}}, |
| 1693 | }; |
| 1694 | |
| 1695 | PacketFragments packet44 = { |
| 1696 | // type (short header, 4 byte packet number) |
| 1697 | {"", |
| 1698 | {0x32}}, |
| 1699 | // connection_id |
| 1700 | {"", |
| 1701 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1702 | // packet number |
| 1703 | {"", |
| 1704 | {0x12, 0x34, 0x56, 0x78}}, |
| 1705 | // frame type (stream frame with fin) |
| 1706 | {"", |
| 1707 | {0xFF}}, |
| 1708 | // stream id |
| 1709 | {"Unable to read stream_id.", |
| 1710 | {0x01, 0x02, 0x03, 0x04}}, |
| 1711 | // offset |
| 1712 | {"Unable to read offset.", |
| 1713 | {0x3A, 0x98, 0xFE, 0xDC, |
| 1714 | 0x32, 0x10, 0x76, 0x54}}, |
| 1715 | {"Unable to read frame data.", |
| 1716 | { |
| 1717 | // data length |
| 1718 | 0x00, 0x0c, |
| 1719 | // data |
| 1720 | 'h', 'e', 'l', 'l', |
| 1721 | 'o', ' ', 'w', 'o', |
| 1722 | 'r', 'l', 'd', '!'}}, |
| 1723 | }; |
| 1724 | |
| 1725 | PacketFragments packet46 = { |
| 1726 | // type (short header, 4 byte packet number) |
| 1727 | {"", |
| 1728 | {0x43}}, |
| 1729 | // connection_id |
| 1730 | {"", |
| 1731 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1732 | // packet number |
| 1733 | {"", |
| 1734 | {0x12, 0x34, 0x56, 0x78}}, |
| 1735 | // frame type (stream frame with fin) |
| 1736 | {"", |
| 1737 | {0xFF}}, |
| 1738 | // stream id |
| 1739 | {"Unable to read stream_id.", |
| 1740 | {0x01, 0x02, 0x03, 0x04}}, |
| 1741 | // offset |
| 1742 | {"Unable to read offset.", |
| 1743 | {0x3A, 0x98, 0xFE, 0xDC, |
| 1744 | 0x32, 0x10, 0x76, 0x54}}, |
| 1745 | {"Unable to read frame data.", |
| 1746 | { |
| 1747 | // data length |
| 1748 | 0x00, 0x0c, |
| 1749 | // data |
| 1750 | 'h', 'e', 'l', 'l', |
| 1751 | 'o', ' ', 'w', 'o', |
| 1752 | 'r', 'l', 'd', '!'}}, |
| 1753 | }; |
| 1754 | |
| 1755 | PacketFragments packet99 = { |
| 1756 | // type (short header, 4 byte packet number) |
| 1757 | {"", |
| 1758 | {0x43}}, |
| 1759 | // connection_id |
| 1760 | {"", |
| 1761 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1762 | // packet number |
| 1763 | {"", |
| 1764 | {0x12, 0x34, 0x56, 0x78}}, |
| 1765 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 1766 | {"", |
| 1767 | { 0x08 | 0x01 | 0x02 | 0x04 }}, |
| 1768 | // stream id |
| 1769 | {"Unable to read stream_id.", |
| 1770 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 1771 | // offset |
| 1772 | {"Unable to read stream data offset.", |
| 1773 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 1774 | 0x32, 0x10, 0x76, 0x54}}, |
| 1775 | // data length |
| 1776 | {"Unable to read stream data length.", |
| 1777 | {kVarInt62OneByte + 0x0c}}, |
| 1778 | // data |
| 1779 | {"Unable to read frame data.", |
| 1780 | { 'h', 'e', 'l', 'l', |
| 1781 | 'o', ' ', 'w', 'o', |
| 1782 | 'r', 'l', 'd', '!'}}, |
| 1783 | }; |
| 1784 | // clang-format on |
| 1785 | |
| 1786 | PacketFragments& fragments = |
| 1787 | framer_.transport_version() == QUIC_VERSION_99 |
| 1788 | ? packet99 |
| 1789 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 1790 | ? packet46 |
| 1791 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 1792 | : packet)); |
| 1793 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1794 | AssemblePacketFromFragments(fragments)); |
| 1795 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 1796 | |
| 1797 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1798 | ASSERT_TRUE(visitor_.header_.get()); |
| 1799 | EXPECT_TRUE(CheckDecryption( |
| 1800 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 1801 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 1802 | |
| 1803 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1804 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1805 | EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 1806 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1807 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 1808 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 1809 | |
| 1810 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 1811 | } |
| 1812 | |
| 1813 | // Test an empty (no data) stream frame. |
| 1814 | TEST_P(QuicFramerTest, EmptyStreamFrame) { |
| 1815 | // Only the IETF QUIC spec explicitly says that empty |
| 1816 | // stream frames are supported. |
| 1817 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 1818 | return; |
| 1819 | } |
| 1820 | // clang-format off |
| 1821 | PacketFragments packet = { |
| 1822 | // type (short header, 4 byte packet number) |
| 1823 | {"", |
| 1824 | {0x43}}, |
| 1825 | // connection_id |
| 1826 | {"", |
| 1827 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1828 | // packet number |
| 1829 | {"", |
| 1830 | {0x12, 0x34, 0x56, 0x78}}, |
| 1831 | // frame type - IETF_STREAM with FIN, LEN, and OFFSET bits set. |
| 1832 | {"", |
| 1833 | { 0x08 | 0x01 | 0x02 | 0x04 }}, |
| 1834 | // stream id |
| 1835 | {"Unable to read stream_id.", |
| 1836 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 1837 | // offset |
| 1838 | {"Unable to read stream data offset.", |
| 1839 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 1840 | 0x32, 0x10, 0x76, 0x54}}, |
| 1841 | // data length |
| 1842 | {"Unable to read stream data length.", |
| 1843 | {kVarInt62OneByte + 0x00}}, |
| 1844 | }; |
| 1845 | // clang-format on |
| 1846 | |
| 1847 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 1848 | AssemblePacketFromFragments(packet)); |
| 1849 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 1850 | |
| 1851 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 1852 | ASSERT_TRUE(visitor_.header_.get()); |
| 1853 | EXPECT_TRUE(CheckDecryption( |
| 1854 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 1855 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 1856 | |
| 1857 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 1858 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 1859 | EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 1860 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 1861 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 1862 | EXPECT_EQ(visitor_.stream_frames_[0].get()->data_length, 0u); |
| 1863 | |
| 1864 | CheckFramingBoundaries(packet, QUIC_INVALID_STREAM_DATA); |
| 1865 | } |
| 1866 | |
| 1867 | TEST_P(QuicFramerTest, MissingDiversificationNonce) { |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame^] | 1868 | if (framer_.version().handshake_protocol != PROTOCOL_QUIC_CRYPTO) { |
| 1869 | // TLS does not use diversification nonces. |
| 1870 | return; |
| 1871 | } |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1872 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1873 | framer_.SetDecrypter(ENCRYPTION_NONE, |
| 1874 | QuicMakeUnique<NullDecrypter>(Perspective::IS_CLIENT)); |
| 1875 | decrypter_ = new test::TestDecrypter(); |
| 1876 | framer_.SetAlternativeDecrypter( |
| 1877 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 1878 | |
| 1879 | // clang-format off |
| 1880 | unsigned char packet[] = { |
| 1881 | // public flags (8 byte connection_id) |
| 1882 | 0x28, |
| 1883 | // connection_id |
| 1884 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 1885 | // packet number |
| 1886 | 0x12, 0x34, 0x56, 0x78, |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame^] | 1887 | // padding frame |
| 1888 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1889 | }; |
| 1890 | |
| 1891 | unsigned char packet44[] = { |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame^] | 1892 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1893 | 0xFC, |
| 1894 | // version tag |
| 1895 | QUIC_VERSION_BYTES, |
| 1896 | // connection_id length |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame^] | 1897 | 0x05, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1898 | // connection_id |
| 1899 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 1900 | // packet number |
| 1901 | 0x12, 0x34, 0x56, 0x78, |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame^] | 1902 | // padding frame |
| 1903 | 0x00, |
| 1904 | }; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1905 | |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame^] | 1906 | unsigned char packet46[] = { |
| 1907 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 1908 | 0xD3, |
| 1909 | // version tag |
| 1910 | QUIC_VERSION_BYTES, |
| 1911 | // connection_id length |
| 1912 | 0x05, |
| 1913 | // connection_id |
| 1914 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 1915 | // packet number |
| 1916 | 0x12, 0x34, 0x56, 0x78, |
| 1917 | // padding frame |
| 1918 | 0x00, |
| 1919 | }; |
| 1920 | |
| 1921 | unsigned char packet99[] = { |
| 1922 | // type (long header, ZERO_RTT_PROTECTED, 4-byte packet number) |
| 1923 | 0xD3, |
| 1924 | // version tag |
| 1925 | QUIC_VERSION_BYTES, |
| 1926 | // connection_id length |
| 1927 | 0x05, |
| 1928 | // connection_id |
| 1929 | 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 1930 | // IETF long header payload length |
| 1931 | 0x05, |
| 1932 | // packet number |
| 1933 | 0x12, 0x34, 0x56, 0x78, |
| 1934 | // padding frame |
| 1935 | 0x00, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1936 | }; |
| 1937 | // clang-format on |
| 1938 | |
| 1939 | unsigned char* p = packet; |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame^] | 1940 | size_t p_length = QUIC_ARRAYSIZE(packet); |
| 1941 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 1942 | p = packet99; |
| 1943 | p_length = QUIC_ARRAYSIZE(packet99); |
| 1944 | } else if (framer_.transport_version() >= QUIC_VERSION_46) { |
| 1945 | p = packet46; |
| 1946 | p_length = QUIC_ARRAYSIZE(packet46); |
| 1947 | } else if (framer_.transport_version() >= QUIC_VERSION_44) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1948 | p = packet44; |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame^] | 1949 | p_length = QUIC_ARRAYSIZE(packet44); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1950 | } |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame^] | 1951 | QuicEncryptedPacket encrypted(AsChars(p), p_length, false); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1952 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame^] | 1953 | if (framer_.transport_version() >= QUIC_VERSION_44) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1954 | // Cannot read diversification nonce. |
| 1955 | EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame^] | 1956 | EXPECT_EQ("Unable to read nonce.", framer_.detailed_error()); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1957 | } else { |
| 1958 | EXPECT_EQ(QUIC_DECRYPTION_FAILURE, framer_.error()); |
| 1959 | } |
| 1960 | } |
| 1961 | |
| 1962 | TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) { |
| 1963 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 1964 | // This test is nonsensical for IETF Quic. |
| 1965 | return; |
| 1966 | } |
| 1967 | // clang-format off |
| 1968 | PacketFragments packet = { |
| 1969 | // public flags (8 byte connection_id) |
| 1970 | {"", |
| 1971 | {0x28}}, |
| 1972 | // connection_id |
| 1973 | {"", |
| 1974 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 1975 | // packet number |
| 1976 | {"", |
| 1977 | {0x12, 0x34, 0x56, 0x78}}, |
| 1978 | // frame type (stream frame with fin) |
| 1979 | {"", |
| 1980 | {0xFE}}, |
| 1981 | // stream id |
| 1982 | {"Unable to read stream_id.", |
| 1983 | {0x02, 0x03, 0x04}}, |
| 1984 | // offset |
| 1985 | {"Unable to read offset.", |
| 1986 | {0x3A, 0x98, 0xFE, 0xDC, |
| 1987 | 0x32, 0x10, 0x76, 0x54}}, |
| 1988 | {"Unable to read frame data.", |
| 1989 | { |
| 1990 | // data length |
| 1991 | 0x00, 0x0c, |
| 1992 | // data |
| 1993 | 'h', 'e', 'l', 'l', |
| 1994 | 'o', ' ', 'w', 'o', |
| 1995 | 'r', 'l', 'd', '!'}}, |
| 1996 | }; |
| 1997 | // clang-format on |
| 1998 | |
| 1999 | PacketFragments& fragments = packet; |
| 2000 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2001 | AssemblePacketFromFragments(fragments)); |
| 2002 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2003 | |
| 2004 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2005 | ASSERT_TRUE(visitor_.header_.get()); |
| 2006 | EXPECT_TRUE(CheckDecryption( |
| 2007 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2008 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2009 | |
| 2010 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2011 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2012 | // Stream ID should be the last 3 bytes of kStreamId. |
| 2013 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2014 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2015 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2016 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2017 | |
| 2018 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2019 | } |
| 2020 | |
| 2021 | TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) { |
| 2022 | // clang-format off |
| 2023 | PacketFragments packet = { |
| 2024 | // public flags (8 byte connection_id) |
| 2025 | {"", |
| 2026 | {0x28}}, |
| 2027 | // connection_id |
| 2028 | {"", |
| 2029 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2030 | // packet number |
| 2031 | {"", |
| 2032 | {0x12, 0x34, 0x56, 0x78}}, |
| 2033 | // frame type (stream frame with fin) |
| 2034 | {"", |
| 2035 | {0xFD}}, |
| 2036 | // stream id |
| 2037 | {"Unable to read stream_id.", |
| 2038 | {0x03, 0x04}}, |
| 2039 | // offset |
| 2040 | {"Unable to read offset.", |
| 2041 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2042 | 0x32, 0x10, 0x76, 0x54}}, |
| 2043 | {"Unable to read frame data.", |
| 2044 | { |
| 2045 | // data length |
| 2046 | 0x00, 0x0c, |
| 2047 | // data |
| 2048 | 'h', 'e', 'l', 'l', |
| 2049 | 'o', ' ', 'w', 'o', |
| 2050 | 'r', 'l', 'd', '!'}}, |
| 2051 | }; |
| 2052 | |
| 2053 | PacketFragments packet44 = { |
| 2054 | // type (short header, 4 byte packet number) |
| 2055 | {"", |
| 2056 | {0x32}}, |
| 2057 | // connection_id |
| 2058 | {"", |
| 2059 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2060 | // packet number |
| 2061 | {"", |
| 2062 | {0x12, 0x34, 0x56, 0x78}}, |
| 2063 | // frame type (stream frame with fin) |
| 2064 | {"", |
| 2065 | {0xFD}}, |
| 2066 | // stream id |
| 2067 | {"Unable to read stream_id.", |
| 2068 | {0x03, 0x04}}, |
| 2069 | // offset |
| 2070 | {"Unable to read offset.", |
| 2071 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2072 | 0x32, 0x10, 0x76, 0x54}}, |
| 2073 | {"Unable to read frame data.", |
| 2074 | { |
| 2075 | // data length |
| 2076 | 0x00, 0x0c, |
| 2077 | // data |
| 2078 | 'h', 'e', 'l', 'l', |
| 2079 | 'o', ' ', 'w', 'o', |
| 2080 | 'r', 'l', 'd', '!'}}, |
| 2081 | }; |
| 2082 | |
| 2083 | PacketFragments packet46 = { |
| 2084 | // type (short header, 4 byte packet number) |
| 2085 | {"", |
| 2086 | {0x43}}, |
| 2087 | // connection_id |
| 2088 | {"", |
| 2089 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2090 | // packet number |
| 2091 | {"", |
| 2092 | {0x12, 0x34, 0x56, 0x78}}, |
| 2093 | // frame type (stream frame with fin) |
| 2094 | {"", |
| 2095 | {0xFD}}, |
| 2096 | // stream id |
| 2097 | {"Unable to read stream_id.", |
| 2098 | {0x03, 0x04}}, |
| 2099 | // offset |
| 2100 | {"Unable to read offset.", |
| 2101 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2102 | 0x32, 0x10, 0x76, 0x54}}, |
| 2103 | {"Unable to read frame data.", |
| 2104 | { |
| 2105 | // data length |
| 2106 | 0x00, 0x0c, |
| 2107 | // data |
| 2108 | 'h', 'e', 'l', 'l', |
| 2109 | 'o', ' ', 'w', 'o', |
| 2110 | 'r', 'l', 'd', '!'}}, |
| 2111 | }; |
| 2112 | |
| 2113 | PacketFragments packet99 = { |
| 2114 | // type (short header, 4 byte packet number) |
| 2115 | {"", |
| 2116 | {0x43}}, |
| 2117 | // connection_id |
| 2118 | {"", |
| 2119 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2120 | // packet number |
| 2121 | {"", |
| 2122 | {0x12, 0x34, 0x56, 0x78}}, |
| 2123 | // frame type (IETF_STREAM frame with LEN, FIN, and OFFSET bits set) |
| 2124 | {"", |
| 2125 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2126 | // stream id |
| 2127 | {"Unable to read stream_id.", |
| 2128 | {kVarInt62TwoBytes + 0x03, 0x04}}, |
| 2129 | // offset |
| 2130 | {"Unable to read stream data offset.", |
| 2131 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2132 | 0x32, 0x10, 0x76, 0x54}}, |
| 2133 | // data length |
| 2134 | {"Unable to read stream data length.", |
| 2135 | {kVarInt62OneByte + 0x0c}}, |
| 2136 | // data |
| 2137 | {"Unable to read frame data.", |
| 2138 | { 'h', 'e', 'l', 'l', |
| 2139 | 'o', ' ', 'w', 'o', |
| 2140 | 'r', 'l', 'd', '!'}}, |
| 2141 | }; |
| 2142 | // clang-format on |
| 2143 | |
| 2144 | PacketFragments& fragments = |
| 2145 | framer_.transport_version() == QUIC_VERSION_99 |
| 2146 | ? packet99 |
| 2147 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 2148 | ? packet46 |
| 2149 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 2150 | : packet)); |
| 2151 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2152 | AssemblePacketFromFragments(fragments)); |
| 2153 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2154 | |
| 2155 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2156 | ASSERT_TRUE(visitor_.header_.get()); |
| 2157 | EXPECT_TRUE(CheckDecryption( |
| 2158 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2159 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2160 | |
| 2161 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2162 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2163 | // Stream ID should be the last 2 bytes of kStreamId. |
| 2164 | EXPECT_EQ(0x0000FFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2165 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2166 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2167 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2168 | |
| 2169 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2170 | } |
| 2171 | |
| 2172 | TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) { |
| 2173 | // clang-format off |
| 2174 | PacketFragments packet = { |
| 2175 | // public flags (8 byte connection_id) |
| 2176 | {"", |
| 2177 | {0x28}}, |
| 2178 | // connection_id |
| 2179 | {"", |
| 2180 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2181 | // packet number |
| 2182 | {"", |
| 2183 | {0x12, 0x34, 0x56, 0x78}}, |
| 2184 | // frame type (stream frame with fin) |
| 2185 | {"", |
| 2186 | {0xFC}}, |
| 2187 | // stream id |
| 2188 | {"Unable to read stream_id.", |
| 2189 | {0x04}}, |
| 2190 | // offset |
| 2191 | {"Unable to read offset.", |
| 2192 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2193 | 0x32, 0x10, 0x76, 0x54}}, |
| 2194 | {"Unable to read frame data.", |
| 2195 | { |
| 2196 | // data length |
| 2197 | 0x00, 0x0c, |
| 2198 | // data |
| 2199 | 'h', 'e', 'l', 'l', |
| 2200 | 'o', ' ', 'w', 'o', |
| 2201 | 'r', 'l', 'd', '!'}}, |
| 2202 | }; |
| 2203 | |
| 2204 | PacketFragments packet44 = { |
| 2205 | // type (short header, 4 byte packet number) |
| 2206 | {"", |
| 2207 | {0x32}}, |
| 2208 | // connection_id |
| 2209 | {"", |
| 2210 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2211 | // packet number |
| 2212 | {"", |
| 2213 | {0x12, 0x34, 0x56, 0x78}}, |
| 2214 | // frame type (stream frame with fin) |
| 2215 | {"", |
| 2216 | {0xFC}}, |
| 2217 | // stream id |
| 2218 | {"Unable to read stream_id.", |
| 2219 | {0x04}}, |
| 2220 | // offset |
| 2221 | {"Unable to read offset.", |
| 2222 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2223 | 0x32, 0x10, 0x76, 0x54}}, |
| 2224 | {"Unable to read frame data.", |
| 2225 | { |
| 2226 | // data length |
| 2227 | 0x00, 0x0c, |
| 2228 | // data |
| 2229 | 'h', 'e', 'l', 'l', |
| 2230 | 'o', ' ', 'w', 'o', |
| 2231 | 'r', 'l', 'd', '!'}}, |
| 2232 | }; |
| 2233 | |
| 2234 | PacketFragments packet46 = { |
| 2235 | // type (short header, 4 byte packet number) |
| 2236 | {"", |
| 2237 | {0x43}}, |
| 2238 | // connection_id |
| 2239 | {"", |
| 2240 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2241 | // packet number |
| 2242 | {"", |
| 2243 | {0x12, 0x34, 0x56, 0x78}}, |
| 2244 | // frame type (stream frame with fin) |
| 2245 | {"", |
| 2246 | {0xFC}}, |
| 2247 | // stream id |
| 2248 | {"Unable to read stream_id.", |
| 2249 | {0x04}}, |
| 2250 | // offset |
| 2251 | {"Unable to read offset.", |
| 2252 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2253 | 0x32, 0x10, 0x76, 0x54}}, |
| 2254 | {"Unable to read frame data.", |
| 2255 | { |
| 2256 | // data length |
| 2257 | 0x00, 0x0c, |
| 2258 | // data |
| 2259 | 'h', 'e', 'l', 'l', |
| 2260 | 'o', ' ', 'w', 'o', |
| 2261 | 'r', 'l', 'd', '!'}}, |
| 2262 | }; |
| 2263 | |
| 2264 | PacketFragments packet99 = { |
| 2265 | // type (short header, 4 byte packet number) |
| 2266 | {"", |
| 2267 | {0x43}}, |
| 2268 | // connection_id |
| 2269 | {"", |
| 2270 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2271 | // packet number |
| 2272 | {"", |
| 2273 | {0x12, 0x34, 0x56, 0x78}}, |
| 2274 | // frame type (IETF_STREAM frame with LEN, FIN, and OFFSET bits set) |
| 2275 | {"", |
| 2276 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2277 | // stream id |
| 2278 | {"Unable to read stream_id.", |
| 2279 | {kVarInt62OneByte + 0x04}}, |
| 2280 | // offset |
| 2281 | {"Unable to read stream data offset.", |
| 2282 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2283 | 0x32, 0x10, 0x76, 0x54}}, |
| 2284 | // data length |
| 2285 | {"Unable to read stream data length.", |
| 2286 | {kVarInt62OneByte + 0x0c}}, |
| 2287 | // data |
| 2288 | {"Unable to read frame data.", |
| 2289 | { 'h', 'e', 'l', 'l', |
| 2290 | 'o', ' ', 'w', 'o', |
| 2291 | 'r', 'l', 'd', '!'}}, |
| 2292 | }; |
| 2293 | // clang-format on |
| 2294 | |
| 2295 | PacketFragments& fragments = |
| 2296 | framer_.transport_version() == QUIC_VERSION_99 |
| 2297 | ? packet99 |
| 2298 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 2299 | ? packet46 |
| 2300 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 2301 | : packet)); |
| 2302 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2303 | AssemblePacketFromFragments(fragments)); |
| 2304 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2305 | |
| 2306 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2307 | ASSERT_TRUE(visitor_.header_.get()); |
| 2308 | EXPECT_TRUE(CheckDecryption( |
| 2309 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2310 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2311 | |
| 2312 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2313 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2314 | // Stream ID should be the last 1 byte of kStreamId. |
| 2315 | EXPECT_EQ(0x000000FF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2316 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2317 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2318 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2319 | |
| 2320 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_DATA); |
| 2321 | } |
| 2322 | |
| 2323 | TEST_P(QuicFramerTest, StreamFrameWithVersion) { |
| 2324 | // clang-format off |
| 2325 | PacketFragments packet = { |
| 2326 | // public flags (version, 8 byte connection_id) |
| 2327 | {"", |
| 2328 | {0x29}}, |
| 2329 | // connection_id |
| 2330 | {"", |
| 2331 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2332 | // version tag |
| 2333 | {"", |
| 2334 | {QUIC_VERSION_BYTES}}, |
| 2335 | // packet number |
| 2336 | {"", |
| 2337 | {0x12, 0x34, 0x56, 0x78}}, |
| 2338 | // frame type (stream frame with fin) |
| 2339 | {"", |
| 2340 | {0xFE}}, |
| 2341 | // stream id |
| 2342 | {"Unable to read stream_id.", |
| 2343 | {0x02, 0x03, 0x04}}, |
| 2344 | // offset |
| 2345 | {"Unable to read offset.", |
| 2346 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2347 | 0x32, 0x10, 0x76, 0x54}}, |
| 2348 | {"Unable to read frame data.", |
| 2349 | { |
| 2350 | // data length |
| 2351 | 0x00, 0x0c, |
| 2352 | // data |
| 2353 | 'h', 'e', 'l', 'l', |
| 2354 | 'o', ' ', 'w', 'o', |
| 2355 | 'r', 'l', 'd', '!'}}, |
| 2356 | }; |
| 2357 | |
| 2358 | PacketFragments packet44 = { |
| 2359 | // public flags (long header with packet type ZERO_RTT_PROTECTED) |
| 2360 | {"", |
| 2361 | {0xFC}}, |
| 2362 | // version tag |
| 2363 | {"", |
| 2364 | {QUIC_VERSION_BYTES}}, |
| 2365 | // connection_id length |
| 2366 | {"", |
| 2367 | {0x50}}, |
| 2368 | // connection_id |
| 2369 | {"", |
| 2370 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2371 | // packet number |
| 2372 | {"", |
| 2373 | {0x12, 0x34, 0x56, 0x78}}, |
| 2374 | // frame type (stream frame with fin) |
| 2375 | {"", |
| 2376 | {0xFE}}, |
| 2377 | // stream id |
| 2378 | {"Unable to read stream_id.", |
| 2379 | {0x02, 0x03, 0x04}}, |
| 2380 | // offset |
| 2381 | {"Unable to read offset.", |
| 2382 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2383 | 0x32, 0x10, 0x76, 0x54}}, |
| 2384 | {"Unable to read frame data.", |
| 2385 | { |
| 2386 | // data length |
| 2387 | 0x00, 0x0c, |
| 2388 | // data |
| 2389 | 'h', 'e', 'l', 'l', |
| 2390 | 'o', ' ', 'w', 'o', |
| 2391 | 'r', 'l', 'd', '!'}}, |
| 2392 | }; |
| 2393 | |
| 2394 | PacketFragments packet46 = { |
| 2395 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 2396 | // 4-byte packet number) |
| 2397 | {"", |
| 2398 | {0xD3}}, |
| 2399 | // version tag |
| 2400 | {"", |
| 2401 | {QUIC_VERSION_BYTES}}, |
| 2402 | // connection_id length |
| 2403 | {"", |
| 2404 | {0x50}}, |
| 2405 | // connection_id |
| 2406 | {"", |
| 2407 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2408 | // packet number |
| 2409 | {"", |
| 2410 | {0x12, 0x34, 0x56, 0x78}}, |
| 2411 | // frame type (stream frame with fin) |
| 2412 | {"", |
| 2413 | {0xFE}}, |
| 2414 | // stream id |
| 2415 | {"Unable to read stream_id.", |
| 2416 | {0x02, 0x03, 0x04}}, |
| 2417 | // offset |
| 2418 | {"Unable to read offset.", |
| 2419 | {0x3A, 0x98, 0xFE, 0xDC, |
| 2420 | 0x32, 0x10, 0x76, 0x54}}, |
| 2421 | {"Unable to read frame data.", |
| 2422 | { |
| 2423 | // data length |
| 2424 | 0x00, 0x0c, |
| 2425 | // data |
| 2426 | 'h', 'e', 'l', 'l', |
| 2427 | 'o', ' ', 'w', 'o', |
| 2428 | 'r', 'l', 'd', '!'}}, |
| 2429 | }; |
| 2430 | |
| 2431 | PacketFragments packet99 = { |
| 2432 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 2433 | // 4-byte packet number) |
| 2434 | {"", |
| 2435 | {0xD3}}, |
| 2436 | // version tag |
| 2437 | {"", |
| 2438 | {QUIC_VERSION_BYTES}}, |
| 2439 | // connection_id length |
| 2440 | {"", |
| 2441 | {0x50}}, |
| 2442 | // connection_id |
| 2443 | {"", |
| 2444 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2445 | // long header packet length |
| 2446 | {"", |
| 2447 | {0x1E}}, |
| 2448 | // packet number |
| 2449 | {"", |
| 2450 | {0x12, 0x34, 0x56, 0x78}}, |
| 2451 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 2452 | {"", |
| 2453 | {0x08 | 0x01 | 0x02 | 0x04}}, |
| 2454 | // stream id |
| 2455 | {"Long header payload length longer than packet.", |
| 2456 | {kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04}}, |
| 2457 | // offset |
| 2458 | {"Long header payload length longer than packet.", |
| 2459 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2460 | 0x32, 0x10, 0x76, 0x54}}, |
| 2461 | // data length |
| 2462 | {"Long header payload length longer than packet.", |
| 2463 | {kVarInt62OneByte + 0x0c}}, |
| 2464 | // data |
| 2465 | {"Long header payload length longer than packet.", |
| 2466 | { 'h', 'e', 'l', 'l', |
| 2467 | 'o', ' ', 'w', 'o', |
| 2468 | 'r', 'l', 'd', '!'}}, |
| 2469 | }; |
| 2470 | // clang-format on |
| 2471 | |
| 2472 | QuicVariableLengthIntegerLength retry_token_length_length = |
| 2473 | VARIABLE_LENGTH_INTEGER_LENGTH_0; |
| 2474 | size_t retry_token_length = 0; |
| 2475 | QuicVariableLengthIntegerLength length_length = |
| 2476 | QuicVersionHasLongHeaderLengths(framer_.transport_version()) |
| 2477 | ? VARIABLE_LENGTH_INTEGER_LENGTH_1 |
| 2478 | : VARIABLE_LENGTH_INTEGER_LENGTH_0; |
| 2479 | |
| 2480 | PacketFragments& fragments = |
| 2481 | framer_.transport_version() == QUIC_VERSION_99 |
| 2482 | ? packet99 |
| 2483 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 2484 | ? packet46 |
| 2485 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 2486 | : packet)); |
| 2487 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2488 | AssemblePacketFromFragments(fragments)); |
| 2489 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2490 | |
| 2491 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2492 | ASSERT_TRUE(visitor_.header_.get()); |
| 2493 | EXPECT_TRUE(CheckDecryption( |
| 2494 | *encrypted, kIncludeVersion, !kIncludeDiversificationNonce, |
| 2495 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID, |
| 2496 | retry_token_length_length, retry_token_length, length_length)); |
| 2497 | |
| 2498 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 2499 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2500 | // Stream ID should be the last 3 bytes of kStreamId. |
| 2501 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 2502 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 2503 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 2504 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 2505 | |
| 2506 | CheckFramingBoundaries(fragments, |
| 2507 | framer_.transport_version() == QUIC_VERSION_99 |
| 2508 | ? QUIC_INVALID_PACKET_HEADER |
| 2509 | : QUIC_INVALID_STREAM_DATA); |
| 2510 | } |
| 2511 | |
| 2512 | TEST_P(QuicFramerTest, RejectPacket) { |
| 2513 | visitor_.accept_packet_ = false; |
| 2514 | |
| 2515 | // clang-format off |
| 2516 | unsigned char packet[] = { |
| 2517 | // public flags (8 byte connection_id) |
| 2518 | 0x28, |
| 2519 | // connection_id |
| 2520 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2521 | // packet number |
| 2522 | 0x12, 0x34, 0x56, 0x78, |
| 2523 | |
| 2524 | // frame type (stream frame with fin) |
| 2525 | 0xFF, |
| 2526 | // stream id |
| 2527 | 0x01, 0x02, 0x03, 0x04, |
| 2528 | // offset |
| 2529 | 0x3A, 0x98, 0xFE, 0xDC, |
| 2530 | 0x32, 0x10, 0x76, 0x54, |
| 2531 | // data length |
| 2532 | 0x00, 0x0c, |
| 2533 | // data |
| 2534 | 'h', 'e', 'l', 'l', |
| 2535 | 'o', ' ', 'w', 'o', |
| 2536 | 'r', 'l', 'd', '!', |
| 2537 | }; |
| 2538 | |
| 2539 | unsigned char packet44[] = { |
| 2540 | // type (short header, 4 byte packet number) |
| 2541 | 0x32, |
| 2542 | // connection_id |
| 2543 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2544 | // packet number |
| 2545 | 0x12, 0x34, 0x56, 0x78, |
| 2546 | |
| 2547 | // frame type (STREAM Frame with FIN, LEN, and OFFSET bits set) |
| 2548 | 0x10 | 0x01 | 0x02 | 0x04, |
| 2549 | // stream id |
| 2550 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 2551 | // offset |
| 2552 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2553 | 0x32, 0x10, 0x76, 0x54, |
| 2554 | // data length |
| 2555 | kVarInt62OneByte + 0x0c, |
| 2556 | // data |
| 2557 | 'h', 'e', 'l', 'l', |
| 2558 | 'o', ' ', 'w', 'o', |
| 2559 | 'r', 'l', 'd', '!', |
| 2560 | }; |
| 2561 | |
| 2562 | unsigned char packet46[] = { |
| 2563 | // type (short header, 4 byte packet number) |
| 2564 | 0x43, |
| 2565 | // connection_id |
| 2566 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2567 | // packet number |
| 2568 | 0x12, 0x34, 0x56, 0x78, |
| 2569 | |
| 2570 | // frame type (STREAM Frame with FIN, LEN, and OFFSET bits set) |
| 2571 | 0x10 | 0x01 | 0x02 | 0x04, |
| 2572 | // stream id |
| 2573 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 2574 | // offset |
| 2575 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 2576 | 0x32, 0x10, 0x76, 0x54, |
| 2577 | // data length |
| 2578 | kVarInt62OneByte + 0x0c, |
| 2579 | // data |
| 2580 | 'h', 'e', 'l', 'l', |
| 2581 | 'o', ' ', 'w', 'o', |
| 2582 | 'r', 'l', 'd', '!', |
| 2583 | }; |
| 2584 | // clang-format on |
| 2585 | |
| 2586 | unsigned char* p = packet; |
| 2587 | if (framer_.transport_version() > QUIC_VERSION_44) { |
| 2588 | p = packet46; |
| 2589 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 2590 | p = packet44; |
| 2591 | } |
| 2592 | QuicEncryptedPacket encrypted(AsChars(p), |
| 2593 | framer_.transport_version() > QUIC_VERSION_43 |
| 2594 | ? QUIC_ARRAYSIZE(packet44) |
| 2595 | : QUIC_ARRAYSIZE(packet), |
| 2596 | false); |
| 2597 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 2598 | |
| 2599 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2600 | ASSERT_TRUE(visitor_.header_.get()); |
| 2601 | EXPECT_TRUE(CheckDecryption( |
| 2602 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2603 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2604 | |
| 2605 | ASSERT_EQ(0u, visitor_.stream_frames_.size()); |
| 2606 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 2607 | } |
| 2608 | |
| 2609 | TEST_P(QuicFramerTest, RejectPublicHeader) { |
| 2610 | visitor_.accept_public_header_ = false; |
| 2611 | |
| 2612 | // clang-format off |
| 2613 | unsigned char packet[] = { |
| 2614 | // public flags (8 byte connection_id) |
| 2615 | 0x28, |
| 2616 | // connection_id |
| 2617 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2618 | }; |
| 2619 | |
| 2620 | unsigned char packet44[] = { |
| 2621 | // type (short header, 1 byte packet number) |
| 2622 | 0x30, |
| 2623 | // connection_id |
| 2624 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2625 | // packet number |
| 2626 | 0x01, |
| 2627 | }; |
| 2628 | |
| 2629 | unsigned char packet46[] = { |
| 2630 | // type (short header, 1 byte packet number) |
| 2631 | 0x40, |
| 2632 | // connection_id |
| 2633 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 2634 | // packet number |
| 2635 | 0x01, |
| 2636 | }; |
| 2637 | // clang-format on |
| 2638 | |
| 2639 | QuicEncryptedPacket encrypted( |
| 2640 | framer_.transport_version() > QUIC_VERSION_44 |
| 2641 | ? AsChars(packet46) |
| 2642 | : (framer_.transport_version() > QUIC_VERSION_43 ? AsChars(packet44) |
| 2643 | : AsChars(packet)), |
| 2644 | framer_.transport_version() > QUIC_VERSION_44 |
| 2645 | ? QUIC_ARRAYSIZE(packet46) |
| 2646 | : (framer_.transport_version() > QUIC_VERSION_43 |
| 2647 | ? QUIC_ARRAYSIZE(packet44) |
| 2648 | : QUIC_ARRAYSIZE(packet)), |
| 2649 | false); |
| 2650 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 2651 | |
| 2652 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2653 | ASSERT_TRUE(visitor_.header_.get()); |
| 2654 | EXPECT_FALSE(visitor_.header_->packet_number.IsInitialized()); |
| 2655 | } |
| 2656 | |
| 2657 | TEST_P(QuicFramerTest, AckFrameOneAckBlock) { |
| 2658 | // clang-format off |
| 2659 | PacketFragments packet = { |
| 2660 | // public flags (8 byte connection_id) |
| 2661 | {"", |
| 2662 | {0x2C}}, |
| 2663 | // connection_id |
| 2664 | {"", |
| 2665 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2666 | // packet number |
| 2667 | {"", |
| 2668 | {0x12, 0x34, 0x56, 0x78}}, |
| 2669 | // frame type (ack frame) |
| 2670 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2671 | {"", |
| 2672 | {0x45}}, |
| 2673 | // largest acked |
| 2674 | {"Unable to read largest acked.", |
| 2675 | {0x12, 0x34}}, |
| 2676 | // Zero delta time. |
| 2677 | {"Unable to read ack delay time.", |
| 2678 | {0x00, 0x00}}, |
| 2679 | // first ack block length. |
| 2680 | {"Unable to read first ack block length.", |
| 2681 | {0x12, 0x34}}, |
| 2682 | // num timestamps. |
| 2683 | {"Unable to read num received packets.", |
| 2684 | {0x00}} |
| 2685 | }; |
| 2686 | |
| 2687 | PacketFragments packet44 = { |
| 2688 | // type (short packet, 4 byte packet number) |
| 2689 | {"", |
| 2690 | {0x32}}, |
| 2691 | // connection_id |
| 2692 | {"", |
| 2693 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2694 | // packet number |
| 2695 | {"", |
| 2696 | {0x12, 0x34, 0x56, 0x78}}, |
| 2697 | // frame type (ack frame) |
| 2698 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2699 | {"", |
| 2700 | {0x45}}, |
| 2701 | // largest acked |
| 2702 | {"Unable to read largest acked.", |
| 2703 | {0x12, 0x34}}, |
| 2704 | // Zero delta time. |
| 2705 | {"Unable to read ack delay time.", |
| 2706 | {0x00, 0x00}}, |
| 2707 | // first ack block length. |
| 2708 | {"Unable to read first ack block length.", |
| 2709 | {0x12, 0x34}}, |
| 2710 | // num timestamps. |
| 2711 | {"Unable to read num received packets.", |
| 2712 | {0x00}} |
| 2713 | }; |
| 2714 | |
| 2715 | PacketFragments packet46 = { |
| 2716 | // type (short packet, 4 byte packet number) |
| 2717 | {"", |
| 2718 | {0x43}}, |
| 2719 | // connection_id |
| 2720 | {"", |
| 2721 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2722 | // packet number |
| 2723 | {"", |
| 2724 | {0x12, 0x34, 0x56, 0x78}}, |
| 2725 | // frame type (ack frame) |
| 2726 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2727 | {"", |
| 2728 | {0x45}}, |
| 2729 | // largest acked |
| 2730 | {"Unable to read largest acked.", |
| 2731 | {0x12, 0x34}}, |
| 2732 | // Zero delta time. |
| 2733 | {"Unable to read ack delay time.", |
| 2734 | {0x00, 0x00}}, |
| 2735 | // first ack block length. |
| 2736 | {"Unable to read first ack block length.", |
| 2737 | {0x12, 0x34}}, |
| 2738 | // num timestamps. |
| 2739 | {"Unable to read num received packets.", |
| 2740 | {0x00}} |
| 2741 | }; |
| 2742 | |
| 2743 | PacketFragments packet99 = { |
| 2744 | // type (short packet, 4 byte packet number) |
| 2745 | {"", |
| 2746 | {0x43}}, |
| 2747 | // connection_id |
| 2748 | {"", |
| 2749 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2750 | // packet number |
| 2751 | {"", |
| 2752 | {0x12, 0x34, 0x56, 0x78}}, |
| 2753 | // frame type (IETF_ACK) |
| 2754 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2755 | // IETF-Quic ignores the bit-fields in the ack type, all of |
| 2756 | // that information is encoded elsewhere in the frame. |
| 2757 | {"", |
| 2758 | {0x02}}, |
| 2759 | // largest acked |
| 2760 | {"Unable to read largest acked.", |
| 2761 | {kVarInt62TwoBytes + 0x12, 0x34}}, |
| 2762 | // Zero delta time. |
| 2763 | {"Unable to read ack delay time.", |
| 2764 | {kVarInt62OneByte + 0x00}}, |
| 2765 | // Ack block count (0 -- no blocks after the first) |
| 2766 | {"Unable to read ack block count.", |
| 2767 | {kVarInt62OneByte + 0x00}}, |
| 2768 | // first ack block length - 1. |
| 2769 | // IETF Quic defines the ack block's value as the "number of |
| 2770 | // packets that preceed the largest packet number in the block" |
| 2771 | // which for the 1st ack block is the largest acked field, |
| 2772 | // above. This means that if we are acking just packet 0x1234 |
| 2773 | // then the 1st ack block will be 0. |
| 2774 | {"Unable to read first ack block length.", |
| 2775 | {kVarInt62TwoBytes + 0x12, 0x33}} |
| 2776 | }; |
| 2777 | // clang-format on |
| 2778 | |
| 2779 | PacketFragments& fragments = |
| 2780 | framer_.transport_version() == QUIC_VERSION_99 |
| 2781 | ? packet99 |
| 2782 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 2783 | ? packet46 |
| 2784 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 2785 | : packet)); |
| 2786 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2787 | AssemblePacketFromFragments(fragments)); |
| 2788 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 2789 | |
| 2790 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 2791 | ASSERT_TRUE(visitor_.header_.get()); |
| 2792 | EXPECT_TRUE(CheckDecryption( |
| 2793 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 2794 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 2795 | |
| 2796 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 2797 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 2798 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 2799 | EXPECT_EQ(kSmallLargestObserved, LargestAcked(frame)); |
| 2800 | ASSERT_EQ(4660u, frame.packets.NumPacketsSlow()); |
| 2801 | |
| 2802 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 2803 | } |
| 2804 | |
| 2805 | // This test checks that the ack frame processor correctly identifies |
| 2806 | // and handles the case where the first ack block is larger than the |
| 2807 | // largest_acked packet. |
| 2808 | TEST_P(QuicFramerTest, FirstAckFrameUnderflow) { |
| 2809 | // clang-format off |
| 2810 | PacketFragments packet = { |
| 2811 | // public flags (8 byte connection_id) |
| 2812 | {"", |
| 2813 | {0x2C}}, |
| 2814 | // connection_id |
| 2815 | {"", |
| 2816 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2817 | // packet number |
| 2818 | {"", |
| 2819 | {0x12, 0x34, 0x56, 0x78}}, |
| 2820 | // frame type (ack frame) |
| 2821 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2822 | {"", |
| 2823 | {0x45}}, |
| 2824 | // largest acked |
| 2825 | {"Unable to read largest acked.", |
| 2826 | {0x12, 0x34}}, |
| 2827 | // Zero delta time. |
| 2828 | {"Unable to read ack delay time.", |
| 2829 | {0x00, 0x00}}, |
| 2830 | // first ack block length. |
| 2831 | {"Unable to read first ack block length.", |
| 2832 | {0x88, 0x88}}, |
| 2833 | // num timestamps. |
| 2834 | {"Underflow with first ack block length 34952 largest acked is 4660.", |
| 2835 | {0x00}} |
| 2836 | }; |
| 2837 | |
| 2838 | PacketFragments packet44 = { |
| 2839 | // type (short header, 4 byte packet number) |
| 2840 | {"", |
| 2841 | {0x32}}, |
| 2842 | // connection_id |
| 2843 | {"", |
| 2844 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2845 | // packet number |
| 2846 | {"", |
| 2847 | {0x12, 0x34, 0x56, 0x78}}, |
| 2848 | // frame type (ack frame) |
| 2849 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2850 | {"", |
| 2851 | {0x45}}, |
| 2852 | // largest acked |
| 2853 | {"Unable to read largest acked.", |
| 2854 | {0x12, 0x34}}, |
| 2855 | // Zero delta time. |
| 2856 | {"Unable to read ack delay time.", |
| 2857 | {0x00, 0x00}}, |
| 2858 | // first ack block length. |
| 2859 | {"Unable to read first ack block length.", |
| 2860 | {0x88, 0x88}}, |
| 2861 | // num timestamps. |
| 2862 | {"Underflow with first ack block length 34952 largest acked is 4660.", |
| 2863 | {0x00}} |
| 2864 | }; |
| 2865 | |
| 2866 | PacketFragments packet46 = { |
| 2867 | // type (short header, 4 byte packet number) |
| 2868 | {"", |
| 2869 | {0x43}}, |
| 2870 | // connection_id |
| 2871 | {"", |
| 2872 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2873 | // packet number |
| 2874 | {"", |
| 2875 | {0x12, 0x34, 0x56, 0x78}}, |
| 2876 | // frame type (ack frame) |
| 2877 | // (one ack block, 2 byte largest observed, 2 byte block length) |
| 2878 | {"", |
| 2879 | {0x45}}, |
| 2880 | // largest acked |
| 2881 | {"Unable to read largest acked.", |
| 2882 | {0x12, 0x34}}, |
| 2883 | // Zero delta time. |
| 2884 | {"Unable to read ack delay time.", |
| 2885 | {0x00, 0x00}}, |
| 2886 | // first ack block length. |
| 2887 | {"Unable to read first ack block length.", |
| 2888 | {0x88, 0x88}}, |
| 2889 | // num timestamps. |
| 2890 | {"Underflow with first ack block length 34952 largest acked is 4660.", |
| 2891 | {0x00}} |
| 2892 | }; |
| 2893 | |
| 2894 | PacketFragments packet99 = { |
| 2895 | // type (short header, 4 byte packet number) |
| 2896 | {"", |
| 2897 | {0x43}}, |
| 2898 | // connection_id |
| 2899 | {"", |
| 2900 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2901 | // packet number |
| 2902 | {"", |
| 2903 | {0x12, 0x34, 0x56, 0x78}}, |
| 2904 | // frame type (IETF_ACK) |
| 2905 | {"", |
| 2906 | {0x02}}, |
| 2907 | // largest acked |
| 2908 | {"Unable to read largest acked.", |
| 2909 | {kVarInt62TwoBytes + 0x12, 0x34}}, |
| 2910 | // Zero delta time. |
| 2911 | {"Unable to read ack delay time.", |
| 2912 | {kVarInt62OneByte + 0x00}}, |
| 2913 | // Ack block count (0 -- no blocks after the first) |
| 2914 | {"Unable to read ack block count.", |
| 2915 | {kVarInt62OneByte + 0x00}}, |
| 2916 | // first ack block length. |
| 2917 | {"Unable to read first ack block length.", |
| 2918 | {kVarInt62TwoBytes + 0x28, 0x88}} |
| 2919 | }; |
| 2920 | // clang-format on |
| 2921 | |
| 2922 | PacketFragments& fragments = |
| 2923 | framer_.transport_version() == QUIC_VERSION_99 |
| 2924 | ? packet99 |
| 2925 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 2926 | ? packet46 |
| 2927 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 2928 | : packet)); |
| 2929 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2930 | AssemblePacketFromFragments(fragments)); |
| 2931 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 2932 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 2933 | } |
| 2934 | |
| 2935 | // This test checks that the ack frame processor correctly identifies |
| 2936 | // and handles the case where the third ack block's gap is larger than the |
| 2937 | // available space in the ack range. |
| 2938 | TEST_P(QuicFramerTest, ThirdAckBlockUnderflowGap) { |
| 2939 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 2940 | // for now, only v99 |
| 2941 | return; |
| 2942 | } |
| 2943 | // clang-format off |
| 2944 | PacketFragments packet99 = { |
| 2945 | // type (short header, 4 byte packet number) |
| 2946 | {"", |
| 2947 | {0x43}}, |
| 2948 | // connection_id |
| 2949 | {"", |
| 2950 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 2951 | // packet number |
| 2952 | {"", |
| 2953 | {0x12, 0x34, 0x56, 0x78}}, |
| 2954 | // frame type (IETF_ACK frame) |
| 2955 | {"", |
| 2956 | {0x02}}, |
| 2957 | // largest acked |
| 2958 | {"Unable to read largest acked.", |
| 2959 | {kVarInt62OneByte + 63}}, |
| 2960 | // Zero delta time. |
| 2961 | {"Unable to read ack delay time.", |
| 2962 | {kVarInt62OneByte + 0x00}}, |
| 2963 | // Ack block count (2 -- 2 blocks after the first) |
| 2964 | {"Unable to read ack block count.", |
| 2965 | {kVarInt62OneByte + 0x02}}, |
| 2966 | // first ack block length. |
| 2967 | {"Unable to read first ack block length.", |
| 2968 | {kVarInt62OneByte + 13}}, // Ack 14 packets, range 50..63 (inclusive) |
| 2969 | |
| 2970 | {"Unable to read gap block value.", |
| 2971 | {kVarInt62OneByte + 9}}, // Gap 10 packets, 40..49 (inclusive) |
| 2972 | {"Unable to read ack block value.", |
| 2973 | {kVarInt62OneByte + 9}}, // Ack 10 packets, 30..39 (inclusive) |
| 2974 | {"Unable to read gap block value.", |
| 2975 | {kVarInt62OneByte + 29}}, // A gap of 30 packets (0..29 inclusive) |
| 2976 | // should be too big, leaving no room |
| 2977 | // for the ack. |
| 2978 | {"Underflow with gap block length 30 previous ack block start is 30.", |
| 2979 | {kVarInt62OneByte + 10}}, // Don't care |
| 2980 | }; |
| 2981 | // clang-format on |
| 2982 | |
| 2983 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 2984 | AssemblePacketFromFragments(packet99)); |
| 2985 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 2986 | EXPECT_EQ( |
| 2987 | framer_.detailed_error(), |
| 2988 | "Underflow with gap block length 30 previous ack block start is 30."); |
| 2989 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 2990 | } |
| 2991 | |
| 2992 | // This test checks that the ack frame processor correctly identifies |
| 2993 | // and handles the case where the third ack block's length is larger than the |
| 2994 | // available space in the ack range. |
| 2995 | TEST_P(QuicFramerTest, ThirdAckBlockUnderflowAck) { |
| 2996 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 2997 | // for now, only v99 |
| 2998 | return; |
| 2999 | } |
| 3000 | // clang-format off |
| 3001 | PacketFragments packet99 = { |
| 3002 | // type (short header, 4 byte packet number) |
| 3003 | {"", |
| 3004 | {0x43}}, |
| 3005 | // connection_id |
| 3006 | {"", |
| 3007 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3008 | // packet number |
| 3009 | {"", |
| 3010 | {0x12, 0x34, 0x56, 0x78}}, |
| 3011 | // frame type (IETF_ACK frame) |
| 3012 | {"", |
| 3013 | {0x02}}, |
| 3014 | // largest acked |
| 3015 | {"Unable to read largest acked.", |
| 3016 | {kVarInt62OneByte + 63}}, |
| 3017 | // Zero delta time. |
| 3018 | {"Unable to read ack delay time.", |
| 3019 | {kVarInt62OneByte + 0x00}}, |
| 3020 | // Ack block count (2 -- 2 blocks after the first) |
| 3021 | {"Unable to read ack block count.", |
| 3022 | {kVarInt62OneByte + 0x02}}, |
| 3023 | // first ack block length. |
| 3024 | {"Unable to read first ack block length.", |
| 3025 | {kVarInt62OneByte + 13}}, // only 50 packet numbers "left" |
| 3026 | |
| 3027 | {"Unable to read gap block value.", |
| 3028 | {kVarInt62OneByte + 10}}, // Only 40 packet numbers left |
| 3029 | {"Unable to read ack block value.", |
| 3030 | {kVarInt62OneByte + 10}}, // only 30 packet numbers left. |
| 3031 | {"Unable to read gap block value.", |
| 3032 | {kVarInt62OneByte + 1}}, // Gap is OK, 29 packet numbers left |
| 3033 | {"Unable to read ack block value.", |
| 3034 | {kVarInt62OneByte + 30}}, // Use up all 30, should be an error |
| 3035 | }; |
| 3036 | // clang-format on |
| 3037 | |
| 3038 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3039 | AssemblePacketFromFragments(packet99)); |
| 3040 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3041 | EXPECT_EQ(framer_.detailed_error(), |
| 3042 | "Underflow with ack block length 31 latest ack block end is 25."); |
| 3043 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3044 | } |
| 3045 | |
| 3046 | // Tests a variety of ack block wrap scenarios. For example, if the |
| 3047 | // N-1th block causes packet 0 to be acked, then a gap would wrap |
| 3048 | // around to 0x3fffffff ffffffff... Make sure we detect this |
| 3049 | // condition. |
| 3050 | TEST_P(QuicFramerTest, AckBlockUnderflowGapWrap) { |
| 3051 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 3052 | // for now, only v99 |
| 3053 | return; |
| 3054 | } |
| 3055 | // clang-format off |
| 3056 | PacketFragments packet99 = { |
| 3057 | // type (short header, 4 byte packet number) |
| 3058 | {"", |
| 3059 | {0x43}}, |
| 3060 | // connection_id |
| 3061 | {"", |
| 3062 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3063 | // packet number |
| 3064 | {"", |
| 3065 | {0x12, 0x34, 0x56, 0x78}}, |
| 3066 | // frame type (IETF_ACK frame) |
| 3067 | {"", |
| 3068 | {0x02}}, |
| 3069 | // largest acked |
| 3070 | {"Unable to read largest acked.", |
| 3071 | {kVarInt62OneByte + 10}}, |
| 3072 | // Zero delta time. |
| 3073 | {"Unable to read ack delay time.", |
| 3074 | {kVarInt62OneByte + 0x00}}, |
| 3075 | // Ack block count (1 -- 1 blocks after the first) |
| 3076 | {"Unable to read ack block count.", |
| 3077 | {kVarInt62OneByte + 1}}, |
| 3078 | // first ack block length. |
| 3079 | {"Unable to read first ack block length.", |
| 3080 | {kVarInt62OneByte + 9}}, // Ack packets 1..10 (inclusive) |
| 3081 | |
| 3082 | {"Unable to read gap block value.", |
| 3083 | {kVarInt62OneByte + 1}}, // Gap of 2 packets (-1...0), should wrap |
| 3084 | {"Underflow with gap block length 2 previous ack block start is 1.", |
| 3085 | {kVarInt62OneByte + 9}}, // irrelevant |
| 3086 | }; |
| 3087 | // clang-format on |
| 3088 | |
| 3089 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3090 | AssemblePacketFromFragments(packet99)); |
| 3091 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3092 | EXPECT_EQ(framer_.detailed_error(), |
| 3093 | "Underflow with gap block length 2 previous ack block start is 1."); |
| 3094 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3095 | } |
| 3096 | |
| 3097 | // As AckBlockUnderflowGapWrap, but in this test, it's the ack |
| 3098 | // component of the ack-block that causes the wrap, not the gap. |
| 3099 | TEST_P(QuicFramerTest, AckBlockUnderflowAckWrap) { |
| 3100 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 3101 | // for now, only v99 |
| 3102 | return; |
| 3103 | } |
| 3104 | // clang-format off |
| 3105 | PacketFragments packet99 = { |
| 3106 | // type (short header, 4 byte packet number) |
| 3107 | {"", |
| 3108 | {0x43}}, |
| 3109 | // connection_id |
| 3110 | {"", |
| 3111 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3112 | // packet number |
| 3113 | {"", |
| 3114 | {0x12, 0x34, 0x56, 0x78}}, |
| 3115 | // frame type (IETF_ACK frame) |
| 3116 | {"", |
| 3117 | {0x02}}, |
| 3118 | // largest acked |
| 3119 | {"Unable to read largest acked.", |
| 3120 | {kVarInt62OneByte + 10}}, |
| 3121 | // Zero delta time. |
| 3122 | {"Unable to read ack delay time.", |
| 3123 | {kVarInt62OneByte + 0x00}}, |
| 3124 | // Ack block count (1 -- 1 blocks after the first) |
| 3125 | {"Unable to read ack block count.", |
| 3126 | {kVarInt62OneByte + 1}}, |
| 3127 | // first ack block length. |
| 3128 | {"Unable to read first ack block length.", |
| 3129 | {kVarInt62OneByte + 6}}, // Ack packets 4..10 (inclusive) |
| 3130 | |
| 3131 | {"Unable to read gap block value.", |
| 3132 | {kVarInt62OneByte + 1}}, // Gap of 2 packets (2..3) |
| 3133 | {"Unable to read ack block value.", |
| 3134 | {kVarInt62OneByte + 9}}, // Should wrap. |
| 3135 | }; |
| 3136 | // clang-format on |
| 3137 | |
| 3138 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3139 | AssemblePacketFromFragments(packet99)); |
| 3140 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3141 | EXPECT_EQ(framer_.detailed_error(), |
| 3142 | "Underflow with ack block length 10 latest ack block end is 1."); |
| 3143 | CheckFramingBoundaries(packet99, QUIC_INVALID_ACK_DATA); |
| 3144 | } |
| 3145 | |
| 3146 | // An ack block that acks the entire range, 1...0x3fffffffffffffff |
| 3147 | TEST_P(QuicFramerTest, AckBlockAcksEverything) { |
| 3148 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 3149 | // for now, only v99 |
| 3150 | return; |
| 3151 | } |
| 3152 | // clang-format off |
| 3153 | PacketFragments packet99 = { |
| 3154 | // type (short header, 4 byte packet number) |
| 3155 | {"", |
| 3156 | {0x43}}, |
| 3157 | // connection_id |
| 3158 | {"", |
| 3159 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3160 | // packet number |
| 3161 | {"", |
| 3162 | {0x12, 0x34, 0x56, 0x78}}, |
| 3163 | // frame type (IETF_ACK frame) |
| 3164 | {"", |
| 3165 | {0x02}}, |
| 3166 | // largest acked |
| 3167 | {"Unable to read largest acked.", |
| 3168 | {kVarInt62EightBytes + 0x3f, 0xff, 0xff, 0xff, |
| 3169 | 0xff, 0xff, 0xff, 0xff}}, |
| 3170 | // Zero delta time. |
| 3171 | {"Unable to read ack delay time.", |
| 3172 | {kVarInt62OneByte + 0x00}}, |
| 3173 | // Ack block count No additional blocks |
| 3174 | {"Unable to read ack block count.", |
| 3175 | {kVarInt62OneByte + 0}}, |
| 3176 | // first ack block length. |
| 3177 | {"Unable to read first ack block length.", |
| 3178 | {kVarInt62EightBytes + 0x3f, 0xff, 0xff, 0xff, |
| 3179 | 0xff, 0xff, 0xff, 0xfe}}, |
| 3180 | }; |
| 3181 | // clang-format on |
| 3182 | |
| 3183 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3184 | AssemblePacketFromFragments(packet99)); |
| 3185 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3186 | EXPECT_EQ(1u, visitor_.ack_frames_.size()); |
| 3187 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3188 | EXPECT_EQ(1u, frame.packets.NumIntervals()); |
| 3189 | EXPECT_EQ(kLargestIetfLargestObserved, LargestAcked(frame)); |
| 3190 | EXPECT_EQ(kLargestIetfLargestObserved.ToUint64(), |
| 3191 | frame.packets.NumPacketsSlow()); |
| 3192 | } |
| 3193 | |
| 3194 | // This test looks for a malformed ack where |
| 3195 | // - There is a largest-acked value (that is, the frame is acking |
| 3196 | // something, |
| 3197 | // - But the length of the first ack block is 0 saying that no frames |
| 3198 | // are being acked with the largest-acked value or there are no |
| 3199 | // additional ack blocks. |
| 3200 | // |
| 3201 | TEST_P(QuicFramerTest, AckFrameFirstAckBlockLengthZero) { |
| 3202 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 3203 | // Not applicable to version 99 -- first ack block contains the |
| 3204 | // number of packets that preceed the largest_acked packet. |
| 3205 | // A value of 0 means no packets preceed --- that the block's |
| 3206 | // length is 1. Therefore the condition that this test checks can |
| 3207 | // not arise. |
| 3208 | return; |
| 3209 | } |
| 3210 | |
| 3211 | // clang-format off |
| 3212 | PacketFragments packet = { |
| 3213 | // public flags (8 byte connection_id) |
| 3214 | {"", |
| 3215 | { 0x2C }}, |
| 3216 | // connection_id |
| 3217 | {"", |
| 3218 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3219 | // packet number |
| 3220 | {"", |
| 3221 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3222 | |
| 3223 | // frame type (ack frame) |
| 3224 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3225 | {"", |
| 3226 | { 0x65 }}, |
| 3227 | // largest acked |
| 3228 | {"Unable to read largest acked.", |
| 3229 | { 0x12, 0x34 }}, |
| 3230 | // Zero delta time. |
| 3231 | {"Unable to read ack delay time.", |
| 3232 | { 0x00, 0x00 }}, |
| 3233 | // num ack blocks ranges. |
| 3234 | {"Unable to read num of ack blocks.", |
| 3235 | { 0x01 }}, |
| 3236 | // first ack block length. |
| 3237 | {"Unable to read first ack block length.", |
| 3238 | { 0x00, 0x00 }}, |
| 3239 | // gap to next block. |
| 3240 | { "First block length is zero.", |
| 3241 | { 0x01 }}, |
| 3242 | // ack block length. |
| 3243 | { "First block length is zero.", |
| 3244 | { 0x0e, 0xaf }}, |
| 3245 | // Number of timestamps. |
| 3246 | { "First block length is zero.", |
| 3247 | { 0x00 }}, |
| 3248 | }; |
| 3249 | |
| 3250 | PacketFragments packet44 = { |
| 3251 | // type (short header, 4 byte packet number) |
| 3252 | {"", |
| 3253 | { 0x32 }}, |
| 3254 | // connection_id |
| 3255 | {"", |
| 3256 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3257 | // packet number |
| 3258 | {"", |
| 3259 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3260 | |
| 3261 | // frame type (ack frame) |
| 3262 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3263 | {"", |
| 3264 | { 0x65 }}, |
| 3265 | // largest acked |
| 3266 | {"Unable to read largest acked.", |
| 3267 | { 0x12, 0x34 }}, |
| 3268 | // Zero delta time. |
| 3269 | {"Unable to read ack delay time.", |
| 3270 | { 0x00, 0x00 }}, |
| 3271 | // num ack blocks ranges. |
| 3272 | {"Unable to read num of ack blocks.", |
| 3273 | { 0x01 }}, |
| 3274 | // first ack block length. |
| 3275 | {"Unable to read first ack block length.", |
| 3276 | { 0x00, 0x00 }}, |
| 3277 | // gap to next block. |
| 3278 | { "First block length is zero.", |
| 3279 | { 0x01 }}, |
| 3280 | // ack block length. |
| 3281 | { "First block length is zero.", |
| 3282 | { 0x0e, 0xaf }}, |
| 3283 | // Number of timestamps. |
| 3284 | { "First block length is zero.", |
| 3285 | { 0x00 }}, |
| 3286 | }; |
| 3287 | |
| 3288 | PacketFragments packet46 = { |
| 3289 | // type (short header, 4 byte packet number) |
| 3290 | {"", |
| 3291 | { 0x43 }}, |
| 3292 | // connection_id |
| 3293 | {"", |
| 3294 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3295 | // packet number |
| 3296 | {"", |
| 3297 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3298 | |
| 3299 | // frame type (ack frame) |
| 3300 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3301 | {"", |
| 3302 | { 0x65 }}, |
| 3303 | // largest acked |
| 3304 | {"Unable to read largest acked.", |
| 3305 | { 0x12, 0x34 }}, |
| 3306 | // Zero delta time. |
| 3307 | {"Unable to read ack delay time.", |
| 3308 | { 0x00, 0x00 }}, |
| 3309 | // num ack blocks ranges. |
| 3310 | {"Unable to read num of ack blocks.", |
| 3311 | { 0x01 }}, |
| 3312 | // first ack block length. |
| 3313 | {"Unable to read first ack block length.", |
| 3314 | { 0x00, 0x00 }}, |
| 3315 | // gap to next block. |
| 3316 | { "First block length is zero.", |
| 3317 | { 0x01 }}, |
| 3318 | // ack block length. |
| 3319 | { "First block length is zero.", |
| 3320 | { 0x0e, 0xaf }}, |
| 3321 | // Number of timestamps. |
| 3322 | { "First block length is zero.", |
| 3323 | { 0x00 }}, |
| 3324 | }; |
| 3325 | |
| 3326 | // clang-format on |
| 3327 | PacketFragments& fragments = |
| 3328 | framer_.transport_version() > QUIC_VERSION_44 |
| 3329 | ? packet46 |
| 3330 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 3331 | |
| 3332 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3333 | AssemblePacketFromFragments(fragments)); |
| 3334 | |
| 3335 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 3336 | EXPECT_EQ(QUIC_INVALID_ACK_DATA, framer_.error()); |
| 3337 | |
| 3338 | ASSERT_TRUE(visitor_.header_.get()); |
| 3339 | EXPECT_TRUE(CheckDecryption( |
| 3340 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3341 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3342 | |
| 3343 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3344 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3345 | |
| 3346 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3347 | } |
| 3348 | |
| 3349 | TEST_P(QuicFramerTest, AckFrameOneAckBlockMaxLength) { |
| 3350 | // clang-format off |
| 3351 | PacketFragments packet = { |
| 3352 | // public flags (8 byte connection_id) |
| 3353 | {"", |
| 3354 | {0x2C}}, |
| 3355 | // connection_id |
| 3356 | {"", |
| 3357 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3358 | // packet number |
| 3359 | {"", |
| 3360 | {0x12, 0x34, 0x56, 0x78}}, |
| 3361 | // frame type (ack frame) |
| 3362 | // (one ack block, 4 byte largest observed, 2 byte block length) |
| 3363 | {"", |
| 3364 | {0x49}}, |
| 3365 | // largest acked |
| 3366 | {"Unable to read largest acked.", |
| 3367 | {0x12, 0x34, 0x56, 0x78}}, |
| 3368 | // Zero delta time. |
| 3369 | {"Unable to read ack delay time.", |
| 3370 | {0x00, 0x00}}, |
| 3371 | // first ack block length. |
| 3372 | {"Unable to read first ack block length.", |
| 3373 | {0x12, 0x34}}, |
| 3374 | // num timestamps. |
| 3375 | {"Unable to read num received packets.", |
| 3376 | {0x00}} |
| 3377 | }; |
| 3378 | |
| 3379 | PacketFragments packet44 = { |
| 3380 | // type (short header, 4 byte packet number) |
| 3381 | {"", |
| 3382 | {0x32}}, |
| 3383 | // connection_id |
| 3384 | {"", |
| 3385 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3386 | // packet number |
| 3387 | {"", |
| 3388 | {0x56, 0x78, 0x9A, 0xBC}}, |
| 3389 | // frame type (ack frame) |
| 3390 | // (one ack block, 4 byte largest observed, 2 byte block length) |
| 3391 | {"", |
| 3392 | {0x49}}, |
| 3393 | // largest acked |
| 3394 | {"Unable to read largest acked.", |
| 3395 | {0x12, 0x34, 0x56, 0x78}}, |
| 3396 | // Zero delta time. |
| 3397 | {"Unable to read ack delay time.", |
| 3398 | {0x00, 0x00}}, |
| 3399 | // first ack block length. |
| 3400 | {"Unable to read first ack block length.", |
| 3401 | {0x12, 0x34}}, |
| 3402 | // num timestamps. |
| 3403 | {"Unable to read num received packets.", |
| 3404 | {0x00}} |
| 3405 | }; |
| 3406 | |
| 3407 | PacketFragments packet46 = { |
| 3408 | // type (short header, 4 byte packet number) |
| 3409 | {"", |
| 3410 | {0x43}}, |
| 3411 | // connection_id |
| 3412 | {"", |
| 3413 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3414 | // packet number |
| 3415 | {"", |
| 3416 | {0x56, 0x78, 0x9A, 0xBC}}, |
| 3417 | // frame type (ack frame) |
| 3418 | // (one ack block, 4 byte largest observed, 2 byte block length) |
| 3419 | {"", |
| 3420 | {0x49}}, |
| 3421 | // largest acked |
| 3422 | {"Unable to read largest acked.", |
| 3423 | {0x12, 0x34, 0x56, 0x78}}, |
| 3424 | // Zero delta time. |
| 3425 | {"Unable to read ack delay time.", |
| 3426 | {0x00, 0x00}}, |
| 3427 | // first ack block length. |
| 3428 | {"Unable to read first ack block length.", |
| 3429 | {0x12, 0x34}}, |
| 3430 | // num timestamps. |
| 3431 | {"Unable to read num received packets.", |
| 3432 | {0x00}} |
| 3433 | }; |
| 3434 | |
| 3435 | PacketFragments packet99 = { |
| 3436 | // type (short header, 4 byte packet number) |
| 3437 | {"", |
| 3438 | {0x43}}, |
| 3439 | // connection_id |
| 3440 | {"", |
| 3441 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3442 | // packet number |
| 3443 | {"", |
| 3444 | {0x56, 0x78, 0x9A, 0xBC}}, |
| 3445 | // frame type (IETF_ACK frame) |
| 3446 | {"", |
| 3447 | {0x02}}, |
| 3448 | // largest acked |
| 3449 | {"Unable to read largest acked.", |
| 3450 | {kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78}}, |
| 3451 | // Zero delta time. |
| 3452 | {"Unable to read ack delay time.", |
| 3453 | {kVarInt62OneByte + 0x00}}, |
| 3454 | // Number of ack blocks after first |
| 3455 | {"Unable to read ack block count.", |
| 3456 | {kVarInt62OneByte + 0x00}}, |
| 3457 | // first ack block length. |
| 3458 | {"Unable to read first ack block length.", |
| 3459 | {kVarInt62TwoBytes + 0x12, 0x33}} |
| 3460 | }; |
| 3461 | // clang-format on |
| 3462 | |
| 3463 | PacketFragments& fragments = |
| 3464 | framer_.transport_version() == QUIC_VERSION_99 |
| 3465 | ? packet99 |
| 3466 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 3467 | ? packet46 |
| 3468 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 3469 | : packet)); |
| 3470 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3471 | AssemblePacketFromFragments(fragments)); |
| 3472 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3473 | |
| 3474 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 3475 | ASSERT_TRUE(visitor_.header_.get()); |
| 3476 | EXPECT_TRUE(CheckDecryption( |
| 3477 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3478 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3479 | |
| 3480 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3481 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3482 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3483 | EXPECT_EQ(kPacketNumber, LargestAcked(frame)); |
| 3484 | ASSERT_EQ(4660u, frame.packets.NumPacketsSlow()); |
| 3485 | |
| 3486 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3487 | } |
| 3488 | |
| 3489 | // Tests ability to handle multiple ackblocks after the first ack |
| 3490 | // block. Non-version-99 tests include multiple timestamps as well. |
| 3491 | TEST_P(QuicFramerTest, AckFrameTwoTimeStampsMultipleAckBlocks) { |
| 3492 | // clang-format off |
| 3493 | PacketFragments packet = { |
| 3494 | // public flags (8 byte connection_id) |
| 3495 | {"", |
| 3496 | { 0x2C }}, |
| 3497 | // connection_id |
| 3498 | {"", |
| 3499 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3500 | // packet number |
| 3501 | {"", |
| 3502 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3503 | |
| 3504 | // frame type (ack frame) |
| 3505 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3506 | {"", |
| 3507 | { 0x65 }}, |
| 3508 | // largest acked |
| 3509 | {"Unable to read largest acked.", |
| 3510 | { 0x12, 0x34 }}, |
| 3511 | // Zero delta time. |
| 3512 | {"Unable to read ack delay time.", |
| 3513 | { 0x00, 0x00 }}, |
| 3514 | // num ack blocks ranges. |
| 3515 | {"Unable to read num of ack blocks.", |
| 3516 | { 0x04 }}, |
| 3517 | // first ack block length. |
| 3518 | {"Unable to read first ack block length.", |
| 3519 | { 0x00, 0x01 }}, |
| 3520 | // gap to next block. |
| 3521 | { "Unable to read gap to next ack block.", |
| 3522 | { 0x01 }}, |
| 3523 | // ack block length. |
| 3524 | { "Unable to ack block length.", |
| 3525 | { 0x0e, 0xaf }}, |
| 3526 | // gap to next block. |
| 3527 | { "Unable to read gap to next ack block.", |
| 3528 | { 0xff }}, |
| 3529 | // ack block length. |
| 3530 | { "Unable to ack block length.", |
| 3531 | { 0x00, 0x00 }}, |
| 3532 | // gap to next block. |
| 3533 | { "Unable to read gap to next ack block.", |
| 3534 | { 0x91 }}, |
| 3535 | // ack block length. |
| 3536 | { "Unable to ack block length.", |
| 3537 | { 0x01, 0xea }}, |
| 3538 | // gap to next block. |
| 3539 | { "Unable to read gap to next ack block.", |
| 3540 | { 0x05 }}, |
| 3541 | // ack block length. |
| 3542 | { "Unable to ack block length.", |
| 3543 | { 0x00, 0x04 }}, |
| 3544 | // Number of timestamps. |
| 3545 | { "Unable to read num received packets.", |
| 3546 | { 0x02 }}, |
| 3547 | // Delta from largest observed. |
| 3548 | { "Unable to read sequence delta in received packets.", |
| 3549 | { 0x01 }}, |
| 3550 | // Delta time. |
| 3551 | { "Unable to read time delta in received packets.", |
| 3552 | { 0x76, 0x54, 0x32, 0x10 }}, |
| 3553 | // Delta from largest observed. |
| 3554 | { "Unable to read sequence delta in received packets.", |
| 3555 | { 0x02 }}, |
| 3556 | // Delta time. |
| 3557 | { "Unable to read incremental time delta in received packets.", |
| 3558 | { 0x32, 0x10 }}, |
| 3559 | }; |
| 3560 | |
| 3561 | PacketFragments packet44 = { |
| 3562 | // type (short header, 4 byte packet number) |
| 3563 | {"", |
| 3564 | { 0x32 }}, |
| 3565 | // connection_id |
| 3566 | {"", |
| 3567 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3568 | // packet number |
| 3569 | {"", |
| 3570 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3571 | |
| 3572 | // frame type (ack frame) |
| 3573 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3574 | {"", |
| 3575 | { 0x65 }}, |
| 3576 | // largest acked |
| 3577 | {"Unable to read largest acked.", |
| 3578 | { 0x12, 0x34 }}, |
| 3579 | // Zero delta time. |
| 3580 | {"Unable to read ack delay time.", |
| 3581 | { 0x00, 0x00 }}, |
| 3582 | // num ack blocks ranges. |
| 3583 | {"Unable to read num of ack blocks.", |
| 3584 | { 0x04 }}, |
| 3585 | // first ack block length. |
| 3586 | {"Unable to read first ack block length.", |
| 3587 | { 0x00, 0x01 }}, |
| 3588 | // gap to next block. |
| 3589 | { "Unable to read gap to next ack block.", |
| 3590 | { 0x01 }}, |
| 3591 | // ack block length. |
| 3592 | { "Unable to ack block length.", |
| 3593 | { 0x0e, 0xaf }}, |
| 3594 | // gap to next block. |
| 3595 | { "Unable to read gap to next ack block.", |
| 3596 | { 0xff }}, |
| 3597 | // ack block length. |
| 3598 | { "Unable to ack block length.", |
| 3599 | { 0x00, 0x00 }}, |
| 3600 | // gap to next block. |
| 3601 | { "Unable to read gap to next ack block.", |
| 3602 | { 0x91 }}, |
| 3603 | // ack block length. |
| 3604 | { "Unable to ack block length.", |
| 3605 | { 0x01, 0xea }}, |
| 3606 | // gap to next block. |
| 3607 | { "Unable to read gap to next ack block.", |
| 3608 | { 0x05 }}, |
| 3609 | // ack block length. |
| 3610 | { "Unable to ack block length.", |
| 3611 | { 0x00, 0x04 }}, |
| 3612 | // Number of timestamps. |
| 3613 | { "Unable to read num received packets.", |
| 3614 | { 0x02 }}, |
| 3615 | // Delta from largest observed. |
| 3616 | { "Unable to read sequence delta in received packets.", |
| 3617 | { 0x01 }}, |
| 3618 | // Delta time. |
| 3619 | { "Unable to read time delta in received packets.", |
| 3620 | { 0x76, 0x54, 0x32, 0x10 }}, |
| 3621 | // Delta from largest observed. |
| 3622 | { "Unable to read sequence delta in received packets.", |
| 3623 | { 0x02 }}, |
| 3624 | // Delta time. |
| 3625 | { "Unable to read incremental time delta in received packets.", |
| 3626 | { 0x32, 0x10 }}, |
| 3627 | }; |
| 3628 | |
| 3629 | PacketFragments packet46 = { |
| 3630 | // type (short header, 4 byte packet number) |
| 3631 | {"", |
| 3632 | { 0x43 }}, |
| 3633 | // connection_id |
| 3634 | {"", |
| 3635 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3636 | // packet number |
| 3637 | {"", |
| 3638 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3639 | |
| 3640 | // frame type (ack frame) |
| 3641 | // (more than one ack block, 2 byte largest observed, 2 byte block length) |
| 3642 | {"", |
| 3643 | { 0x65 }}, |
| 3644 | // largest acked |
| 3645 | {"Unable to read largest acked.", |
| 3646 | { 0x12, 0x34 }}, |
| 3647 | // Zero delta time. |
| 3648 | {"Unable to read ack delay time.", |
| 3649 | { 0x00, 0x00 }}, |
| 3650 | // num ack blocks ranges. |
| 3651 | {"Unable to read num of ack blocks.", |
| 3652 | { 0x04 }}, |
| 3653 | // first ack block length. |
| 3654 | {"Unable to read first ack block length.", |
| 3655 | { 0x00, 0x01 }}, |
| 3656 | // gap to next block. |
| 3657 | { "Unable to read gap to next ack block.", |
| 3658 | { 0x01 }}, |
| 3659 | // ack block length. |
| 3660 | { "Unable to ack block length.", |
| 3661 | { 0x0e, 0xaf }}, |
| 3662 | // gap to next block. |
| 3663 | { "Unable to read gap to next ack block.", |
| 3664 | { 0xff }}, |
| 3665 | // ack block length. |
| 3666 | { "Unable to ack block length.", |
| 3667 | { 0x00, 0x00 }}, |
| 3668 | // gap to next block. |
| 3669 | { "Unable to read gap to next ack block.", |
| 3670 | { 0x91 }}, |
| 3671 | // ack block length. |
| 3672 | { "Unable to ack block length.", |
| 3673 | { 0x01, 0xea }}, |
| 3674 | // gap to next block. |
| 3675 | { "Unable to read gap to next ack block.", |
| 3676 | { 0x05 }}, |
| 3677 | // ack block length. |
| 3678 | { "Unable to ack block length.", |
| 3679 | { 0x00, 0x04 }}, |
| 3680 | // Number of timestamps. |
| 3681 | { "Unable to read num received packets.", |
| 3682 | { 0x02 }}, |
| 3683 | // Delta from largest observed. |
| 3684 | { "Unable to read sequence delta in received packets.", |
| 3685 | { 0x01 }}, |
| 3686 | // Delta time. |
| 3687 | { "Unable to read time delta in received packets.", |
| 3688 | { 0x76, 0x54, 0x32, 0x10 }}, |
| 3689 | // Delta from largest observed. |
| 3690 | { "Unable to read sequence delta in received packets.", |
| 3691 | { 0x02 }}, |
| 3692 | // Delta time. |
| 3693 | { "Unable to read incremental time delta in received packets.", |
| 3694 | { 0x32, 0x10 }}, |
| 3695 | }; |
| 3696 | |
| 3697 | PacketFragments packet99 = { |
| 3698 | // type (short header, 4 byte packet number) |
| 3699 | {"", |
| 3700 | { 0x43 }}, |
| 3701 | // connection_id |
| 3702 | {"", |
| 3703 | { 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10 }}, |
| 3704 | // packet number |
| 3705 | {"", |
| 3706 | { 0x12, 0x34, 0x56, 0x78 }}, |
| 3707 | |
| 3708 | // frame type (IETF_ACK frame) |
| 3709 | {"", |
| 3710 | { 0x02 }}, |
| 3711 | // largest acked |
| 3712 | {"Unable to read largest acked.", |
| 3713 | { kVarInt62TwoBytes + 0x12, 0x34 }}, // = 4660 |
| 3714 | // Zero delta time. |
| 3715 | {"Unable to read ack delay time.", |
| 3716 | { kVarInt62OneByte + 0x00 }}, |
| 3717 | // number of additional ack blocks |
| 3718 | {"Unable to read ack block count.", |
| 3719 | { kVarInt62OneByte + 0x03 }}, |
| 3720 | // first ack block length. |
| 3721 | {"Unable to read first ack block length.", |
| 3722 | { kVarInt62OneByte + 0x00 }}, // 1st block length = 1 |
| 3723 | |
| 3724 | // Additional ACK Block #1 |
| 3725 | // gap to next block. |
| 3726 | { "Unable to read gap block value.", |
| 3727 | { kVarInt62OneByte + 0x00 }}, // gap of 1 packet |
| 3728 | // ack block length. |
| 3729 | { "Unable to read ack block value.", |
| 3730 | { kVarInt62TwoBytes + 0x0e, 0xae }}, // 3759 |
| 3731 | |
| 3732 | // pre-version-99 test includes an ack block of 0 length. this |
| 3733 | // can not happen in version 99. ergo the second block is not |
| 3734 | // present in the v99 test and the gap length of the next block |
| 3735 | // is the sum of the two gaps in the pre-version-99 tests. |
| 3736 | // Additional ACK Block #2 |
| 3737 | // gap to next block. |
| 3738 | { "Unable to read gap block value.", |
| 3739 | { kVarInt62TwoBytes + 0x01, 0x8f }}, // Gap is 400 (0x190) pkts |
| 3740 | // ack block length. |
| 3741 | { "Unable to read ack block value.", |
| 3742 | { kVarInt62TwoBytes + 0x01, 0xe9 }}, // block is 389 (x1ea) pkts |
| 3743 | |
| 3744 | // Additional ACK Block #3 |
| 3745 | // gap to next block. |
| 3746 | { "Unable to read gap block value.", |
| 3747 | { kVarInt62OneByte + 0x04 }}, // Gap is 5 packets. |
| 3748 | // ack block length. |
| 3749 | { "Unable to read ack block value.", |
| 3750 | { kVarInt62OneByte + 0x03 }}, // block is 3 packets. |
| 3751 | }; |
| 3752 | |
| 3753 | // clang-format on |
| 3754 | PacketFragments& fragments = |
| 3755 | framer_.transport_version() == QUIC_VERSION_99 |
| 3756 | ? packet99 |
| 3757 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 3758 | ? packet46 |
| 3759 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 3760 | : packet)); |
| 3761 | |
| 3762 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 3763 | AssemblePacketFromFragments(fragments)); |
| 3764 | |
| 3765 | framer_.set_process_timestamps(true); |
| 3766 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 3767 | |
| 3768 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 3769 | ASSERT_TRUE(visitor_.header_.get()); |
| 3770 | EXPECT_TRUE(CheckDecryption( |
| 3771 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 3772 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 3773 | |
| 3774 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 3775 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 3776 | const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
| 3777 | EXPECT_EQ(kSmallLargestObserved, LargestAcked(frame)); |
| 3778 | ASSERT_EQ(4254u, frame.packets.NumPacketsSlow()); |
| 3779 | EXPECT_EQ(4u, frame.packets.NumIntervals()); |
| 3780 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 3781 | EXPECT_EQ(0u, frame.received_packet_times.size()); |
| 3782 | } else { |
| 3783 | EXPECT_EQ(2u, frame.received_packet_times.size()); |
| 3784 | } |
| 3785 | CheckFramingBoundaries(fragments, QUIC_INVALID_ACK_DATA); |
| 3786 | } |
| 3787 | |
| 3788 | TEST_P(QuicFramerTest, AckFrameTimeStampDeltaTooHigh) { |
| 3789 | // clang-format off |
| 3790 | unsigned char packet[] = { |
| 3791 | // public flags (8 byte connection_id) |
| 3792 | 0x28, |
| 3793 | // connection_id |
| 3794 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3795 | // packet number |
| 3796 | 0x12, 0x34, 0x56, 0x78, |
| 3797 | |
| 3798 | // frame type (ack frame) |
| 3799 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 3800 | 0x40, |
| 3801 | // largest acked |
| 3802 | 0x01, |
| 3803 | // Zero delta time. |
| 3804 | 0x00, 0x00, |
| 3805 | // first ack block length. |
| 3806 | 0x01, |
| 3807 | // num timestamps. |
| 3808 | 0x01, |
| 3809 | // Delta from largest observed. |
| 3810 | 0x01, |
| 3811 | // Delta time. |
| 3812 | 0x10, 0x32, 0x54, 0x76, |
| 3813 | }; |
| 3814 | |
| 3815 | unsigned char packet44[] = { |
| 3816 | // type (short header, 4 byte packet number) |
| 3817 | 0x32, |
| 3818 | // connection_id |
| 3819 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3820 | // packet number |
| 3821 | 0x12, 0x34, 0x56, 0x78, |
| 3822 | |
| 3823 | // frame type (ack frame) |
| 3824 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 3825 | 0x40, |
| 3826 | // largest acked |
| 3827 | 0x01, |
| 3828 | // Zero delta time. |
| 3829 | 0x00, 0x00, |
| 3830 | // first ack block length. |
| 3831 | 0x01, |
| 3832 | // num timestamps. |
| 3833 | 0x01, |
| 3834 | // Delta from largest observed. |
| 3835 | 0x01, |
| 3836 | // Delta time. |
| 3837 | 0x10, 0x32, 0x54, 0x76, |
| 3838 | }; |
| 3839 | |
| 3840 | unsigned char packet46[] = { |
| 3841 | // type (short header, 4 byte packet number) |
| 3842 | 0x43, |
| 3843 | // connection_id |
| 3844 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3845 | // packet number |
| 3846 | 0x12, 0x34, 0x56, 0x78, |
| 3847 | |
| 3848 | // frame type (ack frame) |
| 3849 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 3850 | 0x40, |
| 3851 | // largest acked |
| 3852 | 0x01, |
| 3853 | // Zero delta time. |
| 3854 | 0x00, 0x00, |
| 3855 | // first ack block length. |
| 3856 | 0x01, |
| 3857 | // num timestamps. |
| 3858 | 0x01, |
| 3859 | // Delta from largest observed. |
| 3860 | 0x01, |
| 3861 | // Delta time. |
| 3862 | 0x10, 0x32, 0x54, 0x76, |
| 3863 | }; |
| 3864 | // clang-format on |
| 3865 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 3866 | return; |
| 3867 | } |
| 3868 | QuicEncryptedPacket encrypted( |
| 3869 | AsChars(framer_.transport_version() > QUIC_VERSION_44 |
| 3870 | ? packet46 |
| 3871 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 3872 | : packet)), |
| 3873 | QUIC_ARRAYSIZE(packet), false); |
| 3874 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 3875 | EXPECT_TRUE(QuicTextUtils::StartsWith( |
| 3876 | framer_.detailed_error(), "delta_from_largest_observed too high")); |
| 3877 | } |
| 3878 | |
| 3879 | TEST_P(QuicFramerTest, AckFrameTimeStampSecondDeltaTooHigh) { |
| 3880 | // clang-format off |
| 3881 | unsigned char packet[] = { |
| 3882 | // public flags (8 byte connection_id) |
| 3883 | 0x28, |
| 3884 | // connection_id |
| 3885 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3886 | // packet number |
| 3887 | 0x12, 0x34, 0x56, 0x78, |
| 3888 | |
| 3889 | // frame type (ack frame) |
| 3890 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 3891 | 0x40, |
| 3892 | // largest acked |
| 3893 | 0x03, |
| 3894 | // Zero delta time. |
| 3895 | 0x00, 0x00, |
| 3896 | // first ack block length. |
| 3897 | 0x03, |
| 3898 | // num timestamps. |
| 3899 | 0x02, |
| 3900 | // Delta from largest observed. |
| 3901 | 0x01, |
| 3902 | // Delta time. |
| 3903 | 0x10, 0x32, 0x54, 0x76, |
| 3904 | // Delta from largest observed. |
| 3905 | 0x03, |
| 3906 | // Delta time. |
| 3907 | 0x10, 0x32, |
| 3908 | }; |
| 3909 | |
| 3910 | unsigned char packet44[] = { |
| 3911 | // type (short header, 4 byte packet number) |
| 3912 | 0x32, |
| 3913 | // connection_id |
| 3914 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3915 | // packet number |
| 3916 | 0x12, 0x34, 0x56, 0x78, |
| 3917 | |
| 3918 | // frame type (ack frame) |
| 3919 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 3920 | 0x40, |
| 3921 | // largest acked |
| 3922 | 0x03, |
| 3923 | // Zero delta time. |
| 3924 | 0x00, 0x00, |
| 3925 | // first ack block length. |
| 3926 | 0x03, |
| 3927 | // num timestamps. |
| 3928 | 0x02, |
| 3929 | // Delta from largest observed. |
| 3930 | 0x01, |
| 3931 | // Delta time. |
| 3932 | 0x10, 0x32, 0x54, 0x76, |
| 3933 | // Delta from largest observed. |
| 3934 | 0x03, |
| 3935 | // Delta time. |
| 3936 | 0x10, 0x32, |
| 3937 | }; |
| 3938 | |
| 3939 | unsigned char packet46[] = { |
| 3940 | // type (short header, 4 byte packet number) |
| 3941 | 0x43, |
| 3942 | // connection_id |
| 3943 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 3944 | // packet number |
| 3945 | 0x12, 0x34, 0x56, 0x78, |
| 3946 | |
| 3947 | // frame type (ack frame) |
| 3948 | // (no ack blocks, 1 byte largest observed, 1 byte block length) |
| 3949 | 0x40, |
| 3950 | // largest acked |
| 3951 | 0x03, |
| 3952 | // Zero delta time. |
| 3953 | 0x00, 0x00, |
| 3954 | // first ack block length. |
| 3955 | 0x03, |
| 3956 | // num timestamps. |
| 3957 | 0x02, |
| 3958 | // Delta from largest observed. |
| 3959 | 0x01, |
| 3960 | // Delta time. |
| 3961 | 0x10, 0x32, 0x54, 0x76, |
| 3962 | // Delta from largest observed. |
| 3963 | 0x03, |
| 3964 | // Delta time. |
| 3965 | 0x10, 0x32, |
| 3966 | }; |
| 3967 | // clang-format on |
| 3968 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 3969 | return; |
| 3970 | } |
| 3971 | QuicEncryptedPacket encrypted( |
| 3972 | AsChars(framer_.transport_version() > QUIC_VERSION_44 |
| 3973 | ? packet46 |
| 3974 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 3975 | : packet)), |
| 3976 | QUIC_ARRAYSIZE(packet), false); |
| 3977 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 3978 | EXPECT_TRUE(QuicTextUtils::StartsWith( |
| 3979 | framer_.detailed_error(), "delta_from_largest_observed too high")); |
| 3980 | } |
| 3981 | |
| 3982 | TEST_P(QuicFramerTest, NewStopWaitingFrame) { |
| 3983 | if (version_.transport_version == QUIC_VERSION_99) { |
| 3984 | return; |
| 3985 | } |
| 3986 | // clang-format off |
| 3987 | PacketFragments packet = { |
| 3988 | // public flags (8 byte connection_id) |
| 3989 | {"", |
| 3990 | {0x2C}}, |
| 3991 | // connection_id |
| 3992 | {"", |
| 3993 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 3994 | // packet number |
| 3995 | {"", |
| 3996 | {0x12, 0x34, 0x56, 0x78}}, |
| 3997 | // frame type (stop waiting frame) |
| 3998 | {"", |
| 3999 | {0x06}}, |
| 4000 | // least packet number awaiting an ack, delta from packet number. |
| 4001 | {"Unable to read least unacked delta.", |
| 4002 | {0x00, 0x00, 0x00, 0x08}} |
| 4003 | }; |
| 4004 | |
| 4005 | PacketFragments packet44 = { |
| 4006 | // type (short header, 4 byte packet number) |
| 4007 | {"", |
| 4008 | {0x32}}, |
| 4009 | // connection_id |
| 4010 | {"", |
| 4011 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4012 | // packet number |
| 4013 | {"", |
| 4014 | {0x12, 0x34, 0x56, 0x78}}, |
| 4015 | // frame type (stop waiting frame) |
| 4016 | {"", |
| 4017 | {0x06}}, |
| 4018 | // least packet number awaiting an ack, delta from packet number. |
| 4019 | {"Unable to read least unacked delta.", |
| 4020 | {0x00, 0x00, 0x00, 0x08}} |
| 4021 | }; |
| 4022 | |
| 4023 | PacketFragments packet46 = { |
| 4024 | // type (short header, 4 byte packet number) |
| 4025 | {"", |
| 4026 | {0x43}}, |
| 4027 | // connection_id |
| 4028 | {"", |
| 4029 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4030 | // packet number |
| 4031 | {"", |
| 4032 | {0x12, 0x34, 0x56, 0x78}}, |
| 4033 | // frame type (stop waiting frame) |
| 4034 | {"", |
| 4035 | {0x06}}, |
| 4036 | // least packet number awaiting an ack, delta from packet number. |
| 4037 | {"Unable to read least unacked delta.", |
| 4038 | {0x00, 0x00, 0x00, 0x08}} |
| 4039 | }; |
| 4040 | // clang-format on |
| 4041 | |
| 4042 | PacketFragments& fragments = |
| 4043 | framer_.transport_version() > QUIC_VERSION_44 |
| 4044 | ? packet46 |
| 4045 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 4046 | |
| 4047 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4048 | AssemblePacketFromFragments(fragments)); |
| 4049 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4050 | |
| 4051 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4052 | ASSERT_TRUE(visitor_.header_.get()); |
| 4053 | EXPECT_TRUE(CheckDecryption( |
| 4054 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4055 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4056 | |
| 4057 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 4058 | ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size()); |
| 4059 | const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0]; |
| 4060 | EXPECT_EQ(kLeastUnacked, frame.least_unacked); |
| 4061 | |
| 4062 | CheckFramingBoundaries(fragments, QUIC_INVALID_STOP_WAITING_DATA); |
| 4063 | } |
| 4064 | |
| 4065 | TEST_P(QuicFramerTest, InvalidNewStopWaitingFrame) { |
| 4066 | if (version_.transport_version == QUIC_VERSION_99) { |
| 4067 | return; |
| 4068 | } |
| 4069 | // clang-format off |
| 4070 | unsigned char packet[] = { |
| 4071 | // public flags (8 byte connection_id) |
| 4072 | 0x2C, |
| 4073 | // connection_id |
| 4074 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4075 | // packet number |
| 4076 | 0x12, 0x34, 0x56, 0x78, |
| 4077 | // frame type (stop waiting frame) |
| 4078 | 0x06, |
| 4079 | // least packet number awaiting an ack, delta from packet number. |
| 4080 | 0x13, 0x34, 0x56, 0x78, |
| 4081 | 0x9A, 0xA8, |
| 4082 | }; |
| 4083 | |
| 4084 | unsigned char packet44[] = { |
| 4085 | // type (short header, 4 byte packet number) |
| 4086 | 0x32, |
| 4087 | // connection_id |
| 4088 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4089 | // packet number |
| 4090 | 0x12, 0x34, 0x56, 0x78, |
| 4091 | // frame type (stop waiting frame) |
| 4092 | 0x06, |
| 4093 | // least packet number awaiting an ack, delta from packet number. |
| 4094 | 0x57, 0x78, 0x9A, 0xA8, |
| 4095 | }; |
| 4096 | |
| 4097 | unsigned char packet46[] = { |
| 4098 | // type (short header, 4 byte packet number) |
| 4099 | 0x43, |
| 4100 | // connection_id |
| 4101 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4102 | // packet number |
| 4103 | 0x12, 0x34, 0x56, 0x78, |
| 4104 | // frame type (stop waiting frame) |
| 4105 | 0x06, |
| 4106 | // least packet number awaiting an ack, delta from packet number. |
| 4107 | 0x57, 0x78, 0x9A, 0xA8, |
| 4108 | }; |
| 4109 | // clang-format on |
| 4110 | |
| 4111 | QuicEncryptedPacket encrypted( |
| 4112 | AsChars(framer_.transport_version() > QUIC_VERSION_44 |
| 4113 | ? packet46 |
| 4114 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 4115 | : packet)), |
| 4116 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 4117 | : QUIC_ARRAYSIZE(packet), |
| 4118 | false); |
| 4119 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 4120 | EXPECT_EQ(QUIC_INVALID_STOP_WAITING_DATA, framer_.error()); |
| 4121 | EXPECT_EQ("Invalid unacked delta.", framer_.detailed_error()); |
| 4122 | } |
| 4123 | |
| 4124 | TEST_P(QuicFramerTest, RstStreamFrame) { |
| 4125 | // clang-format off |
| 4126 | PacketFragments packet = { |
| 4127 | // public flags (8 byte connection_id) |
| 4128 | {"", |
| 4129 | {0x28}}, |
| 4130 | // connection_id |
| 4131 | {"", |
| 4132 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4133 | // packet number |
| 4134 | {"", |
| 4135 | {0x12, 0x34, 0x56, 0x78}}, |
| 4136 | // frame type (rst stream frame) |
| 4137 | {"", |
| 4138 | {0x01}}, |
| 4139 | // stream id |
| 4140 | {"Unable to read stream_id.", |
| 4141 | {0x01, 0x02, 0x03, 0x04}}, |
| 4142 | // sent byte offset |
| 4143 | {"Unable to read rst stream sent byte offset.", |
| 4144 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4145 | 0x32, 0x10, 0x76, 0x54}}, |
| 4146 | // error code |
| 4147 | {"Unable to read rst stream error code.", |
| 4148 | {0x00, 0x00, 0x00, 0x01}} |
| 4149 | }; |
| 4150 | |
| 4151 | PacketFragments packet44 = { |
| 4152 | // type (short header, 4 byte packet number) |
| 4153 | {"", |
| 4154 | {0x32}}, |
| 4155 | // connection_id |
| 4156 | {"", |
| 4157 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4158 | // packet number |
| 4159 | {"", |
| 4160 | {0x12, 0x34, 0x56, 0x78}}, |
| 4161 | // frame type (rst stream frame) |
| 4162 | {"", |
| 4163 | {0x01}}, |
| 4164 | // stream id |
| 4165 | {"Unable to read stream_id.", |
| 4166 | {0x01, 0x02, 0x03, 0x04}}, |
| 4167 | // sent byte offset |
| 4168 | {"Unable to read rst stream sent byte offset.", |
| 4169 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4170 | 0x32, 0x10, 0x76, 0x54}}, |
| 4171 | // error code |
| 4172 | {"Unable to read rst stream error code.", |
| 4173 | {0x00, 0x00, 0x00, 0x01}} |
| 4174 | }; |
| 4175 | |
| 4176 | PacketFragments packet46 = { |
| 4177 | // type (short header, 4 byte packet number) |
| 4178 | {"", |
| 4179 | {0x43}}, |
| 4180 | // connection_id |
| 4181 | {"", |
| 4182 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4183 | // packet number |
| 4184 | {"", |
| 4185 | {0x12, 0x34, 0x56, 0x78}}, |
| 4186 | // frame type (rst stream frame) |
| 4187 | {"", |
| 4188 | {0x01}}, |
| 4189 | // stream id |
| 4190 | {"Unable to read stream_id.", |
| 4191 | {0x01, 0x02, 0x03, 0x04}}, |
| 4192 | // sent byte offset |
| 4193 | {"Unable to read rst stream sent byte offset.", |
| 4194 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4195 | 0x32, 0x10, 0x76, 0x54}}, |
| 4196 | // error code |
| 4197 | {"Unable to read rst stream error code.", |
| 4198 | {0x00, 0x00, 0x00, 0x01}} |
| 4199 | }; |
| 4200 | |
| 4201 | PacketFragments packet99 = { |
| 4202 | // type (short header, 4 byte packet number) |
| 4203 | {"", |
| 4204 | {0x43}}, |
| 4205 | // connection_id |
| 4206 | {"", |
| 4207 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4208 | // packet number |
| 4209 | {"", |
| 4210 | {0x12, 0x34, 0x56, 0x78}}, |
| 4211 | // frame type (IETF_RST_STREAM frame) |
| 4212 | {"", |
| 4213 | {0x04}}, |
| 4214 | // stream id |
| 4215 | {"Unable to read rst stream stream id.", |
| 4216 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 4217 | // application error code |
| 4218 | {"Unable to read rst stream error code.", |
| 4219 | {0x00, 0x01}}, // Not varint62 encoded |
| 4220 | // Final Offset |
| 4221 | {"Unable to read rst stream sent byte offset.", |
| 4222 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}} |
| 4223 | }; |
| 4224 | // clang-format on |
| 4225 | |
| 4226 | PacketFragments& fragments = |
| 4227 | framer_.transport_version() == QUIC_VERSION_99 |
| 4228 | ? packet99 |
| 4229 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 4230 | ? packet46 |
| 4231 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 4232 | : packet)); |
| 4233 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4234 | AssemblePacketFromFragments(fragments)); |
| 4235 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4236 | |
| 4237 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4238 | ASSERT_TRUE(visitor_.header_.get()); |
| 4239 | EXPECT_TRUE(CheckDecryption( |
| 4240 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4241 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4242 | |
| 4243 | EXPECT_EQ(kStreamId, visitor_.rst_stream_frame_.stream_id); |
| 4244 | EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code); |
| 4245 | EXPECT_EQ(kStreamOffset, visitor_.rst_stream_frame_.byte_offset); |
| 4246 | CheckFramingBoundaries(fragments, QUIC_INVALID_RST_STREAM_DATA); |
| 4247 | } |
| 4248 | |
| 4249 | TEST_P(QuicFramerTest, ConnectionCloseFrame) { |
| 4250 | // clang-format off |
| 4251 | PacketFragments packet = { |
| 4252 | // public flags (8 byte connection_id) |
| 4253 | {"", |
| 4254 | {0x28}}, |
| 4255 | // connection_id |
| 4256 | {"", |
| 4257 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4258 | // packet number |
| 4259 | {"", |
| 4260 | {0x12, 0x34, 0x56, 0x78}}, |
| 4261 | // frame type (connection close frame) |
| 4262 | {"", |
| 4263 | {0x02}}, |
| 4264 | // error code |
| 4265 | {"Unable to read connection close error code.", |
| 4266 | {0x00, 0x00, 0x00, 0x11}}, |
| 4267 | {"Unable to read connection close error details.", |
| 4268 | { |
| 4269 | // error details length |
| 4270 | 0x0, 0x0d, |
| 4271 | // error details |
| 4272 | 'b', 'e', 'c', 'a', |
| 4273 | 'u', 's', 'e', ' ', |
| 4274 | 'I', ' ', 'c', 'a', |
| 4275 | 'n'} |
| 4276 | } |
| 4277 | }; |
| 4278 | |
| 4279 | PacketFragments packet44 = { |
| 4280 | // type (short header, 4 byte packet number) |
| 4281 | {"", |
| 4282 | {0x32}}, |
| 4283 | // connection_id |
| 4284 | {"", |
| 4285 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4286 | // packet number |
| 4287 | {"", |
| 4288 | {0x12, 0x34, 0x56, 0x78}}, |
| 4289 | // frame type (connection close frame) |
| 4290 | {"", |
| 4291 | {0x02}}, |
| 4292 | // error code |
| 4293 | {"Unable to read connection close error code.", |
| 4294 | {0x00, 0x00, 0x00, 0x11}}, |
| 4295 | {"Unable to read connection close error details.", |
| 4296 | { |
| 4297 | // error details length |
| 4298 | 0x0, 0x0d, |
| 4299 | // error details |
| 4300 | 'b', 'e', 'c', 'a', |
| 4301 | 'u', 's', 'e', ' ', |
| 4302 | 'I', ' ', 'c', 'a', |
| 4303 | 'n'} |
| 4304 | } |
| 4305 | }; |
| 4306 | |
| 4307 | PacketFragments packet46 = { |
| 4308 | // type (short header, 4 byte packet number) |
| 4309 | {"", |
| 4310 | {0x43}}, |
| 4311 | // connection_id |
| 4312 | {"", |
| 4313 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4314 | // packet number |
| 4315 | {"", |
| 4316 | {0x12, 0x34, 0x56, 0x78}}, |
| 4317 | // frame type (connection close frame) |
| 4318 | {"", |
| 4319 | {0x02}}, |
| 4320 | // error code |
| 4321 | {"Unable to read connection close error code.", |
| 4322 | {0x00, 0x00, 0x00, 0x11}}, |
| 4323 | {"Unable to read connection close error details.", |
| 4324 | { |
| 4325 | // error details length |
| 4326 | 0x0, 0x0d, |
| 4327 | // error details |
| 4328 | 'b', 'e', 'c', 'a', |
| 4329 | 'u', 's', 'e', ' ', |
| 4330 | 'I', ' ', 'c', 'a', |
| 4331 | 'n'} |
| 4332 | } |
| 4333 | }; |
| 4334 | |
| 4335 | PacketFragments packet99 = { |
| 4336 | // type (short header, 4 byte packet number) |
| 4337 | {"", |
| 4338 | {0x43}}, |
| 4339 | // connection_id |
| 4340 | {"", |
| 4341 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4342 | // packet number |
| 4343 | {"", |
| 4344 | {0x12, 0x34, 0x56, 0x78}}, |
| 4345 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 4346 | {"", |
| 4347 | {0x1c}}, |
| 4348 | // error code |
| 4349 | {"Unable to read connection close error code.", |
| 4350 | {0x00, 0x11}}, |
| 4351 | {"Unable to read connection close frame type.", |
| 4352 | {kVarInt62TwoBytes + 0x12, 0x34 }}, |
| 4353 | {"Unable to read connection close error details.", |
| 4354 | { |
| 4355 | // error details length |
| 4356 | kVarInt62OneByte + 0x0d, |
| 4357 | // error details |
| 4358 | 'b', 'e', 'c', 'a', |
| 4359 | 'u', 's', 'e', ' ', |
| 4360 | 'I', ' ', 'c', 'a', |
| 4361 | 'n'} |
| 4362 | } |
| 4363 | }; |
| 4364 | // clang-format on |
| 4365 | |
| 4366 | PacketFragments& fragments = |
| 4367 | framer_.transport_version() == QUIC_VERSION_99 |
| 4368 | ? packet99 |
| 4369 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 4370 | ? packet46 |
| 4371 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 4372 | : packet)); |
| 4373 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4374 | AssemblePacketFromFragments(fragments)); |
| 4375 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4376 | |
| 4377 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4378 | ASSERT_TRUE(visitor_.header_.get()); |
| 4379 | EXPECT_TRUE(CheckDecryption( |
| 4380 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4381 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4382 | |
| 4383 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 4384 | |
| 4385 | EXPECT_EQ(0x11, visitor_.connection_close_frame_.error_code); |
| 4386 | EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
| 4387 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4388 | EXPECT_EQ(0x1234u, visitor_.connection_close_frame_.frame_type); |
| 4389 | } |
| 4390 | |
| 4391 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 4392 | |
| 4393 | CheckFramingBoundaries(fragments, QUIC_INVALID_CONNECTION_CLOSE_DATA); |
| 4394 | } |
| 4395 | |
| 4396 | TEST_P(QuicFramerTest, ApplicationCloseFrame) { |
| 4397 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 4398 | // This frame does not exist in versions other than 99. |
| 4399 | return; |
| 4400 | } |
| 4401 | |
| 4402 | // clang-format off |
| 4403 | PacketFragments packet99 = { |
| 4404 | // type (short header, 4 byte packet number) |
| 4405 | {"", |
| 4406 | {0x43}}, |
| 4407 | // connection_id |
| 4408 | {"", |
| 4409 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4410 | // packet number |
| 4411 | {"", |
| 4412 | {0x12, 0x34, 0x56, 0x78}}, |
| 4413 | // frame type (IETF_APPLICATION_CLOSE frame) |
| 4414 | {"", |
| 4415 | {0x1d}}, |
| 4416 | // error code |
| 4417 | {"Unable to read application close error code.", |
| 4418 | {0x00, 0x11}}, |
| 4419 | {"Unable to read application close error details.", |
| 4420 | { |
| 4421 | // error details length |
| 4422 | kVarInt62OneByte + 0x0d, |
| 4423 | // error details |
| 4424 | 'b', 'e', 'c', 'a', |
| 4425 | 'u', 's', 'e', ' ', |
| 4426 | 'I', ' ', 'c', 'a', |
| 4427 | 'n'} |
| 4428 | } |
| 4429 | }; |
| 4430 | // clang-format on |
| 4431 | |
| 4432 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4433 | AssemblePacketFromFragments(packet99)); |
| 4434 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4435 | |
| 4436 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4437 | ASSERT_TRUE(visitor_.header_.get()); |
| 4438 | EXPECT_TRUE(CheckDecryption( |
| 4439 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4440 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4441 | |
| 4442 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 4443 | |
| 4444 | EXPECT_EQ(0x11, visitor_.application_close_frame_.error_code); |
| 4445 | EXPECT_EQ("because I can", visitor_.application_close_frame_.error_details); |
| 4446 | |
| 4447 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 4448 | |
| 4449 | CheckFramingBoundaries(packet99, QUIC_INVALID_APPLICATION_CLOSE_DATA); |
| 4450 | } |
| 4451 | |
| 4452 | TEST_P(QuicFramerTest, GoAwayFrame) { |
| 4453 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4454 | // This frame is not supported in version 99. |
| 4455 | return; |
| 4456 | } |
| 4457 | // clang-format off |
| 4458 | PacketFragments packet = { |
| 4459 | // public flags (8 byte connection_id) |
| 4460 | {"", |
| 4461 | {0x28}}, |
| 4462 | // connection_id |
| 4463 | {"", |
| 4464 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4465 | // packet number |
| 4466 | {"", |
| 4467 | {0x12, 0x34, 0x56, 0x78}}, |
| 4468 | // frame type (go away frame) |
| 4469 | {"", |
| 4470 | {0x03}}, |
| 4471 | // error code |
| 4472 | {"Unable to read go away error code.", |
| 4473 | {0x00, 0x00, 0x00, 0x09}}, |
| 4474 | // stream id |
| 4475 | {"Unable to read last good stream id.", |
| 4476 | {0x01, 0x02, 0x03, 0x04}}, |
| 4477 | // stream id |
| 4478 | {"Unable to read goaway reason.", |
| 4479 | { |
| 4480 | // error details length |
| 4481 | 0x0, 0x0d, |
| 4482 | // error details |
| 4483 | 'b', 'e', 'c', 'a', |
| 4484 | 'u', 's', 'e', ' ', |
| 4485 | 'I', ' ', 'c', 'a', |
| 4486 | 'n'} |
| 4487 | } |
| 4488 | }; |
| 4489 | |
| 4490 | PacketFragments packet44 = { |
| 4491 | // type (short header, 4 byte packet number) |
| 4492 | {"", |
| 4493 | {0x32}}, |
| 4494 | // connection_id |
| 4495 | {"", |
| 4496 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4497 | // packet number |
| 4498 | {"", |
| 4499 | {0x12, 0x34, 0x56, 0x78}}, |
| 4500 | // frame type (go away frame) |
| 4501 | {"", |
| 4502 | {0x03}}, |
| 4503 | // error code |
| 4504 | {"Unable to read go away error code.", |
| 4505 | {0x00, 0x00, 0x00, 0x09}}, |
| 4506 | // stream id |
| 4507 | {"Unable to read last good stream id.", |
| 4508 | {0x01, 0x02, 0x03, 0x04}}, |
| 4509 | // stream id |
| 4510 | {"Unable to read goaway reason.", |
| 4511 | { |
| 4512 | // error details length |
| 4513 | 0x0, 0x0d, |
| 4514 | // error details |
| 4515 | 'b', 'e', 'c', 'a', |
| 4516 | 'u', 's', 'e', ' ', |
| 4517 | 'I', ' ', 'c', 'a', |
| 4518 | 'n'} |
| 4519 | } |
| 4520 | }; |
| 4521 | |
| 4522 | PacketFragments packet46 = { |
| 4523 | // type (short header, 4 byte packet number) |
| 4524 | {"", |
| 4525 | {0x43}}, |
| 4526 | // connection_id |
| 4527 | {"", |
| 4528 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4529 | // packet number |
| 4530 | {"", |
| 4531 | {0x12, 0x34, 0x56, 0x78}}, |
| 4532 | // frame type (go away frame) |
| 4533 | {"", |
| 4534 | {0x03}}, |
| 4535 | // error code |
| 4536 | {"Unable to read go away error code.", |
| 4537 | {0x00, 0x00, 0x00, 0x09}}, |
| 4538 | // stream id |
| 4539 | {"Unable to read last good stream id.", |
| 4540 | {0x01, 0x02, 0x03, 0x04}}, |
| 4541 | // stream id |
| 4542 | {"Unable to read goaway reason.", |
| 4543 | { |
| 4544 | // error details length |
| 4545 | 0x0, 0x0d, |
| 4546 | // error details |
| 4547 | 'b', 'e', 'c', 'a', |
| 4548 | 'u', 's', 'e', ' ', |
| 4549 | 'I', ' ', 'c', 'a', |
| 4550 | 'n'} |
| 4551 | } |
| 4552 | }; |
| 4553 | // clang-format on |
| 4554 | |
| 4555 | PacketFragments& fragments = |
| 4556 | framer_.transport_version() > QUIC_VERSION_44 |
| 4557 | ? packet46 |
| 4558 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 4559 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4560 | AssemblePacketFromFragments(fragments)); |
| 4561 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4562 | |
| 4563 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4564 | ASSERT_TRUE(visitor_.header_.get()); |
| 4565 | EXPECT_TRUE(CheckDecryption( |
| 4566 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4567 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4568 | |
| 4569 | EXPECT_EQ(kStreamId, visitor_.goaway_frame_.last_good_stream_id); |
| 4570 | EXPECT_EQ(0x9, visitor_.goaway_frame_.error_code); |
| 4571 | EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase); |
| 4572 | |
| 4573 | CheckFramingBoundaries(fragments, QUIC_INVALID_GOAWAY_DATA); |
| 4574 | } |
| 4575 | |
| 4576 | TEST_P(QuicFramerTest, WindowUpdateFrame) { |
| 4577 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4578 | // This frame is not in version 99, see MaxDataFrame and MaxStreamDataFrame |
| 4579 | // for Version 99 equivalents. |
| 4580 | return; |
| 4581 | } |
| 4582 | // clang-format off |
| 4583 | PacketFragments packet = { |
| 4584 | // public flags (8 byte connection_id) |
| 4585 | {"", |
| 4586 | {0x28}}, |
| 4587 | // connection_id |
| 4588 | {"", |
| 4589 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4590 | // packet number |
| 4591 | {"", |
| 4592 | {0x12, 0x34, 0x56, 0x78}}, |
| 4593 | // frame type (window update frame) |
| 4594 | {"", |
| 4595 | {0x04}}, |
| 4596 | // stream id |
| 4597 | {"Unable to read stream_id.", |
| 4598 | {0x01, 0x02, 0x03, 0x04}}, |
| 4599 | // byte offset |
| 4600 | {"Unable to read window byte_offset.", |
| 4601 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4602 | 0x32, 0x10, 0x76, 0x54}}, |
| 4603 | }; |
| 4604 | |
| 4605 | PacketFragments packet44 = { |
| 4606 | // type (short header, 4 byte packet number) |
| 4607 | {"", |
| 4608 | {0x32}}, |
| 4609 | // connection_id |
| 4610 | {"", |
| 4611 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4612 | // packet number |
| 4613 | {"", |
| 4614 | {0x12, 0x34, 0x56, 0x78}}, |
| 4615 | // frame type (window update frame) |
| 4616 | {"", |
| 4617 | {0x04}}, |
| 4618 | // stream id |
| 4619 | {"Unable to read stream_id.", |
| 4620 | {0x01, 0x02, 0x03, 0x04}}, |
| 4621 | // byte offset |
| 4622 | {"Unable to read window byte_offset.", |
| 4623 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4624 | 0x32, 0x10, 0x76, 0x54}}, |
| 4625 | }; |
| 4626 | |
| 4627 | PacketFragments packet46 = { |
| 4628 | // type (short header, 4 byte packet number) |
| 4629 | {"", |
| 4630 | {0x43}}, |
| 4631 | // connection_id |
| 4632 | {"", |
| 4633 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4634 | // packet number |
| 4635 | {"", |
| 4636 | {0x12, 0x34, 0x56, 0x78}}, |
| 4637 | // frame type (window update frame) |
| 4638 | {"", |
| 4639 | {0x04}}, |
| 4640 | // stream id |
| 4641 | {"Unable to read stream_id.", |
| 4642 | {0x01, 0x02, 0x03, 0x04}}, |
| 4643 | // byte offset |
| 4644 | {"Unable to read window byte_offset.", |
| 4645 | {0x3A, 0x98, 0xFE, 0xDC, |
| 4646 | 0x32, 0x10, 0x76, 0x54}}, |
| 4647 | }; |
| 4648 | |
| 4649 | // clang-format on |
| 4650 | |
| 4651 | PacketFragments& fragments = |
| 4652 | framer_.transport_version() > QUIC_VERSION_44 |
| 4653 | ? packet46 |
| 4654 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet); |
| 4655 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4656 | AssemblePacketFromFragments(fragments)); |
| 4657 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4658 | |
| 4659 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4660 | ASSERT_TRUE(visitor_.header_.get()); |
| 4661 | EXPECT_TRUE(CheckDecryption( |
| 4662 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4663 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4664 | |
| 4665 | EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id); |
| 4666 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset); |
| 4667 | |
| 4668 | CheckFramingBoundaries(fragments, QUIC_INVALID_WINDOW_UPDATE_DATA); |
| 4669 | } |
| 4670 | |
| 4671 | TEST_P(QuicFramerTest, MaxDataFrame) { |
| 4672 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 4673 | // This frame is available only in version 99. |
| 4674 | return; |
| 4675 | } |
| 4676 | // clang-format off |
| 4677 | PacketFragments packet99 = { |
| 4678 | // type (short header, 4 byte packet number) |
| 4679 | {"", |
| 4680 | {0x43}}, |
| 4681 | // connection_id |
| 4682 | {"", |
| 4683 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4684 | // packet number |
| 4685 | {"", |
| 4686 | {0x12, 0x34, 0x56, 0x78}}, |
| 4687 | // frame type (IETF_MAX_DATA frame) |
| 4688 | {"", |
| 4689 | {0x10}}, |
| 4690 | // byte offset |
| 4691 | {"Can not read MAX_DATA byte-offset", |
| 4692 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 4693 | 0x32, 0x10, 0x76, 0x54}}, |
| 4694 | }; |
| 4695 | // clang-format on |
| 4696 | |
| 4697 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4698 | AssemblePacketFromFragments(packet99)); |
| 4699 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4700 | |
| 4701 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4702 | ASSERT_TRUE(visitor_.header_.get()); |
| 4703 | EXPECT_TRUE(CheckDecryption( |
| 4704 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4705 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4706 | |
| 4707 | EXPECT_EQ(QuicUtils::GetInvalidStreamId(framer_.transport_version()), |
| 4708 | visitor_.window_update_frame_.stream_id); |
| 4709 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset); |
| 4710 | |
| 4711 | CheckFramingBoundaries(packet99, QUIC_INVALID_MAX_DATA_FRAME_DATA); |
| 4712 | } |
| 4713 | |
| 4714 | TEST_P(QuicFramerTest, MaxStreamDataFrame) { |
| 4715 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 4716 | // This frame available only in version 99. |
| 4717 | return; |
| 4718 | } |
| 4719 | // clang-format off |
| 4720 | PacketFragments packet99 = { |
| 4721 | // type (short header, 4 byte packet number) |
| 4722 | {"", |
| 4723 | {0x43}}, |
| 4724 | // connection_id |
| 4725 | {"", |
| 4726 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4727 | // packet number |
| 4728 | {"", |
| 4729 | {0x12, 0x34, 0x56, 0x78}}, |
| 4730 | // frame type (IETF_MAX_STREAM_DATA frame) |
| 4731 | {"", |
| 4732 | {0x11}}, |
| 4733 | // stream id |
| 4734 | {"Can not read MAX_STREAM_DATA stream id", |
| 4735 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 4736 | // byte offset |
| 4737 | {"Can not read MAX_STREAM_DATA byte-count", |
| 4738 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 4739 | 0x32, 0x10, 0x76, 0x54}}, |
| 4740 | }; |
| 4741 | // clang-format on |
| 4742 | |
| 4743 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4744 | AssemblePacketFromFragments(packet99)); |
| 4745 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4746 | |
| 4747 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4748 | ASSERT_TRUE(visitor_.header_.get()); |
| 4749 | EXPECT_TRUE(CheckDecryption( |
| 4750 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4751 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4752 | |
| 4753 | EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id); |
| 4754 | EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset); |
| 4755 | |
| 4756 | CheckFramingBoundaries(packet99, QUIC_INVALID_MAX_STREAM_DATA_FRAME_DATA); |
| 4757 | } |
| 4758 | |
| 4759 | TEST_P(QuicFramerTest, BlockedFrame) { |
| 4760 | // clang-format off |
| 4761 | PacketFragments packet = { |
| 4762 | // public flags (8 byte connection_id) |
| 4763 | {"", |
| 4764 | {0x28}}, |
| 4765 | // connection_id |
| 4766 | {"", |
| 4767 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4768 | // packet number |
| 4769 | {"", |
| 4770 | {0x12, 0x34, 0x56, 0x78}}, |
| 4771 | // frame type (blocked frame) |
| 4772 | {"", |
| 4773 | {0x05}}, |
| 4774 | // stream id |
| 4775 | {"Unable to read stream_id.", |
| 4776 | {0x01, 0x02, 0x03, 0x04}}, |
| 4777 | }; |
| 4778 | |
| 4779 | PacketFragments packet44 = { |
| 4780 | // type (short header, 4 byte packet number) |
| 4781 | {"", |
| 4782 | {0x32}}, |
| 4783 | // connection_id |
| 4784 | {"", |
| 4785 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4786 | // packet number |
| 4787 | {"", |
| 4788 | {0x12, 0x34, 0x56, 0x78}}, |
| 4789 | // frame type (blocked frame) |
| 4790 | {"", |
| 4791 | {0x05}}, |
| 4792 | // stream id |
| 4793 | {"Unable to read stream_id.", |
| 4794 | {0x01, 0x02, 0x03, 0x04}}, |
| 4795 | }; |
| 4796 | |
| 4797 | PacketFragments packet46 = { |
| 4798 | // type (short header, 4 byte packet number) |
| 4799 | {"", |
| 4800 | {0x43}}, |
| 4801 | // connection_id |
| 4802 | {"", |
| 4803 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4804 | // packet number |
| 4805 | {"", |
| 4806 | {0x12, 0x34, 0x56, 0x78}}, |
| 4807 | // frame type (blocked frame) |
| 4808 | {"", |
| 4809 | {0x05}}, |
| 4810 | // stream id |
| 4811 | {"Unable to read stream_id.", |
| 4812 | {0x01, 0x02, 0x03, 0x04}}, |
| 4813 | }; |
| 4814 | |
| 4815 | PacketFragments packet99 = { |
| 4816 | // type (short header, 4 byte packet number) |
| 4817 | {"", |
| 4818 | {0x43}}, |
| 4819 | // connection_id |
| 4820 | {"", |
| 4821 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4822 | // packet number |
| 4823 | {"", |
| 4824 | {0x12, 0x34, 0x56, 0x78}}, |
| 4825 | // frame type (IETF_STREAM_BLOCKED frame) |
| 4826 | {"", |
| 4827 | {0x15}}, |
| 4828 | // stream id |
| 4829 | {"Can not read stream blocked stream id.", |
| 4830 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 4831 | // Offset |
| 4832 | {"Can not read stream blocked offset.", |
| 4833 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 4834 | }; |
| 4835 | // clang-format on |
| 4836 | |
| 4837 | PacketFragments& fragments = |
| 4838 | framer_.transport_version() == QUIC_VERSION_99 |
| 4839 | ? packet99 |
| 4840 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 4841 | ? packet46 |
| 4842 | : (framer_.transport_version() > QUIC_VERSION_43 ? packet44 |
| 4843 | : packet)); |
| 4844 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 4845 | AssemblePacketFromFragments(fragments)); |
| 4846 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 4847 | |
| 4848 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4849 | ASSERT_TRUE(visitor_.header_.get()); |
| 4850 | EXPECT_TRUE(CheckDecryption( |
| 4851 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4852 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4853 | |
| 4854 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4855 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 4856 | } else { |
| 4857 | EXPECT_EQ(0u, visitor_.blocked_frame_.offset); |
| 4858 | } |
| 4859 | EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id); |
| 4860 | |
| 4861 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 4862 | CheckFramingBoundaries(fragments, QUIC_INVALID_STREAM_BLOCKED_DATA); |
| 4863 | } else { |
| 4864 | CheckFramingBoundaries(fragments, QUIC_INVALID_BLOCKED_DATA); |
| 4865 | } |
| 4866 | } |
| 4867 | |
| 4868 | TEST_P(QuicFramerTest, PingFrame) { |
| 4869 | // clang-format off |
| 4870 | unsigned char packet[] = { |
| 4871 | // public flags (8 byte connection_id) |
| 4872 | 0x28, |
| 4873 | // connection_id |
| 4874 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4875 | // packet number |
| 4876 | 0x12, 0x34, 0x56, 0x78, |
| 4877 | |
| 4878 | // frame type (ping frame) |
| 4879 | 0x07, |
| 4880 | }; |
| 4881 | |
| 4882 | unsigned char packet44[] = { |
| 4883 | // type (short header, 4 byte packet number) |
| 4884 | 0x32, |
| 4885 | // connection_id |
| 4886 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4887 | // packet number |
| 4888 | 0x12, 0x34, 0x56, 0x78, |
| 4889 | |
| 4890 | // frame type |
| 4891 | 0x07, |
| 4892 | }; |
| 4893 | |
| 4894 | unsigned char packet46[] = { |
| 4895 | // type (short header, 4 byte packet number) |
| 4896 | 0x43, |
| 4897 | // connection_id |
| 4898 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4899 | // packet number |
| 4900 | 0x12, 0x34, 0x56, 0x78, |
| 4901 | |
| 4902 | // frame type |
| 4903 | 0x07, |
| 4904 | }; |
| 4905 | |
| 4906 | unsigned char packet99[] = { |
| 4907 | // type (short header, 4 byte packet number) |
| 4908 | 0x43, |
| 4909 | // connection_id |
| 4910 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 4911 | // packet number |
| 4912 | 0x12, 0x34, 0x56, 0x78, |
| 4913 | |
| 4914 | // frame type (IETF_PING frame) |
| 4915 | 0x01, |
| 4916 | }; |
| 4917 | // clang-format on |
| 4918 | |
| 4919 | QuicEncryptedPacket encrypted( |
| 4920 | AsChars(framer_.transport_version() == QUIC_VERSION_99 |
| 4921 | ? packet99 |
| 4922 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 4923 | ? packet46 |
| 4924 | : framer_.transport_version() > QUIC_VERSION_43 |
| 4925 | ? packet44 |
| 4926 | : packet)), |
| 4927 | framer_.transport_version() == QUIC_VERSION_99 |
| 4928 | ? QUIC_ARRAYSIZE(packet99) |
| 4929 | : (framer_.transport_version() > QUIC_VERSION_44 |
| 4930 | ? QUIC_ARRAYSIZE(packet46) |
| 4931 | : framer_.transport_version() > QUIC_VERSION_43 |
| 4932 | ? QUIC_ARRAYSIZE(packet44) |
| 4933 | : QUIC_ARRAYSIZE(packet)), |
| 4934 | false); |
| 4935 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 4936 | |
| 4937 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 4938 | ASSERT_TRUE(visitor_.header_.get()); |
| 4939 | EXPECT_TRUE(CheckDecryption( |
| 4940 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 4941 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 4942 | |
| 4943 | EXPECT_EQ(1u, visitor_.ping_frames_.size()); |
| 4944 | |
| 4945 | // No need to check the PING frame boundaries because it has no payload. |
| 4946 | } |
| 4947 | |
| 4948 | TEST_P(QuicFramerTest, MessageFrame) { |
| 4949 | if (framer_.transport_version() <= QUIC_VERSION_44) { |
| 4950 | return; |
| 4951 | } |
| 4952 | // clang-format off |
| 4953 | PacketFragments packet45 = { |
| 4954 | // type (short header, 4 byte packet number) |
| 4955 | {"", |
| 4956 | {0x32}}, |
| 4957 | // connection_id |
| 4958 | {"", |
| 4959 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4960 | // packet number |
| 4961 | {"", |
| 4962 | {0x12, 0x34, 0x56, 0x78}}, |
| 4963 | // message frame type. |
| 4964 | {"", |
| 4965 | { 0x21 }}, |
| 4966 | // message length |
| 4967 | {"Unable to read message length", |
| 4968 | {0x07}}, |
| 4969 | // message data |
| 4970 | {"Unable to read message data", |
| 4971 | {'m', 'e', 's', 's', 'a', 'g', 'e'}}, |
| 4972 | // message frame no length. |
| 4973 | {"", |
| 4974 | { 0x20 }}, |
| 4975 | // message data |
| 4976 | {{}, |
| 4977 | {'m', 'e', 's', 's', 'a', 'g', 'e', '2'}}, |
| 4978 | }; |
| 4979 | |
| 4980 | PacketFragments packet46 = { |
| 4981 | // type (short header, 4 byte packet number) |
| 4982 | {"", |
| 4983 | {0x43}}, |
| 4984 | // connection_id |
| 4985 | {"", |
| 4986 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 4987 | // packet number |
| 4988 | {"", |
| 4989 | {0x12, 0x34, 0x56, 0x78}}, |
| 4990 | // message frame type. |
| 4991 | {"", |
| 4992 | { 0x21 }}, |
| 4993 | // message length |
| 4994 | {"Unable to read message length", |
| 4995 | {0x07}}, |
| 4996 | // message data |
| 4997 | {"Unable to read message data", |
| 4998 | {'m', 'e', 's', 's', 'a', 'g', 'e'}}, |
| 4999 | // message frame no length. |
| 5000 | {"", |
| 5001 | { 0x20 }}, |
| 5002 | // message data |
| 5003 | {{}, |
| 5004 | {'m', 'e', 's', 's', 'a', 'g', 'e', '2'}}, |
| 5005 | }; |
| 5006 | // clang-format on |
| 5007 | |
| 5008 | std::unique_ptr<QuicEncryptedPacket> encrypted(AssemblePacketFromFragments( |
| 5009 | framer_.transport_version() > QUIC_VERSION_44 ? packet46 : packet45)); |
| 5010 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5011 | |
| 5012 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5013 | ASSERT_TRUE(visitor_.header_.get()); |
| 5014 | EXPECT_TRUE(CheckDecryption( |
| 5015 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 5016 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 5017 | |
| 5018 | ASSERT_EQ(2u, visitor_.message_frames_.size()); |
| 5019 | EXPECT_EQ(7u, visitor_.message_frames_[0]->message_length); |
| 5020 | EXPECT_EQ(8u, visitor_.message_frames_[1]->message_length); |
| 5021 | |
| 5022 | CheckFramingBoundaries( |
| 5023 | framer_.transport_version() > QUIC_VERSION_44 ? packet46 : packet45, |
| 5024 | QUIC_INVALID_MESSAGE_DATA); |
| 5025 | } |
| 5026 | |
| 5027 | TEST_P(QuicFramerTest, PublicResetPacketV33) { |
| 5028 | // clang-format off |
| 5029 | PacketFragments packet = { |
| 5030 | // public flags (public reset, 8 byte connection_id) |
| 5031 | {"", |
| 5032 | {0x0A}}, |
| 5033 | // connection_id |
| 5034 | {"", |
| 5035 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5036 | {"Unable to read reset message.", |
| 5037 | { |
| 5038 | // message tag (kPRST) |
| 5039 | 'P', 'R', 'S', 'T', |
| 5040 | // num_entries (2) + padding |
| 5041 | 0x02, 0x00, 0x00, 0x00, |
| 5042 | // tag kRNON |
| 5043 | 'R', 'N', 'O', 'N', |
| 5044 | // end offset 8 |
| 5045 | 0x08, 0x00, 0x00, 0x00, |
| 5046 | // tag kRSEQ |
| 5047 | 'R', 'S', 'E', 'Q', |
| 5048 | // end offset 16 |
| 5049 | 0x10, 0x00, 0x00, 0x00, |
| 5050 | // nonce proof |
| 5051 | 0x89, 0x67, 0x45, 0x23, |
| 5052 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5053 | // rejected packet number |
| 5054 | 0xBC, 0x9A, 0x78, 0x56, |
| 5055 | 0x34, 0x12, 0x00, 0x00, |
| 5056 | } |
| 5057 | } |
| 5058 | }; |
| 5059 | // clang-format on |
| 5060 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5061 | return; |
| 5062 | } |
| 5063 | |
| 5064 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5065 | AssemblePacketFromFragments(packet)); |
| 5066 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5067 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5068 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 5069 | EXPECT_EQ(FramerTestConnectionId(), |
| 5070 | visitor_.public_reset_packet_->connection_id); |
| 5071 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 5072 | EXPECT_EQ( |
| 5073 | IpAddressFamily::IP_UNSPEC, |
| 5074 | visitor_.public_reset_packet_->client_address.host().address_family()); |
| 5075 | |
| 5076 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 5077 | } |
| 5078 | |
| 5079 | TEST_P(QuicFramerTest, PublicResetPacket) { |
| 5080 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5081 | |
| 5082 | // clang-format off |
| 5083 | PacketFragments packet = { |
| 5084 | // public flags (public reset, 8 byte connection_id) |
| 5085 | {"", |
| 5086 | {0x0E}}, |
| 5087 | // connection_id |
| 5088 | {"", |
| 5089 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5090 | {"Unable to read reset message.", |
| 5091 | { |
| 5092 | // message tag (kPRST) |
| 5093 | 'P', 'R', 'S', 'T', |
| 5094 | // num_entries (2) + padding |
| 5095 | 0x02, 0x00, 0x00, 0x00, |
| 5096 | // tag kRNON |
| 5097 | 'R', 'N', 'O', 'N', |
| 5098 | // end offset 8 |
| 5099 | 0x08, 0x00, 0x00, 0x00, |
| 5100 | // tag kRSEQ |
| 5101 | 'R', 'S', 'E', 'Q', |
| 5102 | // end offset 16 |
| 5103 | 0x10, 0x00, 0x00, 0x00, |
| 5104 | // nonce proof |
| 5105 | 0x89, 0x67, 0x45, 0x23, |
| 5106 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5107 | // rejected packet number |
| 5108 | 0xBC, 0x9A, 0x78, 0x56, |
| 5109 | 0x34, 0x12, 0x00, 0x00, |
| 5110 | } |
| 5111 | } |
| 5112 | }; |
| 5113 | // clang-format on |
| 5114 | |
| 5115 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5116 | return; |
| 5117 | } |
| 5118 | |
| 5119 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5120 | AssemblePacketFromFragments(packet)); |
| 5121 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5122 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5123 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 5124 | EXPECT_EQ(FramerTestConnectionId(), |
| 5125 | visitor_.public_reset_packet_->connection_id); |
| 5126 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 5127 | EXPECT_EQ( |
| 5128 | IpAddressFamily::IP_UNSPEC, |
| 5129 | visitor_.public_reset_packet_->client_address.host().address_family()); |
| 5130 | |
| 5131 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 5132 | } |
| 5133 | |
| 5134 | TEST_P(QuicFramerTest, PublicResetPacketWithTrailingJunk) { |
| 5135 | // clang-format off |
| 5136 | unsigned char packet[] = { |
| 5137 | // public flags (public reset, 8 byte connection_id) |
| 5138 | 0x0A, |
| 5139 | // connection_id |
| 5140 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5141 | // message tag (kPRST) |
| 5142 | 'P', 'R', 'S', 'T', |
| 5143 | // num_entries (2) + padding |
| 5144 | 0x02, 0x00, 0x00, 0x00, |
| 5145 | // tag kRNON |
| 5146 | 'R', 'N', 'O', 'N', |
| 5147 | // end offset 8 |
| 5148 | 0x08, 0x00, 0x00, 0x00, |
| 5149 | // tag kRSEQ |
| 5150 | 'R', 'S', 'E', 'Q', |
| 5151 | // end offset 16 |
| 5152 | 0x10, 0x00, 0x00, 0x00, |
| 5153 | // nonce proof |
| 5154 | 0x89, 0x67, 0x45, 0x23, |
| 5155 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5156 | // rejected packet number |
| 5157 | 0xBC, 0x9A, 0x78, 0x56, |
| 5158 | 0x34, 0x12, 0x00, 0x00, |
| 5159 | // trailing junk |
| 5160 | 'j', 'u', 'n', 'k', |
| 5161 | }; |
| 5162 | // clang-format on |
| 5163 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5164 | return; |
| 5165 | } |
| 5166 | |
| 5167 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 5168 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 5169 | ASSERT_EQ(QUIC_INVALID_PUBLIC_RST_PACKET, framer_.error()); |
| 5170 | EXPECT_EQ("Unable to read reset message.", framer_.detailed_error()); |
| 5171 | } |
| 5172 | |
| 5173 | TEST_P(QuicFramerTest, PublicResetPacketWithClientAddress) { |
| 5174 | // clang-format off |
| 5175 | PacketFragments packet = { |
| 5176 | // public flags (public reset, 8 byte connection_id) |
| 5177 | {"", |
| 5178 | {0x0A}}, |
| 5179 | // connection_id |
| 5180 | {"", |
| 5181 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5182 | {"Unable to read reset message.", |
| 5183 | { |
| 5184 | // message tag (kPRST) |
| 5185 | 'P', 'R', 'S', 'T', |
| 5186 | // num_entries (2) + padding |
| 5187 | 0x03, 0x00, 0x00, 0x00, |
| 5188 | // tag kRNON |
| 5189 | 'R', 'N', 'O', 'N', |
| 5190 | // end offset 8 |
| 5191 | 0x08, 0x00, 0x00, 0x00, |
| 5192 | // tag kRSEQ |
| 5193 | 'R', 'S', 'E', 'Q', |
| 5194 | // end offset 16 |
| 5195 | 0x10, 0x00, 0x00, 0x00, |
| 5196 | // tag kCADR |
| 5197 | 'C', 'A', 'D', 'R', |
| 5198 | // end offset 24 |
| 5199 | 0x18, 0x00, 0x00, 0x00, |
| 5200 | // nonce proof |
| 5201 | 0x89, 0x67, 0x45, 0x23, |
| 5202 | 0x01, 0xEF, 0xCD, 0xAB, |
| 5203 | // rejected packet number |
| 5204 | 0xBC, 0x9A, 0x78, 0x56, |
| 5205 | 0x34, 0x12, 0x00, 0x00, |
| 5206 | // client address: 4.31.198.44:443 |
| 5207 | 0x02, 0x00, |
| 5208 | 0x04, 0x1F, 0xC6, 0x2C, |
| 5209 | 0xBB, 0x01, |
| 5210 | } |
| 5211 | } |
| 5212 | }; |
| 5213 | // clang-format on |
| 5214 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5215 | return; |
| 5216 | } |
| 5217 | |
| 5218 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5219 | AssemblePacketFromFragments(packet)); |
| 5220 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5221 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5222 | ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
| 5223 | EXPECT_EQ(FramerTestConnectionId(), |
| 5224 | visitor_.public_reset_packet_->connection_id); |
| 5225 | EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
| 5226 | EXPECT_EQ("4.31.198.44", |
| 5227 | visitor_.public_reset_packet_->client_address.host().ToString()); |
| 5228 | EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port()); |
| 5229 | |
| 5230 | CheckFramingBoundaries(packet, QUIC_INVALID_PUBLIC_RST_PACKET); |
| 5231 | } |
| 5232 | |
| 5233 | TEST_P(QuicFramerTest, IetfStatelessResetPacket) { |
| 5234 | // clang-format off |
| 5235 | unsigned char packet[] = { |
| 5236 | // type (short packet, 1 byte packet number) |
| 5237 | 0x50, |
| 5238 | // connection_id |
| 5239 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5240 | // Random bytes |
| 5241 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5242 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5243 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5244 | 0x01, 0x11, 0x02, 0x22, 0x03, 0x33, 0x04, 0x44, |
| 5245 | // stateless reset token |
| 5246 | 0xB5, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5247 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5248 | }; |
| 5249 | // clang-format on |
| 5250 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 5251 | return; |
| 5252 | } |
| 5253 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5254 | framer_.SetDecrypter(ENCRYPTION_NONE, |
| 5255 | QuicMakeUnique<NullDecrypter>(Perspective::IS_CLIENT)); |
| 5256 | decrypter_ = new test::TestDecrypter(); |
| 5257 | framer_.SetAlternativeDecrypter( |
| 5258 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 5259 | // This packet cannot be decrypted because diversification nonce is missing. |
| 5260 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 5261 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 5262 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5263 | ASSERT_TRUE(visitor_.stateless_reset_packet_.get()); |
| 5264 | EXPECT_EQ(kTestStatelessResetToken, |
| 5265 | visitor_.stateless_reset_packet_->stateless_reset_token); |
| 5266 | } |
| 5267 | |
| 5268 | TEST_P(QuicFramerTest, IetfStatelessResetPacketInvalidStatelessResetToken) { |
| 5269 | // clang-format off |
| 5270 | unsigned char packet[] = { |
| 5271 | // type (short packet, 1 byte packet number) |
| 5272 | 0x50, |
| 5273 | // connection_id |
| 5274 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5275 | // stateless reset token |
| 5276 | 0xB6, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5277 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 5278 | }; |
| 5279 | // clang-format on |
| 5280 | if (framer_.transport_version() <= QUIC_VERSION_43) { |
| 5281 | return; |
| 5282 | } |
| 5283 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5284 | framer_.SetDecrypter(ENCRYPTION_NONE, |
| 5285 | QuicMakeUnique<NullDecrypter>(Perspective::IS_CLIENT)); |
| 5286 | decrypter_ = new test::TestDecrypter(); |
| 5287 | framer_.SetAlternativeDecrypter( |
| 5288 | ENCRYPTION_ZERO_RTT, std::unique_ptr<QuicDecrypter>(decrypter_), false); |
| 5289 | // This packet cannot be decrypted because diversification nonce is missing. |
| 5290 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 5291 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 5292 | EXPECT_EQ(QUIC_DECRYPTION_FAILURE, framer_.error()); |
| 5293 | ASSERT_FALSE(visitor_.stateless_reset_packet_); |
| 5294 | } |
| 5295 | |
| 5296 | TEST_P(QuicFramerTest, VersionNegotiationPacket) { |
| 5297 | // clang-format off |
| 5298 | PacketFragments packet = { |
| 5299 | // public flags (version, 8 byte connection_id) |
| 5300 | {"", |
| 5301 | {0x29}}, |
| 5302 | // connection_id |
| 5303 | {"", |
| 5304 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5305 | // version tag |
| 5306 | {"Unable to read supported version in negotiation.", |
| 5307 | {QUIC_VERSION_BYTES, |
| 5308 | 'Q', '2', '.', '0'}}, |
| 5309 | }; |
| 5310 | |
| 5311 | PacketFragments packet44 = { |
| 5312 | // type (long header) |
| 5313 | {"", |
| 5314 | {0x8F}}, |
| 5315 | // version tag |
| 5316 | {"", |
| 5317 | {0x00, 0x00, 0x00, 0x00}}, |
| 5318 | {"", |
| 5319 | {0x05}}, |
| 5320 | // connection_id |
| 5321 | {"", |
| 5322 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5323 | // Supported versions |
| 5324 | {"Unable to read supported version in negotiation.", |
| 5325 | {QUIC_VERSION_BYTES, |
| 5326 | 'Q', '2', '.', '0'}}, |
| 5327 | }; |
| 5328 | // clang-format on |
| 5329 | |
| 5330 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5331 | |
| 5332 | PacketFragments& fragments = |
| 5333 | framer_.transport_version() > QUIC_VERSION_43 ? packet44 : packet; |
| 5334 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5335 | AssemblePacketFromFragments(fragments)); |
| 5336 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5337 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5338 | ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); |
| 5339 | EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size()); |
| 5340 | EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]); |
| 5341 | |
| 5342 | // Remove the last version from the packet so that every truncated |
| 5343 | // version of the packet is invalid, otherwise checking boundaries |
| 5344 | // is annoyingly complicated. |
| 5345 | for (size_t i = 0; i < 4; ++i) { |
| 5346 | fragments.back().fragment.pop_back(); |
| 5347 | } |
| 5348 | CheckFramingBoundaries(fragments, QUIC_INVALID_VERSION_NEGOTIATION_PACKET); |
| 5349 | } |
| 5350 | |
| 5351 | TEST_P(QuicFramerTest, OldVersionNegotiationPacket) { |
| 5352 | // clang-format off |
| 5353 | PacketFragments packet = { |
| 5354 | // public flags (version, 8 byte connection_id) |
| 5355 | {"", |
| 5356 | {0x2D}}, |
| 5357 | // connection_id |
| 5358 | {"", |
| 5359 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 5360 | // version tag |
| 5361 | {"Unable to read supported version in negotiation.", |
| 5362 | {QUIC_VERSION_BYTES, |
| 5363 | 'Q', '2', '.', '0'}}, |
| 5364 | }; |
| 5365 | // clang-format on |
| 5366 | |
| 5367 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5368 | return; |
| 5369 | } |
| 5370 | |
| 5371 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 5372 | |
| 5373 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 5374 | AssemblePacketFromFragments(packet)); |
| 5375 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 5376 | ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 5377 | ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); |
| 5378 | EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size()); |
| 5379 | EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]); |
| 5380 | |
| 5381 | // Remove the last version from the packet so that every truncated |
| 5382 | // version of the packet is invalid, otherwise checking boundaries |
| 5383 | // is annoyingly complicated. |
| 5384 | for (size_t i = 0; i < 4; ++i) { |
| 5385 | packet.back().fragment.pop_back(); |
| 5386 | } |
| 5387 | CheckFramingBoundaries(packet, QUIC_INVALID_VERSION_NEGOTIATION_PACKET); |
| 5388 | } |
| 5389 | |
| 5390 | TEST_P(QuicFramerTest, BuildPaddingFramePacket) { |
| 5391 | QuicPacketHeader header; |
| 5392 | header.destination_connection_id = FramerTestConnectionId(); |
| 5393 | header.reset_flag = false; |
| 5394 | header.version_flag = false; |
| 5395 | header.packet_number = kPacketNumber; |
| 5396 | |
| 5397 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 5398 | |
| 5399 | // clang-format off |
| 5400 | unsigned char packet[kMaxPacketSize] = { |
| 5401 | // public flags (8 byte connection_id) |
| 5402 | 0x28, |
| 5403 | // connection_id |
| 5404 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5405 | // packet number |
| 5406 | 0x12, 0x34, 0x56, 0x78, |
| 5407 | |
| 5408 | // frame type (padding frame) |
| 5409 | 0x00, |
| 5410 | 0x00, 0x00, 0x00, 0x00 |
| 5411 | }; |
| 5412 | |
| 5413 | unsigned char packet44[kMaxPacketSize] = { |
| 5414 | // type (short header, 4 byte packet number) |
| 5415 | 0x32, |
| 5416 | // connection_id |
| 5417 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5418 | // packet number |
| 5419 | 0x12, 0x34, 0x56, 0x78, |
| 5420 | |
| 5421 | // frame type (padding frame) |
| 5422 | 0x00, |
| 5423 | 0x00, 0x00, 0x00, 0x00 |
| 5424 | }; |
| 5425 | |
| 5426 | unsigned char packet46[kMaxPacketSize] = { |
| 5427 | // type (short header, 4 byte packet number) |
| 5428 | 0x43, |
| 5429 | // connection_id |
| 5430 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5431 | // packet number |
| 5432 | 0x12, 0x34, 0x56, 0x78, |
| 5433 | |
| 5434 | // frame type (padding frame) |
| 5435 | 0x00, |
| 5436 | 0x00, 0x00, 0x00, 0x00 |
| 5437 | }; |
| 5438 | |
| 5439 | unsigned char packet99[kMaxPacketSize] = { |
| 5440 | // type (short header, 4 byte packet number) |
| 5441 | 0x43, |
| 5442 | // connection_id |
| 5443 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5444 | // packet number |
| 5445 | 0x12, 0x34, 0x56, 0x78, |
| 5446 | |
| 5447 | // frame type (padding frame) |
| 5448 | 0x00, |
| 5449 | 0x00, 0x00, 0x00, 0x00 |
| 5450 | }; |
| 5451 | // clang-format on |
| 5452 | |
| 5453 | unsigned char* p = packet; |
| 5454 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5455 | p = packet99; |
| 5456 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 5457 | p = packet46; |
| 5458 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5459 | p = packet44; |
| 5460 | } |
| 5461 | |
| 5462 | uint64_t header_size = GetPacketHeaderSize( |
| 5463 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 5464 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 5465 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 5466 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
| 5467 | memset(p + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); |
| 5468 | |
| 5469 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5470 | ASSERT_TRUE(data != nullptr); |
| 5471 | |
| 5472 | test::CompareCharArraysWithHexError( |
| 5473 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 5474 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 5475 | : QUIC_ARRAYSIZE(packet)); |
| 5476 | } |
| 5477 | |
| 5478 | TEST_P(QuicFramerTest, BuildStreamFramePacketWithNewPaddingFrame) { |
| 5479 | QuicPacketHeader header; |
| 5480 | header.destination_connection_id = FramerTestConnectionId(); |
| 5481 | header.reset_flag = false; |
| 5482 | header.version_flag = false; |
| 5483 | header.packet_number = kPacketNumber; |
| 5484 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
| 5485 | QuicStringPiece("hello world!")); |
| 5486 | QuicPaddingFrame padding_frame(2); |
| 5487 | QuicFrames frames = {QuicFrame(padding_frame), QuicFrame(stream_frame), |
| 5488 | QuicFrame(padding_frame)}; |
| 5489 | |
| 5490 | // clang-format off |
| 5491 | unsigned char packet[] = { |
| 5492 | // public flags (8 byte connection_id) |
| 5493 | 0x28, |
| 5494 | // connection_id |
| 5495 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5496 | // packet number |
| 5497 | 0x12, 0x34, 0x56, 0x78, |
| 5498 | |
| 5499 | // paddings |
| 5500 | 0x00, 0x00, |
| 5501 | // frame type (stream frame with fin) |
| 5502 | 0xFF, |
| 5503 | // stream id |
| 5504 | 0x01, 0x02, 0x03, 0x04, |
| 5505 | // offset |
| 5506 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5507 | 0x32, 0x10, 0x76, 0x54, |
| 5508 | // data length |
| 5509 | 0x00, 0x0c, |
| 5510 | // data |
| 5511 | 'h', 'e', 'l', 'l', |
| 5512 | 'o', ' ', 'w', 'o', |
| 5513 | 'r', 'l', 'd', '!', |
| 5514 | // paddings |
| 5515 | 0x00, 0x00, |
| 5516 | }; |
| 5517 | |
| 5518 | unsigned char packet44[] = { |
| 5519 | // type (short header, 4 byte packet number) |
| 5520 | 0x32, |
| 5521 | // connection_id |
| 5522 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5523 | // packet number |
| 5524 | 0x12, 0x34, 0x56, 0x78, |
| 5525 | |
| 5526 | // paddings |
| 5527 | 0x00, 0x00, |
| 5528 | // frame type (stream frame with fin) |
| 5529 | 0xFF, |
| 5530 | // stream id |
| 5531 | 0x01, 0x02, 0x03, 0x04, |
| 5532 | // offset |
| 5533 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5534 | 0x32, 0x10, 0x76, 0x54, |
| 5535 | // data length |
| 5536 | 0x00, 0x0c, |
| 5537 | // data |
| 5538 | 'h', 'e', 'l', 'l', |
| 5539 | 'o', ' ', 'w', 'o', |
| 5540 | 'r', 'l', 'd', '!', |
| 5541 | // paddings |
| 5542 | 0x00, 0x00, |
| 5543 | }; |
| 5544 | |
| 5545 | unsigned char packet46[] = { |
| 5546 | // type (short header, 4 byte packet number) |
| 5547 | 0x43, |
| 5548 | // connection_id |
| 5549 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5550 | // packet number |
| 5551 | 0x12, 0x34, 0x56, 0x78, |
| 5552 | |
| 5553 | // paddings |
| 5554 | 0x00, 0x00, |
| 5555 | // frame type (stream frame with fin) |
| 5556 | 0xFF, |
| 5557 | // stream id |
| 5558 | 0x01, 0x02, 0x03, 0x04, |
| 5559 | // offset |
| 5560 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5561 | 0x32, 0x10, 0x76, 0x54, |
| 5562 | // data length |
| 5563 | 0x00, 0x0c, |
| 5564 | // data |
| 5565 | 'h', 'e', 'l', 'l', |
| 5566 | 'o', ' ', 'w', 'o', |
| 5567 | 'r', 'l', 'd', '!', |
| 5568 | // paddings |
| 5569 | 0x00, 0x00, |
| 5570 | }; |
| 5571 | |
| 5572 | unsigned char packet99[] = { |
| 5573 | // type (short header, 4 byte packet number) |
| 5574 | 0x43, |
| 5575 | // connection_id |
| 5576 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5577 | // packet number |
| 5578 | 0x12, 0x34, 0x56, 0x78, |
| 5579 | |
| 5580 | // paddings |
| 5581 | 0x00, 0x00, |
| 5582 | // frame type (IETF_STREAM with FIN, LEN, and OFFSET bits set) |
| 5583 | 0x08 | 0x01 | 0x02 | 0x04, |
| 5584 | // stream id |
| 5585 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 5586 | // offset |
| 5587 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 5588 | 0x32, 0x10, 0x76, 0x54, |
| 5589 | // data length |
| 5590 | kVarInt62OneByte + 0x0c, |
| 5591 | // data |
| 5592 | 'h', 'e', 'l', 'l', |
| 5593 | 'o', ' ', 'w', 'o', |
| 5594 | 'r', 'l', 'd', '!', |
| 5595 | // paddings |
| 5596 | 0x00, 0x00, |
| 5597 | }; |
| 5598 | // clang-format on |
| 5599 | |
| 5600 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5601 | ASSERT_TRUE(data != nullptr); |
| 5602 | |
| 5603 | unsigned char* p = packet; |
| 5604 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 5605 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5606 | p = packet99; |
| 5607 | p_size = QUIC_ARRAYSIZE(packet99); |
| 5608 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 5609 | p = packet46; |
| 5610 | p_size = QUIC_ARRAYSIZE(packet46); |
| 5611 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5612 | p = packet44; |
| 5613 | p_size = QUIC_ARRAYSIZE(packet44); |
| 5614 | } |
| 5615 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 5616 | |
| 5617 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 5618 | data->length(), AsChars(p), p_size); |
| 5619 | } |
| 5620 | |
| 5621 | TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) { |
| 5622 | QuicPacketHeader header; |
| 5623 | header.destination_connection_id = FramerTestConnectionId(); |
| 5624 | header.reset_flag = false; |
| 5625 | header.version_flag = false; |
| 5626 | header.packet_number_length = PACKET_4BYTE_PACKET_NUMBER; |
| 5627 | header.packet_number = kPacketNumber; |
| 5628 | |
| 5629 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 5630 | |
| 5631 | // clang-format off |
| 5632 | unsigned char packet[kMaxPacketSize] = { |
| 5633 | // public flags (8 byte connection_id and 4 byte packet number) |
| 5634 | 0x28, |
| 5635 | // connection_id |
| 5636 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5637 | // packet number |
| 5638 | 0x12, 0x34, 0x56, 0x78, |
| 5639 | |
| 5640 | // frame type (padding frame) |
| 5641 | 0x00, |
| 5642 | 0x00, 0x00, 0x00, 0x00 |
| 5643 | }; |
| 5644 | |
| 5645 | unsigned char packet44[kMaxPacketSize] = { |
| 5646 | // type (short header, 4 byte packet number) |
| 5647 | 0x32, |
| 5648 | // connection_id |
| 5649 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5650 | // packet number |
| 5651 | 0x12, 0x34, 0x56, 0x78, |
| 5652 | |
| 5653 | // frame type (padding frame) |
| 5654 | 0x00, |
| 5655 | 0x00, 0x00, 0x00, 0x00 |
| 5656 | }; |
| 5657 | |
| 5658 | unsigned char packet46[kMaxPacketSize] = { |
| 5659 | // type (short header, 4 byte packet number) |
| 5660 | 0x43, |
| 5661 | // connection_id |
| 5662 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5663 | // packet number |
| 5664 | 0x12, 0x34, 0x56, 0x78, |
| 5665 | |
| 5666 | // frame type (padding frame) |
| 5667 | 0x00, |
| 5668 | 0x00, 0x00, 0x00, 0x00 |
| 5669 | }; |
| 5670 | |
| 5671 | unsigned char packet99[kMaxPacketSize] = { |
| 5672 | // type (short header, 4 byte packet number) |
| 5673 | 0x43, |
| 5674 | // connection_id |
| 5675 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5676 | // packet number |
| 5677 | 0x12, 0x34, 0x56, 0x78, |
| 5678 | |
| 5679 | // frame type (padding frame) |
| 5680 | 0x00, |
| 5681 | 0x00, 0x00, 0x00, 0x00 |
| 5682 | }; |
| 5683 | // clang-format on |
| 5684 | |
| 5685 | unsigned char* p = packet; |
| 5686 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5687 | p = packet99; |
| 5688 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 5689 | p = packet46; |
| 5690 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5691 | p = packet44; |
| 5692 | } |
| 5693 | |
| 5694 | uint64_t header_size = GetPacketHeaderSize( |
| 5695 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 5696 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 5697 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 5698 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
| 5699 | memset(p + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); |
| 5700 | |
| 5701 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5702 | ASSERT_TRUE(data != nullptr); |
| 5703 | |
| 5704 | test::CompareCharArraysWithHexError( |
| 5705 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 5706 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 5707 | : QUIC_ARRAYSIZE(packet)); |
| 5708 | } |
| 5709 | |
| 5710 | TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) { |
| 5711 | QuicPacketHeader header; |
| 5712 | header.destination_connection_id = FramerTestConnectionId(); |
| 5713 | header.reset_flag = false; |
| 5714 | header.version_flag = false; |
| 5715 | header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER; |
| 5716 | header.packet_number = kPacketNumber; |
| 5717 | |
| 5718 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 5719 | |
| 5720 | // clang-format off |
| 5721 | unsigned char packet[kMaxPacketSize] = { |
| 5722 | // public flags (8 byte connection_id and 2 byte packet number) |
| 5723 | 0x18, |
| 5724 | // connection_id |
| 5725 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5726 | // packet number |
| 5727 | 0x56, 0x78, |
| 5728 | |
| 5729 | // frame type (padding frame) |
| 5730 | 0x00, |
| 5731 | 0x00, 0x00, 0x00, 0x00 |
| 5732 | }; |
| 5733 | |
| 5734 | unsigned char packet44[kMaxPacketSize] = { |
| 5735 | // type (short header, 2 byte packet number) |
| 5736 | 0x31, |
| 5737 | // connection_id |
| 5738 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5739 | // packet number |
| 5740 | 0x56, 0x78, |
| 5741 | |
| 5742 | // frame type (padding frame) |
| 5743 | 0x00, |
| 5744 | 0x00, 0x00, 0x00, 0x00 |
| 5745 | }; |
| 5746 | |
| 5747 | unsigned char packet46[kMaxPacketSize] = { |
| 5748 | // type (short header, 2 byte packet number) |
| 5749 | 0x41, |
| 5750 | // connection_id |
| 5751 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5752 | // packet number |
| 5753 | 0x56, 0x78, |
| 5754 | |
| 5755 | // frame type (padding frame) |
| 5756 | 0x00, |
| 5757 | 0x00, 0x00, 0x00, 0x00 |
| 5758 | }; |
| 5759 | |
| 5760 | unsigned char packet99[kMaxPacketSize] = { |
| 5761 | // type (short header, 2 byte packet number) |
| 5762 | 0x41, |
| 5763 | // connection_id |
| 5764 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5765 | // packet number |
| 5766 | 0x56, 0x78, |
| 5767 | |
| 5768 | // frame type (padding frame) |
| 5769 | 0x00, |
| 5770 | 0x00, 0x00, 0x00, 0x00 |
| 5771 | }; |
| 5772 | // clang-format on |
| 5773 | |
| 5774 | unsigned char* p = packet; |
| 5775 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5776 | p = packet99; |
| 5777 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 5778 | p = packet46; |
| 5779 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5780 | p = packet44; |
| 5781 | } |
| 5782 | |
| 5783 | uint64_t header_size = GetPacketHeaderSize( |
| 5784 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 5785 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 5786 | !kIncludeDiversificationNonce, PACKET_2BYTE_PACKET_NUMBER, |
| 5787 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
| 5788 | memset(p + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); |
| 5789 | |
| 5790 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5791 | ASSERT_TRUE(data != nullptr); |
| 5792 | |
| 5793 | test::CompareCharArraysWithHexError( |
| 5794 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 5795 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 5796 | : QUIC_ARRAYSIZE(packet)); |
| 5797 | } |
| 5798 | |
| 5799 | TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) { |
| 5800 | QuicPacketHeader header; |
| 5801 | header.destination_connection_id = FramerTestConnectionId(); |
| 5802 | header.reset_flag = false; |
| 5803 | header.version_flag = false; |
| 5804 | header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
| 5805 | header.packet_number = kPacketNumber; |
| 5806 | |
| 5807 | QuicFrames frames = {QuicFrame(QuicPaddingFrame())}; |
| 5808 | |
| 5809 | // clang-format off |
| 5810 | unsigned char packet[kMaxPacketSize] = { |
| 5811 | // public flags (8 byte connection_id and 1 byte packet number) |
| 5812 | 0x08, |
| 5813 | // connection_id |
| 5814 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5815 | // packet number |
| 5816 | 0x78, |
| 5817 | |
| 5818 | // frame type (padding frame) |
| 5819 | 0x00, |
| 5820 | 0x00, 0x00, 0x00, 0x00 |
| 5821 | }; |
| 5822 | |
| 5823 | unsigned char packet44[kMaxPacketSize] = { |
| 5824 | // type (short header, 1 byte packet number) |
| 5825 | 0x30, |
| 5826 | // connection_id |
| 5827 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5828 | // packet number |
| 5829 | 0x78, |
| 5830 | |
| 5831 | // frame type (padding frame) |
| 5832 | 0x00, |
| 5833 | 0x00, 0x00, 0x00, 0x00 |
| 5834 | }; |
| 5835 | |
| 5836 | unsigned char packet46[kMaxPacketSize] = { |
| 5837 | // type (short header, 1 byte packet number) |
| 5838 | 0x40, |
| 5839 | // connection_id |
| 5840 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5841 | // packet number |
| 5842 | 0x78, |
| 5843 | |
| 5844 | // frame type (padding frame) |
| 5845 | 0x00, |
| 5846 | 0x00, 0x00, 0x00, 0x00 |
| 5847 | }; |
| 5848 | |
| 5849 | unsigned char packet99[kMaxPacketSize] = { |
| 5850 | // type (short header, 1 byte packet number) |
| 5851 | 0x40, |
| 5852 | // connection_id |
| 5853 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5854 | // packet number |
| 5855 | 0x78, |
| 5856 | |
| 5857 | // frame type (padding frame) |
| 5858 | 0x00, |
| 5859 | 0x00, 0x00, 0x00, 0x00 |
| 5860 | }; |
| 5861 | // clang-format on |
| 5862 | |
| 5863 | unsigned char* p = packet; |
| 5864 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5865 | p = packet99; |
| 5866 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 5867 | p = packet46; |
| 5868 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 5869 | p = packet44; |
| 5870 | } |
| 5871 | |
| 5872 | uint64_t header_size = GetPacketHeaderSize( |
| 5873 | framer_.transport_version(), PACKET_8BYTE_CONNECTION_ID, |
| 5874 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 5875 | !kIncludeDiversificationNonce, PACKET_1BYTE_PACKET_NUMBER, |
| 5876 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0); |
| 5877 | memset(p + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); |
| 5878 | |
| 5879 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5880 | ASSERT_TRUE(data != nullptr); |
| 5881 | |
| 5882 | test::CompareCharArraysWithHexError( |
| 5883 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 5884 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 5885 | : QUIC_ARRAYSIZE(packet)); |
| 5886 | } |
| 5887 | |
| 5888 | TEST_P(QuicFramerTest, BuildStreamFramePacket) { |
| 5889 | QuicPacketHeader header; |
| 5890 | header.destination_connection_id = FramerTestConnectionId(); |
| 5891 | header.reset_flag = false; |
| 5892 | header.version_flag = false; |
| 5893 | header.packet_number = kPacketNumber; |
| 5894 | if (QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 5895 | header.length_length = VARIABLE_LENGTH_INTEGER_LENGTH_2; |
| 5896 | } |
| 5897 | |
| 5898 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
| 5899 | QuicStringPiece("hello world!")); |
| 5900 | |
| 5901 | QuicFrames frames = {QuicFrame(stream_frame)}; |
| 5902 | |
| 5903 | // clang-format off |
| 5904 | unsigned char packet[] = { |
| 5905 | // public flags (8 byte connection_id) |
| 5906 | 0x28, |
| 5907 | // connection_id |
| 5908 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5909 | // packet number |
| 5910 | 0x12, 0x34, 0x56, 0x78, |
| 5911 | |
| 5912 | // frame type (stream frame with fin and no length) |
| 5913 | 0xDF, |
| 5914 | // stream id |
| 5915 | 0x01, 0x02, 0x03, 0x04, |
| 5916 | // offset |
| 5917 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5918 | 0x32, 0x10, 0x76, 0x54, |
| 5919 | // data |
| 5920 | 'h', 'e', 'l', 'l', |
| 5921 | 'o', ' ', 'w', 'o', |
| 5922 | 'r', 'l', 'd', '!', |
| 5923 | }; |
| 5924 | |
| 5925 | unsigned char packet44[] = { |
| 5926 | // type (short header, 4 byte packet number) |
| 5927 | 0x32, |
| 5928 | // connection_id |
| 5929 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5930 | // packet number |
| 5931 | 0x12, 0x34, 0x56, 0x78, |
| 5932 | |
| 5933 | // frame type (stream frame with fin and no length) |
| 5934 | 0xDF, |
| 5935 | // stream id |
| 5936 | 0x01, 0x02, 0x03, 0x04, |
| 5937 | // offset |
| 5938 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5939 | 0x32, 0x10, 0x76, 0x54, |
| 5940 | // data |
| 5941 | 'h', 'e', 'l', 'l', |
| 5942 | 'o', ' ', 'w', 'o', |
| 5943 | 'r', 'l', 'd', '!', |
| 5944 | }; |
| 5945 | |
| 5946 | unsigned char packet46[] = { |
| 5947 | // type (short header, 4 byte packet number) |
| 5948 | 0x43, |
| 5949 | // connection_id |
| 5950 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5951 | // packet number |
| 5952 | 0x12, 0x34, 0x56, 0x78, |
| 5953 | |
| 5954 | // frame type (stream frame with fin and no length) |
| 5955 | 0xDF, |
| 5956 | // stream id |
| 5957 | 0x01, 0x02, 0x03, 0x04, |
| 5958 | // offset |
| 5959 | 0x3A, 0x98, 0xFE, 0xDC, |
| 5960 | 0x32, 0x10, 0x76, 0x54, |
| 5961 | // data |
| 5962 | 'h', 'e', 'l', 'l', |
| 5963 | 'o', ' ', 'w', 'o', |
| 5964 | 'r', 'l', 'd', '!', |
| 5965 | }; |
| 5966 | |
| 5967 | unsigned char packet99[] = { |
| 5968 | // type (short header, 4 byte packet number) |
| 5969 | 0x43, |
| 5970 | // connection_id |
| 5971 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 5972 | // packet number |
| 5973 | 0x12, 0x34, 0x56, 0x78, |
| 5974 | |
| 5975 | // frame type (IETF_STREAM frame with FIN and OFFSET, no length) |
| 5976 | 0x08 | 0x01 | 0x04, |
| 5977 | // stream id |
| 5978 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 5979 | // offset |
| 5980 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 5981 | 0x32, 0x10, 0x76, 0x54, |
| 5982 | // data |
| 5983 | 'h', 'e', 'l', 'l', |
| 5984 | 'o', ' ', 'w', 'o', |
| 5985 | 'r', 'l', 'd', '!', |
| 5986 | }; |
| 5987 | // clang-format on |
| 5988 | |
| 5989 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 5990 | ASSERT_TRUE(data != nullptr); |
| 5991 | |
| 5992 | unsigned char* p = packet; |
| 5993 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 5994 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 5995 | p = packet99; |
| 5996 | p_size = QUIC_ARRAYSIZE(packet99); |
| 5997 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 5998 | p = packet46; |
| 5999 | p_size = QUIC_ARRAYSIZE(packet46); |
| 6000 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6001 | p = packet44; |
| 6002 | p_size = QUIC_ARRAYSIZE(packet44); |
| 6003 | } |
| 6004 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6005 | data->length(), AsChars(p), p_size); |
| 6006 | } |
| 6007 | |
| 6008 | TEST_P(QuicFramerTest, BuildStreamFramePacketWithVersionFlag) { |
| 6009 | QuicPacketHeader header; |
| 6010 | header.destination_connection_id = FramerTestConnectionId(); |
| 6011 | header.reset_flag = false; |
| 6012 | header.version_flag = true; |
| 6013 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6014 | header.long_packet_type = ZERO_RTT_PROTECTED; |
| 6015 | } |
| 6016 | header.packet_number = kPacketNumber; |
| 6017 | if (QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 6018 | header.length_length = VARIABLE_LENGTH_INTEGER_LENGTH_2; |
| 6019 | } |
| 6020 | |
| 6021 | QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
| 6022 | QuicStringPiece("hello world!")); |
| 6023 | QuicFrames frames = {QuicFrame(stream_frame)}; |
| 6024 | |
| 6025 | // clang-format off |
| 6026 | unsigned char packet[] = { |
| 6027 | // public flags (version, 8 byte connection_id) |
| 6028 | 0x2D, |
| 6029 | // connection_id |
| 6030 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6031 | // version tag |
| 6032 | QUIC_VERSION_BYTES, |
| 6033 | // packet number |
| 6034 | 0x12, 0x34, 0x56, 0x78, |
| 6035 | |
| 6036 | // frame type (stream frame with fin and no length) |
| 6037 | 0xDF, |
| 6038 | // stream id |
| 6039 | 0x01, 0x02, 0x03, 0x04, |
| 6040 | // offset |
| 6041 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6042 | // data |
| 6043 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6044 | }; |
| 6045 | |
| 6046 | unsigned char packet44[] = { |
| 6047 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 6048 | 0xFC, |
| 6049 | // version tag |
| 6050 | QUIC_VERSION_BYTES, |
| 6051 | // connection_id length |
| 6052 | 0x50, |
| 6053 | // connection_id |
| 6054 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6055 | // packet number |
| 6056 | 0x12, 0x34, 0x56, 0x78, |
| 6057 | |
| 6058 | // frame type (stream frame with fin and no length) |
| 6059 | 0xDF, |
| 6060 | // stream id |
| 6061 | 0x01, 0x02, 0x03, 0x04, |
| 6062 | // offset |
| 6063 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6064 | // data |
| 6065 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6066 | }; |
| 6067 | |
| 6068 | unsigned char packet46[] = { |
| 6069 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 6070 | 0xD3, |
| 6071 | // version tag |
| 6072 | QUIC_VERSION_BYTES, |
| 6073 | // connection_id length |
| 6074 | 0x50, |
| 6075 | // connection_id |
| 6076 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6077 | // packet number |
| 6078 | 0x12, 0x34, 0x56, 0x78, |
| 6079 | |
| 6080 | // frame type (stream frame with fin and no length) |
| 6081 | 0xDF, |
| 6082 | // stream id |
| 6083 | 0x01, 0x02, 0x03, 0x04, |
| 6084 | // offset |
| 6085 | 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6086 | // data |
| 6087 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6088 | }; |
| 6089 | |
| 6090 | unsigned char packet99[] = { |
| 6091 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 6092 | 0xD3, |
| 6093 | // version tag |
| 6094 | QUIC_VERSION_BYTES, |
| 6095 | // connection_id length |
| 6096 | 0x50, |
| 6097 | // connection_id |
| 6098 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6099 | // length |
| 6100 | 0x40, 0x1D, |
| 6101 | // packet number |
| 6102 | 0x12, 0x34, 0x56, 0x78, |
| 6103 | |
| 6104 | // frame type (IETF_STREAM frame with fin and offset, no length) |
| 6105 | 0x08 | 0x01 | 0x04, |
| 6106 | // stream id |
| 6107 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 6108 | // offset |
| 6109 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54, |
| 6110 | // data |
| 6111 | 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', |
| 6112 | }; |
| 6113 | // clang-format on |
| 6114 | |
| 6115 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 6116 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6117 | ASSERT_TRUE(data != nullptr); |
| 6118 | |
| 6119 | unsigned char* p = packet; |
| 6120 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6121 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6122 | p = packet99; |
| 6123 | p_size = QUIC_ARRAYSIZE(packet99); |
| 6124 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 6125 | p = packet46; |
| 6126 | p_size = QUIC_ARRAYSIZE(packet46); |
| 6127 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6128 | p = packet44; |
| 6129 | p_size = QUIC_ARRAYSIZE(packet44); |
| 6130 | } |
| 6131 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6132 | data->length(), AsChars(p), p_size); |
| 6133 | } |
| 6134 | |
| 6135 | TEST_P(QuicFramerTest, BuildCryptoFramePacket) { |
| 6136 | if (framer_.transport_version() < QUIC_VERSION_99) { |
| 6137 | // CRYPTO frames aren't supported prior to v46. |
| 6138 | return; |
| 6139 | } |
| 6140 | QuicPacketHeader header; |
| 6141 | header.destination_connection_id = FramerTestConnectionId(); |
| 6142 | header.reset_flag = false; |
| 6143 | header.version_flag = false; |
| 6144 | header.packet_number = kPacketNumber; |
| 6145 | |
| 6146 | SimpleDataProducer data_producer; |
| 6147 | framer_.set_data_producer(&data_producer); |
| 6148 | |
| 6149 | QuicStringPiece crypto_frame_contents("hello world!"); |
| 6150 | QuicCryptoFrame crypto_frame(ENCRYPTION_NONE, kStreamOffset, |
| 6151 | crypto_frame_contents.length()); |
| 6152 | data_producer.SaveCryptoData(ENCRYPTION_NONE, kStreamOffset, |
| 6153 | crypto_frame_contents); |
| 6154 | |
| 6155 | QuicFrames frames = {QuicFrame(&crypto_frame)}; |
| 6156 | |
| 6157 | // clang-format off |
| 6158 | unsigned char packet[] = { |
| 6159 | // type (short header, 4 byte packet number) |
| 6160 | 0x43, |
| 6161 | // connection_id |
| 6162 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6163 | // packet number |
| 6164 | 0x12, 0x34, 0x56, 0x78, |
| 6165 | |
| 6166 | // frame type (IETF_CRYPTO frame) |
| 6167 | 0x06, |
| 6168 | // offset |
| 6169 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6170 | 0x32, 0x10, 0x76, 0x54, |
| 6171 | // length |
| 6172 | kVarInt62OneByte + 12, |
| 6173 | // data |
| 6174 | 'h', 'e', 'l', 'l', |
| 6175 | 'o', ' ', 'w', 'o', |
| 6176 | 'r', 'l', 'd', '!', |
| 6177 | }; |
| 6178 | // clang-format on |
| 6179 | |
| 6180 | size_t packet_size = QUIC_ARRAYSIZE(packet); |
| 6181 | |
| 6182 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6183 | ASSERT_TRUE(data != nullptr); |
| 6184 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6185 | data->length(), AsChars(packet), |
| 6186 | packet_size); |
| 6187 | } |
| 6188 | |
| 6189 | TEST_P(QuicFramerTest, CryptoFrame) { |
| 6190 | if (framer_.transport_version() < QUIC_VERSION_99) { |
| 6191 | // CRYPTO frames aren't supported prior to v46. |
| 6192 | return; |
| 6193 | } |
| 6194 | |
| 6195 | // clang-format off |
| 6196 | PacketFragments packet = { |
| 6197 | // type (short header, 4 byte packet number) |
| 6198 | {"", |
| 6199 | {0x43}}, |
| 6200 | // connection_id |
| 6201 | {"", |
| 6202 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 6203 | // packet number |
| 6204 | {"", |
| 6205 | {0x12, 0x34, 0x56, 0x78}}, |
| 6206 | // frame type (IETF_CRYPTO frame) |
| 6207 | {"", |
| 6208 | {0x06}}, |
| 6209 | // offset |
| 6210 | {"", |
| 6211 | {kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 6212 | 0x32, 0x10, 0x76, 0x54}}, |
| 6213 | // data length |
| 6214 | {"Invalid data length.", |
| 6215 | {kVarInt62OneByte + 12}}, |
| 6216 | // data |
| 6217 | {"Unable to read frame data.", |
| 6218 | {'h', 'e', 'l', 'l', |
| 6219 | 'o', ' ', 'w', 'o', |
| 6220 | 'r', 'l', 'd', '!'}}, |
| 6221 | }; |
| 6222 | // clang-format on |
| 6223 | |
| 6224 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 6225 | AssemblePacketFromFragments(packet)); |
| 6226 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 6227 | |
| 6228 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 6229 | ASSERT_TRUE(visitor_.header_.get()); |
| 6230 | EXPECT_TRUE(CheckDecryption( |
| 6231 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 6232 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 6233 | ASSERT_EQ(1u, visitor_.crypto_frames_.size()); |
| 6234 | QuicCryptoFrame* frame = visitor_.crypto_frames_[0].get(); |
| 6235 | EXPECT_EQ(kStreamOffset, frame->offset); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 6236 | EXPECT_EQ("hello world!", |
| 6237 | std::string(frame->data_buffer, frame->data_length)); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 6238 | |
| 6239 | CheckFramingBoundaries(packet, QUIC_INVALID_FRAME_DATA); |
| 6240 | } |
| 6241 | |
| 6242 | TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) { |
| 6243 | // clang-format off |
| 6244 | unsigned char packet[] = { |
| 6245 | // public flags (version, 8 byte connection_id) |
| 6246 | 0x0D, |
| 6247 | // connection_id |
| 6248 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6249 | // version tag |
| 6250 | QUIC_VERSION_BYTES, |
| 6251 | }; |
| 6252 | unsigned char packet44[] = { |
| 6253 | // type (long header) |
| 6254 | 0x80, |
| 6255 | // version tag |
| 6256 | 0x00, 0x00, 0x00, 0x00, |
| 6257 | // connection_id length |
| 6258 | 0x05, |
| 6259 | // connection_id |
| 6260 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6261 | // version tag |
| 6262 | QUIC_VERSION_BYTES, |
| 6263 | }; |
| 6264 | // clang-format on |
| 6265 | unsigned char* p = packet; |
| 6266 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6267 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6268 | p = packet44; |
| 6269 | p_size = QUIC_ARRAYSIZE(packet44); |
| 6270 | } |
| 6271 | |
| 6272 | QuicConnectionId connection_id = FramerTestConnectionId(); |
| 6273 | std::unique_ptr<QuicEncryptedPacket> data( |
| 6274 | framer_.BuildVersionNegotiationPacket( |
| 6275 | connection_id, framer_.transport_version() > QUIC_VERSION_43, |
| 6276 | SupportedVersions(GetParam()))); |
| 6277 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6278 | data->length(), AsChars(p), p_size); |
| 6279 | } |
| 6280 | |
| 6281 | TEST_P(QuicFramerTest, BuildAckFramePacketOneAckBlock) { |
| 6282 | QuicPacketHeader header; |
| 6283 | header.destination_connection_id = FramerTestConnectionId(); |
| 6284 | header.reset_flag = false; |
| 6285 | header.version_flag = false; |
| 6286 | header.packet_number = kPacketNumber; |
| 6287 | |
| 6288 | // Use kSmallLargestObserved to make this test finished in a short time. |
| 6289 | QuicAckFrame ack_frame = InitAckFrame(kSmallLargestObserved); |
| 6290 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 6291 | |
| 6292 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 6293 | |
| 6294 | // clang-format off |
| 6295 | unsigned char packet[] = { |
| 6296 | // public flags (8 byte connection_id) |
| 6297 | 0x28, |
| 6298 | // connection_id |
| 6299 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6300 | // packet number |
| 6301 | 0x12, 0x34, 0x56, 0x78, |
| 6302 | |
| 6303 | // frame type (ack frame) |
| 6304 | // (no ack blocks, 2 byte largest observed, 2 byte block length) |
| 6305 | 0x45, |
| 6306 | // largest acked |
| 6307 | 0x12, 0x34, |
| 6308 | // Zero delta time. |
| 6309 | 0x00, 0x00, |
| 6310 | // first ack block length. |
| 6311 | 0x12, 0x34, |
| 6312 | // num timestamps. |
| 6313 | 0x00, |
| 6314 | }; |
| 6315 | |
| 6316 | unsigned char packet44[] = { |
| 6317 | // type (short header, 4 byte packet number) |
| 6318 | 0x32, |
| 6319 | // connection_id |
| 6320 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6321 | // packet number |
| 6322 | 0x12, 0x34, 0x56, 0x78, |
| 6323 | |
| 6324 | // frame type (ack frame) |
| 6325 | // (no ack blocks, 2 byte largest observed, 2 byte block length) |
| 6326 | 0x45, |
| 6327 | // largest acked |
| 6328 | 0x12, 0x34, |
| 6329 | // Zero delta time. |
| 6330 | 0x00, 0x00, |
| 6331 | // first ack block length. |
| 6332 | 0x12, 0x34, |
| 6333 | // num timestamps. |
| 6334 | 0x00, |
| 6335 | }; |
| 6336 | |
| 6337 | unsigned char packet46[] = { |
| 6338 | // type (short header, 4 byte packet number) |
| 6339 | 0x43, |
| 6340 | // connection_id |
| 6341 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6342 | // packet number |
| 6343 | 0x12, 0x34, 0x56, 0x78, |
| 6344 | |
| 6345 | // frame type (ack frame) |
| 6346 | // (no ack blocks, 2 byte largest observed, 2 byte block length) |
| 6347 | 0x45, |
| 6348 | // largest acked |
| 6349 | 0x12, 0x34, |
| 6350 | // Zero delta time. |
| 6351 | 0x00, 0x00, |
| 6352 | // first ack block length. |
| 6353 | 0x12, 0x34, |
| 6354 | // num timestamps. |
| 6355 | 0x00, |
| 6356 | }; |
| 6357 | |
| 6358 | unsigned char packet99[] = { |
| 6359 | // type (short header, 4 byte packet number) |
| 6360 | 0x43, |
| 6361 | // connection_id |
| 6362 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6363 | // packet number |
| 6364 | 0x12, 0x34, 0x56, 0x78, |
| 6365 | |
| 6366 | // frame type (IETF_ACK frame) |
| 6367 | 0x02, |
| 6368 | // largest acked |
| 6369 | kVarInt62TwoBytes + 0x12, 0x34, |
| 6370 | // Zero delta time. |
| 6371 | kVarInt62OneByte + 0x00, |
| 6372 | // Number of additional ack blocks. |
| 6373 | kVarInt62OneByte + 0x00, |
| 6374 | // first ack block length. |
| 6375 | kVarInt62TwoBytes + 0x12, 0x33, |
| 6376 | }; |
| 6377 | // clang-format on |
| 6378 | unsigned char* p = packet; |
| 6379 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6380 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6381 | p = packet99; |
| 6382 | p_size = QUIC_ARRAYSIZE(packet99); |
| 6383 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 6384 | p = packet46; |
| 6385 | p_size = QUIC_ARRAYSIZE(packet46); |
| 6386 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6387 | p = packet44; |
| 6388 | p_size = QUIC_ARRAYSIZE(packet44); |
| 6389 | } |
| 6390 | |
| 6391 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6392 | ASSERT_TRUE(data != nullptr); |
| 6393 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6394 | data->length(), AsChars(p), p_size); |
| 6395 | } |
| 6396 | |
| 6397 | TEST_P(QuicFramerTest, BuildAckFramePacketOneAckBlockMaxLength) { |
| 6398 | QuicPacketHeader header; |
| 6399 | header.destination_connection_id = FramerTestConnectionId(); |
| 6400 | header.reset_flag = false; |
| 6401 | header.version_flag = false; |
| 6402 | header.packet_number = kPacketNumber; |
| 6403 | |
| 6404 | QuicAckFrame ack_frame = InitAckFrame(kPacketNumber); |
| 6405 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 6406 | |
| 6407 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 6408 | |
| 6409 | // clang-format off |
| 6410 | unsigned char packet[] = { |
| 6411 | // public flags (8 byte connection_id) |
| 6412 | 0x28, |
| 6413 | // connection_id |
| 6414 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6415 | // packet number |
| 6416 | 0x12, 0x34, 0x56, 0x78, |
| 6417 | |
| 6418 | // frame type (ack frame) |
| 6419 | // (no ack blocks, 4 byte largest observed, 4 byte block length) |
| 6420 | 0x4A, |
| 6421 | // largest acked |
| 6422 | 0x12, 0x34, 0x56, 0x78, |
| 6423 | // Zero delta time. |
| 6424 | 0x00, 0x00, |
| 6425 | // first ack block length. |
| 6426 | 0x12, 0x34, 0x56, 0x78, |
| 6427 | // num timestamps. |
| 6428 | 0x00, |
| 6429 | }; |
| 6430 | |
| 6431 | unsigned char packet44[] = { |
| 6432 | // type (short header, 4 byte packet number) |
| 6433 | 0x32, |
| 6434 | // connection_id |
| 6435 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6436 | // packet number |
| 6437 | 0x12, 0x34, 0x56, 0x78, |
| 6438 | |
| 6439 | // frame type (ack frame) |
| 6440 | // (no ack blocks, 4 byte largest observed, 4 byte block length) |
| 6441 | 0x4A, |
| 6442 | // largest acked |
| 6443 | 0x12, 0x34, 0x56, 0x78, |
| 6444 | // Zero delta time. |
| 6445 | 0x00, 0x00, |
| 6446 | // first ack block length. |
| 6447 | 0x12, 0x34, 0x56, 0x78, |
| 6448 | // num timestamps. |
| 6449 | 0x00, |
| 6450 | }; |
| 6451 | |
| 6452 | unsigned char packet46[] = { |
| 6453 | // type (short header, 4 byte packet number) |
| 6454 | 0x43, |
| 6455 | // connection_id |
| 6456 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6457 | // packet number |
| 6458 | 0x12, 0x34, 0x56, 0x78, |
| 6459 | |
| 6460 | // frame type (ack frame) |
| 6461 | // (no ack blocks, 4 byte largest observed, 4 byte block length) |
| 6462 | 0x4A, |
| 6463 | // largest acked |
| 6464 | 0x12, 0x34, 0x56, 0x78, |
| 6465 | // Zero delta time. |
| 6466 | 0x00, 0x00, |
| 6467 | // first ack block length. |
| 6468 | 0x12, 0x34, 0x56, 0x78, |
| 6469 | // num timestamps. |
| 6470 | 0x00, |
| 6471 | }; |
| 6472 | |
| 6473 | |
| 6474 | unsigned char packet99[] = { |
| 6475 | // type (short header, 4 byte packet number) |
| 6476 | 0x43, |
| 6477 | // connection_id |
| 6478 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6479 | // packet number |
| 6480 | 0x12, 0x34, 0x56, 0x78, |
| 6481 | |
| 6482 | // frame type (IETF_ACK frame) |
| 6483 | 0x02, |
| 6484 | // largest acked |
| 6485 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78, |
| 6486 | // Zero delta time. |
| 6487 | kVarInt62OneByte + 0x00, |
| 6488 | // Nr. of additional ack blocks |
| 6489 | kVarInt62OneByte + 0x00, |
| 6490 | // first ack block length. |
| 6491 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x77, |
| 6492 | }; |
| 6493 | // clang-format on |
| 6494 | unsigned char* p = packet; |
| 6495 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6496 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6497 | p = packet99; |
| 6498 | p_size = QUIC_ARRAYSIZE(packet99); |
| 6499 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 6500 | p = packet46; |
| 6501 | p_size = QUIC_ARRAYSIZE(packet46); |
| 6502 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6503 | p = packet44; |
| 6504 | p_size = QUIC_ARRAYSIZE(packet44); |
| 6505 | } |
| 6506 | |
| 6507 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6508 | ASSERT_TRUE(data != nullptr); |
| 6509 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6510 | data->length(), AsChars(p), p_size); |
| 6511 | } |
| 6512 | |
| 6513 | TEST_P(QuicFramerTest, BuildAckFramePacketMultipleAckBlocks) { |
| 6514 | QuicPacketHeader header; |
| 6515 | header.destination_connection_id = FramerTestConnectionId(); |
| 6516 | header.reset_flag = false; |
| 6517 | header.version_flag = false; |
| 6518 | header.packet_number = kPacketNumber; |
| 6519 | |
| 6520 | // Use kSmallLargestObserved to make this test finished in a short time. |
| 6521 | QuicAckFrame ack_frame = |
| 6522 | InitAckFrame({{QuicPacketNumber(1), QuicPacketNumber(5)}, |
| 6523 | {QuicPacketNumber(10), QuicPacketNumber(500)}, |
| 6524 | {QuicPacketNumber(900), kSmallMissingPacket}, |
| 6525 | {kSmallMissingPacket + 1, kSmallLargestObserved + 1}}); |
| 6526 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 6527 | |
| 6528 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 6529 | |
| 6530 | // clang-format off |
| 6531 | unsigned char packet[] = { |
| 6532 | // public flags (8 byte connection_id) |
| 6533 | 0x28, |
| 6534 | // connection_id |
| 6535 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6536 | // packet number |
| 6537 | 0x12, 0x34, 0x56, 0x78, |
| 6538 | |
| 6539 | // frame type (ack frame) |
| 6540 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 6541 | 0x65, |
| 6542 | // largest acked |
| 6543 | 0x12, 0x34, |
| 6544 | // Zero delta time. |
| 6545 | 0x00, 0x00, |
| 6546 | // num ack blocks ranges. |
| 6547 | 0x04, |
| 6548 | // first ack block length. |
| 6549 | 0x00, 0x01, |
| 6550 | // gap to next block. |
| 6551 | 0x01, |
| 6552 | // ack block length. |
| 6553 | 0x0e, 0xaf, |
| 6554 | // gap to next block. |
| 6555 | 0xff, |
| 6556 | // ack block length. |
| 6557 | 0x00, 0x00, |
| 6558 | // gap to next block. |
| 6559 | 0x91, |
| 6560 | // ack block length. |
| 6561 | 0x01, 0xea, |
| 6562 | // gap to next block. |
| 6563 | 0x05, |
| 6564 | // ack block length. |
| 6565 | 0x00, 0x04, |
| 6566 | // num timestamps. |
| 6567 | 0x00, |
| 6568 | }; |
| 6569 | |
| 6570 | unsigned char packet44[] = { |
| 6571 | // type (short header, 4 byte packet number) |
| 6572 | 0x32, |
| 6573 | // connection_id |
| 6574 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6575 | // packet number |
| 6576 | 0x12, 0x34, 0x56, 0x78, |
| 6577 | |
| 6578 | // frame type (ack frame) |
| 6579 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 6580 | 0x65, |
| 6581 | // largest acked |
| 6582 | 0x12, 0x34, |
| 6583 | // Zero delta time. |
| 6584 | 0x00, 0x00, |
| 6585 | // num ack blocks ranges. |
| 6586 | 0x04, |
| 6587 | // first ack block length. |
| 6588 | 0x00, 0x01, |
| 6589 | // gap to next block. |
| 6590 | 0x01, |
| 6591 | // ack block length. |
| 6592 | 0x0e, 0xaf, |
| 6593 | // gap to next block. |
| 6594 | 0xff, |
| 6595 | // ack block length. |
| 6596 | 0x00, 0x00, |
| 6597 | // gap to next block. |
| 6598 | 0x91, |
| 6599 | // ack block length. |
| 6600 | 0x01, 0xea, |
| 6601 | // gap to next block. |
| 6602 | 0x05, |
| 6603 | // ack block length. |
| 6604 | 0x00, 0x04, |
| 6605 | // num timestamps. |
| 6606 | 0x00, |
| 6607 | }; |
| 6608 | |
| 6609 | unsigned char packet46[] = { |
| 6610 | // type (short header, 4 byte packet number) |
| 6611 | 0x43, |
| 6612 | // connection_id |
| 6613 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6614 | // packet number |
| 6615 | 0x12, 0x34, 0x56, 0x78, |
| 6616 | |
| 6617 | // frame type (ack frame) |
| 6618 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 6619 | 0x65, |
| 6620 | // largest acked |
| 6621 | 0x12, 0x34, |
| 6622 | // Zero delta time. |
| 6623 | 0x00, 0x00, |
| 6624 | // num ack blocks ranges. |
| 6625 | 0x04, |
| 6626 | // first ack block length. |
| 6627 | 0x00, 0x01, |
| 6628 | // gap to next block. |
| 6629 | 0x01, |
| 6630 | // ack block length. |
| 6631 | 0x0e, 0xaf, |
| 6632 | // gap to next block. |
| 6633 | 0xff, |
| 6634 | // ack block length. |
| 6635 | 0x00, 0x00, |
| 6636 | // gap to next block. |
| 6637 | 0x91, |
| 6638 | // ack block length. |
| 6639 | 0x01, 0xea, |
| 6640 | // gap to next block. |
| 6641 | 0x05, |
| 6642 | // ack block length. |
| 6643 | 0x00, 0x04, |
| 6644 | // num timestamps. |
| 6645 | 0x00, |
| 6646 | }; |
| 6647 | |
| 6648 | unsigned char packet99[] = { |
| 6649 | // type (short header, 4 byte packet number) |
| 6650 | 0x43, |
| 6651 | // connection_id |
| 6652 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6653 | // packet number |
| 6654 | 0x12, 0x34, 0x56, 0x78, |
| 6655 | |
| 6656 | // frame type (IETF_ACK frame) |
| 6657 | 0x02, |
| 6658 | // largest acked |
| 6659 | kVarInt62TwoBytes + 0x12, 0x34, |
| 6660 | // Zero delta time. |
| 6661 | kVarInt62OneByte + 0x00, |
| 6662 | // num additional ack blocks. |
| 6663 | kVarInt62OneByte + 0x03, |
| 6664 | // first ack block length. |
| 6665 | kVarInt62OneByte + 0x00, |
| 6666 | |
| 6667 | // gap to next block. |
| 6668 | kVarInt62OneByte + 0x00, |
| 6669 | // ack block length. |
| 6670 | kVarInt62TwoBytes + 0x0e, 0xae, |
| 6671 | |
| 6672 | // gap to next block. |
| 6673 | kVarInt62TwoBytes + 0x01, 0x8f, |
| 6674 | // ack block length. |
| 6675 | kVarInt62TwoBytes + 0x01, 0xe9, |
| 6676 | |
| 6677 | // gap to next block. |
| 6678 | kVarInt62OneByte + 0x04, |
| 6679 | // ack block length. |
| 6680 | kVarInt62OneByte + 0x03, |
| 6681 | }; |
| 6682 | // clang-format on |
| 6683 | unsigned char* p = packet; |
| 6684 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 6685 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 6686 | p = packet99; |
| 6687 | p_size = QUIC_ARRAYSIZE(packet99); |
| 6688 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 6689 | p = packet46; |
| 6690 | p_size = QUIC_ARRAYSIZE(packet46); |
| 6691 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 6692 | p = packet44; |
| 6693 | p_size = QUIC_ARRAYSIZE(packet44); |
| 6694 | } |
| 6695 | |
| 6696 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 6697 | ASSERT_TRUE(data != nullptr); |
| 6698 | |
| 6699 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 6700 | data->length(), AsChars(p), p_size); |
| 6701 | } |
| 6702 | |
| 6703 | TEST_P(QuicFramerTest, BuildAckFramePacketMaxAckBlocks) { |
| 6704 | QuicPacketHeader header; |
| 6705 | header.destination_connection_id = FramerTestConnectionId(); |
| 6706 | header.reset_flag = false; |
| 6707 | header.version_flag = false; |
| 6708 | header.packet_number = kPacketNumber; |
| 6709 | |
| 6710 | // Use kSmallLargestObservedto make this test finished in a short time. |
| 6711 | QuicAckFrame ack_frame; |
| 6712 | ack_frame.largest_acked = kSmallLargestObserved; |
| 6713 | ack_frame.ack_delay_time = QuicTime::Delta::Zero(); |
| 6714 | // 300 ack blocks. |
| 6715 | for (size_t i = 2; i < 2 * 300; i += 2) { |
| 6716 | ack_frame.packets.Add(QuicPacketNumber(i)); |
| 6717 | } |
| 6718 | ack_frame.packets.AddRange(QuicPacketNumber(600), kSmallLargestObserved + 1); |
| 6719 | |
| 6720 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 6721 | |
| 6722 | // clang-format off |
| 6723 | unsigned char packet[] = { |
| 6724 | // public flags (8 byte connection_id) |
| 6725 | 0x28, |
| 6726 | // connection_id |
| 6727 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6728 | // packet number |
| 6729 | 0x12, 0x34, 0x56, 0x78, |
| 6730 | // frame type (ack frame) |
| 6731 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 6732 | 0x65, |
| 6733 | // largest acked |
| 6734 | 0x12, 0x34, |
| 6735 | // Zero delta time. |
| 6736 | 0x00, 0x00, |
| 6737 | // num ack blocks ranges. |
| 6738 | 0xff, |
| 6739 | // first ack block length. |
| 6740 | 0x0f, 0xdd, |
| 6741 | // 255 = 4 * 63 + 3 |
| 6742 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6743 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6744 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6745 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6746 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6747 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6748 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6749 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6750 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6751 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6752 | |
| 6753 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6754 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6755 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6756 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6757 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6758 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6759 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6760 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6761 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6762 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6763 | |
| 6764 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6765 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6766 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6767 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6768 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6769 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6770 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6771 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6772 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6773 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6774 | |
| 6775 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6776 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6777 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6778 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6779 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6780 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6781 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6782 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6783 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6784 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6785 | |
| 6786 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6787 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6788 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6789 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6790 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6791 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6792 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6793 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6794 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6795 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6796 | |
| 6797 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6798 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6799 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6800 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6801 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6802 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6803 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6804 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6805 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6806 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6807 | |
| 6808 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6809 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6810 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6811 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6812 | // num timestamps. |
| 6813 | 0x00, |
| 6814 | }; |
| 6815 | |
| 6816 | unsigned char packet44[] = { |
| 6817 | // type (short header, 4 byte packet number) |
| 6818 | 0x32, |
| 6819 | // connection_id |
| 6820 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6821 | // packet number |
| 6822 | 0x12, 0x34, 0x56, 0x78, |
| 6823 | // frame type (ack frame) |
| 6824 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 6825 | 0x65, |
| 6826 | // largest acked |
| 6827 | 0x12, 0x34, |
| 6828 | // Zero delta time. |
| 6829 | 0x00, 0x00, |
| 6830 | // num ack blocks ranges. |
| 6831 | 0xff, |
| 6832 | // first ack block length. |
| 6833 | 0x0f, 0xdd, |
| 6834 | // 255 = 4 * 63 + 3 |
| 6835 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6836 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6837 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6838 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6839 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6840 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6841 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6842 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6843 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6844 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6845 | |
| 6846 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6847 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6848 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6849 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6850 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6851 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6852 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6853 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6854 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6855 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6856 | |
| 6857 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6858 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6859 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6860 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6861 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6862 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6863 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6864 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6865 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6866 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6867 | |
| 6868 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6869 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6870 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6871 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6872 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6873 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6874 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6875 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6876 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6877 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6878 | |
| 6879 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6880 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6881 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6882 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6883 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6884 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6885 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6886 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6887 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6888 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6889 | |
| 6890 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6891 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6892 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6893 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6894 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6895 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6896 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6897 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6898 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6899 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6900 | |
| 6901 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6902 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6903 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6904 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6905 | // num timestamps. |
| 6906 | 0x00, |
| 6907 | }; |
| 6908 | |
| 6909 | unsigned char packet46[] = { |
| 6910 | // type (short header, 4 byte packet number) |
| 6911 | 0x43, |
| 6912 | // connection_id |
| 6913 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 6914 | // packet number |
| 6915 | 0x12, 0x34, 0x56, 0x78, |
| 6916 | // frame type (ack frame) |
| 6917 | // (has ack blocks, 2 byte largest observed, 2 byte block length) |
| 6918 | 0x65, |
| 6919 | // largest acked |
| 6920 | 0x12, 0x34, |
| 6921 | // Zero delta time. |
| 6922 | 0x00, 0x00, |
| 6923 | // num ack blocks ranges. |
| 6924 | 0xff, |
| 6925 | // first ack block length. |
| 6926 | 0x0f, 0xdd, |
| 6927 | // 255 = 4 * 63 + 3 |
| 6928 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6929 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6930 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6931 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6932 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6933 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6934 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6935 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6936 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6937 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6938 | |
| 6939 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6940 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6941 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6942 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6943 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6944 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6945 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6946 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6947 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6948 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6949 | |
| 6950 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6951 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6952 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6953 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6954 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6955 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6956 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6957 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6958 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6959 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6960 | |
| 6961 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6962 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6963 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6964 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6965 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6966 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6967 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6968 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6969 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6970 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6971 | |
| 6972 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6973 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6974 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6975 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6976 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6977 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6978 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6979 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6980 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6981 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6982 | |
| 6983 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6984 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6985 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6986 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6987 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6988 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6989 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6990 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6991 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6992 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6993 | |
| 6994 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6995 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6996 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6997 | 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, |
| 6998 | // num timestamps. |
| 6999 | 0x00, |
| 7000 | }; |
| 7001 | |
| 7002 | unsigned char packet99[] = { |
| 7003 | // type (short header, 4 byte packet number) |
| 7004 | 0x43, |
| 7005 | // connection_id |
| 7006 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7007 | // packet number |
| 7008 | 0x12, 0x34, 0x56, 0x78, |
| 7009 | // frame type (IETF_ACK frame) |
| 7010 | 0x02, |
| 7011 | // largest acked |
| 7012 | kVarInt62TwoBytes + 0x12, 0x34, |
| 7013 | // Zero delta time. |
| 7014 | kVarInt62OneByte + 0x00, |
| 7015 | // num ack blocks ranges. |
| 7016 | kVarInt62TwoBytes + 0x01, 0x2b, |
| 7017 | // first ack block length. |
| 7018 | kVarInt62TwoBytes + 0x0f, 0xdc, |
| 7019 | // 255 added blocks of gap_size == 1, ack_size == 1 |
| 7020 | #define V99AddedBLOCK kVarInt62OneByte + 0x00, kVarInt62OneByte + 0x00 |
| 7021 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7022 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7023 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7024 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7025 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7026 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7027 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7028 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7029 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7030 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7031 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7032 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7033 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7034 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7035 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7036 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7037 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7038 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7039 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7040 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7041 | |
| 7042 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7043 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7044 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7045 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7046 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7047 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7048 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7049 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7050 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7051 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7052 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7053 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7054 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7055 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7056 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7057 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7058 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7059 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7060 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7061 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7062 | |
| 7063 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7064 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7065 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7066 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7067 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7068 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7069 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7070 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7071 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7072 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7073 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7074 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7075 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7076 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7077 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7078 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7079 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7080 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7081 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7082 | V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, V99AddedBLOCK, |
| 7083 | |
| 7084 | #undef V99AddedBLOCK |
| 7085 | }; |
| 7086 | // clang-format on |
| 7087 | unsigned char* p = packet; |
| 7088 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 7089 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7090 | p = packet99; |
| 7091 | p_size = QUIC_ARRAYSIZE(packet99); |
| 7092 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 7093 | p = packet46; |
| 7094 | p_size = QUIC_ARRAYSIZE(packet46); |
| 7095 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 7096 | p = packet44; |
| 7097 | p_size = QUIC_ARRAYSIZE(packet44); |
| 7098 | } |
| 7099 | |
| 7100 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7101 | ASSERT_TRUE(data != nullptr); |
| 7102 | |
| 7103 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7104 | data->length(), AsChars(p), p_size); |
| 7105 | } |
| 7106 | |
| 7107 | TEST_P(QuicFramerTest, BuildNewStopWaitingPacket) { |
| 7108 | if (version_.transport_version > QUIC_VERSION_43) { |
| 7109 | return; |
| 7110 | } |
| 7111 | QuicPacketHeader header; |
| 7112 | header.destination_connection_id = FramerTestConnectionId(); |
| 7113 | header.reset_flag = false; |
| 7114 | header.version_flag = false; |
| 7115 | header.packet_number = kPacketNumber; |
| 7116 | |
| 7117 | QuicStopWaitingFrame stop_waiting_frame; |
| 7118 | stop_waiting_frame.least_unacked = kLeastUnacked; |
| 7119 | |
| 7120 | QuicFrames frames = {QuicFrame(stop_waiting_frame)}; |
| 7121 | |
| 7122 | // clang-format off |
| 7123 | unsigned char packet[] = { |
| 7124 | // public flags (8 byte connection_id) |
| 7125 | 0x28, |
| 7126 | // connection_id |
| 7127 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7128 | // packet number |
| 7129 | 0x12, 0x34, 0x56, 0x78, |
| 7130 | |
| 7131 | // frame type (stop waiting frame) |
| 7132 | 0x06, |
| 7133 | // least packet number awaiting an ack, delta from packet number. |
| 7134 | 0x00, 0x00, 0x00, 0x08, |
| 7135 | }; |
| 7136 | |
| 7137 | // clang-format on |
| 7138 | |
| 7139 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7140 | ASSERT_TRUE(data != nullptr); |
| 7141 | |
| 7142 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7143 | data->length(), AsChars(packet), |
| 7144 | QUIC_ARRAYSIZE(packet)); |
| 7145 | } |
| 7146 | |
| 7147 | TEST_P(QuicFramerTest, BuildRstFramePacketQuic) { |
| 7148 | QuicPacketHeader header; |
| 7149 | header.destination_connection_id = FramerTestConnectionId(); |
| 7150 | header.reset_flag = false; |
| 7151 | header.version_flag = false; |
| 7152 | header.packet_number = kPacketNumber; |
| 7153 | |
| 7154 | QuicRstStreamFrame rst_frame; |
| 7155 | rst_frame.stream_id = kStreamId; |
| 7156 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7157 | rst_frame.ietf_error_code = 0x01; |
| 7158 | } else { |
| 7159 | rst_frame.error_code = static_cast<QuicRstStreamErrorCode>(0x05060708); |
| 7160 | } |
| 7161 | rst_frame.byte_offset = 0x0807060504030201; |
| 7162 | |
| 7163 | // clang-format off |
| 7164 | unsigned char packet[] = { |
| 7165 | // public flags (8 byte connection_id) |
| 7166 | 0x28, |
| 7167 | // connection_id |
| 7168 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7169 | // packet number |
| 7170 | 0x12, 0x34, 0x56, 0x78, |
| 7171 | |
| 7172 | // frame type (rst stream frame) |
| 7173 | 0x01, |
| 7174 | // stream id |
| 7175 | 0x01, 0x02, 0x03, 0x04, |
| 7176 | // sent byte offset |
| 7177 | 0x08, 0x07, 0x06, 0x05, |
| 7178 | 0x04, 0x03, 0x02, 0x01, |
| 7179 | // error code |
| 7180 | 0x05, 0x06, 0x07, 0x08, |
| 7181 | }; |
| 7182 | |
| 7183 | unsigned char packet44[] = { |
| 7184 | // type (short packet, 4 byte packet number) |
| 7185 | 0x32, |
| 7186 | // connection_id |
| 7187 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7188 | // packet number |
| 7189 | 0x12, 0x34, 0x56, 0x78, |
| 7190 | |
| 7191 | // frame type (rst stream frame) |
| 7192 | 0x01, |
| 7193 | // stream id |
| 7194 | 0x01, 0x02, 0x03, 0x04, |
| 7195 | // sent byte offset |
| 7196 | 0x08, 0x07, 0x06, 0x05, |
| 7197 | 0x04, 0x03, 0x02, 0x01, |
| 7198 | // error code |
| 7199 | 0x05, 0x06, 0x07, 0x08, |
| 7200 | }; |
| 7201 | |
| 7202 | unsigned char packet46[] = { |
| 7203 | // type (short packet, 4 byte packet number) |
| 7204 | 0x43, |
| 7205 | // connection_id |
| 7206 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7207 | // packet number |
| 7208 | 0x12, 0x34, 0x56, 0x78, |
| 7209 | |
| 7210 | // frame type (rst stream frame) |
| 7211 | 0x01, |
| 7212 | // stream id |
| 7213 | 0x01, 0x02, 0x03, 0x04, |
| 7214 | // sent byte offset |
| 7215 | 0x08, 0x07, 0x06, 0x05, |
| 7216 | 0x04, 0x03, 0x02, 0x01, |
| 7217 | // error code |
| 7218 | 0x05, 0x06, 0x07, 0x08, |
| 7219 | }; |
| 7220 | |
| 7221 | unsigned char packet99[] = { |
| 7222 | // type (short packet, 4 byte packet number) |
| 7223 | 0x43, |
| 7224 | // connection_id |
| 7225 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7226 | // packet number |
| 7227 | 0x12, 0x34, 0x56, 0x78, |
| 7228 | |
| 7229 | // frame type (IETF_RST_STREAM frame) |
| 7230 | 0x04, |
| 7231 | // stream id |
| 7232 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 7233 | // error code (not VarInt32 encoded) |
| 7234 | 0x00, 0x01, |
| 7235 | // sent byte offset |
| 7236 | kVarInt62EightBytes + 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 |
| 7237 | }; |
| 7238 | // clang-format on |
| 7239 | |
| 7240 | QuicFrames frames = {QuicFrame(&rst_frame)}; |
| 7241 | |
| 7242 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7243 | ASSERT_TRUE(data != nullptr); |
| 7244 | |
| 7245 | unsigned char* p = packet; |
| 7246 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 7247 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7248 | p = packet99; |
| 7249 | p_size = QUIC_ARRAYSIZE(packet99); |
| 7250 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 7251 | p = packet46; |
| 7252 | p_size = QUIC_ARRAYSIZE(packet46); |
| 7253 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 7254 | p = packet44; |
| 7255 | p_size = QUIC_ARRAYSIZE(packet44); |
| 7256 | } |
| 7257 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 7258 | |
| 7259 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7260 | data->length(), AsChars(p), p_size); |
| 7261 | } |
| 7262 | |
| 7263 | TEST_P(QuicFramerTest, BuildCloseFramePacket) { |
| 7264 | QuicPacketHeader header; |
| 7265 | header.destination_connection_id = FramerTestConnectionId(); |
| 7266 | header.reset_flag = false; |
| 7267 | header.version_flag = false; |
| 7268 | header.packet_number = kPacketNumber; |
| 7269 | |
| 7270 | QuicConnectionCloseFrame close_frame; |
| 7271 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7272 | close_frame.ietf_error_code = |
| 7273 | static_cast<QuicIetfTransportErrorCodes>(0x11); |
| 7274 | close_frame.frame_type = 0x05; |
| 7275 | } else { |
| 7276 | close_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 7277 | } |
| 7278 | close_frame.error_details = "because I can"; |
| 7279 | |
| 7280 | QuicFrames frames = {QuicFrame(&close_frame)}; |
| 7281 | |
| 7282 | // clang-format off |
| 7283 | unsigned char packet[] = { |
| 7284 | // public flags (8 byte connection_id) |
| 7285 | 0x28, |
| 7286 | // connection_id |
| 7287 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7288 | // packet number |
| 7289 | 0x12, 0x34, 0x56, 0x78, |
| 7290 | |
| 7291 | // frame type (connection close frame) |
| 7292 | 0x02, |
| 7293 | // error code |
| 7294 | 0x05, 0x06, 0x07, 0x08, |
| 7295 | // error details length |
| 7296 | 0x00, 0x0d, |
| 7297 | // error details |
| 7298 | 'b', 'e', 'c', 'a', |
| 7299 | 'u', 's', 'e', ' ', |
| 7300 | 'I', ' ', 'c', 'a', |
| 7301 | 'n', |
| 7302 | }; |
| 7303 | |
| 7304 | unsigned char packet44[] = { |
| 7305 | // type (short header, 4 byte packet number) |
| 7306 | 0x32, |
| 7307 | // connection_id |
| 7308 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7309 | // packet number |
| 7310 | 0x12, 0x34, 0x56, 0x78, |
| 7311 | |
| 7312 | // frame type (connection close frame) |
| 7313 | 0x02, |
| 7314 | // error code |
| 7315 | 0x05, 0x06, 0x07, 0x08, |
| 7316 | // error details length |
| 7317 | 0x00, 0x0d, |
| 7318 | // error details |
| 7319 | 'b', 'e', 'c', 'a', |
| 7320 | 'u', 's', 'e', ' ', |
| 7321 | 'I', ' ', 'c', 'a', |
| 7322 | 'n', |
| 7323 | }; |
| 7324 | |
| 7325 | unsigned char packet46[] = { |
| 7326 | // type (short header, 4 byte packet number) |
| 7327 | 0x43, |
| 7328 | // connection_id |
| 7329 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7330 | // packet number |
| 7331 | 0x12, 0x34, 0x56, 0x78, |
| 7332 | |
| 7333 | // frame type (connection close frame) |
| 7334 | 0x02, |
| 7335 | // error code |
| 7336 | 0x05, 0x06, 0x07, 0x08, |
| 7337 | // error details length |
| 7338 | 0x00, 0x0d, |
| 7339 | // error details |
| 7340 | 'b', 'e', 'c', 'a', |
| 7341 | 'u', 's', 'e', ' ', |
| 7342 | 'I', ' ', 'c', 'a', |
| 7343 | 'n', |
| 7344 | }; |
| 7345 | |
| 7346 | unsigned char packet99[] = { |
| 7347 | // type (short header, 4 byte packet number) |
| 7348 | 0x43, |
| 7349 | // connection_id |
| 7350 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7351 | // packet number |
| 7352 | 0x12, 0x34, 0x56, 0x78, |
| 7353 | |
| 7354 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 7355 | 0x1c, |
| 7356 | // error code |
| 7357 | 0x00, 0x11, |
| 7358 | // Frame type within the CONNECTION_CLOSE frame |
| 7359 | kVarInt62OneByte + 0x05, |
| 7360 | // error details length |
| 7361 | kVarInt62OneByte + 0x0d, |
| 7362 | // error details |
| 7363 | 'b', 'e', 'c', 'a', |
| 7364 | 'u', 's', 'e', ' ', |
| 7365 | 'I', ' ', 'c', 'a', |
| 7366 | 'n', |
| 7367 | }; |
| 7368 | // clang-format on |
| 7369 | |
| 7370 | unsigned char* p = packet; |
| 7371 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 7372 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7373 | p = packet99; |
| 7374 | p_size = QUIC_ARRAYSIZE(packet99); |
| 7375 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 7376 | p = packet46; |
| 7377 | p_size = QUIC_ARRAYSIZE(packet46); |
| 7378 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 7379 | p = packet44; |
| 7380 | p_size = QUIC_ARRAYSIZE(packet44); |
| 7381 | } |
| 7382 | |
| 7383 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7384 | ASSERT_TRUE(data != nullptr); |
| 7385 | |
| 7386 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7387 | data->length(), AsChars(p), p_size); |
| 7388 | } |
| 7389 | |
| 7390 | TEST_P(QuicFramerTest, BuildTruncatedCloseFramePacket) { |
| 7391 | QuicPacketHeader header; |
| 7392 | header.destination_connection_id = FramerTestConnectionId(); |
| 7393 | header.reset_flag = false; |
| 7394 | header.version_flag = false; |
| 7395 | header.packet_number = kPacketNumber; |
| 7396 | |
| 7397 | QuicConnectionCloseFrame close_frame; |
| 7398 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7399 | close_frame.ietf_error_code = PROTOCOL_VIOLATION; // value is 0x0a |
| 7400 | EXPECT_EQ(0u, close_frame.frame_type); |
| 7401 | } else { |
| 7402 | close_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 7403 | } |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 7404 | close_frame.error_details = std::string(2048, 'A'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7405 | QuicFrames frames = {QuicFrame(&close_frame)}; |
| 7406 | |
| 7407 | // clang-format off |
| 7408 | unsigned char packet[] = { |
| 7409 | // public flags (8 byte connection_id) |
| 7410 | 0x28, |
| 7411 | // connection_id |
| 7412 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7413 | // packet number |
| 7414 | 0x12, 0x34, 0x56, 0x78, |
| 7415 | |
| 7416 | // frame type (connection close frame) |
| 7417 | 0x02, |
| 7418 | // error code |
| 7419 | 0x05, 0x06, 0x07, 0x08, |
| 7420 | // error details length |
| 7421 | 0x01, 0x00, |
| 7422 | // error details (truncated to 256 bytes) |
| 7423 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7424 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7425 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7426 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7427 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7428 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7429 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7430 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7431 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7432 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7433 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7434 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7435 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7436 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7437 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7438 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7439 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7440 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7441 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7442 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7443 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7444 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7445 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7446 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7447 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7448 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7449 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7450 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7451 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7452 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7453 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7454 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7455 | }; |
| 7456 | |
| 7457 | unsigned char packet44[] = { |
| 7458 | // type (short header, 4 byte packet number) |
| 7459 | 0x32, |
| 7460 | // connection_id |
| 7461 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7462 | // packet number |
| 7463 | 0x12, 0x34, 0x56, 0x78, |
| 7464 | |
| 7465 | // frame type (connection close frame) |
| 7466 | 0x02, |
| 7467 | // error code |
| 7468 | 0x05, 0x06, 0x07, 0x08, |
| 7469 | // error details length |
| 7470 | 0x01, 0x00, |
| 7471 | // error details (truncated to 256 bytes) |
| 7472 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7473 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7474 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7475 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7476 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7477 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7478 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7479 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7480 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7481 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7482 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7483 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7484 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7485 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7486 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7487 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7488 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7489 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7490 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7491 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7492 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7493 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7494 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7495 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7496 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7497 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7498 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7499 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7500 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7501 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7502 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7503 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7504 | }; |
| 7505 | |
| 7506 | unsigned char packet46[] = { |
| 7507 | // type (short header, 4 byte packet number) |
| 7508 | 0x43, |
| 7509 | // connection_id |
| 7510 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7511 | // packet number |
| 7512 | 0x12, 0x34, 0x56, 0x78, |
| 7513 | |
| 7514 | // frame type (connection close frame) |
| 7515 | 0x02, |
| 7516 | // error code |
| 7517 | 0x05, 0x06, 0x07, 0x08, |
| 7518 | // error details length |
| 7519 | 0x01, 0x00, |
| 7520 | // error details (truncated to 256 bytes) |
| 7521 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7522 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7523 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7524 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7525 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7526 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7527 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7528 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7529 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7530 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7531 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7532 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7533 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7534 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7535 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7536 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7537 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7538 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7539 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7540 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7541 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7542 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7543 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7544 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7545 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7546 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7547 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7548 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7549 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7550 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7551 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7552 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7553 | }; |
| 7554 | |
| 7555 | unsigned char packet99[] = { |
| 7556 | // type (short header, 4 byte packet number) |
| 7557 | 0x43, |
| 7558 | // connection_id |
| 7559 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7560 | // packet number |
| 7561 | 0x12, 0x34, 0x56, 0x78, |
| 7562 | |
| 7563 | // frame type (IETF_CONNECTION_CLOSE frame) |
| 7564 | 0x1c, |
| 7565 | // error code |
| 7566 | 0x00, 0x0a, |
| 7567 | // Frame type within the CONNECTION_CLOSE frame |
| 7568 | kVarInt62OneByte + 0x00, |
| 7569 | // error details length |
| 7570 | kVarInt62TwoBytes + 0x01, 0x00, |
| 7571 | // error details (truncated to 256 bytes) |
| 7572 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7573 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7574 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7575 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7576 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7577 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7578 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7579 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7580 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7581 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7582 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7583 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7584 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7585 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7586 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7587 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7588 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7589 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7590 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7591 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7592 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7593 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7594 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7595 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7596 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7597 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7598 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7599 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7600 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7601 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7602 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7603 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7604 | }; |
| 7605 | // clang-format on |
| 7606 | |
| 7607 | unsigned char* p = packet; |
| 7608 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 7609 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7610 | p = packet99; |
| 7611 | p_size = QUIC_ARRAYSIZE(packet99); |
| 7612 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 7613 | p = packet46; |
| 7614 | p_size = QUIC_ARRAYSIZE(packet46); |
| 7615 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 7616 | p = packet44; |
| 7617 | p_size = QUIC_ARRAYSIZE(packet44); |
| 7618 | } |
| 7619 | |
| 7620 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7621 | ASSERT_TRUE(data != nullptr); |
| 7622 | |
| 7623 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7624 | data->length(), AsChars(p), p_size); |
| 7625 | } |
| 7626 | |
| 7627 | TEST_P(QuicFramerTest, BuildApplicationCloseFramePacket) { |
| 7628 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 7629 | // Versions other than 99 do not have ApplicationClose |
| 7630 | return; |
| 7631 | } |
| 7632 | QuicPacketHeader header; |
| 7633 | header.destination_connection_id = FramerTestConnectionId(); |
| 7634 | header.reset_flag = false; |
| 7635 | header.version_flag = false; |
| 7636 | header.packet_number = kPacketNumber; |
| 7637 | |
| 7638 | QuicApplicationCloseFrame app_close_frame; |
| 7639 | app_close_frame.error_code = static_cast<QuicErrorCode>(0x11); |
| 7640 | app_close_frame.error_details = "because I can"; |
| 7641 | |
| 7642 | QuicFrames frames = {QuicFrame(&app_close_frame)}; |
| 7643 | |
| 7644 | // clang-format off |
| 7645 | |
| 7646 | unsigned char packet99[] = { |
| 7647 | // type (short header, 4 byte packet number) |
| 7648 | 0x43, |
| 7649 | // connection_id |
| 7650 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7651 | // packet number |
| 7652 | 0x12, 0x34, 0x56, 0x78, |
| 7653 | |
| 7654 | // frame type (IETF_APPLICATION_CLOSE frame) |
| 7655 | 0x1d, |
| 7656 | // error code |
| 7657 | 0x00, 0x11, |
| 7658 | // error details length |
| 7659 | kVarInt62OneByte + 0x0d, |
| 7660 | // error details |
| 7661 | 'b', 'e', 'c', 'a', |
| 7662 | 'u', 's', 'e', ' ', |
| 7663 | 'I', ' ', 'c', 'a', |
| 7664 | 'n', |
| 7665 | }; |
| 7666 | // clang-format on |
| 7667 | |
| 7668 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7669 | ASSERT_TRUE(data != nullptr); |
| 7670 | |
| 7671 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7672 | data->length(), AsChars(packet99), |
| 7673 | QUIC_ARRAYSIZE(packet99)); |
| 7674 | } |
| 7675 | |
| 7676 | TEST_P(QuicFramerTest, BuildTruncatedApplicationCloseFramePacket) { |
| 7677 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 7678 | // Versions other than 99 do not have this frame. |
| 7679 | return; |
| 7680 | } |
| 7681 | QuicPacketHeader header; |
| 7682 | header.destination_connection_id = FramerTestConnectionId(); |
| 7683 | header.reset_flag = false; |
| 7684 | header.version_flag = false; |
| 7685 | header.packet_number = kPacketNumber; |
| 7686 | |
| 7687 | QuicApplicationCloseFrame app_close_frame; |
| 7688 | app_close_frame.error_code = static_cast<QuicErrorCode>(0x11); |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 7689 | app_close_frame.error_details = std::string(2048, 'A'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7690 | |
| 7691 | QuicFrames frames = {QuicFrame(&app_close_frame)}; |
| 7692 | |
| 7693 | // clang-format off |
| 7694 | unsigned char packet99[] = { |
| 7695 | // type (short header, 4 byte packet number) |
| 7696 | 0x43, |
| 7697 | // connection_id |
| 7698 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7699 | // packet number |
| 7700 | 0x12, 0x34, 0x56, 0x78, |
| 7701 | |
| 7702 | // frame type (IETF_APPLICATION_CLOSE frame) |
| 7703 | 0x1d, |
| 7704 | // error code |
| 7705 | 0x00, 0x11, |
| 7706 | // error details length |
| 7707 | kVarInt62TwoBytes + 0x01, 0x00, |
| 7708 | // error details (truncated to 256 bytes) |
| 7709 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7710 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7711 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7712 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7713 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7714 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7715 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7716 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7717 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7718 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7719 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7720 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7721 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7722 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7723 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7724 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7725 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7726 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7727 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7728 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7729 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7730 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7731 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7732 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7733 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7734 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7735 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7736 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7737 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7738 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7739 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7740 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7741 | }; |
| 7742 | // clang-format on |
| 7743 | |
| 7744 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7745 | ASSERT_TRUE(data != nullptr); |
| 7746 | |
| 7747 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7748 | data->length(), AsChars(packet99), |
| 7749 | QUIC_ARRAYSIZE(packet99)); |
| 7750 | } |
| 7751 | |
| 7752 | TEST_P(QuicFramerTest, BuildGoAwayPacket) { |
| 7753 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7754 | // This frame type is not supported in version 99. |
| 7755 | return; |
| 7756 | } |
| 7757 | QuicPacketHeader header; |
| 7758 | header.destination_connection_id = FramerTestConnectionId(); |
| 7759 | header.reset_flag = false; |
| 7760 | header.version_flag = false; |
| 7761 | header.packet_number = kPacketNumber; |
| 7762 | |
| 7763 | QuicGoAwayFrame goaway_frame; |
| 7764 | goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 7765 | goaway_frame.last_good_stream_id = kStreamId; |
| 7766 | goaway_frame.reason_phrase = "because I can"; |
| 7767 | |
| 7768 | QuicFrames frames = {QuicFrame(&goaway_frame)}; |
| 7769 | |
| 7770 | // clang-format off |
| 7771 | unsigned char packet[] = { |
| 7772 | // public flags (8 byte connection_id) |
| 7773 | 0x28, |
| 7774 | // connection_id |
| 7775 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7776 | // packet number |
| 7777 | 0x12, 0x34, 0x56, 0x78, |
| 7778 | |
| 7779 | // frame type (go away frame) |
| 7780 | 0x03, |
| 7781 | // error code |
| 7782 | 0x05, 0x06, 0x07, 0x08, |
| 7783 | // stream id |
| 7784 | 0x01, 0x02, 0x03, 0x04, |
| 7785 | // error details length |
| 7786 | 0x00, 0x0d, |
| 7787 | // error details |
| 7788 | 'b', 'e', 'c', 'a', |
| 7789 | 'u', 's', 'e', ' ', |
| 7790 | 'I', ' ', 'c', 'a', |
| 7791 | 'n', |
| 7792 | }; |
| 7793 | |
| 7794 | unsigned char packet44[] = { |
| 7795 | // type (short header, 4 byte packet number) |
| 7796 | 0x32, |
| 7797 | // connection_id |
| 7798 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7799 | // packet number |
| 7800 | 0x12, 0x34, 0x56, 0x78, |
| 7801 | |
| 7802 | // frame type (go away frame) |
| 7803 | 0x03, |
| 7804 | // error code |
| 7805 | 0x05, 0x06, 0x07, 0x08, |
| 7806 | // stream id |
| 7807 | 0x01, 0x02, 0x03, 0x04, |
| 7808 | // error details length |
| 7809 | 0x00, 0x0d, |
| 7810 | // error details |
| 7811 | 'b', 'e', 'c', 'a', |
| 7812 | 'u', 's', 'e', ' ', |
| 7813 | 'I', ' ', 'c', 'a', |
| 7814 | 'n', |
| 7815 | }; |
| 7816 | |
| 7817 | unsigned char packet46[] = { |
| 7818 | // type (short header, 4 byte packet number) |
| 7819 | 0x43, |
| 7820 | // connection_id |
| 7821 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7822 | // packet number |
| 7823 | 0x12, 0x34, 0x56, 0x78, |
| 7824 | |
| 7825 | // frame type (go away frame) |
| 7826 | 0x03, |
| 7827 | // error code |
| 7828 | 0x05, 0x06, 0x07, 0x08, |
| 7829 | // stream id |
| 7830 | 0x01, 0x02, 0x03, 0x04, |
| 7831 | // error details length |
| 7832 | 0x00, 0x0d, |
| 7833 | // error details |
| 7834 | 'b', 'e', 'c', 'a', |
| 7835 | 'u', 's', 'e', ' ', |
| 7836 | 'I', ' ', 'c', 'a', |
| 7837 | 'n', |
| 7838 | }; |
| 7839 | |
| 7840 | // clang-format on |
| 7841 | |
| 7842 | unsigned char* p = packet; |
| 7843 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 7844 | if (framer_.transport_version() > QUIC_VERSION_44) { |
| 7845 | p = packet46; |
| 7846 | p_size = QUIC_ARRAYSIZE(packet46); |
| 7847 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 7848 | p = packet44; |
| 7849 | p_size = QUIC_ARRAYSIZE(packet44); |
| 7850 | } |
| 7851 | |
| 7852 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 7853 | ASSERT_TRUE(data != nullptr); |
| 7854 | |
| 7855 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 7856 | data->length(), AsChars(p), p_size); |
| 7857 | } |
| 7858 | |
| 7859 | TEST_P(QuicFramerTest, BuildTruncatedGoAwayPacket) { |
| 7860 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 7861 | // This frame type is not supported in version 99. |
| 7862 | return; |
| 7863 | } |
| 7864 | QuicPacketHeader header; |
| 7865 | header.destination_connection_id = FramerTestConnectionId(); |
| 7866 | header.reset_flag = false; |
| 7867 | header.version_flag = false; |
| 7868 | header.packet_number = kPacketNumber; |
| 7869 | |
| 7870 | QuicGoAwayFrame goaway_frame; |
| 7871 | goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
| 7872 | goaway_frame.last_good_stream_id = kStreamId; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 7873 | goaway_frame.reason_phrase = std::string(2048, 'A'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 7874 | |
| 7875 | QuicFrames frames = {QuicFrame(&goaway_frame)}; |
| 7876 | |
| 7877 | // clang-format off |
| 7878 | unsigned char packet[] = { |
| 7879 | // public flags (8 byte connection_id) |
| 7880 | 0x28, |
| 7881 | // connection_id |
| 7882 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7883 | // packet number |
| 7884 | 0x12, 0x34, 0x56, 0x78, |
| 7885 | |
| 7886 | // frame type (go away frame) |
| 7887 | 0x03, |
| 7888 | // error code |
| 7889 | 0x05, 0x06, 0x07, 0x08, |
| 7890 | // stream id |
| 7891 | 0x01, 0x02, 0x03, 0x04, |
| 7892 | // error details length |
| 7893 | 0x01, 0x00, |
| 7894 | // error details (truncated to 256 bytes) |
| 7895 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7896 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7897 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7898 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7899 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7900 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7901 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7902 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7903 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7904 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7905 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7906 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7907 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7908 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7909 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7910 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7911 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7912 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7913 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7914 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7915 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7916 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7917 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7918 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7919 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7920 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7921 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7922 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7923 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7924 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7925 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7926 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7927 | }; |
| 7928 | |
| 7929 | unsigned char packet44[] = { |
| 7930 | // type (short header, 4 byte packet number) |
| 7931 | 0x32, |
| 7932 | // connection_id |
| 7933 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7934 | // packet number |
| 7935 | 0x12, 0x34, 0x56, 0x78, |
| 7936 | |
| 7937 | // frame type (go away frame) |
| 7938 | 0x03, |
| 7939 | // error code |
| 7940 | 0x05, 0x06, 0x07, 0x08, |
| 7941 | // stream id |
| 7942 | 0x01, 0x02, 0x03, 0x04, |
| 7943 | // error details length |
| 7944 | 0x01, 0x00, |
| 7945 | // error details (truncated to 256 bytes) |
| 7946 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7947 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7948 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7949 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7950 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7951 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7952 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7953 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7954 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7955 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7956 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7957 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7958 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7959 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7960 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7961 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7962 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7963 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7964 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7965 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7966 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7967 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7968 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7969 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7970 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7971 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7972 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7973 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7974 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7975 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7976 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7977 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7978 | }; |
| 7979 | |
| 7980 | unsigned char packet46[] = { |
| 7981 | // type (short header, 4 byte packet number) |
| 7982 | 0x43, |
| 7983 | // connection_id |
| 7984 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 7985 | // packet number |
| 7986 | 0x12, 0x34, 0x56, 0x78, |
| 7987 | |
| 7988 | // frame type (go away frame) |
| 7989 | 0x03, |
| 7990 | // error code |
| 7991 | 0x05, 0x06, 0x07, 0x08, |
| 7992 | // stream id |
| 7993 | 0x01, 0x02, 0x03, 0x04, |
| 7994 | // error details length |
| 7995 | 0x01, 0x00, |
| 7996 | // error details (truncated to 256 bytes) |
| 7997 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7998 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 7999 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8000 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8001 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8002 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8003 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8004 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8005 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8006 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8007 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8008 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8009 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8010 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8011 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8012 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8013 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8014 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8015 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8016 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8017 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8018 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8019 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8020 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8021 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8022 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8023 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8024 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8025 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8026 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8027 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8028 | 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', |
| 8029 | }; |
| 8030 | // clang-format on |
| 8031 | |
| 8032 | unsigned char* p = packet; |
| 8033 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 8034 | if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8035 | p = packet46; |
| 8036 | p_size = QUIC_ARRAYSIZE(packet46); |
| 8037 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8038 | p = packet44; |
| 8039 | p_size = QUIC_ARRAYSIZE(packet44); |
| 8040 | } |
| 8041 | |
| 8042 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8043 | ASSERT_TRUE(data != nullptr); |
| 8044 | |
| 8045 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8046 | data->length(), AsChars(p), p_size); |
| 8047 | } |
| 8048 | |
| 8049 | TEST_P(QuicFramerTest, BuildWindowUpdatePacket) { |
| 8050 | QuicPacketHeader header; |
| 8051 | header.destination_connection_id = FramerTestConnectionId(); |
| 8052 | header.reset_flag = false; |
| 8053 | header.version_flag = false; |
| 8054 | header.packet_number = kPacketNumber; |
| 8055 | |
| 8056 | QuicWindowUpdateFrame window_update_frame; |
| 8057 | window_update_frame.stream_id = kStreamId; |
| 8058 | window_update_frame.byte_offset = 0x1122334455667788; |
| 8059 | |
| 8060 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 8061 | |
| 8062 | // clang-format off |
| 8063 | unsigned char packet[] = { |
| 8064 | // public flags (8 byte connection_id) |
| 8065 | 0x28, |
| 8066 | // connection_id |
| 8067 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8068 | // packet number |
| 8069 | 0x12, 0x34, 0x56, 0x78, |
| 8070 | |
| 8071 | // frame type (window update frame) |
| 8072 | 0x04, |
| 8073 | // stream id |
| 8074 | 0x01, 0x02, 0x03, 0x04, |
| 8075 | // byte offset |
| 8076 | 0x11, 0x22, 0x33, 0x44, |
| 8077 | 0x55, 0x66, 0x77, 0x88, |
| 8078 | }; |
| 8079 | |
| 8080 | unsigned char packet44[] = { |
| 8081 | // type (short header, 4 byte packet number) |
| 8082 | 0x32, |
| 8083 | // connection_id |
| 8084 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8085 | // packet number |
| 8086 | 0x12, 0x34, 0x56, 0x78, |
| 8087 | |
| 8088 | // frame type (window update frame) |
| 8089 | 0x04, |
| 8090 | // stream id |
| 8091 | 0x01, 0x02, 0x03, 0x04, |
| 8092 | // byte offset |
| 8093 | 0x11, 0x22, 0x33, 0x44, |
| 8094 | 0x55, 0x66, 0x77, 0x88, |
| 8095 | }; |
| 8096 | |
| 8097 | unsigned char packet46[] = { |
| 8098 | // type (short header, 4 byte packet number) |
| 8099 | 0x43, |
| 8100 | // connection_id |
| 8101 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8102 | // packet number |
| 8103 | 0x12, 0x34, 0x56, 0x78, |
| 8104 | |
| 8105 | // frame type (window update frame) |
| 8106 | 0x04, |
| 8107 | // stream id |
| 8108 | 0x01, 0x02, 0x03, 0x04, |
| 8109 | // byte offset |
| 8110 | 0x11, 0x22, 0x33, 0x44, |
| 8111 | 0x55, 0x66, 0x77, 0x88, |
| 8112 | }; |
| 8113 | |
| 8114 | unsigned char packet99[] = { |
| 8115 | // type (short header, 4 byte packet number) |
| 8116 | 0x43, |
| 8117 | // connection_id |
| 8118 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8119 | // packet number |
| 8120 | 0x12, 0x34, 0x56, 0x78, |
| 8121 | |
| 8122 | // frame type (IETF_MAX_STREAM_DATA frame) |
| 8123 | 0x11, |
| 8124 | // stream id |
| 8125 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 8126 | // byte offset |
| 8127 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 8128 | 0x55, 0x66, 0x77, 0x88, |
| 8129 | }; |
| 8130 | // clang-format on |
| 8131 | |
| 8132 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8133 | ASSERT_TRUE(data != nullptr); |
| 8134 | |
| 8135 | unsigned char* p = packet; |
| 8136 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 8137 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8138 | p = packet99; |
| 8139 | p_size = QUIC_ARRAYSIZE(packet99); |
| 8140 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8141 | p = packet46; |
| 8142 | p_size = QUIC_ARRAYSIZE(packet46); |
| 8143 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8144 | p = packet44; |
| 8145 | p_size = QUIC_ARRAYSIZE(packet44); |
| 8146 | } |
| 8147 | |
| 8148 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8149 | data->length(), AsChars(p), p_size); |
| 8150 | } |
| 8151 | |
| 8152 | TEST_P(QuicFramerTest, BuildMaxStreamDataPacket) { |
| 8153 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8154 | // This frame is available only in this version. |
| 8155 | return; |
| 8156 | } |
| 8157 | QuicPacketHeader header; |
| 8158 | header.destination_connection_id = FramerTestConnectionId(); |
| 8159 | header.reset_flag = false; |
| 8160 | header.version_flag = false; |
| 8161 | header.packet_number = kPacketNumber; |
| 8162 | |
| 8163 | QuicWindowUpdateFrame window_update_frame; |
| 8164 | window_update_frame.stream_id = kStreamId; |
| 8165 | window_update_frame.byte_offset = 0x1122334455667788; |
| 8166 | |
| 8167 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 8168 | |
| 8169 | // clang-format off |
| 8170 | unsigned char packet99[] = { |
| 8171 | // type (short header, 4 byte packet number) |
| 8172 | 0x43, |
| 8173 | // connection_id |
| 8174 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8175 | // packet number |
| 8176 | 0x12, 0x34, 0x56, 0x78, |
| 8177 | |
| 8178 | // frame type (IETF_MAX_STREAM_DATA frame) |
| 8179 | 0x11, |
| 8180 | // stream id |
| 8181 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 8182 | // byte offset |
| 8183 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 8184 | 0x55, 0x66, 0x77, 0x88, |
| 8185 | }; |
| 8186 | // clang-format on |
| 8187 | |
| 8188 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8189 | ASSERT_TRUE(data != nullptr); |
| 8190 | |
| 8191 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8192 | data->length(), AsChars(packet99), |
| 8193 | QUIC_ARRAYSIZE(packet99)); |
| 8194 | } |
| 8195 | |
| 8196 | TEST_P(QuicFramerTest, BuildMaxDataPacket) { |
| 8197 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8198 | // This frame is available only in this version. |
| 8199 | return; |
| 8200 | } |
| 8201 | QuicPacketHeader header; |
| 8202 | header.destination_connection_id = FramerTestConnectionId(); |
| 8203 | header.reset_flag = false; |
| 8204 | header.version_flag = false; |
| 8205 | header.packet_number = kPacketNumber; |
| 8206 | |
| 8207 | QuicWindowUpdateFrame window_update_frame; |
| 8208 | window_update_frame.stream_id = |
| 8209 | QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
| 8210 | window_update_frame.byte_offset = 0x1122334455667788; |
| 8211 | |
| 8212 | QuicFrames frames = {QuicFrame(&window_update_frame)}; |
| 8213 | |
| 8214 | // clang-format off |
| 8215 | unsigned char packet99[] = { |
| 8216 | // type (short header, 4 byte packet number) |
| 8217 | 0x43, |
| 8218 | // connection_id |
| 8219 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8220 | // packet number |
| 8221 | 0x12, 0x34, 0x56, 0x78, |
| 8222 | |
| 8223 | // frame type (IETF_MAX_DATA frame) |
| 8224 | 0x10, |
| 8225 | // byte offset |
| 8226 | kVarInt62EightBytes + 0x11, 0x22, 0x33, 0x44, |
| 8227 | 0x55, 0x66, 0x77, 0x88, |
| 8228 | }; |
| 8229 | // clang-format on |
| 8230 | |
| 8231 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8232 | ASSERT_TRUE(data != nullptr); |
| 8233 | |
| 8234 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8235 | data->length(), AsChars(packet99), |
| 8236 | QUIC_ARRAYSIZE(packet99)); |
| 8237 | } |
| 8238 | |
| 8239 | TEST_P(QuicFramerTest, BuildBlockedPacket) { |
| 8240 | QuicPacketHeader header; |
| 8241 | header.destination_connection_id = FramerTestConnectionId(); |
| 8242 | header.reset_flag = false; |
| 8243 | header.version_flag = false; |
| 8244 | header.packet_number = kPacketNumber; |
| 8245 | |
| 8246 | QuicBlockedFrame blocked_frame; |
| 8247 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8248 | // For V99, the stream ID must be <invalid> for the frame |
| 8249 | // to be a BLOCKED frame. if it's valid, it will be a |
| 8250 | // STREAM_BLOCKED frame. |
| 8251 | blocked_frame.stream_id = |
| 8252 | QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
| 8253 | } else { |
| 8254 | blocked_frame.stream_id = kStreamId; |
| 8255 | } |
| 8256 | blocked_frame.offset = kStreamOffset; |
| 8257 | |
| 8258 | QuicFrames frames = {QuicFrame(&blocked_frame)}; |
| 8259 | |
| 8260 | // clang-format off |
| 8261 | unsigned char packet[] = { |
| 8262 | // public flags (8 byte connection_id) |
| 8263 | 0x28, |
| 8264 | // connection_id |
| 8265 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8266 | // packet number |
| 8267 | 0x12, 0x34, 0x56, 0x78, |
| 8268 | |
| 8269 | // frame type (blocked frame) |
| 8270 | 0x05, |
| 8271 | // stream id |
| 8272 | 0x01, 0x02, 0x03, 0x04, |
| 8273 | }; |
| 8274 | |
| 8275 | unsigned char packet44[] = { |
| 8276 | // type (short packet, 4 byte packet number) |
| 8277 | 0x32, |
| 8278 | // connection_id |
| 8279 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8280 | // packet number |
| 8281 | 0x12, 0x34, 0x56, 0x78, |
| 8282 | |
| 8283 | // frame type (blocked frame) |
| 8284 | 0x05, |
| 8285 | // stream id |
| 8286 | 0x01, 0x02, 0x03, 0x04, |
| 8287 | }; |
| 8288 | |
| 8289 | unsigned char packet46[] = { |
| 8290 | // type (short packet, 4 byte packet number) |
| 8291 | 0x43, |
| 8292 | // connection_id |
| 8293 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8294 | // packet number |
| 8295 | 0x12, 0x34, 0x56, 0x78, |
| 8296 | |
| 8297 | // frame type (blocked frame) |
| 8298 | 0x05, |
| 8299 | // stream id |
| 8300 | 0x01, 0x02, 0x03, 0x04, |
| 8301 | }; |
| 8302 | |
| 8303 | unsigned char packet99[] = { |
| 8304 | // type (short packet, 4 byte packet number) |
| 8305 | 0x43, |
| 8306 | // connection_id |
| 8307 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8308 | // packet number |
| 8309 | 0x12, 0x34, 0x56, 0x78, |
| 8310 | |
| 8311 | // frame type (IETF_BLOCKED frame) |
| 8312 | 0x14, |
| 8313 | // Offset |
| 8314 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 8315 | }; |
| 8316 | // clang-format on |
| 8317 | |
| 8318 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8319 | ASSERT_TRUE(data != nullptr); |
| 8320 | |
| 8321 | unsigned char* p = packet; |
| 8322 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 8323 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8324 | p = packet99; |
| 8325 | p_size = QUIC_ARRAYSIZE(packet99); |
| 8326 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8327 | p = packet46; |
| 8328 | p_size = QUIC_ARRAYSIZE(packet46); |
| 8329 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8330 | p = packet44; |
| 8331 | p_size = QUIC_ARRAYSIZE(packet44); |
| 8332 | } |
| 8333 | |
| 8334 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8335 | data->length(), AsChars(p), p_size); |
| 8336 | } |
| 8337 | |
| 8338 | TEST_P(QuicFramerTest, BuildPingPacket) { |
| 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 | QuicFrames frames = {QuicFrame(QuicPingFrame())}; |
| 8346 | |
| 8347 | // clang-format off |
| 8348 | unsigned char packet[] = { |
| 8349 | // public flags (8 byte connection_id) |
| 8350 | 0x28, |
| 8351 | // connection_id |
| 8352 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8353 | // packet number |
| 8354 | 0x12, 0x34, 0x56, 0x78, |
| 8355 | |
| 8356 | // frame type (ping frame) |
| 8357 | 0x07, |
| 8358 | }; |
| 8359 | |
| 8360 | unsigned char packet44[] = { |
| 8361 | // type (short header, 4 byte packet number) |
| 8362 | 0x32, |
| 8363 | // connection_id |
| 8364 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8365 | // packet number |
| 8366 | 0x12, 0x34, 0x56, 0x78, |
| 8367 | |
| 8368 | // frame type |
| 8369 | 0x07, |
| 8370 | }; |
| 8371 | |
| 8372 | unsigned char packet46[] = { |
| 8373 | // type (short header, 4 byte packet number) |
| 8374 | 0x43, |
| 8375 | // connection_id |
| 8376 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8377 | // packet number |
| 8378 | 0x12, 0x34, 0x56, 0x78, |
| 8379 | |
| 8380 | // frame type |
| 8381 | 0x07, |
| 8382 | }; |
| 8383 | |
| 8384 | unsigned char packet99[] = { |
| 8385 | // type (short header, 4 byte packet number) |
| 8386 | 0x43, |
| 8387 | // connection_id |
| 8388 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8389 | // packet number |
| 8390 | 0x12, 0x34, 0x56, 0x78, |
| 8391 | |
| 8392 | // frame type (IETF_PING frame) |
| 8393 | 0x01, |
| 8394 | }; |
| 8395 | // clang-format on |
| 8396 | |
| 8397 | unsigned char* p = packet; |
| 8398 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8399 | p = packet99; |
| 8400 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8401 | p = packet46; |
| 8402 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8403 | p = packet44; |
| 8404 | } |
| 8405 | |
| 8406 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8407 | ASSERT_TRUE(data != nullptr); |
| 8408 | |
| 8409 | test::CompareCharArraysWithHexError( |
| 8410 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 8411 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 8412 | : QUIC_ARRAYSIZE(packet)); |
| 8413 | } |
| 8414 | |
| 8415 | TEST_P(QuicFramerTest, BuildMessagePacket) { |
| 8416 | if (framer_.transport_version() <= QUIC_VERSION_44) { |
| 8417 | return; |
| 8418 | } |
| 8419 | QuicPacketHeader header; |
| 8420 | header.destination_connection_id = FramerTestConnectionId(); |
| 8421 | header.reset_flag = false; |
| 8422 | header.version_flag = false; |
| 8423 | header.packet_number = kPacketNumber; |
| 8424 | QuicMemSliceStorage storage(nullptr, 0, nullptr, 0); |
| 8425 | |
| 8426 | QuicMessageFrame frame(1); |
| 8427 | MakeSpan(&allocator_, "message", &storage).SaveMemSlicesAsMessageData(&frame); |
| 8428 | QuicMessageFrame frame2(2); |
| 8429 | MakeSpan(&allocator_, "message2", &storage) |
| 8430 | .SaveMemSlicesAsMessageData(&frame2); |
| 8431 | QuicFrames frames = {QuicFrame(&frame), QuicFrame(&frame2)}; |
| 8432 | |
| 8433 | // clang-format off |
| 8434 | unsigned char packet45[] = { |
| 8435 | // type (short header, 4 byte packet number) |
| 8436 | 0x32, |
| 8437 | // connection_id |
| 8438 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8439 | // packet number |
| 8440 | 0x12, 0x34, 0x56, 0x78, |
| 8441 | |
| 8442 | // frame type (message frame) |
| 8443 | 0x21, |
| 8444 | // Length |
| 8445 | 0x07, |
| 8446 | // Message Data |
| 8447 | 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 8448 | // frame type (message frame no length) |
| 8449 | 0x20, |
| 8450 | // Message Data |
| 8451 | 'm', 'e', 's', 's', 'a', 'g', 'e', '2' |
| 8452 | }; |
| 8453 | |
| 8454 | unsigned char packet46[] = { |
| 8455 | // type (short header, 4 byte packet number) |
| 8456 | 0x43, |
| 8457 | // connection_id |
| 8458 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8459 | // packet number |
| 8460 | 0x12, 0x34, 0x56, 0x78, |
| 8461 | |
| 8462 | // frame type (message frame) |
| 8463 | 0x21, |
| 8464 | // Length |
| 8465 | 0x07, |
| 8466 | // Message Data |
| 8467 | 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 8468 | // frame type (message frame no length) |
| 8469 | 0x20, |
| 8470 | // Message Data |
| 8471 | 'm', 'e', 's', 's', 'a', 'g', 'e', '2' |
| 8472 | }; |
| 8473 | |
| 8474 | unsigned char packet99[] = { |
| 8475 | // type (short header, 4 byte packet number) |
| 8476 | 0x43, |
| 8477 | // connection_id |
| 8478 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8479 | // packet number |
| 8480 | 0x12, 0x34, 0x56, 0x78, |
| 8481 | |
| 8482 | // frame type (IETF_MESSAGE frame) |
| 8483 | 0x21, |
| 8484 | // Length |
| 8485 | 0x07, |
| 8486 | // Message Data |
| 8487 | 'm', 'e', 's', 's', 'a', 'g', 'e', |
| 8488 | // frame type (message frame no length) |
| 8489 | 0x20, |
| 8490 | // Message Data |
| 8491 | 'm', 'e', 's', 's', 'a', 'g', 'e', '2' |
| 8492 | }; |
| 8493 | // clang-format on |
| 8494 | |
| 8495 | unsigned char* p = packet45; |
| 8496 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8497 | p = packet99; |
| 8498 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8499 | p = packet46; |
| 8500 | } |
| 8501 | |
| 8502 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8503 | ASSERT_TRUE(data != nullptr); |
| 8504 | |
| 8505 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8506 | data->length(), AsChars(p), |
| 8507 | QUIC_ARRAYSIZE(packet45)); |
| 8508 | } |
| 8509 | |
| 8510 | // Test that the connectivity probing packet is serialized correctly as a |
| 8511 | // padded PING packet. |
| 8512 | TEST_P(QuicFramerTest, BuildConnectivityProbingPacket) { |
| 8513 | QuicPacketHeader header; |
| 8514 | header.destination_connection_id = FramerTestConnectionId(); |
| 8515 | header.reset_flag = false; |
| 8516 | header.version_flag = false; |
| 8517 | header.packet_number = kPacketNumber; |
| 8518 | |
| 8519 | // clang-format off |
| 8520 | unsigned char packet[] = { |
| 8521 | // public flags (8 byte connection_id) |
| 8522 | 0x28, |
| 8523 | // connection_id |
| 8524 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8525 | // packet number |
| 8526 | 0x12, 0x34, 0x56, 0x78, |
| 8527 | |
| 8528 | // frame type (ping frame) |
| 8529 | 0x07, |
| 8530 | // frame type (padding frame) |
| 8531 | 0x00, |
| 8532 | 0x00, 0x00, 0x00, 0x00 |
| 8533 | }; |
| 8534 | |
| 8535 | unsigned char packet44[] = { |
| 8536 | // type (short header, 4 byte packet number) |
| 8537 | 0x32, |
| 8538 | // connection_id |
| 8539 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8540 | // packet number |
| 8541 | 0x12, 0x34, 0x56, 0x78, |
| 8542 | |
| 8543 | // frame type |
| 8544 | 0x07, |
| 8545 | // frame type (padding frame) |
| 8546 | 0x00, |
| 8547 | 0x00, 0x00, 0x00, 0x00 |
| 8548 | }; |
| 8549 | |
| 8550 | unsigned char packet46[] = { |
| 8551 | // type (short header, 4 byte packet number) |
| 8552 | 0x43, |
| 8553 | // connection_id |
| 8554 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8555 | // packet number |
| 8556 | 0x12, 0x34, 0x56, 0x78, |
| 8557 | |
| 8558 | // frame type |
| 8559 | 0x07, |
| 8560 | // frame type (padding frame) |
| 8561 | 0x00, |
| 8562 | 0x00, 0x00, 0x00, 0x00 |
| 8563 | }; |
| 8564 | |
| 8565 | unsigned char packet99[] = { |
| 8566 | // type (short header, 4 byte packet number) |
| 8567 | 0x43, |
| 8568 | // connection_id |
| 8569 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8570 | // packet number |
| 8571 | 0x12, 0x34, 0x56, 0x78, |
| 8572 | |
| 8573 | // frame type (IETF_PING frame) |
| 8574 | 0x01, |
| 8575 | // frame type (padding frame) |
| 8576 | 0x00, |
| 8577 | 0x00, 0x00, 0x00, 0x00 |
| 8578 | }; |
| 8579 | // clang-format on |
| 8580 | |
| 8581 | unsigned char* p = packet; |
| 8582 | size_t packet_size = QUIC_ARRAYSIZE(packet); |
| 8583 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8584 | p = packet99; |
| 8585 | packet_size = QUIC_ARRAYSIZE(packet99); |
| 8586 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8587 | p = packet46; |
| 8588 | packet_size = QUIC_ARRAYSIZE(packet46); |
| 8589 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8590 | p = packet44; |
| 8591 | packet_size = QUIC_ARRAYSIZE(packet44); |
| 8592 | } |
| 8593 | |
| 8594 | std::unique_ptr<char[]> buffer(new char[kMaxPacketSize]); |
| 8595 | |
| 8596 | size_t length = framer_.BuildConnectivityProbingPacket( |
| 8597 | header, buffer.get(), packet_size, ENCRYPTION_NONE); |
| 8598 | |
| 8599 | EXPECT_NE(0u, length); |
| 8600 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 8601 | header); |
| 8602 | |
| 8603 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 8604 | data.length(), AsChars(p), packet_size); |
| 8605 | } |
| 8606 | |
| 8607 | // Test that the path challenge connectivity probing packet is serialized |
| 8608 | // correctly as a padded PATH CHALLENGE packet. |
| 8609 | TEST_P(QuicFramerTest, BuildPaddedPathChallengePacket) { |
| 8610 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8611 | return; |
| 8612 | } |
| 8613 | |
| 8614 | QuicPacketHeader header; |
| 8615 | header.destination_connection_id = FramerTestConnectionId(); |
| 8616 | header.reset_flag = false; |
| 8617 | header.version_flag = false; |
| 8618 | header.packet_number = kPacketNumber; |
| 8619 | QuicPathFrameBuffer payload; |
| 8620 | |
| 8621 | // clang-format off |
| 8622 | unsigned char packet[] = { |
| 8623 | // type (short header, 4 byte packet number) |
| 8624 | 0x43, |
| 8625 | // connection_id |
| 8626 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8627 | // packet number |
| 8628 | 0x12, 0x34, 0x56, 0x78, |
| 8629 | |
| 8630 | // Path Challenge Frame type (IETF_PATH_CHALLENGE) |
| 8631 | 0x1a, |
| 8632 | // 8 "random" bytes, MockRandom makes lots of r's |
| 8633 | 'r', 'r', 'r', 'r', 'r', 'r', 'r', 'r', |
| 8634 | // frame type (padding frame) |
| 8635 | 0x00, |
| 8636 | 0x00, 0x00, 0x00, 0x00 |
| 8637 | }; |
| 8638 | // clang-format on |
| 8639 | |
| 8640 | std::unique_ptr<char[]> buffer(new char[kMaxPacketSize]); |
| 8641 | MockRandom randomizer; |
| 8642 | |
| 8643 | size_t length = framer_.BuildPaddedPathChallengePacket( |
| 8644 | header, buffer.get(), QUIC_ARRAYSIZE(packet), &payload, &randomizer, |
| 8645 | ENCRYPTION_NONE); |
| 8646 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 8647 | |
| 8648 | // Payload has the random bytes that were generated. Copy them into packet, |
| 8649 | // above, before checking that the generated packet is correct. |
| 8650 | EXPECT_EQ(kQuicPathFrameBufferSize, payload.size()); |
| 8651 | |
| 8652 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 8653 | header); |
| 8654 | |
| 8655 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 8656 | data.length(), AsChars(packet), |
| 8657 | QUIC_ARRAYSIZE(packet)); |
| 8658 | } |
| 8659 | |
| 8660 | // Several tests that the path response connectivity probing packet is |
| 8661 | // serialized correctly as either a padded and unpadded PATH RESPONSE |
| 8662 | // packet. Also generates packets with 1 and 3 PATH_RESPONSES in them to |
| 8663 | // exercised the single- and multiple- payload cases. |
| 8664 | TEST_P(QuicFramerTest, BuildPathResponsePacket1ResponseUnpadded) { |
| 8665 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8666 | return; |
| 8667 | } |
| 8668 | |
| 8669 | QuicPacketHeader header; |
| 8670 | header.destination_connection_id = FramerTestConnectionId(); |
| 8671 | header.reset_flag = false; |
| 8672 | header.version_flag = false; |
| 8673 | header.packet_number = kPacketNumber; |
| 8674 | QuicPathFrameBuffer payload0 = { |
| 8675 | {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}}; |
| 8676 | |
| 8677 | // Build 1 PATH RESPONSE, not padded |
| 8678 | // clang-format off |
| 8679 | unsigned char packet[] = { |
| 8680 | // type (short header, 4 byte packet number) |
| 8681 | 0x43, |
| 8682 | // connection_id |
| 8683 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8684 | // packet number |
| 8685 | 0x12, 0x34, 0x56, 0x78, |
| 8686 | |
| 8687 | // Path Response Frame type (IETF_PATH_RESPONSE) |
| 8688 | 0x1b, |
| 8689 | // 8 "random" bytes |
| 8690 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 8691 | }; |
| 8692 | // clang-format on |
| 8693 | std::unique_ptr<char[]> buffer(new char[kMaxPacketSize]); |
| 8694 | QuicDeque<QuicPathFrameBuffer> payloads; |
| 8695 | payloads.push_back(payload0); |
| 8696 | size_t length = framer_.BuildPathResponsePacket( |
| 8697 | header, buffer.get(), QUIC_ARRAYSIZE(packet), payloads, |
| 8698 | /*is_padded=*/false, ENCRYPTION_NONE); |
| 8699 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 8700 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 8701 | header); |
| 8702 | |
| 8703 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 8704 | data.length(), AsChars(packet), |
| 8705 | QUIC_ARRAYSIZE(packet)); |
| 8706 | } |
| 8707 | |
| 8708 | TEST_P(QuicFramerTest, BuildPathResponsePacket1ResponsePadded) { |
| 8709 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8710 | return; |
| 8711 | } |
| 8712 | |
| 8713 | QuicPacketHeader header; |
| 8714 | header.destination_connection_id = FramerTestConnectionId(); |
| 8715 | header.reset_flag = false; |
| 8716 | header.version_flag = false; |
| 8717 | header.packet_number = kPacketNumber; |
| 8718 | QuicPathFrameBuffer payload0 = { |
| 8719 | {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}}; |
| 8720 | |
| 8721 | // Build 1 PATH RESPONSE, padded |
| 8722 | // clang-format off |
| 8723 | unsigned char packet[] = { |
| 8724 | // type (short header, 4 byte packet number) |
| 8725 | 0x43, |
| 8726 | // connection_id |
| 8727 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8728 | // packet number |
| 8729 | 0x12, 0x34, 0x56, 0x78, |
| 8730 | |
| 8731 | // Path Response Frame type (IETF_PATH_RESPONSE) |
| 8732 | 0x1b, |
| 8733 | // 8 "random" bytes |
| 8734 | 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 8735 | // Padding type and pad |
| 8736 | 0x00, 0x00, 0x00, 0x00, 0x00 |
| 8737 | }; |
| 8738 | // clang-format on |
| 8739 | std::unique_ptr<char[]> buffer(new char[kMaxPacketSize]); |
| 8740 | QuicDeque<QuicPathFrameBuffer> payloads; |
| 8741 | payloads.push_back(payload0); |
| 8742 | size_t length = framer_.BuildPathResponsePacket( |
| 8743 | header, buffer.get(), QUIC_ARRAYSIZE(packet), payloads, |
| 8744 | /*is_padded=*/true, ENCRYPTION_NONE); |
| 8745 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 8746 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 8747 | header); |
| 8748 | |
| 8749 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 8750 | data.length(), AsChars(packet), |
| 8751 | QUIC_ARRAYSIZE(packet)); |
| 8752 | } |
| 8753 | |
| 8754 | TEST_P(QuicFramerTest, BuildPathResponsePacket3ResponsesUnpadded) { |
| 8755 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8756 | return; |
| 8757 | } |
| 8758 | |
| 8759 | QuicPacketHeader header; |
| 8760 | header.destination_connection_id = FramerTestConnectionId(); |
| 8761 | header.reset_flag = false; |
| 8762 | header.version_flag = false; |
| 8763 | header.packet_number = kPacketNumber; |
| 8764 | QuicPathFrameBuffer payload0 = { |
| 8765 | {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}}; |
| 8766 | QuicPathFrameBuffer payload1 = { |
| 8767 | {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}}; |
| 8768 | QuicPathFrameBuffer payload2 = { |
| 8769 | {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28}}; |
| 8770 | |
| 8771 | // Build one packet with 3 PATH RESPONSES, no padding |
| 8772 | // clang-format off |
| 8773 | unsigned char packet[] = { |
| 8774 | // type (short header, 4 byte packet number) |
| 8775 | 0x43, |
| 8776 | // connection_id |
| 8777 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8778 | // packet number |
| 8779 | 0x12, 0x34, 0x56, 0x78, |
| 8780 | |
| 8781 | // 3 path response frames (IETF_PATH_RESPONSE type byte and payload) |
| 8782 | 0x1b, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 8783 | 0x1b, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, |
| 8784 | 0x1b, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, |
| 8785 | }; |
| 8786 | // clang-format on |
| 8787 | |
| 8788 | std::unique_ptr<char[]> buffer(new char[kMaxPacketSize]); |
| 8789 | QuicDeque<QuicPathFrameBuffer> payloads; |
| 8790 | payloads.push_back(payload0); |
| 8791 | payloads.push_back(payload1); |
| 8792 | payloads.push_back(payload2); |
| 8793 | size_t length = framer_.BuildPathResponsePacket( |
| 8794 | header, buffer.get(), QUIC_ARRAYSIZE(packet), payloads, |
| 8795 | /*is_padded=*/false, ENCRYPTION_NONE); |
| 8796 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 8797 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 8798 | header); |
| 8799 | |
| 8800 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 8801 | data.length(), AsChars(packet), |
| 8802 | QUIC_ARRAYSIZE(packet)); |
| 8803 | } |
| 8804 | |
| 8805 | TEST_P(QuicFramerTest, BuildPathResponsePacket3ResponsesPadded) { |
| 8806 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 8807 | return; |
| 8808 | } |
| 8809 | |
| 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 | QuicPathFrameBuffer payload0 = { |
| 8816 | {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}}; |
| 8817 | QuicPathFrameBuffer payload1 = { |
| 8818 | {0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18}}; |
| 8819 | QuicPathFrameBuffer payload2 = { |
| 8820 | {0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28}}; |
| 8821 | |
| 8822 | // Build one packet with 3 PATH RESPONSES, with padding |
| 8823 | // clang-format off |
| 8824 | unsigned char packet[] = { |
| 8825 | // type (short header, 4 byte packet number) |
| 8826 | 0x43, |
| 8827 | // connection_id |
| 8828 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8829 | // packet number |
| 8830 | 0x12, 0x34, 0x56, 0x78, |
| 8831 | |
| 8832 | // 3 path response frames (IETF_PATH_RESPONSE byte and payload) |
| 8833 | 0x1b, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, |
| 8834 | 0x1b, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, |
| 8835 | 0x1b, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, |
| 8836 | // Padding |
| 8837 | 0x00, 0x00, 0x00, 0x00, 0x00 |
| 8838 | }; |
| 8839 | // clang-format on |
| 8840 | |
| 8841 | std::unique_ptr<char[]> buffer(new char[kMaxPacketSize]); |
| 8842 | QuicDeque<QuicPathFrameBuffer> payloads; |
| 8843 | payloads.push_back(payload0); |
| 8844 | payloads.push_back(payload1); |
| 8845 | payloads.push_back(payload2); |
| 8846 | size_t length = framer_.BuildPathResponsePacket( |
| 8847 | header, buffer.get(), QUIC_ARRAYSIZE(packet), payloads, |
| 8848 | /*is_padded=*/true, ENCRYPTION_NONE); |
| 8849 | EXPECT_EQ(length, QUIC_ARRAYSIZE(packet)); |
| 8850 | QuicPacket data(framer_.transport_version(), buffer.release(), length, true, |
| 8851 | header); |
| 8852 | |
| 8853 | test::CompareCharArraysWithHexError("constructed packet", data.data(), |
| 8854 | data.length(), AsChars(packet), |
| 8855 | QUIC_ARRAYSIZE(packet)); |
| 8856 | } |
| 8857 | |
| 8858 | // Test that the MTU discovery packet is serialized correctly as a PING packet. |
| 8859 | TEST_P(QuicFramerTest, BuildMtuDiscoveryPacket) { |
| 8860 | QuicPacketHeader header; |
| 8861 | header.destination_connection_id = FramerTestConnectionId(); |
| 8862 | header.reset_flag = false; |
| 8863 | header.version_flag = false; |
| 8864 | header.packet_number = kPacketNumber; |
| 8865 | |
| 8866 | QuicFrames frames = {QuicFrame(QuicMtuDiscoveryFrame())}; |
| 8867 | |
| 8868 | // clang-format off |
| 8869 | unsigned char packet[] = { |
| 8870 | // public flags (8 byte connection_id) |
| 8871 | 0x28, |
| 8872 | // connection_id |
| 8873 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8874 | // packet number |
| 8875 | 0x12, 0x34, 0x56, 0x78, |
| 8876 | |
| 8877 | // frame type (ping frame) |
| 8878 | 0x07, |
| 8879 | }; |
| 8880 | |
| 8881 | unsigned char packet44[] = { |
| 8882 | // type (short header, 4 byte packet number) |
| 8883 | 0x32, |
| 8884 | // connection_id |
| 8885 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8886 | // packet number |
| 8887 | 0x12, 0x34, 0x56, 0x78, |
| 8888 | |
| 8889 | // frame type |
| 8890 | 0x07, |
| 8891 | }; |
| 8892 | |
| 8893 | unsigned char packet46[] = { |
| 8894 | // type (short header, 4 byte packet number) |
| 8895 | 0x43, |
| 8896 | // connection_id |
| 8897 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8898 | // packet number |
| 8899 | 0x12, 0x34, 0x56, 0x78, |
| 8900 | |
| 8901 | // frame type |
| 8902 | 0x07, |
| 8903 | }; |
| 8904 | |
| 8905 | unsigned char packet99[] = { |
| 8906 | // type (short header, 4 byte packet number) |
| 8907 | 0x43, |
| 8908 | // connection_id |
| 8909 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8910 | // packet number |
| 8911 | 0x12, 0x34, 0x56, 0x78, |
| 8912 | |
| 8913 | // frame type (IETF_PING frame) |
| 8914 | 0x01, |
| 8915 | }; |
| 8916 | // clang-format on |
| 8917 | |
| 8918 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 8919 | ASSERT_TRUE(data != nullptr); |
| 8920 | |
| 8921 | unsigned char* p = packet; |
| 8922 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 8923 | p = packet99; |
| 8924 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 8925 | p = packet46; |
| 8926 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8927 | p = packet44; |
| 8928 | } |
| 8929 | |
| 8930 | test::CompareCharArraysWithHexError( |
| 8931 | "constructed packet", data->data(), data->length(), AsChars(p), |
| 8932 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 8933 | : QUIC_ARRAYSIZE(packet)); |
| 8934 | } |
| 8935 | |
| 8936 | TEST_P(QuicFramerTest, BuildPublicResetPacket) { |
| 8937 | QuicPublicResetPacket reset_packet; |
| 8938 | reset_packet.connection_id = FramerTestConnectionId(); |
| 8939 | reset_packet.nonce_proof = kNonceProof; |
| 8940 | |
| 8941 | // clang-format off |
| 8942 | unsigned char packet[] = { |
| 8943 | // public flags (public reset, 8 byte ConnectionId) |
| 8944 | 0x0E, |
| 8945 | // connection_id |
| 8946 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 8947 | // message tag (kPRST) |
| 8948 | 'P', 'R', 'S', 'T', |
| 8949 | // num_entries (1) + padding |
| 8950 | 0x01, 0x00, 0x00, 0x00, |
| 8951 | // tag kRNON |
| 8952 | 'R', 'N', 'O', 'N', |
| 8953 | // end offset 8 |
| 8954 | 0x08, 0x00, 0x00, 0x00, |
| 8955 | // nonce proof |
| 8956 | 0x89, 0x67, 0x45, 0x23, |
| 8957 | 0x01, 0xEF, 0xCD, 0xAB, |
| 8958 | }; |
| 8959 | // clang-format on |
| 8960 | |
| 8961 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 8962 | return; |
| 8963 | } |
| 8964 | |
| 8965 | std::unique_ptr<QuicEncryptedPacket> data( |
| 8966 | framer_.BuildPublicResetPacket(reset_packet)); |
| 8967 | ASSERT_TRUE(data != nullptr); |
| 8968 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 8969 | data->length(), AsChars(packet), |
| 8970 | QUIC_ARRAYSIZE(packet)); |
| 8971 | } |
| 8972 | |
| 8973 | TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) { |
| 8974 | QuicPublicResetPacket reset_packet; |
| 8975 | reset_packet.connection_id = FramerTestConnectionId(); |
| 8976 | reset_packet.nonce_proof = kNonceProof; |
| 8977 | reset_packet.client_address = |
| 8978 | QuicSocketAddress(QuicIpAddress::Loopback4(), 0x1234); |
| 8979 | |
| 8980 | // clang-format off |
| 8981 | unsigned char packet[] = { |
| 8982 | // public flags (public reset, 8 byte ConnectionId) |
| 8983 | 0x0E, |
| 8984 | // connection_id |
| 8985 | 0xFE, 0xDC, 0xBA, 0x98, |
| 8986 | 0x76, 0x54, 0x32, 0x10, |
| 8987 | // message tag (kPRST) |
| 8988 | 'P', 'R', 'S', 'T', |
| 8989 | // num_entries (2) + padding |
| 8990 | 0x02, 0x00, 0x00, 0x00, |
| 8991 | // tag kRNON |
| 8992 | 'R', 'N', 'O', 'N', |
| 8993 | // end offset 8 |
| 8994 | 0x08, 0x00, 0x00, 0x00, |
| 8995 | // tag kCADR |
| 8996 | 'C', 'A', 'D', 'R', |
| 8997 | // end offset 16 |
| 8998 | 0x10, 0x00, 0x00, 0x00, |
| 8999 | // nonce proof |
| 9000 | 0x89, 0x67, 0x45, 0x23, |
| 9001 | 0x01, 0xEF, 0xCD, 0xAB, |
| 9002 | // client address |
| 9003 | 0x02, 0x00, |
| 9004 | 0x7F, 0x00, 0x00, 0x01, |
| 9005 | 0x34, 0x12, |
| 9006 | }; |
| 9007 | // clang-format on |
| 9008 | |
| 9009 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9010 | return; |
| 9011 | } |
| 9012 | |
| 9013 | std::unique_ptr<QuicEncryptedPacket> data( |
| 9014 | framer_.BuildPublicResetPacket(reset_packet)); |
| 9015 | ASSERT_TRUE(data != nullptr); |
| 9016 | |
| 9017 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 9018 | data->length(), AsChars(packet), |
| 9019 | QUIC_ARRAYSIZE(packet)); |
| 9020 | } |
| 9021 | |
| 9022 | TEST_P(QuicFramerTest, BuildPublicResetPacketWithEndpointId) { |
| 9023 | QuicPublicResetPacket reset_packet; |
| 9024 | reset_packet.connection_id = FramerTestConnectionId(); |
| 9025 | reset_packet.nonce_proof = kNonceProof; |
| 9026 | reset_packet.endpoint_id = "FakeServerId"; |
| 9027 | |
| 9028 | // The tag value map in CryptoHandshakeMessage is a std::map, so the two tags |
| 9029 | // in the packet, kRNON and kEPID, have unspecified ordering w.r.t each other. |
| 9030 | // clang-format off |
| 9031 | unsigned char packet_variant1[] = { |
| 9032 | // public flags (public reset, 8 byte ConnectionId) |
| 9033 | 0x0E, |
| 9034 | // connection_id |
| 9035 | 0xFE, 0xDC, 0xBA, 0x98, |
| 9036 | 0x76, 0x54, 0x32, 0x10, |
| 9037 | // message tag (kPRST) |
| 9038 | 'P', 'R', 'S', 'T', |
| 9039 | // num_entries (2) + padding |
| 9040 | 0x02, 0x00, 0x00, 0x00, |
| 9041 | // tag kRNON |
| 9042 | 'R', 'N', 'O', 'N', |
| 9043 | // end offset 8 |
| 9044 | 0x08, 0x00, 0x00, 0x00, |
| 9045 | // tag kEPID |
| 9046 | 'E', 'P', 'I', 'D', |
| 9047 | // end offset 20 |
| 9048 | 0x14, 0x00, 0x00, 0x00, |
| 9049 | // nonce proof |
| 9050 | 0x89, 0x67, 0x45, 0x23, |
| 9051 | 0x01, 0xEF, 0xCD, 0xAB, |
| 9052 | // Endpoint ID |
| 9053 | 'F', 'a', 'k', 'e', 'S', 'e', 'r', 'v', 'e', 'r', 'I', 'd', |
| 9054 | }; |
| 9055 | unsigned char packet_variant2[] = { |
| 9056 | // public flags (public reset, 8 byte ConnectionId) |
| 9057 | 0x0E, |
| 9058 | // connection_id |
| 9059 | 0xFE, 0xDC, 0xBA, 0x98, |
| 9060 | 0x76, 0x54, 0x32, 0x10, |
| 9061 | // message tag (kPRST) |
| 9062 | 'P', 'R', 'S', 'T', |
| 9063 | // num_entries (2) + padding |
| 9064 | 0x02, 0x00, 0x00, 0x00, |
| 9065 | // tag kEPID |
| 9066 | 'E', 'P', 'I', 'D', |
| 9067 | // end offset 12 |
| 9068 | 0x0C, 0x00, 0x00, 0x00, |
| 9069 | // tag kRNON |
| 9070 | 'R', 'N', 'O', 'N', |
| 9071 | // end offset 20 |
| 9072 | 0x14, 0x00, 0x00, 0x00, |
| 9073 | // Endpoint ID |
| 9074 | 'F', 'a', 'k', 'e', 'S', 'e', 'r', 'v', 'e', 'r', 'I', 'd', |
| 9075 | // nonce proof |
| 9076 | 0x89, 0x67, 0x45, 0x23, |
| 9077 | 0x01, 0xEF, 0xCD, 0xAB, |
| 9078 | }; |
| 9079 | // clang-format on |
| 9080 | |
| 9081 | if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9082 | return; |
| 9083 | } |
| 9084 | |
| 9085 | std::unique_ptr<QuicEncryptedPacket> data( |
| 9086 | framer_.BuildPublicResetPacket(reset_packet)); |
| 9087 | ASSERT_TRUE(data != nullptr); |
| 9088 | |
| 9089 | // Variant 1 ends with char 'd'. Variant 1 ends with char 0xAB. |
| 9090 | if ('d' == data->data()[data->length() - 1]) { |
| 9091 | test::CompareCharArraysWithHexError( |
| 9092 | "constructed packet", data->data(), data->length(), |
| 9093 | AsChars(packet_variant1), QUIC_ARRAYSIZE(packet_variant1)); |
| 9094 | } else { |
| 9095 | test::CompareCharArraysWithHexError( |
| 9096 | "constructed packet", data->data(), data->length(), |
| 9097 | AsChars(packet_variant2), QUIC_ARRAYSIZE(packet_variant2)); |
| 9098 | } |
| 9099 | } |
| 9100 | |
| 9101 | TEST_P(QuicFramerTest, BuildIetfStatelessResetPacket) { |
| 9102 | // clang-format off |
| 9103 | unsigned char packet44[] = { |
| 9104 | // type (short header, 1 byte packet number) |
| 9105 | 0x70, |
| 9106 | // random packet number |
| 9107 | 0xFE, |
| 9108 | // stateless reset token |
| 9109 | 0xB5, 0x69, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 9110 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 9111 | }; |
| 9112 | // clang-format on |
| 9113 | |
| 9114 | std::unique_ptr<QuicEncryptedPacket> data( |
| 9115 | framer_.BuildIetfStatelessResetPacket(FramerTestConnectionId(), |
| 9116 | kTestStatelessResetToken)); |
| 9117 | ASSERT_TRUE(data != nullptr); |
| 9118 | // Skip packet number byte which is random in stateless reset packet. |
| 9119 | test::CompareCharArraysWithHexError("constructed packet", data->data(), 1, |
| 9120 | AsChars(packet44), 1); |
| 9121 | const size_t random_bytes_length = |
| 9122 | data->length() - kPacketHeaderTypeSize - sizeof(kTestStatelessResetToken); |
| 9123 | EXPECT_EQ(kMinRandomBytesLengthInStatelessReset, random_bytes_length); |
| 9124 | // Verify stateless reset token is correct. |
| 9125 | test::CompareCharArraysWithHexError( |
| 9126 | "constructed packet", |
| 9127 | data->data() + data->length() - sizeof(kTestStatelessResetToken), |
| 9128 | sizeof(kTestStatelessResetToken), |
| 9129 | AsChars(packet44) + QUIC_ARRAYSIZE(packet44) - |
| 9130 | sizeof(kTestStatelessResetToken), |
| 9131 | sizeof(kTestStatelessResetToken)); |
| 9132 | } |
| 9133 | |
| 9134 | TEST_P(QuicFramerTest, EncryptPacket) { |
| 9135 | QuicPacketNumber packet_number = kPacketNumber; |
| 9136 | // clang-format off |
| 9137 | unsigned char packet[] = { |
| 9138 | // public flags (8 byte connection_id) |
| 9139 | 0x28, |
| 9140 | // connection_id |
| 9141 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9142 | // packet number |
| 9143 | 0x12, 0x34, 0x56, 0x78, |
| 9144 | |
| 9145 | // redundancy |
| 9146 | 'a', 'b', 'c', 'd', |
| 9147 | 'e', 'f', 'g', 'h', |
| 9148 | 'i', 'j', 'k', 'l', |
| 9149 | 'm', 'n', 'o', 'p', |
| 9150 | }; |
| 9151 | |
| 9152 | unsigned char packet44[] = { |
| 9153 | // type (short header, 4 byte packet number) |
| 9154 | 0x32, |
| 9155 | // connection_id |
| 9156 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9157 | // packet number |
| 9158 | 0x12, 0x34, 0x56, 0x78, |
| 9159 | |
| 9160 | // redundancy |
| 9161 | 'a', 'b', 'c', 'd', |
| 9162 | 'e', 'f', 'g', 'h', |
| 9163 | 'i', 'j', 'k', 'l', |
| 9164 | 'm', 'n', 'o', 'p', |
| 9165 | }; |
| 9166 | |
| 9167 | unsigned char packet46[] = { |
| 9168 | // type (short header, 4 byte packet number) |
| 9169 | 0x43, |
| 9170 | // connection_id |
| 9171 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9172 | // packet number |
| 9173 | 0x12, 0x34, 0x56, 0x78, |
| 9174 | |
| 9175 | // redundancy |
| 9176 | 'a', 'b', 'c', 'd', |
| 9177 | 'e', 'f', 'g', 'h', |
| 9178 | 'i', 'j', 'k', 'l', |
| 9179 | 'm', 'n', 'o', 'p', |
| 9180 | }; |
| 9181 | |
| 9182 | unsigned char packet99[] = { |
| 9183 | // type (short header, 4 byte packet number) |
| 9184 | 0x43, |
| 9185 | // connection_id |
| 9186 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9187 | // packet number |
| 9188 | 0x12, 0x34, 0x56, 0x78, |
| 9189 | |
| 9190 | // redundancy |
| 9191 | 'a', 'b', 'c', 'd', |
| 9192 | 'e', 'f', 'g', 'h', |
| 9193 | 'i', 'j', 'k', 'l', |
| 9194 | 'm', 'n', 'o', 'p', |
| 9195 | }; |
| 9196 | // clang-format on |
| 9197 | |
| 9198 | unsigned char* p = packet; |
| 9199 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9200 | p = packet99; |
| 9201 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 9202 | p = packet46; |
| 9203 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9204 | p = packet44; |
| 9205 | } |
| 9206 | |
| 9207 | std::unique_ptr<QuicPacket> raw(new QuicPacket( |
| 9208 | AsChars(p), QUIC_ARRAYSIZE(packet), false, PACKET_8BYTE_CONNECTION_ID, |
| 9209 | PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
| 9210 | !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER, |
| 9211 | VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, VARIABLE_LENGTH_INTEGER_LENGTH_0)); |
| 9212 | char buffer[kMaxPacketSize]; |
| 9213 | size_t encrypted_length = framer_.EncryptPayload( |
| 9214 | ENCRYPTION_NONE, packet_number, *raw, buffer, kMaxPacketSize); |
| 9215 | |
| 9216 | ASSERT_NE(0u, encrypted_length); |
| 9217 | EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); |
| 9218 | } |
| 9219 | |
| 9220 | TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) { |
| 9221 | QuicPacketNumber packet_number = kPacketNumber; |
| 9222 | // clang-format off |
| 9223 | unsigned char packet[] = { |
| 9224 | // public flags (version, 8 byte connection_id) |
| 9225 | 0x29, |
| 9226 | // connection_id |
| 9227 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9228 | // version tag |
| 9229 | 'Q', '.', '1', '0', |
| 9230 | // packet number |
| 9231 | 0x12, 0x34, 0x56, 0x78, |
| 9232 | |
| 9233 | // redundancy |
| 9234 | 'a', 'b', 'c', 'd', |
| 9235 | 'e', 'f', 'g', 'h', |
| 9236 | 'i', 'j', 'k', 'l', |
| 9237 | 'm', 'n', 'o', 'p', |
| 9238 | }; |
| 9239 | |
| 9240 | unsigned char packet44[] = { |
| 9241 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 9242 | 0xFC, |
| 9243 | // version tag |
| 9244 | 'Q', '.', '1', '0', |
| 9245 | // connection_id length |
| 9246 | 0x50, |
| 9247 | // connection_id |
| 9248 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9249 | // packet number |
| 9250 | 0x12, 0x34, 0x56, 0x78, |
| 9251 | |
| 9252 | // redundancy |
| 9253 | 'a', 'b', 'c', 'd', |
| 9254 | 'e', 'f', 'g', 'h', |
| 9255 | 'i', 'j', 'k', 'l', |
| 9256 | 'm', 'n', 'o', 'p', |
| 9257 | }; |
| 9258 | |
| 9259 | unsigned char packet46[] = { |
| 9260 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 9261 | 0xD3, |
| 9262 | // version tag |
| 9263 | 'Q', '.', '1', '0', |
| 9264 | // connection_id length |
| 9265 | 0x50, |
| 9266 | // connection_id |
| 9267 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9268 | // packet number |
| 9269 | 0x12, 0x34, 0x56, 0x78, |
| 9270 | |
| 9271 | // redundancy |
| 9272 | 'a', 'b', 'c', 'd', |
| 9273 | 'e', 'f', 'g', 'h', |
| 9274 | 'i', 'j', 'k', 'l', |
| 9275 | 'm', 'n', 'o', 'p', |
| 9276 | }; |
| 9277 | |
| 9278 | unsigned char packet99[] = { |
| 9279 | // type (long header with packet type ZERO_RTT_PROTECTED) |
| 9280 | 0xD3, |
| 9281 | // version tag |
| 9282 | 'Q', '.', '1', '0', |
| 9283 | // connection_id length |
| 9284 | 0x50, |
| 9285 | // connection_id |
| 9286 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9287 | // packet number |
| 9288 | 0x12, 0x34, 0x56, 0x78, |
| 9289 | |
| 9290 | // redundancy |
| 9291 | 'a', 'b', 'c', 'd', |
| 9292 | 'e', 'f', 'g', 'h', |
| 9293 | 'i', 'j', 'k', 'l', |
| 9294 | 'm', 'n', 'o', 'p', |
| 9295 | }; |
| 9296 | // clang-format on |
| 9297 | |
| 9298 | unsigned char* p = packet; |
| 9299 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9300 | p = packet99; |
| 9301 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 9302 | p = packet46; |
| 9303 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9304 | p = packet44; |
| 9305 | } |
| 9306 | |
| 9307 | std::unique_ptr<QuicPacket> raw(new QuicPacket( |
| 9308 | AsChars(p), |
| 9309 | framer_.transport_version() > QUIC_VERSION_43 ? QUIC_ARRAYSIZE(packet44) |
| 9310 | : QUIC_ARRAYSIZE(packet), |
| 9311 | false, PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID, |
| 9312 | kIncludeVersion, !kIncludeDiversificationNonce, |
| 9313 | PACKET_4BYTE_PACKET_NUMBER, VARIABLE_LENGTH_INTEGER_LENGTH_0, 0, |
| 9314 | VARIABLE_LENGTH_INTEGER_LENGTH_0)); |
| 9315 | char buffer[kMaxPacketSize]; |
| 9316 | size_t encrypted_length = framer_.EncryptPayload( |
| 9317 | ENCRYPTION_NONE, packet_number, *raw, buffer, kMaxPacketSize); |
| 9318 | |
| 9319 | ASSERT_NE(0u, encrypted_length); |
| 9320 | EXPECT_TRUE(CheckEncryption(packet_number, raw.get())); |
| 9321 | } |
| 9322 | |
| 9323 | TEST_P(QuicFramerTest, AckTruncationLargePacket) { |
| 9324 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9325 | // This test is not applicable to this version; the range count is |
| 9326 | // effectively unlimited |
| 9327 | return; |
| 9328 | } |
| 9329 | |
| 9330 | QuicPacketHeader header; |
| 9331 | header.destination_connection_id = FramerTestConnectionId(); |
| 9332 | header.reset_flag = false; |
| 9333 | header.version_flag = false; |
| 9334 | header.packet_number = kPacketNumber; |
| 9335 | |
| 9336 | QuicAckFrame ack_frame; |
| 9337 | // Create a packet with just the ack. |
| 9338 | ack_frame = MakeAckFrameWithAckBlocks(300, 0u); |
| 9339 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 9340 | |
| 9341 | // Build an ack packet with truncation due to limit in number of nack ranges. |
| 9342 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9343 | std::unique_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); |
| 9344 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9345 | char buffer[kMaxPacketSize]; |
| 9346 | size_t encrypted_length = |
| 9347 | framer_.EncryptPayload(ENCRYPTION_NONE, header.packet_number, |
| 9348 | *raw_ack_packet, buffer, kMaxPacketSize); |
| 9349 | ASSERT_NE(0u, encrypted_length); |
| 9350 | // Now make sure we can turn our ack packet back into an ack frame. |
| 9351 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 9352 | ASSERT_TRUE(framer_.ProcessPacket( |
| 9353 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 9354 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 9355 | QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; |
| 9356 | EXPECT_EQ(QuicPacketNumber(600u), LargestAcked(processed_ack_frame)); |
| 9357 | ASSERT_EQ(256u, processed_ack_frame.packets.NumPacketsSlow()); |
| 9358 | EXPECT_EQ(QuicPacketNumber(90u), processed_ack_frame.packets.Min()); |
| 9359 | EXPECT_EQ(QuicPacketNumber(600u), processed_ack_frame.packets.Max()); |
| 9360 | } |
| 9361 | |
| 9362 | TEST_P(QuicFramerTest, AckTruncationSmallPacket) { |
| 9363 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9364 | // This test is not applicable to this version; the range count is |
| 9365 | // effectively unlimited |
| 9366 | return; |
| 9367 | } |
| 9368 | |
| 9369 | QuicPacketHeader header; |
| 9370 | header.destination_connection_id = FramerTestConnectionId(); |
| 9371 | header.reset_flag = false; |
| 9372 | header.version_flag = false; |
| 9373 | header.packet_number = kPacketNumber; |
| 9374 | |
| 9375 | // Create a packet with just the ack. |
| 9376 | QuicAckFrame ack_frame; |
| 9377 | ack_frame = MakeAckFrameWithAckBlocks(300, 0u); |
| 9378 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 9379 | |
| 9380 | // Build an ack packet with truncation due to limit in number of nack ranges. |
| 9381 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9382 | std::unique_ptr<QuicPacket> raw_ack_packet( |
| 9383 | BuildDataPacket(header, frames, 500)); |
| 9384 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9385 | char buffer[kMaxPacketSize]; |
| 9386 | size_t encrypted_length = |
| 9387 | framer_.EncryptPayload(ENCRYPTION_NONE, header.packet_number, |
| 9388 | *raw_ack_packet, buffer, kMaxPacketSize); |
| 9389 | ASSERT_NE(0u, encrypted_length); |
| 9390 | // Now make sure we can turn our ack packet back into an ack frame. |
| 9391 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 9392 | ASSERT_TRUE(framer_.ProcessPacket( |
| 9393 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 9394 | ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
| 9395 | QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; |
| 9396 | EXPECT_EQ(QuicPacketNumber(600u), LargestAcked(processed_ack_frame)); |
| 9397 | ASSERT_EQ(240u, processed_ack_frame.packets.NumPacketsSlow()); |
| 9398 | EXPECT_EQ(QuicPacketNumber(122u), processed_ack_frame.packets.Min()); |
| 9399 | EXPECT_EQ(QuicPacketNumber(600u), processed_ack_frame.packets.Max()); |
| 9400 | } |
| 9401 | |
| 9402 | TEST_P(QuicFramerTest, CleanTruncation) { |
| 9403 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9404 | // This test is not applicable to this version; the range count is |
| 9405 | // effectively unlimited |
| 9406 | return; |
| 9407 | } |
| 9408 | |
| 9409 | QuicPacketHeader header; |
| 9410 | header.destination_connection_id = FramerTestConnectionId(); |
| 9411 | header.reset_flag = false; |
| 9412 | header.version_flag = false; |
| 9413 | header.packet_number = kPacketNumber; |
| 9414 | |
| 9415 | QuicAckFrame ack_frame = InitAckFrame(201); |
| 9416 | |
| 9417 | // Create a packet with just the ack. |
| 9418 | QuicFrames frames = {QuicFrame(&ack_frame)}; |
| 9419 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9420 | std::unique_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); |
| 9421 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9422 | |
| 9423 | char buffer[kMaxPacketSize]; |
| 9424 | size_t encrypted_length = |
| 9425 | framer_.EncryptPayload(ENCRYPTION_NONE, header.packet_number, |
| 9426 | *raw_ack_packet, buffer, kMaxPacketSize); |
| 9427 | ASSERT_NE(0u, encrypted_length); |
| 9428 | |
| 9429 | // Now make sure we can turn our ack packet back into an ack frame. |
| 9430 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_SERVER); |
| 9431 | ASSERT_TRUE(framer_.ProcessPacket( |
| 9432 | QuicEncryptedPacket(buffer, encrypted_length, false))); |
| 9433 | |
| 9434 | // Test for clean truncation of the ack by comparing the length of the |
| 9435 | // original packets to the re-serialized packets. |
| 9436 | frames.clear(); |
| 9437 | frames.push_back(QuicFrame(visitor_.ack_frames_[0].get())); |
| 9438 | |
| 9439 | size_t original_raw_length = raw_ack_packet->length(); |
| 9440 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 9441 | raw_ack_packet = BuildDataPacket(header, frames); |
| 9442 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9443 | EXPECT_EQ(original_raw_length, raw_ack_packet->length()); |
| 9444 | ASSERT_TRUE(raw_ack_packet != nullptr); |
| 9445 | } |
| 9446 | |
| 9447 | TEST_P(QuicFramerTest, StopPacketProcessing) { |
| 9448 | // clang-format off |
| 9449 | unsigned char packet[] = { |
| 9450 | // public flags (8 byte connection_id) |
| 9451 | 0x28, |
| 9452 | // connection_id |
| 9453 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9454 | // packet number |
| 9455 | 0x12, 0x34, 0x56, 0x78, |
| 9456 | |
| 9457 | // frame type (stream frame with fin) |
| 9458 | 0xFF, |
| 9459 | // stream id |
| 9460 | 0x01, 0x02, 0x03, 0x04, |
| 9461 | // offset |
| 9462 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9463 | 0x32, 0x10, 0x76, 0x54, |
| 9464 | // data length |
| 9465 | 0x00, 0x0c, |
| 9466 | // data |
| 9467 | 'h', 'e', 'l', 'l', |
| 9468 | 'o', ' ', 'w', 'o', |
| 9469 | 'r', 'l', 'd', '!', |
| 9470 | |
| 9471 | // frame type (ack frame) |
| 9472 | 0x40, |
| 9473 | // least packet number awaiting an ack |
| 9474 | 0x12, 0x34, 0x56, 0x78, |
| 9475 | 0x9A, 0xA0, |
| 9476 | // largest observed packet number |
| 9477 | 0x12, 0x34, 0x56, 0x78, |
| 9478 | 0x9A, 0xBF, |
| 9479 | // num missing packets |
| 9480 | 0x01, |
| 9481 | // missing packet |
| 9482 | 0x12, 0x34, 0x56, 0x78, |
| 9483 | 0x9A, 0xBE, |
| 9484 | }; |
| 9485 | |
| 9486 | unsigned char packet44[] = { |
| 9487 | // type (short header, 4 byte packet number) |
| 9488 | 0x32, |
| 9489 | // connection_id |
| 9490 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9491 | // packet number |
| 9492 | 0x12, 0x34, 0x56, 0x78, |
| 9493 | |
| 9494 | // frame type (stream frame with fin) |
| 9495 | 0xFF, |
| 9496 | // stream id |
| 9497 | 0x01, 0x02, 0x03, 0x04, |
| 9498 | // offset |
| 9499 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9500 | 0x32, 0x10, 0x76, 0x54, |
| 9501 | // data length |
| 9502 | 0x00, 0x0c, |
| 9503 | // data |
| 9504 | 'h', 'e', 'l', 'l', |
| 9505 | 'o', ' ', 'w', 'o', |
| 9506 | 'r', 'l', 'd', '!', |
| 9507 | |
| 9508 | // frame type (ack frame) |
| 9509 | 0x40, |
| 9510 | // least packet number awaiting an ack |
| 9511 | 0x12, 0x34, 0x56, 0x78, |
| 9512 | 0x9A, 0xA0, |
| 9513 | // largest observed packet number |
| 9514 | 0x12, 0x34, 0x56, 0x78, |
| 9515 | 0x9A, 0xBF, |
| 9516 | // num missing packets |
| 9517 | 0x01, |
| 9518 | // missing packet |
| 9519 | 0x12, 0x34, 0x56, 0x78, |
| 9520 | 0x9A, 0xBE, |
| 9521 | }; |
| 9522 | |
| 9523 | unsigned char packet46[] = { |
| 9524 | // type (short header, 4 byte packet number) |
| 9525 | 0x43, |
| 9526 | // connection_id |
| 9527 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9528 | // packet number |
| 9529 | 0x12, 0x34, 0x56, 0x78, |
| 9530 | |
| 9531 | // frame type (stream frame with fin) |
| 9532 | 0xFF, |
| 9533 | // stream id |
| 9534 | 0x01, 0x02, 0x03, 0x04, |
| 9535 | // offset |
| 9536 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9537 | 0x32, 0x10, 0x76, 0x54, |
| 9538 | // data length |
| 9539 | 0x00, 0x0c, |
| 9540 | // data |
| 9541 | 'h', 'e', 'l', 'l', |
| 9542 | 'o', ' ', 'w', 'o', |
| 9543 | 'r', 'l', 'd', '!', |
| 9544 | |
| 9545 | // frame type (ack frame) |
| 9546 | 0x40, |
| 9547 | // least packet number awaiting an ack |
| 9548 | 0x12, 0x34, 0x56, 0x78, |
| 9549 | 0x9A, 0xA0, |
| 9550 | // largest observed packet number |
| 9551 | 0x12, 0x34, 0x56, 0x78, |
| 9552 | 0x9A, 0xBF, |
| 9553 | // num missing packets |
| 9554 | 0x01, |
| 9555 | // missing packet |
| 9556 | 0x12, 0x34, 0x56, 0x78, |
| 9557 | 0x9A, 0xBE, |
| 9558 | }; |
| 9559 | |
| 9560 | unsigned char packet99[] = { |
| 9561 | // type (short header, 4 byte packet number) |
| 9562 | 0x43, |
| 9563 | // connection_id |
| 9564 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9565 | // packet number |
| 9566 | 0x12, 0x34, 0x56, 0x78, |
| 9567 | |
| 9568 | // frame type (IETF_STREAM frame with fin, length, and offset bits set) |
| 9569 | 0x08 | 0x01 | 0x02 | 0x04, |
| 9570 | // stream id |
| 9571 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 9572 | // offset |
| 9573 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 9574 | 0x32, 0x10, 0x76, 0x54, |
| 9575 | // data length |
| 9576 | kVarInt62TwoBytes + 0x00, 0x0c, |
| 9577 | // data |
| 9578 | 'h', 'e', 'l', 'l', |
| 9579 | 'o', ' ', 'w', 'o', |
| 9580 | 'r', 'l', 'd', '!', |
| 9581 | |
| 9582 | // frame type (ack frame) |
| 9583 | 0x0d, |
| 9584 | // largest observed packet number |
| 9585 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x78, |
| 9586 | // Delta time |
| 9587 | kVarInt62OneByte + 0x00, |
| 9588 | // Ack Block count |
| 9589 | kVarInt62OneByte + 0x01, |
| 9590 | // First block size (one packet) |
| 9591 | kVarInt62OneByte + 0x00, |
| 9592 | |
| 9593 | // Next gap size & ack. Missing all preceding packets |
| 9594 | kVarInt62FourBytes + 0x12, 0x34, 0x56, 0x77, |
| 9595 | kVarInt62OneByte + 0x00, |
| 9596 | }; |
| 9597 | // clang-format on |
| 9598 | |
| 9599 | MockFramerVisitor visitor; |
| 9600 | framer_.set_visitor(&visitor); |
| 9601 | EXPECT_CALL(visitor, OnPacket()); |
| 9602 | EXPECT_CALL(visitor, OnPacketHeader(_)); |
| 9603 | EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false)); |
| 9604 | EXPECT_CALL(visitor, OnPacketComplete()); |
| 9605 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); |
| 9606 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)).WillOnce(Return(true)); |
| 9607 | EXPECT_CALL(visitor, OnDecryptedPacket(_)); |
| 9608 | |
| 9609 | unsigned char* p = packet; |
| 9610 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 9611 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9612 | p = packet99; |
| 9613 | p_size = QUIC_ARRAYSIZE(packet99); |
| 9614 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 9615 | p = packet46; |
| 9616 | p_size = QUIC_ARRAYSIZE(packet46); |
| 9617 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9618 | p = packet44; |
| 9619 | p_size = QUIC_ARRAYSIZE(packet44); |
| 9620 | } |
| 9621 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 9622 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 9623 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9624 | } |
| 9625 | |
| 9626 | static char kTestString[] = "At least 20 characters."; |
| 9627 | static QuicStreamId kTestQuicStreamId = 1; |
| 9628 | static bool ExpectedStreamFrame(const QuicStreamFrame& frame) { |
| 9629 | return (frame.stream_id == kTestQuicStreamId || |
| 9630 | frame.stream_id == QuicUtils::GetCryptoStreamId(QUIC_VERSION_99)) && |
| 9631 | !frame.fin && frame.offset == 0 && |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 9632 | std::string(frame.data_buffer, frame.data_length) == kTestString; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9633 | // FIN is hard-coded false in ConstructEncryptedPacket. |
| 9634 | // Offset 0 is hard-coded in ConstructEncryptedPacket. |
| 9635 | } |
| 9636 | |
| 9637 | // Verify that the packet returned by ConstructEncryptedPacket() can be properly |
| 9638 | // parsed by the framer. |
| 9639 | TEST_P(QuicFramerTest, ConstructEncryptedPacket) { |
| 9640 | // Since we are using ConstructEncryptedPacket, we have to set the framer's |
| 9641 | // crypto to be Null. |
| 9642 | framer_.SetDecrypter(ENCRYPTION_NONE, |
| 9643 | QuicMakeUnique<NullDecrypter>(framer_.perspective())); |
| 9644 | framer_.SetEncrypter(ENCRYPTION_NONE, |
| 9645 | QuicMakeUnique<NullEncrypter>(framer_.perspective())); |
| 9646 | ParsedQuicVersionVector versions; |
| 9647 | versions.push_back(framer_.version()); |
| 9648 | std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( |
| 9649 | TestConnectionId(), EmptyQuicConnectionId(), false, false, |
| 9650 | kTestQuicStreamId, kTestString, CONNECTION_ID_PRESENT, |
| 9651 | CONNECTION_ID_ABSENT, PACKET_4BYTE_PACKET_NUMBER, &versions)); |
| 9652 | |
| 9653 | MockFramerVisitor visitor; |
| 9654 | framer_.set_visitor(&visitor); |
| 9655 | EXPECT_CALL(visitor, OnPacket()).Times(1); |
| 9656 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)) |
| 9657 | .Times(1) |
| 9658 | .WillOnce(Return(true)); |
| 9659 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)) |
| 9660 | .Times(1) |
| 9661 | .WillOnce(Return(true)); |
| 9662 | EXPECT_CALL(visitor, OnPacketHeader(_)).Times(1).WillOnce(Return(true)); |
| 9663 | EXPECT_CALL(visitor, OnDecryptedPacket(_)).Times(1); |
| 9664 | EXPECT_CALL(visitor, OnError(_)).Times(0); |
| 9665 | EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0); |
QUICHE team | ea74008 | 2019-03-11 17:58:43 -0700 | [diff] [blame] | 9666 | if (!QuicVersionUsesCryptoFrames(framer_.version().transport_version)) { |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 9667 | EXPECT_CALL(visitor, OnStreamFrame(Truly(ExpectedStreamFrame))).Times(1); |
| 9668 | } else { |
| 9669 | EXPECT_CALL(visitor, OnCryptoFrame(_)).Times(1); |
| 9670 | } |
| 9671 | EXPECT_CALL(visitor, OnPacketComplete()).Times(1); |
| 9672 | |
| 9673 | EXPECT_TRUE(framer_.ProcessPacket(*packet)); |
| 9674 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9675 | } |
| 9676 | |
| 9677 | // Verify that the packet returned by ConstructMisFramedEncryptedPacket() |
| 9678 | // does cause the framer to return an error. |
| 9679 | TEST_P(QuicFramerTest, ConstructMisFramedEncryptedPacket) { |
| 9680 | // Since we are using ConstructEncryptedPacket, we have to set the framer's |
| 9681 | // crypto to be Null. |
| 9682 | framer_.SetDecrypter(ENCRYPTION_NONE, |
| 9683 | QuicMakeUnique<NullDecrypter>(framer_.perspective())); |
| 9684 | framer_.SetEncrypter(ENCRYPTION_NONE, |
| 9685 | QuicMakeUnique<NullEncrypter>(framer_.perspective())); |
| 9686 | ParsedQuicVersionVector versions; |
| 9687 | versions.push_back(framer_.version()); |
| 9688 | std::unique_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket( |
| 9689 | TestConnectionId(), EmptyQuicConnectionId(), false, false, |
| 9690 | kTestQuicStreamId, kTestString, CONNECTION_ID_PRESENT, |
| 9691 | CONNECTION_ID_ABSENT, PACKET_4BYTE_PACKET_NUMBER, &versions, |
| 9692 | Perspective::IS_CLIENT)); |
| 9693 | |
| 9694 | MockFramerVisitor visitor; |
| 9695 | framer_.set_visitor(&visitor); |
| 9696 | EXPECT_CALL(visitor, OnPacket()).Times(1); |
| 9697 | EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)) |
| 9698 | .Times(1) |
| 9699 | .WillOnce(Return(true)); |
| 9700 | EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)) |
| 9701 | .Times(1) |
| 9702 | .WillOnce(Return(true)); |
| 9703 | EXPECT_CALL(visitor, OnPacketHeader(_)).Times(1); |
| 9704 | EXPECT_CALL(visitor, OnDecryptedPacket(_)).Times(1); |
| 9705 | EXPECT_CALL(visitor, OnError(_)).Times(1); |
| 9706 | EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0); |
| 9707 | EXPECT_CALL(visitor, OnPacketComplete()).Times(0); |
| 9708 | |
| 9709 | EXPECT_FALSE(framer_.ProcessPacket(*packet)); |
| 9710 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 9711 | } |
| 9712 | |
| 9713 | // Tests for fuzzing with Dr. Fuzz |
| 9714 | // Xref http://www.chromium.org/developers/testing/dr-fuzz for more details. |
| 9715 | #ifdef __cplusplus |
| 9716 | extern "C" { |
| 9717 | #endif |
| 9718 | |
| 9719 | // target function to be fuzzed by Dr. Fuzz |
| 9720 | void QuicFramerFuzzFunc(unsigned char* data, |
| 9721 | size_t size, |
| 9722 | const ParsedQuicVersion& version) { |
| 9723 | QuicFramer framer(AllSupportedVersions(), QuicTime::Zero(), |
| 9724 | Perspective::IS_SERVER, kQuicDefaultConnectionIdLength); |
| 9725 | ASSERT_EQ(GetQuicFlag(FLAGS_quic_supports_tls_handshake), true); |
| 9726 | const char* const packet_bytes = reinterpret_cast<const char*>(data); |
| 9727 | |
| 9728 | // Test the CryptoFramer. |
| 9729 | QuicStringPiece crypto_input(packet_bytes, size); |
| 9730 | std::unique_ptr<CryptoHandshakeMessage> handshake_message( |
| 9731 | CryptoFramer::ParseMessage(crypto_input)); |
| 9732 | |
| 9733 | // Test the regular QuicFramer with the same input. |
| 9734 | NoOpFramerVisitor visitor; |
| 9735 | framer.set_visitor(&visitor); |
| 9736 | framer.set_version(version); |
| 9737 | QuicEncryptedPacket packet(packet_bytes, size); |
| 9738 | framer.ProcessPacket(packet); |
| 9739 | } |
| 9740 | |
| 9741 | #ifdef __cplusplus |
| 9742 | } |
| 9743 | #endif |
| 9744 | |
| 9745 | TEST_P(QuicFramerTest, FramerFuzzTest) { |
| 9746 | // clang-format off |
| 9747 | unsigned char packet[] = { |
| 9748 | // public flags (8 byte connection_id) |
| 9749 | 0x2C, |
| 9750 | // connection_id |
| 9751 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9752 | // packet number |
| 9753 | 0x12, 0x34, 0x56, 0x78, |
| 9754 | // private flags |
| 9755 | 0x00, |
| 9756 | |
| 9757 | // frame type (stream frame with fin) |
| 9758 | 0xFF, |
| 9759 | // stream id |
| 9760 | 0x01, 0x02, 0x03, 0x04, |
| 9761 | // offset |
| 9762 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9763 | 0x32, 0x10, 0x76, 0x54, |
| 9764 | // data length |
| 9765 | 0x00, 0x0c, |
| 9766 | // data |
| 9767 | 'h', 'e', 'l', 'l', |
| 9768 | 'o', ' ', 'w', 'o', |
| 9769 | 'r', 'l', 'd', '!', |
| 9770 | }; |
| 9771 | |
| 9772 | unsigned char packet44[] = { |
| 9773 | // type (short header, 4 byte packet number) |
| 9774 | 0x32, |
| 9775 | // packet number |
| 9776 | 0x12, 0x34, 0x56, 0x78, |
| 9777 | |
| 9778 | // frame type (stream frame with fin, length, and offset bits set) |
| 9779 | 0x10 | 0x01 | 0x02 | 0x04, |
| 9780 | // stream id |
| 9781 | 0x01, 0x02, 0x03, 0x04, |
| 9782 | // offset |
| 9783 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9784 | 0x32, 0x10, 0x76, 0x54, |
| 9785 | // data length |
| 9786 | 0x00, 0x0c, |
| 9787 | // data |
| 9788 | 'h', 'e', 'l', 'l', |
| 9789 | 'o', ' ', 'w', 'o', |
| 9790 | 'r', 'l', 'd', '!', |
| 9791 | }; |
| 9792 | |
| 9793 | unsigned char packet46[] = { |
| 9794 | // type (short header, 4 byte packet number) |
| 9795 | 0x43, |
| 9796 | // packet number |
| 9797 | 0x12, 0x34, 0x56, 0x78, |
| 9798 | |
| 9799 | // frame type (stream frame with fin, length, and offset bits set) |
| 9800 | 0x10 | 0x01 | 0x02 | 0x04, |
| 9801 | // stream id |
| 9802 | 0x01, 0x02, 0x03, 0x04, |
| 9803 | // offset |
| 9804 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9805 | 0x32, 0x10, 0x76, 0x54, |
| 9806 | // data length |
| 9807 | 0x00, 0x0c, |
| 9808 | // data |
| 9809 | 'h', 'e', 'l', 'l', |
| 9810 | 'o', ' ', 'w', 'o', |
| 9811 | 'r', 'l', 'd', '!', |
| 9812 | }; |
| 9813 | |
| 9814 | unsigned char packet99[] = { |
| 9815 | // type (short header, 4 byte packet number) |
| 9816 | 0x43, |
| 9817 | // packet number |
| 9818 | 0x12, 0x34, 0x56, 0x78, |
| 9819 | |
| 9820 | // frame type (IETF_STREAM frame with fin, length, and offset bits set) |
| 9821 | 0x08 | 0x01 | 0x02 | 0x04, |
| 9822 | // stream id |
| 9823 | 0x01, 0x02, 0x03, 0x04, |
| 9824 | // offset |
| 9825 | 0x3A, 0x98, 0xFE, 0xDC, |
| 9826 | 0x32, 0x10, 0x76, 0x54, |
| 9827 | // data length |
| 9828 | 0x00, 0x0c, |
| 9829 | // data |
| 9830 | 'h', 'e', 'l', 'l', |
| 9831 | 'o', ' ', 'w', 'o', |
| 9832 | 'r', 'l', 'd', '!', |
| 9833 | }; |
| 9834 | // clang-format on |
| 9835 | |
| 9836 | unsigned char* p = packet; |
| 9837 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 9838 | p = packet99; |
| 9839 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 9840 | p = packet46; |
| 9841 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 9842 | p = packet44; |
| 9843 | } |
| 9844 | QuicFramerFuzzFunc(p, |
| 9845 | framer_.transport_version() > QUIC_VERSION_43 |
| 9846 | ? QUIC_ARRAYSIZE(packet44) |
| 9847 | : QUIC_ARRAYSIZE(packet), |
| 9848 | framer_.version()); |
| 9849 | } |
| 9850 | |
| 9851 | TEST_P(QuicFramerTest, StartsWithChlo) { |
| 9852 | SimpleDataProducer producer; |
| 9853 | framer_.set_data_producer(&producer); |
| 9854 | QuicStringPiece data("CHLOCHLO"); |
| 9855 | struct iovec iovec; |
| 9856 | iovec.iov_base = const_cast<char*>(data.data()); |
| 9857 | iovec.iov_len = data.length(); |
| 9858 | producer.SaveStreamData( |
| 9859 | QuicUtils::GetCryptoStreamId(framer_.transport_version()), &iovec, 1, 0, |
| 9860 | data.length()); |
| 9861 | for (size_t offset = 0; offset < 5; ++offset) { |
| 9862 | if (offset == 0 || offset == 4) { |
| 9863 | EXPECT_TRUE(framer_.StartsWithChlo( |
| 9864 | QuicUtils::GetCryptoStreamId(framer_.transport_version()), offset)); |
| 9865 | } else { |
| 9866 | EXPECT_FALSE(framer_.StartsWithChlo( |
| 9867 | QuicUtils::GetCryptoStreamId(framer_.transport_version()), offset)); |
| 9868 | } |
| 9869 | } |
| 9870 | } |
| 9871 | |
| 9872 | TEST_P(QuicFramerTest, IetfBlockedFrame) { |
| 9873 | // This test only for version 99. |
| 9874 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9875 | return; |
| 9876 | } |
| 9877 | |
| 9878 | // clang-format off |
| 9879 | PacketFragments packet99 = { |
| 9880 | // type (short header, 4 byte packet number) |
| 9881 | {"", |
| 9882 | {0x43}}, |
| 9883 | // connection_id |
| 9884 | {"", |
| 9885 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 9886 | // packet number |
| 9887 | {"", |
| 9888 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 9889 | // frame type (IETF_BLOCKED) |
| 9890 | {"", |
| 9891 | {0x14}}, |
| 9892 | // blocked offset |
| 9893 | {"Can not read blocked offset.", |
| 9894 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 9895 | }; |
| 9896 | // clang-format on |
| 9897 | |
| 9898 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9899 | AssemblePacketFromFragments(packet99)); |
| 9900 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9901 | |
| 9902 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9903 | ASSERT_TRUE(visitor_.header_.get()); |
| 9904 | EXPECT_TRUE(CheckDecryption( |
| 9905 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9906 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9907 | |
| 9908 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 9909 | |
| 9910 | CheckFramingBoundaries(packet99, QUIC_INVALID_BLOCKED_DATA); |
| 9911 | } |
| 9912 | |
| 9913 | TEST_P(QuicFramerTest, BuildIetfBlockedPacket) { |
| 9914 | // This test only for version 99. |
| 9915 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9916 | return; |
| 9917 | } |
| 9918 | |
| 9919 | QuicPacketHeader header; |
| 9920 | header.destination_connection_id = FramerTestConnectionId(); |
| 9921 | header.reset_flag = false; |
| 9922 | header.version_flag = false; |
| 9923 | header.packet_number = kPacketNumber; |
| 9924 | |
| 9925 | QuicBlockedFrame frame; |
| 9926 | frame.stream_id = QuicUtils::GetInvalidStreamId(framer_.transport_version()); |
| 9927 | frame.offset = kStreamOffset; |
| 9928 | QuicFrames frames = {QuicFrame(&frame)}; |
| 9929 | |
| 9930 | // clang-format off |
| 9931 | unsigned char packet99[] = { |
| 9932 | // type (short header, 4 byte packet number) |
| 9933 | 0x43, |
| 9934 | // connection_id |
| 9935 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 9936 | // packet number |
| 9937 | 0x12, 0x34, 0x56, 0x78, |
| 9938 | |
| 9939 | // frame type (IETF_BLOCKED) |
| 9940 | 0x14, |
| 9941 | // Offset |
| 9942 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 9943 | }; |
| 9944 | // clang-format on |
| 9945 | |
| 9946 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 9947 | ASSERT_TRUE(data != nullptr); |
| 9948 | |
| 9949 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 9950 | data->length(), AsChars(packet99), |
| 9951 | QUIC_ARRAYSIZE(packet99)); |
| 9952 | } |
| 9953 | |
| 9954 | TEST_P(QuicFramerTest, IetfStreamBlockedFrame) { |
| 9955 | // This test only for version 99. |
| 9956 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 9957 | return; |
| 9958 | } |
| 9959 | |
| 9960 | // clang-format off |
| 9961 | PacketFragments packet99 = { |
| 9962 | // type (short header, 4 byte packet number) |
| 9963 | {"", |
| 9964 | {0x43}}, |
| 9965 | // connection_id |
| 9966 | {"", |
| 9967 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 9968 | // packet number |
| 9969 | {"", |
| 9970 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 9971 | // frame type (IETF_STREAM_BLOCKED) |
| 9972 | {"", |
| 9973 | {0x15}}, |
| 9974 | // blocked offset |
| 9975 | {"Can not read stream blocked stream id.", |
| 9976 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 9977 | {"Can not read stream blocked offset.", |
| 9978 | {kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54}}, |
| 9979 | }; |
| 9980 | // clang-format on |
| 9981 | |
| 9982 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 9983 | AssemblePacketFromFragments(packet99)); |
| 9984 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 9985 | |
| 9986 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 9987 | ASSERT_TRUE(visitor_.header_.get()); |
| 9988 | EXPECT_TRUE(CheckDecryption( |
| 9989 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 9990 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 9991 | |
| 9992 | EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id); |
| 9993 | EXPECT_EQ(kStreamOffset, visitor_.blocked_frame_.offset); |
| 9994 | |
| 9995 | CheckFramingBoundaries(packet99, QUIC_INVALID_STREAM_BLOCKED_DATA); |
| 9996 | } |
| 9997 | |
| 9998 | TEST_P(QuicFramerTest, BuildIetfStreamBlockedPacket) { |
| 9999 | // This test only for version 99. |
| 10000 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10001 | return; |
| 10002 | } |
| 10003 | |
| 10004 | QuicPacketHeader header; |
| 10005 | header.destination_connection_id = FramerTestConnectionId(); |
| 10006 | header.reset_flag = false; |
| 10007 | header.version_flag = false; |
| 10008 | header.packet_number = kPacketNumber; |
| 10009 | |
| 10010 | QuicBlockedFrame frame; |
| 10011 | frame.stream_id = kStreamId; |
| 10012 | frame.offset = kStreamOffset; |
| 10013 | QuicFrames frames = {QuicFrame(&frame)}; |
| 10014 | |
| 10015 | // clang-format off |
| 10016 | unsigned char packet99[] = { |
| 10017 | // type (short header, 4 byte packet number) |
| 10018 | 0x43, |
| 10019 | // connection_id |
| 10020 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10021 | // packet number |
| 10022 | 0x12, 0x34, 0x56, 0x78, |
| 10023 | |
| 10024 | // frame type (IETF_STREAM_BLOCKED) |
| 10025 | 0x15, |
| 10026 | // Stream ID |
| 10027 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 10028 | // Offset |
| 10029 | kVarInt62EightBytes + 0x3a, 0x98, 0xFE, 0xDC, 0x32, 0x10, 0x76, 0x54 |
| 10030 | }; |
| 10031 | // clang-format on |
| 10032 | |
| 10033 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10034 | ASSERT_TRUE(data != nullptr); |
| 10035 | |
| 10036 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10037 | data->length(), AsChars(packet99), |
| 10038 | QUIC_ARRAYSIZE(packet99)); |
| 10039 | } |
| 10040 | |
| 10041 | TEST_P(QuicFramerTest, ServerBiDiMaxStreamsFrame) { |
| 10042 | // This test only for version 99. |
| 10043 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10044 | return; |
| 10045 | } |
| 10046 | |
| 10047 | // clang-format off |
| 10048 | PacketFragments packet99 = { |
| 10049 | // type (short header, 4 byte packet number) |
| 10050 | {"", |
| 10051 | {0x43}}, |
| 10052 | // connection_id |
| 10053 | {"", |
| 10054 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10055 | // packet number |
| 10056 | {"", |
| 10057 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10058 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 10059 | {"", |
| 10060 | {0x12}}, |
| 10061 | // max. streams |
| 10062 | {"Can not read MAX_STREAMS stream count.", |
| 10063 | {kVarInt62OneByte + 0x03}}, |
| 10064 | }; |
| 10065 | // clang-format on |
| 10066 | |
| 10067 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10068 | AssemblePacketFromFragments(packet99)); |
| 10069 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10070 | |
| 10071 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10072 | ASSERT_TRUE(visitor_.header_.get()); |
| 10073 | EXPECT_TRUE(CheckDecryption( |
| 10074 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10075 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10076 | |
| 10077 | // This test is a server receiving a MAX_STREAMS frame. The |
| 10078 | // stream ID that it generates should be a server-initiated |
| 10079 | // stream ID. The expected Stream ID is |
| 10080 | // ((0x3-1) * 4) | 0x1 = 0x9 |
| 10081 | // count-to-id server inited, bidi |
| 10082 | EXPECT_EQ(GetNthStreamid(QUIC_VERSION_99, Perspective::IS_SERVER, |
| 10083 | /*bidirectional=*/true, 3), |
| 10084 | visitor_.max_stream_id_frame_.max_stream_id); |
| 10085 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAM_ID_DATA); |
| 10086 | } |
| 10087 | |
| 10088 | TEST_P(QuicFramerTest, ClientBiDiMaxStreamsFrame) { |
| 10089 | // This test only for version 99. |
| 10090 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10091 | return; |
| 10092 | } |
| 10093 | |
| 10094 | // clang-format off |
| 10095 | PacketFragments packet99 = { |
| 10096 | // type (short header, 4 byte packet number) |
| 10097 | {"", |
| 10098 | {0x43}}, |
| 10099 | // Test runs in client mode, no connection id |
| 10100 | // packet number |
| 10101 | {"", |
| 10102 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10103 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 10104 | {"", |
| 10105 | {0x12}}, |
| 10106 | // max. streams |
| 10107 | {"Can not read MAX_STREAMS stream count.", |
| 10108 | {kVarInt62OneByte + 0x03}}, |
| 10109 | }; |
| 10110 | // clang-format on |
| 10111 | |
| 10112 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10113 | AssemblePacketFromFragments(packet99)); |
| 10114 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10115 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10116 | |
| 10117 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10118 | ASSERT_TRUE(visitor_.header_.get()); |
| 10119 | EXPECT_TRUE(CheckDecryption( |
| 10120 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10121 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10122 | |
| 10123 | // This test is a client receiving a MAX_STREAMS frame. The |
| 10124 | // stream ID that it generates should be a client-initiated |
| 10125 | // stream ID. The expected Stream ID is |
| 10126 | // ((0x3-1) * 4) = 0xc |
| 10127 | // It is not 8 because a client-initiated, bidi stream ID's |
| 10128 | // low bits are 00 - which means that the old crypto stream |
| 10129 | // falls into this category, and the first stream is streamid=4, |
| 10130 | // not streamid=0. |
| 10131 | EXPECT_EQ(GetNthStreamid(QUIC_VERSION_99, Perspective::IS_CLIENT, |
| 10132 | /*bidirectional=*/true, 3), |
| 10133 | visitor_.max_stream_id_frame_.max_stream_id); |
| 10134 | |
| 10135 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAM_ID_DATA); |
| 10136 | } |
| 10137 | |
| 10138 | TEST_P(QuicFramerTest, ServerUniDiMaxStreamsFrame) { |
| 10139 | // This test only for version 99. |
| 10140 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10141 | return; |
| 10142 | } |
| 10143 | |
| 10144 | // clang-format off |
| 10145 | PacketFragments packet99 = { |
| 10146 | // type (short header, 4 byte packet number) |
| 10147 | {"", |
| 10148 | {0x43}}, |
| 10149 | // connection_id |
| 10150 | {"", |
| 10151 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10152 | // packet number |
| 10153 | {"", |
| 10154 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10155 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 10156 | {"", |
| 10157 | {0x13}}, |
| 10158 | // max. streams |
| 10159 | {"Can not read MAX_STREAMS stream count.", |
| 10160 | {kVarInt62OneByte + 0x03}}, |
| 10161 | }; |
| 10162 | // clang-format on |
| 10163 | |
| 10164 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10165 | AssemblePacketFromFragments(packet99)); |
| 10166 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10167 | |
| 10168 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10169 | ASSERT_TRUE(visitor_.header_.get()); |
| 10170 | EXPECT_TRUE(CheckDecryption( |
| 10171 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10172 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10173 | |
| 10174 | // This test is a server receiving a MAX_STREAMS frame. The |
| 10175 | // stream ID that it generates should be a server-initiated |
| 10176 | // stream ID. The expected Stream ID is |
| 10177 | // ((0x3-1) * 4) | 0x1 | 0x2 = 0xb |
| 10178 | // count-to-id server inited, unidi |
| 10179 | EXPECT_EQ(GetNthStreamid(QUIC_VERSION_99, Perspective::IS_SERVER, |
| 10180 | /*bidirectional=*/false, 3), |
| 10181 | visitor_.max_stream_id_frame_.max_stream_id); |
| 10182 | |
| 10183 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAM_ID_DATA); |
| 10184 | } |
| 10185 | |
| 10186 | TEST_P(QuicFramerTest, ClientUniDiMaxStreamsFrame) { |
| 10187 | // This test only for version 99. |
| 10188 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10189 | return; |
| 10190 | } |
| 10191 | |
| 10192 | // clang-format off |
| 10193 | PacketFragments packet99 = { |
| 10194 | // type (short header, 4 byte packet number) |
| 10195 | {"", |
| 10196 | {0x43}}, |
| 10197 | // Test runs in client mode, no connection id |
| 10198 | // packet number |
| 10199 | {"", |
| 10200 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10201 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 10202 | {"", |
| 10203 | {0x13}}, |
| 10204 | // max. streams |
| 10205 | {"Can not read MAX_STREAMS stream count.", |
| 10206 | {kVarInt62OneByte + 0x03}}, |
| 10207 | }; |
| 10208 | // clang-format on |
| 10209 | |
| 10210 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10211 | AssemblePacketFromFragments(packet99)); |
| 10212 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10213 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10214 | |
| 10215 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10216 | ASSERT_TRUE(visitor_.header_.get()); |
| 10217 | EXPECT_TRUE(CheckDecryption( |
| 10218 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10219 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10220 | |
| 10221 | // This test is a client receiving a MAX_STREAMS frame. The |
| 10222 | // stream ID that it generates should be a client-initiated |
| 10223 | // stream ID. The expected Stream ID is |
| 10224 | // ((0x3-1) * 4) | 0x02= 0xa |
| 10225 | // count-to-id client/unidi |
| 10226 | EXPECT_EQ(GetNthStreamid(QUIC_VERSION_99, Perspective::IS_CLIENT, |
| 10227 | /*bidirectional=*/false, 3), |
| 10228 | visitor_.max_stream_id_frame_.max_stream_id); |
| 10229 | |
| 10230 | CheckFramingBoundaries(packet99, QUIC_MAX_STREAM_ID_DATA); |
| 10231 | } |
| 10232 | |
| 10233 | // The following four tests ensure that the framer can deserialize a stream |
| 10234 | // count that is large enough to cause the resulting stream ID to exceed the |
| 10235 | // current implementation limit(32 bits). The intent is that when this happens, |
| 10236 | // the stream limit is pegged to the maximum supported value. There are four |
| 10237 | // tests, for the four combinations of uni- and bi-directional, server- and |
| 10238 | // client- initiated. |
| 10239 | TEST_P(QuicFramerTest, ServerBiDiMaxStreamsFrameTooBig) { |
| 10240 | // This test only for version 99. |
| 10241 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10242 | return; |
| 10243 | } |
| 10244 | |
| 10245 | // clang-format off |
| 10246 | unsigned char packet99[] = { |
| 10247 | // type (short header, 4 byte packet number) |
| 10248 | 0x43, |
| 10249 | // connection_id |
| 10250 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10251 | // packet number |
| 10252 | 0x12, 0x34, 0x9A, 0xBC, |
| 10253 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 10254 | 0x12, |
| 10255 | |
| 10256 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10257 | // This encodes a count of 0x40000000, leading to stream |
| 10258 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10259 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 10260 | }; |
| 10261 | // clang-format on |
| 10262 | |
| 10263 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10264 | false); |
| 10265 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 10266 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10267 | ASSERT_TRUE(visitor_.header_.get()); |
| 10268 | EXPECT_TRUE(CheckDecryption( |
| 10269 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10270 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10271 | |
| 10272 | // This test is a server receiving a MAX_STREAMS frame. The |
| 10273 | // stream ID that it generates should be a server-initiated |
| 10274 | // stream ID. The expected Stream ID is |
| 10275 | // 0xfffffffc | 0x01 --> 0xfffffffd |
| 10276 | // maxid server inited, bidi |
| 10277 | EXPECT_EQ(GetNthStreamid(QUIC_VERSION_99, Perspective::IS_SERVER, |
| 10278 | /*bidirectional=*/true, 0x40000000), |
| 10279 | visitor_.max_stream_id_frame_.max_stream_id); |
| 10280 | } |
| 10281 | |
| 10282 | TEST_P(QuicFramerTest, ClientBiDiMaxStreamsFrameTooBig) { |
| 10283 | // This test only for version 99. |
| 10284 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10285 | return; |
| 10286 | } |
| 10287 | |
| 10288 | // clang-format off |
| 10289 | unsigned char packet99[] = { |
| 10290 | // type (short header, 4 byte packet number) |
| 10291 | 0x43, |
| 10292 | // Test runs in client mode, no connection id |
| 10293 | // packet number |
| 10294 | 0x12, 0x34, 0x9A, 0xBC, |
| 10295 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 10296 | 0x12, |
| 10297 | |
| 10298 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10299 | // This encodes a count of 0x40000000, leading to stream |
| 10300 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10301 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 10302 | }; |
| 10303 | // clang-format on |
| 10304 | |
| 10305 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10306 | false); |
| 10307 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10308 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 10309 | |
| 10310 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10311 | ASSERT_TRUE(visitor_.header_.get()); |
| 10312 | EXPECT_TRUE(CheckDecryption( |
| 10313 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10314 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10315 | |
| 10316 | // This test is a client receiving a MAX_STREAMS frame. The |
| 10317 | // stream ID that it generates should be a client-initiated |
| 10318 | // stream ID. The expected Stream ID is |
| 10319 | // 0xfffffffc --> 0xfffffffc |
| 10320 | // max id bidi/client-inited |
| 10321 | // TODO(fkastenholz): Change -2 to -1 when stream id 0 is no longer |
| 10322 | // special. |
| 10323 | // Subtract 1 because client/bidi stream ids start counting at |
| 10324 | // 4, not 0. If we didn;t subtract 1, the resulting math would wrap to stream |
| 10325 | // id 0, not 0xfffffffc. |
| 10326 | EXPECT_EQ(GetNthStreamid(QUIC_VERSION_99, Perspective::IS_CLIENT, |
| 10327 | /*bidirectional=*/true, (0x40000000 - 1)), |
| 10328 | visitor_.max_stream_id_frame_.max_stream_id); |
| 10329 | } |
| 10330 | |
| 10331 | TEST_P(QuicFramerTest, ServerUniDiMaxStreamsFrameTooBig) { |
| 10332 | // This test only for version 99. |
| 10333 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10334 | return; |
| 10335 | } |
| 10336 | |
| 10337 | // clang-format off |
| 10338 | unsigned char packet99[] = { |
| 10339 | // type (short header, 4 byte packet number) |
| 10340 | 0x43, |
| 10341 | // connection_id |
| 10342 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10343 | // packet number |
| 10344 | 0x12, 0x34, 0x9A, 0xBC, |
| 10345 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL) |
| 10346 | 0x13, |
| 10347 | |
| 10348 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10349 | // This encodes a count of 0x40000000, leading to stream |
| 10350 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10351 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 10352 | }; |
| 10353 | // clang-format on |
| 10354 | |
| 10355 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10356 | false); |
| 10357 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 10358 | |
| 10359 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10360 | ASSERT_TRUE(visitor_.header_.get()); |
| 10361 | EXPECT_TRUE(CheckDecryption( |
| 10362 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10363 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10364 | |
| 10365 | // This test is a server receiving a MAX_STREAMS frame. The |
| 10366 | // stream ID that it generates should be a server-initiated |
| 10367 | // stream ID. The expected Stream ID is |
| 10368 | // 0xfffffffc | 0x1 | 0x2 = 0xffffffff |
| 10369 | // maxid server inited, unidi |
| 10370 | EXPECT_EQ(GetNthStreamid(QUIC_VERSION_99, Perspective::IS_SERVER, |
| 10371 | /*bidirectional=*/false, 0x40000000), |
| 10372 | visitor_.max_stream_id_frame_.max_stream_id); |
| 10373 | } |
| 10374 | |
| 10375 | TEST_P(QuicFramerTest, ClientUniDiMaxStreamsFrameTooBig) { |
| 10376 | // This test only for version 99. |
| 10377 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10378 | return; |
| 10379 | } |
| 10380 | |
| 10381 | // clang-format off |
| 10382 | unsigned char packet99[] = { |
| 10383 | // type (short header, 4 byte packet number) |
| 10384 | 0x43, |
| 10385 | // Test runs in client mode, no connection id |
| 10386 | // packet number |
| 10387 | 0x12, 0x34, 0x9A, 0xBC, |
| 10388 | // frame type (IETF_MAX_STREAMS_UNDIRECTIONAL) |
| 10389 | 0x13, |
| 10390 | |
| 10391 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10392 | // This encodes a count of 0x40000000, leading to stream |
| 10393 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10394 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00 |
| 10395 | }; |
| 10396 | // clang-format on |
| 10397 | |
| 10398 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10399 | false); |
| 10400 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10401 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 10402 | |
| 10403 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10404 | ASSERT_TRUE(visitor_.header_.get()); |
| 10405 | EXPECT_TRUE(CheckDecryption( |
| 10406 | encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10407 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10408 | |
| 10409 | // This test is a client receiving a MAX_STREAMS frame. The |
| 10410 | // stream ID that it generates should be a client-initiated |
| 10411 | // stream ID. The expected Stream ID is |
| 10412 | // 0xfffffffc | 0x02= 0xfffffffe |
| 10413 | // maxid client/unidi |
| 10414 | EXPECT_EQ(GetNthStreamid(QUIC_VERSION_99, Perspective::IS_CLIENT, |
| 10415 | /*bidirectional=*/false, 0x40000000), |
| 10416 | visitor_.max_stream_id_frame_.max_stream_id); |
| 10417 | } |
| 10418 | |
| 10419 | // Check that a stream count of 0 is rejected. |
| 10420 | // Directionality and intiation are not important for |
| 10421 | // this test. |
| 10422 | TEST_P(QuicFramerTest, MaxStreamsFrameZeroCount) { |
| 10423 | // This test only for version 99. |
| 10424 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10425 | return; |
| 10426 | } |
| 10427 | |
| 10428 | // clang-format off |
| 10429 | unsigned char packet99[] = { |
| 10430 | // type (short header, 4 byte packet number) |
| 10431 | 0x43, |
| 10432 | // connection_id |
| 10433 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10434 | // packet number |
| 10435 | 0x12, 0x34, 0x9A, 0xBC, |
| 10436 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL) |
| 10437 | 0x12, |
| 10438 | // max. streams == 0. |
| 10439 | kVarInt62OneByte + 0x00 |
| 10440 | }; |
| 10441 | // clang-format on |
| 10442 | |
| 10443 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10444 | false); |
| 10445 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 10446 | EXPECT_EQ(QUIC_MAX_STREAM_ID_DATA, framer_.error()); |
| 10447 | EXPECT_EQ(framer_.detailed_error(), |
| 10448 | "MAX_STREAMS stream count of 0 not supported."); |
| 10449 | } |
| 10450 | |
| 10451 | TEST_P(QuicFramerTest, ServerBiDiStreamsBlockedFrame) { |
| 10452 | // This test only for version 99. |
| 10453 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10454 | return; |
| 10455 | } |
| 10456 | |
| 10457 | // clang-format off |
| 10458 | PacketFragments packet99 = { |
| 10459 | // type (short header, 4 byte packet number) |
| 10460 | {"", |
| 10461 | {0x43}}, |
| 10462 | // connection_id |
| 10463 | {"", |
| 10464 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10465 | // packet number |
| 10466 | {"", |
| 10467 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10468 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL frame) |
| 10469 | {"", |
| 10470 | {0x16}}, |
| 10471 | // stream id |
| 10472 | {"Can not read STREAMS_BLOCKED stream id.", |
| 10473 | {kVarInt62OneByte + 0x03}}, |
| 10474 | }; |
| 10475 | // clang-format on |
| 10476 | |
| 10477 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10478 | AssemblePacketFromFragments(packet99)); |
| 10479 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10480 | |
| 10481 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10482 | ASSERT_TRUE(visitor_.header_.get()); |
| 10483 | EXPECT_TRUE(CheckDecryption( |
| 10484 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10485 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10486 | |
| 10487 | // This test is a server receiving a STREAMS_BLOCKED frame. The |
| 10488 | // stream ID that it generates should be a client-initiated |
| 10489 | // stream ID. The expected Stream ID is |
| 10490 | // ((0x3-1) * 4) = 0xc |
| 10491 | // count-to-id client inited, bidi |
| 10492 | // It is not 8 because a client-initiated, bidi stream ID's |
| 10493 | // low bits are 00 - which means that the old crypto stream |
| 10494 | // falls into this category, and the first stream is streamid=4, |
| 10495 | // not streamid=0. |
| 10496 | EXPECT_EQ(GetNthStreamid(QUIC_VERSION_99, Perspective::IS_CLIENT, |
| 10497 | /*bidirectional=*/true, 3), |
| 10498 | visitor_.stream_id_blocked_frame_.stream_id); |
| 10499 | |
| 10500 | CheckFramingBoundaries(packet99, QUIC_STREAM_ID_BLOCKED_DATA); |
| 10501 | } |
| 10502 | |
| 10503 | TEST_P(QuicFramerTest, ClientBiDiStreamsBlockedFrame) { |
| 10504 | // This test only for version 99. |
| 10505 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10506 | return; |
| 10507 | } |
| 10508 | |
| 10509 | // clang-format off |
| 10510 | PacketFragments packet99 = { |
| 10511 | // type (short header, 4 byte packet number) |
| 10512 | {"", |
| 10513 | {0x43}}, |
| 10514 | // Test runs in client mode, no connection id |
| 10515 | // packet number |
| 10516 | {"", |
| 10517 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10518 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL frame) |
| 10519 | {"", |
| 10520 | {0x16}}, |
| 10521 | // stream id |
| 10522 | {"Can not read STREAMS_BLOCKED stream id.", |
| 10523 | {kVarInt62OneByte + 0x03}}, |
| 10524 | }; |
| 10525 | // clang-format on |
| 10526 | |
| 10527 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10528 | AssemblePacketFromFragments(packet99)); |
| 10529 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10530 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10531 | |
| 10532 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10533 | ASSERT_TRUE(visitor_.header_.get()); |
| 10534 | EXPECT_TRUE(CheckDecryption( |
| 10535 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10536 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10537 | |
| 10538 | // This test is a client receiving a STREAMS_BLOCKED frame. The |
| 10539 | // stream ID that it generates should be a server-initiated |
| 10540 | // stream ID. The expected Stream ID is |
| 10541 | // ((0x3-1) * 4) | 0x01 = 0x9 |
| 10542 | // count-to-id server inited, bidi |
| 10543 | EXPECT_EQ(GetNthStreamid(QUIC_VERSION_99, Perspective::IS_SERVER, |
| 10544 | /*bidirectional=*/true, 3), |
| 10545 | visitor_.stream_id_blocked_frame_.stream_id); |
| 10546 | |
| 10547 | CheckFramingBoundaries(packet99, QUIC_STREAM_ID_BLOCKED_DATA); |
| 10548 | } |
| 10549 | |
| 10550 | TEST_P(QuicFramerTest, ServerUniDiStreamsBlockedFrame) { |
| 10551 | // This test only for version 99. |
| 10552 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10553 | return; |
| 10554 | } |
| 10555 | |
| 10556 | // clang-format off |
| 10557 | PacketFragments packet99 = { |
| 10558 | // type (short header, 4 byte packet number) |
| 10559 | {"", |
| 10560 | {0x43}}, |
| 10561 | // connection_id |
| 10562 | {"", |
| 10563 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 10564 | // packet number |
| 10565 | {"", |
| 10566 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10567 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10568 | {"", |
| 10569 | {0x17}}, |
| 10570 | // stream id |
| 10571 | {"Can not read STREAMS_BLOCKED stream id.", |
| 10572 | {kVarInt62OneByte + 0x03}}, |
| 10573 | }; |
| 10574 | // clang-format on |
| 10575 | |
| 10576 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10577 | AssemblePacketFromFragments(packet99)); |
| 10578 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10579 | |
| 10580 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10581 | ASSERT_TRUE(visitor_.header_.get()); |
| 10582 | EXPECT_TRUE(CheckDecryption( |
| 10583 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10584 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10585 | |
| 10586 | // This test is a server receiving a STREAMS_BLOCKED frame. The |
| 10587 | // stream ID that it generates should be a client-initiated |
| 10588 | // stream ID. The expected Stream ID is |
| 10589 | // ((0x3-1) * 4) | 0x2 = 0xa |
| 10590 | // count-to-id client inited, unidi |
| 10591 | EXPECT_EQ(GetNthStreamid(QUIC_VERSION_99, Perspective::IS_CLIENT, |
| 10592 | /*bidirectional=*/false, 3), |
| 10593 | visitor_.stream_id_blocked_frame_.stream_id); |
| 10594 | |
| 10595 | CheckFramingBoundaries(packet99, QUIC_STREAM_ID_BLOCKED_DATA); |
| 10596 | } |
| 10597 | |
| 10598 | TEST_P(QuicFramerTest, ClientUniDiStreamsBlockedFrame) { |
| 10599 | // This test only for version 99. |
| 10600 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10601 | return; |
| 10602 | } |
| 10603 | |
| 10604 | // clang-format off |
| 10605 | PacketFragments packet99 = { |
| 10606 | // type (short header, 4 byte packet number) |
| 10607 | {"", |
| 10608 | {0x43}}, |
| 10609 | // Test runs in client mode, no connection id |
| 10610 | // packet number |
| 10611 | {"", |
| 10612 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 10613 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10614 | {"", |
| 10615 | {0x17}}, |
| 10616 | // stream id |
| 10617 | {"Can not read STREAMS_BLOCKED stream id.", |
| 10618 | {kVarInt62OneByte + 0x03}}, |
| 10619 | }; |
| 10620 | // clang-format on |
| 10621 | |
| 10622 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 10623 | AssemblePacketFromFragments(packet99)); |
| 10624 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10625 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 10626 | |
| 10627 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 10628 | ASSERT_TRUE(visitor_.header_.get()); |
| 10629 | EXPECT_TRUE(CheckDecryption( |
| 10630 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 10631 | PACKET_0BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 10632 | |
| 10633 | // This test is a client receiving a STREAMS_BLOCKED frame. The |
| 10634 | // stream ID that it generates should be a server-initiated |
| 10635 | // stream ID. The expected Stream ID is |
| 10636 | // ((0x3-1) * 4) | 0x01 | 0x2 = 0xb |
| 10637 | // count-to-id server inited, bidi |
| 10638 | EXPECT_EQ(GetNthStreamid(QUIC_VERSION_99, Perspective::IS_SERVER, |
| 10639 | /*bidirectional=*/false, 3), |
| 10640 | visitor_.stream_id_blocked_frame_.stream_id); |
| 10641 | |
| 10642 | CheckFramingBoundaries(packet99, QUIC_STREAM_ID_BLOCKED_DATA); |
| 10643 | } |
| 10644 | |
| 10645 | // Check that when we get a STREAMS_BLOCKED frame that specifies too large |
| 10646 | // a stream count, we reject with an appropriate error. There is no need to |
| 10647 | // check for different combinations of Uni/Bi directional and client/server |
| 10648 | // initiated; the logic does not take these into account. |
| 10649 | TEST_P(QuicFramerTest, StreamsBlockedFrameTooBig) { |
| 10650 | // This test only for version 99. |
| 10651 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10652 | return; |
| 10653 | } |
| 10654 | |
| 10655 | // clang-format off |
| 10656 | unsigned char packet99[] = { |
| 10657 | // type (short header, 4 byte packet number) |
| 10658 | 0x43, |
| 10659 | // Test runs in client mode, no connection id |
| 10660 | // packet number |
| 10661 | 0x12, 0x34, 0x9A, 0xBC, |
| 10662 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL) |
| 10663 | 0x17, |
| 10664 | |
| 10665 | // max. streams. Max stream ID allowed is 0xffffffff |
| 10666 | // This encodes a count of 0x40000000, leading to stream |
| 10667 | // IDs in the range 0x1 00000000 to 0x1 00000003. |
| 10668 | kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x01 |
| 10669 | }; |
| 10670 | // clang-format on |
| 10671 | |
| 10672 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10673 | false); |
| 10674 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10675 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 10676 | |
| 10677 | EXPECT_EQ(QUIC_STREAM_ID_BLOCKED_DATA, framer_.error()); |
| 10678 | EXPECT_EQ(framer_.detailed_error(), |
| 10679 | "STREAMS_BLOCKED stream count exceeds implementation limit."); |
| 10680 | } |
| 10681 | |
| 10682 | // Test that count==0 is rejected. |
| 10683 | TEST_P(QuicFramerTest, StreamsBlockedFrameZeroCount) { |
| 10684 | // This test only for version 99. |
| 10685 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10686 | return; |
| 10687 | } |
| 10688 | |
| 10689 | // clang-format off |
| 10690 | unsigned char packet99[] = { |
| 10691 | // type (short header, 4 byte packet number) |
| 10692 | 0x43, |
| 10693 | // Test runs in client mode, no connection id |
| 10694 | // packet number |
| 10695 | 0x12, 0x34, 0x9A, 0xBC, |
| 10696 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL) |
| 10697 | 0x17, |
| 10698 | |
| 10699 | // max. streams = 0 |
| 10700 | kVarInt62OneByte + 0x00 |
| 10701 | }; |
| 10702 | // clang-format on |
| 10703 | |
| 10704 | QuicEncryptedPacket encrypted(AsChars(packet99), QUIC_ARRAYSIZE(packet99), |
| 10705 | false); |
| 10706 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10707 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 10708 | |
| 10709 | EXPECT_EQ(QUIC_STREAM_ID_BLOCKED_DATA, framer_.error()); |
| 10710 | EXPECT_EQ(framer_.detailed_error(), |
| 10711 | "STREAMS_BLOCKED stream count 0 not supported."); |
| 10712 | } |
| 10713 | |
| 10714 | TEST_P(QuicFramerTest, BuildServerBiDiStreamsBlockedPacket) { |
| 10715 | // This test only for version 99. |
| 10716 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10717 | return; |
| 10718 | } |
| 10719 | |
| 10720 | QuicPacketHeader header; |
| 10721 | header.destination_connection_id = FramerTestConnectionId(); |
| 10722 | header.reset_flag = false; |
| 10723 | header.version_flag = false; |
| 10724 | header.packet_number = kPacketNumber; |
| 10725 | |
| 10726 | QuicStreamIdBlockedFrame frame; |
| 10727 | // A server building a STREAMS_BLOCKED frame generates |
| 10728 | // a server-initiated stream ID. This test is bidirectional. |
| 10729 | // The low two bits of the stream ID are 01 |
| 10730 | // Expected value is 0x8u | 0x1u; |
| 10731 | frame.stream_id = GetNthStreamid(QUIC_VERSION_99, Perspective::IS_SERVER, |
| 10732 | /*bidirectional=*/true, 3); |
| 10733 | |
| 10734 | QuicFrames frames = {QuicFrame(frame)}; |
| 10735 | |
| 10736 | // clang-format off |
| 10737 | unsigned char packet99[] = { |
| 10738 | // type (short header, 4 byte packet number) |
| 10739 | 0x43, |
| 10740 | // connection_id |
| 10741 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10742 | // packet number |
| 10743 | 0x12, 0x34, 0x56, 0x78, |
| 10744 | |
| 10745 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL frame) |
| 10746 | 0x16, |
| 10747 | // Stream count |
| 10748 | kVarInt62OneByte + 0x03 |
| 10749 | }; |
| 10750 | // clang-format on |
| 10751 | |
| 10752 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10753 | ASSERT_TRUE(data != nullptr); |
| 10754 | |
| 10755 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10756 | data->length(), AsChars(packet99), |
| 10757 | QUIC_ARRAYSIZE(packet99)); |
| 10758 | } |
| 10759 | |
| 10760 | TEST_P(QuicFramerTest, BuildClientBiDiStreamsBlockedPacket) { |
| 10761 | // This test only for version 99. |
| 10762 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10763 | return; |
| 10764 | } |
| 10765 | |
| 10766 | // This test runs in client mode. |
| 10767 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10768 | |
| 10769 | QuicPacketHeader header; |
| 10770 | header.destination_connection_id = FramerTestConnectionId(); |
| 10771 | header.reset_flag = false; |
| 10772 | header.version_flag = false; |
| 10773 | header.packet_number = kPacketNumber; |
| 10774 | |
| 10775 | QuicStreamIdBlockedFrame frame; |
| 10776 | // A client building a STREAMS_BLOCKED frame generates |
| 10777 | // a client-initiated stream ID. This test is bidirectional. |
| 10778 | // The low two bits of the stream ID are 00. Expected value is 0x8 |
| 10779 | frame.stream_id = GetNthStreamid(QUIC_VERSION_99, Perspective::IS_CLIENT, |
| 10780 | /*bidirectional=*/true, 3); |
| 10781 | QuicFrames frames = {QuicFrame(frame)}; |
| 10782 | |
| 10783 | // clang-format off |
| 10784 | unsigned char packet99[] = { |
| 10785 | // type (short header, 4 byte packet number) |
| 10786 | 0x43, |
| 10787 | // connection_id |
| 10788 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10789 | // packet number |
| 10790 | 0x12, 0x34, 0x56, 0x78, |
| 10791 | |
| 10792 | // frame type (IETF_STREAMS_BLOCKED_BIDIRECTIONAL frame) |
| 10793 | 0x16, |
| 10794 | // Stream count |
| 10795 | kVarInt62OneByte + 0x03 |
| 10796 | }; |
| 10797 | // clang-format on |
| 10798 | |
| 10799 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10800 | ASSERT_TRUE(data != nullptr); |
| 10801 | |
| 10802 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10803 | data->length(), AsChars(packet99), |
| 10804 | QUIC_ARRAYSIZE(packet99)); |
| 10805 | } |
| 10806 | |
| 10807 | TEST_P(QuicFramerTest, BuildServerUniStreamsBlockedPacket) { |
| 10808 | // This test only for version 99. |
| 10809 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10810 | return; |
| 10811 | } |
| 10812 | |
| 10813 | QuicPacketHeader header; |
| 10814 | header.destination_connection_id = FramerTestConnectionId(); |
| 10815 | header.reset_flag = false; |
| 10816 | header.version_flag = false; |
| 10817 | header.packet_number = kPacketNumber; |
| 10818 | |
| 10819 | QuicStreamIdBlockedFrame frame; |
| 10820 | // A server building a STREAMS_BLOCKED frame generates |
| 10821 | // a server-initiated stream ID. This test is bidirectional. |
| 10822 | // The low two bits of the stream ID are 11. Expected value is 0xb |
| 10823 | frame.stream_id = GetNthStreamid(QUIC_VERSION_99, Perspective::IS_SERVER, |
| 10824 | /*bidirectional=*/false, 3); |
| 10825 | QuicFrames frames = {QuicFrame(frame)}; |
| 10826 | |
| 10827 | // clang-format off |
| 10828 | unsigned char packet99[] = { |
| 10829 | // type (short header, 4 byte packet number) |
| 10830 | 0x43, |
| 10831 | // connection_id |
| 10832 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10833 | // packet number |
| 10834 | 0x12, 0x34, 0x56, 0x78, |
| 10835 | |
| 10836 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10837 | 0x17, |
| 10838 | // Stream count |
| 10839 | kVarInt62OneByte + 0x03 |
| 10840 | }; |
| 10841 | // clang-format on |
| 10842 | |
| 10843 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10844 | ASSERT_TRUE(data != nullptr); |
| 10845 | |
| 10846 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10847 | data->length(), AsChars(packet99), |
| 10848 | QUIC_ARRAYSIZE(packet99)); |
| 10849 | } |
| 10850 | |
| 10851 | TEST_P(QuicFramerTest, BuildClientUniDiStreamsBlockedPacket) { |
| 10852 | // This test only for version 99. |
| 10853 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10854 | return; |
| 10855 | } |
| 10856 | |
| 10857 | // This test runs in client mode. |
| 10858 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10859 | |
| 10860 | QuicPacketHeader header; |
| 10861 | header.destination_connection_id = FramerTestConnectionId(); |
| 10862 | header.reset_flag = false; |
| 10863 | header.version_flag = false; |
| 10864 | header.packet_number = kPacketNumber; |
| 10865 | |
| 10866 | QuicStreamIdBlockedFrame frame; |
| 10867 | // A client building a STREAMS_BLOCKED frame generates |
| 10868 | // a client-initiated stream ID. This test is bidirectional. |
| 10869 | // The low two bits of the stream ID are 10. Expected value is 0xa |
| 10870 | frame.stream_id = GetNthStreamid(QUIC_VERSION_99, Perspective::IS_CLIENT, |
| 10871 | /*bidirectional=*/false, 3); |
| 10872 | QuicFrames frames = {QuicFrame(frame)}; |
| 10873 | |
| 10874 | // clang-format off |
| 10875 | unsigned char packet99[] = { |
| 10876 | // type (short header, 4 byte packet number) |
| 10877 | 0x43, |
| 10878 | // connection_id |
| 10879 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10880 | // packet number |
| 10881 | 0x12, 0x34, 0x56, 0x78, |
| 10882 | |
| 10883 | // frame type (IETF_STREAMS_BLOCKED_UNIDIRECTIONAL frame) |
| 10884 | 0x17, |
| 10885 | // Stream count |
| 10886 | kVarInt62OneByte + 0x03 |
| 10887 | }; |
| 10888 | // clang-format on |
| 10889 | |
| 10890 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10891 | ASSERT_TRUE(data != nullptr); |
| 10892 | |
| 10893 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10894 | data->length(), AsChars(packet99), |
| 10895 | QUIC_ARRAYSIZE(packet99)); |
| 10896 | } |
| 10897 | |
| 10898 | TEST_P(QuicFramerTest, BuildServerBiDiMaxStreamsPacket) { |
| 10899 | // This test only for version 99. |
| 10900 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10901 | return; |
| 10902 | } |
| 10903 | |
| 10904 | QuicPacketHeader header; |
| 10905 | header.destination_connection_id = FramerTestConnectionId(); |
| 10906 | header.reset_flag = false; |
| 10907 | header.version_flag = false; |
| 10908 | header.packet_number = kPacketNumber; |
| 10909 | |
| 10910 | QuicMaxStreamIdFrame frame; |
| 10911 | // A server building a MAX_STREAMS frame generates |
| 10912 | // a client-initiated stream ID. This test is bidirectional. |
| 10913 | // The low two bits of the stream ID are 00. Expected value is 0xc |
| 10914 | // because streamid==0 is special and the first client/bidi |
| 10915 | // stream is 4, not 0. |
| 10916 | frame.max_stream_id = GetNthStreamid(QUIC_VERSION_99, Perspective::IS_CLIENT, |
| 10917 | /*bidirectional=*/true, 3); |
| 10918 | QuicFrames frames = {QuicFrame(frame)}; |
| 10919 | |
| 10920 | // clang-format off |
| 10921 | unsigned char packet99[] = { |
| 10922 | // type (short header, 4 byte packet number) |
| 10923 | 0x43, |
| 10924 | // connection_id |
| 10925 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10926 | // packet number |
| 10927 | 0x12, 0x34, 0x56, 0x78, |
| 10928 | |
| 10929 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL frame) |
| 10930 | 0x12, |
| 10931 | // Stream count |
| 10932 | kVarInt62OneByte + 0x03 |
| 10933 | }; |
| 10934 | // clang-format on |
| 10935 | |
| 10936 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10937 | ASSERT_TRUE(data != nullptr); |
| 10938 | |
| 10939 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10940 | data->length(), AsChars(packet99), |
| 10941 | QUIC_ARRAYSIZE(packet99)); |
| 10942 | } |
| 10943 | |
| 10944 | TEST_P(QuicFramerTest, BuildClientBiDiMaxStreamsPacket) { |
| 10945 | // This test only for version 99. |
| 10946 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10947 | return; |
| 10948 | } |
| 10949 | |
| 10950 | // This test runs in client mode. |
| 10951 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 10952 | |
| 10953 | QuicPacketHeader header; |
| 10954 | header.destination_connection_id = FramerTestConnectionId(); |
| 10955 | header.reset_flag = false; |
| 10956 | header.version_flag = false; |
| 10957 | header.packet_number = kPacketNumber; |
| 10958 | |
| 10959 | QuicMaxStreamIdFrame frame; |
| 10960 | // A client building a MAX_STREAMS frame generates |
| 10961 | // a server-initiated stream ID. This test is bidirectional. |
| 10962 | // The low two bits of the stream ID are 01. Expected value is 0x9 |
| 10963 | frame.max_stream_id = GetNthStreamid(QUIC_VERSION_99, Perspective::IS_SERVER, |
| 10964 | /*bidirectional=*/true, 3); |
| 10965 | QuicFrames frames = {QuicFrame(frame)}; |
| 10966 | |
| 10967 | // clang-format off |
| 10968 | unsigned char packet99[] = { |
| 10969 | // type (short header, 4 byte packet number) |
| 10970 | 0x43, |
| 10971 | // connection_id |
| 10972 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 10973 | // packet number |
| 10974 | 0x12, 0x34, 0x56, 0x78, |
| 10975 | |
| 10976 | // frame type (IETF_MAX_STREAMS_BIDIRECTIONAL frame) |
| 10977 | 0x12, |
| 10978 | // Stream count |
| 10979 | kVarInt62OneByte + 0x03 |
| 10980 | }; |
| 10981 | // clang-format on |
| 10982 | |
| 10983 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 10984 | ASSERT_TRUE(data != nullptr); |
| 10985 | |
| 10986 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 10987 | data->length(), AsChars(packet99), |
| 10988 | QUIC_ARRAYSIZE(packet99)); |
| 10989 | } |
| 10990 | |
| 10991 | TEST_P(QuicFramerTest, BuildServerUniMaxStreamsPacket) { |
| 10992 | // This test only for version 99. |
| 10993 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 10994 | return; |
| 10995 | } |
| 10996 | |
| 10997 | QuicPacketHeader header; |
| 10998 | header.destination_connection_id = FramerTestConnectionId(); |
| 10999 | header.reset_flag = false; |
| 11000 | header.version_flag = false; |
| 11001 | header.packet_number = kPacketNumber; |
| 11002 | |
| 11003 | QuicMaxStreamIdFrame frame; |
| 11004 | // A server building a MAX_STREAMS frame generates |
| 11005 | // a client-initiated stream ID. This test is bidirectional. |
| 11006 | // The low two bits of the stream ID are 10. Expected value is 0xa |
| 11007 | frame.max_stream_id = GetNthStreamid(QUIC_VERSION_99, Perspective::IS_CLIENT, |
| 11008 | /*bidirectional=*/false, 3); |
| 11009 | QuicFrames frames = {QuicFrame(frame)}; |
| 11010 | |
| 11011 | // clang-format off |
| 11012 | unsigned char packet99[] = { |
| 11013 | // type (short header, 4 byte packet number) |
| 11014 | 0x43, |
| 11015 | // connection_id |
| 11016 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11017 | // packet number |
| 11018 | 0x12, 0x34, 0x56, 0x78, |
| 11019 | |
| 11020 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL frame) |
| 11021 | 0x13, |
| 11022 | // Stream count |
| 11023 | kVarInt62OneByte + 0x03 |
| 11024 | }; |
| 11025 | // clang-format on |
| 11026 | |
| 11027 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11028 | ASSERT_TRUE(data != nullptr); |
| 11029 | |
| 11030 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11031 | data->length(), AsChars(packet99), |
| 11032 | QUIC_ARRAYSIZE(packet99)); |
| 11033 | } |
| 11034 | |
| 11035 | TEST_P(QuicFramerTest, BuildClientUniDiMaxStreamsPacket) { |
| 11036 | // This test only for version 99. |
| 11037 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11038 | return; |
| 11039 | } |
| 11040 | |
| 11041 | // This test runs in client mode. |
| 11042 | QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 11043 | |
| 11044 | QuicPacketHeader header; |
| 11045 | header.destination_connection_id = FramerTestConnectionId(); |
| 11046 | header.reset_flag = false; |
| 11047 | header.version_flag = false; |
| 11048 | header.packet_number = kPacketNumber; |
| 11049 | |
| 11050 | QuicMaxStreamIdFrame frame; |
| 11051 | // A client building a MAX_STREAMS frame generates |
| 11052 | // a server-initiated stream ID. This test is bidirectional. |
| 11053 | // The low two bits of the stream ID are 11. Expected value is 0xb |
| 11054 | frame.max_stream_id = GetNthStreamid(QUIC_VERSION_99, Perspective::IS_SERVER, |
| 11055 | /*bidirectional=*/false, 3); |
| 11056 | QuicFrames frames = {QuicFrame(frame)}; |
| 11057 | |
| 11058 | // clang-format off |
| 11059 | unsigned char packet99[] = { |
| 11060 | // type (short header, 4 byte packet number) |
| 11061 | 0x43, |
| 11062 | // connection_id |
| 11063 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11064 | // packet number |
| 11065 | 0x12, 0x34, 0x56, 0x78, |
| 11066 | |
| 11067 | // frame type (IETF_MAX_STREAMS_UNIDIRECTIONAL frame) |
| 11068 | 0x13, |
| 11069 | // Stream count |
| 11070 | kVarInt62OneByte + 0x03 |
| 11071 | }; |
| 11072 | // clang-format on |
| 11073 | |
| 11074 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11075 | ASSERT_TRUE(data != nullptr); |
| 11076 | |
| 11077 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11078 | data->length(), AsChars(packet99), |
| 11079 | QUIC_ARRAYSIZE(packet99)); |
| 11080 | } |
| 11081 | |
| 11082 | TEST_P(QuicFramerTest, NewConnectionIdFrame) { |
| 11083 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11084 | // This frame is only for version 99. |
| 11085 | return; |
| 11086 | } |
| 11087 | // clang-format off |
| 11088 | PacketFragments packet99 = { |
| 11089 | // type (short header, 4 byte packet number) |
| 11090 | {"", |
| 11091 | {0x43}}, |
| 11092 | // connection_id |
| 11093 | {"", |
| 11094 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11095 | // packet number |
| 11096 | {"", |
| 11097 | {0x12, 0x34, 0x56, 0x78}}, |
| 11098 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 11099 | {"", |
| 11100 | {0x18}}, |
| 11101 | // error code |
| 11102 | {"Unable to read new connection ID frame sequence number.", |
| 11103 | {kVarInt62OneByte + 0x11}}, |
| 11104 | {"Unable to read new connection ID frame connection id length.", |
| 11105 | {0x08}}, // connection ID length |
| 11106 | {"Unable to read new connection ID frame connection id.", |
| 11107 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11}}, |
| 11108 | {"Can not read new connection ID frame reset token.", |
| 11109 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 11110 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 11111 | }; |
| 11112 | // clang-format on |
| 11113 | |
| 11114 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11115 | AssemblePacketFromFragments(packet99)); |
| 11116 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11117 | |
| 11118 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11119 | ASSERT_TRUE(visitor_.header_.get()); |
| 11120 | EXPECT_TRUE(CheckDecryption( |
| 11121 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11122 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11123 | |
| 11124 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 11125 | |
| 11126 | EXPECT_EQ(FramerTestConnectionIdPlusOne(), |
| 11127 | visitor_.new_connection_id_.connection_id); |
| 11128 | EXPECT_EQ(0x11u, visitor_.new_connection_id_.sequence_number); |
| 11129 | EXPECT_EQ(kTestStatelessResetToken, |
| 11130 | visitor_.new_connection_id_.stateless_reset_token); |
| 11131 | |
| 11132 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 11133 | |
| 11134 | CheckFramingBoundaries(packet99, QUIC_INVALID_NEW_CONNECTION_ID_DATA); |
| 11135 | } |
| 11136 | |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame^] | 11137 | TEST_P(QuicFramerTest, NewConnectionIdFrameVariableLength) { |
| 11138 | if (!QuicUtils::VariableLengthConnectionIdAllowedForVersion( |
| 11139 | framer_.transport_version())) { |
| 11140 | return; |
| 11141 | } |
| 11142 | // clang-format off |
| 11143 | PacketFragments packet99 = { |
| 11144 | // type (short header, 4 byte packet number) |
| 11145 | {"", |
| 11146 | {0x43}}, |
| 11147 | // connection_id |
| 11148 | {"", |
| 11149 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11150 | // packet number |
| 11151 | {"", |
| 11152 | {0x12, 0x34, 0x56, 0x78}}, |
| 11153 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 11154 | {"", |
| 11155 | {0x18}}, |
| 11156 | // error code |
| 11157 | {"Unable to read new connection ID frame sequence number.", |
| 11158 | {kVarInt62OneByte + 0x11}}, |
| 11159 | {"Unable to read new connection ID frame connection id length.", |
| 11160 | {0x09}}, // connection ID length |
| 11161 | {"Unable to read new connection ID frame connection id.", |
| 11162 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42}}, |
| 11163 | {"Can not read new connection ID frame reset token.", |
| 11164 | {0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 11165 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}} |
| 11166 | }; |
| 11167 | // clang-format on |
| 11168 | |
| 11169 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11170 | AssemblePacketFromFragments(packet99)); |
| 11171 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11172 | |
| 11173 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11174 | ASSERT_TRUE(visitor_.header_.get()); |
| 11175 | EXPECT_TRUE(CheckDecryption( |
| 11176 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11177 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11178 | |
| 11179 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 11180 | |
| 11181 | EXPECT_EQ(FramerTestConnectionIdNineBytes(), |
| 11182 | visitor_.new_connection_id_.connection_id); |
| 11183 | EXPECT_EQ(0x11u, visitor_.new_connection_id_.sequence_number); |
| 11184 | EXPECT_EQ(kTestStatelessResetToken, |
| 11185 | visitor_.new_connection_id_.stateless_reset_token); |
| 11186 | |
| 11187 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 11188 | |
| 11189 | CheckFramingBoundaries(packet99, QUIC_INVALID_NEW_CONNECTION_ID_DATA); |
| 11190 | } |
| 11191 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11192 | TEST_P(QuicFramerTest, BuildNewConnectionIdFramePacket) { |
| 11193 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11194 | // This frame is only for version 99. |
| 11195 | return; |
| 11196 | } |
| 11197 | QuicPacketHeader header; |
| 11198 | header.destination_connection_id = FramerTestConnectionId(); |
| 11199 | header.reset_flag = false; |
| 11200 | header.version_flag = false; |
| 11201 | header.packet_number = kPacketNumber; |
| 11202 | |
| 11203 | QuicNewConnectionIdFrame frame; |
| 11204 | frame.sequence_number = 0x11; |
| 11205 | // Use this value to force a 4-byte encoded variable length connection ID |
| 11206 | // in the frame. |
| 11207 | frame.connection_id = FramerTestConnectionIdPlusOne(); |
| 11208 | frame.stateless_reset_token = kTestStatelessResetToken; |
| 11209 | |
| 11210 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11211 | |
| 11212 | // clang-format off |
| 11213 | unsigned char packet99[] = { |
| 11214 | // type (short header, 4 byte packet number) |
| 11215 | 0x43, |
| 11216 | // connection_id |
| 11217 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11218 | // packet number |
| 11219 | 0x12, 0x34, 0x56, 0x78, |
| 11220 | |
| 11221 | // frame type (IETF_NEW_CONNECTION_ID frame) |
| 11222 | 0x18, |
| 11223 | // sequence number |
| 11224 | kVarInt62OneByte + 0x11, |
| 11225 | // new connection id length |
| 11226 | 0x08, |
| 11227 | // new connection id |
| 11228 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 11229 | // stateless reset token |
| 11230 | 0xb5, 0x69, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 11231 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 11232 | }; |
| 11233 | // clang-format on |
| 11234 | |
| 11235 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11236 | ASSERT_TRUE(data != nullptr); |
| 11237 | |
| 11238 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11239 | data->length(), AsChars(packet99), |
| 11240 | QUIC_ARRAYSIZE(packet99)); |
| 11241 | } |
| 11242 | |
| 11243 | TEST_P(QuicFramerTest, NewTokenFrame) { |
| 11244 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11245 | // This frame is only for version 99. |
| 11246 | return; |
| 11247 | } |
| 11248 | // clang-format off |
| 11249 | PacketFragments packet = { |
| 11250 | // type (short header, 4 byte packet number) |
| 11251 | {"", |
| 11252 | {0x43}}, |
| 11253 | // connection_id |
| 11254 | {"", |
| 11255 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11256 | // packet number |
| 11257 | {"", |
| 11258 | {0x12, 0x34, 0x56, 0x78}}, |
| 11259 | // frame type (IETF_NEW_TOKEN frame) |
| 11260 | {"", |
| 11261 | {0x07}}, |
| 11262 | // Length |
| 11263 | {"Unable to read new token length.", |
| 11264 | {kVarInt62OneByte + 0x08}}, |
| 11265 | {"Unable to read new token data.", |
| 11266 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}} |
| 11267 | }; |
| 11268 | // clang-format on |
| 11269 | uint8_t expected_token_value[] = {0x00, 0x01, 0x02, 0x03, |
| 11270 | 0x04, 0x05, 0x06, 0x07}; |
| 11271 | |
| 11272 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11273 | AssemblePacketFromFragments(packet)); |
| 11274 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11275 | |
| 11276 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11277 | ASSERT_TRUE(visitor_.header_.get()); |
| 11278 | EXPECT_TRUE(CheckDecryption( |
| 11279 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11280 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11281 | |
| 11282 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 11283 | |
| 11284 | EXPECT_EQ(sizeof(expected_token_value), visitor_.new_token_.token.length()); |
| 11285 | EXPECT_EQ(0, memcmp(expected_token_value, visitor_.new_token_.token.data(), |
| 11286 | sizeof(expected_token_value))); |
| 11287 | |
| 11288 | CheckFramingBoundaries(packet, QUIC_INVALID_NEW_TOKEN); |
| 11289 | } |
| 11290 | |
| 11291 | TEST_P(QuicFramerTest, BuildNewTokenFramePacket) { |
| 11292 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11293 | // This frame is only for version 99. |
| 11294 | return; |
| 11295 | } |
| 11296 | QuicPacketHeader header; |
| 11297 | header.destination_connection_id = FramerTestConnectionId(); |
| 11298 | header.reset_flag = false; |
| 11299 | header.version_flag = false; |
| 11300 | header.packet_number = kPacketNumber; |
| 11301 | |
| 11302 | uint8_t expected_token_value[] = {0x00, 0x01, 0x02, 0x03, |
| 11303 | 0x04, 0x05, 0x06, 0x07}; |
| 11304 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 11305 | QuicNewTokenFrame frame(0, std::string((const char*)(expected_token_value), |
| 11306 | sizeof(expected_token_value))); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11307 | |
| 11308 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11309 | |
| 11310 | // clang-format off |
| 11311 | unsigned char packet[] = { |
| 11312 | // type (short header, 4 byte packet number) |
| 11313 | 0x43, |
| 11314 | // connection_id |
| 11315 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11316 | // packet number |
| 11317 | 0x12, 0x34, 0x56, 0x78, |
| 11318 | |
| 11319 | // frame type (IETF_NEW_TOKEN frame) |
| 11320 | 0x07, |
| 11321 | // Length and token |
| 11322 | kVarInt62OneByte + 0x08, |
| 11323 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 11324 | }; |
| 11325 | // clang-format on |
| 11326 | |
| 11327 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11328 | ASSERT_TRUE(data != nullptr); |
| 11329 | |
| 11330 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11331 | data->length(), AsChars(packet), |
| 11332 | QUIC_ARRAYSIZE(packet)); |
| 11333 | } |
| 11334 | |
| 11335 | TEST_P(QuicFramerTest, IetfStopSendingFrame) { |
| 11336 | // This test is only for version 99. |
| 11337 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11338 | return; |
| 11339 | } |
| 11340 | |
| 11341 | // clang-format off |
| 11342 | PacketFragments packet99 = { |
| 11343 | // type (short header, 4 byte packet number) |
| 11344 | {"", |
| 11345 | {0x43}}, |
| 11346 | // connection_id |
| 11347 | {"", |
| 11348 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11349 | // packet number |
| 11350 | {"", |
| 11351 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11352 | // frame type (IETF_STOP_SENDING frame) |
| 11353 | {"", |
| 11354 | {0x05}}, |
| 11355 | // stream id |
| 11356 | {"Unable to read stop sending stream id.", |
| 11357 | {kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04}}, |
| 11358 | {"Unable to read stop sending application error code.", |
| 11359 | {0x76, 0x54}}, |
| 11360 | }; |
| 11361 | // clang-format on |
| 11362 | |
| 11363 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11364 | AssemblePacketFromFragments(packet99)); |
| 11365 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11366 | |
| 11367 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11368 | ASSERT_TRUE(visitor_.header_.get()); |
| 11369 | EXPECT_TRUE(CheckDecryption( |
| 11370 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11371 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11372 | |
| 11373 | EXPECT_EQ(kStreamId, visitor_.stop_sending_frame_.stream_id); |
| 11374 | EXPECT_EQ(0x7654, visitor_.stop_sending_frame_.application_error_code); |
| 11375 | |
| 11376 | CheckFramingBoundaries(packet99, QUIC_INVALID_STOP_SENDING_FRAME_DATA); |
| 11377 | } |
| 11378 | |
| 11379 | TEST_P(QuicFramerTest, BuildIetfStopSendingPacket) { |
| 11380 | // This test is only for version 99. |
| 11381 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11382 | return; |
| 11383 | } |
| 11384 | |
| 11385 | QuicPacketHeader header; |
| 11386 | header.destination_connection_id = FramerTestConnectionId(); |
| 11387 | header.reset_flag = false; |
| 11388 | header.version_flag = false; |
| 11389 | header.packet_number = kPacketNumber; |
| 11390 | |
| 11391 | QuicStopSendingFrame frame; |
| 11392 | frame.stream_id = kStreamId; |
| 11393 | frame.application_error_code = 0xffff; |
| 11394 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11395 | |
| 11396 | // clang-format off |
| 11397 | unsigned char packet99[] = { |
| 11398 | // type (short header, 4 byte packet number) |
| 11399 | 0x43, |
| 11400 | // connection_id |
| 11401 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11402 | // packet number |
| 11403 | 0x12, 0x34, 0x56, 0x78, |
| 11404 | |
| 11405 | // frame type (IETF_STOP_SENDING frame) |
| 11406 | 0x05, |
| 11407 | // Stream ID |
| 11408 | kVarInt62FourBytes + 0x01, 0x02, 0x03, 0x04, |
| 11409 | // Application error code |
| 11410 | 0xff, 0xff |
| 11411 | }; |
| 11412 | // clang-format on |
| 11413 | |
| 11414 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11415 | ASSERT_TRUE(data != nullptr); |
| 11416 | |
| 11417 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11418 | data->length(), AsChars(packet99), |
| 11419 | QUIC_ARRAYSIZE(packet99)); |
| 11420 | } |
| 11421 | |
| 11422 | TEST_P(QuicFramerTest, IetfPathChallengeFrame) { |
| 11423 | // This test only for version 99. |
| 11424 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11425 | return; |
| 11426 | } |
| 11427 | |
| 11428 | // clang-format off |
| 11429 | PacketFragments packet99 = { |
| 11430 | // type (short header, 4 byte packet number) |
| 11431 | {"", |
| 11432 | {0x43}}, |
| 11433 | // connection_id |
| 11434 | {"", |
| 11435 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11436 | // packet number |
| 11437 | {"", |
| 11438 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11439 | // frame type (IETF_PATH_CHALLENGE) |
| 11440 | {"", |
| 11441 | {0x1a}}, |
| 11442 | // data |
| 11443 | {"Can not read path challenge data.", |
| 11444 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}}, |
| 11445 | }; |
| 11446 | // clang-format on |
| 11447 | |
| 11448 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11449 | AssemblePacketFromFragments(packet99)); |
| 11450 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11451 | |
| 11452 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11453 | ASSERT_TRUE(visitor_.header_.get()); |
| 11454 | EXPECT_TRUE(CheckDecryption( |
| 11455 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11456 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11457 | |
| 11458 | EXPECT_EQ(QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}), |
| 11459 | visitor_.path_challenge_frame_.data_buffer); |
| 11460 | |
| 11461 | CheckFramingBoundaries(packet99, QUIC_INVALID_PATH_CHALLENGE_DATA); |
| 11462 | } |
| 11463 | |
| 11464 | TEST_P(QuicFramerTest, BuildIetfPathChallengePacket) { |
| 11465 | // This test only for version 99. |
| 11466 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11467 | return; |
| 11468 | } |
| 11469 | |
| 11470 | QuicPacketHeader header; |
| 11471 | header.destination_connection_id = FramerTestConnectionId(); |
| 11472 | header.reset_flag = false; |
| 11473 | header.version_flag = false; |
| 11474 | header.packet_number = kPacketNumber; |
| 11475 | |
| 11476 | QuicPathChallengeFrame frame; |
| 11477 | frame.data_buffer = QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}); |
| 11478 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11479 | |
| 11480 | // clang-format off |
| 11481 | unsigned char packet99[] = { |
| 11482 | // type (short header, 4 byte packet number) |
| 11483 | 0x43, |
| 11484 | // connection_id |
| 11485 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11486 | // packet number |
| 11487 | 0x12, 0x34, 0x56, 0x78, |
| 11488 | |
| 11489 | // frame type (IETF_PATH_CHALLENGE) |
| 11490 | 0x1a, |
| 11491 | // Data |
| 11492 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 11493 | }; |
| 11494 | // clang-format on |
| 11495 | |
| 11496 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11497 | ASSERT_TRUE(data != nullptr); |
| 11498 | |
| 11499 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11500 | data->length(), AsChars(packet99), |
| 11501 | QUIC_ARRAYSIZE(packet99)); |
| 11502 | } |
| 11503 | |
| 11504 | TEST_P(QuicFramerTest, IetfPathResponseFrame) { |
| 11505 | // This test only for version 99. |
| 11506 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11507 | return; |
| 11508 | } |
| 11509 | |
| 11510 | // clang-format off |
| 11511 | PacketFragments packet99 = { |
| 11512 | // type (short header, 4 byte packet number) |
| 11513 | {"", |
| 11514 | {0x43}}, |
| 11515 | // connection_id |
| 11516 | {"", |
| 11517 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11518 | // packet number |
| 11519 | {"", |
| 11520 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11521 | // frame type (IETF_PATH_RESPONSE) |
| 11522 | {"", |
| 11523 | {0x1b}}, |
| 11524 | // data |
| 11525 | {"Can not read path response data.", |
| 11526 | {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07}}, |
| 11527 | }; |
| 11528 | // clang-format on |
| 11529 | |
| 11530 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11531 | AssemblePacketFromFragments(packet99)); |
| 11532 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 11533 | |
| 11534 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 11535 | ASSERT_TRUE(visitor_.header_.get()); |
| 11536 | EXPECT_TRUE(CheckDecryption( |
| 11537 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 11538 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 11539 | |
| 11540 | EXPECT_EQ(QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}), |
| 11541 | visitor_.path_response_frame_.data_buffer); |
| 11542 | |
| 11543 | CheckFramingBoundaries(packet99, QUIC_INVALID_PATH_RESPONSE_DATA); |
| 11544 | } |
| 11545 | |
| 11546 | TEST_P(QuicFramerTest, BuildIetfPathResponsePacket) { |
| 11547 | // This test only for version 99. |
| 11548 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11549 | return; |
| 11550 | } |
| 11551 | |
| 11552 | QuicPacketHeader header; |
| 11553 | header.destination_connection_id = FramerTestConnectionId(); |
| 11554 | header.reset_flag = false; |
| 11555 | header.version_flag = false; |
| 11556 | header.packet_number = kPacketNumber; |
| 11557 | |
| 11558 | QuicPathResponseFrame frame; |
| 11559 | frame.data_buffer = QuicPathFrameBuffer({{0, 1, 2, 3, 4, 5, 6, 7}}); |
| 11560 | QuicFrames frames = {QuicFrame(&frame)}; |
| 11561 | |
| 11562 | // clang-format off |
| 11563 | unsigned char packet99[] = { |
| 11564 | // type (short header, 4 byte packet number) |
| 11565 | 0x43, |
| 11566 | // connection_id |
| 11567 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 11568 | // packet number |
| 11569 | 0x12, 0x34, 0x56, 0x78, |
| 11570 | |
| 11571 | // frame type (IETF_PATH_RESPONSE) |
| 11572 | 0x1b, |
| 11573 | // Data |
| 11574 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 |
| 11575 | }; |
| 11576 | // clang-format on |
| 11577 | |
| 11578 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 11579 | ASSERT_TRUE(data != nullptr); |
| 11580 | |
| 11581 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 11582 | data->length(), AsChars(packet99), |
| 11583 | QUIC_ARRAYSIZE(packet99)); |
| 11584 | } |
| 11585 | |
| 11586 | TEST_P(QuicFramerTest, GetRetransmittableControlFrameSize) { |
| 11587 | QuicRstStreamFrame rst_stream(1, 3, QUIC_STREAM_CANCELLED, 1024); |
| 11588 | EXPECT_EQ(QuicFramer::GetRstStreamFrameSize(framer_.transport_version(), |
| 11589 | rst_stream), |
| 11590 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11591 | framer_.transport_version(), QuicFrame(&rst_stream))); |
| 11592 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 11593 | std::string error_detail(2048, 'e'); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11594 | QuicConnectionCloseFrame connection_close(QUIC_NETWORK_IDLE_TIMEOUT, |
| 11595 | error_detail); |
| 11596 | EXPECT_EQ(QuicFramer::GetMinConnectionCloseFrameSize( |
| 11597 | framer_.transport_version(), connection_close) + |
| 11598 | 256, |
| 11599 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11600 | framer_.transport_version(), QuicFrame(&connection_close))); |
| 11601 | |
| 11602 | QuicGoAwayFrame goaway(2, QUIC_PEER_GOING_AWAY, 3, error_detail); |
| 11603 | EXPECT_EQ(QuicFramer::GetMinGoAwayFrameSize() + 256, |
| 11604 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11605 | framer_.transport_version(), QuicFrame(&goaway))); |
| 11606 | |
| 11607 | QuicWindowUpdateFrame window_update(3, 3, 1024); |
| 11608 | EXPECT_EQ(QuicFramer::GetWindowUpdateFrameSize(framer_.transport_version(), |
| 11609 | window_update), |
| 11610 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11611 | framer_.transport_version(), QuicFrame(&window_update))); |
| 11612 | |
| 11613 | QuicBlockedFrame blocked(4, 3, 1024); |
| 11614 | EXPECT_EQ( |
| 11615 | QuicFramer::GetBlockedFrameSize(framer_.transport_version(), blocked), |
| 11616 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11617 | framer_.transport_version(), QuicFrame(&blocked))); |
| 11618 | |
| 11619 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11620 | return; |
| 11621 | } |
| 11622 | QuicApplicationCloseFrame application_close; |
| 11623 | EXPECT_EQ(QuicFramer::GetMinApplicationCloseFrameSize( |
| 11624 | framer_.transport_version(), application_close), |
| 11625 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11626 | framer_.transport_version(), QuicFrame(&application_close))); |
| 11627 | |
| 11628 | QuicNewConnectionIdFrame new_connection_id(5, TestConnectionId(), 1, 101111); |
| 11629 | EXPECT_EQ(QuicFramer::GetNewConnectionIdFrameSize(new_connection_id), |
| 11630 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11631 | framer_.transport_version(), QuicFrame(&new_connection_id))); |
| 11632 | |
| 11633 | QuicMaxStreamIdFrame max_stream_id(6, 3); |
| 11634 | EXPECT_EQ(QuicFramer::GetMaxStreamsFrameSize(framer_.transport_version(), |
| 11635 | max_stream_id), |
| 11636 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11637 | framer_.transport_version(), QuicFrame(max_stream_id))); |
| 11638 | |
| 11639 | QuicStreamIdBlockedFrame stream_id_blocked(7, 3); |
| 11640 | EXPECT_EQ(QuicFramer::GetStreamsBlockedFrameSize(framer_.transport_version(), |
| 11641 | stream_id_blocked), |
| 11642 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11643 | framer_.transport_version(), QuicFrame(stream_id_blocked))); |
| 11644 | |
| 11645 | QuicPathFrameBuffer buffer = { |
| 11646 | {0x80, 0x91, 0xa2, 0xb3, 0xc4, 0xd5, 0xe5, 0xf7}}; |
| 11647 | QuicPathResponseFrame path_response_frame(8, buffer); |
| 11648 | EXPECT_EQ(QuicFramer::GetPathResponseFrameSize(path_response_frame), |
| 11649 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11650 | framer_.transport_version(), QuicFrame(&path_response_frame))); |
| 11651 | |
| 11652 | QuicPathChallengeFrame path_challenge_frame(9, buffer); |
| 11653 | EXPECT_EQ(QuicFramer::GetPathChallengeFrameSize(path_challenge_frame), |
| 11654 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11655 | framer_.transport_version(), QuicFrame(&path_challenge_frame))); |
| 11656 | |
| 11657 | QuicStopSendingFrame stop_sending_frame(10, 3, 20); |
| 11658 | EXPECT_EQ(QuicFramer::GetStopSendingFrameSize(stop_sending_frame), |
| 11659 | QuicFramer::GetRetransmittableControlFrameSize( |
| 11660 | framer_.transport_version(), QuicFrame(&stop_sending_frame))); |
| 11661 | } |
| 11662 | |
| 11663 | // A set of tests to ensure that bad frame-type encodings |
| 11664 | // are properly detected and handled. |
| 11665 | // First, four tests to see that unknown frame types generate |
| 11666 | // a QUIC_INVALID_FRAME_DATA error with detailed information |
| 11667 | // "Illegal frame type." This regardless of the encoding of the type |
| 11668 | // (1/2/4/8 bytes). |
| 11669 | // This only for version 99. |
| 11670 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown1Byte) { |
| 11671 | // This test only for version 99. |
| 11672 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11673 | return; |
| 11674 | } |
| 11675 | // clang-format off |
| 11676 | PacketFragments packet = { |
| 11677 | // type (short header, 4 byte packet number) |
| 11678 | {"", |
| 11679 | {0x43}}, |
| 11680 | // connection_id |
| 11681 | {"", |
| 11682 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11683 | // packet number |
| 11684 | {"", |
| 11685 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11686 | // frame type (unknown value, single-byte encoding) |
| 11687 | {"", |
| 11688 | {0x38}} |
| 11689 | }; |
| 11690 | // clang-format on |
| 11691 | |
| 11692 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11693 | AssemblePacketFromFragments(packet)); |
| 11694 | |
| 11695 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11696 | |
| 11697 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 11698 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11699 | } |
| 11700 | |
| 11701 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown2Bytes) { |
| 11702 | // This test only for version 99. |
| 11703 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11704 | return; |
| 11705 | } |
| 11706 | |
| 11707 | // clang-format off |
| 11708 | PacketFragments packet = { |
| 11709 | // type (short header, 4 byte packet number) |
| 11710 | {"", |
| 11711 | {0x43}}, |
| 11712 | // connection_id |
| 11713 | {"", |
| 11714 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11715 | // packet number |
| 11716 | {"", |
| 11717 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11718 | // frame type (unknown value, two-byte encoding) |
| 11719 | {"", |
| 11720 | {kVarInt62TwoBytes + 0x01, 0x38}} |
| 11721 | }; |
| 11722 | // clang-format on |
| 11723 | |
| 11724 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11725 | AssemblePacketFromFragments(packet)); |
| 11726 | |
| 11727 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11728 | |
| 11729 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 11730 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11731 | } |
| 11732 | |
| 11733 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown4Bytes) { |
| 11734 | // This test only for version 99. |
| 11735 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11736 | return; |
| 11737 | } |
| 11738 | |
| 11739 | // clang-format off |
| 11740 | PacketFragments packet = { |
| 11741 | // type (short header, 4 byte packet number) |
| 11742 | {"", |
| 11743 | {0x43}}, |
| 11744 | // connection_id |
| 11745 | {"", |
| 11746 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11747 | // packet number |
| 11748 | {"", |
| 11749 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11750 | // frame type (unknown value, four-byte encoding) |
| 11751 | {"", |
| 11752 | {kVarInt62FourBytes + 0x01, 0x00, 0x00, 0x38}} |
| 11753 | }; |
| 11754 | // clang-format on |
| 11755 | |
| 11756 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11757 | AssemblePacketFromFragments(packet)); |
| 11758 | |
| 11759 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11760 | |
| 11761 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 11762 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11763 | } |
| 11764 | |
| 11765 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorUnknown8Bytes) { |
| 11766 | // This test only for version 99. |
| 11767 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11768 | return; |
| 11769 | } |
| 11770 | // clang-format off |
| 11771 | PacketFragments packet = { |
| 11772 | // type (short header, 4 byte packet number) |
| 11773 | {"", |
| 11774 | {0x43}}, |
| 11775 | // connection_id |
| 11776 | {"", |
| 11777 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11778 | // packet number |
| 11779 | {"", |
| 11780 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11781 | // frame type (unknown value, eight-byte encoding) |
| 11782 | {"", |
| 11783 | {kVarInt62EightBytes + 0x01, 0x00, 0x00, 0x01, 0x02, 0x34, 0x56, 0x38}} |
| 11784 | }; |
| 11785 | // clang-format on |
| 11786 | |
| 11787 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11788 | AssemblePacketFromFragments(packet)); |
| 11789 | |
| 11790 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11791 | |
| 11792 | EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); |
| 11793 | EXPECT_EQ("Illegal frame type.", framer_.detailed_error()); |
| 11794 | } |
| 11795 | |
| 11796 | // Three tests to check that known frame types that are not minimally |
| 11797 | // encoded generate IETF_QUIC_PROTOCOL_VIOLATION errors with detailed |
| 11798 | // information "Frame type not minimally encoded." |
| 11799 | // Look at the frame-type encoded in 2, 4, and 8 bytes. |
| 11800 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown2Bytes) { |
| 11801 | // This test only for version 99. |
| 11802 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11803 | return; |
| 11804 | } |
| 11805 | |
| 11806 | // clang-format off |
| 11807 | PacketFragments packet = { |
| 11808 | // type (short header, 4 byte packet number) |
| 11809 | {"", |
| 11810 | {0x43}}, |
| 11811 | // connection_id |
| 11812 | {"", |
| 11813 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11814 | // packet number |
| 11815 | {"", |
| 11816 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11817 | // frame type (Blocked, two-byte encoding) |
| 11818 | {"", |
| 11819 | {kVarInt62TwoBytes + 0x00, 0x08}} |
| 11820 | }; |
| 11821 | // clang-format on |
| 11822 | |
| 11823 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11824 | AssemblePacketFromFragments(packet)); |
| 11825 | |
| 11826 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11827 | |
| 11828 | EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); |
| 11829 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 11830 | } |
| 11831 | |
| 11832 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown4Bytes) { |
| 11833 | // This test only for version 99. |
| 11834 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11835 | return; |
| 11836 | } |
| 11837 | |
| 11838 | // clang-format off |
| 11839 | PacketFragments packet = { |
| 11840 | // type (short header, 4 byte packet number) |
| 11841 | {"", |
| 11842 | {0x43}}, |
| 11843 | // connection_id |
| 11844 | {"", |
| 11845 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11846 | // packet number |
| 11847 | {"", |
| 11848 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11849 | // frame type (Blocked, four-byte encoding) |
| 11850 | {"", |
| 11851 | {kVarInt62FourBytes + 0x00, 0x00, 0x00, 0x08}} |
| 11852 | }; |
| 11853 | // clang-format on |
| 11854 | |
| 11855 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11856 | AssemblePacketFromFragments(packet)); |
| 11857 | |
| 11858 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11859 | |
| 11860 | EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); |
| 11861 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 11862 | } |
| 11863 | |
| 11864 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown8Bytes) { |
| 11865 | // This test only for version 99. |
| 11866 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11867 | return; |
| 11868 | } |
| 11869 | // clang-format off |
| 11870 | PacketFragments packet = { |
| 11871 | // type (short header, 4 byte packet number) |
| 11872 | {"", |
| 11873 | {0x43}}, |
| 11874 | // connection_id |
| 11875 | {"", |
| 11876 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11877 | // packet number |
| 11878 | {"", |
| 11879 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11880 | // frame type (Blocked, eight-byte encoding) |
| 11881 | {"", |
| 11882 | {kVarInt62EightBytes + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08}} |
| 11883 | }; |
| 11884 | // clang-format on |
| 11885 | |
| 11886 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 11887 | AssemblePacketFromFragments(packet)); |
| 11888 | |
| 11889 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 11890 | |
| 11891 | EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); |
| 11892 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 11893 | } |
| 11894 | |
| 11895 | // Tests to check that all known OETF frame types that are not minimally |
| 11896 | // encoded generate IETF_QUIC_PROTOCOL_VIOLATION errors with detailed |
| 11897 | // information "Frame type not minimally encoded." |
| 11898 | // Just look at 2-byte encoding. |
| 11899 | TEST_P(QuicFramerTest, IetfFrameTypeEncodingErrorKnown2BytesAllTypes) { |
| 11900 | // This test only for version 99. |
| 11901 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 11902 | return; |
| 11903 | } |
| 11904 | |
| 11905 | // clang-format off |
| 11906 | PacketFragments packets[] = { |
| 11907 | { |
| 11908 | // type (short header, 4 byte packet number) |
| 11909 | {"", |
| 11910 | {0x43}}, |
| 11911 | // connection_id |
| 11912 | {"", |
| 11913 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11914 | // packet number |
| 11915 | {"", |
| 11916 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11917 | // frame type (two-byte encoding) |
| 11918 | {"", |
| 11919 | {kVarInt62TwoBytes + 0x00, 0x00}} |
| 11920 | }, |
| 11921 | { |
| 11922 | // type (short header, 4 byte packet number) |
| 11923 | {"", |
| 11924 | {0x43}}, |
| 11925 | // connection_id |
| 11926 | {"", |
| 11927 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11928 | // packet number |
| 11929 | {"", |
| 11930 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11931 | // frame type (two-byte encoding) |
| 11932 | {"", |
| 11933 | {kVarInt62TwoBytes + 0x00, 0x01}} |
| 11934 | }, |
| 11935 | { |
| 11936 | // type (short header, 4 byte packet number) |
| 11937 | {"", |
| 11938 | {0x43}}, |
| 11939 | // connection_id |
| 11940 | {"", |
| 11941 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11942 | // packet number |
| 11943 | {"", |
| 11944 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11945 | // frame type (two-byte encoding) |
| 11946 | {"", |
| 11947 | {kVarInt62TwoBytes + 0x00, 0x02}} |
| 11948 | }, |
| 11949 | { |
| 11950 | // type (short header, 4 byte packet number) |
| 11951 | {"", |
| 11952 | {0x43}}, |
| 11953 | // connection_id |
| 11954 | {"", |
| 11955 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11956 | // packet number |
| 11957 | {"", |
| 11958 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11959 | // frame type (two-byte encoding) |
| 11960 | {"", |
| 11961 | {kVarInt62TwoBytes + 0x00, 0x03}} |
| 11962 | }, |
| 11963 | { |
| 11964 | // type (short header, 4 byte packet number) |
| 11965 | {"", |
| 11966 | {0x43}}, |
| 11967 | // connection_id |
| 11968 | {"", |
| 11969 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11970 | // packet number |
| 11971 | {"", |
| 11972 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11973 | // frame type (two-byte encoding) |
| 11974 | {"", |
| 11975 | {kVarInt62TwoBytes + 0x00, 0x04}} |
| 11976 | }, |
| 11977 | { |
| 11978 | // type (short header, 4 byte packet number) |
| 11979 | {"", |
| 11980 | {0x43}}, |
| 11981 | // connection_id |
| 11982 | {"", |
| 11983 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11984 | // packet number |
| 11985 | {"", |
| 11986 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 11987 | // frame type (two-byte encoding) |
| 11988 | {"", |
| 11989 | {kVarInt62TwoBytes + 0x00, 0x05}} |
| 11990 | }, |
| 11991 | { |
| 11992 | // type (short header, 4 byte packet number) |
| 11993 | {"", |
| 11994 | {0x43}}, |
| 11995 | // connection_id |
| 11996 | {"", |
| 11997 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 11998 | // packet number |
| 11999 | {"", |
| 12000 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12001 | // frame type (two-byte encoding) |
| 12002 | {"", |
| 12003 | {kVarInt62TwoBytes + 0x00, 0x06}} |
| 12004 | }, |
| 12005 | { |
| 12006 | // type (short header, 4 byte packet number) |
| 12007 | {"", |
| 12008 | {0x43}}, |
| 12009 | // connection_id |
| 12010 | {"", |
| 12011 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12012 | // packet number |
| 12013 | {"", |
| 12014 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12015 | // frame type (two-byte encoding) |
| 12016 | {"", |
| 12017 | {kVarInt62TwoBytes + 0x00, 0x07}} |
| 12018 | }, |
| 12019 | { |
| 12020 | // type (short header, 4 byte packet number) |
| 12021 | {"", |
| 12022 | {0x43}}, |
| 12023 | // connection_id |
| 12024 | {"", |
| 12025 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12026 | // packet number |
| 12027 | {"", |
| 12028 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12029 | // frame type (two-byte encoding) |
| 12030 | {"", |
| 12031 | {kVarInt62TwoBytes + 0x00, 0x08}} |
| 12032 | }, |
| 12033 | { |
| 12034 | // type (short header, 4 byte packet number) |
| 12035 | {"", |
| 12036 | {0x43}}, |
| 12037 | // connection_id |
| 12038 | {"", |
| 12039 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12040 | // packet number |
| 12041 | {"", |
| 12042 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12043 | // frame type (two-byte encoding) |
| 12044 | {"", |
| 12045 | {kVarInt62TwoBytes + 0x00, 0x09}} |
| 12046 | }, |
| 12047 | { |
| 12048 | // type (short header, 4 byte packet number) |
| 12049 | {"", |
| 12050 | {0x43}}, |
| 12051 | // connection_id |
| 12052 | {"", |
| 12053 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12054 | // packet number |
| 12055 | {"", |
| 12056 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12057 | // frame type (two-byte encoding) |
| 12058 | {"", |
| 12059 | {kVarInt62TwoBytes + 0x00, 0x0a}} |
| 12060 | }, |
| 12061 | { |
| 12062 | // type (short header, 4 byte packet number) |
| 12063 | {"", |
| 12064 | {0x43}}, |
| 12065 | // connection_id |
| 12066 | {"", |
| 12067 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12068 | // packet number |
| 12069 | {"", |
| 12070 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12071 | // frame type (two-byte encoding) |
| 12072 | {"", |
| 12073 | {kVarInt62TwoBytes + 0x00, 0x0b}} |
| 12074 | }, |
| 12075 | { |
| 12076 | // type (short header, 4 byte packet number) |
| 12077 | {"", |
| 12078 | {0x43}}, |
| 12079 | // connection_id |
| 12080 | {"", |
| 12081 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12082 | // packet number |
| 12083 | {"", |
| 12084 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12085 | // frame type (two-byte encoding) |
| 12086 | {"", |
| 12087 | {kVarInt62TwoBytes + 0x00, 0x0c}} |
| 12088 | }, |
| 12089 | { |
| 12090 | // type (short header, 4 byte packet number) |
| 12091 | {"", |
| 12092 | {0x43}}, |
| 12093 | // connection_id |
| 12094 | {"", |
| 12095 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12096 | // packet number |
| 12097 | {"", |
| 12098 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12099 | // frame type (two-byte encoding) |
| 12100 | {"", |
| 12101 | {kVarInt62TwoBytes + 0x00, 0x0d}} |
| 12102 | }, |
| 12103 | { |
| 12104 | // type (short header, 4 byte packet number) |
| 12105 | {"", |
| 12106 | {0x43}}, |
| 12107 | // connection_id |
| 12108 | {"", |
| 12109 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12110 | // packet number |
| 12111 | {"", |
| 12112 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12113 | // frame type (two-byte encoding) |
| 12114 | {"", |
| 12115 | {kVarInt62TwoBytes + 0x00, 0x0e}} |
| 12116 | }, |
| 12117 | { |
| 12118 | // type (short header, 4 byte packet number) |
| 12119 | {"", |
| 12120 | {0x43}}, |
| 12121 | // connection_id |
| 12122 | {"", |
| 12123 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12124 | // packet number |
| 12125 | {"", |
| 12126 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12127 | // frame type (two-byte encoding) |
| 12128 | {"", |
| 12129 | {kVarInt62TwoBytes + 0x00, 0x0f}} |
| 12130 | }, |
| 12131 | { |
| 12132 | // type (short header, 4 byte packet number) |
| 12133 | {"", |
| 12134 | {0x43}}, |
| 12135 | // connection_id |
| 12136 | {"", |
| 12137 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12138 | // packet number |
| 12139 | {"", |
| 12140 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12141 | // frame type (two-byte encoding) |
| 12142 | {"", |
| 12143 | {kVarInt62TwoBytes + 0x00, 0x10}} |
| 12144 | }, |
| 12145 | { |
| 12146 | // type (short header, 4 byte packet number) |
| 12147 | {"", |
| 12148 | {0x43}}, |
| 12149 | // connection_id |
| 12150 | {"", |
| 12151 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12152 | // packet number |
| 12153 | {"", |
| 12154 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12155 | // frame type (two-byte encoding) |
| 12156 | {"", |
| 12157 | {kVarInt62TwoBytes + 0x00, 0x11}} |
| 12158 | }, |
| 12159 | { |
| 12160 | // type (short header, 4 byte packet number) |
| 12161 | {"", |
| 12162 | {0x43}}, |
| 12163 | // connection_id |
| 12164 | {"", |
| 12165 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12166 | // packet number |
| 12167 | {"", |
| 12168 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12169 | // frame type (two-byte encoding) |
| 12170 | {"", |
| 12171 | {kVarInt62TwoBytes + 0x00, 0x12}} |
| 12172 | }, |
| 12173 | { |
| 12174 | // type (short header, 4 byte packet number) |
| 12175 | {"", |
| 12176 | {0x43}}, |
| 12177 | // connection_id |
| 12178 | {"", |
| 12179 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12180 | // packet number |
| 12181 | {"", |
| 12182 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12183 | // frame type (two-byte encoding) |
| 12184 | {"", |
| 12185 | {kVarInt62TwoBytes + 0x00, 0x13}} |
| 12186 | }, |
| 12187 | { |
| 12188 | // type (short header, 4 byte packet number) |
| 12189 | {"", |
| 12190 | {0x43}}, |
| 12191 | // connection_id |
| 12192 | {"", |
| 12193 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12194 | // packet number |
| 12195 | {"", |
| 12196 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12197 | // frame type (two-byte encoding) |
| 12198 | {"", |
| 12199 | {kVarInt62TwoBytes + 0x00, 0x14}} |
| 12200 | }, |
| 12201 | { |
| 12202 | // type (short header, 4 byte packet number) |
| 12203 | {"", |
| 12204 | {0x43}}, |
| 12205 | // connection_id |
| 12206 | {"", |
| 12207 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12208 | // packet number |
| 12209 | {"", |
| 12210 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12211 | // frame type (two-byte encoding) |
| 12212 | {"", |
| 12213 | {kVarInt62TwoBytes + 0x00, 0x15}} |
| 12214 | }, |
| 12215 | { |
| 12216 | // type (short header, 4 byte packet number) |
| 12217 | {"", |
| 12218 | {0x43}}, |
| 12219 | // connection_id |
| 12220 | {"", |
| 12221 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12222 | // packet number |
| 12223 | {"", |
| 12224 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12225 | // frame type (two-byte encoding) |
| 12226 | {"", |
| 12227 | {kVarInt62TwoBytes + 0x00, 0x16}} |
| 12228 | }, |
| 12229 | { |
| 12230 | // type (short header, 4 byte packet number) |
| 12231 | {"", |
| 12232 | {0x43}}, |
| 12233 | // connection_id |
| 12234 | {"", |
| 12235 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12236 | // packet number |
| 12237 | {"", |
| 12238 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12239 | // frame type (two-byte encoding) |
| 12240 | {"", |
| 12241 | {kVarInt62TwoBytes + 0x00, 0x17}} |
| 12242 | }, |
| 12243 | { |
| 12244 | // type (short header, 4 byte packet number) |
| 12245 | {"", |
| 12246 | {0x43}}, |
| 12247 | // connection_id |
| 12248 | {"", |
| 12249 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12250 | // packet number |
| 12251 | {"", |
| 12252 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12253 | // frame type (two-byte encoding) |
| 12254 | {"", |
| 12255 | {kVarInt62TwoBytes + 0x00, 0x18}} |
| 12256 | }, |
| 12257 | { |
| 12258 | // type (short header, 4 byte packet number) |
| 12259 | {"", |
| 12260 | {0x43}}, |
| 12261 | // connection_id |
| 12262 | {"", |
| 12263 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12264 | // packet number |
| 12265 | {"", |
| 12266 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12267 | // frame type (two-byte encoding) |
| 12268 | {"", |
| 12269 | {kVarInt62TwoBytes + 0x00, 0x20}} |
| 12270 | }, |
| 12271 | { |
| 12272 | // type (short header, 4 byte packet number) |
| 12273 | {"", |
| 12274 | {0x43}}, |
| 12275 | // connection_id |
| 12276 | {"", |
| 12277 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12278 | // packet number |
| 12279 | {"", |
| 12280 | {0x12, 0x34, 0x9A, 0xBC}}, |
| 12281 | // frame type (two-byte encoding) |
| 12282 | {"", |
| 12283 | {kVarInt62TwoBytes + 0x00, 0x21}} |
| 12284 | }, |
| 12285 | }; |
| 12286 | // clang-format on |
| 12287 | |
| 12288 | for (PacketFragments& packet : packets) { |
| 12289 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 12290 | AssemblePacketFromFragments(packet)); |
| 12291 | |
| 12292 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 12293 | |
| 12294 | EXPECT_EQ(IETF_QUIC_PROTOCOL_VIOLATION, framer_.error()); |
| 12295 | EXPECT_EQ("Frame type not minimally encoded.", framer_.detailed_error()); |
| 12296 | } |
| 12297 | } |
| 12298 | |
| 12299 | TEST_P(QuicFramerTest, RetireConnectionIdFrame) { |
| 12300 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 12301 | // This frame is only for version 99. |
| 12302 | return; |
| 12303 | } |
| 12304 | // clang-format off |
| 12305 | PacketFragments packet99 = { |
| 12306 | // type (short header, 4 byte packet number) |
| 12307 | {"", |
| 12308 | {0x43}}, |
| 12309 | // connection_id |
| 12310 | {"", |
| 12311 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10}}, |
| 12312 | // packet number |
| 12313 | {"", |
| 12314 | {0x12, 0x34, 0x56, 0x78}}, |
| 12315 | // frame type (IETF_RETIRE_CONNECTION_ID frame) |
| 12316 | {"", |
| 12317 | {0x19}}, |
| 12318 | // Sequence number |
| 12319 | {"Unable to read retire connection ID frame sequence number.", |
| 12320 | {kVarInt62TwoBytes + 0x11, 0x22}} |
| 12321 | }; |
| 12322 | // clang-format on |
| 12323 | |
| 12324 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 12325 | AssemblePacketFromFragments(packet99)); |
| 12326 | EXPECT_TRUE(framer_.ProcessPacket(*encrypted)); |
| 12327 | |
| 12328 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 12329 | ASSERT_TRUE(visitor_.header_.get()); |
| 12330 | EXPECT_TRUE(CheckDecryption( |
| 12331 | *encrypted, !kIncludeVersion, !kIncludeDiversificationNonce, |
| 12332 | PACKET_8BYTE_CONNECTION_ID, PACKET_0BYTE_CONNECTION_ID)); |
| 12333 | |
| 12334 | EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
| 12335 | |
| 12336 | EXPECT_EQ(0x1122u, visitor_.retire_connection_id_.sequence_number); |
| 12337 | |
| 12338 | ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
| 12339 | |
| 12340 | CheckFramingBoundaries(packet99, QUIC_INVALID_RETIRE_CONNECTION_ID_DATA); |
| 12341 | } |
| 12342 | |
| 12343 | TEST_P(QuicFramerTest, BuildRetireConnectionIdFramePacket) { |
| 12344 | if (framer_.transport_version() != QUIC_VERSION_99) { |
| 12345 | // This frame is only for version 99. |
| 12346 | return; |
| 12347 | } |
| 12348 | QuicPacketHeader header; |
| 12349 | header.destination_connection_id = FramerTestConnectionId(); |
| 12350 | header.reset_flag = false; |
| 12351 | header.version_flag = false; |
| 12352 | header.packet_number = kPacketNumber; |
| 12353 | |
| 12354 | QuicRetireConnectionIdFrame frame; |
| 12355 | frame.sequence_number = 0x1122; |
| 12356 | |
| 12357 | QuicFrames frames = {QuicFrame(&frame)}; |
| 12358 | |
| 12359 | // clang-format off |
| 12360 | unsigned char packet99[] = { |
| 12361 | // type (short header, 4 byte packet number) |
| 12362 | 0x43, |
| 12363 | // connection_id |
| 12364 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12365 | // packet number |
| 12366 | 0x12, 0x34, 0x56, 0x78, |
| 12367 | |
| 12368 | // frame type (IETF_RETIRE_CONNECTION_ID frame) |
| 12369 | 0x19, |
| 12370 | // sequence number |
| 12371 | kVarInt62TwoBytes + 0x11, 0x22 |
| 12372 | }; |
| 12373 | // clang-format on |
| 12374 | |
| 12375 | std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
| 12376 | ASSERT_TRUE(data != nullptr); |
| 12377 | |
| 12378 | test::CompareCharArraysWithHexError("constructed packet", data->data(), |
| 12379 | data->length(), AsChars(packet99), |
| 12380 | QUIC_ARRAYSIZE(packet99)); |
| 12381 | } |
| 12382 | |
| 12383 | TEST_P(QuicFramerTest, AckFrameWithInvalidLargestObserved) { |
| 12384 | // clang-format off |
| 12385 | unsigned char packet[] = { |
| 12386 | // public flags (8 byte connection_id) |
| 12387 | 0x2C, |
| 12388 | // connection_id |
| 12389 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12390 | // packet number |
| 12391 | 0x12, 0x34, 0x56, 0x78, |
| 12392 | |
| 12393 | // frame type (ack frame) |
| 12394 | 0x45, |
| 12395 | // largest observed |
| 12396 | 0x00, 0x00, |
| 12397 | // Zero delta time. |
| 12398 | 0x00, 0x00, |
| 12399 | // first ack block length. |
| 12400 | 0x00, 0x00, |
| 12401 | // num timestamps. |
| 12402 | 0x00 |
| 12403 | }; |
| 12404 | |
| 12405 | unsigned char packet44[] = { |
| 12406 | // type (short header, 4 byte packet number) |
| 12407 | 0x32, |
| 12408 | // connection_id |
| 12409 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12410 | // packet number |
| 12411 | 0x12, 0x34, 0x56, 0x78, |
| 12412 | |
| 12413 | // frame type (ack frame) |
| 12414 | 0x45, |
| 12415 | // largest observed |
| 12416 | 0x00, 0x00, |
| 12417 | // Zero delta time. |
| 12418 | 0x00, 0x00, |
| 12419 | // first ack block length. |
| 12420 | 0x00, 0x00, |
| 12421 | // num timestamps. |
| 12422 | 0x00 |
| 12423 | }; |
| 12424 | |
| 12425 | unsigned char packet46[] = { |
| 12426 | // type (short header, 4 byte packet number) |
| 12427 | 0x43, |
| 12428 | // connection_id |
| 12429 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12430 | // packet number |
| 12431 | 0x12, 0x34, 0x56, 0x78, |
| 12432 | |
| 12433 | // frame type (ack frame) |
| 12434 | 0x45, |
| 12435 | // largest observed |
| 12436 | 0x00, 0x00, |
| 12437 | // Zero delta time. |
| 12438 | 0x00, 0x00, |
| 12439 | // first ack block length. |
| 12440 | 0x00, 0x00, |
| 12441 | // num timestamps. |
| 12442 | 0x00 |
| 12443 | }; |
| 12444 | |
| 12445 | unsigned char packet99[] = { |
| 12446 | // type (short header, 4 byte packet number) |
| 12447 | 0x43, |
| 12448 | // connection_id |
| 12449 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12450 | // packet number |
| 12451 | 0x12, 0x34, 0x56, 0x78, |
| 12452 | |
| 12453 | // frame type (IETF_ACK frame) |
| 12454 | 0x02, |
| 12455 | // Largest acked |
| 12456 | kVarInt62OneByte + 0x00, |
| 12457 | // Zero delta time. |
| 12458 | kVarInt62OneByte + 0x00, |
| 12459 | // Ack block count 0 |
| 12460 | kVarInt62OneByte + 0x00, |
| 12461 | // First ack block length |
| 12462 | kVarInt62OneByte + 0x00, |
| 12463 | }; |
| 12464 | // clang-format on |
| 12465 | |
| 12466 | unsigned char* p = packet; |
| 12467 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 12468 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 12469 | p = packet99; |
| 12470 | p_size = QUIC_ARRAYSIZE(packet99); |
| 12471 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 12472 | p = packet46; |
| 12473 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 12474 | p = packet44; |
| 12475 | p_size = QUIC_ARRAYSIZE(packet44); |
| 12476 | } |
| 12477 | |
| 12478 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 12479 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 12480 | EXPECT_EQ(framer_.detailed_error(), "Largest acked is 0."); |
| 12481 | } |
| 12482 | |
| 12483 | TEST_P(QuicFramerTest, FirstAckBlockJustUnderFlow) { |
| 12484 | // clang-format off |
| 12485 | unsigned char packet[] = { |
| 12486 | // public flags (8 byte connection_id) |
| 12487 | 0x2C, |
| 12488 | // connection_id |
| 12489 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12490 | // packet number |
| 12491 | 0x12, 0x34, 0x56, 0x78, |
| 12492 | |
| 12493 | // frame type (ack frame) |
| 12494 | 0x45, |
| 12495 | // largest observed |
| 12496 | 0x00, 0x02, |
| 12497 | // Zero delta time. |
| 12498 | 0x00, 0x00, |
| 12499 | // first ack block length. |
| 12500 | 0x00, 0x03, |
| 12501 | // num timestamps. |
| 12502 | 0x00 |
| 12503 | }; |
| 12504 | |
| 12505 | unsigned char packet44[] = { |
| 12506 | // type (short header, 4 byte packet number) |
| 12507 | 0x32, |
| 12508 | // connection_id |
| 12509 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12510 | // packet number |
| 12511 | 0x12, 0x34, 0x56, 0x78, |
| 12512 | |
| 12513 | // frame type (ack frame) |
| 12514 | 0x45, |
| 12515 | // largest observed |
| 12516 | 0x00, 0x02, |
| 12517 | // Zero delta time. |
| 12518 | 0x00, 0x00, |
| 12519 | // first ack block length. |
| 12520 | 0x00, 0x03, |
| 12521 | // num timestamps. |
| 12522 | 0x00 |
| 12523 | }; |
| 12524 | |
| 12525 | unsigned char packet46[] = { |
| 12526 | // type (short header, 4 byte packet number) |
| 12527 | 0x43, |
| 12528 | // connection_id |
| 12529 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12530 | // packet number |
| 12531 | 0x12, 0x34, 0x56, 0x78, |
| 12532 | |
| 12533 | // frame type (ack frame) |
| 12534 | 0x45, |
| 12535 | // largest observed |
| 12536 | 0x00, 0x02, |
| 12537 | // Zero delta time. |
| 12538 | 0x00, 0x00, |
| 12539 | // first ack block length. |
| 12540 | 0x00, 0x03, |
| 12541 | // num timestamps. |
| 12542 | 0x00 |
| 12543 | }; |
| 12544 | |
| 12545 | unsigned char packet99[] = { |
| 12546 | // type (short header, 4 byte packet number) |
| 12547 | 0x43, |
| 12548 | // connection_id |
| 12549 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12550 | // packet number |
| 12551 | 0x12, 0x34, 0x56, 0x78, |
| 12552 | |
| 12553 | // frame type (IETF_ACK frame) |
| 12554 | 0x02, |
| 12555 | // Largest acked |
| 12556 | kVarInt62OneByte + 0x02, |
| 12557 | // Zero delta time. |
| 12558 | kVarInt62OneByte + 0x00, |
| 12559 | // Ack block count 0 |
| 12560 | kVarInt62OneByte + 0x00, |
| 12561 | // First ack block length |
| 12562 | kVarInt62OneByte + 0x02, |
| 12563 | }; |
| 12564 | // clang-format on |
| 12565 | |
| 12566 | unsigned char* p = packet; |
| 12567 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 12568 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 12569 | p = packet99; |
| 12570 | p_size = QUIC_ARRAYSIZE(packet99); |
| 12571 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 12572 | p = packet46; |
| 12573 | p_size = QUIC_ARRAYSIZE(packet46); |
| 12574 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 12575 | p = packet44; |
| 12576 | p_size = QUIC_ARRAYSIZE(packet44); |
| 12577 | } |
| 12578 | |
| 12579 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 12580 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 12581 | EXPECT_EQ(framer_.detailed_error(), |
| 12582 | "Underflow with first ack block length 3 largest acked is 2."); |
| 12583 | } |
| 12584 | |
| 12585 | TEST_P(QuicFramerTest, ThirdAckBlockJustUnderflow) { |
| 12586 | // clang-format off |
| 12587 | unsigned char packet[] = { |
| 12588 | // public flags (8 byte connection_id) |
| 12589 | 0x2C, |
| 12590 | // connection_id |
| 12591 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12592 | // packet number |
| 12593 | 0x12, 0x34, 0x56, 0x78, |
| 12594 | |
| 12595 | // frame type (ack frame) |
| 12596 | 0x60, |
| 12597 | // largest observed |
| 12598 | 0x0A, |
| 12599 | // Zero delta time. |
| 12600 | 0x00, 0x00, |
| 12601 | // Num of ack blocks |
| 12602 | 0x02, |
| 12603 | // first ack block length. |
| 12604 | 0x02, |
| 12605 | // gap to next block |
| 12606 | 0x01, |
| 12607 | // ack block length |
| 12608 | 0x01, |
| 12609 | // gap to next block |
| 12610 | 0x01, |
| 12611 | // ack block length |
| 12612 | 0x06, |
| 12613 | // num timestamps. |
| 12614 | 0x00 |
| 12615 | }; |
| 12616 | |
| 12617 | unsigned char packet44[] = { |
| 12618 | // type (short header, 4 byte packet number) |
| 12619 | 0x32, |
| 12620 | // connection_id |
| 12621 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12622 | // packet number |
| 12623 | 0x12, 0x34, 0x56, 0x78, |
| 12624 | |
| 12625 | // frame type (ack frame) |
| 12626 | 0x60, |
| 12627 | // largest observed |
| 12628 | 0x0A, |
| 12629 | // Zero delta time. |
| 12630 | 0x00, 0x00, |
| 12631 | // Num of ack blocks |
| 12632 | 0x02, |
| 12633 | // first ack block length. |
| 12634 | 0x02, |
| 12635 | // gap to next block |
| 12636 | 0x01, |
| 12637 | // ack block length |
| 12638 | 0x01, |
| 12639 | // gap to next block |
| 12640 | 0x01, |
| 12641 | // ack block length |
| 12642 | 0x06, |
| 12643 | // num timestamps. |
| 12644 | 0x00 |
| 12645 | }; |
| 12646 | |
| 12647 | unsigned char packet46[] = { |
| 12648 | // type (short header, 4 byte packet number) |
| 12649 | 0x43, |
| 12650 | // connection_id |
| 12651 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12652 | // packet number |
| 12653 | 0x12, 0x34, 0x56, 0x78, |
| 12654 | |
| 12655 | // frame type (ack frame) |
| 12656 | 0x60, |
| 12657 | // largest observed |
| 12658 | 0x0A, |
| 12659 | // Zero delta time. |
| 12660 | 0x00, 0x00, |
| 12661 | // Num of ack blocks |
| 12662 | 0x02, |
| 12663 | // first ack block length. |
| 12664 | 0x02, |
| 12665 | // gap to next block |
| 12666 | 0x01, |
| 12667 | // ack block length |
| 12668 | 0x01, |
| 12669 | // gap to next block |
| 12670 | 0x01, |
| 12671 | // ack block length |
| 12672 | 0x06, |
| 12673 | // num timestamps. |
| 12674 | 0x00 |
| 12675 | }; |
| 12676 | |
| 12677 | unsigned char packet99[] = { |
| 12678 | // type (short header, 4 byte packet number) |
| 12679 | 0x43, |
| 12680 | // connection_id |
| 12681 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12682 | // packet number |
| 12683 | 0x12, 0x34, 0x56, 0x78, |
| 12684 | |
| 12685 | // frame type (IETF_ACK frame) |
| 12686 | 0x02, |
| 12687 | // Largest acked |
| 12688 | kVarInt62OneByte + 0x0A, |
| 12689 | // Zero delta time. |
| 12690 | kVarInt62OneByte + 0x00, |
| 12691 | // Ack block count 2 |
| 12692 | kVarInt62OneByte + 0x02, |
| 12693 | // First ack block length |
| 12694 | kVarInt62OneByte + 0x01, |
| 12695 | // gap to next block length |
| 12696 | kVarInt62OneByte + 0x00, |
| 12697 | // ack block length |
| 12698 | kVarInt62OneByte + 0x00, |
| 12699 | // gap to next block length |
| 12700 | kVarInt62OneByte + 0x00, |
| 12701 | // ack block length |
| 12702 | kVarInt62OneByte + 0x05, |
| 12703 | }; |
| 12704 | // clang-format on |
| 12705 | |
| 12706 | unsigned char* p = packet; |
| 12707 | size_t p_size = QUIC_ARRAYSIZE(packet); |
| 12708 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 12709 | p = packet99; |
| 12710 | p_size = QUIC_ARRAYSIZE(packet99); |
| 12711 | } else if (framer_.transport_version() > QUIC_VERSION_44) { |
| 12712 | p = packet46; |
| 12713 | p_size = QUIC_ARRAYSIZE(packet46); |
| 12714 | } else if (framer_.transport_version() > QUIC_VERSION_43) { |
| 12715 | p = packet44; |
| 12716 | p_size = QUIC_ARRAYSIZE(packet44); |
| 12717 | } |
| 12718 | |
| 12719 | QuicEncryptedPacket encrypted(AsChars(p), p_size, false); |
| 12720 | EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 12721 | if (framer_.transport_version() == QUIC_VERSION_99) { |
| 12722 | EXPECT_EQ(framer_.detailed_error(), |
| 12723 | "Underflow with ack block length 6 latest ack block end is 5."); |
| 12724 | } else { |
| 12725 | EXPECT_EQ(framer_.detailed_error(), |
| 12726 | "Underflow with ack block length 6, end of block is 6."); |
| 12727 | } |
| 12728 | } |
| 12729 | |
| 12730 | TEST_P(QuicFramerTest, CoalescedPacket) { |
| 12731 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 12732 | return; |
| 12733 | } |
| 12734 | // clang-format off |
| 12735 | unsigned char packet[] = { |
| 12736 | // first coalesced packet |
| 12737 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12738 | // 4-byte packet number) |
| 12739 | 0xD3, |
| 12740 | // version |
| 12741 | QUIC_VERSION_BYTES, |
| 12742 | // destination connection ID length |
| 12743 | 0x50, |
| 12744 | // destination connection ID |
| 12745 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12746 | // long header packet length |
| 12747 | 0x1E, |
| 12748 | // packet number |
| 12749 | 0x12, 0x34, 0x56, 0x78, |
| 12750 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12751 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12752 | // stream id |
| 12753 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12754 | // offset |
| 12755 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12756 | 0x32, 0x10, 0x76, 0x54, |
| 12757 | // data length |
| 12758 | kVarInt62OneByte + 0x0c, |
| 12759 | // data |
| 12760 | 'h', 'e', 'l', 'l', |
| 12761 | 'o', ' ', 'w', 'o', |
| 12762 | 'r', 'l', 'd', '!', |
| 12763 | // second coalesced packet |
| 12764 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12765 | // 4-byte packet number) |
| 12766 | 0xD3, |
| 12767 | // version |
| 12768 | QUIC_VERSION_BYTES, |
| 12769 | // destination connection ID length |
| 12770 | 0x50, |
| 12771 | // destination connection ID |
| 12772 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12773 | // long header packet length |
| 12774 | 0x1E, |
| 12775 | // packet number |
| 12776 | 0x12, 0x34, 0x56, 0x79, |
| 12777 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12778 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12779 | // stream id |
| 12780 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12781 | // offset |
| 12782 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12783 | 0x32, 0x10, 0x76, 0x54, |
| 12784 | // data length |
| 12785 | kVarInt62OneByte + 0x0c, |
| 12786 | // data |
| 12787 | 'H', 'E', 'L', 'L', |
| 12788 | 'O', '_', 'W', 'O', |
| 12789 | 'R', 'L', 'D', '?', |
| 12790 | }; |
| 12791 | // clang-format on |
| 12792 | |
| 12793 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 12794 | EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 12795 | |
| 12796 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 12797 | ASSERT_TRUE(visitor_.header_.get()); |
| 12798 | |
| 12799 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 12800 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12801 | |
| 12802 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12803 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 12804 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 12805 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 12806 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 12807 | |
| 12808 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 1u); |
| 12809 | EXPECT_TRUE(framer_.ProcessPacket(*visitor_.coalesced_packets_[0].get())); |
| 12810 | |
| 12811 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 12812 | ASSERT_TRUE(visitor_.header_.get()); |
| 12813 | |
| 12814 | ASSERT_EQ(2u, visitor_.stream_frames_.size()); |
| 12815 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12816 | |
| 12817 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12818 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[1]->stream_id); |
| 12819 | EXPECT_TRUE(visitor_.stream_frames_[1]->fin); |
| 12820 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[1]->offset); |
| 12821 | CheckStreamFrameData("HELLO_WORLD?", visitor_.stream_frames_[1].get()); |
| 12822 | } |
| 12823 | |
| 12824 | TEST_P(QuicFramerTest, MismatchedCoalescedPacket) { |
| 12825 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 12826 | return; |
| 12827 | } |
| 12828 | // clang-format off |
| 12829 | unsigned char packet[] = { |
| 12830 | // first coalesced packet |
| 12831 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12832 | // 4-byte packet number) |
| 12833 | 0xD3, |
| 12834 | // version |
| 12835 | QUIC_VERSION_BYTES, |
| 12836 | // destination connection ID length |
| 12837 | 0x50, |
| 12838 | // destination connection ID |
| 12839 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12840 | // long header packet length |
| 12841 | 0x1E, |
| 12842 | // packet number |
| 12843 | 0x12, 0x34, 0x56, 0x78, |
| 12844 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12845 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12846 | // stream id |
| 12847 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12848 | // offset |
| 12849 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12850 | 0x32, 0x10, 0x76, 0x54, |
| 12851 | // data length |
| 12852 | kVarInt62OneByte + 0x0c, |
| 12853 | // data |
| 12854 | 'h', 'e', 'l', 'l', |
| 12855 | 'o', ' ', 'w', 'o', |
| 12856 | 'r', 'l', 'd', '!', |
| 12857 | // second coalesced packet |
| 12858 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12859 | // 4-byte packet number) |
| 12860 | 0xD3, |
| 12861 | // version |
| 12862 | QUIC_VERSION_BYTES, |
| 12863 | // destination connection ID length |
| 12864 | 0x50, |
| 12865 | // destination connection ID |
| 12866 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x11, |
| 12867 | // long header packet length |
| 12868 | 0x1E, |
| 12869 | // packet number |
| 12870 | 0x12, 0x34, 0x56, 0x79, |
| 12871 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12872 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12873 | // stream id |
| 12874 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12875 | // offset |
| 12876 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12877 | 0x32, 0x10, 0x76, 0x54, |
| 12878 | // data length |
| 12879 | kVarInt62OneByte + 0x0c, |
| 12880 | // data |
| 12881 | 'H', 'E', 'L', 'L', |
| 12882 | 'O', '_', 'W', 'O', |
| 12883 | 'R', 'L', 'D', '?', |
| 12884 | }; |
| 12885 | // clang-format on |
| 12886 | |
| 12887 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 12888 | EXPECT_QUIC_PEER_BUG(EXPECT_TRUE(framer_.ProcessPacket(encrypted)), |
| 12889 | "Server: Received mismatched coalesced header.*"); |
| 12890 | |
| 12891 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 12892 | ASSERT_TRUE(visitor_.header_.get()); |
| 12893 | |
| 12894 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 12895 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12896 | |
| 12897 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12898 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 12899 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 12900 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 12901 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 12902 | |
| 12903 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 0u); |
| 12904 | } |
| 12905 | |
| 12906 | TEST_P(QuicFramerTest, InvalidCoalescedPacket) { |
| 12907 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 12908 | return; |
| 12909 | } |
| 12910 | // clang-format off |
| 12911 | unsigned char packet[] = { |
| 12912 | // first coalesced packet |
| 12913 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12914 | // 4-byte packet number) |
| 12915 | 0xD3, |
| 12916 | // version |
| 12917 | QUIC_VERSION_BYTES, |
| 12918 | // destination connection ID length |
| 12919 | 0x50, |
| 12920 | // destination connection ID |
| 12921 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
| 12922 | // long header packet length |
| 12923 | 0x1E, |
| 12924 | // packet number |
| 12925 | 0x12, 0x34, 0x56, 0x78, |
| 12926 | // frame type (IETF_STREAM frame with FIN, LEN, and OFFSET bits set) |
| 12927 | 0x08 | 0x01 | 0x02 | 0x04, |
| 12928 | // stream id |
| 12929 | kVarInt62FourBytes + 0x00, 0x02, 0x03, 0x04, |
| 12930 | // offset |
| 12931 | kVarInt62EightBytes + 0x3A, 0x98, 0xFE, 0xDC, |
| 12932 | 0x32, 0x10, 0x76, 0x54, |
| 12933 | // data length |
| 12934 | kVarInt62OneByte + 0x0c, |
| 12935 | // data |
| 12936 | 'h', 'e', 'l', 'l', |
| 12937 | 'o', ' ', 'w', 'o', |
| 12938 | 'r', 'l', 'd', '!', |
| 12939 | // second coalesced packet |
| 12940 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 12941 | // 4-byte packet number) |
| 12942 | 0xD3, |
| 12943 | // version would be here but we cut off the invalid coalesced header. |
| 12944 | }; |
| 12945 | // clang-format on |
| 12946 | |
| 12947 | QuicEncryptedPacket encrypted(AsChars(packet), QUIC_ARRAYSIZE(packet), false); |
| 12948 | EXPECT_QUIC_PEER_BUG(EXPECT_TRUE(framer_.ProcessPacket(encrypted)), |
| 12949 | "Server: Failed to parse received coalesced header.*"); |
| 12950 | |
| 12951 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 12952 | ASSERT_TRUE(visitor_.header_.get()); |
| 12953 | |
| 12954 | ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
| 12955 | EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
| 12956 | |
| 12957 | // Stream ID should be the last 3 bytes of kStreamId. |
| 12958 | EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
| 12959 | EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
| 12960 | EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
| 12961 | CheckStreamFrameData("hello world!", visitor_.stream_frames_[0].get()); |
| 12962 | |
| 12963 | ASSERT_EQ(visitor_.coalesced_packets_.size(), 0u); |
| 12964 | } |
| 12965 | |
| 12966 | TEST_P(QuicFramerTest, PacketHeaderWithVariableLengthConnectionId) { |
| 12967 | if (framer_.transport_version() < QUIC_VERSION_46) { |
| 12968 | return; |
| 12969 | } |
| 12970 | char connection_id_bytes[9] = {0xFE, 0xDC, 0xBA, 0x98, 0x76, |
| 12971 | 0x54, 0x32, 0x10, 0x42}; |
| 12972 | QuicConnectionId connection_id(connection_id_bytes, |
| 12973 | sizeof(connection_id_bytes)); |
| 12974 | QuicFramerPeer::SetLargestPacketNumber(&framer_, kPacketNumber - 2); |
| 12975 | QuicFramerPeer::SetExpectedConnectionIDLength(&framer_, |
| 12976 | connection_id.length()); |
| 12977 | |
| 12978 | // clang-format off |
| 12979 | PacketFragments packet = { |
| 12980 | // type (8 byte connection_id and 1 byte packet number) |
| 12981 | {"Unable to read type.", |
| 12982 | {0x40}}, |
| 12983 | // connection_id |
| 12984 | {"Unable to read Destination ConnectionId.", |
| 12985 | {0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42}}, |
| 12986 | // packet number |
| 12987 | {"Unable to read packet number.", |
| 12988 | {0x78}}, |
| 12989 | }; |
| 12990 | // clang-format on |
| 12991 | |
| 12992 | std::unique_ptr<QuicEncryptedPacket> encrypted( |
| 12993 | AssemblePacketFromFragments(packet)); |
| 12994 | EXPECT_FALSE(framer_.ProcessPacket(*encrypted)); |
| 12995 | EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
| 12996 | ASSERT_TRUE(visitor_.header_.get()); |
| 12997 | EXPECT_EQ(connection_id, visitor_.header_->destination_connection_id); |
| 12998 | EXPECT_FALSE(visitor_.header_->reset_flag); |
| 12999 | EXPECT_FALSE(visitor_.header_->version_flag); |
| 13000 | EXPECT_EQ(PACKET_1BYTE_PACKET_NUMBER, visitor_.header_->packet_number_length); |
| 13001 | EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
| 13002 | |
| 13003 | CheckFramingBoundaries(packet, QUIC_INVALID_PACKET_HEADER); |
| 13004 | } |
| 13005 | |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 13006 | TEST_P(QuicFramerTest, UpdateExpectedConnectionIdLength) { |
| 13007 | if (framer_.transport_version() < QUIC_VERSION_46) { |
| 13008 | return; |
| 13009 | } |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 13010 | framer_.SetShouldUpdateExpectedConnectionIdLength(true); |
| 13011 | |
| 13012 | // clang-format off |
| 13013 | unsigned char long_header_packet[] = { |
| 13014 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13015 | // 4-byte packet number) |
| 13016 | 0xD3, |
| 13017 | // version |
| 13018 | QUIC_VERSION_BYTES, |
| 13019 | // destination connection ID length |
| 13020 | 0x60, |
| 13021 | // destination connection ID |
| 13022 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 13023 | // packet number |
| 13024 | 0x12, 0x34, 0x56, 0x78, |
| 13025 | // padding frame |
| 13026 | 0x00, |
| 13027 | }; |
| 13028 | unsigned char long_header_packet99[] = { |
| 13029 | // public flags (long header with packet type ZERO_RTT_PROTECTED and |
| 13030 | // 4-byte packet number) |
| 13031 | 0xD3, |
| 13032 | // version |
| 13033 | QUIC_VERSION_BYTES, |
| 13034 | // destination connection ID length |
| 13035 | 0x60, |
| 13036 | // destination connection ID |
| 13037 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 13038 | // long header packet length |
| 13039 | 0x05, |
| 13040 | // packet number |
| 13041 | 0x12, 0x34, 0x56, 0x78, |
| 13042 | // padding frame |
| 13043 | 0x00, |
| 13044 | }; |
| 13045 | // clang-format on |
| 13046 | |
| 13047 | if (!QuicVersionHasLongHeaderLengths(framer_.transport_version())) { |
| 13048 | EXPECT_TRUE(framer_.ProcessPacket( |
| 13049 | QuicEncryptedPacket(AsChars(long_header_packet), |
| 13050 | QUIC_ARRAYSIZE(long_header_packet), false))); |
| 13051 | } else { |
| 13052 | EXPECT_TRUE(framer_.ProcessPacket( |
| 13053 | QuicEncryptedPacket(AsChars(long_header_packet99), |
| 13054 | QUIC_ARRAYSIZE(long_header_packet99), false))); |
| 13055 | } |
| 13056 | |
| 13057 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 13058 | ASSERT_TRUE(visitor_.header_.get()); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame^] | 13059 | EXPECT_EQ(visitor_.header_.get()->destination_connection_id, |
| 13060 | FramerTestConnectionIdNineBytes()); |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 13061 | EXPECT_EQ(visitor_.header_.get()->packet_number, |
| 13062 | QuicPacketNumber(UINT64_C(0x12345678))); |
| 13063 | |
| 13064 | // clang-format off |
| 13065 | unsigned char short_header_packet[] = { |
| 13066 | // type (short header, 4 byte packet number) |
| 13067 | 0x43, |
| 13068 | // connection_id |
| 13069 | 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, 0x42, |
| 13070 | // packet number |
| 13071 | 0x13, 0x37, 0x42, 0x33, |
| 13072 | // padding frame |
| 13073 | 0x00, |
| 13074 | }; |
| 13075 | // clang-format on |
| 13076 | |
| 13077 | QuicEncryptedPacket short_header_encrypted( |
| 13078 | AsChars(short_header_packet), QUIC_ARRAYSIZE(short_header_packet), false); |
| 13079 | EXPECT_TRUE(framer_.ProcessPacket(short_header_encrypted)); |
| 13080 | |
| 13081 | EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
| 13082 | ASSERT_TRUE(visitor_.header_.get()); |
QUICHE team | 8e2e453 | 2019-03-14 14:37:56 -0700 | [diff] [blame^] | 13083 | EXPECT_EQ(visitor_.header_.get()->destination_connection_id, |
| 13084 | FramerTestConnectionIdNineBytes()); |
QUICHE team | 4d9d629 | 2019-03-11 14:25:33 -0700 | [diff] [blame] | 13085 | EXPECT_EQ(visitor_.header_.get()->packet_number, |
| 13086 | QuicPacketNumber(UINT64_C(0x13374233))); |
| 13087 | } |
| 13088 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13089 | } // namespace |
| 13090 | } // namespace test |
| 13091 | } // namespace quic |