OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/quic/quic_framer.h" | 5 #include "net/quic/quic_framer.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 QuicPacketNumber packet_number_; | 144 QuicPacketNumber packet_number_; |
145 string associated_data_; | 145 string associated_data_; |
146 string plaintext_; | 146 string plaintext_; |
147 }; | 147 }; |
148 | 148 |
149 class TestDecrypter : public QuicDecrypter { | 149 class TestDecrypter : public QuicDecrypter { |
150 public: | 150 public: |
151 ~TestDecrypter() override {} | 151 ~TestDecrypter() override {} |
152 bool SetKey(StringPiece key) override { return true; } | 152 bool SetKey(StringPiece key) override { return true; } |
153 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; } | 153 bool SetNoncePrefix(StringPiece nonce_prefix) override { return true; } |
| 154 bool SetPreliminaryKey(StringPiece key) override { |
| 155 QUIC_BUG << "should not be called"; |
| 156 return false; |
| 157 } |
| 158 bool SetDiversificationNonce(DiversificationNonce key) override { |
| 159 return true; |
| 160 } |
154 bool DecryptPacket(QuicPathId path_id, | 161 bool DecryptPacket(QuicPathId path_id, |
155 QuicPacketNumber packet_number, | 162 QuicPacketNumber packet_number, |
156 StringPiece associated_data, | 163 StringPiece associated_data, |
157 StringPiece ciphertext, | 164 StringPiece ciphertext, |
158 char* output, | 165 char* output, |
159 size_t* output_length, | 166 size_t* output_length, |
160 size_t max_output_length) override { | 167 size_t max_output_length) override { |
161 path_id_ = path_id; | 168 path_id_ = path_id; |
162 packet_number_ = packet_number; | 169 packet_number_ = packet_number; |
163 associated_data_ = associated_data.as_string(); | 170 associated_data_ = associated_data.as_string(); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 LOG(ERROR) << "Encrypted incorrect plaintext data. expected " | 381 LOG(ERROR) << "Encrypted incorrect plaintext data. expected " |
375 << packet->Plaintext() | 382 << packet->Plaintext() |
376 << " actual: " << encrypter_->plaintext_; | 383 << " actual: " << encrypter_->plaintext_; |
377 return false; | 384 return false; |
378 } | 385 } |
379 return true; | 386 return true; |
380 } | 387 } |
381 | 388 |
382 bool CheckDecryption(const QuicEncryptedPacket& encrypted, | 389 bool CheckDecryption(const QuicEncryptedPacket& encrypted, |
383 bool includes_version, | 390 bool includes_version, |
384 bool includes_path_id) { | 391 bool includes_path_id, |
| 392 bool includes_diversification_nonce) { |
385 if (visitor_.header_->packet_number != decrypter_->packet_number_) { | 393 if (visitor_.header_->packet_number != decrypter_->packet_number_) { |
386 LOG(ERROR) << "Decrypted incorrect packet number. expected " | 394 LOG(ERROR) << "Decrypted incorrect packet number. expected " |
387 << visitor_.header_->packet_number | 395 << visitor_.header_->packet_number |
388 << " actual: " << decrypter_->packet_number_; | 396 << " actual: " << decrypter_->packet_number_; |
389 return false; | 397 return false; |
390 } | 398 } |
391 if (QuicFramer::GetAssociatedDataFromEncryptedPacket( | 399 if (QuicFramer::GetAssociatedDataFromEncryptedPacket( |
392 encrypted, PACKET_8BYTE_CONNECTION_ID, includes_version, | 400 encrypted, PACKET_8BYTE_CONNECTION_ID, includes_version, |
393 includes_path_id, | 401 includes_path_id, includes_diversification_nonce, |
394 PACKET_6BYTE_PACKET_NUMBER) != decrypter_->associated_data_) { | 402 PACKET_6BYTE_PACKET_NUMBER) != decrypter_->associated_data_) { |
395 LOG(ERROR) << "Decrypted incorrect associated data. expected " | 403 LOG(ERROR) << "Decrypted incorrect associated data. expected " |
396 << QuicFramer::GetAssociatedDataFromEncryptedPacket( | 404 << QuicFramer::GetAssociatedDataFromEncryptedPacket( |
397 encrypted, PACKET_8BYTE_CONNECTION_ID, includes_version, | 405 encrypted, PACKET_8BYTE_CONNECTION_ID, includes_version, |
398 includes_path_id, PACKET_6BYTE_PACKET_NUMBER) | 406 includes_path_id, includes_diversification_nonce, |
| 407 PACKET_6BYTE_PACKET_NUMBER) |
399 << " actual: " << decrypter_->associated_data_; | 408 << " actual: " << decrypter_->associated_data_; |
400 return false; | 409 return false; |
401 } | 410 } |
402 StringPiece ciphertext(encrypted.AsStringPiece().substr( | 411 StringPiece ciphertext( |
403 GetStartOfEncryptedData(PACKET_8BYTE_CONNECTION_ID, includes_version, | 412 encrypted.AsStringPiece().substr(GetStartOfEncryptedData( |
404 includes_path_id, PACKET_6BYTE_PACKET_NUMBER))); | 413 PACKET_8BYTE_CONNECTION_ID, includes_version, includes_path_id, |
| 414 includes_diversification_nonce, PACKET_6BYTE_PACKET_NUMBER))); |
405 if (ciphertext != decrypter_->ciphertext_) { | 415 if (ciphertext != decrypter_->ciphertext_) { |
406 LOG(ERROR) << "Decrypted incorrect ciphertext data. expected " | 416 LOG(ERROR) << "Decrypted incorrect ciphertext data. expected " |
407 << ciphertext << " actual: " << decrypter_->ciphertext_; | 417 << ciphertext << " actual: " << decrypter_->ciphertext_; |
408 return false; | 418 return false; |
409 } | 419 } |
410 return true; | 420 return true; |
411 } | 421 } |
412 | 422 |
413 char* AsChars(unsigned char* data) { return reinterpret_cast<char*>(data); } | 423 char* AsChars(unsigned char* data) { return reinterpret_cast<char*>(data); } |
414 | 424 |
(...skipping 21 matching lines...) Expand all Loading... |
436 if (i < kQuicFrameTypeSize + stream_id_size) { | 446 if (i < kQuicFrameTypeSize + stream_id_size) { |
437 expected_error = "Unable to read stream_id."; | 447 expected_error = "Unable to read stream_id."; |
438 } else if (i < kQuicFrameTypeSize + stream_id_size + | 448 } else if (i < kQuicFrameTypeSize + stream_id_size + |
439 kQuicMaxStreamOffsetSize) { | 449 kQuicMaxStreamOffsetSize) { |
440 expected_error = "Unable to read offset."; | 450 expected_error = "Unable to read offset."; |
441 } else { | 451 } else { |
442 expected_error = "Unable to read frame data."; | 452 expected_error = "Unable to read frame data."; |
443 } | 453 } |
444 CheckProcessingFails( | 454 CheckProcessingFails( |
445 packet, | 455 packet, |
446 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, include_version, | 456 i + GetPacketHeaderSize( |
447 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER), | 457 PACKET_8BYTE_CONNECTION_ID, include_version, !kIncludePathId, |
| 458 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER), |
448 expected_error, QUIC_INVALID_STREAM_DATA); | 459 expected_error, QUIC_INVALID_STREAM_DATA); |
449 } | 460 } |
450 } | 461 } |
451 | 462 |
452 void CheckCalculatePacketNumber(QuicPacketNumber expected_packet_number, | 463 void CheckCalculatePacketNumber(QuicPacketNumber expected_packet_number, |
453 QuicPacketNumber last_packet_number) { | 464 QuicPacketNumber last_packet_number) { |
454 QuicPacketNumber wire_packet_number = expected_packet_number & kMask; | 465 QuicPacketNumber wire_packet_number = expected_packet_number & kMask; |
455 QuicFramerPeer::SetLastPacketNumber(&framer_, last_packet_number); | 466 QuicFramerPeer::SetLastPacketNumber(&framer_, last_packet_number); |
456 EXPECT_EQ( | 467 EXPECT_EQ( |
457 expected_packet_number, | 468 expected_packet_number, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 char packet[] = {0x00}; | 603 char packet[] = {0x00}; |
593 QuicEncryptedPacket encrypted(packet, 0, false); | 604 QuicEncryptedPacket encrypted(packet, 0, false); |
594 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | 605 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
595 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); | 606 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
596 } | 607 } |
597 | 608 |
598 TEST_P(QuicFramerTest, LargePacket) { | 609 TEST_P(QuicFramerTest, LargePacket) { |
599 // clang-format off | 610 // clang-format off |
600 unsigned char packet[kMaxPacketSize + 1] = { | 611 unsigned char packet[kMaxPacketSize + 1] = { |
601 // public flags (8 byte connection_id) | 612 // public flags (8 byte connection_id) |
602 0x3C, | 613 0x38, |
603 // connection_id | 614 // connection_id |
604 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 615 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
605 // packet number | 616 // packet number |
606 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 617 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
607 // private flags | 618 // private flags |
608 0x00, | 619 0x00, |
609 }; | 620 }; |
| 621 // clang-format on |
610 | 622 |
611 memset(packet + GetPacketHeaderSize( | 623 const size_t header_size = GetPacketHeaderSize( |
612 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, !kIncludePathId, | 624 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, !kIncludePathId, |
613 PACKET_6BYTE_PACKET_NUMBER), 0, | 625 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER); |
614 kMaxPacketSize - GetPacketHeaderSize( | 626 |
615 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, !kIncludePathId, | 627 memset(packet + header_size, 0, kMaxPacketSize - header_size); |
616 PACKET_6BYTE_PACKET_NUMBER) + 1); | |
617 // clang-format on | |
618 | 628 |
619 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 629 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
620 EXPECT_DFATAL(framer_.ProcessPacket(encrypted), "Packet too large:1"); | 630 EXPECT_DFATAL(framer_.ProcessPacket(encrypted), "Packet too large:1"); |
621 | 631 |
622 ASSERT_TRUE(visitor_.header_.get()); | 632 ASSERT_TRUE(visitor_.header_.get()); |
623 // Make sure we've parsed the packet header, so we can send an error. | 633 // Make sure we've parsed the packet header, so we can send an error. |
624 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | 634 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); |
625 // Make sure the correct error is propagated. | 635 // Make sure the correct error is propagated. |
626 EXPECT_EQ(QUIC_PACKET_TOO_LARGE, framer_.error()); | 636 EXPECT_EQ(QUIC_PACKET_TOO_LARGE, framer_.error()); |
627 } | 637 } |
628 | 638 |
629 TEST_P(QuicFramerTest, PacketHeader) { | 639 TEST_P(QuicFramerTest, PacketHeader) { |
630 // clang-format off | 640 // clang-format off |
631 unsigned char packet[] = { | 641 unsigned char packet[] = { |
632 // public flags (8 byte connection_id) | 642 // public flags (8 byte connection_id) |
633 0x3C, | 643 0x38, |
634 // connection_id | 644 // connection_id |
635 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 645 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
636 // packet number | 646 // packet number |
637 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 647 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
638 // private flags | 648 // private flags |
639 0x00, | 649 0x00, |
640 }; | 650 }; |
641 // clang-format on | 651 // clang-format on |
642 | 652 |
643 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 653 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
644 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | 654 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
645 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | 655 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
646 ASSERT_TRUE(visitor_.header_.get()); | 656 ASSERT_TRUE(visitor_.header_.get()); |
647 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | 657 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); |
648 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); | 658 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); |
649 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); | 659 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); |
650 EXPECT_FALSE(visitor_.header_->public_header.version_flag); | 660 EXPECT_FALSE(visitor_.header_->public_header.version_flag); |
651 EXPECT_FALSE(visitor_.header_->fec_flag); | 661 EXPECT_FALSE(visitor_.header_->fec_flag); |
652 EXPECT_FALSE(visitor_.header_->entropy_flag); | 662 EXPECT_FALSE(visitor_.header_->entropy_flag); |
653 EXPECT_EQ(0, visitor_.header_->entropy_hash); | 663 EXPECT_EQ(0, visitor_.header_->entropy_hash); |
654 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | 664 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
655 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); | 665 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); |
656 EXPECT_EQ(0u, visitor_.header_->fec_group); | 666 EXPECT_EQ(0u, visitor_.header_->fec_group); |
657 | 667 |
658 // Now test framing boundaries. | 668 // Now test framing boundaries. |
659 for (size_t i = 0; | 669 for (size_t i = 0; |
660 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 670 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
661 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER); | 671 !kIncludePathId, !kIncludeDiversificationNonce, |
| 672 PACKET_6BYTE_PACKET_NUMBER); |
662 ++i) { | 673 ++i) { |
663 string expected_error; | 674 string expected_error; |
664 if (i < kConnectionIdOffset) { | 675 if (i < kConnectionIdOffset) { |
665 expected_error = "Unable to read public flags."; | 676 expected_error = "Unable to read public flags."; |
666 } else if (i < GetPacketNumberOffset(!kIncludeVersion, !kIncludePathId)) { | 677 } else if (i < GetPacketNumberOffset(!kIncludeVersion, !kIncludePathId)) { |
667 expected_error = "Unable to read ConnectionId."; | 678 expected_error = "Unable to read ConnectionId."; |
668 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion, !kIncludePathId)) { | 679 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion, !kIncludePathId)) { |
669 expected_error = "Unable to read packet number."; | 680 expected_error = "Unable to read packet number."; |
670 } else { | 681 } else { |
671 expected_error = "Unable to read private flags."; | 682 expected_error = "Unable to read private flags."; |
672 } | 683 } |
673 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); | 684 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); |
674 } | 685 } |
675 } | 686 } |
676 | 687 |
677 TEST_P(QuicFramerTest, PacketHeaderWith4ByteConnectionId) { | |
678 QuicFramerPeer::SetLastSerializedConnectionId(&framer_, kConnectionId); | |
679 | |
680 // clang-format off | |
681 unsigned char packet[] = { | |
682 // public flags (4 byte connection_id) | |
683 0x38, | |
684 // connection_id | |
685 0x10, 0x32, 0x54, 0x76, | |
686 // packet number | |
687 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
688 // private flags | |
689 0x00, | |
690 }; | |
691 // clang-format on | |
692 | |
693 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
694 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | |
695 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | |
696 ASSERT_TRUE(visitor_.header_.get()); | |
697 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | |
698 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); | |
699 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); | |
700 EXPECT_FALSE(visitor_.header_->public_header.version_flag); | |
701 EXPECT_FALSE(visitor_.header_->fec_flag); | |
702 EXPECT_FALSE(visitor_.header_->entropy_flag); | |
703 EXPECT_EQ(0, visitor_.header_->entropy_hash); | |
704 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | |
705 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); | |
706 EXPECT_EQ(0u, visitor_.header_->fec_group); | |
707 | |
708 // Now test framing boundaries. | |
709 for (size_t i = 0; | |
710 i < GetPacketHeaderSize(PACKET_4BYTE_CONNECTION_ID, !kIncludeVersion, | |
711 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER); | |
712 ++i) { | |
713 string expected_error; | |
714 if (i < kConnectionIdOffset) { | |
715 expected_error = "Unable to read public flags."; | |
716 } else if (i < GetPacketNumberOffset(PACKET_4BYTE_CONNECTION_ID, | |
717 !kIncludeVersion, !kIncludePathId)) { | |
718 expected_error = "Unable to read ConnectionId."; | |
719 } else if (i < GetPrivateFlagsOffset(PACKET_4BYTE_CONNECTION_ID, | |
720 !kIncludeVersion, !kIncludePathId)) { | |
721 expected_error = "Unable to read packet number."; | |
722 } else { | |
723 expected_error = "Unable to read private flags."; | |
724 } | |
725 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); | |
726 } | |
727 } | |
728 | |
729 TEST_P(QuicFramerTest, PacketHeader1ByteConnectionId) { | |
730 QuicFramerPeer::SetLastSerializedConnectionId(&framer_, kConnectionId); | |
731 | |
732 // clang-format off | |
733 unsigned char packet[] = { | |
734 // public flags (1 byte connection_id) | |
735 0x34, | |
736 // connection_id | |
737 0x10, | |
738 // packet number | |
739 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | |
740 // private flags | |
741 0x00, | |
742 }; | |
743 // clang-format on | |
744 | |
745 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | |
746 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | |
747 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | |
748 ASSERT_TRUE(visitor_.header_.get()); | |
749 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | |
750 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); | |
751 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); | |
752 EXPECT_FALSE(visitor_.header_->public_header.version_flag); | |
753 EXPECT_FALSE(visitor_.header_->fec_flag); | |
754 EXPECT_FALSE(visitor_.header_->entropy_flag); | |
755 EXPECT_EQ(0, visitor_.header_->entropy_hash); | |
756 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | |
757 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); | |
758 EXPECT_EQ(0u, visitor_.header_->fec_group); | |
759 | |
760 // Now test framing boundaries. | |
761 for (size_t i = 0; | |
762 i < GetPacketHeaderSize(PACKET_1BYTE_CONNECTION_ID, !kIncludeVersion, | |
763 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER); | |
764 ++i) { | |
765 string expected_error; | |
766 if (i < kConnectionIdOffset) { | |
767 expected_error = "Unable to read public flags."; | |
768 } else if (i < GetPacketNumberOffset(PACKET_1BYTE_CONNECTION_ID, | |
769 !kIncludeVersion, !kIncludePathId)) { | |
770 expected_error = "Unable to read ConnectionId."; | |
771 } else if (i < GetPrivateFlagsOffset(PACKET_1BYTE_CONNECTION_ID, | |
772 !kIncludeVersion, !kIncludePathId)) { | |
773 expected_error = "Unable to read packet number."; | |
774 } else { | |
775 expected_error = "Unable to read private flags."; | |
776 } | |
777 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); | |
778 } | |
779 } | |
780 | |
781 TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) { | 688 TEST_P(QuicFramerTest, PacketHeaderWith0ByteConnectionId) { |
782 QuicFramerPeer::SetLastSerializedConnectionId(&framer_, kConnectionId); | 689 QuicFramerPeer::SetLastSerializedConnectionId(&framer_, kConnectionId); |
783 | 690 |
784 // clang-format off | 691 // clang-format off |
785 unsigned char packet[] = { | 692 unsigned char packet[] = { |
786 // public flags (0 byte connection_id) | 693 // public flags (0 byte connection_id) |
787 0x30, | 694 0x30, |
788 // connection_id | 695 // connection_id |
789 // packet number | 696 // packet number |
790 0xBC, 0x9A, 0x78, 0x56, | 697 0xBC, 0x9A, 0x78, 0x56, |
(...skipping 14 matching lines...) Expand all Loading... |
805 EXPECT_FALSE(visitor_.header_->fec_flag); | 712 EXPECT_FALSE(visitor_.header_->fec_flag); |
806 EXPECT_FALSE(visitor_.header_->entropy_flag); | 713 EXPECT_FALSE(visitor_.header_->entropy_flag); |
807 EXPECT_EQ(0, visitor_.header_->entropy_hash); | 714 EXPECT_EQ(0, visitor_.header_->entropy_hash); |
808 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | 715 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
809 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); | 716 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); |
810 EXPECT_EQ(0u, visitor_.header_->fec_group); | 717 EXPECT_EQ(0u, visitor_.header_->fec_group); |
811 | 718 |
812 // Now test framing boundaries. | 719 // Now test framing boundaries. |
813 for (size_t i = 0; | 720 for (size_t i = 0; |
814 i < GetPacketHeaderSize(PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, | 721 i < GetPacketHeaderSize(PACKET_0BYTE_CONNECTION_ID, !kIncludeVersion, |
815 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER); | 722 !kIncludePathId, !kIncludeDiversificationNonce, |
| 723 PACKET_6BYTE_PACKET_NUMBER); |
816 ++i) { | 724 ++i) { |
817 string expected_error; | 725 string expected_error; |
818 if (i < kConnectionIdOffset) { | 726 if (i < kConnectionIdOffset) { |
819 expected_error = "Unable to read public flags."; | 727 expected_error = "Unable to read public flags."; |
820 } else if (i < GetPacketNumberOffset(PACKET_0BYTE_CONNECTION_ID, | 728 } else if (i < GetPacketNumberOffset(PACKET_0BYTE_CONNECTION_ID, |
821 !kIncludeVersion, !kIncludePathId)) { | 729 !kIncludeVersion, !kIncludePathId)) { |
822 expected_error = "Unable to read ConnectionId."; | 730 expected_error = "Unable to read ConnectionId."; |
823 } else if (i < GetPrivateFlagsOffset(PACKET_0BYTE_CONNECTION_ID, | 731 } else if (i < GetPrivateFlagsOffset(PACKET_0BYTE_CONNECTION_ID, |
824 !kIncludeVersion, !kIncludePathId)) { | 732 !kIncludeVersion, !kIncludePathId)) { |
825 expected_error = "Unable to read packet number."; | 733 expected_error = "Unable to read packet number."; |
826 } else { | 734 } else { |
827 expected_error = "Unable to read private flags."; | 735 expected_error = "Unable to read private flags."; |
828 } | 736 } |
829 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); | 737 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); |
830 } | 738 } |
831 } | 739 } |
832 | 740 |
833 TEST_P(QuicFramerTest, PacketHeaderWithVersionFlag) { | 741 TEST_P(QuicFramerTest, PacketHeaderWithVersionFlag) { |
834 // clang-format off | 742 // clang-format off |
835 unsigned char packet[] = { | 743 unsigned char packet[] = { |
836 // public flags (version) | 744 // public flags (version) |
837 0x3D, | 745 0x39, |
838 // connection_id | 746 // connection_id |
839 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 747 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
840 // version tag | 748 // version tag |
841 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | 749 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), |
842 // packet number | 750 // packet number |
843 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 751 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
844 // private flags | 752 // private flags |
845 0x00, | 753 0x00, |
846 }; | 754 }; |
847 // clang-format on | 755 // clang-format on |
(...skipping 10 matching lines...) Expand all Loading... |
858 EXPECT_FALSE(visitor_.header_->fec_flag); | 766 EXPECT_FALSE(visitor_.header_->fec_flag); |
859 EXPECT_FALSE(visitor_.header_->entropy_flag); | 767 EXPECT_FALSE(visitor_.header_->entropy_flag); |
860 EXPECT_EQ(0, visitor_.header_->entropy_hash); | 768 EXPECT_EQ(0, visitor_.header_->entropy_hash); |
861 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | 769 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
862 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); | 770 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); |
863 EXPECT_EQ(0u, visitor_.header_->fec_group); | 771 EXPECT_EQ(0u, visitor_.header_->fec_group); |
864 | 772 |
865 // Now test framing boundaries. | 773 // Now test framing boundaries. |
866 for (size_t i = 0; | 774 for (size_t i = 0; |
867 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, kIncludeVersion, | 775 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, kIncludeVersion, |
868 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER); | 776 !kIncludePathId, !kIncludeDiversificationNonce, |
| 777 PACKET_6BYTE_PACKET_NUMBER); |
869 ++i) { | 778 ++i) { |
870 string expected_error; | 779 string expected_error; |
871 if (i < kConnectionIdOffset) { | 780 if (i < kConnectionIdOffset) { |
872 expected_error = "Unable to read public flags."; | 781 expected_error = "Unable to read public flags."; |
873 } else if (i < kVersionOffset) { | 782 } else if (i < kVersionOffset) { |
874 expected_error = "Unable to read ConnectionId."; | 783 expected_error = "Unable to read ConnectionId."; |
875 } else if (i < GetPacketNumberOffset(kIncludeVersion, !kIncludePathId)) { | 784 } else if (i < GetPacketNumberOffset(kIncludeVersion, !kIncludePathId)) { |
876 expected_error = "Unable to read protocol version."; | 785 expected_error = "Unable to read protocol version."; |
877 } else if (i < GetPrivateFlagsOffset(kIncludeVersion, !kIncludePathId)) { | 786 } else if (i < GetPrivateFlagsOffset(kIncludeVersion, !kIncludePathId)) { |
878 expected_error = "Unable to read packet number."; | 787 expected_error = "Unable to read packet number."; |
879 } else { | 788 } else { |
880 expected_error = "Unable to read private flags."; | 789 expected_error = "Unable to read private flags."; |
881 } | 790 } |
882 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); | 791 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); |
883 } | 792 } |
884 } | 793 } |
885 | 794 |
886 TEST_P(QuicFramerTest, PacketHeaderWithMultipathFlag) { | 795 TEST_P(QuicFramerTest, PacketHeaderWithMultipathFlag) { |
887 // clang-format off | 796 // clang-format off |
888 unsigned char packet[] = { | 797 unsigned char packet[] = { |
889 // public flags (version) | 798 // public flags (version) |
890 0x7C, | 799 0x78, |
891 // connection_id | 800 // connection_id |
892 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 801 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
893 // path_id | 802 // path_id |
894 0x42, | 803 0x42, |
895 // packet number | 804 // packet number |
896 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 805 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
897 // private flags | 806 // private flags |
898 0x00, | 807 0x00, |
899 }; | 808 }; |
900 // clang-format on | 809 // clang-format on |
901 | 810 |
902 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 811 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
903 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | 812 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
904 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | 813 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
905 ASSERT_TRUE(visitor_.header_.get()); | 814 ASSERT_TRUE(visitor_.header_.get()); |
906 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, kIncludePathId)); | 815 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, kIncludePathId, |
| 816 !kIncludeDiversificationNonce)); |
907 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | 817 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); |
908 EXPECT_TRUE(visitor_.header_->public_header.multipath_flag); | 818 EXPECT_TRUE(visitor_.header_->public_header.multipath_flag); |
909 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); | 819 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); |
910 EXPECT_FALSE(visitor_.header_->public_header.version_flag); | 820 EXPECT_FALSE(visitor_.header_->public_header.version_flag); |
911 EXPECT_FALSE(visitor_.header_->fec_flag); | 821 EXPECT_FALSE(visitor_.header_->fec_flag); |
912 EXPECT_FALSE(visitor_.header_->entropy_flag); | 822 EXPECT_FALSE(visitor_.header_->entropy_flag); |
913 EXPECT_EQ(0, visitor_.header_->entropy_hash); | 823 EXPECT_EQ(0, visitor_.header_->entropy_hash); |
914 EXPECT_EQ(kPathId, visitor_.header_->path_id); | 824 EXPECT_EQ(kPathId, visitor_.header_->path_id); |
915 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | 825 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
916 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); | 826 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); |
917 EXPECT_EQ(0u, visitor_.header_->fec_group); | 827 EXPECT_EQ(0u, visitor_.header_->fec_group); |
918 | 828 |
919 // Now test framing boundaries. | 829 // Now test framing boundaries. |
920 for (size_t i = 0; | 830 for (size_t i = 0; |
921 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 831 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
922 kIncludePathId, PACKET_6BYTE_PACKET_NUMBER); | 832 kIncludePathId, !kIncludeDiversificationNonce, |
| 833 PACKET_6BYTE_PACKET_NUMBER); |
923 ++i) { | 834 ++i) { |
924 string expected_error; | 835 string expected_error; |
925 if (i < kConnectionIdOffset) { | 836 if (i < kConnectionIdOffset) { |
926 expected_error = "Unable to read public flags."; | 837 expected_error = "Unable to read public flags."; |
927 } else if (i < | 838 } else if (i < |
928 GetPathIdOffset(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion)) { | 839 GetPathIdOffset(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion)) { |
929 expected_error = "Unable to read ConnectionId."; | 840 expected_error = "Unable to read ConnectionId."; |
930 } else if (i < GetPacketNumberOffset(!kIncludeVersion, kIncludePathId)) { | 841 } else if (i < GetPacketNumberOffset(!kIncludeVersion, kIncludePathId)) { |
931 expected_error = "Unable to read path id."; | 842 expected_error = "Unable to read path id."; |
932 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion, kIncludePathId)) { | 843 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion, kIncludePathId)) { |
933 expected_error = "Unable to read packet number."; | 844 expected_error = "Unable to read packet number."; |
934 } else { | 845 } else { |
935 expected_error = "Unable to read private flags."; | 846 expected_error = "Unable to read private flags."; |
936 } | 847 } |
937 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); | 848 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); |
938 } | 849 } |
939 } | 850 } |
940 | 851 |
941 TEST_P(QuicFramerTest, PacketHeaderWithBothVersionFlagAndMultipathFlag) { | 852 TEST_P(QuicFramerTest, PacketHeaderWithBothVersionFlagAndMultipathFlag) { |
942 // clang-format off | 853 // clang-format off |
943 unsigned char packet[] = { | 854 unsigned char packet[] = { |
944 // public flags (version) | 855 // public flags (version) |
945 0x7D, | 856 0x79, |
946 // connection_id | 857 // connection_id |
947 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 858 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
948 // version tag | 859 // version tag |
949 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | 860 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), |
950 // path_id | 861 // path_id |
951 0x42, | 862 0x42, |
952 // packet number | 863 // packet number |
953 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 864 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
954 // private flags | 865 // private flags |
955 0x00, | 866 0x00, |
956 }; | 867 }; |
957 // clang-format on | 868 // clang-format on |
958 | 869 |
959 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 870 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
960 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | 871 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
961 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | 872 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
962 ASSERT_TRUE(visitor_.header_.get()); | 873 ASSERT_TRUE(visitor_.header_.get()); |
963 EXPECT_TRUE(CheckDecryption(encrypted, kIncludeVersion, kIncludePathId)); | 874 EXPECT_TRUE(CheckDecryption(encrypted, kIncludeVersion, kIncludePathId, |
| 875 !kIncludeDiversificationNonce)); |
964 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | 876 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); |
965 EXPECT_TRUE(visitor_.header_->public_header.multipath_flag); | 877 EXPECT_TRUE(visitor_.header_->public_header.multipath_flag); |
966 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); | 878 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); |
967 EXPECT_TRUE(visitor_.header_->public_header.version_flag); | 879 EXPECT_TRUE(visitor_.header_->public_header.version_flag); |
968 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]); | 880 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]); |
969 EXPECT_FALSE(visitor_.header_->fec_flag); | 881 EXPECT_FALSE(visitor_.header_->fec_flag); |
970 EXPECT_FALSE(visitor_.header_->entropy_flag); | 882 EXPECT_FALSE(visitor_.header_->entropy_flag); |
971 EXPECT_EQ(0, visitor_.header_->entropy_hash); | 883 EXPECT_EQ(0, visitor_.header_->entropy_hash); |
972 EXPECT_EQ(kPathId, visitor_.header_->path_id); | 884 EXPECT_EQ(kPathId, visitor_.header_->path_id); |
973 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | 885 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
974 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); | 886 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); |
975 EXPECT_EQ(0u, visitor_.header_->fec_group); | 887 EXPECT_EQ(0u, visitor_.header_->fec_group); |
976 | 888 |
977 // Now test framing boundaries. | 889 // Now test framing boundaries. |
978 for (size_t i = 0; | 890 for (size_t i = 0; |
979 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 891 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
980 kIncludePathId, PACKET_6BYTE_PACKET_NUMBER); | 892 kIncludePathId, !kIncludeDiversificationNonce, |
| 893 PACKET_6BYTE_PACKET_NUMBER); |
981 ++i) { | 894 ++i) { |
982 string expected_error; | 895 string expected_error; |
983 if (i < kConnectionIdOffset) { | 896 if (i < kConnectionIdOffset) { |
984 expected_error = "Unable to read public flags."; | 897 expected_error = "Unable to read public flags."; |
985 } else if (i < kVersionOffset) { | 898 } else if (i < kVersionOffset) { |
986 expected_error = "Unable to read ConnectionId."; | 899 expected_error = "Unable to read ConnectionId."; |
987 } else if (i < | 900 } else if (i < |
988 GetPathIdOffset(PACKET_8BYTE_CONNECTION_ID, kIncludeVersion)) { | 901 GetPathIdOffset(PACKET_8BYTE_CONNECTION_ID, kIncludeVersion)) { |
989 expected_error = "Unable to read protocol version."; | 902 expected_error = "Unable to read protocol version."; |
990 } else if (i < GetPacketNumberOffset(kIncludeVersion, kIncludePathId)) { | 903 } else if (i < GetPacketNumberOffset(kIncludeVersion, kIncludePathId)) { |
991 expected_error = "Unable to read path id."; | 904 expected_error = "Unable to read path id."; |
992 } else if (i < GetPrivateFlagsOffset(kIncludeVersion, kIncludePathId)) { | 905 } else if (i < GetPrivateFlagsOffset(kIncludeVersion, kIncludePathId)) { |
993 expected_error = "Unable to read packet number."; | 906 expected_error = "Unable to read packet number."; |
994 } else { | 907 } else { |
995 expected_error = "Unable to read private flags."; | 908 expected_error = "Unable to read private flags."; |
996 } | 909 } |
997 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); | 910 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); |
998 } | 911 } |
999 } | 912 } |
1000 | 913 |
1001 TEST_P(QuicFramerTest, PacketHeaderWithPathChange) { | 914 TEST_P(QuicFramerTest, PacketHeaderWithPathChange) { |
1002 // Packet 1 from path 0x42. | 915 // Packet 1 from path 0x42. |
1003 // clang-format off | 916 // clang-format off |
1004 unsigned char packet1[] = { | 917 unsigned char packet1[] = { |
1005 // public flags (version) | 918 // public flags (version) |
1006 0x7C, | 919 0x78, |
1007 // connection_id | 920 // connection_id |
1008 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 921 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
1009 // path_id | 922 // path_id |
1010 0x42, | 923 0x42, |
1011 // packet number | 924 // packet number |
1012 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 925 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
1013 // private flags | 926 // private flags |
1014 0x00, | 927 0x00, |
1015 }; | 928 }; |
1016 // clang-format on | 929 // clang-format on |
1017 | 930 |
1018 EXPECT_EQ(0u, QuicFramerPeer::GetLastPacketNumber(&framer_)); | 931 EXPECT_EQ(0u, QuicFramerPeer::GetLastPacketNumber(&framer_)); |
1019 EXPECT_EQ(kInvalidPathId, QuicFramerPeer::GetLastPathId(&framer_)); | 932 EXPECT_EQ(kInvalidPathId, QuicFramerPeer::GetLastPathId(&framer_)); |
1020 QuicEncryptedPacket encrypted1(AsChars(packet1), arraysize(packet1), false); | 933 QuicEncryptedPacket encrypted1(AsChars(packet1), arraysize(packet1), false); |
1021 EXPECT_FALSE(framer_.ProcessPacket(encrypted1)); | 934 EXPECT_FALSE(framer_.ProcessPacket(encrypted1)); |
1022 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | 935 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
1023 ASSERT_TRUE(visitor_.header_.get()); | 936 ASSERT_TRUE(visitor_.header_.get()); |
1024 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | 937 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); |
1025 EXPECT_EQ(kPathId, visitor_.header_->path_id); | 938 EXPECT_EQ(kPathId, visitor_.header_->path_id); |
1026 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | 939 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
1027 EXPECT_EQ(kPacketNumber, QuicFramerPeer::GetLastPacketNumber(&framer_)); | 940 EXPECT_EQ(kPacketNumber, QuicFramerPeer::GetLastPacketNumber(&framer_)); |
1028 EXPECT_EQ(kPathId, QuicFramerPeer::GetLastPathId(&framer_)); | 941 EXPECT_EQ(kPathId, QuicFramerPeer::GetLastPathId(&framer_)); |
1029 | 942 |
1030 // Packet 2 from default path. | 943 // Packet 2 from default path. |
1031 // clang-format off | 944 // clang-format off |
1032 unsigned char packet2[] = { | 945 unsigned char packet2[] = { |
1033 // public flags (version) | 946 // public flags (version) |
1034 0x7C, | 947 0x78, |
1035 // connection_id | 948 // connection_id |
1036 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 949 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
1037 // path_id | 950 // path_id |
1038 0x00, | 951 0x00, |
1039 // packet number | 952 // packet number |
1040 0xCC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 953 0xCC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
1041 // private flags | 954 // private flags |
1042 0x00, | 955 0x00, |
1043 }; | 956 }; |
1044 // clang-format on | 957 // clang-format on |
1045 | 958 |
1046 QuicEncryptedPacket encrypted2(AsChars(packet2), arraysize(packet2), false); | 959 QuicEncryptedPacket encrypted2(AsChars(packet2), arraysize(packet2), false); |
1047 EXPECT_FALSE(framer_.ProcessPacket(encrypted2)); | 960 EXPECT_FALSE(framer_.ProcessPacket(encrypted2)); |
1048 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | 961 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
1049 ASSERT_TRUE(visitor_.header_.get()); | 962 ASSERT_TRUE(visitor_.header_.get()); |
1050 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | 963 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); |
1051 EXPECT_EQ(kDefaultPathId, visitor_.header_->path_id); | 964 EXPECT_EQ(kDefaultPathId, visitor_.header_->path_id); |
1052 EXPECT_EQ(kPacketNumber + 16, visitor_.header_->packet_number); | 965 EXPECT_EQ(kPacketNumber + 16, visitor_.header_->packet_number); |
1053 EXPECT_EQ(kPacketNumber + 16, QuicFramerPeer::GetLastPacketNumber(&framer_)); | 966 EXPECT_EQ(kPacketNumber + 16, QuicFramerPeer::GetLastPacketNumber(&framer_)); |
1054 EXPECT_EQ(kDefaultPathId, QuicFramerPeer::GetLastPathId(&framer_)); | 967 EXPECT_EQ(kDefaultPathId, QuicFramerPeer::GetLastPathId(&framer_)); |
1055 | 968 |
1056 // Packet 3 from path 0x42. | 969 // Packet 3 from path 0x42. |
1057 // clang-format off | 970 // clang-format off |
1058 unsigned char packet3[] = { | 971 unsigned char packet3[] = { |
1059 // public flags (version) | 972 // public flags (version) |
1060 0x7C, | 973 0x78, |
1061 // connection_id | 974 // connection_id |
1062 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 975 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
1063 // path_id | 976 // path_id |
1064 0x42, | 977 0x42, |
1065 // packet number | 978 // packet number |
1066 0xBD, 0x9A, 0x78, 0x56, 0x34, 0x12, | 979 0xBD, 0x9A, 0x78, 0x56, 0x34, 0x12, |
1067 // private flags | 980 // private flags |
1068 0x00, | 981 0x00, |
1069 }; | 982 }; |
1070 // clang-format on | 983 // clang-format on |
1071 | 984 |
1072 QuicEncryptedPacket encrypted3(AsChars(packet3), arraysize(packet3), false); | 985 QuicEncryptedPacket encrypted3(AsChars(packet3), arraysize(packet3), false); |
1073 EXPECT_FALSE(framer_.ProcessPacket(encrypted3)); | 986 EXPECT_FALSE(framer_.ProcessPacket(encrypted3)); |
1074 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | 987 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
1075 ASSERT_TRUE(visitor_.header_.get()); | 988 ASSERT_TRUE(visitor_.header_.get()); |
1076 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | 989 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); |
1077 EXPECT_EQ(kPathId, visitor_.header_->path_id); | 990 EXPECT_EQ(kPathId, visitor_.header_->path_id); |
1078 EXPECT_EQ(kPacketNumber + 1, visitor_.header_->packet_number); | 991 EXPECT_EQ(kPacketNumber + 1, visitor_.header_->packet_number); |
1079 EXPECT_EQ(kPacketNumber + 1, QuicFramerPeer::GetLastPacketNumber(&framer_)); | 992 EXPECT_EQ(kPacketNumber + 1, QuicFramerPeer::GetLastPacketNumber(&framer_)); |
1080 EXPECT_EQ(kPathId, QuicFramerPeer::GetLastPathId(&framer_)); | 993 EXPECT_EQ(kPathId, QuicFramerPeer::GetLastPathId(&framer_)); |
1081 } | 994 } |
1082 | 995 |
1083 TEST_P(QuicFramerTest, ReceivedPacketOnClosedPath) { | 996 TEST_P(QuicFramerTest, ReceivedPacketOnClosedPath) { |
1084 // Packet 1 from path 0x42. | 997 // Packet 1 from path 0x42. |
1085 // clang-format off | 998 // clang-format off |
1086 unsigned char packet[] = { | 999 unsigned char packet[] = { |
1087 // public flags (version) | 1000 // public flags (version) |
1088 0x7C, | 1001 0x78, |
1089 // connection_id | 1002 // connection_id |
1090 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 1003 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
1091 // path_id | 1004 // path_id |
1092 0x42, | 1005 0x42, |
1093 // packet number | 1006 // packet number |
1094 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 1007 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
1095 // private flags | 1008 // private flags |
1096 0x00, | 1009 0x00, |
1097 }; | 1010 }; |
1098 // clang-format on | 1011 // clang-format on |
1099 | 1012 |
1100 framer_.OnPathClosed(kPathId); | 1013 framer_.OnPathClosed(kPathId); |
1101 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1014 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
1102 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | 1015 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
1103 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1016 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
1104 EXPECT_EQ(0u, QuicFramerPeer::GetLastPacketNumber(&framer_)); | 1017 EXPECT_EQ(0u, QuicFramerPeer::GetLastPacketNumber(&framer_)); |
1105 EXPECT_EQ(kInvalidPathId, QuicFramerPeer::GetLastPathId(&framer_)); | 1018 EXPECT_EQ(kInvalidPathId, QuicFramerPeer::GetLastPathId(&framer_)); |
1106 } | 1019 } |
1107 | 1020 |
1108 TEST_P(QuicFramerTest, PacketHeaderWith4BytePacketNumber) { | 1021 TEST_P(QuicFramerTest, PacketHeaderWith4BytePacketNumber) { |
1109 QuicFramerPeer::SetLastPacketNumber(&framer_, kPacketNumber - 2); | 1022 QuicFramerPeer::SetLastPacketNumber(&framer_, kPacketNumber - 2); |
1110 | 1023 |
1111 // clang-format off | 1024 // clang-format off |
1112 unsigned char packet[] = { | 1025 unsigned char packet[] = { |
1113 // public flags (8 byte connection_id and 4 byte packet number) | 1026 // public flags (8 byte connection_id and 4 byte packet number) |
1114 0x2C, | 1027 0x28, |
1115 // connection_id | 1028 // connection_id |
1116 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 1029 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
1117 // packet number | 1030 // packet number |
1118 0xBC, 0x9A, 0x78, 0x56, | 1031 0xBC, 0x9A, 0x78, 0x56, |
1119 // private flags | 1032 // private flags |
1120 0x00, | 1033 0x00, |
1121 }; | 1034 }; |
1122 // clang-format on | 1035 // clang-format on |
1123 | 1036 |
1124 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1037 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
1125 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | 1038 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
1126 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | 1039 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
1127 ASSERT_TRUE(visitor_.header_.get()); | 1040 ASSERT_TRUE(visitor_.header_.get()); |
1128 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | 1041 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); |
1129 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); | 1042 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); |
1130 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); | 1043 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); |
1131 EXPECT_FALSE(visitor_.header_->public_header.version_flag); | 1044 EXPECT_FALSE(visitor_.header_->public_header.version_flag); |
1132 EXPECT_FALSE(visitor_.header_->fec_flag); | 1045 EXPECT_FALSE(visitor_.header_->fec_flag); |
1133 EXPECT_FALSE(visitor_.header_->entropy_flag); | 1046 EXPECT_FALSE(visitor_.header_->entropy_flag); |
1134 EXPECT_EQ(0, visitor_.header_->entropy_hash); | 1047 EXPECT_EQ(0, visitor_.header_->entropy_hash); |
1135 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | 1048 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
1136 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); | 1049 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); |
1137 EXPECT_EQ(0u, visitor_.header_->fec_group); | 1050 EXPECT_EQ(0u, visitor_.header_->fec_group); |
1138 | 1051 |
1139 // Now test framing boundaries. | 1052 // Now test framing boundaries. |
1140 for (size_t i = 0; | 1053 for (size_t i = 0; |
1141 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 1054 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
1142 !kIncludePathId, PACKET_4BYTE_PACKET_NUMBER); | 1055 !kIncludePathId, !kIncludeDiversificationNonce, |
| 1056 PACKET_4BYTE_PACKET_NUMBER); |
1143 ++i) { | 1057 ++i) { |
1144 string expected_error; | 1058 string expected_error; |
1145 if (i < kConnectionIdOffset) { | 1059 if (i < kConnectionIdOffset) { |
1146 expected_error = "Unable to read public flags."; | 1060 expected_error = "Unable to read public flags."; |
1147 } else if (i < GetPacketNumberOffset(!kIncludeVersion, !kIncludePathId)) { | 1061 } else if (i < GetPacketNumberOffset(!kIncludeVersion, !kIncludePathId)) { |
1148 expected_error = "Unable to read ConnectionId."; | 1062 expected_error = "Unable to read ConnectionId."; |
1149 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion, !kIncludePathId, | 1063 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion, !kIncludePathId, |
1150 PACKET_4BYTE_PACKET_NUMBER)) { | 1064 PACKET_4BYTE_PACKET_NUMBER)) { |
1151 expected_error = "Unable to read packet number."; | 1065 expected_error = "Unable to read packet number."; |
1152 } else { | 1066 } else { |
1153 expected_error = "Unable to read private flags."; | 1067 expected_error = "Unable to read private flags."; |
1154 } | 1068 } |
1155 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); | 1069 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); |
1156 } | 1070 } |
1157 } | 1071 } |
1158 | 1072 |
1159 TEST_P(QuicFramerTest, PacketHeaderWith2BytePacketNumber) { | 1073 TEST_P(QuicFramerTest, PacketHeaderWith2BytePacketNumber) { |
1160 QuicFramerPeer::SetLastPacketNumber(&framer_, kPacketNumber - 2); | 1074 QuicFramerPeer::SetLastPacketNumber(&framer_, kPacketNumber - 2); |
1161 | 1075 |
1162 // clang-format off | 1076 // clang-format off |
1163 unsigned char packet[] = { | 1077 unsigned char packet[] = { |
1164 // public flags (8 byte connection_id and 2 byte packet number) | 1078 // public flags (8 byte connection_id and 2 byte packet number) |
1165 0x1C, | 1079 0x18, |
1166 // connection_id | 1080 // connection_id |
1167 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 1081 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
1168 // packet number | 1082 // packet number |
1169 0xBC, 0x9A, | 1083 0xBC, 0x9A, |
1170 // private flags | 1084 // private flags |
1171 0x00, | 1085 0x00, |
1172 }; | 1086 }; |
1173 // clang-format on | 1087 // clang-format on |
1174 | 1088 |
1175 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1089 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
1176 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | 1090 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
1177 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | 1091 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
1178 ASSERT_TRUE(visitor_.header_.get()); | 1092 ASSERT_TRUE(visitor_.header_.get()); |
1179 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | 1093 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); |
1180 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); | 1094 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); |
1181 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); | 1095 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); |
1182 EXPECT_FALSE(visitor_.header_->public_header.version_flag); | 1096 EXPECT_FALSE(visitor_.header_->public_header.version_flag); |
1183 EXPECT_FALSE(visitor_.header_->fec_flag); | 1097 EXPECT_FALSE(visitor_.header_->fec_flag); |
1184 EXPECT_FALSE(visitor_.header_->entropy_flag); | 1098 EXPECT_FALSE(visitor_.header_->entropy_flag); |
1185 EXPECT_EQ(0, visitor_.header_->entropy_hash); | 1099 EXPECT_EQ(0, visitor_.header_->entropy_hash); |
1186 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | 1100 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
1187 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); | 1101 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); |
1188 EXPECT_EQ(0u, visitor_.header_->fec_group); | 1102 EXPECT_EQ(0u, visitor_.header_->fec_group); |
1189 | 1103 |
1190 // Now test framing boundaries. | 1104 // Now test framing boundaries. |
1191 for (size_t i = 0; | 1105 for (size_t i = 0; |
1192 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 1106 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
1193 !kIncludePathId, PACKET_2BYTE_PACKET_NUMBER); | 1107 !kIncludePathId, !kIncludeDiversificationNonce, |
| 1108 PACKET_2BYTE_PACKET_NUMBER); |
1194 ++i) { | 1109 ++i) { |
1195 string expected_error; | 1110 string expected_error; |
1196 if (i < kConnectionIdOffset) { | 1111 if (i < kConnectionIdOffset) { |
1197 expected_error = "Unable to read public flags."; | 1112 expected_error = "Unable to read public flags."; |
1198 } else if (i < GetPacketNumberOffset(!kIncludeVersion, !kIncludePathId)) { | 1113 } else if (i < GetPacketNumberOffset(!kIncludeVersion, !kIncludePathId)) { |
1199 expected_error = "Unable to read ConnectionId."; | 1114 expected_error = "Unable to read ConnectionId."; |
1200 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion, !kIncludePathId, | 1115 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion, !kIncludePathId, |
1201 PACKET_2BYTE_PACKET_NUMBER)) { | 1116 PACKET_2BYTE_PACKET_NUMBER)) { |
1202 expected_error = "Unable to read packet number."; | 1117 expected_error = "Unable to read packet number."; |
1203 } else { | 1118 } else { |
1204 expected_error = "Unable to read private flags."; | 1119 expected_error = "Unable to read private flags."; |
1205 } | 1120 } |
1206 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); | 1121 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); |
1207 } | 1122 } |
1208 } | 1123 } |
1209 | 1124 |
1210 TEST_P(QuicFramerTest, PacketHeaderWith1BytePacketNumber) { | 1125 TEST_P(QuicFramerTest, PacketHeaderWith1BytePacketNumber) { |
1211 QuicFramerPeer::SetLastPacketNumber(&framer_, kPacketNumber - 2); | 1126 QuicFramerPeer::SetLastPacketNumber(&framer_, kPacketNumber - 2); |
1212 | 1127 |
1213 // clang-format off | 1128 // clang-format off |
1214 unsigned char packet[] = { | 1129 unsigned char packet[] = { |
1215 // public flags (8 byte connection_id and 1 byte packet number) | 1130 // public flags (8 byte connection_id and 1 byte packet number) |
1216 0x0C, | 1131 0x08, |
1217 // connection_id | 1132 // connection_id |
1218 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 1133 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
1219 // packet number | 1134 // packet number |
1220 0xBC, | 1135 0xBC, |
1221 // private flags | 1136 // private flags |
1222 0x00, | 1137 0x00, |
1223 }; | 1138 }; |
1224 // clang-format on | 1139 // clang-format on |
1225 | 1140 |
1226 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1141 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
1227 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); | 1142 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
1228 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); | 1143 EXPECT_EQ(QUIC_MISSING_PAYLOAD, framer_.error()); |
1229 ASSERT_TRUE(visitor_.header_.get()); | 1144 ASSERT_TRUE(visitor_.header_.get()); |
1230 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); | 1145 EXPECT_EQ(kConnectionId, visitor_.header_->public_header.connection_id); |
1231 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); | 1146 EXPECT_FALSE(visitor_.header_->public_header.multipath_flag); |
1232 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); | 1147 EXPECT_FALSE(visitor_.header_->public_header.reset_flag); |
1233 EXPECT_FALSE(visitor_.header_->public_header.version_flag); | 1148 EXPECT_FALSE(visitor_.header_->public_header.version_flag); |
1234 EXPECT_FALSE(visitor_.header_->fec_flag); | 1149 EXPECT_FALSE(visitor_.header_->fec_flag); |
1235 EXPECT_FALSE(visitor_.header_->entropy_flag); | 1150 EXPECT_FALSE(visitor_.header_->entropy_flag); |
1236 EXPECT_EQ(0, visitor_.header_->entropy_hash); | 1151 EXPECT_EQ(0, visitor_.header_->entropy_hash); |
1237 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); | 1152 EXPECT_EQ(kPacketNumber, visitor_.header_->packet_number); |
1238 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); | 1153 EXPECT_EQ(NOT_IN_FEC_GROUP, visitor_.header_->is_in_fec_group); |
1239 EXPECT_EQ(0u, visitor_.header_->fec_group); | 1154 EXPECT_EQ(0u, visitor_.header_->fec_group); |
1240 | 1155 |
1241 // Now test framing boundaries. | 1156 // Now test framing boundaries. |
1242 for (size_t i = 0; | 1157 for (size_t i = 0; |
1243 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 1158 i < GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
1244 !kIncludePathId, PACKET_1BYTE_PACKET_NUMBER); | 1159 !kIncludePathId, !kIncludeDiversificationNonce, |
| 1160 PACKET_1BYTE_PACKET_NUMBER); |
1245 ++i) { | 1161 ++i) { |
1246 string expected_error; | 1162 string expected_error; |
1247 if (i < kConnectionIdOffset) { | 1163 if (i < kConnectionIdOffset) { |
1248 expected_error = "Unable to read public flags."; | 1164 expected_error = "Unable to read public flags."; |
1249 } else if (i < GetPacketNumberOffset(!kIncludeVersion, !kIncludePathId)) { | 1165 } else if (i < GetPacketNumberOffset(!kIncludeVersion, !kIncludePathId)) { |
1250 expected_error = "Unable to read ConnectionId."; | 1166 expected_error = "Unable to read ConnectionId."; |
1251 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion, !kIncludePathId, | 1167 } else if (i < GetPrivateFlagsOffset(!kIncludeVersion, !kIncludePathId, |
1252 PACKET_1BYTE_PACKET_NUMBER)) { | 1168 PACKET_1BYTE_PACKET_NUMBER)) { |
1253 expected_error = "Unable to read packet number."; | 1169 expected_error = "Unable to read packet number."; |
1254 } else { | 1170 } else { |
1255 expected_error = "Unable to read private flags."; | 1171 expected_error = "Unable to read private flags."; |
1256 } | 1172 } |
1257 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); | 1173 CheckProcessingFails(packet, i, expected_error, QUIC_INVALID_PACKET_HEADER); |
1258 } | 1174 } |
1259 } | 1175 } |
1260 | 1176 |
1261 TEST_P(QuicFramerTest, InvalidPublicFlag) { | 1177 TEST_P(QuicFramerTest, InvalidPublicFlag) { |
1262 // clang-format off | 1178 // clang-format off |
1263 unsigned char packet[] = { | 1179 unsigned char packet[] = { |
1264 // public flags: all flags set but the public reset flag and version flag. | 1180 // public flags: all flags set but the public reset flag and version flag. |
1265 0xFC, | 1181 0xF8, |
1266 // connection_id | 1182 // connection_id |
1267 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 1183 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
1268 // packet number | 1184 // packet number |
1269 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 1185 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
1270 // private flags | 1186 // private flags |
1271 0x00, | 1187 0x00, |
1272 | 1188 |
1273 // frame type (padding) | 1189 // frame type (padding) |
1274 0x00, | 1190 0x00, |
1275 0x00, 0x00, 0x00, 0x00 | 1191 0x00, 0x00, 0x00, 0x00 |
1276 }; | 1192 }; |
1277 // clang-format on | 1193 // clang-format on |
1278 | 1194 |
1279 CheckProcessingFails(packet, arraysize(packet), "Illegal public flags value.", | 1195 CheckProcessingFails(packet, arraysize(packet), "Illegal public flags value.", |
1280 QUIC_INVALID_PACKET_HEADER); | 1196 QUIC_INVALID_PACKET_HEADER); |
1281 | 1197 |
1282 // Now turn off validation. | 1198 // Now turn off validation. |
1283 framer_.set_validate_flags(false); | 1199 framer_.set_validate_flags(false); |
1284 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1200 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
1285 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1201 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
1286 }; | 1202 }; |
1287 | 1203 |
| 1204 TEST_P(QuicFramerTest, PacketWithDiversificationNonce) { |
| 1205 // clang-format off |
| 1206 unsigned char packet[] = { |
| 1207 // public flags: includes nonce flag |
| 1208 0x7C, |
| 1209 // connection_id |
| 1210 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
| 1211 // nonce |
| 1212 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, |
| 1213 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, |
| 1214 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, |
| 1215 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, |
| 1216 // packet number |
| 1217 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
| 1218 // private flags |
| 1219 0x00, |
| 1220 |
| 1221 // frame type (padding) |
| 1222 0x00, |
| 1223 0x00, 0x00, 0x00, 0x00 |
| 1224 }; |
| 1225 // clang-format on |
| 1226 |
| 1227 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
| 1228 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
| 1229 if (framer_.version() > QUIC_VERSION_32) { |
| 1230 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1231 ASSERT_TRUE(visitor_.public_header_->nonce != nullptr); |
| 1232 for (char i = 0; i < 32; ++i) { |
| 1233 EXPECT_EQ(i, (*visitor_.public_header_->nonce)[static_cast<int>(i)]); |
| 1234 } |
| 1235 } else if (framer_.version() < QUIC_VERSION_32) { |
| 1236 // Packet is successfully parsed by accident. |
| 1237 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
| 1238 ASSERT_TRUE(visitor_.public_header_ != nullptr); |
| 1239 } else { |
| 1240 EXPECT_FALSE(framer_.ProcessPacket(encrypted)); |
| 1241 EXPECT_EQ(QUIC_INVALID_PACKET_HEADER, framer_.error()); |
| 1242 EXPECT_EQ("Illegal private flags value.", framer_.detailed_error()); |
| 1243 } |
| 1244 }; |
| 1245 |
1288 TEST_P(QuicFramerTest, InvalidPublicFlagWithMatchingVersions) { | 1246 TEST_P(QuicFramerTest, InvalidPublicFlagWithMatchingVersions) { |
1289 // clang-format off | 1247 // clang-format off |
1290 unsigned char packet[] = { | 1248 unsigned char packet[] = { |
1291 // public flags (8 byte connection_id and version flag and an unknown flag) | 1249 // public flags (8 byte connection_id and version flag and an unknown flag) |
1292 0x8D, | 1250 0x8D, |
1293 // connection_id | 1251 // connection_id |
1294 0x10, 0x32, 0x54, 0x76, | 1252 0x10, 0x32, 0x54, 0x76, |
1295 0x98, 0xBA, 0xDC, 0xFE, | 1253 0x98, 0xBA, 0xDC, 0xFE, |
1296 // version tag | 1254 // version tag |
1297 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | 1255 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), |
1298 // packet number | 1256 // packet number |
1299 0xBC, 0x9A, 0x78, 0x56, | 1257 0xBC, 0x9A, 0x78, 0x56, |
1300 0x34, 0x12, | 1258 0x34, 0x12, |
1301 // private flags | 1259 // private flags |
1302 0x00, | 1260 0x00, |
1303 | 1261 |
1304 // frame type (padding) | 1262 // frame type (padding) |
1305 0x00, | 1263 0x00, |
1306 0x00, 0x00, 0x00, 0x00 | 1264 0x00, 0x00, 0x00, 0x00 |
1307 }; | 1265 }; |
1308 // clang-format on | 1266 // clang-format on |
1309 CheckProcessingFails(packet, arraysize(packet), "Illegal public flags value.", | 1267 CheckProcessingFails(packet, arraysize(packet), "Illegal public flags value.", |
1310 QUIC_INVALID_PACKET_HEADER); | 1268 QUIC_INVALID_PACKET_HEADER); |
1311 }; | 1269 }; |
1312 | 1270 |
1313 TEST_P(QuicFramerTest, LargePublicFlagWithMismatchedVersions) { | 1271 TEST_P(QuicFramerTest, LargePublicFlagWithMismatchedVersions) { |
1314 // clang-format off | 1272 // clang-format off |
1315 unsigned char packet[] = { | 1273 unsigned char packet[] = { |
1316 // public flags (8 byte connection_id, version flag and an unknown flag) | 1274 // public flags (8 byte connection_id, version flag and an unknown flag) |
1317 0x7D, | 1275 0x79, |
1318 // connection_id | 1276 // connection_id |
1319 0x10, 0x32, 0x54, 0x76, | 1277 0x10, 0x32, 0x54, 0x76, |
1320 0x98, 0xBA, 0xDC, 0xFE, | 1278 0x98, 0xBA, 0xDC, 0xFE, |
1321 // version tag | 1279 // version tag |
1322 'Q', '0', '0', '0', | 1280 'Q', '0', '0', '0', |
1323 // packet number | 1281 // packet number |
1324 0xBC, 0x9A, 0x78, 0x56, | 1282 0xBC, 0x9A, 0x78, 0x56, |
1325 0x34, 0x12, | 1283 0x34, 0x12, |
1326 // private flags | 1284 // private flags |
1327 0x00, | 1285 0x00, |
1328 | 1286 |
1329 // frame type (padding frame) | 1287 // frame type (padding frame) |
1330 0x00, | 1288 0x00, |
1331 0x00, 0x00, 0x00, 0x00 | 1289 0x00, 0x00, 0x00, 0x00 |
1332 }; | 1290 }; |
1333 // clang-format on | 1291 // clang-format on |
1334 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1292 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
1335 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1293 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
1336 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1294 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
1337 ASSERT_TRUE(visitor_.header_.get()); | 1295 ASSERT_TRUE(visitor_.header_.get()); |
1338 EXPECT_EQ(0, visitor_.frame_count_); | 1296 EXPECT_EQ(0, visitor_.frame_count_); |
1339 EXPECT_EQ(1, visitor_.version_mismatch_); | 1297 EXPECT_EQ(1, visitor_.version_mismatch_); |
1340 }; | 1298 }; |
1341 | 1299 |
1342 TEST_P(QuicFramerTest, InvalidPrivateFlag) { | 1300 TEST_P(QuicFramerTest, InvalidPrivateFlag) { |
1343 // clang-format off | 1301 // clang-format off |
1344 unsigned char packet[] = { | 1302 unsigned char packet[] = { |
1345 // public flags (8 byte connection_id) | 1303 // public flags (8 byte connection_id) |
1346 0x3C, | 1304 0x38, |
1347 // connection_id | 1305 // connection_id |
1348 0x10, 0x32, 0x54, 0x76, | 1306 0x10, 0x32, 0x54, 0x76, |
1349 0x98, 0xBA, 0xDC, 0xFE, | 1307 0x98, 0xBA, 0xDC, 0xFE, |
1350 // packet number | 1308 // packet number |
1351 0xBC, 0x9A, 0x78, 0x56, | 1309 0xBC, 0x9A, 0x78, 0x56, |
1352 0x34, 0x12, | 1310 0x34, 0x12, |
1353 // private flags | 1311 // private flags |
1354 0x10, | 1312 0x10, |
1355 | 1313 |
1356 // frame type (padding) | 1314 // frame type (padding) |
1357 0x00, | 1315 0x00, |
1358 0x00, 0x00, 0x00, 0x00 | 1316 0x00, 0x00, 0x00, 0x00 |
1359 }; | 1317 }; |
1360 // clang-format on | 1318 // clang-format on |
1361 CheckProcessingFails(packet, arraysize(packet), | 1319 CheckProcessingFails(packet, arraysize(packet), |
1362 "Illegal private flags value.", | 1320 "Illegal private flags value.", |
1363 QUIC_INVALID_PACKET_HEADER); | 1321 QUIC_INVALID_PACKET_HEADER); |
1364 }; | 1322 }; |
1365 | 1323 |
1366 TEST_P(QuicFramerTest, InvalidFECGroupOffset) { | 1324 TEST_P(QuicFramerTest, InvalidFECGroupOffset) { |
1367 // clang-format off | 1325 // clang-format off |
1368 unsigned char packet[] = { | 1326 unsigned char packet[] = { |
1369 // public flags (8 byte connection_id) | 1327 // public flags (8 byte connection_id) |
1370 0x3C, | 1328 0x38, |
1371 // connection_id | 1329 // connection_id |
1372 0x10, 0x32, 0x54, 0x76, | 1330 0x10, 0x32, 0x54, 0x76, |
1373 0x98, 0xBA, 0xDC, 0xFE, | 1331 0x98, 0xBA, 0xDC, 0xFE, |
1374 // packet number | 1332 // packet number |
1375 0x01, 0x00, 0x00, 0x00, | 1333 0x01, 0x00, 0x00, 0x00, |
1376 0x00, 0x00, | 1334 0x00, 0x00, |
1377 // private flags (fec group) | 1335 // private flags (fec group) |
1378 0x02, | 1336 0x02, |
1379 // first fec protected packet offset | 1337 // first fec protected packet offset |
1380 0x10 | 1338 0x10 |
1381 }; | 1339 }; |
1382 // clang-format on | 1340 // clang-format on |
1383 if (framer_.version() > QUIC_VERSION_31) { | 1341 if (framer_.version() > QUIC_VERSION_31) { |
1384 CheckProcessingFails(packet, arraysize(packet), | 1342 CheckProcessingFails(packet, arraysize(packet), |
1385 "Illegal private flags value.", | 1343 "Illegal private flags value.", |
1386 QUIC_INVALID_PACKET_HEADER); | 1344 QUIC_INVALID_PACKET_HEADER); |
1387 } else { | 1345 } else { |
1388 CheckProcessingFails(packet, arraysize(packet), | 1346 CheckProcessingFails(packet, arraysize(packet), |
1389 "First fec protected packet offset must be less " | 1347 "First fec protected packet offset must be less " |
1390 "than the packet number.", | 1348 "than the packet number.", |
1391 QUIC_INVALID_PACKET_HEADER); | 1349 QUIC_INVALID_PACKET_HEADER); |
1392 } | 1350 } |
1393 }; | 1351 }; |
1394 | 1352 |
1395 TEST_P(QuicFramerTest, PaddingFrame) { | 1353 TEST_P(QuicFramerTest, PaddingFrame) { |
1396 // clang-format off | 1354 // clang-format off |
1397 unsigned char packet[] = { | 1355 unsigned char packet[] = { |
1398 // public flags (8 byte connection_id) | 1356 // public flags (8 byte connection_id) |
1399 0x3C, | 1357 0x38, |
1400 // connection_id | 1358 // connection_id |
1401 0x10, 0x32, 0x54, 0x76, | 1359 0x10, 0x32, 0x54, 0x76, |
1402 0x98, 0xBA, 0xDC, 0xFE, | 1360 0x98, 0xBA, 0xDC, 0xFE, |
1403 // packet number | 1361 // packet number |
1404 0xBC, 0x9A, 0x78, 0x56, | 1362 0xBC, 0x9A, 0x78, 0x56, |
1405 0x34, 0x12, | 1363 0x34, 0x12, |
1406 // private flags | 1364 // private flags |
1407 0x00, | 1365 0x00, |
1408 | 1366 |
1409 // frame type (padding frame) | 1367 // frame type (padding frame) |
(...skipping 12 matching lines...) Expand all Loading... |
1422 'h', 'e', 'l', 'l', | 1380 'h', 'e', 'l', 'l', |
1423 'o', ' ', 'w', 'o', | 1381 'o', ' ', 'w', 'o', |
1424 'r', 'l', 'd', '!', | 1382 'r', 'l', 'd', '!', |
1425 }; | 1383 }; |
1426 // clang-format on | 1384 // clang-format on |
1427 | 1385 |
1428 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1386 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
1429 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1387 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
1430 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1388 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
1431 ASSERT_TRUE(visitor_.header_.get()); | 1389 ASSERT_TRUE(visitor_.header_.get()); |
1432 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 1390 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 1391 !kIncludeDiversificationNonce)); |
1433 | 1392 |
1434 ASSERT_EQ(0u, visitor_.stream_frames_.size()); | 1393 ASSERT_EQ(0u, visitor_.stream_frames_.size()); |
1435 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 1394 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
1436 // A packet with no frames is not acceptable. | 1395 // A packet with no frames is not acceptable. |
1437 CheckProcessingFails( | 1396 CheckProcessingFails( |
1438 packet, GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 1397 packet, GetPacketHeaderSize( |
1439 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER), | 1398 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, !kIncludePathId, |
| 1399 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER), |
1440 "Packet has no frames.", QUIC_MISSING_PAYLOAD); | 1400 "Packet has no frames.", QUIC_MISSING_PAYLOAD); |
1441 } | 1401 } |
1442 | 1402 |
1443 TEST_P(QuicFramerTest, StreamFrame) { | 1403 TEST_P(QuicFramerTest, StreamFrame) { |
1444 // clang-format off | 1404 // clang-format off |
1445 unsigned char packet[] = { | 1405 unsigned char packet[] = { |
1446 // public flags (8 byte connection_id) | 1406 // public flags (8 byte connection_id) |
1447 0x3C, | 1407 0x38, |
1448 // connection_id | 1408 // connection_id |
1449 0x10, 0x32, 0x54, 0x76, | 1409 0x10, 0x32, 0x54, 0x76, |
1450 0x98, 0xBA, 0xDC, 0xFE, | 1410 0x98, 0xBA, 0xDC, 0xFE, |
1451 // packet number | 1411 // packet number |
1452 0xBC, 0x9A, 0x78, 0x56, | 1412 0xBC, 0x9A, 0x78, 0x56, |
1453 0x34, 0x12, | 1413 0x34, 0x12, |
1454 // private flags | 1414 // private flags |
1455 0x00, | 1415 0x00, |
1456 | 1416 |
1457 // frame type (stream frame with fin) | 1417 // frame type (stream frame with fin) |
(...skipping 10 matching lines...) Expand all Loading... |
1468 'o', ' ', 'w', 'o', | 1428 'o', ' ', 'w', 'o', |
1469 'r', 'l', 'd', '!', | 1429 'r', 'l', 'd', '!', |
1470 }; | 1430 }; |
1471 // clang-format on | 1431 // clang-format on |
1472 | 1432 |
1473 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1433 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
1474 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1434 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
1475 | 1435 |
1476 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1436 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
1477 ASSERT_TRUE(visitor_.header_.get()); | 1437 ASSERT_TRUE(visitor_.header_.get()); |
1478 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 1438 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 1439 !kIncludeDiversificationNonce)); |
1479 | 1440 |
1480 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | 1441 ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
1481 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 1442 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
1482 EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); | 1443 EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
1483 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); | 1444 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
1484 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); | 1445 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
1485 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); | 1446 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); |
1486 | 1447 |
1487 // Now test framing boundaries. | 1448 // Now test framing boundaries. |
1488 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, !kIncludeVersion); | 1449 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, !kIncludeVersion); |
1489 } | 1450 } |
1490 | 1451 |
1491 TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) { | 1452 TEST_P(QuicFramerTest, StreamFrame3ByteStreamId) { |
1492 // clang-format off | 1453 // clang-format off |
1493 unsigned char packet[] = { | 1454 unsigned char packet[] = { |
1494 // public flags (8 byte connection_id) | 1455 // public flags (8 byte connection_id) |
1495 0x3C, | 1456 0x38, |
1496 // connection_id | 1457 // connection_id |
1497 0x10, 0x32, 0x54, 0x76, | 1458 0x10, 0x32, 0x54, 0x76, |
1498 0x98, 0xBA, 0xDC, 0xFE, | 1459 0x98, 0xBA, 0xDC, 0xFE, |
1499 // packet number | 1460 // packet number |
1500 0xBC, 0x9A, 0x78, 0x56, | 1461 0xBC, 0x9A, 0x78, 0x56, |
1501 0x34, 0x12, | 1462 0x34, 0x12, |
1502 // private flags | 1463 // private flags |
1503 0x00, | 1464 0x00, |
1504 | 1465 |
1505 // frame type (stream frame with fin) | 1466 // frame type (stream frame with fin) |
(...skipping 10 matching lines...) Expand all Loading... |
1516 'o', ' ', 'w', 'o', | 1477 'o', ' ', 'w', 'o', |
1517 'r', 'l', 'd', '!', | 1478 'r', 'l', 'd', '!', |
1518 }; | 1479 }; |
1519 // clang-format on | 1480 // clang-format on |
1520 | 1481 |
1521 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1482 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
1522 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1483 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
1523 | 1484 |
1524 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1485 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
1525 ASSERT_TRUE(visitor_.header_.get()); | 1486 ASSERT_TRUE(visitor_.header_.get()); |
1526 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 1487 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 1488 !kIncludeDiversificationNonce)); |
1527 | 1489 |
1528 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | 1490 ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
1529 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 1491 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
1530 // Stream ID should be the last 3 bytes of kStreamId. | 1492 // Stream ID should be the last 3 bytes of kStreamId. |
1531 EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); | 1493 EXPECT_EQ(0x00FFFFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
1532 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); | 1494 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
1533 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); | 1495 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
1534 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); | 1496 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); |
1535 | 1497 |
1536 // Now test framing boundaries. | 1498 // Now test framing boundaries. |
1537 const size_t stream_id_size = 3; | 1499 const size_t stream_id_size = 3; |
1538 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); | 1500 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); |
1539 } | 1501 } |
1540 | 1502 |
1541 TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) { | 1503 TEST_P(QuicFramerTest, StreamFrame2ByteStreamId) { |
1542 // clang-format off | 1504 // clang-format off |
1543 unsigned char packet[] = { | 1505 unsigned char packet[] = { |
1544 // public flags (8 byte connection_id) | 1506 // public flags (8 byte connection_id) |
1545 0x3C, | 1507 0x38, |
1546 // connection_id | 1508 // connection_id |
1547 0x10, 0x32, 0x54, 0x76, | 1509 0x10, 0x32, 0x54, 0x76, |
1548 0x98, 0xBA, 0xDC, 0xFE, | 1510 0x98, 0xBA, 0xDC, 0xFE, |
1549 // packet number | 1511 // packet number |
1550 0xBC, 0x9A, 0x78, 0x56, | 1512 0xBC, 0x9A, 0x78, 0x56, |
1551 0x34, 0x12, | 1513 0x34, 0x12, |
1552 // private flags | 1514 // private flags |
1553 0x00, | 1515 0x00, |
1554 | 1516 |
1555 // frame type (stream frame with fin) | 1517 // frame type (stream frame with fin) |
(...skipping 10 matching lines...) Expand all Loading... |
1566 'o', ' ', 'w', 'o', | 1528 'o', ' ', 'w', 'o', |
1567 'r', 'l', 'd', '!', | 1529 'r', 'l', 'd', '!', |
1568 }; | 1530 }; |
1569 // clang-format on | 1531 // clang-format on |
1570 | 1532 |
1571 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1533 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
1572 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1534 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
1573 | 1535 |
1574 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1536 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
1575 ASSERT_TRUE(visitor_.header_.get()); | 1537 ASSERT_TRUE(visitor_.header_.get()); |
1576 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 1538 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 1539 !kIncludeDiversificationNonce)); |
1577 | 1540 |
1578 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | 1541 ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
1579 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 1542 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
1580 // Stream ID should be the last 2 bytes of kStreamId. | 1543 // Stream ID should be the last 2 bytes of kStreamId. |
1581 EXPECT_EQ(0x0000FFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); | 1544 EXPECT_EQ(0x0000FFFF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
1582 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); | 1545 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
1583 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); | 1546 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
1584 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); | 1547 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); |
1585 | 1548 |
1586 // Now test framing boundaries. | 1549 // Now test framing boundaries. |
1587 const size_t stream_id_size = 2; | 1550 const size_t stream_id_size = 2; |
1588 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); | 1551 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); |
1589 } | 1552 } |
1590 | 1553 |
1591 TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) { | 1554 TEST_P(QuicFramerTest, StreamFrame1ByteStreamId) { |
1592 // clang-format off | 1555 // clang-format off |
1593 unsigned char packet[] = { | 1556 unsigned char packet[] = { |
1594 // public flags (8 byte connection_id) | 1557 // public flags (8 byte connection_id) |
1595 0x3C, | 1558 0x38, |
1596 // connection_id | 1559 // connection_id |
1597 0x10, 0x32, 0x54, 0x76, | 1560 0x10, 0x32, 0x54, 0x76, |
1598 0x98, 0xBA, 0xDC, 0xFE, | 1561 0x98, 0xBA, 0xDC, 0xFE, |
1599 // packet number | 1562 // packet number |
1600 0xBC, 0x9A, 0x78, 0x56, | 1563 0xBC, 0x9A, 0x78, 0x56, |
1601 0x34, 0x12, | 1564 0x34, 0x12, |
1602 // private flags | 1565 // private flags |
1603 0x00, | 1566 0x00, |
1604 | 1567 |
1605 // frame type (stream frame with fin) | 1568 // frame type (stream frame with fin) |
(...skipping 10 matching lines...) Expand all Loading... |
1616 'o', ' ', 'w', 'o', | 1579 'o', ' ', 'w', 'o', |
1617 'r', 'l', 'd', '!', | 1580 'r', 'l', 'd', '!', |
1618 }; | 1581 }; |
1619 // clang-format on | 1582 // clang-format on |
1620 | 1583 |
1621 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1584 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
1622 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1585 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
1623 | 1586 |
1624 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1587 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
1625 ASSERT_TRUE(visitor_.header_.get()); | 1588 ASSERT_TRUE(visitor_.header_.get()); |
1626 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 1589 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 1590 !kIncludeDiversificationNonce)); |
1627 | 1591 |
1628 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | 1592 ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
1629 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 1593 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
1630 // Stream ID should be the last byte of kStreamId. | 1594 // Stream ID should be the last byte of kStreamId. |
1631 EXPECT_EQ(0x000000FF & kStreamId, visitor_.stream_frames_[0]->stream_id); | 1595 EXPECT_EQ(0x000000FF & kStreamId, visitor_.stream_frames_[0]->stream_id); |
1632 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); | 1596 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
1633 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); | 1597 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
1634 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); | 1598 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); |
1635 | 1599 |
1636 // Now test framing boundaries. | 1600 // Now test framing boundaries. |
1637 const size_t stream_id_size = 1; | 1601 const size_t stream_id_size = 1; |
1638 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); | 1602 CheckStreamFrameBoundaries(packet, stream_id_size, !kIncludeVersion); |
1639 } | 1603 } |
1640 | 1604 |
1641 TEST_P(QuicFramerTest, StreamFrameWithVersion) { | 1605 TEST_P(QuicFramerTest, StreamFrameWithVersion) { |
1642 // clang-format off | 1606 // clang-format off |
1643 unsigned char packet[] = { | 1607 unsigned char packet[] = { |
1644 // public flags (version, 8 byte connection_id) | 1608 // public flags (version, 8 byte connection_id) |
1645 0x3D, | 1609 0x39, |
1646 // connection_id | 1610 // connection_id |
1647 0x10, 0x32, 0x54, 0x76, | 1611 0x10, 0x32, 0x54, 0x76, |
1648 0x98, 0xBA, 0xDC, 0xFE, | 1612 0x98, 0xBA, 0xDC, 0xFE, |
1649 // version tag | 1613 // version tag |
1650 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | 1614 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), |
1651 // packet number | 1615 // packet number |
1652 0xBC, 0x9A, 0x78, 0x56, | 1616 0xBC, 0x9A, 0x78, 0x56, |
1653 0x34, 0x12, | 1617 0x34, 0x12, |
1654 // private flags | 1618 // private flags |
1655 0x00, | 1619 0x00, |
(...skipping 14 matching lines...) Expand all Loading... |
1670 }; | 1634 }; |
1671 // clang-format on | 1635 // clang-format on |
1672 | 1636 |
1673 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1637 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
1674 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1638 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
1675 | 1639 |
1676 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1640 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
1677 ASSERT_TRUE(visitor_.header_.get()); | 1641 ASSERT_TRUE(visitor_.header_.get()); |
1678 EXPECT_TRUE(visitor_.header_->public_header.version_flag); | 1642 EXPECT_TRUE(visitor_.header_->public_header.version_flag); |
1679 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]); | 1643 EXPECT_EQ(GetParam(), visitor_.header_->public_header.versions[0]); |
1680 EXPECT_TRUE(CheckDecryption(encrypted, kIncludeVersion, !kIncludePathId)); | 1644 EXPECT_TRUE(CheckDecryption(encrypted, kIncludeVersion, !kIncludePathId, |
| 1645 !kIncludeDiversificationNonce)); |
1681 | 1646 |
1682 ASSERT_EQ(1u, visitor_.stream_frames_.size()); | 1647 ASSERT_EQ(1u, visitor_.stream_frames_.size()); |
1683 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 1648 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
1684 EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); | 1649 EXPECT_EQ(kStreamId, visitor_.stream_frames_[0]->stream_id); |
1685 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); | 1650 EXPECT_TRUE(visitor_.stream_frames_[0]->fin); |
1686 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); | 1651 EXPECT_EQ(kStreamOffset, visitor_.stream_frames_[0]->offset); |
1687 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); | 1652 CheckStreamFrameData("hello world!", visitor_.stream_frames_[0]); |
1688 | 1653 |
1689 // Now test framing boundaries. | 1654 // Now test framing boundaries. |
1690 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, kIncludeVersion); | 1655 CheckStreamFrameBoundaries(packet, kQuicMaxStreamIdSize, kIncludeVersion); |
1691 } | 1656 } |
1692 | 1657 |
1693 TEST_P(QuicFramerTest, RejectPacket) { | 1658 TEST_P(QuicFramerTest, RejectPacket) { |
1694 visitor_.accept_packet_ = false; | 1659 visitor_.accept_packet_ = false; |
1695 | 1660 |
1696 // clang-format off | 1661 // clang-format off |
1697 unsigned char packet[] = { | 1662 unsigned char packet[] = { |
1698 // public flags (8 byte connection_id) | 1663 // public flags (8 byte connection_id) |
1699 0x3C, | 1664 0x38, |
1700 // connection_id | 1665 // connection_id |
1701 0x10, 0x32, 0x54, 0x76, | 1666 0x10, 0x32, 0x54, 0x76, |
1702 0x98, 0xBA, 0xDC, 0xFE, | 1667 0x98, 0xBA, 0xDC, 0xFE, |
1703 // packet number | 1668 // packet number |
1704 0xBC, 0x9A, 0x78, 0x56, | 1669 0xBC, 0x9A, 0x78, 0x56, |
1705 0x34, 0x12, | 1670 0x34, 0x12, |
1706 // private flags | 1671 // private flags |
1707 0x00, | 1672 0x00, |
1708 | 1673 |
1709 // frame type (stream frame with fin) | 1674 // frame type (stream frame with fin) |
(...skipping 10 matching lines...) Expand all Loading... |
1720 'o', ' ', 'w', 'o', | 1685 'o', ' ', 'w', 'o', |
1721 'r', 'l', 'd', '!', | 1686 'r', 'l', 'd', '!', |
1722 }; | 1687 }; |
1723 // clang-format on | 1688 // clang-format on |
1724 | 1689 |
1725 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1690 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
1726 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1691 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
1727 | 1692 |
1728 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1693 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
1729 ASSERT_TRUE(visitor_.header_.get()); | 1694 ASSERT_TRUE(visitor_.header_.get()); |
1730 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 1695 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 1696 !kIncludeDiversificationNonce)); |
1731 | 1697 |
1732 ASSERT_EQ(0u, visitor_.stream_frames_.size()); | 1698 ASSERT_EQ(0u, visitor_.stream_frames_.size()); |
1733 EXPECT_EQ(0u, visitor_.ack_frames_.size()); | 1699 EXPECT_EQ(0u, visitor_.ack_frames_.size()); |
1734 } | 1700 } |
1735 | 1701 |
1736 TEST_P(QuicFramerTest, RejectPublicHeader) { | 1702 TEST_P(QuicFramerTest, RejectPublicHeader) { |
1737 visitor_.accept_public_header_ = false; | 1703 visitor_.accept_public_header_ = false; |
1738 | 1704 |
1739 // clang-format off | 1705 // clang-format off |
1740 unsigned char packet[] = { | 1706 unsigned char packet[] = { |
1741 // public flags (8 byte connection_id) | 1707 // public flags (8 byte connection_id) |
1742 0x3C, | 1708 0x38, |
1743 // connection_id | 1709 // connection_id |
1744 0x10, 0x32, 0x54, 0x76, | 1710 0x10, 0x32, 0x54, 0x76, |
1745 0x98, 0xBA, 0xDC, 0xFE, | 1711 0x98, 0xBA, 0xDC, 0xFE, |
1746 }; | 1712 }; |
1747 // clang-format on | 1713 // clang-format on |
1748 | 1714 |
1749 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1715 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
1750 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1716 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
1751 | 1717 |
1752 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1718 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
1753 ASSERT_TRUE(visitor_.public_header_.get()); | 1719 ASSERT_TRUE(visitor_.public_header_.get()); |
1754 ASSERT_FALSE(visitor_.header_.get()); | 1720 ASSERT_FALSE(visitor_.header_.get()); |
1755 } | 1721 } |
1756 | 1722 |
1757 TEST_P(QuicFramerTest, AckFrameTwoTimestamp) { | 1723 TEST_P(QuicFramerTest, AckFrameTwoTimestamp) { |
1758 // clang-format off | 1724 // clang-format off |
1759 unsigned char packet[] = { | 1725 unsigned char packet[] = { |
1760 // public flags (8 byte connection_id) | 1726 // public flags (8 byte connection_id) |
1761 0x3C, | 1727 0x38, |
1762 // connection_id | 1728 // connection_id |
1763 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 1729 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
1764 // packet number | 1730 // packet number |
1765 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, | 1731 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, |
1766 // private flags (entropy) | 1732 // private flags (entropy) |
1767 0x01, | 1733 0x01, |
1768 | 1734 |
1769 // frame type (ack frame) | 1735 // frame type (ack frame) |
1770 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | 1736 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) |
1771 0x6C, | 1737 0x6C, |
(...skipping 26 matching lines...) Expand all Loading... |
1798 | 1764 |
1799 if (framer_.version() > QUIC_VERSION_31) { | 1765 if (framer_.version() > QUIC_VERSION_31) { |
1800 return; | 1766 return; |
1801 } | 1767 } |
1802 | 1768 |
1803 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1769 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
1804 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1770 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
1805 | 1771 |
1806 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1772 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
1807 ASSERT_TRUE(visitor_.header_.get()); | 1773 ASSERT_TRUE(visitor_.header_.get()); |
1808 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 1774 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 1775 !kIncludeDiversificationNonce)); |
1809 | 1776 |
1810 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 1777 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
1811 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | 1778 ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
1812 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | 1779 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
1813 EXPECT_EQ(0xBA, frame.entropy_hash); | 1780 EXPECT_EQ(0xBA, frame.entropy_hash); |
1814 EXPECT_EQ(kLargestObserved, frame.largest_observed); | 1781 EXPECT_EQ(kLargestObserved, frame.largest_observed); |
1815 ASSERT_EQ(1u, frame.missing_packets.NumPacketsSlow()); | 1782 ASSERT_EQ(1u, frame.missing_packets.NumPacketsSlow()); |
1816 ASSERT_EQ(2u, frame.received_packet_times.size()); | 1783 ASSERT_EQ(2u, frame.received_packet_times.size()); |
1817 EXPECT_EQ(kMissingPacket, frame.missing_packets.Min()); | 1784 EXPECT_EQ(kMissingPacket, frame.missing_packets.Min()); |
1818 | 1785 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1866 } else if (i < kMissingPacketsRange) { | 1833 } else if (i < kMissingPacketsRange) { |
1867 expected_error = "Unable to read missing packet number delta."; | 1834 expected_error = "Unable to read missing packet number delta."; |
1868 } else if (i < kRevivedPacketsLength) { | 1835 } else if (i < kRevivedPacketsLength) { |
1869 expected_error = "Unable to read missing packet number range."; | 1836 expected_error = "Unable to read missing packet number range."; |
1870 } else { | 1837 } else { |
1871 expected_error = "Unable to read num revived packets."; | 1838 expected_error = "Unable to read num revived packets."; |
1872 } | 1839 } |
1873 CheckProcessingFails( | 1840 CheckProcessingFails( |
1874 packet, | 1841 packet, |
1875 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 1842 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
1876 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER), | 1843 !kIncludePathId, !kIncludeDiversificationNonce, |
| 1844 PACKET_6BYTE_PACKET_NUMBER), |
1877 expected_error, QUIC_INVALID_ACK_DATA); | 1845 expected_error, QUIC_INVALID_ACK_DATA); |
1878 } | 1846 } |
1879 } | 1847 } |
1880 | 1848 |
1881 TEST_P(QuicFramerTest, AckFrameTwoTimestampVersion32) { | 1849 TEST_P(QuicFramerTest, AckFrameTwoTimestampVersion32) { |
1882 // clang-format off | 1850 // clang-format off |
1883 unsigned char packet[] = { | 1851 unsigned char packet[] = { |
1884 // public flags (8 byte connection_id) | 1852 // public flags (8 byte connection_id) |
1885 0x3C, | 1853 0x3C, |
1886 // connection_id | 1854 // connection_id |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1920 | 1888 |
1921 if (framer_.version() <= QUIC_VERSION_31) { | 1889 if (framer_.version() <= QUIC_VERSION_31) { |
1922 return; | 1890 return; |
1923 } | 1891 } |
1924 | 1892 |
1925 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 1893 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
1926 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 1894 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
1927 | 1895 |
1928 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 1896 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
1929 ASSERT_TRUE(visitor_.header_.get()); | 1897 ASSERT_TRUE(visitor_.header_.get()); |
1930 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 1898 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 1899 !kIncludeDiversificationNonce)); |
1931 | 1900 |
1932 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 1901 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
1933 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | 1902 ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
1934 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | 1903 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
1935 EXPECT_EQ(0xBA, frame.entropy_hash); | 1904 EXPECT_EQ(0xBA, frame.entropy_hash); |
1936 EXPECT_EQ(kLargestObserved, frame.largest_observed); | 1905 EXPECT_EQ(kLargestObserved, frame.largest_observed); |
1937 ASSERT_EQ(1u, frame.missing_packets.NumPacketsSlow()); | 1906 ASSERT_EQ(1u, frame.missing_packets.NumPacketsSlow()); |
1938 ASSERT_EQ(2u, frame.received_packet_times.size()); | 1907 ASSERT_EQ(2u, frame.received_packet_times.size()); |
1939 EXPECT_EQ(kMissingPacket, frame.missing_packets.Min()); | 1908 EXPECT_EQ(kMissingPacket, frame.missing_packets.Min()); |
1940 | 1909 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1979 expected_error = | 1948 expected_error = |
1980 "Unable to read incremental time delta in received packets."; | 1949 "Unable to read incremental time delta in received packets."; |
1981 } else if (i < kMissingPacketsOffset) { | 1950 } else if (i < kMissingPacketsOffset) { |
1982 expected_error = "Unable to read num missing packet ranges."; | 1951 expected_error = "Unable to read num missing packet ranges."; |
1983 } else { | 1952 } else { |
1984 expected_error = "Unable to read missing packet number delta."; | 1953 expected_error = "Unable to read missing packet number delta."; |
1985 } | 1954 } |
1986 CheckProcessingFails( | 1955 CheckProcessingFails( |
1987 packet, | 1956 packet, |
1988 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 1957 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
1989 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER), | 1958 !kIncludePathId, !kIncludeDiversificationNonce, |
| 1959 PACKET_6BYTE_PACKET_NUMBER), |
1990 expected_error, QUIC_INVALID_ACK_DATA); | 1960 expected_error, QUIC_INVALID_ACK_DATA); |
1991 } | 1961 } |
1992 } | 1962 } |
1993 | 1963 |
1994 TEST_P(QuicFramerTest, AckFrameOneTimestamp) { | 1964 TEST_P(QuicFramerTest, AckFrameOneTimestamp) { |
1995 // clang-format off | 1965 // clang-format off |
1996 unsigned char packet[] = { | 1966 unsigned char packet[] = { |
1997 // public flags (8 byte connection_id) | 1967 // public flags (8 byte connection_id) |
1998 0x3C, | 1968 0x38, |
1999 // connection_id | 1969 // connection_id |
2000 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 1970 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
2001 // packet number | 1971 // packet number |
2002 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, | 1972 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, |
2003 // private flags (entropy) | 1973 // private flags (entropy) |
2004 0x01, | 1974 0x01, |
2005 | 1975 |
2006 // frame type (ack frame) | 1976 // frame type (ack frame) |
2007 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | 1977 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) |
2008 0x6C, | 1978 0x6C, |
(...skipping 22 matching lines...) Expand all Loading... |
2031 | 2001 |
2032 if (framer_.version() > QUIC_VERSION_31) { | 2002 if (framer_.version() > QUIC_VERSION_31) { |
2033 return; | 2003 return; |
2034 } | 2004 } |
2035 | 2005 |
2036 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 2006 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
2037 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 2007 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
2038 | 2008 |
2039 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 2009 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
2040 ASSERT_TRUE(visitor_.header_.get()); | 2010 ASSERT_TRUE(visitor_.header_.get()); |
2041 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 2011 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 2012 !kIncludeDiversificationNonce)); |
2042 | 2013 |
2043 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 2014 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
2044 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | 2015 ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
2045 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | 2016 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
2046 EXPECT_EQ(0xBA, frame.entropy_hash); | 2017 EXPECT_EQ(0xBA, frame.entropy_hash); |
2047 EXPECT_EQ(kLargestObserved, frame.largest_observed); | 2018 EXPECT_EQ(kLargestObserved, frame.largest_observed); |
2048 ASSERT_EQ(1u, frame.missing_packets.NumPacketsSlow()); | 2019 ASSERT_EQ(1u, frame.missing_packets.NumPacketsSlow()); |
2049 ASSERT_EQ(1u, frame.received_packet_times.size()); | 2020 ASSERT_EQ(1u, frame.received_packet_times.size()); |
2050 EXPECT_EQ(kMissingPacket, frame.missing_packets.Min()); | 2021 EXPECT_EQ(kMissingPacket, frame.missing_packets.Min()); |
2051 | 2022 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2089 } else if (i < kMissingPacketsRange) { | 2060 } else if (i < kMissingPacketsRange) { |
2090 expected_error = "Unable to read missing packet number delta."; | 2061 expected_error = "Unable to read missing packet number delta."; |
2091 } else if (i < kRevivedPacketsLength) { | 2062 } else if (i < kRevivedPacketsLength) { |
2092 expected_error = "Unable to read missing packet number range."; | 2063 expected_error = "Unable to read missing packet number range."; |
2093 } else { | 2064 } else { |
2094 expected_error = "Unable to read num revived packets."; | 2065 expected_error = "Unable to read num revived packets."; |
2095 } | 2066 } |
2096 CheckProcessingFails( | 2067 CheckProcessingFails( |
2097 packet, | 2068 packet, |
2098 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 2069 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
2099 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER), | 2070 !kIncludePathId, !kIncludeDiversificationNonce, |
| 2071 PACKET_6BYTE_PACKET_NUMBER), |
2100 expected_error, QUIC_INVALID_ACK_DATA); | 2072 expected_error, QUIC_INVALID_ACK_DATA); |
2101 } | 2073 } |
2102 } | 2074 } |
2103 | 2075 |
2104 TEST_P(QuicFramerTest, AckFrameOneTimestampVersion32) { | 2076 TEST_P(QuicFramerTest, AckFrameOneTimestampVersion32) { |
2105 // clang-format off | 2077 // clang-format off |
2106 unsigned char packet[] = { | 2078 unsigned char packet[] = { |
2107 // public flags (8 byte connection_id) | 2079 // public flags (8 byte connection_id) |
2108 0x3C, | 2080 0x3C, |
2109 // connection_id | 2081 // connection_id |
(...skipping 29 matching lines...) Expand all Loading... |
2139 | 2111 |
2140 if (framer_.version() <= QUIC_VERSION_31) { | 2112 if (framer_.version() <= QUIC_VERSION_31) { |
2141 return; | 2113 return; |
2142 } | 2114 } |
2143 | 2115 |
2144 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 2116 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
2145 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 2117 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
2146 | 2118 |
2147 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 2119 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
2148 ASSERT_TRUE(visitor_.header_.get()); | 2120 ASSERT_TRUE(visitor_.header_.get()); |
2149 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 2121 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 2122 !kIncludeDiversificationNonce)); |
2150 | 2123 |
2151 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 2124 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
2152 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | 2125 ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
2153 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | 2126 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
2154 EXPECT_EQ(0xBA, frame.entropy_hash); | 2127 EXPECT_EQ(0xBA, frame.entropy_hash); |
2155 EXPECT_EQ(kLargestObserved, frame.largest_observed); | 2128 EXPECT_EQ(kLargestObserved, frame.largest_observed); |
2156 ASSERT_EQ(1u, frame.missing_packets.NumPacketsSlow()); | 2129 ASSERT_EQ(1u, frame.missing_packets.NumPacketsSlow()); |
2157 ASSERT_EQ(1u, frame.received_packet_times.size()); | 2130 ASSERT_EQ(1u, frame.received_packet_times.size()); |
2158 EXPECT_EQ(kMissingPacket, frame.missing_packets.Min()); | 2131 EXPECT_EQ(kMissingPacket, frame.missing_packets.Min()); |
2159 | 2132 |
(...skipping 28 matching lines...) Expand all Loading... |
2188 } else if (i < kNumMissingPacketOffset) { | 2161 } else if (i < kNumMissingPacketOffset) { |
2189 expected_error = "Unable to read time delta in received packets."; | 2162 expected_error = "Unable to read time delta in received packets."; |
2190 } else if (i < kMissingPacketsOffset) { | 2163 } else if (i < kMissingPacketsOffset) { |
2191 expected_error = "Unable to read num missing packet ranges."; | 2164 expected_error = "Unable to read num missing packet ranges."; |
2192 } else { | 2165 } else { |
2193 expected_error = "Unable to read missing packet number delta."; | 2166 expected_error = "Unable to read missing packet number delta."; |
2194 } | 2167 } |
2195 CheckProcessingFails( | 2168 CheckProcessingFails( |
2196 packet, | 2169 packet, |
2197 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 2170 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
2198 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER), | 2171 !kIncludePathId, !kIncludeDiversificationNonce, |
| 2172 PACKET_6BYTE_PACKET_NUMBER), |
2199 expected_error, QUIC_INVALID_ACK_DATA); | 2173 expected_error, QUIC_INVALID_ACK_DATA); |
2200 } | 2174 } |
2201 } | 2175 } |
2202 | 2176 |
2203 TEST_P(QuicFramerTest, AckFrame) { | 2177 TEST_P(QuicFramerTest, AckFrame) { |
2204 // clang-format off | 2178 // clang-format off |
2205 unsigned char packet[] = { | 2179 unsigned char packet[] = { |
2206 // public flags (8 byte connection_id) | 2180 // public flags (8 byte connection_id) |
2207 0x3C, | 2181 0x3C, |
2208 // connection_id | 2182 // connection_id |
(...skipping 27 matching lines...) Expand all Loading... |
2236 | 2210 |
2237 if (framer_.version() > QUIC_VERSION_31) { | 2211 if (framer_.version() > QUIC_VERSION_31) { |
2238 return; | 2212 return; |
2239 } | 2213 } |
2240 | 2214 |
2241 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 2215 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
2242 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 2216 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
2243 | 2217 |
2244 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 2218 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
2245 ASSERT_TRUE(visitor_.header_.get()); | 2219 ASSERT_TRUE(visitor_.header_.get()); |
2246 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 2220 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 2221 !kIncludeDiversificationNonce)); |
2247 | 2222 |
2248 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 2223 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
2249 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | 2224 ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
2250 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | 2225 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
2251 EXPECT_EQ(0xBA, frame.entropy_hash); | 2226 EXPECT_EQ(0xBA, frame.entropy_hash); |
2252 EXPECT_EQ(kLargestObserved, frame.largest_observed); | 2227 EXPECT_EQ(kLargestObserved, frame.largest_observed); |
2253 ASSERT_EQ(1u, frame.missing_packets.NumPacketsSlow()); | 2228 ASSERT_EQ(1u, frame.missing_packets.NumPacketsSlow()); |
2254 EXPECT_EQ(kMissingPacket, frame.missing_packets.Min()); | 2229 EXPECT_EQ(kMissingPacket, frame.missing_packets.Min()); |
2255 | 2230 |
2256 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; | 2231 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; |
(...skipping 29 matching lines...) Expand all Loading... |
2286 } else if (i < kMissingPacketsRange) { | 2261 } else if (i < kMissingPacketsRange) { |
2287 expected_error = "Unable to read missing packet number delta."; | 2262 expected_error = "Unable to read missing packet number delta."; |
2288 } else if (i < kRevivedPacketsLength) { | 2263 } else if (i < kRevivedPacketsLength) { |
2289 expected_error = "Unable to read missing packet number range."; | 2264 expected_error = "Unable to read missing packet number range."; |
2290 } else { | 2265 } else { |
2291 expected_error = "Unable to read num revived packets."; | 2266 expected_error = "Unable to read num revived packets."; |
2292 } | 2267 } |
2293 CheckProcessingFails( | 2268 CheckProcessingFails( |
2294 packet, | 2269 packet, |
2295 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 2270 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
2296 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER), | 2271 !kIncludePathId, !kIncludeDiversificationNonce, |
| 2272 PACKET_6BYTE_PACKET_NUMBER), |
2297 expected_error, QUIC_INVALID_ACK_DATA); | 2273 expected_error, QUIC_INVALID_ACK_DATA); |
2298 } | 2274 } |
2299 } | 2275 } |
2300 | 2276 |
2301 TEST_P(QuicFramerTest, AckFrameVersion32) { | 2277 TEST_P(QuicFramerTest, AckFrameVersion32) { |
2302 // clang-format off | 2278 // clang-format off |
2303 unsigned char packet[] = { | 2279 unsigned char packet[] = { |
2304 // public flags (8 byte connection_id) | 2280 // public flags (8 byte connection_id) |
2305 0x3C, | 2281 0x38, |
2306 // connection_id | 2282 // connection_id |
2307 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 2283 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
2308 // packet number | 2284 // packet number |
2309 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, | 2285 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, |
2310 // private flags (entropy) | 2286 // private flags (entropy) |
2311 0x01, | 2287 0x01, |
2312 | 2288 |
2313 // frame type (ack frame) | 2289 // frame type (ack frame) |
2314 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | 2290 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) |
2315 0x6C, | 2291 0x6C, |
(...skipping 16 matching lines...) Expand all Loading... |
2332 | 2308 |
2333 if (framer_.version() <= QUIC_VERSION_31) { | 2309 if (framer_.version() <= QUIC_VERSION_31) { |
2334 return; | 2310 return; |
2335 } | 2311 } |
2336 | 2312 |
2337 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 2313 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
2338 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 2314 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
2339 | 2315 |
2340 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 2316 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
2341 ASSERT_TRUE(visitor_.header_.get()); | 2317 ASSERT_TRUE(visitor_.header_.get()); |
2342 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 2318 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 2319 !kIncludeDiversificationNonce)); |
2343 | 2320 |
2344 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 2321 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
2345 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | 2322 ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
2346 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | 2323 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
2347 EXPECT_EQ(0xBA, frame.entropy_hash); | 2324 EXPECT_EQ(0xBA, frame.entropy_hash); |
2348 EXPECT_EQ(kLargestObserved, frame.largest_observed); | 2325 EXPECT_EQ(kLargestObserved, frame.largest_observed); |
2349 ASSERT_EQ(1u, frame.missing_packets.NumPacketsSlow()); | 2326 ASSERT_EQ(1u, frame.missing_packets.NumPacketsSlow()); |
2350 EXPECT_EQ(kMissingPacket, frame.missing_packets.Min()); | 2327 EXPECT_EQ(kMissingPacket, frame.missing_packets.Min()); |
2351 | 2328 |
2352 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; | 2329 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; |
(...skipping 20 matching lines...) Expand all Loading... |
2373 } else if (i < kNumMissingPacketOffset) { | 2350 } else if (i < kNumMissingPacketOffset) { |
2374 expected_error = "Unable to read num received packets."; | 2351 expected_error = "Unable to read num received packets."; |
2375 } else if (i < kMissingPacketsOffset) { | 2352 } else if (i < kMissingPacketsOffset) { |
2376 expected_error = "Unable to read num missing packet ranges."; | 2353 expected_error = "Unable to read num missing packet ranges."; |
2377 } else { | 2354 } else { |
2378 expected_error = "Unable to read missing packet number delta."; | 2355 expected_error = "Unable to read missing packet number delta."; |
2379 } | 2356 } |
2380 CheckProcessingFails( | 2357 CheckProcessingFails( |
2381 packet, | 2358 packet, |
2382 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 2359 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
2383 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER), | 2360 !kIncludePathId, !kIncludeDiversificationNonce, |
| 2361 PACKET_6BYTE_PACKET_NUMBER), |
2384 expected_error, QUIC_INVALID_ACK_DATA); | 2362 expected_error, QUIC_INVALID_ACK_DATA); |
2385 } | 2363 } |
2386 } | 2364 } |
2387 | 2365 |
2388 TEST_P(QuicFramerTest, AckFrameRevivedPackets) { | 2366 TEST_P(QuicFramerTest, AckFrameRevivedPackets) { |
2389 // clang-format off | 2367 // clang-format off |
2390 unsigned char packet[] = { | 2368 unsigned char packet[] = { |
2391 // public flags (8 byte connection_id) | 2369 // public flags (8 byte connection_id) |
2392 0x3C, | 2370 0x38, |
2393 // connection_id | 2371 // connection_id |
2394 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 2372 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
2395 // packet number | 2373 // packet number |
2396 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, | 2374 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, |
2397 // private flags (entropy) | 2375 // private flags (entropy) |
2398 0x01, | 2376 0x01, |
2399 | 2377 |
2400 // frame type (ack frame) | 2378 // frame type (ack frame) |
2401 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | 2379 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) |
2402 0x6C, | 2380 0x6C, |
(...skipping 22 matching lines...) Expand all Loading... |
2425 | 2403 |
2426 if (framer_.version() > QUIC_VERSION_31) { | 2404 if (framer_.version() > QUIC_VERSION_31) { |
2427 return; | 2405 return; |
2428 } | 2406 } |
2429 | 2407 |
2430 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 2408 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
2431 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 2409 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
2432 | 2410 |
2433 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 2411 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
2434 ASSERT_TRUE(visitor_.header_.get()); | 2412 ASSERT_TRUE(visitor_.header_.get()); |
2435 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 2413 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 2414 !kIncludeDiversificationNonce)); |
2436 | 2415 |
2437 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 2416 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
2438 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | 2417 ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
2439 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; | 2418 const QuicAckFrame& frame = *visitor_.ack_frames_[0]; |
2440 EXPECT_EQ(0xBA, frame.entropy_hash); | 2419 EXPECT_EQ(0xBA, frame.entropy_hash); |
2441 EXPECT_EQ(kLargestObserved, frame.largest_observed); | 2420 EXPECT_EQ(kLargestObserved, frame.largest_observed); |
2442 ASSERT_EQ(1u, frame.missing_packets.NumPacketsSlow()); | 2421 ASSERT_EQ(1u, frame.missing_packets.NumPacketsSlow()); |
2443 EXPECT_EQ(kMissingPacket, frame.missing_packets.Min()); | 2422 EXPECT_EQ(kMissingPacket, frame.missing_packets.Min()); |
2444 | 2423 |
2445 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; | 2424 const size_t kReceivedEntropyOffset = kQuicFrameTypeSize; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2481 } else if (i < kRevivedPacketsLength) { | 2460 } else if (i < kRevivedPacketsLength) { |
2482 expected_error = "Unable to read missing packet number range."; | 2461 expected_error = "Unable to read missing packet number range."; |
2483 } else if (i < kRevivedPacketSequenceNumberLength) { | 2462 } else if (i < kRevivedPacketSequenceNumberLength) { |
2484 expected_error = "Unable to read num revived packets."; | 2463 expected_error = "Unable to read num revived packets."; |
2485 } else { | 2464 } else { |
2486 expected_error = "Unable to read revived packet."; | 2465 expected_error = "Unable to read revived packet."; |
2487 } | 2466 } |
2488 CheckProcessingFails( | 2467 CheckProcessingFails( |
2489 packet, | 2468 packet, |
2490 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 2469 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
2491 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER), | 2470 !kIncludePathId, !kIncludeDiversificationNonce, |
| 2471 PACKET_6BYTE_PACKET_NUMBER), |
2492 expected_error, QUIC_INVALID_ACK_DATA); | 2472 expected_error, QUIC_INVALID_ACK_DATA); |
2493 } | 2473 } |
2494 } | 2474 } |
2495 | 2475 |
2496 TEST_P(QuicFramerTest, AckFrameNoNacks) { | 2476 TEST_P(QuicFramerTest, AckFrameNoNacks) { |
2497 // clang-format off | 2477 // clang-format off |
2498 unsigned char packet[] = { | 2478 unsigned char packet[] = { |
2499 // public flags (8 byte connection_id) | 2479 // public flags (8 byte connection_id) |
2500 0x3C, | 2480 static_cast<unsigned char>( |
| 2481 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
2501 // connection_id | 2482 // connection_id |
2502 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 2483 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
2503 // packet number | 2484 // packet number |
2504 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, | 2485 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, |
2505 // private flags (entropy) | 2486 // private flags (entropy) |
2506 0x01, | 2487 0x01, |
2507 | 2488 |
2508 // frame type (ack frame) | 2489 // frame type (ack frame) |
2509 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta) | 2490 // (no nacks, not truncated, 6 byte largest observed, 1 byte delta) |
2510 0x4C, | 2491 0x4C, |
2511 // entropy hash of all received packets. | 2492 // entropy hash of all received packets. |
2512 0xBA, | 2493 0xBA, |
2513 // largest observed packet number | 2494 // largest observed packet number |
2514 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12, | 2495 0xBF, 0x9A, 0x78, 0x56, 0x34, 0x12, |
2515 // Zero delta time. | 2496 // Zero delta time. |
2516 0x00, 0x00, | 2497 0x00, 0x00, |
2517 // Number of received packets. | 2498 // Number of received packets. |
2518 0x00, | 2499 0x00, |
2519 }; | 2500 }; |
2520 // clang-format on | 2501 // clang-format on |
2521 | 2502 |
2522 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 2503 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
2523 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 2504 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
2524 | 2505 |
2525 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 2506 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
2526 ASSERT_TRUE(visitor_.header_.get()); | 2507 ASSERT_TRUE(visitor_.header_.get()); |
2527 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 2508 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 2509 !kIncludeDiversificationNonce)); |
2528 | 2510 |
2529 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 2511 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
2530 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | 2512 ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
2531 QuicAckFrame* frame = visitor_.ack_frames_[0]; | 2513 QuicAckFrame* frame = visitor_.ack_frames_[0]; |
2532 EXPECT_EQ(0xBA, frame->entropy_hash); | 2514 EXPECT_EQ(0xBA, frame->entropy_hash); |
2533 EXPECT_EQ(kLargestObserved, frame->largest_observed); | 2515 EXPECT_EQ(kLargestObserved, frame->largest_observed); |
2534 ASSERT_TRUE(frame->missing_packets.Empty()); | 2516 ASSERT_TRUE(frame->missing_packets.Empty()); |
2535 | 2517 |
2536 // Verify that the packet re-serializes identically. | 2518 // Verify that the packet re-serializes identically. |
2537 QuicFrames frames; | 2519 QuicFrames frames; |
2538 frames.push_back(QuicFrame(frame)); | 2520 frames.push_back(QuicFrame(frame)); |
2539 std::unique_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames)); | 2521 std::unique_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames)); |
2540 ASSERT_TRUE(data != nullptr); | 2522 ASSERT_TRUE(data != nullptr); |
2541 | 2523 |
2542 test::CompareCharArraysWithHexError("constructed packet", data->data(), | 2524 test::CompareCharArraysWithHexError("constructed packet", data->data(), |
2543 data->length(), AsChars(packet), | 2525 data->length(), AsChars(packet), |
2544 arraysize(packet)); | 2526 arraysize(packet)); |
2545 } | 2527 } |
2546 | 2528 |
2547 TEST_P(QuicFramerTest, AckFrame500Nacks) { | 2529 TEST_P(QuicFramerTest, AckFrame500Nacks) { |
2548 // clang-format off | 2530 // clang-format off |
2549 unsigned char packet[] = { | 2531 unsigned char packet[] = { |
2550 // public flags (8 byte connection_id) | 2532 // public flags (8 byte connection_id) |
2551 0x3C, | 2533 static_cast<unsigned char>( |
| 2534 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
2552 // connection_id | 2535 // connection_id |
2553 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 2536 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
2554 // packet number | 2537 // packet number |
2555 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, | 2538 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, |
2556 // private flags (entropy) | 2539 // private flags (entropy) |
2557 0x01, | 2540 0x01, |
2558 | 2541 |
2559 // frame type (ack frame) | 2542 // frame type (ack frame) |
2560 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | 2543 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) |
2561 0x6C, | 2544 0x6C, |
(...skipping 24 matching lines...) Expand all Loading... |
2586 | 2569 |
2587 if (framer_.version() > QUIC_VERSION_31) { | 2570 if (framer_.version() > QUIC_VERSION_31) { |
2588 return; | 2571 return; |
2589 } | 2572 } |
2590 | 2573 |
2591 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 2574 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
2592 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 2575 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
2593 | 2576 |
2594 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 2577 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
2595 ASSERT_TRUE(visitor_.header_.get()); | 2578 ASSERT_TRUE(visitor_.header_.get()); |
2596 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 2579 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 2580 !kIncludeDiversificationNonce)); |
2597 | 2581 |
2598 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 2582 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
2599 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | 2583 ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
2600 QuicAckFrame* frame = visitor_.ack_frames_[0]; | 2584 QuicAckFrame* frame = visitor_.ack_frames_[0]; |
2601 EXPECT_EQ(0xBA, frame->entropy_hash); | 2585 EXPECT_EQ(0xBA, frame->entropy_hash); |
2602 EXPECT_EQ(kLargestObserved, frame->largest_observed); | 2586 EXPECT_EQ(kLargestObserved, frame->largest_observed); |
2603 ASSERT_EQ(500u, frame->missing_packets.NumPacketsSlow()); | 2587 ASSERT_EQ(500u, frame->missing_packets.NumPacketsSlow()); |
2604 EXPECT_EQ(kMissingPacket - 499, frame->missing_packets.Min()); | 2588 EXPECT_EQ(kMissingPacket - 499, frame->missing_packets.Min()); |
2605 EXPECT_EQ(kMissingPacket, frame->missing_packets.Max()); | 2589 EXPECT_EQ(kMissingPacket, frame->missing_packets.Max()); |
2606 | 2590 |
2607 // Verify that the packet re-serializes identically. | 2591 // Verify that the packet re-serializes identically. |
2608 QuicFrames frames; | 2592 QuicFrames frames; |
2609 frames.push_back(QuicFrame(frame)); | 2593 frames.push_back(QuicFrame(frame)); |
2610 std::unique_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames)); | 2594 std::unique_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames)); |
2611 ASSERT_TRUE(data != nullptr); | 2595 ASSERT_TRUE(data != nullptr); |
2612 | 2596 |
2613 test::CompareCharArraysWithHexError("constructed packet", data->data(), | 2597 test::CompareCharArraysWithHexError("constructed packet", data->data(), |
2614 data->length(), AsChars(packet), | 2598 data->length(), AsChars(packet), |
2615 arraysize(packet)); | 2599 arraysize(packet)); |
2616 } | 2600 } |
2617 | 2601 |
2618 TEST_P(QuicFramerTest, AckFrame500NacksVersion32) { | 2602 TEST_P(QuicFramerTest, AckFrame500NacksVersion32) { |
2619 // clang-format off | 2603 // clang-format off |
2620 unsigned char packet[] = { | 2604 unsigned char packet[] = { |
2621 // public flags (8 byte connection_id) | 2605 // public flags (8 byte connection_id) |
2622 0x3C, | 2606 static_cast<unsigned char>( |
| 2607 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
2623 // connection_id | 2608 // connection_id |
2624 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 2609 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
2625 // packet number | 2610 // packet number |
2626 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, | 2611 0xA8, 0x9A, 0x78, 0x56, 0x34, 0x12, |
2627 // private flags (entropy) | 2612 // private flags (entropy) |
2628 0x01, | 2613 0x01, |
2629 | 2614 |
2630 // frame type (ack frame) | 2615 // frame type (ack frame) |
2631 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | 2616 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) |
2632 0x6C, | 2617 0x6C, |
(...skipping 22 matching lines...) Expand all Loading... |
2655 | 2640 |
2656 if (framer_.version() <= QUIC_VERSION_31) { | 2641 if (framer_.version() <= QUIC_VERSION_31) { |
2657 return; | 2642 return; |
2658 } | 2643 } |
2659 | 2644 |
2660 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 2645 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
2661 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 2646 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
2662 | 2647 |
2663 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 2648 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
2664 ASSERT_TRUE(visitor_.header_.get()); | 2649 ASSERT_TRUE(visitor_.header_.get()); |
2665 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 2650 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 2651 !kIncludeDiversificationNonce)); |
2666 | 2652 |
2667 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 2653 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
2668 ASSERT_EQ(1u, visitor_.ack_frames_.size()); | 2654 ASSERT_EQ(1u, visitor_.ack_frames_.size()); |
2669 QuicAckFrame* frame = visitor_.ack_frames_[0]; | 2655 QuicAckFrame* frame = visitor_.ack_frames_[0]; |
2670 EXPECT_EQ(0xBA, frame->entropy_hash); | 2656 EXPECT_EQ(0xBA, frame->entropy_hash); |
2671 EXPECT_EQ(kLargestObserved, frame->largest_observed); | 2657 EXPECT_EQ(kLargestObserved, frame->largest_observed); |
2672 ASSERT_EQ(500u, frame->missing_packets.NumPacketsSlow()); | 2658 ASSERT_EQ(500u, frame->missing_packets.NumPacketsSlow()); |
2673 EXPECT_EQ(kMissingPacket - 499, frame->missing_packets.Min()); | 2659 EXPECT_EQ(kMissingPacket - 499, frame->missing_packets.Min()); |
2674 EXPECT_EQ(kMissingPacket, frame->missing_packets.Max()); | 2660 EXPECT_EQ(kMissingPacket, frame->missing_packets.Max()); |
2675 | 2661 |
2676 // Verify that the packet re-serializes identically. | 2662 // Verify that the packet re-serializes identically. |
2677 QuicFrames frames; | 2663 QuicFrames frames; |
2678 frames.push_back(QuicFrame(frame)); | 2664 frames.push_back(QuicFrame(frame)); |
2679 std::unique_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames)); | 2665 std::unique_ptr<QuicPacket> data(BuildDataPacket(*visitor_.header_, frames)); |
2680 ASSERT_TRUE(data != nullptr); | 2666 ASSERT_TRUE(data != nullptr); |
2681 | 2667 |
2682 test::CompareCharArraysWithHexError("constructed packet", data->data(), | 2668 test::CompareCharArraysWithHexError("constructed packet", data->data(), |
2683 data->length(), AsChars(packet), | 2669 data->length(), AsChars(packet), |
2684 arraysize(packet)); | 2670 arraysize(packet)); |
2685 } | 2671 } |
2686 | 2672 |
2687 TEST_P(QuicFramerTest, StopWaitingFrame) { | 2673 TEST_P(QuicFramerTest, StopWaitingFrame) { |
2688 // clang-format off | 2674 // clang-format off |
2689 unsigned char packet[] = { | 2675 unsigned char packet[] = { |
2690 // public flags (8 byte connection_id) | 2676 // public flags (8 byte connection_id) |
2691 0x3C, | 2677 0x38, |
2692 // connection_id | 2678 // connection_id |
2693 0x10, 0x32, 0x54, 0x76, | 2679 0x10, 0x32, 0x54, 0x76, |
2694 0x98, 0xBA, 0xDC, 0xFE, | 2680 0x98, 0xBA, 0xDC, 0xFE, |
2695 // packet number | 2681 // packet number |
2696 0xA8, 0x9A, 0x78, 0x56, | 2682 0xA8, 0x9A, 0x78, 0x56, |
2697 0x34, 0x12, | 2683 0x34, 0x12, |
2698 // private flags (entropy) | 2684 // private flags (entropy) |
2699 0x01, | 2685 0x01, |
2700 | 2686 |
2701 // frame type (ack frame) | 2687 // frame type (ack frame) |
2702 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | 2688 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) |
2703 0x06, | 2689 0x06, |
2704 // entropy hash of sent packets till least awaiting - 1. | 2690 // entropy hash of sent packets till least awaiting - 1. |
2705 0xAB, | 2691 0xAB, |
2706 // least packet number awaiting an ack, delta from packet number. | 2692 // least packet number awaiting an ack, delta from packet number. |
2707 0x08, 0x00, 0x00, 0x00, | 2693 0x08, 0x00, 0x00, 0x00, |
2708 0x00, 0x00, | 2694 0x00, 0x00, |
2709 }; | 2695 }; |
2710 // clang-format on | 2696 // clang-format on |
2711 | 2697 |
2712 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 2698 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
2713 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 2699 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
2714 | 2700 |
2715 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 2701 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
2716 ASSERT_TRUE(visitor_.header_.get()); | 2702 ASSERT_TRUE(visitor_.header_.get()); |
2717 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 2703 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 2704 !kIncludeDiversificationNonce)); |
2718 | 2705 |
2719 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 2706 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
2720 ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size()); | 2707 ASSERT_EQ(1u, visitor_.stop_waiting_frames_.size()); |
2721 const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0]; | 2708 const QuicStopWaitingFrame& frame = *visitor_.stop_waiting_frames_[0]; |
2722 EXPECT_EQ(0xAB, frame.entropy_hash); | 2709 EXPECT_EQ(0xAB, frame.entropy_hash); |
2723 EXPECT_EQ(kLeastUnacked, frame.least_unacked); | 2710 EXPECT_EQ(kLeastUnacked, frame.least_unacked); |
2724 | 2711 |
2725 const size_t kSentEntropyOffset = kQuicFrameTypeSize; | 2712 const size_t kSentEntropyOffset = kQuicFrameTypeSize; |
2726 const size_t kLeastUnackedOffset = kSentEntropyOffset + kQuicEntropyHashSize; | 2713 const size_t kLeastUnackedOffset = kSentEntropyOffset + kQuicEntropyHashSize; |
2727 const size_t frame_size = 7; | 2714 const size_t frame_size = 7; |
2728 for (size_t i = kQuicFrameTypeSize; i < frame_size; ++i) { | 2715 for (size_t i = kQuicFrameTypeSize; i < frame_size; ++i) { |
2729 string expected_error; | 2716 string expected_error; |
2730 if (i < kLeastUnackedOffset) { | 2717 if (i < kLeastUnackedOffset) { |
2731 expected_error = "Unable to read entropy hash for sent packets."; | 2718 expected_error = "Unable to read entropy hash for sent packets."; |
2732 } else { | 2719 } else { |
2733 expected_error = "Unable to read least unacked delta."; | 2720 expected_error = "Unable to read least unacked delta."; |
2734 } | 2721 } |
2735 CheckProcessingFails( | 2722 CheckProcessingFails( |
2736 packet, | 2723 packet, |
2737 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 2724 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
2738 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER), | 2725 !kIncludePathId, !kIncludeDiversificationNonce, |
| 2726 PACKET_6BYTE_PACKET_NUMBER), |
2739 expected_error, QUIC_INVALID_STOP_WAITING_DATA); | 2727 expected_error, QUIC_INVALID_STOP_WAITING_DATA); |
2740 } | 2728 } |
2741 } | 2729 } |
2742 | 2730 |
2743 TEST_P(QuicFramerTest, RstStreamFrameQuic) { | 2731 TEST_P(QuicFramerTest, RstStreamFrameQuic) { |
2744 // clang-format off | 2732 // clang-format off |
2745 unsigned char packet[] = { | 2733 unsigned char packet[] = { |
2746 // public flags (8 byte connection_id) | 2734 // public flags (8 byte connection_id) |
2747 0x3C, | 2735 0x38, |
2748 // connection_id | 2736 // connection_id |
2749 0x10, 0x32, 0x54, 0x76, | 2737 0x10, 0x32, 0x54, 0x76, |
2750 0x98, 0xBA, 0xDC, 0xFE, | 2738 0x98, 0xBA, 0xDC, 0xFE, |
2751 // packet number | 2739 // packet number |
2752 0xBC, 0x9A, 0x78, 0x56, | 2740 0xBC, 0x9A, 0x78, 0x56, |
2753 0x34, 0x12, | 2741 0x34, 0x12, |
2754 // private flags | 2742 // private flags |
2755 0x00, | 2743 0x00, |
2756 | 2744 |
2757 // frame type (rst stream frame) | 2745 // frame type (rst stream frame) |
2758 0x01, | 2746 0x01, |
2759 // stream id | 2747 // stream id |
2760 0x04, 0x03, 0x02, 0x01, | 2748 0x04, 0x03, 0x02, 0x01, |
2761 | 2749 |
2762 // sent byte offset | 2750 // sent byte offset |
2763 0x54, 0x76, 0x10, 0x32, | 2751 0x54, 0x76, 0x10, 0x32, |
2764 0xDC, 0xFE, 0x98, 0xBA, | 2752 0xDC, 0xFE, 0x98, 0xBA, |
2765 | 2753 |
2766 // error code | 2754 // error code |
2767 0x01, 0x00, 0x00, 0x00, | 2755 0x01, 0x00, 0x00, 0x00, |
2768 }; | 2756 }; |
2769 // clang-format on | 2757 // clang-format on |
2770 | 2758 |
2771 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 2759 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
2772 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 2760 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
2773 | 2761 |
2774 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 2762 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
2775 ASSERT_TRUE(visitor_.header_.get()); | 2763 ASSERT_TRUE(visitor_.header_.get()); |
2776 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 2764 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 2765 !kIncludeDiversificationNonce)); |
2777 | 2766 |
2778 EXPECT_EQ(kStreamId, visitor_.rst_stream_frame_.stream_id); | 2767 EXPECT_EQ(kStreamId, visitor_.rst_stream_frame_.stream_id); |
2779 EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code); | 2768 EXPECT_EQ(0x01, visitor_.rst_stream_frame_.error_code); |
2780 EXPECT_EQ(kStreamOffset, visitor_.rst_stream_frame_.byte_offset); | 2769 EXPECT_EQ(kStreamOffset, visitor_.rst_stream_frame_.byte_offset); |
2781 | 2770 |
2782 // Now test framing boundaries. | 2771 // Now test framing boundaries. |
2783 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetRstStreamFrameSize(); | 2772 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetRstStreamFrameSize(); |
2784 ++i) { | 2773 ++i) { |
2785 string expected_error; | 2774 string expected_error; |
2786 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) { | 2775 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) { |
2787 expected_error = "Unable to read stream_id."; | 2776 expected_error = "Unable to read stream_id."; |
2788 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize + | 2777 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize + |
2789 kQuicMaxStreamOffsetSize) { | 2778 kQuicMaxStreamOffsetSize) { |
2790 expected_error = "Unable to read rst stream sent byte offset."; | 2779 expected_error = "Unable to read rst stream sent byte offset."; |
2791 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize + | 2780 } else if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize + |
2792 kQuicMaxStreamOffsetSize + kQuicErrorCodeSize) { | 2781 kQuicMaxStreamOffsetSize + kQuicErrorCodeSize) { |
2793 expected_error = "Unable to read rst stream error code."; | 2782 expected_error = "Unable to read rst stream error code."; |
2794 } | 2783 } |
2795 CheckProcessingFails( | 2784 CheckProcessingFails( |
2796 packet, | 2785 packet, |
2797 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 2786 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
2798 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER), | 2787 !kIncludePathId, !kIncludeDiversificationNonce, |
| 2788 PACKET_6BYTE_PACKET_NUMBER), |
2799 expected_error, QUIC_INVALID_RST_STREAM_DATA); | 2789 expected_error, QUIC_INVALID_RST_STREAM_DATA); |
2800 } | 2790 } |
2801 } | 2791 } |
2802 | 2792 |
2803 TEST_P(QuicFramerTest, ConnectionCloseFrame) { | 2793 TEST_P(QuicFramerTest, ConnectionCloseFrame) { |
2804 // clang-format off | 2794 // clang-format off |
2805 unsigned char packet[] = { | 2795 unsigned char packet[] = { |
2806 // public flags (8 byte connection_id) | 2796 // public flags (8 byte connection_id) |
2807 0x3C, | 2797 0x38, |
2808 // connection_id | 2798 // connection_id |
2809 0x10, 0x32, 0x54, 0x76, | 2799 0x10, 0x32, 0x54, 0x76, |
2810 0x98, 0xBA, 0xDC, 0xFE, | 2800 0x98, 0xBA, 0xDC, 0xFE, |
2811 // packet number | 2801 // packet number |
2812 0xBC, 0x9A, 0x78, 0x56, | 2802 0xBC, 0x9A, 0x78, 0x56, |
2813 0x34, 0x12, | 2803 0x34, 0x12, |
2814 // private flags | 2804 // private flags |
2815 0x00, | 2805 0x00, |
2816 | 2806 |
2817 // frame type (connection close frame) | 2807 // frame type (connection close frame) |
2818 0x02, | 2808 0x02, |
2819 // error code | 2809 // error code |
2820 0x11, 0x00, 0x00, 0x00, | 2810 0x11, 0x00, 0x00, 0x00, |
2821 | 2811 |
2822 // error details length | 2812 // error details length |
2823 0x0d, 0x00, | 2813 0x0d, 0x00, |
2824 // error details | 2814 // error details |
2825 'b', 'e', 'c', 'a', | 2815 'b', 'e', 'c', 'a', |
2826 'u', 's', 'e', ' ', | 2816 'u', 's', 'e', ' ', |
2827 'I', ' ', 'c', 'a', | 2817 'I', ' ', 'c', 'a', |
2828 'n', | 2818 'n', |
2829 }; | 2819 }; |
2830 // clang-format on | 2820 // clang-format on |
2831 | 2821 |
2832 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 2822 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
2833 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 2823 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
2834 | 2824 |
2835 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 2825 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
2836 ASSERT_TRUE(visitor_.header_.get()); | 2826 ASSERT_TRUE(visitor_.header_.get()); |
2837 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 2827 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 2828 !kIncludeDiversificationNonce)); |
2838 | 2829 |
2839 EXPECT_EQ(0u, visitor_.stream_frames_.size()); | 2830 EXPECT_EQ(0u, visitor_.stream_frames_.size()); |
2840 | 2831 |
2841 EXPECT_EQ(0x11, visitor_.connection_close_frame_.error_code); | 2832 EXPECT_EQ(0x11, visitor_.connection_close_frame_.error_code); |
2842 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); | 2833 EXPECT_EQ("because I can", visitor_.connection_close_frame_.error_details); |
2843 | 2834 |
2844 ASSERT_EQ(0u, visitor_.ack_frames_.size()); | 2835 ASSERT_EQ(0u, visitor_.ack_frames_.size()); |
2845 | 2836 |
2846 // Now test framing boundaries. | 2837 // Now test framing boundaries. |
2847 for (size_t i = kQuicFrameTypeSize; | 2838 for (size_t i = kQuicFrameTypeSize; |
2848 i < QuicFramer::GetMinConnectionCloseFrameSize(); ++i) { | 2839 i < QuicFramer::GetMinConnectionCloseFrameSize(); ++i) { |
2849 string expected_error; | 2840 string expected_error; |
2850 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) { | 2841 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) { |
2851 expected_error = "Unable to read connection close error code."; | 2842 expected_error = "Unable to read connection close error code."; |
2852 } else { | 2843 } else { |
2853 expected_error = "Unable to read connection close error details."; | 2844 expected_error = "Unable to read connection close error details."; |
2854 } | 2845 } |
2855 CheckProcessingFails( | 2846 CheckProcessingFails( |
2856 packet, | 2847 packet, |
2857 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 2848 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
2858 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER), | 2849 !kIncludePathId, !kIncludeDiversificationNonce, |
| 2850 PACKET_6BYTE_PACKET_NUMBER), |
2859 expected_error, QUIC_INVALID_CONNECTION_CLOSE_DATA); | 2851 expected_error, QUIC_INVALID_CONNECTION_CLOSE_DATA); |
2860 } | 2852 } |
2861 } | 2853 } |
2862 | 2854 |
2863 TEST_P(QuicFramerTest, GoAwayFrame) { | 2855 TEST_P(QuicFramerTest, GoAwayFrame) { |
2864 // clang-format off | 2856 // clang-format off |
2865 unsigned char packet[] = { | 2857 unsigned char packet[] = { |
2866 // public flags (8 byte connection_id) | 2858 // public flags (8 byte connection_id) |
2867 0x3C, | 2859 0x38, |
2868 // connection_id | 2860 // connection_id |
2869 0x10, 0x32, 0x54, 0x76, | 2861 0x10, 0x32, 0x54, 0x76, |
2870 0x98, 0xBA, 0xDC, 0xFE, | 2862 0x98, 0xBA, 0xDC, 0xFE, |
2871 // packet number | 2863 // packet number |
2872 0xBC, 0x9A, 0x78, 0x56, | 2864 0xBC, 0x9A, 0x78, 0x56, |
2873 0x34, 0x12, | 2865 0x34, 0x12, |
2874 // private flags | 2866 // private flags |
2875 0x00, | 2867 0x00, |
2876 | 2868 |
2877 // frame type (go away frame) | 2869 // frame type (go away frame) |
(...skipping 10 matching lines...) Expand all Loading... |
2888 'I', ' ', 'c', 'a', | 2880 'I', ' ', 'c', 'a', |
2889 'n', | 2881 'n', |
2890 }; | 2882 }; |
2891 // clang-format on | 2883 // clang-format on |
2892 | 2884 |
2893 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 2885 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
2894 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 2886 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
2895 | 2887 |
2896 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 2888 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
2897 ASSERT_TRUE(visitor_.header_.get()); | 2889 ASSERT_TRUE(visitor_.header_.get()); |
2898 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 2890 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 2891 !kIncludeDiversificationNonce)); |
2899 | 2892 |
2900 EXPECT_EQ(kStreamId, visitor_.goaway_frame_.last_good_stream_id); | 2893 EXPECT_EQ(kStreamId, visitor_.goaway_frame_.last_good_stream_id); |
2901 EXPECT_EQ(0x9, visitor_.goaway_frame_.error_code); | 2894 EXPECT_EQ(0x9, visitor_.goaway_frame_.error_code); |
2902 EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase); | 2895 EXPECT_EQ("because I can", visitor_.goaway_frame_.reason_phrase); |
2903 | 2896 |
2904 const size_t reason_size = arraysize("because I can") - 1; | 2897 const size_t reason_size = arraysize("because I can") - 1; |
2905 // Now test framing boundaries. | 2898 // Now test framing boundaries. |
2906 for (size_t i = kQuicFrameTypeSize; | 2899 for (size_t i = kQuicFrameTypeSize; |
2907 i < QuicFramer::GetMinGoAwayFrameSize() + reason_size; ++i) { | 2900 i < QuicFramer::GetMinGoAwayFrameSize() + reason_size; ++i) { |
2908 string expected_error; | 2901 string expected_error; |
2909 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) { | 2902 if (i < kQuicFrameTypeSize + kQuicErrorCodeSize) { |
2910 expected_error = "Unable to read go away error code."; | 2903 expected_error = "Unable to read go away error code."; |
2911 } else if (i < | 2904 } else if (i < |
2912 kQuicFrameTypeSize + kQuicErrorCodeSize + kQuicMaxStreamIdSize) { | 2905 kQuicFrameTypeSize + kQuicErrorCodeSize + kQuicMaxStreamIdSize) { |
2913 expected_error = "Unable to read last good stream id."; | 2906 expected_error = "Unable to read last good stream id."; |
2914 } else { | 2907 } else { |
2915 expected_error = "Unable to read goaway reason."; | 2908 expected_error = "Unable to read goaway reason."; |
2916 } | 2909 } |
2917 CheckProcessingFails( | 2910 CheckProcessingFails( |
2918 packet, | 2911 packet, |
2919 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 2912 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
2920 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER), | 2913 !kIncludePathId, !kIncludeDiversificationNonce, |
| 2914 PACKET_6BYTE_PACKET_NUMBER), |
2921 expected_error, QUIC_INVALID_GOAWAY_DATA); | 2915 expected_error, QUIC_INVALID_GOAWAY_DATA); |
2922 } | 2916 } |
2923 } | 2917 } |
2924 | 2918 |
2925 TEST_P(QuicFramerTest, WindowUpdateFrame) { | 2919 TEST_P(QuicFramerTest, WindowUpdateFrame) { |
2926 // clang-format off | 2920 // clang-format off |
2927 unsigned char packet[] = { | 2921 unsigned char packet[] = { |
2928 // public flags (8 byte connection_id) | 2922 // public flags (8 byte connection_id) |
2929 0x3C, | 2923 0x38, |
2930 // connection_id | 2924 // connection_id |
2931 0x10, 0x32, 0x54, 0x76, | 2925 0x10, 0x32, 0x54, 0x76, |
2932 0x98, 0xBA, 0xDC, 0xFE, | 2926 0x98, 0xBA, 0xDC, 0xFE, |
2933 // packet number | 2927 // packet number |
2934 0xBC, 0x9A, 0x78, 0x56, | 2928 0xBC, 0x9A, 0x78, 0x56, |
2935 0x34, 0x12, | 2929 0x34, 0x12, |
2936 // private flags | 2930 // private flags |
2937 0x00, | 2931 0x00, |
2938 | 2932 |
2939 // frame type (window update frame) | 2933 // frame type (window update frame) |
2940 0x04, | 2934 0x04, |
2941 // stream id | 2935 // stream id |
2942 0x04, 0x03, 0x02, 0x01, | 2936 0x04, 0x03, 0x02, 0x01, |
2943 // byte offset | 2937 // byte offset |
2944 0x54, 0x76, 0x10, 0x32, | 2938 0x54, 0x76, 0x10, 0x32, |
2945 0xDC, 0xFE, 0x98, 0xBA, | 2939 0xDC, 0xFE, 0x98, 0xBA, |
2946 }; | 2940 }; |
2947 // clang-format on | 2941 // clang-format on |
2948 | 2942 |
2949 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 2943 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
2950 | 2944 |
2951 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 2945 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
2952 | 2946 |
2953 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 2947 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
2954 ASSERT_TRUE(visitor_.header_.get()); | 2948 ASSERT_TRUE(visitor_.header_.get()); |
2955 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 2949 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 2950 !kIncludeDiversificationNonce)); |
2956 | 2951 |
2957 EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id); | 2952 EXPECT_EQ(kStreamId, visitor_.window_update_frame_.stream_id); |
2958 EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset); | 2953 EXPECT_EQ(kStreamOffset, visitor_.window_update_frame_.byte_offset); |
2959 | 2954 |
2960 // Now test framing boundaries. | 2955 // Now test framing boundaries. |
2961 for (size_t i = kQuicFrameTypeSize; | 2956 for (size_t i = kQuicFrameTypeSize; |
2962 i < QuicFramer::GetWindowUpdateFrameSize(); ++i) { | 2957 i < QuicFramer::GetWindowUpdateFrameSize(); ++i) { |
2963 string expected_error; | 2958 string expected_error; |
2964 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) { | 2959 if (i < kQuicFrameTypeSize + kQuicMaxStreamIdSize) { |
2965 expected_error = "Unable to read stream_id."; | 2960 expected_error = "Unable to read stream_id."; |
2966 } else { | 2961 } else { |
2967 expected_error = "Unable to read window byte_offset."; | 2962 expected_error = "Unable to read window byte_offset."; |
2968 } | 2963 } |
2969 CheckProcessingFails( | 2964 CheckProcessingFails( |
2970 packet, | 2965 packet, |
2971 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 2966 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
2972 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER), | 2967 !kIncludePathId, !kIncludeDiversificationNonce, |
| 2968 PACKET_6BYTE_PACKET_NUMBER), |
2973 expected_error, QUIC_INVALID_WINDOW_UPDATE_DATA); | 2969 expected_error, QUIC_INVALID_WINDOW_UPDATE_DATA); |
2974 } | 2970 } |
2975 } | 2971 } |
2976 | 2972 |
2977 TEST_P(QuicFramerTest, BlockedFrame) { | 2973 TEST_P(QuicFramerTest, BlockedFrame) { |
2978 // clang-format off | 2974 // clang-format off |
2979 unsigned char packet[] = { | 2975 unsigned char packet[] = { |
2980 // public flags (8 byte connection_id) | 2976 // public flags (8 byte connection_id) |
2981 0x3C, | 2977 0x38, |
2982 // connection_id | 2978 // connection_id |
2983 0x10, 0x32, 0x54, 0x76, | 2979 0x10, 0x32, 0x54, 0x76, |
2984 0x98, 0xBA, 0xDC, 0xFE, | 2980 0x98, 0xBA, 0xDC, 0xFE, |
2985 // packet number | 2981 // packet number |
2986 0xBC, 0x9A, 0x78, 0x56, | 2982 0xBC, 0x9A, 0x78, 0x56, |
2987 0x34, 0x12, | 2983 0x34, 0x12, |
2988 // private flags | 2984 // private flags |
2989 0x00, | 2985 0x00, |
2990 | 2986 |
2991 // frame type (blocked frame) | 2987 // frame type (blocked frame) |
2992 0x05, | 2988 0x05, |
2993 // stream id | 2989 // stream id |
2994 0x04, 0x03, 0x02, 0x01, | 2990 0x04, 0x03, 0x02, 0x01, |
2995 }; | 2991 }; |
2996 // clang-format on | 2992 // clang-format on |
2997 | 2993 |
2998 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 2994 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
2999 | 2995 |
3000 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 2996 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
3001 | 2997 |
3002 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 2998 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
3003 ASSERT_TRUE(visitor_.header_.get()); | 2999 ASSERT_TRUE(visitor_.header_.get()); |
3004 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 3000 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 3001 !kIncludeDiversificationNonce)); |
3005 | 3002 |
3006 EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id); | 3003 EXPECT_EQ(kStreamId, visitor_.blocked_frame_.stream_id); |
3007 | 3004 |
3008 // Now test framing boundaries. | 3005 // Now test framing boundaries. |
3009 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetBlockedFrameSize(); | 3006 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetBlockedFrameSize(); |
3010 ++i) { | 3007 ++i) { |
3011 string expected_error = "Unable to read stream_id."; | 3008 string expected_error = "Unable to read stream_id."; |
3012 CheckProcessingFails( | 3009 CheckProcessingFails( |
3013 packet, | 3010 packet, |
3014 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 3011 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
3015 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER), | 3012 !kIncludePathId, !kIncludeDiversificationNonce, |
| 3013 PACKET_6BYTE_PACKET_NUMBER), |
3016 expected_error, QUIC_INVALID_BLOCKED_DATA); | 3014 expected_error, QUIC_INVALID_BLOCKED_DATA); |
3017 } | 3015 } |
3018 } | 3016 } |
3019 | 3017 |
3020 TEST_P(QuicFramerTest, PingFrame) { | 3018 TEST_P(QuicFramerTest, PingFrame) { |
3021 // clang-format off | 3019 // clang-format off |
3022 unsigned char packet[] = { | 3020 unsigned char packet[] = { |
3023 // public flags (8 byte connection_id) | 3021 // public flags (8 byte connection_id) |
3024 0x3C, | 3022 0x38, |
3025 // connection_id | 3023 // connection_id |
3026 0x10, 0x32, 0x54, 0x76, | 3024 0x10, 0x32, 0x54, 0x76, |
3027 0x98, 0xBA, 0xDC, 0xFE, | 3025 0x98, 0xBA, 0xDC, 0xFE, |
3028 // packet number | 3026 // packet number |
3029 0xBC, 0x9A, 0x78, 0x56, | 3027 0xBC, 0x9A, 0x78, 0x56, |
3030 0x34, 0x12, | 3028 0x34, 0x12, |
3031 // private flags | 3029 // private flags |
3032 0x00, | 3030 0x00, |
3033 | 3031 |
3034 // frame type (ping frame) | 3032 // frame type (ping frame) |
3035 0x07, | 3033 0x07, |
3036 }; | 3034 }; |
3037 // clang-format on | 3035 // clang-format on |
3038 | 3036 |
3039 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); | 3037 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); |
3040 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 3038 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
3041 | 3039 |
3042 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); | 3040 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); |
3043 ASSERT_TRUE(visitor_.header_.get()); | 3041 ASSERT_TRUE(visitor_.header_.get()); |
3044 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId)); | 3042 EXPECT_TRUE(CheckDecryption(encrypted, !kIncludeVersion, !kIncludePathId, |
| 3043 !kIncludeDiversificationNonce)); |
3045 | 3044 |
3046 EXPECT_EQ(1u, visitor_.ping_frames_.size()); | 3045 EXPECT_EQ(1u, visitor_.ping_frames_.size()); |
3047 | 3046 |
3048 // No need to check the PING frame boundaries because it has no payload. | 3047 // No need to check the PING frame boundaries because it has no payload. |
3049 } | 3048 } |
3050 | 3049 |
3051 TEST_P(QuicFramerTest, PathCloseFrame) { | 3050 TEST_P(QuicFramerTest, PathCloseFrame) { |
3052 // clang-format off | 3051 // clang-format off |
3053 unsigned char packet[] = { | 3052 unsigned char packet[] = { |
3054 // public flags (version) | 3053 // public flags (version) |
3055 0x7C, | 3054 0x78, |
3056 // connection_id | 3055 // connection_id |
3057 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 3056 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
3058 // path_id | 3057 // path_id |
3059 0x00, | 3058 0x00, |
3060 // packet number | 3059 // packet number |
3061 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 3060 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
3062 // private flags | 3061 // private flags |
3063 0x00, | 3062 0x00, |
3064 | 3063 |
3065 // frame type (path_close_frame) | 3064 // frame type (path_close_frame) |
(...skipping 14 matching lines...) Expand all Loading... |
3080 // Now test framing boundaries. | 3079 // Now test framing boundaries. |
3081 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetPathCloseFrameSize(); | 3080 for (size_t i = kQuicFrameTypeSize; i < QuicFramer::GetPathCloseFrameSize(); |
3082 ++i) { | 3081 ++i) { |
3083 string expected_error; | 3082 string expected_error; |
3084 if (i < kQuicFrameTypeSize + kQuicPathIdSize) { | 3083 if (i < kQuicFrameTypeSize + kQuicPathIdSize) { |
3085 expected_error = "Unable to read path_id."; | 3084 expected_error = "Unable to read path_id."; |
3086 } | 3085 } |
3087 CheckProcessingFails( | 3086 CheckProcessingFails( |
3088 packet, | 3087 packet, |
3089 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 3088 i + GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, |
3090 kIncludePathId, PACKET_6BYTE_PACKET_NUMBER), | 3089 kIncludePathId, !kIncludeDiversificationNonce, |
| 3090 PACKET_6BYTE_PACKET_NUMBER), |
3091 expected_error, QUIC_INVALID_PATH_CLOSE_DATA); | 3091 expected_error, QUIC_INVALID_PATH_CLOSE_DATA); |
3092 } | 3092 } |
3093 } | 3093 } |
3094 | 3094 |
3095 TEST_P(QuicFramerTest, PublicResetPacket) { | 3095 TEST_P(QuicFramerTest, PublicResetPacket) { |
3096 // clang-format off | 3096 // clang-format off |
3097 unsigned char packet[] = { | 3097 unsigned char packet[] = { |
3098 // public flags (public reset, 8 byte connection_id) | 3098 // public flags (public reset, 8 byte connection_id) |
3099 0x0E, | 3099 0x0A, |
3100 // connection_id | 3100 // connection_id |
3101 0x10, 0x32, 0x54, 0x76, | 3101 0x10, 0x32, 0x54, 0x76, |
3102 0x98, 0xBA, 0xDC, 0xFE, | 3102 0x98, 0xBA, 0xDC, 0xFE, |
3103 // message tag (kPRST) | 3103 // message tag (kPRST) |
3104 'P', 'R', 'S', 'T', | 3104 'P', 'R', 'S', 'T', |
3105 // num_entries (2) + padding | 3105 // num_entries (2) + padding |
3106 0x02, 0x00, 0x00, 0x00, | 3106 0x02, 0x00, 0x00, 0x00, |
3107 // tag kRNON | 3107 // tag kRNON |
3108 'R', 'N', 'O', 'N', | 3108 'R', 'N', 'O', 'N', |
3109 // end offset 8 | 3109 // end offset 8 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3151 CheckProcessingFails(packet, i, expected_error, | 3151 CheckProcessingFails(packet, i, expected_error, |
3152 QUIC_INVALID_PUBLIC_RST_PACKET); | 3152 QUIC_INVALID_PUBLIC_RST_PACKET); |
3153 } | 3153 } |
3154 } | 3154 } |
3155 } | 3155 } |
3156 | 3156 |
3157 TEST_P(QuicFramerTest, PublicResetPacketWithTrailingJunk) { | 3157 TEST_P(QuicFramerTest, PublicResetPacketWithTrailingJunk) { |
3158 // clang-format off | 3158 // clang-format off |
3159 unsigned char packet[] = { | 3159 unsigned char packet[] = { |
3160 // public flags (public reset, 8 byte connection_id) | 3160 // public flags (public reset, 8 byte connection_id) |
3161 0x0E, | 3161 0x0A, |
3162 // connection_id | 3162 // connection_id |
3163 0x10, 0x32, 0x54, 0x76, | 3163 0x10, 0x32, 0x54, 0x76, |
3164 0x98, 0xBA, 0xDC, 0xFE, | 3164 0x98, 0xBA, 0xDC, 0xFE, |
3165 // message tag (kPRST) | 3165 // message tag (kPRST) |
3166 'P', 'R', 'S', 'T', | 3166 'P', 'R', 'S', 'T', |
3167 // num_entries (2) + padding | 3167 // num_entries (2) + padding |
3168 0x02, 0x00, 0x00, 0x00, | 3168 0x02, 0x00, 0x00, 0x00, |
3169 // tag kRNON | 3169 // tag kRNON |
3170 'R', 'N', 'O', 'N', | 3170 'R', 'N', 'O', 'N', |
3171 // end offset 8 | 3171 // end offset 8 |
(...skipping 15 matching lines...) Expand all Loading... |
3187 | 3187 |
3188 string expected_error = "Unable to read reset message."; | 3188 string expected_error = "Unable to read reset message."; |
3189 CheckProcessingFails(packet, arraysize(packet), expected_error, | 3189 CheckProcessingFails(packet, arraysize(packet), expected_error, |
3190 QUIC_INVALID_PUBLIC_RST_PACKET); | 3190 QUIC_INVALID_PUBLIC_RST_PACKET); |
3191 } | 3191 } |
3192 | 3192 |
3193 TEST_P(QuicFramerTest, PublicResetPacketWithClientAddress) { | 3193 TEST_P(QuicFramerTest, PublicResetPacketWithClientAddress) { |
3194 // clang-format off | 3194 // clang-format off |
3195 unsigned char packet[] = { | 3195 unsigned char packet[] = { |
3196 // public flags (public reset, 8 byte connection_id) | 3196 // public flags (public reset, 8 byte connection_id) |
3197 0x0E, | 3197 0x0A, |
3198 // connection_id | 3198 // connection_id |
3199 0x10, 0x32, 0x54, 0x76, | 3199 0x10, 0x32, 0x54, 0x76, |
3200 0x98, 0xBA, 0xDC, 0xFE, | 3200 0x98, 0xBA, 0xDC, 0xFE, |
3201 // message tag (kPRST) | 3201 // message tag (kPRST) |
3202 'P', 'R', 'S', 'T', | 3202 'P', 'R', 'S', 'T', |
3203 // num_entries (3) + padding | 3203 // num_entries (3) + padding |
3204 0x03, 0x00, 0x00, 0x00, | 3204 0x03, 0x00, 0x00, 0x00, |
3205 // tag kRNON | 3205 // tag kRNON |
3206 'R', 'N', 'O', 'N', | 3206 'R', 'N', 'O', 'N', |
3207 // end offset 8 | 3207 // end offset 8 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3258 CheckProcessingFails(packet, i, expected_error, | 3258 CheckProcessingFails(packet, i, expected_error, |
3259 QUIC_INVALID_PUBLIC_RST_PACKET); | 3259 QUIC_INVALID_PUBLIC_RST_PACKET); |
3260 } | 3260 } |
3261 } | 3261 } |
3262 } | 3262 } |
3263 | 3263 |
3264 TEST_P(QuicFramerTest, VersionNegotiationPacket) { | 3264 TEST_P(QuicFramerTest, VersionNegotiationPacket) { |
3265 // clang-format off | 3265 // clang-format off |
3266 unsigned char packet[] = { | 3266 unsigned char packet[] = { |
3267 // public flags (version, 8 byte connection_id) | 3267 // public flags (version, 8 byte connection_id) |
3268 0x3D, | 3268 0x39, |
3269 // connection_id | 3269 // connection_id |
3270 0x10, 0x32, 0x54, 0x76, | 3270 0x10, 0x32, 0x54, 0x76, |
3271 0x98, 0xBA, 0xDC, 0xFE, | 3271 0x98, 0xBA, 0xDC, 0xFE, |
3272 // version tag | 3272 // version tag |
3273 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | 3273 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), |
3274 'Q', '2', '.', '0', | 3274 'Q', '2', '.', '0', |
3275 }; | 3275 }; |
3276 // clang-format on | 3276 // clang-format on |
3277 | 3277 |
3278 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); | 3278 QuicFramerPeer::SetPerspective(&framer_, Perspective::IS_CLIENT); |
(...skipping 17 matching lines...) Expand all Loading... |
3296 error_code = QUIC_INVALID_VERSION_NEGOTIATION_PACKET; | 3296 error_code = QUIC_INVALID_VERSION_NEGOTIATION_PACKET; |
3297 } | 3297 } |
3298 CheckProcessingFails(packet, i, expected_error, error_code); | 3298 CheckProcessingFails(packet, i, expected_error, error_code); |
3299 } | 3299 } |
3300 } | 3300 } |
3301 | 3301 |
3302 TEST_P(QuicFramerTest, DropFecPacket) { | 3302 TEST_P(QuicFramerTest, DropFecPacket) { |
3303 // clang-format off | 3303 // clang-format off |
3304 unsigned char packet[] = { | 3304 unsigned char packet[] = { |
3305 // public flags (8 byte connection_id) | 3305 // public flags (8 byte connection_id) |
3306 0x3C, | 3306 0x38, |
3307 // connection_id | 3307 // connection_id |
3308 0x10, 0x32, 0x54, 0x76, | 3308 0x10, 0x32, 0x54, 0x76, |
3309 0x98, 0xBA, 0xDC, 0xFE, | 3309 0x98, 0xBA, 0xDC, 0xFE, |
3310 // packet number | 3310 // packet number |
3311 0xBC, 0x9A, 0x78, 0x56, | 3311 0xBC, 0x9A, 0x78, 0x56, |
3312 0x34, 0x12, | 3312 0x34, 0x12, |
3313 // private flags (fec group & FEC) | 3313 // private flags (fec group & FEC) |
3314 0x06, | 3314 0x06, |
3315 // first fec protected packet offset | 3315 // first fec protected packet offset |
3316 0x01, | 3316 0x01, |
(...skipping 28 matching lines...) Expand all Loading... |
3345 header.fec_group = 0; | 3345 header.fec_group = 0; |
3346 | 3346 |
3347 QuicPaddingFrame padding_frame; | 3347 QuicPaddingFrame padding_frame; |
3348 | 3348 |
3349 QuicFrames frames; | 3349 QuicFrames frames; |
3350 frames.push_back(QuicFrame(padding_frame)); | 3350 frames.push_back(QuicFrame(padding_frame)); |
3351 | 3351 |
3352 // clang-format off | 3352 // clang-format off |
3353 unsigned char packet[kMaxPacketSize] = { | 3353 unsigned char packet[kMaxPacketSize] = { |
3354 // public flags (8 byte connection_id) | 3354 // public flags (8 byte connection_id) |
3355 0x3C, | 3355 static_cast<unsigned char>( |
| 3356 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
3356 // connection_id | 3357 // connection_id |
3357 0x10, 0x32, 0x54, 0x76, | 3358 0x10, 0x32, 0x54, 0x76, |
3358 0x98, 0xBA, 0xDC, 0xFE, | 3359 0x98, 0xBA, 0xDC, 0xFE, |
3359 // packet number | 3360 // packet number |
3360 0xBC, 0x9A, 0x78, 0x56, | 3361 0xBC, 0x9A, 0x78, 0x56, |
3361 0x34, 0x12, | 3362 0x34, 0x12, |
3362 // private flags | 3363 // private flags |
3363 0x00, | 3364 0x00, |
3364 | 3365 |
3365 // frame type (padding frame) | 3366 // frame type (padding frame) |
3366 0x00, | 3367 0x00, |
3367 0x00, 0x00, 0x00, 0x00 | 3368 0x00, 0x00, 0x00, 0x00 |
3368 }; | 3369 }; |
3369 // clang-format on | 3370 // clang-format on |
3370 | 3371 |
3371 uint64_t header_size = | 3372 uint64_t header_size = GetPacketHeaderSize( |
3372 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 3373 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, !kIncludePathId, |
3373 !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER); | 3374 !kIncludeDiversificationNonce, PACKET_6BYTE_PACKET_NUMBER); |
3374 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); | 3375 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); |
3375 | 3376 |
3376 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | 3377 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
3377 ASSERT_TRUE(data != nullptr); | 3378 ASSERT_TRUE(data != nullptr); |
3378 | 3379 |
3379 test::CompareCharArraysWithHexError("constructed packet", data->data(), | 3380 test::CompareCharArraysWithHexError("constructed packet", data->data(), |
3380 data->length(), AsChars(packet), | 3381 data->length(), AsChars(packet), |
3381 arraysize(packet)); | 3382 arraysize(packet)); |
3382 } | 3383 } |
3383 | 3384 |
3384 TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) { | 3385 TEST_P(QuicFramerTest, Build4ByteSequenceNumberPaddingFramePacket) { |
3385 QuicPacketHeader header; | 3386 QuicPacketHeader header; |
3386 header.public_header.connection_id = kConnectionId; | 3387 header.public_header.connection_id = kConnectionId; |
3387 header.public_header.reset_flag = false; | 3388 header.public_header.reset_flag = false; |
3388 header.public_header.version_flag = false; | 3389 header.public_header.version_flag = false; |
3389 header.fec_flag = false; | 3390 header.fec_flag = false; |
3390 header.entropy_flag = false; | 3391 header.entropy_flag = false; |
3391 header.public_header.packet_number_length = PACKET_4BYTE_PACKET_NUMBER; | 3392 header.public_header.packet_number_length = PACKET_4BYTE_PACKET_NUMBER; |
3392 header.packet_number = kPacketNumber; | 3393 header.packet_number = kPacketNumber; |
3393 header.fec_group = 0; | 3394 header.fec_group = 0; |
3394 | 3395 |
3395 QuicPaddingFrame padding_frame; | 3396 QuicPaddingFrame padding_frame; |
3396 | 3397 |
3397 QuicFrames frames; | 3398 QuicFrames frames; |
3398 frames.push_back(QuicFrame(padding_frame)); | 3399 frames.push_back(QuicFrame(padding_frame)); |
3399 | 3400 |
3400 // clang-format off | 3401 // clang-format off |
3401 unsigned char packet[kMaxPacketSize] = { | 3402 unsigned char packet[kMaxPacketSize] = { |
3402 // public flags (8 byte connection_id and 4 byte packet number) | 3403 // public flags (8 byte connection_id and 4 byte packet number) |
3403 0x2C, | 3404 static_cast<unsigned char>( |
| 3405 framer_.version() > QUIC_VERSION_32 ? 0x28 : 0x2C), |
3404 // connection_id | 3406 // connection_id |
3405 0x10, 0x32, 0x54, 0x76, | 3407 0x10, 0x32, 0x54, 0x76, |
3406 0x98, 0xBA, 0xDC, 0xFE, | 3408 0x98, 0xBA, 0xDC, 0xFE, |
3407 // packet number | 3409 // packet number |
3408 0xBC, 0x9A, 0x78, 0x56, | 3410 0xBC, 0x9A, 0x78, 0x56, |
3409 // private flags | 3411 // private flags |
3410 0x00, | 3412 0x00, |
3411 | 3413 |
3412 // frame type (padding frame) | 3414 // frame type (padding frame) |
3413 0x00, | 3415 0x00, |
3414 0x00, 0x00, 0x00, 0x00 | 3416 0x00, 0x00, 0x00, 0x00 |
3415 }; | 3417 }; |
3416 // clang-format on | 3418 // clang-format on |
3417 | 3419 |
3418 uint64_t header_size = | 3420 uint64_t header_size = GetPacketHeaderSize( |
3419 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 3421 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, !kIncludePathId, |
3420 !kIncludePathId, PACKET_4BYTE_PACKET_NUMBER); | 3422 !kIncludeDiversificationNonce, PACKET_4BYTE_PACKET_NUMBER); |
3421 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); | 3423 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); |
3422 | 3424 |
3423 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | 3425 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
3424 ASSERT_TRUE(data != nullptr); | 3426 ASSERT_TRUE(data != nullptr); |
3425 | 3427 |
3426 test::CompareCharArraysWithHexError("constructed packet", data->data(), | 3428 test::CompareCharArraysWithHexError("constructed packet", data->data(), |
3427 data->length(), AsChars(packet), | 3429 data->length(), AsChars(packet), |
3428 arraysize(packet)); | 3430 arraysize(packet)); |
3429 } | 3431 } |
3430 | 3432 |
3431 TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) { | 3433 TEST_P(QuicFramerTest, Build2ByteSequenceNumberPaddingFramePacket) { |
3432 QuicPacketHeader header; | 3434 QuicPacketHeader header; |
3433 header.public_header.connection_id = kConnectionId; | 3435 header.public_header.connection_id = kConnectionId; |
3434 header.public_header.reset_flag = false; | 3436 header.public_header.reset_flag = false; |
3435 header.public_header.version_flag = false; | 3437 header.public_header.version_flag = false; |
3436 header.fec_flag = false; | 3438 header.fec_flag = false; |
3437 header.entropy_flag = false; | 3439 header.entropy_flag = false; |
3438 header.public_header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER; | 3440 header.public_header.packet_number_length = PACKET_2BYTE_PACKET_NUMBER; |
3439 header.packet_number = kPacketNumber; | 3441 header.packet_number = kPacketNumber; |
3440 header.fec_group = 0; | 3442 header.fec_group = 0; |
3441 | 3443 |
3442 QuicPaddingFrame padding_frame; | 3444 QuicPaddingFrame padding_frame; |
3443 | 3445 |
3444 QuicFrames frames; | 3446 QuicFrames frames; |
3445 frames.push_back(QuicFrame(padding_frame)); | 3447 frames.push_back(QuicFrame(padding_frame)); |
3446 | 3448 |
3447 // clang-format off | 3449 // clang-format off |
3448 unsigned char packet[kMaxPacketSize] = { | 3450 unsigned char packet[kMaxPacketSize] = { |
3449 // public flags (8 byte connection_id and 2 byte packet number) | 3451 // public flags (8 byte connection_id and 2 byte packet number) |
3450 0x1C, | 3452 static_cast<unsigned char>( |
| 3453 framer_.version() > QUIC_VERSION_32 ? 0x18 : 0x1C), |
3451 // connection_id | 3454 // connection_id |
3452 0x10, 0x32, 0x54, 0x76, | 3455 0x10, 0x32, 0x54, 0x76, |
3453 0x98, 0xBA, 0xDC, 0xFE, | 3456 0x98, 0xBA, 0xDC, 0xFE, |
3454 // packet number | 3457 // packet number |
3455 0xBC, 0x9A, | 3458 0xBC, 0x9A, |
3456 // private flags | 3459 // private flags |
3457 0x00, | 3460 0x00, |
3458 | 3461 |
3459 // frame type (padding frame) | 3462 // frame type (padding frame) |
3460 0x00, | 3463 0x00, |
3461 0x00, 0x00, 0x00, 0x00 | 3464 0x00, 0x00, 0x00, 0x00 |
3462 }; | 3465 }; |
3463 // clang-format on | 3466 // clang-format on |
3464 | 3467 |
3465 uint64_t header_size = | 3468 uint64_t header_size = GetPacketHeaderSize( |
3466 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 3469 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, !kIncludePathId, |
3467 !kIncludePathId, PACKET_2BYTE_PACKET_NUMBER); | 3470 !kIncludeDiversificationNonce, PACKET_2BYTE_PACKET_NUMBER); |
3468 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); | 3471 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); |
3469 | 3472 |
3470 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | 3473 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
3471 ASSERT_TRUE(data != nullptr); | 3474 ASSERT_TRUE(data != nullptr); |
3472 | 3475 |
3473 test::CompareCharArraysWithHexError("constructed packet", data->data(), | 3476 test::CompareCharArraysWithHexError("constructed packet", data->data(), |
3474 data->length(), AsChars(packet), | 3477 data->length(), AsChars(packet), |
3475 arraysize(packet)); | 3478 arraysize(packet)); |
3476 } | 3479 } |
3477 | 3480 |
3478 TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) { | 3481 TEST_P(QuicFramerTest, Build1ByteSequenceNumberPaddingFramePacket) { |
3479 QuicPacketHeader header; | 3482 QuicPacketHeader header; |
3480 header.public_header.connection_id = kConnectionId; | 3483 header.public_header.connection_id = kConnectionId; |
3481 header.public_header.reset_flag = false; | 3484 header.public_header.reset_flag = false; |
3482 header.public_header.version_flag = false; | 3485 header.public_header.version_flag = false; |
3483 header.fec_flag = false; | 3486 header.fec_flag = false; |
3484 header.entropy_flag = false; | 3487 header.entropy_flag = false; |
3485 header.public_header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; | 3488 header.public_header.packet_number_length = PACKET_1BYTE_PACKET_NUMBER; |
3486 header.packet_number = kPacketNumber; | 3489 header.packet_number = kPacketNumber; |
3487 header.fec_group = 0; | 3490 header.fec_group = 0; |
3488 | 3491 |
3489 QuicPaddingFrame padding_frame; | 3492 QuicPaddingFrame padding_frame; |
3490 | 3493 |
3491 QuicFrames frames; | 3494 QuicFrames frames; |
3492 frames.push_back(QuicFrame(padding_frame)); | 3495 frames.push_back(QuicFrame(padding_frame)); |
3493 | 3496 |
3494 // clang-format off | 3497 // clang-format off |
3495 unsigned char packet[kMaxPacketSize] = { | 3498 unsigned char packet[kMaxPacketSize] = { |
3496 // public flags (8 byte connection_id and 1 byte packet number) | 3499 // public flags (8 byte connection_id and 1 byte packet number) |
3497 0x0C, | 3500 static_cast<unsigned char>( |
| 3501 framer_.version() > QUIC_VERSION_32 ? 0x08 : 0x0C), |
3498 // connection_id | 3502 // connection_id |
3499 0x10, 0x32, 0x54, 0x76, | 3503 0x10, 0x32, 0x54, 0x76, |
3500 0x98, 0xBA, 0xDC, 0xFE, | 3504 0x98, 0xBA, 0xDC, 0xFE, |
3501 // packet number | 3505 // packet number |
3502 0xBC, | 3506 0xBC, |
3503 // private flags | 3507 // private flags |
3504 0x00, | 3508 0x00, |
3505 | 3509 |
3506 // frame type (padding frame) | 3510 // frame type (padding frame) |
3507 0x00, | 3511 0x00, |
3508 0x00, 0x00, 0x00, 0x00 | 3512 0x00, 0x00, 0x00, 0x00 |
3509 }; | 3513 }; |
3510 // clang-format on | 3514 // clang-format on |
3511 | 3515 |
3512 uint64_t header_size = | 3516 uint64_t header_size = GetPacketHeaderSize( |
3513 GetPacketHeaderSize(PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, | 3517 PACKET_8BYTE_CONNECTION_ID, !kIncludeVersion, !kIncludePathId, |
3514 !kIncludePathId, PACKET_1BYTE_PACKET_NUMBER); | 3518 !kIncludeDiversificationNonce, PACKET_1BYTE_PACKET_NUMBER); |
3515 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); | 3519 memset(packet + header_size + 1, 0x00, kMaxPacketSize - header_size - 1); |
3516 | 3520 |
3517 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); | 3521 std::unique_ptr<QuicPacket> data(BuildDataPacket(header, frames)); |
3518 ASSERT_TRUE(data != nullptr); | 3522 ASSERT_TRUE(data != nullptr); |
3519 | 3523 |
3520 test::CompareCharArraysWithHexError("constructed packet", data->data(), | 3524 test::CompareCharArraysWithHexError("constructed packet", data->data(), |
3521 data->length(), AsChars(packet), | 3525 data->length(), AsChars(packet), |
3522 arraysize(packet)); | 3526 arraysize(packet)); |
3523 } | 3527 } |
3524 | 3528 |
3525 TEST_P(QuicFramerTest, BuildStreamFramePacket) { | 3529 TEST_P(QuicFramerTest, BuildStreamFramePacket) { |
3526 QuicPacketHeader header; | 3530 QuicPacketHeader header; |
3527 header.public_header.connection_id = kConnectionId; | 3531 header.public_header.connection_id = kConnectionId; |
3528 header.public_header.reset_flag = false; | 3532 header.public_header.reset_flag = false; |
3529 header.public_header.version_flag = false; | 3533 header.public_header.version_flag = false; |
3530 header.fec_flag = false; | 3534 header.fec_flag = false; |
3531 header.entropy_flag = true; | 3535 header.entropy_flag = true; |
3532 header.packet_number = kPacketNumber; | 3536 header.packet_number = kPacketNumber; |
3533 header.fec_group = 0; | 3537 header.fec_group = 0; |
3534 | 3538 |
3535 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, | 3539 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
3536 StringPiece("hello world!")); | 3540 StringPiece("hello world!")); |
3537 | 3541 |
3538 QuicFrames frames; | 3542 QuicFrames frames; |
3539 frames.push_back(QuicFrame(&stream_frame)); | 3543 frames.push_back(QuicFrame(&stream_frame)); |
3540 | 3544 |
3541 // clang-format off | 3545 // clang-format off |
3542 unsigned char packet[] = { | 3546 unsigned char packet[] = { |
3543 // public flags (8 byte connection_id) | 3547 // public flags (8 byte connection_id) |
3544 0x3C, | 3548 static_cast<unsigned char>( |
| 3549 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
3545 // connection_id | 3550 // connection_id |
3546 0x10, 0x32, 0x54, 0x76, | 3551 0x10, 0x32, 0x54, 0x76, |
3547 0x98, 0xBA, 0xDC, 0xFE, | 3552 0x98, 0xBA, 0xDC, 0xFE, |
3548 // packet number | 3553 // packet number |
3549 0xBC, 0x9A, 0x78, 0x56, | 3554 0xBC, 0x9A, 0x78, 0x56, |
3550 0x34, 0x12, | 3555 0x34, 0x12, |
3551 // private flags (entropy) | 3556 // private flags (entropy) |
3552 0x01, | 3557 0x01, |
3553 | 3558 |
3554 // frame type (stream frame with fin and no length) | 3559 // frame type (stream frame with fin and no length) |
(...skipping 30 matching lines...) Expand all Loading... |
3585 | 3590 |
3586 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, | 3591 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
3587 StringPiece("hello world!")); | 3592 StringPiece("hello world!")); |
3588 | 3593 |
3589 QuicFrames frames; | 3594 QuicFrames frames; |
3590 frames.push_back(QuicFrame(&stream_frame)); | 3595 frames.push_back(QuicFrame(&stream_frame)); |
3591 | 3596 |
3592 // clang-format off | 3597 // clang-format off |
3593 unsigned char packet[] = { | 3598 unsigned char packet[] = { |
3594 // public flags (version, 8 byte connection_id) | 3599 // public flags (version, 8 byte connection_id) |
3595 0x3D, | 3600 static_cast<unsigned char>( |
| 3601 framer_.version() > QUIC_VERSION_32 ? 0x39 : 0x3D), |
3596 // connection_id | 3602 // connection_id |
3597 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 3603 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
3598 // version tag | 3604 // version tag |
3599 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | 3605 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), |
3600 // packet number | 3606 // packet number |
3601 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 3607 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
3602 // private flags (entropy) | 3608 // private flags (entropy) |
3603 0x01, | 3609 0x01, |
3604 | 3610 |
3605 // frame type (stream frame with fin and no length) | 3611 // frame type (stream frame with fin and no length) |
(...skipping 30 matching lines...) Expand all Loading... |
3636 | 3642 |
3637 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, | 3643 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
3638 StringPiece("hello world!")); | 3644 StringPiece("hello world!")); |
3639 | 3645 |
3640 QuicFrames frames; | 3646 QuicFrames frames; |
3641 frames.push_back(QuicFrame(&stream_frame)); | 3647 frames.push_back(QuicFrame(&stream_frame)); |
3642 | 3648 |
3643 // clang-format off | 3649 // clang-format off |
3644 unsigned char packet[] = { | 3650 unsigned char packet[] = { |
3645 // public flags (8 byte connection_id) | 3651 // public flags (8 byte connection_id) |
3646 0x7C, | 3652 static_cast<unsigned char>( |
| 3653 framer_.version() > QUIC_VERSION_32 ? 0x78 : 0x7C), |
3647 // connection_id | 3654 // connection_id |
3648 0x10, 0x32, 0x54, 0x76, | 3655 0x10, 0x32, 0x54, 0x76, |
3649 0x98, 0xBA, 0xDC, 0xFE, | 3656 0x98, 0xBA, 0xDC, 0xFE, |
3650 // path_id | 3657 // path_id |
3651 0x42, | 3658 0x42, |
3652 // packet number | 3659 // packet number |
3653 0xBC, 0x9A, 0x78, 0x56, | 3660 0xBC, 0x9A, 0x78, 0x56, |
3654 0x34, 0x12, | 3661 0x34, 0x12, |
3655 // private flags (entropy) | 3662 // private flags (entropy) |
3656 0x01, | 3663 0x01, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3691 | 3698 |
3692 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, | 3699 QuicStreamFrame stream_frame(kStreamId, true, kStreamOffset, |
3693 StringPiece("hello world!")); | 3700 StringPiece("hello world!")); |
3694 | 3701 |
3695 QuicFrames frames; | 3702 QuicFrames frames; |
3696 frames.push_back(QuicFrame(&stream_frame)); | 3703 frames.push_back(QuicFrame(&stream_frame)); |
3697 | 3704 |
3698 // clang-format off | 3705 // clang-format off |
3699 unsigned char packet[] = { | 3706 unsigned char packet[] = { |
3700 // public flags (8 byte connection_id) | 3707 // public flags (8 byte connection_id) |
3701 0x7D, | 3708 static_cast<unsigned char>( |
| 3709 framer_.version() > QUIC_VERSION_32 ? 0x79 : 0x7D), |
3702 // connection_id | 3710 // connection_id |
3703 0x10, 0x32, 0x54, 0x76, | 3711 0x10, 0x32, 0x54, 0x76, |
3704 0x98, 0xBA, 0xDC, 0xFE, | 3712 0x98, 0xBA, 0xDC, 0xFE, |
3705 // version tag | 3713 // version tag |
3706 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | 3714 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), |
3707 // path_id | 3715 // path_id |
3708 0x42, | 3716 0x42, |
3709 // packet number | 3717 // packet number |
3710 0xBC, 0x9A, 0x78, 0x56, | 3718 0xBC, 0x9A, 0x78, 0x56, |
3711 0x34, 0x12, | 3719 0x34, 0x12, |
(...skipping 20 matching lines...) Expand all Loading... |
3732 | 3740 |
3733 test::CompareCharArraysWithHexError("constructed packet", data->data(), | 3741 test::CompareCharArraysWithHexError("constructed packet", data->data(), |
3734 data->length(), AsChars(packet), | 3742 data->length(), AsChars(packet), |
3735 arraysize(packet)); | 3743 arraysize(packet)); |
3736 } | 3744 } |
3737 | 3745 |
3738 TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) { | 3746 TEST_P(QuicFramerTest, BuildVersionNegotiationPacket) { |
3739 // clang-format off | 3747 // clang-format off |
3740 unsigned char packet[] = { | 3748 unsigned char packet[] = { |
3741 // public flags (version, 8 byte connection_id) | 3749 // public flags (version, 8 byte connection_id) |
3742 0x0D, | 3750 0x09, |
3743 // connection_id | 3751 // connection_id |
3744 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 3752 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
3745 // version tag | 3753 // version tag |
3746 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), | 3754 'Q', '0', GetQuicVersionDigitTens(), GetQuicVersionDigitOnes(), |
3747 }; | 3755 }; |
3748 // clang-format on | 3756 // clang-format on |
3749 | 3757 |
3750 QuicConnectionId connection_id = kConnectionId; | 3758 QuicConnectionId connection_id = kConnectionId; |
3751 std::unique_ptr<QuicEncryptedPacket> data( | 3759 std::unique_ptr<QuicEncryptedPacket> data( |
3752 framer_.BuildVersionNegotiationPacket(connection_id, | 3760 framer_.BuildVersionNegotiationPacket(connection_id, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3804 // 0 more missing packets in range. | 3812 // 0 more missing packets in range. |
3805 0x00, | 3813 0x00, |
3806 // 0 revived packets. | 3814 // 0 revived packets. |
3807 0x00, | 3815 0x00, |
3808 }; | 3816 }; |
3809 // clang-format on | 3817 // clang-format on |
3810 | 3818 |
3811 // clang-format off | 3819 // clang-format off |
3812 unsigned char packet_version32[] = { | 3820 unsigned char packet_version32[] = { |
3813 // public flags (8 byte connection_id) | 3821 // public flags (8 byte connection_id) |
3814 0x3C, | 3822 static_cast<unsigned char>( |
| 3823 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
3815 // connection_id | 3824 // connection_id |
3816 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 3825 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
3817 // packet number | 3826 // packet number |
3818 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 3827 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
3819 // private flags (entropy) | 3828 // private flags (entropy) |
3820 0x01, | 3829 0x01, |
3821 | 3830 |
3822 // frame type (ack frame) | 3831 // frame type (ack frame) |
3823 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) | 3832 // (has nacks, not truncated, 6 byte largest observed, 1 byte delta) |
3824 0x6C, | 3833 0x6C, |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3955 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | 3964 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, |
3956 | 3965 |
3957 // 0 revived packets. | 3966 // 0 revived packets. |
3958 0x00, | 3967 0x00, |
3959 }; | 3968 }; |
3960 // clang-format on | 3969 // clang-format on |
3961 | 3970 |
3962 // clang-format off | 3971 // clang-format off |
3963 unsigned char packet_version32[] = { | 3972 unsigned char packet_version32[] = { |
3964 // public flags (8 byte connection_id) | 3973 // public flags (8 byte connection_id) |
3965 0x3C, | 3974 static_cast<unsigned char>( |
| 3975 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
3966 // connection_id | 3976 // connection_id |
3967 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 3977 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
3968 // packet number | 3978 // packet number |
3969 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 3979 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
3970 // private flags (entropy) | 3980 // private flags (entropy) |
3971 0x01, | 3981 0x01, |
3972 | 3982 |
3973 // frame type (ack frame) | 3983 // frame type (ack frame) |
3974 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta) | 3984 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta) |
3975 0x74, | 3985 0x74, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4069 for (size_t i = 1; i < 2 * 300; i += 2) { | 4079 for (size_t i = 1; i < 2 * 300; i += 2) { |
4070 ack_frame.missing_packets.Add(i); | 4080 ack_frame.missing_packets.Add(i); |
4071 } | 4081 } |
4072 | 4082 |
4073 QuicFrames frames; | 4083 QuicFrames frames; |
4074 frames.push_back(QuicFrame(&ack_frame)); | 4084 frames.push_back(QuicFrame(&ack_frame)); |
4075 | 4085 |
4076 // clang-format off | 4086 // clang-format off |
4077 unsigned char packet[] = { | 4087 unsigned char packet[] = { |
4078 // public flags (8 byte connection_id) | 4088 // public flags (8 byte connection_id) |
4079 0x3C, | 4089 0x3C, |
4080 // connection_id | 4090 // connection_id |
4081 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 4091 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
4082 // packet number | 4092 // packet number |
4083 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 4093 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
4084 // private flags (entropy) | 4094 // private flags (entropy) |
4085 0x01, | 4095 0x01, |
4086 | 4096 |
4087 // frame type (ack frame) | 4097 // frame type (ack frame) |
4088 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta) | 4098 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta) |
4089 0x74, | 4099 0x74, |
(...skipping 11 matching lines...) Expand all Loading... |
4101 // 6 nack ranges | 4111 // 6 nack ranges |
4102 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, | 4112 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, |
4103 // 0 revived packets. | 4113 // 0 revived packets. |
4104 0x00, | 4114 0x00, |
4105 }; | 4115 }; |
4106 // clang-format on | 4116 // clang-format on |
4107 | 4117 |
4108 // clang-format off | 4118 // clang-format off |
4109 unsigned char packet_version32[] = { | 4119 unsigned char packet_version32[] = { |
4110 // public flags (8 byte connection_id) | 4120 // public flags (8 byte connection_id) |
4111 0x3C, | 4121 static_cast<unsigned char>( |
| 4122 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
4112 // connection_id | 4123 // connection_id |
4113 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 4124 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
4114 // packet number | 4125 // packet number |
4115 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 4126 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
4116 // private flags (entropy) | 4127 // private flags (entropy) |
4117 0x01, | 4128 0x01, |
4118 | 4129 |
4119 // frame type (ack frame) | 4130 // frame type (ack frame) |
4120 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta) | 4131 // (has nacks, is truncated, 2 byte largest observed, 1 byte delta) |
4121 0x74, | 4132 0x74, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4167 QuicStopWaitingFrame stop_waiting_frame; | 4178 QuicStopWaitingFrame stop_waiting_frame; |
4168 stop_waiting_frame.entropy_hash = 0x14; | 4179 stop_waiting_frame.entropy_hash = 0x14; |
4169 stop_waiting_frame.least_unacked = kLeastUnacked; | 4180 stop_waiting_frame.least_unacked = kLeastUnacked; |
4170 | 4181 |
4171 QuicFrames frames; | 4182 QuicFrames frames; |
4172 frames.push_back(QuicFrame(&stop_waiting_frame)); | 4183 frames.push_back(QuicFrame(&stop_waiting_frame)); |
4173 | 4184 |
4174 // clang-format off | 4185 // clang-format off |
4175 unsigned char packet[] = { | 4186 unsigned char packet[] = { |
4176 // public flags (8 byte connection_id) | 4187 // public flags (8 byte connection_id) |
4177 0x3C, | 4188 static_cast<unsigned char>( |
| 4189 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
4178 // connection_id | 4190 // connection_id |
4179 0x10, 0x32, 0x54, 0x76, | 4191 0x10, 0x32, 0x54, 0x76, |
4180 0x98, 0xBA, 0xDC, 0xFE, | 4192 0x98, 0xBA, 0xDC, 0xFE, |
4181 // packet number | 4193 // packet number |
4182 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 4194 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
4183 // private flags (entropy) | 4195 // private flags (entropy) |
4184 0x01, | 4196 0x01, |
4185 | 4197 |
4186 // frame type (stop waiting frame) | 4198 // frame type (stop waiting frame) |
4187 0x06, | 4199 0x06, |
(...skipping 24 matching lines...) Expand all Loading... |
4212 header.fec_group = 0; | 4224 header.fec_group = 0; |
4213 | 4225 |
4214 QuicRstStreamFrame rst_frame; | 4226 QuicRstStreamFrame rst_frame; |
4215 rst_frame.stream_id = kStreamId; | 4227 rst_frame.stream_id = kStreamId; |
4216 rst_frame.error_code = static_cast<QuicRstStreamErrorCode>(0x05060708); | 4228 rst_frame.error_code = static_cast<QuicRstStreamErrorCode>(0x05060708); |
4217 rst_frame.byte_offset = 0x0807060504030201; | 4229 rst_frame.byte_offset = 0x0807060504030201; |
4218 | 4230 |
4219 // clang-format off | 4231 // clang-format off |
4220 unsigned char packet[] = { | 4232 unsigned char packet[] = { |
4221 // public flags (8 byte connection_id) | 4233 // public flags (8 byte connection_id) |
4222 0x3C, | 4234 static_cast<unsigned char>( |
| 4235 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
4223 // connection_id | 4236 // connection_id |
4224 0x10, 0x32, 0x54, 0x76, | 4237 0x10, 0x32, 0x54, 0x76, |
4225 0x98, 0xBA, 0xDC, 0xFE, | 4238 0x98, 0xBA, 0xDC, 0xFE, |
4226 // packet number | 4239 // packet number |
4227 0xBC, 0x9A, 0x78, 0x56, | 4240 0xBC, 0x9A, 0x78, 0x56, |
4228 0x34, 0x12, | 4241 0x34, 0x12, |
4229 // private flags | 4242 // private flags |
4230 0x00, | 4243 0x00, |
4231 | 4244 |
4232 // frame type (rst stream frame) | 4245 // frame type (rst stream frame) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4265 QuicConnectionCloseFrame close_frame; | 4278 QuicConnectionCloseFrame close_frame; |
4266 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708); | 4279 close_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
4267 close_frame.error_details = "because I can"; | 4280 close_frame.error_details = "because I can"; |
4268 | 4281 |
4269 QuicFrames frames; | 4282 QuicFrames frames; |
4270 frames.push_back(QuicFrame(&close_frame)); | 4283 frames.push_back(QuicFrame(&close_frame)); |
4271 | 4284 |
4272 // clang-format off | 4285 // clang-format off |
4273 unsigned char packet[] = { | 4286 unsigned char packet[] = { |
4274 // public flags (8 byte connection_id) | 4287 // public flags (8 byte connection_id) |
4275 0x3C, | 4288 static_cast<unsigned char>( |
| 4289 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
4276 // connection_id | 4290 // connection_id |
4277 0x10, 0x32, 0x54, 0x76, | 4291 0x10, 0x32, 0x54, 0x76, |
4278 0x98, 0xBA, 0xDC, 0xFE, | 4292 0x98, 0xBA, 0xDC, 0xFE, |
4279 // packet number | 4293 // packet number |
4280 0xBC, 0x9A, 0x78, 0x56, | 4294 0xBC, 0x9A, 0x78, 0x56, |
4281 0x34, 0x12, | 4295 0x34, 0x12, |
4282 // private flags (entropy) | 4296 // private flags (entropy) |
4283 0x01, | 4297 0x01, |
4284 | 4298 |
4285 // frame type (connection close frame) | 4299 // frame type (connection close frame) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4318 goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); | 4332 goaway_frame.error_code = static_cast<QuicErrorCode>(0x05060708); |
4319 goaway_frame.last_good_stream_id = kStreamId; | 4333 goaway_frame.last_good_stream_id = kStreamId; |
4320 goaway_frame.reason_phrase = "because I can"; | 4334 goaway_frame.reason_phrase = "because I can"; |
4321 | 4335 |
4322 QuicFrames frames; | 4336 QuicFrames frames; |
4323 frames.push_back(QuicFrame(&goaway_frame)); | 4337 frames.push_back(QuicFrame(&goaway_frame)); |
4324 | 4338 |
4325 // clang-format off | 4339 // clang-format off |
4326 unsigned char packet[] = { | 4340 unsigned char packet[] = { |
4327 // public flags (8 byte connection_id) | 4341 // public flags (8 byte connection_id) |
4328 0x3C, | 4342 static_cast<unsigned char>( |
| 4343 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
4329 // connection_id | 4344 // connection_id |
4330 0x10, 0x32, 0x54, 0x76, | 4345 0x10, 0x32, 0x54, 0x76, |
4331 0x98, 0xBA, 0xDC, 0xFE, | 4346 0x98, 0xBA, 0xDC, 0xFE, |
4332 // packet number | 4347 // packet number |
4333 0xBC, 0x9A, 0x78, 0x56, | 4348 0xBC, 0x9A, 0x78, 0x56, |
4334 0x34, 0x12, | 4349 0x34, 0x12, |
4335 // private flags(entropy) | 4350 // private flags(entropy) |
4336 0x01, | 4351 0x01, |
4337 | 4352 |
4338 // frame type (go away frame) | 4353 // frame type (go away frame) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4372 QuicWindowUpdateFrame window_update_frame; | 4387 QuicWindowUpdateFrame window_update_frame; |
4373 window_update_frame.stream_id = kStreamId; | 4388 window_update_frame.stream_id = kStreamId; |
4374 window_update_frame.byte_offset = 0x1122334455667788; | 4389 window_update_frame.byte_offset = 0x1122334455667788; |
4375 | 4390 |
4376 QuicFrames frames; | 4391 QuicFrames frames; |
4377 frames.push_back(QuicFrame(&window_update_frame)); | 4392 frames.push_back(QuicFrame(&window_update_frame)); |
4378 | 4393 |
4379 // clang-format off | 4394 // clang-format off |
4380 unsigned char packet[] = { | 4395 unsigned char packet[] = { |
4381 // public flags (8 byte connection_id) | 4396 // public flags (8 byte connection_id) |
4382 0x3C, | 4397 static_cast<unsigned char>( |
| 4398 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
4383 // connection_id | 4399 // connection_id |
4384 0x10, 0x32, 0x54, 0x76, | 4400 0x10, 0x32, 0x54, 0x76, |
4385 0x98, 0xBA, 0xDC, 0xFE, | 4401 0x98, 0xBA, 0xDC, 0xFE, |
4386 // packet number | 4402 // packet number |
4387 0xBC, 0x9A, 0x78, 0x56, | 4403 0xBC, 0x9A, 0x78, 0x56, |
4388 0x34, 0x12, | 4404 0x34, 0x12, |
4389 // private flags(entropy) | 4405 // private flags(entropy) |
4390 0x01, | 4406 0x01, |
4391 | 4407 |
4392 // frame type (window update frame) | 4408 // frame type (window update frame) |
(...skipping 26 matching lines...) Expand all Loading... |
4419 | 4435 |
4420 QuicBlockedFrame blocked_frame; | 4436 QuicBlockedFrame blocked_frame; |
4421 blocked_frame.stream_id = kStreamId; | 4437 blocked_frame.stream_id = kStreamId; |
4422 | 4438 |
4423 QuicFrames frames; | 4439 QuicFrames frames; |
4424 frames.push_back(QuicFrame(&blocked_frame)); | 4440 frames.push_back(QuicFrame(&blocked_frame)); |
4425 | 4441 |
4426 // clang-format off | 4442 // clang-format off |
4427 unsigned char packet[] = { | 4443 unsigned char packet[] = { |
4428 // public flags (8 byte connection_id) | 4444 // public flags (8 byte connection_id) |
4429 0x3C, | 4445 static_cast<unsigned char>( |
| 4446 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
4430 // connection_id | 4447 // connection_id |
4431 0x10, 0x32, 0x54, 0x76, | 4448 0x10, 0x32, 0x54, 0x76, |
4432 0x98, 0xBA, 0xDC, 0xFE, | 4449 0x98, 0xBA, 0xDC, 0xFE, |
4433 // packet number | 4450 // packet number |
4434 0xBC, 0x9A, 0x78, 0x56, | 4451 0xBC, 0x9A, 0x78, 0x56, |
4435 0x34, 0x12, | 4452 0x34, 0x12, |
4436 // private flags(entropy) | 4453 // private flags(entropy) |
4437 0x01, | 4454 0x01, |
4438 | 4455 |
4439 // frame type (blocked frame) | 4456 // frame type (blocked frame) |
(...skipping 22 matching lines...) Expand all Loading... |
4462 header.fec_group = 0; | 4479 header.fec_group = 0; |
4463 | 4480 |
4464 QuicPingFrame ping_frame; | 4481 QuicPingFrame ping_frame; |
4465 | 4482 |
4466 QuicFrames frames; | 4483 QuicFrames frames; |
4467 frames.push_back(QuicFrame(ping_frame)); | 4484 frames.push_back(QuicFrame(ping_frame)); |
4468 | 4485 |
4469 // clang-format off | 4486 // clang-format off |
4470 unsigned char packet[] = { | 4487 unsigned char packet[] = { |
4471 // public flags (8 byte connection_id) | 4488 // public flags (8 byte connection_id) |
4472 0x3C, | 4489 static_cast<unsigned char>( |
| 4490 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
4473 // connection_id | 4491 // connection_id |
4474 0x10, 0x32, 0x54, 0x76, | 4492 0x10, 0x32, 0x54, 0x76, |
4475 0x98, 0xBA, 0xDC, 0xFE, | 4493 0x98, 0xBA, 0xDC, 0xFE, |
4476 // packet number | 4494 // packet number |
4477 0xBC, 0x9A, 0x78, 0x56, | 4495 0xBC, 0x9A, 0x78, 0x56, |
4478 0x34, 0x12, | 4496 0x34, 0x12, |
4479 // private flags(entropy) | 4497 // private flags(entropy) |
4480 0x01, | 4498 0x01, |
4481 | 4499 |
4482 // frame type (ping frame) | 4500 // frame type (ping frame) |
(...skipping 22 matching lines...) Expand all Loading... |
4505 header.fec_group = 0; | 4523 header.fec_group = 0; |
4506 | 4524 |
4507 QuicPathCloseFrame path_close; | 4525 QuicPathCloseFrame path_close; |
4508 path_close.path_id = kPathId; | 4526 path_close.path_id = kPathId; |
4509 QuicFrames frames; | 4527 QuicFrames frames; |
4510 frames.push_back(QuicFrame(&path_close)); | 4528 frames.push_back(QuicFrame(&path_close)); |
4511 | 4529 |
4512 // clang-format off | 4530 // clang-format off |
4513 unsigned char packet[] = { | 4531 unsigned char packet[] = { |
4514 // public flags (version) | 4532 // public flags (version) |
4515 0x7C, | 4533 static_cast<unsigned char>( |
| 4534 framer_.version() > QUIC_VERSION_32 ? 0x78 : 0X7C), |
4516 // connection_id | 4535 // connection_id |
4517 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, | 4536 0x10, 0x32, 0x54, 0x76, 0x98, 0xBA, 0xDC, 0xFE, |
4518 // path_id | 4537 // path_id |
4519 0x00, | 4538 0x00, |
4520 // packet number | 4539 // packet number |
4521 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, | 4540 0xBC, 0x9A, 0x78, 0x56, 0x34, 0x12, |
4522 // private flags (entropy) | 4541 // private flags (entropy) |
4523 0x01, | 4542 0x01, |
4524 | 4543 |
4525 // frame type (path_close_frame) | 4544 // frame type (path_close_frame) |
(...skipping 23 matching lines...) Expand all Loading... |
4549 header.fec_group = 0; | 4568 header.fec_group = 0; |
4550 | 4569 |
4551 QuicMtuDiscoveryFrame mtu_discovery_frame; | 4570 QuicMtuDiscoveryFrame mtu_discovery_frame; |
4552 | 4571 |
4553 QuicFrames frames; | 4572 QuicFrames frames; |
4554 frames.push_back(QuicFrame(mtu_discovery_frame)); | 4573 frames.push_back(QuicFrame(mtu_discovery_frame)); |
4555 | 4574 |
4556 // clang-format off | 4575 // clang-format off |
4557 unsigned char packet[] = { | 4576 unsigned char packet[] = { |
4558 // public flags (8 byte connection_id) | 4577 // public flags (8 byte connection_id) |
4559 0x3C, | 4578 static_cast<unsigned char>( |
| 4579 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
4560 // connection_id | 4580 // connection_id |
4561 0x10, 0x32, 0x54, 0x76, | 4581 0x10, 0x32, 0x54, 0x76, |
4562 0x98, 0xBA, 0xDC, 0xFE, | 4582 0x98, 0xBA, 0xDC, 0xFE, |
4563 // packet number | 4583 // packet number |
4564 0xBC, 0x9A, 0x78, 0x56, | 4584 0xBC, 0x9A, 0x78, 0x56, |
4565 0x34, 0x12, | 4585 0x34, 0x12, |
4566 // private flags(entropy) | 4586 // private flags(entropy) |
4567 0x01, | 4587 0x01, |
4568 | 4588 |
4569 // frame type (ping frame) | 4589 // frame type (ping frame) |
(...skipping 13 matching lines...) Expand all Loading... |
4583 QuicPublicResetPacket reset_packet; | 4603 QuicPublicResetPacket reset_packet; |
4584 reset_packet.public_header.connection_id = kConnectionId; | 4604 reset_packet.public_header.connection_id = kConnectionId; |
4585 reset_packet.public_header.reset_flag = true; | 4605 reset_packet.public_header.reset_flag = true; |
4586 reset_packet.public_header.version_flag = false; | 4606 reset_packet.public_header.version_flag = false; |
4587 reset_packet.rejected_packet_number = kPacketNumber; | 4607 reset_packet.rejected_packet_number = kPacketNumber; |
4588 reset_packet.nonce_proof = kNonceProof; | 4608 reset_packet.nonce_proof = kNonceProof; |
4589 | 4609 |
4590 // clang-format off | 4610 // clang-format off |
4591 unsigned char packet[] = { | 4611 unsigned char packet[] = { |
4592 // public flags (public reset, 8 byte ConnectionId) | 4612 // public flags (public reset, 8 byte ConnectionId) |
4593 0x0E, | 4613 0x0A, |
4594 // connection_id | 4614 // connection_id |
4595 0x10, 0x32, 0x54, 0x76, | 4615 0x10, 0x32, 0x54, 0x76, |
4596 0x98, 0xBA, 0xDC, 0xFE, | 4616 0x98, 0xBA, 0xDC, 0xFE, |
4597 // message tag (kPRST) | 4617 // message tag (kPRST) |
4598 'P', 'R', 'S', 'T', | 4618 'P', 'R', 'S', 'T', |
4599 // num_entries (2) + padding | 4619 // num_entries (2) + padding |
4600 0x02, 0x00, 0x00, 0x00, | 4620 0x02, 0x00, 0x00, 0x00, |
4601 // tag kRNON | 4621 // tag kRNON |
4602 'R', 'N', 'O', 'N', | 4622 'R', 'N', 'O', 'N', |
4603 // end offset 8 | 4623 // end offset 8 |
(...skipping 25 matching lines...) Expand all Loading... |
4629 reset_packet.public_header.connection_id = kConnectionId; | 4649 reset_packet.public_header.connection_id = kConnectionId; |
4630 reset_packet.public_header.reset_flag = true; | 4650 reset_packet.public_header.reset_flag = true; |
4631 reset_packet.public_header.version_flag = false; | 4651 reset_packet.public_header.version_flag = false; |
4632 reset_packet.rejected_packet_number = kPacketNumber; | 4652 reset_packet.rejected_packet_number = kPacketNumber; |
4633 reset_packet.nonce_proof = kNonceProof; | 4653 reset_packet.nonce_proof = kNonceProof; |
4634 reset_packet.client_address = IPEndPoint(Loopback4(), 0x1234); | 4654 reset_packet.client_address = IPEndPoint(Loopback4(), 0x1234); |
4635 | 4655 |
4636 // clang-format off | 4656 // clang-format off |
4637 unsigned char packet[] = { | 4657 unsigned char packet[] = { |
4638 // public flags (public reset, 8 byte ConnectionId) | 4658 // public flags (public reset, 8 byte ConnectionId) |
4639 0x0E, | 4659 0x0A, |
4640 // connection_id | 4660 // connection_id |
4641 0x10, 0x32, 0x54, 0x76, | 4661 0x10, 0x32, 0x54, 0x76, |
4642 0x98, 0xBA, 0xDC, 0xFE, | 4662 0x98, 0xBA, 0xDC, 0xFE, |
4643 // message tag (kPRST) | 4663 // message tag (kPRST) |
4644 'P', 'R', 'S', 'T', | 4664 'P', 'R', 'S', 'T', |
4645 // num_entries (3) + padding | 4665 // num_entries (3) + padding |
4646 0x03, 0x00, 0x00, 0x00, | 4666 0x03, 0x00, 0x00, 0x00, |
4647 // tag kRNON | 4667 // tag kRNON |
4648 'R', 'N', 'O', 'N', | 4668 'R', 'N', 'O', 'N', |
4649 // end offset 8 | 4669 // end offset 8 |
(...skipping 26 matching lines...) Expand all Loading... |
4676 test::CompareCharArraysWithHexError("constructed packet", data->data(), | 4696 test::CompareCharArraysWithHexError("constructed packet", data->data(), |
4677 data->length(), AsChars(packet), | 4697 data->length(), AsChars(packet), |
4678 arraysize(packet)); | 4698 arraysize(packet)); |
4679 } | 4699 } |
4680 | 4700 |
4681 TEST_P(QuicFramerTest, EncryptPacket) { | 4701 TEST_P(QuicFramerTest, EncryptPacket) { |
4682 QuicPacketNumber packet_number = kPacketNumber; | 4702 QuicPacketNumber packet_number = kPacketNumber; |
4683 // clang-format off | 4703 // clang-format off |
4684 unsigned char packet[] = { | 4704 unsigned char packet[] = { |
4685 // public flags (8 byte connection_id) | 4705 // public flags (8 byte connection_id) |
4686 0x3C, | 4706 static_cast<unsigned char>( |
| 4707 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
4687 // connection_id | 4708 // connection_id |
4688 0x10, 0x32, 0x54, 0x76, | 4709 0x10, 0x32, 0x54, 0x76, |
4689 0x98, 0xBA, 0xDC, 0xFE, | 4710 0x98, 0xBA, 0xDC, 0xFE, |
4690 // packet number | 4711 // packet number |
4691 0xBC, 0x9A, 0x78, 0x56, | 4712 0xBC, 0x9A, 0x78, 0x56, |
4692 0x34, 0x12, | 4713 0x34, 0x12, |
4693 // private flags | 4714 // private flags |
4694 0x00, | 4715 0x00, |
4695 | 4716 |
4696 // redundancy | 4717 // redundancy |
4697 'a', 'b', 'c', 'd', | 4718 'a', 'b', 'c', 'd', |
4698 'e', 'f', 'g', 'h', | 4719 'e', 'f', 'g', 'h', |
4699 'i', 'j', 'k', 'l', | 4720 'i', 'j', 'k', 'l', |
4700 'm', 'n', 'o', 'p', | 4721 'm', 'n', 'o', 'p', |
4701 }; | 4722 }; |
4702 // clang-format on | 4723 // clang-format on |
4703 | 4724 |
4704 std::unique_ptr<QuicPacket> raw(new QuicPacket( | 4725 std::unique_ptr<QuicPacket> raw(new QuicPacket( |
4705 AsChars(packet), arraysize(packet), false, PACKET_8BYTE_CONNECTION_ID, | 4726 AsChars(packet), arraysize(packet), false, PACKET_8BYTE_CONNECTION_ID, |
4706 !kIncludeVersion, !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER)); | 4727 !kIncludeVersion, !kIncludePathId, !kIncludeDiversificationNonce, |
| 4728 PACKET_6BYTE_PACKET_NUMBER)); |
4707 char buffer[kMaxPacketSize]; | 4729 char buffer[kMaxPacketSize]; |
4708 size_t encrypted_length = | 4730 size_t encrypted_length = |
4709 framer_.EncryptPayload(ENCRYPTION_NONE, kDefaultPathId, packet_number, | 4731 framer_.EncryptPayload(ENCRYPTION_NONE, kDefaultPathId, packet_number, |
4710 *raw, buffer, kMaxPacketSize); | 4732 *raw, buffer, kMaxPacketSize); |
4711 | 4733 |
4712 ASSERT_NE(0u, encrypted_length); | 4734 ASSERT_NE(0u, encrypted_length); |
4713 EXPECT_TRUE(CheckEncryption(kDefaultPathId, packet_number, raw.get())); | 4735 EXPECT_TRUE(CheckEncryption(kDefaultPathId, packet_number, raw.get())); |
4714 } | 4736 } |
4715 | 4737 |
4716 TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) { | 4738 TEST_P(QuicFramerTest, EncryptPacketWithVersionFlag) { |
4717 QuicPacketNumber packet_number = kPacketNumber; | 4739 QuicPacketNumber packet_number = kPacketNumber; |
4718 // clang-format off | 4740 // clang-format off |
4719 unsigned char packet[] = { | 4741 unsigned char packet[] = { |
4720 // public flags (version, 8 byte connection_id) | 4742 // public flags (version, 8 byte connection_id) |
4721 0x3D, | 4743 0x39, |
4722 // connection_id | 4744 // connection_id |
4723 0x10, 0x32, 0x54, 0x76, | 4745 0x10, 0x32, 0x54, 0x76, |
4724 0x98, 0xBA, 0xDC, 0xFE, | 4746 0x98, 0xBA, 0xDC, 0xFE, |
4725 // version tag | 4747 // version tag |
4726 'Q', '.', '1', '0', | 4748 'Q', '.', '1', '0', |
4727 // packet number | 4749 // packet number |
4728 0xBC, 0x9A, 0x78, 0x56, | 4750 0xBC, 0x9A, 0x78, 0x56, |
4729 0x34, 0x12, | 4751 0x34, 0x12, |
4730 // private flags | 4752 // private flags |
4731 0x00, | 4753 0x00, |
4732 | 4754 |
4733 // redundancy | 4755 // redundancy |
4734 'a', 'b', 'c', 'd', | 4756 'a', 'b', 'c', 'd', |
4735 'e', 'f', 'g', 'h', | 4757 'e', 'f', 'g', 'h', |
4736 'i', 'j', 'k', 'l', | 4758 'i', 'j', 'k', 'l', |
4737 'm', 'n', 'o', 'p', | 4759 'm', 'n', 'o', 'p', |
4738 }; | 4760 }; |
4739 // clang-format on | 4761 // clang-format on |
4740 | 4762 |
4741 std::unique_ptr<QuicPacket> raw(new QuicPacket( | 4763 std::unique_ptr<QuicPacket> raw(new QuicPacket( |
4742 AsChars(packet), arraysize(packet), false, PACKET_8BYTE_CONNECTION_ID, | 4764 AsChars(packet), arraysize(packet), false, PACKET_8BYTE_CONNECTION_ID, |
4743 kIncludeVersion, !kIncludePathId, PACKET_6BYTE_PACKET_NUMBER)); | 4765 kIncludeVersion, !kIncludePathId, !kIncludeDiversificationNonce, |
| 4766 PACKET_6BYTE_PACKET_NUMBER)); |
4744 char buffer[kMaxPacketSize]; | 4767 char buffer[kMaxPacketSize]; |
4745 size_t encrypted_length = | 4768 size_t encrypted_length = |
4746 framer_.EncryptPayload(ENCRYPTION_NONE, kDefaultPathId, packet_number, | 4769 framer_.EncryptPayload(ENCRYPTION_NONE, kDefaultPathId, packet_number, |
4747 *raw, buffer, kMaxPacketSize); | 4770 *raw, buffer, kMaxPacketSize); |
4748 | 4771 |
4749 ASSERT_NE(0u, encrypted_length); | 4772 ASSERT_NE(0u, encrypted_length); |
4750 EXPECT_TRUE(CheckEncryption(kDefaultPathId, packet_number, raw.get())); | 4773 EXPECT_TRUE(CheckEncryption(kDefaultPathId, packet_number, raw.get())); |
4751 } | 4774 } |
4752 | 4775 |
4753 TEST_P(QuicFramerTest, EncryptPacketWithMultipathFlag) { | 4776 TEST_P(QuicFramerTest, EncryptPacketWithMultipathFlag) { |
4754 QuicPacketNumber packet_number = kPacketNumber; | 4777 QuicPacketNumber packet_number = kPacketNumber; |
4755 // clang-format off | 4778 // clang-format off |
4756 unsigned char packet[] = { | 4779 unsigned char packet[] = { |
4757 // public flags (version, 8 byte connection_id) | 4780 // public flags (version, 8 byte connection_id) |
4758 0x7C, | 4781 0x78, |
4759 // connection_id | 4782 // connection_id |
4760 0x10, 0x32, 0x54, 0x76, | 4783 0x10, 0x32, 0x54, 0x76, |
4761 0x98, 0xBA, 0xDC, 0xFE, | 4784 0x98, 0xBA, 0xDC, 0xFE, |
4762 // path_id | 4785 // path_id |
4763 0x42, | 4786 0x42, |
4764 // packet number | 4787 // packet number |
4765 0xBC, 0x9A, 0x78, 0x56, | 4788 0xBC, 0x9A, 0x78, 0x56, |
4766 0x34, 0x12, | 4789 0x34, 0x12, |
4767 // private flags | 4790 // private flags |
4768 0x00, | 4791 0x00, |
4769 | 4792 |
4770 // redundancy | 4793 // redundancy |
4771 'a', 'b', 'c', 'd', | 4794 'a', 'b', 'c', 'd', |
4772 'e', 'f', 'g', 'h', | 4795 'e', 'f', 'g', 'h', |
4773 'i', 'j', 'k', 'l', | 4796 'i', 'j', 'k', 'l', |
4774 'm', 'n', 'o', 'p', | 4797 'm', 'n', 'o', 'p', |
4775 }; | 4798 }; |
4776 // clang-format on | 4799 // clang-format on |
4777 | 4800 |
4778 std::unique_ptr<QuicPacket> raw(new QuicPacket( | 4801 std::unique_ptr<QuicPacket> raw(new QuicPacket( |
4779 AsChars(packet), arraysize(packet), false, PACKET_8BYTE_CONNECTION_ID, | 4802 AsChars(packet), arraysize(packet), false, PACKET_8BYTE_CONNECTION_ID, |
4780 !kIncludeVersion, kIncludePathId, PACKET_6BYTE_PACKET_NUMBER)); | 4803 !kIncludeVersion, kIncludePathId, !kIncludeDiversificationNonce, |
| 4804 PACKET_6BYTE_PACKET_NUMBER)); |
4781 char buffer[kMaxPacketSize]; | 4805 char buffer[kMaxPacketSize]; |
4782 size_t encrypted_length = framer_.EncryptPayload( | 4806 size_t encrypted_length = framer_.EncryptPayload( |
4783 ENCRYPTION_NONE, kPathId, packet_number, *raw, buffer, kMaxPacketSize); | 4807 ENCRYPTION_NONE, kPathId, packet_number, *raw, buffer, kMaxPacketSize); |
4784 | 4808 |
4785 ASSERT_NE(0u, encrypted_length); | 4809 ASSERT_NE(0u, encrypted_length); |
4786 EXPECT_TRUE(CheckEncryption(kPathId, packet_number, raw.get())); | 4810 EXPECT_TRUE(CheckEncryption(kPathId, packet_number, raw.get())); |
4787 } | 4811 } |
4788 | 4812 |
4789 TEST_P(QuicFramerTest, EncryptPacketWithBothVersionFlagAndMultipathFlag) { | 4813 TEST_P(QuicFramerTest, EncryptPacketWithBothVersionFlagAndMultipathFlag) { |
4790 QuicPacketNumber packet_number = kPacketNumber; | 4814 QuicPacketNumber packet_number = kPacketNumber; |
4791 // clang-format off | 4815 // clang-format off |
4792 unsigned char packet[] = { | 4816 unsigned char packet[] = { |
4793 // public flags (version, 8 byte connection_id) | 4817 // public flags (version, 8 byte connection_id) |
4794 0x7D, | 4818 0x79, |
4795 // connection_id | 4819 // connection_id |
4796 0x10, 0x32, 0x54, 0x76, | 4820 0x10, 0x32, 0x54, 0x76, |
4797 0x98, 0xBA, 0xDC, 0xFE, | 4821 0x98, 0xBA, 0xDC, 0xFE, |
4798 // version tag | 4822 // version tag |
4799 'Q', '.', '1', '0', | 4823 'Q', '.', '1', '0', |
4800 // path_id | 4824 // path_id |
4801 0x42, | 4825 0x42, |
4802 // packet number | 4826 // packet number |
4803 0xBC, 0x9A, 0x78, 0x56, | 4827 0xBC, 0x9A, 0x78, 0x56, |
4804 0x34, 0x12, | 4828 0x34, 0x12, |
4805 // private flags | 4829 // private flags |
4806 0x00, | 4830 0x00, |
4807 | 4831 |
4808 // redundancy | 4832 // redundancy |
4809 'a', 'b', 'c', 'd', | 4833 'a', 'b', 'c', 'd', |
4810 'e', 'f', 'g', 'h', | 4834 'e', 'f', 'g', 'h', |
4811 'i', 'j', 'k', 'l', | 4835 'i', 'j', 'k', 'l', |
4812 'm', 'n', 'o', 'p', | 4836 'm', 'n', 'o', 'p', |
4813 }; | 4837 }; |
4814 // clang-format on | 4838 // clang-format on |
4815 | 4839 |
4816 std::unique_ptr<QuicPacket> raw(new QuicPacket( | 4840 std::unique_ptr<QuicPacket> raw(new QuicPacket( |
4817 AsChars(packet), arraysize(packet), false, PACKET_8BYTE_CONNECTION_ID, | 4841 AsChars(packet), arraysize(packet), false, PACKET_8BYTE_CONNECTION_ID, |
4818 kIncludeVersion, kIncludePathId, PACKET_6BYTE_PACKET_NUMBER)); | 4842 kIncludeVersion, kIncludePathId, !kIncludeDiversificationNonce, |
| 4843 PACKET_6BYTE_PACKET_NUMBER)); |
4819 char buffer[kMaxPacketSize]; | 4844 char buffer[kMaxPacketSize]; |
4820 size_t encrypted_length = framer_.EncryptPayload( | 4845 size_t encrypted_length = framer_.EncryptPayload( |
4821 ENCRYPTION_NONE, kPathId, packet_number, *raw, buffer, kMaxPacketSize); | 4846 ENCRYPTION_NONE, kPathId, packet_number, *raw, buffer, kMaxPacketSize); |
4822 | 4847 |
4823 ASSERT_NE(0u, encrypted_length); | 4848 ASSERT_NE(0u, encrypted_length); |
4824 EXPECT_TRUE(CheckEncryption(kPathId, packet_number, raw.get())); | 4849 EXPECT_TRUE(CheckEncryption(kPathId, packet_number, raw.get())); |
4825 } | 4850 } |
4826 | 4851 |
4827 TEST_P(QuicFramerTest, AckTruncationLargePacket) { | 4852 TEST_P(QuicFramerTest, AckTruncationLargePacket) { |
4828 QuicPacketHeader header; | 4853 QuicPacketHeader header; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4946 raw_ack_packet.reset(BuildDataPacket(header, frames)); | 4971 raw_ack_packet.reset(BuildDataPacket(header, frames)); |
4947 ASSERT_TRUE(raw_ack_packet != nullptr); | 4972 ASSERT_TRUE(raw_ack_packet != nullptr); |
4948 EXPECT_EQ(original_raw_length, raw_ack_packet->length()); | 4973 EXPECT_EQ(original_raw_length, raw_ack_packet->length()); |
4949 ASSERT_TRUE(raw_ack_packet != nullptr); | 4974 ASSERT_TRUE(raw_ack_packet != nullptr); |
4950 } | 4975 } |
4951 | 4976 |
4952 TEST_P(QuicFramerTest, EntropyFlagTest) { | 4977 TEST_P(QuicFramerTest, EntropyFlagTest) { |
4953 // clang-format off | 4978 // clang-format off |
4954 unsigned char packet[] = { | 4979 unsigned char packet[] = { |
4955 // public flags (8 byte connection_id) | 4980 // public flags (8 byte connection_id) |
4956 0x3C, | 4981 static_cast<unsigned char>( |
| 4982 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
4957 // connection_id | 4983 // connection_id |
4958 0x10, 0x32, 0x54, 0x76, | 4984 0x10, 0x32, 0x54, 0x76, |
4959 0x98, 0xBA, 0xDC, 0xFE, | 4985 0x98, 0xBA, 0xDC, 0xFE, |
4960 // packet number | 4986 // packet number |
4961 0xBC, 0x9A, 0x78, 0x56, | 4987 0xBC, 0x9A, 0x78, 0x56, |
4962 0x34, 0x12, | 4988 0x34, 0x12, |
4963 // private flags (Entropy) | 4989 // private flags (Entropy) |
4964 0x01, | 4990 0x01, |
4965 | 4991 |
4966 // frame type (stream frame with fin and no length) | 4992 // frame type (stream frame with fin and no length) |
(...skipping 16 matching lines...) Expand all Loading... |
4983 ASSERT_TRUE(visitor_.header_.get()); | 5009 ASSERT_TRUE(visitor_.header_.get()); |
4984 EXPECT_TRUE(visitor_.header_->entropy_flag); | 5010 EXPECT_TRUE(visitor_.header_->entropy_flag); |
4985 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash); | 5011 EXPECT_EQ(1 << 4, visitor_.header_->entropy_hash); |
4986 EXPECT_FALSE(visitor_.header_->fec_flag); | 5012 EXPECT_FALSE(visitor_.header_->fec_flag); |
4987 }; | 5013 }; |
4988 | 5014 |
4989 TEST_P(QuicFramerTest, StopPacketProcessing) { | 5015 TEST_P(QuicFramerTest, StopPacketProcessing) { |
4990 // clang-format off | 5016 // clang-format off |
4991 unsigned char packet[] = { | 5017 unsigned char packet[] = { |
4992 // public flags (8 byte connection_id) | 5018 // public flags (8 byte connection_id) |
4993 0x3C, | 5019 static_cast<unsigned char>( |
| 5020 framer_.version() > QUIC_VERSION_32 ? 0x38 : 0x3C), |
4994 // connection_id | 5021 // connection_id |
4995 0x10, 0x32, 0x54, 0x76, | 5022 0x10, 0x32, 0x54, 0x76, |
4996 0x98, 0xBA, 0xDC, 0xFE, | 5023 0x98, 0xBA, 0xDC, 0xFE, |
4997 // packet number | 5024 // packet number |
4998 0xBC, 0x9A, 0x78, 0x56, | 5025 0xBC, 0x9A, 0x78, 0x56, |
4999 0x34, 0x12, | 5026 0x34, 0x12, |
5000 // Entropy | 5027 // Entropy |
5001 0x01, | 5028 0x01, |
5002 | 5029 |
5003 // frame type (stream frame with fin) | 5030 // frame type (stream frame with fin) |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5181 'o', ' ', 'w', 'o', | 5208 'o', ' ', 'w', 'o', |
5182 'r', 'l', 'd', '!', | 5209 'r', 'l', 'd', '!', |
5183 }; | 5210 }; |
5184 // clang-format on | 5211 // clang-format on |
5185 | 5212 |
5186 QuicFramerFuzzFunc(packet, arraysize(packet)); | 5213 QuicFramerFuzzFunc(packet, arraysize(packet)); |
5187 } | 5214 } |
5188 | 5215 |
5189 } // namespace test | 5216 } // namespace test |
5190 } // namespace net | 5217 } // namespace net |
OLD | NEW |