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 asynchronous mode unless the |callback| | |
| 128 // argument | |
| 129 // to GetChannelIDKey is NULL. | |
|
Ryan Hamilton
2014/07/09 16:54:39
nit: can you wrap this onto the previous line?
wtc
2014/07/09 19:44:42
Done. The first line was folded by "git cl format"
| |
| 130 class AsyncTestChannelIDSource : public ChannelIDSource, | |
| 131 public CryptoTestUtils::TaskSource { | |
| 132 public: | |
| 133 // Takes ownership of |sync_source|. | |
| 134 explicit AsyncTestChannelIDSource(ChannelIDSource* sync_source) | |
| 135 : sync_source_(sync_source) {} | |
| 136 virtual ~AsyncTestChannelIDSource() {} | |
| 137 | |
| 138 // ChannelIDSource implementation. | |
| 139 virtual QuicAsyncStatus GetChannelIDKey( | |
| 140 const string& hostname, | |
| 141 scoped_ptr<ChannelIDKey>* channel_id_key, | |
| 142 ChannelIDSourceCallback* callback) OVERRIDE { | |
| 143 // Synchronous mode. | |
| 144 if (!callback) { | |
| 145 return sync_source_->GetChannelIDKey(hostname, channel_id_key, NULL); | |
| 146 } | |
| 147 | |
| 148 // Asynchronous mode. | |
| 149 QuicAsyncStatus status = | |
| 150 sync_source_->GetChannelIDKey(hostname, &channel_id_key_, NULL); | |
| 151 if (status != QUIC_SUCCESS) { | |
| 152 return QUIC_FAILURE; | |
| 153 } | |
| 154 callback_.reset(callback); | |
| 155 return QUIC_PENDING; | |
| 156 } | |
| 157 | |
| 158 // TaskSource implementation. | |
| 159 virtual void RunPending() OVERRIDE { | |
| 160 if (callback_.get()) { | |
| 161 callback_->Run(&channel_id_key_); | |
| 162 callback_.reset(); | |
| 163 } | |
| 164 } | |
| 165 | |
| 166 private: | |
| 167 scoped_ptr<ChannelIDSource> sync_source_; | |
| 168 scoped_ptr<ChannelIDSourceCallback> callback_; | |
| 169 scoped_ptr<ChannelIDKey> channel_id_key_; | |
| 170 }; | |
| 171 | |
| 127 } // anonymous namespace | 172 } // anonymous namespace |
| 128 | 173 |
| 129 CryptoTestUtils::FakeClientOptions::FakeClientOptions() | 174 CryptoTestUtils::FakeClientOptions::FakeClientOptions() |
| 130 : dont_verify_certs(false), | 175 : dont_verify_certs(false), |
| 131 channel_id_enabled(false) { | 176 channel_id_enabled(false), |
| 177 channel_id_source_async(false) { | |
| 132 } | 178 } |
| 133 | 179 |
| 134 // static | 180 // static |
| 135 int CryptoTestUtils::HandshakeWithFakeServer( | 181 int CryptoTestUtils::HandshakeWithFakeServer( |
| 136 PacketSavingConnection* client_conn, | 182 PacketSavingConnection* client_conn, |
| 137 QuicCryptoClientStream* client) { | 183 QuicCryptoClientStream* client) { |
| 138 PacketSavingConnection* server_conn = | 184 PacketSavingConnection* server_conn = |
| 139 new PacketSavingConnection(true, client_conn->supported_versions()); | 185 new PacketSavingConnection(true, client_conn->supported_versions()); |
| 140 TestSession server_session(server_conn, DefaultQuicConfig()); | 186 TestSession server_session(server_conn, DefaultQuicConfig()); |
| 141 | 187 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 169 QuicCryptoClientConfig crypto_config; | 215 QuicCryptoClientConfig crypto_config; |
| 170 | 216 |
| 171 client_session.config()->SetDefaults(); | 217 client_session.config()->SetDefaults(); |
| 172 crypto_config.SetDefaults(); | 218 crypto_config.SetDefaults(); |
| 173 if (!options.dont_verify_certs) { | 219 if (!options.dont_verify_certs) { |
| 174 // TODO(wtc): replace this with ProofVerifierForTesting() when we have | 220 // TODO(wtc): replace this with ProofVerifierForTesting() when we have |
| 175 // a working ProofSourceForTesting(). | 221 // a working ProofSourceForTesting(). |
| 176 crypto_config.SetProofVerifier(FakeProofVerifierForTesting()); | 222 crypto_config.SetProofVerifier(FakeProofVerifierForTesting()); |
| 177 } | 223 } |
| 178 bool is_https = false; | 224 bool is_https = false; |
| 225 AsyncTestChannelIDSource* async_channel_id_source = NULL; | |
| 179 if (options.channel_id_enabled) { | 226 if (options.channel_id_enabled) { |
| 180 is_https = true; | 227 is_https = true; |
| 181 crypto_config.SetChannelIDSource(ChannelIDSourceForTesting()); | 228 |
| 229 ChannelIDSource* source = ChannelIDSourceForTesting(); | |
| 230 if (options.channel_id_source_async) { | |
| 231 async_channel_id_source = new AsyncTestChannelIDSource(source); | |
| 232 source = async_channel_id_source; | |
| 233 } | |
| 234 crypto_config.SetChannelIDSource(source); | |
| 182 } | 235 } |
| 183 QuicServerId server_id(kServerHostname, kServerPort, is_https, | 236 QuicServerId server_id(kServerHostname, kServerPort, is_https, |
| 184 PRIVACY_MODE_DISABLED); | 237 PRIVACY_MODE_DISABLED); |
| 185 QuicCryptoClientStream client(server_id, &client_session, | 238 QuicCryptoClientStream client(server_id, &client_session, |
| 186 ProofVerifyContextForTesting(), | 239 ProofVerifyContextForTesting(), |
| 187 &crypto_config); | 240 &crypto_config); |
| 188 client_session.SetCryptoStream(&client); | 241 client_session.SetCryptoStream(&client); |
| 189 | 242 |
| 190 CHECK(client.CryptoConnect()); | 243 CHECK(client.CryptoConnect()); |
| 191 CHECK_EQ(1u, client_conn->packets_.size()); | 244 CHECK_EQ(1u, client_conn->packets_.size()); |
| 192 | 245 |
| 193 CommunicateHandshakeMessages(client_conn, &client, server_conn, server); | 246 CommunicateHandshakeMessages( |
| 247 client_conn, &client, server_conn, server, async_channel_id_source); | |
| 194 | 248 |
| 195 CompareClientAndServerKeys(&client, server); | 249 CompareClientAndServerKeys(&client, server); |
| 196 | 250 |
| 197 if (options.channel_id_enabled) { | 251 if (options.channel_id_enabled) { |
| 198 scoped_ptr<ChannelIDKey> channel_id_key; | 252 scoped_ptr<ChannelIDKey> channel_id_key; |
| 199 QuicAsyncStatus status = | 253 QuicAsyncStatus status = |
| 200 crypto_config.channel_id_source()->GetChannelIDKey(kServerHostname, | 254 crypto_config.channel_id_source()->GetChannelIDKey(kServerHostname, |
| 201 &channel_id_key, | 255 &channel_id_key, |
| 202 NULL); | 256 NULL); |
| 203 EXPECT_EQ(QUIC_SUCCESS, status); | 257 EXPECT_EQ(QUIC_SUCCESS, status); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 219 options.channel_id_enabled = true; | 273 options.channel_id_enabled = true; |
| 220 scoped_ptr<CryptoHandshakeMessage> scfg( | 274 scoped_ptr<CryptoHandshakeMessage> scfg( |
| 221 crypto_config->AddDefaultConfig(rand, clock, options)); | 275 crypto_config->AddDefaultConfig(rand, clock, options)); |
| 222 } | 276 } |
| 223 | 277 |
| 224 // static | 278 // static |
| 225 void CryptoTestUtils::CommunicateHandshakeMessages( | 279 void CryptoTestUtils::CommunicateHandshakeMessages( |
| 226 PacketSavingConnection* a_conn, | 280 PacketSavingConnection* a_conn, |
| 227 QuicCryptoStream* a, | 281 QuicCryptoStream* a, |
| 228 PacketSavingConnection* b_conn, | 282 PacketSavingConnection* b_conn, |
| 229 QuicCryptoStream* b) { | 283 QuicCryptoStream* b, |
| 284 TaskSource* task_source) { | |
| 230 size_t a_i = 0, b_i = 0; | 285 size_t a_i = 0, b_i = 0; |
| 231 while (!a->handshake_confirmed()) { | 286 while (!a->handshake_confirmed()) { |
| 287 if (task_source) { | |
| 288 task_source->RunPending(); | |
| 289 } | |
| 232 ASSERT_GT(a_conn->packets_.size(), a_i); | 290 ASSERT_GT(a_conn->packets_.size(), a_i); |
| 233 LOG(INFO) << "Processing " << a_conn->packets_.size() - a_i | 291 LOG(INFO) << "Processing " << a_conn->packets_.size() - a_i |
| 234 << " packets a->b"; | 292 << " packets a->b"; |
| 235 MovePackets(a_conn, &a_i, b, b_conn); | 293 MovePackets(a_conn, &a_i, b, b_conn); |
| 236 | 294 |
| 295 if (task_source) { | |
| 296 task_source->RunPending(); | |
| 297 } | |
| 237 ASSERT_GT(b_conn->packets_.size(), b_i); | 298 ASSERT_GT(b_conn->packets_.size(), b_i); |
| 238 LOG(INFO) << "Processing " << b_conn->packets_.size() - b_i | 299 LOG(INFO) << "Processing " << b_conn->packets_.size() - b_i |
| 239 << " packets b->a"; | 300 << " packets b->a"; |
| 240 if (b_conn->packets_.size() - b_i == 2) { | |
| 241 LOG(INFO) << "here"; | |
| 242 } | |
| 243 MovePackets(b_conn, &b_i, a, a_conn); | 301 MovePackets(b_conn, &b_i, a, a_conn); |
| 244 } | 302 } |
| 245 } | 303 } |
| 246 | 304 |
| 247 // static | 305 // static |
| 248 pair<size_t, size_t> CryptoTestUtils::AdvanceHandshake( | 306 pair<size_t, size_t> CryptoTestUtils::AdvanceHandshake( |
| 249 PacketSavingConnection* a_conn, | 307 PacketSavingConnection* a_conn, |
| 250 QuicCryptoStream* a, | 308 QuicCryptoStream* a, |
| 251 size_t a_i, | 309 size_t a_i, |
| 252 PacketSavingConnection* b_conn, | 310 PacketSavingConnection* b_conn, |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 scoped_ptr<QuicData> bytes(CryptoFramer::ConstructHandshakeMessage(msg)); | 583 scoped_ptr<QuicData> bytes(CryptoFramer::ConstructHandshakeMessage(msg)); |
| 526 scoped_ptr<CryptoHandshakeMessage> parsed( | 584 scoped_ptr<CryptoHandshakeMessage> parsed( |
| 527 CryptoFramer::ParseMessage(bytes->AsStringPiece())); | 585 CryptoFramer::ParseMessage(bytes->AsStringPiece())); |
| 528 CHECK(parsed.get()); | 586 CHECK(parsed.get()); |
| 529 | 587 |
| 530 return *parsed; | 588 return *parsed; |
| 531 } | 589 } |
| 532 | 590 |
| 533 } // namespace test | 591 } // namespace test |
| 534 } // namespace net | 592 } // namespace net |
| OLD | NEW |