OLD | NEW |
(Empty) | |
| 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 #include "net/quic/test_tools/fake_proof_source.h" |
| 6 #include "net/quic/test_tools/crypto_test_utils.h" |
| 7 |
| 8 using std::string; |
| 9 |
| 10 namespace net { |
| 11 namespace test { |
| 12 |
| 13 FakeProofSource::FakeProofSource() |
| 14 : delegate_(CryptoTestUtils::ProofSourceForTesting()) {} |
| 15 |
| 16 FakeProofSource::~FakeProofSource() {} |
| 17 |
| 18 FakeProofSource::Params::Params(const IPAddress& server_ip, |
| 19 std::string hostname, |
| 20 std::string server_config, |
| 21 QuicVersion quic_version, |
| 22 std::string chlo_hash, |
| 23 std::unique_ptr<ProofSource::Callback> callback) |
| 24 : server_ip(server_ip), |
| 25 hostname(hostname), |
| 26 server_config(server_config), |
| 27 quic_version(quic_version), |
| 28 chlo_hash(chlo_hash), |
| 29 callback(std::move(callback)) {} |
| 30 |
| 31 FakeProofSource::Params::~Params() {} |
| 32 |
| 33 FakeProofSource::Params::Params(FakeProofSource::Params&& other) = default; |
| 34 |
| 35 FakeProofSource::Params& FakeProofSource::Params::operator=( |
| 36 FakeProofSource::Params&& other) = default; |
| 37 |
| 38 void FakeProofSource::Activate() { |
| 39 active_ = true; |
| 40 } |
| 41 |
| 42 bool FakeProofSource::GetProof(const IPAddress& server_ip, |
| 43 const string& hostname, |
| 44 const string& server_config, |
| 45 QuicVersion quic_version, |
| 46 StringPiece chlo_hash, |
| 47 scoped_refptr<ProofSource::Chain>* out_chain, |
| 48 string* out_signature, |
| 49 string* out_leaf_cert_sct) { |
| 50 LOG(WARNING) << "Synchronous GetProof called"; |
| 51 return delegate_->GetProof(server_ip, hostname, server_config, quic_version, |
| 52 chlo_hash, out_chain, out_signature, |
| 53 out_leaf_cert_sct); |
| 54 } |
| 55 |
| 56 void FakeProofSource::GetProof( |
| 57 const IPAddress& server_ip, |
| 58 const string& hostname, |
| 59 const string& server_config, |
| 60 QuicVersion quic_version, |
| 61 StringPiece chlo_hash, |
| 62 std::unique_ptr<ProofSource::Callback> callback) { |
| 63 if (!active_) { |
| 64 scoped_refptr<Chain> chain; |
| 65 string signature; |
| 66 string leaf_cert_sct; |
| 67 const bool ok = GetProof(server_ip, hostname, server_config, quic_version, |
| 68 chlo_hash, &chain, &signature, &leaf_cert_sct); |
| 69 callback->Run(ok, chain, signature, leaf_cert_sct, |
| 70 /* details = */ nullptr); |
| 71 return; |
| 72 } |
| 73 |
| 74 LOG(WARNING) << "Asynchronous GetProof called"; |
| 75 params_.push_back(Params{server_ip, hostname, server_config, quic_version, |
| 76 chlo_hash.as_string(), std::move(callback)}); |
| 77 } |
| 78 |
| 79 int FakeProofSource::NumPendingCallbacks() const { |
| 80 return params_.size(); |
| 81 } |
| 82 |
| 83 void FakeProofSource::InvokePendingCallback(int n) { |
| 84 CHECK(NumPendingCallbacks() > n); |
| 85 |
| 86 const Params& params = params_[n]; |
| 87 |
| 88 scoped_refptr<ProofSource::Chain> chain; |
| 89 string signature; |
| 90 string leaf_cert_sct; |
| 91 const bool ok = |
| 92 delegate_->GetProof(params.server_ip, params.hostname, |
| 93 params.server_config, params.quic_version, |
| 94 params.chlo_hash, &chain, &signature, &leaf_cert_sct); |
| 95 |
| 96 params.callback->Run(ok, chain, signature, leaf_cert_sct, |
| 97 /* details = */ nullptr); |
| 98 auto it = params_.begin() + n; |
| 99 params_.erase(it); |
| 100 } |
| 101 |
| 102 } // namespace test |
| 103 } // namespace net |
OLD | NEW |