fake_cryptohome_client.cc revision 424c4d7b64af9d0d8fd9624f381f469654d5e3d2
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::Init(dbus::Bus* bus) { 27} 28 29void FakeCryptohomeClient::TpmIsBeingOwned( 30 const BoolDBusMethodCallback& callback) { 31} 32 33bool FakeCryptohomeClient::Unmount(bool* success) { 34 *success = unmount_result_; 35 return true; 36} 37 38void FakeCryptohomeClient::AsyncCheckKey(const std::string& username, 39 const std::string& key, 40 const AsyncMethodCallback& callback) { 41} 42 43bool FakeCryptohomeClient::InstallAttributesIsInvalid(bool* is_invalid) { 44 return false; 45} 46 47void FakeCryptohomeClient::TpmAttestationGetKeyPayload( 48 attestation::AttestationKeyType key_type, 49 const std::string& key_name, 50 const DataMethodCallback& callback) { 51} 52 53void FakeCryptohomeClient::AsyncTpmAttestationFinishCertRequest( 54 const std::string& pca_response, 55 attestation::AttestationKeyType key_type, 56 const std::string& key_name, 57 const AsyncMethodCallback& callback) { 58} 59 60void FakeCryptohomeClient::TpmIsEnabled( 61 const BoolDBusMethodCallback& callback) { 62} 63 64void FakeCryptohomeClient::AsyncTpmAttestationEnroll( 65 const std::string& pca_response, 66 const AsyncMethodCallback& callback) { 67} 68 69void FakeCryptohomeClient::AsyncMigrateKey( 70 const std::string& username, 71 const std::string& from_key, 72 const std::string& to_key, 73 const AsyncMethodCallback& callback) { 74} 75 76void FakeCryptohomeClient::IsMounted(const BoolDBusMethodCallback& callback) { 77 base::MessageLoop::current()->PostTask(FROM_HERE, 78 base::Bind(callback, 79 DBUS_METHOD_CALL_SUCCESS, true)); 80} 81 82bool FakeCryptohomeClient::InstallAttributesGet(const std::string& name, 83 std::vector<uint8>* value, 84 bool* successful) { 85 return false; 86} 87 88void FakeCryptohomeClient::AsyncMount(const std::string& username, 89 const std::string& key, int flags, 90 const AsyncMethodCallback& callback) { 91 DCHECK(!callback.is_null()); 92 93 base::MessageLoop::current()->PostTask(FROM_HERE, 94 base::Bind(callback, 1 /* async_id */)); 95 if (!handler_.is_null()) 96 base::MessageLoop::current()->PostTask(FROM_HERE, 97 base::Bind(handler_, 98 1, // async_id 99 true, // return_status 100 cryptohome::MOUNT_ERROR_NONE)); 101} 102 103void FakeCryptohomeClient::AsyncAddKey(const std::string& username, 104 const std::string& key, 105 const std::string& new_key, 106 const AsyncMethodCallback& callback) { 107 DCHECK(!callback.is_null()); 108 109 base::MessageLoop::current()->PostTask(FROM_HERE, 110 base::Bind(callback, 1 /* async_id */)); 111 if (!handler_.is_null()) 112 base::MessageLoop::current()->PostTask(FROM_HERE, 113 base::Bind(handler_, 114 1, // async_id 115 true, // return_status 116 cryptohome::MOUNT_ERROR_NONE)); 117} 118 119void FakeCryptohomeClient::AsyncMountGuest( 120 const AsyncMethodCallback& callback) { 121} 122 123void FakeCryptohomeClient::AsyncMountPublic( 124 const std::string& public_mount_id, 125 int flags, 126 const AsyncMethodCallback& callback) { 127} 128 129bool FakeCryptohomeClient::CallTpmIsBeingOwnedAndBlock(bool* owning) { 130 return false; 131} 132 133void FakeCryptohomeClient::Pkcs11IsTpmTokenReady( 134 const BoolDBusMethodCallback& callback) { 135} 136 137void FakeCryptohomeClient::TpmClearStoredPassword( 138 const VoidDBusMethodCallback& callback) { 139} 140 141void FakeCryptohomeClient::TpmCanAttemptOwnership( 142 const VoidDBusMethodCallback& callback) { 143} 144 145bool FakeCryptohomeClient::GetSystemSalt(std::vector<uint8>* salt) { 146 salt->assign(kStubSystemSalt, 147 kStubSystemSalt + arraysize(kStubSystemSalt) - 1); 148 return true; 149} 150 151void FakeCryptohomeClient::TpmGetPassword( 152 const StringDBusMethodCallback& callback) { 153} 154 155bool FakeCryptohomeClient::InstallAttributesFinalize(bool* successful) { 156 return false; 157} 158 159void FakeCryptohomeClient::SetAsyncCallStatusHandlers( 160 const AsyncCallStatusHandler& handler, 161 const AsyncCallStatusWithDataHandler& data_handler) { 162 handler_ = handler; 163 data_handler_ = data_handler; 164} 165 166bool FakeCryptohomeClient::CallTpmIsEnabledAndBlock(bool* enabled) { 167 return false; 168} 169 170bool FakeCryptohomeClient::InstallAttributesSet( 171 const std::string& name, 172 const std::vector<uint8>& value, 173 bool* successful) { 174 return false; 175} 176 177bool FakeCryptohomeClient::InstallAttributesIsFirstInstall( 178 bool* is_first_install) { 179 return false; 180} 181 182void FakeCryptohomeClient::TpmAttestationGetCertificate( 183 attestation::AttestationKeyType key_type, 184 const std::string& key_name, 185 const DataMethodCallback& callback) { 186} 187 188void FakeCryptohomeClient::InstallAttributesIsReady( 189 const BoolDBusMethodCallback& callback) { 190 base::MessageLoop::current()->PostTask(FROM_HERE, 191 base::Bind(callback, 192 DBUS_METHOD_CALL_SUCCESS, true)); 193} 194 195void FakeCryptohomeClient::TpmAttestationGetPublicKey( 196 attestation::AttestationKeyType key_type, 197 const std::string& key_name, 198 const DataMethodCallback& callback) { 199} 200 201void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge( 202 attestation::AttestationKeyType key_type, 203 const std::string& key_name, 204 const std::string& challenge, 205 const AsyncMethodCallback& callback) { 206} 207 208void FakeCryptohomeClient::Pkcs11GetTpmTokenInfo( 209 const Pkcs11GetTpmTokenInfoCallback& callback) { 210} 211 212void FakeCryptohomeClient::TpmIsOwned(const BoolDBusMethodCallback& callback) { 213} 214 215void FakeCryptohomeClient::TpmAttestationIsPrepared( 216 const BoolDBusMethodCallback& callback) { 217} 218 219void FakeCryptohomeClient::TpmIsReady(const BoolDBusMethodCallback& callback) { 220} 221 222void FakeCryptohomeClient::AsyncTpmAttestationCreateEnrollRequest( 223 const AsyncMethodCallback& callback) { 224} 225 226void FakeCryptohomeClient::ResetAsyncCallStatusHandlers() { 227 handler_.Reset(); 228 data_handler_.Reset(); 229} 230 231void FakeCryptohomeClient::TpmAttestationDoesKeyExist( 232 attestation::AttestationKeyType key_type, 233 const std::string& key_name, 234 const BoolDBusMethodCallback& callback) { 235} 236 237bool FakeCryptohomeClient::CallTpmIsOwnedAndBlock(bool* owned) { 238 return false; 239} 240 241void FakeCryptohomeClient::AsyncRemove(const std::string& username, 242 const AsyncMethodCallback& callback) { 243} 244 245void FakeCryptohomeClient::TpmAttestationSetKeyPayload( 246 attestation::AttestationKeyType key_type, 247 const std::string& key_name, 248 const std::string& payload, 249 const BoolDBusMethodCallback& callback) { 250} 251 252void FakeCryptohomeClient::GetSanitizedUsername( 253 const std::string& username, 254 const StringDBusMethodCallback& callback) { 255 DCHECK(!callback.is_null()); 256 257 base::MessageLoop::current()->PostTask( 258 FROM_HERE, 259 base::Bind(callback, 260 chromeos::DBUS_METHOD_CALL_SUCCESS, 261 username)); 262 if (!data_handler_.is_null()) 263 base::MessageLoop::current()->PostTask( 264 FROM_HERE, 265 base::Bind(data_handler_, 266 1, // async_id 267 true, // return_status 268 username)); 269} 270 271std::string FakeCryptohomeClient::BlockingGetSanitizedUsername( 272 const std::string& username) { 273 return username; 274} 275 276void FakeCryptohomeClient::TpmAttestationSignEnterpriseChallenge( 277 attestation::AttestationKeyType key_type, 278 const std::string& key_name, 279 const std::string& domain, 280 const std::string& device_id, 281 attestation::AttestationChallengeOptions options, 282 const std::string& challenge, 283 const AsyncMethodCallback& callback) { 284} 285 286void FakeCryptohomeClient::TpmAttestationIsEnrolled( 287 const BoolDBusMethodCallback& callback) { 288} 289 290void FakeCryptohomeClient::TpmAttestationRegisterKey( 291 attestation::AttestationKeyType key_type, 292 const std::string& key_name, 293 const AsyncMethodCallback& callback) { 294} 295 296bool FakeCryptohomeClient::CallTpmClearStoredPasswordAndBlock() { 297 return false; 298} 299 300void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest( 301 attestation::AttestationCertificateProfile certificate_profile, 302 const std::string& user_email, 303 const std::string& request_origin, 304 const AsyncMethodCallback& callback) { 305} 306 307} // namespace chromeos 308