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