Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/settings/session_manager_operation.h" | 5 #include "chrome/browser/chromeos/settings/session_manager_operation.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 return; | 63 return; |
| 64 is_loading_ = true; | 64 is_loading_ = true; |
| 65 if (cloud_validations_) { | 65 if (cloud_validations_) { |
| 66 EnsurePublicKey(base::Bind(&SessionManagerOperation::RetrieveDeviceSettings, | 66 EnsurePublicKey(base::Bind(&SessionManagerOperation::RetrieveDeviceSettings, |
| 67 weak_factory_.GetWeakPtr())); | 67 weak_factory_.GetWeakPtr())); |
| 68 } else { | 68 } else { |
| 69 RetrieveDeviceSettings(); | 69 RetrieveDeviceSettings(); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 void SessionManagerOperation::LoadImmediately() { | |
| 74 scoped_refptr<PublicKey> public_key(new PublicKey()); | |
| 75 | |
| 76 // Keep already-existing public key. | |
| 77 if (public_key_.get() && public_key_->is_loaded()) { | |
|
emaxx
2017/02/22 17:24:33
I believe you have to honor the force_key_load_ fl
Sergey Poromov
2017/02/28 14:01:17
Done.
| |
| 78 public_key->data() = public_key_->data(); | |
| 79 } | |
| 80 if (!public_key->is_loaded() && owner_key_util_->IsPublicKeyPresent()) { | |
| 81 if (!owner_key_util_->ImportPublicKey(&public_key->data())) | |
| 82 LOG(ERROR) << "Failed to load public owner key."; | |
| 83 } | |
| 84 | |
| 85 public_key_ = public_key; | |
| 86 | |
| 87 if (!public_key_.get() || !public_key_->is_loaded()) { | |
| 88 ReportResult(DeviceSettingsService::STORE_KEY_UNAVAILABLE); | |
| 89 return; | |
| 90 } | |
| 91 | |
| 92 BlockingRetrieveDeviceSettings(); | |
| 93 } | |
| 94 | |
| 73 void SessionManagerOperation::ReportResult( | 95 void SessionManagerOperation::ReportResult( |
| 74 DeviceSettingsService::Status status) { | 96 DeviceSettingsService::Status status) { |
| 75 callback_.Run(this, status); | 97 callback_.Run(this, status); |
| 76 } | 98 } |
| 77 | 99 |
| 78 void SessionManagerOperation::EnsurePublicKey(const base::Closure& callback) { | 100 void SessionManagerOperation::EnsurePublicKey(const base::Closure& callback) { |
| 79 if (force_key_load_ || !public_key_.get() || !public_key_->is_loaded()) { | 101 if (force_key_load_ || !public_key_.get() || !public_key_->is_loaded()) { |
| 80 scoped_refptr<base::TaskRunner> task_runner = | 102 scoped_refptr<base::TaskRunner> task_runner = |
| 81 content::BrowserThread::GetBlockingPool() | 103 content::BrowserThread::GetBlockingPool() |
| 82 ->GetTaskRunnerWithShutdownBehavior( | 104 ->GetTaskRunnerWithShutdownBehavior( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 | 147 |
| 126 callback.Run(); | 148 callback.Run(); |
| 127 } | 149 } |
| 128 | 150 |
| 129 void SessionManagerOperation::RetrieveDeviceSettings() { | 151 void SessionManagerOperation::RetrieveDeviceSettings() { |
| 130 session_manager_client()->RetrieveDevicePolicy( | 152 session_manager_client()->RetrieveDevicePolicy( |
| 131 base::Bind(&SessionManagerOperation::ValidateDeviceSettings, | 153 base::Bind(&SessionManagerOperation::ValidateDeviceSettings, |
| 132 weak_factory_.GetWeakPtr())); | 154 weak_factory_.GetWeakPtr())); |
| 133 } | 155 } |
| 134 | 156 |
| 157 void SessionManagerOperation::BlockingRetrieveDeviceSettings() { | |
| 158 ValidateDeviceSettings( | |
| 159 session_manager_client()->BlockingRetrieveDevicePolicy()); | |
| 160 } | |
| 161 | |
| 135 void SessionManagerOperation::ValidateDeviceSettings( | 162 void SessionManagerOperation::ValidateDeviceSettings( |
| 136 const std::string& policy_blob) { | 163 const std::string& policy_blob) { |
| 137 std::unique_ptr<em::PolicyFetchResponse> policy( | 164 std::unique_ptr<em::PolicyFetchResponse> policy( |
| 138 new em::PolicyFetchResponse()); | 165 new em::PolicyFetchResponse()); |
| 139 if (policy_blob.empty()) { | 166 if (policy_blob.empty()) { |
| 140 ReportResult(DeviceSettingsService::STORE_NO_POLICY); | 167 ReportResult(DeviceSettingsService::STORE_NO_POLICY); |
| 141 return; | 168 return; |
| 142 } | 169 } |
| 143 | 170 |
| 144 if (!policy->ParseFromString(policy_blob) || | 171 if (!policy->ParseFromString(policy_blob) || |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 policy::CloudPolicyValidatorBase::DM_TOKEN_NOT_REQUIRED, | 211 policy::CloudPolicyValidatorBase::DM_TOKEN_NOT_REQUIRED, |
| 185 policy::CloudPolicyValidatorBase::DEVICE_ID_NOT_REQUIRED); | 212 policy::CloudPolicyValidatorBase::DEVICE_ID_NOT_REQUIRED); |
| 186 | 213 |
| 187 // We don't check the DMServer verification key below, because the signing | 214 // We don't check the DMServer verification key below, because the signing |
| 188 // key is validated when it is installed. | 215 // key is validated when it is installed. |
| 189 validator->ValidateSignature(public_key_->as_string()); | 216 validator->ValidateSignature(public_key_->as_string()); |
| 190 } | 217 } |
| 191 | 218 |
| 192 validator->ValidatePolicyType(policy::dm_protocol::kChromeDevicePolicyType); | 219 validator->ValidatePolicyType(policy::dm_protocol::kChromeDevicePolicyType); |
| 193 validator->ValidatePayload(); | 220 validator->ValidatePayload(); |
| 194 validator->StartValidation( | 221 if (force_immediate_load_) { |
| 195 base::Bind(&SessionManagerOperation::ReportValidatorStatus, | 222 validator->RunValidation(); |
| 196 weak_factory_.GetWeakPtr())); | 223 ReportValidatorStatus(validator); |
| 224 } else { | |
| 225 validator->StartValidation( | |
| 226 base::Bind(&SessionManagerOperation::ReportValidatorStatus, | |
| 227 weak_factory_.GetWeakPtr())); | |
| 228 } | |
| 197 } | 229 } |
| 198 | 230 |
| 199 void SessionManagerOperation::ReportValidatorStatus( | 231 void SessionManagerOperation::ReportValidatorStatus( |
| 200 policy::DeviceCloudPolicyValidator* validator) { | 232 policy::DeviceCloudPolicyValidator* validator) { |
| 201 DeviceSettingsService::Status status = | 233 DeviceSettingsService::Status status = |
| 202 DeviceSettingsService::STORE_VALIDATION_ERROR; | 234 DeviceSettingsService::STORE_VALIDATION_ERROR; |
| 203 if (validator->success()) { | 235 if (validator->success()) { |
| 204 status = DeviceSettingsService::STORE_SUCCESS; | 236 status = DeviceSettingsService::STORE_SUCCESS; |
| 205 policy_data_ = std::move(validator->policy_data()); | 237 policy_data_ = std::move(validator->policy_data()); |
| 206 device_settings_ = std::move(validator->payload()); | 238 device_settings_ = std::move(validator->payload()); |
| 207 } else { | 239 } else { |
| 208 LOG(ERROR) << "Policy validation failed: " << validator->status(); | 240 LOG(ERROR) << "Policy validation failed: " << validator->status(); |
| 209 | 241 |
| 210 // Those are mostly caused by RTC loss and are recoverable. | 242 // Those are mostly caused by RTC loss and are recoverable. |
| 211 if (validator->status() == | 243 if (validator->status() == |
| 212 policy::DeviceCloudPolicyValidator::VALIDATION_BAD_TIMESTAMP) { | 244 policy::DeviceCloudPolicyValidator::VALIDATION_BAD_TIMESTAMP) { |
| 213 status = DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR; | 245 status = DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR; |
| 214 } | 246 } |
| 215 } | 247 } |
| 216 | 248 |
| 217 ReportResult(status); | 249 ReportResult(status); |
| 218 } | 250 } |
| 219 | 251 |
| 220 LoadSettingsOperation::LoadSettingsOperation(bool force_key_load, | 252 LoadSettingsOperation::LoadSettingsOperation(bool force_key_load, |
| 221 bool cloud_validations, | 253 bool cloud_validations, |
| 254 bool force_immediate_load, | |
| 222 const Callback& callback) | 255 const Callback& callback) |
| 223 : SessionManagerOperation(callback) { | 256 : SessionManagerOperation(callback) { |
| 224 force_key_load_ = force_key_load; | 257 force_key_load_ = force_key_load; |
| 225 cloud_validations_ = cloud_validations; | 258 cloud_validations_ = cloud_validations; |
| 259 force_immediate_load_ = force_immediate_load; | |
| 226 } | 260 } |
| 227 | 261 |
| 228 LoadSettingsOperation::~LoadSettingsOperation() {} | 262 LoadSettingsOperation::~LoadSettingsOperation() {} |
| 229 | 263 |
| 230 void LoadSettingsOperation::Run() { | 264 void LoadSettingsOperation::Run() { |
| 231 StartLoading(); | 265 if (force_immediate_load_) |
| 266 LoadImmediately(); | |
| 267 else | |
| 268 StartLoading(); | |
| 232 } | 269 } |
| 233 | 270 |
| 234 StoreSettingsOperation::StoreSettingsOperation( | 271 StoreSettingsOperation::StoreSettingsOperation( |
| 235 const Callback& callback, | 272 const Callback& callback, |
| 236 std::unique_ptr<em::PolicyFetchResponse> policy) | 273 std::unique_ptr<em::PolicyFetchResponse> policy) |
| 237 : SessionManagerOperation(callback), | 274 : SessionManagerOperation(callback), |
| 238 policy_(std::move(policy)), | 275 policy_(std::move(policy)), |
| 239 weak_factory_(this) {} | 276 weak_factory_(this) {} |
| 240 | 277 |
| 241 StoreSettingsOperation::~StoreSettingsOperation() {} | 278 StoreSettingsOperation::~StoreSettingsOperation() {} |
| 242 | 279 |
| 243 void StoreSettingsOperation::Run() { | 280 void StoreSettingsOperation::Run() { |
| 244 session_manager_client()->StoreDevicePolicy( | 281 session_manager_client()->StoreDevicePolicy( |
| 245 policy_->SerializeAsString(), | 282 policy_->SerializeAsString(), |
| 246 base::Bind(&StoreSettingsOperation::HandleStoreResult, | 283 base::Bind(&StoreSettingsOperation::HandleStoreResult, |
| 247 weak_factory_.GetWeakPtr())); | 284 weak_factory_.GetWeakPtr())); |
| 248 } | 285 } |
| 249 | 286 |
| 250 void StoreSettingsOperation::HandleStoreResult(bool success) { | 287 void StoreSettingsOperation::HandleStoreResult(bool success) { |
| 251 if (!success) | 288 if (!success) |
| 252 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); | 289 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); |
| 253 else | 290 else |
| 254 StartLoading(); | 291 StartLoading(); |
| 255 } | 292 } |
| 256 | 293 |
| 257 } // namespace chromeos | 294 } // namespace chromeos |
| OLD | NEW |