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

Side by Side Diff: chrome/browser/signin/easy_unlock_service_regular.cc

Issue 668213003: Reauthenticate the user before launching Smart Lock setup app. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes + git cl format Created 6 years, 1 month 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
OLDNEW
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()) {
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, apps::AppLifetimeMonitorFactory::GetForProfile(profile()),
90 base::ThreadTaskRunnerHandle::Get().get()));
91
92 OpenSetupApp();
93 }
94
95 void EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices(bool success) {
96 // If the keys were refreshed successfully, the hardlock state should be
97 // cleared, so Smart Lock can be used normally. Otherwise, we fall back to
98 // a hardlock state to force the user to type in their credentials again.
99 if (success) {
100 SetHardlockStateForUser(GetUserEmail(),
101 EasyUnlockScreenlockStateHandler::NO_HARDLOCK);
102 }
103
104 // Even if the keys refresh suceeded, we still fetch the cryptohome keys as a
105 // sanity check.
106 CheckCryptohomeKeysAndMaybeHardlock();
107 }
108 #endif
109
110 void EasyUnlockServiceRegular::OpenSetupApp() {
58 ExtensionService* service = 111 ExtensionService* service =
59 extensions::ExtensionSystem::Get(profile())->extension_service(); 112 extensions::ExtensionSystem::Get(profile())->extension_service();
60 const extensions::Extension* extension = 113 const extensions::Extension* extension =
61 service->GetExtensionById(extension_misc::kEasyUnlockAppId, false); 114 service->GetExtensionById(extension_misc::kEasyUnlockAppId, false);
62 115
63 OpenApplication(AppLaunchParams( 116 OpenApplication(AppLaunchParams(
64 profile(), extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW)); 117 profile(), extension, extensions::LAUNCH_CONTAINER_WINDOW, NEW_WINDOW));
65 } 118 }
66 119
67 const base::DictionaryValue* EasyUnlockServiceRegular::GetPermitAccess() const { 120 const base::DictionaryValue* EasyUnlockServiceRegular::GetPermitAccess() const {
(...skipping 28 matching lines...) Expand all
96 return devices; 149 return devices;
97 150
98 return NULL; 151 return NULL;
99 } 152 }
100 153
101 void EasyUnlockServiceRegular::SetRemoteDevices( 154 void EasyUnlockServiceRegular::SetRemoteDevices(
102 const base::ListValue& devices) { 155 const base::ListValue& devices) {
103 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(), 156 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
104 prefs::kEasyUnlockPairing); 157 prefs::kEasyUnlockPairing);
105 pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy()); 158 pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy());
159
160 #if defined(OS_CHROMEOS)
161 // TODO(tengs): Investigate if we can determine if the remote devices were set
162 // from sync or from the setup app.
163 if (short_lived_user_context_ && short_lived_user_context_->user_context() &&
164 !devices.empty()) {
165 // We may already have the password cached, so proceed to create the
166 // cryptohome keys for sign-in or the system will be hardlocked.
167 chromeos::UserContext* user_context =
168 short_lived_user_context_->user_context();
169 chromeos::EasyUnlockKeyManager* key_manager =
170 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager();
171
172 key_manager->RefreshKeys(
173 *user_context, devices,
174 base::Bind(&EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices,
175 weak_ptr_factory_.GetWeakPtr()));
176 } else {
177 CheckCryptohomeKeysAndMaybeHardlock();
178 }
179 #else
106 CheckCryptohomeKeysAndMaybeHardlock(); 180 CheckCryptohomeKeysAndMaybeHardlock();
181 #endif
107 } 182 }
108 183
109 void EasyUnlockServiceRegular::ClearRemoteDevices() { 184 void EasyUnlockServiceRegular::ClearRemoteDevices() {
110 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(), 185 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
111 prefs::kEasyUnlockPairing); 186 prefs::kEasyUnlockPairing);
112 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL); 187 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL);
113 CheckCryptohomeKeysAndMaybeHardlock(); 188 CheckCryptohomeKeysAndMaybeHardlock();
114 } 189 }
115 190
116 void EasyUnlockServiceRegular::RunTurnOffFlow() { 191 void EasyUnlockServiceRegular::RunTurnOffFlow() {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 void EasyUnlockServiceRegular::InitializeInternal() { 252 void EasyUnlockServiceRegular::InitializeInternal() {
178 registrar_.Init(profile()->GetPrefs()); 253 registrar_.Init(profile()->GetPrefs());
179 registrar_.Add( 254 registrar_.Add(
180 prefs::kEasyUnlockAllowed, 255 prefs::kEasyUnlockAllowed,
181 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged, 256 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged,
182 base::Unretained(this))); 257 base::Unretained(this)));
183 OnPrefsChanged(); 258 OnPrefsChanged();
184 } 259 }
185 260
186 void EasyUnlockServiceRegular::ShutdownInternal() { 261 void EasyUnlockServiceRegular::ShutdownInternal() {
262 #if defined(OS_CHROMEOS)
263 short_lived_user_context_.reset();
264 #endif
265
187 turn_off_flow_.reset(); 266 turn_off_flow_.reset();
188 turn_off_flow_status_ = EasyUnlockService::IDLE; 267 turn_off_flow_status_ = EasyUnlockService::IDLE;
189 registrar_.RemoveAll(); 268 registrar_.RemoveAll();
190 } 269 }
191 270
192 bool EasyUnlockServiceRegular::IsAllowedInternal() { 271 bool EasyUnlockServiceRegular::IsAllowedInternal() {
193 #if defined(OS_CHROMEOS) 272 #if defined(OS_CHROMEOS)
194 if (!user_manager::UserManager::Get()->IsLoggedInAsRegularUser()) 273 if (!user_manager::UserManager::Get()->IsLoggedInAsRegularUser())
195 return false; 274 return false;
196 275
(...skipping 30 matching lines...) Expand all
227 306
228 if (!success) { 307 if (!success) {
229 SetTurnOffFlowStatus(FAIL); 308 SetTurnOffFlowStatus(FAIL);
230 return; 309 return;
231 } 310 }
232 311
233 ClearRemoteDevices(); 312 ClearRemoteDevices();
234 SetTurnOffFlowStatus(IDLE); 313 SetTurnOffFlowStatus(IDLE);
235 ReloadApp(); 314 ReloadApp();
236 } 315 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/easy_unlock_service_regular.h ('k') | chrome/browser/signin/screenlock_bridge.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698