#include "components/sync/service/sync_service_crypto.h"
#include <utility>
#include "base/base64.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/task/sequenced_task_runner.h"
#include "components/os_crypt/sync/os_crypt.h"
#include "components/sync/base/passphrase_enums.h"
#include "components/sync/engine/nigori/nigori.h"
#include "components/sync/engine/sync_string_conversions.h"
#include "components/sync/protocol/nigori_specifics.pb.h"
#include "components/sync/service/sync_service.h"
#include "components/sync/service/trusted_vault_histograms.h"
namespace syncer {
namespace {
enum class TrustedVaultFetchKeysAttemptForUMA { … };
class SyncEncryptionObserverProxy : public SyncEncryptionHandler::Observer { … };
bool CheckNigoriAgainstPendingKeys(const Nigori& nigori,
const sync_pb::EncryptedData& pending_keys) { … }
std::unique_ptr<Nigori> ReadNigoriFromBootstrapToken(
const std::string& bootstrap_token) { … }
std::string SerializeNigoriAsBootstrapToken(const Nigori& nigori) { … }
}
SyncServiceCrypto::State::State() = default;
SyncServiceCrypto::State::~State() = default;
SyncServiceCrypto::SyncServiceCrypto(
Delegate* delegate,
trusted_vault::TrustedVaultClient* trusted_vault_client)
: … { … }
SyncServiceCrypto::~SyncServiceCrypto() = default;
void SyncServiceCrypto::Reset() { … }
void SyncServiceCrypto::StopObservingTrustedVaultClient() { … }
base::Time SyncServiceCrypto::GetExplicitPassphraseTime() const { … }
bool SyncServiceCrypto::IsPassphraseRequired() const { … }
bool SyncServiceCrypto::IsTrustedVaultKeyRequired() const { … }
bool SyncServiceCrypto::IsTrustedVaultRecoverabilityDegraded() const { … }
bool SyncServiceCrypto::IsEncryptEverythingEnabled() const { … }
void SyncServiceCrypto::SetEncryptionPassphrase(const std::string& passphrase) { … }
bool SyncServiceCrypto::SetDecryptionPassphrase(const std::string& passphrase) { … }
void SyncServiceCrypto::SetExplicitPassphraseDecryptionNigoriKey(
std::unique_ptr<Nigori> nigori) { … }
std::unique_ptr<Nigori>
SyncServiceCrypto::GetExplicitPassphraseDecryptionNigoriKey() const { … }
bool SyncServiceCrypto::IsTrustedVaultKeyRequiredStateKnown() const { … }
std::optional<PassphraseType> SyncServiceCrypto::GetPassphraseType() const { … }
void SyncServiceCrypto::SetSyncEngine(const CoreAccountInfo& account_info,
SyncEngine* engine) { … }
std::unique_ptr<SyncEncryptionHandler::Observer>
SyncServiceCrypto::GetEncryptionObserverProxy() { … }
DataTypeSet SyncServiceCrypto::GetAllEncryptedDataTypes() const { … }
bool SyncServiceCrypto::HasCryptoError() const { … }
void SyncServiceCrypto::OnPassphraseRequired(
const KeyDerivationParams& key_derivation_params,
const sync_pb::EncryptedData& pending_keys) { … }
void SyncServiceCrypto::OnPassphraseAccepted() { … }
void SyncServiceCrypto::OnTrustedVaultKeyRequired() { … }
void SyncServiceCrypto::OnTrustedVaultKeyAccepted() { … }
void SyncServiceCrypto::OnEncryptedTypesChanged(DataTypeSet encrypted_types,
bool encrypt_everything) { … }
void SyncServiceCrypto::OnCryptographerStateChanged(
Cryptographer* cryptographer,
bool has_pending_keys) { … }
void SyncServiceCrypto::OnPassphraseTypeChanged(PassphraseType type,
base::Time passphrase_time) { … }
void SyncServiceCrypto::OnTrustedVaultKeysChanged() { … }
void SyncServiceCrypto::OnTrustedVaultRecoverabilityChanged() { … }
void SyncServiceCrypto::FetchTrustedVaultKeys(bool is_second_fetch_attempt) { … }
void SyncServiceCrypto::TrustedVaultKeysFetchedFromClient(
bool is_second_fetch_attempt,
const std::vector<std::vector<uint8_t>>& keys) { … }
void SyncServiceCrypto::TrustedVaultKeysAdded(bool is_second_fetch_attempt) { … }
void SyncServiceCrypto::TrustedVaultKeysMarkedAsStale(
bool is_second_fetch_attempt,
bool result) { … }
void SyncServiceCrypto::FetchTrustedVaultKeysCompletedButInsufficient() { … }
void SyncServiceCrypto::UpdateRequiredUserActionAndNotify(
RequiredUserAction new_required_user_action) { … }
void SyncServiceCrypto::RefreshIsRecoverabilityDegraded() { … }
void SyncServiceCrypto::GetIsRecoverabilityDegradedCompleted(
bool is_recoverability_degraded) { … }
bool SyncServiceCrypto::SetDecryptionKeyWithoutUpdatingBootstrapToken(
std::unique_ptr<Nigori> nigori) { … }
void SyncServiceCrypto::MaybeSetDecryptionKeyFromBootstrapToken() { … }
}