Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Unified Diff: components/sync/core_impl/sync_encryption_handler_impl.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/sync/core_impl/sync_encryption_handler_impl.cc
diff --git a/sync/internal_api/sync_encryption_handler_impl.cc b/components/sync/core_impl/sync_encryption_handler_impl.cc
similarity index 89%
rename from sync/internal_api/sync_encryption_handler_impl.cc
rename to components/sync/core_impl/sync_encryption_handler_impl.cc
index a4aafb6c9189efe9f10ab0d3f45174e844257542..97bb4f10657aca7d2707666e4eb0fe5df113237f 100644
--- a/sync/internal_api/sync_encryption_handler_impl.cc
+++ b/components/sync/core_impl/sync_encryption_handler_impl.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "sync/internal_api/sync_encryption_handler_impl.h"
+#include "components/sync/core_impl/sync_encryption_handler_impl.h"
#include <stddef.h>
#include <stdint.h>
@@ -20,26 +20,26 @@
#include "base/threading/thread_task_runner_handle.h"
#include "base/time/time.h"
#include "base/tracked_objects.h"
-#include "sync/internal_api/public/read_node.h"
-#include "sync/internal_api/public/read_transaction.h"
-#include "sync/internal_api/public/user_share.h"
-#include "sync/internal_api/public/util/experiments.h"
-#include "sync/internal_api/public/util/sync_string_conversions.h"
-#include "sync/internal_api/public/write_node.h"
-#include "sync/internal_api/public/write_transaction.h"
-#include "sync/protocol/encryption.pb.h"
-#include "sync/protocol/nigori_specifics.pb.h"
-#include "sync/protocol/sync.pb.h"
-#include "sync/syncable/directory.h"
-#include "sync/syncable/entry.h"
-#include "sync/syncable/mutable_entry.h"
-#include "sync/syncable/nigori_util.h"
-#include "sync/syncable/syncable_base_transaction.h"
-#include "sync/syncable/syncable_model_neutral_write_transaction.h"
-#include "sync/syncable/syncable_write_transaction.h"
-#include "sync/util/cryptographer.h"
-#include "sync/util/encryptor.h"
-#include "sync/util/time.h"
+#include "components/sync/base/cryptographer.h"
+#include "components/sync/base/encryptor.h"
+#include "components/sync/base/experiments.h"
+#include "components/sync/base/sync_string_conversions.h"
+#include "components/sync/base/time.h"
+#include "components/sync/core/read_node.h"
+#include "components/sync/core/read_transaction.h"
+#include "components/sync/core/user_share.h"
+#include "components/sync/core/write_node.h"
+#include "components/sync/core/write_transaction.h"
+#include "components/sync/protocol/encryption.pb.h"
+#include "components/sync/protocol/nigori_specifics.pb.h"
+#include "components/sync/protocol/sync.pb.h"
+#include "components/sync/syncable/directory.h"
+#include "components/sync/syncable/entry.h"
+#include "components/sync/syncable/mutable_entry.h"
+#include "components/sync/syncable/nigori_util.h"
+#include "components/sync/syncable/syncable_base_transaction.h"
+#include "components/sync/syncable/syncable_model_neutral_write_transaction.h"
+#include "components/sync/syncable/syncable_write_transaction.h"
namespace syncer {
@@ -84,8 +84,7 @@ bool IsNigoriMigratedToKeystore(const sync_pb::NigoriSpecifics& nigori) {
return false;
if (!nigori.keybag_is_frozen())
return false;
- if (nigori.passphrase_type() ==
- sync_pb::NigoriSpecifics::IMPLICIT_PASSPHRASE)
+ if (nigori.passphrase_type() == sync_pb::NigoriSpecifics::IMPLICIT_PASSPHRASE)
return false;
if (nigori.passphrase_type() ==
sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE &&
@@ -111,8 +110,8 @@ PassphraseType ProtoPassphraseTypeToEnum(
}
}
-sync_pb::NigoriSpecifics::PassphraseType
-EnumPassphraseTypeToProto(PassphraseType type) {
+sync_pb::NigoriSpecifics::PassphraseType EnumPassphraseTypeToProto(
+ PassphraseType type) {
switch (type) {
case IMPLICIT_PASSPHRASE:
return sync_pb::NigoriSpecifics::IMPLICIT_PASSPHRASE;
@@ -154,18 +153,16 @@ std::string PackKeystoreBootstrapToken(
JSONStringValueSerializer json(&serialized_keystores);
json.Serialize(keystore_key_values);
std::string encrypted_keystores;
- encryptor->EncryptString(serialized_keystores,
- &encrypted_keystores);
+ encryptor->EncryptString(serialized_keystores, &encrypted_keystores);
std::string keystore_bootstrap;
base::Base64Encode(encrypted_keystores, &keystore_bootstrap);
return keystore_bootstrap;
}
-bool UnpackKeystoreBootstrapToken(
- const std::string& keystore_bootstrap_token,
- Encryptor* encryptor,
- std::vector<std::string>* old_keystore_keys,
- std::string* current_keystore_key) {
+bool UnpackKeystoreBootstrapToken(const std::string& keystore_bootstrap_token,
+ Encryptor* encryptor,
+ std::vector<std::string>* old_keystore_keys,
+ std::string* current_keystore_key) {
if (keystore_bootstrap_token.empty())
return false;
std::string base64_decoded_keystore_bootstrap;
@@ -200,15 +197,11 @@ bool UnpackKeystoreBootstrapToken(
} // namespace
-SyncEncryptionHandlerImpl::Vault::Vault(
- Encryptor* encryptor,
- ModelTypeSet encrypted_types)
- : cryptographer(encryptor),
- encrypted_types(encrypted_types) {
-}
+SyncEncryptionHandlerImpl::Vault::Vault(Encryptor* encryptor,
+ ModelTypeSet encrypted_types)
+ : cryptographer(encryptor), encrypted_types(encrypted_types) {}
-SyncEncryptionHandlerImpl::Vault::~Vault() {
-}
+SyncEncryptionHandlerImpl::Vault::~Vault() {}
SyncEncryptionHandlerImpl::SyncEncryptionHandlerImpl(
UserShare* user_share,
@@ -227,11 +220,8 @@ SyncEncryptionHandlerImpl::SyncEncryptionHandlerImpl(
// If this fails, we won't have a valid keystore key, and will simply request
// new ones from the server on the next DownloadUpdates.
- UnpackKeystoreBootstrapToken(
- restored_keystore_key_for_bootstrapping,
- encryptor,
- &old_keystore_keys_,
- &keystore_key_);
+ UnpackKeystoreBootstrapToken(restored_keystore_key_for_bootstrapping,
+ encryptor, &old_keystore_keys_, &keystore_key_);
}
SyncEncryptionHandlerImpl::~SyncEncryptionHandlerImpl() {}
@@ -260,22 +250,19 @@ void SyncEncryptionHandlerImpl::Init() {
WriteEncryptionStateToNigori(&trans);
}
- UMA_HISTOGRAM_ENUMERATION("Sync.PassphraseType",
- GetPassphraseType(),
+ UMA_HISTOGRAM_ENUMERATION("Sync.PassphraseType", GetPassphraseType(),
PASSPHRASE_TYPE_SIZE);
- bool has_pending_keys = UnlockVault(
- trans.GetWrappedTrans()).cryptographer.has_pending_keys();
- bool is_ready = UnlockVault(
- trans.GetWrappedTrans()).cryptographer.is_ready();
+ bool has_pending_keys =
+ UnlockVault(trans.GetWrappedTrans()).cryptographer.has_pending_keys();
+ bool is_ready = UnlockVault(trans.GetWrappedTrans()).cryptographer.is_ready();
// Log the state of the cryptographer regardless of migration state.
UMA_HISTOGRAM_BOOLEAN("Sync.CryptographerReady", is_ready);
UMA_HISTOGRAM_BOOLEAN("Sync.CryptographerPendingKeys", has_pending_keys);
if (IsNigoriMigratedToKeystore(node.GetNigoriSpecifics())) {
// This account has a nigori node that has been migrated to support
// keystore.
- UMA_HISTOGRAM_ENUMERATION("Sync.NigoriMigrationState",
- MIGRATED,
+ UMA_HISTOGRAM_ENUMERATION("Sync.NigoriMigrationState", MIGRATED,
MIGRATION_STATE_SIZE);
if (has_pending_keys && passphrase_type_ == KEYSTORE_PASSPHRASE) {
// If this is happening, it means the keystore decryptor is either
@@ -305,17 +292,14 @@ void SyncEncryptionHandlerImpl::Init() {
MIGRATION_STATE_SIZE);
}
-
// Always trigger an encrypted types and cryptographer state change event at
// init time so observers get the initial values.
+ FOR_EACH_OBSERVER(Observer, observers_,
+ OnEncryptedTypesChanged(
+ UnlockVault(trans.GetWrappedTrans()).encrypted_types,
+ encrypt_everything_));
FOR_EACH_OBSERVER(
- Observer, observers_,
- OnEncryptedTypesChanged(
- UnlockVault(trans.GetWrappedTrans()).encrypted_types,
- encrypt_everything_));
- FOR_EACH_OBSERVER(
- SyncEncryptionHandler::Observer,
- observers_,
+ SyncEncryptionHandler::Observer, observers_,
OnCryptographerStateChanged(
&UnlockVaultMutable(trans.GetWrappedTrans())->cryptographer));
@@ -409,8 +393,7 @@ void SyncEncryptionHandlerImpl::SetEncryptionPassphrase(
custom_passphrase_time_ = base::Time::Now();
FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
OnPassphraseTypeChanged(
- passphrase_type_,
- GetExplicitPassphraseTime()));
+ passphrase_type_, GetExplicitPassphraseTime()));
} else {
DVLOG(1) << "Setting implicit passphrase for encryption.";
}
@@ -462,8 +445,8 @@ void SyncEncryptionHandlerImpl::SetEncryptionPassphrase(
cryptographer->AddKey(key_params);
success = false;
}
- } // is_explicit
- } // cryptographer->has_pending_keys()
+ } // is_explicit
+ } // cryptographer->has_pending_keys()
} else { // IsExplicitPassphrase(passphrase_type_) == true.
// Case 6. We do not want to override a previously set explicit passphrase,
// so we return a failure.
@@ -572,8 +555,7 @@ void SyncEncryptionHandlerImpl::SetDecryptionPassphrase(
<< "decryption, restoring implicit internal passphrase "
<< "as default.";
std::string bootstrap_token_from_current_key;
- cryptographer->GetBootstrapToken(
- &bootstrap_token_from_current_key);
+ cryptographer->GetBootstrapToken(&bootstrap_token_from_current_key);
cryptographer->DecryptPendingKeys(key_params);
// Overwrite the default from the pending keys.
cryptographer->AddKeyFromBootstrapToken(
@@ -583,7 +565,7 @@ void SyncEncryptionHandlerImpl::SetDecryptionPassphrase(
} else { // !temp_cryptographer.DecryptPendingKeys(..)
DVLOG(1) << "Implicit user provided passphrase failed to decrypt.";
success = false;
- } // temp_cryptographer.DecryptPendingKeys(...)
+ } // temp_cryptographer.DecryptPendingKeys(...)
} else { // cryptographer->is_initialized() == false
if (cryptographer->DecryptPendingKeys(key_params)) {
// This can happpen in two cases:
@@ -605,7 +587,7 @@ void SyncEncryptionHandlerImpl::SetDecryptionPassphrase(
DVLOG(1) << "Implicit user provided passphrase failed to decrypt.";
success = false;
}
- } // cryptographer->is_initialized()
+ } // cryptographer->is_initialized()
} else { // nigori_has_explicit_passphrase == true
// Case 9. Encryption was done with an explicit passphrase, and we decrypt
// with the passphrase provided by the user.
@@ -664,10 +646,8 @@ void SyncEncryptionHandlerImpl::ApplyNigoriUpdate(
}
FOR_EACH_OBSERVER(
- SyncEncryptionHandler::Observer,
- observers_,
- OnCryptographerStateChanged(
- &UnlockVaultMutable(trans)->cryptographer));
+ SyncEncryptionHandler::Observer, observers_,
+ OnCryptographerStateChanged(&UnlockVaultMutable(trans)->cryptographer));
}
void SyncEncryptionHandlerImpl::UpdateNigoriFromEncryptedTypes(
@@ -675,8 +655,7 @@ void SyncEncryptionHandlerImpl::UpdateNigoriFromEncryptedTypes(
syncable::BaseTransaction* const trans) const {
DCHECK(thread_checker_.CalledOnValidThread());
syncable::UpdateNigoriFromEncryptedTypes(UnlockVault(trans).encrypted_types,
- encrypt_everything_,
- nigori);
+ encrypt_everything_, nigori);
}
bool SyncEncryptionHandlerImpl::NeedKeystoreKey(
@@ -713,13 +692,11 @@ bool SyncEncryptionHandlerImpl::SetKeystoreKeys(
// which will force us to download the keystore keys again on the next
// restart.
std::string keystore_bootstrap = PackKeystoreBootstrapToken(
- old_keystore_keys_,
- keystore_key_,
- cryptographer->encryptor());
+ old_keystore_keys_, keystore_key_, cryptographer->encryptor());
- FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
- OnBootstrapTokenUpdated(keystore_bootstrap,
- KEYSTORE_BOOTSTRAP_TOKEN));
+ FOR_EACH_OBSERVER(
+ SyncEncryptionHandler::Observer, observers_,
+ OnBootstrapTokenUpdated(keystore_bootstrap, KEYSTORE_BOOTSTRAP_TOKEN));
DVLOG(1) << "Keystore bootstrap token updated.";
// If this is a first time sync, we get the encryption keys before we process
@@ -729,17 +706,14 @@ bool SyncEncryptionHandlerImpl::SetKeystoreKeys(
if (!entry.good())
return true;
- const sync_pb::NigoriSpecifics& nigori =
- entry.GetSpecifics().nigori();
- if (cryptographer->has_pending_keys() &&
- IsNigoriMigratedToKeystore(nigori) &&
+ const sync_pb::NigoriSpecifics& nigori = entry.GetSpecifics().nigori();
+ if (cryptographer->has_pending_keys() && IsNigoriMigratedToKeystore(nigori) &&
!nigori.keystore_decryptor_token().blob().empty()) {
// If the nigori is already migrated and we have pending keys, we might
// be able to decrypt them using either the keystore decryptor token
// or the existing keystore keys.
- DecryptPendingKeysWithKeystoreKey(keystore_key_,
- nigori.keystore_decryptor_token(),
- cryptographer);
+ DecryptPendingKeysWithKeystoreKey(
+ keystore_key_, nigori.keystore_decryptor_token(), cryptographer);
}
// Note that triggering migration will have no effect if we're already
@@ -820,8 +794,7 @@ void SyncEncryptionHandlerImpl::RestoreNigori(
// which data for some or all types is not currently available. In that case,
// the lookup of the root node will fail and we will skip encryption for that
// type.
-void SyncEncryptionHandlerImpl::ReEncryptEverything(
- WriteTransaction* trans) {
+void SyncEncryptionHandlerImpl::ReEncryptEverything(WriteTransaction* trans) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(UnlockVault(trans->GetWrappedTrans()).cryptographer.is_ready());
for (ModelTypeSet::Iterator iter =
@@ -851,8 +824,8 @@ void SyncEncryptionHandlerImpl::ReEncryptEverything(
to_visit.push(child.GetFirstChildId());
}
if (!child.GetIsPermanentFolder()) {
- // Rewrite the specifics of the node with encrypted data if necessary
- // (only rewrite the non-unique folders).
+ // Rewrite the specifics of the node with encrypted data if necessary
+ // (only rewrite the non-unique folders).
child.ResetFromSpecifics();
}
to_visit.push(child.GetSuccessorId());
@@ -885,12 +858,11 @@ bool SyncEncryptionHandlerImpl::ApplyNigoriUpdateImpl(
syncable::BaseTransaction* const trans) {
DCHECK(thread_checker_.CalledOnValidThread());
DVLOG(1) << "Applying nigori node update.";
- bool nigori_types_need_update = !UpdateEncryptedTypesFromNigori(nigori,
- trans);
+ bool nigori_types_need_update =
+ !UpdateEncryptedTypesFromNigori(nigori, trans);
if (nigori.custom_passphrase_time() != 0) {
- custom_passphrase_time_ =
- ProtoTimeToTime(nigori.custom_passphrase_time());
+ custom_passphrase_time_ = ProtoTimeToTime(nigori.custom_passphrase_time());
}
bool is_nigori_migrated = IsNigoriMigratedToKeystore(nigori);
if (is_nigori_migrated) {
@@ -911,14 +883,12 @@ bool SyncEncryptionHandlerImpl::ApplyNigoriUpdateImpl(
(passphrase_type_ == IMPLICIT_PASSPHRASE ||
nigori_passphrase_type == CUSTOM_PASSPHRASE)) {
DVLOG(1) << "Changing passphrase state from "
- << PassphraseTypeToString(passphrase_type_)
- << " to "
+ << PassphraseTypeToString(passphrase_type_) << " to "
<< PassphraseTypeToString(nigori_passphrase_type);
passphrase_type_ = nigori_passphrase_type;
FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
- OnPassphraseTypeChanged(
- passphrase_type_,
- GetExplicitPassphraseTime()));
+ OnPassphraseTypeChanged(passphrase_type_,
+ GetExplicitPassphraseTime()));
}
if (passphrase_type_ == KEYSTORE_PASSPHRASE && encrypt_everything_) {
// This is the case where another client that didn't support keystore
@@ -931,20 +901,17 @@ bool SyncEncryptionHandlerImpl::ApplyNigoriUpdateImpl(
<< "due to full encryption.";
passphrase_type_ = FROZEN_IMPLICIT_PASSPHRASE;
FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
- OnPassphraseTypeChanged(
- passphrase_type_,
- GetExplicitPassphraseTime()));
+ OnPassphraseTypeChanged(passphrase_type_,
+ GetExplicitPassphraseTime()));
}
} else {
// It's possible that while we're waiting for migration a client that does
// not have keystore encryption enabled switches to a custom passphrase.
- if (nigori.keybag_is_frozen() &&
- passphrase_type_ != CUSTOM_PASSPHRASE) {
+ if (nigori.keybag_is_frozen() && passphrase_type_ != CUSTOM_PASSPHRASE) {
passphrase_type_ = CUSTOM_PASSPHRASE;
FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
- OnPassphraseTypeChanged(
- passphrase_type_,
- GetExplicitPassphraseTime()));
+ OnPassphraseTypeChanged(passphrase_type_,
+ GetExplicitPassphraseTime()));
}
}
@@ -961,8 +928,7 @@ bool SyncEncryptionHandlerImpl::ApplyNigoriUpdateImpl(
need_new_default_key = nigori.keybag_is_frozen();
}
if (!AttemptToInstallKeybag(nigori.encryption_keybag(),
- need_new_default_key,
- cryptographer)) {
+ need_new_default_key, cryptographer)) {
// Check to see if we can decrypt the keybag using the keystore decryptor
// token.
cryptographer->SetPendingKeys(nigori.encryption_keybag());
@@ -998,14 +964,13 @@ bool SyncEncryptionHandlerImpl::ApplyNigoriUpdateImpl(
DVLOG(1) << "OnPassphraseRequired Sent";
sync_pb::EncryptedData pending_keys = cryptographer->GetPendingKeys();
FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
- OnPassphraseRequired(REASON_DECRYPTION,
- pending_keys));
+ OnPassphraseRequired(REASON_DECRYPTION, pending_keys));
} else if (!cryptographer->is_ready()) {
DVLOG(1) << "OnPassphraseRequired sent because cryptographer is not "
<< "ready";
- FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
- OnPassphraseRequired(REASON_ENCRYPTION,
- sync_pb::EncryptedData()));
+ FOR_EACH_OBSERVER(
+ SyncEncryptionHandler::Observer, observers_,
+ OnPassphraseRequired(REASON_ENCRYPTION, sync_pb::EncryptedData()));
}
// Check if the current local encryption state is stricter/newer than the
@@ -1020,12 +985,11 @@ bool SyncEncryptionHandlerImpl::ApplyNigoriUpdateImpl(
} else {
passphrase_type_matches =
(ProtoPassphraseTypeToEnum(nigori.passphrase_type()) ==
- passphrase_type_);
+ passphrase_type_);
}
if (!passphrase_type_matches ||
nigori.encrypt_everything() != encrypt_everything_ ||
- nigori_types_need_update ||
- nigori_needs_new_keys) {
+ nigori_types_need_update || nigori_needs_new_keys) {
DVLOG(1) << "Triggering nigori rewrite.";
return false;
}
@@ -1079,8 +1043,7 @@ void SyncEncryptionHandlerImpl::WriteEncryptionStateToNigori(
}
syncable::UpdateNigoriFromEncryptedTypes(
UnlockVault(trans->GetWrappedTrans()).encrypted_types,
- encrypt_everything_,
- &nigori);
+ encrypt_everything_, &nigori);
if (!custom_passphrase_time_.is_null()) {
nigori.set_custom_passphrase_time(
TimeToProtoTime(custom_passphrase_time_));
@@ -1234,8 +1197,7 @@ void SyncEncryptionHandlerImpl::FinishSetPassphrase(
WriteNode* nigori_node) {
DCHECK(thread_checker_.CalledOnValidThread());
FOR_EACH_OBSERVER(
- SyncEncryptionHandler::Observer,
- observers_,
+ SyncEncryptionHandler::Observer, observers_,
OnCryptographerStateChanged(
&UnlockVaultMutable(trans->GetWrappedTrans())->cryptographer));
@@ -1244,9 +1206,9 @@ void SyncEncryptionHandlerImpl::FinishSetPassphrase(
// passphrase).
if (!bootstrap_token.empty()) {
DVLOG(1) << "Passphrase bootstrap token updated.";
- FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
- OnBootstrapTokenUpdated(bootstrap_token,
- PASSPHRASE_BOOTSTRAP_TOKEN));
+ FOR_EACH_OBSERVER(
+ SyncEncryptionHandler::Observer, observers_,
+ OnBootstrapTokenUpdated(bootstrap_token, PASSPHRASE_BOOTSTRAP_TOKEN));
}
const Cryptographer& cryptographer =
@@ -1260,9 +1222,9 @@ void SyncEncryptionHandlerImpl::FinishSetPassphrase(
OnPassphraseRequired(REASON_DECRYPTION,
cryptographer.GetPendingKeys()));
} else {
- FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
- OnPassphraseRequired(REASON_ENCRYPTION,
- sync_pb::EncryptedData()));
+ FOR_EACH_OBSERVER(
+ SyncEncryptionHandler::Observer, observers_,
+ OnPassphraseRequired(REASON_ENCRYPTION, sync_pb::EncryptedData()));
}
return;
}
@@ -1284,8 +1246,7 @@ void SyncEncryptionHandlerImpl::FinishSetPassphrase(
DVLOG(1) << "Leaving nigori migration state untouched after setting"
<< " passphrase.";
} else {
- nigori.set_keybag_is_frozen(
- IsExplicitPassphrase(passphrase_type_));
+ nigori.set_keybag_is_frozen(IsExplicitPassphrase(passphrase_type_));
}
// If we set a new custom passphrase, store the timestamp.
if (!custom_passphrase_time_.is_null()) {
@@ -1354,15 +1315,13 @@ bool SyncEncryptionHandlerImpl::ShouldTriggerMigration(
nigori.passphrase_type() ==
sync_pb::NigoriSpecifics::KEYSTORE_PASSPHRASE) {
return true;
- } else if (IsExplicitPassphrase(passphrase_type_) &&
- !encrypt_everything_) {
+ } else if (IsExplicitPassphrase(passphrase_type_) && !encrypt_everything_) {
return true;
- } else if (passphrase_type_ == KEYSTORE_PASSPHRASE &&
- encrypt_everything_) {
+ } else if (passphrase_type_ == KEYSTORE_PASSPHRASE && encrypt_everything_) {
return true;
- } else if (
- cryptographer.is_ready() &&
- !cryptographer.CanDecryptUsingDefaultKey(nigori.encryption_keybag())) {
+ } else if (cryptographer.is_ready() &&
+ !cryptographer.CanDecryptUsingDefaultKey(
+ nigori.encryption_keybag())) {
// We need to overwrite the keybag. This might involve overwriting the
// keystore decryptor too.
return true;
@@ -1448,10 +1407,8 @@ bool SyncEncryptionHandlerImpl::AttemptToMigrateNigoriToKeystore(
return false;
}
if (!cryptographer_was_ready && cryptographer->is_ready()) {
- FOR_EACH_OBSERVER(
- SyncEncryptionHandler::Observer,
- observers_,
- OnPassphraseAccepted());
+ FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
+ OnPassphraseAccepted());
}
} else {
// We're in backwards compatible mode -- either the account has an
@@ -1473,16 +1430,15 @@ bool SyncEncryptionHandlerImpl::AttemptToMigrateNigoriToKeystore(
// they'll be preserved in the encryption_keybag when we next write the
// nigori node.
for (std::vector<std::string>::const_iterator iter =
- old_keystore_keys_.begin(); iter != old_keystore_keys_.end();
- ++iter) {
+ old_keystore_keys_.begin();
+ iter != old_keystore_keys_.end(); ++iter) {
KeyParams key_params = {"localhost", "dummy", *iter};
cryptographer->AddNonDefaultKey(key_params);
}
}
if (new_passphrase_type == KEYSTORE_PASSPHRASE &&
!GetKeystoreDecryptor(
- *cryptographer,
- keystore_key_,
+ *cryptographer, keystore_key_,
migrated_nigori.mutable_keystore_decryptor_token())) {
LOG(ERROR) << "Failed to extract keystore decryptor token.";
UMA_HISTOGRAM_ENUMERATION("Sync.AttemptNigoriMigration",
@@ -1493,8 +1449,7 @@ bool SyncEncryptionHandlerImpl::AttemptToMigrateNigoriToKeystore(
if (!cryptographer->GetKeys(migrated_nigori.mutable_encryption_keybag())) {
LOG(ERROR) << "Failed to extract encryption keybag.";
UMA_HISTOGRAM_ENUMERATION("Sync.AttemptNigoriMigration",
- FAILED_TO_EXTRACT_KEYBAG,
- MIGRATION_RESULT_SIZE);
+ FAILED_TO_EXTRACT_KEYBAG, MIGRATION_RESULT_SIZE);
return false;
}
@@ -1507,16 +1462,13 @@ bool SyncEncryptionHandlerImpl::AttemptToMigrateNigoriToKeystore(
TimeToProtoTime(custom_passphrase_time_));
}
- FOR_EACH_OBSERVER(
- SyncEncryptionHandler::Observer,
- observers_,
- OnCryptographerStateChanged(cryptographer));
+ FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
+ OnCryptographerStateChanged(cryptographer));
if (passphrase_type_ != new_passphrase_type) {
passphrase_type_ = new_passphrase_type;
- FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
- OnPassphraseTypeChanged(
- passphrase_type_,
- GetExplicitPassphraseTime()));
+ FOR_EACH_OBSERVER(
+ SyncEncryptionHandler::Observer, observers_,
+ OnPassphraseTypeChanged(passphrase_type_, GetExplicitPassphraseTime()));
}
if (new_encrypt_everything && !encrypt_everything_) {
@@ -1672,19 +1624,13 @@ bool SyncEncryptionHandlerImpl::DecryptPendingKeysWithKeystoreKey(
std::string bootstrap_token;
cryptographer->GetBootstrapToken(&bootstrap_token);
DVLOG(1) << "Keystore decryptor token decrypted pending keys.";
+ FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
+ OnPassphraseAccepted());
FOR_EACH_OBSERVER(
- SyncEncryptionHandler::Observer,
- observers_,
- OnPassphraseAccepted());
- FOR_EACH_OBSERVER(
- SyncEncryptionHandler::Observer,
- observers_,
- OnBootstrapTokenUpdated(bootstrap_token,
- PASSPHRASE_BOOTSTRAP_TOKEN));
- FOR_EACH_OBSERVER(
- SyncEncryptionHandler::Observer,
- observers_,
- OnCryptographerStateChanged(cryptographer));
+ SyncEncryptionHandler::Observer, observers_,
+ OnBootstrapTokenUpdated(bootstrap_token, PASSPHRASE_BOOTSTRAP_TOKEN));
+ FOR_EACH_OBSERVER(SyncEncryptionHandler::Observer, observers_,
+ OnCryptographerStateChanged(cryptographer));
return true;
}
}

Powered by Google App Engine
This is Rietveld 408576698