 Chromium Code Reviews
 Chromium Code Reviews Issue 6910012:
  Add method IsPassphraseRequiredForDecryption to ProfileSyncService  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 6910012:
  Add method IsPassphraseRequiredForDecryption to ProfileSyncService  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| 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/profile_sync_service.h" | 5 #include "chrome/browser/sync/profile_sync_service.h" | 
| 6 | 6 | 
| 7 #include <stddef.h> | 7 #include <stddef.h> | 
| 8 #include <map> | 8 #include <map> | 
| 9 #include <ostream> | 9 #include <ostream> | 
| 10 #include <set> | 10 #include <set> | 
| (...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 SetPassphrase(cached_passphrase_.value, | 609 SetPassphrase(cached_passphrase_.value, | 
| 610 cached_passphrase_.is_explicit, | 610 cached_passphrase_.is_explicit, | 
| 611 cached_passphrase_.is_creation); | 611 cached_passphrase_.is_creation); | 
| 612 cached_passphrase_ = CachedPassphrase(); | 612 cached_passphrase_ = CachedPassphrase(); | 
| 613 return; | 613 return; | 
| 614 } | 614 } | 
| 615 | 615 | 
| 616 // We will skip the passphrase prompt and suppress the warning if the | 616 // We will skip the passphrase prompt and suppress the warning if the | 
| 617 // passphrase is needed for decryption but the user is not syncing an | 617 // passphrase is needed for decryption but the user is not syncing an | 
| 618 // encrypted data type on this machine. Otherwise we prompt. | 618 // encrypted data type on this machine. Otherwise we prompt. | 
| 619 if (!IsEncryptedDatatypeEnabled() && | 619 if (!IsEncryptedDatatypeEnabled() && IsPassphraseRequiredForDecryption()) { | 
| 620 (reason == sync_api::REASON_DECRYPTION || | |
| 621 reason == sync_api::REASON_SET_PASSPHRASE_FAILED)) { | |
| 622 OnPassphraseAccepted(); | 620 OnPassphraseAccepted(); | 
| 623 return; | 621 return; | 
| 624 } | 622 } | 
| 625 | 623 | 
| 626 if (WizardIsVisible() && | 624 if (WizardIsVisible() && IsPassphraseRequiredForDecryption()) { | 
| 627 (reason == sync_api::REASON_DECRYPTION || | |
| 628 reason == sync_api::REASON_SET_PASSPHRASE_FAILED)) { | |
| 629 wizard_.Step(SyncSetupWizard::ENTER_PASSPHRASE); | 625 wizard_.Step(SyncSetupWizard::ENTER_PASSPHRASE); | 
| 630 } | 626 } | 
| 631 | 627 | 
| 632 NotifyObservers(); | 628 NotifyObservers(); | 
| 633 } | 629 } | 
| 634 | 630 | 
| 635 void ProfileSyncService::OnPassphraseAccepted() { | 631 void ProfileSyncService::OnPassphraseAccepted() { | 
| 636 // Make sure the data types that depend on the passphrase are started at | 632 // Make sure the data types that depend on the passphrase are started at | 
| 637 // this time. | 633 // this time. | 
| 638 syncable::ModelTypeSet types; | 634 syncable::ModelTypeSet types; | 
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 base::TimeTicks::Now() - auth_error_time_); | 678 base::TimeTicks::Now() - auth_error_time_); | 
| 683 auth_error_time_ = base::TimeTicks(); // Reset auth_error_time_ to null. | 679 auth_error_time_ = base::TimeTicks(); // Reset auth_error_time_ to null. | 
| 684 } | 680 } | 
| 685 | 681 | 
| 686 wizard_.Step(SyncSetupWizard::GAIA_LOGIN); | 682 wizard_.Step(SyncSetupWizard::GAIA_LOGIN); | 
| 687 | 683 | 
| 688 NotifyObservers(); | 684 NotifyObservers(); | 
| 689 } | 685 } | 
| 690 | 686 | 
| 691 void ProfileSyncService::ShowErrorUI(gfx::NativeWindow parent_window) { | 687 void ProfileSyncService::ShowErrorUI(gfx::NativeWindow parent_window) { | 
| 692 if (ObservedPassphraseRequired()) { | 688 if (IsPassphraseRequired()) { | 
| 693 if (IsUsingSecondaryPassphrase()) | 689 if (IsUsingSecondaryPassphrase()) | 
| 694 PromptForExistingPassphrase(parent_window); | 690 PromptForExistingPassphrase(parent_window); | 
| 695 else | 691 else | 
| 696 SigninForPassphraseMigration(parent_window); | 692 SigninForPassphraseMigration(parent_window); | 
| 697 return; | 693 return; | 
| 698 } | 694 } | 
| 699 const GoogleServiceAuthError& error = GetAuthError(); | 695 const GoogleServiceAuthError& error = GetAuthError(); | 
| 700 if (error.state() == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || | 696 if (error.state() == GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || | 
| 701 error.state() == GoogleServiceAuthError::CAPTCHA_REQUIRED || | 697 error.state() == GoogleServiceAuthError::CAPTCHA_REQUIRED || | 
| 702 error.state() == GoogleServiceAuthError::ACCOUNT_DELETED || | 698 error.state() == GoogleServiceAuthError::ACCOUNT_DELETED || | 
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 938 for (DataTypeController::TypeMap::const_iterator it = | 934 for (DataTypeController::TypeMap::const_iterator it = | 
| 939 data_type_controllers_.begin(); | 935 data_type_controllers_.begin(); | 
| 940 it != data_type_controllers_.end(); ++it) { | 936 it != data_type_controllers_.end(); ++it) { | 
| 941 registered_types->insert((*it).first); | 937 registered_types->insert((*it).first); | 
| 942 } | 938 } | 
| 943 } | 939 } | 
| 944 | 940 | 
| 945 bool ProfileSyncService::IsUsingSecondaryPassphrase() const { | 941 bool ProfileSyncService::IsUsingSecondaryPassphrase() const { | 
| 946 return backend_.get() && (backend_->IsUsingExplicitPassphrase() || | 942 return backend_.get() && (backend_->IsUsingExplicitPassphrase() || | 
| 947 (tried_implicit_gaia_remove_when_bug_62103_fixed_ && | 943 (tried_implicit_gaia_remove_when_bug_62103_fixed_ && | 
| 948 ObservedPassphraseRequired())); | 944 IsPassphraseRequired())); | 
| 949 } | 945 } | 
| 950 | 946 | 
| 951 bool ProfileSyncService::IsCryptographerReady( | 947 bool ProfileSyncService::IsCryptographerReady( | 
| 952 const sync_api::BaseTransaction* trans) const { | 948 const sync_api::BaseTransaction* trans) const { | 
| 953 return backend_.get() && backend_->IsCryptographerReady(trans); | 949 return backend_.get() && backend_->IsCryptographerReady(trans); | 
| 954 } | 950 } | 
| 955 | 951 | 
| 956 SyncBackendHost* ProfileSyncService::GetBackendForTest() { | 952 SyncBackendHost* ProfileSyncService::GetBackendForTest() { | 
| 957 // We don't check |backend_initialized_|; we assume the test class | 953 // We don't check |backend_initialized_|; we assume the test class | 
| 958 // knows what it's doing. | 954 // knows what it's doing. | 
| (...skipping 20 matching lines...) Expand all Loading... | |
| 979 syncable::ModelTypeSet types; | 975 syncable::ModelTypeSet types; | 
| 980 GetPreferredDataTypes(&types); | 976 GetPreferredDataTypes(&types); | 
| 981 // We set this special case here since it's the only datatype whose encryption | 977 // We set this special case here since it's the only datatype whose encryption | 
| 982 // status we already know. All others are set after the initial sync | 978 // status we already know. All others are set after the initial sync | 
| 983 // completes (for now). | 979 // completes (for now). | 
| 984 // TODO(zea): Implement a better way that uses preferences for which types | 980 // TODO(zea): Implement a better way that uses preferences for which types | 
| 985 // need encryption. | 981 // need encryption. | 
| 986 encrypted_types_.clear(); | 982 encrypted_types_.clear(); | 
| 987 if (types.count(syncable::PASSWORDS) > 0) | 983 if (types.count(syncable::PASSWORDS) > 0) | 
| 988 encrypted_types_.insert(syncable::PASSWORDS); | 984 encrypted_types_.insert(syncable::PASSWORDS); | 
| 989 if (passphrase_required_reason_ == sync_api::REASON_DECRYPTION || | 985 if (IsPassphraseRequiredForDecryption()) { | 
| 990 passphrase_required_reason_ == sync_api::REASON_SET_PASSPHRASE_FAILED) { | |
| 991 if (IsEncryptedDatatypeEnabled()) { | 986 if (IsEncryptedDatatypeEnabled()) { | 
| 992 // We need a passphrase still. Prompt the user for a passphrase, and | 987 // We need a passphrase still. Prompt the user for a passphrase, and | 
| 993 // DataTypeManager::Configure() will get called once the passphrase is | 988 // DataTypeManager::Configure() will get called once the passphrase is | 
| 994 // accepted. | 989 // accepted. | 
| 995 OnPassphraseRequired(passphrase_required_reason_); | 990 OnPassphraseRequired(passphrase_required_reason_); | 
| 996 return; | 991 return; | 
| 997 } else { | 992 } else { | 
| 998 // We've been informed that a passphrase is required for decryption, but | 993 // We've been informed that a passphrase is required for decryption, but | 
| 999 // now there are no encrypted data types enabled, so change the value of | 994 // now there are no encrypted data types enabled, so change the value of | 
| 1000 // passphrase_required_reason_ to its default value. (NotifyObservers() | 995 // passphrase_required_reason_ to its default value. (NotifyObservers() | 
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1098 DataTypeController* data_type_controller, | 1093 DataTypeController* data_type_controller, | 
| 1099 ChangeProcessor* change_processor) { | 1094 ChangeProcessor* change_processor) { | 
| 1100 change_processor->Stop(); | 1095 change_processor->Stop(); | 
| 1101 if (backend_.get()) | 1096 if (backend_.get()) | 
| 1102 backend_->DeactivateDataType(data_type_controller, change_processor); | 1097 backend_->DeactivateDataType(data_type_controller, change_processor); | 
| 1103 } | 1098 } | 
| 1104 | 1099 | 
| 1105 void ProfileSyncService::SetPassphrase(const std::string& passphrase, | 1100 void ProfileSyncService::SetPassphrase(const std::string& passphrase, | 
| 1106 bool is_explicit, | 1101 bool is_explicit, | 
| 1107 bool is_creation) { | 1102 bool is_creation) { | 
| 1108 if (ShouldPushChanges() || ObservedPassphraseRequired()) { | 1103 if (ShouldPushChanges() || IsPassphraseRequired()) { | 
| 1109 backend_->SetPassphrase(passphrase, is_explicit); | 1104 backend_->SetPassphrase(passphrase, is_explicit); | 
| 1110 } else { | 1105 } else { | 
| 1111 cached_passphrase_.value = passphrase; | 1106 cached_passphrase_.value = passphrase; | 
| 1112 cached_passphrase_.is_explicit = is_explicit; | 1107 cached_passphrase_.is_explicit = is_explicit; | 
| 1113 cached_passphrase_.is_creation = is_creation; | 1108 cached_passphrase_.is_creation = is_creation; | 
| 1114 } | 1109 } | 
| 1115 } | 1110 } | 
| 1116 | 1111 | 
| 1117 void ProfileSyncService::EncryptDataTypes( | 1112 void ProfileSyncService::EncryptDataTypes( | 
| 1118 const syncable::ModelTypeSet& encrypted_types) { | 1113 const syncable::ModelTypeSet& encrypted_types) { | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1153 | 1148 | 
| 1154 if (!cached_passphrase_.value.empty()) { | 1149 if (!cached_passphrase_.value.empty()) { | 
| 1155 // Don't hold on to the passphrase in raw form longer than needed. | 1150 // Don't hold on to the passphrase in raw form longer than needed. | 
| 1156 SetPassphrase(cached_passphrase_.value, | 1151 SetPassphrase(cached_passphrase_.value, | 
| 1157 cached_passphrase_.is_explicit, | 1152 cached_passphrase_.is_explicit, | 
| 1158 cached_passphrase_.is_creation); | 1153 cached_passphrase_.is_creation); | 
| 1159 cached_passphrase_ = CachedPassphrase(); | 1154 cached_passphrase_ = CachedPassphrase(); | 
| 1160 } | 1155 } | 
| 1161 | 1156 | 
| 1162 // We should never get in a state where we have no encrypted datatypes | 1157 // We should never get in a state where we have no encrypted datatypes | 
| 1163 // enabled, and yet we still think we require a passphrase. | 1158 // enabled, and yet we still think we require a passphrase for decryption. | 
| 1164 DCHECK(passphrase_required_reason_ == | 1159 DCHECK(!(IsPassphraseRequiredForDecryption() && | 
| 1165 sync_api::REASON_PASSPHRASE_NOT_REQUIRED || | 1160 !IsEncryptedDatatypeEnabled())); | 
| 1166 passphrase_required_reason_ == sync_api::REASON_ENCRYPTION || | |
| 1167 IsEncryptedDatatypeEnabled()); | |
| 1168 | 1161 | 
| 1169 // TODO(sync): Less wizard, more toast. | 1162 // TODO(sync): Less wizard, more toast. | 
| 1170 wizard_.Step(SyncSetupWizard::DONE); | 1163 wizard_.Step(SyncSetupWizard::DONE); | 
| 1171 NotifyObservers(); | 1164 NotifyObservers(); | 
| 1172 | 1165 | 
| 1173 // In the old world, this would be a no-op. With new syncer thread, | 1166 // In the old world, this would be a no-op. With new syncer thread, | 
| 1174 // this is the point where it is safe to switch from config-mode to | 1167 // this is the point where it is safe to switch from config-mode to | 
| 1175 // normal operation. | 1168 // normal operation. | 
| 1176 backend_->StartSyncingWithServer(); | 1169 backend_->StartSyncingWithServer(); | 
| 1177 break; | 1170 break; | 
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1203 // request and shouldn't override an explicit one. Thus, we either | 1196 // request and shouldn't override an explicit one. Thus, we either | 
| 1204 // update the implicit passphrase (idempotent if the passphrase didn't | 1197 // update the implicit passphrase (idempotent if the passphrase didn't | 
| 1205 // actually change), or the user has an explicit passphrase set so this | 1198 // actually change), or the user has an explicit passphrase set so this | 
| 1206 // becomes a no-op. | 1199 // becomes a no-op. | 
| 1207 tried_implicit_gaia_remove_when_bug_62103_fixed_ = true; | 1200 tried_implicit_gaia_remove_when_bug_62103_fixed_ = true; | 
| 1208 SetPassphrase(successful->password, false, true); | 1201 SetPassphrase(successful->password, false, true); | 
| 1209 | 1202 | 
| 1210 // If this signin was to initiate a passphrase migration (on the | 1203 // If this signin was to initiate a passphrase migration (on the | 
| 1211 // first computer, thus not for decryption), continue the migration. | 1204 // first computer, thus not for decryption), continue the migration. | 
| 1212 if (passphrase_migration_in_progress_ && | 1205 if (passphrase_migration_in_progress_ && | 
| 1213 passphrase_required_reason_ != sync_api::REASON_DECRYPTION && | 1206 IsPassphraseRequiredForEncryption()) { | 
| 
Raghu Simha
2011/05/02 23:47:23
Tim: This line requires special attention. With th
 
tim (not reviewing)
2011/05/03 00:06:59
The previous logic seems to also include NOT_REQUI
 
Raghu Simha
2011/05/03 00:24:00
I was talking about the previous previous logic in
 | |
| 1214 passphrase_required_reason_ != | |
| 1215 sync_api::REASON_SET_PASSPHRASE_FAILED) { | |
| 1216 wizard_.Step(SyncSetupWizard::PASSPHRASE_MIGRATION); | 1207 wizard_.Step(SyncSetupWizard::PASSPHRASE_MIGRATION); | 
| 1217 passphrase_migration_in_progress_ = false; | 1208 passphrase_migration_in_progress_ = false; | 
| 1218 } | 1209 } | 
| 1219 | 1210 | 
| 1220 break; | 1211 break; | 
| 1221 } | 1212 } | 
| 1222 case NotificationType::GOOGLE_SIGNIN_FAILED: { | 1213 case NotificationType::GOOGLE_SIGNIN_FAILED: { | 
| 1223 GoogleServiceAuthError error = | 1214 GoogleServiceAuthError error = | 
| 1224 *(Details<const GoogleServiceAuthError>(details).ptr()); | 1215 *(Details<const GoogleServiceAuthError>(details).ptr()); | 
| 1225 UpdateAuthErrorState(error); | 1216 UpdateAuthErrorState(error); | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1289 // is initialized, all enabled data types are consistent with one | 1280 // is initialized, all enabled data types are consistent with one | 
| 1290 // another, and no unrecoverable error has transpired. | 1281 // another, and no unrecoverable error has transpired. | 
| 1291 if (unrecoverable_error_detected_) | 1282 if (unrecoverable_error_detected_) | 
| 1292 return false; | 1283 return false; | 
| 1293 | 1284 | 
| 1294 if (!data_type_manager_.get()) | 1285 if (!data_type_manager_.get()) | 
| 1295 return false; | 1286 return false; | 
| 1296 | 1287 | 
| 1297 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 1288 return data_type_manager_->state() == DataTypeManager::CONFIGURED; | 
| 1298 } | 1289 } | 
| OLD | NEW |