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 #ifndef CHROMEOS_DBUS_FAKE_CRYPTOHOME_CLIENT_H_ 6 #define CHROMEOS_DBUS_FAKE_CRYPTOHOME_CLIENT_H_ 7 8 #include <string> 9 10 #include "chromeos/dbus/cryptohome_client.h" 11 12 namespace chromeos { 13 14 // A fake implementation of CryptohomeClient. This only calls callbacks given 15 // as parameters. 16 class FakeCryptohomeClient : public CryptohomeClient { 17 public: 18 FakeCryptohomeClient(); 19 virtual ~FakeCryptohomeClient(); 20 21 // CryptohomeClient overrides. 22 virtual void SetAsyncCallStatusHandlers( 23 const AsyncCallStatusHandler& handler, 24 const AsyncCallStatusWithDataHandler& data_handler) OVERRIDE; 25 virtual void ResetAsyncCallStatusHandlers() OVERRIDE; 26 virtual void IsMounted(const BoolDBusMethodCallback& callback) OVERRIDE; 27 virtual bool Unmount(bool* success) OVERRIDE; 28 virtual void AsyncCheckKey(const std::string& username, 29 const std::string& key, 30 const AsyncMethodCallback& callback) OVERRIDE; 31 virtual void AsyncMigrateKey(const std::string& username, 32 const std::string& from_key, 33 const std::string& to_key, 34 const AsyncMethodCallback& callback) OVERRIDE; 35 virtual void AsyncRemove(const std::string& username, 36 const AsyncMethodCallback& callback) OVERRIDE; 37 virtual bool GetSystemSalt(std::vector<uint8>* salt) OVERRIDE; 38 virtual void GetSanitizedUsername( 39 const std::string& username, 40 const StringDBusMethodCallback& callback) OVERRIDE; 41 virtual std::string BlockingGetSanitizedUsername( 42 const std::string& username) OVERRIDE; 43 virtual void AsyncMount(const std::string& username, 44 const std::string& key, 45 int flags, 46 const AsyncMethodCallback& callback) OVERRIDE; 47 virtual void AsyncAddKey(const std::string& username, 48 const std::string& key, 49 const std::string& new_key, 50 const AsyncMethodCallback& callback) OVERRIDE; 51 virtual void AsyncMountGuest(const AsyncMethodCallback& callback) OVERRIDE; 52 virtual void AsyncMountPublic(const std::string& public_mount_id, 53 int flags, 54 const AsyncMethodCallback& callback) OVERRIDE; 55 virtual void TpmIsReady(const BoolDBusMethodCallback& callback) OVERRIDE; 56 virtual void TpmIsEnabled(const BoolDBusMethodCallback& callback) OVERRIDE; 57 virtual bool CallTpmIsEnabledAndBlock(bool* enabled) OVERRIDE; 58 virtual void TpmGetPassword( 59 const StringDBusMethodCallback& callback) OVERRIDE; 60 virtual void TpmIsOwned(const BoolDBusMethodCallback& callback) OVERRIDE; 61 virtual bool CallTpmIsOwnedAndBlock(bool* owned) OVERRIDE; 62 virtual void TpmIsBeingOwned(const BoolDBusMethodCallback& callback) OVERRIDE; 63 virtual bool CallTpmIsBeingOwnedAndBlock(bool* owning) OVERRIDE; 64 virtual void TpmCanAttemptOwnership( 65 const VoidDBusMethodCallback& callback) OVERRIDE; 66 virtual void TpmClearStoredPassword( 67 const VoidDBusMethodCallback& callback) OVERRIDE; 68 virtual bool CallTpmClearStoredPasswordAndBlock() OVERRIDE; 69 virtual void Pkcs11IsTpmTokenReady( 70 const BoolDBusMethodCallback& callback) OVERRIDE; 71 virtual void Pkcs11GetTpmTokenInfo( 72 const Pkcs11GetTpmTokenInfoCallback& callback) OVERRIDE; 73 virtual bool InstallAttributesGet(const std::string& name, 74 std::vector<uint8>* value, 75 bool* successful) OVERRIDE; 76 virtual bool InstallAttributesSet(const std::string& name, 77 const std::vector<uint8>& value, 78 bool* successful) OVERRIDE; 79 virtual bool InstallAttributesFinalize(bool* successful) OVERRIDE; 80 virtual void InstallAttributesIsReady( 81 const BoolDBusMethodCallback& callback) OVERRIDE; 82 virtual bool InstallAttributesIsInvalid(bool* is_invalid) OVERRIDE; 83 virtual bool InstallAttributesIsFirstInstall(bool* is_first_install) OVERRIDE; 84 virtual void TpmAttestationIsPrepared( 85 const BoolDBusMethodCallback& callback) OVERRIDE; 86 virtual void TpmAttestationIsEnrolled( 87 const BoolDBusMethodCallback& callback) OVERRIDE; 88 virtual void AsyncTpmAttestationCreateEnrollRequest( 89 const AsyncMethodCallback& callback) OVERRIDE; 90 virtual void AsyncTpmAttestationEnroll( 91 const std::string& pca_response, 92 const AsyncMethodCallback& callback) OVERRIDE; 93 virtual void AsyncTpmAttestationCreateCertRequest( 94 int options, 95 const AsyncMethodCallback& callback) OVERRIDE; 96 virtual void AsyncTpmAttestationFinishCertRequest( 97 const std::string& pca_response, 98 attestation::AttestationKeyType key_type, 99 const std::string& key_name, 100 const AsyncMethodCallback& callback) OVERRIDE; 101 virtual void TpmAttestationDoesKeyExist( 102 attestation::AttestationKeyType key_type, 103 const std::string& key_name, 104 const BoolDBusMethodCallback& callback) OVERRIDE; 105 virtual void TpmAttestationGetCertificate( 106 attestation::AttestationKeyType key_type, 107 const std::string& key_name, 108 const DataMethodCallback& callback) OVERRIDE; 109 virtual void TpmAttestationGetPublicKey( 110 attestation::AttestationKeyType key_type, 111 const std::string& key_name, 112 const DataMethodCallback& callback) OVERRIDE; 113 virtual void TpmAttestationRegisterKey( 114 attestation::AttestationKeyType key_type, 115 const std::string& key_name, 116 const AsyncMethodCallback& callback) OVERRIDE; 117 virtual void TpmAttestationSignEnterpriseChallenge( 118 attestation::AttestationKeyType key_type, 119 const std::string& key_name, 120 const std::string& domain, 121 const std::string& device_id, 122 attestation::AttestationChallengeOptions options, 123 const std::string& challenge, 124 const AsyncMethodCallback& callback) OVERRIDE; 125 virtual void TpmAttestationSignSimpleChallenge( 126 attestation::AttestationKeyType key_type, 127 const std::string& key_name, 128 const std::string& challenge, 129 const AsyncMethodCallback& callback) OVERRIDE; 130 virtual void TpmAttestationGetKeyPayload( 131 attestation::AttestationKeyType key_type, 132 const std::string& key_name, 133 const DataMethodCallback& callback) OVERRIDE; 134 virtual void TpmAttestationSetKeyPayload( 135 attestation::AttestationKeyType key_type, 136 const std::string& key_name, 137 const std::string& payload, 138 const BoolDBusMethodCallback& callback) OVERRIDE; 139 140 // Sets the unmount result of Unmount() call. Unmount() always sets the result 141 // and pretends that the underlying method call succeeds. 142 void set_unmount_result(bool result) { 143 unmount_result_= result; 144 } 145 146 private: 147 AsyncCallStatusHandler handler_; 148 AsyncCallStatusWithDataHandler data_handler_; 149 150 bool unmount_result_; 151 152 DISALLOW_COPY_AND_ASSIGN(FakeCryptohomeClient); 153 }; 154 155 } // namespace chromeos 156 157 #endif // CHROMEOS_DBUS_FAKE_CRYPTOHOME_CLIENT_H_ 158