chromium/services/network/sct_auditing/sct_auditing_reporter.cc

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 =;

// The number of bits of an SCT leaf hash sent in a lookup query.
constexpr size_t kHashdanceHashPrefixLength =;

// The maximum allowed size for the lookup query response. 4MB.
constexpr size_t kMaxLookupResponseSize =;

// HashdanceMetadata JSON serialization keys.
constexpr char kLeafHashKey[] =;
constexpr char kIssuedKey[] =;
constexpr char kLogIdKey[] =;
constexpr char kLogMMDKey[] =;
constexpr char kCertificateExpiry[] =;

// Hashdance server response JSON keys.
constexpr char kLookupStatusKey[] =;
constexpr char kLookupHashSuffixKey[] =;
constexpr char kLookupLogStatusKey[] =;
constexpr char kLookupLogIdKey[] =;
constexpr char kLookupIngestedUntilKey[] =;
constexpr char kLookupTimestampKey[] =;

constexpr char kStatusOK[] =;

// Overrides the initial retry delay in SCTAuditingReporter::kBackoffPolicy if
// not nullopt.
std::optional<base::TimeDelta> g_retry_delay_for_testing =;

void RecordLookupQueryResult(SCTAuditingReporter::LookupQueryResult result) {}

// Records whether sending the report to the reporting server succeeded for each
// report sent.
void RecordSCTAuditingReportSucceededMetrics(bool success) {}

// Records whether a report succeeded/failed with retries.
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) {}

}  // namespace

// static
const net::BackoffEntry::Policy SCTAuditingReporter::kDefaultBackoffPolicy =;

// How many times an SCTAuditingReporter should retry sending an audit report.
// Given kDefaultBackoffPolicy above and 15 total retries, this means there will
// be five attempts in the first 30 minutes and then occasional retries for
// roughly the next five days.
// See more discussion in the SCT Auditing Retry and Persistence design doc:
// https://docs.google.com/document/d/1YTUzoG6BDF1QIxosaQDp2H5IzYY7_fwH8qNJXSVX8OQ/edit
constexpr int kMaxRetries =;

// static
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 {}

// static
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() {}

}  // namespace network