OLD | NEW |
---|---|
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 Loading... | |
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 } | |
61 if (it == rules_.end()) { | |
62 // Fall through to the default. | |
63 verify_result->verified_cert = params.certificate(); | |
64 verify_result->cert_status = MapNetErrorToCertStatus(default_result_); | |
65 result = default_result_; | |
58 } | 66 } |
59 | 67 |
60 // Fall through to the default. | 68 if (async_) { |
61 verify_result->verified_cert = params.certificate(); | 69 callback.Run(result); |
Ryan Sleevi
2017/04/12 21:53:17
BUG: This isn't consistent with how Chrome's async
martinkr
2017/04/24 23:54:26
Ah crap, I meant to look up how to properly do thi
Ryan Sleevi
2017/04/25 18:07:09
Yup! SG :)
| |
62 verify_result->cert_status = MapNetErrorToCertStatus(default_result_); | 70 return ERR_IO_PENDING; |
63 return default_result_; | 71 } |
72 return result; | |
64 } | 73 } |
65 | 74 |
66 void MockCertVerifier::AddResultForCert(scoped_refptr<X509Certificate> cert, | 75 void MockCertVerifier::AddResultForCert(scoped_refptr<X509Certificate> cert, |
67 const CertVerifyResult& verify_result, | 76 const CertVerifyResult& verify_result, |
68 int rv) { | 77 int rv) { |
69 AddResultForCertAndHost(std::move(cert), "*", verify_result, rv); | 78 AddResultForCertAndHost(std::move(cert), "*", verify_result, rv); |
70 } | 79 } |
71 | 80 |
72 void MockCertVerifier::AddResultForCertAndHost( | 81 void MockCertVerifier::AddResultForCertAndHost( |
73 scoped_refptr<X509Certificate> cert, | 82 scoped_refptr<X509Certificate> cert, |
74 const std::string& host_pattern, | 83 const std::string& host_pattern, |
75 const CertVerifyResult& verify_result, | 84 const CertVerifyResult& verify_result, |
76 int rv) { | 85 int rv) { |
77 rules_.push_back(Rule(std::move(cert), host_pattern, verify_result, rv)); | 86 rules_.push_back(Rule(std::move(cert), host_pattern, verify_result, rv)); |
78 } | 87 } |
79 | 88 |
80 } // namespace net | 89 } // namespace net |
OLD | NEW |