| OLD | NEW |
| 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/string_number_conversions.h" | 12 #include "base/string_number_conversions.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/cert_library.h" | 15 #include "chrome/browser/chromeos/cros/cert_library.h" |
| 16 #include "chrome/browser/chromeos/cros/cros_library.h" | 16 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 17 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 17 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
| 18 #include "chrome/browser/chromeos/login/authentication_notification_details.h" | 18 #include "chrome/browser/chromeos/login/authentication_notification_details.h" |
| 19 #include "chrome/browser/chromeos/login/login_status_consumer.h" | 19 #include "chrome/browser/chromeos/login/login_status_consumer.h" |
| 20 #include "chrome/browser/chromeos/login/user_manager.h" | 20 #include "chrome/browser/chromeos/login/user_manager.h" |
| 21 #include "chrome/browser/chromeos/settings/cros_settings.h" | 21 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 22 #include "chrome/browser/chromeos/settings/ownership_service.h" |
| 22 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
| 23 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/net/gaia/gaia_auth_util.h" | 25 #include "chrome/common/net/gaia/gaia_auth_util.h" |
| 25 #include "chromeos/cryptohome/async_method_caller.h" | 26 #include "chromeos/cryptohome/async_method_caller.h" |
| 26 #include "chromeos/dbus/cryptohome_client.h" | 27 #include "chromeos/dbus/cryptohome_client.h" |
| 27 #include "chromeos/dbus/dbus_thread_manager.h" | 28 #include "chromeos/dbus/dbus_thread_manager.h" |
| 28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/notification_service.h" | 30 #include "content/public/browser/notification_service.h" |
| 30 #include "crypto/sha2.h" | 31 #include "crypto/sha2.h" |
| 31 #include "third_party/cros_system_api/dbus/service_constants.h" | 32 #include "third_party/cros_system_api/dbus/service_constants.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 migrate_attempted_(false), | 194 migrate_attempted_(false), |
| 194 remove_attempted_(false), | 195 remove_attempted_(false), |
| 195 mount_guest_attempted_(false), | 196 mount_guest_attempted_(false), |
| 196 check_key_attempted_(false), | 197 check_key_attempted_(false), |
| 197 already_reported_success_(false), | 198 already_reported_success_(false), |
| 198 owner_is_verified_(false), | 199 owner_is_verified_(false), |
| 199 user_can_login_(false), | 200 user_can_login_(false), |
| 200 using_oauth_( | 201 using_oauth_( |
| 201 !CommandLine::ForCurrentProcess()->HasSwitch( | 202 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 202 switches::kSkipOAuthLogin)) { | 203 switches::kSkipOAuthLogin)) { |
| 204 // If not already owned, this is a no-op. If it is, this loads the owner's |
| 205 // public key off of disk. |
| 206 OwnershipService::GetSharedInstance()->StartLoadOwnerKeyAttempt(); |
| 203 } | 207 } |
| 204 | 208 |
| 205 void ParallelAuthenticator::AuthenticateToLogin( | 209 void ParallelAuthenticator::AuthenticateToLogin( |
| 206 Profile* profile, | 210 Profile* profile, |
| 207 const std::string& username, | 211 const std::string& username, |
| 208 const std::string& password, | 212 const std::string& password, |
| 209 const std::string& login_token, | 213 const std::string& login_token, |
| 210 const std::string& login_captcha) { | 214 const std::string& login_captcha) { |
| 211 std::string canonicalized = gaia::CanonicalizeEmail(username); | 215 std::string canonicalized = gaia::CanonicalizeEmail(username); |
| 212 authentication_profile_ = profile; | 216 authentication_profile_ = profile; |
| 213 current_state_.reset( | 217 current_state_.reset( |
| 214 new AuthAttemptState( | 218 new AuthAttemptState( |
| 215 canonicalized, | 219 canonicalized, |
| 216 password, | 220 password, |
| 217 HashPassword(password), | 221 HashPassword(password), |
| 218 login_token, | 222 login_token, |
| 219 login_captcha, | 223 login_captcha, |
| 220 !UserManager::Get()->IsKnownUser(canonicalized))); | 224 !UserManager::Get()->IsKnownUser(canonicalized))); |
| 221 // Reset the verified flag. | 225 { |
| 222 owner_is_verified_ = false; | 226 // Reset the verified flag. |
| 227 base::AutoLock for_this_block(owner_verified_lock_); |
| 228 owner_is_verified_ = false; |
| 229 } |
| 223 | 230 |
| 224 const bool create_if_missing = false; | 231 const bool create_if_missing = false; |
| 225 BrowserThread::PostTask( | 232 BrowserThread::PostTask( |
| 226 BrowserThread::UI, FROM_HERE, | 233 BrowserThread::UI, FROM_HERE, |
| 227 base::Bind(&Mount, | 234 base::Bind(&Mount, |
| 228 current_state_.get(), | 235 current_state_.get(), |
| 229 static_cast<AuthAttemptStateResolver*>(this), | 236 static_cast<AuthAttemptStateResolver*>(this), |
| 230 create_if_missing)); | 237 create_if_missing)); |
| 231 // ClientLogin authentication check should happen immediately here. | 238 // ClientLogin authentication check should happen immediately here. |
| 232 // We should not try OAuthLogin check until the profile loads. | 239 // We should not try OAuthLogin check until the profile loads. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 243 const std::string& username, | 250 const std::string& username, |
| 244 const std::string& password) { | 251 const std::string& password) { |
| 245 std::string canonicalized = gaia::CanonicalizeEmail(username); | 252 std::string canonicalized = gaia::CanonicalizeEmail(username); |
| 246 authentication_profile_ = profile; | 253 authentication_profile_ = profile; |
| 247 current_state_.reset( | 254 current_state_.reset( |
| 248 new AuthAttemptState( | 255 new AuthAttemptState( |
| 249 canonicalized, | 256 canonicalized, |
| 250 password, | 257 password, |
| 251 HashPassword(password), | 258 HashPassword(password), |
| 252 !UserManager::Get()->IsKnownUser(canonicalized))); | 259 !UserManager::Get()->IsKnownUser(canonicalized))); |
| 253 | 260 { |
| 254 // Reset the verified flag. | 261 // Reset the verified flag. |
| 255 owner_is_verified_ = false; | 262 base::AutoLock for_this_block(owner_verified_lock_); |
| 263 owner_is_verified_ = false; |
| 264 } |
| 256 | 265 |
| 257 const bool create_if_missing = false; | 266 const bool create_if_missing = false; |
| 258 BrowserThread::PostTask( | 267 BrowserThread::PostTask( |
| 259 BrowserThread::UI, FROM_HERE, | 268 BrowserThread::UI, FROM_HERE, |
| 260 base::Bind(&Mount, | 269 base::Bind(&Mount, |
| 261 current_state_.get(), | 270 current_state_.get(), |
| 262 static_cast<AuthAttemptStateResolver*>(this), | 271 static_cast<AuthAttemptStateResolver*>(this), |
| 263 create_if_missing)); | 272 create_if_missing)); |
| 264 | 273 |
| 265 if (!using_oauth_) { | 274 if (!using_oauth_) { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 remove_attempted_ = true; | 408 remove_attempted_ = true; |
| 400 current_state_->ResetCryptohomeStatus(); | 409 current_state_->ResetCryptohomeStatus(); |
| 401 BrowserThread::PostTask( | 410 BrowserThread::PostTask( |
| 402 BrowserThread::UI, FROM_HERE, | 411 BrowserThread::UI, FROM_HERE, |
| 403 base::Bind(&Remove, | 412 base::Bind(&Remove, |
| 404 current_state_.get(), | 413 current_state_.get(), |
| 405 static_cast<AuthAttemptStateResolver*>(this))); | 414 static_cast<AuthAttemptStateResolver*>(this))); |
| 406 } | 415 } |
| 407 | 416 |
| 408 bool ParallelAuthenticator::VerifyOwner() { | 417 bool ParallelAuthenticator::VerifyOwner() { |
| 418 base::AutoLock for_this_block(owner_verified_lock_); |
| 409 if (owner_is_verified_) | 419 if (owner_is_verified_) |
| 410 return true; | 420 return true; |
| 411 // Check if policy data is fine and continue in safe mode if needed. | 421 // Check if policy data is fine and continue in safe mode if needed. |
| 412 bool is_safe_mode = false; | 422 bool is_safe_mode = false; |
| 413 CrosSettings::Get()->GetBoolean(kPolicyMissingMitigationMode, &is_safe_mode); | 423 CrosSettings::Get()->GetBoolean(kPolicyMissingMitigationMode, &is_safe_mode); |
| 414 if (!is_safe_mode) { | 424 if (!is_safe_mode) { |
| 415 // Now we can continue with the login and report mount success. | 425 // Now we can continue with the login and report mount success. |
| 416 user_can_login_ = true; | 426 user_can_login_ = true; |
| 417 owner_is_verified_ = true; | 427 owner_is_verified_ = true; |
| 418 return true; | 428 return true; |
| 419 } | 429 } |
| 420 // First we have to make sure the current user's cert store is available. | 430 // First we have to make sure the current user's cert store is available. |
| 421 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore(); | 431 CrosLibrary::Get()->GetCertLibrary()->LoadKeyStore(); |
| 422 // Now we can continue reading the private key. | 432 // Now we can continue reading the private key. |
| 423 DeviceSettingsService::Get()->SetUsername(current_state_->username); | 433 BrowserThread::PostTask( |
| 424 DeviceSettingsService::Get()->GetOwnershipStatusAsync( | 434 BrowserThread::FILE, FROM_HERE, |
| 425 base::Bind(&ParallelAuthenticator::OnOwnershipChecked, this)); | 435 base::Bind(&ParallelAuthenticator::FinishVerifyOwnerOnFileThread, this)); |
| 426 return false; | 436 return false; |
| 427 } | 437 } |
| 428 | 438 |
| 429 void ParallelAuthenticator::OnOwnershipChecked( | 439 void ParallelAuthenticator::FinishVerifyOwnerOnFileThread() { |
| 430 DeviceSettingsService::OwnershipStatus status, | 440 base::AutoLock for_this_block(owner_verified_lock_); |
| 431 bool is_owner) { | |
| 432 // Now we can check if this user is the owner. | 441 // Now we can check if this user is the owner. |
| 433 user_can_login_ = is_owner; | 442 user_can_login_ = |
| 443 OwnershipService::GetSharedInstance()->IsCurrentUserOwner(); |
| 434 owner_is_verified_ = true; | 444 owner_is_verified_ = true; |
| 435 Resolve(); | 445 BrowserThread::PostTask( |
| 446 BrowserThread::UI, FROM_HERE, |
| 447 base::Bind(&ParallelAuthenticator::Resolve, this)); |
| 436 } | 448 } |
| 437 | 449 |
| 438 void ParallelAuthenticator::RetryAuth(Profile* profile, | 450 void ParallelAuthenticator::RetryAuth(Profile* profile, |
| 439 const std::string& username, | 451 const std::string& username, |
| 440 const std::string& password, | 452 const std::string& password, |
| 441 const std::string& login_token, | 453 const std::string& login_token, |
| 442 const std::string& login_captcha) { | 454 const std::string& login_captcha) { |
| 443 reauth_state_.reset( | 455 reauth_state_.reset( |
| 444 new AuthAttemptState( | 456 new AuthAttemptState( |
| 445 gaia::CanonicalizeEmail(username), | 457 gaia::CanonicalizeEmail(username), |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 784 } | 796 } |
| 785 | 797 |
| 786 void ParallelAuthenticator::ResolveLoginCompletionStatus() { | 798 void ParallelAuthenticator::ResolveLoginCompletionStatus() { |
| 787 // Shortcut online state resolution process. | 799 // Shortcut online state resolution process. |
| 788 current_state_->RecordOnlineLoginStatus(LoginFailure::None()); | 800 current_state_->RecordOnlineLoginStatus(LoginFailure::None()); |
| 789 Resolve(); | 801 Resolve(); |
| 790 } | 802 } |
| 791 | 803 |
| 792 void ParallelAuthenticator::SetOwnerState(bool owner_check_finished, | 804 void ParallelAuthenticator::SetOwnerState(bool owner_check_finished, |
| 793 bool check_result) { | 805 bool check_result) { |
| 806 base::AutoLock for_this_block(owner_verified_lock_); |
| 794 owner_is_verified_ = owner_check_finished; | 807 owner_is_verified_ = owner_check_finished; |
| 795 user_can_login_ = check_result; | 808 user_can_login_ = check_result; |
| 796 } | 809 } |
| 797 | 810 |
| 798 } // namespace chromeos | 811 } // namespace chromeos |
| OLD | NEW |