Move chromeos::CryptohomeLibrary::HashPassword to chromeos::ParallelAuthenticator

This is a part of effort to remove CrosLibrary and its belongings.

BUG=126719
TEST=None


Review URL: https://chromiumcodereview.appspot.com/10701075

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146055 0039d316-1c4b-4281-b951-d872f2087c98
parent 2616ea05
...@@ -11,12 +11,10 @@ ...@@ -11,12 +11,10 @@
#include "base/string_util.h" #include "base/string_util.h"
#include "chromeos/dbus/cryptohome_client.h" #include "chromeos/dbus/cryptohome_client.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "crypto/sha2.h"
namespace { namespace {
const char kStubSystemSalt[] = "stub_system_salt"; const char kStubSystemSalt[] = "stub_system_salt";
const int kPassHashLen = 32;
} }
...@@ -127,21 +125,6 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary { ...@@ -127,21 +125,6 @@ class CryptohomeLibraryImpl : public CryptohomeLibrary {
return result; return result;
} }
virtual std::string HashPassword(const std::string& password) OVERRIDE {
// Get salt, ascii encode, update sha with that, then update with ascii
// of password, then end.
std::string ascii_salt = GetSystemSalt();
char passhash_buf[kPassHashLen];
// Hash salt and password
crypto::SHA256HashString(ascii_salt + password,
&passhash_buf, sizeof(passhash_buf));
return StringToLowerASCII(base::HexEncode(
reinterpret_cast<const void*>(passhash_buf),
sizeof(passhash_buf) / 2));
}
virtual std::string GetSystemSalt() OVERRIDE { virtual std::string GetSystemSalt() OVERRIDE {
LoadSystemSalt(); // no-op if it's already loaded. LoadSystemSalt(); // no-op if it's already loaded.
return StringToLowerASCII(base::HexEncode( return StringToLowerASCII(base::HexEncode(
...@@ -234,12 +217,6 @@ class CryptohomeLibraryStubImpl : public CryptohomeLibrary { ...@@ -234,12 +217,6 @@ class CryptohomeLibraryStubImpl : public CryptohomeLibrary {
return !locked_; return !locked_;
} }
virtual std::string HashPassword(const std::string& password) OVERRIDE {
return StringToLowerASCII(base::HexEncode(
reinterpret_cast<const void*>(password.data()),
password.length()));
}
virtual std::string GetSystemSalt() OVERRIDE { virtual std::string GetSystemSalt() OVERRIDE {
return kStubSystemSalt; return kStubSystemSalt;
} }
......
...@@ -54,9 +54,6 @@ class CryptohomeLibrary { ...@@ -54,9 +54,6 @@ class CryptohomeLibrary {
virtual bool InstallAttributesIsInvalid() = 0; virtual bool InstallAttributesIsInvalid() = 0;
virtual bool InstallAttributesIsFirstInstall() = 0; virtual bool InstallAttributesIsFirstInstall() = 0;
// Returns hash of |password|, salted with the system salt.
virtual std::string HashPassword(const std::string& password) = 0;
// Returns system hash in hex encoded ascii format. // Returns system hash in hex encoded ascii format.
virtual std::string GetSystemSalt() = 0; virtual std::string GetSystemSalt() = 0;
......
...@@ -23,7 +23,6 @@ class MockCryptohomeLibrary : public CryptohomeLibrary { ...@@ -23,7 +23,6 @@ class MockCryptohomeLibrary : public CryptohomeLibrary {
MockCryptohomeLibrary(); MockCryptohomeLibrary();
virtual ~MockCryptohomeLibrary(); virtual ~MockCryptohomeLibrary();
MOCK_METHOD0(IsMounted, bool(void)); MOCK_METHOD0(IsMounted, bool(void));
MOCK_METHOD1(HashPassword, std::string(const std::string& password));
MOCK_METHOD0(GetSystemSalt, std::string(void)); MOCK_METHOD0(GetSystemSalt, std::string(void));
MOCK_METHOD0(TpmIsReady, bool(void)); MOCK_METHOD0(TpmIsReady, bool(void));
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/file_path.h" #include "base/file_path.h"
#include "base/file_util.h" #include "base/file_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/string_number_conversions.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "chrome/browser/chromeos/boot_times_loader.h" #include "chrome/browser/chromeos/boot_times_loader.h"
#include "chrome/browser/chromeos/cros/cert_library.h" #include "chrome/browser/chromeos/cros/cert_library.h"
...@@ -27,6 +28,7 @@ ...@@ -27,6 +28,7 @@
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "crypto/sha2.h"
#include "third_party/cros_system_api/dbus/service_constants.h" #include "third_party/cros_system_api/dbus/service_constants.h"
using content::BrowserThread; using content::BrowserThread;
...@@ -38,6 +40,9 @@ namespace { ...@@ -38,6 +40,9 @@ namespace {
// Milliseconds until we timeout our attempt to hit ClientLogin. // Milliseconds until we timeout our attempt to hit ClientLogin.
const int kClientLoginTimeoutMs = 10000; const int kClientLoginTimeoutMs = 10000;
// Length of password hashed with SHA-256.
const int kPasswordHashLength = 32;
// Records status and calls resolver->Resolve(). // Records status and calls resolver->Resolve().
void TriggerResolve(AuthAttemptState* attempt, void TriggerResolve(AuthAttemptState* attempt,
AuthAttemptStateResolver* resolver, AuthAttemptStateResolver* resolver,
...@@ -162,6 +167,26 @@ bool WasConnectionIssue(const LoginFailure& online_outcome) { ...@@ -162,6 +167,26 @@ bool WasConnectionIssue(const LoginFailure& online_outcome) {
GoogleServiceAuthError::REQUEST_CANCELED)); GoogleServiceAuthError::REQUEST_CANCELED));
} }
// Returns hash of |password|, salted with the system salt.
std::string HashPassword(const std::string& password) {
// Get salt, ascii encode, update sha with that, then update with ascii
// of password, then end.
std::string ascii_salt =
CrosLibrary::Get()->GetCryptohomeLibrary()->GetSystemSalt();
char passhash_buf[kPasswordHashLength];
// Hash salt and password
crypto::SHA256HashString(ascii_salt + password,
&passhash_buf, sizeof(passhash_buf));
// Only want the top half for 'weak' hashing so that the passphrase is not
// immediately exposed even if the output is reversed.
const int encoded_length = sizeof(passhash_buf) / 2;
return StringToLowerASCII(base::HexEncode(
reinterpret_cast<const void*>(passhash_buf), encoded_length));
}
} // namespace } // namespace
ParallelAuthenticator::ParallelAuthenticator(LoginStatusConsumer* consumer) ParallelAuthenticator::ParallelAuthenticator(LoginStatusConsumer* consumer)
...@@ -193,7 +218,7 @@ void ParallelAuthenticator::AuthenticateToLogin( ...@@ -193,7 +218,7 @@ void ParallelAuthenticator::AuthenticateToLogin(
new AuthAttemptState( new AuthAttemptState(
canonicalized, canonicalized,
password, password,
CrosLibrary::Get()->GetCryptohomeLibrary()->HashPassword(password), HashPassword(password),
login_token, login_token,
login_captcha, login_captcha,
!UserManager::Get()->IsKnownUser(canonicalized))); !UserManager::Get()->IsKnownUser(canonicalized)));
...@@ -230,7 +255,7 @@ void ParallelAuthenticator::CompleteLogin(Profile* profile, ...@@ -230,7 +255,7 @@ void ParallelAuthenticator::CompleteLogin(Profile* profile,
new AuthAttemptState( new AuthAttemptState(
canonicalized, canonicalized,
password, password,
CrosLibrary::Get()->GetCryptohomeLibrary()->HashPassword(password), HashPassword(password),
!UserManager::Get()->IsKnownUser(canonicalized))); !UserManager::Get()->IsKnownUser(canonicalized)));
{ {
// Reset the verified flag. // Reset the verified flag.
...@@ -270,7 +295,7 @@ void ParallelAuthenticator::AuthenticateToUnlock(const std::string& username, ...@@ -270,7 +295,7 @@ void ParallelAuthenticator::AuthenticateToUnlock(const std::string& username,
current_state_.reset( current_state_.reset(
new AuthAttemptState( new AuthAttemptState(
gaia::CanonicalizeEmail(username), gaia::CanonicalizeEmail(username),
CrosLibrary::Get()->GetCryptohomeLibrary()->HashPassword(password))); HashPassword(password)));
check_key_attempted_ = true; check_key_attempted_ = true;
BrowserThread::PostTask( BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE, BrowserThread::UI, FROM_HERE,
...@@ -367,8 +392,7 @@ void ParallelAuthenticator::RecordOAuthCheckFailure( ...@@ -367,8 +392,7 @@ void ParallelAuthenticator::RecordOAuthCheckFailure(
void ParallelAuthenticator::RecoverEncryptedData( void ParallelAuthenticator::RecoverEncryptedData(
const std::string& old_password) { const std::string& old_password) {
std::string old_hash = std::string old_hash = HashPassword(old_password);
CrosLibrary::Get()->GetCryptohomeLibrary()->HashPassword(old_password);
migrate_attempted_ = true; migrate_attempted_ = true;
current_state_->ResetCryptohomeStatus(); current_state_->ResetCryptohomeStatus();
BrowserThread::PostTask( BrowserThread::PostTask(
...@@ -432,7 +456,7 @@ void ParallelAuthenticator::RetryAuth(Profile* profile, ...@@ -432,7 +456,7 @@ void ParallelAuthenticator::RetryAuth(Profile* profile,
new AuthAttemptState( new AuthAttemptState(
gaia::CanonicalizeEmail(username), gaia::CanonicalizeEmail(username),
password, password,
CrosLibrary::Get()->GetCryptohomeLibrary()->HashPassword(password), HashPassword(password),
login_token, login_token,
login_captcha, login_captcha,
false /* not a new user */)); false /* not a new user */));
......
...@@ -490,7 +490,7 @@ TEST_F(ParallelAuthenticatorTest, DriveDataRecover) { ...@@ -490,7 +490,7 @@ TEST_F(ParallelAuthenticatorTest, DriveDataRecover) {
EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, false, _)) EXPECT_CALL(*mock_caller_, AsyncMount(username_, hash_ascii_, false, _))
.Times(1) .Times(1)
.RetiresOnSaturation(); .RetiresOnSaturation();
EXPECT_CALL(*mock_cryptohome_library_, HashPassword(_)) EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt())
.WillOnce(Return(std::string())) .WillOnce(Return(std::string()))
.RetiresOnSaturation(); .RetiresOnSaturation();
...@@ -511,7 +511,7 @@ TEST_F(ParallelAuthenticatorTest, DriveDataRecoverButFail) { ...@@ -511,7 +511,7 @@ TEST_F(ParallelAuthenticatorTest, DriveDataRecoverButFail) {
EXPECT_CALL(*mock_caller_, AsyncMigrateKey(username_, _, hash_ascii_, _)) EXPECT_CALL(*mock_caller_, AsyncMigrateKey(username_, _, hash_ascii_, _))
.Times(1) .Times(1)
.RetiresOnSaturation(); .RetiresOnSaturation();
EXPECT_CALL(*mock_cryptohome_library_, HashPassword(_)) EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt())
.WillOnce(Return(std::string())) .WillOnce(Return(std::string()))
.RetiresOnSaturation(); .RetiresOnSaturation();
...@@ -628,7 +628,7 @@ TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginGetNewPassword) { ...@@ -628,7 +628,7 @@ TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginGetNewPassword) {
_)) _))
.Times(1) .Times(1)
.RetiresOnSaturation(); .RetiresOnSaturation();
EXPECT_CALL(*mock_cryptohome_library_, HashPassword(_)) EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt())
.WillOnce(Return(std::string())) .WillOnce(Return(std::string()))
.RetiresOnSaturation(); .RetiresOnSaturation();
...@@ -666,7 +666,7 @@ TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginGetNewPassword) { ...@@ -666,7 +666,7 @@ TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginGetNewPassword) {
TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginGetCaptchad) { TEST_F(ParallelAuthenticatorTest, DriveOfflineLoginGetCaptchad) {
ExpectLoginSuccess(username_, password_, true); ExpectLoginSuccess(username_, password_, true);
FailOnLoginFailure(); FailOnLoginFailure();
EXPECT_CALL(*mock_cryptohome_library_, HashPassword(_)) EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt())
.WillOnce(Return(std::string())) .WillOnce(Return(std::string()))
.RetiresOnSaturation(); .RetiresOnSaturation();
...@@ -748,7 +748,7 @@ TEST_F(ParallelAuthenticatorTest, DriveUnlock) { ...@@ -748,7 +748,7 @@ TEST_F(ParallelAuthenticatorTest, DriveUnlock) {
EXPECT_CALL(*mock_caller_, AsyncCheckKey(username_, _, _)) EXPECT_CALL(*mock_caller_, AsyncCheckKey(username_, _, _))
.Times(1) .Times(1)
.RetiresOnSaturation(); .RetiresOnSaturation();
EXPECT_CALL(*mock_cryptohome_library_, HashPassword(_)) EXPECT_CALL(*mock_cryptohome_library_, GetSystemSalt())
.WillOnce(Return(std::string())) .WillOnce(Return(std::string()))
.RetiresOnSaturation(); .RetiresOnSaturation();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment