Chromium Code Reviews| 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_chromeos.h" | 5 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
| 6 | 6 |
| 7 #include <keyhi.h> | 7 #include <keyhi.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 | 41 |
| 42 using content::BrowserThread; | 42 using content::BrowserThread; |
| 43 using ownership::OwnerKeyUtil; | 43 using ownership::OwnerKeyUtil; |
| 44 using ownership::PrivateKey; | 44 using ownership::PrivateKey; |
| 45 using ownership::PublicKey; | 45 using ownership::PublicKey; |
| 46 | 46 |
| 47 namespace chromeos { | 47 namespace chromeos { |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 bool IsOwnerInTests(const std::string& user_id) { | 51 bool IsOwnerInTests(const user_manager::UserID& user_id) { |
| 52 if (user_id.empty() || | 52 if (user_id.empty() || |
| 53 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 53 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 54 ::switches::kTestType) || | 54 ::switches::kTestType) || |
| 55 !CrosSettings::IsInitialized()) { | 55 !CrosSettings::IsInitialized()) { |
| 56 return false; | 56 return false; |
| 57 } | 57 } |
| 58 const base::Value* value = CrosSettings::Get()->GetPref(kDeviceOwner); | 58 const base::Value* value = CrosSettings::Get()->GetPref(kDeviceOwner); |
| 59 if (!value || value->GetType() != base::Value::TYPE_STRING) | 59 if (!value || value->GetType() != base::Value::TYPE_STRING) |
| 60 return false; | 60 return false; |
| 61 return static_cast<const base::StringValue*>(value)->GetString() == user_id; | 61 return static_cast<const base::StringValue*>(value)->GetString() == user_id.Ge tUserEmail(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void LoadPrivateKeyByPublicKey( | 64 void LoadPrivateKeyByPublicKey( |
| 65 const scoped_refptr<OwnerKeyUtil>& owner_key_util, | 65 const scoped_refptr<OwnerKeyUtil>& owner_key_util, |
| 66 scoped_refptr<PublicKey> public_key, | 66 scoped_refptr<PublicKey> public_key, |
| 67 const std::string& username_hash, | 67 const std::string& username_hash, |
| 68 const base::Callback<void(const scoped_refptr<PublicKey>& public_key, | 68 const base::Callback<void(const scoped_refptr<PublicKey>& public_key, |
| 69 const scoped_refptr<PrivateKey>& private_key)>& | 69 const scoped_refptr<PrivateKey>& private_key)>& |
| 70 callback) { | 70 callback) { |
| 71 crypto::EnsureNSSInit(); | 71 crypto::EnsureNSSInit(); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 OwnerSettingsServiceChromeOS::ManagementSettings::~ManagementSettings() { | 189 OwnerSettingsServiceChromeOS::ManagementSettings::~ManagementSettings() { |
| 190 } | 190 } |
| 191 | 191 |
| 192 OwnerSettingsServiceChromeOS::OwnerSettingsServiceChromeOS( | 192 OwnerSettingsServiceChromeOS::OwnerSettingsServiceChromeOS( |
| 193 DeviceSettingsService* device_settings_service, | 193 DeviceSettingsService* device_settings_service, |
| 194 Profile* profile, | 194 Profile* profile, |
| 195 const scoped_refptr<OwnerKeyUtil>& owner_key_util) | 195 const scoped_refptr<OwnerKeyUtil>& owner_key_util) |
| 196 : ownership::OwnerSettingsService(owner_key_util), | 196 : ownership::OwnerSettingsService(owner_key_util), |
| 197 device_settings_service_(device_settings_service), | 197 device_settings_service_(device_settings_service), |
| 198 profile_(profile), | 198 profile_(profile), |
| 199 user_id_(std::string(), std::string()), | |
|
Denis Kuznetsov (DE-MUC)
2015/06/10 16:50:45
EmptyUserId()
| |
| 199 waiting_for_profile_creation_(true), | 200 waiting_for_profile_creation_(true), |
| 200 waiting_for_tpm_token_(true), | 201 waiting_for_tpm_token_(true), |
| 201 has_pending_fixups_(false), | 202 has_pending_fixups_(false), |
| 202 has_pending_management_settings_(false), | 203 has_pending_management_settings_(false), |
| 203 weak_factory_(this), | 204 weak_factory_(this), |
| 204 store_settings_factory_(this) { | 205 store_settings_factory_(this) { |
| 205 if (TPMTokenLoader::IsInitialized()) { | 206 if (TPMTokenLoader::IsInitialized()) { |
| 206 TPMTokenLoader::TPMTokenStatus tpm_token_status = | 207 TPMTokenLoader::TPMTokenStatus tpm_token_status = |
| 207 TPMTokenLoader::Get()->IsTPMTokenEnabled( | 208 TPMTokenLoader::Get()->IsTPMTokenEnabled( |
| 208 base::Bind(&OwnerSettingsServiceChromeOS::OnTPMTokenReady, | 209 base::Bind(&OwnerSettingsServiceChromeOS::OnTPMTokenReady, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 276 em::ChromeDeviceSettingsProto settings; | 277 em::ChromeDeviceSettingsProto settings; |
| 277 if (tentative_settings_.get()) { | 278 if (tentative_settings_.get()) { |
| 278 settings = *tentative_settings_; | 279 settings = *tentative_settings_; |
| 279 } else if (device_settings_service_->status() == | 280 } else if (device_settings_service_->status() == |
| 280 DeviceSettingsService::STORE_SUCCESS && | 281 DeviceSettingsService::STORE_SUCCESS && |
| 281 device_settings_service_->device_settings()) { | 282 device_settings_service_->device_settings()) { |
| 282 settings = *device_settings_service_->device_settings(); | 283 settings = *device_settings_service_->device_settings(); |
| 283 } | 284 } |
| 284 UpdateDeviceSettings(setting, value, settings); | 285 UpdateDeviceSettings(setting, value, settings); |
| 285 em::PolicyData policy_data; | 286 em::PolicyData policy_data; |
| 286 policy_data.set_username(user_id_); | 287 policy_data.set_username(user_id_.GetUserEmail()); |
| 287 CHECK(settings.SerializeToString(policy_data.mutable_policy_value())); | 288 CHECK(settings.SerializeToString(policy_data.mutable_policy_value())); |
| 288 FOR_EACH_OBSERVER(OwnerSettingsService::Observer, observers_, | 289 FOR_EACH_OBSERVER(OwnerSettingsService::Observer, observers_, |
| 289 OnTentativeChangesInPolicy(policy_data)); | 290 OnTentativeChangesInPolicy(policy_data)); |
| 290 StorePendingChanges(); | 291 StorePendingChanges(); |
| 291 return true; | 292 return true; |
| 292 } | 293 } |
| 293 | 294 |
| 294 bool OwnerSettingsServiceChromeOS::AppendToList(const std::string& setting, | 295 bool OwnerSettingsServiceChromeOS::AppendToList(const std::string& setting, |
| 295 const base::Value& value) { | 296 const base::Value& value) { |
| 296 DCHECK(thread_checker_.CalledOnValidThread()); | 297 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 314 old_value ? static_cast<const base::ListValue*>(old_value)->DeepCopy() | 315 old_value ? static_cast<const base::ListValue*>(old_value)->DeepCopy() |
| 315 : new base::ListValue()); | 316 : new base::ListValue()); |
| 316 new_value->Remove(value, nullptr); | 317 new_value->Remove(value, nullptr); |
| 317 return Set(setting, *new_value); | 318 return Set(setting, *new_value); |
| 318 } | 319 } |
| 319 | 320 |
| 320 bool OwnerSettingsServiceChromeOS::CommitTentativeDeviceSettings( | 321 bool OwnerSettingsServiceChromeOS::CommitTentativeDeviceSettings( |
| 321 scoped_ptr<enterprise_management::PolicyData> policy) { | 322 scoped_ptr<enterprise_management::PolicyData> policy) { |
| 322 if (!IsOwner() && !IsOwnerInTests(user_id_)) | 323 if (!IsOwner() && !IsOwnerInTests(user_id_)) |
| 323 return false; | 324 return false; |
| 324 if (policy->username() != user_id_) { | 325 if (user_manager::UserID::FromUserEmail(policy->username()) != user_id_) { |
| 325 LOG(ERROR) << "Username mismatch: " << policy->username() << " vs. " | 326 LOG(ERROR) << "Username mismatch: " << policy->username() << " vs. " |
| 326 << user_id_; | 327 << user_id_.GetUserEmail(); |
| 327 return false; | 328 return false; |
| 328 } | 329 } |
| 329 tentative_settings_.reset(new em::ChromeDeviceSettingsProto); | 330 tentative_settings_.reset(new em::ChromeDeviceSettingsProto); |
| 330 CHECK(tentative_settings_->ParseFromString(policy->policy_value())); | 331 CHECK(tentative_settings_->ParseFromString(policy->policy_value())); |
| 331 StorePendingChanges(); | 332 StorePendingChanges(); |
| 332 return true; | 333 return true; |
| 333 } | 334 } |
| 334 | 335 |
| 335 void OwnerSettingsServiceChromeOS::Observe( | 336 void OwnerSettingsServiceChromeOS::Observe( |
| 336 int type, | 337 int type, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 BrowserThread::IO, | 418 BrowserThread::IO, |
| 418 FROM_HERE, | 419 FROM_HERE, |
| 419 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser), | 420 base::Bind(base::IgnoreResult(&crypto::InitializeNSSForChromeOSUser), |
| 420 user_hash, | 421 user_hash, |
| 421 ProfileHelper::GetProfilePathByUserIdHash(user_hash)), | 422 ProfileHelper::GetProfilePathByUserIdHash(user_hash)), |
| 422 base::Bind(&DoesPrivateKeyExistAsync, owner_key_util, callback)); | 423 base::Bind(&DoesPrivateKeyExistAsync, owner_key_util, callback)); |
| 423 } | 424 } |
| 424 | 425 |
| 425 // static | 426 // static |
| 426 scoped_ptr<em::PolicyData> OwnerSettingsServiceChromeOS::AssemblePolicy( | 427 scoped_ptr<em::PolicyData> OwnerSettingsServiceChromeOS::AssemblePolicy( |
| 427 const std::string& user_id, | 428 const user_manager::UserID& user_id, |
| 428 const em::PolicyData* policy_data, | 429 const em::PolicyData* policy_data, |
| 429 bool apply_pending_management_settings, | 430 bool apply_pending_management_settings, |
| 430 const ManagementSettings& pending_management_settings, | 431 const ManagementSettings& pending_management_settings, |
| 431 em::ChromeDeviceSettingsProto* settings) { | 432 em::ChromeDeviceSettingsProto* settings) { |
| 432 scoped_ptr<em::PolicyData> policy(new em::PolicyData()); | 433 scoped_ptr<em::PolicyData> policy(new em::PolicyData()); |
| 433 if (policy_data) { | 434 if (policy_data) { |
| 434 // Preserve management settings. | 435 // Preserve management settings. |
| 435 if (policy_data->has_management_mode()) | 436 if (policy_data->has_management_mode()) |
| 436 policy->set_management_mode(policy_data->management_mode()); | 437 policy->set_management_mode(policy_data->management_mode()); |
| 437 if (policy_data->has_request_token()) | 438 if (policy_data->has_request_token()) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 453 policy->set_request_token(pending_management_settings.request_token); | 454 policy->set_request_token(pending_management_settings.request_token); |
| 454 | 455 |
| 455 if (pending_management_settings.device_id.empty()) | 456 if (pending_management_settings.device_id.empty()) |
| 456 policy->clear_device_id(); | 457 policy->clear_device_id(); |
| 457 else | 458 else |
| 458 policy->set_device_id(pending_management_settings.device_id); | 459 policy->set_device_id(pending_management_settings.device_id); |
| 459 } | 460 } |
| 460 policy->set_policy_type(policy::dm_protocol::kChromeDevicePolicyType); | 461 policy->set_policy_type(policy::dm_protocol::kChromeDevicePolicyType); |
| 461 policy->set_timestamp( | 462 policy->set_timestamp( |
| 462 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()); | 463 (base::Time::Now() - base::Time::UnixEpoch()).InMilliseconds()); |
| 463 policy->set_username(user_id); | 464 policy->set_username(user_id.GetUserEmail()); |
| 464 if (policy_data->management_mode() == em::PolicyData::LOCAL_OWNER || | 465 if (policy_data->management_mode() == em::PolicyData::LOCAL_OWNER || |
| 465 policy_data->management_mode() == em::PolicyData::CONSUMER_MANAGED) { | 466 policy_data->management_mode() == em::PolicyData::CONSUMER_MANAGED) { |
| 466 FixupLocalOwnerPolicy(user_id, settings); | 467 FixupLocalOwnerPolicy(user_id, settings); |
| 467 } | 468 } |
| 468 if (!settings->SerializeToString(policy->mutable_policy_value())) | 469 if (!settings->SerializeToString(policy->mutable_policy_value())) |
| 469 return scoped_ptr<em::PolicyData>(); | 470 return scoped_ptr<em::PolicyData>(); |
| 470 | 471 |
| 471 return policy.Pass(); | 472 return policy.Pass(); |
| 472 } | 473 } |
| 473 | 474 |
| 474 // static | 475 // static |
| 475 void OwnerSettingsServiceChromeOS::FixupLocalOwnerPolicy( | 476 void OwnerSettingsServiceChromeOS::FixupLocalOwnerPolicy( |
| 476 const std::string& user_id, | 477 const user_manager::UserID& user_id, |
| 477 enterprise_management::ChromeDeviceSettingsProto* settings) { | 478 enterprise_management::ChromeDeviceSettingsProto* settings) { |
| 478 if (!settings->has_allow_new_users()) | 479 if (!settings->has_allow_new_users()) |
| 479 settings->mutable_allow_new_users()->set_allow_new_users(true); | 480 settings->mutable_allow_new_users()->set_allow_new_users(true); |
| 480 | 481 |
| 481 em::UserWhitelistProto* whitelist_proto = settings->mutable_user_whitelist(); | 482 em::UserWhitelistProto* whitelist_proto = settings->mutable_user_whitelist(); |
| 482 if (whitelist_proto->user_whitelist().end() == | 483 if (whitelist_proto->user_whitelist().end() == |
| 483 std::find(whitelist_proto->user_whitelist().begin(), | 484 std::find(whitelist_proto->user_whitelist().begin(), |
| 484 whitelist_proto->user_whitelist().end(), user_id)) { | 485 whitelist_proto->user_whitelist().end(), user_id.GetUserEmail()) ) { |
| 485 whitelist_proto->add_user_whitelist(user_id); | 486 whitelist_proto->add_user_whitelist(user_id.GetUserEmail()); |
| 486 } | 487 } |
| 487 } | 488 } |
| 488 | 489 |
| 489 // static | 490 // static |
| 490 void OwnerSettingsServiceChromeOS::UpdateDeviceSettings( | 491 void OwnerSettingsServiceChromeOS::UpdateDeviceSettings( |
| 491 const std::string& path, | 492 const std::string& path, |
| 492 const base::Value& value, | 493 const base::Value& value, |
| 493 enterprise_management::ChromeDeviceSettingsProto& settings) { | 494 enterprise_management::ChromeDeviceSettingsProto& settings) { |
| 494 if (path == kAccountsPrefAllowNewUser) { | 495 if (path == kAccountsPrefAllowNewUser) { |
| 495 em::AllowNewUsersProto* allow = settings.mutable_allow_new_users(); | 496 em::AllowNewUsersProto* allow = settings.mutable_allow_new_users(); |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 622 NOTREACHED(); | 623 NOTREACHED(); |
| 623 } else if (path == kAccountsPrefUsers) { | 624 } else if (path == kAccountsPrefUsers) { |
| 624 em::UserWhitelistProto* whitelist_proto = settings.mutable_user_whitelist(); | 625 em::UserWhitelistProto* whitelist_proto = settings.mutable_user_whitelist(); |
| 625 whitelist_proto->clear_user_whitelist(); | 626 whitelist_proto->clear_user_whitelist(); |
| 626 const base::ListValue* users; | 627 const base::ListValue* users; |
| 627 if (value.GetAsList(&users)) { | 628 if (value.GetAsList(&users)) { |
| 628 for (base::ListValue::const_iterator i = users->begin(); | 629 for (base::ListValue::const_iterator i = users->begin(); |
| 629 i != users->end(); | 630 i != users->end(); |
| 630 ++i) { | 631 ++i) { |
| 631 std::string email; | 632 std::string email; |
| 632 if ((*i)->GetAsString(&email)) | 633 if ((*i)->GetAsString(&email)) { |
| 633 whitelist_proto->add_user_whitelist(email); | 634 const user_manager::UserID user_id(user_manager::UserID::FromUserEmail (email)); |
| 635 whitelist_proto->add_user_whitelist(user_id.GetUserEmail()); | |
| 636 } | |
| 634 } | 637 } |
| 635 } | 638 } |
| 636 } else if (path == kAccountsPrefEphemeralUsersEnabled) { | 639 } else if (path == kAccountsPrefEphemeralUsersEnabled) { |
| 637 em::EphemeralUsersEnabledProto* ephemeral_users_enabled = | 640 em::EphemeralUsersEnabledProto* ephemeral_users_enabled = |
| 638 settings.mutable_ephemeral_users_enabled(); | 641 settings.mutable_ephemeral_users_enabled(); |
| 639 bool ephemeral_users_enabled_value = false; | 642 bool ephemeral_users_enabled_value = false; |
| 640 if (value.GetAsBoolean(&ephemeral_users_enabled_value)) { | 643 if (value.GetAsBoolean(&ephemeral_users_enabled_value)) { |
| 641 ephemeral_users_enabled->set_ephemeral_users_enabled( | 644 ephemeral_users_enabled->set_ephemeral_users_enabled( |
| 642 ephemeral_users_enabled_value); | 645 ephemeral_users_enabled_value); |
| 643 } else { | 646 } else { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 | 712 |
| 710 LOG(FATAL) << "Device setting " << path << " is read-only."; | 713 LOG(FATAL) << "Device setting " << path << " is read-only."; |
| 711 } | 714 } |
| 712 } | 715 } |
| 713 | 716 |
| 714 void OwnerSettingsServiceChromeOS::OnPostKeypairLoadedActions() { | 717 void OwnerSettingsServiceChromeOS::OnPostKeypairLoadedActions() { |
| 715 DCHECK(thread_checker_.CalledOnValidThread()); | 718 DCHECK(thread_checker_.CalledOnValidThread()); |
| 716 | 719 |
| 717 const user_manager::User* user = | 720 const user_manager::User* user = |
| 718 ProfileHelper::Get()->GetUserByProfile(profile_); | 721 ProfileHelper::Get()->GetUserByProfile(profile_); |
| 719 user_id_ = user ? user->GetUserID() : std::string(); | 722 user_id_ = user ? user->GetUserID() : user_manager::EmptyUserID(); |
| 720 | 723 |
| 721 const bool is_owner = IsOwner() || IsOwnerInTests(user_id_); | 724 const bool is_owner = IsOwner() || IsOwnerInTests(user_id_); |
| 722 if (is_owner && device_settings_service_) | 725 if (is_owner && device_settings_service_) |
| 723 device_settings_service_->InitOwner(user_id_, weak_factory_.GetWeakPtr()); | 726 device_settings_service_->InitOwner(user_id_, weak_factory_.GetWeakPtr()); |
| 724 | 727 |
| 725 has_pending_fixups_ = true; | 728 has_pending_fixups_ = true; |
| 726 } | 729 } |
| 727 | 730 |
| 728 void OwnerSettingsServiceChromeOS::ReloadKeypairImpl(const base::Callback< | 731 void OwnerSettingsServiceChromeOS::ReloadKeypairImpl(const base::Callback< |
| 729 void(const scoped_refptr<PublicKey>& public_key, | 732 void(const scoped_refptr<PublicKey>& public_key, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 809 std::vector<OnManagementSettingsSetCallback> callbacks; | 812 std::vector<OnManagementSettingsSetCallback> callbacks; |
| 810 pending_management_settings_callbacks_.swap(callbacks); | 813 pending_management_settings_callbacks_.swap(callbacks); |
| 811 for (const auto& callback : callbacks) { | 814 for (const auto& callback : callbacks) { |
| 812 if (!callback.is_null()) | 815 if (!callback.is_null()) |
| 813 callback.Run(success); | 816 callback.Run(success); |
| 814 } | 817 } |
| 815 StorePendingChanges(); | 818 StorePendingChanges(); |
| 816 } | 819 } |
| 817 | 820 |
| 818 } // namespace chromeos | 821 } // namespace chromeos |
| OLD | NEW |