blob: 41b761ac1191445b7ed765bf74a8614dbd8a3b38 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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 team6dcf6ab2019-12-11 10:10:51 -080013#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050014
15namespace quic {
16namespace 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.
22class 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,
vasilvvc48c8712019-03-11 13:38:16 -070035 const std::string& hostname,
36 const std::string& server_config,
QUICHE teama6ef0a62019-03-07 20:34:33 -050037 QuicTransportVersion transport_version,
QUICHE team6dcf6ab2019-12-11 10:10:51 -080038 quiche::QuicheStringPiece chlo_hash,
QUICHE teama6ef0a62019-03-07 20:34:33 -050039 std::unique_ptr<ProofSource::Callback> callback) override;
40 QuicReferenceCountedPointer<Chain> GetCertChain(
41 const QuicSocketAddress& server_address,
vasilvvc48c8712019-03-11 13:38:16 -070042 const std::string& hostname) override;
QUICHE teama6ef0a62019-03-07 20:34:33 -050043 void ComputeTlsSignature(
44 const QuicSocketAddress& server_address,
vasilvvc48c8712019-03-11 13:38:16 -070045 const std::string& hostname,
QUICHE teama6ef0a62019-03-07 20:34:33 -050046 uint16_t signature_algorithm,
QUICHE team6dcf6ab2019-12-11 10:10:51 -080047 quiche::QuicheStringPiece in,
QUICHE teama6ef0a62019-03-07 20:34:33 -050048 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,
vasilvvc48c8712019-03-11 13:38:16 -070070 std::string hostname,
71 std::string server_config,
QUICHE teama6ef0a62019-03-07 20:34:33 -050072 QuicTransportVersion transport_version,
vasilvvc48c8712019-03-11 13:38:16 -070073 std::string chlo_hash,
QUICHE teama6ef0a62019-03-07 20:34:33 -050074 std::unique_ptr<ProofSource::Callback> callback,
75 ProofSource* delegate);
76 ~GetProofOp() override;
77
78 void Run() override;
79
80 private:
81 QuicSocketAddress server_address_;
vasilvvc48c8712019-03-11 13:38:16 -070082 std::string hostname_;
83 std::string server_config_;
QUICHE teama6ef0a62019-03-07 20:34:33 -050084 QuicTransportVersion transport_version_;
vasilvvc48c8712019-03-11 13:38:16 -070085 std::string chlo_hash_;
QUICHE teama6ef0a62019-03-07 20:34:33 -050086 std::unique_ptr<ProofSource::Callback> callback_;
87 ProofSource* delegate_;
88 };
89
90 class ComputeSignatureOp : public PendingOp {
91 public:
92 ComputeSignatureOp(const QuicSocketAddress& server_address,
vasilvvc48c8712019-03-11 13:38:16 -070093 std::string hostname,
QUICHE teama6ef0a62019-03-07 20:34:33 -050094 uint16_t sig_alg,
QUICHE team6dcf6ab2019-12-11 10:10:51 -080095 quiche::QuicheStringPiece in,
QUICHE teama6ef0a62019-03-07 20:34:33 -050096 std::unique_ptr<ProofSource::SignatureCallback> callback,
97 ProofSource* delegate);
98 ~ComputeSignatureOp() override;
99
100 void Run() override;
101
102 private:
103 QuicSocketAddress server_address_;
vasilvvc48c8712019-03-11 13:38:16 -0700104 std::string hostname_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500105 uint16_t sig_alg_;
vasilvvc48c8712019-03-11 13:38:16 -0700106 std::string in_;
QUICHE teama6ef0a62019-03-07 20:34:33 -0500107 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_