#include "components/safe_browsing/core/browser/db/v4_protocol_manager_util.h"
#include <string_view>
#include "base/base64.h"
#include "base/hash/hash.h"
#include "base/hash/sha1.h"
#include "base/metrics/histogram_functions.h"
#include "base/rand_util.h"
#include "base/ranges/algorithm.h"
#include "base/strings/escape.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "components/version_info/version_info.h"
#include "crypto/sha2.h"
#include "google_apis/google_api_keys.h"
#include "net/base/ip_address.h"
#include "net/base/net_errors.h"
#include "net/http/http_request_headers.h"
#include "url/url_util.h"
Time;
namespace safe_browsing {
const char* g_sbv4_url_prefix_for_testing = …;
const char kSbV4UrlPrefix[] = …;
const base::FilePath::CharType kStoreSuffix[] = …);
namespace {
const char kSbReportsURLPrefix[] = …;
std::string Unescape(const std::string& url) { … }
std::string Escape(const std::string& url) { … }
}
V4ProtocolConfig GetV4ProtocolConfig(const std::string& client_name,
bool disable_auto_update) { … }
void SetSbV4UrlPrefixForTesting(const char* url_prefix) { … }
std::string GetReportUrl(const V4ProtocolConfig& config,
const std::string& method,
const ExtendedReportingLevel* reporting_level,
const bool is_enhanced_protection) { … }
std::ostream& operator<<(std::ostream& os, const ListIdentifier& id) { … }
PlatformType GetCurrentPlatformType() { … }
ListIdentifier GetChromeExtMalwareId() { … }
ListIdentifier GetChromeUrlApiId() { … }
ListIdentifier GetUrlBillingId() { … }
ListIdentifier GetUrlCsdDownloadAllowlistId() { … }
ListIdentifier GetUrlCsdAllowlistId() { … }
ListIdentifier GetUrlHighConfidenceAllowlistId() { … }
ListIdentifier GetUrlMalwareId() { … }
ListIdentifier GetUrlMalBinId() { … }
ListIdentifier GetUrlSocEngId() { … }
ListIdentifier GetUrlSubresourceFilterId() { … }
ListIdentifier GetUrlSuspiciousSiteId() { … }
ListIdentifier GetUrlUwsId() { … }
std::string GetUmaSuffixForStore(const base::FilePath& file_path) { … }
StoreAndHashPrefix::StoreAndHashPrefix(ListIdentifier list_id,
const HashPrefixStr& hash_prefix)
: … { … }
StoreAndHashPrefix::~StoreAndHashPrefix() { … }
bool StoreAndHashPrefix::operator==(const StoreAndHashPrefix& other) const { … }
bool StoreAndHashPrefix::operator!=(const StoreAndHashPrefix& other) const { … }
size_t StoreAndHashPrefix::hash() const { … }
bool SBThreatTypeSetIsValidForCheckBrowseUrl(const SBThreatTypeSet& set) { … }
bool ListIdentifier::operator==(const ListIdentifier& other) const { … }
bool ListIdentifier::operator!=(const ListIdentifier& other) const { … }
size_t ListIdentifier::hash() const { … }
ListIdentifier::ListIdentifier(PlatformType platform_type,
ThreatEntryType threat_entry_type,
ThreatType threat_type)
: … { … }
ListIdentifier::ListIdentifier(const ListUpdateResponse& response)
: … { … }
V4ProtocolConfig::V4ProtocolConfig(const std::string& client_name,
bool disable_auto_update,
const std::string& key_param,
const std::string& version)
: … { … }
V4ProtocolConfig::V4ProtocolConfig(const V4ProtocolConfig& other) = default;
V4ProtocolConfig::~V4ProtocolConfig() { … }
base::TimeDelta V4ProtocolManagerUtil::GetNextBackOffInterval(
size_t* error_count,
size_t* multiplier) { … }
void V4ProtocolManagerUtil::GetRequestUrlAndHeaders(
const std::string& request_base64,
const std::string& method_name,
const V4ProtocolConfig& config,
GURL* gurl,
net::HttpRequestHeaders* headers) { … }
std::string V4ProtocolManagerUtil::ComposeUrl(const std::string& prefix,
const std::string& method,
const std::string& request_base64,
const std::string& key_param) { … }
void V4ProtocolManagerUtil::UpdateHeaders(net::HttpRequestHeaders* headers) { … }
void V4ProtocolManagerUtil::UrlToFullHashes(
const GURL& url,
std::vector<FullHashStr>* full_hashes) { … }
bool V4ProtocolManagerUtil::FullHashToHashPrefix(const FullHashStr& full_hash,
PrefixSize prefix_size,
HashPrefixStr* hash_prefix) { … }
bool V4ProtocolManagerUtil::FullHashToSmallestHashPrefix(
const FullHashStr& full_hash,
HashPrefixStr* hash_prefix) { … }
bool V4ProtocolManagerUtil::FullHashMatchesHashPrefix(
const FullHashStr& full_hash,
const HashPrefixStr& hash_prefix) { … }
void V4ProtocolManagerUtil::GenerateHostsToCheck(
const GURL& url,
std::vector<std::string>* hosts) { … }
void V4ProtocolManagerUtil::GeneratePathsToCheck(
const GURL& url,
std::vector<std::string>* paths) { … }
void V4ProtocolManagerUtil::GeneratePatternsToCheck(
const GURL& url,
std::vector<std::string>* urls) { … }
FullHashStr V4ProtocolManagerUtil::GetFullHash(const GURL& url) { … }
void V4ProtocolManagerUtil::CanonicalizeUrl(const GURL& url,
std::string* canonicalized_hostname,
std::string* canonicalized_path,
std::string* canonicalized_query) { … }
std::string V4ProtocolManagerUtil::RemoveConsecutiveChars(std::string_view str,
const char c) { … }
void V4ProtocolManagerUtil::GenerateHostVariantsToCheck(
const std::string& host,
std::vector<std::string>* hosts) { … }
void V4ProtocolManagerUtil::GeneratePathVariantsToCheck(
const std::string& path,
const std::string& query,
std::vector<std::string>* paths) { … }
void V4ProtocolManagerUtil::SetClientInfoFromConfig(
ClientInfo* client_info,
const V4ProtocolConfig& config) { … }
void V4ProtocolManagerUtil::GetListClientStatesFromStoreStateMap(
const std::unique_ptr<StoreStateMap>& store_state_map,
std::vector<std::string>* list_client_states) { … }
}