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/core/quic_crypto_client_stream.h" | 5 #include "net/quic/core/quic_crypto_client_stream.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" | 9 #include "net/quic/core/crypto/aes_128_gcm_12_encrypter.h" |
10 #include "net/quic/core/crypto/quic_decrypter.h" | 10 #include "net/quic/core/crypto/quic_decrypter.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 class QuicCryptoClientStreamTest : public ::testing::Test { | 34 class QuicCryptoClientStreamTest : public ::testing::Test { |
35 public: | 35 public: |
36 QuicCryptoClientStreamTest() | 36 QuicCryptoClientStreamTest() |
37 : server_id_(kServerHostname, kServerPort, PRIVACY_MODE_DISABLED), | 37 : server_id_(kServerHostname, kServerPort, PRIVACY_MODE_DISABLED), |
38 crypto_config_(CryptoTestUtils::ProofVerifierForTesting()) { | 38 crypto_config_(CryptoTestUtils::ProofVerifierForTesting()) { |
39 CreateConnection(); | 39 CreateConnection(); |
40 } | 40 } |
41 | 41 |
42 void CreateConnection() { | 42 void CreateConnection() { |
43 connection_ = new PacketSavingConnection(&helper_, &alarm_factory_, | 43 connection_ = new PacketSavingConnection(&client_helper_, &alarm_factory_, |
44 Perspective::IS_CLIENT); | 44 Perspective::IS_CLIENT); |
45 // Advance the time, because timers do not like uninitialized times. | 45 // Advance the time, because timers do not like uninitialized times. |
46 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); | 46 connection_->AdvanceTime(QuicTime::Delta::FromSeconds(1)); |
47 | 47 |
48 session_.reset(new TestQuicSpdyClientSession( | 48 session_.reset(new TestQuicSpdyClientSession( |
49 connection_, DefaultQuicConfig(), server_id_, &crypto_config_)); | 49 connection_, DefaultQuicConfig(), server_id_, &crypto_config_)); |
50 } | 50 } |
51 | 51 |
52 void CompleteCryptoHandshake() { | 52 void CompleteCryptoHandshake() { |
53 stream()->CryptoConnect(); | 53 stream()->CryptoConnect(); |
54 QuicConfig config; | 54 QuicConfig config; |
55 CryptoTestUtils::HandshakeWithFakeServer(&config, &helper_, &alarm_factory_, | 55 CryptoTestUtils::HandshakeWithFakeServer(&config, &server_helper_, |
56 connection_, stream(), | 56 &alarm_factory_, connection_, |
57 server_options_); | 57 stream(), server_options_); |
58 } | 58 } |
59 | 59 |
60 void ConstructHandshakeMessage() { | 60 void ConstructHandshakeMessage() { |
61 CryptoFramer framer; | 61 CryptoFramer framer; |
62 message_data_.reset(framer.ConstructHandshakeMessage(message_)); | 62 message_data_.reset(framer.ConstructHandshakeMessage(message_)); |
63 } | 63 } |
64 | 64 |
65 QuicCryptoClientStream* stream() { return session_->GetCryptoStream(); } | 65 QuicCryptoClientStream* stream() { return session_->GetCryptoStream(); } |
66 | 66 |
67 MockQuicConnectionHelper helper_; | 67 MockQuicConnectionHelper server_helper_; |
| 68 MockQuicConnectionHelper client_helper_; |
68 MockAlarmFactory alarm_factory_; | 69 MockAlarmFactory alarm_factory_; |
69 PacketSavingConnection* connection_; | 70 PacketSavingConnection* connection_; |
70 std::unique_ptr<TestQuicSpdyClientSession> session_; | 71 std::unique_ptr<TestQuicSpdyClientSession> session_; |
71 QuicServerId server_id_; | 72 QuicServerId server_id_; |
72 CryptoHandshakeMessage message_; | 73 CryptoHandshakeMessage message_; |
73 std::unique_ptr<QuicData> message_data_; | 74 std::unique_ptr<QuicData> message_data_; |
74 QuicCryptoClientConfig crypto_config_; | 75 QuicCryptoClientConfig crypto_config_; |
75 CryptoTestUtils::FakeServerOptions server_options_; | 76 CryptoTestUtils::FakeServerOptions server_options_; |
76 }; | 77 }; |
77 | 78 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 CreateConnection(); | 135 CreateConnection(); |
135 | 136 |
136 // Advance time 5 years to ensure that we pass the expiry time of the cached | 137 // Advance time 5 years to ensure that we pass the expiry time of the cached |
137 // server config. | 138 // server config. |
138 connection_->AdvanceTime( | 139 connection_->AdvanceTime( |
139 QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); | 140 QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); |
140 | 141 |
141 stream()->CryptoConnect(); | 142 stream()->CryptoConnect(); |
142 // Check that a client hello was sent. | 143 // Check that a client hello was sent. |
143 ASSERT_EQ(1u, connection_->encrypted_packets_.size()); | 144 ASSERT_EQ(1u, connection_->encrypted_packets_.size()); |
| 145 EXPECT_EQ(ENCRYPTION_NONE, connection_->encryption_level()); |
| 146 } |
| 147 |
| 148 TEST_F(QuicCryptoClientStreamTest, ClockSkew) { |
| 149 FLAGS_quic_send_scfg_ttl = true; |
| 150 // Test that if the client's clock is skewed with respect to the server, |
| 151 // the handshake succeeds. In the past, the client would get the server |
| 152 // config, notice that it had already expired and then close the connection. |
| 153 |
| 154 // Advance time 5 years to ensure that we pass the expiry time in the server |
| 155 // config, but the TTL is used instead. |
| 156 connection_->AdvanceTime( |
| 157 QuicTime::Delta::FromSeconds(60 * 60 * 24 * 365 * 5)); |
| 158 |
| 159 // The handshakes completes! |
| 160 CompleteCryptoHandshake(); |
144 } | 161 } |
145 | 162 |
146 TEST_F(QuicCryptoClientStreamTest, InvalidCachedServerConfig) { | 163 TEST_F(QuicCryptoClientStreamTest, InvalidCachedServerConfig) { |
147 // Seed the config with a cached server config. | 164 // Seed the config with a cached server config. |
148 CompleteCryptoHandshake(); | 165 CompleteCryptoHandshake(); |
149 | 166 |
150 // Recreate connection with the new config. | 167 // Recreate connection with the new config. |
151 CreateConnection(); | 168 CreateConnection(); |
152 | 169 |
153 QuicCryptoClientConfig::CachedState* state = | 170 QuicCryptoClientConfig::CachedState* state = |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 0x45, 0x58, 0x50, 0x59, | 207 0x45, 0x58, 0x50, 0x59, |
191 // EXPY end offset | 208 // EXPY end offset |
192 0x08, 0x00, 0x00, 0x00, | 209 0x08, 0x00, 0x00, 0x00, |
193 // Value | 210 // Value |
194 '1', '2', '3', '4', '5', '6', '7', '8'}; | 211 '1', '2', '3', '4', '5', '6', '7', '8'}; |
195 | 212 |
196 CryptoHandshakeMessage server_config_update; | 213 CryptoHandshakeMessage server_config_update; |
197 server_config_update.set_tag(kSCUP); | 214 server_config_update.set_tag(kSCUP); |
198 server_config_update.SetValue(kSourceAddressTokenTag, stk); | 215 server_config_update.SetValue(kSourceAddressTokenTag, stk); |
199 server_config_update.SetValue(kSCFG, scfg); | 216 server_config_update.SetValue(kSCFG, scfg); |
| 217 const uint64_t expiry_seconds = 60 * 60 * 24 * 2; |
| 218 server_config_update.SetValue(kSTTL, expiry_seconds); |
200 | 219 |
201 std::unique_ptr<QuicData> data( | 220 std::unique_ptr<QuicData> data( |
202 CryptoFramer::ConstructHandshakeMessage(server_config_update)); | 221 CryptoFramer::ConstructHandshakeMessage(server_config_update)); |
203 stream()->OnStreamFrame(QuicStreamFrame(kCryptoStreamId, /*fin=*/false, | 222 stream()->OnStreamFrame(QuicStreamFrame(kCryptoStreamId, /*fin=*/false, |
204 /*offset=*/0, data->AsStringPiece())); | 223 /*offset=*/0, data->AsStringPiece())); |
205 | 224 |
206 // Make sure that the STK and SCFG are cached correctly. | 225 // Make sure that the STK and SCFG are cached correctly. |
207 EXPECT_EQ("xstk", state->source_address_token()); | 226 EXPECT_EQ("xstk", state->source_address_token()); |
208 | 227 |
209 string cached_scfg = state->server_config(); | 228 string cached_scfg = state->server_config(); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 client_state->GetNextServerDesignatedConnectionId(); | 374 client_state->GetNextServerDesignatedConnectionId(); |
356 QuicConnectionId expected_id = | 375 QuicConnectionId expected_id = |
357 server_session_->connection()->random_generator()->RandUint64(); | 376 server_session_->connection()->random_generator()->RandUint64(); |
358 EXPECT_EQ(expected_id, server_designated_id); | 377 EXPECT_EQ(expected_id, server_designated_id); |
359 EXPECT_FALSE(client_state->has_server_designated_connection_id()); | 378 EXPECT_FALSE(client_state->has_server_designated_connection_id()); |
360 } | 379 } |
361 | 380 |
362 } // namespace | 381 } // namespace |
363 } // namespace test | 382 } // namespace test |
364 } // namespace net | 383 } // namespace net |
OLD | NEW |