| 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_server_stream.h" | 5 #include "net/quic/quic_crypto_server_stream.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 using std::pair; | 34 using std::pair; |
| 35 using testing::_; | 35 using testing::_; |
| 36 | 36 |
| 37 namespace net { | 37 namespace net { |
| 38 namespace test { | 38 namespace test { |
| 39 | 39 |
| 40 class QuicCryptoServerConfigPeer { | 40 class QuicCryptoServerConfigPeer { |
| 41 public: | 41 public: |
| 42 static string GetPrimaryOrbit(const QuicCryptoServerConfig& config) { | 42 static string GetPrimaryOrbit(const QuicCryptoServerConfig& config) { |
| 43 base::AutoLock lock(config.configs_lock_); | 43 base::AutoLock lock(config.configs_lock_); |
| 44 CHECK(config.primary_config_.get() != NULL); | 44 CHECK(config.primary_config_.get() != nullptr); |
| 45 return string(reinterpret_cast<const char*>(config.primary_config_->orbit), | 45 return string(reinterpret_cast<const char*>(config.primary_config_->orbit), |
| 46 kOrbitSize); | 46 kOrbitSize); |
| 47 } | 47 } |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 const char kServerHostname[] = "test.example.com"; | 52 const char kServerHostname[] = "test.example.com"; |
| 53 const uint16 kServerPort = 80; | 53 const uint16 kServerPort = 80; |
| 54 | 54 |
| 55 class QuicCryptoServerStreamTest : public ::testing::TestWithParam<bool> { | 55 class QuicCryptoServerStreamTest : public ::testing::TestWithParam<bool> { |
| 56 public: | 56 public: |
| 57 QuicCryptoServerStreamTest() | 57 QuicCryptoServerStreamTest() |
| 58 : connection_(new PacketSavingConnection(true)), | 58 : connection_(new PacketSavingConnection(true)), |
| 59 session_(connection_, DefaultQuicConfig()), | 59 session_(connection_, DefaultQuicConfig()), |
| 60 crypto_config_(QuicCryptoServerConfig::TESTING, | 60 crypto_config_(QuicCryptoServerConfig::TESTING, |
| 61 QuicRandom::GetInstance()), | 61 QuicRandom::GetInstance()), |
| 62 stream_(crypto_config_, &session_), | 62 stream_(crypto_config_, &session_), |
| 63 strike_register_client_(NULL) { | 63 strike_register_client_(nullptr) { |
| 64 config_.SetDefaults(); | 64 config_.SetDefaults(); |
| 65 session_.config()->SetDefaults(); | 65 session_.config()->SetDefaults(); |
| 66 session_.SetCryptoStream(&stream_); | 66 session_.SetCryptoStream(&stream_); |
| 67 // We advance the clock initially because the default time is zero and the | 67 // We advance the clock initially because the default time is zero and the |
| 68 // strike register worries that we've just overflowed a uint32 time. | 68 // strike register worries that we've just overflowed a uint32 time. |
| 69 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(100000)); | 69 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(100000)); |
| 70 // TODO(wtc): replace this with ProofSourceForTesting() when Chromium has | 70 // TODO(wtc): replace this with ProofSourceForTesting() when Chromium has |
| 71 // a working ProofSourceForTesting(). | 71 // a working ProofSourceForTesting(). |
| 72 crypto_config_.SetProofSource(CryptoTestUtils::FakeProofSourceForTesting()); | 72 crypto_config_.SetProofSource(CryptoTestUtils::FakeProofSourceForTesting()); |
| 73 crypto_config_.set_strike_register_no_startup_period(); | 73 crypto_config_.set_strike_register_no_startup_period(); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 QuicConfig client_config; | 143 QuicConfig client_config; |
| 144 client_config.SetDefaults(); | 144 client_config.SetDefaults(); |
| 145 scoped_ptr<TestClientSession> client_session( | 145 scoped_ptr<TestClientSession> client_session( |
| 146 new TestClientSession(client_conn, client_config)); | 146 new TestClientSession(client_conn, client_config)); |
| 147 QuicCryptoClientConfig client_crypto_config; | 147 QuicCryptoClientConfig client_crypto_config; |
| 148 client_crypto_config.SetDefaults(); | 148 client_crypto_config.SetDefaults(); |
| 149 | 149 |
| 150 QuicServerId server_id(kServerHostname, kServerPort, false, | 150 QuicServerId server_id(kServerHostname, kServerPort, false, |
| 151 PRIVACY_MODE_DISABLED); | 151 PRIVACY_MODE_DISABLED); |
| 152 scoped_ptr<QuicCryptoClientStream> client(new QuicCryptoClientStream( | 152 scoped_ptr<QuicCryptoClientStream> client(new QuicCryptoClientStream( |
| 153 server_id, client_session.get(), NULL, &client_crypto_config)); | 153 server_id, client_session.get(), nullptr, &client_crypto_config)); |
| 154 client_session->SetCryptoStream(client.get()); | 154 client_session->SetCryptoStream(client.get()); |
| 155 | 155 |
| 156 // Do a first handshake in order to prime the client config with the server's | 156 // Do a first handshake in order to prime the client config with the server's |
| 157 // information. | 157 // information. |
| 158 CHECK(client->CryptoConnect()); | 158 CHECK(client->CryptoConnect()); |
| 159 CHECK_EQ(1u, client_conn->packets_.size()); | 159 CHECK_EQ(1u, client_conn->packets_.size()); |
| 160 | 160 |
| 161 scoped_ptr<TestSession> server_session(new TestSession(server_conn, config_)); | 161 scoped_ptr<TestSession> server_session(new TestSession(server_conn, config_)); |
| 162 scoped_ptr<QuicCryptoServerStream> server( | 162 scoped_ptr<QuicCryptoServerStream> server( |
| 163 new QuicCryptoServerStream(crypto_config_, server_session.get())); | 163 new QuicCryptoServerStream(crypto_config_, server_session.get())); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 175 // We need to advance time past the strike-server window so that it's | 175 // We need to advance time past the strike-server window so that it's |
| 176 // authoritative in this time span. | 176 // authoritative in this time span. |
| 177 client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(102000)); | 177 client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(102000)); |
| 178 server_conn->AdvanceTime(QuicTime::Delta::FromSeconds(102000)); | 178 server_conn->AdvanceTime(QuicTime::Delta::FromSeconds(102000)); |
| 179 | 179 |
| 180 // This causes the client's nonce to be different and thus stops the | 180 // This causes the client's nonce to be different and thus stops the |
| 181 // strike-register from rejecting the repeated nonce. | 181 // strike-register from rejecting the repeated nonce. |
| 182 reinterpret_cast<MockRandom*>(client_conn->random_generator())->ChangeValue(); | 182 reinterpret_cast<MockRandom*>(client_conn->random_generator())->ChangeValue(); |
| 183 client_session.reset(new TestClientSession(client_conn, client_config)); | 183 client_session.reset(new TestClientSession(client_conn, client_config)); |
| 184 server_session.reset(new TestSession(server_conn, config_)); | 184 server_session.reset(new TestSession(server_conn, config_)); |
| 185 client.reset(new QuicCryptoClientStream( | 185 client.reset(new QuicCryptoClientStream(server_id, client_session.get(), |
| 186 server_id, client_session.get(), NULL, &client_crypto_config)); | 186 nullptr, &client_crypto_config)); |
| 187 client_session->SetCryptoStream(client.get()); | 187 client_session->SetCryptoStream(client.get()); |
| 188 | 188 |
| 189 server.reset(new QuicCryptoServerStream(crypto_config_, | 189 server.reset(new QuicCryptoServerStream(crypto_config_, |
| 190 server_session.get())); | 190 server_session.get())); |
| 191 server_session->SetCryptoStream(server.get()); | 191 server_session->SetCryptoStream(server.get()); |
| 192 | 192 |
| 193 CHECK(client->CryptoConnect()); | 193 CHECK(client->CryptoConnect()); |
| 194 | 194 |
| 195 if (AsyncStrikeRegisterVerification()) { | 195 if (AsyncStrikeRegisterVerification()) { |
| 196 EXPECT_FALSE(client->handshake_confirmed()); | 196 EXPECT_FALSE(client->handshake_confirmed()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 | 238 |
| 239 TEST_P(QuicCryptoServerStreamTest, BadMessageType) { | 239 TEST_P(QuicCryptoServerStreamTest, BadMessageType) { |
| 240 message_.set_tag(kSHLO); | 240 message_.set_tag(kSHLO); |
| 241 ConstructHandshakeMessage(); | 241 ConstructHandshakeMessage(); |
| 242 EXPECT_CALL(*connection_, SendConnectionClose( | 242 EXPECT_CALL(*connection_, SendConnectionClose( |
| 243 QUIC_INVALID_CRYPTO_MESSAGE_TYPE)); | 243 QUIC_INVALID_CRYPTO_MESSAGE_TYPE)); |
| 244 stream_.ProcessRawData(message_data_->data(), message_data_->length()); | 244 stream_.ProcessRawData(message_data_->data(), message_data_->length()); |
| 245 } | 245 } |
| 246 | 246 |
| 247 TEST_P(QuicCryptoServerStreamTest, WithoutCertificates) { | 247 TEST_P(QuicCryptoServerStreamTest, WithoutCertificates) { |
| 248 crypto_config_.SetProofSource(NULL); | 248 crypto_config_.SetProofSource(nullptr); |
| 249 client_options_.dont_verify_certs = true; | 249 client_options_.dont_verify_certs = true; |
| 250 | 250 |
| 251 // Only 2 client hellos need to be sent in the no-certs case: one to get the | 251 // Only 2 client hellos need to be sent in the no-certs case: one to get the |
| 252 // source-address token and the second to finish. | 252 // source-address token and the second to finish. |
| 253 EXPECT_EQ(2, CompleteCryptoHandshake()); | 253 EXPECT_EQ(2, CompleteCryptoHandshake()); |
| 254 EXPECT_TRUE(stream_.encryption_established()); | 254 EXPECT_TRUE(stream_.encryption_established()); |
| 255 EXPECT_TRUE(stream_.handshake_confirmed()); | 255 EXPECT_TRUE(stream_.handshake_confirmed()); |
| 256 } | 256 } |
| 257 | 257 |
| 258 TEST_P(QuicCryptoServerStreamTest, ChannelID) { | 258 TEST_P(QuicCryptoServerStreamTest, ChannelID) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 270 client_options_.channel_id_source_async = true; | 270 client_options_.channel_id_source_async = true; |
| 271 // CompleteCryptoHandshake verifies | 271 // CompleteCryptoHandshake verifies |
| 272 // stream_.crypto_negotiated_params().channel_id is correct. | 272 // stream_.crypto_negotiated_params().channel_id is correct. |
| 273 EXPECT_EQ(2, CompleteCryptoHandshake()); | 273 EXPECT_EQ(2, CompleteCryptoHandshake()); |
| 274 EXPECT_TRUE(stream_.encryption_established()); | 274 EXPECT_TRUE(stream_.encryption_established()); |
| 275 EXPECT_TRUE(stream_.handshake_confirmed()); | 275 EXPECT_TRUE(stream_.handshake_confirmed()); |
| 276 } | 276 } |
| 277 | 277 |
| 278 TEST_P(QuicCryptoServerStreamTest, OnlySendSCUPAfterHandshakeComplete) { | 278 TEST_P(QuicCryptoServerStreamTest, OnlySendSCUPAfterHandshakeComplete) { |
| 279 // An attempt to send a SCUP before completing handshake should fail. | 279 // An attempt to send a SCUP before completing handshake should fail. |
| 280 stream_.SendServerConfigUpdate(NULL); | 280 stream_.SendServerConfigUpdate(nullptr); |
| 281 EXPECT_EQ(0, stream_.num_server_config_update_messages_sent()); | 281 EXPECT_EQ(0, stream_.num_server_config_update_messages_sent()); |
| 282 } | 282 } |
| 283 | 283 |
| 284 } // namespace | 284 } // namespace |
| 285 } // namespace test | 285 } // namespace test |
| 286 } // namespace net | 286 } // namespace net |
| OLD | NEW |