| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_PARALLEL_AUTHENTICATOR_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_PARALLEL_AUTHENTICATOR_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/compiler_specific.h" | |
| 12 #include "base/gtest_prod_util.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/synchronization/lock.h" | |
| 15 #include "chromeos/login/auth/auth_attempt_state.h" | |
| 16 #include "chromeos/login/auth/auth_attempt_state_resolver.h" | |
| 17 #include "chromeos/login/auth/authenticator.h" | |
| 18 #include "chromeos/login/auth/test_attempt_state.h" | |
| 19 #include "google_apis/gaia/gaia_auth_consumer.h" | |
| 20 | |
| 21 class AuthFailure; | |
| 22 class Profile; | |
| 23 | |
| 24 namespace chromeos { | |
| 25 | |
| 26 class AuthStatusConsumer; | |
| 27 | |
| 28 // Authenticates a Chromium OS user against cryptohome. | |
| 29 // Relies on the fact that online authentications has been already performed | |
| 30 // (i.e. using_oauth_ is true). | |
| 31 // | |
| 32 // At a high, level, here's what happens: | |
| 33 // AuthenticateToLogin() calls a Cryptohome's method to perform offline login. | |
| 34 // Resultes are stored in a AuthAttemptState owned by ParallelAuthenticator | |
| 35 // and then call Resolve(). Resolve() will attempt to | |
| 36 // determine which AuthState we're in, based on the info at hand. | |
| 37 // It then triggers further action based on the calculated AuthState; this | |
| 38 // further action might include calling back the passed-in AuthStatusConsumer | |
| 39 // to signal that login succeeded or failed, waiting for more outstanding | |
| 40 // operations to complete, or triggering some more Cryptohome method calls. | |
| 41 // | |
| 42 // Typical flows | |
| 43 // ------------- | |
| 44 // Add new user: CONTINUE > CONTINUE > CREATE_NEW > CONTINUE > ONLINE_LOGIN | |
| 45 // Login as existing user: CONTINUE > OFFLINE_LOGIN | |
| 46 // Login as existing user (failure): CONTINUE > FAILED_MOUNT | |
| 47 // Change password detected: | |
| 48 // GAIA online ok: CONTINUE > CONTINUE > NEED_OLD_PW | |
| 49 // Recreate: CREATE_NEW > CONTINUE > ONLINE_LOGIN | |
| 50 // Old password failure: NEED_OLD_PW | |
| 51 // Old password ok: RECOVER_MOUNT > CONTINUE > ONLINE_LOGIN | |
| 52 // | |
| 53 // TODO(nkostylev): Rename ParallelAuthenticator since it is not doing | |
| 54 // offline/online login operations in parallel anymore. | |
| 55 class ParallelAuthenticator : public Authenticator, | |
| 56 public AuthAttemptStateResolver { | |
| 57 public: | |
| 58 enum AuthState { | |
| 59 CONTINUE = 0, // State indeterminate; try again with more info. | |
| 60 NO_MOUNT = 1, // Cryptohome doesn't exist yet. | |
| 61 FAILED_MOUNT = 2, // Failed to mount existing cryptohome. | |
| 62 FAILED_REMOVE = 3, // Failed to remove existing cryptohome. | |
| 63 FAILED_TMPFS = 4, // Failed to mount tmpfs for guest user. | |
| 64 FAILED_TPM = 5, // Failed to mount/create cryptohome, TPM error. | |
| 65 CREATE_NEW = 6, // Need to create cryptohome for a new user. | |
| 66 RECOVER_MOUNT = 7, // After RecoverEncryptedData, mount cryptohome. | |
| 67 POSSIBLE_PW_CHANGE = 8, // Offline login failed, user may have changed pw. | |
| 68 NEED_NEW_PW = 9, // Obsolete (ClientLogin): user changed pw, | |
| 69 // we have the old one. | |
| 70 NEED_OLD_PW = 10, // User changed pw, and we have the new one | |
| 71 // (GAIA auth is OK). | |
| 72 HAVE_NEW_PW = 11, // Obsolete (ClientLogin): We have verified new pw, | |
| 73 // time to migrate key. | |
| 74 OFFLINE_LOGIN = 12, // Login succeeded offline. | |
| 75 DEMO_LOGIN = 13, // Logged in as the demo user. | |
| 76 ONLINE_LOGIN = 14, // Offline and online login succeeded. | |
| 77 UNLOCK = 15, // Screen unlock succeeded. | |
| 78 ONLINE_FAILED = 16, // Obsolete (ClientLogin): Online login disallowed, | |
| 79 // but offline succeeded. | |
| 80 GUEST_LOGIN = 17, // Logged in guest mode. | |
| 81 PUBLIC_ACCOUNT_LOGIN = 18, // Logged into a public account. | |
| 82 SUPERVISED_USER_LOGIN = 19, // Logged in as a supervised user. | |
| 83 LOGIN_FAILED = 20, // Login denied. | |
| 84 OWNER_REQUIRED = 21, // Login is restricted to the owner only. | |
| 85 FAILED_USERNAME_HASH = 22, // Failed GetSanitizedUsername request. | |
| 86 KIOSK_ACCOUNT_LOGIN = 23, // Logged into a kiosk account. | |
| 87 REMOVED_DATA_AFTER_FAILURE = 24, // Successfully removed the user's | |
| 88 // cryptohome after a login failure. | |
| 89 }; | |
| 90 | |
| 91 explicit ParallelAuthenticator(AuthStatusConsumer* consumer); | |
| 92 | |
| 93 // Authenticator overrides. | |
| 94 virtual void CompleteLogin(Profile* profile, | |
| 95 const UserContext& user_context) OVERRIDE; | |
| 96 | |
| 97 // Given |user_context|, this method attempts to authenticate to your | |
| 98 // Chrome OS device. As soon as we have successfully mounted the encrypted | |
| 99 // home directory for the user, we will call consumer_->OnAuthSuccess() | |
| 100 // with the username. | |
| 101 // Upon failure to login consumer_->OnAuthFailure() is called | |
| 102 // with an error message. | |
| 103 // | |
| 104 // Uses |profile| when doing URL fetches. | |
| 105 virtual void AuthenticateToLogin(Profile* profile, | |
| 106 const UserContext& user_context) OVERRIDE; | |
| 107 | |
| 108 // Given |user_context|, this method attempts to authenticate to the cached | |
| 109 // user_context. This will never contact the server even if it's online. | |
| 110 // The auth result is sent to AuthStatusConsumer in a same way as | |
| 111 // AuthenticateToLogin does. | |
| 112 virtual void AuthenticateToUnlock(const UserContext& user_context) OVERRIDE; | |
| 113 | |
| 114 // Initiates supervised user login. | |
| 115 // Creates cryptohome if missing or mounts existing one and | |
| 116 // notifies consumer on the success/failure. | |
| 117 virtual void LoginAsSupervisedUser( | |
| 118 const UserContext& user_context) OVERRIDE; | |
| 119 | |
| 120 // Initiates retail mode login. | |
| 121 // Mounts tmpfs and notifies consumer on the success/failure. | |
| 122 virtual void LoginRetailMode() OVERRIDE; | |
| 123 | |
| 124 // Initiates incognito ("browse without signing in") login. | |
| 125 // Mounts tmpfs and notifies consumer on the success/failure. | |
| 126 virtual void LoginOffTheRecord() OVERRIDE; | |
| 127 | |
| 128 // Initiates login into a public session. | |
| 129 // Mounts an ephemeral cryptohome and notifies consumer on the | |
| 130 // success/failure. | |
| 131 virtual void LoginAsPublicSession(const UserContext& user_context) OVERRIDE; | |
| 132 | |
| 133 // Initiates login into the kiosk mode account identified by |app_user_id|. | |
| 134 // Mounts an ephemeral guest cryptohome if |use_guest_mount| is |true|. | |
| 135 // Otherwise, mounts a public cryptohome, which will be ephemeral if the | |
| 136 // |DeviceEphemeralUsersEnabled| policy is enabled and non-ephemeral | |
| 137 // otherwise. | |
| 138 virtual void LoginAsKioskAccount(const std::string& app_user_id, | |
| 139 bool use_guest_mount) OVERRIDE; | |
| 140 | |
| 141 // These methods must be called on the UI thread, as they make DBus calls | |
| 142 // and also call back to the login UI. | |
| 143 virtual void OnRetailModeAuthSuccess() OVERRIDE; | |
| 144 virtual void OnAuthSuccess() OVERRIDE; | |
| 145 virtual void OnAuthFailure(const AuthFailure& error) OVERRIDE; | |
| 146 virtual void RecoverEncryptedData( | |
| 147 const std::string& old_password) OVERRIDE; | |
| 148 virtual void ResyncEncryptedData() OVERRIDE; | |
| 149 | |
| 150 // AuthAttemptStateResolver overrides. | |
| 151 // Attempts to make a decision and call back |consumer_| based on | |
| 152 // the state we have gathered at the time of call. If a decision | |
| 153 // can't be made, defers until the next time this is called. | |
| 154 // When a decision is made, will call back to |consumer_| on the UI thread. | |
| 155 // | |
| 156 // Must be called on the UI thread. | |
| 157 virtual void Resolve() OVERRIDE; | |
| 158 | |
| 159 void OnOffTheRecordAuthSuccess(); | |
| 160 void OnPasswordChangeDetected(); | |
| 161 | |
| 162 protected: | |
| 163 virtual ~ParallelAuthenticator(); | |
| 164 | |
| 165 private: | |
| 166 friend class ParallelAuthenticatorTest; | |
| 167 FRIEND_TEST_ALL_PREFIXES(ParallelAuthenticatorTest, | |
| 168 ResolveOwnerNeededDirectFailedMount); | |
| 169 FRIEND_TEST_ALL_PREFIXES(ParallelAuthenticatorTest, ResolveOwnerNeededMount); | |
| 170 FRIEND_TEST_ALL_PREFIXES(ParallelAuthenticatorTest, | |
| 171 ResolveOwnerNeededFailedMount); | |
| 172 | |
| 173 // Removes the cryptohome of the user. | |
| 174 void RemoveEncryptedData(); | |
| 175 | |
| 176 // Returns the AuthState we're in, given the status info we have at | |
| 177 // the time of call. | |
| 178 // Must be called on the IO thread. | |
| 179 AuthState ResolveState(); | |
| 180 | |
| 181 // Helper for ResolveState(). | |
| 182 // Given that some cryptohome operation has failed, determine which of the | |
| 183 // possible failure states we're in. | |
| 184 // Must be called on the IO thread. | |
| 185 AuthState ResolveCryptohomeFailureState(); | |
| 186 | |
| 187 // Helper for ResolveState(). | |
| 188 // Given that some cryptohome operation has succeeded, determine which of | |
| 189 // the possible states we're in. | |
| 190 // Must be called on the IO thread. | |
| 191 AuthState ResolveCryptohomeSuccessState(); | |
| 192 | |
| 193 // Helper for ResolveState(). | |
| 194 // Given that some online auth operation has succeeded, determine which of | |
| 195 // the possible success states we're in. | |
| 196 // Must be called on the IO thread. | |
| 197 AuthState ResolveOnlineSuccessState(AuthState offline_state); | |
| 198 | |
| 199 // Used for testing. | |
| 200 void set_attempt_state(TestAttemptState* new_state) { // takes ownership. | |
| 201 current_state_.reset(new_state); | |
| 202 } | |
| 203 | |
| 204 // Used for testing to set the expected state of an owner check. | |
| 205 void SetOwnerState(bool owner_check_finished, bool check_result); | |
| 206 | |
| 207 // checks if the current mounted home contains the owner case and either | |
| 208 // continues or fails the log-in. Used for policy lost mitigation "safe-mode". | |
| 209 // Returns true if the owner check has been successful or if it is not needed. | |
| 210 bool VerifyOwner(); | |
| 211 | |
| 212 // Handles completion of the ownership check and continues login. | |
| 213 void OnOwnershipChecked(bool is_owner); | |
| 214 | |
| 215 // Signal login completion status for cases when a new user is added via | |
| 216 // an external authentication provider (i.e. GAIA extension). | |
| 217 void ResolveLoginCompletionStatus(); | |
| 218 | |
| 219 scoped_ptr<AuthAttemptState> current_state_; | |
| 220 bool migrate_attempted_; | |
| 221 bool remove_attempted_; | |
| 222 bool resync_attempted_; | |
| 223 bool ephemeral_mount_attempted_; | |
| 224 bool check_key_attempted_; | |
| 225 | |
| 226 // 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. | |
| 228 // This allows us to present the same behavior to the caller, regardless | |
| 229 // of the order in which we receive these results. | |
| 230 bool already_reported_success_; | |
| 231 base::Lock success_lock_; // A lock around |already_reported_success_|. | |
| 232 | |
| 233 // Flags signaling whether the owner verification has been done and the result | |
| 234 // of it. | |
| 235 bool owner_is_verified_; | |
| 236 bool user_can_login_; | |
| 237 | |
| 238 // Flag indicating to delete the user's cryptohome the login fails. | |
| 239 bool remove_user_data_on_failure_; | |
| 240 | |
| 241 // When |remove_user_data_on_failure_| is set, we delay calling | |
| 242 // consumer_->OnAuthFailure() until we removed the user cryptohome. | |
| 243 const AuthFailure* delayed_login_failure_; | |
| 244 | |
| 245 DISALLOW_COPY_AND_ASSIGN(ParallelAuthenticator); | |
| 246 }; | |
| 247 | |
| 248 } // namespace chromeos | |
| 249 | |
| 250 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_AUTH_PARALLEL_AUTHENTICATOR_H_ | |
| OLD | NEW |