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