| 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 "sync/engine/syncer_util.h" | 5 #include "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 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 syncable::WriteTransaction* const trans, | 187 syncable::WriteTransaction* const trans, |
| 188 syncable::MutableEntry* const entry, | 188 syncable::MutableEntry* const entry, |
| 189 ConflictResolver* resolver, | 189 ConflictResolver* resolver, |
| 190 Cryptographer* cryptographer) { | 190 Cryptographer* cryptographer) { |
| 191 CHECK(entry->good()); | 191 CHECK(entry->good()); |
| 192 if (!entry->Get(IS_UNAPPLIED_UPDATE)) | 192 if (!entry->Get(IS_UNAPPLIED_UPDATE)) |
| 193 return SUCCESS; // No work to do. | 193 return SUCCESS; // No work to do. |
| 194 syncable::Id id = entry->Get(ID); | 194 syncable::Id id = entry->Get(ID); |
| 195 const sync_pb::EntitySpecifics& specifics = entry->Get(SERVER_SPECIFICS); | 195 const sync_pb::EntitySpecifics& specifics = entry->Get(SERVER_SPECIFICS); |
| 196 | 196 |
| 197 // We intercept updates to the Nigori node, update the Cryptographer and | |
| 198 // encrypt any unsynced changes here because there is no Nigori | |
| 199 // ChangeProcessor. We never put the nigori node in a state of | |
| 200 // conflict_encryption. | |
| 201 // | |
| 202 // We always update the cryptographer with the server's nigori node, | |
| 203 // even if we have a locally modified nigori node (we manually merge nigori | |
| 204 // data in the conflict resolver in that case). This handles the case where | |
| 205 // two clients both set a different passphrase. The second client to attempt | |
| 206 // to commit will go into a state of having pending keys, unioned the set of | |
| 207 // encrypted types, and eventually re-encrypt everything with the passphrase | |
| 208 // of the first client and commit the set of merged encryption keys. Until the | |
| 209 // second client provides the pending passphrase, the cryptographer will | |
| 210 // preserve the encryption keys based on the local passphrase, while the | |
| 211 // nigori node will preserve the server encryption keys. | |
| 212 // | |
| 213 // If non-encryption changes are made to the nigori node, they will be | |
| 214 // lost as part of conflict resolution. This is intended, as we place a higher | |
| 215 // priority on preserving the server's passphrase change to preserving local | |
| 216 // non-encryption changes. Next time the non-encryption changes are made to | |
| 217 // the nigori node (e.g. on restart), they will commit without issue. | |
| 218 if (specifics.has_nigori()) { | |
| 219 const sync_pb::NigoriSpecifics& nigori = specifics.nigori(); | |
| 220 cryptographer->ApplyNigoriUpdate(nigori, trans); | |
| 221 | |
| 222 // Make sure any unsynced changes are properly encrypted as necessary. | |
| 223 // We only perform this if the cryptographer is ready. If not, these are | |
| 224 // re-encrypted at SetDecryptionPassphrase time (via ReEncryptEverything). | |
| 225 // This logic covers the case where the nigori update marked new datatypes | |
| 226 // for encryption, but didn't change the passphrase. | |
| 227 if (cryptographer->is_ready()) { | |
| 228 // Note that we don't bother to encrypt any data for which IS_UNSYNCED | |
| 229 // == false here. The machine that turned on encryption should know about | |
| 230 // and re-encrypt all synced data. It's possible it could get interrupted | |
| 231 // during this process, but we currently reencrypt everything at startup | |
| 232 // as well, so as soon as a client is restarted with this datatype marked | |
| 233 // for encryption, all the data should be updated as necessary. | |
| 234 | |
| 235 // If this fails, something is wrong with the cryptographer, but there's | |
| 236 // nothing we can do about it here. | |
| 237 DVLOG(1) << "Received new nigori, encrypting unsynced changes."; | |
| 238 syncable::ProcessUnsyncedChangesForEncryption(trans, cryptographer); | |
| 239 } | |
| 240 } | |
| 241 | |
| 242 // Only apply updates that we can decrypt. If we can't decrypt the update, it | 197 // Only apply updates that we can decrypt. If we can't decrypt the update, it |
| 243 // is likely because the passphrase has not arrived yet. Because the | 198 // is likely because the passphrase has not arrived yet. Because the |
| 244 // passphrase may not arrive within this GetUpdates, we can't just return | 199 // passphrase may not arrive within this GetUpdates, we can't just return |
| 245 // conflict, else we try to perform normal conflict resolution prematurely or | 200 // conflict, else we try to perform normal conflict resolution prematurely or |
| 246 // the syncer may get stuck. As such, we return CONFLICT_ENCRYPTION, which is | 201 // the syncer may get stuck. As such, we return CONFLICT_ENCRYPTION, which is |
| 247 // treated as an unresolvable conflict. See the description in syncer_types.h. | 202 // treated as an unresolvable conflict. See the description in syncer_types.h. |
| 248 // This prevents any unsynced changes from commiting and postpones conflict | 203 // This prevents any unsynced changes from commiting and postpones conflict |
| 249 // resolution until all data can be decrypted. | 204 // resolution until all data can be decrypted. |
| 250 if (specifics.has_encrypted() && | 205 if (specifics.has_encrypted() && |
| 251 !cryptographer->CanDecrypt(specifics.encrypted())) { | 206 !cryptographer->CanDecrypt(specifics.encrypted())) { |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 if (update.version() < target->Get(SERVER_VERSION)) { | 647 if (update.version() < target->Get(SERVER_VERSION)) { |
| 693 LOG(WARNING) << "Update older than current server version for " | 648 LOG(WARNING) << "Update older than current server version for " |
| 694 << *target << " Update:" | 649 << *target << " Update:" |
| 695 << SyncerProtoUtil::SyncEntityDebugString(update); | 650 << SyncerProtoUtil::SyncEntityDebugString(update); |
| 696 return VERIFY_SUCCESS; // Expected in new sync protocol. | 651 return VERIFY_SUCCESS; // Expected in new sync protocol. |
| 697 } | 652 } |
| 698 return VERIFY_UNDECIDED; | 653 return VERIFY_UNDECIDED; |
| 699 } | 654 } |
| 700 | 655 |
| 701 } // namespace syncer | 656 } // namespace syncer |
| OLD | NEW |