| 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" |
| 11 #include "net/quic/quic_flags.h" | 11 #include "net/quic/quic_flags.h" |
| 12 #include "net/quic/quic_protocol.h" | 12 #include "net/quic/quic_protocol.h" |
| 13 #include "net/quic/quic_server_id.h" | 13 #include "net/quic/quic_server_id.h" |
| 14 #include "net/quic/quic_utils.h" | 14 #include "net/quic/quic_utils.h" |
| 15 #include "net/quic/test_tools/crypto_test_utils.h" | 15 #include "net/quic/test_tools/crypto_test_utils.h" |
| 16 #include "net/quic/test_tools/quic_test_utils.h" | 16 #include "net/quic/test_tools/quic_test_utils.h" |
| 17 #include "net/quic/test_tools/simple_quic_framer.h" | 17 #include "net/quic/test_tools/simple_quic_framer.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| 21 using std::string; | 21 using std::string; |
| 22 | 22 |
| 23 namespace net { | 23 namespace net { |
| 24 namespace test { | 24 namespace test { |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 const char kServerHostname[] = "example.com"; | 27 const char kServerHostname[] = "test.example.com"; |
| 28 const uint16 kServerPort = 80; | 28 const uint16 kServerPort = 443; |
| 29 | 29 |
| 30 class QuicCryptoClientStreamTest : public ::testing::Test { | 30 class QuicCryptoClientStreamTest : public ::testing::Test { |
| 31 public: | 31 public: |
| 32 QuicCryptoClientStreamTest() | 32 QuicCryptoClientStreamTest() |
| 33 : server_id_(kServerHostname, kServerPort, false, PRIVACY_MODE_DISABLED) { | 33 : server_id_(kServerHostname, kServerPort, PRIVACY_MODE_DISABLED), |
| 34 crypto_config_(CryptoTestUtils::ProofVerifierForTesting()) { |
| 34 CreateConnection(); | 35 CreateConnection(); |
| 35 } | 36 } |
| 36 | 37 |
| 37 void CreateConnection() { | 38 void CreateConnection() { |
| 38 connection_ = new PacketSavingConnection(&helper_, Perspective::IS_CLIENT); | 39 connection_ = new PacketSavingConnection(&helper_, Perspective::IS_CLIENT); |
| 39 // Advance the time, because timers do not like uninitialized times. | 40 // Advance the time, because timers do not like uninitialized times. |
| 40 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 41 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
| 41 | 42 |
| 42 session_.reset(new TestQuicSpdyClientSession( | 43 session_.reset(new TestQuicSpdyClientSession( |
| 43 connection_, DefaultQuicConfig(), server_id_, &crypto_config_)); | 44 connection_, DefaultQuicConfig(), server_id_, &crypto_config_)); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 config->IdleConnectionStateLifetime().ToSeconds()); | 109 config->IdleConnectionStateLifetime().ToSeconds()); |
| 109 EXPECT_EQ(kDefaultMaxStreamsPerConnection, | 110 EXPECT_EQ(kDefaultMaxStreamsPerConnection, |
| 110 config->MaxStreamsPerConnection()); | 111 config->MaxStreamsPerConnection()); |
| 111 | 112 |
| 112 const QuicCryptoNegotiatedParameters& crypto_params( | 113 const QuicCryptoNegotiatedParameters& crypto_params( |
| 113 stream()->crypto_negotiated_params()); | 114 stream()->crypto_negotiated_params()); |
| 114 EXPECT_EQ(crypto_config_.aead[0], crypto_params.aead); | 115 EXPECT_EQ(crypto_config_.aead[0], crypto_params.aead); |
| 115 EXPECT_EQ(crypto_config_.kexs[0], crypto_params.key_exchange); | 116 EXPECT_EQ(crypto_config_.kexs[0], crypto_params.key_exchange); |
| 116 } | 117 } |
| 117 | 118 |
| 118 TEST_F(QuicCryptoClientStreamTest, InvalidHostname) { | |
| 119 server_id_ = | |
| 120 QuicServerId("invalid", kServerPort, false, PRIVACY_MODE_DISABLED); | |
| 121 | |
| 122 CreateConnection(); | |
| 123 | |
| 124 CompleteCryptoHandshake(); | |
| 125 EXPECT_TRUE(stream()->encryption_established()); | |
| 126 EXPECT_TRUE(stream()->handshake_confirmed()); | |
| 127 } | |
| 128 | |
| 129 TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) { | 119 TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) { |
| 130 // Seed the config with a cached server config. | 120 // Seed the config with a cached server config. |
| 131 CompleteCryptoHandshake(); | 121 CompleteCryptoHandshake(); |
| 132 | 122 |
| 133 // Recreate connection with the new config. | 123 // Recreate connection with the new config. |
| 134 CreateConnection(); | 124 CreateConnection(); |
| 135 | 125 |
| 136 // Advance time 5 years to ensure that we pass the expiry time of the cached | 126 // Advance time 5 years to ensure that we pass the expiry time of the cached |
| 137 // server config. | 127 // server config. |
| 138 connection_->AdvanceTime( | 128 connection_->AdvanceTime( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 server_config_update.set_tag(kSCUP); | 191 server_config_update.set_tag(kSCUP); |
| 202 scoped_ptr<QuicData> data( | 192 scoped_ptr<QuicData> data( |
| 203 CryptoFramer::ConstructHandshakeMessage(server_config_update)); | 193 CryptoFramer::ConstructHandshakeMessage(server_config_update)); |
| 204 stream()->OnStreamFrame(QuicStreamFrame(kCryptoStreamId, /*fin=*/false, | 194 stream()->OnStreamFrame(QuicStreamFrame(kCryptoStreamId, /*fin=*/false, |
| 205 /*offset=*/0, data->AsStringPiece())); | 195 /*offset=*/0, data->AsStringPiece())); |
| 206 } | 196 } |
| 207 | 197 |
| 208 class QuicCryptoClientStreamStatelessTest : public ::testing::Test { | 198 class QuicCryptoClientStreamStatelessTest : public ::testing::Test { |
| 209 public: | 199 public: |
| 210 QuicCryptoClientStreamStatelessTest() | 200 QuicCryptoClientStreamStatelessTest() |
| 211 : server_crypto_config_(QuicCryptoServerConfig::TESTING, | 201 : client_crypto_config_(CryptoTestUtils::ProofVerifierForTesting()), |
| 212 QuicRandom::GetInstance()), | 202 server_crypto_config_(QuicCryptoServerConfig::TESTING, |
| 213 server_id_(kServerHostname, kServerPort, false, PRIVACY_MODE_DISABLED) { | 203 QuicRandom::GetInstance(), |
| 204 CryptoTestUtils::ProofSourceForTesting()), |
| 205 server_id_(kServerHostname, kServerPort, PRIVACY_MODE_DISABLED) { |
| 214 TestQuicSpdyClientSession* client_session = nullptr; | 206 TestQuicSpdyClientSession* client_session = nullptr; |
| 215 CreateClientSessionForTest(server_id_, | 207 CreateClientSessionForTest(server_id_, |
| 216 /* supports_stateless_rejects= */ true, | 208 /* supports_stateless_rejects= */ true, |
| 217 QuicTime::Delta::FromSeconds(100000), &helper_, | 209 QuicTime::Delta::FromSeconds(100000), &helper_, |
| 218 &client_crypto_config_, &client_connection_, | 210 &client_crypto_config_, &client_connection_, |
| 219 &client_session); | 211 &client_session); |
| 220 CHECK(client_session); | 212 CHECK(client_session); |
| 221 client_session_.reset(client_session); | 213 client_session_.reset(client_session); |
| 222 } | 214 } |
| 223 | 215 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 client_state->GetNextServerDesignatedConnectionId(); | 281 client_state->GetNextServerDesignatedConnectionId(); |
| 290 QuicConnectionId expected_id = | 282 QuicConnectionId expected_id = |
| 291 server_session_->connection()->random_generator()->RandUint64(); | 283 server_session_->connection()->random_generator()->RandUint64(); |
| 292 EXPECT_EQ(expected_id, server_designated_id); | 284 EXPECT_EQ(expected_id, server_designated_id); |
| 293 EXPECT_FALSE(client_state->has_server_designated_connection_id()); | 285 EXPECT_FALSE(client_state->has_server_designated_connection_id()); |
| 294 } | 286 } |
| 295 | 287 |
| 296 } // namespace | 288 } // namespace |
| 297 } // namespace test | 289 } // namespace test |
| 298 } // namespace net | 290 } // namespace net |
| OLD | NEW |