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

Side by Side Diff: chrome/browser/chromeos/login/parallel_authenticator.cc

Issue 9466005: Make sure the device recovers from policy loss in the consumer case. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Now with proper testing. Created 8 years, 9 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chromeos/login/parallel_authenticator.h" 5 #include "chrome/browser/chromeos/login/parallel_authenticator.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "chrome/browser/chromeos/boot_times_loader.h" 14 #include "chrome/browser/chromeos/boot_times_loader.h"
15 #include "chrome/browser/chromeos/cros/cros_library.h" 15 #include "chrome/browser/chromeos/cros/cros_library.h"
16 #include "chrome/browser/chromeos/cros/cryptohome_library.h" 16 #include "chrome/browser/chromeos/cros/cryptohome_library.h"
17 #include "chrome/browser/chromeos/cros_settings.h"
17 #include "chrome/browser/chromeos/cryptohome/async_method_caller.h" 18 #include "chrome/browser/chromeos/cryptohome/async_method_caller.h"
19 #include "chrome/browser/chromeos/dbus/cryptohome_client.h"
20 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h"
18 #include "chrome/browser/chromeos/login/authentication_notification_details.h" 21 #include "chrome/browser/chromeos/login/authentication_notification_details.h"
19 #include "chrome/browser/chromeos/login/login_status_consumer.h" 22 #include "chrome/browser/chromeos/login/login_status_consumer.h"
20 #include "chrome/browser/chromeos/login/ownership_service.h" 23 #include "chrome/browser/chromeos/login/ownership_service.h"
21 #include "chrome/browser/chromeos/login/user_manager.h" 24 #include "chrome/browser/chromeos/login/user_manager.h"
22 #include "chrome/common/chrome_notification_types.h" 25 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/chrome_paths.h" 26 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
25 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
27 #include "third_party/cros_system_api/dbus/service_constants.h" 30 #include "third_party/cros_system_api/dbus/service_constants.h"
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 172
170 } // namespace 173 } // namespace
171 174
172 ParallelAuthenticator::ParallelAuthenticator(LoginStatusConsumer* consumer) 175 ParallelAuthenticator::ParallelAuthenticator(LoginStatusConsumer* consumer)
173 : Authenticator(consumer), 176 : Authenticator(consumer),
174 migrate_attempted_(false), 177 migrate_attempted_(false),
175 remove_attempted_(false), 178 remove_attempted_(false),
176 mount_guest_attempted_(false), 179 mount_guest_attempted_(false),
177 check_key_attempted_(false), 180 check_key_attempted_(false),
178 already_reported_success_(false), 181 already_reported_success_(false),
182 owner_is_verified_(false),
183 user_can_login_(false),
179 using_oauth_( 184 using_oauth_(
180 !CommandLine::ForCurrentProcess()->HasSwitch( 185 !CommandLine::ForCurrentProcess()->HasSwitch(
181 switches::kSkipOAuthLogin)) { 186 switches::kSkipOAuthLogin)) {
182 // If not already owned, this is a no-op. If it is, this loads the owner's 187 // If not already owned, this is a no-op. If it is, this loads the owner's
183 // public key off of disk. 188 // public key off of disk.
184 OwnershipService::GetSharedInstance()->StartLoadOwnerKeyAttempt(); 189 OwnershipService::GetSharedInstance()->StartLoadOwnerKeyAttempt();
185 } 190 }
186 191
187 ParallelAuthenticator::~ParallelAuthenticator() {} 192 ParallelAuthenticator::~ParallelAuthenticator() {}
188 193
189 void ParallelAuthenticator::AuthenticateToLogin( 194 void ParallelAuthenticator::AuthenticateToLogin(
190 Profile* profile, 195 Profile* profile,
191 const std::string& username, 196 const std::string& username,
192 const std::string& password, 197 const std::string& password,
193 const std::string& login_token, 198 const std::string& login_token,
194 const std::string& login_captcha) { 199 const std::string& login_captcha) {
195 std::string canonicalized = Authenticator::Canonicalize(username); 200 std::string canonicalized = Authenticator::Canonicalize(username);
196 authentication_profile_ = profile; 201 authentication_profile_ = profile;
197 current_state_.reset( 202 current_state_.reset(
198 new AuthAttemptState( 203 new AuthAttemptState(
199 canonicalized, 204 canonicalized,
200 password, 205 password,
201 CrosLibrary::Get()->GetCryptohomeLibrary()->HashPassword(password), 206 CrosLibrary::Get()->GetCryptohomeLibrary()->HashPassword(password),
202 login_token, 207 login_token,
203 login_captcha, 208 login_captcha,
204 !UserManager::Get()->IsKnownUser(canonicalized))); 209 !UserManager::Get()->IsKnownUser(canonicalized)));
210 {
211 LOG(ERROR) << "@@@ Resetting for " << username;
Chris Masone 2012/03/13 16:45:53 why LOG(ERROR)?
pastarmovj 2012/03/22 11:48:01 Debug output and it is gone now :)
212 // Reset the verified flag.
213 base::AutoLock for_this_block(owner_verified_lock_);
214 owner_is_verified_ = false;
215 }
216
205 const bool create_if_missing = false; 217 const bool create_if_missing = false;
206 BrowserThread::PostTask( 218 BrowserThread::PostTask(
207 BrowserThread::UI, FROM_HERE, 219 BrowserThread::UI, FROM_HERE,
208 base::Bind(&Mount, 220 base::Bind(&Mount,
209 current_state_.get(), 221 current_state_.get(),
210 static_cast<AuthAttemptStateResolver*>(this), 222 static_cast<AuthAttemptStateResolver*>(this),
211 create_if_missing)); 223 create_if_missing));
212
213 // ClientLogin authentication check should happen immediately here. 224 // ClientLogin authentication check should happen immediately here.
214 // We should not try OAuthLogin check until the profile loads. 225 // We should not try OAuthLogin check until the profile loads.
215 if (!using_oauth_) { 226 if (!using_oauth_) {
216 // Initiate ClientLogin-based post authentication. 227 // Initiate ClientLogin-based post authentication.
217 current_online_ = new OnlineAttempt(using_oauth_, 228 current_online_ = new OnlineAttempt(using_oauth_,
218 current_state_.get(), 229 current_state_.get(),
219 this); 230 this);
220 current_online_->Initiate(profile); 231 current_online_->Initiate(profile);
221 } 232 }
222 } 233 }
223 234
224 void ParallelAuthenticator::CompleteLogin(Profile* profile, 235 void ParallelAuthenticator::CompleteLogin(Profile* profile,
225 const std::string& username, 236 const std::string& username,
226 const std::string& password) { 237 const std::string& password) {
227 std::string canonicalized = Authenticator::Canonicalize(username); 238 std::string canonicalized = Authenticator::Canonicalize(username);
228 authentication_profile_ = profile; 239 authentication_profile_ = profile;
229 current_state_.reset( 240 current_state_.reset(
230 new AuthAttemptState( 241 new AuthAttemptState(
231 canonicalized, 242 canonicalized,
232 password, 243 password,
233 CrosLibrary::Get()->GetCryptohomeLibrary()->HashPassword(password), 244 CrosLibrary::Get()->GetCryptohomeLibrary()->HashPassword(password),
234 !UserManager::Get()->IsKnownUser(canonicalized))); 245 !UserManager::Get()->IsKnownUser(canonicalized)));
246 {
247 LOG(ERROR) << "@@@ Resetting for " << username;
Chris Masone 2012/03/13 16:45:53 Same question as above
pastarmovj 2012/03/22 11:48:01 Debug output and it is gone now :)
248 // Reset the verified flag.
249 base::AutoLock for_this_block(owner_verified_lock_);
250 owner_is_verified_ = false;
251 }
252
235 const bool create_if_missing = false; 253 const bool create_if_missing = false;
236 BrowserThread::PostTask( 254 BrowserThread::PostTask(
237 BrowserThread::UI, FROM_HERE, 255 BrowserThread::UI, FROM_HERE,
238 base::Bind(&Mount, 256 base::Bind(&Mount,
239 current_state_.get(), 257 current_state_.get(),
240 static_cast<AuthAttemptStateResolver*>(this), 258 static_cast<AuthAttemptStateResolver*>(this),
241 create_if_missing)); 259 create_if_missing));
242 260
243 if (!using_oauth_) { 261 if (!using_oauth_) {
244 // Test automation needs to disable oauth, but that leads to other 262 // Test automation needs to disable oauth, but that leads to other
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 remove_attempted_ = true; 397 remove_attempted_ = true;
380 BrowserThread::PostTask( 398 BrowserThread::PostTask(
381 BrowserThread::IO, FROM_HERE, 399 BrowserThread::IO, FROM_HERE,
382 base::Bind(&ResetCryptohomeStatusAndRunCallback, 400 base::Bind(&ResetCryptohomeStatusAndRunCallback,
383 current_state_.get(), 401 current_state_.get(),
384 base::Bind(&Remove, 402 base::Bind(&Remove,
385 current_state_.get(), 403 current_state_.get(),
386 static_cast<AuthAttemptStateResolver*>(this)))); 404 static_cast<AuthAttemptStateResolver*>(this))));
387 } 405 }
388 406
407 void ParallelAuthenticator::VerifyOwnerOnUIThread() {
408 // Check if policy data is fine and continue in safe mode if needed.
409 bool is_safe_mode = false;
410 CrosSettings::Get()->GetBoolean(kPolicyMissingMitigationMode, &is_safe_mode);
411 if (!is_safe_mode) {
412 base::AutoLock for_this_block(owner_verified_lock_);
413 // Now we can continue reading the private key.
Chris Masone 2012/03/13 16:45:53 but you never read the private key here...
pastarmovj 2012/03/22 11:48:01 Comment was wrong. Fixed.
414 user_can_login_ = true;
415 owner_is_verified_ = true;
416 BrowserThread::PostTask(
417 BrowserThread::IO, FROM_HERE,
418 base::Bind(&ParallelAuthenticator::Resolve, this));
419 return;
420 }
421 // First we have to make sure the current user's cert store is available.
422 UserManager::Get()->LoadKeyStore();
423 // Now we can continue reading the private key.
424 BrowserThread::PostTask(
425 BrowserThread::FILE, FROM_HERE,
426 base::Bind(&ParallelAuthenticator::FinishVerifyOwnerOnFileThread, this));
427 }
428
429 void ParallelAuthenticator::FinishVerifyOwnerOnFileThread() {
430 base::AutoLock for_this_block(owner_verified_lock_);
431 // Now we can continue reading the private key.
Chris Masone 2012/03/13 16:45:53 you read it here
pastarmovj 2012/03/22 11:48:01 Done.
432 user_can_login_ =
433 OwnershipService::GetSharedInstance()->IsCurrentUserOwner();
434 owner_is_verified_ = true;
435 BrowserThread::PostTask(
436 BrowserThread::IO, FROM_HERE,
437 base::Bind(&ParallelAuthenticator::Resolve, this));
438 LOG(ERROR) << "@@@ Check finished: " << user_can_login_;
Chris Masone 2012/03/13 16:45:53 ERROR?
pastarmovj 2012/03/22 11:48:01 Debug output. Gone.
439 }
440
389 void ParallelAuthenticator::RetryAuth(Profile* profile, 441 void ParallelAuthenticator::RetryAuth(Profile* profile,
390 const std::string& username, 442 const std::string& username,
391 const std::string& password, 443 const std::string& password,
392 const std::string& login_token, 444 const std::string& login_token,
393 const std::string& login_captcha) { 445 const std::string& login_captcha) {
394 reauth_state_.reset( 446 reauth_state_.reset(
395 new AuthAttemptState( 447 new AuthAttemptState(
396 Authenticator::Canonicalize(username), 448 Authenticator::Canonicalize(username),
397 password, 449 password,
398 CrosLibrary::Get()->GetCryptohomeLibrary()->HashPassword(password), 450 CrosLibrary::Get()->GetCryptohomeLibrary()->HashPassword(password),
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 break; 600 break;
549 case LOGIN_FAILED: 601 case LOGIN_FAILED:
550 current_state_->ResetCryptohomeStatus(); 602 current_state_->ResetCryptohomeStatus();
551 BrowserThread::PostTask(BrowserThread::UI, 603 BrowserThread::PostTask(BrowserThread::UI,
552 FROM_HERE, 604 FROM_HERE,
553 base::Bind( 605 base::Bind(
554 &ParallelAuthenticator::OnLoginFailure, 606 &ParallelAuthenticator::OnLoginFailure,
555 this, 607 this,
556 current_state_->online_outcome())); 608 current_state_->online_outcome()));
557 break; 609 break;
610 case OWNER_REQUIRED: {
611 current_state_->ResetCryptohomeStatus();
612 bool success = false;
613 DBusThreadManager::Get()->GetCryptohomeClient()->Unmount(&success);
614 if (!success) {
615 // Maybe we should reboot immediately here?
616 LOG(ERROR) << "Couldn't unmount users home!";
617 }
618 BrowserThread::PostTask(BrowserThread::UI,
619 FROM_HERE,
620 base::Bind(
621 &ParallelAuthenticator::OnLoginFailure,
622 this,
623 LoginFailure(LoginFailure::OWNER_REQUIRED)));
624 break;
625 }
558 default: 626 default:
559 NOTREACHED(); 627 NOTREACHED();
560 break; 628 break;
561 } 629 }
562 } 630 }
563 631
564 ParallelAuthenticator::AuthState ParallelAuthenticator::ResolveState() { 632 ParallelAuthenticator::AuthState ParallelAuthenticator::ResolveState() {
565 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 633 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
566 // If we haven't mounted the user's home dir yet, we can't be done. 634 // If we haven't mounted the user's home dir yet, we can't be done.
567 // We never get past here if a cryptohome op is still pending. 635 // We never get past here if a cryptohome op is still pending.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 if (mount_guest_attempted_) { 735 if (mount_guest_attempted_) {
668 if (current_state_->username == kDemoUser) 736 if (current_state_->username == kDemoUser)
669 return DEMO_LOGIN; 737 return DEMO_LOGIN;
670 else 738 else
671 return GUEST_LOGIN; 739 return GUEST_LOGIN;
672 } 740 }
673 if (migrate_attempted_) 741 if (migrate_attempted_)
674 return RECOVER_MOUNT; 742 return RECOVER_MOUNT;
675 if (check_key_attempted_) 743 if (check_key_attempted_)
676 return UNLOCK; 744 return UNLOCK;
677 return OFFLINE_LOGIN; 745
746 base::AutoLock for_this_block(owner_verified_lock_);
747 LOG(ERROR) << "@@@ cryptohome state " << owner_is_verified_;
Chris Masone 2012/03/13 16:45:53 ERROR?
pastarmovj 2012/03/22 11:48:01 Ditto.
748 if (!owner_is_verified_) {
749 BrowserThread::PostTask(
750 BrowserThread::UI, FROM_HERE,
751 base::Bind(&ParallelAuthenticator::VerifyOwnerOnUIThread, this));
752 return CONTINUE;
753 }
754 return user_can_login_ ? OFFLINE_LOGIN : OWNER_REQUIRED;
678 } 755 }
679 756
680 ParallelAuthenticator::AuthState 757 ParallelAuthenticator::AuthState
681 ParallelAuthenticator::ResolveOnlineFailureState( 758 ParallelAuthenticator::ResolveOnlineFailureState(
682 ParallelAuthenticator::AuthState offline_state) { 759 ParallelAuthenticator::AuthState offline_state) {
683 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 760 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
684 if (offline_state == OFFLINE_LOGIN) { 761 if (offline_state == OFFLINE_LOGIN) {
685 if (WasConnectionIssue(current_state_->online_outcome())) { 762 if (WasConnectionIssue(current_state_->online_outcome())) {
686 // Couldn't do an online check, so just go with the offline result. 763 // Couldn't do an online check, so just go with the offline result.
687 return OFFLINE_LOGIN; 764 return OFFLINE_LOGIN;
(...skipping 24 matching lines...) Expand all
712 return offline_state; 789 return offline_state;
713 } 790 }
714 } 791 }
715 792
716 void ParallelAuthenticator::ResolveLoginCompletionStatus() { 793 void ParallelAuthenticator::ResolveLoginCompletionStatus() {
717 // Shortcut online state resolution process. 794 // Shortcut online state resolution process.
718 current_state_->RecordOnlineLoginStatus(LoginFailure::None()); 795 current_state_->RecordOnlineLoginStatus(LoginFailure::None());
719 Resolve(); 796 Resolve();
720 } 797 }
721 798
799 void ParallelAuthenticator::SetOwnerState(bool owner_check_finished,
800 bool check_result) {
801 base::AutoLock for_this_block(owner_verified_lock_);
802 owner_is_verified_ = owner_check_finished;
803 user_can_login_ = check_result;
804 }
805
722 } // namespace chromeos 806 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698