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

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

Issue 808563004: Clean up Smart Lock cryptohome keys logic: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use UserContext after create keys operation Created 6 years 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/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "base/prefs/scoped_user_pref_update.h" 10 #include "base/prefs/scoped_user_pref_update.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 #if defined(OS_CHROMEOS) 85 #if defined(OS_CHROMEOS)
86 void EasyUnlockServiceRegular::OnUserContextFromReauth( 86 void EasyUnlockServiceRegular::OnUserContextFromReauth(
87 const chromeos::UserContext& user_context) { 87 const chromeos::UserContext& user_context) {
88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 88 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
89 short_lived_user_context_.reset(new chromeos::ShortLivedUserContext( 89 short_lived_user_context_.reset(new chromeos::ShortLivedUserContext(
90 user_context, apps::AppLifetimeMonitorFactory::GetForProfile(profile()), 90 user_context, apps::AppLifetimeMonitorFactory::GetForProfile(profile()),
91 base::ThreadTaskRunnerHandle::Get().get())); 91 base::ThreadTaskRunnerHandle::Get().get()));
92 92
93 OpenSetupApp(); 93 OpenSetupApp();
94
95 // Use this opportunity to clear the crytohome keys if it was not already
96 // cleared earlier.
97 const base::ListValue* devices = GetRemoteDevices();
98 if (!devices || devices->empty()) {
99 chromeos::EasyUnlockKeyManager* key_manager =
100 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager();
101 key_manager->RefreshKeys(
102 user_context, base::ListValue(),
103 base::Bind(&EasyUnlockServiceRegular::SetHardlockAfterKeyOperation,
104 weak_ptr_factory_.GetWeakPtr(),
105 EasyUnlockScreenlockStateHandler::NO_PAIRING));
106 }
94 } 107 }
95 108
96 void EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices(bool success) { 109 void EasyUnlockServiceRegular::SetHardlockAfterKeyOperation(
97 // If the keys were refreshed successfully, the hardlock state should be 110 EasyUnlockScreenlockStateHandler::HardlockState state_on_success,
98 // cleared, so Smart Lock can be used normally. Otherwise, we fall back to 111 bool success) {
99 // a hardlock state to force the user to type in their credentials again. 112 if (success)
100 if (success) { 113 SetHardlockStateForUser(GetUserEmail(), state_on_success);
101 SetHardlockStateForUser(GetUserEmail(),
102 EasyUnlockScreenlockStateHandler::NO_HARDLOCK);
103 }
104 114
105 // Even if the keys refresh suceeded, we still fetch the cryptohome keys as a 115 // Even if the key operation (removeKey or refreshKey) suceeded, we still
106 // sanity check. 116 // fetch and check the cryptohome keys against the keys in local preferences
117 // as a sanity check.
107 CheckCryptohomeKeysAndMaybeHardlock(); 118 CheckCryptohomeKeysAndMaybeHardlock();
108 } 119 }
109 #endif 120 #endif
110 121
111 void EasyUnlockServiceRegular::OpenSetupApp() { 122 void EasyUnlockServiceRegular::OpenSetupApp() {
112 ExtensionService* service = 123 ExtensionService* service =
113 extensions::ExtensionSystem::Get(profile())->extension_service(); 124 extensions::ExtensionSystem::Get(profile())->extension_service();
114 const extensions::Extension* extension = 125 const extensions::Extension* extension =
115 service->GetExtensionById(extension_misc::kEasyUnlockAppId, false); 126 service->GetExtensionById(extension_misc::kEasyUnlockAppId, false);
116 127
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 if (pairing_dict && pairing_dict->GetList(kKeyDevices, &devices)) 161 if (pairing_dict && pairing_dict->GetList(kKeyDevices, &devices))
151 return devices; 162 return devices;
152 163
153 return NULL; 164 return NULL;
154 } 165 }
155 166
156 void EasyUnlockServiceRegular::SetRemoteDevices( 167 void EasyUnlockServiceRegular::SetRemoteDevices(
157 const base::ListValue& devices) { 168 const base::ListValue& devices) {
158 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(), 169 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
159 prefs::kEasyUnlockPairing); 170 prefs::kEasyUnlockPairing);
160 pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy()); 171 if (devices.empty())
172 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL);
173 else
174 pairing_update->SetWithoutPathExpansion(kKeyDevices, devices.DeepCopy());
161 175
162 #if defined(OS_CHROMEOS) 176 #if defined(OS_CHROMEOS)
163 // TODO(tengs): Investigate if we can determine if the remote devices were set 177 // TODO(tengs): Investigate if we can determine if the remote devices were set
164 // from sync or from the setup app. 178 // from sync or from the setup app.
165 if (short_lived_user_context_ && short_lived_user_context_->user_context() && 179 if (short_lived_user_context_ && short_lived_user_context_->user_context()) {
166 !devices.empty()) {
167 // We may already have the password cached, so proceed to create the 180 // We may already have the password cached, so proceed to create the
168 // cryptohome keys for sign-in or the system will be hardlocked. 181 // cryptohome keys for sign-in or the system will be hardlocked.
169 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager() 182 chromeos::UserSessionManager::GetInstance()
183 ->GetEasyUnlockKeyManager()
170 ->RefreshKeys( 184 ->RefreshKeys(
171 *short_lived_user_context_->user_context(), 185 *short_lived_user_context_->user_context(), devices,
172 devices, 186 base::Bind(&EasyUnlockServiceRegular::SetHardlockAfterKeyOperation,
173 base::Bind(&EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices, 187 weak_ptr_factory_.GetWeakPtr(),
174 weak_ptr_factory_.GetWeakPtr())); 188 EasyUnlockScreenlockStateHandler::NO_HARDLOCK));
175 } else { 189 } else {
176 CheckCryptohomeKeysAndMaybeHardlock(); 190 CheckCryptohomeKeysAndMaybeHardlock();
177 } 191 }
178 #else 192 #else
179 CheckCryptohomeKeysAndMaybeHardlock(); 193 CheckCryptohomeKeysAndMaybeHardlock();
180 #endif 194 #endif
181 } 195 }
182 196
183 void EasyUnlockServiceRegular::ClearRemoteDevices() {
184 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
185 prefs::kEasyUnlockPairing);
186 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL);
187 CheckCryptohomeKeysAndMaybeHardlock();
188 }
189
190 void EasyUnlockServiceRegular::RunTurnOffFlow() { 197 void EasyUnlockServiceRegular::RunTurnOffFlow() {
191 if (turn_off_flow_status_ == PENDING) 198 if (turn_off_flow_status_ == PENDING)
192 return; 199 return;
193 200
194 SetTurnOffFlowStatus(PENDING); 201 SetTurnOffFlowStatus(PENDING);
195 202
196 // Currently there should only be one registered phone. 203 // Currently there should only be one registered phone.
197 // TODO(xiyuan): Revisit this when server supports toggle for all or 204 // TODO(xiyuan): Revisit this when server supports toggle for all or
198 // there are multiple phones. 205 // there are multiple phones.
199 const base::DictionaryValue* pairing_dict = 206 const base::DictionaryValue* pairing_dict =
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 } 302 }
296 303
297 void EasyUnlockServiceRegular::OnTurnOffFlowFinished(bool success) { 304 void EasyUnlockServiceRegular::OnTurnOffFlowFinished(bool success) {
298 turn_off_flow_.reset(); 305 turn_off_flow_.reset();
299 306
300 if (!success) { 307 if (!success) {
301 SetTurnOffFlowStatus(FAIL); 308 SetTurnOffFlowStatus(FAIL);
302 return; 309 return;
303 } 310 }
304 311
305 ClearRemoteDevices(); 312 SetRemoteDevices(base::ListValue());
306 SetTurnOffFlowStatus(IDLE); 313 SetTurnOffFlowStatus(IDLE);
307 ReloadApp(); 314 ReloadApp();
308 } 315 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698