Commit 281a234f authored by Maksim Moskvitin's avatar Maksim Moskvitin Committed by Commit Bot

[Sync:USS] Implement NigoriSyncBridgeImpl::GetData()

This CL implements GetData() modulo we have no support for some
NigoriSpecifics fields yet. GetData() implementation should unblock
implementation of SetEncryptionPassphrase(), since it allows to obtain
EntityData from current in-memory state.

Bug: 922900
Change-Id: I739935a10be2637c09406a8deb4d1df50cc57013
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1622805
Commit-Queue: Maksim Moskvitin <mmoskvitin@google.com>
Reviewed-by: default avatarMikel Astiz <mastiz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#663032}
parent 6b305d1a
......@@ -21,6 +21,8 @@ namespace {
using sync_pb::NigoriSpecifics;
const char kNigoriNonUniqueName[] = "Nigori";
// Attempts to decrypt |keystore_decryptor_token| with |keystore_keys|. Returns
// serialized Nigori key if successful and base::nullopt otherwise.
base::Optional<std::string> DecryptKeystoreDecryptor(
......@@ -544,8 +546,32 @@ void NigoriSyncBridgeImpl::UpdateCryptographerFromExplicitPassphraseNigori(
std::unique_ptr<EntityData> NigoriSyncBridgeImpl::GetData() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(cryptographer_.is_ready());
DCHECK_NE(passphrase_type_, NigoriSpecifics::UNKNOWN);
NigoriSpecifics specifics;
cryptographer_.GetKeys(specifics.mutable_encryption_keybag());
specifics.set_keybag_is_frozen(true);
specifics.set_encrypt_everything(encrypt_everything_);
specifics.set_passphrase_type(passphrase_type_);
if (passphrase_type_ == NigoriSpecifics::KEYSTORE_PASSPHRASE) {
cryptographer_.EncryptString(cryptographer_.GetDefaultNigoriKeyData(),
specifics.mutable_keystore_decryptor_token());
}
if (!keystore_migration_time_.is_null()) {
specifics.set_keystore_migration_time(
TimeToProtoTime(keystore_migration_time_));
}
if (!custom_passphrase_time_.is_null()) {
specifics.set_custom_passphrase_time(
TimeToProtoTime(custom_passphrase_time_));
}
// TODO(crbug.com/922900): add other fields support.
NOTIMPLEMENTED();
return nullptr;
auto entity_data = std::make_unique<EntityData>();
*entity_data->specifics.mutable_nigori() = std::move(specifics);
entity_data->non_unique_name = kNigoriNonUniqueName;
return entity_data;
}
ConflictResolution NigoriSyncBridgeImpl::ResolveConflict(
......
......@@ -321,8 +321,9 @@ TEST_F(NigoriSyncBridgeImplTest,
EXPECT_THAT(cryptographer, HasDefaultKeyDerivedFrom(kCurrentKeyParams));
}
// Tests that we build keystore Nigori, put it to processor and initialize
// the cryptographer, when the default Nigori is received.
// Tests that we build keystore Nigori, put it to processor, initialize the
// cryptographer and expose a valid entity through GetData(), when the default
// Nigori is received.
TEST_F(NigoriSyncBridgeImplTest,
ShouldPutAndMakeCryptographerReadyOnDefaultNigori) {
const std::string kRawKeystoreKey = "raw_keystore_key";
......@@ -338,6 +339,7 @@ TEST_F(NigoriSyncBridgeImplTest,
EXPECT_CALL(*processor(), Put(HasKeystoreNigori()));
EXPECT_THAT(bridge()->MergeSyncData(std::move(default_entity_data)),
Eq(base::nullopt));
EXPECT_THAT(bridge()->GetData(), HasKeystoreNigori());
const Cryptographer& cryptographer = bridge()->GetCryptographerForTesting();
EXPECT_THAT(cryptographer, CanDecryptWith(kKeystoreKeyParams));
......
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