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 "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& user_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 user_id.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& user_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 user_id.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& user_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 user_id.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& user_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 user_id.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.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& user_id, Callback callback) override { |
107 DBusThreadManager::Get()->GetCryptohomeClient()-> | 103 DBusThreadManager::Get()->GetCryptohomeClient()->AsyncRemove( |
108 AsyncRemove(user_email, base::Bind( | 104 user_id.id(), |
109 &AsyncMethodCallerImpl::RegisterAsyncCallback, | 105 base::Bind(&AsyncMethodCallerImpl::RegisterAsyncCallback, |
110 weak_ptr_factory_.GetWeakPtr(), | 106 weak_ptr_factory_.GetWeakPtr(), callback, |
111 callback, | 107 "Couldn't initiate async removal of cryptohome.")); |
112 "Couldn't initiate async removal of cryptohome.")); | |
113 } | 108 } |
114 | 109 |
115 void AsyncTpmAttestationCreateEnrollRequest( | 110 void AsyncTpmAttestationCreateEnrollRequest( |
116 chromeos::attestation::PrivacyCAType pca_type, | 111 chromeos::attestation::PrivacyCAType pca_type, |
117 const DataCallback& callback) override { | 112 const DataCallback& callback) override { |
118 DBusThreadManager::Get()->GetCryptohomeClient()-> | 113 DBusThreadManager::Get()->GetCryptohomeClient()-> |
119 AsyncTpmAttestationCreateEnrollRequest(pca_type, base::Bind( | 114 AsyncTpmAttestationCreateEnrollRequest(pca_type, base::Bind( |
120 &AsyncMethodCallerImpl::RegisterAsyncDataCallback, | 115 &AsyncMethodCallerImpl::RegisterAsyncDataCallback, |
121 weak_ptr_factory_.GetWeakPtr(), | 116 weak_ptr_factory_.GetWeakPtr(), |
122 callback, | 117 callback, |
123 "Couldn't initiate async attestation enroll request.")); | 118 "Couldn't initiate async attestation enroll request.")); |
124 } | 119 } |
125 | 120 |
126 void AsyncTpmAttestationEnroll(chromeos::attestation::PrivacyCAType pca_type, | 121 void AsyncTpmAttestationEnroll(chromeos::attestation::PrivacyCAType pca_type, |
127 const std::string& pca_response, | 122 const std::string& pca_response, |
128 const Callback& callback) override { | 123 const Callback& callback) override { |
129 DBusThreadManager::Get()->GetCryptohomeClient()-> | 124 DBusThreadManager::Get()->GetCryptohomeClient()-> |
130 AsyncTpmAttestationEnroll(pca_type, pca_response, base::Bind( | 125 AsyncTpmAttestationEnroll(pca_type, pca_response, base::Bind( |
131 &AsyncMethodCallerImpl::RegisterAsyncCallback, | 126 &AsyncMethodCallerImpl::RegisterAsyncCallback, |
132 weak_ptr_factory_.GetWeakPtr(), | 127 weak_ptr_factory_.GetWeakPtr(), |
133 callback, | 128 callback, |
134 "Couldn't initiate async attestation enroll.")); | 129 "Couldn't initiate async attestation enroll.")); |
135 } | 130 } |
136 | 131 |
137 void AsyncTpmAttestationCreateCertRequest( | 132 void AsyncTpmAttestationCreateCertRequest( |
138 chromeos::attestation::PrivacyCAType pca_type, | 133 chromeos::attestation::PrivacyCAType pca_type, |
139 chromeos::attestation::AttestationCertificateProfile certificate_profile, | 134 chromeos::attestation::AttestationCertificateProfile certificate_profile, |
140 const std::string& user_id, | 135 const Identification& user_id, |
141 const std::string& request_origin, | 136 const std::string& request_origin, |
142 const DataCallback& callback) override { | 137 const DataCallback& callback) override { |
143 DBusThreadManager::Get()->GetCryptohomeClient()-> | 138 DBusThreadManager::Get() |
144 AsyncTpmAttestationCreateCertRequest( | 139 ->GetCryptohomeClient() |
145 pca_type, | 140 ->AsyncTpmAttestationCreateCertRequest( |
146 certificate_profile, | 141 pca_type, certificate_profile, user_id.id(), request_origin, |
147 user_id, | |
148 request_origin, | |
149 base::Bind(&AsyncMethodCallerImpl::RegisterAsyncDataCallback, | 142 base::Bind(&AsyncMethodCallerImpl::RegisterAsyncDataCallback, |
150 weak_ptr_factory_.GetWeakPtr(), | 143 weak_ptr_factory_.GetWeakPtr(), callback, |
151 callback, | |
152 "Couldn't initiate async attestation cert request.")); | 144 "Couldn't initiate async attestation cert request.")); |
153 } | 145 } |
154 | 146 |
155 void AsyncTpmAttestationFinishCertRequest( | 147 void AsyncTpmAttestationFinishCertRequest( |
156 const std::string& pca_response, | 148 const std::string& pca_response, |
157 chromeos::attestation::AttestationKeyType key_type, | 149 chromeos::attestation::AttestationKeyType key_type, |
158 const std::string& user_id, | 150 const Identification& user_id, |
159 const std::string& key_name, | 151 const std::string& key_name, |
160 const DataCallback& callback) override { | 152 const DataCallback& callback) override { |
161 DBusThreadManager::Get()->GetCryptohomeClient()-> | 153 DBusThreadManager::Get() |
162 AsyncTpmAttestationFinishCertRequest( | 154 ->GetCryptohomeClient() |
163 pca_response, | 155 ->AsyncTpmAttestationFinishCertRequest( |
164 key_type, | 156 pca_response, key_type, user_id.id(), key_name, |
165 user_id, | |
166 key_name, | |
167 base::Bind( | 157 base::Bind( |
168 &AsyncMethodCallerImpl::RegisterAsyncDataCallback, | 158 &AsyncMethodCallerImpl::RegisterAsyncDataCallback, |
169 weak_ptr_factory_.GetWeakPtr(), | 159 weak_ptr_factory_.GetWeakPtr(), callback, |
170 callback, | |
171 "Couldn't initiate async attestation finish cert request.")); | 160 "Couldn't initiate async attestation finish cert request.")); |
172 } | 161 } |
173 | 162 |
174 void TpmAttestationRegisterKey( | 163 void TpmAttestationRegisterKey( |
175 chromeos::attestation::AttestationKeyType key_type, | 164 chromeos::attestation::AttestationKeyType key_type, |
176 const std::string& user_id, | 165 const Identification& user_id, |
177 const std::string& key_name, | 166 const std::string& key_name, |
178 const Callback& callback) override { | 167 const Callback& callback) override { |
179 DBusThreadManager::Get()->GetCryptohomeClient()-> | 168 DBusThreadManager::Get()->GetCryptohomeClient()->TpmAttestationRegisterKey( |
180 TpmAttestationRegisterKey( | 169 key_type, user_id.id(), key_name, |
181 key_type, | 170 base::Bind(&AsyncMethodCallerImpl::RegisterAsyncCallback, |
182 user_id, | 171 weak_ptr_factory_.GetWeakPtr(), callback, |
183 key_name, | 172 "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 } | 173 } |
190 | 174 |
191 void TpmAttestationSignEnterpriseChallenge( | 175 void TpmAttestationSignEnterpriseChallenge( |
192 chromeos::attestation::AttestationKeyType key_type, | 176 chromeos::attestation::AttestationKeyType key_type, |
193 const std::string& user_id, | 177 const Identification& user_id, |
194 const std::string& key_name, | 178 const std::string& key_name, |
195 const std::string& domain, | 179 const std::string& domain, |
196 const std::string& device_id, | 180 const std::string& device_id, |
197 chromeos::attestation::AttestationChallengeOptions options, | 181 chromeos::attestation::AttestationChallengeOptions options, |
198 const std::string& challenge, | 182 const std::string& challenge, |
199 const DataCallback& callback) override { | 183 const DataCallback& callback) override { |
200 DBusThreadManager::Get()->GetCryptohomeClient()-> | 184 DBusThreadManager::Get() |
201 TpmAttestationSignEnterpriseChallenge( | 185 ->GetCryptohomeClient() |
202 key_type, | 186 ->TpmAttestationSignEnterpriseChallenge( |
203 user_id, | 187 key_type, user_id.id(), key_name, domain, device_id, options, |
204 key_name, | |
205 domain, | |
206 device_id, | |
207 options, | |
208 challenge, | 188 challenge, |
209 base::Bind( | 189 base::Bind( |
210 &AsyncMethodCallerImpl::RegisterAsyncDataCallback, | 190 &AsyncMethodCallerImpl::RegisterAsyncDataCallback, |
211 weak_ptr_factory_.GetWeakPtr(), | 191 weak_ptr_factory_.GetWeakPtr(), callback, |
212 callback, | |
213 "Couldn't initiate async attestation enterprise challenge.")); | 192 "Couldn't initiate async attestation enterprise challenge.")); |
214 } | 193 } |
215 | 194 |
216 void TpmAttestationSignSimpleChallenge( | 195 void TpmAttestationSignSimpleChallenge( |
217 chromeos::attestation::AttestationKeyType key_type, | 196 chromeos::attestation::AttestationKeyType key_type, |
218 const std::string& user_id, | 197 const Identification& user_id, |
219 const std::string& key_name, | 198 const std::string& key_name, |
220 const std::string& challenge, | 199 const std::string& challenge, |
221 const DataCallback& callback) override { | 200 const DataCallback& callback) override { |
222 DBusThreadManager::Get()->GetCryptohomeClient()-> | 201 DBusThreadManager::Get() |
223 TpmAttestationSignSimpleChallenge( | 202 ->GetCryptohomeClient() |
224 key_type, | 203 ->TpmAttestationSignSimpleChallenge( |
225 user_id, | 204 key_type, user_id.id(), key_name, challenge, |
226 key_name, | |
227 challenge, | |
228 base::Bind( | 205 base::Bind( |
229 &AsyncMethodCallerImpl::RegisterAsyncDataCallback, | 206 &AsyncMethodCallerImpl::RegisterAsyncDataCallback, |
230 weak_ptr_factory_.GetWeakPtr(), | 207 weak_ptr_factory_.GetWeakPtr(), callback, |
231 callback, | |
232 "Couldn't initiate async attestation simple challenge.")); | 208 "Couldn't initiate async attestation simple challenge.")); |
233 } | 209 } |
234 | 210 |
235 void AsyncGetSanitizedUsername(const std::string& user, | 211 void AsyncGetSanitizedUsername(const Identification& user_id, |
236 const DataCallback& callback) override { | 212 const DataCallback& callback) override { |
237 DBusThreadManager::Get()->GetCryptohomeClient()-> | 213 DBusThreadManager::Get()->GetCryptohomeClient()->GetSanitizedUsername( |
238 GetSanitizedUsername(user, | 214 user_id.id(), |
239 base::Bind( | 215 base::Bind(&AsyncMethodCallerImpl::GetSanitizedUsernameCallback, |
240 &AsyncMethodCallerImpl::GetSanitizedUsernameCallback, | 216 weak_ptr_factory_.GetWeakPtr(), callback)); |
241 weak_ptr_factory_.GetWeakPtr(), | |
242 callback)); | |
243 } | 217 } |
244 | 218 |
245 virtual void GetSanitizedUsernameCallback( | 219 virtual void GetSanitizedUsernameCallback( |
246 const DataCallback& callback, | 220 const DataCallback& callback, |
247 const chromeos::DBusMethodCallStatus call_status, | 221 const chromeos::DBusMethodCallStatus call_status, |
248 const std::string& result) { | 222 const std::string& result) { |
249 callback.Run(true, result); | 223 callback.Run(true, result); |
250 } | 224 } |
251 | 225 |
252 private: | 226 private: |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 g_async_method_caller = NULL; | 362 g_async_method_caller = NULL; |
389 VLOG(1) << "AsyncMethodCaller Shutdown completed"; | 363 VLOG(1) << "AsyncMethodCaller Shutdown completed"; |
390 } | 364 } |
391 | 365 |
392 // static | 366 // static |
393 AsyncMethodCaller* AsyncMethodCaller::GetInstance() { | 367 AsyncMethodCaller* AsyncMethodCaller::GetInstance() { |
394 return g_async_method_caller; | 368 return g_async_method_caller; |
395 } | 369 } |
396 | 370 |
397 } // namespace cryptohome | 371 } // namespace cryptohome |
OLD | NEW |