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

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

Issue 2796303005: cros: Call GetPrivateSlotForChromeOSUser properly (Closed)
Patch Set: Created 3 years, 8 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 using content::BrowserThread; 47 using content::BrowserThread;
48 using ownership::OwnerKeyUtil; 48 using ownership::OwnerKeyUtil;
49 using ownership::PrivateKey; 49 using ownership::PrivateKey;
50 using ownership::PublicKey; 50 using ownership::PublicKey;
51 51
52 namespace chromeos { 52 namespace chromeos {
53 53
54 namespace { 54 namespace {
55 55
56 using ReloadKeyCallback =
57 base::Callback<void(const scoped_refptr<PublicKey>& public_key,
58 const scoped_refptr<PrivateKey>& private_key)>;
59
56 bool IsOwnerInTests(const std::string& user_id) { 60 bool IsOwnerInTests(const std::string& user_id) {
57 if (user_id.empty() || 61 if (user_id.empty() ||
58 !base::CommandLine::ForCurrentProcess()->HasSwitch( 62 !base::CommandLine::ForCurrentProcess()->HasSwitch(
59 ::switches::kTestType) || 63 ::switches::kTestType) ||
60 !CrosSettings::IsInitialized()) { 64 !CrosSettings::IsInitialized()) {
61 return false; 65 return false;
62 } 66 }
63 const base::Value* value = CrosSettings::Get()->GetPref(kDeviceOwner); 67 const base::Value* value = CrosSettings::Get()->GetPref(kDeviceOwner);
64 if (!value || value->GetType() != base::Value::Type::STRING) 68 if (!value || value->GetType() != base::Value::Type::STRING)
65 return false; 69 return false;
66 return static_cast<const base::Value*>(value)->GetString() == user_id; 70 return static_cast<const base::Value*>(value)->GetString() == user_id;
67 } 71 }
68 72
69 void LoadPrivateKeyByPublicKeyOnWorkerThread( 73 void LoadPrivateKeyByPublicKeyOnWorkerThread(
70 const scoped_refptr<OwnerKeyUtil>& owner_key_util, 74 const scoped_refptr<OwnerKeyUtil>& owner_key_util,
71 crypto::ScopedPK11Slot public_slot, 75 crypto::ScopedPK11Slot public_slot,
72 crypto::ScopedPK11Slot private_slot, 76 crypto::ScopedPK11Slot private_slot,
73 const base::Callback<void(const scoped_refptr<PublicKey>& public_key, 77 const ReloadKeyCallback& callback) {
74 const scoped_refptr<PrivateKey>& private_key)>&
75 callback) {
76 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); 78 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread());
77 79
78 std::vector<uint8_t> public_key_data; 80 std::vector<uint8_t> public_key_data;
79 scoped_refptr<PublicKey> public_key; 81 scoped_refptr<PublicKey> public_key;
80 if (!owner_key_util->ImportPublicKey(&public_key_data)) { 82 if (!owner_key_util->ImportPublicKey(&public_key_data)) {
81 scoped_refptr<PrivateKey> private_key; 83 scoped_refptr<PrivateKey> private_key;
82 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 84 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
83 base::Bind(callback, public_key, private_key)); 85 base::Bind(callback, public_key, private_key));
84 return; 86 return;
85 } 87 }
(...skipping 13 matching lines...) Expand all
99 private_slot.get()))); 101 private_slot.get())));
100 if (!private_key->key()) { 102 if (!private_key->key()) {
101 private_key = new PrivateKey(owner_key_util->FindPrivateKeyInSlot( 103 private_key = new PrivateKey(owner_key_util->FindPrivateKeyInSlot(
102 public_key->data(), public_slot.get())); 104 public_key->data(), public_slot.get()));
103 } 105 }
104 BrowserThread::PostTask(BrowserThread::UI, 106 BrowserThread::PostTask(BrowserThread::UI,
105 FROM_HERE, 107 FROM_HERE,
106 base::Bind(callback, public_key, private_key)); 108 base::Bind(callback, public_key, private_key));
107 } 109 }
108 110
109 void LoadPrivateKeyOnIOThread( 111 void ContinueLoadPrivateKeyOnIOThread(
110 const scoped_refptr<OwnerKeyUtil>& owner_key_util, 112 const scoped_refptr<OwnerKeyUtil>& owner_key_util,
111 const std::string username_hash, 113 const std::string username_hash,
112 const base::Callback<void(const scoped_refptr<PublicKey>& public_key, 114 const ReloadKeyCallback& callback,
113 const scoped_refptr<PrivateKey>& private_key)>& 115 crypto::ScopedPK11Slot private_slot) {
114 callback) {
115 DCHECK_CURRENTLY_ON(BrowserThread::IO); 116 DCHECK_CURRENTLY_ON(BrowserThread::IO);
116 117
117 crypto::EnsureNSSInit();
118 crypto::ScopedPK11Slot public_slot =
119 crypto::GetPublicSlotForChromeOSUser(username_hash);
120 crypto::ScopedPK11Slot private_slot = crypto::GetPrivateSlotForChromeOSUser(
121 username_hash, base::Callback<void(crypto::ScopedPK11Slot)>());
122
123 scoped_refptr<base::TaskRunner> task_runner = 118 scoped_refptr<base::TaskRunner> task_runner =
124 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior( 119 BrowserThread::GetBlockingPool()->GetTaskRunnerWithShutdownBehavior(
125 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN); 120 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN);
126 task_runner->PostTask( 121 task_runner->PostTask(
127 FROM_HERE, 122 FROM_HERE,
128 base::Bind(&LoadPrivateKeyByPublicKeyOnWorkerThread, owner_key_util, 123 base::Bind(
129 base::Passed(std::move(public_slot)), 124 &LoadPrivateKeyByPublicKeyOnWorkerThread, owner_key_util,
130 base::Passed(std::move(private_slot)), callback)); 125 base::Passed(crypto::GetPublicSlotForChromeOSUser(username_hash)),
126 base::Passed(std::move(private_slot)), callback));
127 }
128
129 void LoadPrivateKeyOnIOThread(const scoped_refptr<OwnerKeyUtil>& owner_key_util,
mattm 2017/04/06 18:00:52 Is it possible for this function to get called mul
xiyuan 2017/04/06 18:14:25 Yes, it is possible. I have seen two overlapping c
mattm 2017/04/06 18:23:27 If it's already happening and the code is fine wit
130 const std::string username_hash,
131 const ReloadKeyCallback& callback) {
132 DCHECK_CURRENTLY_ON(BrowserThread::IO);
133
134 crypto::EnsureNSSInit();
135
136 auto continue_load_private_key_callback =
137 base::Bind(&ContinueLoadPrivateKeyOnIOThread, owner_key_util,
138 username_hash, callback);
139
140 crypto::ScopedPK11Slot private_slot = crypto::GetPrivateSlotForChromeOSUser(
141 username_hash, continue_load_private_key_callback);
142 if (private_slot)
143 continue_load_private_key_callback.Run(std::move(private_slot));
131 } 144 }
132 145
133 bool DoesPrivateKeyExistAsyncHelper( 146 bool DoesPrivateKeyExistAsyncHelper(
134 const scoped_refptr<OwnerKeyUtil>& owner_key_util) { 147 const scoped_refptr<OwnerKeyUtil>& owner_key_util) {
135 std::vector<uint8_t> public_key; 148 std::vector<uint8_t> public_key;
136 if (!owner_key_util->ImportPublicKey(&public_key)) 149 if (!owner_key_util->ImportPublicKey(&public_key))
137 return false; 150 return false;
138 crypto::ScopedSECKEYPrivateKey key = 151 crypto::ScopedSECKEYPrivateKey key =
139 crypto::FindNSSKeyFromPublicKeyInfo(public_key); 152 crypto::FindNSSKeyFromPublicKeyInfo(public_key);
140 return key && SECKEY_GetPrivateKeyType(key.get()) == rsaKey; 153 return key && SECKEY_GetPrivateKeyType(key.get()) == rsaKey;
(...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 745
733 void OwnerSettingsServiceChromeOS::ReportStatusAndContinueStoring( 746 void OwnerSettingsServiceChromeOS::ReportStatusAndContinueStoring(
734 bool success) { 747 bool success) {
735 store_settings_factory_.InvalidateWeakPtrs(); 748 store_settings_factory_.InvalidateWeakPtrs();
736 for (auto& observer : observers_) 749 for (auto& observer : observers_)
737 observer.OnSignedPolicyStored(success); 750 observer.OnSignedPolicyStored(success);
738 StorePendingChanges(); 751 StorePendingChanges();
739 } 752 }
740 753
741 } // namespace chromeos 754 } // 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