| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 login_token_.assign(token); | 110 login_token_.assign(token); |
| 111 login_captcha_.assign(captcha); | 111 login_captcha_.assign(captcha); |
| 112 } | 112 } |
| 113 | 113 |
| 114 void GoogleAuthenticator::ClearClientLoginAttempt() { | 114 void GoogleAuthenticator::ClearClientLoginAttempt() { |
| 115 // Not clearing the password, because we may need to pass it to the | 115 // Not clearing the password, because we may need to pass it to the |
| 116 // sync service if login is successful. | 116 // sync service if login is successful. |
| 117 login_token_.clear(); | 117 login_token_.clear(); |
| 118 login_captcha_.clear(); | 118 login_captcha_.clear(); |
| 119 } | 119 } |
| 120 bool GoogleAuthenticator::CompleteLogin(Profile* profile, | 120 void GoogleAuthenticator::CompleteLogin(Profile* profile, |
| 121 const std::string& username, | 121 const std::string& username, |
| 122 const std::string& password) { | 122 const std::string& password) { |
| 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 124 authentication_profile_ = profile; | 124 authentication_profile_ = profile; |
| 125 username_.assign(Canonicalize(username)); | 125 username_.assign(Canonicalize(username)); |
| 126 ascii_hash_.assign(HashPassword(password)); | 126 ascii_hash_.assign(HashPassword(password)); |
| 127 | 127 |
| 128 BrowserThread::PostTask( | 128 BrowserThread::PostTask( |
| 129 BrowserThread::UI, FROM_HERE, | 129 BrowserThread::UI, FROM_HERE, |
| 130 NewRunnableMethod(this, | 130 NewRunnableMethod(this, |
| 131 &GoogleAuthenticator::OnLoginSuccess, | 131 &GoogleAuthenticator::OnLoginSuccess, |
| 132 GaiaAuthConsumer::ClientLoginResult(), false)); | 132 GaiaAuthConsumer::ClientLoginResult(), false)); |
| 133 return true; | |
| 134 } | 133 } |
| 135 | 134 |
| 136 bool GoogleAuthenticator::AuthenticateToLogin( | 135 void GoogleAuthenticator::AuthenticateToLogin( |
| 137 Profile* profile, | 136 Profile* profile, |
| 138 const std::string& username, | 137 const std::string& username, |
| 139 const std::string& password, | 138 const std::string& password, |
| 140 const std::string& login_token, | 139 const std::string& login_token, |
| 141 const std::string& login_captcha) { | 140 const std::string& login_captcha) { |
| 142 unlock_ = false; | 141 unlock_ = false; |
| 143 authentication_profile_ = profile; | 142 authentication_profile_ = profile; |
| 144 | 143 |
| 145 // TODO(cmasone): Figure out how to parallelize fetch, username/password | 144 // TODO(cmasone): Figure out how to parallelize fetch, username/password |
| 146 // processing without impacting testability. | 145 // processing without impacting testability. |
| 147 username_.assign(Canonicalize(username)); | 146 username_.assign(Canonicalize(username)); |
| 148 ascii_hash_.assign(HashPassword(password)); | 147 ascii_hash_.assign(HashPassword(password)); |
| 149 | 148 |
| 150 gaia_authenticator_.reset( | 149 gaia_authenticator_.reset( |
| 151 new GaiaAuthFetcher(this, | 150 new GaiaAuthFetcher(this, |
| 152 GaiaConstants::kChromeOSSource, | 151 GaiaConstants::kChromeOSSource, |
| 153 profile->GetRequestContext())); | 152 profile->GetRequestContext())); |
| 154 // Will be used for retries. | 153 // Will be used for retries. |
| 155 PrepareClientLoginAttempt(password, login_token, login_captcha); | 154 PrepareClientLoginAttempt(password, login_token, login_captcha); |
| 156 TryClientLogin(); | 155 TryClientLogin(); |
| 157 return true; | |
| 158 } | 156 } |
| 159 | 157 |
| 160 bool GoogleAuthenticator::AuthenticateToUnlock(const std::string& username, | 158 bool GoogleAuthenticator::AuthenticateToUnlock(const std::string& username, |
| 161 const std::string& password) { | 159 const std::string& password) { |
| 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 163 username_.assign(Canonicalize(username)); | 161 username_.assign(Canonicalize(username)); |
| 164 ascii_hash_.assign(HashPassword(password)); | 162 ascii_hash_.assign(HashPassword(password)); |
| 165 unlock_ = true; | 163 unlock_ = true; |
| 166 BrowserThread::PostTask( | 164 BrowserThread::PostTask( |
| 167 BrowserThread::FILE, FROM_HERE, | 165 BrowserThread::FILE, FROM_HERE, |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 const unsigned int len) { | 506 const unsigned int len) { |
| 509 if (len < 2*binary_len) | 507 if (len < 2*binary_len) |
| 510 return false; | 508 return false; |
| 511 memset(hex_string, 0, len); | 509 memset(hex_string, 0, len); |
| 512 for (uint i = 0, j = 0; i < binary_len; i++, j+=2) | 510 for (uint i = 0, j = 0; i < binary_len; i++, j+=2) |
| 513 snprintf(hex_string + j, len - j, "%02x", binary[i]); | 511 snprintf(hex_string + j, len - j, "%02x", binary[i]); |
| 514 return true; | 512 return true; |
| 515 } | 513 } |
| 516 | 514 |
| 517 } // namespace chromeos | 515 } // namespace chromeos |
| OLD | NEW |