| 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(Perspective::IS_CLIENT); | 39 connection_ = new PacketSavingConnection(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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 config->IdleConnectionStateLifetime().ToSeconds()); | 108 config->IdleConnectionStateLifetime().ToSeconds()); |
| 108 EXPECT_EQ(kDefaultMaxStreamsPerConnection, | 109 EXPECT_EQ(kDefaultMaxStreamsPerConnection, |
| 109 config->MaxStreamsPerConnection()); | 110 config->MaxStreamsPerConnection()); |
| 110 | 111 |
| 111 const QuicCryptoNegotiatedParameters& crypto_params( | 112 const QuicCryptoNegotiatedParameters& crypto_params( |
| 112 stream()->crypto_negotiated_params()); | 113 stream()->crypto_negotiated_params()); |
| 113 EXPECT_EQ(crypto_config_.aead[0], crypto_params.aead); | 114 EXPECT_EQ(crypto_config_.aead[0], crypto_params.aead); |
| 114 EXPECT_EQ(crypto_config_.kexs[0], crypto_params.key_exchange); | 115 EXPECT_EQ(crypto_config_.kexs[0], crypto_params.key_exchange); |
| 115 } | 116 } |
| 116 | 117 |
| 117 TEST_F(QuicCryptoClientStreamTest, InvalidHostname) { | |
| 118 server_id_ = | |
| 119 QuicServerId("invalid", kServerPort, false, PRIVACY_MODE_DISABLED); | |
| 120 | |
| 121 CreateConnection(); | |
| 122 | |
| 123 CompleteCryptoHandshake(); | |
| 124 EXPECT_TRUE(stream()->encryption_established()); | |
| 125 EXPECT_TRUE(stream()->handshake_confirmed()); | |
| 126 } | |
| 127 | |
| 128 TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) { | 118 TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) { |
| 129 // Seed the config with a cached server config. | 119 // Seed the config with a cached server config. |
| 130 CompleteCryptoHandshake(); | 120 CompleteCryptoHandshake(); |
| 131 | 121 |
| 132 // Recreate connection with the new config. | 122 // Recreate connection with the new config. |
| 133 CreateConnection(); | 123 CreateConnection(); |
| 134 | 124 |
| 135 // Advance time 5 years to ensure that we pass the expiry time of the cached | 125 // Advance time 5 years to ensure that we pass the expiry time of the cached |
| 136 // server config. | 126 // server config. |
| 137 connection_->AdvanceTime( | 127 connection_->AdvanceTime( |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 server_config_update.set_tag(kSCUP); | 190 server_config_update.set_tag(kSCUP); |
| 201 scoped_ptr<QuicData> data( | 191 scoped_ptr<QuicData> data( |
| 202 CryptoFramer::ConstructHandshakeMessage(server_config_update)); | 192 CryptoFramer::ConstructHandshakeMessage(server_config_update)); |
| 203 stream()->OnStreamFrame(QuicStreamFrame(kCryptoStreamId, /*fin=*/false, | 193 stream()->OnStreamFrame(QuicStreamFrame(kCryptoStreamId, /*fin=*/false, |
| 204 /*offset=*/0, data->AsStringPiece())); | 194 /*offset=*/0, data->AsStringPiece())); |
| 205 } | 195 } |
| 206 | 196 |
| 207 class QuicCryptoClientStreamStatelessTest : public ::testing::Test { | 197 class QuicCryptoClientStreamStatelessTest : public ::testing::Test { |
| 208 public: | 198 public: |
| 209 QuicCryptoClientStreamStatelessTest() | 199 QuicCryptoClientStreamStatelessTest() |
| 210 : server_crypto_config_(QuicCryptoServerConfig::TESTING, | 200 : client_crypto_config_(CryptoTestUtils::ProofVerifierForTesting()), |
| 211 QuicRandom::GetInstance()), | 201 server_crypto_config_(QuicCryptoServerConfig::TESTING, |
| 212 server_id_(kServerHostname, kServerPort, false, PRIVACY_MODE_DISABLED) { | 202 QuicRandom::GetInstance(), |
| 203 CryptoTestUtils::ProofSourceForTesting()), |
| 204 server_id_(kServerHostname, kServerPort, PRIVACY_MODE_DISABLED) { |
| 213 TestQuicSpdyClientSession* client_session = nullptr; | 205 TestQuicSpdyClientSession* client_session = nullptr; |
| 214 CreateClientSessionForTest(server_id_, | 206 CreateClientSessionForTest(server_id_, |
| 215 /* supports_stateless_rejects= */ true, | 207 /* supports_stateless_rejects= */ true, |
| 216 QuicTime::Delta::FromSeconds(100000), | 208 QuicTime::Delta::FromSeconds(100000), |
| 217 &client_crypto_config_, &client_connection_, | 209 &client_crypto_config_, &client_connection_, |
| 218 &client_session); | 210 &client_session); |
| 219 CHECK(client_session); | 211 CHECK(client_session); |
| 220 client_session_.reset(client_session); | 212 client_session_.reset(client_session); |
| 221 } | 213 } |
| 222 | 214 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 client_state->GetNextServerDesignatedConnectionId(); | 278 client_state->GetNextServerDesignatedConnectionId(); |
| 287 QuicConnectionId expected_id = | 279 QuicConnectionId expected_id = |
| 288 server_session_->connection()->random_generator()->RandUint64(); | 280 server_session_->connection()->random_generator()->RandUint64(); |
| 289 EXPECT_EQ(expected_id, server_designated_id); | 281 EXPECT_EQ(expected_id, server_designated_id); |
| 290 EXPECT_FALSE(client_state->has_server_designated_connection_id()); | 282 EXPECT_FALSE(client_state->has_server_designated_connection_id()); |
| 291 } | 283 } |
| 292 | 284 |
| 293 } // namespace | 285 } // namespace |
| 294 } // namespace test | 286 } // namespace test |
| 295 } // namespace net | 287 } // namespace net |
| OLD | NEW |