| 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_connection.h" | 5 #include "net/quic/quic_connection.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 2429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2440 | 2440 |
| 2441 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); | 2441 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); |
| 2442 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); | 2442 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
| 2443 | 2443 |
| 2444 SendStreamDataToPeer(2, "bar", 0, !kFin, nullptr); | 2444 SendStreamDataToPeer(2, "bar", 0, !kFin, nullptr); |
| 2445 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); | 2445 EXPECT_CALL(*send_algorithm_, OnPacketSent(_, _, _, _, _)).Times(1); |
| 2446 | 2446 |
| 2447 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION); | 2447 connection_.RetransmitUnackedPackets(ALL_INITIAL_RETRANSMISSION); |
| 2448 } | 2448 } |
| 2449 | 2449 |
| 2450 TEST_P(QuicConnectionTest, DelayForwardSecureEncryptionUntilClientIsReady) { |
| 2451 ValueRestore<bool> old_flag(&FLAGS_enable_quic_delay_forward_security, true); |
| 2452 |
| 2453 // A TaggingEncrypter puts kTagSize copies of the given byte (0x02 here) at |
| 2454 // the end of the packet. We can test this to check which encrypter was used. |
| 2455 use_tagging_decrypter(); |
| 2456 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); |
| 2457 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
| 2458 SendAckPacketToPeer(); |
| 2459 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); |
| 2460 |
| 2461 // Set a forward-secure encrypter but do not make it the default, and verify |
| 2462 // that it is not yet used. |
| 2463 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, |
| 2464 new TaggingEncrypter(0x03)); |
| 2465 SendAckPacketToPeer(); |
| 2466 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); |
| 2467 |
| 2468 // Now simulate receipt of a forward-secure packet and verify that the |
| 2469 // forward-secure encrypter is now used. |
| 2470 connection_.OnDecryptedPacket(ENCRYPTION_FORWARD_SECURE); |
| 2471 SendAckPacketToPeer(); |
| 2472 EXPECT_EQ(0x03030303u, writer_->final_bytes_of_last_packet()); |
| 2473 } |
| 2474 |
| 2475 TEST_P(QuicConnectionTest, DelayForwardSecureEncryptionUntilManyPacketSent) { |
| 2476 ValueRestore<bool> old_flag(&FLAGS_enable_quic_delay_forward_security, true); |
| 2477 |
| 2478 // Set a congestion window of 10 packets. |
| 2479 QuicPacketCount congestion_window = 10; |
| 2480 EXPECT_CALL(*send_algorithm_, GetCongestionWindow()).WillRepeatedly( |
| 2481 Return(congestion_window * kDefaultMaxPacketSize)); |
| 2482 |
| 2483 // A TaggingEncrypter puts kTagSize copies of the given byte (0x02 here) at |
| 2484 // the end of the packet. We can test this to check which encrypter was used. |
| 2485 use_tagging_decrypter(); |
| 2486 connection_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(0x02)); |
| 2487 connection_.SetDefaultEncryptionLevel(ENCRYPTION_INITIAL); |
| 2488 SendAckPacketToPeer(); |
| 2489 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); |
| 2490 |
| 2491 // Set a forward-secure encrypter but do not make it the default, and |
| 2492 // verify that it is not yet used. |
| 2493 connection_.SetEncrypter(ENCRYPTION_FORWARD_SECURE, |
| 2494 new TaggingEncrypter(0x03)); |
| 2495 SendAckPacketToPeer(); |
| 2496 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); |
| 2497 |
| 2498 // Now send a packet "Far enough" after the encrypter was set and verify that |
| 2499 // the forward-secure encrypter is now used. |
| 2500 for (uint64 i = 0; i < 3 * congestion_window - 1; ++i) { |
| 2501 EXPECT_EQ(0x02020202u, writer_->final_bytes_of_last_packet()); |
| 2502 SendAckPacketToPeer(); |
| 2503 } |
| 2504 EXPECT_EQ(0x03030303u, writer_->final_bytes_of_last_packet()); |
| 2505 } |
| 2506 |
| 2450 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { | 2507 TEST_P(QuicConnectionTest, BufferNonDecryptablePackets) { |
| 2451 // SetFromConfig is always called after construction from InitializeSession. | 2508 // SetFromConfig is always called after construction from InitializeSession. |
| 2452 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); | 2509 EXPECT_CALL(*send_algorithm_, SetFromConfig(_, _)); |
| 2453 QuicConfig config; | 2510 QuicConfig config; |
| 2454 connection_.SetFromConfig(config); | 2511 connection_.SetFromConfig(config); |
| 2455 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); | 2512 EXPECT_CALL(visitor_, OnSuccessfulVersionNegotiation(_)); |
| 2456 use_tagging_decrypter(); | 2513 use_tagging_decrypter(); |
| 2457 | 2514 |
| 2458 const uint8 tag = 0x07; | 2515 const uint8 tag = 0x07; |
| 2459 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); | 2516 framer_.SetEncrypter(ENCRYPTION_INITIAL, new TaggingEncrypter(tag)); |
| (...skipping 1647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4107 QuicBlockedFrame blocked; | 4164 QuicBlockedFrame blocked; |
| 4108 blocked.stream_id = 3; | 4165 blocked.stream_id = 3; |
| 4109 EXPECT_CALL(visitor_, OnBlockedFrames(_)); | 4166 EXPECT_CALL(visitor_, OnBlockedFrames(_)); |
| 4110 ProcessFramePacket(QuicFrame(&blocked)); | 4167 ProcessFramePacket(QuicFrame(&blocked)); |
| 4111 EXPECT_TRUE(ack_alarm->IsSet()); | 4168 EXPECT_TRUE(ack_alarm->IsSet()); |
| 4112 } | 4169 } |
| 4113 | 4170 |
| 4114 } // namespace | 4171 } // namespace |
| 4115 } // namespace test | 4172 } // namespace test |
| 4116 } // namespace net | 4173 } // namespace net |
| OLD | NEW |