| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/sync/engine/syncer_util.h" | 5 #include "chrome/browser/sync/engine/syncer_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 // of the first client and commit the set of merged encryption keys. Until the | 273 // of the first client and commit the set of merged encryption keys. Until the |
| 274 // second client provides the pending passphrase, the cryptographer will | 274 // second client provides the pending passphrase, the cryptographer will |
| 275 // preserve the encryption keys based on the local passphrase, while the | 275 // preserve the encryption keys based on the local passphrase, while the |
| 276 // nigori node will preserve the server encryption keys. | 276 // nigori node will preserve the server encryption keys. |
| 277 // | 277 // |
| 278 // If non-encryption changes are made to the nigori node, they will be | 278 // If non-encryption changes are made to the nigori node, they will be |
| 279 // lost as part of conflict resolution. This is intended, as we place a higher | 279 // lost as part of conflict resolution. This is intended, as we place a higher |
| 280 // priority on preserving the server's passphrase change to preserving local | 280 // priority on preserving the server's passphrase change to preserving local |
| 281 // non-encryption changes. Next time the non-encryption changes are made to | 281 // non-encryption changes. Next time the non-encryption changes are made to |
| 282 // the nigori node (e.g. on restart), they will commit without issue. | 282 // the nigori node (e.g. on restart), they will commit without issue. |
| 283 if (specifics.HasExtension(sync_pb::nigori)) { | 283 if (specifics.has_nigori()) { |
| 284 const sync_pb::NigoriSpecifics& nigori = | 284 const sync_pb::NigoriSpecifics& nigori = specifics.nigori(); |
| 285 specifics.GetExtension(sync_pb::nigori); | |
| 286 cryptographer->Update(nigori); | 285 cryptographer->Update(nigori); |
| 287 | 286 |
| 288 // Make sure any unsynced changes are properly encrypted as necessary. | 287 // Make sure any unsynced changes are properly encrypted as necessary. |
| 289 // We only perform this if the cryptographer is ready. If not, these are | 288 // We only perform this if the cryptographer is ready. If not, these are |
| 290 // re-encrypted at SetPassphrase time (via ReEncryptEverything). This logic | 289 // re-encrypted at SetPassphrase time (via ReEncryptEverything). This logic |
| 291 // covers the case where the nigori updated marked new datatypes for | 290 // covers the case where the nigori updated marked new datatypes for |
| 292 // encryption, but didn't change the passphrase. | 291 // encryption, but didn't change the passphrase. |
| 293 if (cryptographer->is_ready()) { | 292 if (cryptographer->is_ready()) { |
| 294 // Note that we don't bother to encrypt any data for which IS_UNSYNCED | 293 // Note that we don't bother to encrypt any data for which IS_UNSYNCED |
| 295 // == false here. The machine that turned on encryption should know about | 294 // == false here. The machine that turned on encryption should know about |
| (...skipping 17 matching lines...) Expand all Loading... |
| 313 // treated as an unresolvable conflict. See the description in syncer_types.h. | 312 // treated as an unresolvable conflict. See the description in syncer_types.h. |
| 314 // This prevents any unsynced changes from commiting and postpones conflict | 313 // This prevents any unsynced changes from commiting and postpones conflict |
| 315 // resolution until all data can be decrypted. | 314 // resolution until all data can be decrypted. |
| 316 if (specifics.has_encrypted() && | 315 if (specifics.has_encrypted() && |
| 317 !cryptographer->CanDecrypt(specifics.encrypted())) { | 316 !cryptographer->CanDecrypt(specifics.encrypted())) { |
| 318 // We can't decrypt this node yet. | 317 // We can't decrypt this node yet. |
| 319 DVLOG(1) << "Received an undecryptable " | 318 DVLOG(1) << "Received an undecryptable " |
| 320 << syncable::ModelTypeToString(entry->GetServerModelType()) | 319 << syncable::ModelTypeToString(entry->GetServerModelType()) |
| 321 << " update, returning encryption_conflict."; | 320 << " update, returning encryption_conflict."; |
| 322 return CONFLICT_ENCRYPTION; | 321 return CONFLICT_ENCRYPTION; |
| 323 } else if (specifics.HasExtension(sync_pb::password) && | 322 } else if (specifics.has_password() && |
| 324 entry->Get(UNIQUE_SERVER_TAG).empty()) { | 323 entry->Get(UNIQUE_SERVER_TAG).empty()) { |
| 325 // Passwords use their own legacy encryption scheme. | 324 // Passwords use their own legacy encryption scheme. |
| 326 const sync_pb::PasswordSpecifics& password = | 325 const sync_pb::PasswordSpecifics& password = specifics.password(); |
| 327 specifics.GetExtension(sync_pb::password); | |
| 328 if (!cryptographer->CanDecrypt(password.encrypted())) { | 326 if (!cryptographer->CanDecrypt(password.encrypted())) { |
| 329 DVLOG(1) << "Received an undecryptable password update, returning " | 327 DVLOG(1) << "Received an undecryptable password update, returning " |
| 330 << "encryption_conflict."; | 328 << "encryption_conflict."; |
| 331 return CONFLICT_ENCRYPTION; | 329 return CONFLICT_ENCRYPTION; |
| 332 } | 330 } |
| 333 } | 331 } |
| 334 | 332 |
| 335 if (!entry->Get(SERVER_IS_DEL)) { | 333 if (!entry->Get(SERVER_IS_DEL)) { |
| 336 syncable::Id new_parent = entry->Get(SERVER_PARENT_ID); | 334 syncable::Id new_parent = entry->Get(SERVER_PARENT_ID); |
| 337 Entry parent(trans, GET_BY_ID, new_parent); | 335 Entry parent(trans, GET_BY_ID, new_parent); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 // protocol. | 387 // protocol. |
| 390 void UpdateBookmarkSpecifics(const std::string& singleton_tag, | 388 void UpdateBookmarkSpecifics(const std::string& singleton_tag, |
| 391 const std::string& url, | 389 const std::string& url, |
| 392 const std::string& favicon_bytes, | 390 const std::string& favicon_bytes, |
| 393 MutableEntry* local_entry) { | 391 MutableEntry* local_entry) { |
| 394 // In the new-style protocol, the server no longer sends bookmark info for | 392 // In the new-style protocol, the server no longer sends bookmark info for |
| 395 // the "google_chrome" folder. Mimic that here. | 393 // the "google_chrome" folder. Mimic that here. |
| 396 if (singleton_tag == "google_chrome") | 394 if (singleton_tag == "google_chrome") |
| 397 return; | 395 return; |
| 398 sync_pb::EntitySpecifics pb; | 396 sync_pb::EntitySpecifics pb; |
| 399 sync_pb::BookmarkSpecifics* bookmark = pb.MutableExtension(sync_pb::bookmark); | 397 sync_pb::BookmarkSpecifics* bookmark = pb.mutable_bookmark(); |
| 400 if (!url.empty()) | 398 if (!url.empty()) |
| 401 bookmark->set_url(url); | 399 bookmark->set_url(url); |
| 402 if (!favicon_bytes.empty()) | 400 if (!favicon_bytes.empty()) |
| 403 bookmark->set_favicon(favicon_bytes); | 401 bookmark->set_favicon(favicon_bytes); |
| 404 local_entry->Put(SERVER_SPECIFICS, pb); | 402 local_entry->Put(SERVER_SPECIFICS, pb); |
| 405 } | 403 } |
| 406 | 404 |
| 407 } // namespace | 405 } // namespace |
| 408 | 406 |
| 409 // Pass in name and checksum because of UTF8 conversion. | 407 // Pass in name and checksum because of UTF8 conversion. |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 if (update.version() < target->Get(SERVER_VERSION)) { | 769 if (update.version() < target->Get(SERVER_VERSION)) { |
| 772 LOG(WARNING) << "Update older than current server version for " | 770 LOG(WARNING) << "Update older than current server version for " |
| 773 << *target << " Update:" | 771 << *target << " Update:" |
| 774 << SyncerProtoUtil::SyncEntityDebugString(update); | 772 << SyncerProtoUtil::SyncEntityDebugString(update); |
| 775 return VERIFY_SUCCESS; // Expected in new sync protocol. | 773 return VERIFY_SUCCESS; // Expected in new sync protocol. |
| 776 } | 774 } |
| 777 return VERIFY_UNDECIDED; | 775 return VERIFY_UNDECIDED; |
| 778 } | 776 } |
| 779 | 777 |
| 780 } // namespace browser_sync | 778 } // namespace browser_sync |
| OLD | NEW |