diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-07-31 15:50:41 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-08-30 12:35:23 +0000 |
commit | 7b2ffa587235a47d4094787d72f38102089f402a (patch) | |
tree | 30e82af9cbab08a7fa028bb18f4f2987a3f74dfa /chromium/net/cert_net | |
parent | d94af01c90575348c4e81a418257f254b6f8d225 (diff) | |
download | qtwebengine-chromium-7b2ffa587235a47d4094787d72f38102089f402a.tar.gz |
BASELINE: Update Chromium to 76.0.3809.94
Change-Id: I321c3f5f929c105aec0f98c5091ef6108822e647
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/net/cert_net')
-rw-r--r-- | chromium/net/cert_net/cert_net_fetcher_impl.cc | 261 | ||||
-rw-r--r-- | chromium/net/cert_net/cert_net_fetcher_impl.h | 51 | ||||
-rw-r--r-- | chromium/net/cert_net/cert_net_fetcher_impl_unittest.cc | 5 | ||||
-rw-r--r-- | chromium/net/cert_net/nss_ocsp_unittest.cc | 3 |
4 files changed, 193 insertions, 127 deletions
diff --git a/chromium/net/cert_net/cert_net_fetcher_impl.cc b/chromium/net/cert_net/cert_net_fetcher_impl.cc index e2f2083e7cb..11a1166a23a 100644 --- a/chromium/net/cert_net/cert_net_fetcher_impl.cc +++ b/chromium/net/cert_net/cert_net_fetcher_impl.cc @@ -99,8 +99,6 @@ const int kMaxResponseSizeInBytesForAia = 64 * 1024; // The default timeout in seconds for fetch requests. const int kTimeoutSeconds = 15; -class RequestCore; -struct RequestParams; class Job; struct JobToRequestParamsComparator; @@ -113,13 +111,15 @@ struct JobComparator { // owned types doesn't come until C++17. using JobSet = std::map<Job*, std::unique_ptr<Job>, JobComparator>; +} // namespace + // AsyncCertNetFetcherImpl manages URLRequests in an async fashion on the // URLRequestContexts's task runner thread. // // * Schedules // * De-duplicates requests // * Handles timeouts -class AsyncCertNetFetcherImpl { +class CertNetFetcherImpl::AsyncCertNetFetcherImpl { public: // Initializes AsyncCertNetFetcherImpl using the specified URLRequestContext // for issuing requests. |context| must remain valid until Shutdown() is @@ -162,6 +162,8 @@ class AsyncCertNetFetcherImpl { DISALLOW_COPY_AND_ASSIGN(AsyncCertNetFetcherImpl); }; +namespace { + // Policy for which URLs are allowed to be fetched. This is called both for the // initial URL and for each redirect. Returns OK on success or a net error // code on failure. @@ -196,9 +198,12 @@ enum HttpMethod { HTTP_METHOD_POST, }; +} // namespace + // RequestCore tracks an outstanding call to Fetch(). It is // reference-counted for ease of sharing between threads. -class RequestCore : public base::RefCountedThreadSafe<RequestCore> { +class CertNetFetcherImpl::RequestCore + : public base::RefCountedThreadSafe<RequestCore> { public: explicit RequestCore(scoped_refptr<base::SingleThreadTaskRunner> task_runner) : completion_event_(base::WaitableEvent::ResetPolicy::MANUAL, @@ -273,7 +278,7 @@ class RequestCore : public base::RefCountedThreadSafe<RequestCore> { DISALLOW_COPY_AND_ASSIGN(RequestCore); }; -struct RequestParams { +struct CertNetFetcherImpl::RequestParams { RequestParams(); bool operator<(const RequestParams& other) const; @@ -291,31 +296,36 @@ struct RequestParams { DISALLOW_COPY_AND_ASSIGN(RequestParams); }; -RequestParams::RequestParams() +CertNetFetcherImpl::RequestParams::RequestParams() : http_method(HTTP_METHOD_GET), max_response_bytes(0) {} -bool RequestParams::operator<(const RequestParams& other) const { +bool CertNetFetcherImpl::RequestParams::operator<( + const RequestParams& other) const { return std::tie(url, http_method, max_response_bytes, timeout) < std::tie(other.url, other.http_method, other.max_response_bytes, other.timeout); } +namespace { + // Job tracks an outstanding URLRequest as well as all of the pending requests // for it. class Job : public URLRequest::Delegate { public: - Job(std::unique_ptr<RequestParams> request_params, - AsyncCertNetFetcherImpl* parent); + Job(std::unique_ptr<CertNetFetcherImpl::RequestParams> request_params, + CertNetFetcherImpl::AsyncCertNetFetcherImpl* parent); ~Job() override; - const RequestParams& request_params() const { return *request_params_; } + const CertNetFetcherImpl::RequestParams& request_params() const { + return *request_params_; + } // Creates a request and attaches it to the job. When the job completes it // will notify the request of completion through OnJobCompleted. - void AttachRequest(scoped_refptr<RequestCore> request); + void AttachRequest(scoped_refptr<CertNetFetcherImpl::RequestCore> request); // Removes |request| from the job. - void DetachRequest(RequestCore* request); + void DetachRequest(CertNetFetcherImpl::RequestCore* request); // Creates and starts a URLRequest for the job. After the URLRequest has // completed, OnJobCompleted() will be invoked and all the registered requests @@ -363,10 +373,10 @@ class Job : public URLRequest::Delegate { void FailRequest(Error error); // The requests attached to this job. - std::vector<scoped_refptr<RequestCore>> requests_; + std::vector<scoped_refptr<CertNetFetcherImpl::RequestCore>> requests_; // The input parameters for starting a URLRequest. - std::unique_ptr<RequestParams> request_params_; + std::unique_ptr<CertNetFetcherImpl::RequestParams> request_params_; // The URLRequest response information. std::vector<uint8_t> response_body_; @@ -379,12 +389,14 @@ class Job : public URLRequest::Delegate { base::OneShotTimer timer_; // Non-owned pointer to the AsyncCertNetFetcherImpl that created this job. - AsyncCertNetFetcherImpl* parent_; + CertNetFetcherImpl::AsyncCertNetFetcherImpl* parent_; DISALLOW_COPY_AND_ASSIGN(Job); }; -void RequestCore::CancelJob() { +} // namespace + +void CertNetFetcherImpl::RequestCore::CancelJob() { if (!task_runner_->RunsTasksInCurrentSequence()) { task_runner_->PostTask(FROM_HERE, base::BindOnce(&RequestCore::CancelJob, this)); @@ -400,7 +412,7 @@ void RequestCore::CancelJob() { SignalImmediateError(); } -void RequestCore::SignalImmediateError() { +void CertNetFetcherImpl::RequestCore::SignalImmediateError() { // These data members are normally only written on the network thread, but it // is safe to write here from either thread. This is because // SignalImmediateError is only to be called before this request is attached @@ -416,8 +428,10 @@ void RequestCore::SignalImmediateError() { completion_event_.Signal(); } -Job::Job(std::unique_ptr<RequestParams> request_params, - AsyncCertNetFetcherImpl* parent) +namespace { + +Job::Job(std::unique_ptr<CertNetFetcherImpl::RequestParams> request_params, + CertNetFetcherImpl::AsyncCertNetFetcherImpl* parent) : request_params_(std::move(request_params)), parent_(parent) {} Job::~Job() { @@ -425,12 +439,13 @@ Job::~Job() { Stop(); } -void Job::AttachRequest(scoped_refptr<RequestCore> request) { +void Job::AttachRequest( + scoped_refptr<CertNetFetcherImpl::RequestCore> request) { request->AttachedToJob(this); requests_.push_back(std::move(request)); } -void Job::DetachRequest(RequestCore* request) { +void Job::DetachRequest(CertNetFetcherImpl::RequestCore* request) { std::unique_ptr<Job> delete_this; auto it = std::find(requests_.begin(), requests_.end(), request); @@ -610,13 +625,16 @@ void Job::FailRequest(Error error) { OnUrlRequestCompleted(result); } -AsyncCertNetFetcherImpl::AsyncCertNetFetcherImpl(URLRequestContext* context) +} // namespace + +CertNetFetcherImpl::AsyncCertNetFetcherImpl::AsyncCertNetFetcherImpl( + URLRequestContext* context) : context_(context) { // Allow creation to happen from another thread. thread_checker_.DetachFromThread(); } -AsyncCertNetFetcherImpl::~AsyncCertNetFetcherImpl() { +CertNetFetcherImpl::AsyncCertNetFetcherImpl::~AsyncCertNetFetcherImpl() { DCHECK(thread_checker_.CalledOnValidThread()); jobs_.clear(); } @@ -625,7 +643,7 @@ bool JobComparator::operator()(const Job* job1, const Job* job2) const { return job1->request_params() < job2->request_params(); } -void AsyncCertNetFetcherImpl::Fetch( +void CertNetFetcherImpl::AsyncCertNetFetcherImpl::Fetch( std::unique_ptr<RequestParams> request_params, scoped_refptr<RequestCore> request) { DCHECK(thread_checker_.CalledOnValidThread()); @@ -647,7 +665,7 @@ void AsyncCertNetFetcherImpl::Fetch( job->StartURLRequest(context_); } -void AsyncCertNetFetcherImpl::Shutdown() { +void CertNetFetcherImpl::AsyncCertNetFetcherImpl::Shutdown() { DCHECK(thread_checker_.CalledOnValidThread()); for (const auto& job : jobs_) { job.first->Cancel(); @@ -655,14 +673,19 @@ void AsyncCertNetFetcherImpl::Shutdown() { jobs_.clear(); } +namespace { + struct JobToRequestParamsComparator { bool operator()(const JobSet::value_type& job, - const RequestParams& value) const { + const CertNetFetcherImpl::RequestParams& value) const { return job.first->request_params() < value; } }; -Job* AsyncCertNetFetcherImpl::FindJob(const RequestParams& params) { +} // namespace + +Job* CertNetFetcherImpl::AsyncCertNetFetcherImpl::FindJob( + const RequestParams& params) { DCHECK(thread_checker_.CalledOnValidThread()); // The JobSet is kept in sorted order so items can be found using binary @@ -674,7 +697,8 @@ Job* AsyncCertNetFetcherImpl::FindJob(const RequestParams& params) { return nullptr; } -std::unique_ptr<Job> AsyncCertNetFetcherImpl::RemoveJob(Job* job) { +std::unique_ptr<Job> CertNetFetcherImpl::AsyncCertNetFetcherImpl::RemoveJob( + Job* job) { DCHECK(thread_checker_.CalledOnValidThread()); auto it = jobs_.find(job); CHECK(it != jobs_.end()); @@ -683,9 +707,12 @@ std::unique_ptr<Job> AsyncCertNetFetcherImpl::RemoveJob(Job* job) { return owned_job; } +namespace { + class CertNetFetcherRequestImpl : public CertNetFetcher::Request { public: - explicit CertNetFetcherRequestImpl(scoped_refptr<RequestCore> core) + explicit CertNetFetcherRequestImpl( + scoped_refptr<CertNetFetcherImpl::RequestCore> core) : core_(std::move(core)) { DCHECK(core_); } @@ -703,121 +730,115 @@ class CertNetFetcherRequestImpl : public CertNetFetcher::Request { } private: - scoped_refptr<RequestCore> core_; + scoped_refptr<CertNetFetcherImpl::RequestCore> core_; }; -class CertNetFetcherImpl : public CertNetFetcher { - public: - explicit CertNetFetcherImpl(URLRequestContext* context) - : task_runner_(base::ThreadTaskRunnerHandle::Get()), context_(context) {} +} // namespace - void Shutdown() override { - DCHECK(task_runner_->RunsTasksInCurrentSequence()); - if (impl_) { - impl_->Shutdown(); - impl_.reset(); - } - context_ = nullptr; - } +CertNetFetcherImpl::CertNetFetcherImpl() + : task_runner_(base::ThreadTaskRunnerHandle::Get()) {} - std::unique_ptr<Request> FetchCaIssuers(const GURL& url, - int timeout_milliseconds, - int max_response_bytes) override { - std::unique_ptr<RequestParams> request_params(new RequestParams); +CertNetFetcherImpl::~CertNetFetcherImpl() { + // The fetcher must be shutdown (at which point |context_| will be set to + // null) before destruction. + DCHECK(!context_); +} - request_params->url = url; - request_params->http_method = HTTP_METHOD_GET; - request_params->timeout = GetTimeout(timeout_milliseconds); - request_params->max_response_bytes = - GetMaxResponseBytes(max_response_bytes, kMaxResponseSizeInBytesForAia); +void CertNetFetcherImpl::SetURLRequestContext(URLRequestContext* context) { + DCHECK(task_runner_->RunsTasksInCurrentSequence()); + context_ = context; +} - return DoFetch(std::move(request_params)); +void CertNetFetcherImpl::Shutdown() { + DCHECK(task_runner_->RunsTasksInCurrentSequence()); + if (impl_) { + impl_->Shutdown(); + impl_.reset(); } + context_ = nullptr; +} - std::unique_ptr<Request> FetchCrl(const GURL& url, - int timeout_milliseconds, - int max_response_bytes) override { - std::unique_ptr<RequestParams> request_params(new RequestParams); +std::unique_ptr<CertNetFetcher::Request> CertNetFetcherImpl::FetchCaIssuers( + const GURL& url, + int timeout_milliseconds, + int max_response_bytes) { + std::unique_ptr<RequestParams> request_params(new RequestParams); - request_params->url = url; - request_params->http_method = HTTP_METHOD_GET; - request_params->timeout = GetTimeout(timeout_milliseconds); - request_params->max_response_bytes = - GetMaxResponseBytes(max_response_bytes, kMaxResponseSizeInBytesForCrl); + request_params->url = url; + request_params->http_method = HTTP_METHOD_GET; + request_params->timeout = GetTimeout(timeout_milliseconds); + request_params->max_response_bytes = + GetMaxResponseBytes(max_response_bytes, kMaxResponseSizeInBytesForAia); - return DoFetch(std::move(request_params)); - } + return DoFetch(std::move(request_params)); +} - WARN_UNUSED_RESULT std::unique_ptr<Request> FetchOcsp( - const GURL& url, - int timeout_milliseconds, - int max_response_bytes) override { - std::unique_ptr<RequestParams> request_params(new RequestParams); +std::unique_ptr<CertNetFetcher::Request> CertNetFetcherImpl::FetchCrl( + const GURL& url, + int timeout_milliseconds, + int max_response_bytes) { + std::unique_ptr<RequestParams> request_params(new RequestParams); - request_params->url = url; - request_params->http_method = HTTP_METHOD_GET; - request_params->timeout = GetTimeout(timeout_milliseconds); - request_params->max_response_bytes = - GetMaxResponseBytes(max_response_bytes, kMaxResponseSizeInBytesForAia); + request_params->url = url; + request_params->http_method = HTTP_METHOD_GET; + request_params->timeout = GetTimeout(timeout_milliseconds); + request_params->max_response_bytes = + GetMaxResponseBytes(max_response_bytes, kMaxResponseSizeInBytesForCrl); - return DoFetch(std::move(request_params)); - } + return DoFetch(std::move(request_params)); +} - private: - ~CertNetFetcherImpl() override { - // The fetcher must be shutdown (at which point |context_| will be set to - // null) before destruction. - DCHECK(!context_); - } +std::unique_ptr<CertNetFetcher::Request> CertNetFetcherImpl::FetchOcsp( + const GURL& url, + int timeout_milliseconds, + int max_response_bytes) { + std::unique_ptr<RequestParams> request_params(new RequestParams); - void DoFetchOnNetworkSequence(std::unique_ptr<RequestParams> request_params, - scoped_refptr<RequestCore> request) { - DCHECK(task_runner_->RunsTasksInCurrentSequence()); + request_params->url = url; + request_params->http_method = HTTP_METHOD_GET; + request_params->timeout = GetTimeout(timeout_milliseconds); + request_params->max_response_bytes = + GetMaxResponseBytes(max_response_bytes, kMaxResponseSizeInBytesForAia); - if (!context_) { - // The fetcher might have been shutdown between when this task was posted - // and when it is running. In this case, signal the request and do not - // start a network request. - request->SignalImmediateError(); - return; - } + return DoFetch(std::move(request_params)); +} - if (!impl_) { - impl_.reset(new AsyncCertNetFetcherImpl(context_)); - } +void CertNetFetcherImpl::DoFetchOnNetworkSequence( + std::unique_ptr<RequestParams> request_params, + scoped_refptr<RequestCore> request) { + DCHECK(task_runner_->RunsTasksInCurrentSequence()); - impl_->Fetch(std::move(request_params), request); + if (!context_) { + // The fetcher might have been shutdown between when this task was posted + // and when it is running. In this case, signal the request and do not + // start a network request. + request->SignalImmediateError(); + return; } - std::unique_ptr<Request> DoFetch( - std::unique_ptr<RequestParams> request_params) { - scoped_refptr<RequestCore> request_core = new RequestCore(task_runner_); - - // If the fetcher has already been shutdown, DoFetchOnNetworkSequence will - // signal the request with an error. However, if the fetcher shuts down - // before DoFetchOnNetworkSequence runs and PostTask still returns true, - // then the request will hang (that is, WaitForResult will not return). - if (!task_runner_->PostTask( - FROM_HERE, - base::BindOnce(&CertNetFetcherImpl::DoFetchOnNetworkSequence, this, - std::move(request_params), request_core))) { - request_core->SignalImmediateError(); - } - - return std::make_unique<CertNetFetcherRequestImpl>(std::move(request_core)); + if (!impl_) { + impl_.reset(new AsyncCertNetFetcherImpl(context_)); } - private: - scoped_refptr<base::SingleThreadTaskRunner> task_runner_; - // Not owned. |context_| must stay valid until Shutdown() is called. - URLRequestContext* context_ = nullptr; - std::unique_ptr<AsyncCertNetFetcherImpl> impl_; -}; + impl_->Fetch(std::move(request_params), request); +} -} // namespace +std::unique_ptr<CertNetFetcherImpl::Request> CertNetFetcherImpl::DoFetch( + std::unique_ptr<RequestParams> request_params) { + scoped_refptr<RequestCore> request_core = new RequestCore(task_runner_); + + // If the fetcher has already been shutdown, DoFetchOnNetworkSequence will + // signal the request with an error. However, if the fetcher shuts down + // before DoFetchOnNetworkSequence runs and PostTask still returns true, + // then the request will hang (that is, WaitForResult will not return). + if (!task_runner_->PostTask( + FROM_HERE, + base::BindOnce(&CertNetFetcherImpl::DoFetchOnNetworkSequence, this, + std::move(request_params), request_core))) { + request_core->SignalImmediateError(); + } -scoped_refptr<CertNetFetcher> CreateCertNetFetcher(URLRequestContext* context) { - return base::MakeRefCounted<CertNetFetcherImpl>(context); + return std::make_unique<CertNetFetcherRequestImpl>(std::move(request_core)); } } // namespace net diff --git a/chromium/net/cert_net/cert_net_fetcher_impl.h b/chromium/net/cert_net/cert_net_fetcher_impl.h index 42a53c28dd9..b1ad43e3076 100644 --- a/chromium/net/cert_net/cert_net_fetcher_impl.h +++ b/chromium/net/cert_net/cert_net_fetcher_impl.h @@ -7,19 +7,62 @@ #include "base/memory/ref_counted.h" #include "net/base/net_export.h" +#include "net/cert/cert_net_fetcher.h" + +namespace base { +class SingleThreadTaskRunner; +} namespace net { -class CertNetFetcher; class URLRequestContext; -// Creates a CertNetFetcher that issues requests through the provided +// A CertNetFetcher that issues requests through the provided // URLRequestContext. The URLRequestContext must stay valid until the returned // CertNetFetcher's Shutdown method is called. The CertNetFetcher is to be // created and shutdown on the network thread. Its Fetch methods are to be used // on a *different* thread, since it gives a blocking interface to URL fetching. -NET_EXPORT scoped_refptr<CertNetFetcher> CreateCertNetFetcher( - URLRequestContext* context); +class NET_EXPORT CertNetFetcherImpl : public CertNetFetcher { + public: + class AsyncCertNetFetcherImpl; + class RequestCore; + struct RequestParams; + + // Creates the CertNetFetcherImpl. SetURLRequestContext must be called before + // the fetcher can be used. + CertNetFetcherImpl(); + + // Set the URLRequestContext this fetcher should use. + // |context_| must stay valid until Shutdown() is called. + void SetURLRequestContext(URLRequestContext* context); + + // CertNetFetcher impl: + void Shutdown() override; + std::unique_ptr<Request> FetchCaIssuers(const GURL& url, + int timeout_milliseconds, + int max_response_bytes) override; + std::unique_ptr<Request> FetchCrl(const GURL& url, + int timeout_milliseconds, + int max_response_bytes) override; + WARN_UNUSED_RESULT std::unique_ptr<Request> FetchOcsp( + const GURL& url, + int timeout_milliseconds, + int max_response_bytes) override; + + private: + ~CertNetFetcherImpl() override; + + void DoFetchOnNetworkSequence(std::unique_ptr<RequestParams> request_params, + scoped_refptr<RequestCore> request); + + std::unique_ptr<Request> DoFetch( + std::unique_ptr<RequestParams> request_params); + + scoped_refptr<base::SingleThreadTaskRunner> task_runner_; + // Not owned. |context_| must stay valid until Shutdown() is called. + URLRequestContext* context_ = nullptr; + std::unique_ptr<AsyncCertNetFetcherImpl> impl_; +}; } // namespace net diff --git a/chromium/net/cert_net/cert_net_fetcher_impl_unittest.cc b/chromium/net/cert_net/cert_net_fetcher_impl_unittest.cc index 87bfddfcffd..2456bb2898e 100644 --- a/chromium/net/cert_net/cert_net_fetcher_impl_unittest.cc +++ b/chromium/net/cert_net/cert_net_fetcher_impl_unittest.cc @@ -134,7 +134,8 @@ class CertNetFetcherImplTest : public PlatformTest { CertNetFetcher* fetcher() const { return fetcher_.get(); } void CreateFetcherOnNetworkThread(base::WaitableEvent* done) { - fetcher_ = CreateCertNetFetcher(&state_->context); + fetcher_ = base::MakeRefCounted<CertNetFetcherImpl>(); + fetcher_->SetURLRequestContext(&state_->context); done->Signal(); } @@ -223,7 +224,7 @@ class CertNetFetcherImplTest : public PlatformTest { EmbeddedTestServer test_server_; std::unique_ptr<base::Thread> network_thread_; - scoped_refptr<CertNetFetcher> fetcher_; + scoped_refptr<CertNetFetcherImpl> fetcher_; std::unique_ptr<NetworkThreadState> state_; }; diff --git a/chromium/net/cert_net/nss_ocsp_unittest.cc b/chromium/net/cert_net/nss_ocsp_unittest.cc index 9c42f2fb9d8..79984fff9ae 100644 --- a/chromium/net/cert_net/nss_ocsp_unittest.cc +++ b/chromium/net/cert_net/nss_ocsp_unittest.cc @@ -150,7 +150,8 @@ TEST_F(NssHttpTest, TestAia) { int flags = 0; int error = verifier()->Verify( CertVerifier::RequestParams(test_cert, "aia-host.invalid", flags, - std::string()), + /*ocsp_response=*/std::string(), + /*sct_list=*/std::string()), &verify_result, test_callback.callback(), &request, NetLogWithSource()); ASSERT_THAT(error, IsError(ERR_IO_PENDING)); |