1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromeos/dbus/fake_cryptohome_client.h"
8 #include "base/message_loop.h"
9 #include "third_party/cros_system_api/dbus/service_constants.h"
15 // A fake system salt. GetSystemSalt copies it to the given buffer.
16 const char kStubSystemSalt
[] = "stub_system_salt";
20 FakeCryptohomeClient::FakeCryptohomeClient() : unmount_result_(false) {
23 FakeCryptohomeClient::~FakeCryptohomeClient() {
26 void FakeCryptohomeClient::TpmIsBeingOwned(
27 const BoolDBusMethodCallback
& callback
) {
30 bool FakeCryptohomeClient::Unmount(bool* success
) {
31 *success
= unmount_result_
;
35 void FakeCryptohomeClient::AsyncCheckKey(const std::string
& username
,
36 const std::string
& key
,
37 const AsyncMethodCallback
& callback
) {
40 bool FakeCryptohomeClient::InstallAttributesIsInvalid(bool* is_invalid
) {
44 void FakeCryptohomeClient::TpmAttestationGetKeyPayload(
45 attestation::AttestationKeyType key_type
,
46 const std::string
& key_name
,
47 const DataMethodCallback
& callback
) {
50 void FakeCryptohomeClient::AsyncTpmAttestationFinishCertRequest(
51 const std::string
& pca_response
,
52 attestation::AttestationKeyType key_type
,
53 const std::string
& key_name
,
54 const AsyncMethodCallback
& callback
) {
57 void FakeCryptohomeClient::TpmIsEnabled(
58 const BoolDBusMethodCallback
& callback
) {
61 void FakeCryptohomeClient::AsyncTpmAttestationEnroll(
62 const std::string
& pca_response
,
63 const AsyncMethodCallback
& callback
) {
66 void FakeCryptohomeClient::AsyncMigrateKey(
67 const std::string
& username
,
68 const std::string
& from_key
,
69 const std::string
& to_key
,
70 const AsyncMethodCallback
& callback
) {
73 void FakeCryptohomeClient::IsMounted(const BoolDBusMethodCallback
& callback
) {
74 base::MessageLoop::current()->PostTask(FROM_HERE
,
76 DBUS_METHOD_CALL_SUCCESS
, true));
79 bool FakeCryptohomeClient::InstallAttributesGet(const std::string
& name
,
80 std::vector
<uint8
>* value
,
85 void FakeCryptohomeClient::AsyncMount(const std::string
& username
,
86 const std::string
& key
, int flags
,
87 const AsyncMethodCallback
& callback
) {
88 DCHECK(!callback
.is_null());
90 base::MessageLoop::current()->PostTask(FROM_HERE
,
91 base::Bind(callback
, 1 /* async_id */));
92 if (!handler_
.is_null())
93 base::MessageLoop::current()->PostTask(FROM_HERE
,
96 true, // return_status
97 cryptohome::MOUNT_ERROR_NONE
));
100 void FakeCryptohomeClient::AsyncMountGuest(
101 const AsyncMethodCallback
& callback
) {
104 bool FakeCryptohomeClient::CallTpmIsBeingOwnedAndBlock(bool* owning
) {
108 void FakeCryptohomeClient::Pkcs11IsTpmTokenReady(
109 const BoolDBusMethodCallback
& callback
) {
112 void FakeCryptohomeClient::TpmClearStoredPassword(
113 const VoidDBusMethodCallback
& callback
) {
116 void FakeCryptohomeClient::TpmCanAttemptOwnership(
117 const VoidDBusMethodCallback
& callback
) {
120 bool FakeCryptohomeClient::GetSystemSalt(std::vector
<uint8
>* salt
) {
121 salt
->assign(kStubSystemSalt
,
122 kStubSystemSalt
+ arraysize(kStubSystemSalt
) - 1);
126 void FakeCryptohomeClient::TpmGetPassword(
127 const StringDBusMethodCallback
& callback
) {
130 bool FakeCryptohomeClient::InstallAttributesFinalize(bool* successful
) {
134 void FakeCryptohomeClient::SetAsyncCallStatusHandlers(
135 const AsyncCallStatusHandler
& handler
,
136 const AsyncCallStatusWithDataHandler
& data_handler
) {
138 data_handler_
= data_handler
;
141 bool FakeCryptohomeClient::CallTpmIsEnabledAndBlock(bool* enabled
) {
145 bool FakeCryptohomeClient::InstallAttributesSet(
146 const std::string
& name
,
147 const std::vector
<uint8
>& value
,
152 bool FakeCryptohomeClient::InstallAttributesIsFirstInstall(
153 bool* is_first_install
) {
157 void FakeCryptohomeClient::TpmAttestationGetCertificate(
158 attestation::AttestationKeyType key_type
,
159 const std::string
& key_name
,
160 const DataMethodCallback
& callback
) {
163 void FakeCryptohomeClient::InstallAttributesIsReady(
164 const BoolDBusMethodCallback
& callback
) {
165 base::MessageLoop::current()->PostTask(FROM_HERE
,
167 DBUS_METHOD_CALL_SUCCESS
, true));
170 void FakeCryptohomeClient::TpmAttestationGetPublicKey(
171 attestation::AttestationKeyType key_type
,
172 const std::string
& key_name
,
173 const DataMethodCallback
& callback
) {
176 void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge(
177 attestation::AttestationKeyType key_type
,
178 const std::string
& key_name
,
179 const std::string
& challenge
,
180 const AsyncMethodCallback
& callback
) {
183 void FakeCryptohomeClient::Pkcs11GetTpmTokenInfo(
184 const Pkcs11GetTpmTokenInfoCallback
& callback
) {
187 void FakeCryptohomeClient::TpmIsOwned(const BoolDBusMethodCallback
& callback
) {
190 void FakeCryptohomeClient::TpmAttestationIsPrepared(
191 const BoolDBusMethodCallback
& callback
) {
194 void FakeCryptohomeClient::TpmIsReady(const BoolDBusMethodCallback
& callback
) {
197 void FakeCryptohomeClient::AsyncTpmAttestationCreateEnrollRequest(
198 const AsyncMethodCallback
& callback
) {
201 void FakeCryptohomeClient::ResetAsyncCallStatusHandlers() {
203 data_handler_
.Reset();
206 void FakeCryptohomeClient::TpmAttestationDoesKeyExist(
207 attestation::AttestationKeyType key_type
,
208 const std::string
& key_name
,
209 const BoolDBusMethodCallback
& callback
) {
212 bool FakeCryptohomeClient::CallTpmIsOwnedAndBlock(bool* owned
) {
216 void FakeCryptohomeClient::AsyncRemove(const std::string
& username
,
217 const AsyncMethodCallback
& callback
) {
220 void FakeCryptohomeClient::TpmAttestationSetKeyPayload(
221 attestation::AttestationKeyType key_type
,
222 const std::string
& key_name
,
223 const std::string
& payload
,
224 const BoolDBusMethodCallback
& callback
) {
227 void FakeCryptohomeClient::GetSanitizedUsername(
228 const std::string
& username
,
229 const StringDBusMethodCallback
& callback
) {
230 DCHECK(!callback
.is_null());
232 base::MessageLoop::current()->PostTask(
235 chromeos::DBUS_METHOD_CALL_SUCCESS
,
237 if (!data_handler_
.is_null())
238 base::MessageLoop::current()->PostTask(
240 base::Bind(data_handler_
,
242 true, // return_status
246 void FakeCryptohomeClient::TpmAttestationSignEnterpriseChallenge(
247 attestation::AttestationKeyType key_type
,
248 const std::string
& key_name
,
249 const std::string
& domain
,
250 const std::string
& device_id
,
251 attestation::AttestationChallengeOptions options
,
252 const std::string
& challenge
,
253 const AsyncMethodCallback
& callback
) {
256 void FakeCryptohomeClient::TpmAttestationIsEnrolled(
257 const BoolDBusMethodCallback
& callback
) {
260 void FakeCryptohomeClient::TpmAttestationRegisterKey(
261 attestation::AttestationKeyType key_type
,
262 const std::string
& key_name
,
263 const AsyncMethodCallback
& callback
) {
266 bool FakeCryptohomeClient::CallTpmClearStoredPasswordAndBlock() {
270 void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest(
272 const AsyncMethodCallback
& callback
) {
275 } // namespace chromeos