chromium/components/safe_browsing/core/browser/hashprefix_realtime/ohttp_key_service.cc

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

#include "components/safe_browsing/core/browser/hashprefix_realtime/ohttp_key_service.h"

#include "base/base64.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_functions.h"
#include "base/rand_util.h"
#include "base/strings/escape.h"
#include "components/prefs/pref_service.h"
#include "components/safe_browsing/core/browser/utils/backoff_operator.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/safe_browsing/core/common/hashprefix_realtime/hash_realtime_utils.h"
#include "components/safe_browsing/core/common/safe_browsing_prefs.h"
#include "components/safe_browsing/core/common/utils.h"
#include "google_apis/google_api_keys.h"
#include "net/base/net_errors.h"
#include "net/http/http_request_headers.h"
#include "net/http/http_status_code.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/simple_url_loader.h"
#include "services/network/public/mojom/url_response_head.mojom.h"

namespace {

constexpr base::TimeDelta kKeyFetchTimeout =;

constexpr char kKeyFetchServerUrl[] =;
// Key older than 3 days is considered expired and should be refetched.
constexpr base::TimeDelta kKeyExpirationDuration =;
// For slower rotated keys (the old mechanism), key older than 7 days is
// considered expired and should be refetched.
constexpr base::TimeDelta kSlowerKeyExpirationDuration =;

// Async fetch will kick in if the key is close to the expiration threshold.
constexpr base::TimeDelta kKeyCloseToExpirationThreshold =;

// The interval that async workflow checks the status of the key.
constexpr base::TimeDelta kAsyncFetchCheckInterval =;

// The minimum interval that async workflow checks the status of the key.
constexpr base::TimeDelta kAsyncFetchCheckMinInterval =;

// The error code represents that the server cannot successfully decrypt the
// request. Defined in
// https://www.ietf.org/archive/id/draft-ietf-ohai-ohttp-02.html#name-server-responsibilities
constexpr net::HttpStatusCode kKeyRelatedHttpErrorCode =;

// The header that the server sets if the server is able to decrypt the request,
// but the key is outdated.
constexpr char kKeyRotatedHeader[] =;

// The maximum delayed time to fetch a new key if the key fetch is triggered
// by the server.
constexpr int kServerTriggeredFetchMaxDelayTimeSec =;

// Backoff constants
const size_t kNumFailuresToEnforceBackoff =;
const size_t kMinBackOffResetDurationInSeconds =;   //  5 minutes.
const size_t kMaxBackOffResetDurationInSeconds =;  // 1 day.

constexpr net::NetworkTrafficAnnotationTag kOhttpKeyTrafficAnnotation =;

bool IsEnabled(PrefService* pref_service, std::optional<std::string> country) {}

GURL GetKeyFetchingUrl() {}

}  // namespace

namespace safe_browsing {

OhttpKeyService::OhttpKeyService(
    scoped_refptr<network::SharedURLLoaderFactory> url_loader_factory,
    PrefService* pref_service,
    PrefService* local_state,
    base::RepeatingCallback<std::optional<std::string>()> country_getter)
    :{}

OhttpKeyService::~OhttpKeyService() = default;

void OhttpKeyService::OnConfiguringPrefsChanged() {}

void OhttpKeyService::SetEnabled(bool enable) {}

void OhttpKeyService::GetOhttpKey(Callback callback) {}

void OhttpKeyService::NotifyLookupResponse(
    const std::string& key,
    int response_code,
    scoped_refptr<net::HttpResponseHeaders> headers) {}

void OhttpKeyService::StartFetch(Callback callback,
                                 FetchTriggerReason trigger_reason) {}

void OhttpKeyService::OnURLLoaderComplete(
    base::TimeTicks request_start_time,
    std::unique_ptr<std::string> response_body) {}

void OhttpKeyService::MaybeStartOrRescheduleAsyncFetch() {}

void OhttpKeyService::OnAsyncFetchCompleted(
    std::optional<std::string> ohttp_key) {}

bool OhttpKeyService::ShouldStartAsyncFetch() {}

void OhttpKeyService::MaybeStartServerTriggeredFetch(
    std::string previous_key,
    FetchTriggerReason trigger_reason) {}

void OhttpKeyService::PopulateKeyFromPref() {}

void OhttpKeyService::StoreKeyToPref() {}

void OhttpKeyService::Shutdown() {}

void OhttpKeyService::set_ohttp_key_for_testing(
    OhttpKeyAndExpiration ohttp_key) {}

std::optional<OhttpKeyService::OhttpKeyAndExpiration>
OhttpKeyService::get_ohttp_key_for_testing() {}

}  // namespace safe_browsing