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

Side by Side Diff: chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.cc

Issue 2488573003: Expose signing key from cloud policy stores (Closed)
Patch Set: Rebase 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/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
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
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 validator->ValidateSignatureAllowingRotation( 281 validator->ValidateSignatureAllowingRotation(
282 policy_key_, GetPolicyVerificationKey(), 282 public_key_, GetPolicyVerificationKey(),
283 ExtractDomain(account_id_.GetUserEmail())); 283 ExtractDomain(account_id_.GetUserEmail()));
284 } 284 }
285 285
286 // Start validation. The Validator will delete itself once validation is 286 // Start validation. The Validator will delete itself once validation is
287 // complete. 287 // complete.
288 validator.release()->StartValidation( 288 validator.release()->StartValidation(
289 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyToStoreValidated, 289 base::Bind(&UserCloudPolicyStoreChromeOS::OnPolicyToStoreValidated,
290 weak_factory_.GetWeakPtr())); 290 weak_factory_.GetWeakPtr()));
291 } 291 }
292 292
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 legacy_loader_.reset(); 353 legacy_loader_.reset();
354 354
355 std::unique_ptr<em::PolicyFetchResponse> policy( 355 std::unique_ptr<em::PolicyFetchResponse> policy(
356 new em::PolicyFetchResponse()); 356 new em::PolicyFetchResponse());
357 if (!policy->ParseFromString(policy_blob)) { 357 if (!policy->ParseFromString(policy_blob)) {
358 status_ = STATUS_PARSE_ERROR; 358 status_ = STATUS_PARSE_ERROR;
359 NotifyStoreError(); 359 NotifyStoreError();
360 return; 360 return;
361 } 361 }
362 362
363 // Load |policy_key_| to verify the loaded policy. 363 // Load |public_key_| to verify the loaded policy.
364 EnsurePolicyKeyLoaded( 364 EnsurePolicyKeyLoaded(
365 base::Bind(&UserCloudPolicyStoreChromeOS::ValidateRetrievedPolicy, 365 base::Bind(&UserCloudPolicyStoreChromeOS::ValidateRetrievedPolicy,
366 weak_factory_.GetWeakPtr(), 366 weak_factory_.GetWeakPtr(),
367 base::Passed(&policy))); 367 base::Passed(&policy)));
368 } 368 }
369 369
370 void UserCloudPolicyStoreChromeOS::ValidateRetrievedPolicy( 370 void UserCloudPolicyStoreChromeOS::ValidateRetrievedPolicy(
371 std::unique_ptr<em::PolicyFetchResponse> policy) { 371 std::unique_ptr<em::PolicyFetchResponse> policy) {
372 // Create and configure a validator for the loaded policy. 372 // Create and configure a validator for the loaded policy.
373 std::unique_ptr<UserCloudPolicyValidator> validator = 373 std::unique_ptr<UserCloudPolicyValidator> validator =
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 LOG(ERROR) << "Failed to read key at " << path.value(); 516 LOG(ERROR) << "Failed to read key at " << path.value();
517 } 517 }
518 518
519 if (key->empty()) 519 if (key->empty())
520 SampleValidationFailure(VALIDATION_FAILURE_LOAD_KEY); 520 SampleValidationFailure(VALIDATION_FAILURE_LOAD_KEY);
521 } 521 }
522 522
523 void UserCloudPolicyStoreChromeOS::OnPolicyKeyReloaded( 523 void UserCloudPolicyStoreChromeOS::OnPolicyKeyReloaded(
524 std::string* key, 524 std::string* key,
525 const base::Closure& callback) { 525 const base::Closure& callback) {
526 policy_key_ = *key; 526 public_key_ = *key;
527 policy_key_loaded_ = true; 527 policy_key_loaded_ = true;
528 callback.Run(); 528 callback.Run();
529 } 529 }
530 530
531 void UserCloudPolicyStoreChromeOS::EnsurePolicyKeyLoaded( 531 void UserCloudPolicyStoreChromeOS::EnsurePolicyKeyLoaded(
532 const base::Closure& callback) { 532 const base::Closure& callback) {
533 if (policy_key_loaded_) { 533 if (policy_key_loaded_) {
534 callback.Run(); 534 callback.Run();
535 } else { 535 } else {
536 // 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 22 matching lines...) Expand all
559 559
560 std::unique_ptr<UserCloudPolicyValidator> 560 std::unique_ptr<UserCloudPolicyValidator>
561 UserCloudPolicyStoreChromeOS::CreateValidatorForLoad( 561 UserCloudPolicyStoreChromeOS::CreateValidatorForLoad(
562 std::unique_ptr<em::PolicyFetchResponse> policy) { 562 std::unique_ptr<em::PolicyFetchResponse> policy) {
563 std::unique_ptr<UserCloudPolicyValidator> validator = CreateValidator( 563 std::unique_ptr<UserCloudPolicyValidator> validator = CreateValidator(
564 std::move(policy), CloudPolicyValidatorBase::TIMESTAMP_NOT_BEFORE); 564 std::move(policy), CloudPolicyValidatorBase::TIMESTAMP_NOT_BEFORE);
565 validator->ValidateUsername(account_id_.GetUserEmail(), true); 565 validator->ValidateUsername(account_id_.GetUserEmail(), true);
566 // The policy loaded from session manager need not be validated using the 566 // The policy loaded from session manager need not be validated using the
567 // verification key since it is secure, and since there may be legacy policy 567 // verification key since it is secure, and since there may be legacy policy
568 // data that was stored without a verification key. 568 // data that was stored without a verification key.
569 validator->ValidateSignature(policy_key_); 569 validator->ValidateSignature(public_key_);
570 return validator; 570 return validator;
571 } 571 }
572
572 } // namespace policy 573 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698