Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(362)

Side by Side Diff: chrome/browser/chromeos/cros/cryptohome_library.cc

Issue 10701075: Remove chromeos::CryptohomeLibrary::HashPassword (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clarify comment in HashPassword() Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/cros/cryptohome_library.h" 5 #include "chrome/browser/chromeos/cros/cryptohome_library.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "chromeos/dbus/cryptohome_client.h" 12 #include "chromeos/dbus/cryptohome_client.h"
13 #include "chromeos/dbus/dbus_thread_manager.h" 13 #include "chromeos/dbus/dbus_thread_manager.h"
14 #include "crypto/sha2.h"
15 14
16 namespace { 15 namespace {
17 16
18 const char kStubSystemSalt[] = "stub_system_salt"; 17 const char kStubSystemSalt[] = "stub_system_salt";
19 const int kPassHashLen = 32;
20 18
21 } 19 }
22 20
23 namespace chromeos { 21 namespace chromeos {
24 22
25 // This class handles the interaction with the ChromeOS cryptohome library APIs. 23 // This class handles the interaction with the ChromeOS cryptohome library APIs.
26 class CryptohomeLibraryImpl : public CryptohomeLibrary { 24 class CryptohomeLibraryImpl : public CryptohomeLibrary {
27 public: 25 public:
28 CryptohomeLibraryImpl() : weak_ptr_factory_(this) { 26 CryptohomeLibraryImpl() : weak_ptr_factory_(this) {
29 } 27 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 return result; 118 return result;
121 } 119 }
122 120
123 virtual bool InstallAttributesIsFirstInstall() OVERRIDE { 121 virtual bool InstallAttributesIsFirstInstall() OVERRIDE {
124 bool result = false; 122 bool result = false;
125 DBusThreadManager::Get()->GetCryptohomeClient()-> 123 DBusThreadManager::Get()->GetCryptohomeClient()->
126 InstallAttributesIsFirstInstall(&result); 124 InstallAttributesIsFirstInstall(&result);
127 return result; 125 return result;
128 } 126 }
129 127
130 virtual std::string HashPassword(const std::string& password) OVERRIDE {
131 // Get salt, ascii encode, update sha with that, then update with ascii
132 // of password, then end.
133 std::string ascii_salt = GetSystemSalt();
134 char passhash_buf[kPassHashLen];
135
136 // Hash salt and password
137 crypto::SHA256HashString(ascii_salt + password,
138 &passhash_buf, sizeof(passhash_buf));
139
140 return StringToLowerASCII(base::HexEncode(
141 reinterpret_cast<const void*>(passhash_buf),
142 sizeof(passhash_buf) / 2));
143 }
144
145 virtual std::string GetSystemSalt() OVERRIDE { 128 virtual std::string GetSystemSalt() OVERRIDE {
146 LoadSystemSalt(); // no-op if it's already loaded. 129 LoadSystemSalt(); // no-op if it's already loaded.
147 return StringToLowerASCII(base::HexEncode( 130 return StringToLowerASCII(base::HexEncode(
148 reinterpret_cast<const void*>(system_salt_.data()), 131 reinterpret_cast<const void*>(system_salt_.data()),
149 system_salt_.size())); 132 system_salt_.size()));
150 } 133 }
151 134
152 private: 135 private:
153 void LoadSystemSalt() { 136 void LoadSystemSalt() {
154 if (!system_salt_.empty()) 137 if (!system_salt_.empty())
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 210 }
228 211
229 virtual bool InstallAttributesIsInvalid() OVERRIDE { 212 virtual bool InstallAttributesIsInvalid() OVERRIDE {
230 return false; 213 return false;
231 } 214 }
232 215
233 virtual bool InstallAttributesIsFirstInstall() OVERRIDE { 216 virtual bool InstallAttributesIsFirstInstall() OVERRIDE {
234 return !locked_; 217 return !locked_;
235 } 218 }
236 219
237 virtual std::string HashPassword(const std::string& password) OVERRIDE {
238 return StringToLowerASCII(base::HexEncode(
239 reinterpret_cast<const void*>(password.data()),
240 password.length()));
241 }
242
243 virtual std::string GetSystemSalt() OVERRIDE { 220 virtual std::string GetSystemSalt() OVERRIDE {
244 return kStubSystemSalt; 221 return kStubSystemSalt;
245 } 222 }
246 223
247 private: 224 private:
248 std::map<std::string, std::string> install_attrs_; 225 std::map<std::string, std::string> install_attrs_;
249 bool locked_; 226 bool locked_;
250 DISALLOW_COPY_AND_ASSIGN(CryptohomeLibraryStubImpl); 227 DISALLOW_COPY_AND_ASSIGN(CryptohomeLibraryStubImpl);
251 }; 228 };
252 229
253 CryptohomeLibrary::CryptohomeLibrary() {} 230 CryptohomeLibrary::CryptohomeLibrary() {}
254 CryptohomeLibrary::~CryptohomeLibrary() {} 231 CryptohomeLibrary::~CryptohomeLibrary() {}
255 232
256 // static 233 // static
257 CryptohomeLibrary* CryptohomeLibrary::GetImpl(bool stub) { 234 CryptohomeLibrary* CryptohomeLibrary::GetImpl(bool stub) {
258 CryptohomeLibrary* impl; 235 CryptohomeLibrary* impl;
259 if (stub) 236 if (stub)
260 impl = new CryptohomeLibraryStubImpl(); 237 impl = new CryptohomeLibraryStubImpl();
261 else 238 else
262 impl = new CryptohomeLibraryImpl(); 239 impl = new CryptohomeLibraryImpl();
263 return impl; 240 return impl;
264 } 241 }
265 242
266 } // namespace chromeos 243 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/cryptohome_library.h ('k') | chrome/browser/chromeos/cros/mock_cryptohome_library.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698