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_stream_factory.h" | 5 #include "net/quic/quic_stream_factory.h" |
6 | 6 |
7 #include <openssl/aead.h> | 7 #include <openssl/aead.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <tuple> | 10 #include <tuple> |
(...skipping 16 matching lines...) Expand all Loading... |
27 #include "crypto/openssl_util.h" | 27 #include "crypto/openssl_util.h" |
28 #include "net/base/ip_address.h" | 28 #include "net/base/ip_address.h" |
29 #include "net/base/net_errors.h" | 29 #include "net/base/net_errors.h" |
30 #include "net/cert/cert_verifier.h" | 30 #include "net/cert/cert_verifier.h" |
31 #include "net/cert/ct_verifier.h" | 31 #include "net/cert/ct_verifier.h" |
32 #include "net/dns/host_resolver.h" | 32 #include "net/dns/host_resolver.h" |
33 #include "net/dns/single_request_host_resolver.h" | 33 #include "net/dns/single_request_host_resolver.h" |
34 #include "net/http/bidirectional_stream_impl.h" | 34 #include "net/http/bidirectional_stream_impl.h" |
35 #include "net/quic/bidirectional_stream_quic_impl.h" | 35 #include "net/quic/bidirectional_stream_quic_impl.h" |
36 #include "net/quic/crypto/channel_id_chromium.h" | 36 #include "net/quic/crypto/channel_id_chromium.h" |
| 37 #include "net/quic/crypto/proof_verifier.h" |
37 #include "net/quic/crypto/proof_verifier_chromium.h" | 38 #include "net/quic/crypto/proof_verifier_chromium.h" |
38 #include "net/quic/crypto/properties_based_quic_server_info.h" | 39 #include "net/quic/crypto/properties_based_quic_server_info.h" |
39 #include "net/quic/crypto/quic_random.h" | 40 #include "net/quic/crypto/quic_random.h" |
40 #include "net/quic/crypto/quic_server_info.h" | 41 #include "net/quic/crypto/quic_server_info.h" |
41 #include "net/quic/port_suggester.h" | 42 #include "net/quic/port_suggester.h" |
42 #include "net/quic/quic_chromium_alarm_factory.h" | 43 #include "net/quic/quic_chromium_alarm_factory.h" |
43 #include "net/quic/quic_chromium_connection_helper.h" | 44 #include "net/quic/quic_chromium_connection_helper.h" |
44 #include "net/quic/quic_chromium_packet_reader.h" | 45 #include "net/quic/quic_chromium_packet_reader.h" |
45 #include "net/quic/quic_chromium_packet_writer.h" | 46 #include "net/quic/quic_chromium_packet_writer.h" |
46 #include "net/quic/quic_client_promised_info.h" | 47 #include "net/quic/quic_client_promised_info.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 QuicConfig config; | 161 QuicConfig config; |
161 config.SetIdleConnectionStateLifetime( | 162 config.SetIdleConnectionStateLifetime( |
162 QuicTime::Delta::FromSeconds(idle_connection_timeout_seconds), | 163 QuicTime::Delta::FromSeconds(idle_connection_timeout_seconds), |
163 QuicTime::Delta::FromSeconds(idle_connection_timeout_seconds)); | 164 QuicTime::Delta::FromSeconds(idle_connection_timeout_seconds)); |
164 config.SetConnectionOptionsToSend(connection_options); | 165 config.SetConnectionOptionsToSend(connection_options); |
165 return config; | 166 return config; |
166 } | 167 } |
167 | 168 |
168 } // namespace | 169 } // namespace |
169 | 170 |
| 171 // Responsible for verifying the certificates saved in |
| 172 // QuicCryptoClientConfig, and for notifying any associated requests when |
| 173 // complete. Results from cert verification are ignored. |
| 174 class QuicStreamFactory::CertVerifierJob { |
| 175 public: |
| 176 // ProofVerifierCallbackImpl is passed as the callback method to |
| 177 // VerifyCertChain. The ProofVerifier calls this class with the result of cert |
| 178 // verification when verification is performed asynchronously. |
| 179 class ProofVerifierCallbackImpl : public ProofVerifierCallback { |
| 180 public: |
| 181 explicit ProofVerifierCallbackImpl(CertVerifierJob* job) : job_(job) {} |
| 182 |
| 183 ~ProofVerifierCallbackImpl() override {} |
| 184 |
| 185 void Run(bool ok, |
| 186 const std::string& error_details, |
| 187 std::unique_ptr<ProofVerifyDetails>* details) override { |
| 188 if (job_ == nullptr) |
| 189 return; |
| 190 job_->verify_callback_ = nullptr; |
| 191 job_->OnComplete(); |
| 192 } |
| 193 |
| 194 void Cancel() { job_ = nullptr; } |
| 195 |
| 196 private: |
| 197 CertVerifierJob* job_; |
| 198 }; |
| 199 |
| 200 CertVerifierJob(const QuicServerId& server_id, |
| 201 int cert_verify_flags, |
| 202 const BoundNetLog& net_log) |
| 203 : server_id_(server_id), |
| 204 verify_callback_(nullptr), |
| 205 verify_context_(base::WrapUnique( |
| 206 new ProofVerifyContextChromium(cert_verify_flags, net_log))), |
| 207 net_log_(net_log), |
| 208 weak_factory_(this) {} |
| 209 |
| 210 ~CertVerifierJob() { |
| 211 if (verify_callback_) |
| 212 verify_callback_->Cancel(); |
| 213 } |
| 214 |
| 215 // Starts verification of certs cached in the |crypto_config|. |
| 216 QuicAsyncStatus Run(QuicCryptoClientConfig* crypto_config, |
| 217 const CompletionCallback& callback) { |
| 218 QuicCryptoClientConfig::CachedState* cached = |
| 219 crypto_config->LookupOrCreate(server_id_); |
| 220 ProofVerifierCallbackImpl* verify_callback = |
| 221 new ProofVerifierCallbackImpl(this); |
| 222 QuicAsyncStatus status = crypto_config->proof_verifier()->VerifyCertChain( |
| 223 server_id_.host(), cached->certs(), verify_context_.get(), |
| 224 &verify_error_details_, &verify_details_, verify_callback); |
| 225 if (status == QUIC_PENDING) { |
| 226 verify_callback_ = verify_callback; |
| 227 callback_ = callback; |
| 228 } else { |
| 229 delete verify_callback; |
| 230 } |
| 231 return status; |
| 232 } |
| 233 |
| 234 void OnComplete() { |
| 235 if (!callback_.is_null()) |
| 236 callback_.Run(OK); |
| 237 } |
| 238 |
| 239 const QuicServerId& server_id() const { return server_id_; } |
| 240 |
| 241 private: |
| 242 QuicServerId server_id_; |
| 243 ProofVerifierCallbackImpl* verify_callback_; |
| 244 std::unique_ptr<ProofVerifyContext> verify_context_; |
| 245 std::unique_ptr<ProofVerifyDetails> verify_details_; |
| 246 std::string verify_error_details_; |
| 247 const BoundNetLog net_log_; |
| 248 CompletionCallback callback_; |
| 249 base::WeakPtrFactory<CertVerifierJob> weak_factory_; |
| 250 |
| 251 DISALLOW_COPY_AND_ASSIGN(CertVerifierJob); |
| 252 }; |
| 253 |
170 // Responsible for creating a new QUIC session to the specified server, and | 254 // Responsible for creating a new QUIC session to the specified server, and |
171 // for notifying any associated requests when complete. | 255 // for notifying any associated requests when complete. |
172 class QuicStreamFactory::Job { | 256 class QuicStreamFactory::Job { |
173 public: | 257 public: |
174 Job(QuicStreamFactory* factory, | 258 Job(QuicStreamFactory* factory, |
175 HostResolver* host_resolver, | 259 HostResolver* host_resolver, |
176 const QuicSessionKey& key, | 260 const QuicSessionKey& key, |
177 bool was_alternative_service_recently_broken, | 261 bool was_alternative_service_recently_broken, |
178 int cert_verify_flags, | 262 int cert_verify_flags, |
179 QuicServerInfo* server_info, | 263 QuicServerInfo* server_info, |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() { | 441 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() { |
358 // If we are waiting for WaitForDataReadyCallback, then cancel the callback. | 442 // If we are waiting for WaitForDataReadyCallback, then cancel the callback. |
359 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE) | 443 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE) |
360 return; | 444 return; |
361 server_info_->CancelWaitForDataReadyCallback(); | 445 server_info_->CancelWaitForDataReadyCallback(); |
362 OnIOComplete(OK); | 446 OnIOComplete(OK); |
363 } | 447 } |
364 | 448 |
365 int QuicStreamFactory::Job::DoResolveHost() { | 449 int QuicStreamFactory::Job::DoResolveHost() { |
366 // Start loading the data now, and wait for it after we resolve the host. | 450 // Start loading the data now, and wait for it after we resolve the host. |
367 if (server_info_) { | 451 if (server_info_) |
368 server_info_->Start(); | 452 server_info_->Start(); |
369 } | |
370 | 453 |
371 io_state_ = STATE_RESOLVE_HOST_COMPLETE; | 454 io_state_ = STATE_RESOLVE_HOST_COMPLETE; |
372 dns_resolution_start_time_ = base::TimeTicks::Now(); | 455 dns_resolution_start_time_ = base::TimeTicks::Now(); |
373 return host_resolver_.Resolve( | 456 return host_resolver_.Resolve( |
374 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY, | 457 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY, |
375 &address_list_, | 458 &address_list_, |
376 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()), | 459 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()), |
377 net_log_); | 460 net_log_); |
378 } | 461 } |
379 | 462 |
380 int QuicStreamFactory::Job::DoResolveHostComplete(int rv) { | 463 int QuicStreamFactory::Job::DoResolveHostComplete(int rv) { |
381 dns_resolution_end_time_ = base::TimeTicks::Now(); | 464 dns_resolution_end_time_ = base::TimeTicks::Now(); |
382 UMA_HISTOGRAM_TIMES("Net.QuicSession.HostResolutionTime", | 465 UMA_HISTOGRAM_TIMES("Net.QuicSession.HostResolutionTime", |
383 dns_resolution_end_time_ - dns_resolution_start_time_); | 466 dns_resolution_end_time_ - dns_resolution_start_time_); |
384 if (rv != OK) | 467 if (rv != OK) |
385 return rv; | 468 return rv; |
386 | 469 |
387 DCHECK(!factory_->HasActiveSession(key_.server_id())); | 470 DCHECK(!factory_->HasActiveSession(key_.server_id())); |
388 | 471 |
389 // Inform the factory of this resolution, which will set up | 472 // Inform the factory of this resolution, which will set up |
390 // a session alias, if possible. | 473 // a session alias, if possible. |
391 if (factory_->OnResolution(key_, address_list_)) { | 474 if (factory_->OnResolution(key_, address_list_)) |
392 return OK; | 475 return OK; |
393 } | |
394 | 476 |
395 if (server_info_) | 477 if (server_info_) |
396 io_state_ = STATE_LOAD_SERVER_INFO; | 478 io_state_ = STATE_LOAD_SERVER_INFO; |
397 else | 479 else |
398 io_state_ = STATE_CONNECT; | 480 io_state_ = STATE_CONNECT; |
399 return OK; | 481 return OK; |
400 } | 482 } |
401 | 483 |
402 int QuicStreamFactory::Job::DoLoadServerInfo() { | 484 int QuicStreamFactory::Job::DoLoadServerInfo() { |
403 io_state_ = STATE_LOAD_SERVER_INFO_COMPLETE; | 485 io_state_ = STATE_LOAD_SERVER_INFO_COMPLETE; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 | 544 |
463 int rv = factory_->CreateSession( | 545 int rv = factory_->CreateSession( |
464 key_, cert_verify_flags_, std::move(server_info_), address_list_, | 546 key_, cert_verify_flags_, std::move(server_info_), address_list_, |
465 dns_resolution_end_time_, net_log_, &session_); | 547 dns_resolution_end_time_, net_log_, &session_); |
466 if (rv != OK) { | 548 if (rv != OK) { |
467 DCHECK(rv != ERR_IO_PENDING); | 549 DCHECK(rv != ERR_IO_PENDING); |
468 DCHECK(!session_); | 550 DCHECK(!session_); |
469 return rv; | 551 return rv; |
470 } | 552 } |
471 | 553 |
472 if (!session_->connection()->connected()) { | 554 if (!session_->connection()->connected()) |
473 return ERR_CONNECTION_CLOSED; | 555 return ERR_CONNECTION_CLOSED; |
474 } | |
475 | 556 |
476 session_->StartReading(); | 557 session_->StartReading(); |
477 if (!session_->connection()->connected()) { | 558 if (!session_->connection()->connected()) |
478 return ERR_QUIC_PROTOCOL_ERROR; | 559 return ERR_QUIC_PROTOCOL_ERROR; |
479 } | |
480 bool require_confirmation = factory_->require_confirmation() || | 560 bool require_confirmation = factory_->require_confirmation() || |
481 was_alternative_service_recently_broken_; | 561 was_alternative_service_recently_broken_; |
482 | 562 |
483 rv = session_->CryptoConnect( | 563 rv = session_->CryptoConnect( |
484 require_confirmation, | 564 require_confirmation, |
485 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); | 565 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); |
486 | 566 |
487 if (!session_->connection()->connected() && | 567 if (!session_->connection()->connected() && |
488 session_->error() == QUIC_PROOF_INVALID) | 568 session_->error() == QUIC_PROOF_INVALID) { |
489 return ERR_QUIC_HANDSHAKE_FAILED; | 569 return ERR_QUIC_HANDSHAKE_FAILED; |
| 570 } |
490 | 571 |
491 return rv; | 572 return rv; |
492 } | 573 } |
493 | 574 |
494 int QuicStreamFactory::Job::DoResumeConnect() { | 575 int QuicStreamFactory::Job::DoResumeConnect() { |
495 io_state_ = STATE_CONNECT_COMPLETE; | 576 io_state_ = STATE_CONNECT_COMPLETE; |
496 | 577 |
497 int rv = session_->ResumeCryptoConnect( | 578 int rv = session_->ResumeCryptoConnect( |
498 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); | 579 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); |
499 | 580 |
500 return rv; | 581 return rv; |
501 } | 582 } |
502 | 583 |
503 int QuicStreamFactory::Job::DoConnectComplete(int rv) { | 584 int QuicStreamFactory::Job::DoConnectComplete(int rv) { |
504 if (session_ && session_->error() == QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT) { | 585 if (session_ && session_->error() == QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT) { |
505 num_sent_client_hellos_ += session_->GetNumSentClientHellos(); | 586 num_sent_client_hellos_ += session_->GetNumSentClientHellos(); |
506 if (num_sent_client_hellos_ >= QuicCryptoClientStream::kMaxClientHellos) { | 587 if (num_sent_client_hellos_ >= QuicCryptoClientStream::kMaxClientHellos) |
507 return ERR_QUIC_HANDSHAKE_FAILED; | 588 return ERR_QUIC_HANDSHAKE_FAILED; |
508 } | |
509 // The handshake was rejected statelessly, so create another connection | 589 // The handshake was rejected statelessly, so create another connection |
510 // to resume the handshake. | 590 // to resume the handshake. |
511 io_state_ = STATE_CONNECT; | 591 io_state_ = STATE_CONNECT; |
512 return OK; | 592 return OK; |
513 } | 593 } |
514 | 594 |
515 if (rv != OK) | 595 if (rv != OK) |
516 return rv; | 596 return rv; |
517 | 597 |
518 DCHECK(!factory_->HasActiveSession(key_.server_id())); | 598 DCHECK(!factory_->HasActiveSession(key_.server_id())); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 int threshold_public_resets_post_handshake, | 705 int threshold_public_resets_post_handshake, |
626 int threshold_timeouts_with_open_streams, | 706 int threshold_timeouts_with_open_streams, |
627 int socket_receive_buffer_size, | 707 int socket_receive_buffer_size, |
628 bool delay_tcp_race, | 708 bool delay_tcp_race, |
629 int max_server_configs_stored_in_properties, | 709 int max_server_configs_stored_in_properties, |
630 bool close_sessions_on_ip_change, | 710 bool close_sessions_on_ip_change, |
631 bool disable_quic_on_timeout_with_open_streams, | 711 bool disable_quic_on_timeout_with_open_streams, |
632 int idle_connection_timeout_seconds, | 712 int idle_connection_timeout_seconds, |
633 bool migrate_sessions_on_network_change, | 713 bool migrate_sessions_on_network_change, |
634 bool migrate_sessions_early, | 714 bool migrate_sessions_early, |
| 715 bool race_cert_verification, |
635 const QuicTagVector& connection_options, | 716 const QuicTagVector& connection_options, |
636 bool enable_token_binding) | 717 bool enable_token_binding) |
637 : require_confirmation_(true), | 718 : require_confirmation_(true), |
638 net_log_(net_log), | 719 net_log_(net_log), |
639 host_resolver_(host_resolver), | 720 host_resolver_(host_resolver), |
640 client_socket_factory_(client_socket_factory), | 721 client_socket_factory_(client_socket_factory), |
641 http_server_properties_(http_server_properties), | 722 http_server_properties_(http_server_properties), |
642 transport_security_state_(transport_security_state), | 723 transport_security_state_(transport_security_state), |
643 cert_transparency_verifier_(cert_transparency_verifier), | 724 cert_transparency_verifier_(cert_transparency_verifier), |
644 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), | 725 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
678 delay_tcp_race_(delay_tcp_race), | 759 delay_tcp_race_(delay_tcp_race), |
679 yield_after_packets_(kQuicYieldAfterPacketsRead), | 760 yield_after_packets_(kQuicYieldAfterPacketsRead), |
680 yield_after_duration_(QuicTime::Delta::FromMilliseconds( | 761 yield_after_duration_(QuicTime::Delta::FromMilliseconds( |
681 kQuicYieldAfterDurationMilliseconds)), | 762 kQuicYieldAfterDurationMilliseconds)), |
682 close_sessions_on_ip_change_(close_sessions_on_ip_change), | 763 close_sessions_on_ip_change_(close_sessions_on_ip_change), |
683 migrate_sessions_on_network_change_( | 764 migrate_sessions_on_network_change_( |
684 migrate_sessions_on_network_change && | 765 migrate_sessions_on_network_change && |
685 NetworkChangeNotifier::AreNetworkHandlesSupported()), | 766 NetworkChangeNotifier::AreNetworkHandlesSupported()), |
686 migrate_sessions_early_(migrate_sessions_early && | 767 migrate_sessions_early_(migrate_sessions_early && |
687 migrate_sessions_on_network_change_), | 768 migrate_sessions_on_network_change_), |
| 769 race_cert_verification_(race_cert_verification), |
688 port_seed_(random_generator_->RandUint64()), | 770 port_seed_(random_generator_->RandUint64()), |
689 check_persisted_supports_quic_(true), | 771 check_persisted_supports_quic_(true), |
690 has_initialized_data_(false), | 772 has_initialized_data_(false), |
691 num_push_streams_created_(0), | 773 num_push_streams_created_(0), |
692 status_(OPEN), | 774 status_(OPEN), |
693 task_runner_(nullptr), | 775 task_runner_(nullptr), |
694 ssl_config_service_(ssl_config_service), | 776 ssl_config_service_(ssl_config_service), |
695 weak_factory_(this) { | 777 weak_factory_(this) { |
696 if (ssl_config_service_.get()) | 778 if (ssl_config_service_.get()) |
697 ssl_config_service_->AddObserver(this); | 779 ssl_config_service_->AddObserver(this); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 CloseAllSessions(ERR_ABORTED, QUIC_CONNECTION_CANCELLED); | 827 CloseAllSessions(ERR_ABORTED, QUIC_CONNECTION_CANCELLED); |
746 while (!all_sessions_.empty()) { | 828 while (!all_sessions_.empty()) { |
747 delete all_sessions_.begin()->first; | 829 delete all_sessions_.begin()->first; |
748 all_sessions_.erase(all_sessions_.begin()); | 830 all_sessions_.erase(all_sessions_.begin()); |
749 } | 831 } |
750 while (!active_jobs_.empty()) { | 832 while (!active_jobs_.empty()) { |
751 const QuicServerId server_id = active_jobs_.begin()->first; | 833 const QuicServerId server_id = active_jobs_.begin()->first; |
752 STLDeleteElements(&(active_jobs_[server_id])); | 834 STLDeleteElements(&(active_jobs_[server_id])); |
753 active_jobs_.erase(server_id); | 835 active_jobs_.erase(server_id); |
754 } | 836 } |
| 837 while (!active_cert_verifier_jobs_.empty()) |
| 838 active_cert_verifier_jobs_.erase(active_cert_verifier_jobs_.begin()); |
755 if (ssl_config_service_.get()) | 839 if (ssl_config_service_.get()) |
756 ssl_config_service_->RemoveObserver(this); | 840 ssl_config_service_->RemoveObserver(this); |
757 if (migrate_sessions_on_network_change_) { | 841 if (migrate_sessions_on_network_change_) { |
758 NetworkChangeNotifier::RemoveNetworkObserver(this); | 842 NetworkChangeNotifier::RemoveNetworkObserver(this); |
759 } else if (close_sessions_on_ip_change_) { | 843 } else if (close_sessions_on_ip_change_) { |
760 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 844 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
761 } | 845 } |
762 } | 846 } |
763 | 847 |
764 void QuicStreamFactory::set_require_confirmation(bool require_confirmation) { | 848 void QuicStreamFactory::set_require_confirmation(bool require_confirmation) { |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
876 | 960 |
877 QuicServerInfo* quic_server_info = nullptr; | 961 QuicServerInfo* quic_server_info = nullptr; |
878 if (quic_server_info_factory_.get()) { | 962 if (quic_server_info_factory_.get()) { |
879 bool load_from_disk_cache = !disable_disk_cache_; | 963 bool load_from_disk_cache = !disable_disk_cache_; |
880 MaybeInitialize(); | 964 MaybeInitialize(); |
881 if (!ContainsKey(quic_supported_servers_at_startup_, destination)) { | 965 if (!ContainsKey(quic_supported_servers_at_startup_, destination)) { |
882 // If there is no entry for QUIC, consider that as a new server and | 966 // If there is no entry for QUIC, consider that as a new server and |
883 // don't wait for Cache thread to load the data for that server. | 967 // don't wait for Cache thread to load the data for that server. |
884 load_from_disk_cache = false; | 968 load_from_disk_cache = false; |
885 } | 969 } |
886 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) { | 970 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) |
887 quic_server_info = quic_server_info_factory_->GetForServer(server_id); | 971 quic_server_info = quic_server_info_factory_->GetForServer(server_id); |
888 } | |
889 } | 972 } |
890 | 973 |
| 974 StartCertVerifyJob(server_id, cert_verify_flags, net_log); |
| 975 |
891 QuicSessionKey key(destination, server_id); | 976 QuicSessionKey key(destination, server_id); |
892 std::unique_ptr<Job> job( | 977 std::unique_ptr<Job> job( |
893 new Job(this, host_resolver_, key, WasQuicRecentlyBroken(server_id), | 978 new Job(this, host_resolver_, key, WasQuicRecentlyBroken(server_id), |
894 cert_verify_flags, quic_server_info, net_log)); | 979 cert_verify_flags, quic_server_info, net_log)); |
895 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, | 980 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, |
896 base::Unretained(this), job.get())); | 981 base::Unretained(this), job.get())); |
897 if (rv == ERR_IO_PENDING) { | 982 if (rv == ERR_IO_PENDING) { |
898 active_requests_[request] = server_id; | 983 active_requests_[request] = server_id; |
899 job_requests_map_[server_id].insert(request); | 984 job_requests_map_[server_id].insert(request); |
900 active_jobs_[server_id].insert(job.release()); | 985 active_jobs_[server_id].insert(job.release()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 active_jobs_[key.server_id()].insert(aux_job); | 1026 active_jobs_[key.server_id()].insert(aux_job); |
942 task_runner_->PostTask(FROM_HERE, | 1027 task_runner_->PostTask(FROM_HERE, |
943 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob, | 1028 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob, |
944 aux_job->GetWeakPtr())); | 1029 aux_job->GetWeakPtr())); |
945 } | 1030 } |
946 | 1031 |
947 bool QuicStreamFactory::OnResolution(const QuicSessionKey& key, | 1032 bool QuicStreamFactory::OnResolution(const QuicSessionKey& key, |
948 const AddressList& address_list) { | 1033 const AddressList& address_list) { |
949 const QuicServerId& server_id(key.server_id()); | 1034 const QuicServerId& server_id(key.server_id()); |
950 DCHECK(!HasActiveSession(server_id)); | 1035 DCHECK(!HasActiveSession(server_id)); |
951 if (disable_connection_pooling_) { | 1036 if (disable_connection_pooling_) |
952 return false; | 1037 return false; |
953 } | |
954 for (const IPEndPoint& address : address_list) { | 1038 for (const IPEndPoint& address : address_list) { |
955 if (!ContainsKey(ip_aliases_, address)) | 1039 if (!ContainsKey(ip_aliases_, address)) |
956 continue; | 1040 continue; |
957 | 1041 |
958 const SessionSet& sessions = ip_aliases_[address]; | 1042 const SessionSet& sessions = ip_aliases_[address]; |
959 for (QuicChromiumClientSession* session : sessions) { | 1043 for (QuicChromiumClientSession* session : sessions) { |
960 if (!session->CanPool(server_id.host(), server_id.privacy_mode())) | 1044 if (!session->CanPool(server_id.host(), server_id.privacy_mode())) |
961 continue; | 1045 continue; |
962 active_sessions_[server_id] = session; | 1046 active_sessions_[server_id] = session; |
963 session_aliases_[session].insert(key); | 1047 session_aliases_[session].insert(key); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 for (Job* other_job : active_jobs_[server_id]) { | 1097 for (Job* other_job : active_jobs_[server_id]) { |
1014 if (other_job != job) | 1098 if (other_job != job) |
1015 other_job->Cancel(); | 1099 other_job->Cancel(); |
1016 } | 1100 } |
1017 | 1101 |
1018 STLDeleteElements(&(active_jobs_[server_id])); | 1102 STLDeleteElements(&(active_jobs_[server_id])); |
1019 active_jobs_.erase(server_id); | 1103 active_jobs_.erase(server_id); |
1020 job_requests_map_.erase(server_id); | 1104 job_requests_map_.erase(server_id); |
1021 } | 1105 } |
1022 | 1106 |
| 1107 void QuicStreamFactory::OnCertVerifyJobComplete(CertVerifierJob* job, int rv) { |
| 1108 active_cert_verifier_jobs_.erase(job->server_id()); |
| 1109 } |
| 1110 |
1023 std::unique_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession( | 1111 std::unique_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession( |
1024 QuicChromiumClientSession* session) { | 1112 QuicChromiumClientSession* session) { |
1025 return std::unique_ptr<QuicHttpStream>( | 1113 return std::unique_ptr<QuicHttpStream>( |
1026 new QuicHttpStream(session->GetWeakPtr())); | 1114 new QuicHttpStream(session->GetWeakPtr())); |
1027 } | 1115 } |
1028 | 1116 |
1029 QuicChromiumClientSession::QuicDisabledReason | 1117 QuicChromiumClientSession::QuicDisabledReason |
1030 QuicStreamFactory::QuicDisabledReason(uint16_t port) const { | 1118 QuicStreamFactory::QuicDisabledReason(uint16_t port) const { |
1031 if (max_number_of_lossy_connections_ > 0 && | 1119 if (max_number_of_lossy_connections_ > 0 && |
1032 number_of_lossy_connections_.find(port) != | 1120 number_of_lossy_connections_.find(port) != |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 | 1216 |
1129 void QuicStreamFactory::OnSessionGoingAway(QuicChromiumClientSession* session) { | 1217 void QuicStreamFactory::OnSessionGoingAway(QuicChromiumClientSession* session) { |
1130 const AliasSet& aliases = session_aliases_[session]; | 1218 const AliasSet& aliases = session_aliases_[session]; |
1131 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); | 1219 for (AliasSet::const_iterator it = aliases.begin(); it != aliases.end(); |
1132 ++it) { | 1220 ++it) { |
1133 const QuicServerId& server_id = it->server_id(); | 1221 const QuicServerId& server_id = it->server_id(); |
1134 DCHECK(active_sessions_.count(server_id)); | 1222 DCHECK(active_sessions_.count(server_id)); |
1135 DCHECK_EQ(session, active_sessions_[server_id]); | 1223 DCHECK_EQ(session, active_sessions_[server_id]); |
1136 // Track sessions which have recently gone away so that we can disable | 1224 // Track sessions which have recently gone away so that we can disable |
1137 // port suggestions. | 1225 // port suggestions. |
1138 if (session->goaway_received()) { | 1226 if (session->goaway_received()) |
1139 gone_away_aliases_.insert(*it); | 1227 gone_away_aliases_.insert(*it); |
1140 } | |
1141 | 1228 |
1142 active_sessions_.erase(server_id); | 1229 active_sessions_.erase(server_id); |
1143 ProcessGoingAwaySession(session, server_id, true); | 1230 ProcessGoingAwaySession(session, server_id, true); |
1144 } | 1231 } |
1145 ProcessGoingAwaySession(session, all_sessions_[session].server_id(), false); | 1232 ProcessGoingAwaySession(session, all_sessions_[session].server_id(), false); |
1146 if (!aliases.empty()) { | 1233 if (!aliases.empty()) { |
1147 const IPEndPoint peer_address = session->connection()->peer_address(); | 1234 const IPEndPoint peer_address = session->connection()->peer_address(); |
1148 ip_aliases_[peer_address].erase(session); | 1235 ip_aliases_[peer_address].erase(session); |
1149 if (ip_aliases_[peer_address].empty()) { | 1236 if (ip_aliases_[peer_address].empty()) |
1150 ip_aliases_.erase(peer_address); | 1237 ip_aliases_.erase(peer_address); |
1151 } | |
1152 } | 1238 } |
1153 session_aliases_.erase(session); | 1239 session_aliases_.erase(session); |
1154 } | 1240 } |
1155 | 1241 |
1156 void QuicStreamFactory::MaybeDisableQuic(QuicChromiumClientSession* session) { | 1242 void QuicStreamFactory::MaybeDisableQuic(QuicChromiumClientSession* session) { |
1157 DCHECK(session); | 1243 DCHECK(session); |
1158 uint16_t port = session->server_id().port(); | 1244 uint16_t port = session->server_id().port(); |
1159 if (IsQuicDisabled(port)) | 1245 if (IsQuicDisabled(port)) |
1160 return; | 1246 return; |
1161 | 1247 |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1246 MaybeDisableQuic(session); | 1332 MaybeDisableQuic(session); |
1247 OnSessionGoingAway(session); | 1333 OnSessionGoingAway(session); |
1248 delete session; | 1334 delete session; |
1249 all_sessions_.erase(session); | 1335 all_sessions_.erase(session); |
1250 } | 1336 } |
1251 | 1337 |
1252 void QuicStreamFactory::OnSessionConnectTimeout( | 1338 void QuicStreamFactory::OnSessionConnectTimeout( |
1253 QuicChromiumClientSession* session) { | 1339 QuicChromiumClientSession* session) { |
1254 const AliasSet& aliases = session_aliases_[session]; | 1340 const AliasSet& aliases = session_aliases_[session]; |
1255 | 1341 |
1256 if (aliases.empty()) { | 1342 if (aliases.empty()) |
1257 return; | 1343 return; |
1258 } | |
1259 | 1344 |
1260 for (const QuicSessionKey& key : aliases) { | 1345 for (const QuicSessionKey& key : aliases) { |
1261 const QuicServerId& server_id = key.server_id(); | 1346 const QuicServerId& server_id = key.server_id(); |
1262 SessionMap::iterator session_it = active_sessions_.find(server_id); | 1347 SessionMap::iterator session_it = active_sessions_.find(server_id); |
1263 DCHECK(session_it != active_sessions_.end()); | 1348 DCHECK(session_it != active_sessions_.end()); |
1264 DCHECK_EQ(session, session_it->second); | 1349 DCHECK_EQ(session, session_it->second); |
1265 active_sessions_.erase(session_it); | 1350 active_sessions_.erase(session_it); |
1266 } | 1351 } |
1267 | 1352 |
1268 const IPEndPoint peer_address = session->connection()->peer_address(); | 1353 const IPEndPoint peer_address = session->connection()->peer_address(); |
1269 ip_aliases_[peer_address].erase(session); | 1354 ip_aliases_[peer_address].erase(session); |
1270 if (ip_aliases_[peer_address].empty()) { | 1355 if (ip_aliases_[peer_address].empty()) |
1271 ip_aliases_.erase(peer_address); | 1356 ip_aliases_.erase(peer_address); |
1272 } | |
1273 QuicSessionKey key = *aliases.begin(); | 1357 QuicSessionKey key = *aliases.begin(); |
1274 session_aliases_.erase(session); | 1358 session_aliases_.erase(session); |
1275 Job* job = new Job(this, host_resolver_, session, key); | 1359 Job* job = new Job(this, host_resolver_, session, key); |
1276 active_jobs_[key.server_id()].insert(job); | 1360 active_jobs_[key.server_id()].insert(job); |
1277 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, | 1361 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, |
1278 base::Unretained(this), job)); | 1362 base::Unretained(this), job)); |
1279 DCHECK_EQ(ERR_IO_PENDING, rv); | 1363 DCHECK_EQ(ERR_IO_PENDING, rv); |
1280 } | 1364 } |
1281 | 1365 |
1282 void QuicStreamFactory::CancelRequest(QuicStreamRequest* request) { | 1366 void QuicStreamFactory::CancelRequest(QuicStreamRequest* request) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1358 MaybeMigrateOrCloseSessions(network, /*force_close=*/false, | 1442 MaybeMigrateOrCloseSessions(network, /*force_close=*/false, |
1359 scoped_event_log.net_log()); | 1443 scoped_event_log.net_log()); |
1360 } | 1444 } |
1361 | 1445 |
1362 NetworkHandle QuicStreamFactory::FindAlternateNetwork( | 1446 NetworkHandle QuicStreamFactory::FindAlternateNetwork( |
1363 NetworkHandle old_network) { | 1447 NetworkHandle old_network) { |
1364 // Find a new network that sessions bound to |old_network| can be migrated to. | 1448 // Find a new network that sessions bound to |old_network| can be migrated to. |
1365 NetworkChangeNotifier::NetworkList network_list; | 1449 NetworkChangeNotifier::NetworkList network_list; |
1366 NetworkChangeNotifier::GetConnectedNetworks(&network_list); | 1450 NetworkChangeNotifier::GetConnectedNetworks(&network_list); |
1367 for (NetworkHandle new_network : network_list) { | 1451 for (NetworkHandle new_network : network_list) { |
1368 if (new_network != old_network) { | 1452 if (new_network != old_network) |
1369 return new_network; | 1453 return new_network; |
1370 } | |
1371 } | 1454 } |
1372 return NetworkChangeNotifier::kInvalidNetworkHandle; | 1455 return NetworkChangeNotifier::kInvalidNetworkHandle; |
1373 } | 1456 } |
1374 | 1457 |
1375 void QuicStreamFactory::MaybeMigrateOrCloseSessions( | 1458 void QuicStreamFactory::MaybeMigrateOrCloseSessions( |
1376 NetworkHandle network, | 1459 NetworkHandle network, |
1377 bool force_close, | 1460 bool force_close, |
1378 const BoundNetLog& bound_net_log) { | 1461 const BoundNetLog& bound_net_log) { |
1379 DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network); | 1462 DCHECK_NE(NetworkChangeNotifier::kInvalidNetworkHandle, network); |
1380 NetworkHandle new_network = FindAlternateNetwork(network); | 1463 NetworkHandle new_network = FindAlternateNetwork(network); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() check. | 1624 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() check. |
1542 if (active_sessions_.empty()) | 1625 if (active_sessions_.empty()) |
1543 return false; | 1626 return false; |
1544 return ContainsKey(active_sessions_, server_id); | 1627 return ContainsKey(active_sessions_, server_id); |
1545 } | 1628 } |
1546 | 1629 |
1547 bool QuicStreamFactory::HasActiveJob(const QuicServerId& server_id) const { | 1630 bool QuicStreamFactory::HasActiveJob(const QuicServerId& server_id) const { |
1548 return ContainsKey(active_jobs_, server_id); | 1631 return ContainsKey(active_jobs_, server_id); |
1549 } | 1632 } |
1550 | 1633 |
| 1634 bool QuicStreamFactory::HasActiveCertVerifierJob( |
| 1635 const QuicServerId& server_id) const { |
| 1636 return ContainsKey(active_cert_verifier_jobs_, server_id); |
| 1637 } |
| 1638 |
1551 int QuicStreamFactory::ConfigureSocket(DatagramClientSocket* socket, | 1639 int QuicStreamFactory::ConfigureSocket(DatagramClientSocket* socket, |
1552 IPEndPoint addr, | 1640 IPEndPoint addr, |
1553 NetworkHandle network) { | 1641 NetworkHandle network) { |
1554 if (enable_non_blocking_io_ && | 1642 if (enable_non_blocking_io_ && |
1555 client_socket_factory_ == ClientSocketFactory::GetDefaultFactory()) { | 1643 client_socket_factory_ == ClientSocketFactory::GetDefaultFactory()) { |
1556 #if defined(OS_WIN) | 1644 #if defined(OS_WIN) |
1557 static_cast<UDPClientSocket*>(socket)->UseNonBlockingIO(); | 1645 static_cast<UDPClientSocket*>(socket)->UseNonBlockingIO(); |
1558 #endif | 1646 #endif |
1559 } | 1647 } |
1560 | 1648 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1629 DatagramSocket::DEFAULT_BIND; // Use OS to randomize. | 1717 DatagramSocket::DEFAULT_BIND; // Use OS to randomize. |
1630 | 1718 |
1631 std::unique_ptr<DatagramClientSocket> socket( | 1719 std::unique_ptr<DatagramClientSocket> socket( |
1632 client_socket_factory_->CreateDatagramClientSocket( | 1720 client_socket_factory_->CreateDatagramClientSocket( |
1633 bind_type, base::Bind(&PortSuggester::SuggestPort, port_suggester), | 1721 bind_type, base::Bind(&PortSuggester::SuggestPort, port_suggester), |
1634 net_log.net_log(), net_log.source())); | 1722 net_log.net_log(), net_log.source())); |
1635 | 1723 |
1636 // Passing in kInvalidNetworkHandle binds socket to default network. | 1724 // Passing in kInvalidNetworkHandle binds socket to default network. |
1637 int rv = ConfigureSocket(socket.get(), addr, | 1725 int rv = ConfigureSocket(socket.get(), addr, |
1638 NetworkChangeNotifier::kInvalidNetworkHandle); | 1726 NetworkChangeNotifier::kInvalidNetworkHandle); |
1639 if (rv != OK) { | 1727 if (rv != OK) |
1640 return rv; | 1728 return rv; |
1641 } | |
1642 | 1729 |
1643 if (enable_port_selection) { | 1730 if (enable_port_selection) |
1644 DCHECK_LE(1u, port_suggester->call_count()); | 1731 DCHECK_LE(1u, port_suggester->call_count()); |
1645 } else { | 1732 else |
1646 DCHECK_EQ(0u, port_suggester->call_count()); | 1733 DCHECK_EQ(0u, port_suggester->call_count()); |
1647 } | |
1648 | 1734 |
1649 if (!helper_.get()) { | 1735 if (!helper_.get()) { |
1650 helper_.reset( | 1736 helper_.reset( |
1651 new QuicChromiumConnectionHelper(clock_.get(), random_generator_)); | 1737 new QuicChromiumConnectionHelper(clock_.get(), random_generator_)); |
1652 } | 1738 } |
1653 | 1739 |
1654 if (!alarm_factory_.get()) { | 1740 if (!alarm_factory_.get()) { |
1655 alarm_factory_.reset(new QuicChromiumAlarmFactory( | 1741 alarm_factory_.reset(new QuicChromiumAlarmFactory( |
1656 base::ThreadTaskRunnerHandle::Get().get(), clock_.get())); | 1742 base::ThreadTaskRunnerHandle::Get().get(), clock_.get())); |
1657 } | 1743 } |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1748 alternative_service); | 1834 alternative_service); |
1749 } | 1835 } |
1750 | 1836 |
1751 bool QuicStreamFactory::CryptoConfigCacheIsEmpty( | 1837 bool QuicStreamFactory::CryptoConfigCacheIsEmpty( |
1752 const QuicServerId& server_id) { | 1838 const QuicServerId& server_id) { |
1753 QuicCryptoClientConfig::CachedState* cached = | 1839 QuicCryptoClientConfig::CachedState* cached = |
1754 crypto_config_.LookupOrCreate(server_id); | 1840 crypto_config_.LookupOrCreate(server_id); |
1755 return cached->IsEmpty(); | 1841 return cached->IsEmpty(); |
1756 } | 1842 } |
1757 | 1843 |
| 1844 void QuicStreamFactory::StartCertVerifyJob(const QuicServerId& server_id, |
| 1845 int cert_verify_flags, |
| 1846 const BoundNetLog& net_log) { |
| 1847 if (!race_cert_verification_) |
| 1848 return; |
| 1849 QuicCryptoClientConfig::CachedState* cached = |
| 1850 crypto_config_.LookupOrCreate(server_id); |
| 1851 if (!cached || cached->certs().empty() || |
| 1852 HasActiveCertVerifierJob(server_id)) { |
| 1853 return; |
| 1854 } |
| 1855 std::unique_ptr<CertVerifierJob> cert_verifier_job( |
| 1856 new CertVerifierJob(server_id, cert_verify_flags, net_log)); |
| 1857 QuicAsyncStatus status = cert_verifier_job->Run( |
| 1858 &crypto_config_, |
| 1859 base::Bind(&QuicStreamFactory::OnCertVerifyJobComplete, |
| 1860 base::Unretained(this), cert_verifier_job.get())); |
| 1861 if (status == QUIC_PENDING) |
| 1862 active_cert_verifier_jobs_[server_id] = std::move(cert_verifier_job); |
| 1863 } |
| 1864 |
1758 void QuicStreamFactory::InitializeCachedStateInCryptoConfig( | 1865 void QuicStreamFactory::InitializeCachedStateInCryptoConfig( |
1759 const QuicServerId& server_id, | 1866 const QuicServerId& server_id, |
1760 const std::unique_ptr<QuicServerInfo>& server_info, | 1867 const std::unique_ptr<QuicServerInfo>& server_info, |
1761 QuicConnectionId* connection_id) { | 1868 QuicConnectionId* connection_id) { |
1762 QuicCryptoClientConfig::CachedState* cached = | 1869 QuicCryptoClientConfig::CachedState* cached = |
1763 crypto_config_.LookupOrCreate(server_id); | 1870 crypto_config_.LookupOrCreate(server_id); |
1764 if (cached->has_server_designated_connection_id()) | 1871 if (cached->has_server_designated_connection_id()) |
1765 *connection_id = cached->GetNextServerDesignatedConnectionId(); | 1872 *connection_id = cached->GetNextServerDesignatedConnectionId(); |
1766 | 1873 |
1767 if (!cached->IsEmpty()) | 1874 if (!cached->IsEmpty()) |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1869 // Since the session was active, there's no longer an | 1976 // Since the session was active, there's no longer an |
1870 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 1977 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
1871 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 1978 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
1872 // it as recently broken, which means that 0-RTT will be disabled but we'll | 1979 // it as recently broken, which means that 0-RTT will be disabled but we'll |
1873 // still race. | 1980 // still race. |
1874 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1981 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
1875 alternative_service); | 1982 alternative_service); |
1876 } | 1983 } |
1877 | 1984 |
1878 } // namespace net | 1985 } // namespace net |
OLD | NEW |