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