| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ownership/owner_settings_service.h" | 5 #include "chrome/browser/chromeos/ownership/owner_settings_service.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/path_service.h" |
| 13 #include "base/prefs/pref_service.h" |
| 12 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 13 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" | 15 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" |
| 14 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 15 #include "chrome/browser/chromeos/settings/cros_settings.h" | 17 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 16 #include "chrome/browser/chromeos/settings/session_manager_operation.h" | 18 #include "chrome/browser/chromeos/settings/session_manager_operation.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chromeos/chromeos_paths.h" |
| 18 #include "chromeos/dbus/dbus_thread_manager.h" | 21 #include "chromeos/dbus/dbus_thread_manager.h" |
| 19 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 22 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 20 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 21 #include "content/public/browser/notification_details.h" | 24 #include "content/public/browser/notification_details.h" |
| 22 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/browser/notification_source.h" | 26 #include "content/public/browser/notification_source.h" |
| 24 #include "content/public/common/content_switches.h" | 27 #include "content/public/common/content_switches.h" |
| 25 #include "crypto/nss_util.h" | 28 #include "crypto/nss_util.h" |
| 26 #include "crypto/nss_util_internal.h" | 29 #include "crypto/nss_util_internal.h" |
| 27 #include "crypto/rsa_private_key.h" | 30 #include "crypto/rsa_private_key.h" |
| 28 #include "crypto/scoped_nss_types.h" | 31 #include "crypto/scoped_nss_types.h" |
| 29 #include "crypto/signature_creator.h" | 32 #include "crypto/signature_creator.h" |
| 30 | 33 |
| 31 namespace em = enterprise_management; | 34 namespace em = enterprise_management; |
| 32 | 35 |
| 33 using content::BrowserThread; | 36 using content::BrowserThread; |
| 37 using ownership::OwnerKeyUtil; |
| 38 using ownership::PrivateKey; |
| 39 using ownership::PublicKey; |
| 34 | 40 |
| 35 namespace chromeos { | 41 namespace chromeos { |
| 36 | 42 |
| 37 namespace { | 43 namespace { |
| 38 | 44 |
| 39 scoped_refptr<OwnerKeyUtil>* g_owner_key_util_for_testing = NULL; | 45 scoped_refptr<OwnerKeyUtil>* g_owner_key_util_for_testing = NULL; |
| 40 DeviceSettingsService* g_device_settings_service_for_testing = NULL; | 46 DeviceSettingsService* g_device_settings_service_for_testing = NULL; |
| 41 | 47 |
| 42 bool IsOwnerInTests(const std::string& user_id) { | 48 bool IsOwnerInTests(const std::string& user_id) { |
| 43 if (user_id.empty() || | 49 if (user_id.empty() || |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 } | 175 } |
| 170 | 176 |
| 171 // Checks whether NSS slots with private key are mounted or | 177 // Checks whether NSS slots with private key are mounted or |
| 172 // not. Responds via |callback|. | 178 // not. Responds via |callback|. |
| 173 void DoesPrivateKeyExistAsync( | 179 void DoesPrivateKeyExistAsync( |
| 174 const OwnerSettingsService::IsOwnerCallback& callback) { | 180 const OwnerSettingsService::IsOwnerCallback& callback) { |
| 175 scoped_refptr<OwnerKeyUtil> owner_key_util; | 181 scoped_refptr<OwnerKeyUtil> owner_key_util; |
| 176 if (g_owner_key_util_for_testing) | 182 if (g_owner_key_util_for_testing) |
| 177 owner_key_util = *g_owner_key_util_for_testing; | 183 owner_key_util = *g_owner_key_util_for_testing; |
| 178 else | 184 else |
| 179 owner_key_util = OwnerKeyUtil::Create(); | 185 owner_key_util = OwnerSettingsService::MakeOwnerKeyUtil(); |
| 186 if (!owner_key_util) { |
| 187 callback.Run(false); |
| 188 return; |
| 189 } |
| 180 scoped_refptr<base::TaskRunner> task_runner = | 190 scoped_refptr<base::TaskRunner> task_runner = |
| 181 content::BrowserThread::GetBlockingPool() | 191 content::BrowserThread::GetBlockingPool() |
| 182 ->GetTaskRunnerWithShutdownBehavior( | 192 ->GetTaskRunnerWithShutdownBehavior( |
| 183 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 193 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 184 base::PostTaskAndReplyWithResult( | 194 base::PostTaskAndReplyWithResult( |
| 185 task_runner.get(), | 195 task_runner.get(), |
| 186 FROM_HERE, | 196 FROM_HERE, |
| 187 base::Bind(&DoesPrivateKeyExistAsyncHelper, owner_key_util), | 197 base::Bind(&DoesPrivateKeyExistAsyncHelper, owner_key_util), |
| 188 callback); | 198 callback); |
| 189 } | 199 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } | 235 } |
| 226 | 236 |
| 227 NOTREACHED(); | 237 NOTREACHED(); |
| 228 return false; | 238 return false; |
| 229 } | 239 } |
| 230 | 240 |
| 231 } // namespace | 241 } // namespace |
| 232 | 242 |
| 233 OwnerSettingsService::OwnerSettingsService(Profile* profile) | 243 OwnerSettingsService::OwnerSettingsService(Profile* profile) |
| 234 : profile_(profile), | 244 : profile_(profile), |
| 235 owner_key_util_(OwnerKeyUtil::Create()), | 245 owner_key_util_(MakeOwnerKeyUtil()), |
| 236 waiting_for_profile_creation_(true), | 246 waiting_for_profile_creation_(true), |
| 237 waiting_for_tpm_token_(true), | 247 waiting_for_tpm_token_(true), |
| 238 weak_factory_(this) { | 248 weak_factory_(this) { |
| 239 if (TPMTokenLoader::IsInitialized()) { | 249 if (TPMTokenLoader::IsInitialized()) { |
| 240 waiting_for_tpm_token_ = !TPMTokenLoader::Get()->IsTPMTokenReady(); | 250 waiting_for_tpm_token_ = !TPMTokenLoader::Get()->IsTPMTokenReady(); |
| 241 TPMTokenLoader::Get()->AddObserver(this); | 251 TPMTokenLoader::Get()->AddObserver(this); |
| 242 } | 252 } |
| 243 | 253 |
| 244 if (DBusThreadManager::IsInitialized() && | 254 if (DBusThreadManager::IsInitialized() && |
| 245 DBusThreadManager::Get()->GetSessionManagerClient()) { | 255 DBusThreadManager::Get()->GetSessionManagerClient()) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 BrowserThread::IO, | 393 BrowserThread::IO, |
| 384 FROM_HERE, | 394 FROM_HERE, |
| 385 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser), | 395 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser), |
| 386 user_id, | 396 user_id, |
| 387 user_hash, | 397 user_hash, |
| 388 ProfileHelper::GetProfilePathByUserIdHash(user_hash)), | 398 ProfileHelper::GetProfilePathByUserIdHash(user_hash)), |
| 389 base::Bind(&DoesPrivateKeyExistAsync, callback)); | 399 base::Bind(&DoesPrivateKeyExistAsync, callback)); |
| 390 } | 400 } |
| 391 | 401 |
| 392 // static | 402 // static |
| 403 scoped_refptr<ownership::OwnerKeyUtil> |
| 404 OwnerSettingsService::MakeOwnerKeyUtil() { |
| 405 base::FilePath public_key_path; |
| 406 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &public_key_path)) |
| 407 return NULL; |
| 408 return new OwnerKeyUtil(public_key_path); |
| 409 } |
| 410 |
| 411 // static |
| 393 void OwnerSettingsService::SetOwnerKeyUtilForTesting( | 412 void OwnerSettingsService::SetOwnerKeyUtilForTesting( |
| 394 const scoped_refptr<OwnerKeyUtil>& owner_key_util) { | 413 const scoped_refptr<OwnerKeyUtil>& owner_key_util) { |
| 395 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 396 if (g_owner_key_util_for_testing) { | 415 if (g_owner_key_util_for_testing) { |
| 397 delete g_owner_key_util_for_testing; | 416 delete g_owner_key_util_for_testing; |
| 398 g_owner_key_util_for_testing = NULL; | 417 g_owner_key_util_for_testing = NULL; |
| 399 } | 418 } |
| 400 if (owner_key_util.get()) { | 419 if (owner_key_util.get()) { |
| 401 g_owner_key_util_for_testing = new scoped_refptr<OwnerKeyUtil>(); | 420 g_owner_key_util_for_testing = new scoped_refptr<OwnerKeyUtil>(); |
| 402 *g_owner_key_util_for_testing = owner_key_util; | 421 *g_owner_key_util_for_testing = owner_key_util; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 DeviceSettingsService* OwnerSettingsService::GetDeviceSettingsService() { | 539 DeviceSettingsService* OwnerSettingsService::GetDeviceSettingsService() { |
| 521 DCHECK(thread_checker_.CalledOnValidThread()); | 540 DCHECK(thread_checker_.CalledOnValidThread()); |
| 522 if (g_device_settings_service_for_testing) | 541 if (g_device_settings_service_for_testing) |
| 523 return g_device_settings_service_for_testing; | 542 return g_device_settings_service_for_testing; |
| 524 if (DeviceSettingsService::IsInitialized()) | 543 if (DeviceSettingsService::IsInitialized()) |
| 525 return DeviceSettingsService::Get(); | 544 return DeviceSettingsService::Get(); |
| 526 return NULL; | 545 return NULL; |
| 527 } | 546 } |
| 528 | 547 |
| 529 } // namespace chromeos | 548 } // namespace chromeos |
| OLD | NEW |