#include "components/sync/nigori/nigori_sync_bridge_impl.h"
#include <utility>
#include "base/base64.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/observer_list.h"
#include "components/sync/base/passphrase_enums.h"
#include "components/sync/base/time.h"
#include "components/sync/engine/nigori/cross_user_sharing_public_key.h"
#include "components/sync/engine/nigori/nigori.h"
#include "components/sync/nigori/keystore_keys_cryptographer.h"
#include "components/sync/nigori/nigori_storage.h"
#include "components/sync/nigori/pending_local_nigori_commit.h"
#include "components/sync/protocol/encryption.pb.h"
#include "components/sync/protocol/entity_data.h"
#include "components/sync/protocol/nigori_local_data.pb.h"
#include "components/sync/protocol/nigori_specifics.pb.h"
namespace syncer {
namespace {
NigoriSpecifics;
const char kNigoriNonUniqueName[] = …;
enum class KeyDerivationMethodStateForMetrics { … };
enum class CrossUserSharingKeyPairStateOnDecryptPendingKeys { … };
CrossUserSharingKeyPairStateOnDecryptPendingKeys
GetKeyPairStateOnDecryptPendingKeys(const CrossUserSharingKeys& new_key_pair,
std::optional<uint32_t> key_pair_version) { … }
KeyDerivationMethodStateForMetrics GetKeyDerivationMethodStateForMetrics(
const std::optional<KeyDerivationParams>& key_derivation_params) { … }
std::string GetScryptSaltFromSpecifics(
const sync_pb::NigoriSpecifics& specifics) { … }
KeyDerivationParams GetKeyDerivationParamsFromSpecifics(
const sync_pb::NigoriSpecifics& specifics) { … }
std::vector<std::string> Base64EncodeKeys(
const std::vector<std::vector<uint8_t>>& keys) { … }
bool SpecificsHasValidKeyDerivationParams(const NigoriSpecifics& specifics) { … }
bool IsValidNigoriSpecifics(const NigoriSpecifics& specifics) { … }
bool IsValidPassphraseTransition(
NigoriSpecifics::PassphraseType old_passphrase_type,
NigoriSpecifics::PassphraseType new_passphrase_type) { … }
bool UpdatePassphraseType(NigoriSpecifics::PassphraseType new_type,
NigoriSpecifics::PassphraseType* current_type) { … }
bool IsValidEncryptedTypesTransition(bool old_encrypt_everything,
const NigoriSpecifics& specifics) { … }
bool IsValidLocalData(const sync_pb::NigoriLocalData& local_data) { … }
std::optional<CrossUserSharingPublicKey> PublicKeyFromProto(
const sync_pb::CrossUserSharingPublicKey& public_key) { … }
}
class NigoriSyncBridgeImpl::BroadcastingObserver
: public SyncEncryptionHandler::Observer { … };
NigoriSyncBridgeImpl::NigoriSyncBridgeImpl(
std::unique_ptr<NigoriLocalChangeProcessor> processor,
std::unique_ptr<NigoriStorage> storage)
: … { … }
NigoriSyncBridgeImpl::~NigoriSyncBridgeImpl() { … }
void NigoriSyncBridgeImpl::AddObserver(Observer* observer) { … }
void NigoriSyncBridgeImpl::RemoveObserver(Observer* observer) { … }
void NigoriSyncBridgeImpl::NotifyInitialStateToObservers() { … }
DataTypeSet NigoriSyncBridgeImpl::GetEncryptedTypes() { … }
Cryptographer* NigoriSyncBridgeImpl::GetCryptographer() { … }
PassphraseType NigoriSyncBridgeImpl::GetPassphraseType() { … }
void NigoriSyncBridgeImpl::SetEncryptionPassphrase(
const std::string& passphrase,
const KeyDerivationParams& key_derivation_params) { … }
void NigoriSyncBridgeImpl::SetExplicitPassphraseDecryptionKey(
std::unique_ptr<Nigori> key) { … }
void NigoriSyncBridgeImpl::AddTrustedVaultDecryptionKeys(
const std::vector<std::vector<uint8_t>>& keys) { … }
base::Time NigoriSyncBridgeImpl::GetKeystoreMigrationTime() { … }
KeystoreKeysHandler* NigoriSyncBridgeImpl::GetKeystoreKeysHandler() { … }
const sync_pb::NigoriSpecifics::TrustedVaultDebugInfo&
NigoriSyncBridgeImpl::GetTrustedVaultDebugInfo() { … }
bool NigoriSyncBridgeImpl::NeedKeystoreKey() const { … }
bool NigoriSyncBridgeImpl::SetKeystoreKeys(
const std::vector<std::vector<uint8_t>>& keys) { … }
std::optional<ModelError> NigoriSyncBridgeImpl::MergeFullSyncData(
std::optional<EntityData> data) { … }
std::optional<ModelError> NigoriSyncBridgeImpl::ApplyIncrementalSyncChanges(
std::optional<EntityData> data) { … }
std::optional<ModelError> NigoriSyncBridgeImpl::UpdateLocalState(
const NigoriSpecifics& specifics) { … }
NigoriKeyBag NigoriSyncBridgeImpl::BuildDecryptionKeyBagForRemoteKeybag()
const { … }
std::optional<ModelError> NigoriSyncBridgeImpl::TryDecryptPendingKeysWith(
const NigoriKeyBag& key_bag) { … }
std::unique_ptr<EntityData> NigoriSyncBridgeImpl::GetDataForCommit() { … }
std::unique_ptr<EntityData> NigoriSyncBridgeImpl::GetDataForDebugging() { … }
void NigoriSyncBridgeImpl::ApplyDisableSyncChanges() { … }
const CryptographerImpl& NigoriSyncBridgeImpl::GetCryptographerImplForTesting()
const { … }
bool NigoriSyncBridgeImpl::HasPendingKeysForTesting() const { … }
KeyDerivationParams
NigoriSyncBridgeImpl::GetCustomPassphraseKeyDerivationParamsForTesting() const { … }
base::Time NigoriSyncBridgeImpl::GetExplicitPassphraseTime() const { … }
KeyDerivationParams NigoriSyncBridgeImpl::GetKeyDerivationParamsForPendingKeys()
const { … }
void NigoriSyncBridgeImpl::MaybeNotifyOfPendingKeys() const { … }
sync_pb::NigoriLocalData NigoriSyncBridgeImpl::SerializeAsNigoriLocalData()
const { … }
void NigoriSyncBridgeImpl::MaybeTriggerKeystoreReencryption() { … }
void NigoriSyncBridgeImpl::QueuePendingLocalCommit(
std::unique_ptr<PendingLocalNigoriCommit> local_commit) { … }
void NigoriSyncBridgeImpl::PutNextApplicablePendingLocalCommit() { … }
void NigoriSyncBridgeImpl::MaybePopulateKeystoreKeysIntoCryptographer() { … }
std::unique_ptr<EntityData> NigoriSyncBridgeImpl::GetDataImpl() { … }
}