| 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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_GOOGLE_AUTHENTICATOR_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_GOOGLE_AUTHENTICATOR_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_GOOGLE_AUTHENTICATOR_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_GOOGLE_AUTHENTICATOR_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/ref_counted.h" | 12 #include "base/ref_counted.h" |
| 13 #include "base/scoped_ptr.h" | 13 #include "base/scoped_ptr.h" |
| 14 #include "base/sha2.h" | 14 #include "base/sha2.h" |
| 15 #include "chrome/browser/chromeos/cros/cros_library.h" | 15 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 16 #include "chrome/browser/chromeos/cros/cryptohome_library.h" | 16 #include "chrome/browser/chromeos/cros/cryptohome_library.h" |
| 17 #include "chrome/browser/chromeos/login/authenticator.h" | 17 #include "chrome/browser/chromeos/login/authenticator.h" |
| 18 #include "chrome/browser/chromeos/login/auth_response_handler.h" | 18 #include "chrome/browser/chromeos/login/auth_response_handler.h" |
| 19 #include "chrome/browser/net/url_fetcher.h" | 19 #include "chrome/browser/net/url_fetcher.h" |
| 20 | 20 |
| 21 class LoginStatusConsumer; | 21 class LoginStatusConsumer; |
| 22 | 22 |
| 23 // Authenticates a Chromium OS user against the Google Accounts ClientLogin API. | 23 // Authenticates a Chromium OS user against the Google Accounts ClientLogin API. |
| 24 | 24 |
| 25 class GoogleAuthenticator : public Authenticator, | 25 class GoogleAuthenticator : public Authenticator, |
| 26 public URLFetcher::Delegate { | 26 public URLFetcher::Delegate { |
| 27 public: | 27 public: |
| 28 GoogleAuthenticator(LoginStatusConsumer* consumer, | 28 GoogleAuthenticator(LoginStatusConsumer* consumer, |
| 29 chromeos::CryptohomeLibrary* library, | |
| 30 AuthResponseHandler* cl_handler, | 29 AuthResponseHandler* cl_handler, |
| 31 AuthResponseHandler* i_handler) | 30 AuthResponseHandler* i_handler) |
| 32 : Authenticator(consumer), | 31 : Authenticator(consumer), |
| 33 library_(library), | |
| 34 fetcher_(NULL), | 32 fetcher_(NULL), |
| 35 getter_(NULL), | 33 getter_(NULL), |
| 36 client_login_handler_(cl_handler), | 34 client_login_handler_(cl_handler), |
| 37 issue_handler_(i_handler) { | 35 issue_handler_(i_handler) { |
| 38 if (!library && chromeos::CrosLibrary::EnsureLoaded()) | 36 CHECK(chromeos::CrosLibrary::Get()->EnsureLoaded()); |
| 39 library_ = chromeos::CryptohomeLibrary::Get(); | 37 library_ = chromeos::CrosLibrary::Get()->GetCryptohomeLibrary(); |
| 40 } | 38 } |
| 41 | 39 |
| 42 explicit GoogleAuthenticator(LoginStatusConsumer* consumer) | 40 explicit GoogleAuthenticator(LoginStatusConsumer* consumer) |
| 43 : Authenticator(consumer), | 41 : Authenticator(consumer), |
| 44 fetcher_(NULL), | 42 fetcher_(NULL), |
| 45 getter_(NULL), | 43 getter_(NULL), |
| 46 client_login_handler_(NULL), | 44 client_login_handler_(NULL), |
| 47 issue_handler_(NULL) { | 45 issue_handler_(NULL) { |
| 48 CHECK(chromeos::CrosLibrary::EnsureLoaded()); | 46 CHECK(chromeos::CrosLibrary::Get()->EnsureLoaded()); |
| 49 library_ = chromeos::CryptohomeLibrary::Get(); | 47 library_ = chromeos::CrosLibrary::Get()->GetCryptohomeLibrary(); |
| 50 } | 48 } |
| 51 | 49 |
| 52 virtual ~GoogleAuthenticator() {} | 50 virtual ~GoogleAuthenticator() {} |
| 53 | 51 |
| 54 // Given a |username| and |password|, this method attempts to authenticate to | 52 // Given a |username| and |password|, this method attempts to authenticate to |
| 55 // the Google accounts servers. The ultimate result is either a callback to | 53 // the Google accounts servers. The ultimate result is either a callback to |
| 56 // consumer_->OnLoginSuccess() with the |username| and a vector of | 54 // consumer_->OnLoginSuccess() with the |username| and a vector of |
| 57 // authentication cookies or a callback to consumer_->OnLoginFailure() with | 55 // authentication cookies or a callback to consumer_->OnLoginFailure() with |
| 58 // an error message. | 56 // an error message. |
| 59 // | 57 // |
| (...skipping 14 matching lines...) Expand all Loading... |
| 74 | 72 |
| 75 // Returns the ascii encoding of the system salt. | 73 // Returns the ascii encoding of the system salt. |
| 76 std::string SaltAsAscii(); | 74 std::string SaltAsAscii(); |
| 77 | 75 |
| 78 // I need these static methods so I can PostTasks that use methods | 76 // I need these static methods so I can PostTasks that use methods |
| 79 // of sublcasses of LoginStatusConsumer. I can't seem to make | 77 // of sublcasses of LoginStatusConsumer. I can't seem to make |
| 80 // RunnableMethods out of methods belonging to subclasses without referring | 78 // RunnableMethods out of methods belonging to subclasses without referring |
| 81 // to the subclasses specifically, and I want to allow mocked out | 79 // to the subclasses specifically, and I want to allow mocked out |
| 82 // LoginStatusConsumers to be used here as well. | 80 // LoginStatusConsumers to be used here as well. |
| 83 static void OnLoginSuccess(LoginStatusConsumer* consumer, | 81 static void OnLoginSuccess(LoginStatusConsumer* consumer, |
| 84 chromeos::CryptohomeLibrary* library, | |
| 85 const std::string& username, | 82 const std::string& username, |
| 86 const std::string& passhash, | 83 const std::string& passhash, |
| 87 const ResponseCookies& cookies); | 84 const ResponseCookies& cookies); |
| 88 static void CheckOffline(LoginStatusConsumer* consumer, | 85 static void CheckOffline(LoginStatusConsumer* consumer, |
| 89 chromeos::CryptohomeLibrary* library, | |
| 90 const std::string& username, | 86 const std::string& username, |
| 91 const std::string& passhash, | 87 const std::string& passhash, |
| 92 const URLRequestStatus& status); | 88 const URLRequestStatus& status); |
| 93 static void OnLoginFailure(LoginStatusConsumer* consumer, | 89 static void OnLoginFailure(LoginStatusConsumer* consumer, |
| 94 const std::string& data); | 90 const std::string& data); |
| 95 | 91 |
| 96 // Meant for testing. | 92 // Meant for testing. |
| 97 void set_system_salt(const std::vector<unsigned char>& fake_salt) { | 93 void set_system_salt(const std::vector<unsigned char>& fake_salt) { |
| 98 system_salt_ = fake_salt; | 94 system_salt_ = fake_salt; |
| 99 } | 95 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // Returns false if |hex_string| is too small, true otherwise. | 127 // Returns false if |hex_string| is too small, true otherwise. |
| 132 static bool BinaryToHex(const std::vector<unsigned char>& binary, | 128 static bool BinaryToHex(const std::vector<unsigned char>& binary, |
| 133 const unsigned int binary_len, | 129 const unsigned int binary_len, |
| 134 char* hex_string, | 130 char* hex_string, |
| 135 const unsigned int len); | 131 const unsigned int len); |
| 136 | 132 |
| 137 DISALLOW_COPY_AND_ASSIGN(GoogleAuthenticator); | 133 DISALLOW_COPY_AND_ASSIGN(GoogleAuthenticator); |
| 138 }; | 134 }; |
| 139 | 135 |
| 140 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_GOOGLE_AUTHENTICATOR_H_ | 136 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_GOOGLE_AUTHENTICATOR_H_ |
| OLD | NEW |