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_connection.h" | 5 #include "net/quic/core/quic_connection.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <memory> | 8 #include <memory> |
9 #include <ostream> | 9 #include <ostream> |
10 #include <utility> | 10 #include <utility> |
(...skipping 2626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2637 | 2637 |
2638 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); | 2638 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); |
2639 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 2639 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
2640 | 2640 |
2641 SendStreamDataToPeer(2, "bar", 0, !kFin, nullptr); | 2641 SendStreamDataToPeer(2, "bar", 0, !kFin, nullptr); |
2642 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 2642 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
2643 | 2643 |
2644 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION); | 2644 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION); |
2645 } | 2645 } |
2646 | 2646 |
2647 TEST_P(QuicConnectionTest, DelayForwardSecureEncryptionUntilClientIsReady) { | |
2648 FLAGS_quic_remove_obsolete_forward_secure = false; | |
2649 // A TaggingEncrypter puts kTagSize copies of the given byte (0x02 here) at | |
2650 // the end of the packet. We can test this to check which encrypter was used. | |
2651 use_tagging_decrypter(); | |
2652 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); | |
2653 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | |
2654 SendAckPacketToPeer(); | |
2655 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); | |
2656 | |
2657 // Set a forward-secure encrypter but do not make it the default, and verify | |
2658 // that it is not yet used. | |
2659 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, | |
2660 new TaggingEncrypter(0x03)); | |
2661 SendAckPacketToPeer(); | |
2662 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); | |
2663 | |
2664 // Now simulate receipt of a forward-secure packet and verify that the | |
2665 // forward-secure encrypter is now used. | |
2666 connection_.OnDecryptedPacket(ENCRYPTION_FORWARD_SECURE); | |
2667 SendAckPacketToPeer(); | |
2668 EXPECT_EQ(0x03030303u, writer_->final_bytes_of_last_packet()); | |
2669 } | |
2670 | |
2671 TEST_P(QuicConnectionTest, DelayForwardSecureEncryptionUntilManyPacketSent) { | |
2672 FLAGS_quic_remove_obsolete_forward_secure = false; | |
2673 // Set a congestion window of 10 packets. | |
2674 QuicPacketCount congestion_window = 10; | |
2675 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()) | |
2676 .WillRepeatedly(Return(congestion_window * kDefaultMaxPacketSize)); | |
2677 | |
2678 // A TaggingEncrypter puts kTagSize copies of the given byte (0x02 here) at | |
2679 // the end of the packet. We can test this to check which encrypter was used. | |
2680 use_tagging_decrypter(); | |
2681 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); | |
2682 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | |
2683 SendAckPacketToPeer(); | |
2684 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); | |
2685 | |
2686 // Set a forward-secure encrypter but do not make it the default, and | |
2687 // verify that it is not yet used. | |
2688 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, | |
2689 new TaggingEncrypter(0x03)); | |
2690 SendAckPacketToPeer(); | |
2691 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); | |
2692 | |
2693 // Now send a packet "Far enough" after the encrypter was set and verify that | |
2694 // the forward-secure encrypter is now used. | |
2695 for (uint64_t i = 0; i < 3 * congestion_window - 1; ++i) { | |
2696 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); | |
2697 SendAckPacketToPeer(); | |
2698 } | |
2699 EXPECT_EQ(0x03030303u, writer_->final_bytes_of_last_packet()); | |
2700 } | |
2701 | |
2702 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { | 2647 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { |
2703 // SetFromConfig is always called after construction from InitializeSession. | 2648 // SetFromConfig is always called after construction from InitializeSession. |
2704 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 2649 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
2705 QuicConfig config; | 2650 QuicConfig config; |
2706 connection_.SetFromConfig(config); | 2651 connection_.SetFromConfig(config); |
2707 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2652 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
2708 use_tagging_decrypter(); | 2653 use_tagging_decrypter(); |
2709 | 2654 |
2710 const uint8_t tag = 0x07; | 2655 const uint8_t tag = 0x07; |
2711 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2656 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
(...skipping 2586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5298 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); | 5243 connection_.SendStreamDataWithString(3, "foo", 0, !kFin, nullptr); |
5299 EXPECT_EQ(1u, writer_->frame_count()); | 5244 EXPECT_EQ(1u, writer_->frame_count()); |
5300 EXPECT_FALSE(writer_->connection_close_frames().empty()); | 5245 EXPECT_FALSE(writer_->connection_close_frames().empty()); |
5301 // Ack frame is not bundled in connection close packet. | 5246 // Ack frame is not bundled in connection close packet. |
5302 EXPECT_TRUE(writer_->ack_frames().empty()); | 5247 EXPECT_TRUE(writer_->ack_frames().empty()); |
5303 } | 5248 } |
5304 | 5249 |
5305 } // namespace | 5250 } // namespace |
5306 } // namespace test | 5251 } // namespace test |
5307 } // namespace net | 5252 } // namespace net |
OLD | NEW |