OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/sync/syncable/nigori_util.h" | 5 #include "components/sync/syncable/nigori_util.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <queue> | 10 #include <queue> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
15 #include "components/sync/base/cryptographer.h" | 15 #include "components/sync/base/cryptographer.h" |
| 16 #include "components/sync/base/passphrase_type.h" |
16 #include "components/sync/syncable/directory.h" | 17 #include "components/sync/syncable/directory.h" |
17 #include "components/sync/syncable/entry.h" | 18 #include "components/sync/syncable/entry.h" |
18 #include "components/sync/syncable/mutable_entry.h" | 19 #include "components/sync/syncable/mutable_entry.h" |
19 #include "components/sync/syncable/nigori_handler.h" | 20 #include "components/sync/syncable/nigori_handler.h" |
20 #include "components/sync/syncable/syncable_util.h" | 21 #include "components/sync/syncable/syncable_util.h" |
21 #include "components/sync/syncable/syncable_write_transaction.h" | 22 #include "components/sync/syncable/syncable_write_transaction.h" |
22 | 23 |
23 namespace syncer { | 24 namespace syncer { |
24 namespace syncable { | 25 namespace syncable { |
25 | 26 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 } | 141 } |
141 // Push the successor. | 142 // Push the successor. |
142 to_visit.push(child.GetSuccessorId()); | 143 to_visit.push(child.GetSuccessorId()); |
143 } | 144 } |
144 return true; | 145 return true; |
145 } | 146 } |
146 | 147 |
147 bool UpdateEntryWithEncryption(BaseTransaction* const trans, | 148 bool UpdateEntryWithEncryption(BaseTransaction* const trans, |
148 const sync_pb::EntitySpecifics& new_specifics, | 149 const sync_pb::EntitySpecifics& new_specifics, |
149 syncable::MutableEntry* entry) { | 150 syncable::MutableEntry* entry) { |
| 151 return UpdateEntryWithEncryption(trans, new_specifics, entry, |
| 152 syncer::PassphraseType::UNDEFINED); |
| 153 } |
| 154 |
| 155 bool UpdateEntryWithEncryption(BaseTransaction* const trans, |
| 156 const sync_pb::EntitySpecifics& new_specifics, |
| 157 syncable::MutableEntry* entry, |
| 158 PassphraseType passphrase_type) { |
150 NigoriHandler* nigori_handler = trans->directory()->GetNigoriHandler(); | 159 NigoriHandler* nigori_handler = trans->directory()->GetNigoriHandler(); |
151 Cryptographer* cryptographer = trans->directory()->GetCryptographer(trans); | 160 Cryptographer* cryptographer = trans->directory()->GetCryptographer(trans); |
152 ModelType type = GetModelTypeFromSpecifics(new_specifics); | 161 ModelType type = GetModelTypeFromSpecifics(new_specifics); |
153 DCHECK_GE(type, FIRST_REAL_MODEL_TYPE); | 162 DCHECK_GE(type, FIRST_REAL_MODEL_TYPE); |
154 const sync_pb::EntitySpecifics& old_specifics = entry->GetSpecifics(); | 163 const sync_pb::EntitySpecifics& old_specifics = entry->GetSpecifics(); |
155 const ModelTypeSet encrypted_types = | 164 const ModelTypeSet encrypted_types = |
156 nigori_handler ? nigori_handler->GetEncryptedTypes(trans) | 165 nigori_handler ? nigori_handler->GetEncryptedTypes(trans) |
157 : ModelTypeSet(); | 166 : ModelTypeSet(); |
158 // It's possible the nigori lost the set of encrypted types. If the current | 167 // It's possible the nigori lost the set of encrypted types. If the current |
159 // specifics are already encrypted, we want to ensure we continue encrypting. | 168 // specifics are already encrypted, we want to ensure we continue encrypting. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 // For bookmarks we actually put bogus data into the unencrypted specifics, | 227 // For bookmarks we actually put bogus data into the unencrypted specifics, |
219 // else the server will try to do it for us. | 228 // else the server will try to do it for us. |
220 if (type == BOOKMARKS) { | 229 if (type == BOOKMARKS) { |
221 sync_pb::BookmarkSpecifics* bookmark_specifics = | 230 sync_pb::BookmarkSpecifics* bookmark_specifics = |
222 generated_specifics.mutable_bookmark(); | 231 generated_specifics.mutable_bookmark(); |
223 if (!entry->GetIsDir()) | 232 if (!entry->GetIsDir()) |
224 bookmark_specifics->set_url(kEncryptedString); | 233 bookmark_specifics->set_url(kEncryptedString); |
225 bookmark_specifics->set_title(kEncryptedString); | 234 bookmark_specifics->set_title(kEncryptedString); |
226 } | 235 } |
227 } | 236 } |
| 237 |
| 238 if (type == PASSWORDS && IsExplicitPassphrase(passphrase_type)) { |
| 239 sync_pb::PasswordSpecifics* password_specifics = |
| 240 generated_specifics.mutable_password(); |
| 241 password_specifics->clear_unencrypted_metadata(); |
| 242 } |
| 243 |
228 entry->PutSpecifics(generated_specifics); | 244 entry->PutSpecifics(generated_specifics); |
229 DVLOG(1) << "Overwriting specifics of type " << ModelTypeToString(type) | 245 DVLOG(1) << "Overwriting specifics of type " << ModelTypeToString(type) |
230 << " and marking for syncing."; | 246 << " and marking for syncing."; |
231 syncable::MarkForSyncing(entry); | 247 syncable::MarkForSyncing(entry); |
232 return true; | 248 return true; |
233 } | 249 } |
234 | 250 |
235 void UpdateNigoriFromEncryptedTypes(ModelTypeSet encrypted_types, | 251 void UpdateNigoriFromEncryptedTypes(ModelTypeSet encrypted_types, |
236 bool encrypt_everything, | 252 bool encrypt_everything, |
237 sync_pb::NigoriSpecifics* nigori) { | 253 sync_pb::NigoriSpecifics* nigori) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 encrypted_types.Put(ARTICLES); | 322 encrypted_types.Put(ARTICLES); |
307 if (nigori.encrypt_app_list()) | 323 if (nigori.encrypt_app_list()) |
308 encrypted_types.Put(APP_LIST); | 324 encrypted_types.Put(APP_LIST); |
309 if (nigori.encrypt_arc_package()) | 325 if (nigori.encrypt_arc_package()) |
310 encrypted_types.Put(ARC_PACKAGE); | 326 encrypted_types.Put(ARC_PACKAGE); |
311 return encrypted_types; | 327 return encrypted_types; |
312 } | 328 } |
313 | 329 |
314 } // namespace syncable | 330 } // namespace syncable |
315 } // namespace syncer | 331 } // namespace syncer |
OLD | NEW |