| 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 12 matching lines...) Expand all Loading... |
| 23 #include "crypto/signature_creator.h" | 23 #include "crypto/signature_creator.h" |
| 24 | 24 |
| 25 using ownership::OwnerKeyUtil; | 25 using ownership::OwnerKeyUtil; |
| 26 using ownership::PublicKey; | 26 using ownership::PublicKey; |
| 27 | 27 |
| 28 namespace em = enterprise_management; | 28 namespace em = enterprise_management; |
| 29 | 29 |
| 30 namespace chromeos { | 30 namespace chromeos { |
| 31 | 31 |
| 32 SessionManagerOperation::SessionManagerOperation(const Callback& callback) | 32 SessionManagerOperation::SessionManagerOperation(const Callback& callback) |
| 33 : session_manager_client_(NULL), | 33 : callback_(callback), weak_factory_(this) {} |
| 34 callback_(callback), | |
| 35 force_key_load_(false), | |
| 36 is_loading_(false), | |
| 37 weak_factory_(this) {} | |
| 38 | 34 |
| 39 SessionManagerOperation::~SessionManagerOperation() {} | 35 SessionManagerOperation::~SessionManagerOperation() {} |
| 40 | 36 |
| 41 void SessionManagerOperation::Start( | 37 void SessionManagerOperation::Start( |
| 42 SessionManagerClient* session_manager_client, | 38 SessionManagerClient* session_manager_client, |
| 43 scoped_refptr<OwnerKeyUtil> owner_key_util, | 39 scoped_refptr<OwnerKeyUtil> owner_key_util, |
| 44 scoped_refptr<PublicKey> public_key) { | 40 scoped_refptr<PublicKey> public_key) { |
| 45 session_manager_client_ = session_manager_client; | 41 session_manager_client_ = session_manager_client; |
| 46 owner_key_util_ = owner_key_util; | 42 owner_key_util_ = owner_key_util; |
| 47 public_key_ = public_key; | 43 public_key_ = public_key; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 59 weak_factory_.InvalidateWeakPtrs(); | 55 weak_factory_.InvalidateWeakPtrs(); |
| 60 // Mark as not loading to start loading again. | 56 // Mark as not loading to start loading again. |
| 61 is_loading_ = false; | 57 is_loading_ = false; |
| 62 StartLoading(); | 58 StartLoading(); |
| 63 } | 59 } |
| 64 | 60 |
| 65 void SessionManagerOperation::StartLoading() { | 61 void SessionManagerOperation::StartLoading() { |
| 66 if (is_loading_) | 62 if (is_loading_) |
| 67 return; | 63 return; |
| 68 is_loading_ = true; | 64 is_loading_ = true; |
| 69 EnsurePublicKey(base::Bind(&SessionManagerOperation::RetrieveDeviceSettings, | 65 if (verify_signature_) { |
| 70 weak_factory_.GetWeakPtr())); | 66 EnsurePublicKey(base::Bind(&SessionManagerOperation::RetrieveDeviceSettings, |
| 67 weak_factory_.GetWeakPtr())); |
| 68 } else { |
| 69 RetrieveDeviceSettings(); |
| 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 void SessionManagerOperation::ReportResult( | 73 void SessionManagerOperation::ReportResult( |
| 74 DeviceSettingsService::Status status) { | 74 DeviceSettingsService::Status status) { |
| 75 callback_.Run(this, status); | 75 callback_.Run(this, status); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void SessionManagerOperation::EnsurePublicKey(const base::Closure& callback) { | 78 void SessionManagerOperation::EnsurePublicKey(const base::Closure& callback) { |
| 79 if (force_key_load_ || !public_key_.get() || !public_key_->is_loaded()) { | 79 if (force_key_load_ || !public_key_.get() || !public_key_->is_loaded()) { |
| 80 scoped_refptr<base::TaskRunner> task_runner = | 80 scoped_refptr<base::TaskRunner> task_runner = |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 content::BrowserThread::GetBlockingPool(); | 151 content::BrowserThread::GetBlockingPool(); |
| 152 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | 152 scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
| 153 pool->GetSequencedTaskRunnerWithShutdownBehavior( | 153 pool->GetSequencedTaskRunnerWithShutdownBehavior( |
| 154 pool->GetSequenceToken(), | 154 pool->GetSequenceToken(), |
| 155 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); | 155 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); |
| 156 | 156 |
| 157 policy::DeviceCloudPolicyValidator* validator = | 157 policy::DeviceCloudPolicyValidator* validator = |
| 158 policy::DeviceCloudPolicyValidator::Create(std::move(policy), | 158 policy::DeviceCloudPolicyValidator::Create(std::move(policy), |
| 159 background_task_runner); | 159 background_task_runner); |
| 160 | 160 |
| 161 // Policy auto-generated by session manager doesn't include a timestamp, so | 161 if (verify_signature_) { |
| 162 // the timestamp shouldn't be verified in that case. | 162 // Policy auto-generated by session manager doesn't include a timestamp, so |
| 163 // | 163 // the timestamp shouldn't be verified in that case. |
| 164 // Additionally, offline devices can get their clock set backwards in time | 164 // |
| 165 // under some hardware conditions; checking the timestamp now could likely | 165 // Additionally, offline devices can get their clock set backwards in time |
| 166 // find a value in the future, and prevent the user from signing-in or | 166 // under some hardware conditions; checking the timestamp now could likely |
| 167 // starting guest mode. Tlsdate will eventually fix the clock when the device | 167 // find a value in the future, and prevent the user from signing-in or |
| 168 // is back online, but the network configuration may come from device ONC. | 168 // starting guest mode. Tlsdate will eventually fix the clock when the |
| 169 // | 169 // device is back online, but the network configuration may come from device |
| 170 // To prevent all of these issues the timestamp is just not verified when | 170 // ONC. |
| 171 // loading the device policy from session manager. Note that the timestamp is | 171 // |
| 172 // still verified during enrollment and when a new policy is fetched from the | 172 // To prevent all of these issues the timestamp is just not verified when |
| 173 // server. | 173 // loading the device policy from session manager. Note that the timestamp |
| 174 // | 174 // is still verified during enrollment and when a new policy is fetched from |
| 175 // The two *_NOT_REQUIRED options are necessary because both the DM token and | 175 // the server. |
| 176 // the device id are empty for a user logging in on an actual Chrome OS device | 176 // |
| 177 // that is not enterprise-managed. Note for devs: The strings are not empty | 177 // The two *_NOT_REQUIRED options are necessary because both the DM token |
| 178 // when you test Chrome with target_os = "chromeos" on Linux! | 178 // and the device id are empty for a user logging in on an actual Chrome OS |
| 179 validator->ValidateAgainstCurrentPolicy( | 179 // device that is not enterprise-managed. Note for devs: The strings are not |
| 180 policy_data_.get(), | 180 // empty when you test Chrome with target_os = "chromeos" on Linux! |
| 181 policy::CloudPolicyValidatorBase::TIMESTAMP_NOT_VALIDATED, | 181 validator->ValidateAgainstCurrentPolicy( |
| 182 policy::CloudPolicyValidatorBase::DM_TOKEN_NOT_REQUIRED, | 182 policy_data_.get(), |
| 183 policy::CloudPolicyValidatorBase::DEVICE_ID_NOT_REQUIRED); | 183 policy::CloudPolicyValidatorBase::TIMESTAMP_NOT_VALIDATED, |
| 184 policy::CloudPolicyValidatorBase::DM_TOKEN_NOT_REQUIRED, |
| 185 policy::CloudPolicyValidatorBase::DEVICE_ID_NOT_REQUIRED); |
| 186 |
| 187 // We don't check the DMServer verification key below, because the signing |
| 188 // key is validated when it is installed. |
| 189 validator->ValidateSignature(public_key_->as_string(), |
| 190 std::string(), // No key validation check. |
| 191 std::string(), |
| 192 false); |
| 193 } |
| 194 |
| 184 validator->ValidatePolicyType(policy::dm_protocol::kChromeDevicePolicyType); | 195 validator->ValidatePolicyType(policy::dm_protocol::kChromeDevicePolicyType); |
| 185 validator->ValidatePayload(); | 196 validator->ValidatePayload(); |
| 186 // We don't check the DMServer verification key below, because the signing | |
| 187 // key is validated when it is installed. | |
| 188 validator->ValidateSignature(public_key_->as_string(), | |
| 189 std::string(), // No key validation check. | |
| 190 std::string(), | |
| 191 false); | |
| 192 validator->StartValidation( | 197 validator->StartValidation( |
| 193 base::Bind(&SessionManagerOperation::ReportValidatorStatus, | 198 base::Bind(&SessionManagerOperation::ReportValidatorStatus, |
| 194 weak_factory_.GetWeakPtr())); | 199 weak_factory_.GetWeakPtr())); |
| 195 } | 200 } |
| 196 | 201 |
| 197 void SessionManagerOperation::ReportValidatorStatus( | 202 void SessionManagerOperation::ReportValidatorStatus( |
| 198 policy::DeviceCloudPolicyValidator* validator) { | 203 policy::DeviceCloudPolicyValidator* validator) { |
| 199 DeviceSettingsService::Status status = | 204 DeviceSettingsService::Status status = |
| 200 DeviceSettingsService::STORE_VALIDATION_ERROR; | 205 DeviceSettingsService::STORE_VALIDATION_ERROR; |
| 201 if (validator->success()) { | 206 if (validator->success()) { |
| 202 status = DeviceSettingsService::STORE_SUCCESS; | 207 status = DeviceSettingsService::STORE_SUCCESS; |
| 203 policy_data_ = std::move(validator->policy_data()); | 208 policy_data_ = std::move(validator->policy_data()); |
| 204 device_settings_ = std::move(validator->payload()); | 209 device_settings_ = std::move(validator->payload()); |
| 205 } else { | 210 } else { |
| 206 LOG(ERROR) << "Policy validation failed: " << validator->status(); | 211 LOG(ERROR) << "Policy validation failed: " << validator->status(); |
| 207 | 212 |
| 208 // Those are mostly caused by RTC loss and are recoverable. | 213 // Those are mostly caused by RTC loss and are recoverable. |
| 209 if (validator->status() == | 214 if (validator->status() == |
| 210 policy::DeviceCloudPolicyValidator::VALIDATION_BAD_TIMESTAMP) { | 215 policy::DeviceCloudPolicyValidator::VALIDATION_BAD_TIMESTAMP) { |
| 211 status = DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR; | 216 status = DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR; |
| 212 } | 217 } |
| 213 } | 218 } |
| 214 | 219 |
| 215 ReportResult(status); | 220 ReportResult(status); |
| 216 } | 221 } |
| 217 | 222 |
| 218 LoadSettingsOperation::LoadSettingsOperation(const Callback& callback) | 223 LoadSettingsOperation::LoadSettingsOperation(bool force_key_load, |
| 219 : SessionManagerOperation(callback) {} | 224 bool verify_signature, |
| 225 const Callback& callback) |
| 226 : SessionManagerOperation(callback) { |
| 227 force_key_load_ = force_key_load; |
| 228 verify_signature_ = verify_signature; |
| 229 } |
| 220 | 230 |
| 221 LoadSettingsOperation::~LoadSettingsOperation() {} | 231 LoadSettingsOperation::~LoadSettingsOperation() {} |
| 222 | 232 |
| 223 void LoadSettingsOperation::Run() { | 233 void LoadSettingsOperation::Run() { |
| 224 StartLoading(); | 234 StartLoading(); |
| 225 } | 235 } |
| 226 | 236 |
| 227 StoreSettingsOperation::StoreSettingsOperation( | 237 StoreSettingsOperation::StoreSettingsOperation( |
| 228 const Callback& callback, | 238 const Callback& callback, |
| 229 std::unique_ptr<em::PolicyFetchResponse> policy) | 239 std::unique_ptr<em::PolicyFetchResponse> policy) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 241 } | 251 } |
| 242 | 252 |
| 243 void StoreSettingsOperation::HandleStoreResult(bool success) { | 253 void StoreSettingsOperation::HandleStoreResult(bool success) { |
| 244 if (!success) | 254 if (!success) |
| 245 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); | 255 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); |
| 246 else | 256 else |
| 247 StartLoading(); | 257 StartLoading(); |
| 248 } | 258 } |
| 249 | 259 |
| 250 } // namespace chromeos | 260 } // namespace chromeos |
| OLD | NEW |