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/core/quic_framer.h" | 5 #include "net/quic/core/quic_framer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cstdint> | 8 #include <cstdint> |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
(...skipping 2837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2848 : arraysize(packet), | 2848 : arraysize(packet), |
2849 false); | 2849 false); |
2850 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 2850 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
2851 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); | 2851 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
2852 ASSERT_TRUE(visitor_.public_reset_packet_.get()); | 2852 ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
2853 EXPECT_EQ(kConnectionId, | 2853 EXPECT_EQ(kConnectionId, |
2854 visitor_.public_reset_packet_->public_header.connection_id); | 2854 visitor_.public_reset_packet_->public_header.connection_id); |
2855 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); | 2855 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); |
2856 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); | 2856 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); |
2857 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); | 2857 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
2858 EXPECT_EQ(0u, visitor_.public_reset_packet_->rejected_packet_number); | |
2859 EXPECT_EQ( | 2858 EXPECT_EQ( |
2860 IpAddressFamily::IP_UNSPEC, | 2859 IpAddressFamily::IP_UNSPEC, |
2861 visitor_.public_reset_packet_->client_address.host().address_family()); | 2860 visitor_.public_reset_packet_->client_address.host().address_family()); |
2862 | 2861 |
2863 // Now test framing boundaries. | 2862 // Now test framing boundaries. |
2864 if (!QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())) { | 2863 if (!QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())) { |
2865 for (size_t i = 0; i < arraysize(packet); ++i) { | 2864 for (size_t i = 0; i < arraysize(packet); ++i) { |
2866 string expected_error; | 2865 string expected_error; |
2867 QUIC_DLOG(INFO) << "iteration: " << i; | 2866 QUIC_DLOG(INFO) << "iteration: " << i; |
2868 if (i < kConnectionIdOffset) { | 2867 if (i < kConnectionIdOffset) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2967 : arraysize(packet), | 2966 : arraysize(packet), |
2968 false); | 2967 false); |
2969 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 2968 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
2970 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); | 2969 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
2971 ASSERT_TRUE(visitor_.public_reset_packet_.get()); | 2970 ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
2972 EXPECT_EQ(kConnectionId, | 2971 EXPECT_EQ(kConnectionId, |
2973 visitor_.public_reset_packet_->public_header.connection_id); | 2972 visitor_.public_reset_packet_->public_header.connection_id); |
2974 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); | 2973 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); |
2975 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); | 2974 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); |
2976 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); | 2975 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
2977 EXPECT_EQ(0u, visitor_.public_reset_packet_->rejected_packet_number); | |
2978 EXPECT_EQ( | 2976 EXPECT_EQ( |
2979 IpAddressFamily::IP_UNSPEC, | 2977 IpAddressFamily::IP_UNSPEC, |
2980 visitor_.public_reset_packet_->client_address.host().address_family()); | 2978 visitor_.public_reset_packet_->client_address.host().address_family()); |
2981 | 2979 |
2982 // Now test framing boundaries. | 2980 // Now test framing boundaries. |
2983 if (!QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())) { | 2981 if (!QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())) { |
2984 for (size_t i = 0; i < arraysize(packet); ++i) { | 2982 for (size_t i = 0; i < arraysize(packet); ++i) { |
2985 string expected_error; | 2983 string expected_error; |
2986 QUIC_DLOG(INFO) << "iteration: " << i; | 2984 QUIC_DLOG(INFO) << "iteration: " << i; |
2987 if (i < kConnectionIdOffset) { | 2985 if (i < kConnectionIdOffset) { |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3169 : arraysize(packet), | 3167 : arraysize(packet), |
3170 false); | 3168 false); |
3171 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); | 3169 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); |
3172 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); | 3170 ASSERT_EQ(QUIC_NO_ERROR, framer_.error()); |
3173 ASSERT_TRUE(visitor_.public_reset_packet_.get()); | 3171 ASSERT_TRUE(visitor_.public_reset_packet_.get()); |
3174 EXPECT_EQ(kConnectionId, | 3172 EXPECT_EQ(kConnectionId, |
3175 visitor_.public_reset_packet_->public_header.connection_id); | 3173 visitor_.public_reset_packet_->public_header.connection_id); |
3176 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); | 3174 EXPECT_TRUE(visitor_.public_reset_packet_->public_header.reset_flag); |
3177 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); | 3175 EXPECT_FALSE(visitor_.public_reset_packet_->public_header.version_flag); |
3178 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); | 3176 EXPECT_EQ(kNonceProof, visitor_.public_reset_packet_->nonce_proof); |
3179 EXPECT_EQ(0u, visitor_.public_reset_packet_->rejected_packet_number); | |
3180 EXPECT_EQ("4.31.198.44", | 3177 EXPECT_EQ("4.31.198.44", |
3181 visitor_.public_reset_packet_->client_address.host().ToString()); | 3178 visitor_.public_reset_packet_->client_address.host().ToString()); |
3182 EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port()); | 3179 EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port()); |
3183 | 3180 |
3184 // Now test framing boundaries. | 3181 // Now test framing boundaries. |
3185 if (!QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())) { | 3182 if (!QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective())) { |
3186 for (size_t i = 0; i < arraysize(packet); ++i) { | 3183 for (size_t i = 0; i < arraysize(packet); ++i) { |
3187 string expected_error; | 3184 string expected_error; |
3188 QUIC_DLOG(INFO) << "iteration: " << i; | 3185 QUIC_DLOG(INFO) << "iteration: " << i; |
3189 if (i < kConnectionIdOffset) { | 3186 if (i < kConnectionIdOffset) { |
(...skipping 1587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4777 ? arraysize(packet_cid_be) | 4774 ? arraysize(packet_cid_be) |
4778 : arraysize(packet)); | 4775 : arraysize(packet)); |
4779 } | 4776 } |
4780 | 4777 |
4781 TEST_P(QuicFramerTest, BuildPublicResetPacketOld) { | 4778 TEST_P(QuicFramerTest, BuildPublicResetPacketOld) { |
4782 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = true; | 4779 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = true; |
4783 QuicPublicResetPacket reset_packet; | 4780 QuicPublicResetPacket reset_packet; |
4784 reset_packet.public_header.connection_id = kConnectionId; | 4781 reset_packet.public_header.connection_id = kConnectionId; |
4785 reset_packet.public_header.reset_flag = true; | 4782 reset_packet.public_header.reset_flag = true; |
4786 reset_packet.public_header.version_flag = false; | 4783 reset_packet.public_header.version_flag = false; |
4787 reset_packet.rejected_packet_number = kPacketNumber; | |
4788 reset_packet.nonce_proof = kNonceProof; | 4784 reset_packet.nonce_proof = kNonceProof; |
4789 | 4785 |
4790 // clang-format off | 4786 // clang-format off |
4791 unsigned char packet[] = { | 4787 unsigned char packet[] = { |
4792 // public flags (public reset, 8 byte ConnectionId) | 4788 // public flags (public reset, 8 byte ConnectionId) |
4793 0x0E, | 4789 0x0E, |
4794 // connection_id | 4790 // connection_id |
4795 0x10, 0x32, 0x54, 0x76, | 4791 0x10, 0x32, 0x54, 0x76, |
4796 0x98, 0xBA, 0xDC, 0xFE, | 4792 0x98, 0xBA, 0xDC, 0xFE, |
4797 // message tag (kPRST) | 4793 // message tag (kPRST) |
4798 'P', 'R', 'S', 'T', | 4794 'P', 'R', 'S', 'T', |
4799 // num_entries (2) + padding | |
4800 0x02, 0x00, 0x00, 0x00, | |
4801 // tag kRNON | |
4802 'R', 'N', 'O', 'N', | |
4803 // end offset 8 | |
4804 0x08, 0x00, 0x00, 0x00, | |
4805 // tag kRSEQ | |
4806 'R', 'S', 'E', 'Q', | |
4807 // end offset 16 | |
4808 0x10, 0x00, 0x00, 0x00, | |
4809 // nonce proof | |
4810 0x89, 0x67, 0x45, 0x23, | |
4811 0x01, 0xEF, 0xCD, 0xAB, | |
4812 // rejected packet number | |
4813 0xBC, 0x9A, 0x78, 0x56, | |
4814 0x34, 0x12, 0x00, 0x00, | |
4815 }; | |
4816 | |
4817 unsigned char packet_cid_be[] = { | |
4818 // public flags (public reset, 8 byte ConnectionId) | |
4819 0x0E, | |
4820 // connection_id | |
4821 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, | |
4822 // message tag (kPRST) | |
4823 'P', 'R', 'S', 'T', | |
4824 // num_entries (2) + padding | |
4825 0x02, 0x00, 0x00, 0x00, | |
4826 // tag kRNON | |
4827 'R', 'N', 'O', 'N', | |
4828 // end offset 8 | |
4829 0x08, 0x00, 0x00, 0x00, | |
4830 // tag kRSEQ | |
4831 'R', 'S', 'E', 'Q', | |
4832 // end offset 16 | |
4833 0x10, 0x00, 0x00, 0x00, | |
4834 // nonce proof | |
4835 0x89, 0x67, 0x45, 0x23, | |
4836 0x01, 0xEF, 0xCD, 0xAB, | |
4837 // rejected packet number | |
4838 0xBC, 0x9A, 0x78, 0x56, | |
4839 0x34, 0x12, 0x00, 0x00, | |
4840 }; | |
4841 | |
4842 unsigned char packet_no_rejected_packet_number[] = { | |
4843 // public flags (public reset, 8 byte ConnectionId) | |
4844 0x0E, | |
4845 // connection_id | |
4846 0x10, 0x32, 0x54, 0x76, | |
4847 0x98, 0xBA, 0xDC, 0xFE, | |
4848 // message tag (kPRST) | |
4849 'P', 'R', 'S', 'T', | |
4850 // num_entries (1) + padding | 4795 // num_entries (1) + padding |
4851 0x01, 0x00, 0x00, 0x00, | 4796 0x01, 0x00, 0x00, 0x00, |
4852 // tag kRNON | 4797 // tag kRNON |
4853 'R', 'N', 'O', 'N', | 4798 'R', 'N', 'O', 'N', |
4854 // end offset 8 | 4799 // end offset 8 |
4855 0x08, 0x00, 0x00, 0x00, | 4800 0x08, 0x00, 0x00, 0x00, |
4856 // nonce proof | 4801 // nonce proof |
4857 0x89, 0x67, 0x45, 0x23, | 4802 0x89, 0x67, 0x45, 0x23, |
4858 0x01, 0xEF, 0xCD, 0xAB, | 4803 0x01, 0xEF, 0xCD, 0xAB, |
4859 }; | 4804 }; |
4860 | 4805 |
4861 unsigned char packet_no_rejected_packet_number_cid_be[] = { | 4806 unsigned char packet_cid_be[] = { |
4862 // public flags (public reset, 8 byte ConnectionId) | 4807 // public flags (public reset, 8 byte ConnectionId) |
4863 0x0E, | 4808 0x0E, |
4864 // connection_id | 4809 // connection_id |
4865 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, | 4810 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, |
4866 // message tag (kPRST) | 4811 // message tag (kPRST) |
4867 'P', 'R', 'S', 'T', | 4812 'P', 'R', 'S', 'T', |
4868 // num_entries (1) + padding | 4813 // num_entries (1) + padding |
4869 0x01, 0x00, 0x00, 0x00, | 4814 0x01, 0x00, 0x00, 0x00, |
4870 // tag kRNON | 4815 // tag kRNON |
4871 'R', 'N', 'O', 'N', | 4816 'R', 'N', 'O', 'N', |
4872 // end offset 8 | 4817 // end offset 8 |
4873 0x08, 0x00, 0x00, 0x00, | 4818 0x08, 0x00, 0x00, 0x00, |
4874 // nonce proof | 4819 // nonce proof |
4875 0x89, 0x67, 0x45, 0x23, | 4820 0x89, 0x67, 0x45, 0x23, |
4876 0x01, 0xEF, 0xCD, 0xAB, | 4821 0x01, 0xEF, 0xCD, 0xAB, |
4877 }; | 4822 }; |
4878 // clang-format on | 4823 // clang-format on |
4879 | 4824 |
4880 std::unique_ptr<QuicEncryptedPacket> data( | 4825 std::unique_ptr<QuicEncryptedPacket> data( |
4881 framer_.BuildPublicResetPacket(reset_packet)); | 4826 framer_.BuildPublicResetPacket(reset_packet)); |
4882 ASSERT_TRUE(data != nullptr); | 4827 ASSERT_TRUE(data != nullptr); |
4883 if (FLAGS_quic_reloadable_flag_quic_remove_packet_number_from_public_reset) { | 4828 test::CompareCharArraysWithHexError( |
4884 test::CompareCharArraysWithHexError( | 4829 "constructed packet", data->data(), data->length(), |
4885 "constructed packet", data->data(), data->length(), | 4830 AsChars( |
4886 AsChars( | 4831 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) |
4887 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) | 4832 ? packet_cid_be |
4888 ? packet_no_rejected_packet_number_cid_be | 4833 : packet), |
4889 : packet_no_rejected_packet_number), | 4834 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) |
4890 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) | 4835 ? arraysize(packet_cid_be) |
4891 ? arraysize(packet_no_rejected_packet_number_cid_be) | 4836 : arraysize(packet)); |
4892 : arraysize(packet_no_rejected_packet_number)); | |
4893 } else { | |
4894 test::CompareCharArraysWithHexError( | |
4895 "constructed packet", data->data(), data->length(), | |
4896 AsChars( | |
4897 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) | |
4898 ? packet_cid_be | |
4899 : packet), | |
4900 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) | |
4901 ? arraysize(packet_cid_be) | |
4902 : arraysize(packet)); | |
4903 } | |
4904 } | 4837 } |
4905 | 4838 |
4906 TEST_P(QuicFramerTest, BuildPublicResetPacket) { | 4839 TEST_P(QuicFramerTest, BuildPublicResetPacket) { |
4907 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = false; | 4840 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = false; |
4908 QuicPublicResetPacket reset_packet; | 4841 QuicPublicResetPacket reset_packet; |
4909 reset_packet.public_header.connection_id = kConnectionId; | 4842 reset_packet.public_header.connection_id = kConnectionId; |
4910 reset_packet.public_header.reset_flag = true; | 4843 reset_packet.public_header.reset_flag = true; |
4911 reset_packet.public_header.version_flag = false; | 4844 reset_packet.public_header.version_flag = false; |
4912 reset_packet.rejected_packet_number = kPacketNumber; | |
4913 reset_packet.nonce_proof = kNonceProof; | 4845 reset_packet.nonce_proof = kNonceProof; |
4914 | 4846 |
4915 // clang-format off | 4847 // clang-format off |
4916 unsigned char packet[] = { | 4848 unsigned char packet[] = { |
4917 // public flags (public reset, 8 byte ConnectionId) | 4849 // public flags (public reset, 8 byte ConnectionId) |
4918 0x0A, | 4850 0x0A, |
4919 // connection_id | 4851 // connection_id |
4920 0x10, 0x32, 0x54, 0x76, | 4852 0x10, 0x32, 0x54, 0x76, |
4921 0x98, 0xBA, 0xDC, 0xFE, | 4853 0x98, 0xBA, 0xDC, 0xFE, |
4922 // message tag (kPRST) | 4854 // message tag (kPRST) |
4923 'P', 'R', 'S', 'T', | 4855 'P', 'R', 'S', 'T', |
4924 // num_entries (2) + padding | 4856 // num_entries (1) + padding |
4925 0x02, 0x00, 0x00, 0x00, | 4857 0x01, 0x00, 0x00, 0x00, |
4926 // tag kRNON | 4858 // tag kRNON |
4927 'R', 'N', 'O', 'N', | 4859 'R', 'N', 'O', 'N', |
4928 // end offset 8 | 4860 // end offset 8 |
4929 0x08, 0x00, 0x00, 0x00, | 4861 0x08, 0x00, 0x00, 0x00, |
4930 // tag kRSEQ | 4862 // nonce proof |
4931 'R', 'S', 'E', 'Q', | 4863 0x89, 0x67, 0x45, 0x23, |
4932 // end offset 16 | 4864 0x01, 0xEF, 0xCD, 0xAB, |
4933 0x10, 0x00, 0x00, 0x00, | |
4934 // nonce proof | |
4935 0x89, 0x67, 0x45, 0x23, | |
4936 0x01, 0xEF, 0xCD, 0xAB, | |
4937 // rejected packet number | |
4938 0xBC, 0x9A, 0x78, 0x56, | |
4939 0x34, 0x12, 0x00, 0x00, | |
4940 }; | 4865 }; |
4941 | 4866 |
4942 unsigned char packet_cid_be[] = { | 4867 unsigned char packet_cid_be[] = { |
4943 // public flags (public reset, 8 byte ConnectionId) | 4868 // public flags (public reset, 8 byte ConnectionId) |
4944 0x0A, | 4869 0x0A, |
4945 // connection_id | 4870 // connection_id |
4946 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, | 4871 0xFE, 0xDC, 0xBA, 0x98, |
4947 // message tag (kPRST) | 4872 0x76, 0x54, 0x32, 0x10, |
4948 'P', 'R', 'S', 'T', | 4873 // message tag (kPRST) |
4949 // num_entries (2) + padding | 4874 'P', 'R', 'S', 'T', |
4950 0x02, 0x00, 0x00, 0x00, | 4875 // num_entries (1) + padding |
4951 // tag kRNON | 4876 0x01, 0x00, 0x00, 0x00, |
4952 'R', 'N', 'O', 'N', | 4877 // tag kRNON |
4953 // end offset 8 | 4878 'R', 'N', 'O', 'N', |
4954 0x08, 0x00, 0x00, 0x00, | 4879 // end offset 8 |
4955 // tag kRSEQ | 4880 0x08, 0x00, 0x00, 0x00, |
4956 'R', 'S', 'E', 'Q', | 4881 // nonce proof |
4957 // end offset 16 | 4882 0x89, 0x67, 0x45, 0x23, |
4958 0x10, 0x00, 0x00, 0x00, | 4883 0x01, 0xEF, 0xCD, 0xAB, |
4959 // nonce proof | |
4960 0x89, 0x67, 0x45, 0x23, | |
4961 0x01, 0xEF, 0xCD, 0xAB, | |
4962 // rejected packet number | |
4963 0xBC, 0x9A, 0x78, 0x56, | |
4964 0x34, 0x12, 0x00, 0x00, | |
4965 }; | |
4966 | |
4967 unsigned char packet_no_rejected_packet_number[] = { | |
4968 // public flags (public reset, 8 byte ConnectionId) | |
4969 0x0A, | |
4970 // connection_id | |
4971 0x10, 0x32, 0x54, 0x76, | |
4972 0x98, 0xBA, 0xDC, 0xFE, | |
4973 // message tag (kPRST) | |
4974 'P', 'R', 'S', 'T', | |
4975 // num_entries (1) + padding | |
4976 0x01, 0x00, 0x00, 0x00, | |
4977 // tag kRNON | |
4978 'R', 'N', 'O', 'N', | |
4979 // end offset 8 | |
4980 0x08, 0x00, 0x00, 0x00, | |
4981 // nonce proof | |
4982 0x89, 0x67, 0x45, 0x23, | |
4983 0x01, 0xEF, 0xCD, 0xAB, | |
4984 }; | |
4985 | |
4986 unsigned char packet_no_rejected_packet_number_cid_be[] = { | |
4987 // public flags (public reset, 8 byte ConnectionId) | |
4988 0x0A, | |
4989 // connection_id | |
4990 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, | |
4991 // message tag (kPRST) | |
4992 'P', 'R', 'S', 'T', | |
4993 // num_entries (1) + padding | |
4994 0x01, 0x00, 0x00, 0x00, | |
4995 // tag kRNON | |
4996 'R', 'N', 'O', 'N', | |
4997 // end offset 8 | |
4998 0x08, 0x00, 0x00, 0x00, | |
4999 // nonce proof | |
5000 0x89, 0x67, 0x45, 0x23, | |
5001 0x01, 0xEF, 0xCD, 0xAB, | |
5002 }; | 4884 }; |
5003 // clang-format on | 4885 // clang-format on |
5004 | 4886 |
5005 std::unique_ptr<QuicEncryptedPacket> data( | 4887 std::unique_ptr<QuicEncryptedPacket> data( |
5006 framer_.BuildPublicResetPacket(reset_packet)); | 4888 framer_.BuildPublicResetPacket(reset_packet)); |
5007 ASSERT_TRUE(data != nullptr); | 4889 ASSERT_TRUE(data != nullptr); |
5008 | 4890 |
5009 if (FLAGS_quic_reloadable_flag_quic_remove_packet_number_from_public_reset) { | 4891 test::CompareCharArraysWithHexError( |
5010 test::CompareCharArraysWithHexError( | 4892 "constructed packet", data->data(), data->length(), |
5011 "constructed packet", data->data(), data->length(), | 4893 AsChars( |
5012 AsChars( | 4894 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) |
5013 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) | 4895 ? packet_cid_be |
5014 ? packet_no_rejected_packet_number_cid_be | 4896 : packet), |
5015 : packet_no_rejected_packet_number), | 4897 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) |
5016 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) | 4898 ? arraysize(packet_cid_be) |
5017 ? arraysize(packet_no_rejected_packet_number_cid_be) | 4899 : arraysize(packet)); |
5018 : arraysize(packet_no_rejected_packet_number)); | |
5019 } else { | |
5020 test::CompareCharArraysWithHexError( | |
5021 "constructed packet", data->data(), data->length(), | |
5022 AsChars( | |
5023 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) | |
5024 ? packet_cid_be | |
5025 : packet), | |
5026 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) | |
5027 ? arraysize(packet_cid_be) | |
5028 : arraysize(packet)); | |
5029 } | |
5030 } | 4900 } |
5031 | 4901 |
5032 TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) { | 4902 TEST_P(QuicFramerTest, BuildPublicResetPacketWithClientAddress) { |
5033 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = false; | 4903 FLAGS_quic_reloadable_flag_quic_use_old_public_reset_packets = false; |
5034 QuicPublicResetPacket reset_packet; | 4904 QuicPublicResetPacket reset_packet; |
5035 reset_packet.public_header.connection_id = kConnectionId; | 4905 reset_packet.public_header.connection_id = kConnectionId; |
5036 reset_packet.public_header.reset_flag = true; | 4906 reset_packet.public_header.reset_flag = true; |
5037 reset_packet.public_header.version_flag = false; | 4907 reset_packet.public_header.version_flag = false; |
5038 reset_packet.rejected_packet_number = kPacketNumber; | |
5039 reset_packet.nonce_proof = kNonceProof; | 4908 reset_packet.nonce_proof = kNonceProof; |
5040 reset_packet.client_address = | 4909 reset_packet.client_address = |
5041 QuicSocketAddress(QuicIpAddress::Loopback4(), 0x1234); | 4910 QuicSocketAddress(QuicIpAddress::Loopback4(), 0x1234); |
5042 | 4911 |
5043 // clang-format off | 4912 // clang-format off |
5044 unsigned char packet[] = { | 4913 unsigned char packet[] = { |
5045 // public flags (public reset, 8 byte ConnectionId) | |
5046 0x0A, | |
5047 // connection_id | |
5048 0x10, 0x32, 0x54, 0x76, | |
5049 0x98, 0xBA, 0xDC, 0xFE, | |
5050 // message tag (kPRST) | |
5051 'P', 'R', 'S', 'T', | |
5052 // num_entries (3) + padding | |
5053 0x03, 0x00, 0x00, 0x00, | |
5054 // tag kRNON | |
5055 'R', 'N', 'O', 'N', | |
5056 // end offset 8 | |
5057 0x08, 0x00, 0x00, 0x00, | |
5058 // tag kRSEQ | |
5059 'R', 'S', 'E', 'Q', | |
5060 // end offset 16 | |
5061 0x10, 0x00, 0x00, 0x00, | |
5062 // tag kCADR | |
5063 'C', 'A', 'D', 'R', | |
5064 // end offset 24 | |
5065 0x18, 0x00, 0x00, 0x00, | |
5066 // nonce proof | |
5067 0x89, 0x67, 0x45, 0x23, | |
5068 0x01, 0xEF, 0xCD, 0xAB, | |
5069 // rejected packet number | |
5070 0xBC, 0x9A, 0x78, 0x56, | |
5071 0x34, 0x12, 0x00, 0x00, | |
5072 // client address | |
5073 0x02, 0x00, | |
5074 0x7F, 0x00, 0x00, 0x01, | |
5075 0x34, 0x12, | |
5076 }; | |
5077 | |
5078 unsigned char packet_cid_be[] = { | |
5079 // public flags (public reset, 8 byte ConnectionId) | |
5080 0x0A, | |
5081 // connection_id | |
5082 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, | |
5083 // message tag (kPRST) | |
5084 'P', 'R', 'S', 'T', | |
5085 // num_entries (3) + padding | |
5086 0x03, 0x00, 0x00, 0x00, | |
5087 // tag kRNON | |
5088 'R', 'N', 'O', 'N', | |
5089 // end offset 8 | |
5090 0x08, 0x00, 0x00, 0x00, | |
5091 // tag kRSEQ | |
5092 'R', 'S', 'E', 'Q', | |
5093 // end offset 16 | |
5094 0x10, 0x00, 0x00, 0x00, | |
5095 // tag kCADR | |
5096 'C', 'A', 'D', 'R', | |
5097 // end offset 24 | |
5098 0x18, 0x00, 0x00, 0x00, | |
5099 // nonce proof | |
5100 0x89, 0x67, 0x45, 0x23, | |
5101 0x01, 0xEF, 0xCD, 0xAB, | |
5102 // rejected packet number | |
5103 0xBC, 0x9A, 0x78, 0x56, | |
5104 0x34, 0x12, 0x00, 0x00, | |
5105 // client address | |
5106 0x02, 0x00, | |
5107 0x7F, 0x00, 0x00, 0x01, | |
5108 0x34, 0x12, | |
5109 }; | |
5110 | |
5111 unsigned char packet_no_rejected_packet_number[] = { | |
5112 // public flags (public reset, 8 byte ConnectionId) | 4914 // public flags (public reset, 8 byte ConnectionId) |
5113 0x0A, | 4915 0x0A, |
5114 // connection_id | 4916 // connection_id |
5115 0x10, 0x32, 0x54, 0x76, | 4917 0x10, 0x32, 0x54, 0x76, |
5116 0x98, 0xBA, 0xDC, 0xFE, | 4918 0x98, 0xBA, 0xDC, 0xFE, |
5117 // message tag (kPRST) | 4919 // message tag (kPRST) |
5118 'P', 'R', 'S', 'T', | 4920 'P', 'R', 'S', 'T', |
5119 // num_entries (2) + padding | 4921 // num_entries (2) + padding |
5120 0x02, 0x00, 0x00, 0x00, | 4922 0x02, 0x00, 0x00, 0x00, |
5121 // tag kRNON | 4923 // tag kRNON |
5122 'R', 'N', 'O', 'N', | 4924 'R', 'N', 'O', 'N', |
5123 // end offset 8 | 4925 // end offset 8 |
5124 0x08, 0x00, 0x00, 0x00, | 4926 0x08, 0x00, 0x00, 0x00, |
5125 // tag kCADR | 4927 // tag kCADR |
5126 'C', 'A', 'D', 'R', | 4928 'C', 'A', 'D', 'R', |
5127 // end offset 16 | 4929 // end offset 16 |
5128 0x10, 0x00, 0x00, 0x00, | 4930 0x10, 0x00, 0x00, 0x00, |
5129 // nonce proof | 4931 // nonce proof |
5130 0x89, 0x67, 0x45, 0x23, | 4932 0x89, 0x67, 0x45, 0x23, |
5131 0x01, 0xEF, 0xCD, 0xAB, | 4933 0x01, 0xEF, 0xCD, 0xAB, |
5132 // client address | 4934 // client address |
5133 0x02, 0x00, | 4935 0x02, 0x00, |
5134 0x7F, 0x00, 0x00, 0x01, | 4936 0x7F, 0x00, 0x00, 0x01, |
5135 0x34, 0x12, | 4937 0x34, 0x12, |
5136 }; | 4938 }; |
5137 | 4939 |
5138 unsigned char packet_no_rejected_packet_number_cid_be[] = { | 4940 unsigned char packet_cid_be[] = { |
5139 // public flags (public reset, 8 byte ConnectionId) | 4941 // public flags (public reset, 8 byte ConnectionId) |
5140 0x0A, | 4942 0x0A, |
5141 // connection_id | 4943 // connection_id |
5142 0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10, | 4944 0xFE, 0xDC, 0xBA, 0x98, |
| 4945 0x76, 0x54, 0x32, 0x10, |
5143 // message tag (kPRST) | 4946 // message tag (kPRST) |
5144 'P', 'R', 'S', 'T', | 4947 'P', 'R', 'S', 'T', |
5145 // num_entries (2) + padding | 4948 // num_entries (2) + padding |
5146 0x02, 0x00, 0x00, 0x00, | 4949 0x02, 0x00, 0x00, 0x00, |
5147 // tag kRNON | 4950 // tag kRNON |
5148 'R', 'N', 'O', 'N', | 4951 'R', 'N', 'O', 'N', |
5149 // end offset 8 | 4952 // end offset 8 |
5150 0x08, 0x00, 0x00, 0x00, | 4953 0x08, 0x00, 0x00, 0x00, |
5151 // tag kCADR | 4954 // tag kCADR |
5152 'C', 'A', 'D', 'R', | 4955 'C', 'A', 'D', 'R', |
5153 // end offset 16 | 4956 // end offset 16 |
5154 0x10, 0x00, 0x00, 0x00, | 4957 0x10, 0x00, 0x00, 0x00, |
5155 // nonce proof | 4958 // nonce proof |
5156 0x89, 0x67, 0x45, 0x23, | 4959 0x89, 0x67, 0x45, 0x23, |
5157 0x01, 0xEF, 0xCD, 0xAB, | 4960 0x01, 0xEF, 0xCD, 0xAB, |
5158 // client address | 4961 // client address |
5159 0x02, 0x00, | 4962 0x02, 0x00, |
5160 0x7F, 0x00, 0x00, 0x01, | 4963 0x7F, 0x00, 0x00, 0x01, |
5161 0x34, 0x12, | 4964 0x34, 0x12, |
5162 }; | 4965 }; |
5163 // clang-format on | 4966 // clang-format on |
5164 | 4967 |
5165 std::unique_ptr<QuicEncryptedPacket> data( | 4968 std::unique_ptr<QuicEncryptedPacket> data( |
5166 framer_.BuildPublicResetPacket(reset_packet)); | 4969 framer_.BuildPublicResetPacket(reset_packet)); |
5167 ASSERT_TRUE(data != nullptr); | 4970 ASSERT_TRUE(data != nullptr); |
5168 | 4971 |
5169 if (FLAGS_quic_reloadable_flag_quic_remove_packet_number_from_public_reset) { | 4972 test::CompareCharArraysWithHexError( |
5170 test::CompareCharArraysWithHexError( | 4973 "constructed packet", data->data(), data->length(), |
5171 "constructed packet", data->data(), data->length(), | 4974 AsChars( |
5172 AsChars( | 4975 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) |
5173 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) | 4976 ? packet_cid_be |
5174 ? packet_no_rejected_packet_number_cid_be | 4977 : packet), |
5175 : packet_no_rejected_packet_number), | |
5176 | 4978 |
5177 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) | 4979 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) |
5178 ? arraysize(packet_no_rejected_packet_number_cid_be) | 4980 ? arraysize(packet_cid_be) |
5179 : arraysize(packet_no_rejected_packet_number)); | 4981 : arraysize(packet)); |
5180 } else { | |
5181 test::CompareCharArraysWithHexError( | |
5182 "constructed packet", data->data(), data->length(), | |
5183 AsChars( | |
5184 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) | |
5185 ? packet_cid_be | |
5186 : packet), | |
5187 | |
5188 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) | |
5189 ? arraysize(packet_cid_be) | |
5190 : arraysize(packet)); | |
5191 } | |
5192 } | 4982 } |
5193 | 4983 |
5194 TEST_P(QuicFramerTest, EncryptPacket) { | 4984 TEST_P(QuicFramerTest, EncryptPacket) { |
5195 QuicPacketNumber packet_number = kPacketNumber; | 4985 QuicPacketNumber packet_number = kPacketNumber; |
5196 // clang-format off | 4986 // clang-format off |
5197 unsigned char packet[] = { | 4987 unsigned char packet[] = { |
5198 // public flags (8 byte connection_id) | 4988 // public flags (8 byte connection_id) |
5199 0x38, | 4989 0x38, |
5200 // connection_id | 4990 // connection_id |
5201 0x10, 0x32, 0x54, 0x76, | 4991 0x10, 0x32, 0x54, 0x76, |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5681 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) | 5471 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) |
5682 ? packet_cid_be | 5472 ? packet_cid_be |
5683 : packet, | 5473 : packet, |
5684 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) | 5474 QuicUtils::IsConnectionIdWireFormatBigEndian(framer_.perspective()) |
5685 ? arraysize(packet_cid_be) | 5475 ? arraysize(packet_cid_be) |
5686 : arraysize(packet)); | 5476 : arraysize(packet)); |
5687 } | 5477 } |
5688 | 5478 |
5689 } // namespace test | 5479 } // namespace test |
5690 } // namespace net | 5480 } // namespace net |
OLD | NEW |