Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / chromeos / dbus / fake_cryptohome_client.cc
blobc00f3d457d10963c331b217f95a456c997834dfe
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"
7 #include "base/bind.h"
8 #include "base/message_loop.h"
9 #include "third_party/cros_system_api/dbus/service_constants.h"
11 namespace chromeos {
13 namespace {
15 // A fake system salt. GetSystemSalt copies it to the given buffer.
16 const char kStubSystemSalt[] = "stub_system_salt";
18 } // namespace
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_;
32 return true;
35 void FakeCryptohomeClient::AsyncCheckKey(const std::string& username,
36 const std::string& key,
37 const AsyncMethodCallback& callback) {
40 bool FakeCryptohomeClient::InstallAttributesIsInvalid(bool* is_invalid) {
41 return false;
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,
75 base::Bind(callback,
76 DBUS_METHOD_CALL_SUCCESS, true));
79 bool FakeCryptohomeClient::InstallAttributesGet(const std::string& name,
80 std::vector<uint8>* value,
81 bool* successful) {
82 return false;
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,
94 base::Bind(handler_,
95 1, // async_id
96 true, // return_status
97 cryptohome::MOUNT_ERROR_NONE));
100 void FakeCryptohomeClient::AsyncAddKey(const std::string& username,
101 const std::string& key,
102 const std::string& new_key,
103 const AsyncMethodCallback& callback) {
104 DCHECK(!callback.is_null());
106 base::MessageLoop::current()->PostTask(FROM_HERE,
107 base::Bind(callback, 1 /* async_id */));
108 if (!handler_.is_null())
109 base::MessageLoop::current()->PostTask(FROM_HERE,
110 base::Bind(handler_,
111 1, // async_id
112 true, // return_status
113 cryptohome::MOUNT_ERROR_NONE));
116 void FakeCryptohomeClient::AsyncMountGuest(
117 const AsyncMethodCallback& callback) {
120 bool FakeCryptohomeClient::CallTpmIsBeingOwnedAndBlock(bool* owning) {
121 return false;
124 void FakeCryptohomeClient::Pkcs11IsTpmTokenReady(
125 const BoolDBusMethodCallback& callback) {
128 void FakeCryptohomeClient::TpmClearStoredPassword(
129 const VoidDBusMethodCallback& callback) {
132 void FakeCryptohomeClient::TpmCanAttemptOwnership(
133 const VoidDBusMethodCallback& callback) {
136 bool FakeCryptohomeClient::GetSystemSalt(std::vector<uint8>* salt) {
137 salt->assign(kStubSystemSalt,
138 kStubSystemSalt + arraysize(kStubSystemSalt) - 1);
139 return true;
142 void FakeCryptohomeClient::TpmGetPassword(
143 const StringDBusMethodCallback& callback) {
146 bool FakeCryptohomeClient::InstallAttributesFinalize(bool* successful) {
147 return false;
150 void FakeCryptohomeClient::SetAsyncCallStatusHandlers(
151 const AsyncCallStatusHandler& handler,
152 const AsyncCallStatusWithDataHandler& data_handler) {
153 handler_ = handler;
154 data_handler_ = data_handler;
157 bool FakeCryptohomeClient::CallTpmIsEnabledAndBlock(bool* enabled) {
158 return false;
161 bool FakeCryptohomeClient::InstallAttributesSet(
162 const std::string& name,
163 const std::vector<uint8>& value,
164 bool* successful) {
165 return false;
168 bool FakeCryptohomeClient::InstallAttributesIsFirstInstall(
169 bool* is_first_install) {
170 return false;
173 void FakeCryptohomeClient::TpmAttestationGetCertificate(
174 attestation::AttestationKeyType key_type,
175 const std::string& key_name,
176 const DataMethodCallback& callback) {
179 void FakeCryptohomeClient::InstallAttributesIsReady(
180 const BoolDBusMethodCallback& callback) {
181 base::MessageLoop::current()->PostTask(FROM_HERE,
182 base::Bind(callback,
183 DBUS_METHOD_CALL_SUCCESS, true));
186 void FakeCryptohomeClient::TpmAttestationGetPublicKey(
187 attestation::AttestationKeyType key_type,
188 const std::string& key_name,
189 const DataMethodCallback& callback) {
192 void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge(
193 attestation::AttestationKeyType key_type,
194 const std::string& key_name,
195 const std::string& challenge,
196 const AsyncMethodCallback& callback) {
199 void FakeCryptohomeClient::Pkcs11GetTpmTokenInfo(
200 const Pkcs11GetTpmTokenInfoCallback& callback) {
203 void FakeCryptohomeClient::TpmIsOwned(const BoolDBusMethodCallback& callback) {
206 void FakeCryptohomeClient::TpmAttestationIsPrepared(
207 const BoolDBusMethodCallback& callback) {
210 void FakeCryptohomeClient::TpmIsReady(const BoolDBusMethodCallback& callback) {
213 void FakeCryptohomeClient::AsyncTpmAttestationCreateEnrollRequest(
214 const AsyncMethodCallback& callback) {
217 void FakeCryptohomeClient::ResetAsyncCallStatusHandlers() {
218 handler_.Reset();
219 data_handler_.Reset();
222 void FakeCryptohomeClient::TpmAttestationDoesKeyExist(
223 attestation::AttestationKeyType key_type,
224 const std::string& key_name,
225 const BoolDBusMethodCallback& callback) {
228 bool FakeCryptohomeClient::CallTpmIsOwnedAndBlock(bool* owned) {
229 return false;
232 void FakeCryptohomeClient::AsyncRemove(const std::string& username,
233 const AsyncMethodCallback& callback) {
236 void FakeCryptohomeClient::TpmAttestationSetKeyPayload(
237 attestation::AttestationKeyType key_type,
238 const std::string& key_name,
239 const std::string& payload,
240 const BoolDBusMethodCallback& callback) {
243 void FakeCryptohomeClient::GetSanitizedUsername(
244 const std::string& username,
245 const StringDBusMethodCallback& callback) {
246 DCHECK(!callback.is_null());
248 base::MessageLoop::current()->PostTask(
249 FROM_HERE,
250 base::Bind(callback,
251 chromeos::DBUS_METHOD_CALL_SUCCESS,
252 username));
253 if (!data_handler_.is_null())
254 base::MessageLoop::current()->PostTask(
255 FROM_HERE,
256 base::Bind(data_handler_,
257 1, // async_id
258 true, // return_status
259 username));
262 void FakeCryptohomeClient::TpmAttestationSignEnterpriseChallenge(
263 attestation::AttestationKeyType key_type,
264 const std::string& key_name,
265 const std::string& domain,
266 const std::string& device_id,
267 attestation::AttestationChallengeOptions options,
268 const std::string& challenge,
269 const AsyncMethodCallback& callback) {
272 void FakeCryptohomeClient::TpmAttestationIsEnrolled(
273 const BoolDBusMethodCallback& callback) {
276 void FakeCryptohomeClient::TpmAttestationRegisterKey(
277 attestation::AttestationKeyType key_type,
278 const std::string& key_name,
279 const AsyncMethodCallback& callback) {
282 bool FakeCryptohomeClient::CallTpmClearStoredPasswordAndBlock() {
283 return false;
286 void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest(
287 int options,
288 const AsyncMethodCallback& callback) {
291 } // namespace chromeos