| 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_crypto_client_stream.h" | 5 #include "net/quic/quic_crypto_client_stream.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" | 8 #include "net/quic/crypto/aes_128_gcm_12_encrypter.h" |
| 9 #include "net/quic/crypto/quic_decrypter.h" | 9 #include "net/quic/crypto/quic_decrypter.h" |
| 10 #include "net/quic/crypto/quic_encrypter.h" | 10 #include "net/quic/crypto/quic_encrypter.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 const char kServerHostname[] = "example.com"; | 24 const char kServerHostname[] = "example.com"; |
| 25 const uint16 kServerPort = 80; | 25 const uint16 kServerPort = 80; |
| 26 | 26 |
| 27 class QuicCryptoClientStreamTest : public ::testing::Test { | 27 class QuicCryptoClientStreamTest : public ::testing::Test { |
| 28 public: | 28 public: |
| 29 QuicCryptoClientStreamTest() | 29 QuicCryptoClientStreamTest() |
| 30 : connection_(new PacketSavingConnection(false)), | 30 : connection_(new PacketSavingConnection(false)), |
| 31 session_(new TestClientSession(connection_, DefaultQuicConfig())), | 31 session_(new TestClientSession(connection_, DefaultQuicConfig())), |
| 32 server_id_(kServerHostname, kServerPort, false, PRIVACY_MODE_DISABLED), | 32 server_id_(kServerHostname, kServerPort, false, PRIVACY_MODE_DISABLED), |
| 33 stream_(new QuicCryptoClientStream( | 33 stream_(new QuicCryptoClientStream(server_id_, |
| 34 server_id_, session_.get(), NULL, &crypto_config_)) { | 34 session_.get(), |
| 35 NULL, |
| 36 &crypto_config_)) { |
| 35 session_->SetCryptoStream(stream_.get()); | 37 session_->SetCryptoStream(stream_.get()); |
| 36 session_->config()->SetDefaults(); | 38 session_->config()->SetDefaults(); |
| 37 crypto_config_.SetDefaults(); | 39 crypto_config_.SetDefaults(); |
| 38 } | 40 } |
| 39 | 41 |
| 40 void CompleteCryptoHandshake() { | 42 void CompleteCryptoHandshake() { |
| 41 EXPECT_TRUE(stream_->CryptoConnect()); | 43 EXPECT_TRUE(stream_->CryptoConnect()); |
| 42 CryptoTestUtils::HandshakeWithFakeServer(connection_, stream_.get()); | 44 CryptoTestUtils::HandshakeWithFakeServer(connection_, stream_.get()); |
| 43 } | 45 } |
| 44 | 46 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 63 | 65 |
| 64 TEST_F(QuicCryptoClientStreamTest, ConnectedAfterSHLO) { | 66 TEST_F(QuicCryptoClientStreamTest, ConnectedAfterSHLO) { |
| 65 CompleteCryptoHandshake(); | 67 CompleteCryptoHandshake(); |
| 66 EXPECT_TRUE(stream_->encryption_established()); | 68 EXPECT_TRUE(stream_->encryption_established()); |
| 67 EXPECT_TRUE(stream_->handshake_confirmed()); | 69 EXPECT_TRUE(stream_->handshake_confirmed()); |
| 68 } | 70 } |
| 69 | 71 |
| 70 TEST_F(QuicCryptoClientStreamTest, MessageAfterHandshake) { | 72 TEST_F(QuicCryptoClientStreamTest, MessageAfterHandshake) { |
| 71 CompleteCryptoHandshake(); | 73 CompleteCryptoHandshake(); |
| 72 | 74 |
| 73 EXPECT_CALL(*connection_, SendConnectionClose( | 75 EXPECT_CALL( |
| 74 QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE)); | 76 *connection_, |
| 77 SendConnectionClose(QUIC_CRYPTO_MESSAGE_AFTER_HANDSHAKE_COMPLETE)); |
| 75 message_.set_tag(kCHLO); | 78 message_.set_tag(kCHLO); |
| 76 ConstructHandshakeMessage(); | 79 ConstructHandshakeMessage(); |
| 77 stream_->ProcessRawData(message_data_->data(), message_data_->length()); | 80 stream_->ProcessRawData(message_data_->data(), message_data_->length()); |
| 78 } | 81 } |
| 79 | 82 |
| 80 TEST_F(QuicCryptoClientStreamTest, BadMessageType) { | 83 TEST_F(QuicCryptoClientStreamTest, BadMessageType) { |
| 81 EXPECT_TRUE(stream_->CryptoConnect()); | 84 EXPECT_TRUE(stream_->CryptoConnect()); |
| 82 | 85 |
| 83 message_.set_tag(kCHLO); | 86 message_.set_tag(kCHLO); |
| 84 ConstructHandshakeMessage(); | 87 ConstructHandshakeMessage(); |
| 85 | 88 |
| 86 EXPECT_CALL(*connection_, SendConnectionCloseWithDetails( | 89 EXPECT_CALL(*connection_, |
| 87 QUIC_INVALID_CRYPTO_MESSAGE_TYPE, "Expected REJ")); | 90 SendConnectionCloseWithDetails(QUIC_INVALID_CRYPTO_MESSAGE_TYPE, |
| 91 "Expected REJ")); |
| 88 stream_->ProcessRawData(message_data_->data(), message_data_->length()); | 92 stream_->ProcessRawData(message_data_->data(), message_data_->length()); |
| 89 } | 93 } |
| 90 | 94 |
| 91 TEST_F(QuicCryptoClientStreamTest, NegotiatedParameters) { | 95 TEST_F(QuicCryptoClientStreamTest, NegotiatedParameters) { |
| 92 CompleteCryptoHandshake(); | 96 CompleteCryptoHandshake(); |
| 93 | 97 |
| 94 const QuicConfig* config = session_->config(); | 98 const QuicConfig* config = session_->config(); |
| 95 EXPECT_EQ(FLAGS_enable_quic_pacing ? kPACE : kQBIC, | 99 EXPECT_EQ(FLAGS_enable_quic_pacing ? kPACE : kQBIC, |
| 96 config->congestion_control()); | 100 config->congestion_control()); |
| 97 EXPECT_EQ(kDefaultTimeoutSecs, | 101 EXPECT_EQ(kDefaultTimeoutSecs, |
| 98 config->idle_connection_state_lifetime().ToSeconds()); | 102 config->idle_connection_state_lifetime().ToSeconds()); |
| 99 EXPECT_EQ(kDefaultMaxStreamsPerConnection, | 103 EXPECT_EQ(kDefaultMaxStreamsPerConnection, |
| 100 config->max_streams_per_connection()); | 104 config->max_streams_per_connection()); |
| 101 EXPECT_EQ(0, config->keepalive_timeout().ToSeconds()); | 105 EXPECT_EQ(0, config->keepalive_timeout().ToSeconds()); |
| 102 | 106 |
| 103 const QuicCryptoNegotiatedParameters& crypto_params( | 107 const QuicCryptoNegotiatedParameters& crypto_params( |
| 104 stream_->crypto_negotiated_params()); | 108 stream_->crypto_negotiated_params()); |
| 105 EXPECT_EQ(crypto_config_.aead[0], crypto_params.aead); | 109 EXPECT_EQ(crypto_config_.aead[0], crypto_params.aead); |
| 106 EXPECT_EQ(crypto_config_.kexs[0], crypto_params.key_exchange); | 110 EXPECT_EQ(crypto_config_.kexs[0], crypto_params.key_exchange); |
| 107 } | 111 } |
| 108 | 112 |
| 109 TEST_F(QuicCryptoClientStreamTest, InvalidHostname) { | 113 TEST_F(QuicCryptoClientStreamTest, InvalidHostname) { |
| 110 QuicServerId server_id("invalid", 80, false, PRIVACY_MODE_DISABLED); | 114 QuicServerId server_id("invalid", 80, false, PRIVACY_MODE_DISABLED); |
| 111 stream_.reset(new QuicCryptoClientStream(server_id, session_.get(), NULL, | 115 stream_.reset(new QuicCryptoClientStream( |
| 112 &crypto_config_)); | 116 server_id, session_.get(), NULL, &crypto_config_)); |
| 113 session_->SetCryptoStream(stream_.get()); | 117 session_->SetCryptoStream(stream_.get()); |
| 114 | 118 |
| 115 CompleteCryptoHandshake(); | 119 CompleteCryptoHandshake(); |
| 116 EXPECT_TRUE(stream_->encryption_established()); | 120 EXPECT_TRUE(stream_->encryption_established()); |
| 117 EXPECT_TRUE(stream_->handshake_confirmed()); | 121 EXPECT_TRUE(stream_->handshake_confirmed()); |
| 118 } | 122 } |
| 119 | 123 |
| 120 TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) { | 124 TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) { |
| 121 // Seed the config with a cached server config. | 125 // Seed the config with a cached server config. |
| 122 CompleteCryptoHandshake(); | 126 CompleteCryptoHandshake(); |
| 123 | 127 |
| 124 connection_ = new PacketSavingConnection(true); | 128 connection_ = new PacketSavingConnection(true); |
| 125 session_.reset(new TestClientSession(connection_, DefaultQuicConfig())); | 129 session_.reset(new TestClientSession(connection_, DefaultQuicConfig())); |
| 126 stream_.reset(new QuicCryptoClientStream(server_id_, session_.get(), NULL, | 130 stream_.reset(new QuicCryptoClientStream( |
| 127 &crypto_config_)); | 131 server_id_, session_.get(), NULL, &crypto_config_)); |
| 128 | 132 |
| 129 session_->SetCryptoStream(stream_.get()); | 133 session_->SetCryptoStream(stream_.get()); |
| 130 session_->config()->SetDefaults(); | 134 session_->config()->SetDefaults(); |
| 131 | 135 |
| 132 // Advance time 5 years to ensure that we pass the expiry time of the cached | 136 // Advance time 5 years to ensure that we pass the expiry time of the cached |
| 133 // server config. | 137 // server config. |
| 134 reinterpret_cast<MockClock*>(const_cast<QuicClock*>(connection_->clock())) | 138 reinterpret_cast<MockClock*>(const_cast<QuicClock*>(connection_->clock())) |
| 135 ->AdvanceTime(QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); | 139 ->AdvanceTime(QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); |
| 136 | 140 |
| 137 // Check that a client hello was sent and that CryptoConnect doesn't fail | 141 // Check that a client hello was sent and that CryptoConnect doesn't fail |
| 138 // with an error. | 142 // with an error. |
| 139 EXPECT_TRUE(stream_->CryptoConnect()); | 143 EXPECT_TRUE(stream_->CryptoConnect()); |
| 140 ASSERT_EQ(1u, connection_->packets_.size()); | 144 ASSERT_EQ(1u, connection_->packets_.size()); |
| 141 } | 145 } |
| 142 | 146 |
| 143 } // namespace | 147 } // namespace |
| 144 } // namespace test | 148 } // namespace test |
| 145 } // namespace net | 149 } // namespace net |
| OLD | NEW |