| 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 "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/chromeos/login/users/user.h" | 12 #include "chrome/browser/chromeos/login/users/user.h" |
| 12 #include "chrome/browser/chromeos/login/users/user_manager.h" | 13 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 13 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" | 14 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" |
| 14 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/notification_details.h" | 18 #include "content/public/browser/notification_details.h" |
| 18 #include "content/public/browser/notification_source.h" | 19 #include "content/public/browser/notification_source.h" |
| 19 #include "crypto/nss_util.h" | 20 #include "crypto/nss_util.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 username_hash, | 96 username_hash, |
| 96 callback)); | 97 callback)); |
| 97 if (!rv) { | 98 if (!rv) { |
| 98 // IO thread doesn't exists in unit tests, but it's safe to use NSS from | 99 // IO thread doesn't exists in unit tests, but it's safe to use NSS from |
| 99 // BlockingPool in unit tests. | 100 // BlockingPool in unit tests. |
| 100 LoadPrivateKeyByPublicKey( | 101 LoadPrivateKeyByPublicKey( |
| 101 owner_key_util, public_key, username_hash, callback); | 102 owner_key_util, public_key, username_hash, callback); |
| 102 } | 103 } |
| 103 } | 104 } |
| 104 | 105 |
| 105 bool IsPrivateKeyExistAsyncHelper( | 106 bool DoesPrivateKeyExistAsyncHelper( |
| 106 const scoped_refptr<OwnerKeyUtil>& owner_key_util) { | 107 const scoped_refptr<OwnerKeyUtil>& owner_key_util) { |
| 107 std::vector<uint8> public_key; | 108 std::vector<uint8> public_key; |
| 108 if (!owner_key_util->ImportPublicKey(&public_key)) | 109 if (!owner_key_util->ImportPublicKey(&public_key)) |
| 109 return false; | 110 return false; |
| 110 scoped_ptr<crypto::RSAPrivateKey> key( | 111 scoped_ptr<crypto::RSAPrivateKey> key( |
| 111 crypto::RSAPrivateKey::FindFromPublicKeyInfo(public_key)); | 112 crypto::RSAPrivateKey::FindFromPublicKeyInfo(public_key)); |
| 112 bool is_owner = key.get() != NULL; | 113 bool is_owner = key.get() != NULL; |
| 113 return is_owner; | 114 return is_owner; |
| 114 } | 115 } |
| 115 | 116 |
| 117 // Checks whether NSS slots with private key are mounted or |
| 118 // not. Responds via |callback|. |
| 119 void DoesPrivateKeyExistAsync( |
| 120 const OwnerSettingsService::IsOwnerCallback& callback) { |
| 121 scoped_refptr<OwnerKeyUtil> owner_key_util; |
| 122 if (g_owner_key_util_for_testing) |
| 123 owner_key_util = *g_owner_key_util_for_testing; |
| 124 else |
| 125 owner_key_util = OwnerKeyUtil::Create(); |
| 126 scoped_refptr<base::TaskRunner> task_runner = |
| 127 content::BrowserThread::GetBlockingPool() |
| 128 ->GetTaskRunnerWithShutdownBehavior( |
| 129 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 130 base::PostTaskAndReplyWithResult( |
| 131 task_runner.get(), |
| 132 FROM_HERE, |
| 133 base::Bind(&DoesPrivateKeyExistAsyncHelper, owner_key_util), |
| 134 callback); |
| 135 } |
| 136 |
| 116 } // namespace | 137 } // namespace |
| 117 | 138 |
| 118 OwnerSettingsService::OwnerSettingsService(Profile* profile) | 139 OwnerSettingsService::OwnerSettingsService(Profile* profile) |
| 119 : profile_(profile), | 140 : profile_(profile), |
| 120 owner_key_util_(OwnerKeyUtil::Create()), | 141 owner_key_util_(OwnerKeyUtil::Create()), |
| 121 waiting_for_profile_creation_(true), | 142 waiting_for_profile_creation_(true), |
| 122 waiting_for_tpm_token_(true), | 143 waiting_for_tpm_token_(true), |
| 123 weak_factory_(this) { | 144 weak_factory_(this) { |
| 124 if (TPMTokenLoader::IsInitialized()) { | 145 if (TPMTokenLoader::IsInitialized()) { |
| 125 waiting_for_tpm_token_ = !TPMTokenLoader::Get()->IsTPMTokenReady(); | 146 waiting_for_tpm_token_ = !TPMTokenLoader::Get()->IsTPMTokenReady(); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 void OwnerSettingsService::OnTPMTokenReady() { | 211 void OwnerSettingsService::OnTPMTokenReady() { |
| 191 DCHECK(thread_checker_.CalledOnValidThread()); | 212 DCHECK(thread_checker_.CalledOnValidThread()); |
| 192 waiting_for_tpm_token_ = false; | 213 waiting_for_tpm_token_ = false; |
| 193 | 214 |
| 194 // TPMTokenLoader initializes the TPM and NSS database which is necessary to | 215 // TPMTokenLoader initializes the TPM and NSS database which is necessary to |
| 195 // determine ownership. Force a reload once we know these are initialized. | 216 // determine ownership. Force a reload once we know these are initialized. |
| 196 ReloadPrivateKey(); | 217 ReloadPrivateKey(); |
| 197 } | 218 } |
| 198 | 219 |
| 199 // static | 220 // static |
| 200 void OwnerSettingsService::IsPrivateKeyExistAsync( | 221 void OwnerSettingsService::IsOwnerForSafeModeAsync( |
| 222 const std::string& user_id, |
| 223 const std::string& user_hash, |
| 201 const IsOwnerCallback& callback) { | 224 const IsOwnerCallback& callback) { |
| 202 scoped_refptr<OwnerKeyUtil> owner_key_util; | 225 CHECK(chromeos::LoginState::Get()->IsInSafeMode()); |
| 203 if (g_owner_key_util_for_testing) | 226 |
| 204 owner_key_util = *g_owner_key_util_for_testing; | 227 // Make sure NSS is initialized and NSS DB is loaded for the user before |
| 205 else | 228 // searching for the owner key. |
| 206 owner_key_util = OwnerKeyUtil::Create(); | 229 BrowserThread::PostTaskAndReply( |
| 207 scoped_refptr<base::TaskRunner> task_runner = | 230 BrowserThread::IO, |
| 208 content::BrowserThread::GetBlockingPool() | |
| 209 ->GetTaskRunnerWithShutdownBehavior( | |
| 210 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | |
| 211 base::PostTaskAndReplyWithResult( | |
| 212 task_runner.get(), | |
| 213 FROM_HERE, | 231 FROM_HERE, |
| 214 base::Bind(&IsPrivateKeyExistAsyncHelper, owner_key_util), | 232 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser), |
| 215 callback); | 233 user_id, |
| 234 user_hash, |
| 235 ProfileHelper::GetProfilePathByUserIdHash(user_hash)), |
| 236 base::Bind(&DoesPrivateKeyExistAsync, callback)); |
| 216 } | 237 } |
| 217 | 238 |
| 218 // static | 239 // static |
| 219 void OwnerSettingsService::SetOwnerKeyUtilForTesting( | 240 void OwnerSettingsService::SetOwnerKeyUtilForTesting( |
| 220 const scoped_refptr<OwnerKeyUtil>& owner_key_util) { | 241 const scoped_refptr<OwnerKeyUtil>& owner_key_util) { |
| 221 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 222 if (g_owner_key_util_for_testing) { | 243 if (g_owner_key_util_for_testing) { |
| 223 delete g_owner_key_util_for_testing; | 244 delete g_owner_key_util_for_testing; |
| 224 g_owner_key_util_for_testing = NULL; | 245 g_owner_key_util_for_testing = NULL; |
| 225 } | 246 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 DeviceSettingsService* OwnerSettingsService::GetDeviceSettingsService() { | 303 DeviceSettingsService* OwnerSettingsService::GetDeviceSettingsService() { |
| 283 DCHECK(thread_checker_.CalledOnValidThread()); | 304 DCHECK(thread_checker_.CalledOnValidThread()); |
| 284 if (g_device_settings_service_for_testing) | 305 if (g_device_settings_service_for_testing) |
| 285 return g_device_settings_service_for_testing; | 306 return g_device_settings_service_for_testing; |
| 286 if (DeviceSettingsService::IsInitialized()) | 307 if (DeviceSettingsService::IsInitialized()) |
| 287 return DeviceSettingsService::Get(); | 308 return DeviceSettingsService::Get(); |
| 288 return NULL; | 309 return NULL; |
| 289 } | 310 } |
| 290 | 311 |
| 291 } // namespace chromeos | 312 } // namespace chromeos |
| OLD | NEW |