Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: chrome/browser/sync/engine/syncapi.cc

Issue 7551024: [Sync] Fix encryption/passphrase handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/syncapi.h" 5 #include "chrome/browser/sync/engine/syncapi.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <bitset> 8 #include <bitset>
9 #include <iomanip> 9 #include <iomanip>
10 #include <list> 10 #include <list>
(...skipping 2086 matching lines...) Expand 10 before | Expand all | Expand 10 after
2097 WriteNode node(&trans); 2097 WriteNode node(&trans);
2098 if (!node.InitByTagLookup(kNigoriTag)) { 2098 if (!node.InitByTagLookup(kNigoriTag)) {
2099 NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not " 2099 NOTREACHED() << "Unable to set encrypted datatypes because Nigori node not "
2100 << "found."; 2100 << "found.";
2101 return; 2101 return;
2102 } 2102 }
2103 2103
2104 Cryptographer* cryptographer = trans.GetCryptographer(); 2104 Cryptographer* cryptographer = trans.GetCryptographer();
2105 2105
2106 if (!cryptographer->is_initialized()) { 2106 if (!cryptographer->is_initialized()) {
2107 NOTREACHED() << "Attempting to encrypt datatypes when cryptographer not " 2107 VLOG(1) << "Attempting to encrypt datatypes when cryptographer not "
2108 << "initialized."; 2108 << "initialized, prompting for passphrase.";
2109 ObserverList<SyncManager::Observer> temp_obs_list;
2110 CopyObservers(&temp_obs_list);
2111 // TODO(zea): this isn't really decryption, but that's the only way we have
2112 // to prompt the user for a passsphrase. See http://crbug.com/91379.
2113 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list,
2114 OnPassphraseRequired(sync_api::REASON_DECRYPTION));
2109 return; 2115 return;
2110 } 2116 }
2111 2117
2112 // Update the Nigori node set of encrypted datatypes so other machines notice. 2118 // Update the Nigori node's set of encrypted datatypes.
2113 // Note, we merge the current encrypted types with those requested. Once a 2119 // Note, we merge the current encrypted types with those requested. Once a
2114 // datatypes is marked as needing encryption, it is never unmarked. 2120 // datatypes is marked as needing encryption, it is never unmarked.
2115 sync_pb::NigoriSpecifics nigori; 2121 sync_pb::NigoriSpecifics nigori;
2116 nigori.CopyFrom(node.GetNigoriSpecifics()); 2122 nigori.CopyFrom(node.GetNigoriSpecifics());
2117 syncable::ModelTypeSet current_encrypted_types = GetEncryptedTypes(&trans); 2123 syncable::ModelTypeSet current_encrypted_types = GetEncryptedTypes(&trans);
2118 syncable::ModelTypeSet newly_encrypted_types; 2124 syncable::ModelTypeSet newly_encrypted_types;
2119 std::set_union(current_encrypted_types.begin(), current_encrypted_types.end(), 2125 std::set_union(current_encrypted_types.begin(), current_encrypted_types.end(),
2120 encrypted_types.begin(), encrypted_types.end(), 2126 encrypted_types.begin(), encrypted_types.end(),
2121 std::inserter(newly_encrypted_types, 2127 std::inserter(newly_encrypted_types,
2122 newly_encrypted_types.begin())); 2128 newly_encrypted_types.begin()));
2123 if (newly_encrypted_types == current_encrypted_types) 2129 if (newly_encrypted_types == current_encrypted_types) {
2124 return; // Set of encrypted types did not change. 2130 // Set of encrypted types has not changed, just notify and return.
2131 ObserverList<SyncManager::Observer> temp_obs_list;
2132 CopyObservers(&temp_obs_list);
2133 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list,
2134 OnEncryptionComplete(current_encrypted_types));
2135 return;
2136 }
2125 syncable::FillNigoriEncryptedTypes(newly_encrypted_types, &nigori); 2137 syncable::FillNigoriEncryptedTypes(newly_encrypted_types, &nigori);
2126 node.SetNigoriSpecifics(nigori); 2138 node.SetNigoriSpecifics(nigori);
2127 2139
2128 cryptographer->SetEncryptedTypes(nigori); 2140 cryptographer->SetEncryptedTypes(nigori);
2129 2141
2130 // TODO(zea): only reencrypt this datatype? ReEncrypting everything is a 2142 // TODO(zea): only reencrypt this datatype? ReEncrypting everything is a
2131 // safer approach, and should not impact anything that is already encrypted 2143 // safer approach, and should not impact anything that is already encrypted
2132 // (redundant changes are ignored). 2144 // (redundant changes are ignored).
2133 ReEncryptEverything(&trans); 2145 ReEncryptEverything(&trans);
2134 return; 2146 return;
(...skipping 24 matching lines...) Expand all
2159 to_visit.push(child_id); 2171 to_visit.push(child_id);
2160 while (!to_visit.empty()) { 2172 while (!to_visit.empty()) {
2161 child_id = to_visit.front(); 2173 child_id = to_visit.front();
2162 to_visit.pop(); 2174 to_visit.pop();
2163 if (child_id == kInvalidId) 2175 if (child_id == kInvalidId)
2164 continue; 2176 continue;
2165 2177
2166 WriteNode child(trans); 2178 WriteNode child(trans);
2167 if (!child.InitByIdLookup(child_id)) { 2179 if (!child.InitByIdLookup(child_id)) {
2168 NOTREACHED(); 2180 NOTREACHED();
2169 return; 2181 continue;
2170 } 2182 }
2171 if (child.GetIsFolder()) { 2183 if (child.GetIsFolder()) {
2172 to_visit.push(child.GetFirstChildId()); 2184 to_visit.push(child.GetFirstChildId());
2173 } 2185 }
2174 if (child.GetEntry()->Get(syncable::UNIQUE_SERVER_TAG).empty()) { 2186 if (child.GetEntry()->Get(syncable::UNIQUE_SERVER_TAG).empty()) {
2175 // Rewrite the specifics of the node with encrypted data if necessary 2187 // Rewrite the specifics of the node with encrypted data if necessary
2176 // (only rewrite the non-unique folders). 2188 // (only rewrite the non-unique folders).
2177 child.ResetFromSpecifics(); 2189 child.ResetFromSpecifics();
2178 } 2190 }
2179 to_visit.push(child.GetSuccessorId()); 2191 to_visit.push(child.GetSuccessorId());
2180 } 2192 }
2181 } 2193 }
2182 2194
2183 if (routes.count(syncable::PASSWORDS) > 0) { 2195 if (routes.count(syncable::PASSWORDS) > 0) {
2184 // Passwords are encrypted with their own legacy scheme. 2196 // Passwords are encrypted with their own legacy scheme.
2185 ReadNode passwords_root(trans); 2197 ReadNode passwords_root(trans);
2186 std::string passwords_tag = 2198 std::string passwords_tag =
2187 syncable::ModelTypeToRootTag(syncable::PASSWORDS); 2199 syncable::ModelTypeToRootTag(syncable::PASSWORDS);
2188 if (!passwords_root.InitByTagLookup(passwords_tag)) { 2200 // It's possible we'll have the password routing info and not the password
2189 LOG(WARNING) << "No passwords to reencrypt."; 2201 // root if we attempted to SetPassphrase before passwords was enabled.
2190 return; 2202 if (passwords_root.InitByTagLookup(passwords_tag)) {
2191 } 2203 int64 child_id = passwords_root.GetFirstChildId();
2192 2204 while (child_id != kInvalidId) {
2193 int64 child_id = passwords_root.GetFirstChildId(); 2205 WriteNode child(trans);
2194 while (child_id != kInvalidId) { 2206 if (!child.InitByIdLookup(child_id)) {
2195 WriteNode child(trans); 2207 NOTREACHED();
2196 if (!child.InitByIdLookup(child_id)) { 2208 return;
2197 NOTREACHED(); 2209 }
2198 return; 2210 child.SetPasswordSpecifics(child.GetPasswordSpecifics());
2211 child_id = child.GetSuccessorId();
2199 } 2212 }
2200 child.SetPasswordSpecifics(child.GetPasswordSpecifics());
2201 child_id = child.GetSuccessorId();
2202 } 2213 }
2203 } 2214 }
2204 2215
2205 ObserverList<SyncManager::Observer> temp_obs_list; 2216 ObserverList<SyncManager::Observer> temp_obs_list;
2206 CopyObservers(&temp_obs_list); 2217 CopyObservers(&temp_obs_list);
2207 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list, 2218 FOR_EACH_OBSERVER(SyncManager::Observer, temp_obs_list,
2208 OnEncryptionComplete(encrypted_types)); 2219 OnEncryptionComplete(encrypted_types));
2209 } 2220 }
2210 2221
2211 SyncManager::~SyncManager() { 2222 SyncManager::~SyncManager() {
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
3074 void SyncManager::TriggerOnIncomingNotificationForTest( 3085 void SyncManager::TriggerOnIncomingNotificationForTest(
3075 const syncable::ModelTypeBitSet& model_types) { 3086 const syncable::ModelTypeBitSet& model_types) {
3076 syncable::ModelTypePayloadMap model_types_with_payloads = 3087 syncable::ModelTypePayloadMap model_types_with_payloads =
3077 syncable::ModelTypePayloadMapFromBitSet(model_types, 3088 syncable::ModelTypePayloadMapFromBitSet(model_types,
3078 std::string()); 3089 std::string());
3079 3090
3080 data_->OnIncomingNotification(model_types_with_payloads); 3091 data_->OnIncomingNotification(model_types_with_payloads);
3081 } 3092 }
3082 3093
3083 } // namespace sync_api 3094 } // namespace sync_api
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/sync/profile_sync_service.h » ('j') | chrome/browser/sync/profile_sync_service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698