| 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/policy/user_cloud_policy_store_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 : UserCloudPolicyStoreBase(background_task_runner), | 187 : UserCloudPolicyStoreBase(background_task_runner), |
| 188 cryptohome_client_(cryptohome_client), | 188 cryptohome_client_(cryptohome_client), |
| 189 session_manager_client_(session_manager_client), | 189 session_manager_client_(session_manager_client), |
| 190 account_id_(account_id), | 190 account_id_(account_id), |
| 191 user_policy_key_dir_(user_policy_key_dir), | 191 user_policy_key_dir_(user_policy_key_dir), |
| 192 legacy_cache_dir_(legacy_token_cache_file.DirName()), | 192 legacy_cache_dir_(legacy_token_cache_file.DirName()), |
| 193 legacy_loader_(new LegacyPolicyCacheLoader(legacy_token_cache_file, | 193 legacy_loader_(new LegacyPolicyCacheLoader(legacy_token_cache_file, |
| 194 legacy_policy_cache_file, | 194 legacy_policy_cache_file, |
| 195 background_task_runner)), | 195 background_task_runner)), |
| 196 legacy_caches_loaded_(false), | 196 legacy_caches_loaded_(false), |
| 197 owning_domain_(ExtractDomain(account_id_.GetUserEmail())), |
| 197 policy_key_loaded_(false), | 198 policy_key_loaded_(false), |
| 198 weak_factory_(this) {} | 199 weak_factory_(this) {} |
| 199 | 200 |
| 200 UserCloudPolicyStoreChromeOS::~UserCloudPolicyStoreChromeOS() {} | 201 UserCloudPolicyStoreChromeOS::~UserCloudPolicyStoreChromeOS() {} |
| 201 | 202 |
| 202 void UserCloudPolicyStoreChromeOS::Store( | 203 void UserCloudPolicyStoreChromeOS::Store( |
| 203 const em::PolicyFetchResponse& policy) { | 204 const em::PolicyFetchResponse& policy) { |
| 204 // Cancel all pending requests. | 205 // Cancel all pending requests. |
| 205 weak_factory_.InvalidateWeakPtrs(); | 206 weak_factory_.InvalidateWeakPtrs(); |
| 206 std::unique_ptr<em::PolicyFetchResponse> response( | 207 std::unique_ptr<em::PolicyFetchResponse> response( |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 cryptohome_client_->BlockingGetSanitizedUsername( | 253 cryptohome_client_->BlockingGetSanitizedUsername( |
| 253 cryptohome::Identification(account_id_)); | 254 cryptohome::Identification(account_id_)); |
| 254 if (sanitized_username.empty()) { | 255 if (sanitized_username.empty()) { |
| 255 status_ = STATUS_LOAD_ERROR; | 256 status_ = STATUS_LOAD_ERROR; |
| 256 NotifyStoreError(); | 257 NotifyStoreError(); |
| 257 return; | 258 return; |
| 258 } | 259 } |
| 259 | 260 |
| 260 policy_key_path_ = user_policy_key_dir_.Append( | 261 policy_key_path_ = user_policy_key_dir_.Append( |
| 261 base::StringPrintf(kPolicyKeyFile, sanitized_username.c_str())); | 262 base::StringPrintf(kPolicyKeyFile, sanitized_username.c_str())); |
| 262 LoadPolicyKey(policy_key_path_, &policy_key_); | 263 LoadPolicyKey(policy_key_path_, &public_key_); |
| 263 policy_key_loaded_ = true; | 264 policy_key_loaded_ = true; |
| 264 | 265 |
| 265 std::unique_ptr<UserCloudPolicyValidator> validator = | 266 std::unique_ptr<UserCloudPolicyValidator> validator = |
| 266 CreateValidatorForLoad(std::move(policy)); | 267 CreateValidatorForLoad(std::move(policy)); |
| 267 validator->RunValidation(); | 268 validator->RunValidation(); |
| 268 OnRetrievedPolicyValidated(validator.get()); | 269 OnRetrievedPolicyValidated(validator.get()); |
| 269 } | 270 } |
| 270 | 271 |
| 271 void UserCloudPolicyStoreChromeOS::ValidatePolicyForStore( | 272 void UserCloudPolicyStoreChromeOS::ValidatePolicyForStore( |
| 272 std::unique_ptr<em::PolicyFetchResponse> policy) { | 273 std::unique_ptr<em::PolicyFetchResponse> policy) { |
| 273 // Create and configure a validator. | 274 // Create and configure a validator. |
| 274 std::unique_ptr<UserCloudPolicyValidator> validator = CreateValidator( | 275 std::unique_ptr<UserCloudPolicyValidator> validator = CreateValidator( |
| 275 std::move(policy), CloudPolicyValidatorBase::TIMESTAMP_FULLY_VALIDATED); | 276 std::move(policy), CloudPolicyValidatorBase::TIMESTAMP_FULLY_VALIDATED); |
| 276 validator->ValidateUsername(account_id_.GetUserEmail(), true); | 277 validator->ValidateUsername(account_id_.GetUserEmail(), true); |
| 277 if (policy_key_.empty()) { | 278 if (public_key_.empty()) { |
| 278 validator->ValidateInitialKey(GetPolicyVerificationKey(), | 279 validator->ValidateInitialKey(GetPolicyVerificationKey(), owning_domain_); |
| 279 ExtractDomain(account_id_.GetUserEmail())); | |
| 280 } else { | 280 } else { |
| 281 const bool allow_rotation = true; | 281 const bool allow_rotation = true; |
| 282 validator->ValidateSignature(policy_key_, GetPolicyVerificationKey(), | 282 validator->ValidateSignature(public_key_, GetPolicyVerificationKey(), |
| 283 ExtractDomain(account_id_.GetUserEmail()), | 283 owning_domain_, allow_rotation); |
| 284 allow_rotation); | |
| 285 } | 284 } |
| 286 | 285 |
| 287 // Start validation. The Validator will delete itself once validation is | 286 // Start validation. The Validator will delete itself once validation is |
| 288 // complete. | 287 // complete. |
| 289 validator.release()->StartValidation( | 288 validator.release()->StartValidation( |
| 290 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyToStoreValidated, | 289 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyToStoreValidated, |
| 291 weak_factory_.GetWeakPtr())); | 290 weak_factory_.GetWeakPtr())); |
| 292 } | 291 } |
| 293 | 292 |
| 294 void UserCloudPolicyStoreChromeOS::OnPolicyToStoreValidated( | 293 void UserCloudPolicyStoreChromeOS::OnPolicyToStoreValidated( |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 legacy_loader_.reset(); | 353 legacy_loader_.reset(); |
| 355 | 354 |
| 356 std::unique_ptr<em::PolicyFetchResponse> policy( | 355 std::unique_ptr<em::PolicyFetchResponse> policy( |
| 357 new em::PolicyFetchResponse()); | 356 new em::PolicyFetchResponse()); |
| 358 if (!policy->ParseFromString(policy_blob)) { | 357 if (!policy->ParseFromString(policy_blob)) { |
| 359 status_ = STATUS_PARSE_ERROR; | 358 status_ = STATUS_PARSE_ERROR; |
| 360 NotifyStoreError(); | 359 NotifyStoreError(); |
| 361 return; | 360 return; |
| 362 } | 361 } |
| 363 | 362 |
| 364 // Load |policy_key_| to verify the loaded policy. | 363 // Load |public_key_| to verify the loaded policy. |
| 365 EnsurePolicyKeyLoaded( | 364 EnsurePolicyKeyLoaded( |
| 366 base::Bind(&UserCloudPolicyStoreChromeOS::ValidateRetrievedPolicy, | 365 base::Bind(&UserCloudPolicyStoreChromeOS::ValidateRetrievedPolicy, |
| 367 weak_factory_.GetWeakPtr(), | 366 weak_factory_.GetWeakPtr(), |
| 368 base::Passed(&policy))); | 367 base::Passed(&policy))); |
| 369 } | 368 } |
| 370 | 369 |
| 371 void UserCloudPolicyStoreChromeOS::ValidateRetrievedPolicy( | 370 void UserCloudPolicyStoreChromeOS::ValidateRetrievedPolicy( |
| 372 std::unique_ptr<em::PolicyFetchResponse> policy) { | 371 std::unique_ptr<em::PolicyFetchResponse> policy) { |
| 373 // Create and configure a validator for the loaded policy. | 372 // Create and configure a validator for the loaded policy. |
| 374 std::unique_ptr<UserCloudPolicyValidator> validator = | 373 std::unique_ptr<UserCloudPolicyValidator> validator = |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 LOG(ERROR) << "Failed to read key at " << path.value(); | 516 LOG(ERROR) << "Failed to read key at " << path.value(); |
| 518 } | 517 } |
| 519 | 518 |
| 520 if (key->empty()) | 519 if (key->empty()) |
| 521 SampleValidationFailure(VALIDATION_FAILURE_LOAD_KEY); | 520 SampleValidationFailure(VALIDATION_FAILURE_LOAD_KEY); |
| 522 } | 521 } |
| 523 | 522 |
| 524 void UserCloudPolicyStoreChromeOS::OnPolicyKeyReloaded( | 523 void UserCloudPolicyStoreChromeOS::OnPolicyKeyReloaded( |
| 525 std::string* key, | 524 std::string* key, |
| 526 const base::Closure& callback) { | 525 const base::Closure& callback) { |
| 527 policy_key_ = *key; | 526 public_key_ = *key; |
| 528 policy_key_loaded_ = true; | 527 policy_key_loaded_ = true; |
| 529 callback.Run(); | 528 callback.Run(); |
| 530 } | 529 } |
| 531 | 530 |
| 532 void UserCloudPolicyStoreChromeOS::EnsurePolicyKeyLoaded( | 531 void UserCloudPolicyStoreChromeOS::EnsurePolicyKeyLoaded( |
| 533 const base::Closure& callback) { | 532 const base::Closure& callback) { |
| 534 if (policy_key_loaded_) { | 533 if (policy_key_loaded_) { |
| 535 callback.Run(); | 534 callback.Run(); |
| 536 } else { | 535 } else { |
| 537 // Get the hashed username that's part of the key's path, to determine | 536 // Get the hashed username that's part of the key's path, to determine |
| (...skipping 25 matching lines...) Expand all Loading... |
| 563 std::unique_ptr<em::PolicyFetchResponse> policy) { | 562 std::unique_ptr<em::PolicyFetchResponse> policy) { |
| 564 std::unique_ptr<UserCloudPolicyValidator> validator = CreateValidator( | 563 std::unique_ptr<UserCloudPolicyValidator> validator = CreateValidator( |
| 565 std::move(policy), CloudPolicyValidatorBase::TIMESTAMP_NOT_BEFORE); | 564 std::move(policy), CloudPolicyValidatorBase::TIMESTAMP_NOT_BEFORE); |
| 566 validator->ValidateUsername(account_id_.GetUserEmail(), true); | 565 validator->ValidateUsername(account_id_.GetUserEmail(), true); |
| 567 const bool allow_rotation = false; | 566 const bool allow_rotation = false; |
| 568 const std::string empty_key = std::string(); | 567 const std::string empty_key = std::string(); |
| 569 // The policy loaded from session manager need not be validated using the | 568 // The policy loaded from session manager need not be validated using the |
| 570 // verification key since it is secure, and since there may be legacy policy | 569 // verification key since it is secure, and since there may be legacy policy |
| 571 // data that was stored without a verification key. Hence passing an empty | 570 // data that was stored without a verification key. Hence passing an empty |
| 572 // value for the verification key. | 571 // value for the verification key. |
| 573 validator->ValidateSignature(policy_key_, empty_key, | 572 validator->ValidateSignature(public_key_, empty_key, owning_domain_, |
| 574 ExtractDomain(account_id_.GetUserEmail()), | |
| 575 allow_rotation); | 573 allow_rotation); |
| 576 return validator; | 574 return validator; |
| 577 } | 575 } |
| 578 } // namespace policy | 576 } // namespace policy |
| OLD | NEW |