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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 class QuicCryptoServerStreamTest : public testing::TestWithParam<bool> { | 52 class QuicCryptoServerStreamTest : public testing::TestWithParam<bool> { |
53 public: | 53 public: |
54 QuicCryptoServerStreamTest() | 54 QuicCryptoServerStreamTest() |
55 : guid_(1), | 55 : connection_(new PacketSavingConnection(true)), |
56 addr_(ParseIPLiteralToNumber("192.0.2.33", &ip_) ? | |
57 ip_ : IPAddressNumber(), 1), | |
58 connection_(new PacketSavingConnection(guid_, addr_, true)), | |
59 session_(connection_, DefaultQuicConfig(), true), | 56 session_(connection_, DefaultQuicConfig(), true), |
60 crypto_config_(QuicCryptoServerConfig::TESTING, | 57 crypto_config_(QuicCryptoServerConfig::TESTING, |
61 QuicRandom::GetInstance()), | 58 QuicRandom::GetInstance()), |
62 stream_(crypto_config_, &session_), | 59 stream_(crypto_config_, &session_), |
63 strike_register_client_(NULL) { | 60 strike_register_client_(NULL) { |
64 config_.SetDefaults(); | 61 config_.SetDefaults(); |
65 session_.config()->SetDefaults(); | 62 session_.config()->SetDefaults(); |
66 session_.SetCryptoStream(&stream_); | 63 session_.SetCryptoStream(&stream_); |
67 // We advance the clock initially because the default time is zero and the | 64 // 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. | 65 // strike register worries that we've just overflowed a uint32 time. |
(...skipping 28 matching lines...) Expand all Loading... |
97 CryptoFramer framer; | 94 CryptoFramer framer; |
98 message_data_.reset(framer.ConstructHandshakeMessage(message_)); | 95 message_data_.reset(framer.ConstructHandshakeMessage(message_)); |
99 } | 96 } |
100 | 97 |
101 int CompleteCryptoHandshake() { | 98 int CompleteCryptoHandshake() { |
102 return CryptoTestUtils::HandshakeWithFakeClient(connection_, &stream_, | 99 return CryptoTestUtils::HandshakeWithFakeClient(connection_, &stream_, |
103 client_options_); | 100 client_options_); |
104 } | 101 } |
105 | 102 |
106 protected: | 103 protected: |
107 IPAddressNumber ip_; | |
108 QuicGuid guid_; | |
109 IPEndPoint addr_; | |
110 PacketSavingConnection* connection_; | 104 PacketSavingConnection* connection_; |
111 TestSession session_; | 105 TestSession session_; |
112 QuicConfig config_; | 106 QuicConfig config_; |
113 QuicCryptoServerConfig crypto_config_; | 107 QuicCryptoServerConfig crypto_config_; |
114 QuicCryptoServerStream stream_; | 108 QuicCryptoServerStream stream_; |
115 CryptoHandshakeMessage message_; | 109 CryptoHandshakeMessage message_; |
116 scoped_ptr<QuicData> message_data_; | 110 scoped_ptr<QuicData> message_data_; |
117 CryptoTestUtils::FakeClientOptions client_options_; | 111 CryptoTestUtils::FakeClientOptions client_options_; |
118 DelayedVerifyStrikeRegisterClient* strike_register_client_; | 112 DelayedVerifyStrikeRegisterClient* strike_register_client_; |
119 }; | 113 }; |
120 | 114 |
121 INSTANTIATE_TEST_CASE_P(Tests, QuicCryptoServerStreamTest, testing::Bool()); | 115 INSTANTIATE_TEST_CASE_P(Tests, QuicCryptoServerStreamTest, testing::Bool()); |
122 | 116 |
123 TEST_P(QuicCryptoServerStreamTest, NotInitiallyConected) { | 117 TEST_P(QuicCryptoServerStreamTest, NotInitiallyConected) { |
124 EXPECT_FALSE(stream_.encryption_established()); | 118 EXPECT_FALSE(stream_.encryption_established()); |
125 EXPECT_FALSE(stream_.handshake_confirmed()); | 119 EXPECT_FALSE(stream_.handshake_confirmed()); |
126 } | 120 } |
127 | 121 |
128 TEST_P(QuicCryptoServerStreamTest, ConnectedAfterCHLO) { | 122 TEST_P(QuicCryptoServerStreamTest, ConnectedAfterCHLO) { |
129 // CompleteCryptoHandshake returns the number of client hellos sent. This | 123 // CompleteCryptoHandshake returns the number of client hellos sent. This |
130 // test should send: | 124 // test should send: |
131 // * One to get a source-address token and certificates. | 125 // * One to get a source-address token and certificates. |
132 // * One to complete the handshake. | 126 // * One to complete the handshake. |
133 EXPECT_EQ(2, CompleteCryptoHandshake()); | 127 EXPECT_EQ(2, CompleteCryptoHandshake()); |
134 EXPECT_TRUE(stream_.encryption_established()); | 128 EXPECT_TRUE(stream_.encryption_established()); |
135 EXPECT_TRUE(stream_.handshake_confirmed()); | 129 EXPECT_TRUE(stream_.handshake_confirmed()); |
136 } | 130 } |
137 | 131 |
138 TEST_P(QuicCryptoServerStreamTest, ZeroRTT) { | 132 TEST_P(QuicCryptoServerStreamTest, ZeroRTT) { |
139 QuicGuid guid(1); | 133 PacketSavingConnection* client_conn = new PacketSavingConnection(false); |
140 IPAddressNumber ip; | 134 PacketSavingConnection* server_conn = new PacketSavingConnection(false); |
141 ParseIPLiteralToNumber("127.0.0.1", &ip); | |
142 IPEndPoint addr(ip, 0); | |
143 PacketSavingConnection* client_conn = | |
144 new PacketSavingConnection(guid, addr, false); | |
145 PacketSavingConnection* server_conn = | |
146 new PacketSavingConnection(guid, addr, false); | |
147 client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(100000)); | 135 client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(100000)); |
148 server_conn->AdvanceTime(QuicTime::Delta::FromSeconds(100000)); | 136 server_conn->AdvanceTime(QuicTime::Delta::FromSeconds(100000)); |
149 | 137 |
150 QuicConfig client_config; | 138 QuicConfig client_config; |
151 client_config.SetDefaults(); | 139 client_config.SetDefaults(); |
152 scoped_ptr<TestSession> client_session( | 140 scoped_ptr<TestSession> client_session( |
153 new TestSession(client_conn, client_config, false)); | 141 new TestSession(client_conn, client_config, false)); |
154 QuicCryptoClientConfig client_crypto_config; | 142 QuicCryptoClientConfig client_crypto_config; |
155 client_crypto_config.SetDefaults(); | 143 client_crypto_config.SetDefaults(); |
156 | 144 |
(...skipping 12 matching lines...) Expand all Loading... |
169 new QuicCryptoServerStream(crypto_config_, server_session.get())); | 157 new QuicCryptoServerStream(crypto_config_, server_session.get())); |
170 server_session->SetCryptoStream(server.get()); | 158 server_session->SetCryptoStream(server.get()); |
171 | 159 |
172 CryptoTestUtils::CommunicateHandshakeMessages( | 160 CryptoTestUtils::CommunicateHandshakeMessages( |
173 client_conn, client.get(), server_conn, server.get()); | 161 client_conn, client.get(), server_conn, server.get()); |
174 EXPECT_EQ(2, client->num_sent_client_hellos()); | 162 EXPECT_EQ(2, client->num_sent_client_hellos()); |
175 | 163 |
176 // Now do another handshake, hopefully in 0-RTT. | 164 // Now do another handshake, hopefully in 0-RTT. |
177 LOG(INFO) << "Resetting for 0-RTT handshake attempt"; | 165 LOG(INFO) << "Resetting for 0-RTT handshake attempt"; |
178 | 166 |
179 client_conn = new PacketSavingConnection(guid, addr, false); | 167 client_conn = new PacketSavingConnection(false); |
180 server_conn = new PacketSavingConnection(guid, addr, false); | 168 server_conn = new PacketSavingConnection(false); |
181 // We need to advance time past the strike-server window so that it's | 169 // We need to advance time past the strike-server window so that it's |
182 // authoritative in this time span. | 170 // authoritative in this time span. |
183 client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(102000)); | 171 client_conn->AdvanceTime(QuicTime::Delta::FromSeconds(102000)); |
184 server_conn->AdvanceTime(QuicTime::Delta::FromSeconds(102000)); | 172 server_conn->AdvanceTime(QuicTime::Delta::FromSeconds(102000)); |
185 | 173 |
186 // This causes the client's nonce to be different and thus stops the | 174 // This causes the client's nonce to be different and thus stops the |
187 // strike-register from rejecting the repeated nonce. | 175 // strike-register from rejecting the repeated nonce. |
188 reinterpret_cast<MockRandom*>(client_conn->random_generator())->ChangeValue(); | 176 reinterpret_cast<MockRandom*>(client_conn->random_generator())->ChangeValue(); |
189 client_session.reset(new TestSession(client_conn, client_config, false)); | 177 client_session.reset(new TestSession(client_conn, client_config, false)); |
190 server_session.reset(new TestSession(server_conn, config_, true)); | 178 server_session.reset(new TestSession(server_conn, config_, true)); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 // CompleteCryptoHandshake verifies | 254 // CompleteCryptoHandshake verifies |
267 // stream_.crypto_negotiated_params().channel_id is correct. | 255 // stream_.crypto_negotiated_params().channel_id is correct. |
268 EXPECT_EQ(2, CompleteCryptoHandshake()); | 256 EXPECT_EQ(2, CompleteCryptoHandshake()); |
269 EXPECT_TRUE(stream_.encryption_established()); | 257 EXPECT_TRUE(stream_.encryption_established()); |
270 EXPECT_TRUE(stream_.handshake_confirmed()); | 258 EXPECT_TRUE(stream_.handshake_confirmed()); |
271 } | 259 } |
272 | 260 |
273 } // namespace | 261 } // namespace |
274 } // namespace test | 262 } // namespace test |
275 } // namespace net | 263 } // namespace net |
OLD | NEW |