Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Side by Side Diff: net/quic/quic_framer_test.cc

Issue 153993015: Use an alternative fix for OneShotVisitor of CryptoFramer that doesn't (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_framer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 return GetPrivateFlagsOffset(PACKET_8BYTE_GUID, include_version) + 87 return GetPrivateFlagsOffset(PACKET_8BYTE_GUID, include_version) +
88 kPrivateFlagsSize; 88 kPrivateFlagsSize;
89 } 89 }
90 90
91 size_t GetFecGroupOffset(bool include_version, 91 size_t GetFecGroupOffset(bool include_version,
92 QuicSequenceNumberLength sequence_number_length) { 92 QuicSequenceNumberLength sequence_number_length) {
93 return GetPrivateFlagsOffset(include_version, sequence_number_length) + 93 return GetPrivateFlagsOffset(include_version, sequence_number_length) +
94 kPrivateFlagsSize; 94 kPrivateFlagsSize;
95 } 95 }
96 96
97 // Index into the message tag of the public reset packet.
98 // Public resets always have full guids.
99 const size_t kPublicResetPacketMessageTagOffset =
100 kGuidOffset + PACKET_8BYTE_GUID;
101
102 // TODO(wtc): remove this when we drop support for QUIC_VERSION_13.
97 // Index into the nonce proof of the public reset packet. 103 // Index into the nonce proof of the public reset packet.
98 // Public resets always have full guids. 104 // Public resets always have full guids.
99 const size_t kPublicResetPacketNonceProofOffset = 105 const size_t kPublicResetPacketNonceProofOffset =
100 kGuidOffset + PACKET_8BYTE_GUID; 106 kGuidOffset + PACKET_8BYTE_GUID;
101 107
108 // TODO(wtc): remove this when we drop support for QUIC_VERSION_13.
102 // Index into the rejected sequence number of the public reset packet. 109 // Index into the rejected sequence number of the public reset packet.
103 const size_t kPublicResetPacketRejectedSequenceNumberOffset = 110 const size_t kPublicResetPacketRejectedSequenceNumberOffset =
104 kPublicResetPacketNonceProofOffset + kPublicResetNonceSize; 111 kPublicResetPacketNonceProofOffset + kPublicResetNonceSize;
105 112
106 // TODO(wtc): remove this when we drop support for QUIC_VERSION_13.
107 // Size of the old-style public reset packet.
108 const size_t kPublicResetPacketOldSize =
109 kPublicResetPacketRejectedSequenceNumberOffset +
110 PACKET_6BYTE_SEQUENCE_NUMBER;
111
112 class TestEncrypter : public QuicEncrypter { 113 class TestEncrypter : public QuicEncrypter {
113 public: 114 public:
114 virtual ~TestEncrypter() {} 115 virtual ~TestEncrypter() {}
115 virtual bool SetKey(StringPiece key) OVERRIDE { 116 virtual bool SetKey(StringPiece key) OVERRIDE {
116 return true; 117 return true;
117 } 118 }
118 virtual bool SetNoncePrefix(StringPiece nonce_prefix) OVERRIDE { 119 virtual bool SetNoncePrefix(StringPiece nonce_prefix) OVERRIDE {
119 return true; 120 return true;
120 } 121 }
121 virtual bool Encrypt(StringPiece nonce, 122 virtual bool Encrypt(StringPiece nonce,
(...skipping 2404 matching lines...) Expand 10 before | Expand all | Expand 10 after
2526 visitor_.public_reset_packet_->client_address.address().empty()); 2527 visitor_.public_reset_packet_->client_address.address().empty());
2527 2528
2528 // Now test framing boundaries 2529 // Now test framing boundaries
2529 for (size_t i = 0; i < arraysize(packet); ++i) { 2530 for (size_t i = 0; i < arraysize(packet); ++i) {
2530 string expected_error; 2531 string expected_error;
2531 DLOG(INFO) << "iteration: " << i; 2532 DLOG(INFO) << "iteration: " << i;
2532 if (i < kGuidOffset) { 2533 if (i < kGuidOffset) {
2533 expected_error = "Unable to read public flags."; 2534 expected_error = "Unable to read public flags.";
2534 CheckProcessingFails(packet, i, expected_error, 2535 CheckProcessingFails(packet, i, expected_error,
2535 QUIC_INVALID_PACKET_HEADER); 2536 QUIC_INVALID_PACKET_HEADER);
2536 } else if (i < kPublicResetPacketNonceProofOffset) { 2537 } else if (i < kPublicResetPacketMessageTagOffset) {
2537 expected_error = "Unable to read GUID."; 2538 expected_error = "Unable to read GUID.";
2538 CheckProcessingFails(packet, i, expected_error, 2539 CheckProcessingFails(packet, i, expected_error,
2539 QUIC_INVALID_PACKET_HEADER); 2540 QUIC_INVALID_PACKET_HEADER);
2540 } else if (i < kPublicResetPacketRejectedSequenceNumberOffset) {
2541 expected_error = "Unable to read nonce proof.";
2542 CheckProcessingFails(packet, i, expected_error,
2543 QUIC_INVALID_PUBLIC_RST_PACKET);
2544 } else if (i < kPublicResetPacketOldSize) {
2545 expected_error = "Unable to read rejected sequence number.";
2546 CheckProcessingFails(packet, i, expected_error,
2547 QUIC_INVALID_PUBLIC_RST_PACKET);
2548 } else if (i == kPublicResetPacketOldSize) {
2549 // This looks like an old public reset packet, so there won't be an
2550 // error.
2551 } else { 2541 } else {
2552 expected_error = "Unable to read reset message."; 2542 expected_error = "Unable to read reset message.";
2553 CheckProcessingFails(packet, i, expected_error, 2543 CheckProcessingFails(packet, i, expected_error,
2554 QUIC_INVALID_PUBLIC_RST_PACKET); 2544 QUIC_INVALID_PUBLIC_RST_PACKET);
2555 } 2545 }
2556 } 2546 }
2557 } 2547 }
2558 2548
2549 TEST_P(QuicFramerTest, PublicResetPacketWithTrailingJunk) {
2550 unsigned char packet[] = {
2551 // public flags (public reset, 8 byte guid)
2552 0x0E,
2553 // guid
2554 0x10, 0x32, 0x54, 0x76,
2555 0x98, 0xBA, 0xDC, 0xFE,
2556 // message tag (kPRST)
2557 'P', 'R', 'S', 'T',
2558 // num_entries (2) + padding
2559 0x02, 0x00, 0x00, 0x00,
2560 // tag kRNON
2561 'R', 'N', 'O', 'N',
2562 // end offset 8
2563 0x08, 0x00, 0x00, 0x00,
2564 // tag kRSEQ
2565 'R', 'S', 'E', 'Q',
2566 // end offset 16
2567 0x10, 0x00, 0x00, 0x00,
2568 // nonce proof
2569 0x89, 0x67, 0x45, 0x23,
2570 0x01, 0xEF, 0xCD, 0xAB,
2571 // rejected sequence number
2572 0xBC, 0x9A, 0x78, 0x56,
2573 0x34, 0x12, 0x00, 0x00,
2574 // trailing junk
2575 'j', 'u', 'n', 'k',
2576 };
2577
2578 string expected_error = "Unable to read reset message.";
2579 CheckProcessingFails(packet, arraysize(packet), expected_error,
2580 QUIC_INVALID_PUBLIC_RST_PACKET);
2581 }
2582
2559 TEST_P(QuicFramerTest, PublicResetPacketWithClientAddress) { 2583 TEST_P(QuicFramerTest, PublicResetPacketWithClientAddress) {
2560 unsigned char packet[] = { 2584 unsigned char packet[] = {
2561 // public flags (public reset, 8 byte guid) 2585 // public flags (public reset, 8 byte guid)
2562 0x0E, 2586 0x0E,
2563 // guid 2587 // guid
2564 0x10, 0x32, 0x54, 0x76, 2588 0x10, 0x32, 0x54, 0x76,
2565 0x98, 0xBA, 0xDC, 0xFE, 2589 0x98, 0xBA, 0xDC, 0xFE,
2566 // message tag (kPRST) 2590 // message tag (kPRST)
2567 'P', 'R', 'S', 'T', 2591 'P', 'R', 'S', 'T',
2568 // num_entries (3) + padding 2592 // num_entries (3) + padding
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2609 EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port()); 2633 EXPECT_EQ(443, visitor_.public_reset_packet_->client_address.port());
2610 2634
2611 // Now test framing boundaries 2635 // Now test framing boundaries
2612 for (size_t i = 0; i < arraysize(packet); ++i) { 2636 for (size_t i = 0; i < arraysize(packet); ++i) {
2613 string expected_error; 2637 string expected_error;
2614 DLOG(INFO) << "iteration: " << i; 2638 DLOG(INFO) << "iteration: " << i;
2615 if (i < kGuidOffset) { 2639 if (i < kGuidOffset) {
2616 expected_error = "Unable to read public flags."; 2640 expected_error = "Unable to read public flags.";
2617 CheckProcessingFails(packet, i, expected_error, 2641 CheckProcessingFails(packet, i, expected_error,
2618 QUIC_INVALID_PACKET_HEADER); 2642 QUIC_INVALID_PACKET_HEADER);
2619 } else if (i < kPublicResetPacketNonceProofOffset) { 2643 } else if (i < kPublicResetPacketMessageTagOffset) {
2620 expected_error = "Unable to read GUID."; 2644 expected_error = "Unable to read GUID.";
2621 CheckProcessingFails(packet, i, expected_error, 2645 CheckProcessingFails(packet, i, expected_error,
2622 QUIC_INVALID_PACKET_HEADER); 2646 QUIC_INVALID_PACKET_HEADER);
2623 } else if (i < kPublicResetPacketRejectedSequenceNumberOffset) {
2624 expected_error = "Unable to read nonce proof.";
2625 CheckProcessingFails(packet, i, expected_error,
2626 QUIC_INVALID_PUBLIC_RST_PACKET);
2627 } else if (i < kPublicResetPacketOldSize) {
2628 expected_error = "Unable to read rejected sequence number.";
2629 CheckProcessingFails(packet, i, expected_error,
2630 QUIC_INVALID_PUBLIC_RST_PACKET);
2631 } else if (i == kPublicResetPacketOldSize) {
2632 // This looks like an old public reset packet, so there won't be an
2633 // error.
2634 } else { 2647 } else {
2635 expected_error = "Unable to read reset message."; 2648 expected_error = "Unable to read reset message.";
2636 CheckProcessingFails(packet, i, expected_error, 2649 CheckProcessingFails(packet, i, expected_error,
2637 QUIC_INVALID_PUBLIC_RST_PACKET); 2650 QUIC_INVALID_PUBLIC_RST_PACKET);
2638 } 2651 }
2639 } 2652 }
2640 } 2653 }
2641 2654
2642 // TODO(wtc): remove this test when we drop support for QUIC_VERSION_13. 2655 // TODO(wtc): remove this test when we drop support for QUIC_VERSION_13.
2643 TEST_P(QuicFramerTest, PublicResetPacketOld) { 2656 TEST_P(QuicFramerTest, PublicResetPacketOld) {
(...skipping 1469 matching lines...) Expand 10 before | Expand all | Expand 10 after
4113 EXPECT_CALL(visitor, OnPacketComplete()); 4126 EXPECT_CALL(visitor, OnPacketComplete());
4114 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true)); 4127 EXPECT_CALL(visitor, OnUnauthenticatedPublicHeader(_)).WillOnce(Return(true));
4115 4128
4116 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false); 4129 QuicEncryptedPacket encrypted(AsChars(packet), arraysize(packet), false);
4117 EXPECT_TRUE(framer_.ProcessPacket(encrypted)); 4130 EXPECT_TRUE(framer_.ProcessPacket(encrypted));
4118 EXPECT_EQ(QUIC_NO_ERROR, framer_.error()); 4131 EXPECT_EQ(QUIC_NO_ERROR, framer_.error());
4119 } 4132 }
4120 4133
4121 } // namespace test 4134 } // namespace test
4122 } // namespace net 4135 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_framer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698