OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/policy/cloud_policy_cache.h" | 5 #include "chrome/browser/policy/cloud_policy_cache.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 CloudPolicyCache* cache_; | 74 CloudPolicyCache* cache_; |
75 // Policy level this provider will handle. | 75 // Policy level this provider will handle. |
76 CloudPolicyCache::PolicyLevel level_; | 76 CloudPolicyCache::PolicyLevel level_; |
77 | 77 |
78 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProvider); | 78 DISALLOW_COPY_AND_ASSIGN(CloudPolicyProvider); |
79 }; | 79 }; |
80 | 80 |
81 // Saves policy information to a file. | 81 // Saves policy information to a file. |
82 class PersistPolicyTask : public Task { | 82 class PersistPolicyTask : public Task { |
83 public: | 83 public: |
84 PersistPolicyTask(const FilePath& path, | 84 PersistPolicyTask( |
Mattias Nissler (ping if slow)
2011/02/21 14:55:27
Any reason for the changed indentation?
gfeher
2011/02/22 15:57:29
There must have been, but now I am not seeing it.
| |
85 const em::CloudPolicyResponse* cloud_policy_response, | 85 const FilePath& path, |
86 const em::DevicePolicyResponse* device_policy_response, | 86 const em::PolicyFetchResponse* cloud_policy_response, |
87 const bool is_unmanaged) | 87 const em::DevicePolicyResponse* device_policy_response, |
88 : path_(path), | 88 const bool is_unmanaged) |
89 cloud_policy_response_(cloud_policy_response), | 89 : path_(path), |
Mattias Nissler (ping if slow)
2011/02/21 14:55:27
AFAIK, you don't need to increase indentation here
Jakob Kummerow
2011/02/21 16:15:00
nit: indentation (":" should be 4 spaces deeper th
gfeher
2011/02/22 15:57:29
Done.
| |
90 device_policy_response_(device_policy_response), | 90 cloud_policy_response_(cloud_policy_response), |
91 is_unmanaged_(is_unmanaged) {} | 91 device_policy_response_(device_policy_response), |
92 is_unmanaged_(is_unmanaged) {} | |
92 | 93 |
93 private: | 94 private: |
94 // Task override. | 95 // Task override. |
95 virtual void Run(); | 96 virtual void Run(); |
96 | 97 |
97 const FilePath path_; | 98 const FilePath path_; |
98 scoped_ptr<const em::CloudPolicyResponse> cloud_policy_response_; | 99 scoped_ptr<const em::PolicyFetchResponse> cloud_policy_response_; |
99 scoped_ptr<const em::DevicePolicyResponse> device_policy_response_; | 100 scoped_ptr<const em::DevicePolicyResponse> device_policy_response_; |
100 const bool is_unmanaged_; | 101 const bool is_unmanaged_; |
101 }; | 102 }; |
102 | 103 |
103 void PersistPolicyTask::Run() { | 104 void PersistPolicyTask::Run() { |
104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
105 std::string data; | 106 std::string data; |
106 em::CachedCloudPolicyResponse cached_policy; | 107 em::CachedCloudPolicyResponse cached_policy; |
107 if (cloud_policy_response_.get()) { | 108 if (cloud_policy_response_.get()) { |
108 cached_policy.mutable_cloud_policy()->CopyFrom(*cloud_policy_response_); | 109 cached_policy.mutable_cloud_policy()->CopyFrom(*cloud_policy_response_); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 device_policy_.reset(value.release()); | 205 device_policy_.reset(value.release()); |
205 has_device_policy_ = true; | 206 has_device_policy_ = true; |
206 } | 207 } |
207 last_policy_refresh_time_ = timestamp; | 208 last_policy_refresh_time_ = timestamp; |
208 initialization_complete_ = true; | 209 initialization_complete_ = true; |
209 | 210 |
210 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, | 211 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, |
211 observer_list_, OnUpdatePolicy()); | 212 observer_list_, OnUpdatePolicy()); |
212 } | 213 } |
213 | 214 |
214 bool CloudPolicyCache::SetPolicy(const em::CloudPolicyResponse& policy) { | 215 bool CloudPolicyCache::SetPolicy(const em::PolicyFetchResponse& policy) { |
215 DCHECK(CalledOnValidThread()); | 216 DCHECK(CalledOnValidThread()); |
216 is_unmanaged_ = false; | 217 is_unmanaged_ = false; |
217 base::Time timestamp; | 218 base::Time timestamp; |
218 PolicyMap mandatory_policy; | 219 PolicyMap mandatory_policy; |
219 PolicyMap recommended_policy; | 220 PolicyMap recommended_policy; |
220 bool ok = DecodePolicyResponse(policy, &mandatory_policy, &recommended_policy, | 221 bool ok = DecodePolicyResponse(policy, &mandatory_policy, &recommended_policy, |
221 ×tamp); | 222 ×tamp); |
222 if (!ok) { | 223 if (!ok) { |
223 // TODO(jkummerow): Signal error to CloudPolicyController. | 224 // TODO(jkummerow): Signal error to CloudPolicyController. |
224 return false; | 225 return false; |
225 } | 226 } |
226 const bool new_policy_differs = | 227 const bool new_policy_differs = |
227 !mandatory_policy_.Equals(mandatory_policy) || | 228 !mandatory_policy_.Equals(mandatory_policy) || |
228 !recommended_policy_.Equals(recommended_policy); | 229 !recommended_policy_.Equals(recommended_policy); |
229 mandatory_policy_.Swap(&mandatory_policy); | 230 mandatory_policy_.Swap(&mandatory_policy); |
230 recommended_policy_.Swap(&recommended_policy); | 231 recommended_policy_.Swap(&recommended_policy); |
231 initialization_complete_ = true; | 232 initialization_complete_ = true; |
232 last_policy_refresh_time_ = timestamp; | 233 last_policy_refresh_time_ = timestamp; |
233 has_device_policy_ = false; | 234 has_device_policy_ = false; |
234 | 235 |
235 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, | 236 FOR_EACH_OBSERVER(ConfigurationPolicyProvider::Observer, |
236 observer_list_, OnUpdatePolicy()); | 237 observer_list_, OnUpdatePolicy()); |
237 | 238 |
238 if (timestamp > base::Time::NowFromSystemTime() + | 239 if (timestamp > base::Time::NowFromSystemTime() + |
239 base::TimeDelta::FromMinutes(1)) { | 240 base::TimeDelta::FromMinutes(1)) { |
240 LOG(WARNING) << "Server returned policy with timestamp from the future, " | 241 LOG(WARNING) << "Server returned policy with timestamp from the future, " |
241 "not persisting to disk."; | 242 "not persisting to disk."; |
242 } else { | 243 } else { |
243 em::CloudPolicyResponse* policy_copy = new em::CloudPolicyResponse; | 244 em::PolicyFetchResponse* policy_copy = new em::PolicyFetchResponse; |
244 policy_copy->CopyFrom(policy); | 245 policy_copy->CopyFrom(policy); |
245 BrowserThread::PostTask( | 246 BrowserThread::PostTask( |
246 BrowserThread::FILE, | 247 BrowserThread::FILE, |
247 FROM_HERE, | 248 FROM_HERE, |
248 new PersistPolicyTask(backing_file_path_, policy_copy, NULL, false)); | 249 new PersistPolicyTask(backing_file_path_, policy_copy, NULL, false)); |
249 } | 250 } |
250 return new_policy_differs; | 251 return new_policy_differs; |
251 } | 252 } |
252 | 253 |
253 bool CloudPolicyCache::SetDevicePolicy(const em::DevicePolicyResponse& policy) { | 254 bool CloudPolicyCache::SetDevicePolicy(const em::DevicePolicyResponse& policy) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
295 observer_list_, OnUpdatePolicy()); | 296 observer_list_, OnUpdatePolicy()); |
296 | 297 |
297 BrowserThread::PostTask( | 298 BrowserThread::PostTask( |
298 BrowserThread::FILE, | 299 BrowserThread::FILE, |
299 FROM_HERE, | 300 FROM_HERE, |
300 new PersistPolicyTask(backing_file_path_, NULL, NULL, true)); | 301 new PersistPolicyTask(backing_file_path_, NULL, NULL, true)); |
301 } | 302 } |
302 | 303 |
303 // static | 304 // static |
304 bool CloudPolicyCache::DecodePolicyResponse( | 305 bool CloudPolicyCache::DecodePolicyResponse( |
305 const em::CloudPolicyResponse& policy_response, | 306 const em::PolicyFetchResponse& policy_response, |
306 PolicyMap* mandatory, | 307 PolicyMap* mandatory, |
307 PolicyMap* recommended, | 308 PolicyMap* recommended, |
308 base::Time* timestamp) { | 309 base::Time* timestamp) { |
309 std::string data = policy_response.signed_response(); | 310 std::string data = policy_response.policy_data(); |
310 | 311 |
311 if (!VerifySignature(policy_response.signature(), data, | 312 if (!VerifySignature(policy_response.policy_data_signature(), data, |
312 policy_response.certificate_chain())) { | 313 policy_response.certificate_chain())) { |
313 LOG(WARNING) << "Failed to verify signature."; | 314 LOG(WARNING) << "Failed to verify signature."; |
314 return false; | 315 return false; |
315 } | 316 } |
316 | 317 |
317 em::SignedCloudPolicyResponse response; | 318 em::PolicyData policy_data; |
318 if (!response.ParseFromArray(data.c_str(), data.size())) { | 319 if (!policy_data.ParseFromString(data)) { |
319 LOG(WARNING) << "Failed to parse SignedCloudPolicyResponse protobuf."; | 320 LOG(WARNING) << "Failed to parse PolicyData protobuf."; |
320 return false; | 321 return false; |
321 } | 322 } |
322 | 323 |
323 // TODO(jkummerow): Verify response.device_token(). Needs final specification | 324 // TODO(jkummerow): Verify policy_data.device_token(). Needs final |
324 // which token we're actually sending / expecting to get back. | 325 // specification which token we're actually sending / expecting to get back. |
325 | 326 |
326 // TODO(jkummerow): Store response.device_name(), if we decide to transfer | 327 // TODO(jkummerow): Store policy_data.device_name(), if we decide to transfer |
327 // it from the server to the client. | 328 // it from the server to the client. |
328 | 329 |
329 DCHECK(timestamp); | 330 DCHECK(timestamp); |
330 *timestamp = base::Time::FromTimeT(response.timestamp()); | 331 *timestamp = base::Time::FromTimeT( |
331 DecodePolicy(response.settings(), mandatory, recommended); | 332 policy_data.timestamp() / kPolicyResponseTimestampResolution); |
Mattias Nissler (ping if slow)
2011/02/21 14:55:27
I'd recommend base::Time::UnixEpoch() + base::Time
Jakob Kummerow
2011/02/21 16:15:00
What? We're not doing any additions here. But we n
gfeher
2011/02/22 15:57:29
Yep. This is converting seconds to milliseconds.
Mattias Nissler (ping if slow)
2011/02/22 16:20:50
What I proposed is just a way of converting from y
| |
333 em::CloudPolicySettings policy; | |
334 if (!policy.ParseFromString(policy_data.policy_value())) { | |
335 LOG(WARNING) << "Failed to parse CloudPolicySettingsj protobuf."; | |
336 return false; | |
337 } | |
338 DecodePolicy(policy, mandatory, recommended); | |
332 return true; | 339 return true; |
333 } | 340 } |
334 | 341 |
335 // static | 342 // static |
336 bool CloudPolicyCache::VerifySignature( | 343 bool CloudPolicyCache::VerifySignature( |
337 const std::string& signature, | 344 const std::string& signature, |
338 const std::string& data, | 345 const std::string& data, |
339 const RepeatedPtrField<std::string>& certificate_chain) { | 346 const RepeatedPtrField<std::string>& certificate_chain) { |
340 // TODO(jkummerow): Implement this. Non-trivial because we want to do it | 347 // TODO(jkummerow): Implement this. Non-trivial because we want to do it |
341 // for all platforms -> it's enough work to deserve its own CL. | 348 // for all platforms -> it's enough work to deserve its own CL. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
451 CloudPolicyCache::DecodeValue(named_value->value()); | 458 CloudPolicyCache::DecodeValue(named_value->value()); |
452 if (decoded_value) | 459 if (decoded_value) |
453 result->Set(named_value->name(), decoded_value); | 460 result->Set(named_value->name(), decoded_value); |
454 } | 461 } |
455 } | 462 } |
456 } | 463 } |
457 return result; | 464 return result; |
458 } | 465 } |
459 | 466 |
460 } // namespace policy | 467 } // namespace policy |
OLD | NEW |