| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/nigori_util.h" | 5 #include "chrome/browser/sync/engine/nigori_util.h" |
| 6 | 6 |
| 7 #include <queue> | 7 #include <queue> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 &entry)) { | 31 &entry)) { |
| 32 NOTREACHED(); | 32 NOTREACHED(); |
| 33 return false; | 33 return false; |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 return true; | 36 return true; |
| 37 } | 37 } |
| 38 | 38 |
| 39 bool VerifyUnsyncedChangesAreEncrypted( | 39 bool VerifyUnsyncedChangesAreEncrypted( |
| 40 BaseTransaction* const trans, | 40 BaseTransaction* const trans, |
| 41 ModelEnumSet encrypted_types) { | 41 ModelTypeSet encrypted_types) { |
| 42 std::vector<int64> handles; | 42 std::vector<int64> handles; |
| 43 browser_sync::SyncerUtil::GetUnsyncedEntries(trans, &handles); | 43 browser_sync::SyncerUtil::GetUnsyncedEntries(trans, &handles); |
| 44 for (size_t i = 0; i < handles.size(); ++i) { | 44 for (size_t i = 0; i < handles.size(); ++i) { |
| 45 Entry entry(trans, GET_BY_HANDLE, handles[i]); | 45 Entry entry(trans, GET_BY_HANDLE, handles[i]); |
| 46 if (!entry.good()) { | 46 if (!entry.good()) { |
| 47 NOTREACHED(); | 47 NOTREACHED(); |
| 48 return false; | 48 return false; |
| 49 } | 49 } |
| 50 if (EntryNeedsEncryption(encrypted_types, entry)) | 50 if (EntryNeedsEncryption(encrypted_types, entry)) |
| 51 return false; | 51 return false; |
| 52 } | 52 } |
| 53 return true; | 53 return true; |
| 54 } | 54 } |
| 55 | 55 |
| 56 bool EntryNeedsEncryption(ModelEnumSet encrypted_types, | 56 bool EntryNeedsEncryption(ModelTypeSet encrypted_types, |
| 57 const Entry& entry) { | 57 const Entry& entry) { |
| 58 if (!entry.Get(UNIQUE_SERVER_TAG).empty()) | 58 if (!entry.Get(UNIQUE_SERVER_TAG).empty()) |
| 59 return false; // We don't encrypt unique server nodes. | 59 return false; // We don't encrypt unique server nodes. |
| 60 syncable::ModelType type = entry.GetModelType(); | 60 syncable::ModelType type = entry.GetModelType(); |
| 61 if (type == PASSWORDS || type == NIGORI) | 61 if (type == PASSWORDS || type == NIGORI) |
| 62 return false; | 62 return false; |
| 63 // Checking NON_UNIQUE_NAME is not necessary for the correctness of encrypting | 63 // Checking NON_UNIQUE_NAME is not necessary for the correctness of encrypting |
| 64 // the data, nor for determining if data is encrypted. We simply ensure it has | 64 // the data, nor for determining if data is encrypted. We simply ensure it has |
| 65 // been overwritten to avoid any possible leaks of sensitive data. | 65 // been overwritten to avoid any possible leaks of sensitive data. |
| 66 return SpecificsNeedsEncryption(encrypted_types, entry.Get(SPECIFICS)) || | 66 return SpecificsNeedsEncryption(encrypted_types, entry.Get(SPECIFICS)) || |
| 67 (encrypted_types.Has(type) && | 67 (encrypted_types.Has(type) && |
| 68 entry.Get(NON_UNIQUE_NAME) != kEncryptedString); | 68 entry.Get(NON_UNIQUE_NAME) != kEncryptedString); |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool SpecificsNeedsEncryption(ModelEnumSet encrypted_types, | 71 bool SpecificsNeedsEncryption(ModelTypeSet encrypted_types, |
| 72 const sync_pb::EntitySpecifics& specifics) { | 72 const sync_pb::EntitySpecifics& specifics) { |
| 73 const ModelType type = GetModelTypeFromSpecifics(specifics); | 73 const ModelType type = GetModelTypeFromSpecifics(specifics); |
| 74 if (type == PASSWORDS || type == NIGORI) | 74 if (type == PASSWORDS || type == NIGORI) |
| 75 return false; // These types have their own encryption schemes. | 75 return false; // These types have their own encryption schemes. |
| 76 if (!encrypted_types.Has(type)) | 76 if (!encrypted_types.Has(type)) |
| 77 return false; // This type does not require encryption | 77 return false; // This type does not require encryption |
| 78 return !specifics.has_encrypted(); | 78 return !specifics.has_encrypted(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 // Mainly for testing. | 81 // Mainly for testing. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 return false; | 138 return false; |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 // Push the successor. | 141 // Push the successor. |
| 142 to_visit.push(child.Get(NEXT_ID)); | 142 to_visit.push(child.Get(NEXT_ID)); |
| 143 } | 143 } |
| 144 return true; | 144 return true; |
| 145 } | 145 } |
| 146 | 146 |
| 147 } // namespace syncable | 147 } // namespace syncable |
| OLD | NEW |