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 "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 #include "net/cert/cert_status_flags.h" | 10 #include "net/cert/cert_status_flags.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 MockCertVerifier::~MockCertVerifier() {} | 37 MockCertVerifier::~MockCertVerifier() {} |
38 | 38 |
39 int MockCertVerifier::Verify(X509Certificate* cert, | 39 int MockCertVerifier::Verify(X509Certificate* cert, |
40 const std::string& hostname, | 40 const std::string& hostname, |
41 int flags, | 41 int flags, |
42 CRLSet* crl_set, | 42 CRLSet* crl_set, |
43 CertVerifyResult* verify_result, | 43 CertVerifyResult* verify_result, |
44 const CompletionCallback& callback, | 44 const CompletionCallback& callback, |
45 RequestHandle* out_req, | 45 RequestHandle* out_req, |
46 const BoundNetLog& net_log) { | 46 const BoundNetLog& net_log) { |
47 RuleList::const_iterator it; | 47 if (cert) { |
Ryan Sleevi
2015/03/19 04:38:24
Why this change? The API contract of CertVerifier
| |
48 for (it = rules_.begin(); it != rules_.end(); ++it) { | 48 RuleList::const_iterator it; |
49 // Check just the server cert. Intermediates will be ignored. | 49 for (it = rules_.begin(); it != rules_.end(); ++it) { |
50 if (!it->cert->Equals(cert)) | 50 // Check just the server cert. Intermediates will be ignored. |
51 continue; | 51 if (!it->cert->Equals(cert)) |
52 if (!MatchPattern(hostname, it->hostname)) | 52 continue; |
53 continue; | 53 if (!MatchPattern(hostname, it->hostname)) |
54 *verify_result = it->result; | 54 continue; |
55 return it->rv; | 55 *verify_result = it->result; |
56 return it->rv; | |
57 } | |
56 } | 58 } |
57 | 59 |
58 // Fall through to the default. | 60 // Fall through to the default. |
59 verify_result->verified_cert = cert; | 61 verify_result->verified_cert = cert; |
60 verify_result->cert_status = MapNetErrorToCertStatus(default_result_); | 62 verify_result->cert_status = MapNetErrorToCertStatus(default_result_); |
61 return default_result_; | 63 return default_result_; |
62 } | 64 } |
63 | 65 |
64 void MockCertVerifier::CancelRequest(RequestHandle req) { | 66 void MockCertVerifier::CancelRequest(RequestHandle req) { |
65 NOTIMPLEMENTED(); | 67 NOTIMPLEMENTED(); |
66 } | 68 } |
67 | 69 |
68 void MockCertVerifier::AddResultForCert(X509Certificate* cert, | 70 void MockCertVerifier::AddResultForCert(X509Certificate* cert, |
69 const CertVerifyResult& verify_result, | 71 const CertVerifyResult& verify_result, |
70 int rv) { | 72 int rv) { |
71 AddResultForCertAndHost(cert, "*", verify_result, rv); | 73 AddResultForCertAndHost(cert, "*", verify_result, rv); |
72 } | 74 } |
73 | 75 |
74 void MockCertVerifier::AddResultForCertAndHost( | 76 void MockCertVerifier::AddResultForCertAndHost( |
75 X509Certificate* cert, | 77 X509Certificate* cert, |
76 const std::string& host_pattern, | 78 const std::string& host_pattern, |
77 const CertVerifyResult& verify_result, | 79 const CertVerifyResult& verify_result, |
78 int rv) { | 80 int rv) { |
79 Rule rule(cert, host_pattern, verify_result, rv); | 81 Rule rule(cert, host_pattern, verify_result, rv); |
80 rules_.push_back(rule); | 82 rules_.push_back(rule); |
81 } | 83 } |
82 | 84 |
83 } // namespace net | 85 } // namespace net |
OLD | NEW |