Commit 5776922a authored by Maksim Moskvitin's avatar Maksim Moskvitin Committed by Commit Bot

[Sync:USS] Support disabling sync for USS Nigori

Once sync is disabled, we need to clear all Nigori data and reset model
state. Since ModelTypeController for Nigori lives inside
SyncEngineBackend we also need to explicitly disconnect and stop Nigori
during DoShutdown().

Bug: 922900
Change-Id: Ide16fe4652d8bbdb5972c22110ae73492444e354
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1784717
Commit-Queue: Maksim Moskvitin <mmoskvitin@google.com>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#693178}
parent ef2a9295
......@@ -516,6 +516,10 @@ void SyncEngineBackend::DoShutdown(ShutdownReason reason) {
if (nigori_handler_proxy_) {
sync_encryption_handler_->RemoveObserver(nigori_handler_proxy_.get());
}
if (nigori_controller_) {
sync_manager_->GetModelTypeConnector()->DisconnectNonBlockingType(NIGORI);
nigori_controller_->Stop(reason, base::DoNothing());
}
DoDestroySyncManager();
registrar_ = nullptr;
......
......@@ -977,7 +977,22 @@ ConflictResolution NigoriSyncBridgeImpl::ResolveConflict(
void NigoriSyncBridgeImpl::ApplyDisableSyncChanges() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
NOTIMPLEMENTED();
// The user intended to disable sync, so we need to clear all the data.
storage_->ClearData();
serialized_explicit_passphrase_key_ = "";
keystore_keys_.clear();
cryptographer_.CopyFrom(Cryptographer());
passphrase_type_ = NigoriSpecifics::UNKNOWN;
encrypt_everything_ = false;
custom_passphrase_time_ = base::Time();
keystore_migration_time_ = base::Time();
custom_passphrase_key_derivation_params_ = base::nullopt;
for (auto& observer : observers_) {
observer.OnCryptographerStateChanged(&cryptographer_);
}
for (auto& observer : observers_) {
observer.OnEncryptedTypesChanged(SensitiveTypes(), false);
}
}
const Cryptographer& NigoriSyncBridgeImpl::GetCryptographerForTesting() const {
......
......@@ -117,7 +117,7 @@ class NigoriSyncBridgeImpl : public KeystoreKeysHandler,
// Stores serialized sync_pb::NigoriKey derived from explicit passphrase and
// loaded from the prefs. Empty if prefs doesn't contain this key or in case
// of decryption/decoding errors.
const std::string serialized_explicit_passphrase_key_;
std::string serialized_explicit_passphrase_key_;
// Base64 encoded keystore keys. The last element is the current keystore
// key. These keys are not a part of Nigori node and are persisted
......
......@@ -281,9 +281,10 @@ class NigoriSyncBridgeImplTest : public testing::Test {
auto processor =
std::make_unique<testing::NiceMock<MockNigoriLocalChangeProcessor>>();
processor_ = processor.get();
auto storage = std::make_unique<testing::NiceMock<MockNigoriStorage>>();
storage_ = storage.get();
bridge_ = std::make_unique<NigoriSyncBridgeImpl>(
std::move(processor),
std::make_unique<testing::NiceMock<MockNigoriStorage>>(), &encryptor_,
std::move(processor), std::move(storage), &encryptor_,
/*packed_explicit_passphrase_key=*/std::string());
bridge_->AddObserver(&observer_);
}
......@@ -293,12 +294,14 @@ class NigoriSyncBridgeImplTest : public testing::Test {
NigoriSyncBridgeImpl* bridge() { return bridge_.get(); }
MockNigoriLocalChangeProcessor* processor() { return processor_; }
MockObserver* observer() { return &observer_; }
MockNigoriStorage* storage() { return storage_; }
private:
const FakeEncryptor encryptor_;
std::unique_ptr<NigoriSyncBridgeImpl> bridge_;
// Ownership transferred to |bridge_|.
testing::NiceMock<MockNigoriLocalChangeProcessor>* processor_;
testing::NiceMock<MockNigoriStorage>* storage_;
testing::NiceMock<MockObserver> observer_;
};
......@@ -532,6 +535,23 @@ TEST_F(NigoriSyncBridgeImplTest, ShouldFailOnUnknownPassprase) {
Ne(base::nullopt));
}
TEST_F(NigoriSyncBridgeImplTest, ShouldClearDataWhenSyncDisabled) {
const std::string kRawKeystoreKey = "raw_keystore_key";
const KeyParams kKeystoreKeyParams = KeystoreKeyParams(kRawKeystoreKey);
EntityData entity_data;
*entity_data.specifics.mutable_nigori() = BuildKeystoreNigoriSpecifics(
/*keybag_keys_params=*/{kKeystoreKeyParams},
/*keystore_decryptor_params=*/kKeystoreKeyParams,
/*keystore_key_params=*/kKeystoreKeyParams);
ASSERT_TRUE(bridge()->SetKeystoreKeys({kRawKeystoreKey}));
ASSERT_THAT(bridge()->MergeSyncData(std::move(entity_data)),
Eq(base::nullopt));
EXPECT_CALL(*storage(), ClearData);
bridge()->ApplyDisableSyncChanges();
EXPECT_FALSE(bridge()->GetCryptographerForTesting().is_initialized());
}
// Tests decryption logic for explicit passphrase. In order to check that we're
// able to decrypt the data encrypted with old key (i.e. keystore keys or old
// GAIA passphrase) we add one extra key to the encryption keybag.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment