| 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 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 const char kServerHostname[] = "example.com"; | 25 const char kServerHostname[] = "example.com"; |
| 26 const uint16 kServerPort = 80; | 26 const uint16 kServerPort = 80; |
| 27 | 27 |
| 28 class QuicCryptoClientStreamTest : public ::testing::Test { | 28 class QuicCryptoClientStreamTest : public ::testing::Test { |
| 29 public: | 29 public: |
| 30 QuicCryptoClientStreamTest() | 30 QuicCryptoClientStreamTest() |
| 31 : connection_(new PacketSavingConnection(false)), | 31 : connection_(new PacketSavingConnection(false)), |
| 32 session_(new TestClientSession(connection_, DefaultQuicConfig())), | 32 session_(new TestClientSession(connection_, DefaultQuicConfig())), |
| 33 server_id_(kServerHostname, kServerPort, false, PRIVACY_MODE_DISABLED), | 33 server_id_(kServerHostname, kServerPort, false, PRIVACY_MODE_DISABLED), |
| 34 stream_(new QuicCryptoClientStream( | 34 stream_(new QuicCryptoClientStream(server_id_, session_.get(), nullptr, |
| 35 server_id_, session_.get(), NULL, &crypto_config_)) { | 35 &crypto_config_)) { |
| 36 session_->SetCryptoStream(stream_.get()); | 36 session_->SetCryptoStream(stream_.get()); |
| 37 session_->config()->SetDefaults(); | 37 session_->config()->SetDefaults(); |
| 38 crypto_config_.SetDefaults(); | 38 crypto_config_.SetDefaults(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void CompleteCryptoHandshake() { | 41 void CompleteCryptoHandshake() { |
| 42 EXPECT_TRUE(stream_->CryptoConnect()); | 42 EXPECT_TRUE(stream_->CryptoConnect()); |
| 43 CryptoTestUtils::HandshakeWithFakeServer(connection_, stream_.get()); | 43 CryptoTestUtils::HandshakeWithFakeServer(connection_, stream_.get()); |
| 44 } | 44 } |
| 45 | 45 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 EXPECT_EQ(0, config->KeepaliveTimeout().ToSeconds()); | 101 EXPECT_EQ(0, config->KeepaliveTimeout().ToSeconds()); |
| 102 | 102 |
| 103 const QuicCryptoNegotiatedParameters& crypto_params( | 103 const QuicCryptoNegotiatedParameters& crypto_params( |
| 104 stream_->crypto_negotiated_params()); | 104 stream_->crypto_negotiated_params()); |
| 105 EXPECT_EQ(crypto_config_.aead[0], crypto_params.aead); | 105 EXPECT_EQ(crypto_config_.aead[0], crypto_params.aead); |
| 106 EXPECT_EQ(crypto_config_.kexs[0], crypto_params.key_exchange); | 106 EXPECT_EQ(crypto_config_.kexs[0], crypto_params.key_exchange); |
| 107 } | 107 } |
| 108 | 108 |
| 109 TEST_F(QuicCryptoClientStreamTest, InvalidHostname) { | 109 TEST_F(QuicCryptoClientStreamTest, InvalidHostname) { |
| 110 QuicServerId server_id("invalid", 80, false, PRIVACY_MODE_DISABLED); | 110 QuicServerId server_id("invalid", 80, false, PRIVACY_MODE_DISABLED); |
| 111 stream_.reset(new QuicCryptoClientStream(server_id, session_.get(), NULL, | 111 stream_.reset(new QuicCryptoClientStream(server_id, session_.get(), nullptr, |
| 112 &crypto_config_)); | 112 &crypto_config_)); |
| 113 session_->SetCryptoStream(stream_.get()); | 113 session_->SetCryptoStream(stream_.get()); |
| 114 | 114 |
| 115 CompleteCryptoHandshake(); | 115 CompleteCryptoHandshake(); |
| 116 EXPECT_TRUE(stream_->encryption_established()); | 116 EXPECT_TRUE(stream_->encryption_established()); |
| 117 EXPECT_TRUE(stream_->handshake_confirmed()); | 117 EXPECT_TRUE(stream_->handshake_confirmed()); |
| 118 } | 118 } |
| 119 | 119 |
| 120 TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) { | 120 TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) { |
| 121 // Seed the config with a cached server config. | 121 // Seed the config with a cached server config. |
| 122 CompleteCryptoHandshake(); | 122 CompleteCryptoHandshake(); |
| 123 | 123 |
| 124 connection_ = new PacketSavingConnection(true); | 124 connection_ = new PacketSavingConnection(true); |
| 125 session_.reset(new TestClientSession(connection_, DefaultQuicConfig())); | 125 session_.reset(new TestClientSession(connection_, DefaultQuicConfig())); |
| 126 stream_.reset(new QuicCryptoClientStream(server_id_, session_.get(), NULL, | 126 stream_.reset(new QuicCryptoClientStream(server_id_, session_.get(), nullptr, |
| 127 &crypto_config_)); | 127 &crypto_config_)); |
| 128 | 128 |
| 129 session_->SetCryptoStream(stream_.get()); | 129 session_->SetCryptoStream(stream_.get()); |
| 130 session_->config()->SetDefaults(); | 130 session_->config()->SetDefaults(); |
| 131 | 131 |
| 132 // Advance time 5 years to ensure that we pass the expiry time of the cached | 132 // Advance time 5 years to ensure that we pass the expiry time of the cached |
| 133 // server config. | 133 // server config. |
| 134 reinterpret_cast<MockClock*>(const_cast<QuicClock*>(connection_->clock())) | 134 reinterpret_cast<MockClock*>(const_cast<QuicClock*>(connection_->clock())) |
| 135 ->AdvanceTime(QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); | 135 ->AdvanceTime(QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); |
| 136 | 136 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 CryptoHandshakeMessage server_config_update; | 196 CryptoHandshakeMessage server_config_update; |
| 197 server_config_update.set_tag(kSCUP); | 197 server_config_update.set_tag(kSCUP); |
| 198 scoped_ptr<QuicData> data( | 198 scoped_ptr<QuicData> data( |
| 199 CryptoFramer::ConstructHandshakeMessage(server_config_update)); | 199 CryptoFramer::ConstructHandshakeMessage(server_config_update)); |
| 200 stream_->ProcessRawData(data->data(), data->length()); | 200 stream_->ProcessRawData(data->data(), data->length()); |
| 201 } | 201 } |
| 202 | 202 |
| 203 } // namespace | 203 } // namespace |
| 204 } // namespace test | 204 } // namespace test |
| 205 } // namespace net | 205 } // namespace net |
| OLD | NEW |