#include "services/network/sct_auditing/sct_auditing_reporter.h"
#include "base/base64.h"
#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/json/json_reader.h"
#include "base/json/values_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/rand_util.h"
#include "base/strings/escape.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/base/request_priority.h"
#include "net/http/http_status_code.h"
#include "net/traffic_annotation/network_traffic_annotation.h"
#include "services/network/network_context.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/network_service.mojom.h"
#include "services/network/public/mojom/url_response_head.mojom.h"
namespace network {
namespace {
constexpr int kSendSCTReportTimeoutSeconds = …;
constexpr size_t kHashdanceHashPrefixLength = …;
constexpr size_t kMaxLookupResponseSize = …;
constexpr char kLeafHashKey[] = …;
constexpr char kIssuedKey[] = …;
constexpr char kLogIdKey[] = …;
constexpr char kLogMMDKey[] = …;
constexpr char kCertificateExpiry[] = …;
constexpr char kLookupStatusKey[] = …;
constexpr char kLookupHashSuffixKey[] = …;
constexpr char kLookupLogStatusKey[] = …;
constexpr char kLookupLogIdKey[] = …;
constexpr char kLookupIngestedUntilKey[] = …;
constexpr char kLookupTimestampKey[] = …;
constexpr char kStatusOK[] = …;
std::optional<base::TimeDelta> g_retry_delay_for_testing = …;
void RecordLookupQueryResult(SCTAuditingReporter::LookupQueryResult result) { … }
void RecordSCTAuditingReportSucceededMetrics(bool success) { … }
void ReportSCTAuditingCompletionStatusMetrics(
SCTAuditingReporter::CompletionStatus status) { … }
std::string TruncatePrefix(base::span<char> bytes, size_t bits_number) { … }
std::string TruncateSuffix(base::span<char> bytes, size_t bits_number) { … }
}
const net::BackoffEntry::Policy SCTAuditingReporter::kDefaultBackoffPolicy = …;
constexpr int kMaxRetries = …;
std::optional<SCTAuditingReporter::SCTHashdanceMetadata>
SCTAuditingReporter::SCTHashdanceMetadata::FromValue(const base::Value& value) { … }
SCTAuditingReporter::SCTHashdanceMetadata::SCTHashdanceMetadata() = default;
SCTAuditingReporter::SCTHashdanceMetadata::~SCTHashdanceMetadata() = default;
SCTAuditingReporter::SCTHashdanceMetadata::SCTHashdanceMetadata(
SCTHashdanceMetadata&&) = default;
SCTAuditingReporter::SCTHashdanceMetadata&
SCTAuditingReporter::SCTHashdanceMetadata::operator=(SCTHashdanceMetadata&&) =
default;
base::Value SCTAuditingReporter::SCTHashdanceMetadata::ToValue() const { … }
void SCTAuditingReporter::SetRetryDelayForTesting(
std::optional<base::TimeDelta> delay) { … }
SCTAuditingReporter::SCTAuditingReporter(
NetworkContext* owner_network_context,
net::HashValue reporter_key,
std::unique_ptr<sct_auditing::SCTClientReport> report,
bool is_hashdance,
std::optional<SCTHashdanceMetadata> sct_hashdance_metadata,
mojom::SCTAuditingConfigurationPtr configuration,
mojom::URLLoaderFactory* url_loader_factory,
ReporterUpdatedCallback update_callback,
ReporterDoneCallback done_callback,
std::unique_ptr<net::BackoffEntry> persisted_backoff_entry,
bool counted_towards_report_limit)
: … { … }
SCTAuditingReporter::~SCTAuditingReporter() = default;
void SCTAuditingReporter::Start() { … }
void SCTAuditingReporter::OnCheckReportAllowedStatusComplete(bool allowed) { … }
void SCTAuditingReporter::ScheduleRequestWithBackoff(base::OnceClosure request,
base::TimeDelta delay) { … }
void SCTAuditingReporter::SendLookupQuery() { … }
void SCTAuditingReporter::OnSendLookupQueryComplete(
std::unique_ptr<std::string> response_body) { … }
void SCTAuditingReporter::SendReport() { … }
void SCTAuditingReporter::OnSendReportComplete(
scoped_refptr<net::HttpResponseHeaders> headers) { … }
void SCTAuditingReporter::MaybeRetryRequest() { … }
}