Chromium Code Reviews| 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/test_tools/crypto_test_utils.h" | 5 #include "net/quic/test_tools/crypto_test_utils.h" |
| 6 | 6 |
| 7 #include "net/quic/crypto/channel_id.h" | 7 #include "net/quic/crypto/channel_id.h" |
| 8 #include "net/quic/crypto/common_cert_set.h" | 8 #include "net/quic/crypto/common_cert_set.h" |
| 9 #include "net/quic/crypto/crypto_handshake.h" | 9 #include "net/quic/crypto/crypto_handshake.h" |
| 10 #include "net/quic/crypto/quic_crypto_server_config.h" | 10 #include "net/quic/crypto/quic_crypto_server_config.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 *value = c - 'a' + 10; | 117 *value = c - 'a' + 10; |
| 118 return true; | 118 return true; |
| 119 } | 119 } |
| 120 if (c >= 'A' && c <= 'F') { | 120 if (c >= 'A' && c <= 'F') { |
| 121 *value = c - 'A' + 10; | 121 *value = c - 'A' + 10; |
| 122 return true; | 122 return true; |
| 123 } | 123 } |
| 124 return false; | 124 return false; |
| 125 } | 125 } |
| 126 | 126 |
| 127 // A ChannelIDSource that works in async mode unless the |callback| argument | |
| 128 // to GetChannelIDKey is NULL. | |
| 129 class AsyncTestChannelIDSource : public ChannelIDSource, | |
| 130 public CryptoTestUtils::TaskSource { | |
| 131 public: | |
| 132 // Takes ownership of |sync_source|. | |
| 133 explicit AsyncTestChannelIDSource(ChannelIDSource* sync_source) | |
| 134 : sync_source_(sync_source) {} | |
| 135 virtual ~AsyncTestChannelIDSource() {} | |
| 136 | |
| 137 // ChannelIDSource implementation. | |
| 138 virtual QuicAsyncStatus GetChannelIDKey( | |
| 139 const string& hostname, | |
| 140 scoped_ptr<ChannelIDKey>* channel_id_key, | |
| 141 ChannelIDSourceCallback* callback) OVERRIDE { | |
| 142 if (!callback) { | |
| 143 return sync_source_->GetChannelIDKey(hostname, channel_id_key, NULL); | |
| 144 } | |
| 145 | |
| 146 QuicAsyncStatus status = | |
| 147 sync_source_->GetChannelIDKey(hostname, &channel_id_key_, NULL); | |
| 148 if (status != QUIC_SUCCESS) { | |
| 149 return QUIC_FAILURE; | |
| 150 } | |
| 151 callback_.reset(callback); | |
| 152 return QUIC_PENDING; | |
| 153 } | |
| 154 | |
| 155 // TaskSource implementation. | |
| 156 virtual void RunPending() OVERRIDE { | |
| 157 if (callback_.get()) { | |
| 158 callback_->Run(&channel_id_key_); | |
| 159 callback_.reset(); | |
| 160 } | |
| 161 } | |
| 162 | |
| 163 private: | |
| 164 scoped_ptr<ChannelIDSource> sync_source_; | |
| 165 scoped_ptr<ChannelIDSourceCallback> callback_; | |
| 166 scoped_ptr<ChannelIDKey> channel_id_key_; | |
| 167 }; | |
| 168 | |
| 127 } // anonymous namespace | 169 } // anonymous namespace |
| 128 | 170 |
| 129 CryptoTestUtils::FakeClientOptions::FakeClientOptions() | 171 CryptoTestUtils::FakeClientOptions::FakeClientOptions() |
| 130 : dont_verify_certs(false), | 172 : dont_verify_certs(false), |
| 131 channel_id_enabled(false) { | 173 channel_id_enabled(false), |
| 174 channel_id_source_async(false) { | |
| 132 } | 175 } |
| 133 | 176 |
| 134 // static | 177 // static |
| 135 int CryptoTestUtils::HandshakeWithFakeServer( | 178 int CryptoTestUtils::HandshakeWithFakeServer( |
| 136 PacketSavingConnection* client_conn, | 179 PacketSavingConnection* client_conn, |
| 137 QuicCryptoClientStream* client) { | 180 QuicCryptoClientStream* client) { |
| 138 PacketSavingConnection* server_conn = | 181 PacketSavingConnection* server_conn = |
| 139 new PacketSavingConnection(true, client_conn->supported_versions()); | 182 new PacketSavingConnection(true, client_conn->supported_versions()); |
| 140 TestSession server_session(server_conn, DefaultQuicConfig()); | 183 TestSession server_session(server_conn, DefaultQuicConfig()); |
| 141 | 184 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 169 QuicCryptoClientConfig crypto_config; | 212 QuicCryptoClientConfig crypto_config; |
| 170 | 213 |
| 171 client_session.config()->SetDefaults(); | 214 client_session.config()->SetDefaults(); |
| 172 crypto_config.SetDefaults(); | 215 crypto_config.SetDefaults(); |
| 173 if (!options.dont_verify_certs) { | 216 if (!options.dont_verify_certs) { |
| 174 // TODO(wtc): replace this with ProofVerifierForTesting() when we have | 217 // TODO(wtc): replace this with ProofVerifierForTesting() when we have |
| 175 // a working ProofSourceForTesting(). | 218 // a working ProofSourceForTesting(). |
| 176 crypto_config.SetProofVerifier(FakeProofVerifierForTesting()); | 219 crypto_config.SetProofVerifier(FakeProofVerifierForTesting()); |
| 177 } | 220 } |
| 178 bool is_https = false; | 221 bool is_https = false; |
| 222 AsyncTestChannelIDSource* async_channel_id_source = NULL; | |
| 179 if (options.channel_id_enabled) { | 223 if (options.channel_id_enabled) { |
| 180 is_https = true; | 224 is_https = true; |
| 181 crypto_config.SetChannelIDSource(ChannelIDSourceForTesting()); | 225 |
| 226 ChannelIDSource* source = ChannelIDSourceForTesting(); | |
| 227 if (options.channel_id_source_async) { | |
| 228 async_channel_id_source = new AsyncTestChannelIDSource(source); | |
| 229 source = async_channel_id_source; | |
| 230 } | |
| 231 crypto_config.SetChannelIDSource(source); | |
| 182 } | 232 } |
| 183 QuicServerId server_id(kServerHostname, kServerPort, is_https, | 233 QuicServerId server_id(kServerHostname, kServerPort, is_https, |
| 184 PRIVACY_MODE_DISABLED); | 234 PRIVACY_MODE_DISABLED); |
| 185 QuicCryptoClientStream client(server_id, &client_session, | 235 QuicCryptoClientStream client(server_id, &client_session, |
| 186 ProofVerifyContextForTesting(), | 236 ProofVerifyContextForTesting(), |
| 187 &crypto_config); | 237 &crypto_config); |
| 188 client_session.SetCryptoStream(&client); | 238 client_session.SetCryptoStream(&client); |
| 189 | 239 |
| 190 CHECK(client.CryptoConnect()); | 240 CHECK(client.CryptoConnect()); |
| 191 CHECK_EQ(1u, client_conn->packets_.size()); | 241 CHECK_EQ(1u, client_conn->packets_.size()); |
| 192 | 242 |
| 193 CommunicateHandshakeMessages(client_conn, &client, server_conn, server); | 243 CommunicateHandshakeMessages( |
| 244 client_conn, &client, server_conn, server, async_channel_id_source); | |
| 194 | 245 |
| 195 CompareClientAndServerKeys(&client, server); | 246 CompareClientAndServerKeys(&client, server); |
| 196 | 247 |
| 197 if (options.channel_id_enabled) { | 248 if (options.channel_id_enabled) { |
| 198 scoped_ptr<ChannelIDKey> channel_id_key; | 249 scoped_ptr<ChannelIDKey> channel_id_key; |
| 199 QuicAsyncStatus status = | 250 QuicAsyncStatus status = |
| 200 crypto_config.channel_id_source()->GetChannelIDKey(kServerHostname, | 251 crypto_config.channel_id_source()->GetChannelIDKey(kServerHostname, |
| 201 &channel_id_key, | 252 &channel_id_key, |
| 202 NULL); | 253 NULL); |
| 203 EXPECT_EQ(QUIC_SUCCESS, status); | 254 EXPECT_EQ(QUIC_SUCCESS, status); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 219 options.channel_id_enabled = true; | 270 options.channel_id_enabled = true; |
| 220 scoped_ptr<CryptoHandshakeMessage> scfg( | 271 scoped_ptr<CryptoHandshakeMessage> scfg( |
| 221 crypto_config->AddDefaultConfig(rand, clock, options)); | 272 crypto_config->AddDefaultConfig(rand, clock, options)); |
| 222 } | 273 } |
| 223 | 274 |
| 224 // static | 275 // static |
| 225 void CryptoTestUtils::CommunicateHandshakeMessages( | 276 void CryptoTestUtils::CommunicateHandshakeMessages( |
| 226 PacketSavingConnection* a_conn, | 277 PacketSavingConnection* a_conn, |
| 227 QuicCryptoStream* a, | 278 QuicCryptoStream* a, |
| 228 PacketSavingConnection* b_conn, | 279 PacketSavingConnection* b_conn, |
| 229 QuicCryptoStream* b) { | 280 QuicCryptoStream* b, |
| 281 TaskSource* task_source) { | |
| 230 size_t a_i = 0, b_i = 0; | 282 size_t a_i = 0, b_i = 0; |
| 231 while (!a->handshake_confirmed()) { | 283 while (!a->handshake_confirmed()) { |
| 284 if (task_source) { | |
| 285 task_source->RunPending(); | |
| 286 } | |
| 232 ASSERT_GT(a_conn->packets_.size(), a_i); | 287 ASSERT_GT(a_conn->packets_.size(), a_i); |
| 233 LOG(INFO) << "Processing " << a_conn->packets_.size() - a_i | 288 LOG(INFO) << "Processing " << a_conn->packets_.size() - a_i |
| 234 << " packets a->b"; | 289 << " packets a->b"; |
| 235 MovePackets(a_conn, &a_i, b, b_conn); | 290 MovePackets(a_conn, &a_i, b, b_conn); |
| 236 | 291 |
| 292 if (task_source) { | |
| 293 task_source->RunPending(); | |
| 294 } | |
| 237 ASSERT_GT(b_conn->packets_.size(), b_i); | 295 ASSERT_GT(b_conn->packets_.size(), b_i); |
| 238 LOG(INFO) << "Processing " << b_conn->packets_.size() - b_i | 296 LOG(INFO) << "Processing " << b_conn->packets_.size() - b_i |
| 239 << " packets b->a"; | 297 << " packets b->a"; |
| 240 if (b_conn->packets_.size() - b_i == 2) { | |
| 241 LOG(INFO) << "here"; | |
|
wtc
2014/07/09 01:03:52
This looks like a debugging message that Adam forg
| |
| 242 } | |
| 243 MovePackets(b_conn, &b_i, a, a_conn); | 298 MovePackets(b_conn, &b_i, a, a_conn); |
| 244 } | 299 } |
| 245 } | 300 } |
| 246 | 301 |
| 247 // static | 302 // static |
| 248 pair<size_t, size_t> CryptoTestUtils::AdvanceHandshake( | 303 pair<size_t, size_t> CryptoTestUtils::AdvanceHandshake( |
| 249 PacketSavingConnection* a_conn, | 304 PacketSavingConnection* a_conn, |
| 250 QuicCryptoStream* a, | 305 QuicCryptoStream* a, |
| 251 size_t a_i, | 306 size_t a_i, |
| 252 PacketSavingConnection* b_conn, | 307 PacketSavingConnection* b_conn, |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 scoped_ptr<QuicData> bytes(CryptoFramer::ConstructHandshakeMessage(msg)); | 580 scoped_ptr<QuicData> bytes(CryptoFramer::ConstructHandshakeMessage(msg)); |
| 526 scoped_ptr<CryptoHandshakeMessage> parsed( | 581 scoped_ptr<CryptoHandshakeMessage> parsed( |
| 527 CryptoFramer::ParseMessage(bytes->AsStringPiece())); | 582 CryptoFramer::ParseMessage(bytes->AsStringPiece())); |
| 528 CHECK(parsed.get()); | 583 CHECK(parsed.get()); |
| 529 | 584 |
| 530 return *parsed; | 585 return *parsed; |
| 531 } | 586 } |
| 532 | 587 |
| 533 } // namespace test | 588 } // namespace test |
| 534 } // namespace net | 589 } // namespace net |
| OLD | NEW |