| 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/tools/quic/quic_dispatcher.h" | 5 #include "net/tools/quic/quic_dispatcher.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <ostream> | 8 #include <ostream> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "net/quic/core/crypto/crypto_handshake.h" | 13 #include "net/quic/core/crypto/crypto_handshake.h" |
| 14 #include "net/quic/core/crypto/quic_crypto_server_config.h" | 14 #include "net/quic/core/crypto/quic_crypto_server_config.h" |
| 15 #include "net/quic/core/crypto/quic_random.h" | 15 #include "net/quic/core/crypto/quic_random.h" |
| 16 #include "net/quic/core/quic_crypto_stream.h" | 16 #include "net/quic/core/quic_crypto_stream.h" |
| 17 #include "net/quic/core/quic_flags.h" | 17 #include "net/quic/core/quic_flags.h" |
| 18 #include "net/quic/core/quic_utils.h" | 18 #include "net/quic/core/quic_utils.h" |
| 19 #include "net/quic/test_tools/crypto_test_utils.h" | 19 #include "net/quic/test_tools/crypto_test_utils.h" |
| 20 #include "net/quic/test_tools/fake_proof_source.h" |
| 20 #include "net/quic/test_tools/quic_buffered_packet_store_peer.h" | 21 #include "net/quic/test_tools/quic_buffered_packet_store_peer.h" |
| 21 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" | 22 #include "net/quic/test_tools/quic_crypto_server_config_peer.h" |
| 22 #include "net/quic/test_tools/quic_test_utils.h" | 23 #include "net/quic/test_tools/quic_test_utils.h" |
| 23 #include "net/quic/test_tools/quic_time_wait_list_manager_peer.h" | 24 #include "net/quic/test_tools/quic_time_wait_list_manager_peer.h" |
| 24 #include "net/test/gtest_util.h" | 25 #include "net/test/gtest_util.h" |
| 25 #include "net/tools/epoll_server/epoll_server.h" | 26 #include "net/tools/epoll_server/epoll_server.h" |
| 26 #include "net/tools/quic/chlo_extractor.h" | 27 #include "net/tools/quic/chlo_extractor.h" |
| 27 #include "net/tools/quic/quic_epoll_alarm_factory.h" | 28 #include "net/tools/quic/quic_epoll_alarm_factory.h" |
| 28 #include "net/tools/quic/quic_epoll_connection_helper.h" | 29 #include "net/tools/quic/quic_epoll_connection_helper.h" |
| 29 #include "net/tools/quic/quic_packet_writer_wrapper.h" | 30 #include "net/tools/quic/quic_packet_writer_wrapper.h" |
| (...skipping 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1532 ProcessPacket(client_addr_, conn_id, true, false, SerializeFullCHLO()); | 1533 ProcessPacket(client_addr_, conn_id, true, false, SerializeFullCHLO()); |
| 1533 } | 1534 } |
| 1534 EXPECT_FALSE(store->HasChloForConnection(/*connection_id=*/1)); | 1535 EXPECT_FALSE(store->HasChloForConnection(/*connection_id=*/1)); |
| 1535 | 1536 |
| 1536 // CHLO on connection 1 should still be buffered. | 1537 // CHLO on connection 1 should still be buffered. |
| 1537 ProcessPacket(client_addr_, /*connection_id=*/1, true, false, | 1538 ProcessPacket(client_addr_, /*connection_id=*/1, true, false, |
| 1538 SerializeFullCHLO()); | 1539 SerializeFullCHLO()); |
| 1539 EXPECT_TRUE(store->HasChloForConnection(/*connection_id=*/1)); | 1540 EXPECT_TRUE(store->HasChloForConnection(/*connection_id=*/1)); |
| 1540 } | 1541 } |
| 1541 | 1542 |
| 1542 // Implementation of ProofSource which delegates to a ProofSourceForTesting, | |
| 1543 // except that when the async GetProof is called, it captures the call and | |
| 1544 // allows tests to see that a call is pending, which they can then cause to | |
| 1545 // complete at a time of their choosing. | |
| 1546 class FakeProofSource : public ProofSource { | |
| 1547 public: | |
| 1548 FakeProofSource() : delegate_(CryptoTestUtils::ProofSourceForTesting()) {} | |
| 1549 | |
| 1550 // Before this object is "active", all calls to GetProof will be delegated | |
| 1551 // immediately. Once "active", the async ones will be intercepted. This | |
| 1552 // distinction is necessary to ensure that GetProof can be called without | |
| 1553 // interference during test case setup. | |
| 1554 void Activate() { active_ = true; } | |
| 1555 | |
| 1556 bool GetProof(const IPAddress& server_ip, | |
| 1557 const string& hostname, | |
| 1558 const string& server_config, | |
| 1559 QuicVersion quic_version, | |
| 1560 StringPiece chlo_hash, | |
| 1561 scoped_refptr<ProofSource::Chain>* out_chain, | |
| 1562 string* out_signature, | |
| 1563 string* out_leaf_cert_sct) override { | |
| 1564 return delegate_->GetProof(server_ip, hostname, server_config, quic_version, | |
| 1565 chlo_hash, out_chain, out_signature, | |
| 1566 out_leaf_cert_sct); | |
| 1567 } | |
| 1568 | |
| 1569 void GetProof(const IPAddress& server_ip, | |
| 1570 const string& hostname, | |
| 1571 const string& server_config, | |
| 1572 QuicVersion quic_version, | |
| 1573 StringPiece chlo_hash, | |
| 1574 std::unique_ptr<ProofSource::Callback> callback) override { | |
| 1575 if (!active_) { | |
| 1576 scoped_refptr<Chain> chain; | |
| 1577 string signature; | |
| 1578 string leaf_cert_sct; | |
| 1579 const bool ok = | |
| 1580 GetProof(server_ip, hostname, server_config, quic_version, | |
| 1581 chlo_hash.as_string(), &chain, &signature, &leaf_cert_sct); | |
| 1582 callback->Run(ok, chain, signature, leaf_cert_sct, | |
| 1583 /* details = */ nullptr); | |
| 1584 return; | |
| 1585 } | |
| 1586 | |
| 1587 params_.push_back(Params{server_ip, hostname, server_config, quic_version, | |
| 1588 chlo_hash.as_string(), std::move(callback)}); | |
| 1589 } | |
| 1590 | |
| 1591 int NumPendingCallbacks() const { return params_.size(); } | |
| 1592 | |
| 1593 void InvokePendingCallback(int n) { | |
| 1594 CHECK(NumPendingCallbacks() > n); | |
| 1595 | |
| 1596 const Params& params = params_[n]; | |
| 1597 | |
| 1598 scoped_refptr<ProofSource::Chain> chain; | |
| 1599 string signature; | |
| 1600 string leaf_cert_sct; | |
| 1601 const bool ok = delegate_->GetProof(params.server_ip, params.hostname, | |
| 1602 params.server_config, | |
| 1603 params.quic_version, params.chlo_hash, | |
| 1604 &chain, &signature, &leaf_cert_sct); | |
| 1605 | |
| 1606 params.callback->Run(ok, chain, signature, leaf_cert_sct, | |
| 1607 /* details = */ nullptr); | |
| 1608 params_.erase(params_.begin() + n); | |
| 1609 } | |
| 1610 | |
| 1611 private: | |
| 1612 std::unique_ptr<ProofSource> delegate_; | |
| 1613 bool active_ = false; | |
| 1614 | |
| 1615 struct Params { | |
| 1616 IPAddress server_ip; | |
| 1617 string hostname; | |
| 1618 string server_config; | |
| 1619 QuicVersion quic_version; | |
| 1620 string chlo_hash; | |
| 1621 std::unique_ptr<ProofSource::Callback> callback; | |
| 1622 }; | |
| 1623 | |
| 1624 std::vector<Params> params_; | |
| 1625 }; | |
| 1626 | |
| 1627 // Test which exercises the async GetProof codepaths, especially in the context | 1543 // Test which exercises the async GetProof codepaths, especially in the context |
| 1628 // of stateless rejection. | 1544 // of stateless rejection. |
| 1629 class AsyncGetProofTest : public QuicDispatcherTest { | 1545 class AsyncGetProofTest : public QuicDispatcherTest { |
| 1630 public: | 1546 public: |
| 1631 AsyncGetProofTest() | 1547 AsyncGetProofTest() |
| 1632 : QuicDispatcherTest( | 1548 : QuicDispatcherTest( |
| 1633 std::unique_ptr<FakeProofSource>(new FakeProofSource())), | 1549 std::unique_ptr<FakeProofSource>(new FakeProofSource())), |
| 1634 client_addr_(net::test::Loopback4(), 1234), | 1550 client_addr_(net::test::Loopback4(), 1234), |
| 1635 crypto_config_peer_(&crypto_config_) { | 1551 crypto_config_peer_(&crypto_config_) { |
| 1636 FLAGS_enable_async_get_proof = true; | 1552 FLAGS_enable_async_get_proof = true; |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2105 check.Call(2); | 2021 check.Call(2); |
| 2106 GetFakeProofSource()->InvokePendingCallback(0); | 2022 GetFakeProofSource()->InvokePendingCallback(0); |
| 2107 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0); | 2023 ASSERT_EQ(GetFakeProofSource()->NumPendingCallbacks(), 0); |
| 2108 EXPECT_FALSE(store->HasBufferedPackets(conn_id)); | 2024 EXPECT_FALSE(store->HasBufferedPackets(conn_id)); |
| 2109 EXPECT_FALSE(time_wait_list_manager_->IsConnectionIdInTimeWait(conn_id)); | 2025 EXPECT_FALSE(time_wait_list_manager_->IsConnectionIdInTimeWait(conn_id)); |
| 2110 } | 2026 } |
| 2111 | 2027 |
| 2112 } // namespace | 2028 } // namespace |
| 2113 } // namespace test | 2029 } // namespace test |
| 2114 } // namespace net | 2030 } // namespace net |
| OLD | NEW |