Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Side by Side Diff: ios/web/net/cert_verifier_block_adapter.cc

Issue 2225483002: [ios] Removed CertVerifierBlockAdapter. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed review comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 "ios/web/net/cert_verifier_block_adapter.h"
6
7 #include <utility>
8
9 #include "base/mac/bind_objc_block.h"
10 #include "net/base/net_errors.h"
11 #include "net/cert/crl_set.h"
12 #include "net/cert/x509_certificate.h"
13 #include "net/log/net_log.h"
14
15 namespace web {
16
17 namespace {
18
19 // Resource manager which keeps CertVerifyResult, X509Certificate,
20 // CertVerifier::Request and BoundNetLog alive until verification is completed.
21 // This class is refcounted so it can be captured by a block, keeping its
22 // members alive.
23 struct VerificationContext
24 : public base::RefCountedThreadSafe<VerificationContext> {
25 VerificationContext(scoped_refptr<net::X509Certificate> cert,
26 net::NetLog* net_log)
27 : request(nullptr),
28 cert(std::move(cert)),
29 net_log(net::BoundNetLog::Make(
30 net_log,
31 net::NetLog::SOURCE_IOS_WEB_VIEW_CERT_VERIFIER)) {}
32
33 // Stores the current verification request. The request must outlive the
34 // VerificationContext and the CertVerifierBlockAdapter, so that the
35 // verification request is not cancelled. CertVerifierBlockAdapter::Verify
36 // guarantees its completion handler to be called, which will not happen if
37 // verification request is cancelled.
38 std::unique_ptr<net::CertVerifier::Request> request;
39 // The result of certificate verification.
40 net::CertVerifyResult result;
41 // Certificate being verified.
42 scoped_refptr<net::X509Certificate> cert;
43 // BoundNetLog required by CertVerifier.
44 net::BoundNetLog net_log;
45
46 private:
47 friend class base::RefCountedThreadSafe<VerificationContext>;
48 VerificationContext() = delete;
49 ~VerificationContext() {}
50 };
51 }
52
53 CertVerifierBlockAdapter::CertVerifierBlockAdapter(
54 net::CertVerifier* cert_verifier,
55 net::NetLog* net_log)
56 : cert_verifier_(cert_verifier), net_log_(net_log) {
57 DCHECK(cert_verifier_);
58 }
59
60 CertVerifierBlockAdapter::~CertVerifierBlockAdapter() {
61 DCHECK(thread_checker_.CalledOnValidThread());
62 }
63
64 CertVerifierBlockAdapter::Params::Params(
65 const scoped_refptr<net::X509Certificate>& cert,
66 const std::string& hostname)
67 : cert(cert), hostname(hostname), flags(0) {}
68
69 CertVerifierBlockAdapter::Params::Params(const Params& other) = default;
70
71 CertVerifierBlockAdapter::Params::~Params() {
72 }
73
74 void CertVerifierBlockAdapter::Verify(
75 const Params& params,
76 void (^completion_handler)(net::CertVerifyResult, int)) {
77 DCHECK(thread_checker_.CalledOnValidThread());
78 DCHECK(completion_handler);
79 if (!params.cert || params.hostname.empty()) {
80 completion_handler(net::CertVerifyResult(), net::ERR_INVALID_ARGUMENT);
81 return;
82 }
83
84 scoped_refptr<VerificationContext> context(
85 new VerificationContext(params.cert, net_log_));
86 net::CompletionCallback callback = base::BindBlock(^(int error) {
87 completion_handler(context->result, error);
88 });
89 std::unique_ptr<net::CertVerifier::Request> request;
90 int error = cert_verifier_->Verify(
91 net::CertVerifier::RequestParams(params.cert.get(), params.hostname,
92 params.flags, params.ocsp_response,
93 net::CertificateList()),
94 params.crl_set.get(), &(context->result), callback, &request,
95 context->net_log);
96 if (error == net::ERR_IO_PENDING) {
97 // Keep the |net::CertVerifier::Request| alive until verification completes.
98 // Because |context| is kept alive by |callback| (through base::BindBlock),
99 // this means that the cert verification request cannot be cancelled.
100 // However, it guarantees that |callback| - and thus |completion_handler| -
101 // will always be called, which is a necessary part of the API contract of
102 // |CertVerifierBlockAdapter::Verify()|.
103 context->request = std::move(request);
104 // Completion handler will be called from |callback| when verification
105 // request is completed.
106 return;
107 }
108
109 // Verification has either failed or result was retrieved from the cache.
110 completion_handler(context->result, error);
111 }
112
113 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/net/cert_verifier_block_adapter.h ('k') | ios/web/net/cert_verifier_block_adapter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698