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

Side by Side Diff: chromeos/cryptohome/cryptohome_library.cc

Issue 23904025: Move IsRunningOnChromeOS to SysInfo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 2 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 "chromeos/cryptohome/cryptohome_library.h" 5 #include "chromeos/cryptohome/cryptohome_library.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/chromeos/chromeos_version.h"
11 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
12 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 12 #include "base/strings/string_util.h"
13 #include "base/sys_info.h"
14 #include "chromeos/dbus/cryptohome_client.h" 14 #include "chromeos/dbus/cryptohome_client.h"
15 #include "chromeos/dbus/dbus_thread_manager.h" 15 #include "chromeos/dbus/dbus_thread_manager.h"
16 #include "crypto/encryptor.h" 16 #include "crypto/encryptor.h"
17 #include "crypto/nss_util.h" 17 #include "crypto/nss_util.h"
18 #include "crypto/sha2.h" 18 #include "crypto/sha2.h"
19 #include "crypto/symmetric_key.h" 19 #include "crypto/symmetric_key.h"
20 20
21 namespace chromeos { 21 namespace chromeos {
22 22
23 namespace { 23 namespace {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 return result; 115 return result;
116 } 116 }
117 117
118 virtual std::string GetSystemSalt() OVERRIDE { 118 virtual std::string GetSystemSalt() OVERRIDE {
119 LoadSystemSalt(); // no-op if it's already loaded. 119 LoadSystemSalt(); // no-op if it's already loaded.
120 return system_salt_; 120 return system_salt_;
121 } 121 }
122 122
123 virtual std::string EncryptWithSystemSalt(const std::string& token) OVERRIDE { 123 virtual std::string EncryptWithSystemSalt(const std::string& token) OVERRIDE {
124 // Don't care about token encryption while debugging. 124 // Don't care about token encryption while debugging.
125 if (!base::chromeos::IsRunningOnChromeOS()) 125 if (!base::SysInfo::IsRunningOnChromeOS())
126 return token; 126 return token;
127 127
128 if (!LoadSystemSaltKey()) { 128 if (!LoadSystemSaltKey()) {
129 LOG(WARNING) << "System salt key is not available for encrypt."; 129 LOG(WARNING) << "System salt key is not available for encrypt.";
130 return std::string(); 130 return std::string();
131 } 131 }
132 return EncryptTokenWithKey(system_salt_key_.get(), 132 return EncryptTokenWithKey(system_salt_key_.get(),
133 system_salt_, 133 system_salt_,
134 token); 134 token);
135 } 135 }
136 136
137 virtual std::string DecryptWithSystemSalt( 137 virtual std::string DecryptWithSystemSalt(
138 const std::string& encrypted_token_hex) OVERRIDE { 138 const std::string& encrypted_token_hex) OVERRIDE {
139 // Don't care about token encryption while debugging. 139 // Don't care about token encryption while debugging.
140 if (!base::chromeos::IsRunningOnChromeOS()) 140 if (!base::SysInfo::IsRunningOnChromeOS())
141 return encrypted_token_hex; 141 return encrypted_token_hex;
142 142
143 if (!LoadSystemSaltKey()) { 143 if (!LoadSystemSaltKey()) {
144 LOG(WARNING) << "System salt key is not available for decrypt."; 144 LOG(WARNING) << "System salt key is not available for decrypt.";
145 return std::string(); 145 return std::string();
146 } 146 }
147 return DecryptTokenWithKey(system_salt_key_.get(), 147 return DecryptTokenWithKey(system_salt_key_.get(),
148 system_salt_, 148 system_salt_,
149 encrypted_token_hex); 149 encrypted_token_hex);
150 } 150 }
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 310
311 CryptohomeLibrary::CryptohomeLibrary() {} 311 CryptohomeLibrary::CryptohomeLibrary() {}
312 CryptohomeLibrary::~CryptohomeLibrary() {} 312 CryptohomeLibrary::~CryptohomeLibrary() {}
313 313
314 static CryptohomeLibrary* g_cryptohome_library = NULL; 314 static CryptohomeLibrary* g_cryptohome_library = NULL;
315 static CryptohomeLibrary* g_test_cryptohome_library = NULL; 315 static CryptohomeLibrary* g_test_cryptohome_library = NULL;
316 316
317 // static 317 // static
318 void CryptohomeLibrary::Initialize() { 318 void CryptohomeLibrary::Initialize() {
319 CHECK(!g_cryptohome_library); 319 CHECK(!g_cryptohome_library);
320 if (base::chromeos::IsRunningOnChromeOS()) 320 if (base::SysInfo::IsRunningOnChromeOS())
321 g_cryptohome_library = new CryptohomeLibraryImpl(); 321 g_cryptohome_library = new CryptohomeLibraryImpl();
322 else 322 else
323 g_cryptohome_library = new CryptohomeLibraryStubImpl(); 323 g_cryptohome_library = new CryptohomeLibraryStubImpl();
324 } 324 }
325 325
326 // static 326 // static
327 bool CryptohomeLibrary::IsInitialized() { 327 bool CryptohomeLibrary::IsInitialized() {
328 return g_cryptohome_library; 328 return g_cryptohome_library;
329 } 329 }
330 330
(...skipping 18 matching lines...) Expand all
349 CHECK(!g_test_cryptohome_library || !impl); 349 CHECK(!g_test_cryptohome_library || !impl);
350 g_test_cryptohome_library = impl; 350 g_test_cryptohome_library = impl;
351 } 351 }
352 352
353 // static 353 // static
354 CryptohomeLibrary* CryptohomeLibrary::GetTestImpl() { 354 CryptohomeLibrary* CryptohomeLibrary::GetTestImpl() {
355 return new CryptohomeLibraryStubImpl(); 355 return new CryptohomeLibraryStubImpl();
356 } 356 }
357 357
358 } // namespace chromeos 358 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698