| OLD | NEW |
| (Empty) |
| 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/quic/quic_framer.h" | |
| 6 | |
| 7 #include <stdint.h> | |
| 8 | |
| 9 #include <algorithm> | |
| 10 #include <map> | |
| 11 #include <memory> | |
| 12 #include <string> | |
| 13 #include <vector> | |
| 14 | |
| 15 #include "base/logging.h" | |
| 16 #include "base/stl_util.h" | |
| 17 #include "net/quic/crypto/null_decrypter.h" | |
| 18 #include "net/quic/crypto/quic_decrypter.h" | |
| 19 #include "net/quic/crypto/quic_encrypter.h" | |
| 20 #include "net/quic/quic_protocol.h" | |
| 21 #include "net/quic/quic_utils.h" | |
| 22 #include "net/quic/test_tools/quic_framer_peer.h" | |
| 23 #include "net/quic/test_tools/quic_test_utils.h" | |
| 24 #include "net/test/gtest_util.h" | |
| 25 | |
| 26 using base::StringPiece; | |
| 27 using std::make_pair; | |
| 28 using std::map; | |
| 29 using std::numeric_limits; | |
| 30 using std::pair; | |
| 31 using std::string; | |
| 32 using std::vector; | |
| 33 using testing::Return; | |
| 34 using testing::Truly; | |
| 35 using testing::_; | |
| 36 | |
| 37 namespace net { | |
| 38 namespace test { | |
| 39 | |
| 40 const QuicPacketNumber kEpoch = UINT64_C(1) << 48; | |
| 41 const QuicPacketNumber kMask = kEpoch - 1; | |
| 42 | |
| 43 // Use fields in which each byte is distinct to ensure that every byte is | |
| 44 // framed correctly. The values are otherwise arbitrary. | |
| 45 const QuicConnectionId kConnectionId = UINT64_C(0xFEDCBA9876543210); | |
| 46 const QuicPathId kPathId = 0x42; | |
| 47 const QuicPacketNumber kPacketNumber = UINT64_C(0x123456789ABC); | |
| 48 const QuicPacketNumber kLargestObserved = UINT64_C(0x0123456789ABF); | |
| 49 const QuicPacketNumber kSmallLargestObserved = UINT16_C(0x1234); | |
| 50 const QuicPacketNumber kMissingPacket = UINT64_C(0x0123456789ABE); | |
| 51 const QuicPacketNumber kSmallMissingPacket = UINT16_C(0x1233); | |
| 52 const QuicPacketNumber kLeastUnacked = UINT64_C(0x0123456789AA0); | |
| 53 const QuicStreamId kStreamId = UINT64_C(0x01020304); | |
| 54 const QuicStreamOffset kStreamOffset = UINT64_C(0xBA98FEDC32107654); | |
| 55 const QuicPublicResetNonceProof kNonceProof = UINT64_C(0xABCDEF0123456789); | |
| 56 | |
| 57 // Index into the connection_id offset in the header. | |
| 58 const size_t kConnectionIdOffset = kPublicFlagsSize; | |
| 59 // Index into the version string in the header. (if present). | |
| 60 const size_t kVersionOffset = kConnectionIdOffset + PACKET_8BYTE_CONNECTION_ID; | |
| 61 | |
| 62 // Size in bytes of the stream frame fields for an arbitrary StreamID and | |
| 63 // offset and the last frame in a packet. | |
| 64 size_t GetMinStreamFrameSize() { | |
| 65 return kQuicFrameTypeSize + kQuicMaxStreamIdSize + kQuicMaxStreamOffsetSize; | |
| 66 } | |
| 67 | |
| 68 // Index into the path id offset in the header (if present). | |
| 69 size_t GetPathIdOffset(QuicConnectionIdLength connection_id_length, | |
| 70 bool include_version) { | |
| 71 return kConnectionIdOffset + connection_id_length + | |
| 72 (include_version ? kQuicVersionSize : 0); | |
| 73 } | |
| 74 | |
| 75 // Index into the packet number offset in the header. | |
| 76 size_t GetPacketNumberOffset(QuicConnectionIdLength connection_id_length, | |
| 77 bool include_version, | |
| 78 bool include_path_id) { | |
| 79 return kConnectionIdOffset + connection_id_length + | |
| 80 (include_version ? kQuicVersionSize : 0) + | |
| 81 (include_path_id ? kQuicPathIdSize : 0); | |
| 82 } | |
| 83 | |
| 84 size_t GetPacketNumberOffset(bool include_version, bool include_path_id) { | |
| 85 return GetPacketNumberOffset(PACKET_8BYTE_CONNECTION_ID, include_version, | |
| 86 include_path_id); | |
| 87 } | |
| 88 | |
| 89 // Index into the private flags offset in the data packet header. | |
| 90 size_t GetPrivateFlagsOffset(QuicConnectionIdLength connection_id_length, | |
| 91 bool include_version, | |
| 92 bool include_path_id) { | |
| 93 return GetPacketNumberOffset(connection_id_length, include_version, | |
| 94 include_path_id) + | |
| 95 PACKET_6BYTE_PACKET_NUMBER; | |
| 96 } | |
| 97 | |
| 98 size_t GetPrivateFlagsOffset(bool include_version, bool include_path_id) { | |
| 99 return GetPrivateFlagsOffset(PACKET_8BYTE_CONNECTION_ID, include_version, | |
| 100 include_path_id); | |
| 101 } | |
| 102 | |
| 103 size_t GetPrivateFlagsOffset(bool include_version, | |
| 104 bool include_path_id, | |
| 105 QuicPacketNumberLength packet_number_length) { | |
| 106 return GetPacketNumberOffset(PACKET_8BYTE_CONNECTION_ID, include_version, | |
| 107 include_path_id) + | |
| 108 packet_number_length; | |
| 109 } | |
| 110 | |
| 111 // Index into the message tag of the public reset packet. | |
| 112 // Public resets always have full connection_ids. | |
| 113 const size_t kPublicResetPacketMessageTagOffset = | |
| 114 kConnectionIdOffset + PACKET_8BYTE_CONNECTION_ID; | |
| 115 | |
| 116 class TestEncrypter : public QuicEncrypter { | |
| 117 public: | |
| 118 ~TestEncrypter() override {} | |
| 119 bool SetKey(StringPiece key) override { return true; } | |
| 120 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; } | |
| 121 bool EncryptPacket(QuicPathId path_id, | |
| 122 QuicPacketNumber packet_number, | |
| 123 StringPiece associated_data, | |
| 124 StringPiece plaintext, | |
| 125 char* output, | |
| 126 size_t* output_length, | |
| 127 size_t max_output_length) override { | |
| 128 path_id_ = path_id; | |
| 129 packet_number_ = packet_number; | |
| 130 associated_data_ = associated_data.as_string(); | |
| 131 plaintext_ = plaintext.as_string(); | |
| 132 memcpy(output, plaintext.data(), plaintext.length()); | |
| 133 *output_length = plaintext.length(); | |
| 134 return true; | |
| 135 } | |
| 136 size_t GetKeySize() const override { return 0; } | |
| 137 size_t GetNoncePrefixSize() const override { return 0; } | |
| 138 size_t GetMaxPlaintextSize(size_t ciphertext_size) const override { | |
| 139 return ciphertext_size; | |
| 140 } | |
| 141 size_t GetCiphertextSize(size_t plaintext_size) const override { | |
| 142 return plaintext_size; | |
| 143 } | |
| 144 StringPiece GetKey() const override { return StringPiece(); } | |
| 145 StringPiece GetNoncePrefix() const override { return StringPiece(); } | |
| 146 QuicPathId path_id_; | |
| 147 QuicPacketNumber packet_number_; | |
| 148 string associated_data_; | |
| 149 string plaintext_; | |
| 150 }; | |
| 151 | |
| 152 class TestDecrypter : public QuicDecrypter { | |
| 153 public: | |
| 154 ~TestDecrypter() override {} | |
| 155 bool SetKey(StringPiece key) override { return true; } | |
| 156 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; } | |
| 157 bool SetPreliminaryKey(StringPiece key) override { | |
| 158 QUIC_BUG << "should not be called"; | |
| 159 return false; | |
| 160 } | |
| 161 bool SetDiversificationNonce(DiversificationNonce key) override { | |
| 162 return true; | |
| 163 } | |
| 164 bool DecryptPacket(QuicPathId path_id, | |
| 165 QuicPacketNumber packet_number, | |
| 166 StringPiece associated_data, | |
| 167 StringPiece ciphertext, | |
| 168 char* output, | |
| 169 size_t* output_length, | |
| 170 size_t max_output_length) override { | |
| 171 path_id_ = path_id; | |
| 172 packet_number_ = packet_number; | |
| 173 associated_data_ = associated_data.as_string(); | |
| 174 ciphertext_ = ciphertext.as_string(); | |
| 175 memcpy(output, ciphertext.data(), ciphertext.length()); | |
| 176 *output_length = ciphertext.length(); | |
| 177 return true; | |
| 178 } | |
| 179 StringPiece GetKey() const override { return StringPiece(); } | |
| 180 StringPiece GetNoncePrefix() const override { return StringPiece(); } | |
| 181 const char* cipher_name() const override { return "Test"; } | |
| 182 // Use a distinct value starting with 0xFFFFFF, which is never used by TLS. | |
| 183 uint32_t cipher_id() const override { return 0xFFFFFFF2; } | |
| 184 QuicPathId path_id_; | |
| 185 QuicPacketNumber packet_number_; | |
| 186 string associated_data_; | |
| 187 string ciphertext_; | |
| 188 }; | |
| 189 | |
| 190 class TestQuicVisitor : public QuicFramerVisitorInterface { | |
| 191 public: | |
| 192 TestQuicVisitor() | |
| 193 : error_count_(0), | |
| 194 version_mismatch_(0), | |
| 195 packet_count_(0), | |
| 196 frame_count_(0), | |
| 197 complete_packets_(0), | |
| 198 accept_packet_(true), | |
| 199 accept_public_header_(true) {} | |
| 200 | |
| 201 ~TestQuicVisitor() override { | |
| 202 STLDeleteElements(&stream_frames_); | |
| 203 STLDeleteElements(&ack_frames_); | |
| 204 STLDeleteElements(&stop_waiting_frames_); | |
| 205 STLDeleteElements(&padding_frames_); | |
| 206 STLDeleteElements(&ping_frames_); | |
| 207 STLDeleteElements(&stream_data_); | |
| 208 } | |
| 209 | |
| 210 void OnError(QuicFramer* f) override { | |
| 211 DVLOG(1) << "QuicFramer Error: " << QuicUtils::ErrorToString(f->error()) | |
| 212 << " (" << f->error() << ")"; | |
| 213 ++error_count_; | |
| 214 } | |
| 215 | |
| 216 void OnPacket() override {} | |
| 217 | |
| 218 void OnPublicResetPacket(const QuicPublicResetPacket& packet) override { | |
| 219 public_reset_packet_.reset(new QuicPublicResetPacket(packet)); | |
| 220 } | |
| 221 | |
| 222 void OnVersionNegotiationPacket( | |
| 223 const QuicVersionNegotiationPacket& packet) override { | |
| 224 version_negotiation_packet_.reset(new QuicVersionNegotiationPacket(packet)); | |
| 225 } | |
| 226 | |
| 227 bool OnProtocolVersionMismatch(QuicVersion version) override { | |
| 228 DVLOG(1) << "QuicFramer Version Mismatch, version: " << version; | |
| 229 ++version_mismatch_; | |
| 230 return true; | |
| 231 } | |
| 232 | |
| 233 bool OnUnauthenticatedPublicHeader( | |
| 234 const QuicPacketPublicHeader& header) override { | |
| 235 public_header_.reset(new QuicPacketPublicHeader(header)); | |
| 236 return accept_public_header_; | |
| 237 } | |
| 238 | |
| 239 bool OnUnauthenticatedHeader(const QuicPacketHeader& header) override { | |
| 240 return true; | |
| 241 } | |
| 242 | |
| 243 void OnDecryptedPacket(EncryptionLevel level) override {} | |
| 244 | |
| 245 bool OnPacketHeader(const QuicPacketHeader& header) override { | |
| 246 if (header.fec_flag) { | |
| 247 // Drop any FEC packet. | |
| 248 return false; | |
| 249 } | |
| 250 ++packet_count_; | |
| 251 header_.reset(new QuicPacketHeader(header)); | |
| 252 return accept_packet_; | |
| 253 } | |
| 254 | |
| 255 bool OnStreamFrame(const QuicStreamFrame& frame) override { | |
| 256 ++frame_count_; | |
| 257 // Save a copy of the data so it is valid after the packet is processed. | |
| 258 string* string_data = new string(); | |
| 259 StringPiece(frame.data_buffer, frame.data_length) | |
| 260 .AppendToString(string_data); | |
| 261 stream_data_.push_back(string_data); | |
| 262 stream_frames_.push_back(new QuicStreamFrame(frame.stream_id, frame.fin, | |
| 263 frame.offset, *string_data)); | |
| 264 return true; | |
| 265 } | |
| 266 | |
| 267 bool OnAckFrame(const QuicAckFrame& frame) override { | |
| 268 ++frame_count_; | |
| 269 ack_frames_.push_back(new QuicAckFrame(frame)); | |
| 270 return true; | |
| 271 } | |
| 272 | |
| 273 bool OnStopWaitingFrame(const QuicStopWaitingFrame& frame) override { | |
| 274 ++frame_count_; | |
| 275 stop_waiting_frames_.push_back(new QuicStopWaitingFrame(frame)); | |
| 276 return true; | |
| 277 } | |
| 278 | |
| 279 bool OnPaddingFrame(const QuicPaddingFrame& frame) override { | |
| 280 padding_frames_.push_back(new QuicPaddingFrame(frame)); | |
| 281 return true; | |
| 282 } | |
| 283 | |
| 284 bool OnPingFrame(const QuicPingFrame& frame) override { | |
| 285 ++frame_count_; | |
| 286 ping_frames_.push_back(new QuicPingFrame(frame)); | |
| 287 return true; | |
| 288 } | |
| 289 | |
| 290 void OnPacketComplete() override { ++complete_packets_; } | |
| 291 | |
| 292 bool OnRstStreamFrame(const QuicRstStreamFrame& frame) override { | |
| 293 rst_stream_frame_ = frame; | |
| 294 return true; | |
| 295 } | |
| 296 | |
| 297 bool OnConnectionCloseFrame(const QuicConnectionCloseFrame& frame) override { | |
| 298 connection_close_frame_ = frame; | |
| 299 return true; | |
| 300 } | |
| 301 | |
| 302 bool OnGoAwayFrame(const QuicGoAwayFrame& frame) override { | |
| 303 goaway_frame_ = frame; | |
| 304 return true; | |
| 305 } | |
| 306 | |
| 307 bool OnWindowUpdateFrame(const QuicWindowUpdateFrame& frame) override { | |
| 308 window_update_frame_ = frame; | |
| 309 return true; | |
| 310 } | |
| 311 | |
| 312 bool OnBlockedFrame(const QuicBlockedFrame& frame) override { | |
| 313 blocked_frame_ = frame; | |
| 314 return true; | |
| 315 } | |
| 316 | |
| 317 bool OnPathCloseFrame(const QuicPathCloseFrame& frame) override { | |
| 318 path_close_frame_ = frame; | |
| 319 return true; | |
| 320 } | |
| 321 | |
| 322 // Counters from the visitor_ callbacks. | |
| 323 int error_count_; | |
| 324 int version_mismatch_; | |
| 325 int packet_count_; | |
| 326 int frame_count_; | |
| 327 int complete_packets_; | |
| 328 bool accept_packet_; | |
| 329 bool accept_public_header_; | |
| 330 | |
| 331 std::unique_ptr<QuicPacketHeader> header_; | |
| 332 std::unique_ptr<QuicPacketPublicHeader> public_header_; | |
| 333 std::unique_ptr<QuicPublicResetPacket> public_reset_packet_; | |
| 334 std::unique_ptr<QuicVersionNegotiationPacket> version_negotiation_packet_; | |
| 335 vector<QuicStreamFrame*> stream_frames_; | |
| 336 vector<QuicAckFrame*> ack_frames_; | |
| 337 vector<QuicStopWaitingFrame*> stop_waiting_frames_; | |
| 338 vector<QuicPaddingFrame*> padding_frames_; | |
| 339 vector<QuicPingFrame*> ping_frames_; | |
| 340 QuicRstStreamFrame rst_stream_frame_; | |
| 341 QuicConnectionCloseFrame connection_close_frame_; | |
| 342 QuicGoAwayFrame goaway_frame_; | |
| 343 QuicWindowUpdateFrame window_update_frame_; | |
| 344 QuicBlockedFrame blocked_frame_; | |
| 345 QuicPathCloseFrame path_close_frame_; | |
| 346 vector<string*> stream_data_; | |
| 347 }; | |
| 348 | |
| 349 class QuicFramerTest : public ::testing::TestWithParam<QuicVersion> { | |
| 350 public: | |
| 351 QuicFramerTest() | |
| 352 : encrypter_(new test::TestEncrypter()), | |
| 353 decrypter_(new test::TestDecrypter()), | |
| 354 start_(QuicTime::Zero() + QuicTime::Delta::FromMicroseconds(0x10)), | |
| 355 framer_(QuicSupportedVersions(), start_, Perspective::IS_SERVER) { | |
| 356 version_ = GetParam(); | |
| 357 framer_.set_version(version_); | |
| 358 framer_.SetDecrypter(ENCRYPTION_NONE, decrypter_); | |
| 359 framer_.SetEncrypter(ENCRYPTION_NONE, encrypter_); | |
| 360 framer_.set_visitor(&visitor_); | |
| 361 framer_.set_received_entropy_calculator(&entropy_calculator_); | |
| 362 } | |
| 363 | |
| 364 // Helper function to get unsigned char representation of digit in the | |
| 365 // units place of the current QUIC version number. | |
| 366 unsigned char GetQuicVersionDigitOnes() { | |
| 367 return static_cast<unsigned char>('0' + version_ % 10); | |
| 368 } | |
| 369 | |
| 370 // Helper function to get unsigned char representation of digit in the | |
| 371 // tens place of the current QUIC version number. | |
| 372 unsigned char GetQuicVersionDigitTens() { | |
| 373 return static_cast<unsigned char>('0' + (version_ / 10) % 10); | |
| 374 } | |
| 375 | |
| 376 bool CheckEncryption(QuicPathId path_id, | |
| 377 QuicPacketNumber packet_number, | |
| 378 QuicPacket* packet) { | |
| 379 if (packet_number != encrypter_->packet_number_) { | |
| 380 LOG(ERROR) << "Encrypted incorrect packet number. expected " | |
| 381 << packet_number << " actual: " << encrypter_->packet_number_; | |
| 382 return false; | |
| 383 } | |
| 384 if (packet->AssociatedData(framer_.version()) != | |
| 385 encrypter_->associated_data_) { | |
| 386 LOG(ERROR) << "Encrypted incorrect associated data. expected " | |
| 387 << packet->AssociatedData(framer_.version()) | |
| 388 << " actual: " << encrypter_->associated_data_; | |
| 389 return false; | |
| 390 } | |
| 391 if (packet->Plaintext(framer_.version()) != encrypter_->plaintext_) { | |
| 392 LOG(ERROR) << "Encrypted incorrect plaintext data. expected " | |
| 393 << packet->Plaintext(framer_.version()) | |
| 394 << " actual: " << encrypter_->plaintext_; | |
| 395 return false; | |
| 396 } | |
| 397 return true; | |
| 398 } | |
| 399 | |
| 400 bool CheckDecryption(const QuicEncryptedPacket& encrypted, | |
| 401 bool includes_version, | |
| 402 bool includes_path_id, | |
| 403 bool includes_diversification_nonce) { | |
| 404 if (visitor_.header_->packet_number != decrypter_->packet_number_) { | |
| 405 LOG(ERROR) << "Decrypted incorrect packet number. expected " | |
| 406 << visitor_.header_->packet_number | |
| 407 << " actual: " << decrypter_->packet_number_; | |
| 408 return false; | |
| 409 } | |
| 410 if (QuicFramer::GetAssociatedDataFromEncryptedPacket( | |
| 411 framer_.version(), encrypted, PACKET_8BYTE_CONNECTION_ID, | |
| 412 includes_version, includes_path_id, includes_diversification_nonce, | |
| 413 PACKET_6BYTE_PACKET_NUMBER) != decrypter_->associated_data_) { | |
| 414 LOG(ERROR) << "Decrypted incorrect associated data. expected " | |
| 415 << QuicFramer::GetAssociatedDataFromEncryptedPacket( | |
| 416 framer_.version(), encrypted, | |
| 417 PACKET_8BYTE_CONNECTION_ID, includes_version, | |
| 418 includes_path_id, includes_diversification_nonce, | |
| 419 PACKET_6BYTE_PACKET_NUMBER) | |
| 420 << " actual: " << decrypter_->associated_data_; | |
| 421 return false; | |
| 422 } | |
| 423 StringPiece ciphertext( | |
| 424 encrypted.AsStringPiece().substr(GetStartOfEncryptedData( | |
| 425 framer_.version(), PACKET_8BYTE_CONNECTION_ID, includes_version, | |
| 426 includes_path_id, includes_diversification_nonce, | |
| 427 PACKET_6BYTE_PACKET_NUMBER))); | |
| 428 if (ciphertext != decrypter_->ciphertext_) { | |
| 429 LOG(ERROR) << "Decrypted incorrect ciphertext data. expected " | |
| 430 << ciphertext << " actual: " << decrypter_->ciphertext_; | |
| 431 return false; | |
| 432 } | |
| 433 return true; | |
| 434 } | |
| 435 | |
| 436 char* AsChars(unsigned char* data) { return reinterpret_cast<char*>(data); } | |
| 437 | |
| 438 void CheckProcessingFails(unsigned char* packet, | |
| 439 size_t len, | |
| 440 string expected_error, | |
| 441 QuicErrorCode error_code) { | |
| 442 QuicEncryptedPacket encrypted(AsChars(packet), len, false); | |
| 443 EXPECT_FALSE(framer_.ProcessPacket(encrypted)) << "len: " << len; | |
| 444 EXPECT_EQ(expected_error, framer_.detailed_error()) << "len: " << len; | |
| 445 EXPECT_EQ(error_code, framer_.error()) << "len: " << len; | |
| 446 } | |
| 447 | |
| 448 // Checks if the supplied string matches data in the supplied StreamFrame. | |
| 449 void CheckStreamFrameData(string str, QuicStreamFrame* frame) { | |
| 450 EXPECT_EQ(str, string(frame->data_buffer, frame->data_length)); | |
| 451 } | |
| 452 | |
| 453 void CheckStreamFrameBoundaries(unsigned char* packet, | |
| 454 size_t stream_id_size, | |
| 455 bool include_version) { | |
| 456 // Now test framing boundaries. | |
| 457 for (size_t i = kQuicFrameTypeSize; i < GetMinStreamFrameSize(); ++i) { | |
| 458 string expected_error; | |
| 459 if (i < kQuicFrameTypeSize + stream_id_size) { | |
| 460 expected_error = "Unable to read stream_id."; | |
| 461 } else if (i < kQuicFrameTypeSize + stream_id_size + | |
| 462 kQuicMaxStreamOffsetSize) { | |
| 463 expected_error = "Unable to read offset."; | |
| 464 } else { | |
| 465 expected_error = "Unable to read frame data."; | |
| 466 } | |
| 467 CheckProcessingFails( | |
| 468 packet, | |
| 469 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 470 include_version, !kIncludePathId, | |
| 471 !kIncludeDiversificationNonce, | |
| 472 PACKET_6BYTE_PACKET_NUMBER), | |
| 473 expected_error, QUIC_INVALID_STREAM_DATA); | |
| 474 } | |
| 475 } | |
| 476 | |
| 477 void CheckCalculatePacketNumber(QuicPacketNumber expected_packet_number, | |
| 478 QuicPacketNumber last_packet_number) { | |
| 479 QuicPacketNumber wire_packet_number = expected_packet_number & kMask; | |
| 480 QuicFramerPeer::SetLastPacketNumber(&framer_, last_packet_number); | |
| 481 EXPECT_EQ( | |
| 482 expected_packet_number, | |
| 483 QuicFramerPeer::CalculatePacketNumberFromWire( | |
| 484 &framer_, PACKET_6BYTE_PACKET_NUMBER, | |
| 485 QuicFramerPeer::GetLastPacketNumber(&framer_), wire_packet_number)) | |
| 486 << "last_packet_number: " << last_packet_number | |
| 487 << " wire_packet_number: " << wire_packet_number; | |
| 488 } | |
| 489 | |
| 490 QuicPacket* BuildDataPacket(const QuicPacketHeader& header, | |
| 491 const QuicFrames& frames) { | |
| 492 return BuildUnsizedDataPacket(&framer_, header, frames); | |
| 493 } | |
| 494 | |
| 495 QuicPacket* BuildDataPacket(const QuicPacketHeader& header, | |
| 496 const QuicFrames& frames, | |
| 497 size_t packet_size) { | |
| 498 return BuildUnsizedDataPacket(&framer_, header, frames, packet_size); | |
| 499 } | |
| 500 | |
| 501 test::TestEncrypter* encrypter_; | |
| 502 test::TestDecrypter* decrypter_; | |
| 503 QuicVersion version_; | |
| 504 QuicTime start_; | |
| 505 QuicFramer framer_; | |
| 506 test::TestQuicVisitor visitor_; | |
| 507 test::TestEntropyCalculator entropy_calculator_; | |
| 508 }; | |
| 509 | |
| 510 // Run all framer tests with all supported versions of QUIC. | |
| 511 INSTANTIATE_TEST_CASE_P(QuicFramerTests, | |
| 512 QuicFramerTest, | |
| 513 ::testing::ValuesIn(kSupportedQuicVersions)); | |
| 514 | |
| 515 TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochStart) { | |
| 516 // A few quick manual sanity checks. | |
| 517 CheckCalculatePacketNumber(UINT64_C(1), UINT64_C(0)); | |
| 518 CheckCalculatePacketNumber(kEpoch + 1, kMask); | |
| 519 CheckCalculatePacketNumber(kEpoch, kMask); | |
| 520 | |
| 521 // Cases where the last number was close to the start of the range. | |
| 522 for (uint64_t last = 0; last < 10; last++) { | |
| 523 // Small numbers should not wrap (even if they're out of order). | |
| 524 for (uint64_t j = 0; j < 10; j++) { | |
| 525 CheckCalculatePacketNumber(j, last); | |
| 526 } | |
| 527 | |
| 528 // Large numbers should not wrap either (because we're near 0 already). | |
| 529 for (uint64_t j = 0; j < 10; j++) { | |
| 530 CheckCalculatePacketNumber(kEpoch - 1 - j, last); | |
| 531 } | |
| 532 } | |
| 533 } | |
| 534 | |
| 535 TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearEpochEnd) { | |
| 536 // Cases where the last number was close to the end of the range | |
| 537 for (uint64_t i = 0; i < 10; i++) { | |
| 538 QuicPacketNumber last = kEpoch - i; | |
| 539 | |
| 540 // Small numbers should wrap. | |
| 541 for (uint64_t j = 0; j < 10; j++) { | |
| 542 CheckCalculatePacketNumber(kEpoch + j, last); | |
| 543 } | |
| 544 | |
| 545 // Large numbers should not (even if they're out of order). | |
| 546 for (uint64_t j = 0; j < 10; j++) { | |
| 547 CheckCalculatePacketNumber(kEpoch - 1 - j, last); | |
| 548 } | |
| 549 } | |
| 550 } | |
| 551 | |
| 552 // Next check where we're in a non-zero epoch to verify we handle | |
| 553 // reverse wrapping, too. | |
| 554 TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearPrevEpoch) { | |
| 555 const uint64_t prev_epoch = 1 * kEpoch; | |
| 556 const uint64_t cur_epoch = 2 * kEpoch; | |
| 557 // Cases where the last number was close to the start of the range | |
| 558 for (uint64_t i = 0; i < 10; i++) { | |
| 559 uint64_t last = cur_epoch + i; | |
| 560 // Small number should not wrap (even if they're out of order). | |
| 561 for (uint64_t j = 0; j < 10; j++) { | |
| 562 CheckCalculatePacketNumber(cur_epoch + j, last); | |
| 563 } | |
| 564 | |
| 565 // But large numbers should reverse wrap. | |
| 566 for (uint64_t j = 0; j < 10; j++) { | |
| 567 uint64_t num = kEpoch - 1 - j; | |
| 568 CheckCalculatePacketNumber(prev_epoch + num, last); | |
| 569 } | |
| 570 } | |
| 571 } | |
| 572 | |
| 573 TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearNextEpoch) { | |
| 574 const uint64_t cur_epoch = 2 * kEpoch; | |
| 575 const uint64_t next_epoch = 3 * kEpoch; | |
| 576 // Cases where the last number was close to the end of the range | |
| 577 for (uint64_t i = 0; i < 10; i++) { | |
| 578 QuicPacketNumber last = next_epoch - 1 - i; | |
| 579 | |
| 580 // Small numbers should wrap. | |
| 581 for (uint64_t j = 0; j < 10; j++) { | |
| 582 CheckCalculatePacketNumber(next_epoch + j, last); | |
| 583 } | |
| 584 | |
| 585 // but large numbers should not (even if they're out of order). | |
| 586 for (uint64_t j = 0; j < 10; j++) { | |
| 587 uint64_t num = kEpoch - 1 - j; | |
| 588 CheckCalculatePacketNumber(cur_epoch + num, last); | |
| 589 } | |
| 590 } | |
| 591 } | |
| 592 | |
| 593 TEST_P(QuicFramerTest, CalculatePacketNumberFromWireNearNextMax) { | |
| 594 const uint64_t max_number = numeric_limits<uint64_t>::max(); | |
| 595 const uint64_t max_epoch = max_number & ~kMask; | |
| 596 | |
| 597 // Cases where the last number was close to the end of the range | |
| 598 for (uint64_t i = 0; i < 10; i++) { | |
| 599 // Subtract 1, because the expected next packet number is 1 more than the | |
| 600 // last packet number. | |
| 601 QuicPacketNumber last = max_number - i - 1; | |
| 602 | |
| 603 // Small numbers should not wrap, because they have nowhere to go. | |
| 604 for (uint64_t j = 0; j < 10; j++) { | |
| 605 CheckCalculatePacketNumber(max_epoch + j, last); | |
| 606 } | |
| 607 | |
| 608 // Large numbers should not wrap either. | |
| 609 for (uint64_t j = 0; j < 10; j++) { | |
| 610 uint64_t num = kEpoch - 1 - j; | |
| 611 CheckCalculatePacketNumber(max_epoch + num, last); | |
| 612 } | |
| 613 } | |
| 614 } | |
| 615 | |
| 616 TEST_P(QuicFramerTest, EmptyPacket) { | |
| 617 char packet[] = {0x00}; | |
| 618 QuicEncryptedPacket encrypted(packet, 0, false); | |
| 619 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | |
| 620 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); | |
| 621 } | |
| 622 | |
| 623 TEST_P(QuicFramerTest, LargePacket) { | |
| 624 // clang-format off | |
| 625 unsigned char packet[kMaxPacketSize + 1] = { | |
| 626 // public flags (8 byte connection_id) | |
| 627 0x38, | |
| 628 // connection_id | |
| 629 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 630 // packet number | |
| 631 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 632 // private flags | |
| 633 0x00, | |
| 634 }; | |
| 635 // clang-format on | |
| 636 | |
| 637 const size_t header_size = GetPacketHeaderSize( | |
| 638 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | |
| 639 !kIncludePathId, !kIncludeDiversificationNonce, | |
| 640 PACKET_6BYTE_PACKET_NUMBER); | |
| 641 | |
| 642 memset(packet + header_size, 0, kMaxPacketSize - header_size); | |
| 643 | |
| 644 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 645 EXPECT_DFATAL(framer_.ProcessPacket(encrypted), "Packet too large:1"); | |
| 646 | |
| 647 ASSERT_TRUE(visitor_.header_.get()); | |
| 648 // Make sure we've parsed the packet header, so we can send an error. | |
| 649 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | |
| 650 // Make sure the correct error is propagated. | |
| 651 EXPECT_EQ(QUIC_PACKET_TOO_LARGE, framer_.error()); | |
| 652 } | |
| 653 | |
| 654 TEST_P(QuicFramerTest, PacketHeader) { | |
| 655 // clang-format off | |
| 656 unsigned char packet[] = { | |
| 657 // public flags (8 byte connection_id) | |
| 658 0x38, | |
| 659 // connection_id | |
| 660 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 661 // packet number | |
| 662 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 663 // private flags | |
| 664 0x00, | |
| 665 }; | |
| 666 unsigned char packet_34[] = { | |
| 667 // public flags (8 byte connection_id) | |
| 668 0x38, | |
| 669 // connection_id | |
| 670 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 671 // packet number | |
| 672 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 673 }; | |
| 674 // clang-format on | |
| 675 | |
| 676 QuicEncryptedPacket encrypted( | |
| 677 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 678 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 679 : arraysize(packet_34), | |
| 680 false); | |
| 681 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | |
| 682 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | |
| 683 ASSERT_TRUE(visitor_.header_.get()); | |
| 684 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | |
| 685 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); | |
| 686 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); | |
| 687 EXPECT_FALSE(visitor_.header_->public_header.version_flag); | |
| 688 EXPECT_FALSE(visitor_.header_->fec_flag); | |
| 689 EXPECT_FALSE(visitor_.header_->entropy_flag); | |
| 690 EXPECT_EQ(0, visitor_.header_->entropy_hash); | |
| 691 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | |
| 692 | |
| 693 // Now test framing boundaries. | |
| 694 for (size_t i = 0; | |
| 695 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 696 !kIncludeVersion, !kIncludePathId, | |
| 697 !kIncludeDiversificationNonce, | |
| 698 PACKET_6BYTE_PACKET_NUMBER); | |
| 699 ++i) { | |
| 700 string expected_error; | |
| 701 if (i < kConnectionIdOffset) { | |
| 702 expected_error = "Unable to read public flags."; | |
| 703 } else if (i < GetPacketNumberOffset(!kIncludeVersion, !kIncludePathId)) { | |
| 704 expected_error = "Unable to read ConnectionId."; | |
| 705 } else { | |
| 706 if (framer_.version() <= QUIC_VERSION_33) { | |
| 707 if (i < GetPrivateFlagsOffset(!kIncludeVersion, !kIncludePathId)) { | |
| 708 expected_error = "Unable to read packet number."; | |
| 709 } else { | |
| 710 expected_error = "Unable to read private flags."; | |
| 711 } | |
| 712 } else { | |
| 713 expected_error = "Unable to read packet number."; | |
| 714 } | |
| 715 } | |
| 716 CheckProcessingFails( | |
| 717 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, i, | |
| 718 expected_error, QUIC_INVALID_PACKET_HEADER); | |
| 719 } | |
| 720 } | |
| 721 | |
| 722 TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) { | |
| 723 QuicFramerPeer::SetLastSerializedConnectionId(&framer_, kConnectionId); | |
| 724 | |
| 725 // clang-format off | |
| 726 unsigned char packet[] = { | |
| 727 // public flags (0 byte connection_id) | |
| 728 0x30, | |
| 729 // connection_id | |
| 730 // packet number | |
| 731 0xBC, 0x9A, 0x78, 0x56, | |
| 732 0x34, 0x12, | |
| 733 // private flags | |
| 734 0x00, | |
| 735 }; | |
| 736 unsigned char packet_34[] = { | |
| 737 // public flags (0 byte connection_id) | |
| 738 0x30, | |
| 739 // connection_id | |
| 740 // packet number | |
| 741 0xBC, 0x9A, 0x78, 0x56, | |
| 742 0x34, 0x12, | |
| 743 }; | |
| 744 // clang-format on | |
| 745 | |
| 746 QuicEncryptedPacket encrypted( | |
| 747 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 748 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 749 : arraysize(packet_34), | |
| 750 false); | |
| 751 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | |
| 752 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | |
| 753 ASSERT_TRUE(visitor_.header_.get()); | |
| 754 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | |
| 755 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); | |
| 756 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); | |
| 757 EXPECT_FALSE(visitor_.header_->public_header.version_flag); | |
| 758 EXPECT_FALSE(visitor_.header_->fec_flag); | |
| 759 EXPECT_FALSE(visitor_.header_->entropy_flag); | |
| 760 EXPECT_EQ(0, visitor_.header_->entropy_hash); | |
| 761 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | |
| 762 | |
| 763 // Now test framing boundaries. | |
| 764 for (size_t i = 0; | |
| 765 i < GetPacketHeaderSize(framer_.version(), PACKET_0BYTE_CONNECTION_ID, | |
| 766 !kIncludeVersion, !kIncludePathId, | |
| 767 !kIncludeDiversificationNonce, | |
| 768 PACKET_6BYTE_PACKET_NUMBER); | |
| 769 ++i) { | |
| 770 string expected_error; | |
| 771 if (i < kConnectionIdOffset) { | |
| 772 expected_error = "Unable to read public flags."; | |
| 773 } else if (i < GetPacketNumberOffset(PACKET_0BYTE_CONNECTION_ID, | |
| 774 !kIncludeVersion, !kIncludePathId)) { | |
| 775 expected_error = "Unable to read ConnectionId."; | |
| 776 } else { | |
| 777 if (framer_.version() <= QUIC_VERSION_33) { | |
| 778 if (i < GetPrivateFlagsOffset(PACKET_0BYTE_CONNECTION_ID, | |
| 779 !kIncludeVersion, !kIncludePathId)) { | |
| 780 expected_error = "Unable to read packet number."; | |
| 781 } else { | |
| 782 expected_error = "Unable to read private flags."; | |
| 783 } | |
| 784 } else { | |
| 785 expected_error = "Unable to read packet number."; | |
| 786 } | |
| 787 } | |
| 788 CheckProcessingFails( | |
| 789 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, i, | |
| 790 expected_error, QUIC_INVALID_PACKET_HEADER); | |
| 791 } | |
| 792 } | |
| 793 | |
| 794 TEST_P(QuicFramerTest, PacketHeaderWithVersionFlag) { | |
| 795 // clang-format off | |
| 796 unsigned char packet[] = { | |
| 797 // public flags (version) | |
| 798 0x39, | |
| 799 // connection_id | |
| 800 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 801 // version tag | |
| 802 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | |
| 803 // packet number | |
| 804 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 805 // private flags | |
| 806 0x00, | |
| 807 }; | |
| 808 unsigned char packet_34[] = { | |
| 809 // public flags (version) | |
| 810 0x39, | |
| 811 // connection_id | |
| 812 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 813 // version tag | |
| 814 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | |
| 815 // packet number | |
| 816 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 817 }; | |
| 818 // clang-format on | |
| 819 | |
| 820 QuicEncryptedPacket encrypted( | |
| 821 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 822 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 823 : arraysize(packet_34), | |
| 824 false); | |
| 825 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | |
| 826 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | |
| 827 ASSERT_TRUE(visitor_.header_.get()); | |
| 828 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | |
| 829 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); | |
| 830 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); | |
| 831 EXPECT_TRUE(visitor_.header_->public_header.version_flag); | |
| 832 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]); | |
| 833 EXPECT_FALSE(visitor_.header_->fec_flag); | |
| 834 EXPECT_FALSE(visitor_.header_->entropy_flag); | |
| 835 EXPECT_EQ(0, visitor_.header_->entropy_hash); | |
| 836 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | |
| 837 | |
| 838 // Now test framing boundaries. | |
| 839 for (size_t i = 0; | |
| 840 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 841 kIncludeVersion, !kIncludePathId, | |
| 842 !kIncludeDiversificationNonce, | |
| 843 PACKET_6BYTE_PACKET_NUMBER); | |
| 844 ++i) { | |
| 845 string expected_error; | |
| 846 if (i < kConnectionIdOffset) { | |
| 847 expected_error = "Unable to read public flags."; | |
| 848 } else if (i < kVersionOffset) { | |
| 849 expected_error = "Unable to read ConnectionId."; | |
| 850 } else if (i < GetPacketNumberOffset(kIncludeVersion, !kIncludePathId)) { | |
| 851 expected_error = "Unable to read protocol version."; | |
| 852 } else { | |
| 853 if (framer_.version() <= QUIC_VERSION_33) { | |
| 854 if (i < GetPrivateFlagsOffset(kIncludeVersion, !kIncludePathId)) { | |
| 855 expected_error = "Unable to read packet number."; | |
| 856 } else { | |
| 857 expected_error = "Unable to read private flags."; | |
| 858 } | |
| 859 } else { | |
| 860 expected_error = "Unable to read packet number."; | |
| 861 } | |
| 862 } | |
| 863 CheckProcessingFails( | |
| 864 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, i, | |
| 865 expected_error, QUIC_INVALID_PACKET_HEADER); | |
| 866 } | |
| 867 } | |
| 868 | |
| 869 TEST_P(QuicFramerTest, PacketHeaderWithMultipathFlag) { | |
| 870 // clang-format off | |
| 871 unsigned char packet[] = { | |
| 872 // public flags (version) | |
| 873 0x78, | |
| 874 // connection_id | |
| 875 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 876 // path_id | |
| 877 0x42, | |
| 878 // packet number | |
| 879 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 880 // private flags | |
| 881 0x00, | |
| 882 }; | |
| 883 unsigned char packet_34[] = { | |
| 884 // public flags (version) | |
| 885 0x78, | |
| 886 // connection_id | |
| 887 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 888 // path_id | |
| 889 0x42, | |
| 890 // packet number | |
| 891 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 892 }; | |
| 893 // clang-format on | |
| 894 | |
| 895 QuicEncryptedPacket encrypted( | |
| 896 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 897 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 898 : arraysize(packet_34), | |
| 899 false); | |
| 900 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | |
| 901 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | |
| 902 ASSERT_TRUE(visitor_.header_.get()); | |
| 903 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, kIncludePathId, | |
| 904 !kIncludeDiversificationNonce)); | |
| 905 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | |
| 906 EXPECT_TRUE(visitor_.header_->public_header.multipath_flag); | |
| 907 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); | |
| 908 EXPECT_FALSE(visitor_.header_->public_header.version_flag); | |
| 909 EXPECT_FALSE(visitor_.header_->fec_flag); | |
| 910 EXPECT_FALSE(visitor_.header_->entropy_flag); | |
| 911 EXPECT_EQ(0, visitor_.header_->entropy_hash); | |
| 912 EXPECT_EQ(kPathId, visitor_.header_->path_id); | |
| 913 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | |
| 914 | |
| 915 // Now test framing boundaries. | |
| 916 for (size_t i = 0; | |
| 917 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 918 !kIncludeVersion, kIncludePathId, | |
| 919 !kIncludeDiversificationNonce, | |
| 920 PACKET_6BYTE_PACKET_NUMBER); | |
| 921 ++i) { | |
| 922 string expected_error; | |
| 923 if (i < kConnectionIdOffset) { | |
| 924 expected_error = "Unable to read public flags."; | |
| 925 } else if (i < | |
| 926 GetPathIdOffset(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion)) { | |
| 927 expected_error = "Unable to read ConnectionId."; | |
| 928 } else if (i < GetPacketNumberOffset(!kIncludeVersion, kIncludePathId)) { | |
| 929 expected_error = "Unable to read path id."; | |
| 930 } else { | |
| 931 if (framer_.version() <= QUIC_VERSION_33) { | |
| 932 if (i < GetPrivateFlagsOffset(!kIncludeVersion, kIncludePathId)) { | |
| 933 expected_error = "Unable to read packet number."; | |
| 934 } else { | |
| 935 expected_error = "Unable to read private flags."; | |
| 936 } | |
| 937 } else { | |
| 938 expected_error = "Unable to read packet number."; | |
| 939 } | |
| 940 } | |
| 941 CheckProcessingFails( | |
| 942 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, i, | |
| 943 expected_error, QUIC_INVALID_PACKET_HEADER); | |
| 944 } | |
| 945 } | |
| 946 | |
| 947 TEST_P(QuicFramerTest, PacketHeaderWithBothVersionFlagAndMultipathFlag) { | |
| 948 // clang-format off | |
| 949 unsigned char packet[] = { | |
| 950 // public flags (version) | |
| 951 0x79, | |
| 952 // connection_id | |
| 953 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 954 // version tag | |
| 955 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | |
| 956 // path_id | |
| 957 0x42, | |
| 958 // packet number | |
| 959 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 960 // private flags | |
| 961 0x00, | |
| 962 }; | |
| 963 unsigned char packet_34[] = { | |
| 964 // public flags (version) | |
| 965 0x79, | |
| 966 // connection_id | |
| 967 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 968 // version tag | |
| 969 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | |
| 970 // path_id | |
| 971 0x42, | |
| 972 // packet number | |
| 973 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 974 }; | |
| 975 // clang-format on | |
| 976 | |
| 977 QuicEncryptedPacket encrypted( | |
| 978 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 979 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 980 : arraysize(packet_34), | |
| 981 false); | |
| 982 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | |
| 983 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | |
| 984 ASSERT_TRUE(visitor_.header_.get()); | |
| 985 EXPECT_TRUE(CheckDecryption(encrypted, kIncludeVersion, kIncludePathId, | |
| 986 !kIncludeDiversificationNonce)); | |
| 987 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | |
| 988 EXPECT_TRUE(visitor_.header_->public_header.multipath_flag); | |
| 989 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); | |
| 990 EXPECT_TRUE(visitor_.header_->public_header.version_flag); | |
| 991 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]); | |
| 992 EXPECT_FALSE(visitor_.header_->fec_flag); | |
| 993 EXPECT_FALSE(visitor_.header_->entropy_flag); | |
| 994 EXPECT_EQ(0, visitor_.header_->entropy_hash); | |
| 995 EXPECT_EQ(kPathId, visitor_.header_->path_id); | |
| 996 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | |
| 997 | |
| 998 // Now test framing boundaries. | |
| 999 for (size_t i = 0; | |
| 1000 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 1001 !kIncludeVersion, kIncludePathId, | |
| 1002 !kIncludeDiversificationNonce, | |
| 1003 PACKET_6BYTE_PACKET_NUMBER); | |
| 1004 ++i) { | |
| 1005 string expected_error; | |
| 1006 if (i < kConnectionIdOffset) { | |
| 1007 expected_error = "Unable to read public flags."; | |
| 1008 } else if (i < kVersionOffset) { | |
| 1009 expected_error = "Unable to read ConnectionId."; | |
| 1010 } else if (i < | |
| 1011 GetPathIdOffset(PACKET_8BYTE_CONNECTION_ID, kIncludeVersion)) { | |
| 1012 expected_error = "Unable to read protocol version."; | |
| 1013 } else if (i < GetPacketNumberOffset(kIncludeVersion, kIncludePathId)) { | |
| 1014 expected_error = "Unable to read path id."; | |
| 1015 } else { | |
| 1016 if (framer_.version() <= QUIC_VERSION_33) { | |
| 1017 if (i < GetPrivateFlagsOffset(kIncludeVersion, kIncludePathId)) { | |
| 1018 expected_error = "Unable to read packet number."; | |
| 1019 } else { | |
| 1020 expected_error = "Unable to read private flags."; | |
| 1021 } | |
| 1022 } else { | |
| 1023 expected_error = "Unable to read packet number."; | |
| 1024 } | |
| 1025 } | |
| 1026 CheckProcessingFails( | |
| 1027 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, i, | |
| 1028 expected_error, QUIC_INVALID_PACKET_HEADER); | |
| 1029 } | |
| 1030 } | |
| 1031 | |
| 1032 TEST_P(QuicFramerTest, PacketHeaderWithPathChange) { | |
| 1033 // Packet 1 from path 0x42. | |
| 1034 // clang-format off | |
| 1035 unsigned char packet1[] = { | |
| 1036 // public flags (version) | |
| 1037 0x78, | |
| 1038 // connection_id | |
| 1039 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 1040 // path_id | |
| 1041 0x42, | |
| 1042 // packet number | |
| 1043 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 1044 // private flags | |
| 1045 0x00, | |
| 1046 }; | |
| 1047 unsigned char packet1_34[] = { | |
| 1048 // public flags (version) | |
| 1049 0x78, | |
| 1050 // connection_id | |
| 1051 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 1052 // path_id | |
| 1053 0x42, | |
| 1054 // packet number | |
| 1055 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 1056 }; | |
| 1057 // clang-format on | |
| 1058 | |
| 1059 EXPECT_EQ(0u, QuicFramerPeer::GetLastPacketNumber(&framer_)); | |
| 1060 EXPECT_EQ(kInvalidPathId, QuicFramerPeer::GetLastPathId(&framer_)); | |
| 1061 QuicEncryptedPacket encrypted1( | |
| 1062 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet1 : packet1_34), | |
| 1063 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet1) | |
| 1064 : arraysize(packet1_34), | |
| 1065 false); | |
| 1066 EXPECT_FALSE(framer_.ProcessPacket(encrypted1)); | |
| 1067 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | |
| 1068 ASSERT_TRUE(visitor_.header_.get()); | |
| 1069 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | |
| 1070 EXPECT_EQ(kPathId, visitor_.header_->path_id); | |
| 1071 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | |
| 1072 EXPECT_EQ(kPacketNumber, QuicFramerPeer::GetLastPacketNumber(&framer_)); | |
| 1073 EXPECT_EQ(kPathId, QuicFramerPeer::GetLastPathId(&framer_)); | |
| 1074 | |
| 1075 // Packet 2 from default path. | |
| 1076 // clang-format off | |
| 1077 unsigned char packet2[] = { | |
| 1078 // public flags (version) | |
| 1079 0x78, | |
| 1080 // connection_id | |
| 1081 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 1082 // path_id | |
| 1083 0x00, | |
| 1084 // packet number | |
| 1085 0xCC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 1086 // private flags | |
| 1087 0x00, | |
| 1088 }; | |
| 1089 unsigned char packet2_34[] = { | |
| 1090 // public flags (version) | |
| 1091 0x78, | |
| 1092 // connection_id | |
| 1093 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 1094 // path_id | |
| 1095 0x00, | |
| 1096 // packet number | |
| 1097 0xCC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 1098 }; | |
| 1099 // clang-format on | |
| 1100 | |
| 1101 QuicEncryptedPacket encrypted2( | |
| 1102 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet2 : packet2_34), | |
| 1103 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet2) | |
| 1104 : arraysize(packet2_34), | |
| 1105 false); | |
| 1106 EXPECT_FALSE(framer_.ProcessPacket(encrypted2)); | |
| 1107 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | |
| 1108 ASSERT_TRUE(visitor_.header_.get()); | |
| 1109 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | |
| 1110 EXPECT_EQ(kDefaultPathId, visitor_.header_->path_id); | |
| 1111 EXPECT_EQ(kPacketNumber + 16, visitor_.header_->packet_number); | |
| 1112 EXPECT_EQ(kPacketNumber + 16, QuicFramerPeer::GetLastPacketNumber(&framer_)); | |
| 1113 EXPECT_EQ(kDefaultPathId, QuicFramerPeer::GetLastPathId(&framer_)); | |
| 1114 | |
| 1115 // Packet 3 from path 0x42. | |
| 1116 // clang-format off | |
| 1117 unsigned char packet3[] = { | |
| 1118 // public flags (version) | |
| 1119 0x78, | |
| 1120 // connection_id | |
| 1121 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 1122 // path_id | |
| 1123 0x42, | |
| 1124 // packet number | |
| 1125 0xBD, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 1126 // private flags | |
| 1127 0x00, | |
| 1128 }; | |
| 1129 unsigned char packet3_34[] = { | |
| 1130 // public flags (version) | |
| 1131 0x78, | |
| 1132 // connection_id | |
| 1133 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 1134 // path_id | |
| 1135 0x42, | |
| 1136 // packet number | |
| 1137 0xBD, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 1138 }; | |
| 1139 // clang-format on | |
| 1140 | |
| 1141 QuicEncryptedPacket encrypted3( | |
| 1142 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet3 : packet3_34), | |
| 1143 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet3) | |
| 1144 : arraysize(packet3_34), | |
| 1145 false); | |
| 1146 EXPECT_FALSE(framer_.ProcessPacket(encrypted3)); | |
| 1147 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | |
| 1148 ASSERT_TRUE(visitor_.header_.get()); | |
| 1149 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | |
| 1150 EXPECT_EQ(kPathId, visitor_.header_->path_id); | |
| 1151 EXPECT_EQ(kPacketNumber + 1, visitor_.header_->packet_number); | |
| 1152 EXPECT_EQ(kPacketNumber + 1, QuicFramerPeer::GetLastPacketNumber(&framer_)); | |
| 1153 EXPECT_EQ(kPathId, QuicFramerPeer::GetLastPathId(&framer_)); | |
| 1154 } | |
| 1155 | |
| 1156 TEST_P(QuicFramerTest, ReceivedPacketOnClosedPath) { | |
| 1157 // Packet 1 from path 0x42. | |
| 1158 // clang-format off | |
| 1159 unsigned char packet[] = { | |
| 1160 // public flags (version) | |
| 1161 0x78, | |
| 1162 // connection_id | |
| 1163 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 1164 // path_id | |
| 1165 0x42, | |
| 1166 // packet number | |
| 1167 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 1168 // private flags | |
| 1169 0x00, | |
| 1170 }; | |
| 1171 unsigned char packet_34[] = { | |
| 1172 // public flags (version) | |
| 1173 0x78, | |
| 1174 // connection_id | |
| 1175 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 1176 // path_id | |
| 1177 0x42, | |
| 1178 // packet number | |
| 1179 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 1180 // private flags | |
| 1181 0x00, | |
| 1182 }; | |
| 1183 // clang-format on | |
| 1184 | |
| 1185 framer_.OnPathClosed(kPathId); | |
| 1186 QuicEncryptedPacket encrypted( | |
| 1187 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 1188 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 1189 : arraysize(packet_34), | |
| 1190 false); | |
| 1191 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | |
| 1192 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 1193 EXPECT_EQ(0u, QuicFramerPeer::GetLastPacketNumber(&framer_)); | |
| 1194 EXPECT_EQ(kInvalidPathId, QuicFramerPeer::GetLastPathId(&framer_)); | |
| 1195 } | |
| 1196 | |
| 1197 TEST_P(QuicFramerTest, PacketHeaderWith4BytePacketNumber) { | |
| 1198 QuicFramerPeer::SetLastPacketNumber(&framer_, kPacketNumber - 2); | |
| 1199 | |
| 1200 // clang-format off | |
| 1201 unsigned char packet[] = { | |
| 1202 // public flags (8 byte connection_id and 4 byte packet number) | |
| 1203 0x28, | |
| 1204 // connection_id | |
| 1205 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 1206 // packet number | |
| 1207 0xBC, 0x9A, 0x78, 0x56, | |
| 1208 // private flags | |
| 1209 0x00, | |
| 1210 }; | |
| 1211 unsigned char packet_34[] = { | |
| 1212 // public flags (8 byte connection_id and 4 byte packet number) | |
| 1213 0x28, | |
| 1214 // connection_id | |
| 1215 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 1216 // packet number | |
| 1217 0xBC, 0x9A, 0x78, 0x56, | |
| 1218 }; | |
| 1219 // clang-format on | |
| 1220 | |
| 1221 QuicEncryptedPacket encrypted( | |
| 1222 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 1223 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 1224 : arraysize(packet_34), | |
| 1225 false); | |
| 1226 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | |
| 1227 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | |
| 1228 ASSERT_TRUE(visitor_.header_.get()); | |
| 1229 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | |
| 1230 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); | |
| 1231 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); | |
| 1232 EXPECT_FALSE(visitor_.header_->public_header.version_flag); | |
| 1233 EXPECT_FALSE(visitor_.header_->fec_flag); | |
| 1234 EXPECT_FALSE(visitor_.header_->entropy_flag); | |
| 1235 EXPECT_EQ(0, visitor_.header_->entropy_hash); | |
| 1236 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | |
| 1237 | |
| 1238 // Now test framing boundaries. | |
| 1239 for (size_t i = 0; | |
| 1240 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 1241 !kIncludeVersion, !kIncludePathId, | |
| 1242 !kIncludeDiversificationNonce, | |
| 1243 PACKET_4BYTE_PACKET_NUMBER); | |
| 1244 ++i) { | |
| 1245 string expected_error; | |
| 1246 if (i < kConnectionIdOffset) { | |
| 1247 expected_error = "Unable to read public flags."; | |
| 1248 } else if (i < GetPacketNumberOffset(!kIncludeVersion, !kIncludePathId)) { | |
| 1249 expected_error = "Unable to read ConnectionId."; | |
| 1250 } else { | |
| 1251 if (framer_.version() <= QUIC_VERSION_33) { | |
| 1252 if (i < GetPrivateFlagsOffset(!kIncludeVersion, !kIncludePathId, | |
| 1253 PACKET_4BYTE_PACKET_NUMBER)) { | |
| 1254 expected_error = "Unable to read packet number."; | |
| 1255 } else { | |
| 1256 expected_error = "Unable to read private flags."; | |
| 1257 } | |
| 1258 } else { | |
| 1259 expected_error = "Unable to read packet number."; | |
| 1260 } | |
| 1261 } | |
| 1262 CheckProcessingFails( | |
| 1263 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, i, | |
| 1264 expected_error, QUIC_INVALID_PACKET_HEADER); | |
| 1265 } | |
| 1266 } | |
| 1267 | |
| 1268 TEST_P(QuicFramerTest, PacketHeaderWith2BytePacketNumber) { | |
| 1269 QuicFramerPeer::SetLastPacketNumber(&framer_, kPacketNumber - 2); | |
| 1270 | |
| 1271 // clang-format off | |
| 1272 unsigned char packet[] = { | |
| 1273 // public flags (8 byte connection_id and 2 byte packet number) | |
| 1274 0x18, | |
| 1275 // connection_id | |
| 1276 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 1277 // packet number | |
| 1278 0xBC, 0x9A, | |
| 1279 // private flags | |
| 1280 0x00, | |
| 1281 }; | |
| 1282 unsigned char packet_34[] = { | |
| 1283 // public flags (8 byte connection_id and 2 byte packet number) | |
| 1284 0x18, | |
| 1285 // connection_id | |
| 1286 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 1287 // packet number | |
| 1288 0xBC, 0x9A, | |
| 1289 }; | |
| 1290 // clang-format on | |
| 1291 | |
| 1292 QuicEncryptedPacket encrypted( | |
| 1293 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 1294 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 1295 : arraysize(packet_34), | |
| 1296 false); | |
| 1297 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | |
| 1298 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | |
| 1299 ASSERT_TRUE(visitor_.header_.get()); | |
| 1300 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | |
| 1301 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); | |
| 1302 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); | |
| 1303 EXPECT_FALSE(visitor_.header_->public_header.version_flag); | |
| 1304 EXPECT_FALSE(visitor_.header_->fec_flag); | |
| 1305 EXPECT_FALSE(visitor_.header_->entropy_flag); | |
| 1306 EXPECT_EQ(0, visitor_.header_->entropy_hash); | |
| 1307 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | |
| 1308 | |
| 1309 // Now test framing boundaries. | |
| 1310 for (size_t i = 0; | |
| 1311 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 1312 !kIncludeVersion, !kIncludePathId, | |
| 1313 !kIncludeDiversificationNonce, | |
| 1314 PACKET_2BYTE_PACKET_NUMBER); | |
| 1315 ++i) { | |
| 1316 string expected_error; | |
| 1317 if (i < kConnectionIdOffset) { | |
| 1318 expected_error = "Unable to read public flags."; | |
| 1319 } else if (i < GetPacketNumberOffset(!kIncludeVersion, !kIncludePathId)) { | |
| 1320 expected_error = "Unable to read ConnectionId."; | |
| 1321 } else { | |
| 1322 if (framer_.version() <= QUIC_VERSION_33) { | |
| 1323 if (i < GetPrivateFlagsOffset(!kIncludeVersion, !kIncludePathId, | |
| 1324 PACKET_2BYTE_PACKET_NUMBER)) { | |
| 1325 expected_error = "Unable to read packet number."; | |
| 1326 } else { | |
| 1327 expected_error = "Unable to read private flags."; | |
| 1328 } | |
| 1329 } else { | |
| 1330 expected_error = "Unable to read packet number."; | |
| 1331 } | |
| 1332 } | |
| 1333 CheckProcessingFails( | |
| 1334 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, i, | |
| 1335 expected_error, QUIC_INVALID_PACKET_HEADER); | |
| 1336 } | |
| 1337 } | |
| 1338 | |
| 1339 TEST_P(QuicFramerTest, PacketHeaderWith1BytePacketNumber) { | |
| 1340 QuicFramerPeer::SetLastPacketNumber(&framer_, kPacketNumber - 2); | |
| 1341 | |
| 1342 // clang-format off | |
| 1343 unsigned char packet[] = { | |
| 1344 // public flags (8 byte connection_id and 1 byte packet number) | |
| 1345 0x08, | |
| 1346 // connection_id | |
| 1347 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 1348 // packet number | |
| 1349 0xBC, | |
| 1350 // private flags | |
| 1351 0x00, | |
| 1352 }; | |
| 1353 unsigned char packet_34[] = { | |
| 1354 // public flags (8 byte connection_id and 1 byte packet number) | |
| 1355 0x08, | |
| 1356 // connection_id | |
| 1357 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 1358 // packet number | |
| 1359 0xBC, | |
| 1360 }; | |
| 1361 // clang-format on | |
| 1362 | |
| 1363 QuicEncryptedPacket encrypted( | |
| 1364 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 1365 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 1366 : arraysize(packet_34), | |
| 1367 false); | |
| 1368 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | |
| 1369 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | |
| 1370 ASSERT_TRUE(visitor_.header_.get()); | |
| 1371 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | |
| 1372 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); | |
| 1373 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); | |
| 1374 EXPECT_FALSE(visitor_.header_->public_header.version_flag); | |
| 1375 EXPECT_FALSE(visitor_.header_->fec_flag); | |
| 1376 EXPECT_FALSE(visitor_.header_->entropy_flag); | |
| 1377 EXPECT_EQ(0, visitor_.header_->entropy_hash); | |
| 1378 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | |
| 1379 | |
| 1380 // Now test framing boundaries. | |
| 1381 for (size_t i = 0; | |
| 1382 i < GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 1383 !kIncludeVersion, !kIncludePathId, | |
| 1384 !kIncludeDiversificationNonce, | |
| 1385 PACKET_1BYTE_PACKET_NUMBER); | |
| 1386 ++i) { | |
| 1387 string expected_error; | |
| 1388 if (i < kConnectionIdOffset) { | |
| 1389 expected_error = "Unable to read public flags."; | |
| 1390 } else if (i < GetPacketNumberOffset(!kIncludeVersion, !kIncludePathId)) { | |
| 1391 expected_error = "Unable to read ConnectionId."; | |
| 1392 } else { | |
| 1393 if (framer_.version() <= QUIC_VERSION_33) { | |
| 1394 if (i < GetPrivateFlagsOffset(!kIncludeVersion, !kIncludePathId, | |
| 1395 PACKET_1BYTE_PACKET_NUMBER)) { | |
| 1396 expected_error = "Unable to read packet number."; | |
| 1397 } else { | |
| 1398 expected_error = "Unable to read private flags."; | |
| 1399 } | |
| 1400 } else { | |
| 1401 expected_error = "Unable to read packet number."; | |
| 1402 } | |
| 1403 } | |
| 1404 CheckProcessingFails( | |
| 1405 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, i, | |
| 1406 expected_error, QUIC_INVALID_PACKET_HEADER); | |
| 1407 } | |
| 1408 } | |
| 1409 | |
| 1410 TEST_P(QuicFramerTest, InvalidPublicFlag) { | |
| 1411 if (framer_.version() > QUIC_VERSION_33) { | |
| 1412 return; | |
| 1413 } | |
| 1414 // clang-format off | |
| 1415 unsigned char packet[] = { | |
| 1416 // public flags: all flags set but the public reset flag and version flag. | |
| 1417 0xF8, | |
| 1418 // connection_id | |
| 1419 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 1420 // packet number | |
| 1421 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 1422 // private flags | |
| 1423 0x00, | |
| 1424 | |
| 1425 // frame type (padding) | |
| 1426 0x00, | |
| 1427 0x00, 0x00, 0x00, 0x00 | |
| 1428 }; | |
| 1429 // clang-format on | |
| 1430 | |
| 1431 CheckProcessingFails(packet, arraysize(packet), "Illegal public flags value.", | |
| 1432 QUIC_INVALID_PACKET_HEADER); | |
| 1433 | |
| 1434 // Now turn off validation. | |
| 1435 framer_.set_validate_flags(false); | |
| 1436 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 1437 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 1438 }; | |
| 1439 | |
| 1440 TEST_P(QuicFramerTest, PacketWithDiversificationNonce) { | |
| 1441 // clang-format off | |
| 1442 unsigned char packet[] = { | |
| 1443 // public flags: includes nonce flag | |
| 1444 0x7C, | |
| 1445 // connection_id | |
| 1446 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 1447 // nonce | |
| 1448 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
| 1449 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | |
| 1450 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | |
| 1451 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, | |
| 1452 // packet number | |
| 1453 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 1454 // private flags | |
| 1455 0x00, | |
| 1456 | |
| 1457 // frame type (padding) | |
| 1458 0x00, | |
| 1459 0x00, 0x00, 0x00, 0x00 | |
| 1460 }; | |
| 1461 unsigned char packet_34[] = { | |
| 1462 // public flags: includes nonce flag | |
| 1463 0x7C, | |
| 1464 // connection_id | |
| 1465 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 1466 // nonce | |
| 1467 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
| 1468 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | |
| 1469 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | |
| 1470 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, | |
| 1471 // packet number | |
| 1472 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 1473 | |
| 1474 // frame type (padding) | |
| 1475 0x00, | |
| 1476 0x00, 0x00, 0x00, 0x00 | |
| 1477 }; | |
| 1478 // clang-format on | |
| 1479 | |
| 1480 QuicEncryptedPacket encrypted( | |
| 1481 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 1482 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 1483 : arraysize(packet_34), | |
| 1484 false); | |
| 1485 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); | |
| 1486 if (framer_.version() > QUIC_VERSION_32) { | |
| 1487 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 1488 ASSERT_TRUE(visitor_.public_header_->nonce != nullptr); | |
| 1489 for (char i = 0; i < 32; ++i) { | |
| 1490 EXPECT_EQ(i, (*visitor_.public_header_->nonce)[static_cast<int>(i)]); | |
| 1491 } | |
| 1492 } else if (framer_.version() < QUIC_VERSION_32) { | |
| 1493 // Packet is successfully parsed by accident. | |
| 1494 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 1495 ASSERT_TRUE(visitor_.public_header_ != nullptr); | |
| 1496 } else { | |
| 1497 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | |
| 1498 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); | |
| 1499 EXPECT_EQ("Illegal private flags value.", framer_.detailed_error()); | |
| 1500 } | |
| 1501 }; | |
| 1502 | |
| 1503 TEST_P(QuicFramerTest, InvalidPublicFlagWithMatchingVersions) { | |
| 1504 if (framer_.version() > QUIC_VERSION_33) { | |
| 1505 return; | |
| 1506 } | |
| 1507 // clang-format off | |
| 1508 unsigned char packet[] = { | |
| 1509 // public flags (8 byte connection_id and version flag and an unknown flag) | |
| 1510 0x8D, | |
| 1511 // connection_id | |
| 1512 0x10, 0x32, 0x54, 0x76, | |
| 1513 0x98, 0xBA, 0xDC, 0xFE, | |
| 1514 // version tag | |
| 1515 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | |
| 1516 // packet number | |
| 1517 0xBC, 0x9A, 0x78, 0x56, | |
| 1518 0x34, 0x12, | |
| 1519 // private flags | |
| 1520 0x00, | |
| 1521 | |
| 1522 // frame type (padding) | |
| 1523 0x00, | |
| 1524 0x00, 0x00, 0x00, 0x00 | |
| 1525 }; | |
| 1526 // clang-format on | |
| 1527 CheckProcessingFails(packet, arraysize(packet), "Illegal public flags value.", | |
| 1528 QUIC_INVALID_PACKET_HEADER); | |
| 1529 }; | |
| 1530 | |
| 1531 TEST_P(QuicFramerTest, LargePublicFlagWithMismatchedVersions) { | |
| 1532 // clang-format off | |
| 1533 unsigned char packet[] = { | |
| 1534 // public flags (8 byte connection_id, version flag and an unknown flag) | |
| 1535 0x79, | |
| 1536 // connection_id | |
| 1537 0x10, 0x32, 0x54, 0x76, | |
| 1538 0x98, 0xBA, 0xDC, 0xFE, | |
| 1539 // version tag | |
| 1540 'Q', '0', '0', '0', | |
| 1541 // packet number | |
| 1542 0xBC, 0x9A, 0x78, 0x56, | |
| 1543 0x34, 0x12, | |
| 1544 // private flags | |
| 1545 0x00, | |
| 1546 | |
| 1547 // frame type (padding frame) | |
| 1548 0x00, | |
| 1549 0x00, 0x00, 0x00, 0x00 | |
| 1550 }; | |
| 1551 unsigned char packet_34[] = { | |
| 1552 // public flags (8 byte connection_id, version flag and an unknown flag) | |
| 1553 0x79, | |
| 1554 // connection_id | |
| 1555 0x10, 0x32, 0x54, 0x76, | |
| 1556 0x98, 0xBA, 0xDC, 0xFE, | |
| 1557 // version tag | |
| 1558 'Q', '0', '0', '0', | |
| 1559 // packet number | |
| 1560 0xBC, 0x9A, 0x78, 0x56, | |
| 1561 0x34, 0x12, | |
| 1562 | |
| 1563 // frame type (padding frame) | |
| 1564 0x00, | |
| 1565 0x00, 0x00, 0x00, 0x00 | |
| 1566 }; | |
| 1567 // clang-format on | |
| 1568 QuicEncryptedPacket encrypted( | |
| 1569 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 1570 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 1571 : arraysize(packet_34), | |
| 1572 false); | |
| 1573 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 1574 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 1575 ASSERT_TRUE(visitor_.header_.get()); | |
| 1576 EXPECT_EQ(0, visitor_.frame_count_); | |
| 1577 EXPECT_EQ(1, visitor_.version_mismatch_); | |
| 1578 }; | |
| 1579 | |
| 1580 TEST_P(QuicFramerTest, InvalidPrivateFlag) { | |
| 1581 if (framer_.version() > QUIC_VERSION_33) { | |
| 1582 return; | |
| 1583 } | |
| 1584 // clang-format off | |
| 1585 unsigned char packet[] = { | |
| 1586 // public flags (8 byte connection_id) | |
| 1587 0x38, | |
| 1588 // connection_id | |
| 1589 0x10, 0x32, 0x54, 0x76, | |
| 1590 0x98, 0xBA, 0xDC, 0xFE, | |
| 1591 // packet number | |
| 1592 0xBC, 0x9A, 0x78, 0x56, | |
| 1593 0x34, 0x12, | |
| 1594 // private flags | |
| 1595 0x10, | |
| 1596 | |
| 1597 // frame type (padding) | |
| 1598 0x00, | |
| 1599 0x00, 0x00, 0x00, 0x00 | |
| 1600 }; | |
| 1601 // clang-format on | |
| 1602 CheckProcessingFails(packet, arraysize(packet), | |
| 1603 "Illegal private flags value.", | |
| 1604 QUIC_INVALID_PACKET_HEADER); | |
| 1605 }; | |
| 1606 | |
| 1607 TEST_P(QuicFramerTest, InvalidFECGroupOffset) { | |
| 1608 if (framer_.version() > QUIC_VERSION_33) { | |
| 1609 return; | |
| 1610 } | |
| 1611 // clang-format off | |
| 1612 unsigned char packet[] = { | |
| 1613 // public flags (8 byte connection_id) | |
| 1614 0x38, | |
| 1615 // connection_id | |
| 1616 0x10, 0x32, 0x54, 0x76, | |
| 1617 0x98, 0xBA, 0xDC, 0xFE, | |
| 1618 // packet number | |
| 1619 0x01, 0x00, 0x00, 0x00, | |
| 1620 0x00, 0x00, | |
| 1621 // private flags (fec group) | |
| 1622 0x02, | |
| 1623 // first fec protected packet offset | |
| 1624 0x10 | |
| 1625 }; | |
| 1626 // clang-format on | |
| 1627 if (framer_.version() > QUIC_VERSION_31) { | |
| 1628 CheckProcessingFails(packet, arraysize(packet), | |
| 1629 "Illegal private flags value.", | |
| 1630 QUIC_INVALID_PACKET_HEADER); | |
| 1631 } else { | |
| 1632 CheckProcessingFails(packet, arraysize(packet), | |
| 1633 "First fec protected packet offset must be less " | |
| 1634 "than the packet number.", | |
| 1635 QUIC_INVALID_PACKET_HEADER); | |
| 1636 } | |
| 1637 }; | |
| 1638 | |
| 1639 TEST_P(QuicFramerTest, PaddingFrame) { | |
| 1640 // clang-format off | |
| 1641 unsigned char packet[] = { | |
| 1642 // public flags (8 byte connection_id) | |
| 1643 0x38, | |
| 1644 // connection_id | |
| 1645 0x10, 0x32, 0x54, 0x76, | |
| 1646 0x98, 0xBA, 0xDC, 0xFE, | |
| 1647 // packet number | |
| 1648 0xBC, 0x9A, 0x78, 0x56, | |
| 1649 0x34, 0x12, | |
| 1650 // private flags | |
| 1651 0x00, | |
| 1652 | |
| 1653 // frame type (padding frame) | |
| 1654 0x00, | |
| 1655 // Ignored data (which in this case is a stream frame) | |
| 1656 // frame type (stream frame with fin) | |
| 1657 0xFF, | |
| 1658 // stream id | |
| 1659 0x04, 0x03, 0x02, 0x01, | |
| 1660 // offset | |
| 1661 0x54, 0x76, 0x10, 0x32, | |
| 1662 0xDC, 0xFE, 0x98, 0xBA, | |
| 1663 // data length | |
| 1664 0x0c, 0x00, | |
| 1665 // data | |
| 1666 'h', 'e', 'l', 'l', | |
| 1667 'o', ' ', 'w', 'o', | |
| 1668 'r', 'l', 'd', '!', | |
| 1669 }; | |
| 1670 unsigned char packet_34[] = { | |
| 1671 // public flags (8 byte connection_id) | |
| 1672 0x38, | |
| 1673 // connection_id | |
| 1674 0x10, 0x32, 0x54, 0x76, | |
| 1675 0x98, 0xBA, 0xDC, 0xFE, | |
| 1676 // packet number | |
| 1677 0xBC, 0x9A, 0x78, 0x56, | |
| 1678 0x34, 0x12, | |
| 1679 | |
| 1680 // frame type (padding frame) | |
| 1681 0x00, | |
| 1682 // Ignored data (which in this case is a stream frame) | |
| 1683 // frame type (stream frame with fin) | |
| 1684 0xFF, | |
| 1685 // stream id | |
| 1686 0x04, 0x03, 0x02, 0x01, | |
| 1687 // offset | |
| 1688 0x54, 0x76, 0x10, 0x32, | |
| 1689 0xDC, 0xFE, 0x98, 0xBA, | |
| 1690 // data length | |
| 1691 0x0c, 0x00, | |
| 1692 // data | |
| 1693 'h', 'e', 'l', 'l', | |
| 1694 'o', ' ', 'w', 'o', | |
| 1695 'r', 'l', 'd', '!', | |
| 1696 }; | |
| 1697 // clang-format on | |
| 1698 | |
| 1699 QuicEncryptedPacket encrypted( | |
| 1700 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 1701 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 1702 : arraysize(packet_34), | |
| 1703 false); | |
| 1704 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 1705 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 1706 ASSERT_TRUE(visitor_.header_.get()); | |
| 1707 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 1708 !kIncludeDiversificationNonce)); | |
| 1709 | |
| 1710 ASSERT_EQ(0u, visitor_.stream_frames_.size()); | |
| 1711 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | |
| 1712 // A packet with no frames is not acceptable. | |
| 1713 CheckProcessingFails( | |
| 1714 packet, GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 1715 !kIncludeVersion, !kIncludePathId, | |
| 1716 !kIncludeDiversificationNonce, | |
| 1717 PACKET_6BYTE_PACKET_NUMBER), | |
| 1718 "Packet has no frames.", QUIC_MISSING_PAYLOAD); | |
| 1719 } | |
| 1720 | |
| 1721 TEST_P(QuicFramerTest, StreamFrame) { | |
| 1722 // clang-format off | |
| 1723 unsigned char packet[] = { | |
| 1724 // public flags (8 byte connection_id) | |
| 1725 0x38, | |
| 1726 // connection_id | |
| 1727 0x10, 0x32, 0x54, 0x76, | |
| 1728 0x98, 0xBA, 0xDC, 0xFE, | |
| 1729 // packet number | |
| 1730 0xBC, 0x9A, 0x78, 0x56, | |
| 1731 0x34, 0x12, | |
| 1732 // private flags | |
| 1733 0x00, | |
| 1734 | |
| 1735 // frame type (stream frame with fin) | |
| 1736 0xFF, | |
| 1737 // stream id | |
| 1738 0x04, 0x03, 0x02, 0x01, | |
| 1739 // offset | |
| 1740 0x54, 0x76, 0x10, 0x32, | |
| 1741 0xDC, 0xFE, 0x98, 0xBA, | |
| 1742 // data length | |
| 1743 0x0c, 0x00, | |
| 1744 // data | |
| 1745 'h', 'e', 'l', 'l', | |
| 1746 'o', ' ', 'w', 'o', | |
| 1747 'r', 'l', 'd', '!', | |
| 1748 }; | |
| 1749 unsigned char packet_34[] = { | |
| 1750 // public flags (8 byte connection_id) | |
| 1751 0x38, | |
| 1752 // connection_id | |
| 1753 0x10, 0x32, 0x54, 0x76, | |
| 1754 0x98, 0xBA, 0xDC, 0xFE, | |
| 1755 // packet number | |
| 1756 0xBC, 0x9A, 0x78, 0x56, | |
| 1757 0x34, 0x12, | |
| 1758 | |
| 1759 // frame type (stream frame with fin) | |
| 1760 0xFF, | |
| 1761 // stream id | |
| 1762 0x04, 0x03, 0x02, 0x01, | |
| 1763 // offset | |
| 1764 0x54, 0x76, 0x10, 0x32, | |
| 1765 0xDC, 0xFE, 0x98, 0xBA, | |
| 1766 // data length | |
| 1767 0x0c, 0x00, | |
| 1768 // data | |
| 1769 'h', 'e', 'l', 'l', | |
| 1770 'o', ' ', 'w', 'o', | |
| 1771 'r', 'l', 'd', '!', | |
| 1772 }; | |
| 1773 // clang-format on | |
| 1774 | |
| 1775 QuicEncryptedPacket encrypted( | |
| 1776 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 1777 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 1778 : arraysize(packet_34), | |
| 1779 false); | |
| 1780 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 1781 | |
| 1782 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 1783 ASSERT_TRUE(visitor_.header_.get()); | |
| 1784 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 1785 !kIncludeDiversificationNonce)); | |
| 1786 | |
| 1787 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | |
| 1788 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | |
| 1789 EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); | |
| 1790 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); | |
| 1791 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); | |
| 1792 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); | |
| 1793 | |
| 1794 // Now test framing boundaries. | |
| 1795 CheckStreamFrameBoundaries( | |
| 1796 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, | |
| 1797 kQuicMaxStreamIdSize, !kIncludeVersion); | |
| 1798 } | |
| 1799 | |
| 1800 TEST_P(QuicFramerTest, MissingDiversificationNonce) { | |
| 1801 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); | |
| 1802 framer_.SetDecrypter(ENCRYPTION_NONE, new NullDecrypter()); | |
| 1803 decrypter_ = new test::TestDecrypter(); | |
| 1804 framer_.SetAlternativeDecrypter(ENCRYPTION_INITIAL, decrypter_, false); | |
| 1805 | |
| 1806 // clang-format off | |
| 1807 unsigned char packet[] = { | |
| 1808 // public flags (8 byte connection_id) | |
| 1809 0x38, | |
| 1810 // connection_id | |
| 1811 0x10, 0x32, 0x54, 0x76, | |
| 1812 0x98, 0xBA, 0xDC, 0xFE, | |
| 1813 // packet number | |
| 1814 0xBC, 0x9A, 0x78, 0x56, | |
| 1815 0x34, 0x12, | |
| 1816 // private flags | |
| 1817 0x00, | |
| 1818 | |
| 1819 // frame type (stream frame with fin) | |
| 1820 0xFF, | |
| 1821 // stream id | |
| 1822 0x04, 0x03, 0x02, 0x01, | |
| 1823 // offset | |
| 1824 0x54, 0x76, 0x10, 0x32, | |
| 1825 0xDC, 0xFE, 0x98, 0xBA, | |
| 1826 // data length | |
| 1827 0x0c, 0x00, | |
| 1828 // data | |
| 1829 'h', 'e', 'l', 'l', | |
| 1830 'o', ' ', 'w', 'o', | |
| 1831 'r', 'l', 'd', '!', | |
| 1832 }; | |
| 1833 unsigned char packet_34[] = { | |
| 1834 // public flags (8 byte connection_id) | |
| 1835 0x38, | |
| 1836 // connection_id | |
| 1837 0x10, 0x32, 0x54, 0x76, | |
| 1838 0x98, 0xBA, 0xDC, 0xFE, | |
| 1839 // packet number | |
| 1840 0xBC, 0x9A, 0x78, 0x56, | |
| 1841 0x34, 0x12, | |
| 1842 | |
| 1843 // frame type (stream frame with fin) | |
| 1844 0xFF, | |
| 1845 // stream id | |
| 1846 0x04, 0x03, 0x02, 0x01, | |
| 1847 // offset | |
| 1848 0x54, 0x76, 0x10, 0x32, | |
| 1849 0xDC, 0xFE, 0x98, 0xBA, | |
| 1850 // data length | |
| 1851 0x0c, 0x00, | |
| 1852 // data | |
| 1853 'h', 'e', 'l', 'l', | |
| 1854 'o', ' ', 'w', 'o', | |
| 1855 'r', 'l', 'd', '!', | |
| 1856 }; | |
| 1857 // clang-format on | |
| 1858 | |
| 1859 QuicEncryptedPacket encrypted( | |
| 1860 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 1861 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 1862 : arraysize(packet_34), | |
| 1863 false); | |
| 1864 if (framer_.version() > QUIC_VERSION_32) { | |
| 1865 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | |
| 1866 EXPECT_EQ(QUIC_DECRYPTION_FAILURE, framer_.error()); | |
| 1867 | |
| 1868 } else { | |
| 1869 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 1870 | |
| 1871 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 1872 ASSERT_TRUE(visitor_.header_.get()); | |
| 1873 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 1874 !kIncludeDiversificationNonce)); | |
| 1875 } | |
| 1876 } | |
| 1877 | |
| 1878 TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) { | |
| 1879 // clang-format off | |
| 1880 unsigned char packet[] = { | |
| 1881 // public flags (8 byte connection_id) | |
| 1882 0x38, | |
| 1883 // connection_id | |
| 1884 0x10, 0x32, 0x54, 0x76, | |
| 1885 0x98, 0xBA, 0xDC, 0xFE, | |
| 1886 // packet number | |
| 1887 0xBC, 0x9A, 0x78, 0x56, | |
| 1888 0x34, 0x12, | |
| 1889 // private flags | |
| 1890 0x00, | |
| 1891 | |
| 1892 // frame type (stream frame with fin) | |
| 1893 0xFE, | |
| 1894 // stream id | |
| 1895 0x04, 0x03, 0x02, | |
| 1896 // offset | |
| 1897 0x54, 0x76, 0x10, 0x32, | |
| 1898 0xDC, 0xFE, 0x98, 0xBA, | |
| 1899 // data length | |
| 1900 0x0c, 0x00, | |
| 1901 // data | |
| 1902 'h', 'e', 'l', 'l', | |
| 1903 'o', ' ', 'w', 'o', | |
| 1904 'r', 'l', 'd', '!', | |
| 1905 }; | |
| 1906 unsigned char packet_34[] = { | |
| 1907 // public flags (8 byte connection_id) | |
| 1908 0x38, | |
| 1909 // connection_id | |
| 1910 0x10, 0x32, 0x54, 0x76, | |
| 1911 0x98, 0xBA, 0xDC, 0xFE, | |
| 1912 // packet number | |
| 1913 0xBC, 0x9A, 0x78, 0x56, | |
| 1914 0x34, 0x12, | |
| 1915 | |
| 1916 // frame type (stream frame with fin) | |
| 1917 0xFE, | |
| 1918 // stream id | |
| 1919 0x04, 0x03, 0x02, | |
| 1920 // offset | |
| 1921 0x54, 0x76, 0x10, 0x32, | |
| 1922 0xDC, 0xFE, 0x98, 0xBA, | |
| 1923 // data length | |
| 1924 0x0c, 0x00, | |
| 1925 // data | |
| 1926 'h', 'e', 'l', 'l', | |
| 1927 'o', ' ', 'w', 'o', | |
| 1928 'r', 'l', 'd', '!', | |
| 1929 }; | |
| 1930 // clang-format on | |
| 1931 | |
| 1932 QuicEncryptedPacket encrypted( | |
| 1933 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 1934 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 1935 : arraysize(packet_34), | |
| 1936 false); | |
| 1937 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 1938 | |
| 1939 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 1940 ASSERT_TRUE(visitor_.header_.get()); | |
| 1941 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 1942 !kIncludeDiversificationNonce)); | |
| 1943 | |
| 1944 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | |
| 1945 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | |
| 1946 // Stream ID should be the last 3 bytes of kStreamId. | |
| 1947 EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); | |
| 1948 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); | |
| 1949 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); | |
| 1950 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); | |
| 1951 | |
| 1952 // Now test framing boundaries. | |
| 1953 const size_t stream_id_size = 3; | |
| 1954 CheckStreamFrameBoundaries( | |
| 1955 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, stream_id_size, | |
| 1956 !kIncludeVersion); | |
| 1957 } | |
| 1958 | |
| 1959 TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) { | |
| 1960 // clang-format off | |
| 1961 unsigned char packet[] = { | |
| 1962 // public flags (8 byte connection_id) | |
| 1963 0x38, | |
| 1964 // connection_id | |
| 1965 0x10, 0x32, 0x54, 0x76, | |
| 1966 0x98, 0xBA, 0xDC, 0xFE, | |
| 1967 // packet number | |
| 1968 0xBC, 0x9A, 0x78, 0x56, | |
| 1969 0x34, 0x12, | |
| 1970 // private flags | |
| 1971 0x00, | |
| 1972 | |
| 1973 // frame type (stream frame with fin) | |
| 1974 0xFD, | |
| 1975 // stream id | |
| 1976 0x04, 0x03, | |
| 1977 // offset | |
| 1978 0x54, 0x76, 0x10, 0x32, | |
| 1979 0xDC, 0xFE, 0x98, 0xBA, | |
| 1980 // data length | |
| 1981 0x0c, 0x00, | |
| 1982 // data | |
| 1983 'h', 'e', 'l', 'l', | |
| 1984 'o', ' ', 'w', 'o', | |
| 1985 'r', 'l', 'd', '!', | |
| 1986 }; | |
| 1987 unsigned char packet_34[] = { | |
| 1988 // public flags (8 byte connection_id) | |
| 1989 0x38, | |
| 1990 // connection_id | |
| 1991 0x10, 0x32, 0x54, 0x76, | |
| 1992 0x98, 0xBA, 0xDC, 0xFE, | |
| 1993 // packet number | |
| 1994 0xBC, 0x9A, 0x78, 0x56, | |
| 1995 0x34, 0x12, | |
| 1996 | |
| 1997 // frame type (stream frame with fin) | |
| 1998 0xFD, | |
| 1999 // stream id | |
| 2000 0x04, 0x03, | |
| 2001 // offset | |
| 2002 0x54, 0x76, 0x10, 0x32, | |
| 2003 0xDC, 0xFE, 0x98, 0xBA, | |
| 2004 // data length | |
| 2005 0x0c, 0x00, | |
| 2006 // data | |
| 2007 'h', 'e', 'l', 'l', | |
| 2008 'o', ' ', 'w', 'o', | |
| 2009 'r', 'l', 'd', '!', | |
| 2010 }; | |
| 2011 // clang-format on | |
| 2012 | |
| 2013 QuicEncryptedPacket encrypted( | |
| 2014 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 2015 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 2016 : arraysize(packet_34), | |
| 2017 false); | |
| 2018 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 2019 | |
| 2020 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 2021 ASSERT_TRUE(visitor_.header_.get()); | |
| 2022 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 2023 !kIncludeDiversificationNonce)); | |
| 2024 | |
| 2025 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | |
| 2026 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | |
| 2027 // Stream ID should be the last 2 bytes of kStreamId. | |
| 2028 EXPECT_EQ(0x0000FFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); | |
| 2029 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); | |
| 2030 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); | |
| 2031 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); | |
| 2032 | |
| 2033 // Now test framing boundaries. | |
| 2034 const size_t stream_id_size = 2; | |
| 2035 CheckStreamFrameBoundaries( | |
| 2036 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, stream_id_size, | |
| 2037 !kIncludeVersion); | |
| 2038 } | |
| 2039 | |
| 2040 TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) { | |
| 2041 // clang-format off | |
| 2042 unsigned char packet[] = { | |
| 2043 // public flags (8 byte connection_id) | |
| 2044 0x38, | |
| 2045 // connection_id | |
| 2046 0x10, 0x32, 0x54, 0x76, | |
| 2047 0x98, 0xBA, 0xDC, 0xFE, | |
| 2048 // packet number | |
| 2049 0xBC, 0x9A, 0x78, 0x56, | |
| 2050 0x34, 0x12, | |
| 2051 // private flags | |
| 2052 0x00, | |
| 2053 | |
| 2054 // frame type (stream frame with fin) | |
| 2055 0xFC, | |
| 2056 // stream id | |
| 2057 0x04, | |
| 2058 // offset | |
| 2059 0x54, 0x76, 0x10, 0x32, | |
| 2060 0xDC, 0xFE, 0x98, 0xBA, | |
| 2061 // data length | |
| 2062 0x0c, 0x00, | |
| 2063 // data | |
| 2064 'h', 'e', 'l', 'l', | |
| 2065 'o', ' ', 'w', 'o', | |
| 2066 'r', 'l', 'd', '!', | |
| 2067 }; | |
| 2068 unsigned char packet_34[] = { | |
| 2069 // public flags (8 byte connection_id) | |
| 2070 0x38, | |
| 2071 // connection_id | |
| 2072 0x10, 0x32, 0x54, 0x76, | |
| 2073 0x98, 0xBA, 0xDC, 0xFE, | |
| 2074 // packet number | |
| 2075 0xBC, 0x9A, 0x78, 0x56, | |
| 2076 0x34, 0x12, | |
| 2077 | |
| 2078 // frame type (stream frame with fin) | |
| 2079 0xFC, | |
| 2080 // stream id | |
| 2081 0x04, | |
| 2082 // offset | |
| 2083 0x54, 0x76, 0x10, 0x32, | |
| 2084 0xDC, 0xFE, 0x98, 0xBA, | |
| 2085 // data length | |
| 2086 0x0c, 0x00, | |
| 2087 // data | |
| 2088 'h', 'e', 'l', 'l', | |
| 2089 'o', ' ', 'w', 'o', | |
| 2090 'r', 'l', 'd', '!', | |
| 2091 }; | |
| 2092 // clang-format on | |
| 2093 | |
| 2094 QuicEncryptedPacket encrypted( | |
| 2095 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 2096 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 2097 : arraysize(packet_34), | |
| 2098 false); | |
| 2099 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 2100 | |
| 2101 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 2102 ASSERT_TRUE(visitor_.header_.get()); | |
| 2103 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 2104 !kIncludeDiversificationNonce)); | |
| 2105 | |
| 2106 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | |
| 2107 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | |
| 2108 // Stream ID should be the last byte of kStreamId. | |
| 2109 EXPECT_EQ(0x000000FF & kStreamId, visitor_.stream_frames_[0]->stream_id); | |
| 2110 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); | |
| 2111 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); | |
| 2112 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); | |
| 2113 | |
| 2114 // Now test framing boundaries. | |
| 2115 const size_t stream_id_size = 1; | |
| 2116 CheckStreamFrameBoundaries( | |
| 2117 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, stream_id_size, | |
| 2118 !kIncludeVersion); | |
| 2119 } | |
| 2120 | |
| 2121 TEST_P(QuicFramerTest, StreamFrameWithVersion) { | |
| 2122 // clang-format off | |
| 2123 unsigned char packet[] = { | |
| 2124 // public flags (version, 8 byte connection_id) | |
| 2125 0x39, | |
| 2126 // connection_id | |
| 2127 0x10, 0x32, 0x54, 0x76, | |
| 2128 0x98, 0xBA, 0xDC, 0xFE, | |
| 2129 // version tag | |
| 2130 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | |
| 2131 // packet number | |
| 2132 0xBC, 0x9A, 0x78, 0x56, | |
| 2133 0x34, 0x12, | |
| 2134 // private flags | |
| 2135 0x00, | |
| 2136 | |
| 2137 // frame type (stream frame with fin) | |
| 2138 0xFF, | |
| 2139 // stream id | |
| 2140 0x04, 0x03, 0x02, 0x01, | |
| 2141 // offset | |
| 2142 0x54, 0x76, 0x10, 0x32, | |
| 2143 0xDC, 0xFE, 0x98, 0xBA, | |
| 2144 // data length | |
| 2145 0x0c, 0x00, | |
| 2146 // data | |
| 2147 'h', 'e', 'l', 'l', | |
| 2148 'o', ' ', 'w', 'o', | |
| 2149 'r', 'l', 'd', '!', | |
| 2150 }; | |
| 2151 unsigned char packet_34[] = { | |
| 2152 // public flags (version, 8 byte connection_id) | |
| 2153 0x39, | |
| 2154 // connection_id | |
| 2155 0x10, 0x32, 0x54, 0x76, | |
| 2156 0x98, 0xBA, 0xDC, 0xFE, | |
| 2157 // version tag | |
| 2158 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | |
| 2159 // packet number | |
| 2160 0xBC, 0x9A, 0x78, 0x56, | |
| 2161 0x34, 0x12, | |
| 2162 | |
| 2163 // frame type (stream frame with fin) | |
| 2164 0xFF, | |
| 2165 // stream id | |
| 2166 0x04, 0x03, 0x02, 0x01, | |
| 2167 // offset | |
| 2168 0x54, 0x76, 0x10, 0x32, | |
| 2169 0xDC, 0xFE, 0x98, 0xBA, | |
| 2170 // data length | |
| 2171 0x0c, 0x00, | |
| 2172 // data | |
| 2173 'h', 'e', 'l', 'l', | |
| 2174 'o', ' ', 'w', 'o', | |
| 2175 'r', 'l', 'd', '!', | |
| 2176 }; | |
| 2177 // clang-format on | |
| 2178 | |
| 2179 QuicEncryptedPacket encrypted( | |
| 2180 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 2181 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 2182 : arraysize(packet_34), | |
| 2183 false); | |
| 2184 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 2185 | |
| 2186 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 2187 ASSERT_TRUE(visitor_.header_.get()); | |
| 2188 EXPECT_TRUE(visitor_.header_->public_header.version_flag); | |
| 2189 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]); | |
| 2190 EXPECT_TRUE(CheckDecryption(encrypted, kIncludeVersion, !kIncludePathId, | |
| 2191 !kIncludeDiversificationNonce)); | |
| 2192 | |
| 2193 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | |
| 2194 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | |
| 2195 EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); | |
| 2196 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); | |
| 2197 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); | |
| 2198 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); | |
| 2199 | |
| 2200 // Now test framing boundaries. | |
| 2201 CheckStreamFrameBoundaries( | |
| 2202 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, | |
| 2203 kQuicMaxStreamIdSize, kIncludeVersion); | |
| 2204 } | |
| 2205 | |
| 2206 TEST_P(QuicFramerTest, RejectPacket) { | |
| 2207 visitor_.accept_packet_ = false; | |
| 2208 | |
| 2209 // clang-format off | |
| 2210 unsigned char packet[] = { | |
| 2211 // public flags (8 byte connection_id) | |
| 2212 0x38, | |
| 2213 // connection_id | |
| 2214 0x10, 0x32, 0x54, 0x76, | |
| 2215 0x98, 0xBA, 0xDC, 0xFE, | |
| 2216 // packet number | |
| 2217 0xBC, 0x9A, 0x78, 0x56, | |
| 2218 0x34, 0x12, | |
| 2219 // private flags | |
| 2220 0x00, | |
| 2221 | |
| 2222 // frame type (stream frame with fin) | |
| 2223 0xFF, | |
| 2224 // stream id | |
| 2225 0x04, 0x03, 0x02, 0x01, | |
| 2226 // offset | |
| 2227 0x54, 0x76, 0x10, 0x32, | |
| 2228 0xDC, 0xFE, 0x98, 0xBA, | |
| 2229 // data length | |
| 2230 0x0c, 0x00, | |
| 2231 // data | |
| 2232 'h', 'e', 'l', 'l', | |
| 2233 'o', ' ', 'w', 'o', | |
| 2234 'r', 'l', 'd', '!', | |
| 2235 }; | |
| 2236 unsigned char packet_34[] = { | |
| 2237 // public flags (8 byte connection_id) | |
| 2238 0x38, | |
| 2239 // connection_id | |
| 2240 0x10, 0x32, 0x54, 0x76, | |
| 2241 0x98, 0xBA, 0xDC, 0xFE, | |
| 2242 // packet number | |
| 2243 0xBC, 0x9A, 0x78, 0x56, | |
| 2244 0x34, 0x12, | |
| 2245 | |
| 2246 // frame type (stream frame with fin) | |
| 2247 0xFF, | |
| 2248 // stream id | |
| 2249 0x04, 0x03, 0x02, 0x01, | |
| 2250 // offset | |
| 2251 0x54, 0x76, 0x10, 0x32, | |
| 2252 0xDC, 0xFE, 0x98, 0xBA, | |
| 2253 // data length | |
| 2254 0x0c, 0x00, | |
| 2255 // data | |
| 2256 'h', 'e', 'l', 'l', | |
| 2257 'o', ' ', 'w', 'o', | |
| 2258 'r', 'l', 'd', '!', | |
| 2259 }; | |
| 2260 // clang-format on | |
| 2261 | |
| 2262 QuicEncryptedPacket encrypted( | |
| 2263 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 2264 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 2265 : arraysize(packet_34), | |
| 2266 false); | |
| 2267 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 2268 | |
| 2269 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 2270 ASSERT_TRUE(visitor_.header_.get()); | |
| 2271 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 2272 !kIncludeDiversificationNonce)); | |
| 2273 | |
| 2274 ASSERT_EQ(0u, visitor_.stream_frames_.size()); | |
| 2275 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | |
| 2276 } | |
| 2277 | |
| 2278 TEST_P(QuicFramerTest, RejectPublicHeader) { | |
| 2279 visitor_.accept_public_header_ = false; | |
| 2280 | |
| 2281 // clang-format off | |
| 2282 unsigned char packet[] = { | |
| 2283 // public flags (8 byte connection_id) | |
| 2284 0x38, | |
| 2285 // connection_id | |
| 2286 0x10, 0x32, 0x54, 0x76, | |
| 2287 0x98, 0xBA, 0xDC, 0xFE, | |
| 2288 }; | |
| 2289 // clang-format on | |
| 2290 | |
| 2291 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 2292 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 2293 | |
| 2294 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 2295 ASSERT_TRUE(visitor_.public_header_.get()); | |
| 2296 ASSERT_FALSE(visitor_.header_.get()); | |
| 2297 } | |
| 2298 | |
| 2299 TEST_P(QuicFramerTest, AckFrameTwoTimestamp) { | |
| 2300 // clang-format off | |
| 2301 unsigned char packet[] = { | |
| 2302 // public flags (8 byte connection_id) | |
| 2303 0x38, | |
| 2304 // connection_id | |
| 2305 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 2306 // packet number | |
| 2307 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 2308 // private flags (entropy) | |
| 2309 0x01, | |
| 2310 | |
| 2311 // frame type (ack frame) | |
| 2312 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | |
| 2313 0x6C, | |
| 2314 // entropy hash of all received packets. | |
| 2315 0xBA, | |
| 2316 // largest observed packet number | |
| 2317 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 2318 // Zero delta time. | |
| 2319 0x00, 0x00, | |
| 2320 // Number of timestamps. | |
| 2321 0x02, | |
| 2322 // Delta from largest observed. | |
| 2323 0x01, | |
| 2324 // Delta time. | |
| 2325 0x10, 0x32, 0x54, 0x76, | |
| 2326 // Delta from largest observed. | |
| 2327 0x02, | |
| 2328 // Delta time. | |
| 2329 0x10, 0x32, | |
| 2330 // num missing packets | |
| 2331 0x01, | |
| 2332 // missing packet delta | |
| 2333 0x01, | |
| 2334 // 0 more missing packets in range. | |
| 2335 0x00, | |
| 2336 // Number of revived packets. | |
| 2337 0x00, | |
| 2338 }; | |
| 2339 // clang-format on | |
| 2340 | |
| 2341 if (framer_.version() > QUIC_VERSION_31) { | |
| 2342 return; | |
| 2343 } | |
| 2344 | |
| 2345 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 2346 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 2347 | |
| 2348 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 2349 ASSERT_TRUE(visitor_.header_.get()); | |
| 2350 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 2351 !kIncludeDiversificationNonce)); | |
| 2352 | |
| 2353 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | |
| 2354 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | |
| 2355 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | |
| 2356 EXPECT_EQ(0xBA, frame.entropy_hash); | |
| 2357 EXPECT_EQ(kLargestObserved, frame.largest_observed); | |
| 2358 ASSERT_EQ(1u, frame.packets.NumPacketsSlow()); | |
| 2359 ASSERT_EQ(2u, frame.received_packet_times.size()); | |
| 2360 EXPECT_EQ(kMissingPacket, frame.packets.Min()); | |
| 2361 | |
| 2362 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; | |
| 2363 const size_t kLargestObservedOffset = | |
| 2364 kReceivedEntropyOffset + kQuicEntropyHashSize; | |
| 2365 const size_t kMissingDeltaTimeOffset = | |
| 2366 kLargestObservedOffset + PACKET_6BYTE_PACKET_NUMBER; | |
| 2367 const size_t kNumTimestampsOffset = | |
| 2368 kMissingDeltaTimeOffset + kQuicDeltaTimeLargestObservedSize; | |
| 2369 const size_t kTimestampDeltaLargestObserved1 = | |
| 2370 kNumTimestampsOffset + kQuicNumTimestampsSize; | |
| 2371 const size_t kTimestampTimeDeltaLargestObserved1 = | |
| 2372 kTimestampDeltaLargestObserved1 + 1; | |
| 2373 const size_t kTimestampDeltaLargestObserved2 = | |
| 2374 kTimestampTimeDeltaLargestObserved1 + 4; | |
| 2375 const size_t kTimestampTimeDeltaLargestObserved2 = | |
| 2376 kTimestampDeltaLargestObserved2 + 1; | |
| 2377 const size_t kNumMissingPacketOffset = | |
| 2378 kTimestampTimeDeltaLargestObserved2 + 2; | |
| 2379 const size_t kMissingPacketsOffset = | |
| 2380 kNumMissingPacketOffset + kNumberOfNackRangesSize; | |
| 2381 const size_t kMissingPacketsRange = | |
| 2382 kMissingPacketsOffset + PACKET_1BYTE_PACKET_NUMBER; | |
| 2383 const size_t kRevivedPacketsLength = | |
| 2384 kMissingPacketsRange + PACKET_1BYTE_PACKET_NUMBER; | |
| 2385 // Now test framing boundaries. | |
| 2386 const size_t ack_frame_size = | |
| 2387 kRevivedPacketsLength + PACKET_1BYTE_PACKET_NUMBER; | |
| 2388 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) { | |
| 2389 string expected_error; | |
| 2390 if (i < kLargestObservedOffset) { | |
| 2391 expected_error = "Unable to read entropy hash for received packets."; | |
| 2392 } else if (i < kMissingDeltaTimeOffset) { | |
| 2393 expected_error = "Unable to read largest observed."; | |
| 2394 } else if (i < kNumTimestampsOffset) { | |
| 2395 expected_error = "Unable to read ack delay time."; | |
| 2396 } else if (i < kTimestampDeltaLargestObserved1) { | |
| 2397 expected_error = "Unable to read num received packets."; | |
| 2398 } else if (i < kTimestampTimeDeltaLargestObserved1) { | |
| 2399 expected_error = "Unable to read sequence delta in received packets."; | |
| 2400 } else if (i < kTimestampDeltaLargestObserved2) { | |
| 2401 expected_error = "Unable to read time delta in received packets."; | |
| 2402 } else if (i < kTimestampTimeDeltaLargestObserved2) { | |
| 2403 expected_error = "Unable to read sequence delta in received packets."; | |
| 2404 } else if (i < kNumMissingPacketOffset) { | |
| 2405 expected_error = | |
| 2406 "Unable to read incremental time delta in received packets."; | |
| 2407 } else if (i < kMissingPacketsOffset) { | |
| 2408 expected_error = "Unable to read num missing packet ranges."; | |
| 2409 } else if (i < kMissingPacketsRange) { | |
| 2410 expected_error = "Unable to read missing packet number delta."; | |
| 2411 } else if (i < kRevivedPacketsLength) { | |
| 2412 expected_error = "Unable to read missing packet number range."; | |
| 2413 } else { | |
| 2414 expected_error = "Unable to read num revived packets."; | |
| 2415 } | |
| 2416 CheckProcessingFails( | |
| 2417 packet, | |
| 2418 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 2419 !kIncludeVersion, !kIncludePathId, | |
| 2420 !kIncludeDiversificationNonce, | |
| 2421 PACKET_6BYTE_PACKET_NUMBER), | |
| 2422 expected_error, QUIC_INVALID_ACK_DATA); | |
| 2423 } | |
| 2424 } | |
| 2425 | |
| 2426 TEST_P(QuicFramerTest, AckFrameTwoTimestampVersion32) { | |
| 2427 // clang-format off | |
| 2428 unsigned char packet[] = { | |
| 2429 // public flags (8 byte connection_id) | |
| 2430 0x3C, | |
| 2431 // connection_id | |
| 2432 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 2433 // packet number | |
| 2434 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 2435 // private flags (entropy) | |
| 2436 0x01, | |
| 2437 | |
| 2438 // frame type (ack frame) | |
| 2439 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | |
| 2440 0x6C, | |
| 2441 // entropy hash of all received packets. | |
| 2442 0xBA, | |
| 2443 // largest observed packet number | |
| 2444 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 2445 // Zero delta time. | |
| 2446 0x00, 0x00, | |
| 2447 // Number of timestamps. | |
| 2448 0x02, | |
| 2449 // Delta from largest observed. | |
| 2450 0x01, | |
| 2451 // Delta time. | |
| 2452 0x10, 0x32, 0x54, 0x76, | |
| 2453 // Delta from largest observed. | |
| 2454 0x02, | |
| 2455 // Delta time. | |
| 2456 0x10, 0x32, | |
| 2457 // num missing packets | |
| 2458 0x01, | |
| 2459 // missing packet delta | |
| 2460 0x01, | |
| 2461 // 0 more missing packets in range. | |
| 2462 0x00, | |
| 2463 }; | |
| 2464 // clang-format on | |
| 2465 | |
| 2466 if (framer_.version() <= QUIC_VERSION_31 || | |
| 2467 framer_.version() > QUIC_VERSION_33) { | |
| 2468 return; | |
| 2469 } | |
| 2470 | |
| 2471 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 2472 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 2473 | |
| 2474 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 2475 ASSERT_TRUE(visitor_.header_.get()); | |
| 2476 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 2477 !kIncludeDiversificationNonce)); | |
| 2478 | |
| 2479 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | |
| 2480 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | |
| 2481 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | |
| 2482 EXPECT_EQ(0xBA, frame.entropy_hash); | |
| 2483 EXPECT_EQ(kLargestObserved, frame.largest_observed); | |
| 2484 ASSERT_EQ(1u, frame.packets.NumPacketsSlow()); | |
| 2485 ASSERT_EQ(2u, frame.received_packet_times.size()); | |
| 2486 EXPECT_EQ(kMissingPacket, frame.packets.Min()); | |
| 2487 | |
| 2488 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; | |
| 2489 const size_t kLargestObservedOffset = | |
| 2490 kReceivedEntropyOffset + kQuicEntropyHashSize; | |
| 2491 const size_t kMissingDeltaTimeOffset = | |
| 2492 kLargestObservedOffset + PACKET_6BYTE_PACKET_NUMBER; | |
| 2493 const size_t kNumTimestampsOffset = | |
| 2494 kMissingDeltaTimeOffset + kQuicDeltaTimeLargestObservedSize; | |
| 2495 const size_t kTimestampDeltaLargestObserved1 = | |
| 2496 kNumTimestampsOffset + kQuicNumTimestampsSize; | |
| 2497 const size_t kTimestampTimeDeltaLargestObserved1 = | |
| 2498 kTimestampDeltaLargestObserved1 + 1; | |
| 2499 const size_t kTimestampDeltaLargestObserved2 = | |
| 2500 kTimestampTimeDeltaLargestObserved1 + 4; | |
| 2501 const size_t kTimestampTimeDeltaLargestObserved2 = | |
| 2502 kTimestampDeltaLargestObserved2 + 1; | |
| 2503 const size_t kNumMissingPacketOffset = | |
| 2504 kTimestampTimeDeltaLargestObserved2 + 2; | |
| 2505 const size_t kMissingPacketsOffset = | |
| 2506 kNumMissingPacketOffset + kNumberOfNackRangesSize; | |
| 2507 // Now test framing boundaries. | |
| 2508 const size_t ack_frame_size = PACKET_1BYTE_PACKET_NUMBER; | |
| 2509 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) { | |
| 2510 string expected_error; | |
| 2511 if (i < kLargestObservedOffset) { | |
| 2512 expected_error = "Unable to read entropy hash for received packets."; | |
| 2513 } else if (i < kMissingDeltaTimeOffset) { | |
| 2514 expected_error = "Unable to read largest observed."; | |
| 2515 } else if (i < kNumTimestampsOffset) { | |
| 2516 expected_error = "Unable to read ack delay time."; | |
| 2517 } else if (i < kTimestampDeltaLargestObserved1) { | |
| 2518 expected_error = "Unable to read num received packets."; | |
| 2519 } else if (i < kTimestampTimeDeltaLargestObserved1) { | |
| 2520 expected_error = "Unable to read sequence delta in received packets."; | |
| 2521 } else if (i < kTimestampDeltaLargestObserved2) { | |
| 2522 expected_error = "Unable to read time delta in received packets."; | |
| 2523 } else if (i < kTimestampTimeDeltaLargestObserved2) { | |
| 2524 expected_error = "Unable to read sequence delta in received packets."; | |
| 2525 } else if (i < kNumMissingPacketOffset) { | |
| 2526 expected_error = | |
| 2527 "Unable to read incremental time delta in received packets."; | |
| 2528 } else if (i < kMissingPacketsOffset) { | |
| 2529 expected_error = "Unable to read num missing packet ranges."; | |
| 2530 } else { | |
| 2531 expected_error = "Unable to read missing packet number delta."; | |
| 2532 } | |
| 2533 CheckProcessingFails( | |
| 2534 packet, | |
| 2535 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 2536 !kIncludeVersion, !kIncludePathId, | |
| 2537 !kIncludeDiversificationNonce, | |
| 2538 PACKET_6BYTE_PACKET_NUMBER), | |
| 2539 expected_error, QUIC_INVALID_ACK_DATA); | |
| 2540 } | |
| 2541 } | |
| 2542 | |
| 2543 TEST_P(QuicFramerTest, AckFrameOneTimestamp) { | |
| 2544 // clang-format off | |
| 2545 unsigned char packet[] = { | |
| 2546 // public flags (8 byte connection_id) | |
| 2547 0x38, | |
| 2548 // connection_id | |
| 2549 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 2550 // packet number | |
| 2551 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 2552 // private flags (entropy) | |
| 2553 0x01, | |
| 2554 | |
| 2555 // frame type (ack frame) | |
| 2556 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | |
| 2557 0x6C, | |
| 2558 // entropy hash of all received packets. | |
| 2559 0xBA, | |
| 2560 // largest observed packet number | |
| 2561 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 2562 // Zero delta time. | |
| 2563 0x00, 0x00, | |
| 2564 // Number of timestamps. | |
| 2565 0x01, | |
| 2566 // Delta from largest observed. | |
| 2567 0x01, | |
| 2568 // Delta time. | |
| 2569 0x10, 0x32, 0x54, 0x76, | |
| 2570 // num missing packets | |
| 2571 0x01, | |
| 2572 // missing packet delta | |
| 2573 0x01, | |
| 2574 // 0 more missing packets in range. | |
| 2575 0x00, | |
| 2576 // Number of revived packets. | |
| 2577 0x00, | |
| 2578 }; | |
| 2579 // clang-format on | |
| 2580 | |
| 2581 if (framer_.version() > QUIC_VERSION_31) { | |
| 2582 return; | |
| 2583 } | |
| 2584 | |
| 2585 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 2586 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 2587 | |
| 2588 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 2589 ASSERT_TRUE(visitor_.header_.get()); | |
| 2590 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 2591 !kIncludeDiversificationNonce)); | |
| 2592 | |
| 2593 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | |
| 2594 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | |
| 2595 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | |
| 2596 EXPECT_EQ(0xBA, frame.entropy_hash); | |
| 2597 EXPECT_EQ(kLargestObserved, frame.largest_observed); | |
| 2598 ASSERT_EQ(1u, frame.packets.NumPacketsSlow()); | |
| 2599 ASSERT_EQ(1u, frame.received_packet_times.size()); | |
| 2600 EXPECT_EQ(kMissingPacket, frame.packets.Min()); | |
| 2601 | |
| 2602 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; | |
| 2603 const size_t kLargestObservedOffset = | |
| 2604 kReceivedEntropyOffset + kQuicEntropyHashSize; | |
| 2605 const size_t kMissingDeltaTimeOffset = | |
| 2606 kLargestObservedOffset + PACKET_6BYTE_PACKET_NUMBER; | |
| 2607 const size_t kNumTimestampsOffset = | |
| 2608 kMissingDeltaTimeOffset + kQuicDeltaTimeLargestObservedSize; | |
| 2609 const size_t kTimestampDeltaLargestObserved = | |
| 2610 kNumTimestampsOffset + kQuicNumTimestampsSize; | |
| 2611 const size_t kTimestampTimeDeltaLargestObserved = | |
| 2612 kTimestampDeltaLargestObserved + 1; | |
| 2613 const size_t kNumMissingPacketOffset = kTimestampTimeDeltaLargestObserved + 4; | |
| 2614 const size_t kMissingPacketsOffset = | |
| 2615 kNumMissingPacketOffset + kNumberOfNackRangesSize; | |
| 2616 const size_t kMissingPacketsRange = | |
| 2617 kMissingPacketsOffset + PACKET_1BYTE_PACKET_NUMBER; | |
| 2618 const size_t kRevivedPacketsLength = | |
| 2619 kMissingPacketsRange + PACKET_1BYTE_PACKET_NUMBER; | |
| 2620 // Now test framing boundaries. | |
| 2621 const size_t ack_frame_size = | |
| 2622 kRevivedPacketsLength + PACKET_1BYTE_PACKET_NUMBER; | |
| 2623 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) { | |
| 2624 string expected_error; | |
| 2625 if (i < kLargestObservedOffset) { | |
| 2626 expected_error = "Unable to read entropy hash for received packets."; | |
| 2627 } else if (i < kMissingDeltaTimeOffset) { | |
| 2628 expected_error = "Unable to read largest observed."; | |
| 2629 } else if (i < kNumTimestampsOffset) { | |
| 2630 expected_error = "Unable to read ack delay time."; | |
| 2631 } else if (i < kTimestampDeltaLargestObserved) { | |
| 2632 expected_error = "Unable to read num received packets."; | |
| 2633 } else if (i < kTimestampTimeDeltaLargestObserved) { | |
| 2634 expected_error = "Unable to read sequence delta in received packets."; | |
| 2635 } else if (i < kNumMissingPacketOffset) { | |
| 2636 expected_error = "Unable to read time delta in received packets."; | |
| 2637 } else if (i < kMissingPacketsOffset) { | |
| 2638 expected_error = "Unable to read num missing packet ranges."; | |
| 2639 } else if (i < kMissingPacketsRange) { | |
| 2640 expected_error = "Unable to read missing packet number delta."; | |
| 2641 } else if (i < kRevivedPacketsLength) { | |
| 2642 expected_error = "Unable to read missing packet number range."; | |
| 2643 } else { | |
| 2644 expected_error = "Unable to read num revived packets."; | |
| 2645 } | |
| 2646 CheckProcessingFails( | |
| 2647 packet, | |
| 2648 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 2649 !kIncludeVersion, !kIncludePathId, | |
| 2650 !kIncludeDiversificationNonce, | |
| 2651 PACKET_6BYTE_PACKET_NUMBER), | |
| 2652 expected_error, QUIC_INVALID_ACK_DATA); | |
| 2653 } | |
| 2654 } | |
| 2655 | |
| 2656 TEST_P(QuicFramerTest, AckFrameOneTimestampVersion32) { | |
| 2657 // clang-format off | |
| 2658 unsigned char packet[] = { | |
| 2659 // public flags (8 byte connection_id) | |
| 2660 0x3C, | |
| 2661 // connection_id | |
| 2662 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 2663 // packet number | |
| 2664 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 2665 // private flags (entropy) | |
| 2666 0x01, | |
| 2667 | |
| 2668 // frame type (ack frame) | |
| 2669 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | |
| 2670 0x6C, | |
| 2671 // entropy hash of all received packets. | |
| 2672 0xBA, | |
| 2673 // largest observed packet number | |
| 2674 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 2675 // Zero delta time. | |
| 2676 0x00, 0x00, | |
| 2677 // Number of timestamps. | |
| 2678 0x01, | |
| 2679 // Delta from largest observed. | |
| 2680 0x01, | |
| 2681 // Delta time. | |
| 2682 0x10, 0x32, 0x54, 0x76, | |
| 2683 // num missing packets | |
| 2684 0x01, | |
| 2685 // missing packet delta | |
| 2686 0x01, | |
| 2687 // 0 more missing packets in range. | |
| 2688 0x00, | |
| 2689 }; | |
| 2690 // clang-format on | |
| 2691 | |
| 2692 if (framer_.version() <= QUIC_VERSION_31 || | |
| 2693 framer_.version() > QUIC_VERSION_33) { | |
| 2694 return; | |
| 2695 } | |
| 2696 | |
| 2697 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 2698 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 2699 | |
| 2700 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 2701 ASSERT_TRUE(visitor_.header_.get()); | |
| 2702 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 2703 !kIncludeDiversificationNonce)); | |
| 2704 | |
| 2705 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | |
| 2706 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | |
| 2707 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | |
| 2708 EXPECT_EQ(0xBA, frame.entropy_hash); | |
| 2709 EXPECT_EQ(kLargestObserved, frame.largest_observed); | |
| 2710 ASSERT_EQ(1u, frame.packets.NumPacketsSlow()); | |
| 2711 ASSERT_EQ(1u, frame.received_packet_times.size()); | |
| 2712 EXPECT_EQ(kMissingPacket, frame.packets.Min()); | |
| 2713 | |
| 2714 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; | |
| 2715 const size_t kLargestObservedOffset = | |
| 2716 kReceivedEntropyOffset + kQuicEntropyHashSize; | |
| 2717 const size_t kMissingDeltaTimeOffset = | |
| 2718 kLargestObservedOffset + PACKET_6BYTE_PACKET_NUMBER; | |
| 2719 const size_t kNumTimestampsOffset = | |
| 2720 kMissingDeltaTimeOffset + kQuicDeltaTimeLargestObservedSize; | |
| 2721 const size_t kTimestampDeltaLargestObserved = | |
| 2722 kNumTimestampsOffset + kQuicNumTimestampsSize; | |
| 2723 const size_t kTimestampTimeDeltaLargestObserved = | |
| 2724 kTimestampDeltaLargestObserved + 1; | |
| 2725 const size_t kNumMissingPacketOffset = kTimestampTimeDeltaLargestObserved + 4; | |
| 2726 const size_t kMissingPacketsOffset = | |
| 2727 kNumMissingPacketOffset + kNumberOfNackRangesSize; | |
| 2728 // Now test framing boundaries. | |
| 2729 const size_t ack_frame_size = PACKET_1BYTE_PACKET_NUMBER; | |
| 2730 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) { | |
| 2731 string expected_error; | |
| 2732 if (i < kLargestObservedOffset) { | |
| 2733 expected_error = "Unable to read entropy hash for received packets."; | |
| 2734 } else if (i < kMissingDeltaTimeOffset) { | |
| 2735 expected_error = "Unable to read largest observed."; | |
| 2736 } else if (i < kNumTimestampsOffset) { | |
| 2737 expected_error = "Unable to read ack delay time."; | |
| 2738 } else if (i < kTimestampDeltaLargestObserved) { | |
| 2739 expected_error = "Unable to read num received packets."; | |
| 2740 } else if (i < kTimestampTimeDeltaLargestObserved) { | |
| 2741 expected_error = "Unable to read sequence delta in received packets."; | |
| 2742 } else if (i < kNumMissingPacketOffset) { | |
| 2743 expected_error = "Unable to read time delta in received packets."; | |
| 2744 } else if (i < kMissingPacketsOffset) { | |
| 2745 expected_error = "Unable to read num missing packet ranges."; | |
| 2746 } else { | |
| 2747 expected_error = "Unable to read missing packet number delta."; | |
| 2748 } | |
| 2749 CheckProcessingFails( | |
| 2750 packet, | |
| 2751 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 2752 !kIncludeVersion, !kIncludePathId, | |
| 2753 !kIncludeDiversificationNonce, | |
| 2754 PACKET_6BYTE_PACKET_NUMBER), | |
| 2755 expected_error, QUIC_INVALID_ACK_DATA); | |
| 2756 } | |
| 2757 } | |
| 2758 | |
| 2759 TEST_P(QuicFramerTest, AckFrame) { | |
| 2760 // clang-format off | |
| 2761 unsigned char packet[] = { | |
| 2762 // public flags (8 byte connection_id) | |
| 2763 0x3C, | |
| 2764 // connection_id | |
| 2765 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 2766 // packet number | |
| 2767 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 2768 // private flags (entropy) | |
| 2769 0x01, | |
| 2770 | |
| 2771 // frame type (ack frame) | |
| 2772 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | |
| 2773 0x6C, | |
| 2774 // entropy hash of all received packets. | |
| 2775 0xBA, | |
| 2776 // largest observed packet number | |
| 2777 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 2778 // Zero delta time. | |
| 2779 0x00, 0x00, | |
| 2780 // Number of timestamps. | |
| 2781 0x00, | |
| 2782 // num missing packets | |
| 2783 0x01, | |
| 2784 // missing packet delta | |
| 2785 0x01, | |
| 2786 // 0 more missing packets in range. | |
| 2787 0x00, | |
| 2788 // Number of revived packets. | |
| 2789 0x00, | |
| 2790 }; | |
| 2791 // clang-format on | |
| 2792 | |
| 2793 if (framer_.version() > QUIC_VERSION_31) { | |
| 2794 return; | |
| 2795 } | |
| 2796 | |
| 2797 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 2798 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 2799 | |
| 2800 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 2801 ASSERT_TRUE(visitor_.header_.get()); | |
| 2802 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 2803 !kIncludeDiversificationNonce)); | |
| 2804 | |
| 2805 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | |
| 2806 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | |
| 2807 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | |
| 2808 EXPECT_EQ(0xBA, frame.entropy_hash); | |
| 2809 EXPECT_EQ(kLargestObserved, frame.largest_observed); | |
| 2810 ASSERT_EQ(1u, frame.packets.NumPacketsSlow()); | |
| 2811 EXPECT_EQ(kMissingPacket, frame.packets.Min()); | |
| 2812 | |
| 2813 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; | |
| 2814 const size_t kLargestObservedOffset = | |
| 2815 kReceivedEntropyOffset + kQuicEntropyHashSize; | |
| 2816 const size_t kMissingDeltaTimeOffset = | |
| 2817 kLargestObservedOffset + PACKET_6BYTE_PACKET_NUMBER; | |
| 2818 const size_t kNumTimestampsOffset = | |
| 2819 kMissingDeltaTimeOffset + kQuicDeltaTimeLargestObservedSize; | |
| 2820 const size_t kNumMissingPacketOffset = | |
| 2821 kNumTimestampsOffset + kQuicNumTimestampsSize; | |
| 2822 const size_t kMissingPacketsOffset = | |
| 2823 kNumMissingPacketOffset + kNumberOfNackRangesSize; | |
| 2824 const size_t kMissingPacketsRange = | |
| 2825 kMissingPacketsOffset + PACKET_1BYTE_PACKET_NUMBER; | |
| 2826 const size_t kRevivedPacketsLength = | |
| 2827 kMissingPacketsRange + PACKET_1BYTE_PACKET_NUMBER; | |
| 2828 // Now test framing boundaries. | |
| 2829 const size_t ack_frame_size = | |
| 2830 kRevivedPacketsLength + PACKET_1BYTE_PACKET_NUMBER; | |
| 2831 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) { | |
| 2832 string expected_error; | |
| 2833 if (i < kLargestObservedOffset) { | |
| 2834 expected_error = "Unable to read entropy hash for received packets."; | |
| 2835 } else if (i < kMissingDeltaTimeOffset) { | |
| 2836 expected_error = "Unable to read largest observed."; | |
| 2837 } else if (i < kNumTimestampsOffset) { | |
| 2838 expected_error = "Unable to read ack delay time."; | |
| 2839 } else if (i < kNumMissingPacketOffset) { | |
| 2840 expected_error = "Unable to read num received packets."; | |
| 2841 } else if (i < kMissingPacketsOffset) { | |
| 2842 expected_error = "Unable to read num missing packet ranges."; | |
| 2843 } else if (i < kMissingPacketsRange) { | |
| 2844 expected_error = "Unable to read missing packet number delta."; | |
| 2845 } else if (i < kRevivedPacketsLength) { | |
| 2846 expected_error = "Unable to read missing packet number range."; | |
| 2847 } else { | |
| 2848 expected_error = "Unable to read num revived packets."; | |
| 2849 } | |
| 2850 CheckProcessingFails( | |
| 2851 packet, | |
| 2852 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 2853 !kIncludeVersion, !kIncludePathId, | |
| 2854 !kIncludeDiversificationNonce, | |
| 2855 PACKET_6BYTE_PACKET_NUMBER), | |
| 2856 expected_error, QUIC_INVALID_ACK_DATA); | |
| 2857 } | |
| 2858 } | |
| 2859 | |
| 2860 TEST_P(QuicFramerTest, NewAckFrameOneAckBlock) { | |
| 2861 // clang-format off | |
| 2862 unsigned char packet[] = { | |
| 2863 // public flags (8 byte connection_id) | |
| 2864 0x3C, | |
| 2865 // connection_id | |
| 2866 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 2867 // packet number | |
| 2868 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 2869 | |
| 2870 // frame type (ack frame) | |
| 2871 // (one ack block, 2 byte largest observed, 2 byte block length) | |
| 2872 0x45, | |
| 2873 // largest acked | |
| 2874 0x34, 0x12, | |
| 2875 // Zero delta time. | |
| 2876 0x00, 0x00, | |
| 2877 // first ack block length. | |
| 2878 0x34, 0x12, | |
| 2879 // num timestamps. | |
| 2880 0x00, | |
| 2881 }; | |
| 2882 // clang-format on | |
| 2883 | |
| 2884 if (framer_.version() <= QUIC_VERSION_33) { | |
| 2885 return; | |
| 2886 } | |
| 2887 | |
| 2888 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 2889 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 2890 | |
| 2891 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 2892 ASSERT_TRUE(visitor_.header_.get()); | |
| 2893 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 2894 !kIncludeDiversificationNonce)); | |
| 2895 | |
| 2896 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | |
| 2897 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | |
| 2898 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | |
| 2899 EXPECT_EQ(kSmallLargestObserved, frame.largest_observed); | |
| 2900 EXPECT_FALSE(frame.missing); | |
| 2901 ASSERT_EQ(4660u, frame.packets.NumPacketsSlow()); | |
| 2902 | |
| 2903 const size_t kLargestAckedOffset = kQuicFrameTypeSize; | |
| 2904 const size_t kLargestAckedDeltaTimeOffset = | |
| 2905 kLargestAckedOffset + PACKET_2BYTE_PACKET_NUMBER; | |
| 2906 const size_t kFirstAckBlockLengthOffset = | |
| 2907 kLargestAckedDeltaTimeOffset + kQuicDeltaTimeLargestObservedSize; | |
| 2908 const size_t kNumTimestampsOffset = | |
| 2909 kFirstAckBlockLengthOffset + PACKET_2BYTE_PACKET_NUMBER; | |
| 2910 // Now test framing boundaries. | |
| 2911 const size_t ack_frame_size = | |
| 2912 kFirstAckBlockLengthOffset + PACKET_2BYTE_PACKET_NUMBER; | |
| 2913 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) { | |
| 2914 string expected_error; | |
| 2915 if (i < kLargestAckedDeltaTimeOffset) { | |
| 2916 expected_error = "Unable to read largest acked."; | |
| 2917 } else if (i < kFirstAckBlockLengthOffset) { | |
| 2918 expected_error = "Unable to read ack delay time."; | |
| 2919 } else if (i < kNumTimestampsOffset) { | |
| 2920 expected_error = "Unable to read first ack block length."; | |
| 2921 } else { | |
| 2922 expected_error = "Unable to read num received packets."; | |
| 2923 } | |
| 2924 CheckProcessingFails( | |
| 2925 packet, | |
| 2926 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 2927 !kIncludeVersion, !kIncludePathId, | |
| 2928 !kIncludeDiversificationNonce, | |
| 2929 PACKET_6BYTE_PACKET_NUMBER), | |
| 2930 expected_error, QUIC_INVALID_ACK_DATA); | |
| 2931 } | |
| 2932 } | |
| 2933 | |
| 2934 TEST_P(QuicFramerTest, NewAckFrameTwoTimeStampsMultipleAckBlocks) { | |
| 2935 // clang-format off | |
| 2936 unsigned char packet[] = { | |
| 2937 // public flags (8 byte connection_id) | |
| 2938 0x3C, | |
| 2939 // connection_id | |
| 2940 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 2941 // packet number | |
| 2942 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 2943 | |
| 2944 // frame type (ack frame) | |
| 2945 // (more than one ack block, 2 byte largest observed, 2 byte block length) | |
| 2946 0x65, | |
| 2947 // largest acked | |
| 2948 0x34, 0x12, | |
| 2949 // Zero delta time. | |
| 2950 0x00, 0x00, | |
| 2951 // num ack blocks ranges. | |
| 2952 0x04, | |
| 2953 // first ack block length. | |
| 2954 0x01, 0x00, | |
| 2955 // gap to next block. | |
| 2956 0x01, | |
| 2957 // ack block length. | |
| 2958 0xaf, 0x0e, | |
| 2959 // gap to next block. | |
| 2960 0xff, | |
| 2961 // ack block length. | |
| 2962 0x00, 0x00, | |
| 2963 // gap to next block. | |
| 2964 0x91, | |
| 2965 // ack block length. | |
| 2966 0xea, 0x01, | |
| 2967 // gap to next block. | |
| 2968 0x05, | |
| 2969 // ack block length. | |
| 2970 0x04, 0x00, | |
| 2971 // Number of timestamps. | |
| 2972 0x02, | |
| 2973 // Delta from largest observed. | |
| 2974 0x01, | |
| 2975 // Delta time. | |
| 2976 0x10, 0x32, 0x54, 0x76, | |
| 2977 // Delta from largest observed. | |
| 2978 0x02, | |
| 2979 // Delta time. | |
| 2980 0x10, 0x32, | |
| 2981 }; | |
| 2982 // clang-format on | |
| 2983 | |
| 2984 if (framer_.version() <= QUIC_VERSION_33) { | |
| 2985 return; | |
| 2986 } | |
| 2987 | |
| 2988 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 2989 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 2990 | |
| 2991 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 2992 ASSERT_TRUE(visitor_.header_.get()); | |
| 2993 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 2994 !kIncludeDiversificationNonce)); | |
| 2995 | |
| 2996 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | |
| 2997 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | |
| 2998 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | |
| 2999 EXPECT_EQ(kSmallLargestObserved, frame.largest_observed); | |
| 3000 EXPECT_FALSE(frame.missing); | |
| 3001 ASSERT_EQ(4254u, frame.packets.NumPacketsSlow()); | |
| 3002 | |
| 3003 const size_t kLargestAckedOffset = kQuicFrameTypeSize; | |
| 3004 const size_t kLargestAckedDeltaTimeOffset = | |
| 3005 kLargestAckedOffset + PACKET_2BYTE_PACKET_NUMBER; | |
| 3006 const size_t kNumberOfAckBlocksOffset = | |
| 3007 kLargestAckedDeltaTimeOffset + kQuicDeltaTimeLargestObservedSize; | |
| 3008 const size_t kFirstAckBlockLengthOffset = | |
| 3009 kNumberOfAckBlocksOffset + kNumberOfAckBlocksSize; | |
| 3010 const size_t kGapToNextBlockOffset1 = | |
| 3011 kFirstAckBlockLengthOffset + PACKET_2BYTE_PACKET_NUMBER; | |
| 3012 const size_t kAckBlockLengthOffset1 = kGapToNextBlockOffset1 + 1; | |
| 3013 const size_t kGapToNextBlockOffset2 = | |
| 3014 kAckBlockLengthOffset1 + PACKET_2BYTE_PACKET_NUMBER; | |
| 3015 const size_t kAckBlockLengthOffset2 = kGapToNextBlockOffset2 + 1; | |
| 3016 const size_t kGapToNextBlockOffset3 = | |
| 3017 kAckBlockLengthOffset2 + PACKET_2BYTE_PACKET_NUMBER; | |
| 3018 const size_t kAckBlockLengthOffset3 = kGapToNextBlockOffset3 + 1; | |
| 3019 const size_t kGapToNextBlockOffset4 = | |
| 3020 kAckBlockLengthOffset3 + PACKET_2BYTE_PACKET_NUMBER; | |
| 3021 const size_t kAckBlockLengthOffset4 = kGapToNextBlockOffset3 + 1; | |
| 3022 const size_t kNumTimestampsOffset = | |
| 3023 kAckBlockLengthOffset4 + PACKET_2BYTE_PACKET_NUMBER; | |
| 3024 const size_t kTimestampDeltaLargestObserved1 = | |
| 3025 kNumTimestampsOffset + kQuicNumTimestampsSize; | |
| 3026 const size_t kTimestampTimeDeltaLargestObserved1 = | |
| 3027 kTimestampDeltaLargestObserved1 + 1; | |
| 3028 const size_t kTimestampDeltaLargestObserved2 = | |
| 3029 kTimestampTimeDeltaLargestObserved1 + 4; | |
| 3030 const size_t kTimestampTimeDeltaLargestObserved2 = | |
| 3031 kTimestampDeltaLargestObserved2 + 1; | |
| 3032 | |
| 3033 // Now test framing boundaries. | |
| 3034 const size_t ack_frame_size = | |
| 3035 kAckBlockLengthOffset4 + PACKET_2BYTE_PACKET_NUMBER; | |
| 3036 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) { | |
| 3037 string expected_error; | |
| 3038 if (i < kLargestAckedDeltaTimeOffset) { | |
| 3039 expected_error = "Unable to read largest acked."; | |
| 3040 } else if (i < kNumberOfAckBlocksOffset) { | |
| 3041 expected_error = "Unable to read ack delay time."; | |
| 3042 } else if (i < kFirstAckBlockLengthOffset) { | |
| 3043 expected_error = "Unable to read num of ack blocks."; | |
| 3044 } else if (i < kGapToNextBlockOffset1) { | |
| 3045 expected_error = "Unable to read first ack block length."; | |
| 3046 } else if (i < kAckBlockLengthOffset1) { | |
| 3047 expected_error = "Unable to read gap to next ack block."; | |
| 3048 } else if (i < kGapToNextBlockOffset2) { | |
| 3049 expected_error = "Unable to ack block length."; | |
| 3050 } else if (i < kAckBlockLengthOffset2) { | |
| 3051 expected_error = "Unable to read gap to next ack block."; | |
| 3052 } else if (i < kGapToNextBlockOffset3) { | |
| 3053 expected_error = "Unable to ack block length."; | |
| 3054 } else if (i < kAckBlockLengthOffset3) { | |
| 3055 expected_error = "Unable to read gap to next ack block."; | |
| 3056 } else if (i < kGapToNextBlockOffset4) { | |
| 3057 expected_error = "Unable to ack block length."; | |
| 3058 } else if (i < kAckBlockLengthOffset4) { | |
| 3059 expected_error = "Unable to read gap to next ack block."; | |
| 3060 } else if (i < kNumTimestampsOffset) { | |
| 3061 expected_error = "Unable to ack block length."; | |
| 3062 } else if (i < kTimestampDeltaLargestObserved1) { | |
| 3063 expected_error = "Unable to read num received packets."; | |
| 3064 } else if (i < kTimestampTimeDeltaLargestObserved1) { | |
| 3065 expected_error = "Unable to read sequence delta in received packets."; | |
| 3066 } else if (i < kTimestampDeltaLargestObserved2) { | |
| 3067 expected_error = "Unable to read time delta in received packets."; | |
| 3068 } else if (i < kTimestampTimeDeltaLargestObserved2) { | |
| 3069 expected_error = "Unable to read sequence delta in received packets."; | |
| 3070 } else { | |
| 3071 expected_error = | |
| 3072 "Unable to read incremental time delta in received packets."; | |
| 3073 } | |
| 3074 | |
| 3075 CheckProcessingFails( | |
| 3076 packet, | |
| 3077 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 3078 !kIncludeVersion, !kIncludePathId, | |
| 3079 !kIncludeDiversificationNonce, | |
| 3080 PACKET_6BYTE_PACKET_NUMBER), | |
| 3081 expected_error, QUIC_INVALID_ACK_DATA); | |
| 3082 } | |
| 3083 } | |
| 3084 | |
| 3085 TEST_P(QuicFramerTest, AckFrameVersion32) { | |
| 3086 // clang-format off | |
| 3087 unsigned char packet[] = { | |
| 3088 // public flags (8 byte connection_id) | |
| 3089 0x38, | |
| 3090 // connection_id | |
| 3091 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 3092 // packet number | |
| 3093 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 3094 // private flags (entropy) | |
| 3095 0x01, | |
| 3096 | |
| 3097 // frame type (ack frame) | |
| 3098 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | |
| 3099 0x6C, | |
| 3100 // entropy hash of all received packets. | |
| 3101 0xBA, | |
| 3102 // largest observed packet number | |
| 3103 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 3104 // Zero delta time. | |
| 3105 0x00, 0x00, | |
| 3106 // Number of timestamps. | |
| 3107 0x00, | |
| 3108 // num missing packets | |
| 3109 0x01, | |
| 3110 // missing packet delta | |
| 3111 0x01, | |
| 3112 // 0 more missing packets in range. | |
| 3113 0x00, | |
| 3114 }; | |
| 3115 // clang-format on | |
| 3116 | |
| 3117 if (framer_.version() <= QUIC_VERSION_31 || | |
| 3118 framer_.version() > QUIC_VERSION_33) { | |
| 3119 return; | |
| 3120 } | |
| 3121 | |
| 3122 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 3123 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 3124 | |
| 3125 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 3126 ASSERT_TRUE(visitor_.header_.get()); | |
| 3127 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 3128 !kIncludeDiversificationNonce)); | |
| 3129 | |
| 3130 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | |
| 3131 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | |
| 3132 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | |
| 3133 EXPECT_EQ(0xBA, frame.entropy_hash); | |
| 3134 EXPECT_EQ(kLargestObserved, frame.largest_observed); | |
| 3135 ASSERT_EQ(1u, frame.packets.NumPacketsSlow()); | |
| 3136 EXPECT_EQ(kMissingPacket, frame.packets.Min()); | |
| 3137 | |
| 3138 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; | |
| 3139 const size_t kLargestObservedOffset = | |
| 3140 kReceivedEntropyOffset + kQuicEntropyHashSize; | |
| 3141 const size_t kMissingDeltaTimeOffset = | |
| 3142 kLargestObservedOffset + PACKET_6BYTE_PACKET_NUMBER; | |
| 3143 const size_t kNumTimestampsOffset = | |
| 3144 kMissingDeltaTimeOffset + kQuicDeltaTimeLargestObservedSize; | |
| 3145 const size_t kNumMissingPacketOffset = | |
| 3146 kNumTimestampsOffset + kQuicNumTimestampsSize; | |
| 3147 const size_t kMissingPacketsOffset = | |
| 3148 kNumMissingPacketOffset + kNumberOfNackRangesSize; | |
| 3149 // Now test framing boundaries. | |
| 3150 const size_t ack_frame_size = PACKET_1BYTE_PACKET_NUMBER; | |
| 3151 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) { | |
| 3152 string expected_error; | |
| 3153 if (i < kLargestObservedOffset) { | |
| 3154 expected_error = "Unable to read entropy hash for received packets."; | |
| 3155 } else if (i < kMissingDeltaTimeOffset) { | |
| 3156 expected_error = "Unable to read largest observed."; | |
| 3157 } else if (i < kNumTimestampsOffset) { | |
| 3158 expected_error = "Unable to read ack delay time."; | |
| 3159 } else if (i < kNumMissingPacketOffset) { | |
| 3160 expected_error = "Unable to read num received packets."; | |
| 3161 } else if (i < kMissingPacketsOffset) { | |
| 3162 expected_error = "Unable to read num missing packet ranges."; | |
| 3163 } else { | |
| 3164 expected_error = "Unable to read missing packet number delta."; | |
| 3165 } | |
| 3166 CheckProcessingFails( | |
| 3167 packet, | |
| 3168 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 3169 !kIncludeVersion, !kIncludePathId, | |
| 3170 !kIncludeDiversificationNonce, | |
| 3171 PACKET_6BYTE_PACKET_NUMBER), | |
| 3172 expected_error, QUIC_INVALID_ACK_DATA); | |
| 3173 } | |
| 3174 } | |
| 3175 | |
| 3176 TEST_P(QuicFramerTest, AckFrameRevivedPackets) { | |
| 3177 // clang-format off | |
| 3178 unsigned char packet[] = { | |
| 3179 // public flags (8 byte connection_id) | |
| 3180 0x38, | |
| 3181 // connection_id | |
| 3182 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 3183 // packet number | |
| 3184 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 3185 // private flags (entropy) | |
| 3186 0x01, | |
| 3187 | |
| 3188 // frame type (ack frame) | |
| 3189 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | |
| 3190 0x6C, | |
| 3191 // entropy hash of all received packets. | |
| 3192 0xBA, | |
| 3193 // largest observed packet number | |
| 3194 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 3195 // Zero delta time. | |
| 3196 0x00, 0x00, | |
| 3197 // num received packets. | |
| 3198 0x00, | |
| 3199 // num missing packets | |
| 3200 0x01, | |
| 3201 // missing packet delta | |
| 3202 0x01, | |
| 3203 // 0 more missing packets in range. | |
| 3204 0x00, | |
| 3205 // Number of revived packets. | |
| 3206 0x01, | |
| 3207 // Revived packet number. | |
| 3208 0xBE, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 3209 // Number of revived packets. | |
| 3210 0x00, | |
| 3211 }; | |
| 3212 // clang-format on | |
| 3213 | |
| 3214 if (framer_.version() > QUIC_VERSION_31) { | |
| 3215 return; | |
| 3216 } | |
| 3217 | |
| 3218 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 3219 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 3220 | |
| 3221 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 3222 ASSERT_TRUE(visitor_.header_.get()); | |
| 3223 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 3224 !kIncludeDiversificationNonce)); | |
| 3225 | |
| 3226 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | |
| 3227 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | |
| 3228 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | |
| 3229 EXPECT_EQ(0xBA, frame.entropy_hash); | |
| 3230 EXPECT_EQ(kLargestObserved, frame.largest_observed); | |
| 3231 ASSERT_EQ(1u, frame.packets.NumPacketsSlow()); | |
| 3232 EXPECT_EQ(kMissingPacket, frame.packets.Min()); | |
| 3233 | |
| 3234 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; | |
| 3235 const size_t kLargestObservedOffset = | |
| 3236 kReceivedEntropyOffset + kQuicEntropyHashSize; | |
| 3237 const size_t kMissingDeltaTimeOffset = | |
| 3238 kLargestObservedOffset + PACKET_6BYTE_PACKET_NUMBER; | |
| 3239 const size_t kNumTimestampsOffset = | |
| 3240 kMissingDeltaTimeOffset + kQuicDeltaTimeLargestObservedSize; | |
| 3241 const size_t kNumMissingPacketOffset = | |
| 3242 kNumTimestampsOffset + kQuicNumTimestampsSize; | |
| 3243 const size_t kMissingPacketsOffset = | |
| 3244 kNumMissingPacketOffset + kNumberOfNackRangesSize; | |
| 3245 const size_t kMissingPacketsRange = | |
| 3246 kMissingPacketsOffset + PACKET_1BYTE_PACKET_NUMBER; | |
| 3247 const size_t kRevivedPacketsLength = | |
| 3248 kMissingPacketsRange + PACKET_1BYTE_PACKET_NUMBER; | |
| 3249 const size_t kRevivedPacketSequenceNumberLength = | |
| 3250 kRevivedPacketsLength + PACKET_1BYTE_PACKET_NUMBER; | |
| 3251 // Now test framing boundaries. | |
| 3252 const size_t ack_frame_size = | |
| 3253 kRevivedPacketSequenceNumberLength + PACKET_6BYTE_PACKET_NUMBER; | |
| 3254 for (size_t i = kQuicFrameTypeSize; i < ack_frame_size; ++i) { | |
| 3255 string expected_error; | |
| 3256 if (i < kReceivedEntropyOffset) { | |
| 3257 expected_error = "Unable to read least unacked delta."; | |
| 3258 } else if (i < kLargestObservedOffset) { | |
| 3259 expected_error = "Unable to read entropy hash for received packets."; | |
| 3260 } else if (i < kMissingDeltaTimeOffset) { | |
| 3261 expected_error = "Unable to read largest observed."; | |
| 3262 } else if (i < kNumTimestampsOffset) { | |
| 3263 expected_error = "Unable to read ack delay time."; | |
| 3264 } else if (i < kNumMissingPacketOffset) { | |
| 3265 expected_error = "Unable to read num received packets."; | |
| 3266 } else if (i < kMissingPacketsOffset) { | |
| 3267 expected_error = "Unable to read num missing packet ranges."; | |
| 3268 } else if (i < kMissingPacketsRange) { | |
| 3269 expected_error = "Unable to read missing packet number delta."; | |
| 3270 } else if (i < kRevivedPacketsLength) { | |
| 3271 expected_error = "Unable to read missing packet number range."; | |
| 3272 } else if (i < kRevivedPacketSequenceNumberLength) { | |
| 3273 expected_error = "Unable to read num revived packets."; | |
| 3274 } else { | |
| 3275 expected_error = "Unable to read revived packet."; | |
| 3276 } | |
| 3277 CheckProcessingFails( | |
| 3278 packet, | |
| 3279 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 3280 !kIncludeVersion, !kIncludePathId, | |
| 3281 !kIncludeDiversificationNonce, | |
| 3282 PACKET_6BYTE_PACKET_NUMBER), | |
| 3283 expected_error, QUIC_INVALID_ACK_DATA); | |
| 3284 } | |
| 3285 } | |
| 3286 | |
| 3287 TEST_P(QuicFramerTest, AckFrameNoNacks) { | |
| 3288 // clang-format off | |
| 3289 unsigned char packet[] = { | |
| 3290 // public flags (8 byte connection_id) | |
| 3291 static_cast<unsigned char>( | |
| 3292 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 3293 // connection_id | |
| 3294 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 3295 // packet number | |
| 3296 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 3297 // private flags (entropy) | |
| 3298 0x01, | |
| 3299 | |
| 3300 // frame type (ack frame) | |
| 3301 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta) | |
| 3302 0x4C, | |
| 3303 // entropy hash of all received packets. | |
| 3304 0xBA, | |
| 3305 // largest observed packet number | |
| 3306 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 3307 // Zero delta time. | |
| 3308 0x00, 0x00, | |
| 3309 // Number of received packets. | |
| 3310 0x00, | |
| 3311 }; | |
| 3312 // clang-format on | |
| 3313 if (framer_.version() >= QUIC_VERSION_31) { | |
| 3314 return; | |
| 3315 } | |
| 3316 | |
| 3317 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 3318 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 3319 | |
| 3320 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 3321 ASSERT_TRUE(visitor_.header_.get()); | |
| 3322 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 3323 !kIncludeDiversificationNonce)); | |
| 3324 | |
| 3325 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | |
| 3326 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | |
| 3327 QuicAckFrame* frame = visitor_.ack_frames_[0]; | |
| 3328 EXPECT_EQ(0xBA, frame->entropy_hash); | |
| 3329 EXPECT_EQ(kLargestObserved, frame->largest_observed); | |
| 3330 ASSERT_TRUE(frame->packets.Empty()); | |
| 3331 | |
| 3332 // Verify that the packet re-serializes identically. | |
| 3333 QuicFrames frames; | |
| 3334 frames.push_back(QuicFrame(frame)); | |
| 3335 std::unique_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames)); | |
| 3336 ASSERT_TRUE(data != nullptr); | |
| 3337 | |
| 3338 test::CompareCharArraysWithHexError("constructed packet", data->data(), | |
| 3339 data->length(), AsChars(packet), | |
| 3340 arraysize(packet)); | |
| 3341 } | |
| 3342 | |
| 3343 TEST_P(QuicFramerTest, AckFrame500Nacks) { | |
| 3344 // clang-format off | |
| 3345 unsigned char packet[] = { | |
| 3346 // public flags (8 byte connection_id) | |
| 3347 static_cast<unsigned char>( | |
| 3348 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 3349 // connection_id | |
| 3350 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 3351 // packet number | |
| 3352 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 3353 // private flags (entropy) | |
| 3354 0x01, | |
| 3355 | |
| 3356 // frame type (ack frame) | |
| 3357 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | |
| 3358 0x6C, | |
| 3359 // entropy hash of all received packets. | |
| 3360 0xBA, | |
| 3361 // largest observed packet number | |
| 3362 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 3363 // Zero delta time. | |
| 3364 0x00, 0x00, | |
| 3365 // No received packets. | |
| 3366 0x00, | |
| 3367 // num missing packet ranges | |
| 3368 0x02, | |
| 3369 // missing packet delta | |
| 3370 0x01, | |
| 3371 // 243 more missing packets in range. | |
| 3372 // The ranges are listed in this order so the re-constructed packet | |
| 3373 // matches. | |
| 3374 0xF3, | |
| 3375 // No gap between ranges | |
| 3376 0x00, | |
| 3377 // 255 more missing packets in range. | |
| 3378 0xFF, | |
| 3379 // No revived packets. | |
| 3380 0x00, | |
| 3381 }; | |
| 3382 // clang-format on | |
| 3383 | |
| 3384 if (framer_.version() > QUIC_VERSION_31) { | |
| 3385 return; | |
| 3386 } | |
| 3387 | |
| 3388 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 3389 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 3390 | |
| 3391 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 3392 ASSERT_TRUE(visitor_.header_.get()); | |
| 3393 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 3394 !kIncludeDiversificationNonce)); | |
| 3395 | |
| 3396 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | |
| 3397 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | |
| 3398 QuicAckFrame* frame = visitor_.ack_frames_[0]; | |
| 3399 EXPECT_EQ(0xBA, frame->entropy_hash); | |
| 3400 EXPECT_EQ(kLargestObserved, frame->largest_observed); | |
| 3401 ASSERT_EQ(500u, frame->packets.NumPacketsSlow()); | |
| 3402 EXPECT_EQ(kMissingPacket - 499, frame->packets.Min()); | |
| 3403 EXPECT_EQ(kMissingPacket, frame->packets.Max()); | |
| 3404 | |
| 3405 // Verify that the packet re-serializes identically. | |
| 3406 QuicFrames frames; | |
| 3407 frames.push_back(QuicFrame(frame)); | |
| 3408 std::unique_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames)); | |
| 3409 ASSERT_TRUE(data != nullptr); | |
| 3410 | |
| 3411 test::CompareCharArraysWithHexError("constructed packet", data->data(), | |
| 3412 data->length(), AsChars(packet), | |
| 3413 arraysize(packet)); | |
| 3414 } | |
| 3415 | |
| 3416 TEST_P(QuicFramerTest, AckFrame500NacksVersion32) { | |
| 3417 // clang-format off | |
| 3418 unsigned char packet[] = { | |
| 3419 // public flags (8 byte connection_id) | |
| 3420 static_cast<unsigned char>( | |
| 3421 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 3422 // connection_id | |
| 3423 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 3424 // packet number | |
| 3425 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 3426 // private flags (entropy) | |
| 3427 0x01, | |
| 3428 | |
| 3429 // frame type (ack frame) | |
| 3430 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | |
| 3431 0x6C, | |
| 3432 // entropy hash of all received packets. | |
| 3433 0xBA, | |
| 3434 // largest observed packet number | |
| 3435 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 3436 // Zero delta time. | |
| 3437 0x00, 0x00, | |
| 3438 // No received packets. | |
| 3439 0x00, | |
| 3440 // num missing packet ranges | |
| 3441 0x02, | |
| 3442 // missing packet delta | |
| 3443 0x01, | |
| 3444 // 243 more missing packets in range. | |
| 3445 // The ranges are listed in this order so the re-constructed packet | |
| 3446 // matches. | |
| 3447 0xF3, | |
| 3448 // No gap between ranges | |
| 3449 0x00, | |
| 3450 // 255 more missing packets in range. | |
| 3451 0xFF, | |
| 3452 }; | |
| 3453 // clang-format on | |
| 3454 | |
| 3455 if (framer_.version() <= QUIC_VERSION_31 || | |
| 3456 framer_.version() > QUIC_VERSION_33) { | |
| 3457 return; | |
| 3458 } | |
| 3459 | |
| 3460 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 3461 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 3462 | |
| 3463 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 3464 ASSERT_TRUE(visitor_.header_.get()); | |
| 3465 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 3466 !kIncludeDiversificationNonce)); | |
| 3467 | |
| 3468 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | |
| 3469 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | |
| 3470 QuicAckFrame* frame = visitor_.ack_frames_[0]; | |
| 3471 EXPECT_EQ(0xBA, frame->entropy_hash); | |
| 3472 EXPECT_EQ(kLargestObserved, frame->largest_observed); | |
| 3473 ASSERT_EQ(500u, frame->packets.NumPacketsSlow()); | |
| 3474 EXPECT_EQ(kMissingPacket - 499, frame->packets.Min()); | |
| 3475 EXPECT_EQ(kMissingPacket, frame->packets.Max()); | |
| 3476 | |
| 3477 // Verify that the packet re-serializes identically. | |
| 3478 QuicFrames frames; | |
| 3479 frames.push_back(QuicFrame(frame)); | |
| 3480 std::unique_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames)); | |
| 3481 ASSERT_TRUE(data != nullptr); | |
| 3482 | |
| 3483 test::CompareCharArraysWithHexError("constructed packet", data->data(), | |
| 3484 data->length(), AsChars(packet), | |
| 3485 arraysize(packet)); | |
| 3486 } | |
| 3487 | |
| 3488 TEST_P(QuicFramerTest, StopWaitingFrame) { | |
| 3489 if (framer_.version() > QUIC_VERSION_33) { | |
| 3490 return; | |
| 3491 } | |
| 3492 // clang-format off | |
| 3493 unsigned char packet[] = { | |
| 3494 // public flags (8 byte connection_id) | |
| 3495 0x38, | |
| 3496 // connection_id | |
| 3497 0x10, 0x32, 0x54, 0x76, | |
| 3498 0x98, 0xBA, 0xDC, 0xFE, | |
| 3499 // packet number | |
| 3500 0xA8, 0x9A, 0x78, 0x56, | |
| 3501 0x34, 0x12, | |
| 3502 // private flags (entropy) | |
| 3503 0x01, | |
| 3504 | |
| 3505 // frame type (ack frame) | |
| 3506 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | |
| 3507 0x06, | |
| 3508 // entropy hash of sent packets till least awaiting - 1. | |
| 3509 0xAB, | |
| 3510 // least packet number awaiting an ack, delta from packet number. | |
| 3511 0x08, 0x00, 0x00, 0x00, | |
| 3512 0x00, 0x00, | |
| 3513 }; | |
| 3514 // clang-format on | |
| 3515 | |
| 3516 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 3517 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 3518 | |
| 3519 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 3520 ASSERT_TRUE(visitor_.header_.get()); | |
| 3521 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 3522 !kIncludeDiversificationNonce)); | |
| 3523 | |
| 3524 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | |
| 3525 ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size()); | |
| 3526 const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0]; | |
| 3527 EXPECT_EQ(0xAB, frame.entropy_hash); | |
| 3528 EXPECT_EQ(kLeastUnacked, frame.least_unacked); | |
| 3529 | |
| 3530 const size_t kSentEntropyOffset = kQuicFrameTypeSize; | |
| 3531 const size_t kLeastUnackedOffset = kSentEntropyOffset + kQuicEntropyHashSize; | |
| 3532 const size_t frame_size = 7; | |
| 3533 for (size_t i = kQuicFrameTypeSize; i < frame_size; ++i) { | |
| 3534 string expected_error; | |
| 3535 if (i < kLeastUnackedOffset) { | |
| 3536 expected_error = "Unable to read entropy hash for sent packets."; | |
| 3537 } else { | |
| 3538 expected_error = "Unable to read least unacked delta."; | |
| 3539 } | |
| 3540 CheckProcessingFails( | |
| 3541 packet, | |
| 3542 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 3543 !kIncludeVersion, !kIncludePathId, | |
| 3544 !kIncludeDiversificationNonce, | |
| 3545 PACKET_6BYTE_PACKET_NUMBER), | |
| 3546 expected_error, QUIC_INVALID_STOP_WAITING_DATA); | |
| 3547 } | |
| 3548 } | |
| 3549 | |
| 3550 TEST_P(QuicFramerTest, NewStopWaitingFrame) { | |
| 3551 if (framer_.version() <= QUIC_VERSION_33) { | |
| 3552 return; | |
| 3553 } | |
| 3554 // clang-format off | |
| 3555 unsigned char packet[] = { | |
| 3556 // public flags (8 byte connection_id) | |
| 3557 0x3C, | |
| 3558 // connection_id | |
| 3559 0x10, 0x32, 0x54, 0x76, | |
| 3560 0x98, 0xBA, 0xDC, 0xFE, | |
| 3561 // packet number | |
| 3562 0xA8, 0x9A, 0x78, 0x56, | |
| 3563 0x34, 0x12, | |
| 3564 // frame type (stop waiting frame) | |
| 3565 0x06, | |
| 3566 // least packet number awaiting an ack, delta from packet number. | |
| 3567 0x08, 0x00, 0x00, 0x00, | |
| 3568 0x00, 0x00, | |
| 3569 }; | |
| 3570 // clang-format on | |
| 3571 | |
| 3572 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 3573 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 3574 | |
| 3575 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 3576 ASSERT_TRUE(visitor_.header_.get()); | |
| 3577 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 3578 !kIncludeDiversificationNonce)); | |
| 3579 | |
| 3580 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | |
| 3581 ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size()); | |
| 3582 const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0]; | |
| 3583 EXPECT_EQ(kLeastUnacked, frame.least_unacked); | |
| 3584 | |
| 3585 const size_t frame_size = 7; | |
| 3586 for (size_t i = kQuicFrameTypeSize; i < frame_size; ++i) { | |
| 3587 string expected_error; | |
| 3588 expected_error = "Unable to read least unacked delta."; | |
| 3589 CheckProcessingFails( | |
| 3590 packet, | |
| 3591 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 3592 !kIncludeVersion, !kIncludePathId, | |
| 3593 !kIncludeDiversificationNonce, | |
| 3594 PACKET_6BYTE_PACKET_NUMBER), | |
| 3595 expected_error, QUIC_INVALID_STOP_WAITING_DATA); | |
| 3596 } | |
| 3597 } | |
| 3598 | |
| 3599 TEST_P(QuicFramerTest, RstStreamFrameQuic) { | |
| 3600 // clang-format off | |
| 3601 unsigned char packet[] = { | |
| 3602 // public flags (8 byte connection_id) | |
| 3603 0x38, | |
| 3604 // connection_id | |
| 3605 0x10, 0x32, 0x54, 0x76, | |
| 3606 0x98, 0xBA, 0xDC, 0xFE, | |
| 3607 // packet number | |
| 3608 0xBC, 0x9A, 0x78, 0x56, | |
| 3609 0x34, 0x12, | |
| 3610 // private flags | |
| 3611 0x00, | |
| 3612 | |
| 3613 // frame type (rst stream frame) | |
| 3614 0x01, | |
| 3615 // stream id | |
| 3616 0x04, 0x03, 0x02, 0x01, | |
| 3617 | |
| 3618 // sent byte offset | |
| 3619 0x54, 0x76, 0x10, 0x32, | |
| 3620 0xDC, 0xFE, 0x98, 0xBA, | |
| 3621 | |
| 3622 // error code | |
| 3623 0x01, 0x00, 0x00, 0x00, | |
| 3624 }; | |
| 3625 unsigned char packet_34[] = { | |
| 3626 // public flags (8 byte connection_id) | |
| 3627 0x38, | |
| 3628 // connection_id | |
| 3629 0x10, 0x32, 0x54, 0x76, | |
| 3630 0x98, 0xBA, 0xDC, 0xFE, | |
| 3631 // packet number | |
| 3632 0xBC, 0x9A, 0x78, 0x56, | |
| 3633 0x34, 0x12, | |
| 3634 | |
| 3635 // frame type (rst stream frame) | |
| 3636 0x01, | |
| 3637 // stream id | |
| 3638 0x04, 0x03, 0x02, 0x01, | |
| 3639 | |
| 3640 // sent byte offset | |
| 3641 0x54, 0x76, 0x10, 0x32, | |
| 3642 0xDC, 0xFE, 0x98, 0xBA, | |
| 3643 | |
| 3644 // error code | |
| 3645 0x01, 0x00, 0x00, 0x00, | |
| 3646 }; | |
| 3647 // clang-format on | |
| 3648 | |
| 3649 QuicEncryptedPacket encrypted( | |
| 3650 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 3651 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 3652 : arraysize(packet_34), | |
| 3653 false); | |
| 3654 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 3655 | |
| 3656 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 3657 ASSERT_TRUE(visitor_.header_.get()); | |
| 3658 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 3659 !kIncludeDiversificationNonce)); | |
| 3660 | |
| 3661 EXPECT_EQ(kStreamId, visitor_.rst_stream_frame_.stream_id); | |
| 3662 EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code); | |
| 3663 EXPECT_EQ(kStreamOffset, visitor_.rst_stream_frame_.byte_offset); | |
| 3664 | |
| 3665 // Now test framing boundaries. | |
| 3666 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetRstStreamFrameSize(); | |
| 3667 ++i) { | |
| 3668 string expected_error; | |
| 3669 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) { | |
| 3670 expected_error = "Unable to read stream_id."; | |
| 3671 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize + | |
| 3672 kQuicMaxStreamOffsetSize) { | |
| 3673 expected_error = "Unable to read rst stream sent byte offset."; | |
| 3674 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize + | |
| 3675 kQuicMaxStreamOffsetSize + kQuicErrorCodeSize) { | |
| 3676 expected_error = "Unable to read rst stream error code."; | |
| 3677 } | |
| 3678 CheckProcessingFails( | |
| 3679 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, | |
| 3680 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 3681 !kIncludeVersion, !kIncludePathId, | |
| 3682 !kIncludeDiversificationNonce, | |
| 3683 PACKET_6BYTE_PACKET_NUMBER), | |
| 3684 expected_error, QUIC_INVALID_RST_STREAM_DATA); | |
| 3685 } | |
| 3686 } | |
| 3687 | |
| 3688 TEST_P(QuicFramerTest, ConnectionCloseFrame) { | |
| 3689 // clang-format off | |
| 3690 unsigned char packet[] = { | |
| 3691 // public flags (8 byte connection_id) | |
| 3692 0x38, | |
| 3693 // connection_id | |
| 3694 0x10, 0x32, 0x54, 0x76, | |
| 3695 0x98, 0xBA, 0xDC, 0xFE, | |
| 3696 // packet number | |
| 3697 0xBC, 0x9A, 0x78, 0x56, | |
| 3698 0x34, 0x12, | |
| 3699 // private flags | |
| 3700 0x00, | |
| 3701 | |
| 3702 // frame type (connection close frame) | |
| 3703 0x02, | |
| 3704 // error code | |
| 3705 0x11, 0x00, 0x00, 0x00, | |
| 3706 | |
| 3707 // error details length | |
| 3708 0x0d, 0x00, | |
| 3709 // error details | |
| 3710 'b', 'e', 'c', 'a', | |
| 3711 'u', 's', 'e', ' ', | |
| 3712 'I', ' ', 'c', 'a', | |
| 3713 'n', | |
| 3714 }; | |
| 3715 unsigned char packet_34[] = { | |
| 3716 // public flags (8 byte connection_id) | |
| 3717 0x38, | |
| 3718 // connection_id | |
| 3719 0x10, 0x32, 0x54, 0x76, | |
| 3720 0x98, 0xBA, 0xDC, 0xFE, | |
| 3721 // packet number | |
| 3722 0xBC, 0x9A, 0x78, 0x56, | |
| 3723 0x34, 0x12, | |
| 3724 | |
| 3725 // frame type (connection close frame) | |
| 3726 0x02, | |
| 3727 // error code | |
| 3728 0x11, 0x00, 0x00, 0x00, | |
| 3729 | |
| 3730 // error details length | |
| 3731 0x0d, 0x00, | |
| 3732 // error details | |
| 3733 'b', 'e', 'c', 'a', | |
| 3734 'u', 's', 'e', ' ', | |
| 3735 'I', ' ', 'c', 'a', | |
| 3736 'n', | |
| 3737 }; | |
| 3738 // clang-format on | |
| 3739 | |
| 3740 QuicEncryptedPacket encrypted( | |
| 3741 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 3742 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 3743 : arraysize(packet_34), | |
| 3744 false); | |
| 3745 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 3746 | |
| 3747 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 3748 ASSERT_TRUE(visitor_.header_.get()); | |
| 3749 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 3750 !kIncludeDiversificationNonce)); | |
| 3751 | |
| 3752 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | |
| 3753 | |
| 3754 EXPECT_EQ(0x11, visitor_.connection_close_frame_.error_code); | |
| 3755 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); | |
| 3756 | |
| 3757 ASSERT_EQ(0u, visitor_.ack_frames_.size()); | |
| 3758 | |
| 3759 // Now test framing boundaries. | |
| 3760 for (size_t i = kQuicFrameTypeSize; | |
| 3761 i < QuicFramer::GetMinConnectionCloseFrameSize(); ++i) { | |
| 3762 string expected_error; | |
| 3763 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) { | |
| 3764 expected_error = "Unable to read connection close error code."; | |
| 3765 } else { | |
| 3766 expected_error = "Unable to read connection close error details."; | |
| 3767 } | |
| 3768 CheckProcessingFails( | |
| 3769 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, | |
| 3770 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 3771 !kIncludeVersion, !kIncludePathId, | |
| 3772 !kIncludeDiversificationNonce, | |
| 3773 PACKET_6BYTE_PACKET_NUMBER), | |
| 3774 expected_error, QUIC_INVALID_CONNECTION_CLOSE_DATA); | |
| 3775 } | |
| 3776 } | |
| 3777 | |
| 3778 TEST_P(QuicFramerTest, GoAwayFrame) { | |
| 3779 // clang-format off | |
| 3780 unsigned char packet[] = { | |
| 3781 // public flags (8 byte connection_id) | |
| 3782 0x38, | |
| 3783 // connection_id | |
| 3784 0x10, 0x32, 0x54, 0x76, | |
| 3785 0x98, 0xBA, 0xDC, 0xFE, | |
| 3786 // packet number | |
| 3787 0xBC, 0x9A, 0x78, 0x56, | |
| 3788 0x34, 0x12, | |
| 3789 // private flags | |
| 3790 0x00, | |
| 3791 | |
| 3792 // frame type (go away frame) | |
| 3793 0x03, | |
| 3794 // error code | |
| 3795 0x09, 0x00, 0x00, 0x00, | |
| 3796 // stream id | |
| 3797 0x04, 0x03, 0x02, 0x01, | |
| 3798 // error details length | |
| 3799 0x0d, 0x00, | |
| 3800 // error details | |
| 3801 'b', 'e', 'c', 'a', | |
| 3802 'u', 's', 'e', ' ', | |
| 3803 'I', ' ', 'c', 'a', | |
| 3804 'n', | |
| 3805 }; | |
| 3806 unsigned char packet_34[] = { | |
| 3807 // public flags (8 byte connection_id) | |
| 3808 0x38, | |
| 3809 // connection_id | |
| 3810 0x10, 0x32, 0x54, 0x76, | |
| 3811 0x98, 0xBA, 0xDC, 0xFE, | |
| 3812 // packet number | |
| 3813 0xBC, 0x9A, 0x78, 0x56, | |
| 3814 0x34, 0x12, | |
| 3815 | |
| 3816 // frame type (go away frame) | |
| 3817 0x03, | |
| 3818 // error code | |
| 3819 0x09, 0x00, 0x00, 0x00, | |
| 3820 // stream id | |
| 3821 0x04, 0x03, 0x02, 0x01, | |
| 3822 // error details length | |
| 3823 0x0d, 0x00, | |
| 3824 // error details | |
| 3825 'b', 'e', 'c', 'a', | |
| 3826 'u', 's', 'e', ' ', | |
| 3827 'I', ' ', 'c', 'a', | |
| 3828 'n', | |
| 3829 }; | |
| 3830 // clang-format on | |
| 3831 | |
| 3832 QuicEncryptedPacket encrypted( | |
| 3833 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 3834 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 3835 : arraysize(packet_34), | |
| 3836 false); | |
| 3837 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 3838 | |
| 3839 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 3840 ASSERT_TRUE(visitor_.header_.get()); | |
| 3841 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 3842 !kIncludeDiversificationNonce)); | |
| 3843 | |
| 3844 EXPECT_EQ(kStreamId, visitor_.goaway_frame_.last_good_stream_id); | |
| 3845 EXPECT_EQ(0x9, visitor_.goaway_frame_.error_code); | |
| 3846 EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase); | |
| 3847 | |
| 3848 const size_t reason_size = arraysize("because I can") - 1; | |
| 3849 // Now test framing boundaries. | |
| 3850 for (size_t i = kQuicFrameTypeSize; | |
| 3851 i < QuicFramer::GetMinGoAwayFrameSize() + reason_size; ++i) { | |
| 3852 string expected_error; | |
| 3853 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) { | |
| 3854 expected_error = "Unable to read go away error code."; | |
| 3855 } else if (i < | |
| 3856 kQuicFrameTypeSize + kQuicErrorCodeSize + kQuicMaxStreamIdSize) { | |
| 3857 expected_error = "Unable to read last good stream id."; | |
| 3858 } else { | |
| 3859 expected_error = "Unable to read goaway reason."; | |
| 3860 } | |
| 3861 CheckProcessingFails( | |
| 3862 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, | |
| 3863 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 3864 !kIncludeVersion, !kIncludePathId, | |
| 3865 !kIncludeDiversificationNonce, | |
| 3866 PACKET_6BYTE_PACKET_NUMBER), | |
| 3867 expected_error, QUIC_INVALID_GOAWAY_DATA); | |
| 3868 } | |
| 3869 } | |
| 3870 | |
| 3871 TEST_P(QuicFramerTest, WindowUpdateFrame) { | |
| 3872 // clang-format off | |
| 3873 unsigned char packet[] = { | |
| 3874 // public flags (8 byte connection_id) | |
| 3875 0x38, | |
| 3876 // connection_id | |
| 3877 0x10, 0x32, 0x54, 0x76, | |
| 3878 0x98, 0xBA, 0xDC, 0xFE, | |
| 3879 // packet number | |
| 3880 0xBC, 0x9A, 0x78, 0x56, | |
| 3881 0x34, 0x12, | |
| 3882 // private flags | |
| 3883 0x00, | |
| 3884 | |
| 3885 // frame type (window update frame) | |
| 3886 0x04, | |
| 3887 // stream id | |
| 3888 0x04, 0x03, 0x02, 0x01, | |
| 3889 // byte offset | |
| 3890 0x54, 0x76, 0x10, 0x32, | |
| 3891 0xDC, 0xFE, 0x98, 0xBA, | |
| 3892 }; | |
| 3893 unsigned char packet_34[] = { | |
| 3894 // public flags (8 byte connection_id) | |
| 3895 0x38, | |
| 3896 // connection_id | |
| 3897 0x10, 0x32, 0x54, 0x76, | |
| 3898 0x98, 0xBA, 0xDC, 0xFE, | |
| 3899 // packet number | |
| 3900 0xBC, 0x9A, 0x78, 0x56, | |
| 3901 0x34, 0x12, | |
| 3902 | |
| 3903 // frame type (window update frame) | |
| 3904 0x04, | |
| 3905 // stream id | |
| 3906 0x04, 0x03, 0x02, 0x01, | |
| 3907 // byte offset | |
| 3908 0x54, 0x76, 0x10, 0x32, | |
| 3909 0xDC, 0xFE, 0x98, 0xBA, | |
| 3910 }; | |
| 3911 // clang-format on | |
| 3912 | |
| 3913 QuicEncryptedPacket encrypted( | |
| 3914 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 3915 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 3916 : arraysize(packet_34), | |
| 3917 false); | |
| 3918 | |
| 3919 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 3920 | |
| 3921 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 3922 ASSERT_TRUE(visitor_.header_.get()); | |
| 3923 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 3924 !kIncludeDiversificationNonce)); | |
| 3925 | |
| 3926 EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id); | |
| 3927 EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset); | |
| 3928 | |
| 3929 // Now test framing boundaries. | |
| 3930 for (size_t i = kQuicFrameTypeSize; | |
| 3931 i < QuicFramer::GetWindowUpdateFrameSize(); ++i) { | |
| 3932 string expected_error; | |
| 3933 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) { | |
| 3934 expected_error = "Unable to read stream_id."; | |
| 3935 } else { | |
| 3936 expected_error = "Unable to read window byte_offset."; | |
| 3937 } | |
| 3938 CheckProcessingFails( | |
| 3939 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, | |
| 3940 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 3941 !kIncludeVersion, !kIncludePathId, | |
| 3942 !kIncludeDiversificationNonce, | |
| 3943 PACKET_6BYTE_PACKET_NUMBER), | |
| 3944 expected_error, QUIC_INVALID_WINDOW_UPDATE_DATA); | |
| 3945 } | |
| 3946 } | |
| 3947 | |
| 3948 TEST_P(QuicFramerTest, BlockedFrame) { | |
| 3949 // clang-format off | |
| 3950 unsigned char packet[] = { | |
| 3951 // public flags (8 byte connection_id) | |
| 3952 0x38, | |
| 3953 // connection_id | |
| 3954 0x10, 0x32, 0x54, 0x76, | |
| 3955 0x98, 0xBA, 0xDC, 0xFE, | |
| 3956 // packet number | |
| 3957 0xBC, 0x9A, 0x78, 0x56, | |
| 3958 0x34, 0x12, | |
| 3959 // private flags | |
| 3960 0x00, | |
| 3961 | |
| 3962 // frame type (blocked frame) | |
| 3963 0x05, | |
| 3964 // stream id | |
| 3965 0x04, 0x03, 0x02, 0x01, | |
| 3966 }; | |
| 3967 unsigned char packet_34[] = { | |
| 3968 // public flags (8 byte connection_id) | |
| 3969 0x38, | |
| 3970 // connection_id | |
| 3971 0x10, 0x32, 0x54, 0x76, | |
| 3972 0x98, 0xBA, 0xDC, 0xFE, | |
| 3973 // packet number | |
| 3974 0xBC, 0x9A, 0x78, 0x56, | |
| 3975 0x34, 0x12, | |
| 3976 | |
| 3977 // frame type (blocked frame) | |
| 3978 0x05, | |
| 3979 // stream id | |
| 3980 0x04, 0x03, 0x02, 0x01, | |
| 3981 }; | |
| 3982 // clang-format on | |
| 3983 | |
| 3984 QuicEncryptedPacket encrypted( | |
| 3985 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 3986 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 3987 : arraysize(packet_34), | |
| 3988 false); | |
| 3989 | |
| 3990 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 3991 | |
| 3992 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 3993 ASSERT_TRUE(visitor_.header_.get()); | |
| 3994 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 3995 !kIncludeDiversificationNonce)); | |
| 3996 | |
| 3997 EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id); | |
| 3998 | |
| 3999 // Now test framing boundaries. | |
| 4000 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetBlockedFrameSize(); | |
| 4001 ++i) { | |
| 4002 string expected_error = "Unable to read stream_id."; | |
| 4003 CheckProcessingFails( | |
| 4004 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, | |
| 4005 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 4006 !kIncludeVersion, !kIncludePathId, | |
| 4007 !kIncludeDiversificationNonce, | |
| 4008 PACKET_6BYTE_PACKET_NUMBER), | |
| 4009 expected_error, QUIC_INVALID_BLOCKED_DATA); | |
| 4010 } | |
| 4011 } | |
| 4012 | |
| 4013 TEST_P(QuicFramerTest, PingFrame) { | |
| 4014 // clang-format off | |
| 4015 unsigned char packet[] = { | |
| 4016 // public flags (8 byte connection_id) | |
| 4017 0x38, | |
| 4018 // connection_id | |
| 4019 0x10, 0x32, 0x54, 0x76, | |
| 4020 0x98, 0xBA, 0xDC, 0xFE, | |
| 4021 // packet number | |
| 4022 0xBC, 0x9A, 0x78, 0x56, | |
| 4023 0x34, 0x12, | |
| 4024 // private flags | |
| 4025 0x00, | |
| 4026 | |
| 4027 // frame type (ping frame) | |
| 4028 0x07, | |
| 4029 }; | |
| 4030 unsigned char packet_34[] = { | |
| 4031 // public flags (8 byte connection_id) | |
| 4032 0x38, | |
| 4033 // connection_id | |
| 4034 0x10, 0x32, 0x54, 0x76, | |
| 4035 0x98, 0xBA, 0xDC, 0xFE, | |
| 4036 // packet number | |
| 4037 0xBC, 0x9A, 0x78, 0x56, | |
| 4038 0x34, 0x12, | |
| 4039 | |
| 4040 // frame type (ping frame) | |
| 4041 0x07, | |
| 4042 }; | |
| 4043 // clang-format on | |
| 4044 | |
| 4045 QuicEncryptedPacket encrypted( | |
| 4046 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 4047 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 4048 : arraysize(packet_34), | |
| 4049 false); | |
| 4050 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 4051 | |
| 4052 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 4053 ASSERT_TRUE(visitor_.header_.get()); | |
| 4054 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, | |
| 4055 !kIncludeDiversificationNonce)); | |
| 4056 | |
| 4057 EXPECT_EQ(1u, visitor_.ping_frames_.size()); | |
| 4058 | |
| 4059 // No need to check the PING frame boundaries because it has no payload. | |
| 4060 } | |
| 4061 | |
| 4062 TEST_P(QuicFramerTest, PathCloseFrame) { | |
| 4063 // clang-format off | |
| 4064 unsigned char packet[] = { | |
| 4065 // public flags (version) | |
| 4066 0x78, | |
| 4067 // connection_id | |
| 4068 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 4069 // path_id | |
| 4070 0x00, | |
| 4071 // packet number | |
| 4072 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 4073 // private flags | |
| 4074 0x00, | |
| 4075 | |
| 4076 // frame type (path_close_frame) | |
| 4077 0x08, | |
| 4078 // path id | |
| 4079 0x42, | |
| 4080 }; | |
| 4081 unsigned char packet_34[] = { | |
| 4082 // public flags (version) | |
| 4083 0x78, | |
| 4084 // connection_id | |
| 4085 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 4086 // path_id | |
| 4087 0x00, | |
| 4088 // packet number | |
| 4089 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 4090 | |
| 4091 // frame type (path_close_frame) | |
| 4092 0x08, | |
| 4093 // path id | |
| 4094 0x42, | |
| 4095 }; | |
| 4096 // clang-format on | |
| 4097 | |
| 4098 QuicEncryptedPacket encrypted( | |
| 4099 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 4100 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 4101 : arraysize(packet_34), | |
| 4102 false); | |
| 4103 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 4104 | |
| 4105 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 4106 ASSERT_TRUE(visitor_.header_.get()); | |
| 4107 // TODO(fayang): CheckDecryption after cl/110553865 is landed. | |
| 4108 EXPECT_EQ(kPathId, visitor_.path_close_frame_.path_id); | |
| 4109 | |
| 4110 // Now test framing boundaries. | |
| 4111 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetPathCloseFrameSize(); | |
| 4112 ++i) { | |
| 4113 string expected_error; | |
| 4114 if (i < kQuicFrameTypeSize + kQuicPathIdSize) { | |
| 4115 expected_error = "Unable to read path_id."; | |
| 4116 } | |
| 4117 CheckProcessingFails( | |
| 4118 framer_.version() <= QUIC_VERSION_33 ? packet : packet_34, | |
| 4119 i + GetPacketHeaderSize(framer_.version(), PACKET_8BYTE_CONNECTION_ID, | |
| 4120 !kIncludeVersion, kIncludePathId, | |
| 4121 !kIncludeDiversificationNonce, | |
| 4122 PACKET_6BYTE_PACKET_NUMBER), | |
| 4123 expected_error, QUIC_INVALID_PATH_CLOSE_DATA); | |
| 4124 } | |
| 4125 } | |
| 4126 | |
| 4127 TEST_P(QuicFramerTest, PublicResetPacketV33) { | |
| 4128 // clang-format off | |
| 4129 unsigned char packet[] = { | |
| 4130 // public flags (public reset, 8 byte connection_id) | |
| 4131 0x0A, | |
| 4132 // connection_id | |
| 4133 0x10, 0x32, 0x54, 0x76, | |
| 4134 0x98, 0xBA, 0xDC, 0xFE, | |
| 4135 // message tag (kPRST) | |
| 4136 'P', 'R', 'S', 'T', | |
| 4137 // num_entries (2) + padding | |
| 4138 0x02, 0x00, 0x00, 0x00, | |
| 4139 // tag kRNON | |
| 4140 'R', 'N', 'O', 'N', | |
| 4141 // end offset 8 | |
| 4142 0x08, 0x00, 0x00, 0x00, | |
| 4143 // tag kRSEQ | |
| 4144 'R', 'S', 'E', 'Q', | |
| 4145 // end offset 16 | |
| 4146 0x10, 0x00, 0x00, 0x00, | |
| 4147 // nonce proof | |
| 4148 0x89, 0x67, 0x45, 0x23, | |
| 4149 0x01, 0xEF, 0xCD, 0xAB, | |
| 4150 // rejected packet number | |
| 4151 0xBC, 0x9A, 0x78, 0x56, | |
| 4152 0x34, 0x12, 0x00, 0x00, | |
| 4153 }; | |
| 4154 // clang-format on | |
| 4155 | |
| 4156 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 4157 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 4158 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 4159 ASSERT_TRUE(visitor_.public_reset_packet_.get()); | |
| 4160 EXPECT_EQ(kConnectionId, | |
| 4161 visitor_.public_reset_packet_->public_header.connection_id); | |
| 4162 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); | |
| 4163 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); | |
| 4164 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); | |
| 4165 EXPECT_EQ(0u, visitor_.public_reset_packet_->rejected_packet_number); | |
| 4166 EXPECT_EQ(ADDRESS_FAMILY_UNSPECIFIED, | |
| 4167 visitor_.public_reset_packet_->client_address.GetFamily()); | |
| 4168 | |
| 4169 // Now test framing boundaries. | |
| 4170 for (size_t i = 0; i < arraysize(packet); ++i) { | |
| 4171 string expected_error; | |
| 4172 DVLOG(1) << "iteration: " << i; | |
| 4173 if (i < kConnectionIdOffset) { | |
| 4174 expected_error = "Unable to read public flags."; | |
| 4175 CheckProcessingFails(packet, i, expected_error, | |
| 4176 QUIC_INVALID_PACKET_HEADER); | |
| 4177 } else if (i < kPublicResetPacketMessageTagOffset) { | |
| 4178 expected_error = "Unable to read ConnectionId."; | |
| 4179 CheckProcessingFails(packet, i, expected_error, | |
| 4180 QUIC_INVALID_PACKET_HEADER); | |
| 4181 } else { | |
| 4182 expected_error = "Unable to read reset message."; | |
| 4183 CheckProcessingFails(packet, i, expected_error, | |
| 4184 QUIC_INVALID_PUBLIC_RST_PACKET); | |
| 4185 } | |
| 4186 } | |
| 4187 } | |
| 4188 | |
| 4189 TEST_P(QuicFramerTest, PublicResetPacket) { | |
| 4190 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); | |
| 4191 | |
| 4192 // clang-format off | |
| 4193 unsigned char packet[] = { | |
| 4194 // public flags (public reset, 8 byte connection_id) | |
| 4195 0x0E, | |
| 4196 // connection_id | |
| 4197 0x10, 0x32, 0x54, 0x76, | |
| 4198 0x98, 0xBA, 0xDC, 0xFE, | |
| 4199 // message tag (kPRST) | |
| 4200 'P', 'R', 'S', 'T', | |
| 4201 // num_entries (2) + padding | |
| 4202 0x02, 0x00, 0x00, 0x00, | |
| 4203 // tag kRNON | |
| 4204 'R', 'N', 'O', 'N', | |
| 4205 // end offset 8 | |
| 4206 0x08, 0x00, 0x00, 0x00, | |
| 4207 // tag kRSEQ | |
| 4208 'R', 'S', 'E', 'Q', | |
| 4209 // end offset 16 | |
| 4210 0x10, 0x00, 0x00, 0x00, | |
| 4211 // nonce proof | |
| 4212 0x89, 0x67, 0x45, 0x23, | |
| 4213 0x01, 0xEF, 0xCD, 0xAB, | |
| 4214 // rejected packet number | |
| 4215 0xBC, 0x9A, 0x78, 0x56, | |
| 4216 0x34, 0x12, 0x00, 0x00, | |
| 4217 }; | |
| 4218 // clang-format on | |
| 4219 | |
| 4220 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 4221 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 4222 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 4223 ASSERT_TRUE(visitor_.public_reset_packet_.get()); | |
| 4224 EXPECT_EQ(kConnectionId, | |
| 4225 visitor_.public_reset_packet_->public_header.connection_id); | |
| 4226 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); | |
| 4227 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); | |
| 4228 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); | |
| 4229 EXPECT_EQ(0u, visitor_.public_reset_packet_->rejected_packet_number); | |
| 4230 EXPECT_EQ(ADDRESS_FAMILY_UNSPECIFIED, | |
| 4231 visitor_.public_reset_packet_->client_address.GetFamily()); | |
| 4232 | |
| 4233 // Now test framing boundaries. | |
| 4234 for (size_t i = 0; i < arraysize(packet); ++i) { | |
| 4235 string expected_error; | |
| 4236 DVLOG(1) << "iteration: " << i; | |
| 4237 if (i < kConnectionIdOffset) { | |
| 4238 expected_error = "Unable to read public flags."; | |
| 4239 CheckProcessingFails(packet, i, expected_error, | |
| 4240 QUIC_INVALID_PACKET_HEADER); | |
| 4241 } else if (i < kPublicResetPacketMessageTagOffset) { | |
| 4242 expected_error = "Unable to read ConnectionId."; | |
| 4243 CheckProcessingFails(packet, i, expected_error, | |
| 4244 QUIC_INVALID_PACKET_HEADER); | |
| 4245 } else { | |
| 4246 expected_error = "Unable to read reset message."; | |
| 4247 CheckProcessingFails(packet, i, expected_error, | |
| 4248 QUIC_INVALID_PUBLIC_RST_PACKET); | |
| 4249 } | |
| 4250 } | |
| 4251 } | |
| 4252 | |
| 4253 TEST_P(QuicFramerTest, PublicResetPacketWithTrailingJunk) { | |
| 4254 // clang-format off | |
| 4255 unsigned char packet[] = { | |
| 4256 // public flags (public reset, 8 byte connection_id) | |
| 4257 0x0A, | |
| 4258 // connection_id | |
| 4259 0x10, 0x32, 0x54, 0x76, | |
| 4260 0x98, 0xBA, 0xDC, 0xFE, | |
| 4261 // message tag (kPRST) | |
| 4262 'P', 'R', 'S', 'T', | |
| 4263 // num_entries (2) + padding | |
| 4264 0x02, 0x00, 0x00, 0x00, | |
| 4265 // tag kRNON | |
| 4266 'R', 'N', 'O', 'N', | |
| 4267 // end offset 8 | |
| 4268 0x08, 0x00, 0x00, 0x00, | |
| 4269 // tag kRSEQ | |
| 4270 'R', 'S', 'E', 'Q', | |
| 4271 // end offset 16 | |
| 4272 0x10, 0x00, 0x00, 0x00, | |
| 4273 // nonce proof | |
| 4274 0x89, 0x67, 0x45, 0x23, | |
| 4275 0x01, 0xEF, 0xCD, 0xAB, | |
| 4276 // rejected packet number | |
| 4277 0xBC, 0x9A, 0x78, 0x56, | |
| 4278 0x34, 0x12, 0x00, 0x00, | |
| 4279 // trailing junk | |
| 4280 'j', 'u', 'n', 'k', | |
| 4281 }; | |
| 4282 // clang-format on | |
| 4283 | |
| 4284 string expected_error = "Unable to read reset message."; | |
| 4285 CheckProcessingFails(packet, arraysize(packet), expected_error, | |
| 4286 QUIC_INVALID_PUBLIC_RST_PACKET); | |
| 4287 } | |
| 4288 | |
| 4289 TEST_P(QuicFramerTest, PublicResetPacketWithClientAddress) { | |
| 4290 // clang-format off | |
| 4291 unsigned char packet[] = { | |
| 4292 // public flags (public reset, 8 byte connection_id) | |
| 4293 0x0A, | |
| 4294 // connection_id | |
| 4295 0x10, 0x32, 0x54, 0x76, | |
| 4296 0x98, 0xBA, 0xDC, 0xFE, | |
| 4297 // message tag (kPRST) | |
| 4298 'P', 'R', 'S', 'T', | |
| 4299 // num_entries (3) + padding | |
| 4300 0x03, 0x00, 0x00, 0x00, | |
| 4301 // tag kRNON | |
| 4302 'R', 'N', 'O', 'N', | |
| 4303 // end offset 8 | |
| 4304 0x08, 0x00, 0x00, 0x00, | |
| 4305 // tag kRSEQ | |
| 4306 'R', 'S', 'E', 'Q', | |
| 4307 // end offset 16 | |
| 4308 0x10, 0x00, 0x00, 0x00, | |
| 4309 // tag kCADR | |
| 4310 'C', 'A', 'D', 'R', | |
| 4311 // end offset 24 | |
| 4312 0x18, 0x00, 0x00, 0x00, | |
| 4313 // nonce proof | |
| 4314 0x89, 0x67, 0x45, 0x23, | |
| 4315 0x01, 0xEF, 0xCD, 0xAB, | |
| 4316 // rejected packet number | |
| 4317 0xBC, 0x9A, 0x78, 0x56, | |
| 4318 0x34, 0x12, 0x00, 0x00, | |
| 4319 // client address: 4.31.198.44:443 | |
| 4320 0x02, 0x00, | |
| 4321 0x04, 0x1F, 0xC6, 0x2C, | |
| 4322 0xBB, 0x01, | |
| 4323 }; | |
| 4324 // clang-format on | |
| 4325 | |
| 4326 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 4327 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 4328 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 4329 ASSERT_TRUE(visitor_.public_reset_packet_.get()); | |
| 4330 EXPECT_EQ(kConnectionId, | |
| 4331 visitor_.public_reset_packet_->public_header.connection_id); | |
| 4332 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); | |
| 4333 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); | |
| 4334 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); | |
| 4335 EXPECT_EQ(0u, visitor_.public_reset_packet_->rejected_packet_number); | |
| 4336 EXPECT_EQ("4.31.198.44", | |
| 4337 visitor_.public_reset_packet_->client_address.address().ToString()); | |
| 4338 EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port()); | |
| 4339 | |
| 4340 // Now test framing boundaries. | |
| 4341 for (size_t i = 0; i < arraysize(packet); ++i) { | |
| 4342 string expected_error; | |
| 4343 DVLOG(1) << "iteration: " << i; | |
| 4344 if (i < kConnectionIdOffset) { | |
| 4345 expected_error = "Unable to read public flags."; | |
| 4346 CheckProcessingFails(packet, i, expected_error, | |
| 4347 QUIC_INVALID_PACKET_HEADER); | |
| 4348 } else if (i < kPublicResetPacketMessageTagOffset) { | |
| 4349 expected_error = "Unable to read ConnectionId."; | |
| 4350 CheckProcessingFails(packet, i, expected_error, | |
| 4351 QUIC_INVALID_PACKET_HEADER); | |
| 4352 } else { | |
| 4353 expected_error = "Unable to read reset message."; | |
| 4354 CheckProcessingFails(packet, i, expected_error, | |
| 4355 QUIC_INVALID_PUBLIC_RST_PACKET); | |
| 4356 } | |
| 4357 } | |
| 4358 } | |
| 4359 | |
| 4360 TEST_P(QuicFramerTest, VersionNegotiationPacket) { | |
| 4361 // clang-format off | |
| 4362 unsigned char packet[] = { | |
| 4363 // public flags (version, 8 byte connection_id) | |
| 4364 0x39, | |
| 4365 // connection_id | |
| 4366 0x10, 0x32, 0x54, 0x76, | |
| 4367 0x98, 0xBA, 0xDC, 0xFE, | |
| 4368 // version tag | |
| 4369 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | |
| 4370 'Q', '2', '.', '0', | |
| 4371 }; | |
| 4372 // clang-format on | |
| 4373 | |
| 4374 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); | |
| 4375 | |
| 4376 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 4377 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 4378 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 4379 ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); | |
| 4380 EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size()); | |
| 4381 EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]); | |
| 4382 | |
| 4383 for (size_t i = 0; i <= kPublicFlagsSize + PACKET_8BYTE_CONNECTION_ID; ++i) { | |
| 4384 string expected_error; | |
| 4385 QuicErrorCode error_code = QUIC_INVALID_PACKET_HEADER; | |
| 4386 if (i < kConnectionIdOffset) { | |
| 4387 expected_error = "Unable to read public flags."; | |
| 4388 } else if (i < kVersionOffset) { | |
| 4389 expected_error = "Unable to read ConnectionId."; | |
| 4390 } else { | |
| 4391 expected_error = "Unable to read supported version in negotiation."; | |
| 4392 error_code = QUIC_INVALID_VERSION_NEGOTIATION_PACKET; | |
| 4393 } | |
| 4394 CheckProcessingFails(packet, i, expected_error, error_code); | |
| 4395 } | |
| 4396 } | |
| 4397 | |
| 4398 TEST_P(QuicFramerTest, OldVersionNegotiationPacket) { | |
| 4399 // clang-format off | |
| 4400 unsigned char packet[] = { | |
| 4401 // public flags (version, 8 byte connection_id) | |
| 4402 0x3D, | |
| 4403 // connection_id | |
| 4404 0x10, 0x32, 0x54, 0x76, | |
| 4405 0x98, 0xBA, 0xDC, 0xFE, | |
| 4406 // version tag | |
| 4407 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | |
| 4408 'Q', '2', '.', '0', | |
| 4409 }; | |
| 4410 // clang-format on | |
| 4411 | |
| 4412 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); | |
| 4413 | |
| 4414 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 4415 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 4416 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 4417 ASSERT_TRUE(visitor_.version_negotiation_packet_.get()); | |
| 4418 EXPECT_EQ(2u, visitor_.version_negotiation_packet_->versions.size()); | |
| 4419 EXPECT_EQ(GetParam(), visitor_.version_negotiation_packet_->versions[0]); | |
| 4420 | |
| 4421 for (size_t i = 0; i <= kPublicFlagsSize + PACKET_8BYTE_CONNECTION_ID; ++i) { | |
| 4422 string expected_error; | |
| 4423 QuicErrorCode error_code = QUIC_INVALID_PACKET_HEADER; | |
| 4424 if (i < kConnectionIdOffset) { | |
| 4425 expected_error = "Unable to read public flags."; | |
| 4426 } else if (i < kVersionOffset) { | |
| 4427 expected_error = "Unable to read ConnectionId."; | |
| 4428 } else { | |
| 4429 expected_error = "Unable to read supported version in negotiation."; | |
| 4430 error_code = QUIC_INVALID_VERSION_NEGOTIATION_PACKET; | |
| 4431 } | |
| 4432 CheckProcessingFails(packet, i, expected_error, error_code); | |
| 4433 } | |
| 4434 } | |
| 4435 | |
| 4436 TEST_P(QuicFramerTest, DropFecPacket) { | |
| 4437 // clang-format off | |
| 4438 unsigned char packet[] = { | |
| 4439 // public flags (8 byte connection_id) | |
| 4440 0x38, | |
| 4441 // connection_id | |
| 4442 0x10, 0x32, 0x54, 0x76, | |
| 4443 0x98, 0xBA, 0xDC, 0xFE, | |
| 4444 // packet number | |
| 4445 0xBC, 0x9A, 0x78, 0x56, | |
| 4446 0x34, 0x12, | |
| 4447 // private flags (fec group & FEC) | |
| 4448 0x06, | |
| 4449 // first fec protected packet offset | |
| 4450 0x01, | |
| 4451 | |
| 4452 // redundancy | |
| 4453 'a', 'b', 'c', 'd', | |
| 4454 'e', 'f', 'g', 'h', | |
| 4455 'i', 'j', 'k', 'l', | |
| 4456 'm', 'n', 'o', 'p', | |
| 4457 }; | |
| 4458 if (framer_.version() > QUIC_VERSION_33) { | |
| 4459 return; | |
| 4460 } | |
| 4461 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 4462 if (framer_.version() <= QUIC_VERSION_31) { | |
| 4463 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 4464 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 4465 } else { | |
| 4466 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | |
| 4467 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); | |
| 4468 } | |
| 4469 EXPECT_FALSE(visitor_.header_.get()); | |
| 4470 } | |
| 4471 | |
| 4472 TEST_P(QuicFramerTest, BuildPaddingFramePacket) { | |
| 4473 QuicPacketHeader header; | |
| 4474 header.public_header.connection_id = kConnectionId; | |
| 4475 header.public_header.reset_flag = false; | |
| 4476 header.public_header.version_flag = false; | |
| 4477 header.fec_flag = false; | |
| 4478 header.entropy_flag = false; | |
| 4479 header.packet_number = kPacketNumber; | |
| 4480 | |
| 4481 QuicPaddingFrame padding_frame; | |
| 4482 | |
| 4483 QuicFrames frames; | |
| 4484 frames.push_back(QuicFrame(padding_frame)); | |
| 4485 | |
| 4486 // clang-format off | |
| 4487 unsigned char packet[kMaxPacketSize] = { | |
| 4488 // public flags (8 byte connection_id) | |
| 4489 static_cast<unsigned char>( | |
| 4490 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 4491 // connection_id | |
| 4492 0x10, 0x32, 0x54, 0x76, | |
| 4493 0x98, 0xBA, 0xDC, 0xFE, | |
| 4494 // packet number | |
| 4495 0xBC, 0x9A, 0x78, 0x56, | |
| 4496 0x34, 0x12, | |
| 4497 // private flags | |
| 4498 0x00, | |
| 4499 | |
| 4500 // frame type (padding frame) | |
| 4501 0x00, | |
| 4502 0x00, 0x00, 0x00, 0x00 | |
| 4503 }; | |
| 4504 unsigned char packet_34[kMaxPacketSize] = { | |
| 4505 // public flags (8 byte connection_id) | |
| 4506 0x38, | |
| 4507 // connection_id | |
| 4508 0x10, 0x32, 0x54, 0x76, | |
| 4509 0x98, 0xBA, 0xDC, 0xFE, | |
| 4510 // packet number | |
| 4511 0xBC, 0x9A, 0x78, 0x56, | |
| 4512 0x34, 0x12, | |
| 4513 | |
| 4514 // frame type (padding frame) | |
| 4515 0x00, | |
| 4516 0x00, 0x00, 0x00, 0x00 | |
| 4517 }; | |
| 4518 // clang-format on | |
| 4519 | |
| 4520 uint64_t header_size = GetPacketHeaderSize( | |
| 4521 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | |
| 4522 !kIncludePathId, !kIncludeDiversificationNonce, | |
| 4523 PACKET_6BYTE_PACKET_NUMBER); | |
| 4524 memset((framer_.version() <= QUIC_VERSION_33 ? packet : packet_34) + | |
| 4525 header_size + 1, | |
| 4526 0x00, kMaxPacketSize - header_size - 1); | |
| 4527 | |
| 4528 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 4529 ASSERT_TRUE(data != nullptr); | |
| 4530 | |
| 4531 test::CompareCharArraysWithHexError( | |
| 4532 "constructed packet", data->data(), data->length(), | |
| 4533 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 4534 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 4535 : arraysize(packet_34)); | |
| 4536 } | |
| 4537 | |
| 4538 TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) { | |
| 4539 QuicPacketHeader header; | |
| 4540 header.public_header.connection_id = kConnectionId; | |
| 4541 header.public_header.reset_flag = false; | |
| 4542 header.public_header.version_flag = false; | |
| 4543 header.fec_flag = false; | |
| 4544 header.entropy_flag = false; | |
| 4545 header.public_header.packet_number_length = PACKET_4BYTE_PACKET_NUMBER; | |
| 4546 header.packet_number = kPacketNumber; | |
| 4547 | |
| 4548 QuicPaddingFrame padding_frame; | |
| 4549 | |
| 4550 QuicFrames frames; | |
| 4551 frames.push_back(QuicFrame(padding_frame)); | |
| 4552 | |
| 4553 // clang-format off | |
| 4554 unsigned char packet[kMaxPacketSize] = { | |
| 4555 // public flags (8 byte connection_id and 4 byte packet number) | |
| 4556 static_cast<unsigned char>( | |
| 4557 framer_.version() > QUIC_VERSION_32 ? 0x28 : 0x2C), | |
| 4558 // connection_id | |
| 4559 0x10, 0x32, 0x54, 0x76, | |
| 4560 0x98, 0xBA, 0xDC, 0xFE, | |
| 4561 // packet number | |
| 4562 0xBC, 0x9A, 0x78, 0x56, | |
| 4563 // private flags | |
| 4564 0x00, | |
| 4565 | |
| 4566 // frame type (padding frame) | |
| 4567 0x00, | |
| 4568 0x00, 0x00, 0x00, 0x00 | |
| 4569 }; | |
| 4570 unsigned char packet_34[kMaxPacketSize] = { | |
| 4571 // public flags (8 byte connection_id and 4 byte packet number) | |
| 4572 0x28, | |
| 4573 // connection_id | |
| 4574 0x10, 0x32, 0x54, 0x76, | |
| 4575 0x98, 0xBA, 0xDC, 0xFE, | |
| 4576 // packet number | |
| 4577 0xBC, 0x9A, 0x78, 0x56, | |
| 4578 | |
| 4579 // frame type (padding frame) | |
| 4580 0x00, | |
| 4581 0x00, 0x00, 0x00, 0x00 | |
| 4582 }; | |
| 4583 // clang-format on | |
| 4584 | |
| 4585 uint64_t header_size = GetPacketHeaderSize( | |
| 4586 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | |
| 4587 !kIncludePathId, !kIncludeDiversificationNonce, | |
| 4588 PACKET_4BYTE_PACKET_NUMBER); | |
| 4589 memset((framer_.version() <= QUIC_VERSION_33 ? packet : packet_34) + | |
| 4590 header_size + 1, | |
| 4591 0x00, kMaxPacketSize - header_size - 1); | |
| 4592 | |
| 4593 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 4594 ASSERT_TRUE(data != nullptr); | |
| 4595 | |
| 4596 test::CompareCharArraysWithHexError( | |
| 4597 "constructed packet", data->data(), data->length(), | |
| 4598 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 4599 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 4600 : arraysize(packet_34)); | |
| 4601 } | |
| 4602 | |
| 4603 TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) { | |
| 4604 QuicPacketHeader header; | |
| 4605 header.public_header.connection_id = kConnectionId; | |
| 4606 header.public_header.reset_flag = false; | |
| 4607 header.public_header.version_flag = false; | |
| 4608 header.fec_flag = false; | |
| 4609 header.entropy_flag = false; | |
| 4610 header.public_header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER; | |
| 4611 header.packet_number = kPacketNumber; | |
| 4612 | |
| 4613 QuicPaddingFrame padding_frame; | |
| 4614 | |
| 4615 QuicFrames frames; | |
| 4616 frames.push_back(QuicFrame(padding_frame)); | |
| 4617 | |
| 4618 // clang-format off | |
| 4619 unsigned char packet[kMaxPacketSize] = { | |
| 4620 // public flags (8 byte connection_id and 2 byte packet number) | |
| 4621 static_cast<unsigned char>( | |
| 4622 framer_.version() > QUIC_VERSION_32 ? 0x18 : 0x1C), | |
| 4623 // connection_id | |
| 4624 0x10, 0x32, 0x54, 0x76, | |
| 4625 0x98, 0xBA, 0xDC, 0xFE, | |
| 4626 // packet number | |
| 4627 0xBC, 0x9A, | |
| 4628 // private flags | |
| 4629 0x00, | |
| 4630 | |
| 4631 // frame type (padding frame) | |
| 4632 0x00, | |
| 4633 0x00, 0x00, 0x00, 0x00 | |
| 4634 }; | |
| 4635 unsigned char packet_34[kMaxPacketSize] = { | |
| 4636 // public flags (8 byte connection_id and 2 byte packet number) | |
| 4637 0x18, | |
| 4638 // connection_id | |
| 4639 0x10, 0x32, 0x54, 0x76, | |
| 4640 0x98, 0xBA, 0xDC, 0xFE, | |
| 4641 // packet number | |
| 4642 0xBC, 0x9A, | |
| 4643 | |
| 4644 // frame type (padding frame) | |
| 4645 0x00, | |
| 4646 0x00, 0x00, 0x00, 0x00 | |
| 4647 }; | |
| 4648 // clang-format on | |
| 4649 | |
| 4650 uint64_t header_size = GetPacketHeaderSize( | |
| 4651 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | |
| 4652 !kIncludePathId, !kIncludeDiversificationNonce, | |
| 4653 PACKET_2BYTE_PACKET_NUMBER); | |
| 4654 memset((framer_.version() <= QUIC_VERSION_33 ? packet : packet_34) + | |
| 4655 header_size + 1, | |
| 4656 0x00, kMaxPacketSize - header_size - 1); | |
| 4657 | |
| 4658 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 4659 ASSERT_TRUE(data != nullptr); | |
| 4660 | |
| 4661 test::CompareCharArraysWithHexError( | |
| 4662 "constructed packet", data->data(), data->length(), | |
| 4663 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 4664 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 4665 : arraysize(packet_34)); | |
| 4666 } | |
| 4667 | |
| 4668 TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) { | |
| 4669 QuicPacketHeader header; | |
| 4670 header.public_header.connection_id = kConnectionId; | |
| 4671 header.public_header.reset_flag = false; | |
| 4672 header.public_header.version_flag = false; | |
| 4673 header.fec_flag = false; | |
| 4674 header.entropy_flag = false; | |
| 4675 header.public_header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; | |
| 4676 header.packet_number = kPacketNumber; | |
| 4677 | |
| 4678 QuicPaddingFrame padding_frame; | |
| 4679 | |
| 4680 QuicFrames frames; | |
| 4681 frames.push_back(QuicFrame(padding_frame)); | |
| 4682 | |
| 4683 // clang-format off | |
| 4684 unsigned char packet[kMaxPacketSize] = { | |
| 4685 // public flags (8 byte connection_id and 1 byte packet number) | |
| 4686 static_cast<unsigned char>( | |
| 4687 framer_.version() > QUIC_VERSION_32 ? 0x08 : 0x0C), | |
| 4688 // connection_id | |
| 4689 0x10, 0x32, 0x54, 0x76, | |
| 4690 0x98, 0xBA, 0xDC, 0xFE, | |
| 4691 // packet number | |
| 4692 0xBC, | |
| 4693 // private flags | |
| 4694 0x00, | |
| 4695 | |
| 4696 // frame type (padding frame) | |
| 4697 0x00, | |
| 4698 0x00, 0x00, 0x00, 0x00 | |
| 4699 }; | |
| 4700 unsigned char packet_34[kMaxPacketSize] = { | |
| 4701 // public flags (8 byte connection_id and 1 byte packet number) | |
| 4702 0x08, | |
| 4703 // connection_id | |
| 4704 0x10, 0x32, 0x54, 0x76, | |
| 4705 0x98, 0xBA, 0xDC, 0xFE, | |
| 4706 // packet number | |
| 4707 0xBC, | |
| 4708 | |
| 4709 // frame type (padding frame) | |
| 4710 0x00, | |
| 4711 0x00, 0x00, 0x00, 0x00 | |
| 4712 }; | |
| 4713 // clang-format on | |
| 4714 | |
| 4715 uint64_t header_size = GetPacketHeaderSize( | |
| 4716 framer_.version(), PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | |
| 4717 !kIncludePathId, !kIncludeDiversificationNonce, | |
| 4718 PACKET_1BYTE_PACKET_NUMBER); | |
| 4719 memset((framer_.version() <= QUIC_VERSION_33 ? packet : packet_34) + | |
| 4720 header_size + 1, | |
| 4721 0x00, kMaxPacketSize - header_size - 1); | |
| 4722 | |
| 4723 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 4724 ASSERT_TRUE(data != nullptr); | |
| 4725 | |
| 4726 test::CompareCharArraysWithHexError( | |
| 4727 "constructed packet", data->data(), data->length(), | |
| 4728 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 4729 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 4730 : arraysize(packet_34)); | |
| 4731 } | |
| 4732 | |
| 4733 TEST_P(QuicFramerTest, BuildStreamFramePacket) { | |
| 4734 QuicPacketHeader header; | |
| 4735 header.public_header.connection_id = kConnectionId; | |
| 4736 header.public_header.reset_flag = false; | |
| 4737 header.public_header.version_flag = false; | |
| 4738 header.fec_flag = false; | |
| 4739 header.entropy_flag = true; | |
| 4740 header.packet_number = kPacketNumber; | |
| 4741 | |
| 4742 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, | |
| 4743 StringPiece("hello world!")); | |
| 4744 | |
| 4745 QuicFrames frames; | |
| 4746 frames.push_back(QuicFrame(&stream_frame)); | |
| 4747 | |
| 4748 // clang-format off | |
| 4749 unsigned char packet[] = { | |
| 4750 // public flags (8 byte connection_id) | |
| 4751 static_cast<unsigned char>( | |
| 4752 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 4753 // connection_id | |
| 4754 0x10, 0x32, 0x54, 0x76, | |
| 4755 0x98, 0xBA, 0xDC, 0xFE, | |
| 4756 // packet number | |
| 4757 0xBC, 0x9A, 0x78, 0x56, | |
| 4758 0x34, 0x12, | |
| 4759 // private flags (entropy) | |
| 4760 0x01, | |
| 4761 | |
| 4762 // frame type (stream frame with fin and no length) | |
| 4763 0xDF, | |
| 4764 // stream id | |
| 4765 0x04, 0x03, 0x02, 0x01, | |
| 4766 // offset | |
| 4767 0x54, 0x76, 0x10, 0x32, | |
| 4768 0xDC, 0xFE, 0x98, 0xBA, | |
| 4769 // data | |
| 4770 'h', 'e', 'l', 'l', | |
| 4771 'o', ' ', 'w', 'o', | |
| 4772 'r', 'l', 'd', '!', | |
| 4773 }; | |
| 4774 unsigned char packet_34[] = { | |
| 4775 // public flags (8 byte connection_id) | |
| 4776 0x38, | |
| 4777 // connection_id | |
| 4778 0x10, 0x32, 0x54, 0x76, | |
| 4779 0x98, 0xBA, 0xDC, 0xFE, | |
| 4780 // packet number | |
| 4781 0xBC, 0x9A, 0x78, 0x56, | |
| 4782 0x34, 0x12, | |
| 4783 | |
| 4784 // frame type (stream frame with fin and no length) | |
| 4785 0xDF, | |
| 4786 // stream id | |
| 4787 0x04, 0x03, 0x02, 0x01, | |
| 4788 // offset | |
| 4789 0x54, 0x76, 0x10, 0x32, | |
| 4790 0xDC, 0xFE, 0x98, 0xBA, | |
| 4791 // data | |
| 4792 'h', 'e', 'l', 'l', | |
| 4793 'o', ' ', 'w', 'o', | |
| 4794 'r', 'l', 'd', '!', | |
| 4795 }; | |
| 4796 // clang-format on | |
| 4797 | |
| 4798 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 4799 ASSERT_TRUE(data != nullptr); | |
| 4800 | |
| 4801 test::CompareCharArraysWithHexError( | |
| 4802 "constructed packet", data->data(), data->length(), | |
| 4803 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 4804 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 4805 : arraysize(packet_34)); | |
| 4806 } | |
| 4807 | |
| 4808 TEST_P(QuicFramerTest, BuildStreamFramePacketWithVersionFlag) { | |
| 4809 QuicPacketHeader header; | |
| 4810 header.public_header.connection_id = kConnectionId; | |
| 4811 header.public_header.reset_flag = false; | |
| 4812 header.public_header.version_flag = true; | |
| 4813 header.fec_flag = false; | |
| 4814 header.entropy_flag = true; | |
| 4815 header.packet_number = kPacketNumber; | |
| 4816 | |
| 4817 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, | |
| 4818 StringPiece("hello world!")); | |
| 4819 | |
| 4820 QuicFrames frames; | |
| 4821 frames.push_back(QuicFrame(&stream_frame)); | |
| 4822 | |
| 4823 // clang-format off | |
| 4824 unsigned char packet[] = { | |
| 4825 // public flags (version, 8 byte connection_id) | |
| 4826 static_cast<unsigned char>( | |
| 4827 framer_.version() > QUIC_VERSION_32 ? 0x3D : 0x3D), | |
| 4828 // connection_id | |
| 4829 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 4830 // version tag | |
| 4831 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | |
| 4832 // packet number | |
| 4833 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 4834 // private flags (entropy) | |
| 4835 0x01, | |
| 4836 | |
| 4837 // frame type (stream frame with fin and no length) | |
| 4838 0xDF, | |
| 4839 // stream id | |
| 4840 0x04, 0x03, 0x02, 0x01, | |
| 4841 // offset | |
| 4842 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA, | |
| 4843 // data | |
| 4844 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', | |
| 4845 }; | |
| 4846 unsigned char packet_34[] = { | |
| 4847 // public flags (version, 8 byte connection_id) | |
| 4848 0x3D, | |
| 4849 // connection_id | |
| 4850 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 4851 // version tag | |
| 4852 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | |
| 4853 // packet number | |
| 4854 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 4855 | |
| 4856 // frame type (stream frame with fin and no length) | |
| 4857 0xDF, | |
| 4858 // stream id | |
| 4859 0x04, 0x03, 0x02, 0x01, | |
| 4860 // offset | |
| 4861 0x54, 0x76, 0x10, 0x32, 0xDC, 0xFE, 0x98, 0xBA, | |
| 4862 // data | |
| 4863 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!', | |
| 4864 }; | |
| 4865 // clang-format on | |
| 4866 | |
| 4867 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); | |
| 4868 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 4869 ASSERT_TRUE(data != nullptr); | |
| 4870 | |
| 4871 test::CompareCharArraysWithHexError( | |
| 4872 "constructed packet", data->data(), data->length(), | |
| 4873 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 4874 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 4875 : arraysize(packet_34)); | |
| 4876 } | |
| 4877 | |
| 4878 TEST_P(QuicFramerTest, BuildStreamFramePacketWithMultipathFlag) { | |
| 4879 QuicPacketHeader header; | |
| 4880 header.public_header.connection_id = kConnectionId; | |
| 4881 header.public_header.multipath_flag = true; | |
| 4882 header.public_header.reset_flag = false; | |
| 4883 header.public_header.version_flag = false; | |
| 4884 header.fec_flag = false; | |
| 4885 header.entropy_flag = true; | |
| 4886 header.path_id = kPathId; | |
| 4887 header.packet_number = kPacketNumber; | |
| 4888 | |
| 4889 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, | |
| 4890 StringPiece("hello world!")); | |
| 4891 | |
| 4892 QuicFrames frames; | |
| 4893 frames.push_back(QuicFrame(&stream_frame)); | |
| 4894 | |
| 4895 // clang-format off | |
| 4896 unsigned char packet[] = { | |
| 4897 // public flags (8 byte connection_id) | |
| 4898 static_cast<unsigned char>( | |
| 4899 framer_.version() > QUIC_VERSION_32 ? 0x78 : 0x7C), | |
| 4900 // connection_id | |
| 4901 0x10, 0x32, 0x54, 0x76, | |
| 4902 0x98, 0xBA, 0xDC, 0xFE, | |
| 4903 // path_id | |
| 4904 0x42, | |
| 4905 // packet number | |
| 4906 0xBC, 0x9A, 0x78, 0x56, | |
| 4907 0x34, 0x12, | |
| 4908 // private flags (entropy) | |
| 4909 0x01, | |
| 4910 | |
| 4911 // frame type (stream frame with fin and no length) | |
| 4912 0xDF, | |
| 4913 // stream id | |
| 4914 0x04, 0x03, 0x02, 0x01, | |
| 4915 // offset | |
| 4916 0x54, 0x76, 0x10, 0x32, | |
| 4917 0xDC, 0xFE, 0x98, 0xBA, | |
| 4918 // data | |
| 4919 'h', 'e', 'l', 'l', | |
| 4920 'o', ' ', 'w', 'o', | |
| 4921 'r', 'l', 'd', '!', | |
| 4922 }; | |
| 4923 unsigned char packet_34[] = { | |
| 4924 // public flags (8 byte connection_id) | |
| 4925 0x78, | |
| 4926 // connection_id | |
| 4927 0x10, 0x32, 0x54, 0x76, | |
| 4928 0x98, 0xBA, 0xDC, 0xFE, | |
| 4929 // path_id | |
| 4930 0x42, | |
| 4931 // packet number | |
| 4932 0xBC, 0x9A, 0x78, 0x56, | |
| 4933 0x34, 0x12, | |
| 4934 | |
| 4935 // frame type (stream frame with fin and no length) | |
| 4936 0xDF, | |
| 4937 // stream id | |
| 4938 0x04, 0x03, 0x02, 0x01, | |
| 4939 // offset | |
| 4940 0x54, 0x76, 0x10, 0x32, | |
| 4941 0xDC, 0xFE, 0x98, 0xBA, | |
| 4942 // data | |
| 4943 'h', 'e', 'l', 'l', | |
| 4944 'o', ' ', 'w', 'o', | |
| 4945 'r', 'l', 'd', '!', | |
| 4946 }; | |
| 4947 // clang-format on | |
| 4948 | |
| 4949 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 4950 ASSERT_TRUE(data != nullptr); | |
| 4951 | |
| 4952 test::CompareCharArraysWithHexError( | |
| 4953 "constructed packet", data->data(), data->length(), | |
| 4954 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 4955 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 4956 : arraysize(packet_34)); | |
| 4957 } | |
| 4958 | |
| 4959 TEST_P(QuicFramerTest, BuildStreamFramePacketWithBothVersionAndMultipathFlag) { | |
| 4960 QuicPacketHeader header; | |
| 4961 header.public_header.connection_id = kConnectionId; | |
| 4962 header.public_header.multipath_flag = true; | |
| 4963 header.public_header.reset_flag = false; | |
| 4964 header.public_header.version_flag = true; | |
| 4965 header.fec_flag = false; | |
| 4966 header.entropy_flag = true; | |
| 4967 header.path_id = kPathId; | |
| 4968 header.packet_number = kPacketNumber; | |
| 4969 | |
| 4970 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, | |
| 4971 StringPiece("hello world!")); | |
| 4972 | |
| 4973 QuicFrames frames; | |
| 4974 frames.push_back(QuicFrame(&stream_frame)); | |
| 4975 | |
| 4976 // clang-format off | |
| 4977 unsigned char packet[] = { | |
| 4978 // public flags (8 byte connection_id) | |
| 4979 static_cast<unsigned char>( | |
| 4980 framer_.version() > QUIC_VERSION_32 ? 0x7D : 0x7D), | |
| 4981 // connection_id | |
| 4982 0x10, 0x32, 0x54, 0x76, | |
| 4983 0x98, 0xBA, 0xDC, 0xFE, | |
| 4984 // version tag | |
| 4985 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | |
| 4986 // path_id | |
| 4987 0x42, | |
| 4988 // packet number | |
| 4989 0xBC, 0x9A, 0x78, 0x56, | |
| 4990 0x34, 0x12, | |
| 4991 // private flags (entropy) | |
| 4992 0x01, | |
| 4993 | |
| 4994 // frame type (stream frame with fin and no length) | |
| 4995 0xDF, | |
| 4996 // stream id | |
| 4997 0x04, 0x03, 0x02, 0x01, | |
| 4998 // offset | |
| 4999 0x54, 0x76, 0x10, 0x32, | |
| 5000 0xDC, 0xFE, 0x98, 0xBA, | |
| 5001 // data | |
| 5002 'h', 'e', 'l', 'l', | |
| 5003 'o', ' ', 'w', 'o', | |
| 5004 'r', 'l', 'd', '!', | |
| 5005 }; | |
| 5006 unsigned char packet_34[] = { | |
| 5007 // public flags (8 byte connection_id) | |
| 5008 0x7D, | |
| 5009 // connection_id | |
| 5010 0x10, 0x32, 0x54, 0x76, | |
| 5011 0x98, 0xBA, 0xDC, 0xFE, | |
| 5012 // version tag | |
| 5013 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | |
| 5014 // path_id | |
| 5015 0x42, | |
| 5016 // packet number | |
| 5017 0xBC, 0x9A, 0x78, 0x56, | |
| 5018 0x34, 0x12, | |
| 5019 | |
| 5020 // frame type (stream frame with fin and no length) | |
| 5021 0xDF, | |
| 5022 // stream id | |
| 5023 0x04, 0x03, 0x02, 0x01, | |
| 5024 // offset | |
| 5025 0x54, 0x76, 0x10, 0x32, | |
| 5026 0xDC, 0xFE, 0x98, 0xBA, | |
| 5027 // data | |
| 5028 'h', 'e', 'l', 'l', | |
| 5029 'o', ' ', 'w', 'o', | |
| 5030 'r', 'l', 'd', '!', | |
| 5031 }; | |
| 5032 // clang-format on | |
| 5033 | |
| 5034 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); | |
| 5035 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 5036 ASSERT_TRUE(data != nullptr); | |
| 5037 | |
| 5038 test::CompareCharArraysWithHexError( | |
| 5039 "constructed packet", data->data(), data->length(), | |
| 5040 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 5041 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 5042 : arraysize(packet_34)); | |
| 5043 } | |
| 5044 | |
| 5045 TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) { | |
| 5046 // clang-format off | |
| 5047 unsigned char packet[] = { | |
| 5048 // public flags (version, 8 byte connection_id) | |
| 5049 0x0D, | |
| 5050 // connection_id | |
| 5051 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 5052 // version tag | |
| 5053 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | |
| 5054 }; | |
| 5055 // clang-format on | |
| 5056 | |
| 5057 QuicConnectionId connection_id = kConnectionId; | |
| 5058 std::unique_ptr<QuicEncryptedPacket> data( | |
| 5059 framer_.BuildVersionNegotiationPacket(connection_id, | |
| 5060 SupportedVersions(GetParam()))); | |
| 5061 test::CompareCharArraysWithHexError("constructed packet", data->data(), | |
| 5062 data->length(), AsChars(packet), | |
| 5063 arraysize(packet)); | |
| 5064 } | |
| 5065 | |
| 5066 TEST_P(QuicFramerTest, BuildAckFramePacket) { | |
| 5067 if (framer_.version() > QUIC_VERSION_33) { | |
| 5068 return; | |
| 5069 } | |
| 5070 | |
| 5071 QuicPacketHeader header; | |
| 5072 header.public_header.connection_id = kConnectionId; | |
| 5073 header.public_header.reset_flag = false; | |
| 5074 header.public_header.version_flag = false; | |
| 5075 header.fec_flag = false; | |
| 5076 header.entropy_flag = true; | |
| 5077 header.packet_number = kPacketNumber; | |
| 5078 | |
| 5079 QuicAckFrame ack_frame; | |
| 5080 ack_frame.entropy_hash = 0x43; | |
| 5081 ack_frame.largest_observed = kLargestObserved; | |
| 5082 ack_frame.ack_delay_time = QuicTime::Delta::Zero(); | |
| 5083 ack_frame.packets.Add(kMissingPacket); | |
| 5084 | |
| 5085 QuicFrames frames; | |
| 5086 frames.push_back(QuicFrame(&ack_frame)); | |
| 5087 | |
| 5088 // clang-format off | |
| 5089 unsigned char packet[] = { | |
| 5090 // public flags (8 byte connection_id) | |
| 5091 0x3C, | |
| 5092 // connection_id | |
| 5093 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 5094 // packet number | |
| 5095 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 5096 // private flags (entropy) | |
| 5097 0x01, | |
| 5098 | |
| 5099 // frame type (ack frame) | |
| 5100 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | |
| 5101 0x6C, | |
| 5102 // entropy hash of all received packets. | |
| 5103 0x43, | |
| 5104 // largest observed packet number | |
| 5105 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 5106 // Zero delta time. | |
| 5107 0x00, 0x00, | |
| 5108 // num received packets. | |
| 5109 0x00, | |
| 5110 // num missing packet ranges | |
| 5111 0x01, | |
| 5112 // missing packet delta | |
| 5113 0x01, | |
| 5114 // 0 more missing packets in range. | |
| 5115 0x00, | |
| 5116 // 0 revived packets. | |
| 5117 0x00, | |
| 5118 }; | |
| 5119 // clang-format on | |
| 5120 | |
| 5121 // clang-format off | |
| 5122 unsigned char packet_version32[] = { | |
| 5123 // public flags (8 byte connection_id) | |
| 5124 static_cast<unsigned char>( | |
| 5125 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 5126 // connection_id | |
| 5127 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 5128 // packet number | |
| 5129 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 5130 // private flags (entropy) | |
| 5131 0x01, | |
| 5132 | |
| 5133 // frame type (ack frame) | |
| 5134 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | |
| 5135 0x6C, | |
| 5136 // entropy hash of all received packets. | |
| 5137 0x43, | |
| 5138 // largest observed packet number | |
| 5139 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 5140 // Zero delta time. | |
| 5141 0x00, 0x00, | |
| 5142 // num received packets. | |
| 5143 0x00, | |
| 5144 // num missing packet ranges | |
| 5145 0x01, | |
| 5146 // missing packet delta | |
| 5147 0x01, | |
| 5148 // 0 more missing packets in range. | |
| 5149 0x00, | |
| 5150 }; | |
| 5151 // clang-format on | |
| 5152 | |
| 5153 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 5154 ASSERT_TRUE(data != nullptr); | |
| 5155 | |
| 5156 if (framer_.version() <= QUIC_VERSION_31) { | |
| 5157 test::CompareCharArraysWithHexError("constructed packet", data->data(), | |
| 5158 data->length(), AsChars(packet), | |
| 5159 arraysize(packet)); | |
| 5160 } else { | |
| 5161 test::CompareCharArraysWithHexError( | |
| 5162 "constructed packet", data->data(), data->length(), | |
| 5163 AsChars(packet_version32), arraysize(packet_version32)); | |
| 5164 } | |
| 5165 } | |
| 5166 | |
| 5167 // TODO(jri): Add test for tuncated packets in which the original ack frame had | |
| 5168 // revived packets. (In both the large and small packet cases below). | |
| 5169 | |
| 5170 TEST_P(QuicFramerTest, BuildTruncatedAckFrameLargePacket) { | |
| 5171 if (framer_.version() > QUIC_VERSION_33) { | |
| 5172 return; | |
| 5173 } | |
| 5174 | |
| 5175 QuicPacketHeader header; | |
| 5176 header.public_header.connection_id = kConnectionId; | |
| 5177 header.public_header.reset_flag = false; | |
| 5178 header.public_header.version_flag = false; | |
| 5179 header.fec_flag = false; | |
| 5180 header.entropy_flag = true; | |
| 5181 header.packet_number = kPacketNumber; | |
| 5182 | |
| 5183 QuicAckFrame ack_frame; | |
| 5184 // This entropy hash is different from what shows up in the packet below, | |
| 5185 // since entropy is recomputed by the framer on ack truncation (by | |
| 5186 // TestEntropyCalculator for this test.) | |
| 5187 ack_frame.entropy_hash = 0x43; | |
| 5188 ack_frame.largest_observed = 2 * 300; | |
| 5189 ack_frame.ack_delay_time = QuicTime::Delta::Zero(); | |
| 5190 for (size_t i = 1; i < 2 * 300; i += 2) { | |
| 5191 ack_frame.packets.Add(i); | |
| 5192 } | |
| 5193 | |
| 5194 QuicFrames frames; | |
| 5195 frames.push_back(QuicFrame(&ack_frame)); | |
| 5196 | |
| 5197 // clang-format off | |
| 5198 unsigned char packet[] = { | |
| 5199 // public flags (8 byte connection_id) | |
| 5200 0x3C, | |
| 5201 // connection_id | |
| 5202 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 5203 // packet number | |
| 5204 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 5205 // private flags (entropy) | |
| 5206 0x01, | |
| 5207 | |
| 5208 // frame type (ack frame) | |
| 5209 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta) | |
| 5210 0x74, | |
| 5211 // entropy hash of all received packets, set to 1 by TestEntropyCalculator | |
| 5212 // since ack is truncated. | |
| 5213 0x01, | |
| 5214 // 2-byte largest observed packet number. | |
| 5215 // Expected to be 510 (0x1FE), since only 255 nack ranges can fit. | |
| 5216 0xFE, 0x01, | |
| 5217 // Zero delta time. | |
| 5218 0x00, 0x00, | |
| 5219 // num missing packet ranges (limited to 255 by size of this field). | |
| 5220 0xFF, | |
| 5221 // {missing packet delta, further missing packets in range} | |
| 5222 // 6 nack ranges x 42 + 3 nack ranges | |
| 5223 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5224 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5225 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5226 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5227 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5228 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5229 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5230 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5231 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5232 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5233 | |
| 5234 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5235 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5236 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5237 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5238 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5239 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5240 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5241 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5242 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5243 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5244 | |
| 5245 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5246 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5247 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5248 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5249 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5250 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5251 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5252 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5253 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5254 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5255 | |
| 5256 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5257 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5258 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5259 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5260 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5261 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5262 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5263 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5264 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5265 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5266 | |
| 5267 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5268 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5269 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5270 | |
| 5271 // 0 revived packets. | |
| 5272 0x00, | |
| 5273 }; | |
| 5274 // clang-format on | |
| 5275 | |
| 5276 // clang-format off | |
| 5277 unsigned char packet_version32[] = { | |
| 5278 // public flags (8 byte connection_id) | |
| 5279 static_cast<unsigned char>( | |
| 5280 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 5281 // connection_id | |
| 5282 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 5283 // packet number | |
| 5284 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 5285 // private flags (entropy) | |
| 5286 0x01, | |
| 5287 | |
| 5288 // frame type (ack frame) | |
| 5289 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta) | |
| 5290 0x74, | |
| 5291 // entropy hash of all received packets, set to 1 by TestEntropyCalculator | |
| 5292 // since ack is truncated. | |
| 5293 0x01, | |
| 5294 // 2-byte largest observed packet number. | |
| 5295 // Expected to be 510 (0x1FE), since only 255 nack ranges can fit. | |
| 5296 0xFE, 0x01, | |
| 5297 // Zero delta time. | |
| 5298 0x00, 0x00, | |
| 5299 // num missing packet ranges (limited to 255 by size of this field). | |
| 5300 0xFF, | |
| 5301 // {missing packet delta, further missing packets in range} | |
| 5302 // 6 nack ranges x 42 + 3 nack ranges | |
| 5303 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5304 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5305 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5306 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5307 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5308 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5309 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5310 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5311 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5312 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5313 | |
| 5314 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5315 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5316 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5317 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5318 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5319 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5320 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5321 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5322 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5323 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5324 | |
| 5325 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5326 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5327 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5328 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5329 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5330 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5331 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5332 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5333 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5334 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5335 | |
| 5336 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5337 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5338 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5339 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5340 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5341 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5342 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5343 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5344 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5345 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5346 | |
| 5347 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5348 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5349 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5350 }; | |
| 5351 // clang-format on | |
| 5352 | |
| 5353 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 5354 ASSERT_TRUE(data != nullptr); | |
| 5355 | |
| 5356 if (framer_.version() <= QUIC_VERSION_31) { | |
| 5357 test::CompareCharArraysWithHexError("constructed packet", data->data(), | |
| 5358 data->length(), AsChars(packet), | |
| 5359 arraysize(packet)); | |
| 5360 } else { | |
| 5361 test::CompareCharArraysWithHexError( | |
| 5362 "constructed packet", data->data(), data->length(), | |
| 5363 AsChars(packet_version32), arraysize(packet_version32)); | |
| 5364 } | |
| 5365 } | |
| 5366 | |
| 5367 TEST_P(QuicFramerTest, BuildTruncatedAckFrameSmallPacket) { | |
| 5368 if (framer_.version() > QUIC_VERSION_33) { | |
| 5369 return; | |
| 5370 } | |
| 5371 | |
| 5372 QuicPacketHeader header; | |
| 5373 header.public_header.connection_id = kConnectionId; | |
| 5374 header.public_header.reset_flag = false; | |
| 5375 header.public_header.version_flag = false; | |
| 5376 header.fec_flag = false; | |
| 5377 header.entropy_flag = true; | |
| 5378 header.packet_number = kPacketNumber; | |
| 5379 | |
| 5380 QuicAckFrame ack_frame; | |
| 5381 // This entropy hash is different from what shows up in the packet below, | |
| 5382 // since entropy is recomputed by the framer on ack truncation (by | |
| 5383 // TestEntropyCalculator for this test.) | |
| 5384 ack_frame.entropy_hash = 0x43; | |
| 5385 ack_frame.largest_observed = 2 * 300; | |
| 5386 ack_frame.ack_delay_time = QuicTime::Delta::Zero(); | |
| 5387 for (size_t i = 1; i < 2 * 300; i += 2) { | |
| 5388 ack_frame.packets.Add(i); | |
| 5389 } | |
| 5390 | |
| 5391 QuicFrames frames; | |
| 5392 frames.push_back(QuicFrame(&ack_frame)); | |
| 5393 | |
| 5394 // clang-format off | |
| 5395 unsigned char packet[] = { | |
| 5396 // public flags (8 byte connection_id) | |
| 5397 0x3C, | |
| 5398 // connection_id | |
| 5399 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 5400 // packet number | |
| 5401 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 5402 // private flags (entropy) | |
| 5403 0x01, | |
| 5404 | |
| 5405 // frame type (ack frame) | |
| 5406 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta) | |
| 5407 0x74, | |
| 5408 // entropy hash of all received packets, set to 1 by TestEntropyCalculator | |
| 5409 // since ack is truncated. | |
| 5410 0x01, | |
| 5411 // 2-byte largest observed packet number. | |
| 5412 // Expected to be 12 (0x0C), since only 6 nack ranges can fit. | |
| 5413 0x0C, 0x00, | |
| 5414 // Zero delta time. | |
| 5415 0x00, 0x00, | |
| 5416 // num missing packet ranges (limited to 6 by packet size of 37). | |
| 5417 0x06, | |
| 5418 // {missing packet delta, further missing packets in range} | |
| 5419 // 6 nack ranges | |
| 5420 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5421 // 0 revived packets. | |
| 5422 0x00, | |
| 5423 }; | |
| 5424 // clang-format on | |
| 5425 | |
| 5426 // clang-format off | |
| 5427 unsigned char packet_version32[] = { | |
| 5428 // public flags (8 byte connection_id) | |
| 5429 static_cast<unsigned char>( | |
| 5430 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 5431 // connection_id | |
| 5432 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 5433 // packet number | |
| 5434 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 5435 // private flags (entropy) | |
| 5436 0x01, | |
| 5437 | |
| 5438 // frame type (ack frame) | |
| 5439 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta) | |
| 5440 0x74, | |
| 5441 // entropy hash of all received packets, set to 1 by TestEntropyCalculator | |
| 5442 // since ack is truncated. | |
| 5443 0x01, | |
| 5444 // 2-byte largest observed packet number. | |
| 5445 // Expected to be 12 (0x0C), since only 6 nack ranges can fit. | |
| 5446 0x0C, 0x00, | |
| 5447 // Zero delta time. | |
| 5448 0x00, 0x00, | |
| 5449 // num missing packet ranges (limited to 6 by packet size of 37). | |
| 5450 0x06, | |
| 5451 // {missing packet delta, further missing packets in range} | |
| 5452 // 6 nack ranges | |
| 5453 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | |
| 5454 }; | |
| 5455 // clang-format on | |
| 5456 | |
| 5457 if (framer_.version() <= QUIC_VERSION_31) { | |
| 5458 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames, 37u)); | |
| 5459 ASSERT_TRUE(data != nullptr); | |
| 5460 // Expect 1 byte unused since at least 2 bytes are needed to fit more nacks. | |
| 5461 EXPECT_EQ(36u, data->length()); | |
| 5462 test::CompareCharArraysWithHexError("constructed packet", data->data(), | |
| 5463 data->length(), AsChars(packet), | |
| 5464 arraysize(packet)); | |
| 5465 } else { | |
| 5466 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames, 36u)); | |
| 5467 ASSERT_TRUE(data != nullptr); | |
| 5468 // Expect 1 byte unused since at least 2 bytes are needed to fit more nacks. | |
| 5469 EXPECT_EQ(35u, data->length()); | |
| 5470 test::CompareCharArraysWithHexError( | |
| 5471 "constructed packet", data->data(), data->length(), | |
| 5472 AsChars(packet_version32), arraysize(packet_version32)); | |
| 5473 } | |
| 5474 } | |
| 5475 | |
| 5476 TEST_P(QuicFramerTest, BuildNewAckFramePacketOneAckBlock) { | |
| 5477 if (framer_.version() <= QUIC_VERSION_33) { | |
| 5478 return; | |
| 5479 } | |
| 5480 | |
| 5481 QuicPacketHeader header; | |
| 5482 header.public_header.connection_id = kConnectionId; | |
| 5483 header.public_header.reset_flag = false; | |
| 5484 header.public_header.version_flag = false; | |
| 5485 header.packet_number = kPacketNumber; | |
| 5486 | |
| 5487 // Use kSmallLargestObserved to make this test finished in a short time. | |
| 5488 QuicAckFrame ack_frame; | |
| 5489 ack_frame.largest_observed = kSmallLargestObserved; | |
| 5490 ack_frame.ack_delay_time = QuicTime::Delta::Zero(); | |
| 5491 ack_frame.missing = false; | |
| 5492 ack_frame.packets.Add(1, kSmallLargestObserved + 1); | |
| 5493 | |
| 5494 QuicFrames frames; | |
| 5495 frames.push_back(QuicFrame(&ack_frame)); | |
| 5496 | |
| 5497 // clang-format off | |
| 5498 unsigned char packet[] = { | |
| 5499 // public flags (8 byte connection_id) | |
| 5500 0x38, | |
| 5501 // connection_id | |
| 5502 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 5503 // packet number | |
| 5504 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 5505 | |
| 5506 // frame type (ack frame) | |
| 5507 // (no ack blocks, 2 byte largest observed, 2 byte block length) | |
| 5508 0x45, | |
| 5509 // largest acked | |
| 5510 0x34, 0x12, | |
| 5511 // Zero delta time. | |
| 5512 0x00, 0x00, | |
| 5513 // first ack block length. | |
| 5514 0x34, 0x12, | |
| 5515 // num timestamps. | |
| 5516 0x00, | |
| 5517 }; | |
| 5518 // clang-format on | |
| 5519 | |
| 5520 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 5521 ASSERT_TRUE(data != nullptr); | |
| 5522 | |
| 5523 test::CompareCharArraysWithHexError("constructed packet", data->data(), | |
| 5524 data->length(), AsChars(packet), | |
| 5525 arraysize(packet)); | |
| 5526 } | |
| 5527 | |
| 5528 TEST_P(QuicFramerTest, BuildNewAckFramePacketMultipleAckBlocks) { | |
| 5529 if (framer_.version() <= QUIC_VERSION_33) { | |
| 5530 return; | |
| 5531 } | |
| 5532 | |
| 5533 QuicPacketHeader header; | |
| 5534 header.public_header.connection_id = kConnectionId; | |
| 5535 header.public_header.reset_flag = false; | |
| 5536 header.public_header.version_flag = false; | |
| 5537 header.packet_number = kPacketNumber; | |
| 5538 | |
| 5539 // Use kSmallLargestObserved to make this test finished in a short time. | |
| 5540 QuicAckFrame ack_frame; | |
| 5541 ack_frame.largest_observed = kSmallLargestObserved; | |
| 5542 ack_frame.ack_delay_time = QuicTime::Delta::Zero(); | |
| 5543 ack_frame.missing = false; | |
| 5544 ack_frame.packets.Add(1, 5); | |
| 5545 ack_frame.packets.Add(10, 500); | |
| 5546 ack_frame.packets.Add(900, kSmallMissingPacket); | |
| 5547 ack_frame.packets.Add(kSmallMissingPacket + 1, kSmallLargestObserved + 1); | |
| 5548 | |
| 5549 QuicFrames frames; | |
| 5550 frames.push_back(QuicFrame(&ack_frame)); | |
| 5551 | |
| 5552 // clang-format off | |
| 5553 unsigned char packet[] = { | |
| 5554 // public flags (8 byte connection_id) | |
| 5555 0x38, | |
| 5556 // connection_id | |
| 5557 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 5558 // packet number | |
| 5559 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 5560 | |
| 5561 // frame type (ack frame) | |
| 5562 // (has ack blocks, 2 byte largest observed, 2 byte block length) | |
| 5563 0x65, | |
| 5564 // largest acked | |
| 5565 0x34, 0x12, | |
| 5566 // Zero delta time. | |
| 5567 0x00, 0x00, | |
| 5568 // num ack blocks ranges. | |
| 5569 0x04, | |
| 5570 // first ack block length. | |
| 5571 0x01, 0x00, | |
| 5572 // gap to next block. | |
| 5573 0x01, | |
| 5574 // ack block length. | |
| 5575 0xaf, 0x0e, | |
| 5576 // gap to next block. | |
| 5577 0xff, | |
| 5578 // ack block length. | |
| 5579 0x00, 0x00, | |
| 5580 // gap to next block. | |
| 5581 0x91, | |
| 5582 // ack block length. | |
| 5583 0xea, 0x01, | |
| 5584 // gap to next block. | |
| 5585 0x05, | |
| 5586 // ack block length. | |
| 5587 0x04, 0x00, | |
| 5588 // num timestamps. | |
| 5589 0x00, | |
| 5590 }; | |
| 5591 // clang-format on | |
| 5592 | |
| 5593 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 5594 ASSERT_TRUE(data != nullptr); | |
| 5595 | |
| 5596 test::CompareCharArraysWithHexError("constructed packet", data->data(), | |
| 5597 data->length(), AsChars(packet), | |
| 5598 arraysize(packet)); | |
| 5599 } | |
| 5600 | |
| 5601 TEST_P(QuicFramerTest, BuildNewAckFramePacketMaxAckBlocks) { | |
| 5602 if (framer_.version() <= QUIC_VERSION_33) { | |
| 5603 return; | |
| 5604 } | |
| 5605 | |
| 5606 QuicPacketHeader header; | |
| 5607 header.public_header.connection_id = kConnectionId; | |
| 5608 header.public_header.reset_flag = false; | |
| 5609 header.public_header.version_flag = false; | |
| 5610 header.packet_number = kPacketNumber; | |
| 5611 | |
| 5612 // Use kSmallLargestObservedto make this test finished in a short time. | |
| 5613 QuicAckFrame ack_frame; | |
| 5614 ack_frame.largest_observed = kSmallLargestObserved; | |
| 5615 ack_frame.ack_delay_time = QuicTime::Delta::Zero(); | |
| 5616 ack_frame.missing = false; | |
| 5617 // 300 ack blocks. | |
| 5618 for (size_t i = 2; i < 2 * 300; i += 2) { | |
| 5619 ack_frame.packets.Add(i); | |
| 5620 } | |
| 5621 ack_frame.packets.Add(600, kSmallLargestObserved + 1); | |
| 5622 | |
| 5623 QuicFrames frames; | |
| 5624 frames.push_back(QuicFrame(&ack_frame)); | |
| 5625 | |
| 5626 // clang-format off | |
| 5627 unsigned char packet[] = { | |
| 5628 // public flags (8 byte connection_id) | |
| 5629 0x38, | |
| 5630 // connection_id | |
| 5631 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 5632 // packet number | |
| 5633 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 5634 // frame type (ack frame) | |
| 5635 // (has ack blocks, 2 byte largest observed, 2 byte block length) | |
| 5636 0x65, | |
| 5637 // largest acked | |
| 5638 0x34, 0x12, | |
| 5639 // Zero delta time. | |
| 5640 0x00, 0x00, | |
| 5641 // num ack blocks ranges. | |
| 5642 0xff, | |
| 5643 // first ack block length. | |
| 5644 0xdd, 0x0f, | |
| 5645 // 255 = 4 * 63 + 3 | |
| 5646 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5647 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5648 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5649 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5650 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5651 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5652 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5653 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5654 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5655 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5656 | |
| 5657 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5658 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5659 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5660 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5661 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5662 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5663 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5664 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5665 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5666 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5667 | |
| 5668 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5669 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5670 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5671 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5672 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5673 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5674 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5675 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5676 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5677 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5678 | |
| 5679 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5680 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5681 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5682 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5683 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5684 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5685 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5686 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5687 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5688 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5689 | |
| 5690 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5691 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5692 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5693 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5694 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5695 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5696 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5697 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5698 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5699 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5700 | |
| 5701 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5702 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5703 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5704 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5705 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5706 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5707 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5708 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5709 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5710 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5711 | |
| 5712 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5713 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5714 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5715 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, 0x01, 0x01, 0x00, | |
| 5716 // num timestamps. | |
| 5717 0x00, | |
| 5718 }; | |
| 5719 | |
| 5720 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 5721 ASSERT_TRUE(data != nullptr); | |
| 5722 | |
| 5723 test::CompareCharArraysWithHexError("constructed packet", data->data(), | |
| 5724 data->length(), AsChars(packet), | |
| 5725 arraysize(packet)); | |
| 5726 } | |
| 5727 | |
| 5728 TEST_P(QuicFramerTest, BuildStopWaitingPacket) { | |
| 5729 if (framer_.version() > QUIC_VERSION_33) { | |
| 5730 return; | |
| 5731 } | |
| 5732 QuicPacketHeader header; | |
| 5733 header.public_header.connection_id = kConnectionId; | |
| 5734 header.public_header.reset_flag = false; | |
| 5735 header.public_header.version_flag = false; | |
| 5736 header.fec_flag = false; | |
| 5737 header.entropy_flag = true; | |
| 5738 header.packet_number = kPacketNumber; | |
| 5739 | |
| 5740 QuicStopWaitingFrame stop_waiting_frame; | |
| 5741 stop_waiting_frame.entropy_hash = 0x14; | |
| 5742 stop_waiting_frame.least_unacked = kLeastUnacked; | |
| 5743 | |
| 5744 QuicFrames frames; | |
| 5745 frames.push_back(QuicFrame(&stop_waiting_frame)); | |
| 5746 | |
| 5747 // clang-format off | |
| 5748 unsigned char packet[] = { | |
| 5749 // public flags (8 byte connection_id) | |
| 5750 static_cast<unsigned char>( | |
| 5751 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 5752 // connection_id | |
| 5753 0x10, 0x32, 0x54, 0x76, | |
| 5754 0x98, 0xBA, 0xDC, 0xFE, | |
| 5755 // packet number | |
| 5756 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 5757 // private flags (entropy) | |
| 5758 0x01, | |
| 5759 | |
| 5760 // frame type (stop waiting frame) | |
| 5761 0x06, | |
| 5762 // entropy hash of sent packets till least awaiting - 1. | |
| 5763 0x14, | |
| 5764 // least packet number awaiting an ack, delta from packet number. | |
| 5765 0x1C, 0x00, 0x00, 0x00, | |
| 5766 0x00, 0x00, | |
| 5767 }; | |
| 5768 // clang-format on | |
| 5769 | |
| 5770 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 5771 ASSERT_TRUE(data != nullptr); | |
| 5772 | |
| 5773 test::CompareCharArraysWithHexError("constructed packet", data->data(), | |
| 5774 data->length(), AsChars(packet), | |
| 5775 arraysize(packet)); | |
| 5776 } | |
| 5777 | |
| 5778 TEST_P(QuicFramerTest, BuildNewStopWaitingPacket) { | |
| 5779 if (framer_.version() <= QUIC_VERSION_33) { | |
| 5780 return; | |
| 5781 } | |
| 5782 QuicPacketHeader header; | |
| 5783 header.public_header.connection_id = kConnectionId; | |
| 5784 header.public_header.reset_flag = false; | |
| 5785 header.public_header.version_flag = false; | |
| 5786 header.fec_flag = false; | |
| 5787 header.entropy_flag = false; | |
| 5788 header.packet_number = kPacketNumber; | |
| 5789 | |
| 5790 QuicStopWaitingFrame stop_waiting_frame; | |
| 5791 stop_waiting_frame.least_unacked = kLeastUnacked; | |
| 5792 | |
| 5793 QuicFrames frames; | |
| 5794 frames.push_back(QuicFrame(&stop_waiting_frame)); | |
| 5795 | |
| 5796 // clang-format off | |
| 5797 unsigned char packet[] = { | |
| 5798 // public flags (8 byte connection_id) | |
| 5799 0x38, | |
| 5800 // connection_id | |
| 5801 0x10, 0x32, 0x54, 0x76, | |
| 5802 0x98, 0xBA, 0xDC, 0xFE, | |
| 5803 // packet number | |
| 5804 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 5805 | |
| 5806 // frame type (stop waiting frame) | |
| 5807 0x06, | |
| 5808 // least packet number awaiting an ack, delta from packet number. | |
| 5809 0x1C, 0x00, 0x00, 0x00, | |
| 5810 0x00, 0x00, | |
| 5811 }; | |
| 5812 // clang-format on | |
| 5813 | |
| 5814 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 5815 ASSERT_TRUE(data != nullptr); | |
| 5816 | |
| 5817 test::CompareCharArraysWithHexError("constructed packet", data->data(), | |
| 5818 data->length(), AsChars(packet), | |
| 5819 arraysize(packet)); | |
| 5820 } | |
| 5821 | |
| 5822 TEST_P(QuicFramerTest, BuildRstFramePacketQuic) { | |
| 5823 QuicPacketHeader header; | |
| 5824 header.public_header.connection_id = kConnectionId; | |
| 5825 header.public_header.reset_flag = false; | |
| 5826 header.public_header.version_flag = false; | |
| 5827 header.fec_flag = false; | |
| 5828 header.entropy_flag = false; | |
| 5829 header.packet_number = kPacketNumber; | |
| 5830 | |
| 5831 QuicRstStreamFrame rst_frame; | |
| 5832 rst_frame.stream_id = kStreamId; | |
| 5833 rst_frame.error_code = static_cast<QuicRstStreamErrorCode>(0x05060708); | |
| 5834 rst_frame.byte_offset = 0x0807060504030201; | |
| 5835 | |
| 5836 // clang-format off | |
| 5837 unsigned char packet[] = { | |
| 5838 // public flags (8 byte connection_id) | |
| 5839 static_cast<unsigned char>( | |
| 5840 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 5841 // connection_id | |
| 5842 0x10, 0x32, 0x54, 0x76, | |
| 5843 0x98, 0xBA, 0xDC, 0xFE, | |
| 5844 // packet number | |
| 5845 0xBC, 0x9A, 0x78, 0x56, | |
| 5846 0x34, 0x12, | |
| 5847 // private flags | |
| 5848 0x00, | |
| 5849 | |
| 5850 // frame type (rst stream frame) | |
| 5851 0x01, | |
| 5852 // stream id | |
| 5853 0x04, 0x03, 0x02, 0x01, | |
| 5854 // sent byte offset | |
| 5855 0x01, 0x02, 0x03, 0x04, | |
| 5856 0x05, 0x06, 0x07, 0x08, | |
| 5857 // error code | |
| 5858 0x08, 0x07, 0x06, 0x05, | |
| 5859 }; | |
| 5860 unsigned char packet_34[] = { | |
| 5861 // public flags (8 byte connection_id) | |
| 5862 0x38, | |
| 5863 // connection_id | |
| 5864 0x10, 0x32, 0x54, 0x76, | |
| 5865 0x98, 0xBA, 0xDC, 0xFE, | |
| 5866 // packet number | |
| 5867 0xBC, 0x9A, 0x78, 0x56, | |
| 5868 0x34, 0x12, | |
| 5869 | |
| 5870 // frame type (rst stream frame) | |
| 5871 0x01, | |
| 5872 // stream id | |
| 5873 0x04, 0x03, 0x02, 0x01, | |
| 5874 // sent byte offset | |
| 5875 0x01, 0x02, 0x03, 0x04, | |
| 5876 0x05, 0x06, 0x07, 0x08, | |
| 5877 // error code | |
| 5878 0x08, 0x07, 0x06, 0x05, | |
| 5879 }; | |
| 5880 // clang-format on | |
| 5881 | |
| 5882 QuicFrames frames; | |
| 5883 frames.push_back(QuicFrame(&rst_frame)); | |
| 5884 | |
| 5885 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 5886 ASSERT_TRUE(data != nullptr); | |
| 5887 | |
| 5888 test::CompareCharArraysWithHexError( | |
| 5889 "constructed packet", data->data(), data->length(), | |
| 5890 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 5891 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 5892 : arraysize(packet_34)); | |
| 5893 } | |
| 5894 | |
| 5895 TEST_P(QuicFramerTest, BuildCloseFramePacket) { | |
| 5896 QuicPacketHeader header; | |
| 5897 header.public_header.connection_id = kConnectionId; | |
| 5898 header.public_header.reset_flag = false; | |
| 5899 header.public_header.version_flag = false; | |
| 5900 header.fec_flag = false; | |
| 5901 header.entropy_flag = true; | |
| 5902 header.packet_number = kPacketNumber; | |
| 5903 | |
| 5904 QuicConnectionCloseFrame close_frame; | |
| 5905 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708); | |
| 5906 close_frame.error_details = "because I can"; | |
| 5907 | |
| 5908 QuicFrames frames; | |
| 5909 frames.push_back(QuicFrame(&close_frame)); | |
| 5910 | |
| 5911 // clang-format off | |
| 5912 unsigned char packet[] = { | |
| 5913 // public flags (8 byte connection_id) | |
| 5914 static_cast<unsigned char>( | |
| 5915 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 5916 // connection_id | |
| 5917 0x10, 0x32, 0x54, 0x76, | |
| 5918 0x98, 0xBA, 0xDC, 0xFE, | |
| 5919 // packet number | |
| 5920 0xBC, 0x9A, 0x78, 0x56, | |
| 5921 0x34, 0x12, | |
| 5922 // private flags (entropy) | |
| 5923 0x01, | |
| 5924 | |
| 5925 // frame type (connection close frame) | |
| 5926 0x02, | |
| 5927 // error code | |
| 5928 0x08, 0x07, 0x06, 0x05, | |
| 5929 // error details length | |
| 5930 0x0d, 0x00, | |
| 5931 // error details | |
| 5932 'b', 'e', 'c', 'a', | |
| 5933 'u', 's', 'e', ' ', | |
| 5934 'I', ' ', 'c', 'a', | |
| 5935 'n', | |
| 5936 }; | |
| 5937 unsigned char packet_34[] = { | |
| 5938 // public flags (8 byte connection_id) | |
| 5939 static_cast<unsigned char>( | |
| 5940 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 5941 // connection_id | |
| 5942 0x10, 0x32, 0x54, 0x76, | |
| 5943 0x98, 0xBA, 0xDC, 0xFE, | |
| 5944 // packet number | |
| 5945 0xBC, 0x9A, 0x78, 0x56, | |
| 5946 0x34, 0x12, | |
| 5947 | |
| 5948 // frame type (connection close frame) | |
| 5949 0x02, | |
| 5950 // error code | |
| 5951 0x08, 0x07, 0x06, 0x05, | |
| 5952 // error details length | |
| 5953 0x0d, 0x00, | |
| 5954 // error details | |
| 5955 'b', 'e', 'c', 'a', | |
| 5956 'u', 's', 'e', ' ', | |
| 5957 'I', ' ', 'c', 'a', | |
| 5958 'n', | |
| 5959 }; | |
| 5960 // clang-format on | |
| 5961 | |
| 5962 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 5963 ASSERT_TRUE(data != nullptr); | |
| 5964 | |
| 5965 test::CompareCharArraysWithHexError( | |
| 5966 "constructed packet", data->data(), data->length(), | |
| 5967 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 5968 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 5969 : arraysize(packet_34)); | |
| 5970 } | |
| 5971 | |
| 5972 TEST_P(QuicFramerTest, BuildGoAwayPacket) { | |
| 5973 QuicPacketHeader header; | |
| 5974 header.public_header.connection_id = kConnectionId; | |
| 5975 header.public_header.reset_flag = false; | |
| 5976 header.public_header.version_flag = false; | |
| 5977 header.fec_flag = false; | |
| 5978 header.entropy_flag = true; | |
| 5979 header.packet_number = kPacketNumber; | |
| 5980 | |
| 5981 QuicGoAwayFrame goaway_frame; | |
| 5982 goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); | |
| 5983 goaway_frame.last_good_stream_id = kStreamId; | |
| 5984 goaway_frame.reason_phrase = "because I can"; | |
| 5985 | |
| 5986 QuicFrames frames; | |
| 5987 frames.push_back(QuicFrame(&goaway_frame)); | |
| 5988 | |
| 5989 // clang-format off | |
| 5990 unsigned char packet[] = { | |
| 5991 // public flags (8 byte connection_id) | |
| 5992 static_cast<unsigned char>( | |
| 5993 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 5994 // connection_id | |
| 5995 0x10, 0x32, 0x54, 0x76, | |
| 5996 0x98, 0xBA, 0xDC, 0xFE, | |
| 5997 // packet number | |
| 5998 0xBC, 0x9A, 0x78, 0x56, | |
| 5999 0x34, 0x12, | |
| 6000 // private flags(entropy) | |
| 6001 0x01, | |
| 6002 | |
| 6003 // frame type (go away frame) | |
| 6004 0x03, | |
| 6005 // error code | |
| 6006 0x08, 0x07, 0x06, 0x05, | |
| 6007 // stream id | |
| 6008 0x04, 0x03, 0x02, 0x01, | |
| 6009 // error details length | |
| 6010 0x0d, 0x00, | |
| 6011 // error details | |
| 6012 'b', 'e', 'c', 'a', | |
| 6013 'u', 's', 'e', ' ', | |
| 6014 'I', ' ', 'c', 'a', | |
| 6015 'n', | |
| 6016 }; | |
| 6017 unsigned char packet_34[] = { | |
| 6018 // public flags (8 byte connection_id) | |
| 6019 0x38, | |
| 6020 // connection_id | |
| 6021 0x10, 0x32, 0x54, 0x76, | |
| 6022 0x98, 0xBA, 0xDC, 0xFE, | |
| 6023 // packet number | |
| 6024 0xBC, 0x9A, 0x78, 0x56, | |
| 6025 0x34, 0x12, | |
| 6026 | |
| 6027 // frame type (go away frame) | |
| 6028 0x03, | |
| 6029 // error code | |
| 6030 0x08, 0x07, 0x06, 0x05, | |
| 6031 // stream id | |
| 6032 0x04, 0x03, 0x02, 0x01, | |
| 6033 // error details length | |
| 6034 0x0d, 0x00, | |
| 6035 // error details | |
| 6036 'b', 'e', 'c', 'a', | |
| 6037 'u', 's', 'e', ' ', | |
| 6038 'I', ' ', 'c', 'a', | |
| 6039 'n', | |
| 6040 }; | |
| 6041 // clang-format on | |
| 6042 | |
| 6043 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 6044 ASSERT_TRUE(data != nullptr); | |
| 6045 | |
| 6046 test::CompareCharArraysWithHexError( | |
| 6047 "constructed packet", data->data(), data->length(), | |
| 6048 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 6049 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 6050 : arraysize(packet_34)); | |
| 6051 } | |
| 6052 | |
| 6053 TEST_P(QuicFramerTest, BuildWindowUpdatePacket) { | |
| 6054 QuicPacketHeader header; | |
| 6055 header.public_header.connection_id = kConnectionId; | |
| 6056 header.public_header.reset_flag = false; | |
| 6057 header.public_header.version_flag = false; | |
| 6058 header.fec_flag = false; | |
| 6059 header.entropy_flag = true; | |
| 6060 header.packet_number = kPacketNumber; | |
| 6061 | |
| 6062 QuicWindowUpdateFrame window_update_frame; | |
| 6063 window_update_frame.stream_id = kStreamId; | |
| 6064 window_update_frame.byte_offset = 0x1122334455667788; | |
| 6065 | |
| 6066 QuicFrames frames; | |
| 6067 frames.push_back(QuicFrame(&window_update_frame)); | |
| 6068 | |
| 6069 // clang-format off | |
| 6070 unsigned char packet[] = { | |
| 6071 // public flags (8 byte connection_id) | |
| 6072 static_cast<unsigned char>( | |
| 6073 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 6074 // connection_id | |
| 6075 0x10, 0x32, 0x54, 0x76, | |
| 6076 0x98, 0xBA, 0xDC, 0xFE, | |
| 6077 // packet number | |
| 6078 0xBC, 0x9A, 0x78, 0x56, | |
| 6079 0x34, 0x12, | |
| 6080 // private flags(entropy) | |
| 6081 0x01, | |
| 6082 | |
| 6083 // frame type (window update frame) | |
| 6084 0x04, | |
| 6085 // stream id | |
| 6086 0x04, 0x03, 0x02, 0x01, | |
| 6087 // byte offset | |
| 6088 0x88, 0x77, 0x66, 0x55, | |
| 6089 0x44, 0x33, 0x22, 0x11, | |
| 6090 }; | |
| 6091 unsigned char packet_34[] = { | |
| 6092 // public flags (8 byte connection_id) | |
| 6093 0x38, | |
| 6094 // connection_id | |
| 6095 0x10, 0x32, 0x54, 0x76, | |
| 6096 0x98, 0xBA, 0xDC, 0xFE, | |
| 6097 // packet number | |
| 6098 0xBC, 0x9A, 0x78, 0x56, | |
| 6099 0x34, 0x12, | |
| 6100 | |
| 6101 // frame type (window update frame) | |
| 6102 0x04, | |
| 6103 // stream id | |
| 6104 0x04, 0x03, 0x02, 0x01, | |
| 6105 // byte offset | |
| 6106 0x88, 0x77, 0x66, 0x55, | |
| 6107 0x44, 0x33, 0x22, 0x11, | |
| 6108 }; | |
| 6109 // clang-format on | |
| 6110 | |
| 6111 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 6112 ASSERT_TRUE(data != nullptr); | |
| 6113 | |
| 6114 test::CompareCharArraysWithHexError( | |
| 6115 "constructed packet", data->data(), data->length(), | |
| 6116 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 6117 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 6118 : arraysize(packet_34)); | |
| 6119 } | |
| 6120 | |
| 6121 TEST_P(QuicFramerTest, BuildBlockedPacket) { | |
| 6122 QuicPacketHeader header; | |
| 6123 header.public_header.connection_id = kConnectionId; | |
| 6124 header.public_header.reset_flag = false; | |
| 6125 header.public_header.version_flag = false; | |
| 6126 header.fec_flag = false; | |
| 6127 header.entropy_flag = true; | |
| 6128 header.packet_number = kPacketNumber; | |
| 6129 | |
| 6130 QuicBlockedFrame blocked_frame; | |
| 6131 blocked_frame.stream_id = kStreamId; | |
| 6132 | |
| 6133 QuicFrames frames; | |
| 6134 frames.push_back(QuicFrame(&blocked_frame)); | |
| 6135 | |
| 6136 // clang-format off | |
| 6137 unsigned char packet[] = { | |
| 6138 // public flags (8 byte connection_id) | |
| 6139 static_cast<unsigned char>( | |
| 6140 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 6141 // connection_id | |
| 6142 0x10, 0x32, 0x54, 0x76, | |
| 6143 0x98, 0xBA, 0xDC, 0xFE, | |
| 6144 // packet number | |
| 6145 0xBC, 0x9A, 0x78, 0x56, | |
| 6146 0x34, 0x12, | |
| 6147 // private flags(entropy) | |
| 6148 0x01, | |
| 6149 | |
| 6150 // frame type (blocked frame) | |
| 6151 0x05, | |
| 6152 // stream id | |
| 6153 0x04, 0x03, 0x02, 0x01, | |
| 6154 }; | |
| 6155 unsigned char packet_34[] = { | |
| 6156 // public flags (8 byte connection_id) | |
| 6157 0x38, | |
| 6158 // connection_id | |
| 6159 0x10, 0x32, 0x54, 0x76, | |
| 6160 0x98, 0xBA, 0xDC, 0xFE, | |
| 6161 // packet number | |
| 6162 0xBC, 0x9A, 0x78, 0x56, | |
| 6163 0x34, 0x12, | |
| 6164 | |
| 6165 // frame type (blocked frame) | |
| 6166 0x05, | |
| 6167 // stream id | |
| 6168 0x04, 0x03, 0x02, 0x01, | |
| 6169 }; | |
| 6170 // clang-format on | |
| 6171 | |
| 6172 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 6173 ASSERT_TRUE(data != nullptr); | |
| 6174 | |
| 6175 test::CompareCharArraysWithHexError( | |
| 6176 "constructed packet", data->data(), data->length(), | |
| 6177 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 6178 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 6179 : arraysize(packet_34)); | |
| 6180 } | |
| 6181 | |
| 6182 TEST_P(QuicFramerTest, BuildPingPacket) { | |
| 6183 QuicPacketHeader header; | |
| 6184 header.public_header.connection_id = kConnectionId; | |
| 6185 header.public_header.reset_flag = false; | |
| 6186 header.public_header.version_flag = false; | |
| 6187 header.fec_flag = false; | |
| 6188 header.entropy_flag = true; | |
| 6189 header.packet_number = kPacketNumber; | |
| 6190 | |
| 6191 QuicPingFrame ping_frame; | |
| 6192 | |
| 6193 QuicFrames frames; | |
| 6194 frames.push_back(QuicFrame(ping_frame)); | |
| 6195 | |
| 6196 // clang-format off | |
| 6197 unsigned char packet[] = { | |
| 6198 // public flags (8 byte connection_id) | |
| 6199 static_cast<unsigned char>( | |
| 6200 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 6201 // connection_id | |
| 6202 0x10, 0x32, 0x54, 0x76, | |
| 6203 0x98, 0xBA, 0xDC, 0xFE, | |
| 6204 // packet number | |
| 6205 0xBC, 0x9A, 0x78, 0x56, | |
| 6206 0x34, 0x12, | |
| 6207 // private flags(entropy) | |
| 6208 0x01, | |
| 6209 | |
| 6210 // frame type (ping frame) | |
| 6211 0x07, | |
| 6212 }; | |
| 6213 unsigned char packet_34[] = { | |
| 6214 // public flags (8 byte connection_id) | |
| 6215 static_cast<unsigned char>( | |
| 6216 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 6217 // connection_id | |
| 6218 0x10, 0x32, 0x54, 0x76, | |
| 6219 0x98, 0xBA, 0xDC, 0xFE, | |
| 6220 // packet number | |
| 6221 0xBC, 0x9A, 0x78, 0x56, | |
| 6222 0x34, 0x12, | |
| 6223 | |
| 6224 // frame type (ping frame) | |
| 6225 0x07, | |
| 6226 }; | |
| 6227 // clang-format on | |
| 6228 | |
| 6229 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 6230 ASSERT_TRUE(data != nullptr); | |
| 6231 | |
| 6232 test::CompareCharArraysWithHexError( | |
| 6233 "constructed packet", data->data(), data->length(), | |
| 6234 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 6235 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 6236 : arraysize(packet_34)); | |
| 6237 } | |
| 6238 | |
| 6239 TEST_P(QuicFramerTest, BuildPathClosePacket) { | |
| 6240 QuicPacketHeader header; | |
| 6241 header.public_header.connection_id = kConnectionId; | |
| 6242 header.public_header.multipath_flag = true; | |
| 6243 header.public_header.reset_flag = false; | |
| 6244 header.public_header.version_flag = false; | |
| 6245 header.fec_flag = false; | |
| 6246 header.entropy_flag = true; | |
| 6247 header.path_id = kDefaultPathId; | |
| 6248 header.packet_number = kPacketNumber; | |
| 6249 | |
| 6250 QuicPathCloseFrame path_close; | |
| 6251 path_close.path_id = kPathId; | |
| 6252 QuicFrames frames; | |
| 6253 frames.push_back(QuicFrame(&path_close)); | |
| 6254 | |
| 6255 // clang-format off | |
| 6256 unsigned char packet[] = { | |
| 6257 // public flags (version) | |
| 6258 static_cast<unsigned char>( | |
| 6259 framer_.version() > QUIC_VERSION_32 ? 0x78 : 0X7C), | |
| 6260 // connection_id | |
| 6261 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 6262 // path_id | |
| 6263 0x00, | |
| 6264 // packet number | |
| 6265 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 6266 // private flags (entropy) | |
| 6267 0x01, | |
| 6268 | |
| 6269 // frame type (path_close_frame) | |
| 6270 0x08, | |
| 6271 // path id | |
| 6272 0x42, | |
| 6273 }; | |
| 6274 unsigned char packet_34[] = { | |
| 6275 // public flags (version) | |
| 6276 static_cast<unsigned char>( | |
| 6277 framer_.version() > QUIC_VERSION_32 ? 0x78 : 0X7C), | |
| 6278 // connection_id | |
| 6279 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | |
| 6280 // path_id | |
| 6281 0x00, | |
| 6282 // packet number | |
| 6283 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
| 6284 | |
| 6285 // frame type (path_close_frame) | |
| 6286 0x08, | |
| 6287 // path id | |
| 6288 0x42, | |
| 6289 }; | |
| 6290 // clang-format on | |
| 6291 | |
| 6292 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 6293 ASSERT_TRUE(data != nullptr); | |
| 6294 | |
| 6295 test::CompareCharArraysWithHexError( | |
| 6296 "constructed packet", data->data(), data->length(), | |
| 6297 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 6298 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 6299 : arraysize(packet_34)); | |
| 6300 } | |
| 6301 | |
| 6302 // Test that the MTU discovery packet is serialized correctly as a PING packet. | |
| 6303 TEST_P(QuicFramerTest, BuildMtuDiscoveryPacket) { | |
| 6304 QuicPacketHeader header; | |
| 6305 header.public_header.connection_id = kConnectionId; | |
| 6306 header.public_header.reset_flag = false; | |
| 6307 header.public_header.version_flag = false; | |
| 6308 header.fec_flag = false; | |
| 6309 header.entropy_flag = true; | |
| 6310 header.packet_number = kPacketNumber; | |
| 6311 | |
| 6312 QuicMtuDiscoveryFrame mtu_discovery_frame; | |
| 6313 | |
| 6314 QuicFrames frames; | |
| 6315 frames.push_back(QuicFrame(mtu_discovery_frame)); | |
| 6316 | |
| 6317 // clang-format off | |
| 6318 unsigned char packet[] = { | |
| 6319 // public flags (8 byte connection_id) | |
| 6320 static_cast<unsigned char>( | |
| 6321 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 6322 // connection_id | |
| 6323 0x10, 0x32, 0x54, 0x76, | |
| 6324 0x98, 0xBA, 0xDC, 0xFE, | |
| 6325 // packet number | |
| 6326 0xBC, 0x9A, 0x78, 0x56, | |
| 6327 0x34, 0x12, | |
| 6328 // private flags(entropy) | |
| 6329 0x01, | |
| 6330 | |
| 6331 // frame type (ping frame) | |
| 6332 0x07, | |
| 6333 }; | |
| 6334 unsigned char packet_34[] = { | |
| 6335 // public flags (8 byte connection_id) | |
| 6336 static_cast<unsigned char>( | |
| 6337 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 6338 // connection_id | |
| 6339 0x10, 0x32, 0x54, 0x76, | |
| 6340 0x98, 0xBA, 0xDC, 0xFE, | |
| 6341 // packet number | |
| 6342 0xBC, 0x9A, 0x78, 0x56, | |
| 6343 0x34, 0x12, | |
| 6344 | |
| 6345 // frame type (ping frame) | |
| 6346 0x07, | |
| 6347 }; | |
| 6348 // clang-format on | |
| 6349 | |
| 6350 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | |
| 6351 ASSERT_TRUE(data != nullptr); | |
| 6352 | |
| 6353 test::CompareCharArraysWithHexError( | |
| 6354 "constructed packet", data->data(), data->length(), | |
| 6355 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 6356 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 6357 : arraysize(packet_34)); | |
| 6358 } | |
| 6359 | |
| 6360 TEST_P(QuicFramerTest, BuildPublicResetPacketOld) { | |
| 6361 FLAGS_quic_use_old_public_reset_packets = true; | |
| 6362 QuicPublicResetPacket reset_packet; | |
| 6363 reset_packet.public_header.connection_id = kConnectionId; | |
| 6364 reset_packet.public_header.reset_flag = true; | |
| 6365 reset_packet.public_header.version_flag = false; | |
| 6366 reset_packet.rejected_packet_number = kPacketNumber; | |
| 6367 reset_packet.nonce_proof = kNonceProof; | |
| 6368 | |
| 6369 // clang-format off | |
| 6370 unsigned char packet[] = { | |
| 6371 // public flags (public reset, 8 byte ConnectionId) | |
| 6372 0x0E, | |
| 6373 // connection_id | |
| 6374 0x10, 0x32, 0x54, 0x76, | |
| 6375 0x98, 0xBA, 0xDC, 0xFE, | |
| 6376 // message tag (kPRST) | |
| 6377 'P', 'R', 'S', 'T', | |
| 6378 // num_entries (2) + padding | |
| 6379 0x02, 0x00, 0x00, 0x00, | |
| 6380 // tag kRNON | |
| 6381 'R', 'N', 'O', 'N', | |
| 6382 // end offset 8 | |
| 6383 0x08, 0x00, 0x00, 0x00, | |
| 6384 // tag kRSEQ | |
| 6385 'R', 'S', 'E', 'Q', | |
| 6386 // end offset 16 | |
| 6387 0x10, 0x00, 0x00, 0x00, | |
| 6388 // nonce proof | |
| 6389 0x89, 0x67, 0x45, 0x23, | |
| 6390 0x01, 0xEF, 0xCD, 0xAB, | |
| 6391 // rejected packet number | |
| 6392 0xBC, 0x9A, 0x78, 0x56, | |
| 6393 0x34, 0x12, 0x00, 0x00, | |
| 6394 }; | |
| 6395 // clang-format on | |
| 6396 | |
| 6397 std::unique_ptr<QuicEncryptedPacket> data( | |
| 6398 framer_.BuildPublicResetPacket(reset_packet)); | |
| 6399 ASSERT_TRUE(data != nullptr); | |
| 6400 | |
| 6401 test::CompareCharArraysWithHexError("constructed packet", data->data(), | |
| 6402 data->length(), AsChars(packet), | |
| 6403 arraysize(packet)); | |
| 6404 } | |
| 6405 | |
| 6406 TEST_P(QuicFramerTest, BuildPublicResetPacket) { | |
| 6407 FLAGS_quic_use_old_public_reset_packets = false; | |
| 6408 QuicPublicResetPacket reset_packet; | |
| 6409 reset_packet.public_header.connection_id = kConnectionId; | |
| 6410 reset_packet.public_header.reset_flag = true; | |
| 6411 reset_packet.public_header.version_flag = false; | |
| 6412 reset_packet.rejected_packet_number = kPacketNumber; | |
| 6413 reset_packet.nonce_proof = kNonceProof; | |
| 6414 | |
| 6415 // clang-format off | |
| 6416 unsigned char packet[] = { | |
| 6417 // public flags (public reset, 8 byte ConnectionId) | |
| 6418 0x0A, | |
| 6419 // connection_id | |
| 6420 0x10, 0x32, 0x54, 0x76, | |
| 6421 0x98, 0xBA, 0xDC, 0xFE, | |
| 6422 // message tag (kPRST) | |
| 6423 'P', 'R', 'S', 'T', | |
| 6424 // num_entries (2) + padding | |
| 6425 0x02, 0x00, 0x00, 0x00, | |
| 6426 // tag kRNON | |
| 6427 'R', 'N', 'O', 'N', | |
| 6428 // end offset 8 | |
| 6429 0x08, 0x00, 0x00, 0x00, | |
| 6430 // tag kRSEQ | |
| 6431 'R', 'S', 'E', 'Q', | |
| 6432 // end offset 16 | |
| 6433 0x10, 0x00, 0x00, 0x00, | |
| 6434 // nonce proof | |
| 6435 0x89, 0x67, 0x45, 0x23, | |
| 6436 0x01, 0xEF, 0xCD, 0xAB, | |
| 6437 // rejected packet number | |
| 6438 0xBC, 0x9A, 0x78, 0x56, | |
| 6439 0x34, 0x12, 0x00, 0x00, | |
| 6440 }; | |
| 6441 // clang-format on | |
| 6442 | |
| 6443 std::unique_ptr<QuicEncryptedPacket> data( | |
| 6444 framer_.BuildPublicResetPacket(reset_packet)); | |
| 6445 ASSERT_TRUE(data != nullptr); | |
| 6446 | |
| 6447 test::CompareCharArraysWithHexError("constructed packet", data->data(), | |
| 6448 data->length(), AsChars(packet), | |
| 6449 arraysize(packet)); | |
| 6450 } | |
| 6451 | |
| 6452 TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) { | |
| 6453 FLAGS_quic_use_old_public_reset_packets = false; | |
| 6454 QuicPublicResetPacket reset_packet; | |
| 6455 reset_packet.public_header.connection_id = kConnectionId; | |
| 6456 reset_packet.public_header.reset_flag = true; | |
| 6457 reset_packet.public_header.version_flag = false; | |
| 6458 reset_packet.rejected_packet_number = kPacketNumber; | |
| 6459 reset_packet.nonce_proof = kNonceProof; | |
| 6460 reset_packet.client_address = IPEndPoint(Loopback4(), 0x1234); | |
| 6461 | |
| 6462 // clang-format off | |
| 6463 unsigned char packet[] = { | |
| 6464 // public flags (public reset, 8 byte ConnectionId) | |
| 6465 0x0A, | |
| 6466 // connection_id | |
| 6467 0x10, 0x32, 0x54, 0x76, | |
| 6468 0x98, 0xBA, 0xDC, 0xFE, | |
| 6469 // message tag (kPRST) | |
| 6470 'P', 'R', 'S', 'T', | |
| 6471 // num_entries (3) + padding | |
| 6472 0x03, 0x00, 0x00, 0x00, | |
| 6473 // tag kRNON | |
| 6474 'R', 'N', 'O', 'N', | |
| 6475 // end offset 8 | |
| 6476 0x08, 0x00, 0x00, 0x00, | |
| 6477 // tag kRSEQ | |
| 6478 'R', 'S', 'E', 'Q', | |
| 6479 // end offset 16 | |
| 6480 0x10, 0x00, 0x00, 0x00, | |
| 6481 // tag kCADR | |
| 6482 'C', 'A', 'D', 'R', | |
| 6483 // end offset 24 | |
| 6484 0x18, 0x00, 0x00, 0x00, | |
| 6485 // nonce proof | |
| 6486 0x89, 0x67, 0x45, 0x23, | |
| 6487 0x01, 0xEF, 0xCD, 0xAB, | |
| 6488 // rejected packet number | |
| 6489 0xBC, 0x9A, 0x78, 0x56, | |
| 6490 0x34, 0x12, 0x00, 0x00, | |
| 6491 // client address | |
| 6492 0x02, 0x00, | |
| 6493 0x7F, 0x00, 0x00, 0x01, | |
| 6494 0x34, 0x12, | |
| 6495 }; | |
| 6496 // clang-format on | |
| 6497 | |
| 6498 std::unique_ptr<QuicEncryptedPacket> data( | |
| 6499 framer_.BuildPublicResetPacket(reset_packet)); | |
| 6500 ASSERT_TRUE(data != nullptr); | |
| 6501 | |
| 6502 test::CompareCharArraysWithHexError("constructed packet", data->data(), | |
| 6503 data->length(), AsChars(packet), | |
| 6504 arraysize(packet)); | |
| 6505 } | |
| 6506 | |
| 6507 TEST_P(QuicFramerTest, EncryptPacket) { | |
| 6508 QuicPacketNumber packet_number = kPacketNumber; | |
| 6509 // clang-format off | |
| 6510 unsigned char packet[] = { | |
| 6511 // public flags (8 byte connection_id) | |
| 6512 static_cast<unsigned char>( | |
| 6513 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 6514 // connection_id | |
| 6515 0x10, 0x32, 0x54, 0x76, | |
| 6516 0x98, 0xBA, 0xDC, 0xFE, | |
| 6517 // packet number | |
| 6518 0xBC, 0x9A, 0x78, 0x56, | |
| 6519 0x34, 0x12, | |
| 6520 // private flags | |
| 6521 0x00, | |
| 6522 | |
| 6523 // redundancy | |
| 6524 'a', 'b', 'c', 'd', | |
| 6525 'e', 'f', 'g', 'h', | |
| 6526 'i', 'j', 'k', 'l', | |
| 6527 'm', 'n', 'o', 'p', | |
| 6528 }; | |
| 6529 unsigned char packet_34[] = { | |
| 6530 // public flags (8 byte connection_id) | |
| 6531 static_cast<unsigned char>( | |
| 6532 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 6533 // connection_id | |
| 6534 0x10, 0x32, 0x54, 0x76, | |
| 6535 0x98, 0xBA, 0xDC, 0xFE, | |
| 6536 // packet number | |
| 6537 0xBC, 0x9A, 0x78, 0x56, | |
| 6538 0x34, 0x12, | |
| 6539 | |
| 6540 // redundancy | |
| 6541 'a', 'b', 'c', 'd', | |
| 6542 'e', 'f', 'g', 'h', | |
| 6543 'i', 'j', 'k', 'l', | |
| 6544 'm', 'n', 'o', 'p', | |
| 6545 }; | |
| 6546 // clang-format on | |
| 6547 | |
| 6548 std::unique_ptr<QuicPacket> raw(new QuicPacket( | |
| 6549 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 6550 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 6551 : arraysize(packet_34), | |
| 6552 false, PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, !kIncludePathId, | |
| 6553 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER)); | |
| 6554 char buffer[kMaxPacketSize]; | |
| 6555 size_t encrypted_length = | |
| 6556 framer_.EncryptPayload(ENCRYPTION_NONE, kDefaultPathId, packet_number, | |
| 6557 *raw, buffer, kMaxPacketSize); | |
| 6558 | |
| 6559 ASSERT_NE(0u, encrypted_length); | |
| 6560 EXPECT_TRUE(CheckEncryption(kDefaultPathId, packet_number, raw.get())); | |
| 6561 } | |
| 6562 | |
| 6563 TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) { | |
| 6564 QuicPacketNumber packet_number = kPacketNumber; | |
| 6565 // clang-format off | |
| 6566 unsigned char packet[] = { | |
| 6567 // public flags (version, 8 byte connection_id) | |
| 6568 0x39, | |
| 6569 // connection_id | |
| 6570 0x10, 0x32, 0x54, 0x76, | |
| 6571 0x98, 0xBA, 0xDC, 0xFE, | |
| 6572 // version tag | |
| 6573 'Q', '.', '1', '0', | |
| 6574 // packet number | |
| 6575 0xBC, 0x9A, 0x78, 0x56, | |
| 6576 0x34, 0x12, | |
| 6577 // private flags | |
| 6578 0x00, | |
| 6579 | |
| 6580 // redundancy | |
| 6581 'a', 'b', 'c', 'd', | |
| 6582 'e', 'f', 'g', 'h', | |
| 6583 'i', 'j', 'k', 'l', | |
| 6584 'm', 'n', 'o', 'p', | |
| 6585 }; | |
| 6586 unsigned char packet_34[] = { | |
| 6587 // public flags (version, 8 byte connection_id) | |
| 6588 0x39, | |
| 6589 // connection_id | |
| 6590 0x10, 0x32, 0x54, 0x76, | |
| 6591 0x98, 0xBA, 0xDC, 0xFE, | |
| 6592 // version tag | |
| 6593 'Q', '.', '1', '0', | |
| 6594 // packet number | |
| 6595 0xBC, 0x9A, 0x78, 0x56, | |
| 6596 0x34, 0x12, | |
| 6597 | |
| 6598 // redundancy | |
| 6599 'a', 'b', 'c', 'd', | |
| 6600 'e', 'f', 'g', 'h', | |
| 6601 'i', 'j', 'k', 'l', | |
| 6602 'm', 'n', 'o', 'p', | |
| 6603 }; | |
| 6604 // clang-format on | |
| 6605 | |
| 6606 std::unique_ptr<QuicPacket> raw(new QuicPacket( | |
| 6607 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 6608 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 6609 : arraysize(packet_34), | |
| 6610 false, PACKET_8BYTE_CONNECTION_ID, kIncludeVersion, !kIncludePathId, | |
| 6611 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER)); | |
| 6612 char buffer[kMaxPacketSize]; | |
| 6613 size_t encrypted_length = | |
| 6614 framer_.EncryptPayload(ENCRYPTION_NONE, kDefaultPathId, packet_number, | |
| 6615 *raw, buffer, kMaxPacketSize); | |
| 6616 | |
| 6617 ASSERT_NE(0u, encrypted_length); | |
| 6618 EXPECT_TRUE(CheckEncryption(kDefaultPathId, packet_number, raw.get())); | |
| 6619 } | |
| 6620 | |
| 6621 TEST_P(QuicFramerTest, EncryptPacketWithMultipathFlag) { | |
| 6622 QuicPacketNumber packet_number = kPacketNumber; | |
| 6623 // clang-format off | |
| 6624 unsigned char packet[] = { | |
| 6625 // public flags (version, 8 byte connection_id) | |
| 6626 0x78, | |
| 6627 // connection_id | |
| 6628 0x10, 0x32, 0x54, 0x76, | |
| 6629 0x98, 0xBA, 0xDC, 0xFE, | |
| 6630 // path_id | |
| 6631 0x42, | |
| 6632 // packet number | |
| 6633 0xBC, 0x9A, 0x78, 0x56, | |
| 6634 0x34, 0x12, | |
| 6635 // private flags | |
| 6636 0x00, | |
| 6637 | |
| 6638 // redundancy | |
| 6639 'a', 'b', 'c', 'd', | |
| 6640 'e', 'f', 'g', 'h', | |
| 6641 'i', 'j', 'k', 'l', | |
| 6642 'm', 'n', 'o', 'p', | |
| 6643 }; | |
| 6644 unsigned char packet_34[] = { | |
| 6645 // public flags (version, 8 byte connection_id) | |
| 6646 0x78, | |
| 6647 // connection_id | |
| 6648 0x10, 0x32, 0x54, 0x76, | |
| 6649 0x98, 0xBA, 0xDC, 0xFE, | |
| 6650 // path_id | |
| 6651 0x42, | |
| 6652 // packet number | |
| 6653 0xBC, 0x9A, 0x78, 0x56, | |
| 6654 0x34, 0x12, | |
| 6655 | |
| 6656 // redundancy | |
| 6657 'a', 'b', 'c', 'd', | |
| 6658 'e', 'f', 'g', 'h', | |
| 6659 'i', 'j', 'k', 'l', | |
| 6660 'm', 'n', 'o', 'p', | |
| 6661 }; | |
| 6662 // clang-format on | |
| 6663 | |
| 6664 std::unique_ptr<QuicPacket> raw(new QuicPacket( | |
| 6665 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 6666 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 6667 : arraysize(packet_34), | |
| 6668 false, PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, kIncludePathId, | |
| 6669 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER)); | |
| 6670 char buffer[kMaxPacketSize]; | |
| 6671 size_t encrypted_length = framer_.EncryptPayload( | |
| 6672 ENCRYPTION_NONE, kPathId, packet_number, *raw, buffer, kMaxPacketSize); | |
| 6673 | |
| 6674 ASSERT_NE(0u, encrypted_length); | |
| 6675 EXPECT_TRUE(CheckEncryption(kPathId, packet_number, raw.get())); | |
| 6676 } | |
| 6677 | |
| 6678 TEST_P(QuicFramerTest, EncryptPacketWithBothVersionFlagAndMultipathFlag) { | |
| 6679 QuicPacketNumber packet_number = kPacketNumber; | |
| 6680 // clang-format off | |
| 6681 unsigned char packet[] = { | |
| 6682 // public flags (version, 8 byte connection_id) | |
| 6683 0x79, | |
| 6684 // connection_id | |
| 6685 0x10, 0x32, 0x54, 0x76, | |
| 6686 0x98, 0xBA, 0xDC, 0xFE, | |
| 6687 // version tag | |
| 6688 'Q', '.', '1', '0', | |
| 6689 // path_id | |
| 6690 0x42, | |
| 6691 // packet number | |
| 6692 0xBC, 0x9A, 0x78, 0x56, | |
| 6693 0x34, 0x12, | |
| 6694 // private flags | |
| 6695 0x00, | |
| 6696 | |
| 6697 // redundancy | |
| 6698 'a', 'b', 'c', 'd', | |
| 6699 'e', 'f', 'g', 'h', | |
| 6700 'i', 'j', 'k', 'l', | |
| 6701 'm', 'n', 'o', 'p', | |
| 6702 }; | |
| 6703 unsigned char packet_34[] = { | |
| 6704 // public flags (version, 8 byte connection_id) | |
| 6705 0x79, | |
| 6706 // connection_id | |
| 6707 0x10, 0x32, 0x54, 0x76, | |
| 6708 0x98, 0xBA, 0xDC, 0xFE, | |
| 6709 // version tag | |
| 6710 'Q', '.', '1', '0', | |
| 6711 // path_id | |
| 6712 0x42, | |
| 6713 // packet number | |
| 6714 0xBC, 0x9A, 0x78, 0x56, | |
| 6715 0x34, 0x12, | |
| 6716 | |
| 6717 // redundancy | |
| 6718 'a', 'b', 'c', 'd', | |
| 6719 'e', 'f', 'g', 'h', | |
| 6720 'i', 'j', 'k', 'l', | |
| 6721 'm', 'n', 'o', 'p', | |
| 6722 }; | |
| 6723 // clang-format on | |
| 6724 | |
| 6725 std::unique_ptr<QuicPacket> raw(new QuicPacket( | |
| 6726 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 6727 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 6728 : arraysize(packet_34), | |
| 6729 false, PACKET_8BYTE_CONNECTION_ID, kIncludeVersion, kIncludePathId, | |
| 6730 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER)); | |
| 6731 char buffer[kMaxPacketSize]; | |
| 6732 size_t encrypted_length = framer_.EncryptPayload( | |
| 6733 ENCRYPTION_NONE, kPathId, packet_number, *raw, buffer, kMaxPacketSize); | |
| 6734 | |
| 6735 ASSERT_NE(0u, encrypted_length); | |
| 6736 EXPECT_TRUE(CheckEncryption(kPathId, packet_number, raw.get())); | |
| 6737 } | |
| 6738 | |
| 6739 TEST_P(QuicFramerTest, AckTruncationLargePacket) { | |
| 6740 QuicPacketHeader header; | |
| 6741 header.public_header.connection_id = kConnectionId; | |
| 6742 header.public_header.reset_flag = false; | |
| 6743 header.public_header.version_flag = false; | |
| 6744 header.fec_flag = false; | |
| 6745 header.entropy_flag = false; | |
| 6746 header.packet_number = kPacketNumber; | |
| 6747 | |
| 6748 QuicAckFrame ack_frame; | |
| 6749 // Create a packet with just the ack. | |
| 6750 if (framer_.version() <= QUIC_VERSION_33) { | |
| 6751 ack_frame = MakeAckFrameWithNackRanges(300, 0u); | |
| 6752 } else { | |
| 6753 ack_frame = MakeAckFrameWithAckBlocks(300, 0u); | |
| 6754 } | |
| 6755 QuicFrame frame; | |
| 6756 frame.type = ACK_FRAME; | |
| 6757 frame.ack_frame = &ack_frame; | |
| 6758 QuicFrames frames; | |
| 6759 frames.push_back(frame); | |
| 6760 | |
| 6761 // Build an ack packet with truncation due to limit in number of nack ranges. | |
| 6762 std::unique_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); | |
| 6763 ASSERT_TRUE(raw_ack_packet != nullptr); | |
| 6764 char buffer[kMaxPacketSize]; | |
| 6765 size_t encrypted_length = framer_.EncryptPayload( | |
| 6766 ENCRYPTION_NONE, kDefaultPathId, header.packet_number, *raw_ack_packet, | |
| 6767 buffer, kMaxPacketSize); | |
| 6768 ASSERT_NE(0u, encrypted_length); | |
| 6769 // Now make sure we can turn our ack packet back into an ack frame. | |
| 6770 ASSERT_TRUE(framer_.ProcessPacket( | |
| 6771 QuicEncryptedPacket(buffer, encrypted_length, false))); | |
| 6772 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | |
| 6773 QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; | |
| 6774 if (framer_.version() <= QUIC_VERSION_33) { | |
| 6775 EXPECT_TRUE(processed_ack_frame.is_truncated); | |
| 6776 EXPECT_EQ(510u, processed_ack_frame.largest_observed); | |
| 6777 EXPECT_TRUE(processed_ack_frame.missing); | |
| 6778 ASSERT_EQ(255u, processed_ack_frame.packets.NumPacketsSlow()); | |
| 6779 EXPECT_EQ(1u, processed_ack_frame.packets.Min()); | |
| 6780 EXPECT_EQ(509u, processed_ack_frame.packets.Max()); | |
| 6781 } else { | |
| 6782 EXPECT_FALSE(processed_ack_frame.is_truncated); | |
| 6783 EXPECT_FALSE(processed_ack_frame.missing); | |
| 6784 EXPECT_EQ(600u, processed_ack_frame.largest_observed); | |
| 6785 ASSERT_EQ(256u, processed_ack_frame.packets.NumPacketsSlow()); | |
| 6786 EXPECT_EQ(90u, processed_ack_frame.packets.Min()); | |
| 6787 EXPECT_EQ(600u, processed_ack_frame.packets.Max()); | |
| 6788 } | |
| 6789 } | |
| 6790 | |
| 6791 TEST_P(QuicFramerTest, AckTruncationSmallPacket) { | |
| 6792 QuicPacketHeader header; | |
| 6793 header.public_header.connection_id = kConnectionId; | |
| 6794 header.public_header.reset_flag = false; | |
| 6795 header.public_header.version_flag = false; | |
| 6796 header.fec_flag = false; | |
| 6797 header.entropy_flag = false; | |
| 6798 header.packet_number = kPacketNumber; | |
| 6799 | |
| 6800 // Create a packet with just the ack. | |
| 6801 QuicAckFrame ack_frame; | |
| 6802 if (framer_.version() <= QUIC_VERSION_33) { | |
| 6803 ack_frame = MakeAckFrameWithNackRanges(300, 0u); | |
| 6804 } else { | |
| 6805 ack_frame = MakeAckFrameWithAckBlocks(300, 0u); | |
| 6806 } | |
| 6807 QuicFrame frame; | |
| 6808 frame.type = ACK_FRAME; | |
| 6809 frame.ack_frame = &ack_frame; | |
| 6810 QuicFrames frames; | |
| 6811 frames.push_back(frame); | |
| 6812 | |
| 6813 // Build an ack packet with truncation due to limit in number of nack ranges. | |
| 6814 std::unique_ptr<QuicPacket> raw_ack_packet( | |
| 6815 BuildDataPacket(header, frames, 500)); | |
| 6816 ASSERT_TRUE(raw_ack_packet != nullptr); | |
| 6817 char buffer[kMaxPacketSize]; | |
| 6818 size_t encrypted_length = framer_.EncryptPayload( | |
| 6819 ENCRYPTION_NONE, kDefaultPathId, header.packet_number, *raw_ack_packet, | |
| 6820 buffer, kMaxPacketSize); | |
| 6821 ASSERT_NE(0u, encrypted_length); | |
| 6822 // Now make sure we can turn our ack packet back into an ack frame. | |
| 6823 ASSERT_TRUE(framer_.ProcessPacket( | |
| 6824 QuicEncryptedPacket(buffer, encrypted_length, false))); | |
| 6825 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | |
| 6826 QuicAckFrame& processed_ack_frame = *visitor_.ack_frames_[0]; | |
| 6827 if (framer_.version() <= QUIC_VERSION_33) { | |
| 6828 EXPECT_TRUE(processed_ack_frame.is_truncated); | |
| 6829 EXPECT_EQ(476u, processed_ack_frame.largest_observed); | |
| 6830 EXPECT_TRUE(processed_ack_frame.missing); | |
| 6831 ASSERT_EQ(238u, processed_ack_frame.packets.NumPacketsSlow()); | |
| 6832 EXPECT_EQ(1u, processed_ack_frame.packets.Min()); | |
| 6833 EXPECT_EQ(475u, processed_ack_frame.packets.Max()); | |
| 6834 } else { | |
| 6835 EXPECT_FALSE(processed_ack_frame.is_truncated); | |
| 6836 EXPECT_EQ(600u, processed_ack_frame.largest_observed); | |
| 6837 EXPECT_FALSE(processed_ack_frame.missing); | |
| 6838 ASSERT_EQ(239u, processed_ack_frame.packets.NumPacketsSlow()); | |
| 6839 EXPECT_EQ(124u, processed_ack_frame.packets.Min()); | |
| 6840 EXPECT_EQ(600u, processed_ack_frame.packets.Max()); | |
| 6841 } | |
| 6842 } | |
| 6843 | |
| 6844 TEST_P(QuicFramerTest, CleanTruncation) { | |
| 6845 QuicPacketHeader header; | |
| 6846 header.public_header.connection_id = kConnectionId; | |
| 6847 header.public_header.reset_flag = false; | |
| 6848 header.public_header.version_flag = false; | |
| 6849 header.fec_flag = false; | |
| 6850 header.entropy_flag = true; | |
| 6851 header.packet_number = kPacketNumber; | |
| 6852 | |
| 6853 QuicAckFrame ack_frame; | |
| 6854 ack_frame.largest_observed = 201; | |
| 6855 ack_frame.packets.Add(1, ack_frame.largest_observed); | |
| 6856 | |
| 6857 // Create a packet with just the ack. | |
| 6858 QuicFrame frame; | |
| 6859 frame.type = ACK_FRAME; | |
| 6860 frame.ack_frame = &ack_frame; | |
| 6861 QuicFrames frames; | |
| 6862 frames.push_back(frame); | |
| 6863 | |
| 6864 std::unique_ptr<QuicPacket> raw_ack_packet(BuildDataPacket(header, frames)); | |
| 6865 ASSERT_TRUE(raw_ack_packet != nullptr); | |
| 6866 | |
| 6867 char buffer[kMaxPacketSize]; | |
| 6868 size_t encrypted_length = framer_.EncryptPayload( | |
| 6869 ENCRYPTION_NONE, kDefaultPathId, header.packet_number, *raw_ack_packet, | |
| 6870 buffer, kMaxPacketSize); | |
| 6871 ASSERT_NE(0u, encrypted_length); | |
| 6872 | |
| 6873 // Now make sure we can turn our ack packet back into an ack frame. | |
| 6874 ASSERT_TRUE(framer_.ProcessPacket( | |
| 6875 QuicEncryptedPacket(buffer, encrypted_length, false))); | |
| 6876 | |
| 6877 // Test for clean truncation of the ack by comparing the length of the | |
| 6878 // original packets to the re-serialized packets. | |
| 6879 frames.clear(); | |
| 6880 frame.type = ACK_FRAME; | |
| 6881 frame.ack_frame = visitor_.ack_frames_[0]; | |
| 6882 frames.push_back(frame); | |
| 6883 | |
| 6884 size_t original_raw_length = raw_ack_packet->length(); | |
| 6885 raw_ack_packet.reset(BuildDataPacket(header, frames)); | |
| 6886 ASSERT_TRUE(raw_ack_packet != nullptr); | |
| 6887 EXPECT_EQ(original_raw_length, raw_ack_packet->length()); | |
| 6888 ASSERT_TRUE(raw_ack_packet != nullptr); | |
| 6889 } | |
| 6890 | |
| 6891 TEST_P(QuicFramerTest, EntropyFlagTest) { | |
| 6892 if (framer_.version() > QUIC_VERSION_33) { | |
| 6893 return; | |
| 6894 } | |
| 6895 // clang-format off | |
| 6896 unsigned char packet[] = { | |
| 6897 // public flags (8 byte connection_id) | |
| 6898 static_cast<unsigned char>( | |
| 6899 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 6900 // connection_id | |
| 6901 0x10, 0x32, 0x54, 0x76, | |
| 6902 0x98, 0xBA, 0xDC, 0xFE, | |
| 6903 // packet number | |
| 6904 0xBC, 0x9A, 0x78, 0x56, | |
| 6905 0x34, 0x12, | |
| 6906 // private flags (Entropy) | |
| 6907 0x01, | |
| 6908 | |
| 6909 // frame type (stream frame with fin and no length) | |
| 6910 0xDF, | |
| 6911 // stream id | |
| 6912 0x04, 0x03, 0x02, 0x01, | |
| 6913 // offset | |
| 6914 0x54, 0x76, 0x10, 0x32, | |
| 6915 0xDC, 0xFE, 0x98, 0xBA, | |
| 6916 // data | |
| 6917 'h', 'e', 'l', 'l', | |
| 6918 'o', ' ', 'w', 'o', | |
| 6919 'r', 'l', 'd', '!', | |
| 6920 }; | |
| 6921 // clang-format on | |
| 6922 | |
| 6923 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
| 6924 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 6925 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 6926 ASSERT_TRUE(visitor_.header_.get()); | |
| 6927 EXPECT_TRUE(visitor_.header_->entropy_flag); | |
| 6928 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash); | |
| 6929 EXPECT_FALSE(visitor_.header_->fec_flag); | |
| 6930 }; | |
| 6931 | |
| 6932 TEST_P(QuicFramerTest, StopPacketProcessing) { | |
| 6933 // clang-format off | |
| 6934 unsigned char packet[] = { | |
| 6935 // public flags (8 byte connection_id) | |
| 6936 static_cast<unsigned char>( | |
| 6937 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 6938 // connection_id | |
| 6939 0x10, 0x32, 0x54, 0x76, | |
| 6940 0x98, 0xBA, 0xDC, 0xFE, | |
| 6941 // packet number | |
| 6942 0xBC, 0x9A, 0x78, 0x56, | |
| 6943 0x34, 0x12, | |
| 6944 // Entropy | |
| 6945 0x01, | |
| 6946 | |
| 6947 // frame type (stream frame with fin) | |
| 6948 0xFF, | |
| 6949 // stream id | |
| 6950 0x04, 0x03, 0x02, 0x01, | |
| 6951 // offset | |
| 6952 0x54, 0x76, 0x10, 0x32, | |
| 6953 0xDC, 0xFE, 0x98, 0xBA, | |
| 6954 // data length | |
| 6955 0x0c, 0x00, | |
| 6956 // data | |
| 6957 'h', 'e', 'l', 'l', | |
| 6958 'o', ' ', 'w', 'o', | |
| 6959 'r', 'l', 'd', '!', | |
| 6960 | |
| 6961 // frame type (ack frame) | |
| 6962 0x40, | |
| 6963 // entropy hash of sent packets till least awaiting - 1. | |
| 6964 0x14, | |
| 6965 // least packet number awaiting an ack | |
| 6966 0xA0, 0x9A, 0x78, 0x56, | |
| 6967 0x34, 0x12, | |
| 6968 // entropy hash of all received packets. | |
| 6969 0x43, | |
| 6970 // largest observed packet number | |
| 6971 0xBF, 0x9A, 0x78, 0x56, | |
| 6972 0x34, 0x12, | |
| 6973 // num missing packets | |
| 6974 0x01, | |
| 6975 // missing packet | |
| 6976 0xBE, 0x9A, 0x78, 0x56, | |
| 6977 0x34, 0x12, | |
| 6978 }; | |
| 6979 unsigned char packet_34[] = { | |
| 6980 // public flags (8 byte connection_id) | |
| 6981 static_cast<unsigned char>( | |
| 6982 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), | |
| 6983 // connection_id | |
| 6984 0x10, 0x32, 0x54, 0x76, | |
| 6985 0x98, 0xBA, 0xDC, 0xFE, | |
| 6986 // packet number | |
| 6987 0xBC, 0x9A, 0x78, 0x56, | |
| 6988 0x34, 0x12, | |
| 6989 | |
| 6990 // frame type (stream frame with fin) | |
| 6991 0xFF, | |
| 6992 // stream id | |
| 6993 0x04, 0x03, 0x02, 0x01, | |
| 6994 // offset | |
| 6995 0x54, 0x76, 0x10, 0x32, | |
| 6996 0xDC, 0xFE, 0x98, 0xBA, | |
| 6997 // data length | |
| 6998 0x0c, 0x00, | |
| 6999 // data | |
| 7000 'h', 'e', 'l', 'l', | |
| 7001 'o', ' ', 'w', 'o', | |
| 7002 'r', 'l', 'd', '!', | |
| 7003 | |
| 7004 // frame type (ack frame) | |
| 7005 0x40, | |
| 7006 // entropy hash of sent packets till least awaiting - 1. | |
| 7007 0x14, | |
| 7008 // least packet number awaiting an ack | |
| 7009 0xA0, 0x9A, 0x78, 0x56, | |
| 7010 0x34, 0x12, | |
| 7011 // entropy hash of all received packets. | |
| 7012 0x43, | |
| 7013 // largest observed packet number | |
| 7014 0xBF, 0x9A, 0x78, 0x56, | |
| 7015 0x34, 0x12, | |
| 7016 // num missing packets | |
| 7017 0x01, | |
| 7018 // missing packet | |
| 7019 0xBE, 0x9A, 0x78, 0x56, | |
| 7020 0x34, 0x12, | |
| 7021 }; | |
| 7022 // clang-format on | |
| 7023 | |
| 7024 MockFramerVisitor visitor; | |
| 7025 framer_.set_visitor(&visitor); | |
| 7026 EXPECT_CALL(visitor, OnPacket()); | |
| 7027 EXPECT_CALL(visitor, OnPacketHeader(_)); | |
| 7028 EXPECT_CALL(visitor, OnStreamFrame(_)).WillOnce(Return(false)); | |
| 7029 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0); | |
| 7030 EXPECT_CALL(visitor, OnPacketComplete()); | |
| 7031 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); | |
| 7032 EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)).WillOnce(Return(true)); | |
| 7033 EXPECT_CALL(visitor, OnDecryptedPacket(_)); | |
| 7034 | |
| 7035 QuicEncryptedPacket encrypted( | |
| 7036 AsChars(framer_.version() <= QUIC_VERSION_33 ? packet : packet_34), | |
| 7037 framer_.version() <= QUIC_VERSION_33 ? arraysize(packet) | |
| 7038 : arraysize(packet_34), | |
| 7039 false); | |
| 7040 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | |
| 7041 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 7042 } | |
| 7043 | |
| 7044 static char kTestString[] = "At least 20 characters."; | |
| 7045 static QuicStreamId kTestQuicStreamId = 1; | |
| 7046 static bool ExpectedStreamFrame(const QuicStreamFrame& frame) { | |
| 7047 return frame.stream_id == kTestQuicStreamId && !frame.fin && | |
| 7048 frame.offset == 0 && | |
| 7049 string(frame.data_buffer, frame.data_length) == kTestString; | |
| 7050 // FIN is hard-coded false in ConstructEncryptedPacket. | |
| 7051 // Offset 0 is hard-coded in ConstructEncryptedPacket. | |
| 7052 } | |
| 7053 | |
| 7054 // Verify that the packet returned by ConstructEncryptedPacket() can be properly | |
| 7055 // parsed by the framer. | |
| 7056 TEST_P(QuicFramerTest, ConstructEncryptedPacket) { | |
| 7057 // Since we are using ConstructEncryptedPacket, we have to set the framer's | |
| 7058 // crypto to be Null. | |
| 7059 framer_.SetDecrypter(ENCRYPTION_NONE, QuicDecrypter::Create(kNULL)); | |
| 7060 framer_.SetEncrypter(ENCRYPTION_NONE, QuicEncrypter::Create(kNULL)); | |
| 7061 QuicVersionVector versions; | |
| 7062 versions.push_back(framer_.version()); | |
| 7063 std::unique_ptr<QuicEncryptedPacket> packet(ConstructEncryptedPacket( | |
| 7064 42, false, false, false, kDefaultPathId, kTestQuicStreamId, kTestString, | |
| 7065 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, &versions)); | |
| 7066 | |
| 7067 MockFramerVisitor visitor; | |
| 7068 framer_.set_visitor(&visitor); | |
| 7069 EXPECT_CALL(visitor, OnPacket()).Times(1); | |
| 7070 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)) | |
| 7071 .Times(1) | |
| 7072 .WillOnce(Return(true)); | |
| 7073 EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)) | |
| 7074 .Times(1) | |
| 7075 .WillOnce(Return(true)); | |
| 7076 EXPECT_CALL(visitor, OnPacketHeader(_)).Times(1).WillOnce(Return(true)); | |
| 7077 EXPECT_CALL(visitor, OnDecryptedPacket(_)).Times(1); | |
| 7078 EXPECT_CALL(visitor, OnError(_)).Times(0); | |
| 7079 EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0); | |
| 7080 EXPECT_CALL(visitor, OnStreamFrame(Truly(ExpectedStreamFrame))).Times(1); | |
| 7081 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0); | |
| 7082 EXPECT_CALL(visitor, OnPacketComplete()).Times(1); | |
| 7083 | |
| 7084 EXPECT_TRUE(framer_.ProcessPacket(*packet)); | |
| 7085 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | |
| 7086 } | |
| 7087 | |
| 7088 // Verify that the packet returned by ConstructMisFramedEncryptedPacket() | |
| 7089 // does cause the framer to return an error. | |
| 7090 TEST_P(QuicFramerTest, ConstructMisFramedEncryptedPacket) { | |
| 7091 // Since we are using ConstructEncryptedPacket, we have to set the framer's | |
| 7092 // crypto to be Null. | |
| 7093 framer_.SetDecrypter(ENCRYPTION_NONE, QuicDecrypter::Create(kNULL)); | |
| 7094 framer_.SetEncrypter(ENCRYPTION_NONE, QuicEncrypter::Create(kNULL)); | |
| 7095 QuicVersionVector versions; | |
| 7096 versions.push_back(framer_.version()); | |
| 7097 std::unique_ptr<QuicEncryptedPacket> packet(ConstructMisFramedEncryptedPacket( | |
| 7098 42, false, false, false, kDefaultPathId, kTestQuicStreamId, kTestString, | |
| 7099 PACKET_8BYTE_CONNECTION_ID, PACKET_6BYTE_PACKET_NUMBER, &versions, | |
| 7100 Perspective::IS_SERVER)); | |
| 7101 | |
| 7102 MockFramerVisitor visitor; | |
| 7103 framer_.set_visitor(&visitor); | |
| 7104 EXPECT_CALL(visitor, OnPacket()).Times(1); | |
| 7105 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)) | |
| 7106 .Times(1) | |
| 7107 .WillOnce(Return(true)); | |
| 7108 EXPECT_CALL(visitor, OnUnauthenticatedHeader(_)) | |
| 7109 .Times(1) | |
| 7110 .WillOnce(Return(true)); | |
| 7111 if (framer_.version() <= QUIC_VERSION_33) { | |
| 7112 EXPECT_CALL(visitor, OnPacketHeader(_)).Times(0); | |
| 7113 } else { | |
| 7114 EXPECT_CALL(visitor, OnPacketHeader(_)).Times(1); | |
| 7115 } | |
| 7116 EXPECT_CALL(visitor, OnDecryptedPacket(_)).Times(1); | |
| 7117 EXPECT_CALL(visitor, OnError(_)).Times(1); | |
| 7118 EXPECT_CALL(visitor, OnStreamFrame(_)).Times(0); | |
| 7119 EXPECT_CALL(visitor, OnAckFrame(_)).Times(0); | |
| 7120 EXPECT_CALL(visitor, OnPacketComplete()).Times(0); | |
| 7121 | |
| 7122 EXPECT_FALSE(framer_.ProcessPacket(*packet)); | |
| 7123 if (framer_.version() <= QUIC_VERSION_33) { | |
| 7124 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); | |
| 7125 } else { | |
| 7126 EXPECT_EQ(QUIC_INVALID_FRAME_DATA, framer_.error()); | |
| 7127 } | |
| 7128 } | |
| 7129 | |
| 7130 // Tests for fuzzing with Dr. Fuzz | |
| 7131 // Xref http://www.chromium.org/developers/testing/dr-fuzz for more details. | |
| 7132 #ifdef __cplusplus | |
| 7133 extern "C" { | |
| 7134 #endif | |
| 7135 | |
| 7136 // target function to be fuzzed by Dr. Fuzz | |
| 7137 void QuicFramerFuzzFunc(unsigned char* data, size_t size) { | |
| 7138 QuicFramer framer(QuicSupportedVersions(), QuicTime::Zero(), | |
| 7139 Perspective::IS_SERVER); | |
| 7140 const char* const packet_bytes = reinterpret_cast<const char*>(data); | |
| 7141 | |
| 7142 // Test the CryptoFramer. | |
| 7143 StringPiece crypto_input(packet_bytes, size); | |
| 7144 std::unique_ptr<CryptoHandshakeMessage> handshake_message( | |
| 7145 CryptoFramer::ParseMessage(crypto_input)); | |
| 7146 | |
| 7147 // Test the regular QuicFramer with the same input. | |
| 7148 NoOpFramerVisitor visitor; | |
| 7149 framer.set_visitor(&visitor); | |
| 7150 QuicEncryptedPacket packet(packet_bytes, size); | |
| 7151 framer.ProcessPacket(packet); | |
| 7152 } | |
| 7153 | |
| 7154 #ifdef __cplusplus | |
| 7155 } | |
| 7156 #endif | |
| 7157 | |
| 7158 TEST_P(QuicFramerTest, FramerFuzzTest) { | |
| 7159 // clang-format off | |
| 7160 unsigned char packet[] = { | |
| 7161 // public flags (8 byte connection_id) | |
| 7162 0x3C, | |
| 7163 // connection_id | |
| 7164 0x10, 0x32, 0x54, 0x76, | |
| 7165 0x98, 0xBA, 0xDC, 0xFE, | |
| 7166 // packet number | |
| 7167 0xBC, 0x9A, 0x78, 0x56, | |
| 7168 0x34, 0x12, | |
| 7169 // private flags | |
| 7170 0x00, | |
| 7171 | |
| 7172 // frame type (stream frame with fin) | |
| 7173 0xFF, | |
| 7174 // stream id | |
| 7175 0x04, 0x03, 0x02, 0x01, | |
| 7176 // offset | |
| 7177 0x54, 0x76, 0x10, 0x32, | |
| 7178 0xDC, 0xFE, 0x98, 0xBA, | |
| 7179 // data length | |
| 7180 0x0c, 0x00, | |
| 7181 // data | |
| 7182 'h', 'e', 'l', 'l', | |
| 7183 'o', ' ', 'w', 'o', | |
| 7184 'r', 'l', 'd', '!', | |
| 7185 }; | |
| 7186 // clang-format on | |
| 7187 | |
| 7188 QuicFramerFuzzFunc(packet, arraysize(packet)); | |
| 7189 } | |
| 7190 | |
| 7191 } // namespace test | |
| 7192 } // namespace net | |
| OLD | NEW |