OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/dbus/fake_cryptohome_client.h" | 5 #include "chromeos/dbus/fake_cryptohome_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | |
8 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "crypto/nss_util.h" | |
9 #include "third_party/cros_system_api/dbus/service_constants.h" | 11 #include "third_party/cros_system_api/dbus/service_constants.h" |
10 | 12 |
11 namespace chromeos { | 13 namespace chromeos { |
12 | 14 |
13 namespace { | 15 FakeCryptohomeClient::FakeCryptohomeClient() |
16 : async_call_id_(1), | |
17 tpm_is_ready_counter_(0), | |
18 unmount_result_(true), | |
19 locked_(false), | |
20 weak_ptr_factory_(this) {} | |
14 | 21 |
15 // A fake system salt. GetSystemSalt copies it to the given buffer. | 22 FakeCryptohomeClient::~FakeCryptohomeClient() {} |
16 const char kStubSystemSalt[] = "stub_system_salt"; | |
17 | |
18 } // namespace | |
19 | |
20 FakeCryptohomeClient::FakeCryptohomeClient() : unmount_result_(false) { | |
21 } | |
22 | |
23 FakeCryptohomeClient::~FakeCryptohomeClient() { | |
24 } | |
25 | 23 |
26 void FakeCryptohomeClient::Init(dbus::Bus* bus) { | 24 void FakeCryptohomeClient::Init(dbus::Bus* bus) { |
27 } | 25 } |
28 | 26 |
29 void FakeCryptohomeClient::TpmIsBeingOwned( | 27 void FakeCryptohomeClient::SetAsyncCallStatusHandlers( |
28 const AsyncCallStatusHandler& handler, | |
29 const AsyncCallStatusWithDataHandler& data_handler) { | |
30 async_call_status_handler_ = handler; | |
31 async_call_status_data_handler_ = data_handler; | |
32 } | |
33 | |
34 void FakeCryptohomeClient::ResetAsyncCallStatusHandlers() { | |
35 async_call_status_handler_.Reset(); | |
36 async_call_status_data_handler_.Reset(); | |
37 } | |
38 | |
39 void FakeCryptohomeClient::IsMounted( | |
30 const BoolDBusMethodCallback& callback) { | 40 const BoolDBusMethodCallback& callback) { |
41 base::MessageLoop::current()->PostTask( | |
42 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); | |
31 } | 43 } |
32 | 44 |
33 bool FakeCryptohomeClient::Unmount(bool* success) { | 45 bool FakeCryptohomeClient::Unmount(bool* success) { |
34 *success = unmount_result_; | 46 *success = unmount_result_; |
35 return true; | 47 return true; |
36 } | 48 } |
37 | 49 |
38 void FakeCryptohomeClient::AsyncCheckKey(const std::string& username, | 50 void FakeCryptohomeClient::AsyncCheckKey( |
39 const std::string& key, | 51 const std::string& username, |
40 const AsyncMethodCallback& callback) { | 52 const std::string& key, |
41 } | 53 const AsyncMethodCallback& callback) { |
42 | 54 ReturnAsyncMethodResult(callback, false); |
43 bool FakeCryptohomeClient::InstallAttributesIsInvalid(bool* is_invalid) { | |
44 return false; | |
45 } | |
46 | |
47 void FakeCryptohomeClient::TpmAttestationGetKeyPayload( | |
48 attestation::AttestationKeyType key_type, | |
49 const std::string& key_name, | |
50 const DataMethodCallback& callback) { | |
51 } | |
52 | |
53 void FakeCryptohomeClient::AsyncTpmAttestationFinishCertRequest( | |
54 const std::string& pca_response, | |
55 attestation::AttestationKeyType key_type, | |
56 const std::string& key_name, | |
57 const AsyncMethodCallback& callback) { | |
58 } | |
59 | |
60 void FakeCryptohomeClient::TpmIsEnabled( | |
61 const BoolDBusMethodCallback& callback) { | |
62 } | |
63 | |
64 void FakeCryptohomeClient::AsyncTpmAttestationEnroll( | |
65 const std::string& pca_response, | |
66 const AsyncMethodCallback& callback) { | |
67 } | 55 } |
68 | 56 |
69 void FakeCryptohomeClient::AsyncMigrateKey( | 57 void FakeCryptohomeClient::AsyncMigrateKey( |
70 const std::string& username, | 58 const std::string& username, |
71 const std::string& from_key, | 59 const std::string& from_key, |
72 const std::string& to_key, | 60 const std::string& to_key, |
73 const AsyncMethodCallback& callback) { | 61 const AsyncMethodCallback& callback) { |
74 } | 62 ReturnAsyncMethodResult(callback, false); |
75 | 63 } |
76 void FakeCryptohomeClient::IsMounted(const BoolDBusMethodCallback& callback) { | 64 |
77 base::MessageLoop::current()->PostTask(FROM_HERE, | 65 void FakeCryptohomeClient::AsyncRemove( |
78 base::Bind(callback, | 66 const std::string& username, |
79 DBUS_METHOD_CALL_SUCCESS, true)); | 67 const AsyncMethodCallback& callback) { |
80 } | 68 ReturnAsyncMethodResult(callback, false); |
81 | 69 } |
82 bool FakeCryptohomeClient::InstallAttributesGet(const std::string& name, | 70 |
83 std::vector<uint8>* value, | 71 bool FakeCryptohomeClient::GetSystemSalt(std::vector<uint8>* salt) { |
84 bool* successful) { | 72 const char kStubSystemSalt[] = "stub_system_salt"; |
85 return false; | 73 salt->assign(kStubSystemSalt, |
74 kStubSystemSalt + arraysize(kStubSystemSalt) - 1); | |
75 return true; | |
76 } | |
77 | |
78 void FakeCryptohomeClient::GetSanitizedUsername( | |
79 const std::string& username, | |
80 const StringDBusMethodCallback& callback) { | |
81 // Even for stub implementation we have to return different values so that | |
82 // multi-profiles would work. | |
83 std::string sanitized_username = GetStubSanitizedUsername(username); | |
84 base::MessageLoop::current()->PostTask( | |
85 FROM_HERE, | |
86 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, sanitized_username)); | |
87 } | |
88 | |
89 std::string FakeCryptohomeClient::BlockingGetSanitizedUsername( | |
90 const std::string& username) { | |
91 return GetStubSanitizedUsername(username); | |
86 } | 92 } |
87 | 93 |
88 void FakeCryptohomeClient::AsyncMount(const std::string& username, | 94 void FakeCryptohomeClient::AsyncMount(const std::string& username, |
89 const std::string& key, int flags, | 95 const std::string& key, |
90 const AsyncMethodCallback& callback) { | 96 int flags, |
91 DCHECK(!callback.is_null()); | 97 const AsyncMethodCallback& callback) { |
92 | 98 ReturnAsyncMethodResult(callback, false); |
93 base::MessageLoop::current()->PostTask(FROM_HERE, | 99 } |
94 base::Bind(callback, 1 /* async_id */)); | 100 |
95 if (!handler_.is_null()) | 101 void FakeCryptohomeClient::AsyncAddKey( |
96 base::MessageLoop::current()->PostTask(FROM_HERE, | 102 const std::string& username, |
97 base::Bind(handler_, | 103 const std::string& key, |
98 1, // async_id | 104 const std::string& new_key, |
99 true, // return_status | 105 const AsyncMethodCallback& callback) { |
100 cryptohome::MOUNT_ERROR_NONE)); | 106 ReturnAsyncMethodResult(callback, false); |
101 } | |
102 | |
103 void FakeCryptohomeClient::AsyncAddKey(const std::string& username, | |
104 const std::string& key, | |
105 const std::string& new_key, | |
106 const AsyncMethodCallback& callback) { | |
107 DCHECK(!callback.is_null()); | |
108 | |
109 base::MessageLoop::current()->PostTask(FROM_HERE, | |
110 base::Bind(callback, 1 /* async_id */)); | |
111 if (!handler_.is_null()) | |
112 base::MessageLoop::current()->PostTask(FROM_HERE, | |
113 base::Bind(handler_, | |
114 1, // async_id | |
115 true, // return_status | |
116 cryptohome::MOUNT_ERROR_NONE)); | |
117 } | 107 } |
118 | 108 |
119 void FakeCryptohomeClient::AsyncMountGuest( | 109 void FakeCryptohomeClient::AsyncMountGuest( |
120 const AsyncMethodCallback& callback) { | 110 const AsyncMethodCallback& callback) { |
111 ReturnAsyncMethodResult(callback, false); | |
121 } | 112 } |
122 | 113 |
123 void FakeCryptohomeClient::AsyncMountPublic( | 114 void FakeCryptohomeClient::AsyncMountPublic( |
124 const std::string& public_mount_id, | 115 const std::string& public_mount_id, |
125 int flags, | 116 int flags, |
126 const AsyncMethodCallback& callback) { | 117 const AsyncMethodCallback& callback) { |
118 ReturnAsyncMethodResult(callback, false); | |
119 } | |
120 | |
121 void FakeCryptohomeClient::TpmIsReady( | |
122 const BoolDBusMethodCallback& callback) { | |
123 base::MessageLoop::current()->PostTask( | |
124 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); | |
125 } | |
126 | |
127 void FakeCryptohomeClient::TpmIsEnabled( | |
128 const BoolDBusMethodCallback& callback) { | |
129 base::MessageLoop::current()->PostTask( | |
130 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); | |
131 } | |
132 | |
133 bool FakeCryptohomeClient::CallTpmIsEnabledAndBlock(bool* enabled) { | |
134 *enabled = true; | |
135 return true; | |
136 } | |
137 | |
138 void FakeCryptohomeClient::TpmGetPassword( | |
139 const StringDBusMethodCallback& callback) { | |
140 const char kStubTpmPassword[] = "Stub-TPM-password"; | |
141 base::MessageLoop::current()->PostTask( | |
142 FROM_HERE, | |
143 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, | |
144 std::string(kStubTpmPassword))); | |
145 } | |
146 | |
147 void FakeCryptohomeClient::TpmIsOwned( | |
148 const BoolDBusMethodCallback& callback) { | |
149 base::MessageLoop::current()->PostTask( | |
150 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); | |
151 } | |
152 | |
153 bool FakeCryptohomeClient::CallTpmIsOwnedAndBlock(bool* owned) { | |
154 *owned = true; | |
155 return true; | |
156 } | |
157 | |
158 void FakeCryptohomeClient::TpmIsBeingOwned( | |
159 const BoolDBusMethodCallback& callback) { | |
160 base::MessageLoop::current()->PostTask( | |
161 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); | |
127 } | 162 } |
128 | 163 |
129 bool FakeCryptohomeClient::CallTpmIsBeingOwnedAndBlock(bool* owning) { | 164 bool FakeCryptohomeClient::CallTpmIsBeingOwnedAndBlock(bool* owning) { |
130 return false; | 165 *owning = true; |
131 } | 166 return true; |
132 | 167 } |
133 void FakeCryptohomeClient::Pkcs11IsTpmTokenReady( | 168 |
134 const BoolDBusMethodCallback& callback) { | 169 void FakeCryptohomeClient::TpmCanAttemptOwnership( |
170 const VoidDBusMethodCallback& callback) { | |
171 base::MessageLoop::current()->PostTask( | |
172 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS)); | |
135 } | 173 } |
136 | 174 |
137 void FakeCryptohomeClient::TpmClearStoredPassword( | 175 void FakeCryptohomeClient::TpmClearStoredPassword( |
138 const VoidDBusMethodCallback& callback) { | 176 const VoidDBusMethodCallback& callback) { |
139 } | 177 base::MessageLoop::current()->PostTask( |
140 | 178 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS)); |
141 void FakeCryptohomeClient::TpmCanAttemptOwnership( | 179 } |
142 const VoidDBusMethodCallback& callback) { | 180 |
143 } | 181 bool FakeCryptohomeClient::CallTpmClearStoredPasswordAndBlock() { |
144 | 182 return true; |
145 bool FakeCryptohomeClient::GetSystemSalt(std::vector<uint8>* salt) { | 183 } |
146 salt->assign(kStubSystemSalt, | 184 |
147 kStubSystemSalt + arraysize(kStubSystemSalt) - 1); | 185 void FakeCryptohomeClient::Pkcs11IsTpmTokenReady( |
148 return true; | 186 const BoolDBusMethodCallback& callback) { |
149 } | 187 base::MessageLoop::current()->PostTask( |
150 | 188 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); |
151 void FakeCryptohomeClient::TpmGetPassword( | 189 } |
152 const StringDBusMethodCallback& callback) { | 190 |
153 } | 191 void FakeCryptohomeClient::Pkcs11GetTpmTokenInfo( |
154 | 192 const Pkcs11GetTpmTokenInfoCallback& callback) { |
155 bool FakeCryptohomeClient::InstallAttributesFinalize(bool* successful) { | 193 const char kStubUserPin[] = "012345"; |
156 return false; | 194 base::MessageLoop::current()->PostTask( |
157 } | 195 FROM_HERE, |
158 | 196 base::Bind(callback, |
159 void FakeCryptohomeClient::SetAsyncCallStatusHandlers( | 197 DBUS_METHOD_CALL_SUCCESS, |
160 const AsyncCallStatusHandler& handler, | 198 std::string(crypto::kTestTPMTokenName), |
hashimoto
2013/09/26 08:41:29
Linker is complaining about this.
[917/4779] SOLI
satorux1
2013/09/26 09:58:36
Fixed in Patch Set 2.
| |
161 const AsyncCallStatusWithDataHandler& data_handler) { | 199 std::string(kStubUserPin))); |
162 handler_ = handler; | 200 } |
163 data_handler_ = data_handler; | 201 |
164 } | 202 bool FakeCryptohomeClient::InstallAttributesGet(const std::string& name, |
165 | 203 std::vector<uint8>* value, |
166 bool FakeCryptohomeClient::CallTpmIsEnabledAndBlock(bool* enabled) { | 204 bool* successful) { |
167 return false; | 205 if (install_attrs_.find(name) != install_attrs_.end()) { |
206 *value = install_attrs_[name]; | |
207 *successful = true; | |
208 } else { | |
209 value->clear(); | |
210 *successful = false; | |
211 } | |
212 return true; | |
168 } | 213 } |
169 | 214 |
170 bool FakeCryptohomeClient::InstallAttributesSet( | 215 bool FakeCryptohomeClient::InstallAttributesSet( |
171 const std::string& name, | 216 const std::string& name, |
172 const std::vector<uint8>& value, | 217 const std::vector<uint8>& value, |
173 bool* successful) { | 218 bool* successful) { |
174 return false; | 219 install_attrs_[name] = value; |
220 *successful = true; | |
221 return true; | |
222 } | |
223 | |
224 bool FakeCryptohomeClient::InstallAttributesFinalize(bool* successful) { | |
225 locked_ = true; | |
226 *successful = true; | |
227 return true; | |
228 } | |
229 | |
230 void FakeCryptohomeClient::InstallAttributesIsReady( | |
231 const BoolDBusMethodCallback& callback) { | |
232 base::MessageLoop::current()->PostTask( | |
233 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); | |
234 } | |
235 | |
236 bool FakeCryptohomeClient::InstallAttributesIsInvalid(bool* is_invalid) { | |
237 *is_invalid = false; | |
238 return true; | |
175 } | 239 } |
176 | 240 |
177 bool FakeCryptohomeClient::InstallAttributesIsFirstInstall( | 241 bool FakeCryptohomeClient::InstallAttributesIsFirstInstall( |
178 bool* is_first_install) { | 242 bool* is_first_install) { |
179 return false; | 243 *is_first_install = !locked_; |
244 return true; | |
245 } | |
246 | |
247 void FakeCryptohomeClient::TpmAttestationIsPrepared( | |
248 const BoolDBusMethodCallback& callback) { | |
249 base::MessageLoop::current()->PostTask( | |
250 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); | |
251 } | |
252 | |
253 void FakeCryptohomeClient::TpmAttestationIsEnrolled( | |
254 const BoolDBusMethodCallback& callback) { | |
255 base::MessageLoop::current()->PostTask( | |
256 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); | |
257 } | |
258 | |
259 void FakeCryptohomeClient::AsyncTpmAttestationCreateEnrollRequest( | |
260 const AsyncMethodCallback& callback) { | |
261 ReturnAsyncMethodResult(callback, true); | |
262 } | |
263 | |
264 void FakeCryptohomeClient::AsyncTpmAttestationEnroll( | |
265 const std::string& pca_response, | |
266 const AsyncMethodCallback& callback) { | |
267 ReturnAsyncMethodResult(callback, false); | |
268 } | |
269 | |
270 void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest( | |
271 attestation::AttestationCertificateProfile certificate_profile, | |
272 const std::string& user_email, | |
273 const std::string& request_origin, | |
274 const AsyncMethodCallback& callback) { | |
275 ReturnAsyncMethodResult(callback, true); | |
276 } | |
277 | |
278 void FakeCryptohomeClient::AsyncTpmAttestationFinishCertRequest( | |
279 const std::string& pca_response, | |
280 attestation::AttestationKeyType key_type, | |
281 const std::string& key_name, | |
282 const AsyncMethodCallback& callback) { | |
283 ReturnAsyncMethodResult(callback, true); | |
284 } | |
285 | |
286 void FakeCryptohomeClient::TpmAttestationDoesKeyExist( | |
287 attestation::AttestationKeyType key_type, | |
288 const std::string& key_name, | |
289 const BoolDBusMethodCallback& callback) { | |
290 base::MessageLoop::current()->PostTask( | |
291 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); | |
180 } | 292 } |
181 | 293 |
182 void FakeCryptohomeClient::TpmAttestationGetCertificate( | 294 void FakeCryptohomeClient::TpmAttestationGetCertificate( |
183 attestation::AttestationKeyType key_type, | 295 attestation::AttestationKeyType key_type, |
184 const std::string& key_name, | 296 const std::string& key_name, |
185 const DataMethodCallback& callback) { | 297 const DataMethodCallback& callback) { |
186 } | 298 base::MessageLoop::current()->PostTask( |
187 | 299 FROM_HERE, |
188 void FakeCryptohomeClient::InstallAttributesIsReady( | 300 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); |
189 const BoolDBusMethodCallback& callback) { | |
190 base::MessageLoop::current()->PostTask(FROM_HERE, | |
191 base::Bind(callback, | |
192 DBUS_METHOD_CALL_SUCCESS, true)); | |
193 } | 301 } |
194 | 302 |
195 void FakeCryptohomeClient::TpmAttestationGetPublicKey( | 303 void FakeCryptohomeClient::TpmAttestationGetPublicKey( |
196 attestation::AttestationKeyType key_type, | 304 attestation::AttestationKeyType key_type, |
197 const std::string& key_name, | 305 const std::string& key_name, |
198 const DataMethodCallback& callback) { | 306 const DataMethodCallback& callback) { |
199 } | 307 base::MessageLoop::current()->PostTask( |
200 | 308 FROM_HERE, |
201 void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge( | 309 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); |
202 attestation::AttestationKeyType key_type, | 310 } |
203 const std::string& key_name, | 311 |
204 const std::string& challenge, | 312 void FakeCryptohomeClient::TpmAttestationRegisterKey( |
205 const AsyncMethodCallback& callback) { | 313 attestation::AttestationKeyType key_type, |
206 } | 314 const std::string& key_name, |
207 | 315 const AsyncMethodCallback& callback) { |
208 void FakeCryptohomeClient::Pkcs11GetTpmTokenInfo( | 316 ReturnAsyncMethodResult(callback, true); |
209 const Pkcs11GetTpmTokenInfoCallback& callback) { | |
210 } | |
211 | |
212 void FakeCryptohomeClient::TpmIsOwned(const BoolDBusMethodCallback& callback) { | |
213 } | |
214 | |
215 void FakeCryptohomeClient::TpmAttestationIsPrepared( | |
216 const BoolDBusMethodCallback& callback) { | |
217 } | |
218 | |
219 void FakeCryptohomeClient::TpmIsReady(const BoolDBusMethodCallback& callback) { | |
220 } | |
221 | |
222 void FakeCryptohomeClient::AsyncTpmAttestationCreateEnrollRequest( | |
223 const AsyncMethodCallback& callback) { | |
224 } | |
225 | |
226 void FakeCryptohomeClient::ResetAsyncCallStatusHandlers() { | |
227 handler_.Reset(); | |
228 data_handler_.Reset(); | |
229 } | |
230 | |
231 void FakeCryptohomeClient::TpmAttestationDoesKeyExist( | |
232 attestation::AttestationKeyType key_type, | |
233 const std::string& key_name, | |
234 const BoolDBusMethodCallback& callback) { | |
235 } | |
236 | |
237 bool FakeCryptohomeClient::CallTpmIsOwnedAndBlock(bool* owned) { | |
238 return false; | |
239 } | |
240 | |
241 void FakeCryptohomeClient::AsyncRemove(const std::string& username, | |
242 const AsyncMethodCallback& callback) { | |
243 } | |
244 | |
245 void FakeCryptohomeClient::TpmAttestationSetKeyPayload( | |
246 attestation::AttestationKeyType key_type, | |
247 const std::string& key_name, | |
248 const std::string& payload, | |
249 const BoolDBusMethodCallback& callback) { | |
250 } | |
251 | |
252 void FakeCryptohomeClient::GetSanitizedUsername( | |
253 const std::string& username, | |
254 const StringDBusMethodCallback& callback) { | |
255 DCHECK(!callback.is_null()); | |
256 | |
257 base::MessageLoop::current()->PostTask( | |
258 FROM_HERE, | |
259 base::Bind(callback, | |
260 chromeos::DBUS_METHOD_CALL_SUCCESS, | |
261 username)); | |
262 if (!data_handler_.is_null()) | |
263 base::MessageLoop::current()->PostTask( | |
264 FROM_HERE, | |
265 base::Bind(data_handler_, | |
266 1, // async_id | |
267 true, // return_status | |
268 username)); | |
269 } | |
270 | |
271 std::string FakeCryptohomeClient::BlockingGetSanitizedUsername( | |
272 const std::string& username) { | |
273 return username; | |
274 } | 317 } |
275 | 318 |
276 void FakeCryptohomeClient::TpmAttestationSignEnterpriseChallenge( | 319 void FakeCryptohomeClient::TpmAttestationSignEnterpriseChallenge( |
277 attestation::AttestationKeyType key_type, | 320 attestation::AttestationKeyType key_type, |
278 const std::string& key_name, | 321 const std::string& key_name, |
279 const std::string& domain, | 322 const std::string& domain, |
280 const std::string& device_id, | 323 const std::string& device_id, |
281 attestation::AttestationChallengeOptions options, | 324 attestation::AttestationChallengeOptions options, |
282 const std::string& challenge, | 325 const std::string& challenge, |
283 const AsyncMethodCallback& callback) { | 326 const AsyncMethodCallback& callback) { |
327 ReturnAsyncMethodResult(callback, true); | |
284 } | 328 } |
285 | 329 |
286 void FakeCryptohomeClient::TpmAttestationIsEnrolled( | 330 void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge( |
287 const BoolDBusMethodCallback& callback) { | 331 attestation::AttestationKeyType key_type, |
332 const std::string& key_name, | |
333 const std::string& challenge, | |
334 const AsyncMethodCallback& callback) { | |
335 ReturnAsyncMethodResult(callback, true); | |
288 } | 336 } |
289 | 337 |
290 void FakeCryptohomeClient::TpmAttestationRegisterKey( | 338 void FakeCryptohomeClient::TpmAttestationGetKeyPayload( |
291 attestation::AttestationKeyType key_type, | 339 attestation::AttestationKeyType key_type, |
292 const std::string& key_name, | 340 const std::string& key_name, |
293 const AsyncMethodCallback& callback) { | 341 const DataMethodCallback& callback) { |
342 base::MessageLoop::current()->PostTask( | |
343 FROM_HERE, | |
344 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); | |
294 } | 345 } |
295 | 346 |
296 bool FakeCryptohomeClient::CallTpmClearStoredPasswordAndBlock() { | 347 void FakeCryptohomeClient::TpmAttestationSetKeyPayload( |
297 return false; | 348 attestation::AttestationKeyType key_type, |
349 const std::string& key_name, | |
350 const std::string& payload, | |
351 const BoolDBusMethodCallback& callback) { | |
352 base::MessageLoop::current()->PostTask( | |
353 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); | |
298 } | 354 } |
299 | 355 |
300 void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest( | 356 void FakeCryptohomeClient::ReturnAsyncMethodResult( |
301 attestation::AttestationCertificateProfile certificate_profile, | 357 const AsyncMethodCallback& callback, |
302 const std::string& user_email, | 358 bool returns_data) { |
303 const std::string& request_origin, | 359 base::MessageLoop::current()->PostTask( |
304 const AsyncMethodCallback& callback) { | 360 FROM_HERE, |
361 base::Bind(&FakeCryptohomeClient::ReturnAsyncMethodResultInternal, | |
362 weak_ptr_factory_.GetWeakPtr(), | |
363 callback, | |
364 returns_data)); | |
305 } | 365 } |
306 | 366 |
307 } // namespace chromeos | 367 void FakeCryptohomeClient::ReturnAsyncMethodResultInternal( |
368 const AsyncMethodCallback& callback, | |
369 bool returns_data) { | |
370 callback.Run(async_call_id_); | |
371 if (!returns_data && !async_call_status_handler_.is_null()) { | |
372 base::MessageLoop::current()->PostTask( | |
373 FROM_HERE, | |
374 base::Bind(async_call_status_handler_, | |
375 async_call_id_, | |
376 true, | |
377 cryptohome::MOUNT_ERROR_NONE)); | |
378 } else if (returns_data && !async_call_status_data_handler_.is_null()) { | |
379 base::MessageLoop::current()->PostTask( | |
380 FROM_HERE, | |
381 base::Bind(async_call_status_data_handler_, | |
382 async_call_id_, | |
383 true, | |
384 std::string())); | |
385 } | |
386 ++async_call_id_; | |
387 } | |
388 | |
389 } // namespace chromeos | |
OLD | NEW |