Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/signin/easy_unlock_service_regular.h" | 5 #include "chrome/browser/signin/easy_unlock_service_regular.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/prefs/scoped_user_pref_update.h" | 11 #include "base/prefs/scoped_user_pref_update.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/signin/easy_unlock_toggle_flow.h" | 15 #include "chrome/browser/signin/easy_unlock_toggle_flow.h" |
| 16 #include "chrome/browser/signin/screenlock_bridge.h" | 16 #include "chrome/browser/signin/screenlock_bridge.h" |
| 17 #include "chrome/browser/ui/extensions/application_launch.h" | 17 #include "chrome/browser/ui/extensions/application_launch.h" |
| 18 #include "chrome/common/extensions/extension_constants.h" | 18 #include "chrome/common/extensions/extension_constants.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "components/pref_registry/pref_registry_syncable.h" | 20 #include "components/pref_registry/pref_registry_syncable.h" |
| 21 #include "content/public/browser/browser_thread.h" | |
| 21 #include "extensions/browser/extension_system.h" | 22 #include "extensions/browser/extension_system.h" |
| 22 | 23 |
| 23 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
| 25 #include "apps/app_lifetime_monitor_factory.h" | |
| 26 #include "base/thread_task_runner_handle.h" | |
| 27 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" | |
| 28 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_reauth.h" | |
| 29 #include "chrome/browser/chromeos/login/session/user_session_manager.h" | |
| 24 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 30 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 25 #include "components/user_manager/user_manager.h" | 31 #include "components/user_manager/user_manager.h" |
| 26 #endif | 32 #endif |
| 27 | 33 |
| 28 namespace { | 34 namespace { |
| 29 | 35 |
| 30 // Key name of the local device permit record dictonary in kEasyUnlockPairing. | 36 // Key name of the local device permit record dictonary in kEasyUnlockPairing. |
| 31 const char kKeyPermitAccess[] = "permitAccess"; | 37 const char kKeyPermitAccess[] = "permitAccess"; |
| 32 | 38 |
| 33 // Key name of the remote device list in kEasyUnlockPairing. | 39 // Key name of the remote device list in kEasyUnlockPairing. |
| 34 const char kKeyDevices[] = "devices"; | 40 const char kKeyDevices[] = "devices"; |
| 35 | 41 |
| 36 // Key name of the phone public key in a device dictionary. | 42 // Key name of the phone public key in a device dictionary. |
| 37 const char kKeyPhoneId[] = "permitRecord.id"; | 43 const char kKeyPhoneId[] = "permitRecord.id"; |
| 38 | 44 |
| 39 } // namespace | 45 } // namespace |
| 40 | 46 |
| 41 EasyUnlockServiceRegular::EasyUnlockServiceRegular(Profile* profile) | 47 EasyUnlockServiceRegular::EasyUnlockServiceRegular(Profile* profile) |
| 42 : EasyUnlockService(profile), | 48 : EasyUnlockService(profile), |
| 43 turn_off_flow_status_(EasyUnlockService::IDLE) { | 49 turn_off_flow_status_(EasyUnlockService::IDLE), |
| 50 weak_ptr_factory_(this) { | |
| 44 } | 51 } |
| 45 | 52 |
| 46 EasyUnlockServiceRegular::~EasyUnlockServiceRegular() { | 53 EasyUnlockServiceRegular::~EasyUnlockServiceRegular() { |
| 47 } | 54 } |
| 48 | 55 |
| 49 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const { | 56 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const { |
| 50 return EasyUnlockService::TYPE_REGULAR; | 57 return EasyUnlockService::TYPE_REGULAR; |
| 51 } | 58 } |
| 52 | 59 |
| 53 std::string EasyUnlockServiceRegular::GetUserEmail() const { | 60 std::string EasyUnlockServiceRegular::GetUserEmail() const { |
| 54 return ScreenlockBridge::GetAuthenticatedUserEmail(profile()); | 61 return ScreenlockBridge::GetAuthenticatedUserEmail(profile()); |
| 55 } | 62 } |
| 56 | 63 |
| 57 void EasyUnlockServiceRegular::LaunchSetup() { | 64 void EasyUnlockServiceRegular::LaunchSetup() { |
| 65 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 66 #if defined(OS_CHROMEOS) | |
| 67 // Force the user to reauthenticate by showing a modal overlay (similar to the | |
| 68 // lock screen). The password obtained from the reauth is cached for a short | |
| 69 // period of time and used to create the cryptohome keys for sign-in. | |
| 70 if (short_lived_user_context_ && short_lived_user_context_->user_context()) { | |
|
tbarzic
2014/11/01 23:21:45
maybe we could also check that the credentials are
tbarzic
2014/11/01 23:40:51
you can ignore this (we should not be keeping user
Tim Song
2014/11/03 19:10:43
Acknowledged
| |
| 71 OpenSetupApp(); | |
| 72 } else { | |
| 73 bool reauth_success = chromeos::EasyUnlockReauth::ReauthForUserContext( | |
| 74 base::Bind(&EasyUnlockServiceRegular::OnUserContextFromReauth, | |
| 75 weak_ptr_factory_.GetWeakPtr())); | |
| 76 if (!reauth_success) | |
| 77 OpenSetupApp(); | |
| 78 } | |
| 79 #else | |
| 80 OpenSetupApp(); | |
| 81 #endif | |
| 82 } | |
| 83 | |
| 84 #if defined(OS_CHROMEOS) | |
| 85 void EasyUnlockServiceRegular::OnUserContextFromReauth( | |
| 86 const chromeos::UserContext& user_context) { | |
| 87 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 88 short_lived_user_context_.reset(new chromeos::ShortLivedUserContext( | |
| 89 user_context, | |
| 90 apps::AppLifetimeMonitorFactory::GetForProfile(profile()), | |
| 91 base::ThreadTaskRunnerHandle::Get().get())); | |
| 92 | |
| 93 OpenSetupApp(); | |
| 94 } | |
| 95 | |
| 96 void EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices(bool success) { | |
| 97 // If the keys were refreshed successfully, the hardlock state should be | |
| 98 // cleared, so Smart Lock can be used normally. Otherwise, we fall back to | |
| 99 // a hardlock state to force the user to type in their credentials again. | |
| 100 if (success) { | |
| 101 SetHardlockStateForUser(GetUserEmail(), | |
| 102 EasyUnlockScreenlockStateHandler::NO_HARDLOCK); | |
| 103 } | |
| 104 | |
| 105 // Even if the keys refresh suceeded, we still fetch the cryptohome keys as a | |
| 106 // sanity check. | |
| 107 CheckCryptohomeKeysAndMaybeHardlock(); | |
| 108 } | |
| 109 #endif | |
| 110 | |
| 111 void EasyUnlockServiceRegular::OpenSetupApp() { | |
| 58 ExtensionService* service = | 112 ExtensionService* service = |
| 59 extensions::ExtensionSystem::Get(profile())->extension_service(); | 113 extensions::ExtensionSystem::Get(profile())->extension_service(); |
| 60 const extensions::Extension* extension = | 114 const extensions::Extension* extension = |
| 61 service->GetExtensionById(extension_misc::kEasyUnlockAppId, false); | 115 service->GetExtensionById(extension_misc::kEasyUnlockAppId, false); |
| 62 | 116 |
| 63 OpenApplication(AppLaunchParams( | 117 OpenApplication(AppLaunchParams( |
| 64 profile(), extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); | 118 profile(), extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); |
| 65 } | 119 } |
| 66 | 120 |
| 67 const base::DictionaryValue* EasyUnlockServiceRegular::GetPermitAccess() const { | 121 const base::DictionaryValue* EasyUnlockServiceRegular::GetPermitAccess() const { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 96 return devices; | 150 return devices; |
| 97 | 151 |
| 98 return NULL; | 152 return NULL; |
| 99 } | 153 } |
| 100 | 154 |
| 101 void EasyUnlockServiceRegular::SetRemoteDevices( | 155 void EasyUnlockServiceRegular::SetRemoteDevices( |
| 102 const base::ListValue& devices) { | 156 const base::ListValue& devices) { |
| 103 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(), | 157 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(), |
| 104 prefs::kEasyUnlockPairing); | 158 prefs::kEasyUnlockPairing); |
| 105 pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy()); | 159 pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy()); |
| 160 | |
| 161 #if defined(OS_CHROMEOS) | |
| 162 if (short_lived_user_context_ && short_lived_user_context_->user_context() && | |
| 163 !devices.empty()) { | |
| 164 // We may already have the password cached, so proceed to create the | |
|
tbarzic
2014/11/01 23:21:45
my main concern here is that SetRemoteDevices coul
tbarzic
2014/11/01 23:29:05
actually, a workaround could be to check whether S
tbarzic
2014/11/03 22:50:13
any update on this? (as I said, at least a TODO wo
Tim Song
2014/11/04 00:23:08
Sorry, missed these comments.
I'm not sure if thi
| |
| 165 // cryptohome keys for sign-in or the system will be hardlocked. | |
| 166 chromeos::UserContext* user_context = | |
| 167 short_lived_user_context_->user_context(); | |
| 168 chromeos::EasyUnlockKeyManager* key_manager = | |
| 169 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager(); | |
| 170 | |
| 171 // Set the hardlock state to pairing_changed here | |
| 172 SetHardlockStateForUser(GetUserEmail(), | |
|
tbarzic
2014/11/01 23:21:45
why is this needed here?
tbarzic
2014/11/03 22:50:13
how about this one?
Tim Song
2014/11/04 00:23:08
Done. Sorry that was a left over.
| |
| 173 EasyUnlockScreenlockStateHandler::PAIRING_CHANGED); | |
| 174 key_manager->RefreshKeys( | |
| 175 *user_context, | |
| 176 devices, | |
| 177 base::Bind(&EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices, | |
| 178 weak_ptr_factory_.GetWeakPtr())); | |
| 179 } else { | |
| 180 CheckCryptohomeKeysAndMaybeHardlock(); | |
| 181 } | |
| 182 #else | |
| 106 CheckCryptohomeKeysAndMaybeHardlock(); | 183 CheckCryptohomeKeysAndMaybeHardlock(); |
| 184 #endif | |
| 107 } | 185 } |
| 108 | 186 |
| 109 void EasyUnlockServiceRegular::ClearRemoteDevices() { | 187 void EasyUnlockServiceRegular::ClearRemoteDevices() { |
| 110 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(), | 188 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(), |
| 111 prefs::kEasyUnlockPairing); | 189 prefs::kEasyUnlockPairing); |
| 112 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL); | 190 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL); |
| 113 CheckCryptohomeKeysAndMaybeHardlock(); | 191 CheckCryptohomeKeysAndMaybeHardlock(); |
| 114 } | 192 } |
| 115 | 193 |
| 116 void EasyUnlockServiceRegular::RunTurnOffFlow() { | 194 void EasyUnlockServiceRegular::RunTurnOffFlow() { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 void EasyUnlockServiceRegular::InitializeInternal() { | 255 void EasyUnlockServiceRegular::InitializeInternal() { |
| 178 registrar_.Init(profile()->GetPrefs()); | 256 registrar_.Init(profile()->GetPrefs()); |
| 179 registrar_.Add( | 257 registrar_.Add( |
| 180 prefs::kEasyUnlockAllowed, | 258 prefs::kEasyUnlockAllowed, |
| 181 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged, | 259 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged, |
| 182 base::Unretained(this))); | 260 base::Unretained(this))); |
| 183 OnPrefsChanged(); | 261 OnPrefsChanged(); |
| 184 } | 262 } |
| 185 | 263 |
| 186 void EasyUnlockServiceRegular::ShutdownInternal() { | 264 void EasyUnlockServiceRegular::ShutdownInternal() { |
| 265 #if defined(OS_CHROMEOS) | |
| 266 short_lived_user_context_.reset(); | |
| 267 #endif | |
| 268 | |
| 187 turn_off_flow_.reset(); | 269 turn_off_flow_.reset(); |
| 188 turn_off_flow_status_ = EasyUnlockService::IDLE; | 270 turn_off_flow_status_ = EasyUnlockService::IDLE; |
| 189 registrar_.RemoveAll(); | 271 registrar_.RemoveAll(); |
| 190 } | 272 } |
| 191 | 273 |
| 192 bool EasyUnlockServiceRegular::IsAllowedInternal() { | 274 bool EasyUnlockServiceRegular::IsAllowedInternal() { |
| 193 #if defined(OS_CHROMEOS) | 275 #if defined(OS_CHROMEOS) |
| 194 if (!user_manager::UserManager::Get()->IsLoggedInAsRegularUser()) | 276 if (!user_manager::UserManager::Get()->IsLoggedInAsRegularUser()) |
| 195 return false; | 277 return false; |
| 196 | 278 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 227 | 309 |
| 228 if (!success) { | 310 if (!success) { |
| 229 SetTurnOffFlowStatus(FAIL); | 311 SetTurnOffFlowStatus(FAIL); |
| 230 return; | 312 return; |
| 231 } | 313 } |
| 232 | 314 |
| 233 ClearRemoteDevices(); | 315 ClearRemoteDevices(); |
| 234 SetTurnOffFlowStatus(IDLE); | 316 SetTurnOffFlowStatus(IDLE); |
| 235 ReloadApp(); | 317 ReloadApp(); |
| 236 } | 318 } |
| OLD | NEW |