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

Unified Diff: chrome/browser/sync/engine/syncapi.cc

Issue 7108067: [Sync] Ensure cryptographer ready before encrypting. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 6 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: chrome/browser/sync/engine/syncapi.cc
diff --git a/chrome/browser/sync/engine/syncapi.cc b/chrome/browser/sync/engine/syncapi.cc
index 360b6947b8346a074646d9eb7374e070c9eacba7..5f60488744a90ce599d0b61c6c60d9ee23e38b45 100644
--- a/chrome/browser/sync/engine/syncapi.cc
+++ b/chrome/browser/sync/engine/syncapi.cc
@@ -202,7 +202,7 @@ UserShare::~UserShare() {}
////////////////////////////////////
// BaseNode member definitions.
-BaseNode::BaseNode() {}
+BaseNode::BaseNode() : password_data_(new sync_pb::PasswordSpecificsData) {}
BaseNode::~BaseNode() {}
@@ -245,8 +245,10 @@ bool BaseNode::DecryptIfNecessary() {
// Passwords have their own legacy encryption structure.
scoped_ptr<sync_pb::PasswordSpecificsData> data(DecryptPasswordSpecifics(
specifics, GetTransaction()->GetCryptographer()));
- if (!data.get())
+ if (!data.get()) {
+ LOG(ERROR) << "Failed to decrypt password specifics.";
return false;
+ }
password_data_.swap(data);
return true;
}
@@ -259,9 +261,8 @@ bool BaseNode::DecryptIfNecessary() {
specifics.encrypted();
std::string plaintext_data = GetTransaction()->GetCryptographer()->
DecryptToString(encrypted);
- if (plaintext_data.length() == 0)
- return false;
- if (!unencrypted_data_.ParseFromString(plaintext_data)) {
+ if (plaintext_data.length() == 0 ||
+ !unencrypted_data_.ParseFromString(plaintext_data)) {
LOG(ERROR) << "Failed to decrypt encrypted node of type " <<
syncable::ModelTypeToString(GetModelType()) << ".";
return false;
@@ -404,7 +405,6 @@ const sync_pb::NigoriSpecifics& BaseNode::GetNigoriSpecifics() const {
const sync_pb::PasswordSpecificsData& BaseNode::GetPasswordSpecifics() const {
DCHECK_EQ(syncable::PASSWORDS, GetModelType());
- DCHECK(password_data_.get());
return *password_data_;
}
@@ -571,7 +571,9 @@ void WriteNode::SetPasswordSpecifics(
sync_pb::PasswordSpecifics new_value;
if (!cryptographer->Encrypt(data, new_value.mutable_encrypted())) {
- NOTREACHED();
+ LOG(ERROR) << "Failed to encrypt password, possibly due to sync node "
+ << "corruption";
+ return;
}
sync_pb::EntitySpecifics entity_specifics;
@@ -1829,14 +1831,18 @@ void SyncManager::SyncInternal::BootstrapEncryption(
CopyObservers(&temp_obs_list);
FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list,
OnPassphraseRequired(sync_api::REASON_DECRYPTION));
+ return;
+ }
+
+ if (!cryptographer->is_ready()) {
+ NOTREACHED() << "Cryptographer failed to initialize.";
+ return;
}
// Refresh list of encrypted datatypes.
encrypted_types = GetEncryptedTypes(&trans);
}
-
-
// Ensure any datatypes that need encryption are encrypted.
EncryptDataTypes(encrypted_types);
}
@@ -2085,14 +2091,19 @@ void SyncManager::SyncInternal::EncryptDataTypes(
WriteTransaction trans(GetUserShare());
WriteNode node(&trans);
if (!node.InitByTagLookup(kNigoriTag)) {
- LOG(ERROR) << "Unable to set encrypted datatypes because Nigori node not "
- << "found.";
- NOTREACHED();
+ NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not "
+ << "found.";
return;
}
Cryptographer* cryptographer = trans.GetCryptographer();
+ if (!cryptographer->is_ready()) {
+ NOTREACHED() << "Attempting to encrypt datatypes when cryptographer not "
+ << "ready.";
+ return;
+ }
+
// Update the Nigori node set of encrypted datatypes so other machines notice.
// Note, we merge the current encrypted types with those requested. Once a
// datatypes is marked as needing encryption, it is never unmarked.
« no previous file with comments | « no previous file | chrome/browser/sync/engine/syncapi_unittest.cc » ('j') | chrome/browser/sync/engine/syncapi_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698