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