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