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 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 } | 413 } |
404 } | 414 } |
405 | 415 |
406 // static | 416 // static |
407 void OwnerSettingsService::SetDeviceSettingsServiceForTesting( | 417 void OwnerSettingsService::SetDeviceSettingsServiceForTesting( |
408 DeviceSettingsService* device_settings_service) { | 418 DeviceSettingsService* device_settings_service) { |
409 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
410 g_device_settings_service_for_testing = device_settings_service; | 420 g_device_settings_service_for_testing = device_settings_service; |
411 } | 421 } |
412 | 422 |
| 423 // static |
| 424 scoped_refptr<ownership::OwnerKeyUtil> |
| 425 OwnerSettingsService::MakeOwnerKeyUtil() { |
| 426 base::FilePath public_key_path; |
| 427 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &public_key_path)) |
| 428 return NULL; |
| 429 return OwnerKeyUtil::Create(public_key_path); |
| 430 } |
| 431 |
413 void OwnerSettingsService::ReloadPrivateKey() { | 432 void OwnerSettingsService::ReloadPrivateKey() { |
414 DCHECK(thread_checker_.CalledOnValidThread()); | 433 DCHECK(thread_checker_.CalledOnValidThread()); |
415 if (waiting_for_profile_creation_ || waiting_for_tpm_token_) | 434 if (waiting_for_profile_creation_ || waiting_for_tpm_token_) |
416 return; | 435 return; |
417 scoped_refptr<base::TaskRunner> task_runner = | 436 scoped_refptr<base::TaskRunner> task_runner = |
418 content::BrowserThread::GetBlockingPool() | 437 content::BrowserThread::GetBlockingPool() |
419 ->GetTaskRunnerWithShutdownBehavior( | 438 ->GetTaskRunnerWithShutdownBehavior( |
420 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 439 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
421 task_runner->PostTask( | 440 task_runner->PostTask( |
422 FROM_HERE, | 441 FROM_HERE, |
(...skipping 97 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 |