#include "content/services/auction_worklet/trusted_signals_kvv2_helper.h"
#include <sys/types.h>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <numeric>
#include <optional>
#include <string>
#include <string_view>
#include <vector>
#include "base/check.h"
#include "base/containers/span.h"
#include "base/containers/span_reader.h"
#include "base/containers/span_writer.h"
#include "base/json/json_reader.h"
#include "base/memory/scoped_refptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "base/types/expected.h"
#include "base/types/optional_ref.h"
#include "components/cbor/reader.h"
#include "components/cbor/values.h"
#include "components/cbor/writer.h"
#include "content/common/features.h"
#include "content/services/auction_worklet/auction_v8_helper.h"
#include "content/services/auction_worklet/trusted_signals.h"
#include "content/services/auction_worklet/trusted_signals_request_manager.h"
#include "third_party/zlib/google/compression_utils.h"
#include "url/origin.h"
namespace auction_worklet {
namespace {
constexpr std::array<std::string_view, 2> kAcceptCompression = …;
constexpr size_t kCompressionFormatSize = …;
constexpr size_t kCborStringLengthSize = …;
constexpr size_t kOhttpHeaderSize = …;
constexpr char kTagInterestGroupName[] = …;
constexpr char kTagKey[] = …;
constexpr char kTagRenderUrls[] = …;
constexpr char kTagAdComponentRenderUrls[] = …;
void AddPostRequestConstants(cbor::Value::MapValue& request_map_value) { … }
quiche::ObliviousHttpRequest CreateOHttpRequest(
mojom::TrustedSignalsPublicKeyPtr public_key,
cbor::Value::MapValue request_map_value) { … }
cbor::Value MakeArgument(std::string_view tag,
const std::set<std::string>& data) { … }
base::expected<CompressionGroupResult,
TrustedSignalsKVv2ResponseParser::ErrorInfo>
ParseCompressionGroup(
const cbor::Value& group,
auction_worklet::mojom::TrustedSignalsCompressionScheme compression_scheme,
int& compression_group_id_out) { … }
base::expected<
std::pair<auction_worklet::mojom::TrustedSignalsCompressionScheme,
std::vector<uint8_t>>,
TrustedSignalsKVv2ResponseParser::ErrorInfo>
ExtractCompressionSchemaAndCborStringFromResponseBody(
base::span<const uint8_t> response_body) { … }
base::expected<std::map<std::string, const cbor::Value::MapValue*>,
TrustedSignalsKVv2ResponseParser::ErrorInfo>
ParseKeyGroupOutputsToMap(const cbor::Value::ArrayValue& key_group_outputs) { … }
base::expected<std::string_view, TrustedSignalsKVv2ResponseParser::ErrorInfo>
GetKeyValueDataString(
const std::pair<cbor::Value, cbor::Value>& key_value_pair) { … }
base::expected<std::map<std::string, AuctionV8Helper::SerializedValue>,
TrustedSignalsKVv2ResponseParser::ErrorInfo>
SerializeKeyGroupOutputsMap(
AuctionV8Helper* v8_helper,
const std::map<std::string, const cbor::Value::MapValue*>&
key_group_outputs_map,
const std::set<std::string>& keys,
const char* tag) { … }
base::expected<cbor::Value, TrustedSignalsKVv2ResponseParser::ErrorInfo>
GetContentFromCompressionGroup(const CompressionGroupResult& group_result) { … }
base::expected<const cbor::Value::ArrayValue*,
TrustedSignalsKVv2ResponseParser::ErrorInfo>
GetKeyGroupOutputsFromPartition(const cbor::Value& partition_value,
int& id_out,
std::optional<uint32_t>& data_version_out) { … }
}
TrustedSignalsKVv2RequestHelper::TrustedSignalsKVv2RequestHelper(
std::string post_request_body,
quiche::ObliviousHttpRequest::Context context)
: … { … }
TrustedSignalsKVv2RequestHelper::TrustedSignalsKVv2RequestHelper(
TrustedSignalsKVv2RequestHelper&&) = default;
TrustedSignalsKVv2RequestHelper& TrustedSignalsKVv2RequestHelper::operator=(
TrustedSignalsKVv2RequestHelper&&) = default;
TrustedSignalsKVv2RequestHelper::~TrustedSignalsKVv2RequestHelper() = default;
std::string TrustedSignalsKVv2RequestHelper::TakePostRequestBody() { … }
quiche::ObliviousHttpRequest::Context
TrustedSignalsKVv2RequestHelper::TakeOHttpRequestContext() { … }
TrustedSignalsKVv2RequestHelperBuilder ::
~TrustedSignalsKVv2RequestHelperBuilder() = default;
TrustedSignalsKVv2RequestHelperBuilder::TrustedSignalsKVv2RequestHelperBuilder(
std::string hostname,
GURL trusted_signals_url,
std::optional<int> experiment_group_id)
: … { … }
std::unique_ptr<TrustedSignalsKVv2RequestHelper>
TrustedSignalsKVv2RequestHelperBuilder::Build(
mojom::TrustedSignalsPublicKeyPtr public_key) { … }
TrustedSignalsKVv2RequestHelperBuilder::Partition::Partition() = default;
TrustedSignalsKVv2RequestHelperBuilder::Partition::Partition(
int partition_id,
const std::string& interest_group_name,
const std::set<std::string>& bidding_keys,
const std::string& hostname,
const std::optional<int>& experiment_group_id,
std::pair<std::string, std::string> trusted_bidding_signals_slot_size_param)
: … { … }
TrustedSignalsKVv2RequestHelperBuilder::Partition::Partition(
int partition_id,
const std::string& render_url,
const std::set<std::string>& ad_component_render_urls,
const std::string& hostname,
const std::optional<int>& experiment_group_id)
: … { … }
TrustedSignalsKVv2RequestHelperBuilder::Partition::Partition(Partition&&) =
default;
TrustedSignalsKVv2RequestHelperBuilder::Partition::~Partition() = default;
TrustedSignalsKVv2RequestHelperBuilder::Partition&
TrustedSignalsKVv2RequestHelperBuilder::Partition::operator=(Partition&&) =
default;
TrustedBiddingSignalsKVv2RequestHelperBuilder::
TrustedBiddingSignalsKVv2RequestHelperBuilder(
const std::string& hostname,
const GURL& trusted_signals_url,
std::optional<int> experiment_group_id,
const std::string& trusted_bidding_signals_slot_size_param)
: … { … }
TrustedBiddingSignalsKVv2RequestHelperBuilder::
~TrustedBiddingSignalsKVv2RequestHelperBuilder() = default;
TrustedSignalsKVv2RequestHelperBuilder::IsolationIndex
TrustedBiddingSignalsKVv2RequestHelperBuilder::AddTrustedSignalsRequest(
const std::string& interest_group_name,
const std::set<std::string>& bidding_keys,
const url::Origin& interest_group_join_origin,
const blink::mojom::InterestGroup::ExecutionMode execution_mode) { … }
cbor::Value::MapValue
TrustedBiddingSignalsKVv2RequestHelperBuilder::BuildMapForPartition(
const Partition& partition,
int partition_id,
int compression_group_id) { … }
TrustedScoringSignalsKVv2RequestHelperBuilder::
TrustedScoringSignalsKVv2RequestHelperBuilder(
const std::string& hostname,
const GURL& trusted_signals_url,
std::optional<int> experiment_group_id)
: … { … }
TrustedScoringSignalsKVv2RequestHelperBuilder::
~TrustedScoringSignalsKVv2RequestHelperBuilder() = default;
TrustedSignalsKVv2RequestHelperBuilder::IsolationIndex
TrustedScoringSignalsKVv2RequestHelperBuilder::AddTrustedSignalsRequest(
const GURL& render_url,
const std::set<std::string>& ad_component_render_urls,
const url::Origin& owner_origin,
const url::Origin& interest_group_join_origin) { … }
cbor::Value::MapValue
TrustedScoringSignalsKVv2RequestHelperBuilder::BuildMapForPartition(
const Partition& partition,
int partition_id,
int compression_group_id) { … }
CompressionGroupResult::CompressionGroupResult() = default;
CompressionGroupResult::CompressionGroupResult(
auction_worklet::mojom::TrustedSignalsCompressionScheme scheme,
std::vector<uint8_t> content,
base::TimeDelta ttl)
: … { … }
CompressionGroupResult::CompressionGroupResult(CompressionGroupResult&&) =
default;
CompressionGroupResult& CompressionGroupResult::operator=(
CompressionGroupResult&&) = default;
CompressionGroupResult::~CompressionGroupResult() = default;
TrustedSignalsKVv2ResponseParser::SignalsFetchResult
TrustedSignalsKVv2ResponseParser::ParseResponseToSignalsFetchResult(
const std::string& body_string,
quiche::ObliviousHttpRequest::Context& context) { … }
TrustedSignalsKVv2ResponseParser::TrustedSignalsResultMap
TrustedSignalsKVv2ResponseParser::ParseBiddingSignalsFetchResultToResultMap(
AuctionV8Helper* v8_helper,
const std::set<std::string>& interest_group_names,
const std::set<std::string>& keys,
const TrustedSignalsKVv2ResponseParser::CompressionGroupResultMap&
compression_group_result_map) { … }
TrustedSignalsKVv2ResponseParser::TrustedSignalsResultMap
TrustedSignalsKVv2ResponseParser::ParseScoringSignalsFetchResultToResultMap(
AuctionV8Helper* v8_helper,
const std::set<std::string>& render_urls,
const std::set<std::string>& ad_component_render_urls,
const TrustedSignalsKVv2ResponseParser::CompressionGroupResultMap&
compression_group_result_map) { … }
}