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 |
48 scoped_refptr<ownership::OwnerKeyUtil> MakeOwnerKeyUtil() { | |
49 base::FilePath public_key_path; | |
50 if (!PathService::Get(chromeos::FILE_OWNER_KEY, &public_key_path)) | |
51 return NULL; | |
52 return OwnerKeyUtil::Create(public_key_path); | |
53 } | |
stevenjb
2014/08/26 16:02:12
So, while I do like removing the reference to chro
ygorshenin1
2014/08/26 16:31:16
Done.
| |
54 | |
42 bool IsOwnerInTests(const std::string& user_id) { | 55 bool IsOwnerInTests(const std::string& user_id) { |
43 if (user_id.empty() || | 56 if (user_id.empty() || |
44 !CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType) || | 57 !CommandLine::ForCurrentProcess()->HasSwitch(::switches::kTestType) || |
45 !CrosSettings::IsInitialized()) { | 58 !CrosSettings::IsInitialized()) { |
46 return false; | 59 return false; |
47 } | 60 } |
48 const base::Value* value = CrosSettings::Get()->GetPref(kDeviceOwner); | 61 const base::Value* value = CrosSettings::Get()->GetPref(kDeviceOwner); |
49 if (!value || value->GetType() != base::Value::TYPE_STRING) | 62 if (!value || value->GetType() != base::Value::TYPE_STRING) |
50 return false; | 63 return false; |
51 return static_cast<const base::StringValue*>(value)->GetString() == user_id; | 64 return static_cast<const base::StringValue*>(value)->GetString() == user_id; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 } | 182 } |
170 | 183 |
171 // Checks whether NSS slots with private key are mounted or | 184 // Checks whether NSS slots with private key are mounted or |
172 // not. Responds via |callback|. | 185 // not. Responds via |callback|. |
173 void DoesPrivateKeyExistAsync( | 186 void DoesPrivateKeyExistAsync( |
174 const OwnerSettingsService::IsOwnerCallback& callback) { | 187 const OwnerSettingsService::IsOwnerCallback& callback) { |
175 scoped_refptr<OwnerKeyUtil> owner_key_util; | 188 scoped_refptr<OwnerKeyUtil> owner_key_util; |
176 if (g_owner_key_util_for_testing) | 189 if (g_owner_key_util_for_testing) |
177 owner_key_util = *g_owner_key_util_for_testing; | 190 owner_key_util = *g_owner_key_util_for_testing; |
178 else | 191 else |
179 owner_key_util = OwnerKeyUtil::Create(); | 192 owner_key_util = MakeOwnerKeyUtil(); |
193 if (!owner_key_util) { | |
194 callback.Run(false); | |
195 return; | |
196 } | |
180 scoped_refptr<base::TaskRunner> task_runner = | 197 scoped_refptr<base::TaskRunner> task_runner = |
181 content::BrowserThread::GetBlockingPool() | 198 content::BrowserThread::GetBlockingPool() |
182 ->GetTaskRunnerWithShutdownBehavior( | 199 ->GetTaskRunnerWithShutdownBehavior( |
183 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 200 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
184 base::PostTaskAndReplyWithResult( | 201 base::PostTaskAndReplyWithResult( |
185 task_runner.get(), | 202 task_runner.get(), |
186 FROM_HERE, | 203 FROM_HERE, |
187 base::Bind(&DoesPrivateKeyExistAsyncHelper, owner_key_util), | 204 base::Bind(&DoesPrivateKeyExistAsyncHelper, owner_key_util), |
188 callback); | 205 callback); |
189 } | 206 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 } | 242 } |
226 | 243 |
227 NOTREACHED(); | 244 NOTREACHED(); |
228 return false; | 245 return false; |
229 } | 246 } |
230 | 247 |
231 } // namespace | 248 } // namespace |
232 | 249 |
233 OwnerSettingsService::OwnerSettingsService(Profile* profile) | 250 OwnerSettingsService::OwnerSettingsService(Profile* profile) |
234 : profile_(profile), | 251 : profile_(profile), |
235 owner_key_util_(OwnerKeyUtil::Create()), | 252 owner_key_util_(MakeOwnerKeyUtil()), |
236 waiting_for_profile_creation_(true), | 253 waiting_for_profile_creation_(true), |
237 waiting_for_tpm_token_(true), | 254 waiting_for_tpm_token_(true), |
238 weak_factory_(this) { | 255 weak_factory_(this) { |
239 if (TPMTokenLoader::IsInitialized()) { | 256 if (TPMTokenLoader::IsInitialized()) { |
240 waiting_for_tpm_token_ = !TPMTokenLoader::Get()->IsTPMTokenReady(); | 257 waiting_for_tpm_token_ = !TPMTokenLoader::Get()->IsTPMTokenReady(); |
241 TPMTokenLoader::Get()->AddObserver(this); | 258 TPMTokenLoader::Get()->AddObserver(this); |
242 } | 259 } |
243 | 260 |
244 if (DBusThreadManager::IsInitialized() && | 261 if (DBusThreadManager::IsInitialized() && |
245 DBusThreadManager::Get()->GetSessionManagerClient()) { | 262 DBusThreadManager::Get()->GetSessionManagerClient()) { |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 DeviceSettingsService* OwnerSettingsService::GetDeviceSettingsService() { | 537 DeviceSettingsService* OwnerSettingsService::GetDeviceSettingsService() { |
521 DCHECK(thread_checker_.CalledOnValidThread()); | 538 DCHECK(thread_checker_.CalledOnValidThread()); |
522 if (g_device_settings_service_for_testing) | 539 if (g_device_settings_service_for_testing) |
523 return g_device_settings_service_for_testing; | 540 return g_device_settings_service_for_testing; |
524 if (DeviceSettingsService::IsInitialized()) | 541 if (DeviceSettingsService::IsInitialized()) |
525 return DeviceSettingsService::Get(); | 542 return DeviceSettingsService::Get(); |
526 return NULL; | 543 return NULL; |
527 } | 544 } |
528 | 545 |
529 } // namespace chromeos | 546 } // namespace chromeos |
OLD | NEW |