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

Side by Side Diff: chrome/browser/chromeos/ownership/owner_settings_service_chromeos.cc

Issue 2761353003: Call OwnerKeyUtil::FindPrivateKeyInSlot() in the blocking pool. (Closed)
Patch Set: DCHECK for worker thread. Created 3 years, 9 months 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/ownership/owner_settings_service_chromeos.h" 5 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
6 6
7 #include <keyhi.h> 7 #include <keyhi.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 ::switches::kTestType) || 58 ::switches::kTestType) ||
59 !CrosSettings::IsInitialized()) { 59 !CrosSettings::IsInitialized()) {
60 return false; 60 return false;
61 } 61 }
62 const base::Value* value = CrosSettings::Get()->GetPref(kDeviceOwner); 62 const base::Value* value = CrosSettings::Get()->GetPref(kDeviceOwner);
63 if (!value || value->GetType() != base::Value::Type::STRING) 63 if (!value || value->GetType() != base::Value::Type::STRING)
64 return false; 64 return false;
65 return static_cast<const base::Value*>(value)->GetString() == user_id; 65 return static_cast<const base::Value*>(value)->GetString() == user_id;
66 } 66 }
67 67
68 void LoadPrivateKeyByPublicKey( 68 void LoadPrivateKeyByPublicKeyOnWorkerThread(
69 const scoped_refptr<OwnerKeyUtil>& owner_key_util, 69 const scoped_refptr<OwnerKeyUtil>& owner_key_util,
70 scoped_refptr<PublicKey> public_key, 70 scoped_refptr<PublicKey> public_key,
71 const std::string& username_hash, 71 crypto::ScopedPK11Slot public_slot,
72 crypto::ScopedPK11Slot private_slot,
72 const base::Callback<void(const scoped_refptr<PublicKey>& public_key, 73 const base::Callback<void(const scoped_refptr<PublicKey>& public_key,
73 const scoped_refptr<PrivateKey>& private_key)>& 74 const scoped_refptr<PrivateKey>& private_key)>&
74 callback) { 75 callback) {
75 crypto::EnsureNSSInit(); 76 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
76 crypto::ScopedPK11Slot public_slot =
77 crypto::GetPublicSlotForChromeOSUser(username_hash);
78 crypto::ScopedPK11Slot private_slot = crypto::GetPrivateSlotForChromeOSUser(
79 username_hash, base::Callback<void(crypto::ScopedPK11Slot)>());
80 77
81 // If private slot is already available, this will check it. If not, we'll get 78 // If private slot is already available, this will check it. If not, we'll get
82 // called again later when the TPM Token is ready, and the slot will be 79 // called again later when the TPM Token is ready, and the slot will be
83 // available then. FindPrivateKeyInSlot internally checks for a null slot if 80 // available then. FindPrivateKeyInSlot internally checks for a null slot if
84 // needbe. 81 // needbe.
85 // 82 //
86 // TODO(davidben): The null check should be in the caller rather than 83 // TODO(davidben): The null check should be in the caller rather than
87 // internally in the OwnerKeyUtil implementation. The tests currently get a 84 // internally in the OwnerKeyUtil implementation. The tests currently get a
88 // null private_slot and expect the mock OwnerKeyUtil to still be called. 85 // null private_slot and expect the mock OwnerKeyUtil to still be called.
89 scoped_refptr<PrivateKey> private_key( 86 scoped_refptr<PrivateKey> private_key(
90 new PrivateKey(owner_key_util->FindPrivateKeyInSlot(public_key->data(), 87 new PrivateKey(owner_key_util->FindPrivateKeyInSlot(public_key->data(),
91 private_slot.get()))); 88 private_slot.get())));
92 if (!private_key->key()) { 89 if (!private_key->key()) {
93 private_key = new PrivateKey(owner_key_util->FindPrivateKeyInSlot( 90 private_key = new PrivateKey(owner_key_util->FindPrivateKeyInSlot(
94 public_key->data(), public_slot.get())); 91 public_key->data(), public_slot.get()));
95 } 92 }
96 BrowserThread::PostTask(BrowserThread::UI, 93 BrowserThread::PostTask(BrowserThread::UI,
mattm 2017/04/03 22:28:21 Seems a bit weird this posts explicitly to the UI
Shuhei Takahashi 2017/04/05 11:07:37 Maybe we can pass TaskRunner around to avoid being
97 FROM_HERE, 94 FROM_HERE,
98 base::Bind(callback, public_key, private_key)); 95 base::Bind(callback, public_key, private_key));
99 } 96 }
100 97
98 void LoadPrivateKeyByPublicKey(
99 const scoped_refptr<OwnerKeyUtil>& owner_key_util,
100 scoped_refptr<PublicKey> public_key,
101 const std::string& username_hash,
102 const base::Callback<void(const scoped_refptr<PublicKey>& public_key,
103 const scoped_refptr<PrivateKey>& private_key)>&
104 callback) {
105 DCHECK_CURRENTLY_ON(BrowserThread::IO);
davidben 2017/04/03 21:07:49 I was going to suggest that all of this move to th
mattm 2017/04/03 22:28:21 (Did you mean to say worker thread there, rather t
Shuhei Takahashi 2017/04/04 05:53:29 OK, then your suggestion is to make it "UI->IO->Wo
Shuhei Takahashi 2017/04/05 11:07:36 Updated the patch to avoid unnecessary thread swit
106
107 crypto::EnsureNSSInit();
108 crypto::ScopedPK11Slot public_slot =
109 crypto::GetPublicSlotForChromeOSUser(username_hash);
110 crypto::ScopedPK11Slot private_slot = crypto::GetPrivateSlotForChromeOSUser(
111 username_hash, base::Callback<void(crypto::ScopedPK11Slot)>());
mattm 2017/04/03 22:28:21 This isn't specifying a callback or checking the p
Shuhei Takahashi 2017/04/04 05:53:29 Sorry I don't know. I just mechanically moved the
112
113 // This task interacts with the TPM, so use the blocking pool.
114 scoped_refptr<base::TaskRunner> task_runner =
115 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
116 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
117 task_runner->PostTask(
118 FROM_HERE,
119 base::Bind(&LoadPrivateKeyByPublicKeyOnWorkerThread, owner_key_util,
120 public_key, base::Passed(std::move(public_slot)),
121 base::Passed(std::move(private_slot)), callback));
122 }
123
101 void LoadPrivateKey( 124 void LoadPrivateKey(
102 const scoped_refptr<OwnerKeyUtil>& owner_key_util, 125 const scoped_refptr<OwnerKeyUtil>& owner_key_util,
103 const std::string username_hash, 126 const std::string username_hash,
104 const base::Callback<void(const scoped_refptr<PublicKey>& public_key, 127 const base::Callback<void(const scoped_refptr<PublicKey>& public_key,
105 const scoped_refptr<PrivateKey>& private_key)>& 128 const scoped_refptr<PrivateKey>& private_key)>&
106 callback) { 129 callback) {
107 std::vector<uint8_t> public_key_data; 130 std::vector<uint8_t> public_key_data;
108 scoped_refptr<PublicKey> public_key; 131 scoped_refptr<PublicKey> public_key;
109 if (!owner_key_util->ImportPublicKey(&public_key_data)) { 132 if (!owner_key_util->ImportPublicKey(&public_key_data)) {
110 scoped_refptr<PrivateKey> private_key; 133 scoped_refptr<PrivateKey> private_key;
(...skipping 540 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 const bool is_owner = IsOwner() || IsOwnerInTests(user_id_); 674 const bool is_owner = IsOwner() || IsOwnerInTests(user_id_);
652 if (is_owner && device_settings_service_) 675 if (is_owner && device_settings_service_)
653 device_settings_service_->InitOwner(user_id_, weak_factory_.GetWeakPtr()); 676 device_settings_service_->InitOwner(user_id_, weak_factory_.GetWeakPtr());
654 677
655 has_pending_fixups_ = true; 678 has_pending_fixups_ = true;
656 } 679 }
657 680
658 void OwnerSettingsServiceChromeOS::ReloadKeypairImpl(const base::Callback< 681 void OwnerSettingsServiceChromeOS::ReloadKeypairImpl(const base::Callback<
659 void(const scoped_refptr<PublicKey>& public_key, 682 void(const scoped_refptr<PublicKey>& public_key,
660 const scoped_refptr<PrivateKey>& private_key)>& callback) { 683 const scoped_refptr<PrivateKey>& private_key)>& callback) {
661 DCHECK(thread_checker_.CalledOnValidThread()); 684 DCHECK(thread_checker_.CalledOnValidThread());
mattm 2017/04/03 22:28:21 What thread does this end up on? UI?
Shuhei Takahashi 2017/04/05 11:07:37 IIUC this object lives on the UI thread.
662 685
663 if (waiting_for_profile_creation_ || waiting_for_tpm_token_) 686 if (waiting_for_profile_creation_ || waiting_for_tpm_token_)
664 return; 687 return;
665 scoped_refptr<base::TaskRunner> task_runner = 688 scoped_refptr<base::TaskRunner> task_runner =
666 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( 689 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
667 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 690 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
668 task_runner->PostTask( 691 task_runner->PostTask(
669 FROM_HERE, 692 FROM_HERE,
670 base::Bind(&LoadPrivateKey, 693 base::Bind(&LoadPrivateKey,
671 owner_key_util_, 694 owner_key_util_,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 752
730 void OwnerSettingsServiceChromeOS::ReportStatusAndContinueStoring( 753 void OwnerSettingsServiceChromeOS::ReportStatusAndContinueStoring(
731 bool success) { 754 bool success) {
732 store_settings_factory_.InvalidateWeakPtrs(); 755 store_settings_factory_.InvalidateWeakPtrs();
733 for (auto& observer : observers_) 756 for (auto& observer : observers_)
734 observer.OnSignedPolicyStored(success); 757 observer.OnSignedPolicyStored(success);
735 StorePendingChanges(); 758 StorePendingChanges();
736 } 759 }
737 760
738 } // namespace chromeos 761 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698