| 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/parallel_authenticator.h" | 5 #include "chrome/browser/chromeos/login/parallel_authenticator.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 744 } | 744 } |
| 745 std::string ParallelAuthenticator::DecryptToken( | 745 std::string ParallelAuthenticator::DecryptToken( |
| 746 const std::string& encrypted_token_hex) { | 746 const std::string& encrypted_token_hex) { |
| 747 if (!LoadSupplementalUserKey()) | 747 if (!LoadSupplementalUserKey()) |
| 748 return std::string(); | 748 return std::string(); |
| 749 return DecryptTokenWithKey(supplemental_user_key_.get(), | 749 return DecryptTokenWithKey(supplemental_user_key_.get(), |
| 750 SaltAsAscii(), | 750 SaltAsAscii(), |
| 751 encrypted_token_hex); | 751 encrypted_token_hex); |
| 752 } | 752 } |
| 753 | 753 |
| 754 std::string ParallelAuthenticator::DecryptLegacyToken( | |
| 755 const std::string& encrypted_token_hex) { | |
| 756 scoped_ptr<crypto::SymmetricKey> key( | |
| 757 crypto::SymmetricKey::DeriveKeyFromPassword( | |
| 758 crypto::SymmetricKey::AES, UserSupplementalKeyAsAscii(), | |
| 759 SaltAsAscii(), 1000, 256)); | |
| 760 return DecryptTokenWithKey(key.get(), SaltAsAscii(), encrypted_token_hex); | |
| 761 } | |
| 762 | |
| 763 std::string ParallelAuthenticator::HashPassword(const std::string& password) { | 754 std::string ParallelAuthenticator::HashPassword(const std::string& password) { |
| 764 // Get salt, ascii encode, update sha with that, then update with ascii | 755 // Get salt, ascii encode, update sha with that, then update with ascii |
| 765 // of password, then end. | 756 // of password, then end. |
| 766 std::string ascii_salt = SaltAsAscii(); | 757 std::string ascii_salt = SaltAsAscii(); |
| 767 char passhash_buf[kPassHashLen]; | 758 char passhash_buf[kPassHashLen]; |
| 768 | 759 |
| 769 // Hash salt and password | 760 // Hash salt and password |
| 770 crypto::SHA256HashString(ascii_salt + password, | 761 crypto::SHA256HashString(ascii_salt + password, |
| 771 &passhash_buf, sizeof(passhash_buf)); | 762 &passhash_buf, sizeof(passhash_buf)); |
| 772 | 763 |
| 773 return StringToLowerASCII(base::HexEncode( | 764 return StringToLowerASCII(base::HexEncode( |
| 774 reinterpret_cast<const void*>(passhash_buf), | 765 reinterpret_cast<const void*>(passhash_buf), |
| 775 sizeof(passhash_buf) / 2)); | 766 sizeof(passhash_buf) / 2)); |
| 776 } | 767 } |
| 777 | 768 |
| 778 std::string ParallelAuthenticator::SaltAsAscii() { | 769 std::string ParallelAuthenticator::SaltAsAscii() { |
| 779 LoadSystemSalt(); // no-op if it's already loaded. | 770 LoadSystemSalt(); // no-op if it's already loaded. |
| 780 return StringToLowerASCII(base::HexEncode( | 771 return StringToLowerASCII(base::HexEncode( |
| 781 reinterpret_cast<const void*>(system_salt_.data()), | 772 reinterpret_cast<const void*>(system_salt_.data()), |
| 782 system_salt_.size())); | 773 system_salt_.size())); |
| 783 } | 774 } |
| 784 | 775 |
| 785 std::string ParallelAuthenticator::UserSupplementalKeyAsAscii() { | |
| 786 // TODO(zelidrag, wad): http://crosbug.com/18633 - Replace this with the real | |
| 787 // user suplemental key gets exposed in from cryptolib. | |
| 788 return SaltAsAscii(); | |
| 789 } | |
| 790 | |
| 791 void ParallelAuthenticator::ResolveLoginCompletionStatus() { | 776 void ParallelAuthenticator::ResolveLoginCompletionStatus() { |
| 792 // Shortcut online state resolution process. | 777 // Shortcut online state resolution process. |
| 793 current_state_->RecordOnlineLoginStatus(GaiaAuthConsumer::ClientLoginResult(), | 778 current_state_->RecordOnlineLoginStatus(GaiaAuthConsumer::ClientLoginResult(), |
| 794 LoginFailure::None()); | 779 LoginFailure::None()); |
| 795 Resolve(); | 780 Resolve(); |
| 796 } | 781 } |
| 797 | 782 |
| 798 } // namespace chromeos | 783 } // namespace chromeos |
| OLD | NEW |