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