#include "components/security_interstitials/content/stateful_ssl_host_state_delegate.h"
#include <stdint.h>
#include <functional>
#include <memory>
#include <optional>
#include <set>
#include <utility>
#include "base/base64.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/json/values_util.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/time/clock.h"
#include "base/time/default_clock.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "components/content_settings/core/browser/content_settings_pref_provider.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/security_interstitials/core/pref_names.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/storage_partition.h"
#include "net/base/hash_value.h"
#include "net/cert/x509_certificate.h"
#include "services/network/public/mojom/network_context.mojom.h"
#include "url/gurl.h"
namespace {
#if BUILDFLAG(IS_ANDROID)
StatefulSSLHostStateDelegate::RecurrentInterstitialMode
kRecurrentInterstitialDefaultMode =
StatefulSSLHostStateDelegate::RecurrentInterstitialMode::PREF;
#else
StatefulSSLHostStateDelegate::RecurrentInterstitialMode
kRecurrentInterstitialDefaultMode = …;
#endif
constexpr int kRecurrentInterstitialDefaultThreshold = …;
constexpr int kRecurrentInterstitialDefaultResetTime = …;
const uint64_t kDefaultCertErrorBypassExpirationInSeconds = …604800);
const uint64_t kHTTPSFirstModeBypassExpirationInSeconds = …1296000);
const char kSSLCertDecisionCertErrorMapKey[] = …;
const char kSSLCertDecisionExpirationTimeKey[] = …;
const char kSSLCertDecisionVersionKey[] = …;
const int kDefaultSSLCertDecisionVersion = …;
void UpdateRecurrentInterstitialPref(PrefService* pref_service,
base::Clock* clock,
int error,
int threshold) { … }
bool DoesRecurrentInterstitialPrefMeetThreshold(PrefService* pref_service,
base::Clock* clock,
int error,
int threshold,
int error_reset_time) { … }
GURL GetSecureGURLForHost(const std::string& host) { … }
std::string GetKey(const net::X509Certificate& cert, int error) { … }
bool HostFilterToPatternFilter(
base::OnceCallback<bool(const std::string&)> host_filter,
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern) { … }
}
StatefulSSLHostStateDelegate::StatefulSSLHostStateDelegate(
content::BrowserContext* browser_context,
PrefService* pref_service,
HostContentSettingsMap* host_content_settings_map)
: … { … }
StatefulSSLHostStateDelegate::~StatefulSSLHostStateDelegate() = default;
void StatefulSSLHostStateDelegate::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) { … }
void StatefulSSLHostStateDelegate::AllowCert(
const std::string& host,
const net::X509Certificate& cert,
int error,
content::StoragePartition* storage_partition) { … }
void StatefulSSLHostStateDelegate::Clear(
base::RepeatingCallback<bool(const std::string&)> host_filter) { … }
content::SSLHostStateDelegate::CertJudgment
StatefulSSLHostStateDelegate::QueryPolicy(
const std::string& host,
const net::X509Certificate& cert,
int error,
content::StoragePartition* storage_partition) { … }
void StatefulSSLHostStateDelegate::HostRanInsecureContent(
const std::string& host,
int child_id,
InsecureContentType content_type) { … }
bool StatefulSSLHostStateDelegate::DidHostRunInsecureContent(
const std::string& host,
int child_id,
InsecureContentType content_type) { … }
void StatefulSSLHostStateDelegate::AllowHttpForHost(
const std::string& host,
content::StoragePartition* storage_partition) { … }
bool StatefulSSLHostStateDelegate::IsHttpAllowedForHost(
const std::string& host,
content::StoragePartition* storage_partition) { … }
void StatefulSSLHostStateDelegate::SetHttpsEnforcementForHost(
const std::string& host,
bool enforced,
content::StoragePartition* storage_partition) { … }
bool StatefulSSLHostStateDelegate::IsHttpsEnforcedForUrl(
const GURL& url,
content::StoragePartition* storage_partition) { … }
std::set<GURL> StatefulSSLHostStateDelegate::GetHttpsEnforcedHosts(
content::StoragePartition* storage_partition) const { … }
void StatefulSSLHostStateDelegate::ClearHttpsOnlyModeAllowlist() { … }
void StatefulSSLHostStateDelegate::ClearHttpsEnforcelist() { … }
void StatefulSSLHostStateDelegate::RevokeUserAllowExceptions(
const std::string& host) { … }
bool StatefulSSLHostStateDelegate::HasAllowException(
const std::string& host,
content::StoragePartition* storage_partition) { … }
bool StatefulSSLHostStateDelegate::HasAllowExceptionForAnyHost(
content::StoragePartition* storage_partition) { … }
bool StatefulSSLHostStateDelegate::HasCertAllowExceptionForAnyHost(
content::StoragePartition* storage_partition) { … }
bool StatefulSSLHostStateDelegate::IsHttpAllowedForAnyHost(
content::StoragePartition* storage_partition) { … }
void StatefulSSLHostStateDelegate::RevokeUserAllowExceptionsHard(
const std::string& host) { … }
void StatefulSSLHostStateDelegate::DidDisplayErrorPage(int error) { … }
bool StatefulSSLHostStateDelegate::HasSeenRecurrentErrors(int error) const { … }
void StatefulSSLHostStateDelegate::ResetRecurrentErrorCountForTesting() { … }
bool StatefulSSLHostStateDelegate::
HttpsFirstBalancedModeSuppressedForTesting() { … }
void StatefulSSLHostStateDelegate::
SetHttpsFirstBalancedModeSuppressedForTesting(bool suppressed) { … }
void StatefulSSLHostStateDelegate::SetClockForTesting(
std::unique_ptr<base::Clock> clock) { … }
void StatefulSSLHostStateDelegate::SetRecurrentInterstitialThresholdForTesting(
int threshold) { … }
void StatefulSSLHostStateDelegate::SetRecurrentInterstitialModeForTesting(
StatefulSSLHostStateDelegate::RecurrentInterstitialMode mode) { … }
void StatefulSSLHostStateDelegate::SetRecurrentInterstitialResetTimeForTesting(
int reset) { … }
int StatefulSSLHostStateDelegate::GetRecurrentInterstitialThreshold() const { … }
int StatefulSSLHostStateDelegate::GetRecurrentInterstitialResetTime() const { … }
StatefulSSLHostStateDelegate::RecurrentInterstitialMode
StatefulSSLHostStateDelegate::GetRecurrentInterstitialMode() const { … }
bool StatefulSSLHostStateDelegate::HasCertAllowException(
const std::string& host,
content::StoragePartition* storage_partition) { … }
base::Value::Dict* StatefulSSLHostStateDelegate::GetValidCertDecisionsDict(
CreateDictionaryEntriesDisposition create_entries,
base::Value::Dict& dict) { … }