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