fake_cryptohome_client.cc revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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::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()); 105 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)); 114} 115 116void FakeCryptohomeClient::AsyncMountGuest( 117 const AsyncMethodCallback& callback) { 118} 119 120bool FakeCryptohomeClient::CallTpmIsBeingOwnedAndBlock(bool* owning) { 121 return false; 122} 123 124void FakeCryptohomeClient::Pkcs11IsTpmTokenReady( 125 const BoolDBusMethodCallback& callback) { 126} 127 128void FakeCryptohomeClient::TpmClearStoredPassword( 129 const VoidDBusMethodCallback& callback) { 130} 131 132void FakeCryptohomeClient::TpmCanAttemptOwnership( 133 const VoidDBusMethodCallback& callback) { 134} 135 136bool FakeCryptohomeClient::GetSystemSalt(std::vector<uint8>* salt) { 137 salt->assign(kStubSystemSalt, 138 kStubSystemSalt + arraysize(kStubSystemSalt) - 1); 139 return true; 140} 141 142void FakeCryptohomeClient::TpmGetPassword( 143 const StringDBusMethodCallback& callback) { 144} 145 146bool FakeCryptohomeClient::InstallAttributesFinalize(bool* successful) { 147 return false; 148} 149 150void FakeCryptohomeClient::SetAsyncCallStatusHandlers( 151 const AsyncCallStatusHandler& handler, 152 const AsyncCallStatusWithDataHandler& data_handler) { 153 handler_ = handler; 154 data_handler_ = data_handler; 155} 156 157bool FakeCryptohomeClient::CallTpmIsEnabledAndBlock(bool* enabled) { 158 return false; 159} 160 161bool FakeCryptohomeClient::InstallAttributesSet( 162 const std::string& name, 163 const std::vector<uint8>& value, 164 bool* successful) { 165 return false; 166} 167 168bool FakeCryptohomeClient::InstallAttributesIsFirstInstall( 169 bool* is_first_install) { 170 return false; 171} 172 173void FakeCryptohomeClient::TpmAttestationGetCertificate( 174 attestation::AttestationKeyType key_type, 175 const std::string& key_name, 176 const DataMethodCallback& callback) { 177} 178 179void FakeCryptohomeClient::InstallAttributesIsReady( 180 const BoolDBusMethodCallback& callback) { 181 base::MessageLoop::current()->PostTask(FROM_HERE, 182 base::Bind(callback, 183 DBUS_METHOD_CALL_SUCCESS, true)); 184} 185 186void FakeCryptohomeClient::TpmAttestationGetPublicKey( 187 attestation::AttestationKeyType key_type, 188 const std::string& key_name, 189 const DataMethodCallback& callback) { 190} 191 192void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge( 193 attestation::AttestationKeyType key_type, 194 const std::string& key_name, 195 const std::string& challenge, 196 const AsyncMethodCallback& callback) { 197} 198 199void FakeCryptohomeClient::Pkcs11GetTpmTokenInfo( 200 const Pkcs11GetTpmTokenInfoCallback& callback) { 201} 202 203void FakeCryptohomeClient::TpmIsOwned(const BoolDBusMethodCallback& callback) { 204} 205 206void FakeCryptohomeClient::TpmAttestationIsPrepared( 207 const BoolDBusMethodCallback& callback) { 208} 209 210void FakeCryptohomeClient::TpmIsReady(const BoolDBusMethodCallback& callback) { 211} 212 213void FakeCryptohomeClient::AsyncTpmAttestationCreateEnrollRequest( 214 const AsyncMethodCallback& callback) { 215} 216 217void FakeCryptohomeClient::ResetAsyncCallStatusHandlers() { 218 handler_.Reset(); 219 data_handler_.Reset(); 220} 221 222void FakeCryptohomeClient::TpmAttestationDoesKeyExist( 223 attestation::AttestationKeyType key_type, 224 const std::string& key_name, 225 const BoolDBusMethodCallback& callback) { 226} 227 228bool FakeCryptohomeClient::CallTpmIsOwnedAndBlock(bool* owned) { 229 return false; 230} 231 232void FakeCryptohomeClient::AsyncRemove(const std::string& username, 233 const AsyncMethodCallback& callback) { 234} 235 236void FakeCryptohomeClient::TpmAttestationSetKeyPayload( 237 attestation::AttestationKeyType key_type, 238 const std::string& key_name, 239 const std::string& payload, 240 const BoolDBusMethodCallback& callback) { 241} 242 243void FakeCryptohomeClient::GetSanitizedUsername( 244 const std::string& username, 245 const StringDBusMethodCallback& callback) { 246 DCHECK(!callback.is_null()); 247 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)); 260} 261 262void 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) { 270} 271 272void FakeCryptohomeClient::TpmAttestationIsEnrolled( 273 const BoolDBusMethodCallback& callback) { 274} 275 276void FakeCryptohomeClient::TpmAttestationRegisterKey( 277 attestation::AttestationKeyType key_type, 278 const std::string& key_name, 279 const AsyncMethodCallback& callback) { 280} 281 282bool FakeCryptohomeClient::CallTpmClearStoredPasswordAndBlock() { 283 return false; 284} 285 286void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest( 287 int options, 288 const AsyncMethodCallback& callback) { 289} 290 291} // namespace chromeos 292