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

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

Issue 1306733006: Revert of WKWebView: Added cert verification API to web controller. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 "ios/web/net/cert_verifier_block_adapter.h" 5 #include "ios/web/net/cert_verifier_block_adapter.h"
6 6
7 #include "base/mac/bind_objc_block.h" 7 #include "base/mac/bind_objc_block.h"
8 #include "net/base/net_errors.h" 8 #include "net/base/net_errors.h"
9 #include "net/cert/cert_verify_result.h"
9 #include "net/cert/crl_set.h" 10 #include "net/cert/crl_set.h"
10 #include "net/cert/x509_certificate.h" 11 #include "net/cert/x509_certificate.h"
11 #include "net/log/net_log.h"
12 12
13 namespace web { 13 namespace net {
14 14
15 namespace { 15 namespace {
16 16
17 // Resource manager which keeps CertVerifyResult, X509Certificate and 17 // Resource manager which keeps CertVerifier::Request, CertVerifyResult and
18 // BoundNetLog alive until verification is completed. Also holds unowned pointer 18 // X509Certificate alive until verification is completed.
19 // to |net::CertVerifier::Request|. 19 struct VerificationContext : public base::RefCounted<VerificationContext> {
20 struct VerificationContext 20 VerificationContext(scoped_refptr<net::X509Certificate> cert) : cert(cert) {
21 : public base::RefCountedThreadSafe<VerificationContext> { 21 result.cert_status = CERT_STATUS_INVALID;
22 VerificationContext(scoped_refptr<net::X509Certificate> cert, 22 }
23 net::NetLog* net_log) 23 // Verification request. Must be alive until verification is completed,
24 : request(nullptr), 24 // otherwise it will be cancelled.
25 cert(cert.Pass()), 25 scoped_ptr<CertVerifier::Request> request;
26 net_log(net::BoundNetLog::Make(
27 net_log,
28 net::NetLog::SOURCE_IOS_WEB_VIEW_CERT_VERIFIER)) {}
29 // Unowned verification request.
30 net::CertVerifier::Request* request;
31 // The result of certificate verification. 26 // The result of certificate verification.
32 net::CertVerifyResult result; 27 CertVerifyResult result;
33 // Certificate being verified. 28 // Certificate being verificated.
34 scoped_refptr<net::X509Certificate> cert; 29 scoped_refptr<net::X509Certificate> cert;
35 // BoundNetLog required by CertVerifier. 30
36 net::BoundNetLog net_log; 31 // Copies CertVerifyResult and wraps it into a scoped_ptr.
32 scoped_ptr<CertVerifyResult> scoped_result() {
33 scoped_ptr<CertVerifyResult> scoped_result(new CertVerifyResult());
34 scoped_result->CopyFrom(result);
35 return scoped_result.Pass();
36 }
37 37
38 private: 38 private:
39 friend class base::RefCountedThreadSafe<VerificationContext>;
40 VerificationContext() = delete; 39 VerificationContext() = delete;
40 // Required by base::RefCounted.
41 friend class base::RefCounted<VerificationContext>;
41 ~VerificationContext() {} 42 ~VerificationContext() {}
42 }; 43 };
43 } 44 }
44 45
46 CertVerifierBlockAdapter::CertVerifierBlockAdapter()
47 : CertVerifierBlockAdapter(
48 scoped_ptr<CertVerifier>(CertVerifier::CreateDefault())) {
49 }
50
45 CertVerifierBlockAdapter::CertVerifierBlockAdapter( 51 CertVerifierBlockAdapter::CertVerifierBlockAdapter(
46 net::CertVerifier* cert_verifier, 52 scoped_ptr<CertVerifier> cert_verifier)
47 net::NetLog* net_log) 53 : cert_verifier_(cert_verifier.Pass()) {
48 : cert_verifier_(cert_verifier), net_log_(net_log) {
49 DCHECK(cert_verifier_); 54 DCHECK(cert_verifier_);
50 DCHECK(net_log_);
51 } 55 }
52 56
53 CertVerifierBlockAdapter::~CertVerifierBlockAdapter() { 57 CertVerifierBlockAdapter::~CertVerifierBlockAdapter() {
54 DCHECK(thread_checker_.CalledOnValidThread());
55 } 58 }
56 59
57 CertVerifierBlockAdapter::Params::Params( 60 CertVerifierBlockAdapter::Params::Params(scoped_refptr<X509Certificate> cert,
58 const scoped_refptr<net::X509Certificate>& cert, 61 const std::string& hostname)
59 const std::string& hostname) 62 : cert(cert),
60 : cert(cert), hostname(hostname), flags(0) {} 63 hostname(hostname),
64 flags(static_cast<CertVerifier::VerifyFlags>(0)) {
65 }
61 66
62 CertVerifierBlockAdapter::Params::~Params() { 67 CertVerifierBlockAdapter::Params::~Params() {
63 } 68 }
64 69
65 void CertVerifierBlockAdapter::Verify( 70 void CertVerifierBlockAdapter::Verify(
66 const Params& params, 71 const Params& params,
67 void (^completion_handler)(net::CertVerifyResult, int)) { 72 void (^completion_handler)(scoped_ptr<CertVerifyResult>, int)) {
68 DCHECK(thread_checker_.CalledOnValidThread());
69 DCHECK(completion_handler); 73 DCHECK(completion_handler);
70 if (!params.cert || params.hostname.empty()) {
71 completion_handler(net::CertVerifyResult(), net::ERR_INVALID_ARGUMENT);
72 return;
73 }
74 74
75 scoped_refptr<VerificationContext> context( 75 scoped_refptr<VerificationContext> context(
76 new VerificationContext(params.cert, net_log_)); 76 new VerificationContext(params.cert));
77 net::CompletionCallback callback = base::BindBlock(^(int error) { 77 CompletionCallback callback = base::BindBlock(^(int) {
78 // Remove pending request. 78 completion_handler(context->scoped_result(), 0);
79 auto request_iterator = std::find( 79 });
80 pending_requests_.begin(), pending_requests_.end(), context->request); 80 int status = cert_verifier_->Verify(params.cert.get(), params.hostname,
81 DCHECK(pending_requests_.end() != request_iterator); 81 params.ocsp_response, params.flags,
82 pending_requests_.erase(request_iterator); 82 params.crl_set.get(), &(context->result),
83 callback, &(context->request), net_log_);
83 84
84 completion_handler(context->result, error); 85 if (status == ERR_IO_PENDING) {
85 });
86 scoped_ptr<net::CertVerifier::Request> request;
87 int error = cert_verifier_->Verify(params.cert.get(), params.hostname,
88 params.ocsp_response, params.flags,
89 params.crl_set.get(), &(context->result),
90 callback, &request, context->net_log);
91 if (error == net::ERR_IO_PENDING) {
92 // Make sure that |net::CertVerifier::Request| is alive until either
93 // verification is completed or CertVerifierBlockAdapter is destroyed.
94 pending_requests_.push_back(request.Pass());
95 context->request = pending_requests_.back();
96 // Completion handler will be called from |callback| when verification 86 // Completion handler will be called from |callback| when verification
97 // request is completed. 87 // request is completed.
98 return; 88 return;
99 } 89 }
100 90
101 // Verification has either failed or result was retrieved from the cache. 91 // Verification has either failed or result was retrieved from the cache.
102 completion_handler(context->result, error); 92 completion_handler(status ? nullptr : context->scoped_result(), status);
103 } 93 }
104 94
105 } // namespace web 95 } // net
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