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
3 // found in the LICENSE file.
5 #ifndef CHROMEOS_DBUS_FAKE_CRYPTOHOME_CLIENT_H_
6 #define CHROMEOS_DBUS_FAKE_CRYPTOHOME_CLIENT_H_
10 #include "base/basictypes.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chromeos/dbus/cryptohome_client.h"
16 class CHROMEOS_EXPORT FakeCryptohomeClient
: public CryptohomeClient
{
18 FakeCryptohomeClient();
19 ~FakeCryptohomeClient() override
;
21 void Init(dbus::Bus
* bus
) override
;
22 void SetAsyncCallStatusHandlers(
23 const AsyncCallStatusHandler
& handler
,
24 const AsyncCallStatusWithDataHandler
& data_handler
) override
;
25 void ResetAsyncCallStatusHandlers() override
;
26 void WaitForServiceToBeAvailable(
27 const WaitForServiceToBeAvailableCallback
& callback
) override
;
28 void IsMounted(const BoolDBusMethodCallback
& callback
) override
;
29 bool Unmount(bool* success
) override
;
30 void AsyncCheckKey(const std::string
& username
,
31 const std::string
& key
,
32 const AsyncMethodCallback
& callback
) override
;
33 void AsyncMigrateKey(const std::string
& username
,
34 const std::string
& from_key
,
35 const std::string
& to_key
,
36 const AsyncMethodCallback
& callback
) override
;
37 void AsyncRemove(const std::string
& username
,
38 const AsyncMethodCallback
& callback
) override
;
39 void GetSystemSalt(const GetSystemSaltCallback
& callback
) override
;
40 void GetSanitizedUsername(const std::string
& username
,
41 const StringDBusMethodCallback
& callback
) override
;
42 std::string
BlockingGetSanitizedUsername(
43 const std::string
& username
) override
;
44 void AsyncMount(const std::string
& username
,
45 const std::string
& key
,
47 const AsyncMethodCallback
& callback
) override
;
48 void AsyncAddKey(const std::string
& username
,
49 const std::string
& key
,
50 const std::string
& new_key
,
51 const AsyncMethodCallback
& callback
) override
;
52 void AsyncMountGuest(const AsyncMethodCallback
& callback
) override
;
53 void AsyncMountPublic(const std::string
& public_mount_id
,
55 const AsyncMethodCallback
& callback
) override
;
56 void TpmIsReady(const BoolDBusMethodCallback
& callback
) override
;
57 void TpmIsEnabled(const BoolDBusMethodCallback
& callback
) override
;
58 bool CallTpmIsEnabledAndBlock(bool* enabled
) override
;
59 void TpmGetPassword(const StringDBusMethodCallback
& callback
) override
;
60 void TpmIsOwned(const BoolDBusMethodCallback
& callback
) override
;
61 bool CallTpmIsOwnedAndBlock(bool* owned
) override
;
62 void TpmIsBeingOwned(const BoolDBusMethodCallback
& callback
) override
;
63 bool CallTpmIsBeingOwnedAndBlock(bool* owning
) override
;
64 void TpmCanAttemptOwnership(const VoidDBusMethodCallback
& callback
) override
;
65 void TpmClearStoredPassword(const VoidDBusMethodCallback
& callback
) override
;
66 bool CallTpmClearStoredPasswordAndBlock() override
;
67 void Pkcs11IsTpmTokenReady(const BoolDBusMethodCallback
& callback
) override
;
68 void Pkcs11GetTpmTokenInfo(
69 const Pkcs11GetTpmTokenInfoCallback
& callback
) override
;
70 void Pkcs11GetTpmTokenInfoForUser(
71 const std::string
& username
,
72 const Pkcs11GetTpmTokenInfoCallback
& callback
) override
;
73 bool InstallAttributesGet(const std::string
& name
,
74 std::vector
<uint8
>* value
,
75 bool* successful
) override
;
76 bool InstallAttributesSet(const std::string
& name
,
77 const std::vector
<uint8
>& value
,
78 bool* successful
) override
;
79 bool InstallAttributesFinalize(bool* successful
) override
;
80 void InstallAttributesIsReady(
81 const BoolDBusMethodCallback
& callback
) override
;
82 bool InstallAttributesIsInvalid(bool* is_invalid
) override
;
83 bool InstallAttributesIsFirstInstall(bool* is_first_install
) override
;
84 void TpmAttestationIsPrepared(
85 const BoolDBusMethodCallback
& callback
) override
;
86 void TpmAttestationIsEnrolled(
87 const BoolDBusMethodCallback
& callback
) override
;
88 void AsyncTpmAttestationCreateEnrollRequest(
89 chromeos::attestation::PrivacyCAType pca_type
,
90 const AsyncMethodCallback
& callback
) override
;
91 void AsyncTpmAttestationEnroll(chromeos::attestation::PrivacyCAType pca_type
,
92 const std::string
& pca_response
,
93 const AsyncMethodCallback
& callback
) override
;
94 void AsyncTpmAttestationCreateCertRequest(
95 chromeos::attestation::PrivacyCAType pca_type
,
96 attestation::AttestationCertificateProfile certificate_profile
,
97 const std::string
& user_id
,
98 const std::string
& request_origin
,
99 const AsyncMethodCallback
& callback
) override
;
100 void AsyncTpmAttestationFinishCertRequest(
101 const std::string
& pca_response
,
102 attestation::AttestationKeyType key_type
,
103 const std::string
& user_id
,
104 const std::string
& key_name
,
105 const AsyncMethodCallback
& callback
) override
;
106 void TpmAttestationDoesKeyExist(
107 attestation::AttestationKeyType key_type
,
108 const std::string
& user_id
,
109 const std::string
& key_name
,
110 const BoolDBusMethodCallback
& callback
) override
;
111 void TpmAttestationGetCertificate(
112 attestation::AttestationKeyType key_type
,
113 const std::string
& user_id
,
114 const std::string
& key_name
,
115 const DataMethodCallback
& callback
) override
;
116 void TpmAttestationGetPublicKey(attestation::AttestationKeyType key_type
,
117 const std::string
& user_id
,
118 const std::string
& key_name
,
119 const DataMethodCallback
& callback
) override
;
120 void TpmAttestationRegisterKey(attestation::AttestationKeyType key_type
,
121 const std::string
& user_id
,
122 const std::string
& key_name
,
123 const AsyncMethodCallback
& callback
) override
;
124 void TpmAttestationSignEnterpriseChallenge(
125 attestation::AttestationKeyType key_type
,
126 const std::string
& user_id
,
127 const std::string
& key_name
,
128 const std::string
& domain
,
129 const std::string
& device_id
,
130 attestation::AttestationChallengeOptions options
,
131 const std::string
& challenge
,
132 const AsyncMethodCallback
& callback
) override
;
133 void TpmAttestationSignSimpleChallenge(
134 attestation::AttestationKeyType key_type
,
135 const std::string
& user_id
,
136 const std::string
& key_name
,
137 const std::string
& challenge
,
138 const AsyncMethodCallback
& callback
) override
;
139 void TpmAttestationGetKeyPayload(attestation::AttestationKeyType key_type
,
140 const std::string
& user_id
,
141 const std::string
& key_name
,
142 const DataMethodCallback
& callback
) override
;
143 void TpmAttestationSetKeyPayload(
144 attestation::AttestationKeyType key_type
,
145 const std::string
& user_id
,
146 const std::string
& key_name
,
147 const std::string
& payload
,
148 const BoolDBusMethodCallback
& callback
) override
;
149 void TpmAttestationDeleteKeys(
150 attestation::AttestationKeyType key_type
,
151 const std::string
& user_id
,
152 const std::string
& key_prefix
,
153 const BoolDBusMethodCallback
& callback
) override
;
154 void GetKeyDataEx(const cryptohome::AccountIdentifier
& id
,
155 const cryptohome::AuthorizationRequest
& auth
,
156 const cryptohome::GetKeyDataRequest
& request
,
157 const ProtobufMethodCallback
& callback
) override
;
158 void CheckKeyEx(const cryptohome::AccountIdentifier
& id
,
159 const cryptohome::AuthorizationRequest
& auth
,
160 const cryptohome::CheckKeyRequest
& request
,
161 const ProtobufMethodCallback
& callback
) override
;
162 void MountEx(const cryptohome::AccountIdentifier
& id
,
163 const cryptohome::AuthorizationRequest
& auth
,
164 const cryptohome::MountRequest
& request
,
165 const ProtobufMethodCallback
& callback
) override
;
166 void AddKeyEx(const cryptohome::AccountIdentifier
& id
,
167 const cryptohome::AuthorizationRequest
& auth
,
168 const cryptohome::AddKeyRequest
& request
,
169 const ProtobufMethodCallback
& callback
) override
;
170 void UpdateKeyEx(const cryptohome::AccountIdentifier
& id
,
171 const cryptohome::AuthorizationRequest
& auth
,
172 const cryptohome::UpdateKeyRequest
& request
,
173 const ProtobufMethodCallback
& callback
) override
;
174 void RemoveKeyEx(const cryptohome::AccountIdentifier
& id
,
175 const cryptohome::AuthorizationRequest
& auth
,
176 const cryptohome::RemoveKeyRequest
& request
,
177 const ProtobufMethodCallback
& callback
) override
;
178 void GetBootAttribute(const cryptohome::GetBootAttributeRequest
& request
,
179 const ProtobufMethodCallback
& callback
) override
;
180 void SetBootAttribute(const cryptohome::SetBootAttributeRequest
& request
,
181 const ProtobufMethodCallback
& callback
) override
;
182 void FlushAndSignBootAttributes(
183 const cryptohome::FlushAndSignBootAttributesRequest
& request
,
184 const ProtobufMethodCallback
& callback
) override
;
186 // Changes the behavior of WaitForServiceToBeAvailable(). This method runs
187 // pending callbacks if is_available is true.
188 void SetServiceIsAvailable(bool is_available
);
190 // Sets the unmount result of Unmount() call.
191 void set_unmount_result(bool result
) {
192 unmount_result_
= result
;
195 // Sets the system salt which will be returned from GetSystemSalt(). By
196 // default, GetSystemSalt() returns the value generated by
197 // GetStubSystemSalt().
198 void set_system_salt(const std::vector
<uint8
>& system_salt
) {
199 system_salt_
= system_salt
;
202 // Returns the stub system salt as raw bytes. (not as a string encoded in the
203 // format used by SystemSaltGetter::ConvertRawSaltToHexString()).
204 static std::vector
<uint8
> GetStubSystemSalt();
207 void ReturnProtobufMethodCallback(
208 const cryptohome::BaseReply
& reply
,
209 const ProtobufMethodCallback
& callback
);
211 // Posts tasks which return fake results to the UI thread.
212 void ReturnAsyncMethodResult(const AsyncMethodCallback
& callback
,
215 // This method is used to implement ReturnAsyncMethodResult.
216 void ReturnAsyncMethodResultInternal(const AsyncMethodCallback
& callback
,
219 bool service_is_available_
;
221 AsyncCallStatusHandler async_call_status_handler_
;
222 AsyncCallStatusWithDataHandler async_call_status_data_handler_
;
223 bool unmount_result_
;
224 std::vector
<uint8
> system_salt_
;
226 std::vector
<WaitForServiceToBeAvailableCallback
>
227 pending_wait_for_service_to_be_available_callbacks_
;
229 // A stub store for InstallAttributes, mapping an attribute name to the
230 // associated data blob. Used to implement InstallAttributesSet and -Get.
231 std::map
<std::string
, std::vector
<uint8
> > install_attrs_
;
233 base::WeakPtrFactory
<FakeCryptohomeClient
> weak_ptr_factory_
;
235 DISALLOW_COPY_AND_ASSIGN(FakeCryptohomeClient
);
238 } // namespace chromeos
240 #endif // CHROMEOS_DBUS_FAKE_CRYPTOHOME_CLIENT_H_