| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 "android_webview/browser/aw_ssl_host_state_delegate.h" | 5 #include "android_webview/browser/aw_ssl_host_state_delegate.h" |
| 6 | 6 |
| 7 #include "base/callback.h" |
| 7 #include "net/base/hash_value.h" | 8 #include "net/base/hash_value.h" |
| 8 | 9 |
| 9 using content::SSLHostStateDelegate; | 10 using content::SSLHostStateDelegate; |
| 10 | 11 |
| 11 namespace android_webview { | 12 namespace android_webview { |
| 12 | 13 |
| 13 namespace internal { | 14 namespace internal { |
| 14 net::SHA256HashValue getChainFingerprint256(const net::X509Certificate& cert) { | 15 net::SHA256HashValue getChainFingerprint256(const net::X509Certificate& cert) { |
| 15 net::SHA256HashValue fingerprint = | 16 net::SHA256HashValue fingerprint = |
| 16 net::X509Certificate::CalculateChainFingerprint256( | 17 net::X509Certificate::CalculateChainFingerprint256( |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // Intentional no-op for Android WebView. | 70 // Intentional no-op for Android WebView. |
| 70 return false; | 71 return false; |
| 71 } | 72 } |
| 72 | 73 |
| 73 void AwSSLHostStateDelegate::AllowCert(const std::string& host, | 74 void AwSSLHostStateDelegate::AllowCert(const std::string& host, |
| 74 const net::X509Certificate& cert, | 75 const net::X509Certificate& cert, |
| 75 net::CertStatus error) { | 76 net::CertStatus error) { |
| 76 cert_policy_for_host_[host].Allow(cert, error); | 77 cert_policy_for_host_[host].Allow(cert, error); |
| 77 } | 78 } |
| 78 | 79 |
| 79 void AwSSLHostStateDelegate::Clear() { | 80 void AwSSLHostStateDelegate::Clear( |
| 80 cert_policy_for_host_.clear(); | 81 const base::Callback<bool(const std::string&)>& host_filter) { |
| 82 if (host_filter.is_null()) { |
| 83 cert_policy_for_host_.clear(); |
| 84 return; |
| 85 } |
| 86 |
| 87 for (auto it = cert_policy_for_host_.begin(); |
| 88 it != cert_policy_for_host_.end();) { |
| 89 auto next_it = std::next(it); |
| 90 |
| 91 if (host_filter.Run(it->first)) |
| 92 cert_policy_for_host_.erase(it); |
| 93 |
| 94 it = next_it; |
| 95 } |
| 81 } | 96 } |
| 82 | 97 |
| 83 SSLHostStateDelegate::CertJudgment AwSSLHostStateDelegate::QueryPolicy( | 98 SSLHostStateDelegate::CertJudgment AwSSLHostStateDelegate::QueryPolicy( |
| 84 const std::string& host, | 99 const std::string& host, |
| 85 const net::X509Certificate& cert, | 100 const net::X509Certificate& cert, |
| 86 net::CertStatus error, | 101 net::CertStatus error, |
| 87 bool* expired_previous_decision) { | 102 bool* expired_previous_decision) { |
| 88 return cert_policy_for_host_[host].Check(cert, error) | 103 return cert_policy_for_host_[host].Check(cert, error) |
| 89 ? SSLHostStateDelegate::ALLOWED | 104 ? SSLHostStateDelegate::ALLOWED |
| 90 : SSLHostStateDelegate::DENIED; | 105 : SSLHostStateDelegate::DENIED; |
| 91 } | 106 } |
| 92 | 107 |
| 93 void AwSSLHostStateDelegate::RevokeUserAllowExceptions( | 108 void AwSSLHostStateDelegate::RevokeUserAllowExceptions( |
| 94 const std::string& host) { | 109 const std::string& host) { |
| 95 cert_policy_for_host_.erase(host); | 110 cert_policy_for_host_.erase(host); |
| 96 } | 111 } |
| 97 | 112 |
| 98 bool AwSSLHostStateDelegate::HasAllowException(const std::string& host) const { | 113 bool AwSSLHostStateDelegate::HasAllowException(const std::string& host) const { |
| 99 auto policy_iterator = cert_policy_for_host_.find(host); | 114 auto policy_iterator = cert_policy_for_host_.find(host); |
| 100 return policy_iterator != cert_policy_for_host_.end() && | 115 return policy_iterator != cert_policy_for_host_.end() && |
| 101 policy_iterator->second.HasAllowException(); | 116 policy_iterator->second.HasAllowException(); |
| 102 } | 117 } |
| 103 | 118 |
| 104 } // namespace android_webview | 119 } // namespace android_webview |
| OLD | NEW |