QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef QUICHE_QUIC_TEST_TOOLS_FAKE_PROOF_SOURCE_H_ |
| 6 | #define QUICHE_QUIC_TEST_TOOLS_FAKE_PROOF_SOURCE_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
| 12 | #include "net/third_party/quiche/src/quic/core/crypto/proof_source.h" |
QUICHE team | 6dcf6ab | 2019-12-11 10:10:51 -0800 | [diff] [blame] | 13 | #include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 14 | |
| 15 | namespace quic { |
| 16 | namespace test { |
| 17 | |
| 18 | // Implementation of ProofSource which delegates to a ProofSourceForTesting, |
| 19 | // except that when the async GetProof is called, it captures the call and |
| 20 | // allows tests to see that a call is pending, which they can then cause to |
| 21 | // complete at a time of their choosing. |
| 22 | class FakeProofSource : public ProofSource { |
| 23 | public: |
| 24 | FakeProofSource(); |
| 25 | ~FakeProofSource() override; |
| 26 | |
| 27 | // Before this object is "active", all calls to GetProof will be delegated |
| 28 | // immediately. Once "active", the async ones will be intercepted. This |
| 29 | // distinction is necessary to ensure that GetProof can be called without |
| 30 | // interference during test case setup. |
| 31 | void Activate(); |
| 32 | |
| 33 | // ProofSource interface |
| 34 | void GetProof(const QuicSocketAddress& server_address, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 35 | const std::string& hostname, |
| 36 | const std::string& server_config, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 37 | QuicTransportVersion transport_version, |
QUICHE team | 6dcf6ab | 2019-12-11 10:10:51 -0800 | [diff] [blame] | 38 | quiche::QuicheStringPiece chlo_hash, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 39 | std::unique_ptr<ProofSource::Callback> callback) override; |
| 40 | QuicReferenceCountedPointer<Chain> GetCertChain( |
| 41 | const QuicSocketAddress& server_address, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 42 | const std::string& hostname) override; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 43 | void ComputeTlsSignature( |
| 44 | const QuicSocketAddress& server_address, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 45 | const std::string& hostname, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 46 | uint16_t signature_algorithm, |
QUICHE team | 6dcf6ab | 2019-12-11 10:10:51 -0800 | [diff] [blame] | 47 | quiche::QuicheStringPiece in, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 48 | std::unique_ptr<ProofSource::SignatureCallback> callback) override; |
| 49 | |
| 50 | // Get the number of callbacks which are pending |
| 51 | int NumPendingCallbacks() const; |
| 52 | |
| 53 | // Invoke a pending callback. The index refers to the position in |
| 54 | // pending_ops_ of the callback to be completed. |
| 55 | void InvokePendingCallback(int n); |
| 56 | |
| 57 | private: |
| 58 | std::unique_ptr<ProofSource> delegate_; |
| 59 | bool active_ = false; |
| 60 | |
| 61 | class PendingOp { |
| 62 | public: |
| 63 | virtual ~PendingOp(); |
| 64 | virtual void Run() = 0; |
| 65 | }; |
| 66 | |
| 67 | class GetProofOp : public PendingOp { |
| 68 | public: |
| 69 | GetProofOp(const QuicSocketAddress& server_addr, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 70 | std::string hostname, |
| 71 | std::string server_config, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 72 | QuicTransportVersion transport_version, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 73 | std::string chlo_hash, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 74 | std::unique_ptr<ProofSource::Callback> callback, |
| 75 | ProofSource* delegate); |
| 76 | ~GetProofOp() override; |
| 77 | |
| 78 | void Run() override; |
| 79 | |
| 80 | private: |
| 81 | QuicSocketAddress server_address_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 82 | std::string hostname_; |
| 83 | std::string server_config_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 84 | QuicTransportVersion transport_version_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 85 | std::string chlo_hash_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 86 | std::unique_ptr<ProofSource::Callback> callback_; |
| 87 | ProofSource* delegate_; |
| 88 | }; |
| 89 | |
| 90 | class ComputeSignatureOp : public PendingOp { |
| 91 | public: |
| 92 | ComputeSignatureOp(const QuicSocketAddress& server_address, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 93 | std::string hostname, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 94 | uint16_t sig_alg, |
QUICHE team | 6dcf6ab | 2019-12-11 10:10:51 -0800 | [diff] [blame] | 95 | quiche::QuicheStringPiece in, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 96 | std::unique_ptr<ProofSource::SignatureCallback> callback, |
| 97 | ProofSource* delegate); |
| 98 | ~ComputeSignatureOp() override; |
| 99 | |
| 100 | void Run() override; |
| 101 | |
| 102 | private: |
| 103 | QuicSocketAddress server_address_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 104 | std::string hostname_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 105 | uint16_t sig_alg_; |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 106 | std::string in_; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 107 | std::unique_ptr<ProofSource::SignatureCallback> callback_; |
| 108 | ProofSource* delegate_; |
| 109 | }; |
| 110 | |
| 111 | std::vector<std::unique_ptr<PendingOp>> pending_ops_; |
| 112 | }; |
| 113 | |
| 114 | } // namespace test |
| 115 | } // namespace quic |
| 116 | |
| 117 | #endif // QUICHE_QUIC_TEST_TOOLS_FAKE_PROOF_SOURCE_H_ |