| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 const sync_pb::EntitySpecifics& specifics) { | 74 const sync_pb::EntitySpecifics& specifics) { |
| 75 ModelType type = GetModelTypeFromSpecifics(specifics); | 75 ModelType type = GetModelTypeFromSpecifics(specifics); |
| 76 if (type == PASSWORDS || type == NIGORI) | 76 if (type == PASSWORDS || type == NIGORI) |
| 77 return false; // These types have their own encryption schemes. | 77 return false; // These types have their own encryption schemes. |
| 78 if (encrypted_types.count(type) == 0) | 78 if (encrypted_types.count(type) == 0) |
| 79 return false; // This type does not require encryption | 79 return false; // This type does not require encryption |
| 80 return !specifics.has_encrypted(); | 80 return !specifics.has_encrypted(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Mainly for testing. | 83 // Mainly for testing. |
| 84 bool VerifyDataTypeEncryption(BaseTransaction* const trans, | 84 bool VerifyDataTypeEncryptionForTest( |
| 85 browser_sync::Cryptographer* cryptographer, | 85 BaseTransaction* const trans, |
| 86 ModelType type, | 86 browser_sync::Cryptographer* cryptographer, |
| 87 bool is_encrypted) { | 87 ModelType type, |
| 88 bool is_encrypted) { |
| 88 if (type == PASSWORDS || type == NIGORI) { | 89 if (type == PASSWORDS || type == NIGORI) { |
| 89 NOTREACHED(); | 90 NOTREACHED(); |
| 90 return true; | 91 return true; |
| 91 } | 92 } |
| 92 std::string type_tag = ModelTypeToRootTag(type); | 93 std::string type_tag = ModelTypeToRootTag(type); |
| 93 Entry type_root(trans, GET_BY_SERVER_TAG, type_tag); | 94 Entry type_root(trans, GET_BY_SERVER_TAG, type_tag); |
| 94 if (!type_root.good()) { | 95 if (!type_root.good()) { |
| 95 NOTREACHED(); | 96 NOTREACHED(); |
| 96 return false; | 97 return false; |
| 97 } | 98 } |
| 98 | 99 |
| 99 std::queue<Id> to_visit; | 100 std::queue<Id> to_visit; |
| 100 Id id_string = | 101 Id id_string; |
| 101 trans->directory()->GetFirstChildId(trans, type_root.Get(ID)); | 102 if (!trans->directory()->GetFirstChildId( |
| 103 trans, type_root.Get(ID), &id_string)) { |
| 104 NOTREACHED(); |
| 105 return false; |
| 106 } |
| 102 to_visit.push(id_string); | 107 to_visit.push(id_string); |
| 103 while (!to_visit.empty()) { | 108 while (!to_visit.empty()) { |
| 104 id_string = to_visit.front(); | 109 id_string = to_visit.front(); |
| 105 to_visit.pop(); | 110 to_visit.pop(); |
| 106 if (id_string.IsRoot()) | 111 if (id_string.IsRoot()) |
| 107 continue; | 112 continue; |
| 108 | 113 |
| 109 Entry child(trans, GET_BY_ID, id_string); | 114 Entry child(trans, GET_BY_ID, id_string); |
| 110 if (!child.good()) { | 115 if (!child.good()) { |
| 111 NOTREACHED(); | 116 NOTREACHED(); |
| 112 return false; | 117 return false; |
| 113 } | 118 } |
| 114 if (child.Get(IS_DIR)) { | 119 if (child.Get(IS_DIR)) { |
| 120 Id child_id_string; |
| 121 if (!trans->directory()->GetFirstChildId( |
| 122 trans, child.Get(ID), &child_id_string)) { |
| 123 NOTREACHED(); |
| 124 return false; |
| 125 } |
| 115 // Traverse the children. | 126 // Traverse the children. |
| 116 to_visit.push( | 127 to_visit.push(child_id_string); |
| 117 trans->directory()->GetFirstChildId(trans, child.Get(ID))); | |
| 118 } | 128 } |
| 119 const sync_pb::EntitySpecifics& specifics = child.Get(SPECIFICS); | 129 const sync_pb::EntitySpecifics& specifics = child.Get(SPECIFICS); |
| 120 DCHECK_EQ(type, child.GetModelType()); | 130 DCHECK_EQ(type, child.GetModelType()); |
| 121 DCHECK_EQ(type, GetModelTypeFromSpecifics(specifics)); | 131 DCHECK_EQ(type, GetModelTypeFromSpecifics(specifics)); |
| 122 // We don't encrypt the server's permanent items. | 132 // We don't encrypt the server's permanent items. |
| 123 if (child.Get(UNIQUE_SERVER_TAG).empty()) { | 133 if (child.Get(UNIQUE_SERVER_TAG).empty()) { |
| 124 if (specifics.has_encrypted() != is_encrypted) | 134 if (specifics.has_encrypted() != is_encrypted) |
| 125 return false; | 135 return false; |
| 126 if (specifics.has_encrypted()) { | 136 if (specifics.has_encrypted()) { |
| 127 if (child.Get(NON_UNIQUE_NAME) != kEncryptedString) | 137 if (child.Get(NON_UNIQUE_NAME) != kEncryptedString) |
| 128 return false; | 138 return false; |
| 129 if (!cryptographer->CanDecryptUsingDefaultKey(specifics.encrypted())) | 139 if (!cryptographer->CanDecryptUsingDefaultKey(specifics.encrypted())) |
| 130 return false; | 140 return false; |
| 131 } | 141 } |
| 132 } | 142 } |
| 133 // Push the successor. | 143 // Push the successor. |
| 134 to_visit.push(child.Get(NEXT_ID)); | 144 to_visit.push(child.Get(NEXT_ID)); |
| 135 } | 145 } |
| 136 return true; | 146 return true; |
| 137 } | 147 } |
| 138 | 148 |
| 139 } // namespace syncable | 149 } // namespace syncable |
| OLD | NEW |