Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(111)

Side by Side Diff: chrome/browser/chromeos/settings/session_manager_operation.cc

Issue 2486813002: Add DeviceADPolicyManager to provide AD policy. (Closed)
Patch Set: Polish Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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(
emaxx 2016/11/17 01:14:32 There's some contradiction between the flag variab
Thiemo Nagel 2016/11/17 14:19:07 Done.
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 }
191
184 validator->ValidatePolicyType(policy::dm_protocol::kChromeDevicePolicyType); 192 validator->ValidatePolicyType(policy::dm_protocol::kChromeDevicePolicyType);
185 validator->ValidatePayload(); 193 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 validator->StartValidation( 194 validator->StartValidation(
190 base::Bind(&SessionManagerOperation::ReportValidatorStatus, 195 base::Bind(&SessionManagerOperation::ReportValidatorStatus,
191 weak_factory_.GetWeakPtr())); 196 weak_factory_.GetWeakPtr()));
192 } 197 }
193 198
194 void SessionManagerOperation::ReportValidatorStatus( 199 void SessionManagerOperation::ReportValidatorStatus(
195 policy::DeviceCloudPolicyValidator* validator) { 200 policy::DeviceCloudPolicyValidator* validator) {
196 DeviceSettingsService::Status status = 201 DeviceSettingsService::Status status =
197 DeviceSettingsService::STORE_VALIDATION_ERROR; 202 DeviceSettingsService::STORE_VALIDATION_ERROR;
198 if (validator->success()) { 203 if (validator->success()) {
199 status = DeviceSettingsService::STORE_SUCCESS; 204 status = DeviceSettingsService::STORE_SUCCESS;
200 policy_data_ = std::move(validator->policy_data()); 205 policy_data_ = std::move(validator->policy_data());
201 device_settings_ = std::move(validator->payload()); 206 device_settings_ = std::move(validator->payload());
202 } else { 207 } else {
203 LOG(ERROR) << "Policy validation failed: " << validator->status(); 208 LOG(ERROR) << "Policy validation failed: " << validator->status();
204 209
205 // Those are mostly caused by RTC loss and are recoverable. 210 // Those are mostly caused by RTC loss and are recoverable.
206 if (validator->status() == 211 if (validator->status() ==
207 policy::DeviceCloudPolicyValidator::VALIDATION_BAD_TIMESTAMP) { 212 policy::DeviceCloudPolicyValidator::VALIDATION_BAD_TIMESTAMP) {
208 status = DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR; 213 status = DeviceSettingsService::STORE_TEMP_VALIDATION_ERROR;
209 } 214 }
210 } 215 }
211 216
212 ReportResult(status); 217 ReportResult(status);
213 } 218 }
214 219
215 LoadSettingsOperation::LoadSettingsOperation(const Callback& callback) 220 LoadSettingsOperation::LoadSettingsOperation(bool force_key_load,
216 : SessionManagerOperation(callback) {} 221 bool verify_signature,
222 const Callback& callback)
223 : SessionManagerOperation(callback) {
224 force_key_load_ = force_key_load;
225 verify_signature_ = verify_signature;
226 }
217 227
218 LoadSettingsOperation::~LoadSettingsOperation() {} 228 LoadSettingsOperation::~LoadSettingsOperation() {}
219 229
220 void LoadSettingsOperation::Run() { 230 void LoadSettingsOperation::Run() {
221 StartLoading(); 231 StartLoading();
222 } 232 }
223 233
224 StoreSettingsOperation::StoreSettingsOperation( 234 StoreSettingsOperation::StoreSettingsOperation(
225 const Callback& callback, 235 const Callback& callback,
226 std::unique_ptr<em::PolicyFetchResponse> policy) 236 std::unique_ptr<em::PolicyFetchResponse> policy)
(...skipping 11 matching lines...) Expand all
238 } 248 }
239 249
240 void StoreSettingsOperation::HandleStoreResult(bool success) { 250 void StoreSettingsOperation::HandleStoreResult(bool success) {
241 if (!success) 251 if (!success)
242 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED); 252 ReportResult(DeviceSettingsService::STORE_OPERATION_FAILED);
243 else 253 else
244 StartLoading(); 254 StartLoading();
245 } 255 }
246 256
247 } // namespace chromeos 257 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698