| 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/syncable/nigori_util.h" | 5 #include "chrome/browser/sync/syncable/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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 BaseTransaction* const trans, | 56 BaseTransaction* const trans, |
| 57 const ModelTypeSet& encrypted_types) { | 57 const ModelTypeSet& encrypted_types) { |
| 58 std::vector<int64> handles; | 58 std::vector<int64> handles; |
| 59 browser_sync::SyncerUtil::GetUnsyncedEntries(trans, &handles); | 59 browser_sync::SyncerUtil::GetUnsyncedEntries(trans, &handles); |
| 60 for (size_t i = 0; i < handles.size(); ++i) { | 60 for (size_t i = 0; i < handles.size(); ++i) { |
| 61 Entry entry(trans, GET_BY_HANDLE, handles[i]); | 61 Entry entry(trans, GET_BY_HANDLE, handles[i]); |
| 62 if (!entry.good()) { | 62 if (!entry.good()) { |
| 63 NOTREACHED(); | 63 NOTREACHED(); |
| 64 return false; | 64 return false; |
| 65 } | 65 } |
| 66 if (EntryNeedsEncryption(encrypted_types, entry)) | 66 const sync_pb::EntitySpecifics& entry_specifics = entry.Get(SPECIFICS); |
| 67 ModelType type = entry.GetModelType(); |
| 68 if (type == PASSWORDS) |
| 69 continue; |
| 70 if (encrypted_types.count(type) > 0 && |
| 71 !entry_specifics.has_encrypted()) { |
| 72 // This datatype requires encryption but this data is not encrypted. |
| 67 return false; | 73 return false; |
| 74 } |
| 68 } | 75 } |
| 69 return true; | 76 return true; |
| 70 } | 77 } |
| 71 | 78 |
| 72 bool EntryNeedsEncryption(const ModelTypeSet& encrypted_types, | |
| 73 const Entry& entry) { | |
| 74 if (!entry.Get(UNIQUE_SERVER_TAG).empty()) | |
| 75 return false; // We don't encrypt unique server nodes. | |
| 76 return SpecificsNeedsEncryption(encrypted_types, entry.Get(SPECIFICS)); | |
| 77 } | |
| 78 | |
| 79 bool SpecificsNeedsEncryption(const ModelTypeSet& encrypted_types, | |
| 80 const sync_pb::EntitySpecifics& specifics) { | |
| 81 ModelType type = GetModelTypeFromSpecifics(specifics); | |
| 82 if (type == PASSWORDS || type == NIGORI) | |
| 83 return false; // These types have their own encryption schemes. | |
| 84 if (encrypted_types.count(type) == 0) | |
| 85 return false; // This type does not require encryption | |
| 86 return !specifics.has_encrypted(); | |
| 87 } | |
| 88 | |
| 89 // Mainly for testing. | 79 // Mainly for testing. |
| 90 bool VerifyDataTypeEncryption(BaseTransaction* const trans, | 80 bool VerifyDataTypeEncryption(BaseTransaction* const trans, |
| 91 browser_sync::Cryptographer* cryptographer, | 81 browser_sync::Cryptographer* cryptographer, |
| 92 ModelType type, | 82 ModelType type, |
| 93 bool is_encrypted) { | 83 bool is_encrypted) { |
| 94 if (type == PASSWORDS || type == NIGORI) { | 84 if (type == PASSWORDS || type == NIGORI) { |
| 95 NOTREACHED(); | 85 NOTREACHED(); |
| 96 return true; | 86 return true; |
| 97 } | 87 } |
| 98 std::string type_tag = ModelTypeToRootTag(type); | 88 std::string type_tag = ModelTypeToRootTag(type); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 return false; | 126 return false; |
| 137 } | 127 } |
| 138 } | 128 } |
| 139 // Push the successor. | 129 // Push the successor. |
| 140 to_visit.push(child.Get(NEXT_ID)); | 130 to_visit.push(child.Get(NEXT_ID)); |
| 141 } | 131 } |
| 142 return true; | 132 return true; |
| 143 } | 133 } |
| 144 | 134 |
| 145 } // namespace syncable | 135 } // namespace syncable |
| OLD | NEW |