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

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: 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::UserContext* user_context = 182 chromeos::UserContext* user_context =
170 short_lived_user_context_->user_context(); 183 short_lived_user_context_->user_context();
171 chromeos::EasyUnlockKeyManager* key_manager = 184 chromeos::EasyUnlockKeyManager* key_manager =
172 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager(); 185 chromeos::UserSessionManager::GetInstance()->GetEasyUnlockKeyManager();
173 186
174 key_manager->RefreshKeys( 187 key_manager->RefreshKeys(
175 *user_context, devices, 188 *user_context, devices,
176 base::Bind(&EasyUnlockServiceRegular::OnKeysRefreshedForSetDevices, 189 base::Bind(&EasyUnlockServiceRegular::SetHardlockAfterKeyOperation,
177 weak_ptr_factory_.GetWeakPtr())); 190 weak_ptr_factory_.GetWeakPtr(),
191 EasyUnlockScreenlockStateHandler::NO_HARDLOCK));
178 } else { 192 } else {
179 CheckCryptohomeKeysAndMaybeHardlock(); 193 CheckCryptohomeKeysAndMaybeHardlock();
180 } 194 }
181 #else 195 #else
182 CheckCryptohomeKeysAndMaybeHardlock(); 196 CheckCryptohomeKeysAndMaybeHardlock();
183 #endif 197 #endif
184 } 198 }
185 199
186 void EasyUnlockServiceRegular::ClearRemoteDevices() {
187 DictionaryPrefUpdate pairing_update(profile()->GetPrefs(),
188 prefs::kEasyUnlockPairing);
189 pairing_update->RemoveWithoutPathExpansion(kKeyDevices, NULL);
190 CheckCryptohomeKeysAndMaybeHardlock();
191 }
192
193 void EasyUnlockServiceRegular::RunTurnOffFlow() { 200 void EasyUnlockServiceRegular::RunTurnOffFlow() {
194 if (turn_off_flow_status_ == PENDING) 201 if (turn_off_flow_status_ == PENDING)
195 return; 202 return;
196 203
197 SetTurnOffFlowStatus(PENDING); 204 SetTurnOffFlowStatus(PENDING);
198 205
199 // Currently there should only be one registered phone. 206 // Currently there should only be one registered phone.
200 // TODO(xiyuan): Revisit this when server supports toggle for all or 207 // TODO(xiyuan): Revisit this when server supports toggle for all or
201 // there are multiple phones. 208 // there are multiple phones.
202 const base::DictionaryValue* pairing_dict = 209 const base::DictionaryValue* pairing_dict =
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 305 }
299 306
300 void EasyUnlockServiceRegular::OnTurnOffFlowFinished(bool success) { 307 void EasyUnlockServiceRegular::OnTurnOffFlowFinished(bool success) {
301 turn_off_flow_.reset(); 308 turn_off_flow_.reset();
302 309
303 if (!success) { 310 if (!success) {
304 SetTurnOffFlowStatus(FAIL); 311 SetTurnOffFlowStatus(FAIL);
305 return; 312 return;
306 } 313 }
307 314
308 ClearRemoteDevices(); 315 SetRemoteDevices(base::ListValue());
309 SetTurnOffFlowStatus(IDLE); 316 SetTurnOffFlowStatus(IDLE);
310 ReloadApp(); 317 ReloadApp();
311 } 318 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698