| 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/chromium/quic_stream_factory.h" | 5 #include "net/quic/chromium/quic_stream_factory.h" |
| 6 | 6 |
| 7 #include <ostream> | 7 #include <ostream> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "net/base/test_proxy_delegate.h" |
| 15 #include "net/cert/cert_verifier.h" | 16 #include "net/cert/cert_verifier.h" |
| 16 #include "net/cert/ct_policy_enforcer.h" | 17 #include "net/cert/ct_policy_enforcer.h" |
| 17 #include "net/cert/multi_log_ct_verifier.h" | 18 #include "net/cert/multi_log_ct_verifier.h" |
| 18 #include "net/dns/mock_host_resolver.h" | 19 #include "net/dns/mock_host_resolver.h" |
| 19 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
| 20 #include "net/http/http_response_info.h" | 21 #include "net/http/http_response_info.h" |
| 21 #include "net/http/http_server_properties_impl.h" | 22 #include "net/http/http_server_properties_impl.h" |
| 22 #include "net/http/http_util.h" | 23 #include "net/http/http_util.h" |
| 23 #include "net/http/transport_security_state.h" | 24 #include "net/http/transport_security_state.h" |
| 24 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" | 25 #include "net/quic/chromium/crypto/proof_verifier_chromium.h" |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 // If |factory_| was initialized, then it took over ownership of |clock_|. | 268 // If |factory_| was initialized, then it took over ownership of |clock_|. |
| 268 // If |factory_| was not initialized, then |clock_| needs to be destroyed. | 269 // If |factory_| was not initialized, then |clock_| needs to be destroyed. |
| 269 if (!factory_) | 270 if (!factory_) |
| 270 delete clock_; | 271 delete clock_; |
| 271 } | 272 } |
| 272 | 273 |
| 273 void Initialize() { | 274 void Initialize() { |
| 274 DCHECK(!factory_); | 275 DCHECK(!factory_); |
| 275 factory_.reset(new QuicStreamFactory( | 276 factory_.reset(new QuicStreamFactory( |
| 276 net_log_.net_log(), &host_resolver_, ssl_config_service_.get(), | 277 net_log_.net_log(), &host_resolver_, ssl_config_service_.get(), |
| 277 &socket_factory_, &http_server_properties_, cert_verifier_.get(), | 278 &socket_factory_, &http_server_properties_, &test_proxy_delegate_, |
| 278 &ct_policy_enforcer_, channel_id_service_.get(), | 279 cert_verifier_.get(), &ct_policy_enforcer_, channel_id_service_.get(), |
| 279 &transport_security_state_, cert_transparency_verifier_.get(), | 280 &transport_security_state_, cert_transparency_verifier_.get(), |
| 280 /*SocketPerformanceWatcherFactory*/ nullptr, | 281 /*SocketPerformanceWatcherFactory*/ nullptr, |
| 281 &crypto_client_stream_factory_, &random_generator_, clock_, | 282 &crypto_client_stream_factory_, &random_generator_, clock_, |
| 282 kDefaultMaxPacketSize, string(), SupportedVersions(version_), | 283 kDefaultMaxPacketSize, string(), SupportedVersions(version_), |
| 283 enable_port_selection_, always_require_handshake_confirmation_, | 284 enable_port_selection_, always_require_handshake_confirmation_, |
| 284 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, | 285 disable_connection_pooling_, load_server_info_timeout_srtt_multiplier_, |
| 285 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, | 286 enable_connection_racing_, enable_non_blocking_io_, disable_disk_cache_, |
| 286 prefer_aes_, receive_buffer_size_, delay_tcp_race_, | 287 prefer_aes_, receive_buffer_size_, delay_tcp_race_, |
| 287 /*max_server_configs_stored_in_properties*/ 0, | 288 /*max_server_configs_stored_in_properties*/ 0, |
| 288 close_sessions_on_ip_change_, | 289 close_sessions_on_ip_change_, |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 << " " << actual_address.port(); | 492 << " " << actual_address.port(); |
| 492 DVLOG(1) << "Expected address: " << expected_address.address().ToString() | 493 DVLOG(1) << "Expected address: " << expected_address.address().ToString() |
| 493 << " " << expected_address.port(); | 494 << " " << expected_address.port(); |
| 494 | 495 |
| 495 stream.reset(); | 496 stream.reset(); |
| 496 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); | 497 EXPECT_TRUE(socket_data1.AllReadDataConsumed()); |
| 497 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); | 498 EXPECT_TRUE(socket_data2.AllReadDataConsumed()); |
| 498 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); | 499 EXPECT_TRUE(socket_data2.AllWriteDataConsumed()); |
| 499 } | 500 } |
| 500 | 501 |
| 502 // Verifies that the QUIC stream factory is initialized correctly. |
| 503 // If |proxy_delegate_provides_quic_supported_proxy| is true, then |
| 504 // ProxyDelegate provides a proxy that supports QUIC at startup. Otherwise, |
| 505 // a non proxy server that support alternative services is added to the |
| 506 // HttpServerProperties map. |
| 507 void VerifyInitialization(bool proxy_delegate_provides_quic_supported_proxy) { |
| 508 idle_connection_timeout_seconds_ = 500; |
| 509 Initialize(); |
| 510 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); |
| 511 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); |
| 512 const QuicConfig* config = QuicStreamFactoryPeer::GetConfig(factory_.get()); |
| 513 EXPECT_EQ(500, config->IdleConnectionStateLifetime().ToSeconds()); |
| 514 |
| 515 QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); |
| 516 |
| 517 const AlternativeService alternative_service1(QUIC, host_port_pair_.host(), |
| 518 host_port_pair_.port()); |
| 519 AlternativeServiceInfoVector alternative_service_info_vector; |
| 520 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 521 alternative_service_info_vector.push_back( |
| 522 AlternativeServiceInfo(alternative_service1, expiration)); |
| 523 http_server_properties_.SetAlternativeServices( |
| 524 url::SchemeHostPort(url_), alternative_service_info_vector); |
| 525 |
| 526 HostPortPair host_port_pair2(kServer2HostName, kDefaultServerPort); |
| 527 url::SchemeHostPort server2("https", kServer2HostName, kDefaultServerPort); |
| 528 const AlternativeService alternative_service2(QUIC, host_port_pair2.host(), |
| 529 host_port_pair2.port()); |
| 530 AlternativeServiceInfoVector alternative_service_info_vector2; |
| 531 alternative_service_info_vector2.push_back( |
| 532 AlternativeServiceInfo(alternative_service2, expiration)); |
| 533 if (!proxy_delegate_provides_quic_supported_proxy) { |
| 534 http_server_properties_.SetAlternativeServices( |
| 535 server2, alternative_service_info_vector2); |
| 536 // Verify that the properties of both QUIC servers are stored in the |
| 537 // HTTP properties map. |
| 538 EXPECT_EQ(2U, http_server_properties_.alternative_service_map().size()); |
| 539 } else { |
| 540 test_proxy_delegate_.set_alternative_proxy_server(net::ProxyServer( |
| 541 net::ProxyServer::SCHEME_QUIC, |
| 542 net::HostPortPair(kServer2HostName, kDefaultServerPort))); |
| 543 // Verify that the properties of only the first QUIC server are stored in |
| 544 // the HTTP properties map. |
| 545 EXPECT_EQ(1U, http_server_properties_.alternative_service_map().size()); |
| 546 } |
| 547 |
| 548 http_server_properties_.SetMaxServerConfigsStoredInProperties( |
| 549 kMaxQuicServersToPersist); |
| 550 |
| 551 QuicServerId quic_server_id(kDefaultServerHostName, 80, |
| 552 PRIVACY_MODE_DISABLED); |
| 553 QuicServerInfoFactory* quic_server_info_factory = |
| 554 new PropertiesBasedQuicServerInfoFactory(&http_server_properties_); |
| 555 factory_->set_quic_server_info_factory(quic_server_info_factory); |
| 556 |
| 557 std::unique_ptr<QuicServerInfo> quic_server_info( |
| 558 quic_server_info_factory->GetForServer(quic_server_id)); |
| 559 |
| 560 // Update quic_server_info's server_config and persist it. |
| 561 QuicServerInfo::State* state = quic_server_info->mutable_state(); |
| 562 // Minimum SCFG that passes config validation checks. |
| 563 const char scfg[] = {// SCFG |
| 564 0x53, 0x43, 0x46, 0x47, |
| 565 // num entries |
| 566 0x01, 0x00, |
| 567 // padding |
| 568 0x00, 0x00, |
| 569 // EXPY |
| 570 0x45, 0x58, 0x50, 0x59, |
| 571 // EXPY end offset |
| 572 0x08, 0x00, 0x00, 0x00, |
| 573 // Value |
| 574 '1', '2', '3', '4', '5', '6', '7', '8'}; |
| 575 |
| 576 // Create temporary strings becasue Persist() clears string data in |state|. |
| 577 string server_config(reinterpret_cast<const char*>(&scfg), sizeof(scfg)); |
| 578 string source_address_token("test_source_address_token"); |
| 579 string cert_sct("test_cert_sct"); |
| 580 string chlo_hash("test_chlo_hash"); |
| 581 string signature("test_signature"); |
| 582 string test_cert("test_cert"); |
| 583 vector<string> certs; |
| 584 certs.push_back(test_cert); |
| 585 state->server_config = server_config; |
| 586 state->source_address_token = source_address_token; |
| 587 state->cert_sct = cert_sct; |
| 588 state->chlo_hash = chlo_hash; |
| 589 state->server_config_sig = signature; |
| 590 state->certs = certs; |
| 591 |
| 592 quic_server_info->Persist(); |
| 593 |
| 594 QuicServerId quic_server_id2(kServer2HostName, 80, PRIVACY_MODE_DISABLED); |
| 595 std::unique_ptr<QuicServerInfo> quic_server_info2( |
| 596 quic_server_info_factory->GetForServer(quic_server_id2)); |
| 597 |
| 598 // Update quic_server_info2's server_config and persist it. |
| 599 QuicServerInfo::State* state2 = quic_server_info2->mutable_state(); |
| 600 |
| 601 // Minimum SCFG that passes config validation checks. |
| 602 const char scfg2[] = {// SCFG |
| 603 0x53, 0x43, 0x46, 0x47, |
| 604 // num entries |
| 605 0x01, 0x00, |
| 606 // padding |
| 607 0x00, 0x00, |
| 608 // EXPY |
| 609 0x45, 0x58, 0x50, 0x59, |
| 610 // EXPY end offset |
| 611 0x08, 0x00, 0x00, 0x00, |
| 612 // Value |
| 613 '8', '7', '3', '4', '5', '6', '2', '1'}; |
| 614 |
| 615 // Create temporary strings becasue Persist() clears string data in |
| 616 // |state2|. |
| 617 string server_config2(reinterpret_cast<const char*>(&scfg2), sizeof(scfg2)); |
| 618 string source_address_token2("test_source_address_token2"); |
| 619 string cert_sct2("test_cert_sct2"); |
| 620 string chlo_hash2("test_chlo_hash2"); |
| 621 string signature2("test_signature2"); |
| 622 string test_cert2("test_cert2"); |
| 623 vector<string> certs2; |
| 624 certs2.push_back(test_cert2); |
| 625 state2->server_config = server_config2; |
| 626 state2->source_address_token = source_address_token2; |
| 627 state2->cert_sct = cert_sct2; |
| 628 state2->chlo_hash = chlo_hash2; |
| 629 state2->server_config_sig = signature2; |
| 630 state2->certs = certs2; |
| 631 |
| 632 quic_server_info2->Persist(); |
| 633 |
| 634 QuicStreamFactoryPeer::MaybeInitialize(factory_.get()); |
| 635 EXPECT_TRUE(QuicStreamFactoryPeer::HasInitializedData(factory_.get())); |
| 636 |
| 637 // Verify the MRU order is maintained. |
| 638 const QuicServerInfoMap& quic_server_info_map = |
| 639 http_server_properties_.quic_server_info_map(); |
| 640 EXPECT_EQ(2u, quic_server_info_map.size()); |
| 641 QuicServerInfoMap::const_iterator quic_server_info_map_it = |
| 642 quic_server_info_map.begin(); |
| 643 EXPECT_EQ(quic_server_info_map_it->first, quic_server_id2); |
| 644 ++quic_server_info_map_it; |
| 645 EXPECT_EQ(quic_server_info_map_it->first, quic_server_id); |
| 646 |
| 647 EXPECT_TRUE(QuicStreamFactoryPeer::SupportsQuicAtStartUp(factory_.get(), |
| 648 host_port_pair_)); |
| 649 EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( |
| 650 factory_.get(), quic_server_id)); |
| 651 QuicCryptoClientConfig* crypto_config = |
| 652 QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); |
| 653 QuicCryptoClientConfig::CachedState* cached = |
| 654 crypto_config->LookupOrCreate(quic_server_id); |
| 655 EXPECT_FALSE(cached->server_config().empty()); |
| 656 EXPECT_TRUE(cached->GetServerConfig()); |
| 657 EXPECT_EQ(server_config, cached->server_config()); |
| 658 EXPECT_EQ(source_address_token, cached->source_address_token()); |
| 659 EXPECT_EQ(cert_sct, cached->cert_sct()); |
| 660 EXPECT_EQ(chlo_hash, cached->chlo_hash()); |
| 661 EXPECT_EQ(signature, cached->signature()); |
| 662 ASSERT_EQ(1U, cached->certs().size()); |
| 663 EXPECT_EQ(test_cert, cached->certs()[0]); |
| 664 |
| 665 EXPECT_TRUE(QuicStreamFactoryPeer::SupportsQuicAtStartUp(factory_.get(), |
| 666 host_port_pair2)); |
| 667 EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( |
| 668 factory_.get(), quic_server_id2)); |
| 669 QuicCryptoClientConfig::CachedState* cached2 = |
| 670 crypto_config->LookupOrCreate(quic_server_id2); |
| 671 EXPECT_FALSE(cached2->server_config().empty()); |
| 672 EXPECT_TRUE(cached2->GetServerConfig()); |
| 673 EXPECT_EQ(server_config2, cached2->server_config()); |
| 674 EXPECT_EQ(source_address_token2, cached2->source_address_token()); |
| 675 EXPECT_EQ(cert_sct2, cached2->cert_sct()); |
| 676 EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); |
| 677 EXPECT_EQ(signature2, cached2->signature()); |
| 678 ASSERT_EQ(1U, cached->certs().size()); |
| 679 EXPECT_EQ(test_cert2, cached2->certs()[0]); |
| 680 } |
| 681 |
| 501 void RunTestLoopUntilIdle() { | 682 void RunTestLoopUntilIdle() { |
| 502 while (!runner_->GetPostedTasks().empty()) | 683 while (!runner_->GetPostedTasks().empty()) |
| 503 runner_->RunNextTask(); | 684 runner_->RunNextTask(); |
| 504 } | 685 } |
| 505 | 686 |
| 506 // Helper methods for tests of connection migration on write error. | 687 // Helper methods for tests of connection migration on write error. |
| 507 void TestMigrationOnWriteErrorNonMigratableStream(IoMode write_error_mode); | 688 void TestMigrationOnWriteErrorNonMigratableStream(IoMode write_error_mode); |
| 508 void TestMigrationOnWriteErrorMigrationDisabled(IoMode write_error_mode); | 689 void TestMigrationOnWriteErrorMigrationDisabled(IoMode write_error_mode); |
| 509 void TestMigrationOnWriteError(IoMode write_error_mode); | 690 void TestMigrationOnWriteError(IoMode write_error_mode); |
| 510 void TestMigrationOnWriteErrorNoNewNetwork(IoMode write_error_mode); | 691 void TestMigrationOnWriteErrorNoNewNetwork(IoMode write_error_mode); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 525 scoped_refptr<SSLConfigService> ssl_config_service_; | 706 scoped_refptr<SSLConfigService> ssl_config_service_; |
| 526 MockClientSocketFactory socket_factory_; | 707 MockClientSocketFactory socket_factory_; |
| 527 MockCryptoClientStreamFactory crypto_client_stream_factory_; | 708 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
| 528 MockRandom random_generator_; | 709 MockRandom random_generator_; |
| 529 MockClock* clock_; // Owned by |factory_| once created. | 710 MockClock* clock_; // Owned by |factory_| once created. |
| 530 scoped_refptr<TestTaskRunner> runner_; | 711 scoped_refptr<TestTaskRunner> runner_; |
| 531 QuicVersion version_; | 712 QuicVersion version_; |
| 532 QuicTestPacketMaker client_maker_; | 713 QuicTestPacketMaker client_maker_; |
| 533 QuicTestPacketMaker server_maker_; | 714 QuicTestPacketMaker server_maker_; |
| 534 HttpServerPropertiesImpl http_server_properties_; | 715 HttpServerPropertiesImpl http_server_properties_; |
| 716 TestProxyDelegate test_proxy_delegate_; |
| 535 std::unique_ptr<CertVerifier> cert_verifier_; | 717 std::unique_ptr<CertVerifier> cert_verifier_; |
| 536 std::unique_ptr<ChannelIDService> channel_id_service_; | 718 std::unique_ptr<ChannelIDService> channel_id_service_; |
| 537 TransportSecurityState transport_security_state_; | 719 TransportSecurityState transport_security_state_; |
| 538 std::unique_ptr<CTVerifier> cert_transparency_verifier_; | 720 std::unique_ptr<CTVerifier> cert_transparency_verifier_; |
| 539 CTPolicyEnforcer ct_policy_enforcer_; | 721 CTPolicyEnforcer ct_policy_enforcer_; |
| 540 std::unique_ptr<ScopedMockNetworkChangeNotifier> | 722 std::unique_ptr<ScopedMockNetworkChangeNotifier> |
| 541 scoped_mock_network_change_notifier_; | 723 scoped_mock_network_change_notifier_; |
| 542 std::unique_ptr<QuicStreamFactory> factory_; | 724 std::unique_ptr<QuicStreamFactory> factory_; |
| 543 HostPortPair host_port_pair_; | 725 HostPortPair host_port_pair_; |
| 544 GURL url_; | 726 GURL url_; |
| (...skipping 3902 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4447 | 4629 |
| 4448 EXPECT_THAT(callback_.WaitForResult(), IsOk()); | 4630 EXPECT_THAT(callback_.WaitForResult(), IsOk()); |
| 4449 | 4631 |
| 4450 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); | 4632 std::unique_ptr<QuicHttpStream> stream = request.CreateStream(); |
| 4451 EXPECT_TRUE(stream.get()); | 4633 EXPECT_TRUE(stream.get()); |
| 4452 EXPECT_TRUE(socket_data.AllReadDataConsumed()); | 4634 EXPECT_TRUE(socket_data.AllReadDataConsumed()); |
| 4453 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); | 4635 EXPECT_TRUE(socket_data.AllWriteDataConsumed()); |
| 4454 QuicStreamFactoryPeer::SetDelayTcpRace(factory_.get(), delay_tcp_race); | 4636 QuicStreamFactoryPeer::SetDelayTcpRace(factory_.get(), delay_tcp_race); |
| 4455 } | 4637 } |
| 4456 | 4638 |
| 4639 // Verifies that the QUIC stream factory is initialized correctly. |
| 4457 TEST_P(QuicStreamFactoryTest, MaybeInitialize) { | 4640 TEST_P(QuicStreamFactoryTest, MaybeInitialize) { |
| 4458 idle_connection_timeout_seconds_ = 500; | 4641 VerifyInitialization(false); |
| 4459 Initialize(); | 4642 } |
| 4460 ProofVerifyDetailsChromium verify_details = DefaultProofVerifyDetails(); | |
| 4461 crypto_client_stream_factory_.AddProofVerifyDetails(&verify_details); | |
| 4462 const QuicConfig* config = QuicStreamFactoryPeer::GetConfig(factory_.get()); | |
| 4463 EXPECT_EQ(500, config->IdleConnectionStateLifetime().ToSeconds()); | |
| 4464 | 4643 |
| 4465 QuicStreamFactoryPeer::SetTaskRunner(factory_.get(), runner_.get()); | 4644 // Verifies that the alternative proxy server provided by the proxy delegate |
| 4466 | 4645 // is added to the list of supported QUIC proxy servers, and the QUIC stream |
| 4467 const AlternativeService alternative_service1(QUIC, host_port_pair_.host(), | 4646 // factory is initialized correctly. |
| 4468 host_port_pair_.port()); | 4647 TEST_P(QuicStreamFactoryTest, MaybeInitializeAlternativeProxyServer) { |
| 4469 AlternativeServiceInfoVector alternative_service_info_vector; | 4648 VerifyInitialization(true); |
| 4470 base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); | |
| 4471 alternative_service_info_vector.push_back( | |
| 4472 AlternativeServiceInfo(alternative_service1, expiration)); | |
| 4473 http_server_properties_.SetAlternativeServices( | |
| 4474 url::SchemeHostPort(url_), alternative_service_info_vector); | |
| 4475 | |
| 4476 HostPortPair host_port_pair2(kServer2HostName, kDefaultServerPort); | |
| 4477 url::SchemeHostPort server2("https", kServer2HostName, kDefaultServerPort); | |
| 4478 const AlternativeService alternative_service2(QUIC, host_port_pair2.host(), | |
| 4479 host_port_pair2.port()); | |
| 4480 AlternativeServiceInfoVector alternative_service_info_vector2; | |
| 4481 alternative_service_info_vector2.push_back( | |
| 4482 AlternativeServiceInfo(alternative_service2, expiration)); | |
| 4483 http_server_properties_.SetAlternativeServices( | |
| 4484 server2, alternative_service_info_vector2); | |
| 4485 | |
| 4486 http_server_properties_.SetMaxServerConfigsStoredInProperties( | |
| 4487 kMaxQuicServersToPersist); | |
| 4488 | |
| 4489 QuicServerId quic_server_id(kDefaultServerHostName, 80, | |
| 4490 PRIVACY_MODE_DISABLED); | |
| 4491 QuicServerInfoFactory* quic_server_info_factory = | |
| 4492 new PropertiesBasedQuicServerInfoFactory(&http_server_properties_); | |
| 4493 factory_->set_quic_server_info_factory(quic_server_info_factory); | |
| 4494 | |
| 4495 std::unique_ptr<QuicServerInfo> quic_server_info( | |
| 4496 quic_server_info_factory->GetForServer(quic_server_id)); | |
| 4497 | |
| 4498 // Update quic_server_info's server_config and persist it. | |
| 4499 QuicServerInfo::State* state = quic_server_info->mutable_state(); | |
| 4500 // Minimum SCFG that passes config validation checks. | |
| 4501 const char scfg[] = {// SCFG | |
| 4502 0x53, 0x43, 0x46, 0x47, | |
| 4503 // num entries | |
| 4504 0x01, 0x00, | |
| 4505 // padding | |
| 4506 0x00, 0x00, | |
| 4507 // EXPY | |
| 4508 0x45, 0x58, 0x50, 0x59, | |
| 4509 // EXPY end offset | |
| 4510 0x08, 0x00, 0x00, 0x00, | |
| 4511 // Value | |
| 4512 '1', '2', '3', '4', '5', '6', '7', '8'}; | |
| 4513 | |
| 4514 // Create temporary strings becasue Persist() clears string data in |state|. | |
| 4515 string server_config(reinterpret_cast<const char*>(&scfg), sizeof(scfg)); | |
| 4516 string source_address_token("test_source_address_token"); | |
| 4517 string cert_sct("test_cert_sct"); | |
| 4518 string chlo_hash("test_chlo_hash"); | |
| 4519 string signature("test_signature"); | |
| 4520 string test_cert("test_cert"); | |
| 4521 vector<string> certs; | |
| 4522 certs.push_back(test_cert); | |
| 4523 state->server_config = server_config; | |
| 4524 state->source_address_token = source_address_token; | |
| 4525 state->cert_sct = cert_sct; | |
| 4526 state->chlo_hash = chlo_hash; | |
| 4527 state->server_config_sig = signature; | |
| 4528 state->certs = certs; | |
| 4529 | |
| 4530 quic_server_info->Persist(); | |
| 4531 | |
| 4532 QuicServerId quic_server_id2(kServer2HostName, 80, PRIVACY_MODE_DISABLED); | |
| 4533 std::unique_ptr<QuicServerInfo> quic_server_info2( | |
| 4534 quic_server_info_factory->GetForServer(quic_server_id2)); | |
| 4535 | |
| 4536 // Update quic_server_info2's server_config and persist it. | |
| 4537 QuicServerInfo::State* state2 = quic_server_info2->mutable_state(); | |
| 4538 | |
| 4539 // Minimum SCFG that passes config validation checks. | |
| 4540 const char scfg2[] = {// SCFG | |
| 4541 0x53, 0x43, 0x46, 0x47, | |
| 4542 // num entries | |
| 4543 0x01, 0x00, | |
| 4544 // padding | |
| 4545 0x00, 0x00, | |
| 4546 // EXPY | |
| 4547 0x45, 0x58, 0x50, 0x59, | |
| 4548 // EXPY end offset | |
| 4549 0x08, 0x00, 0x00, 0x00, | |
| 4550 // Value | |
| 4551 '8', '7', '3', '4', '5', '6', '2', '1'}; | |
| 4552 | |
| 4553 // Create temporary strings becasue Persist() clears string data in |state2|. | |
| 4554 string server_config2(reinterpret_cast<const char*>(&scfg2), sizeof(scfg2)); | |
| 4555 string source_address_token2("test_source_address_token2"); | |
| 4556 string cert_sct2("test_cert_sct2"); | |
| 4557 string chlo_hash2("test_chlo_hash2"); | |
| 4558 string signature2("test_signature2"); | |
| 4559 string test_cert2("test_cert2"); | |
| 4560 vector<string> certs2; | |
| 4561 certs2.push_back(test_cert2); | |
| 4562 state2->server_config = server_config2; | |
| 4563 state2->source_address_token = source_address_token2; | |
| 4564 state2->cert_sct = cert_sct2; | |
| 4565 state2->chlo_hash = chlo_hash2; | |
| 4566 state2->server_config_sig = signature2; | |
| 4567 state2->certs = certs2; | |
| 4568 | |
| 4569 quic_server_info2->Persist(); | |
| 4570 | |
| 4571 QuicStreamFactoryPeer::MaybeInitialize(factory_.get()); | |
| 4572 EXPECT_TRUE(QuicStreamFactoryPeer::HasInitializedData(factory_.get())); | |
| 4573 | |
| 4574 // Verify the MRU order is maintained. | |
| 4575 const QuicServerInfoMap& quic_server_info_map = | |
| 4576 http_server_properties_.quic_server_info_map(); | |
| 4577 EXPECT_EQ(2u, quic_server_info_map.size()); | |
| 4578 QuicServerInfoMap::const_iterator quic_server_info_map_it = | |
| 4579 quic_server_info_map.begin(); | |
| 4580 EXPECT_EQ(quic_server_info_map_it->first, quic_server_id2); | |
| 4581 ++quic_server_info_map_it; | |
| 4582 EXPECT_EQ(quic_server_info_map_it->first, quic_server_id); | |
| 4583 | |
| 4584 EXPECT_TRUE(QuicStreamFactoryPeer::SupportsQuicAtStartUp(factory_.get(), | |
| 4585 host_port_pair_)); | |
| 4586 EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty(factory_.get(), | |
| 4587 quic_server_id)); | |
| 4588 QuicCryptoClientConfig* crypto_config = | |
| 4589 QuicStreamFactoryPeer::GetCryptoConfig(factory_.get()); | |
| 4590 QuicCryptoClientConfig::CachedState* cached = | |
| 4591 crypto_config->LookupOrCreate(quic_server_id); | |
| 4592 EXPECT_FALSE(cached->server_config().empty()); | |
| 4593 EXPECT_TRUE(cached->GetServerConfig()); | |
| 4594 EXPECT_EQ(server_config, cached->server_config()); | |
| 4595 EXPECT_EQ(source_address_token, cached->source_address_token()); | |
| 4596 EXPECT_EQ(cert_sct, cached->cert_sct()); | |
| 4597 EXPECT_EQ(chlo_hash, cached->chlo_hash()); | |
| 4598 EXPECT_EQ(signature, cached->signature()); | |
| 4599 ASSERT_EQ(1U, cached->certs().size()); | |
| 4600 EXPECT_EQ(test_cert, cached->certs()[0]); | |
| 4601 | |
| 4602 EXPECT_TRUE(QuicStreamFactoryPeer::SupportsQuicAtStartUp(factory_.get(), | |
| 4603 host_port_pair2)); | |
| 4604 EXPECT_FALSE(QuicStreamFactoryPeer::CryptoConfigCacheIsEmpty( | |
| 4605 factory_.get(), quic_server_id2)); | |
| 4606 QuicCryptoClientConfig::CachedState* cached2 = | |
| 4607 crypto_config->LookupOrCreate(quic_server_id2); | |
| 4608 EXPECT_FALSE(cached2->server_config().empty()); | |
| 4609 EXPECT_TRUE(cached2->GetServerConfig()); | |
| 4610 EXPECT_EQ(server_config2, cached2->server_config()); | |
| 4611 EXPECT_EQ(source_address_token2, cached2->source_address_token()); | |
| 4612 EXPECT_EQ(cert_sct2, cached2->cert_sct()); | |
| 4613 EXPECT_EQ(chlo_hash2, cached2->chlo_hash()); | |
| 4614 EXPECT_EQ(signature2, cached2->signature()); | |
| 4615 ASSERT_EQ(1U, cached->certs().size()); | |
| 4616 EXPECT_EQ(test_cert2, cached2->certs()[0]); | |
| 4617 } | 4649 } |
| 4618 | 4650 |
| 4619 TEST_P(QuicStreamFactoryTest, StartCertVerifyJob) { | 4651 TEST_P(QuicStreamFactoryTest, StartCertVerifyJob) { |
| 4620 Initialize(); | 4652 Initialize(); |
| 4621 | 4653 |
| 4622 MockQuicData socket_data; | 4654 MockQuicData socket_data; |
| 4623 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); | 4655 socket_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); |
| 4624 socket_data.AddSocketDataToFactory(&socket_factory_); | 4656 socket_data.AddSocketDataToFactory(&socket_factory_); |
| 4625 | 4657 |
| 4626 // Save current state of |race_cert_verification|. | 4658 // Save current state of |race_cert_verification|. |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5275 // Clear all cached states. | 5307 // Clear all cached states. |
| 5276 factory_->ClearCachedStatesInCryptoConfig( | 5308 factory_->ClearCachedStatesInCryptoConfig( |
| 5277 base::Callback<bool(const GURL&)>()); | 5309 base::Callback<bool(const GURL&)>()); |
| 5278 EXPECT_TRUE(test_cases[0].state->certs().empty()); | 5310 EXPECT_TRUE(test_cases[0].state->certs().empty()); |
| 5279 EXPECT_TRUE(test_cases[1].state->certs().empty()); | 5311 EXPECT_TRUE(test_cases[1].state->certs().empty()); |
| 5280 EXPECT_TRUE(test_cases[2].state->certs().empty()); | 5312 EXPECT_TRUE(test_cases[2].state->certs().empty()); |
| 5281 } | 5313 } |
| 5282 | 5314 |
| 5283 } // namespace test | 5315 } // namespace test |
| 5284 } // namespace net | 5316 } // namespace net |
| OLD | NEW |