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_protocol.h" | 11 #include "net/quic/quic_protocol.h" |
12 #include "net/quic/test_tools/crypto_test_utils.h" | 12 #include "net/quic/test_tools/crypto_test_utils.h" |
13 #include "net/quic/test_tools/quic_test_utils.h" | 13 #include "net/quic/test_tools/quic_test_utils.h" |
14 #include "net/quic/test_tools/simple_quic_framer.h" | 14 #include "net/quic/test_tools/simple_quic_framer.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 namespace test { | 19 namespace test { |
20 namespace { | 20 namespace { |
21 | 21 |
22 const char kServerHostname[] = "example.com"; | 22 const char kServerHostname[] = "example.com"; |
| 23 const uint16 kServerPort = 80; |
23 | 24 |
24 class QuicCryptoClientStreamTest : public ::testing::Test { | 25 class QuicCryptoClientStreamTest : public ::testing::Test { |
25 public: | 26 public: |
26 QuicCryptoClientStreamTest() | 27 QuicCryptoClientStreamTest() |
27 : connection_(new PacketSavingConnection(false)), | 28 : connection_(new PacketSavingConnection(false)), |
28 session_(new TestSession(connection_, DefaultQuicConfig())), | 29 session_(new TestSession(connection_, DefaultQuicConfig())), |
29 stream_(new QuicCryptoClientStream(kServerHostname, session_.get(), | 30 stream_(new QuicCryptoClientStream(kServerHostname, kServerPort, |
30 &crypto_config_)) { | 31 session_.get(), &crypto_config_)) { |
31 session_->SetCryptoStream(stream_.get()); | 32 session_->SetCryptoStream(stream_.get()); |
32 crypto_config_.SetDefaults(); | 33 crypto_config_.SetDefaults(); |
33 } | 34 } |
34 | 35 |
35 void CompleteCryptoHandshake() { | 36 void CompleteCryptoHandshake() { |
36 EXPECT_TRUE(stream_->CryptoConnect()); | 37 EXPECT_TRUE(stream_->CryptoConnect()); |
37 CryptoTestUtils::HandshakeWithFakeServer(connection_, stream_.get()); | 38 CryptoTestUtils::HandshakeWithFakeServer(connection_, stream_.get()); |
38 } | 39 } |
39 | 40 |
40 void ConstructHandshakeMessage() { | 41 void ConstructHandshakeMessage() { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 config->max_streams_per_connection()); | 95 config->max_streams_per_connection()); |
95 EXPECT_EQ(0, config->keepalive_timeout().ToSeconds()); | 96 EXPECT_EQ(0, config->keepalive_timeout().ToSeconds()); |
96 | 97 |
97 const QuicCryptoNegotiatedParameters& crypto_params( | 98 const QuicCryptoNegotiatedParameters& crypto_params( |
98 stream_->crypto_negotiated_params()); | 99 stream_->crypto_negotiated_params()); |
99 EXPECT_EQ(kAESG, crypto_params.aead); | 100 EXPECT_EQ(kAESG, crypto_params.aead); |
100 EXPECT_EQ(kC255, crypto_params.key_exchange); | 101 EXPECT_EQ(kC255, crypto_params.key_exchange); |
101 } | 102 } |
102 | 103 |
103 TEST_F(QuicCryptoClientStreamTest, InvalidHostname) { | 104 TEST_F(QuicCryptoClientStreamTest, InvalidHostname) { |
104 stream_.reset(new QuicCryptoClientStream("invalid", session_.get(), | 105 stream_.reset(new QuicCryptoClientStream("invalid", kServerPort, |
105 &crypto_config_)); | 106 session_.get(), &crypto_config_)); |
106 session_->SetCryptoStream(stream_.get()); | 107 session_->SetCryptoStream(stream_.get()); |
107 | 108 |
108 CompleteCryptoHandshake(); | 109 CompleteCryptoHandshake(); |
109 EXPECT_TRUE(stream_->encryption_established()); | 110 EXPECT_TRUE(stream_->encryption_established()); |
110 EXPECT_TRUE(stream_->handshake_confirmed()); | 111 EXPECT_TRUE(stream_->handshake_confirmed()); |
111 } | 112 } |
112 | 113 |
113 TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) { | 114 TEST_F(QuicCryptoClientStreamTest, ExpiredServerConfig) { |
114 // Seed the config with a cached server config. | 115 // Seed the config with a cached server config. |
115 CompleteCryptoHandshake(); | 116 CompleteCryptoHandshake(); |
116 | 117 |
117 connection_ = new PacketSavingConnection(true); | 118 connection_ = new PacketSavingConnection(true); |
118 session_.reset(new TestSession(connection_, DefaultQuicConfig())); | 119 session_.reset(new TestSession(connection_, DefaultQuicConfig())); |
119 stream_.reset(new QuicCryptoClientStream(kServerHostname, session_.get(), | 120 stream_.reset(new QuicCryptoClientStream(kServerHostname, kServerPort, |
120 &crypto_config_)); | 121 session_.get(), &crypto_config_)); |
121 | 122 |
122 session_->SetCryptoStream(stream_.get()); | 123 session_->SetCryptoStream(stream_.get()); |
123 session_->config()->SetDefaults(); | 124 session_->config()->SetDefaults(); |
124 | 125 |
125 // 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 |
126 // server config. | 127 // server config. |
127 reinterpret_cast<MockClock*>(const_cast<QuicClock*>(connection_->clock())) | 128 reinterpret_cast<MockClock*>(const_cast<QuicClock*>(connection_->clock())) |
128 ->AdvanceTime(QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); | 129 ->AdvanceTime(QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); |
129 | 130 |
130 // Check that a client hello was sent and that CryptoConnect doesn't fail | 131 // Check that a client hello was sent and that CryptoConnect doesn't fail |
131 // with an error. | 132 // with an error. |
132 EXPECT_TRUE(stream_->CryptoConnect()); | 133 EXPECT_TRUE(stream_->CryptoConnect()); |
133 ASSERT_EQ(1u, connection_->packets_.size()); | 134 ASSERT_EQ(1u, connection_->packets_.size()); |
134 } | 135 } |
135 | 136 |
136 } // namespace | 137 } // namespace |
137 } // namespace test | 138 } // namespace test |
138 } // namespace net | 139 } // namespace net |
OLD | NEW |