| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 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 | 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/platform/api/quic_logging.h" | 5 #include "net/quic/platform/api/quic_logging.h" |
| 6 #include "net/quic/test_tools/fake_proof_source.h" | 6 #include "net/quic/test_tools/fake_proof_source.h" |
| 7 #include "net/quic/test_tools/crypto_test_utils.h" | 7 #include "net/quic/test_tools/crypto_test_utils.h" |
| 8 | 8 |
| 9 using std::string; | 9 using std::string; |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 FakeProofSource::Params::Params(FakeProofSource::Params&& other) = default; | 36 FakeProofSource::Params::Params(FakeProofSource::Params&& other) = default; |
| 37 | 37 |
| 38 FakeProofSource::Params& FakeProofSource::Params::operator=( | 38 FakeProofSource::Params& FakeProofSource::Params::operator=( |
| 39 FakeProofSource::Params&& other) = default; | 39 FakeProofSource::Params&& other) = default; |
| 40 | 40 |
| 41 void FakeProofSource::Activate() { | 41 void FakeProofSource::Activate() { |
| 42 active_ = true; | 42 active_ = true; |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool FakeProofSource::GetProof( | |
| 46 const QuicSocketAddress& server_address, | |
| 47 const string& hostname, | |
| 48 const string& server_config, | |
| 49 QuicVersion quic_version, | |
| 50 StringPiece chlo_hash, | |
| 51 const QuicTagVector& connection_options, | |
| 52 QuicReferenceCountedPointer<ProofSource::Chain>* out_chain, | |
| 53 QuicCryptoProof* out_proof) { | |
| 54 QUIC_LOG(WARNING) << "Synchronous GetProof called"; | |
| 55 return delegate_->GetProof(server_address, hostname, server_config, | |
| 56 quic_version, chlo_hash, connection_options, | |
| 57 out_chain, out_proof); | |
| 58 } | |
| 59 | |
| 60 void FakeProofSource::GetProof( | 45 void FakeProofSource::GetProof( |
| 61 const QuicSocketAddress& server_address, | 46 const QuicSocketAddress& server_address, |
| 62 const string& hostname, | 47 const string& hostname, |
| 63 const string& server_config, | 48 const string& server_config, |
| 64 QuicVersion quic_version, | 49 QuicVersion quic_version, |
| 65 StringPiece chlo_hash, | 50 StringPiece chlo_hash, |
| 66 const QuicTagVector& connection_options, | 51 const QuicTagVector& connection_options, |
| 67 std::unique_ptr<ProofSource::Callback> callback) { | 52 std::unique_ptr<ProofSource::Callback> callback) { |
| 68 if (!active_) { | 53 if (!active_) { |
| 69 QuicReferenceCountedPointer<Chain> chain; | 54 delegate_->GetProof(server_address, hostname, server_config, quic_version, |
| 70 QuicCryptoProof proof; | 55 chlo_hash, connection_options, std::move(callback)); |
| 71 const bool ok = | |
| 72 GetProof(server_address, hostname, server_config, quic_version, | |
| 73 chlo_hash, connection_options, &chain, &proof); | |
| 74 callback->Run(ok, chain, proof, /* details = */ nullptr); | |
| 75 return; | 56 return; |
| 76 } | 57 } |
| 77 | 58 |
| 78 QUIC_LOG(WARNING) << "Asynchronous GetProof called"; | |
| 79 params_.push_back(Params{server_address, hostname, server_config, | 59 params_.push_back(Params{server_address, hostname, server_config, |
| 80 quic_version, chlo_hash.as_string(), | 60 quic_version, chlo_hash.as_string(), |
| 81 connection_options, std::move(callback)}); | 61 connection_options, std::move(callback)}); |
| 82 } | 62 } |
| 83 | 63 |
| 84 int FakeProofSource::NumPendingCallbacks() const { | 64 int FakeProofSource::NumPendingCallbacks() const { |
| 85 return params_.size(); | 65 return params_.size(); |
| 86 } | 66 } |
| 87 | 67 |
| 88 void FakeProofSource::InvokePendingCallback(int n) { | 68 void FakeProofSource::InvokePendingCallback(int n) { |
| 89 CHECK(NumPendingCallbacks() > n); | 69 CHECK(NumPendingCallbacks() > n); |
| 90 | 70 |
| 91 const Params& params = params_[n]; | 71 Params& params = params_[n]; |
| 92 | 72 |
| 93 QuicReferenceCountedPointer<ProofSource::Chain> chain; | 73 // Note: relies on the callback being invoked synchronously |
| 94 QuicCryptoProof proof; | 74 delegate_->GetProof(params.server_address, params.hostname, |
| 95 const bool ok = delegate_->GetProof( | 75 params.server_config, params.quic_version, |
| 96 params.server_address, params.hostname, params.server_config, | 76 params.chlo_hash, params.connection_options, |
| 97 params.quic_version, params.chlo_hash, params.connection_options, &chain, | 77 std::move(params.callback)); |
| 98 &proof); | |
| 99 | 78 |
| 100 params.callback->Run(ok, chain, proof, /* details = */ nullptr); | |
| 101 auto it = params_.begin() + n; | 79 auto it = params_.begin() + n; |
| 102 params_.erase(it); | 80 params_.erase(it); |
| 103 } | 81 } |
| 104 | 82 |
| 105 } // namespace test | 83 } // namespace test |
| 106 } // namespace net | 84 } // namespace net |
| OLD | NEW |