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

Side by Side Diff: net/cert/mock_cert_verifier.cc

Issue 2753123002: Add --ignore-certificate-errors-spki-list switch and UMA histogram. (Closed)
Patch Set: Really add IgnoreErrorsCertVerifier. Created 3 years, 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/cert/mock_cert_verifier.h" 5 #include "net/cert/mock_cert_verifier.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 18 matching lines...) Expand all
29 DCHECK(cert); 29 DCHECK(cert);
30 DCHECK(result.verified_cert); 30 DCHECK(result.verified_cert);
31 } 31 }
32 32
33 scoped_refptr<X509Certificate> cert; 33 scoped_refptr<X509Certificate> cert;
34 std::string hostname; 34 std::string hostname;
35 CertVerifyResult result; 35 CertVerifyResult result;
36 int rv; 36 int rv;
37 }; 37 };
38 38
39 MockCertVerifier::MockCertVerifier() : default_result_(ERR_CERT_INVALID) {} 39 MockCertVerifier::MockCertVerifier()
40 : default_result_(ERR_CERT_INVALID), async_(false) {}
40 41
41 MockCertVerifier::~MockCertVerifier() {} 42 MockCertVerifier::~MockCertVerifier() {}
42 43
43 int MockCertVerifier::Verify(const RequestParams& params, 44 int MockCertVerifier::Verify(const RequestParams& params,
44 CRLSet* crl_set, 45 CRLSet* crl_set,
45 CertVerifyResult* verify_result, 46 CertVerifyResult* verify_result,
46 const CompletionCallback& callback, 47 const CompletionCallback& callback,
47 std::unique_ptr<Request>* out_req, 48 std::unique_ptr<Request>* out_req,
48 const NetLogWithSource& net_log) { 49 const NetLogWithSource& net_log) {
50 int result;
49 RuleList::const_iterator it; 51 RuleList::const_iterator it;
50 for (it = rules_.begin(); it != rules_.end(); ++it) { 52 for (it = rules_.begin(); it != rules_.end(); ++it) {
51 // Check just the server cert. Intermediates will be ignored. 53 // Check just the server cert. Intermediates will be ignored.
52 if (!it->cert->Equals(params.certificate().get())) 54 if (!it->cert->Equals(params.certificate().get()))
53 continue; 55 continue;
54 if (!base::MatchPattern(params.hostname(), it->hostname)) 56 if (!base::MatchPattern(params.hostname(), it->hostname))
55 continue; 57 continue;
56 *verify_result = it->result; 58 *verify_result = it->result;
57 return it->rv; 59 result = it->rv;
60 goto exit;
Ryan Sleevi 2017/04/07 16:08:05 We don't use goto in Chromium code
martinkr 2017/04/07 21:40:57 Done.
58 } 61 }
59 62
60 // Fall through to the default. 63 // Fall through to the default.
61 verify_result->verified_cert = params.certificate(); 64 verify_result->verified_cert = params.certificate();
62 verify_result->cert_status = MapNetErrorToCertStatus(default_result_); 65 verify_result->cert_status = MapNetErrorToCertStatus(default_result_);
63 return default_result_; 66 result = default_result_;
67
68 exit:
69 if (async_) {
70 callback.Run(result);
71 return ERR_IO_PENDING;
72 }
73 return result;
64 } 74 }
65 75
66 void MockCertVerifier::AddResultForCert(scoped_refptr<X509Certificate> cert, 76 void MockCertVerifier::AddResultForCert(scoped_refptr<X509Certificate> cert,
67 const CertVerifyResult& verify_result, 77 const CertVerifyResult& verify_result,
68 int rv) { 78 int rv) {
69 AddResultForCertAndHost(std::move(cert), "*", verify_result, rv); 79 AddResultForCertAndHost(std::move(cert), "*", verify_result, rv);
70 } 80 }
71 81
72 void MockCertVerifier::AddResultForCertAndHost( 82 void MockCertVerifier::AddResultForCertAndHost(
73 scoped_refptr<X509Certificate> cert, 83 scoped_refptr<X509Certificate> cert,
74 const std::string& host_pattern, 84 const std::string& host_pattern,
75 const CertVerifyResult& verify_result, 85 const CertVerifyResult& verify_result,
76 int rv) { 86 int rv) {
77 rules_.push_back(Rule(std::move(cert), host_pattern, verify_result, rv)); 87 rules_.push_back(Rule(std::move(cert), host_pattern, verify_result, rv));
78 } 88 }
79 89
80 } // namespace net 90 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698