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

Side by Side Diff: chromeos/cryptohome/async_method_caller.cc

Issue 1693383003: ChromeOS cryptohome should be able to use gaia id as user identifier. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add cryptohome::Identification() . Created 4 years, 10 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
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 "chromeos/cryptohome/async_method_caller.h" 5 #include "chromeos/cryptohome/async_method_caller.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/containers/hash_tables.h" 8 #include "base/containers/hash_tables.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/thread_task_runner_handle.h" 12 #include "base/thread_task_runner_handle.h"
13 #include "chromeos/cryptohome/cryptohome_parameters.h"
13 #include "chromeos/dbus/dbus_thread_manager.h" 14 #include "chromeos/dbus/dbus_thread_manager.h"
14 15
15 using chromeos::DBusThreadManager; 16 using chromeos::DBusThreadManager;
16 17
17 namespace cryptohome { 18 namespace cryptohome {
18 19
19 namespace { 20 namespace {
20 21
21 AsyncMethodCaller* g_async_method_caller = NULL; 22 AsyncMethodCaller* g_async_method_caller = NULL;
22 23
23 // The implementation of AsyncMethodCaller 24 // The implementation of AsyncMethodCaller
24 class AsyncMethodCallerImpl : public AsyncMethodCaller { 25 class AsyncMethodCallerImpl : public AsyncMethodCaller {
25 public: 26 public:
26 AsyncMethodCallerImpl() : weak_ptr_factory_(this) { 27 AsyncMethodCallerImpl() : weak_ptr_factory_(this) {
27 DBusThreadManager::Get()->GetCryptohomeClient()->SetAsyncCallStatusHandlers( 28 DBusThreadManager::Get()->GetCryptohomeClient()->SetAsyncCallStatusHandlers(
28 base::Bind(&AsyncMethodCallerImpl::HandleAsyncResponse, 29 base::Bind(&AsyncMethodCallerImpl::HandleAsyncResponse,
29 weak_ptr_factory_.GetWeakPtr()), 30 weak_ptr_factory_.GetWeakPtr()),
30 base::Bind(&AsyncMethodCallerImpl::HandleAsyncDataResponse, 31 base::Bind(&AsyncMethodCallerImpl::HandleAsyncDataResponse,
31 weak_ptr_factory_.GetWeakPtr())); 32 weak_ptr_factory_.GetWeakPtr()));
32 } 33 }
33 34
34 ~AsyncMethodCallerImpl() override { 35 ~AsyncMethodCallerImpl() override {
35 DBusThreadManager::Get()->GetCryptohomeClient()-> 36 DBusThreadManager::Get()->GetCryptohomeClient()->
36 ResetAsyncCallStatusHandlers(); 37 ResetAsyncCallStatusHandlers();
37 } 38 }
38 39
39 void AsyncCheckKey(const std::string& user_email, 40 void AsyncCheckKey(const Identification& cryptohome_id,
40 const std::string& passhash, 41 const std::string& passhash,
41 Callback callback) override { 42 Callback callback) override {
42 DBusThreadManager::Get()->GetCryptohomeClient()-> 43 DBusThreadManager::Get()->GetCryptohomeClient()->AsyncCheckKey(
43 AsyncCheckKey(user_email, passhash, base::Bind( 44 cryptohome_id, passhash,
44 &AsyncMethodCallerImpl::RegisterAsyncCallback, 45 base::Bind(&AsyncMethodCallerImpl::RegisterAsyncCallback,
45 weak_ptr_factory_.GetWeakPtr(), 46 weak_ptr_factory_.GetWeakPtr(), callback,
46 callback, 47 "Couldn't initiate async check of user's key."));
47 "Couldn't initiate async check of user's key."));
48 } 48 }
49 49
50 void AsyncMigrateKey(const std::string& user_email, 50 void AsyncMigrateKey(const Identification& cryptohome_id,
51 const std::string& old_hash, 51 const std::string& old_hash,
52 const std::string& new_hash, 52 const std::string& new_hash,
53 Callback callback) override { 53 Callback callback) override {
54 DBusThreadManager::Get()->GetCryptohomeClient()-> 54 DBusThreadManager::Get()->GetCryptohomeClient()->AsyncMigrateKey(
55 AsyncMigrateKey(user_email, old_hash, new_hash, base::Bind( 55 cryptohome_id, old_hash, new_hash,
56 &AsyncMethodCallerImpl::RegisterAsyncCallback, 56 base::Bind(&AsyncMethodCallerImpl::RegisterAsyncCallback,
57 weak_ptr_factory_.GetWeakPtr(), 57 weak_ptr_factory_.GetWeakPtr(), callback,
58 callback, 58 "Couldn't initiate aync migration of user's key"));
59 "Couldn't initiate aync migration of user's key"));
60 } 59 }
61 60
62 void AsyncMount(const std::string& user_email, 61 void AsyncMount(const Identification& cryptohome_id,
63 const std::string& passhash, 62 const std::string& passhash,
64 int flags, 63 int flags,
65 Callback callback) override { 64 Callback callback) override {
66 DBusThreadManager::Get()->GetCryptohomeClient()-> 65 DBusThreadManager::Get()->GetCryptohomeClient()->AsyncMount(
67 AsyncMount(user_email, passhash, flags, base::Bind( 66 cryptohome_id, passhash, flags,
68 &AsyncMethodCallerImpl::RegisterAsyncCallback, 67 base::Bind(&AsyncMethodCallerImpl::RegisterAsyncCallback,
69 weak_ptr_factory_.GetWeakPtr(), 68 weak_ptr_factory_.GetWeakPtr(), callback,
70 callback, 69 "Couldn't initiate async mount of cryptohome."));
71 "Couldn't initiate async mount of cryptohome."));
72 } 70 }
73 71
74 void AsyncAddKey(const std::string& user_email, 72 void AsyncAddKey(const Identification& cryptohome_id,
75 const std::string& passhash, 73 const std::string& passhash,
76 const std::string& new_passhash, 74 const std::string& new_passhash,
77 Callback callback) override { 75 Callback callback) override {
78 DBusThreadManager::Get()->GetCryptohomeClient()-> 76 DBusThreadManager::Get()->GetCryptohomeClient()->AsyncAddKey(
79 AsyncAddKey(user_email, passhash, new_passhash, base::Bind( 77 cryptohome_id, passhash, new_passhash,
80 &AsyncMethodCallerImpl::RegisterAsyncCallback, 78 base::Bind(&AsyncMethodCallerImpl::RegisterAsyncCallback,
81 weak_ptr_factory_.GetWeakPtr(), 79 weak_ptr_factory_.GetWeakPtr(), callback,
82 callback, 80 "Couldn't initiate async key addition."));
83 "Couldn't initiate async key addition."));
84 } 81 }
85 82
86 void AsyncMountGuest(Callback callback) override { 83 void AsyncMountGuest(Callback callback) override {
87 DBusThreadManager::Get()->GetCryptohomeClient()-> 84 DBusThreadManager::Get()->GetCryptohomeClient()->
88 AsyncMountGuest(base::Bind( 85 AsyncMountGuest(base::Bind(
89 &AsyncMethodCallerImpl::RegisterAsyncCallback, 86 &AsyncMethodCallerImpl::RegisterAsyncCallback,
90 weak_ptr_factory_.GetWeakPtr(), 87 weak_ptr_factory_.GetWeakPtr(),
91 callback, 88 callback,
92 "Couldn't initiate async mount of cryptohome.")); 89 "Couldn't initiate async mount of cryptohome."));
93 } 90 }
94 91
95 void AsyncMountPublic(const std::string& public_mount_id, 92 void AsyncMountPublic(const Identification& public_mount_id,
96 int flags, 93 int flags,
97 Callback callback) override { 94 Callback callback) override {
98 DBusThreadManager::Get()->GetCryptohomeClient()-> 95 DBusThreadManager::Get()->GetCryptohomeClient()->AsyncMountPublic(
99 AsyncMountPublic(public_mount_id, flags, base::Bind( 96 public_mount_id, flags,
100 &AsyncMethodCallerImpl::RegisterAsyncCallback, 97 base::Bind(&AsyncMethodCallerImpl::RegisterAsyncCallback,
101 weak_ptr_factory_.GetWeakPtr(), 98 weak_ptr_factory_.GetWeakPtr(), callback,
102 callback, 99 "Couldn't initiate async mount public of cryptohome."));
103 "Couldn't initiate async mount public of cryptohome."));
104 } 100 }
105 101
106 void AsyncRemove(const std::string& user_email, Callback callback) override { 102 void AsyncRemove(const Identification& cryptohome_id,
107 DBusThreadManager::Get()->GetCryptohomeClient()-> 103 Callback callback) override {
108 AsyncRemove(user_email, base::Bind( 104 DBusThreadManager::Get()->GetCryptohomeClient()->AsyncRemove(
109 &AsyncMethodCallerImpl::RegisterAsyncCallback, 105 cryptohome_id,
110 weak_ptr_factory_.GetWeakPtr(), 106 base::Bind(&AsyncMethodCallerImpl::RegisterAsyncCallback,
111 callback, 107 weak_ptr_factory_.GetWeakPtr(), callback,
112 "Couldn't initiate async removal of cryptohome.")); 108 "Couldn't initiate async removal of cryptohome."));
113 } 109 }
114 110
115 void AsyncTpmAttestationCreateEnrollRequest( 111 void AsyncTpmAttestationCreateEnrollRequest(
116 chromeos::attestation::PrivacyCAType pca_type, 112 chromeos::attestation::PrivacyCAType pca_type,
117 const DataCallback& callback) override { 113 const DataCallback& callback) override {
118 DBusThreadManager::Get()->GetCryptohomeClient()-> 114 DBusThreadManager::Get()->GetCryptohomeClient()->
119 AsyncTpmAttestationCreateEnrollRequest(pca_type, base::Bind( 115 AsyncTpmAttestationCreateEnrollRequest(pca_type, base::Bind(
120 &AsyncMethodCallerImpl::RegisterAsyncDataCallback, 116 &AsyncMethodCallerImpl::RegisterAsyncDataCallback,
121 weak_ptr_factory_.GetWeakPtr(), 117 weak_ptr_factory_.GetWeakPtr(),
122 callback, 118 callback,
123 "Couldn't initiate async attestation enroll request.")); 119 "Couldn't initiate async attestation enroll request."));
124 } 120 }
125 121
126 void AsyncTpmAttestationEnroll(chromeos::attestation::PrivacyCAType pca_type, 122 void AsyncTpmAttestationEnroll(chromeos::attestation::PrivacyCAType pca_type,
127 const std::string& pca_response, 123 const std::string& pca_response,
128 const Callback& callback) override { 124 const Callback& callback) override {
129 DBusThreadManager::Get()->GetCryptohomeClient()-> 125 DBusThreadManager::Get()->GetCryptohomeClient()->
130 AsyncTpmAttestationEnroll(pca_type, pca_response, base::Bind( 126 AsyncTpmAttestationEnroll(pca_type, pca_response, base::Bind(
131 &AsyncMethodCallerImpl::RegisterAsyncCallback, 127 &AsyncMethodCallerImpl::RegisterAsyncCallback,
132 weak_ptr_factory_.GetWeakPtr(), 128 weak_ptr_factory_.GetWeakPtr(),
133 callback, 129 callback,
134 "Couldn't initiate async attestation enroll.")); 130 "Couldn't initiate async attestation enroll."));
135 } 131 }
136 132
137 void AsyncTpmAttestationCreateCertRequest( 133 void AsyncTpmAttestationCreateCertRequest(
138 chromeos::attestation::PrivacyCAType pca_type, 134 chromeos::attestation::PrivacyCAType pca_type,
139 chromeos::attestation::AttestationCertificateProfile certificate_profile, 135 chromeos::attestation::AttestationCertificateProfile certificate_profile,
140 const std::string& user_id, 136 const Identification& cryptohome_id,
141 const std::string& request_origin, 137 const std::string& request_origin,
142 const DataCallback& callback) override { 138 const DataCallback& callback) override {
143 DBusThreadManager::Get()->GetCryptohomeClient()-> 139 DBusThreadManager::Get()
144 AsyncTpmAttestationCreateCertRequest( 140 ->GetCryptohomeClient()
145 pca_type, 141 ->AsyncTpmAttestationCreateCertRequest(
146 certificate_profile, 142 pca_type, certificate_profile, cryptohome_id, request_origin,
147 user_id,
148 request_origin,
149 base::Bind(&AsyncMethodCallerImpl::RegisterAsyncDataCallback, 143 base::Bind(&AsyncMethodCallerImpl::RegisterAsyncDataCallback,
150 weak_ptr_factory_.GetWeakPtr(), 144 weak_ptr_factory_.GetWeakPtr(), callback,
151 callback,
152 "Couldn't initiate async attestation cert request.")); 145 "Couldn't initiate async attestation cert request."));
153 } 146 }
154 147
155 void AsyncTpmAttestationFinishCertRequest( 148 void AsyncTpmAttestationFinishCertRequest(
156 const std::string& pca_response, 149 const std::string& pca_response,
157 chromeos::attestation::AttestationKeyType key_type, 150 chromeos::attestation::AttestationKeyType key_type,
158 const std::string& user_id, 151 const Identification& cryptohome_id,
159 const std::string& key_name, 152 const std::string& key_name,
160 const DataCallback& callback) override { 153 const DataCallback& callback) override {
161 DBusThreadManager::Get()->GetCryptohomeClient()-> 154 DBusThreadManager::Get()
162 AsyncTpmAttestationFinishCertRequest( 155 ->GetCryptohomeClient()
163 pca_response, 156 ->AsyncTpmAttestationFinishCertRequest(
164 key_type, 157 pca_response, key_type, cryptohome_id, key_name,
165 user_id,
166 key_name,
167 base::Bind( 158 base::Bind(
168 &AsyncMethodCallerImpl::RegisterAsyncDataCallback, 159 &AsyncMethodCallerImpl::RegisterAsyncDataCallback,
169 weak_ptr_factory_.GetWeakPtr(), 160 weak_ptr_factory_.GetWeakPtr(), callback,
170 callback,
171 "Couldn't initiate async attestation finish cert request.")); 161 "Couldn't initiate async attestation finish cert request."));
172 } 162 }
173 163
174 void TpmAttestationRegisterKey( 164 void TpmAttestationRegisterKey(
175 chromeos::attestation::AttestationKeyType key_type, 165 chromeos::attestation::AttestationKeyType key_type,
176 const std::string& user_id, 166 const Identification& cryptohome_id,
177 const std::string& key_name, 167 const std::string& key_name,
178 const Callback& callback) override { 168 const Callback& callback) override {
179 DBusThreadManager::Get()->GetCryptohomeClient()-> 169 DBusThreadManager::Get()->GetCryptohomeClient()->TpmAttestationRegisterKey(
180 TpmAttestationRegisterKey( 170 key_type, cryptohome_id, key_name,
181 key_type, 171 base::Bind(&AsyncMethodCallerImpl::RegisterAsyncCallback,
182 user_id, 172 weak_ptr_factory_.GetWeakPtr(), callback,
183 key_name, 173 "Couldn't initiate async attestation register key."));
184 base::Bind(
185 &AsyncMethodCallerImpl::RegisterAsyncCallback,
186 weak_ptr_factory_.GetWeakPtr(),
187 callback,
188 "Couldn't initiate async attestation register key."));
189 } 174 }
190 175
191 void TpmAttestationSignEnterpriseChallenge( 176 void TpmAttestationSignEnterpriseChallenge(
192 chromeos::attestation::AttestationKeyType key_type, 177 chromeos::attestation::AttestationKeyType key_type,
193 const std::string& user_id, 178 const Identification& cryptohome_id,
194 const std::string& key_name, 179 const std::string& key_name,
195 const std::string& domain, 180 const std::string& domain,
196 const std::string& device_id, 181 const std::string& device_id,
197 chromeos::attestation::AttestationChallengeOptions options, 182 chromeos::attestation::AttestationChallengeOptions options,
198 const std::string& challenge, 183 const std::string& challenge,
199 const DataCallback& callback) override { 184 const DataCallback& callback) override {
200 DBusThreadManager::Get()->GetCryptohomeClient()-> 185 DBusThreadManager::Get()
201 TpmAttestationSignEnterpriseChallenge( 186 ->GetCryptohomeClient()
202 key_type, 187 ->TpmAttestationSignEnterpriseChallenge(
203 user_id, 188 key_type, cryptohome_id, key_name, domain, device_id, options,
204 key_name,
205 domain,
206 device_id,
207 options,
208 challenge, 189 challenge,
209 base::Bind( 190 base::Bind(
210 &AsyncMethodCallerImpl::RegisterAsyncDataCallback, 191 &AsyncMethodCallerImpl::RegisterAsyncDataCallback,
211 weak_ptr_factory_.GetWeakPtr(), 192 weak_ptr_factory_.GetWeakPtr(), callback,
212 callback,
213 "Couldn't initiate async attestation enterprise challenge.")); 193 "Couldn't initiate async attestation enterprise challenge."));
214 } 194 }
215 195
216 void TpmAttestationSignSimpleChallenge( 196 void TpmAttestationSignSimpleChallenge(
217 chromeos::attestation::AttestationKeyType key_type, 197 chromeos::attestation::AttestationKeyType key_type,
218 const std::string& user_id, 198 const Identification& cryptohome_id,
219 const std::string& key_name, 199 const std::string& key_name,
220 const std::string& challenge, 200 const std::string& challenge,
221 const DataCallback& callback) override { 201 const DataCallback& callback) override {
222 DBusThreadManager::Get()->GetCryptohomeClient()-> 202 DBusThreadManager::Get()
223 TpmAttestationSignSimpleChallenge( 203 ->GetCryptohomeClient()
224 key_type, 204 ->TpmAttestationSignSimpleChallenge(
225 user_id, 205 key_type, cryptohome_id, key_name, challenge,
226 key_name,
227 challenge,
228 base::Bind( 206 base::Bind(
229 &AsyncMethodCallerImpl::RegisterAsyncDataCallback, 207 &AsyncMethodCallerImpl::RegisterAsyncDataCallback,
230 weak_ptr_factory_.GetWeakPtr(), 208 weak_ptr_factory_.GetWeakPtr(), callback,
231 callback,
232 "Couldn't initiate async attestation simple challenge.")); 209 "Couldn't initiate async attestation simple challenge."));
233 } 210 }
234 211
235 void AsyncGetSanitizedUsername(const std::string& user, 212 void AsyncGetSanitizedUsername(const Identification& cryptohome_id,
236 const DataCallback& callback) override { 213 const DataCallback& callback) override {
237 DBusThreadManager::Get()->GetCryptohomeClient()-> 214 DBusThreadManager::Get()->GetCryptohomeClient()->GetSanitizedUsername(
238 GetSanitizedUsername(user, 215 cryptohome_id,
239 base::Bind( 216 base::Bind(&AsyncMethodCallerImpl::GetSanitizedUsernameCallback,
240 &AsyncMethodCallerImpl::GetSanitizedUsernameCallback, 217 weak_ptr_factory_.GetWeakPtr(), callback));
241 weak_ptr_factory_.GetWeakPtr(),
242 callback));
243 } 218 }
244 219
245 virtual void GetSanitizedUsernameCallback( 220 virtual void GetSanitizedUsernameCallback(
246 const DataCallback& callback, 221 const DataCallback& callback,
247 const chromeos::DBusMethodCallStatus call_status, 222 const chromeos::DBusMethodCallStatus call_status,
248 const std::string& result) { 223 const std::string& result) {
249 callback.Run(true, result); 224 callback.Run(true, result);
250 } 225 }
251 226
252 private: 227 private:
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 g_async_method_caller = NULL; 363 g_async_method_caller = NULL;
389 VLOG(1) << "AsyncMethodCaller Shutdown completed"; 364 VLOG(1) << "AsyncMethodCaller Shutdown completed";
390 } 365 }
391 366
392 // static 367 // static
393 AsyncMethodCaller* AsyncMethodCaller::GetInstance() { 368 AsyncMethodCaller* AsyncMethodCaller::GetInstance() {
394 return g_async_method_caller; 369 return g_async_method_caller;
395 } 370 }
396 371
397 } // namespace cryptohome 372 } // namespace cryptohome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698