2015-05-19 19:55:58 +02:00
|
|
|
// Copyright (c) 2014 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/ssl_host_state_delegate.h"
|
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
#include "base/callback.h"
|
2015-05-19 19:55:58 +02:00
|
|
|
#include "net/base/hash_value.h"
|
|
|
|
|
|
|
|
using content::SSLHostStateDelegate;
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CertPolicy::CertPolicy() {}
|
|
|
|
CertPolicy::~CertPolicy() {}
|
2015-05-19 19:55:58 +02:00
|
|
|
|
|
|
|
// For an allowance, we consider a given |cert| to be a match to a saved
|
|
|
|
// allowed cert if the |error| is an exact match to or subset of the errors
|
|
|
|
// in the saved CertStatus.
|
2018-06-19 00:08:20 +02:00
|
|
|
bool CertPolicy::Check(const net::X509Certificate& cert, int error) const {
|
2017-12-07 22:44:24 +01:00
|
|
|
net::SHA256HashValue fingerprint = cert.CalculateChainFingerprint256();
|
2018-02-15 01:12:09 +01:00
|
|
|
const auto& allowed_iter = allowed_.find(fingerprint);
|
2015-05-19 19:55:58 +02:00
|
|
|
if ((allowed_iter != allowed_.end()) && (allowed_iter->second & error) &&
|
|
|
|
((allowed_iter->second & error) == error)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-19 00:08:20 +02:00
|
|
|
void CertPolicy::Allow(const net::X509Certificate& cert, int error) {
|
2015-05-19 19:55:58 +02:00
|
|
|
// If this same cert had already been saved with a different error status,
|
|
|
|
// this will replace it with the new error status.
|
2017-12-07 22:44:24 +01:00
|
|
|
net::SHA256HashValue fingerprint = cert.CalculateChainFingerprint256();
|
2015-05-19 19:55:58 +02:00
|
|
|
allowed_[fingerprint] = error;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefSSLHostStateDelegate::CefSSLHostStateDelegate() {}
|
2015-05-19 19:55:58 +02:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
CefSSLHostStateDelegate::~CefSSLHostStateDelegate() {}
|
2015-05-19 19:55:58 +02:00
|
|
|
|
2016-08-31 13:25:56 +02:00
|
|
|
void CefSSLHostStateDelegate::HostRanInsecureContent(
|
|
|
|
const std::string& host,
|
|
|
|
int child_id,
|
|
|
|
InsecureContentType content_type) {
|
2015-05-19 19:55:58 +02:00
|
|
|
// Intentional no-op.
|
|
|
|
}
|
|
|
|
|
2016-08-31 13:25:56 +02:00
|
|
|
bool CefSSLHostStateDelegate::DidHostRunInsecureContent(
|
|
|
|
const std::string& host,
|
|
|
|
int child_id,
|
2019-09-04 17:13:32 +02:00
|
|
|
InsecureContentType content_type) {
|
2015-05-19 19:55:58 +02:00
|
|
|
// Intentional no-op.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefSSLHostStateDelegate::AllowCert(const std::string& host,
|
|
|
|
const net::X509Certificate& cert,
|
2020-03-04 01:29:39 +01:00
|
|
|
int error,
|
|
|
|
content::WebContents* web_contents) {
|
2015-05-19 19:55:58 +02:00
|
|
|
cert_policy_for_host_[host].Allow(cert, error);
|
|
|
|
}
|
|
|
|
|
2016-10-17 20:14:44 +02:00
|
|
|
void CefSSLHostStateDelegate::Clear(
|
2020-02-10 18:10:17 +01:00
|
|
|
const base::RepeatingCallback<bool(const std::string&)> host_filter) {
|
2016-10-17 20:14:44 +02:00
|
|
|
if (host_filter.is_null()) {
|
|
|
|
cert_policy_for_host_.clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto it = cert_policy_for_host_.begin();
|
|
|
|
it != cert_policy_for_host_.end();) {
|
|
|
|
auto next_it = std::next(it);
|
|
|
|
|
|
|
|
if (host_filter.Run(it->first))
|
|
|
|
cert_policy_for_host_.erase(it);
|
|
|
|
|
|
|
|
it = next_it;
|
|
|
|
}
|
2015-05-19 19:55:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SSLHostStateDelegate::CertJudgment CefSSLHostStateDelegate::QueryPolicy(
|
|
|
|
const std::string& host,
|
|
|
|
const net::X509Certificate& cert,
|
2020-03-04 01:29:39 +01:00
|
|
|
int error,
|
|
|
|
content::WebContents* web_contents) {
|
2015-05-19 19:55:58 +02:00
|
|
|
return cert_policy_for_host_[host].Check(cert, error)
|
|
|
|
? SSLHostStateDelegate::ALLOWED
|
|
|
|
: SSLHostStateDelegate::DENIED;
|
|
|
|
}
|
2015-06-06 00:06:48 +02:00
|
|
|
|
|
|
|
void CefSSLHostStateDelegate::RevokeUserAllowExceptions(
|
|
|
|
const std::string& host) {
|
|
|
|
cert_policy_for_host_.erase(host);
|
|
|
|
}
|
|
|
|
|
2020-03-04 01:29:39 +01:00
|
|
|
bool CefSSLHostStateDelegate::HasAllowException(
|
|
|
|
const std::string& host,
|
|
|
|
content::WebContents* web_contents) {
|
2015-06-06 00:06:48 +02:00
|
|
|
auto policy_iterator = cert_policy_for_host_.find(host);
|
|
|
|
return policy_iterator != cert_policy_for_host_.end() &&
|
|
|
|
policy_iterator->second.HasAllowException();
|
|
|
|
}
|