#include "components/trusted_vault/trusted_vault_connection_impl.h"
#include <algorithm>
#include <string>
#include <utility>
#include "base/base64url.h"
#include "base/containers/span.h"
#include "base/files/important_file_writer.h"
#include "base/functional/bind.h"
#include "base/functional/overloaded.h"
#include "base/metrics/histogram_functions.h"
#include "base/time/time.h"
#include "components/signin/public/identity_manager/account_info.h"
#include "components/trusted_vault/download_keys_response_handler.h"
#include "components/trusted_vault/proto/vault.pb.h"
#include "components/trusted_vault/proto_string_bytes_conversion.h"
#include "components/trusted_vault/securebox.h"
#include "components/trusted_vault/trusted_vault_access_token_fetcher.h"
#include "components/trusted_vault/trusted_vault_connection.h"
#include "components/trusted_vault/trusted_vault_crypto.h"
#include "components/trusted_vault/trusted_vault_histograms.h"
#include "components/trusted_vault/trusted_vault_request.h"
#include "components/trusted_vault/trusted_vault_server_constants.h"
#include "net/base/url_util.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace trusted_vault {
namespace {
TrustedVaultRequest::RecordFetchStatusCallback MakeFetchStatusCallback(
SecurityDomainId security_domain_id,
TrustedVaultURLFetchReasonForUMA reason) { … }
std::optional<int> GetLastKeyVersionFromJoinSecurityDomainsResponse(
const trusted_vault_pb::JoinSecurityDomainsResponse response) { … }
std::optional<int> GetLastKeyVersionFromAlreadyExistsResponse(
const std::string& response_body) { … }
trusted_vault_pb::SharedMemberKey CreateSharedMemberKey(
const TrustedVaultKeyAndVersion& trusted_vault_key_and_version,
const SecureBoxPublicKey& public_key) { … }
trusted_vault_pb::SharedMemberKey CreateSharedMemberKey(
const MemberKeys& precomputed) { … }
trusted_vault_pb::PhysicalDeviceMetadata::DeviceType
GetLocalPhysicalDeviceType() { … }
trusted_vault_pb::SecurityDomainMember CreateSecurityDomainMember(
const SecureBoxPublicKey& public_key,
AuthenticationFactorType authentication_factor_type) { … }
void AddSharedMemberKeysFromSource(
trusted_vault_pb::JoinSecurityDomainsRequest* request,
const SecureBoxPublicKey& public_key,
const MemberKeysSource& member_keys_source) { … }
trusted_vault_pb::JoinSecurityDomainsRequest CreateJoinSecurityDomainsRequest(
SecurityDomainId security_domain,
const MemberKeysSource& member_keys_source,
const SecureBoxPublicKey& public_key,
AuthenticationFactorType authentication_factor_type) { … }
void RunRegisterAuthenticationFactorCallback(
TrustedVaultConnection::RegisterAuthenticationFactorCallback callback,
TrustedVaultRegistrationStatus status,
int last_key_version) { … }
void ProcessJoinSecurityDomainsResponse(
TrustedVaultConnectionImpl::JoinSecurityDomainsCallback callback,
TrustedVaultRequest::HttpStatus http_status,
const std::string& response_body) { … }
base::Time ToTime(const trusted_vault_pb::Timestamp& proto) { … }
void ProcessDownloadKeysResponse(
std::unique_ptr<DownloadKeysResponseHandler> response_handler,
TrustedVaultConnection::DownloadNewKeysCallback callback,
TrustedVaultRequest::HttpStatus http_status,
const std::string& response_body) { … }
void ProcessDownloadIsRecoverabilityDegradedResponse(
TrustedVaultConnection::IsRecoverabilityDegradedCallback callback,
TrustedVaultRequest::HttpStatus http_status,
const std::string& response_body) { … }
class DownloadAuthenticationFactorsRegistrationStateRequest
: public TrustedVaultConnection::Request { … };
TrustedVaultURLFetchReasonForUMA
GetURLFetchReasonForUMAForJoinSecurityDomainsRequest(
AuthenticationFactorType authentication_factor_type) { … }
std::vector<TrustedVaultKeyAndVersion> ConstantKeySource() { … }
}
std::vector<TrustedVaultKeyAndVersion> GetTrustedVaultKeysWithVersions(
const std::vector<std::vector<uint8_t>>& trusted_vault_keys,
int last_key_version) { … }
TrustedVaultConnectionImpl::TrustedVaultConnectionImpl(
SecurityDomainId security_domain,
const GURL& trusted_vault_service_url,
std::unique_ptr<network::PendingSharedURLLoaderFactory>
pending_url_loader_factory,
std::unique_ptr<TrustedVaultAccessTokenFetcher> access_token_fetcher)
: … { … }
TrustedVaultConnectionImpl::~TrustedVaultConnectionImpl() = default;
std::unique_ptr<TrustedVaultConnection::Request>
TrustedVaultConnectionImpl::RegisterAuthenticationFactor(
const CoreAccountInfo& account_info,
const MemberKeysSource& member_keys_source,
const SecureBoxPublicKey& authentication_factor_public_key,
AuthenticationFactorType authentication_factor_type,
RegisterAuthenticationFactorCallback callback) { … }
std::unique_ptr<TrustedVaultConnection::Request>
TrustedVaultConnectionImpl::RegisterLocalDeviceWithoutKeys(
const CoreAccountInfo& account_info,
const SecureBoxPublicKey& device_public_key,
RegisterAuthenticationFactorCallback callback) { … }
std::unique_ptr<TrustedVaultConnection::Request>
TrustedVaultConnectionImpl::DownloadNewKeys(
const CoreAccountInfo& account_info,
const TrustedVaultKeyAndVersion& last_trusted_vault_key_and_version,
std::unique_ptr<SecureBoxKeyPair> device_key_pair,
DownloadNewKeysCallback callback) { … }
std::unique_ptr<TrustedVaultConnection::Request>
TrustedVaultConnectionImpl::DownloadIsRecoverabilityDegraded(
const CoreAccountInfo& account_info,
IsRecoverabilityDegradedCallback callback) { … }
std::unique_ptr<TrustedVaultConnection::Request>
TrustedVaultConnectionImpl::DownloadAuthenticationFactorsRegistrationState(
const CoreAccountInfo& account_info,
DownloadAuthenticationFactorsRegistrationStateCallback callback) { … }
std::unique_ptr<TrustedVaultConnection::Request>
TrustedVaultConnectionImpl::SendJoinSecurityDomainsRequest(
const CoreAccountInfo& account_info,
const MemberKeysSource& member_keys_source,
const SecureBoxPublicKey& authentication_factor_public_key,
AuthenticationFactorType authentication_factor_type,
JoinSecurityDomainsCallback callback) { … }
scoped_refptr<network::SharedURLLoaderFactory>
TrustedVaultConnectionImpl::GetOrCreateURLLoaderFactory() { … }
}