fake_cryptohome_client.cc revision 868fa2fe829687343ffae624259930155e16dbd8
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.
4
5#include "chromeos/dbus/fake_cryptohome_client.h"
6
7#include "base/bind.h"
8#include "base/message_loop.h"
9#include "third_party/cros_system_api/dbus/service_constants.h"
10
11namespace chromeos {
12
13namespace {
14
15// A fake system salt. GetSystemSalt copies it to the given buffer.
16const char kStubSystemSalt[] = "stub_system_salt";
17
18}  // namespace
19
20FakeCryptohomeClient::FakeCryptohomeClient() : unmount_result_(false) {
21}
22
23FakeCryptohomeClient::~FakeCryptohomeClient() {
24}
25
26void FakeCryptohomeClient::TpmIsBeingOwned(
27    const BoolDBusMethodCallback& callback) {
28}
29
30bool FakeCryptohomeClient::Unmount(bool* success) {
31  *success = unmount_result_;
32  return true;
33}
34
35void FakeCryptohomeClient::AsyncCheckKey(const std::string& username,
36                                         const std::string& key,
37                                         const AsyncMethodCallback& callback) {
38}
39
40bool FakeCryptohomeClient::InstallAttributesIsInvalid(bool* is_invalid) {
41  return false;
42}
43
44void FakeCryptohomeClient::TpmAttestationGetKeyPayload(
45    attestation::AttestationKeyType key_type,
46    const std::string& key_name,
47    const DataMethodCallback& callback) {
48}
49
50void FakeCryptohomeClient::AsyncTpmAttestationFinishCertRequest(
51    const std::string& pca_response,
52    attestation::AttestationKeyType key_type,
53    const std::string& key_name,
54    const AsyncMethodCallback& callback) {
55}
56
57void FakeCryptohomeClient::TpmIsEnabled(
58    const BoolDBusMethodCallback& callback) {
59}
60
61void FakeCryptohomeClient::AsyncTpmAttestationEnroll(
62    const std::string& pca_response,
63    const AsyncMethodCallback& callback) {
64}
65
66void FakeCryptohomeClient::AsyncMigrateKey(
67    const std::string& username,
68    const std::string& from_key,
69    const std::string& to_key,
70    const AsyncMethodCallback& callback) {
71}
72
73void FakeCryptohomeClient::IsMounted(const BoolDBusMethodCallback& callback) {
74  base::MessageLoop::current()->PostTask(FROM_HERE,
75                                   base::Bind(callback,
76                                              DBUS_METHOD_CALL_SUCCESS, true));
77}
78
79bool FakeCryptohomeClient::InstallAttributesGet(const std::string& name,
80                                                std::vector<uint8>* value,
81                                                bool* successful) {
82  return false;
83}
84
85void FakeCryptohomeClient::AsyncMount(const std::string& username,
86                                      const std::string& key, int flags,
87                                      const AsyncMethodCallback& callback) {
88  DCHECK(!callback.is_null());
89
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));
98}
99
100void FakeCryptohomeClient::AsyncMountGuest(
101    const AsyncMethodCallback& callback) {
102}
103
104bool FakeCryptohomeClient::CallTpmIsBeingOwnedAndBlock(bool* owning) {
105  return false;
106}
107
108void FakeCryptohomeClient::Pkcs11IsTpmTokenReady(
109    const BoolDBusMethodCallback& callback) {
110}
111
112void FakeCryptohomeClient::TpmClearStoredPassword(
113    const VoidDBusMethodCallback& callback) {
114}
115
116void FakeCryptohomeClient::TpmCanAttemptOwnership(
117    const VoidDBusMethodCallback& callback) {
118}
119
120bool FakeCryptohomeClient::GetSystemSalt(std::vector<uint8>* salt) {
121  salt->assign(kStubSystemSalt,
122               kStubSystemSalt + arraysize(kStubSystemSalt) - 1);
123  return true;
124}
125
126void FakeCryptohomeClient::TpmGetPassword(
127    const StringDBusMethodCallback& callback) {
128}
129
130bool FakeCryptohomeClient::InstallAttributesFinalize(bool* successful) {
131  return false;
132}
133
134void FakeCryptohomeClient::SetAsyncCallStatusHandlers(
135    const AsyncCallStatusHandler& handler,
136    const AsyncCallStatusWithDataHandler& data_handler) {
137  handler_ = handler;
138  data_handler_ = data_handler;
139}
140
141bool FakeCryptohomeClient::CallTpmIsEnabledAndBlock(bool* enabled) {
142  return false;
143}
144
145bool FakeCryptohomeClient::InstallAttributesSet(
146    const std::string& name,
147    const std::vector<uint8>& value,
148    bool* successful) {
149  return false;
150}
151
152bool FakeCryptohomeClient::InstallAttributesIsFirstInstall(
153    bool* is_first_install) {
154  return false;
155}
156
157void FakeCryptohomeClient::TpmAttestationGetCertificate(
158    attestation::AttestationKeyType key_type,
159    const std::string& key_name,
160    const DataMethodCallback& callback) {
161}
162
163void FakeCryptohomeClient::InstallAttributesIsReady(
164    const BoolDBusMethodCallback& callback) {
165  base::MessageLoop::current()->PostTask(FROM_HERE,
166                                   base::Bind(callback,
167                                              DBUS_METHOD_CALL_SUCCESS, true));
168}
169
170void FakeCryptohomeClient::TpmAttestationGetPublicKey(
171    attestation::AttestationKeyType key_type,
172    const std::string& key_name,
173    const DataMethodCallback& callback) {
174}
175
176void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge(
177    attestation::AttestationKeyType key_type,
178    const std::string& key_name,
179    const std::string& challenge,
180    const AsyncMethodCallback& callback) {
181}
182
183void FakeCryptohomeClient::Pkcs11GetTpmTokenInfo(
184    const Pkcs11GetTpmTokenInfoCallback& callback) {
185}
186
187void FakeCryptohomeClient::TpmIsOwned(const BoolDBusMethodCallback& callback) {
188}
189
190void FakeCryptohomeClient::TpmAttestationIsPrepared(
191    const BoolDBusMethodCallback& callback) {
192}
193
194void FakeCryptohomeClient::TpmIsReady(const BoolDBusMethodCallback& callback) {
195}
196
197void FakeCryptohomeClient::AsyncTpmAttestationCreateEnrollRequest(
198    const AsyncMethodCallback& callback) {
199}
200
201void FakeCryptohomeClient::ResetAsyncCallStatusHandlers() {
202  handler_.Reset();
203  data_handler_.Reset();
204}
205
206void FakeCryptohomeClient::TpmAttestationDoesKeyExist(
207    attestation::AttestationKeyType key_type,
208    const std::string& key_name,
209    const BoolDBusMethodCallback& callback) {
210}
211
212bool FakeCryptohomeClient::CallTpmIsOwnedAndBlock(bool* owned) {
213  return false;
214}
215
216void FakeCryptohomeClient::AsyncRemove(const std::string& username,
217                                       const AsyncMethodCallback& callback) {
218}
219
220void FakeCryptohomeClient::TpmAttestationSetKeyPayload(
221    attestation::AttestationKeyType key_type,
222    const std::string& key_name,
223    const std::string& payload,
224    const BoolDBusMethodCallback& callback) {
225}
226
227void FakeCryptohomeClient::GetSanitizedUsername(
228    const std::string& username,
229    const StringDBusMethodCallback& callback) {
230  DCHECK(!callback.is_null());
231
232  base::MessageLoop::current()->PostTask(
233      FROM_HERE,
234      base::Bind(callback,
235                 chromeos::DBUS_METHOD_CALL_SUCCESS,
236                 username));
237  if (!data_handler_.is_null())
238    base::MessageLoop::current()->PostTask(
239        FROM_HERE,
240        base::Bind(data_handler_,
241                   1,     // async_id
242                   true,  // return_status
243                   username));
244}
245
246void 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) {
254}
255
256void FakeCryptohomeClient::TpmAttestationIsEnrolled(
257    const BoolDBusMethodCallback& callback) {
258}
259
260void FakeCryptohomeClient::TpmAttestationRegisterKey(
261    attestation::AttestationKeyType key_type,
262    const std::string& key_name,
263    const AsyncMethodCallback& callback) {
264}
265
266bool FakeCryptohomeClient::CallTpmClearStoredPasswordAndBlock() {
267  return false;
268}
269
270void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest(
271    int options,
272    const AsyncMethodCallback& callback) {
273}
274
275} // namespace chromeos
276