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 "base/prefs/pref_service.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" | 14 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" |
16 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
17 #include "chrome/browser/chromeos/settings/cros_settings.h" | 16 #include "chrome/browser/chromeos/settings/cros_settings.h" |
18 #include "chrome/browser/chromeos/settings/session_manager_operation.h" | 17 #include "chrome/browser/chromeos/settings/session_manager_operation.h" |
19 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
20 #include "chromeos/chromeos_paths.h" | |
21 #include "chromeos/dbus/dbus_thread_manager.h" | 19 #include "chromeos/dbus/dbus_thread_manager.h" |
22 #include "components/ownership/owner_key_util_impl.h" | |
23 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 20 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
24 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
26 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
27 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
28 #include "content/public/common/content_switches.h" | 25 #include "content/public/common/content_switches.h" |
29 #include "crypto/nss_util.h" | 26 #include "crypto/nss_util.h" |
30 #include "crypto/nss_util_internal.h" | 27 #include "crypto/nss_util_internal.h" |
31 #include "crypto/rsa_private_key.h" | 28 #include "crypto/rsa_private_key.h" |
32 #include "crypto/scoped_nss_types.h" | 29 #include "crypto/scoped_nss_types.h" |
33 #include "crypto/signature_creator.h" | 30 #include "crypto/signature_creator.h" |
34 | 31 |
35 namespace em = enterprise_management; | 32 namespace em = enterprise_management; |
36 | 33 |
37 using content::BrowserThread; | 34 using content::BrowserThread; |
38 using ownership::OwnerKeyUtil; | 35 using ownership::OwnerKeyUtil; |
39 using ownership::PrivateKey; | 36 using ownership::PrivateKey; |
40 using ownership::PublicKey; | 37 using ownership::PublicKey; |
41 | 38 |
42 namespace chromeos { | 39 namespace chromeos { |
43 | 40 |
44 namespace { | 41 namespace { |
45 | 42 |
46 scoped_refptr<OwnerKeyUtil>* g_owner_key_util_for_testing = NULL; | |
47 DeviceSettingsService* g_device_settings_service_for_testing = NULL; | 43 DeviceSettingsService* g_device_settings_service_for_testing = NULL; |
48 | 44 |
49 bool IsOwnerInTests(const std::string& user_id) { | 45 bool IsOwnerInTests(const std::string& user_id) { |
50 if (user_id.empty() || | 46 if (user_id.empty() || |
51 !CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType) || | 47 !CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType) || |
52 !CrosSettings::IsInitialized()) { | 48 !CrosSettings::IsInitialized()) { |
53 return false; | 49 return false; |
54 } | 50 } |
55 const base::Value* value = CrosSettings::Get()->GetPref(kDeviceOwner); | 51 const base::Value* value = CrosSettings::Get()->GetPref(kDeviceOwner); |
56 if (!value || value->GetType() != base::Value::TYPE_STRING) | 52 if (!value || value->GetType() != base::Value::TYPE_STRING) |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 scoped_ptr<crypto::RSAPrivateKey> key( | 168 scoped_ptr<crypto::RSAPrivateKey> key( |
173 crypto::RSAPrivateKey::FindFromPublicKeyInfo(public_key)); | 169 crypto::RSAPrivateKey::FindFromPublicKeyInfo(public_key)); |
174 bool is_owner = key.get() != NULL; | 170 bool is_owner = key.get() != NULL; |
175 return is_owner; | 171 return is_owner; |
176 } | 172 } |
177 | 173 |
178 // Checks whether NSS slots with private key are mounted or | 174 // Checks whether NSS slots with private key are mounted or |
179 // not. Responds via |callback|. | 175 // not. Responds via |callback|. |
180 void DoesPrivateKeyExistAsync( | 176 void DoesPrivateKeyExistAsync( |
181 const OwnerSettingsService::IsOwnerCallback& callback) { | 177 const OwnerSettingsService::IsOwnerCallback& callback) { |
182 scoped_refptr<OwnerKeyUtil> owner_key_util; | 178 scoped_refptr<OwnerKeyUtil> owner_key_util = |
183 if (g_owner_key_util_for_testing) | 179 OwnerSettingsServiceFactory::GetInstance()->GetOwnerKeyUtil(); |
erikwright (departed)
2014/09/02 19:13:56
This circular dependency between the factory and t
ygorshenin1
2014/09/03 10:14:58
I agree with you that we need to get rid of the ci
erikwright (departed)
2014/09/03 14:07:16
In my first reading I thought you were using a Pro
| |
184 owner_key_util = *g_owner_key_util_for_testing; | 180 |
185 else | |
186 owner_key_util = OwnerSettingsService::MakeOwnerKeyUtil(); | |
187 if (!owner_key_util) { | 181 if (!owner_key_util) { |
188 callback.Run(false); | 182 callback.Run(false); |
189 return; | 183 return; |
190 } | 184 } |
191 scoped_refptr<base::TaskRunner> task_runner = | 185 scoped_refptr<base::TaskRunner> task_runner = |
192 content::BrowserThread::GetBlockingPool() | 186 content::BrowserThread::GetBlockingPool() |
193 ->GetTaskRunnerWithShutdownBehavior( | 187 ->GetTaskRunnerWithShutdownBehavior( |
194 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 188 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
195 base::PostTaskAndReplyWithResult( | 189 base::PostTaskAndReplyWithResult( |
196 task_runner.get(), | 190 task_runner.get(), |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
234 // For consumer management unenrollment. | 228 // For consumer management unenrollment. |
235 return new_mode == em::PolicyData::NOT_MANAGED; | 229 return new_mode == em::PolicyData::NOT_MANAGED; |
236 } | 230 } |
237 | 231 |
238 NOTREACHED(); | 232 NOTREACHED(); |
239 return false; | 233 return false; |
240 } | 234 } |
241 | 235 |
242 } // namespace | 236 } // namespace |
243 | 237 |
244 OwnerSettingsService::OwnerSettingsService(Profile* profile) | 238 OwnerSettingsService::OwnerSettingsService( |
239 Profile* profile, | |
240 const scoped_refptr<OwnerKeyUtil>& owner_key_util) | |
245 : profile_(profile), | 241 : profile_(profile), |
246 owner_key_util_(MakeOwnerKeyUtil()), | 242 owner_key_util_(owner_key_util), |
247 waiting_for_profile_creation_(true), | 243 waiting_for_profile_creation_(true), |
248 waiting_for_tpm_token_(true), | 244 waiting_for_tpm_token_(true), |
249 weak_factory_(this) { | 245 weak_factory_(this) { |
250 if (TPMTokenLoader::IsInitialized()) { | 246 if (TPMTokenLoader::IsInitialized()) { |
251 waiting_for_tpm_token_ = !TPMTokenLoader::Get()->IsTPMTokenReady(); | 247 waiting_for_tpm_token_ = !TPMTokenLoader::Get()->IsTPMTokenReady(); |
252 TPMTokenLoader::Get()->AddObserver(this); | 248 TPMTokenLoader::Get()->AddObserver(this); |
253 } | 249 } |
254 | 250 |
255 if (DBusThreadManager::IsInitialized() && | 251 if (DBusThreadManager::IsInitialized() && |
256 DBusThreadManager::Get()->GetSessionManagerClient()) { | 252 DBusThreadManager::Get()->GetSessionManagerClient()) { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 BrowserThread::IO, | 390 BrowserThread::IO, |
395 FROM_HERE, | 391 FROM_HERE, |
396 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser), | 392 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser), |
397 user_id, | 393 user_id, |
398 user_hash, | 394 user_hash, |
399 ProfileHelper::GetProfilePathByUserIdHash(user_hash)), | 395 ProfileHelper::GetProfilePathByUserIdHash(user_hash)), |
400 base::Bind(&DoesPrivateKeyExistAsync, callback)); | 396 base::Bind(&DoesPrivateKeyExistAsync, callback)); |
401 } | 397 } |
402 | 398 |
403 // static | 399 // 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 | |
413 void OwnerSettingsService::SetOwnerKeyUtilForTesting( | |
414 const scoped_refptr<OwnerKeyUtil>& owner_key_util) { | |
415 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
416 if (g_owner_key_util_for_testing) { | |
417 delete g_owner_key_util_for_testing; | |
418 g_owner_key_util_for_testing = NULL; | |
419 } | |
420 if (owner_key_util.get()) { | |
421 g_owner_key_util_for_testing = new scoped_refptr<OwnerKeyUtil>(); | |
422 *g_owner_key_util_for_testing = owner_key_util; | |
423 } | |
424 } | |
425 | |
426 // static | |
427 void OwnerSettingsService::SetDeviceSettingsServiceForTesting( | 400 void OwnerSettingsService::SetDeviceSettingsServiceForTesting( |
428 DeviceSettingsService* device_settings_service) { | 401 DeviceSettingsService* device_settings_service) { |
429 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 402 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
430 g_device_settings_service_for_testing = device_settings_service; | 403 g_device_settings_service_for_testing = device_settings_service; |
431 } | 404 } |
432 | 405 |
433 void OwnerSettingsService::ReloadPrivateKey() { | 406 void OwnerSettingsService::ReloadPrivateKey() { |
434 DCHECK(thread_checker_.CalledOnValidThread()); | 407 DCHECK(thread_checker_.CalledOnValidThread()); |
435 if (waiting_for_profile_creation_ || waiting_for_tpm_token_) | 408 if (waiting_for_profile_creation_ || waiting_for_tpm_token_) |
436 return; | 409 return; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
525 void OwnerSettingsService::HandleError(DeviceSettingsService::Status status, | 498 void OwnerSettingsService::HandleError(DeviceSettingsService::Status status, |
526 const base::Closure& callback) { | 499 const base::Closure& callback) { |
527 LOG(ERROR) << "Session manager operation failed: " << status; | 500 LOG(ERROR) << "Session manager operation failed: " << status; |
528 GetDeviceSettingsService()->OnSignAndStoreOperationCompleted(status); | 501 GetDeviceSettingsService()->OnSignAndStoreOperationCompleted(status); |
529 if (!callback.is_null()) | 502 if (!callback.is_null()) |
530 callback.Run(); | 503 callback.Run(); |
531 } | 504 } |
532 | 505 |
533 scoped_refptr<OwnerKeyUtil> OwnerSettingsService::GetOwnerKeyUtil() { | 506 scoped_refptr<OwnerKeyUtil> OwnerSettingsService::GetOwnerKeyUtil() { |
534 DCHECK(thread_checker_.CalledOnValidThread()); | 507 DCHECK(thread_checker_.CalledOnValidThread()); |
535 if (g_owner_key_util_for_testing) | |
536 return *g_owner_key_util_for_testing; | |
537 return owner_key_util_; | 508 return owner_key_util_; |
538 } | 509 } |
539 | 510 |
540 DeviceSettingsService* OwnerSettingsService::GetDeviceSettingsService() { | 511 DeviceSettingsService* OwnerSettingsService::GetDeviceSettingsService() { |
541 DCHECK(thread_checker_.CalledOnValidThread()); | 512 DCHECK(thread_checker_.CalledOnValidThread()); |
542 if (g_device_settings_service_for_testing) | 513 if (g_device_settings_service_for_testing) |
543 return g_device_settings_service_for_testing; | 514 return g_device_settings_service_for_testing; |
544 if (DeviceSettingsService::IsInitialized()) | 515 if (DeviceSettingsService::IsInitialized()) |
545 return DeviceSettingsService::Get(); | 516 return DeviceSettingsService::Get(); |
546 return NULL; | 517 return NULL; |
547 } | 518 } |
548 | 519 |
549 } // namespace chromeos | 520 } // namespace chromeos |
OLD | NEW |