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