| 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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_PARALLEL_AUTHENTICATOR_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_PARALLEL_AUTHENTICATOR_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_PARALLEL_AUTHENTICATOR_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_PARALLEL_AUTHENTICATOR_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 16 #include "chrome/browser/chromeos/login/authenticator.h" | 16 #include "chrome/browser/chromeos/login/authenticator.h" |
| 17 #include "chrome/browser/chromeos/login/auth_attempt_state.h" | 17 #include "chrome/browser/chromeos/login/auth_attempt_state.h" |
| 18 #include "chrome/browser/chromeos/login/auth_attempt_state_resolver.h" | 18 #include "chrome/browser/chromeos/login/auth_attempt_state_resolver.h" |
| 19 #include "chrome/browser/chromeos/login/test_attempt_state.h" | 19 #include "chrome/browser/chromeos/login/test_attempt_state.h" |
| 20 #include "chrome/browser/chromeos/login/online_attempt.h" | 20 #include "chrome/browser/chromeos/login/online_attempt.h" |
| 21 #include "chrome/common/net/gaia/gaia_auth_consumer.h" | 21 #include "chrome/common/net/gaia/gaia_auth_consumer.h" |
| 22 | 22 |
| 23 class LoginFailure; | 23 class LoginFailure; |
| 24 class Profile; | 24 class Profile; |
| 25 | 25 |
| 26 namespace chromeos { | 26 namespace chromeos { |
| 27 | 27 |
| 28 class LoginStatusConsumer; | 28 class LoginStatusConsumer; |
| 29 class ResolveChecker; | |
| 30 | 29 |
| 31 // Authenticates a Chromium OS user against the Google Accounts ClientLogin API. | 30 // Authenticates a Chromium OS user against the Google Accounts ClientLogin API. |
| 32 // | 31 // |
| 33 // Simultaneously attempts authentication both offline and online. | 32 // Simultaneously attempts authentication both offline and online. |
| 34 // | 33 // |
| 35 // At a high, level, here's what happens: | 34 // At a high, level, here's what happens: |
| 36 // AuthenticateToLogin() creates an OnlineAttempt and calls a Cryptohome's | 35 // AuthenticateToLogin() creates an OnlineAttempt and calls a Cryptohome's |
| 37 // method to perform online and offline login simultaneously. When one of | 36 // method to perform online and offline login simultaneously. When one of |
| 38 // these completes, it will store results in a AuthAttemptState owned by | 37 // these completes, it will store results in a AuthAttemptState owned by |
| 39 // ParallelAuthenticator and then call Resolve(). Resolve() will attempt to | 38 // ParallelAuthenticator and then call Resolve(). Resolve() will attempt to |
| (...skipping 16 matching lines...) Expand all Loading... |
| 56 POSSIBLE_PW_CHANGE, // Offline login failed, user may have changed pw. | 55 POSSIBLE_PW_CHANGE, // Offline login failed, user may have changed pw. |
| 57 NEED_NEW_PW, // User changed pw, and we have the old one. | 56 NEED_NEW_PW, // User changed pw, and we have the old one. |
| 58 NEED_OLD_PW, // User changed pw, and we have the new one. | 57 NEED_OLD_PW, // User changed pw, and we have the new one. |
| 59 HAVE_NEW_PW, // We have verified new pw, time to migrate key. | 58 HAVE_NEW_PW, // We have verified new pw, time to migrate key. |
| 60 OFFLINE_LOGIN, // Login succeeded offline. | 59 OFFLINE_LOGIN, // Login succeeded offline. |
| 61 DEMO_LOGIN, // Logged in as the demo user. | 60 DEMO_LOGIN, // Logged in as the demo user. |
| 62 ONLINE_LOGIN, // Offline and online login succeeded. | 61 ONLINE_LOGIN, // Offline and online login succeeded. |
| 63 UNLOCK, // Screen unlock succeeded. | 62 UNLOCK, // Screen unlock succeeded. |
| 64 ONLINE_FAILED, // Online login disallowed, but offline succeeded. | 63 ONLINE_FAILED, // Online login disallowed, but offline succeeded. |
| 65 GUEST_LOGIN, // Logged in guest mode. | 64 GUEST_LOGIN, // Logged in guest mode. |
| 66 LOGIN_FAILED // Login denied. | 65 LOGIN_FAILED, // Login denied. |
| 66 OWNER_REQUIRED // Login is restricted to the owner only. |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 explicit ParallelAuthenticator(LoginStatusConsumer* consumer); | 69 explicit ParallelAuthenticator(LoginStatusConsumer* consumer); |
| 70 virtual ~ParallelAuthenticator(); | 70 virtual ~ParallelAuthenticator(); |
| 71 | 71 |
| 72 // Authenticator overrides. | 72 // Authenticator overrides. |
| 73 virtual void CompleteLogin(Profile* profile, | 73 virtual void CompleteLogin(Profile* profile, |
| 74 const std::string& username, | 74 const std::string& username, |
| 75 const std::string& password) OVERRIDE; | 75 const std::string& password) OVERRIDE; |
| 76 | 76 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 // Used for testing. | 192 // Used for testing. |
| 193 void set_attempt_state(TestAttemptState* new_state) { // takes ownership. | 193 void set_attempt_state(TestAttemptState* new_state) { // takes ownership. |
| 194 current_state_.reset(new_state); | 194 current_state_.reset(new_state); |
| 195 } | 195 } |
| 196 | 196 |
| 197 // Sets an online attemp for testing. | 197 // Sets an online attemp for testing. |
| 198 void set_online_attempt(OnlineAttempt* attempt) { | 198 void set_online_attempt(OnlineAttempt* attempt) { |
| 199 current_online_.reset(attempt); | 199 current_online_.reset(attempt); |
| 200 } | 200 } |
| 201 | 201 |
| 202 // Used for testing to set the expected state of an owner check. |
| 203 void SetOwnerState(bool owner_check_finished, bool check_result); |
| 204 |
| 202 // If we don't have the system salt yet, loads it from the CryptohomeLibrary. | 205 // If we don't have the system salt yet, loads it from the CryptohomeLibrary. |
| 203 void LoadSystemSalt(); | 206 void LoadSystemSalt(); |
| 204 // If we don't have supplemental_user_key_ yet, loads it from the NSS DB. | 207 // If we don't have supplemental_user_key_ yet, loads it from the NSS DB. |
| 205 // Returns false if the key can not be loaded/created. | 208 // Returns false if the key can not be loaded/created. |
| 206 bool LoadSupplementalUserKey(); | 209 bool LoadSupplementalUserKey(); |
| 207 | 210 |
| 211 // checks if the current mounted home contains the owner case and either |
| 212 // continues or fails the log-in. Used for policy lost mitigation "safe-mode". |
| 213 // Returns true if the owner check has been successful or if it is not needed. |
| 214 bool VerifyOwner(); |
| 215 |
| 216 // checks if the current mounted home contains the owner case and either |
| 217 // continues or fails the log-in. Used for policy lost mitigation "safe-mode". |
| 218 void FinishVerifyOwnerOnFileThread(); |
| 219 |
| 208 // Records OAuth1 access token verification failure for |user_account|. | 220 // Records OAuth1 access token verification failure for |user_account|. |
| 209 void RecordOAuthCheckFailure(const std::string& user_account); | 221 void RecordOAuthCheckFailure(const std::string& user_account); |
| 210 | 222 |
| 211 // Signal login completion status for cases when a new user is added via | 223 // Signal login completion status for cases when a new user is added via |
| 212 // an external authentication provider (i.e. GAIA extension). | 224 // an external authentication provider (i.e. GAIA extension). |
| 213 void ResolveLoginCompletionStatus(); | 225 void ResolveLoginCompletionStatus(); |
| 214 | 226 |
| 215 // Used when we need to try online authentication again, after successful | 227 // Used when we need to try online authentication again, after successful |
| 216 // mount, but failed online login. | 228 // mount, but failed online login. |
| 217 scoped_ptr<AuthAttemptState> reauth_state_; | 229 scoped_ptr<AuthAttemptState> reauth_state_; |
| 218 | 230 |
| 219 scoped_ptr<AuthAttemptState> current_state_; | 231 scoped_ptr<AuthAttemptState> current_state_; |
| 220 scoped_ptr<OnlineAttempt> current_online_; | 232 scoped_ptr<OnlineAttempt> current_online_; |
| 221 bool migrate_attempted_; | 233 bool migrate_attempted_; |
| 222 bool remove_attempted_; | 234 bool remove_attempted_; |
| 223 bool mount_guest_attempted_; | 235 bool mount_guest_attempted_; |
| 224 bool check_key_attempted_; | 236 bool check_key_attempted_; |
| 225 | 237 |
| 226 // When the user has changed her password, but gives us the old one, we will | 238 // When the user has changed her password, but gives us the old one, we will |
| 227 // be able to mount her cryptohome, but online authentication will fail. | 239 // be able to mount her cryptohome, but online authentication will fail. |
| 228 // This allows us to present the same behavior to the caller, regardless | 240 // This allows us to present the same behavior to the caller, regardless |
| 229 // of the order in which we receive these results. | 241 // of the order in which we receive these results. |
| 230 bool already_reported_success_; | 242 bool already_reported_success_; |
| 231 base::Lock success_lock_; // A lock around already_reported_success_. | 243 base::Lock success_lock_; // A lock around |already_reported_success_|. |
| 244 |
| 245 // Flags signaling whether the owner verification has been done and the result |
| 246 // of it. |
| 247 bool owner_is_verified_; |
| 248 bool user_can_login_; |
| 249 // A lock for |owner_is_verified_| and |user_can_login_|. |
| 250 base::Lock owner_verified_lock_; |
| 232 | 251 |
| 233 // True if we use OAuth-based authentication flow. | 252 // True if we use OAuth-based authentication flow. |
| 234 bool using_oauth_; | 253 bool using_oauth_; |
| 235 | 254 |
| 255 FRIEND_TEST_ALL_PREFIXES(ParallelAuthenticatorTest, |
| 256 ResolveOwnerNeededDirectFailedMount); |
| 257 FRIEND_TEST_ALL_PREFIXES(ParallelAuthenticatorTest, ResolveOwnerNeededMount); |
| 258 FRIEND_TEST_ALL_PREFIXES(ParallelAuthenticatorTest, |
| 259 ResolveOwnerNeededFailedMount); |
| 236 DISALLOW_COPY_AND_ASSIGN(ParallelAuthenticator); | 260 DISALLOW_COPY_AND_ASSIGN(ParallelAuthenticator); |
| 237 }; | 261 }; |
| 238 | 262 |
| 239 } // namespace chromeos | 263 } // namespace chromeos |
| 240 | 264 |
| 241 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_PARALLEL_AUTHENTICATOR_H_ | 265 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_PARALLEL_AUTHENTICATOR_H_ |
| OLD | NEW |