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_CRYPTOHOME_CLIENT_STUB_H_
6 #define CHROMEOS_DBUS_CRYPTOHOME_CLIENT_STUB_H_
10 #include "base/basictypes.h"
11 #include "base/memory/weak_ptr.h"
12 #include "chromeos/dbus/cryptohome_client.h"
16 class CryptohomeClientStubImpl
: public CryptohomeClient
{
18 CryptohomeClientStubImpl();
19 virtual ~CryptohomeClientStubImpl();
21 virtual void SetAsyncCallStatusHandlers(
22 const AsyncCallStatusHandler
& handler
,
23 const AsyncCallStatusWithDataHandler
& data_handler
) OVERRIDE
;
24 virtual void ResetAsyncCallStatusHandlers() OVERRIDE
;
25 virtual void IsMounted(const BoolDBusMethodCallback
& callback
) OVERRIDE
;
26 virtual bool Unmount(bool* success
) OVERRIDE
;
27 virtual void AsyncCheckKey(const std::string
& username
,
28 const std::string
& key
,
29 const AsyncMethodCallback
& callback
) OVERRIDE
;
30 virtual void AsyncMigrateKey(const std::string
& username
,
31 const std::string
& from_key
,
32 const std::string
& to_key
,
33 const AsyncMethodCallback
& callback
) OVERRIDE
;
34 virtual void AsyncRemove(const std::string
& username
,
35 const AsyncMethodCallback
& callback
) OVERRIDE
;
36 virtual bool GetSystemSalt(std::vector
<uint8
>* salt
) OVERRIDE
;
37 virtual void GetSanitizedUsername(
38 const std::string
& username
,
39 const StringDBusMethodCallback
& callback
) OVERRIDE
;
40 virtual std::string
BlockingGetSanitizedUsername(
41 const std::string
& username
) OVERRIDE
;
42 virtual void AsyncMount(const std::string
& username
,
43 const std::string
& key
,
45 const AsyncMethodCallback
& callback
) OVERRIDE
;
46 virtual void AsyncAddKey(const std::string
& username
,
47 const std::string
& key
,
48 const std::string
& new_key
,
49 const AsyncMethodCallback
& callback
) OVERRIDE
;
50 virtual void AsyncMountGuest(const AsyncMethodCallback
& callback
) OVERRIDE
;
51 virtual void AsyncMountPublic(const std::string
& public_mount_id
,
53 const AsyncMethodCallback
& callback
) OVERRIDE
;
54 virtual void TpmIsReady(const BoolDBusMethodCallback
& callback
) OVERRIDE
;
55 virtual void TpmIsEnabled(const BoolDBusMethodCallback
& callback
) OVERRIDE
;
56 virtual bool CallTpmIsEnabledAndBlock(bool* enabled
) OVERRIDE
;
57 virtual void TpmGetPassword(
58 const StringDBusMethodCallback
& callback
) OVERRIDE
;
59 virtual void TpmIsOwned(const BoolDBusMethodCallback
& callback
) OVERRIDE
;
60 virtual bool CallTpmIsOwnedAndBlock(bool* owned
) OVERRIDE
;
61 virtual void TpmIsBeingOwned(const BoolDBusMethodCallback
& callback
) OVERRIDE
;
62 virtual bool CallTpmIsBeingOwnedAndBlock(bool* owning
) OVERRIDE
;
63 virtual void TpmCanAttemptOwnership(
64 const VoidDBusMethodCallback
& callback
) OVERRIDE
;
65 virtual void TpmClearStoredPassword(
66 const VoidDBusMethodCallback
& callback
) OVERRIDE
;
67 virtual bool CallTpmClearStoredPasswordAndBlock() OVERRIDE
;
68 virtual void Pkcs11IsTpmTokenReady(
69 const BoolDBusMethodCallback
& callback
) OVERRIDE
;
70 virtual void Pkcs11GetTpmTokenInfo(
71 const Pkcs11GetTpmTokenInfoCallback
& callback
) OVERRIDE
;
72 virtual bool InstallAttributesGet(const std::string
& name
,
73 std::vector
<uint8
>* value
,
74 bool* successful
) OVERRIDE
;
75 virtual bool InstallAttributesSet(const std::string
& name
,
76 const std::vector
<uint8
>& value
,
77 bool* successful
) OVERRIDE
;
78 virtual bool InstallAttributesFinalize(bool* successful
) OVERRIDE
;
79 virtual void InstallAttributesIsReady(
80 const BoolDBusMethodCallback
& callback
) OVERRIDE
;
81 virtual bool InstallAttributesIsInvalid(bool* is_invalid
) OVERRIDE
;
82 virtual bool InstallAttributesIsFirstInstall(bool* is_first_install
) OVERRIDE
;
83 virtual void TpmAttestationIsPrepared(
84 const BoolDBusMethodCallback
& callback
) OVERRIDE
;
85 virtual void TpmAttestationIsEnrolled(
86 const BoolDBusMethodCallback
& callback
) OVERRIDE
;
87 virtual void AsyncTpmAttestationCreateEnrollRequest(
88 const AsyncMethodCallback
& callback
) OVERRIDE
;
89 virtual void AsyncTpmAttestationEnroll(
90 const std::string
& pca_response
,
91 const AsyncMethodCallback
& callback
) OVERRIDE
;
92 virtual void AsyncTpmAttestationCreateCertRequest(
93 attestation::AttestationCertificateProfile certificate_profile
,
94 const std::string
& user_email
,
95 const std::string
& request_origin
,
96 const AsyncMethodCallback
& callback
) OVERRIDE
;
97 virtual void AsyncTpmAttestationFinishCertRequest(
98 const std::string
& pca_response
,
99 attestation::AttestationKeyType key_type
,
100 const std::string
& key_name
,
101 const AsyncMethodCallback
& callback
) OVERRIDE
;
102 virtual void TpmAttestationDoesKeyExist(
103 attestation::AttestationKeyType key_type
,
104 const std::string
& key_name
,
105 const BoolDBusMethodCallback
& callback
) OVERRIDE
;
106 virtual void TpmAttestationGetCertificate(
107 attestation::AttestationKeyType key_type
,
108 const std::string
& key_name
,
109 const DataMethodCallback
& callback
) OVERRIDE
;
110 virtual void TpmAttestationGetPublicKey(
111 attestation::AttestationKeyType key_type
,
112 const std::string
& key_name
,
113 const DataMethodCallback
& callback
) OVERRIDE
;
114 virtual void TpmAttestationRegisterKey(
115 attestation::AttestationKeyType key_type
,
116 const std::string
& key_name
,
117 const AsyncMethodCallback
& callback
) OVERRIDE
;
118 virtual void TpmAttestationSignEnterpriseChallenge(
119 attestation::AttestationKeyType key_type
,
120 const std::string
& key_name
,
121 const std::string
& domain
,
122 const std::string
& device_id
,
123 attestation::AttestationChallengeOptions options
,
124 const std::string
& challenge
,
125 const AsyncMethodCallback
& callback
) OVERRIDE
;
126 virtual void TpmAttestationSignSimpleChallenge(
127 attestation::AttestationKeyType key_type
,
128 const std::string
& key_name
,
129 const std::string
& challenge
,
130 const AsyncMethodCallback
& callback
) OVERRIDE
;
131 virtual void TpmAttestationGetKeyPayload(
132 attestation::AttestationKeyType key_type
,
133 const std::string
& key_name
,
134 const DataMethodCallback
& callback
) OVERRIDE
;
135 virtual void TpmAttestationSetKeyPayload(
136 attestation::AttestationKeyType key_type
,
137 const std::string
& key_name
,
138 const std::string
& payload
,
139 const BoolDBusMethodCallback
& callback
) OVERRIDE
;
142 // Posts tasks which return fake results to the UI thread.
143 void ReturnAsyncMethodResult(const AsyncMethodCallback
& callback
,
146 // This method is used to implement ReturnAsyncMethodResult.
147 void ReturnAsyncMethodResultInternal(const AsyncMethodCallback
& callback
,
151 AsyncCallStatusHandler async_call_status_handler_
;
152 AsyncCallStatusWithDataHandler async_call_status_data_handler_
;
153 int tpm_is_ready_counter_
;
155 // A stub store for InstallAttributes, mapping an attribute name to the
156 // associated data blob. Used to implement InstallAttributesSet and -Get.
157 std::map
<std::string
, std::vector
<uint8
> > install_attrs_
;
159 base::WeakPtrFactory
<CryptohomeClientStubImpl
> weak_ptr_factory_
;
161 DISALLOW_COPY_AND_ASSIGN(CryptohomeClientStubImpl
);
164 } // namespace chromeos
166 #endif // CHROMEOS_DBUS_CRYPTOHOME_CLIENT_STUB_H_