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

Side by Side Diff: chrome/browser/sync/sync_setup_flow.cc

Issue 7551024: [Sync] Fix encryption/passphrase handling. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase + fix allstatus 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
« no previous file with comments | « chrome/browser/sync/profile_sync_service_harness.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/sync_setup_flow.h" 5 #include "chrome/browser/sync/sync_setup_flow.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 args->SetBoolean("syncApps", 168 args->SetBoolean("syncApps",
169 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncApps)); 169 service->profile()->GetPrefs()->GetBoolean(prefs::kSyncApps));
170 args->SetBoolean("encryptionEnabled", 170 args->SetBoolean("encryptionEnabled",
171 !CommandLine::ForCurrentProcess()->HasSwitch( 171 !CommandLine::ForCurrentProcess()->HasSwitch(
172 switches::kDisableSyncEncryption)); 172 switches::kDisableSyncEncryption));
173 173
174 syncable::ModelTypeSet encrypted_types; 174 syncable::ModelTypeSet encrypted_types;
175 service->GetEncryptedDataTypes(&encrypted_types); 175 service->GetEncryptedDataTypes(&encrypted_types);
176 bool encrypt_all = 176 bool encrypt_all =
177 encrypted_types.upper_bound(syncable::PASSWORDS) != encrypted_types.end(); 177 encrypted_types.upper_bound(syncable::PASSWORDS) != encrypted_types.end();
178 if (service->HasPendingEncryptedTypes())
179 encrypt_all = true;
178 args->SetBoolean("encryptAllData", encrypt_all); 180 args->SetBoolean("encryptAllData", encrypt_all);
179 181
180 // Load the parameters for the encryption tab. 182 // Load the parameters for the encryption tab.
181 args->SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase()); 183 args->SetBoolean("usePassphrase", service->IsUsingSecondaryPassphrase());
182 } 184 }
183 185
184 bool SyncSetupFlow::AttachSyncSetupHandler(SyncSetupFlowHandler* handler) { 186 bool SyncSetupFlow::AttachSyncSetupHandler(SyncSetupFlowHandler* handler) {
185 if (flow_handler_) 187 if (flow_handler_)
186 return false; 188 return false;
187 189
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 const std::string& password, 262 const std::string& password,
261 const std::string& captcha, 263 const std::string& captcha,
262 const std::string& access_code) { 264 const std::string& access_code) {
263 service_->OnUserSubmittedAuth(username, password, captcha, access_code); 265 service_->OnUserSubmittedAuth(username, password, captcha, access_code);
264 } 266 }
265 267
266 void SyncSetupFlow::OnUserConfigured(const SyncConfiguration& configuration) { 268 void SyncSetupFlow::OnUserConfigured(const SyncConfiguration& configuration) {
267 // Go to the "loading..." screen. 269 // Go to the "loading..." screen.
268 Advance(SyncSetupWizard::SETTING_UP); 270 Advance(SyncSetupWizard::SETTING_UP);
269 271
272 // Note: encryption will not occur until OnUserChoseDatatypes is called.
273 syncable::ModelTypeSet encrypted_types;
270 if (configuration.encrypt_all) { 274 if (configuration.encrypt_all) {
271 syncable::ModelTypeSet data_types; 275 // Encrypt all registered types.
272 service_->GetRegisteredDataTypes(&data_types); 276 service_->GetRegisteredDataTypes(&encrypted_types);
273 service_->EncryptDataTypes(data_types); 277 } // Else we clear the pending types for encryption.
274 } 278 service_->set_pending_types_for_encryption(encrypted_types);
275
276 // If we are activating the passphrase, we need to have one supplied.
277 DCHECK(service_->IsUsingSecondaryPassphrase() ||
278 !configuration.use_secondary_passphrase ||
279 configuration.secondary_passphrase.length() > 0);
280 279
281 if (!configuration.gaia_passphrase.empty()) { 280 if (!configuration.gaia_passphrase.empty()) {
282 // Caller passed a gaia passphrase. This is illegal if we are currently 281 // Caller passed a gaia passphrase. This is illegal if we are currently
283 // using a secondary passphrase. 282 // using a secondary passphrase.
284 DCHECK(!service_->IsUsingSecondaryPassphrase()); 283 DCHECK(!service_->IsUsingSecondaryPassphrase());
285 service_->SetPassphrase(configuration.gaia_passphrase, false, false); 284 service_->SetPassphrase(configuration.gaia_passphrase, false, false);
286 } 285 }
287 286
287 // It's possible the user has to provide a secondary passphrase even when
288 // they have not set one previously. This occurs when the user has changed
289 // their gaia password and then sign in to a new machine for the first time.
290 // The new machine will download data encrypted with their old gaia password,
291 // which their current gaia password will not be able to decrypt, triggering
292 // a prompt for a passphrase. At this point, the user must enter their old
293 // password, which we store as a new secondary passphrase.
294 // TODO(zea): eventually use the above gaia_passphrase instead of the
295 // secondary passphrase in this case.
288 if (configuration.use_secondary_passphrase) { 296 if (configuration.use_secondary_passphrase) {
289 if (!service_->IsUsingSecondaryPassphrase()) { 297 if (!service_->IsUsingSecondaryPassphrase()) {
290 service_->SetPassphrase(configuration.secondary_passphrase, true, true); 298 service_->SetPassphrase(configuration.secondary_passphrase, true, true);
291 tried_creating_explicit_passphrase_ = true; 299 tried_creating_explicit_passphrase_ = true;
292 } else { 300 } else {
293 service_->SetPassphrase(configuration.secondary_passphrase, true, false); 301 service_->SetPassphrase(configuration.secondary_passphrase, true, false);
294 tried_setting_explicit_passphrase_ = true; 302 tried_setting_explicit_passphrase_ = true;
295 } 303 }
296 } 304 }
297 305
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 break; 447 break;
440 } 448 }
441 case SyncSetupWizard::DONE: 449 case SyncSetupWizard::DONE:
442 flow_handler_->ShowSetupDone( 450 flow_handler_->ShowSetupDone(
443 UTF16ToWide(service_->GetAuthenticatedUsername())); 451 UTF16ToWide(service_->GetAuthenticatedUsername()));
444 break; 452 break;
445 default: 453 default:
446 NOTREACHED() << "Invalid advance state: " << state; 454 NOTREACHED() << "Invalid advance state: " << state;
447 } 455 }
448 } 456 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_harness.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698