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

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

Issue 1392143003: Allways call didReceiveAuthenticationChallenge: completion handler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added a unittest; Updated comments; Created 5 years, 2 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/crl_set.h" 9 #include "net/cert/crl_set.h"
10 #include "net/cert/x509_certificate.h" 10 #include "net/cert/x509_certificate.h"
11 #include "net/log/net_log.h" 11 #include "net/log/net_log.h"
12 12
13 namespace web { 13 namespace web {
14 14
15 namespace { 15 namespace {
16 16
17 // Resource manager which keeps CertVerifyResult, X509Certificate and 17 // Resource manager which keeps CertVerifyResult, X509Certificate and
18 // BoundNetLog alive until verification is completed. Also holds unowned pointer 18 // BoundNetLog alive until verification is completed. Also holds unowned pointer
19 // to |net::CertVerifier::Request|. 19 // to |net::CertVerifier::Request|.
Ryan Sleevi 2015/10/28 18:32:27 This comment needs updating. Also, an explainer o
Eugene But (OOO till 7-30) 2015/10/29 15:43:38 Done.
20 struct VerificationContext 20 struct VerificationContext
21 : public base::RefCountedThreadSafe<VerificationContext> { 21 : public base::RefCountedThreadSafe<VerificationContext> {
22 VerificationContext(scoped_refptr<net::X509Certificate> cert, 22 VerificationContext(scoped_refptr<net::X509Certificate> cert,
23 net::NetLog* net_log) 23 net::NetLog* net_log)
24 : request(nullptr), 24 : request(nullptr),
25 cert(cert.Pass()), 25 cert(cert.Pass()),
26 net_log(net::BoundNetLog::Make( 26 net_log(net::BoundNetLog::Make(
27 net_log, 27 net_log,
28 net::NetLog::SOURCE_IOS_WEB_VIEW_CERT_VERIFIER)) {} 28 net::NetLog::SOURCE_IOS_WEB_VIEW_CERT_VERIFIER)) {}
29 // Unowned verification request. 29 // Verification request must be alive until verification is completed.
Ryan Sleevi 2015/10/28 18:32:27 I find this comment a bit confusing. You're making
Eugene But (OOO till 7-30) 2015/10/29 15:43:38 Done.
30 net::CertVerifier::Request* request; 30 scoped_ptr<net::CertVerifier::Request> request;
31 // The result of certificate verification. 31 // The result of certificate verification.
32 net::CertVerifyResult result; 32 net::CertVerifyResult result;
33 // Certificate being verified. 33 // Certificate being verified.
34 scoped_refptr<net::X509Certificate> cert; 34 scoped_refptr<net::X509Certificate> cert;
35 // BoundNetLog required by CertVerifier. 35 // BoundNetLog required by CertVerifier.
36 net::BoundNetLog net_log; 36 net::BoundNetLog net_log;
37 37
38 private: 38 private:
39 friend class base::RefCountedThreadSafe<VerificationContext>; 39 friend class base::RefCountedThreadSafe<VerificationContext>;
40 VerificationContext() = delete; 40 VerificationContext() = delete;
(...skipping 26 matching lines...) Expand all
67 DCHECK(thread_checker_.CalledOnValidThread()); 67 DCHECK(thread_checker_.CalledOnValidThread());
68 DCHECK(completion_handler); 68 DCHECK(completion_handler);
69 if (!params.cert || params.hostname.empty()) { 69 if (!params.cert || params.hostname.empty()) {
70 completion_handler(net::CertVerifyResult(), net::ERR_INVALID_ARGUMENT); 70 completion_handler(net::CertVerifyResult(), net::ERR_INVALID_ARGUMENT);
71 return; 71 return;
72 } 72 }
73 73
74 scoped_refptr<VerificationContext> context( 74 scoped_refptr<VerificationContext> context(
75 new VerificationContext(params.cert, net_log_)); 75 new VerificationContext(params.cert, net_log_));
76 net::CompletionCallback callback = base::BindBlock(^(int error) { 76 net::CompletionCallback callback = base::BindBlock(^(int error) {
77 // Remove pending request.
78 auto request_iterator = std::find(
79 pending_requests_.begin(), pending_requests_.end(), context->request);
80 DCHECK(pending_requests_.end() != request_iterator);
81 pending_requests_.erase(request_iterator);
82
83 completion_handler(context->result, error); 77 completion_handler(context->result, error);
84 }); 78 });
85 scoped_ptr<net::CertVerifier::Request> request; 79 scoped_ptr<net::CertVerifier::Request> request;
86 int error = cert_verifier_->Verify(params.cert.get(), params.hostname, 80 int error = cert_verifier_->Verify(params.cert.get(), params.hostname,
87 params.ocsp_response, params.flags, 81 params.ocsp_response, params.flags,
88 params.crl_set.get(), &(context->result), 82 params.crl_set.get(), &(context->result),
89 callback, &request, context->net_log); 83 callback, &request, context->net_log);
90 if (error == net::ERR_IO_PENDING) { 84 if (error == net::ERR_IO_PENDING) {
91 // Make sure that |net::CertVerifier::Request| is alive until either 85 // Make sure that |net::CertVerifier::Request| is alive until verification
92 // verification is completed or CertVerifierBlockAdapter is destroyed. 86 // is completed. It means that cert verification request will not be
93 pending_requests_.push_back(request.Pass()); 87 // cancellable but it will guarantee that |completion_handler| callback is
94 context->request = pending_requests_.back(); 88 // always called by this method, which is a part of API contract.
Ryan Sleevi 2015/10/28 18:32:27 This still reads a bit... weird. // Keep the |net
Eugene But (OOO till 7-30) 2015/10/29 15:43:38 Done.
89 context->request = request.Pass();
95 // Completion handler will be called from |callback| when verification 90 // Completion handler will be called from |callback| when verification
96 // request is completed. 91 // request is completed.
97 return; 92 return;
98 } 93 }
99 94
100 // Verification has either failed or result was retrieved from the cache. 95 // Verification has either failed or result was retrieved from the cache.
101 completion_handler(context->result, error); 96 completion_handler(context->result, error);
102 } 97 }
103 98
104 } // namespace web 99 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698