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