OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/google_authenticator.h" | 5 #include "chrome/browser/chromeos/login/google_authenticator.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 CHECK(chromeos::CrosLibrary::Get()->EnsureLoaded()); | 61 CHECK(chromeos::CrosLibrary::Get()->EnsureLoaded()); |
62 // If not already owned, this is a no-op. If it is, this loads the owner's | 62 // If not already owned, this is a no-op. If it is, this loads the owner's |
63 // public key off of disk. | 63 // public key off of disk. |
64 OwnershipService::GetSharedInstance()->StartLoadOwnerKeyAttempt(); | 64 OwnershipService::GetSharedInstance()->StartLoadOwnerKeyAttempt(); |
65 } | 65 } |
66 | 66 |
67 GoogleAuthenticator::~GoogleAuthenticator() {} | 67 GoogleAuthenticator::~GoogleAuthenticator() {} |
68 | 68 |
69 void GoogleAuthenticator::CancelClientLogin() { | 69 void GoogleAuthenticator::CancelClientLogin() { |
70 if (gaia_authenticator_->HasPendingFetch()) { | 70 if (gaia_authenticator_->HasPendingFetch()) { |
71 LOG(INFO) << "Canceling ClientLogin attempt."; | 71 VLOG(1) << "Canceling ClientLogin attempt."; |
72 gaia_authenticator_->CancelRequest(); | 72 gaia_authenticator_->CancelRequest(); |
73 | 73 |
74 BrowserThread::PostTask( | 74 BrowserThread::PostTask( |
75 BrowserThread::FILE, FROM_HERE, | 75 BrowserThread::FILE, FROM_HERE, |
76 NewRunnableMethod(this, | 76 NewRunnableMethod(this, |
77 &GoogleAuthenticator::LoadLocalaccount, | 77 &GoogleAuthenticator::LoadLocalaccount, |
78 std::string(kLocalaccountFile))); | 78 std::string(kLocalaccountFile))); |
79 | 79 |
80 CheckOffline(LoginFailure(LoginFailure::LOGIN_TIMED_OUT)); | 80 CheckOffline(LoginFailure(LoginFailure::LOGIN_TIMED_OUT)); |
81 } | 81 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 return true; | 138 return true; |
139 } | 139 } |
140 | 140 |
141 bool GoogleAuthenticator::AuthenticateToUnlock(const std::string& username, | 141 bool GoogleAuthenticator::AuthenticateToUnlock(const std::string& username, |
142 const std::string& password) { | 142 const std::string& password) { |
143 username_.assign(Canonicalize(username)); | 143 username_.assign(Canonicalize(username)); |
144 ascii_hash_.assign(HashPassword(password)); | 144 ascii_hash_.assign(HashPassword(password)); |
145 unlock_ = true; | 145 unlock_ = true; |
146 LoadLocalaccount(kLocalaccountFile); | 146 LoadLocalaccount(kLocalaccountFile); |
147 if (!localaccount_.empty() && localaccount_ == username) { | 147 if (!localaccount_.empty() && localaccount_ == username) { |
148 LOG(INFO) << "unlocking local account"; | 148 VLOG(1) << "Unlocking localaccount"; |
149 BrowserThread::PostTask( | 149 BrowserThread::PostTask( |
150 BrowserThread::UI, FROM_HERE, | 150 BrowserThread::UI, FROM_HERE, |
151 NewRunnableMethod(this, | 151 NewRunnableMethod(this, |
152 &GoogleAuthenticator::OnLoginSuccess, | 152 &GoogleAuthenticator::OnLoginSuccess, |
153 GaiaAuthConsumer::ClientLoginResult(), false)); | 153 GaiaAuthConsumer::ClientLoginResult(), false)); |
154 } else { | 154 } else { |
155 BrowserThread::PostTask( | 155 BrowserThread::PostTask( |
156 BrowserThread::UI, FROM_HERE, | 156 BrowserThread::UI, FROM_HERE, |
157 NewRunnableMethod(this, &GoogleAuthenticator::CheckOffline, | 157 NewRunnableMethod(this, &GoogleAuthenticator::CheckOffline, |
158 LoginFailure(LoginFailure::UNLOCK_FAILED))); | 158 LoginFailure(LoginFailure::UNLOCK_FAILED))); |
(...skipping 14 matching lines...) Expand all Loading... |
173 } else { | 173 } else { |
174 LOG(ERROR) << "Could not mount tmpfs: " << mount_error; | 174 LOG(ERROR) << "Could not mount tmpfs: " << mount_error; |
175 consumer_->OnLoginFailure( | 175 consumer_->OnLoginFailure( |
176 LoginFailure(LoginFailure::COULD_NOT_MOUNT_TMPFS)); | 176 LoginFailure(LoginFailure::COULD_NOT_MOUNT_TMPFS)); |
177 } | 177 } |
178 } | 178 } |
179 | 179 |
180 void GoogleAuthenticator::OnClientLoginSuccess( | 180 void GoogleAuthenticator::OnClientLoginSuccess( |
181 const GaiaAuthConsumer::ClientLoginResult& credentials) { | 181 const GaiaAuthConsumer::ClientLoginResult& credentials) { |
182 | 182 |
183 LOG(INFO) << "Online login successful!"; | 183 VLOG(1) << "Online login successful!"; |
184 ClearClientLoginAttempt(); | 184 ClearClientLoginAttempt(); |
185 | 185 |
186 BrowserThread::PostTask( | 186 BrowserThread::PostTask( |
187 BrowserThread::UI, FROM_HERE, | 187 BrowserThread::UI, FROM_HERE, |
188 NewRunnableMethod(this, | 188 NewRunnableMethod(this, |
189 &GoogleAuthenticator::OnLoginSuccess, | 189 &GoogleAuthenticator::OnLoginSuccess, |
190 credentials, false)); | 190 credentials, false)); |
191 } | 191 } |
192 | 192 |
193 void GoogleAuthenticator::OnClientLoginFailure( | 193 void GoogleAuthenticator::OnClientLoginFailure( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 consumer_->OnLoginSuccess(username_, credentials, request_pending); | 254 consumer_->OnLoginSuccess(username_, credentials, request_pending); |
255 } else if (!unlock_ && | 255 } else if (!unlock_ && |
256 mount_error == chromeos::kCryptohomeMountErrorKeyFailure) { | 256 mount_error == chromeos::kCryptohomeMountErrorKeyFailure) { |
257 consumer_->OnPasswordChangeDetected(credentials); | 257 consumer_->OnPasswordChangeDetected(credentials); |
258 } else { | 258 } else { |
259 OnLoginFailure(LoginFailure(LoginFailure::COULD_NOT_MOUNT_CRYPTOHOME)); | 259 OnLoginFailure(LoginFailure(LoginFailure::COULD_NOT_MOUNT_CRYPTOHOME)); |
260 } | 260 } |
261 } | 261 } |
262 | 262 |
263 void GoogleAuthenticator::CheckOffline(const LoginFailure& error) { | 263 void GoogleAuthenticator::CheckOffline(const LoginFailure& error) { |
264 LOG(INFO) << "Attempting offline login"; | 264 VLOG(1) << "Attempting offline login"; |
265 if (CrosLibrary::Get()->GetCryptohomeLibrary()->CheckKey( | 265 if (CrosLibrary::Get()->GetCryptohomeLibrary()->CheckKey( |
266 username_.c_str(), | 266 username_.c_str(), |
267 ascii_hash_.c_str())) { | 267 ascii_hash_.c_str())) { |
268 // The fetch didn't succeed, but offline login did. | 268 // The fetch didn't succeed, but offline login did. |
269 LOG(INFO) << "Offline login successful!"; | 269 VLOG(1) << "Offline login successful!"; |
270 OnLoginSuccess(GaiaAuthConsumer::ClientLoginResult(), false); | 270 OnLoginSuccess(GaiaAuthConsumer::ClientLoginResult(), false); |
271 } else { | 271 } else { |
272 // We couldn't hit the network, and offline login failed. | 272 // We couldn't hit the network, and offline login failed. |
273 GoogleAuthenticator::CheckLocalaccount(error); | 273 GoogleAuthenticator::CheckLocalaccount(error); |
274 } | 274 } |
275 } | 275 } |
276 | 276 |
277 void GoogleAuthenticator::CheckLocalaccount(const LoginFailure& error) { | 277 void GoogleAuthenticator::CheckLocalaccount(const LoginFailure& error) { |
278 { | 278 { |
279 AutoLock for_this_block(localaccount_lock_); | 279 AutoLock for_this_block(localaccount_lock_); |
280 LOG(INFO) << "Checking localaccount"; | 280 VLOG(1) << "Checking localaccount"; |
281 if (!checked_for_localaccount_) { | 281 if (!checked_for_localaccount_) { |
282 BrowserThread::PostDelayedTask( | 282 BrowserThread::PostDelayedTask( |
283 BrowserThread::UI, | 283 BrowserThread::UI, |
284 FROM_HERE, | 284 FROM_HERE, |
285 NewRunnableMethod(this, | 285 NewRunnableMethod(this, |
286 &GoogleAuthenticator::CheckLocalaccount, | 286 &GoogleAuthenticator::CheckLocalaccount, |
287 error), | 287 error), |
288 kLocalaccountRetryIntervalMs); | 288 kLocalaccountRetryIntervalMs); |
289 return; | 289 return; |
290 } | 290 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
363 { | 363 { |
364 AutoLock for_this_block(localaccount_lock_); | 364 AutoLock for_this_block(localaccount_lock_); |
365 if (checked_for_localaccount_) | 365 if (checked_for_localaccount_) |
366 return; | 366 return; |
367 } | 367 } |
368 FilePath localaccount_file; | 368 FilePath localaccount_file; |
369 std::string localaccount; | 369 std::string localaccount; |
370 if (PathService::Get(base::DIR_EXE, &localaccount_file)) { | 370 if (PathService::Get(base::DIR_EXE, &localaccount_file)) { |
371 localaccount_file = localaccount_file.Append(filename); | 371 localaccount_file = localaccount_file.Append(filename); |
372 LOG(INFO) << "looking for localaccount in " << localaccount_file.value(); | 372 VLOG(1) << "Looking for localaccount in " << localaccount_file.value(); |
373 | 373 |
374 ReadFileToString(localaccount_file, &localaccount); | 374 ReadFileToString(localaccount_file, &localaccount); |
375 TrimWhitespaceASCII(localaccount, TRIM_TRAILING, &localaccount); | 375 TrimWhitespaceASCII(localaccount, TRIM_TRAILING, &localaccount); |
376 LOG(INFO) << "Loading localaccount: " << localaccount; | 376 VLOG(1) << "Loading localaccount: " << localaccount; |
377 } else { | 377 } else { |
378 LOG(INFO) << "Assuming no localaccount"; | 378 VLOG(1) << "Assuming no localaccount"; |
379 } | 379 } |
380 SetLocalaccount(localaccount); | 380 SetLocalaccount(localaccount); |
381 } | 381 } |
382 | 382 |
383 void GoogleAuthenticator::SetLocalaccount(const std::string& new_name) { | 383 void GoogleAuthenticator::SetLocalaccount(const std::string& new_name) { |
384 localaccount_ = new_name; | 384 localaccount_ = new_name; |
385 { // extra braces for clarity about AutoLock scope. | 385 { // extra braces for clarity about AutoLock scope. |
386 AutoLock for_this_block(localaccount_lock_); | 386 AutoLock for_this_block(localaccount_lock_); |
387 checked_for_localaccount_ = true; | 387 checked_for_localaccount_ = true; |
388 } | 388 } |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 const unsigned int len) { | 440 const unsigned int len) { |
441 if (len < 2*binary_len) | 441 if (len < 2*binary_len) |
442 return false; | 442 return false; |
443 memset(hex_string, 0, len); | 443 memset(hex_string, 0, len); |
444 for (uint i = 0, j = 0; i < binary_len; i++, j+=2) | 444 for (uint i = 0, j = 0; i < binary_len; i++, j+=2) |
445 snprintf(hex_string + j, len - j, "%02x", binary[i]); | 445 snprintf(hex_string + j, len - j, "%02x", binary[i]); |
446 return true; | 446 return true; |
447 } | 447 } |
448 | 448 |
449 } // namespace chromeos | 449 } // namespace chromeos |
OLD | NEW |