| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/dbus/fake_cryptohome_client.h" | 5 #include "chromeos/dbus/fake_cryptohome_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 13 #include "chromeos/chromeos_paths.h" | 13 #include "chromeos/chromeos_paths.h" |
| 14 #include "chromeos/dbus/cryptohome/key.pb.h" | 14 #include "chromeos/dbus/cryptohome/key.pb.h" |
| 15 #include "chromeos/dbus/cryptohome/rpc.pb.h" | 15 #include "chromeos/dbus/cryptohome/rpc.pb.h" |
| 16 #include "components/user_manager/user_id.h" |
| 16 #include "third_party/cros_system_api/dbus/service_constants.h" | 17 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 17 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h" | 18 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h" |
| 18 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream.h" | 19 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream.h" |
| 19 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite
.h" | 20 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite
.h" |
| 20 | 21 |
| 21 namespace chromeos { | 22 namespace chromeos { |
| 22 | 23 |
| 23 FakeCryptohomeClient::FakeCryptohomeClient() | 24 FakeCryptohomeClient::FakeCryptohomeClient() |
| 24 : service_is_available_(true), | 25 : service_is_available_(true), |
| 25 async_call_id_(1), | 26 async_call_id_(1), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 base::MessageLoop::current()->PostTask( | 64 base::MessageLoop::current()->PostTask( |
| 64 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); | 65 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); |
| 65 } | 66 } |
| 66 | 67 |
| 67 bool FakeCryptohomeClient::Unmount(bool* success) { | 68 bool FakeCryptohomeClient::Unmount(bool* success) { |
| 68 *success = unmount_result_; | 69 *success = unmount_result_; |
| 69 return true; | 70 return true; |
| 70 } | 71 } |
| 71 | 72 |
| 72 void FakeCryptohomeClient::AsyncCheckKey( | 73 void FakeCryptohomeClient::AsyncCheckKey( |
| 73 const std::string& username, | 74 const user_manager::UserID& user_id, |
| 74 const std::string& key, | 75 const std::string& key, |
| 75 const AsyncMethodCallback& callback) { | 76 const AsyncMethodCallback& callback) { |
| 76 ReturnAsyncMethodResult(callback, false); | 77 ReturnAsyncMethodResult(callback, false); |
| 77 } | 78 } |
| 78 | 79 |
| 79 void FakeCryptohomeClient::AsyncMigrateKey( | 80 void FakeCryptohomeClient::AsyncMigrateKey( |
| 80 const std::string& username, | 81 const user_manager::UserID& user_id, |
| 81 const std::string& from_key, | 82 const std::string& from_key, |
| 82 const std::string& to_key, | 83 const std::string& to_key, |
| 83 const AsyncMethodCallback& callback) { | 84 const AsyncMethodCallback& callback) { |
| 84 ReturnAsyncMethodResult(callback, false); | 85 ReturnAsyncMethodResult(callback, false); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void FakeCryptohomeClient::AsyncRemove( | 88 void FakeCryptohomeClient::AsyncRemove( |
| 88 const std::string& username, | 89 const user_manager::UserID& user_id, |
| 89 const AsyncMethodCallback& callback) { | 90 const AsyncMethodCallback& callback) { |
| 90 ReturnAsyncMethodResult(callback, false); | 91 ReturnAsyncMethodResult(callback, false); |
| 91 } | 92 } |
| 92 | 93 |
| 93 void FakeCryptohomeClient::GetSystemSalt( | 94 void FakeCryptohomeClient::GetSystemSalt( |
| 94 const GetSystemSaltCallback& callback) { | 95 const GetSystemSaltCallback& callback) { |
| 95 base::MessageLoop::current()->PostTask( | 96 base::MessageLoop::current()->PostTask( |
| 96 FROM_HERE, | 97 FROM_HERE, |
| 97 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, system_salt_)); | 98 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, system_salt_)); |
| 98 } | 99 } |
| 99 | 100 |
| 100 void FakeCryptohomeClient::GetSanitizedUsername( | 101 void FakeCryptohomeClient::GetSanitizedUsername( |
| 101 const std::string& username, | 102 const user_manager::UserID& user_id, |
| 102 const StringDBusMethodCallback& callback) { | 103 const StringDBusMethodCallback& callback) { |
| 103 // Even for stub implementation we have to return different values so that | 104 // Even for stub implementation we have to return different values so that |
| 104 // multi-profiles would work. | 105 // multi-profiles would work. |
| 105 std::string sanitized_username = GetStubSanitizedUsername(username); | 106 std::string sanitized_username = GetStubSanitizedUsername(user_id); |
| 106 base::MessageLoop::current()->PostTask( | 107 base::MessageLoop::current()->PostTask( |
| 107 FROM_HERE, | 108 FROM_HERE, |
| 108 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, sanitized_username)); | 109 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, sanitized_username)); |
| 109 } | 110 } |
| 110 | 111 |
| 111 std::string FakeCryptohomeClient::BlockingGetSanitizedUsername( | 112 std::string FakeCryptohomeClient::BlockingGetSanitizedUsername( |
| 112 const std::string& username) { | 113 const user_manager::UserID& user_id) { |
| 113 return GetStubSanitizedUsername(username); | 114 return GetStubSanitizedUsername(user_id); |
| 114 } | 115 } |
| 115 | 116 |
| 116 void FakeCryptohomeClient::AsyncMount(const std::string& username, | 117 void FakeCryptohomeClient::AsyncMount(const user_manager::UserID& user_id, |
| 117 const std::string& key, | 118 const std::string& key, |
| 118 int flags, | 119 int flags, |
| 119 const AsyncMethodCallback& callback) { | 120 const AsyncMethodCallback& callback) { |
| 120 ReturnAsyncMethodResult(callback, false); | 121 ReturnAsyncMethodResult(callback, false); |
| 121 } | 122 } |
| 122 | 123 |
| 123 void FakeCryptohomeClient::AsyncAddKey( | 124 void FakeCryptohomeClient::AsyncAddKey( |
| 124 const std::string& username, | 125 const user_manager::UserID& user_id, |
| 125 const std::string& key, | 126 const std::string& key, |
| 126 const std::string& new_key, | 127 const std::string& new_key, |
| 127 const AsyncMethodCallback& callback) { | 128 const AsyncMethodCallback& callback) { |
| 128 ReturnAsyncMethodResult(callback, false); | 129 ReturnAsyncMethodResult(callback, false); |
| 129 } | 130 } |
| 130 | 131 |
| 131 void FakeCryptohomeClient::AsyncMountGuest( | 132 void FakeCryptohomeClient::AsyncMountGuest( |
| 132 const AsyncMethodCallback& callback) { | 133 const AsyncMethodCallback& callback) { |
| 133 ReturnAsyncMethodResult(callback, false); | 134 ReturnAsyncMethodResult(callback, false); |
| 134 } | 135 } |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 base::MessageLoop::current()->PostTask( | 219 base::MessageLoop::current()->PostTask( |
| 219 FROM_HERE, | 220 FROM_HERE, |
| 220 base::Bind(callback, | 221 base::Bind(callback, |
| 221 DBUS_METHOD_CALL_SUCCESS, | 222 DBUS_METHOD_CALL_SUCCESS, |
| 222 std::string(kStubTPMTokenName), | 223 std::string(kStubTPMTokenName), |
| 223 std::string(kStubUserPin), | 224 std::string(kStubUserPin), |
| 224 kStubSlot)); | 225 kStubSlot)); |
| 225 } | 226 } |
| 226 | 227 |
| 227 void FakeCryptohomeClient::Pkcs11GetTpmTokenInfoForUser( | 228 void FakeCryptohomeClient::Pkcs11GetTpmTokenInfoForUser( |
| 228 const std::string& username, | 229 const user_manager::UserID& user_id, |
| 229 const Pkcs11GetTpmTokenInfoCallback& callback) { | 230 const Pkcs11GetTpmTokenInfoCallback& callback) { |
| 230 Pkcs11GetTpmTokenInfo(callback); | 231 Pkcs11GetTpmTokenInfo(callback); |
| 231 } | 232 } |
| 232 | 233 |
| 233 bool FakeCryptohomeClient::InstallAttributesGet(const std::string& name, | 234 bool FakeCryptohomeClient::InstallAttributesGet(const std::string& name, |
| 234 std::vector<uint8>* value, | 235 std::vector<uint8>* value, |
| 235 bool* successful) { | 236 bool* successful) { |
| 236 if (install_attrs_.find(name) != install_attrs_.end()) { | 237 if (install_attrs_.find(name) != install_attrs_.end()) { |
| 237 *value = install_attrs_[name]; | 238 *value = install_attrs_[name]; |
| 238 *successful = true; | 239 *successful = true; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 void FakeCryptohomeClient::AsyncTpmAttestationEnroll( | 351 void FakeCryptohomeClient::AsyncTpmAttestationEnroll( |
| 351 chromeos::attestation::PrivacyCAType pca_type, | 352 chromeos::attestation::PrivacyCAType pca_type, |
| 352 const std::string& pca_response, | 353 const std::string& pca_response, |
| 353 const AsyncMethodCallback& callback) { | 354 const AsyncMethodCallback& callback) { |
| 354 ReturnAsyncMethodResult(callback, false); | 355 ReturnAsyncMethodResult(callback, false); |
| 355 } | 356 } |
| 356 | 357 |
| 357 void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest( | 358 void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest( |
| 358 chromeos::attestation::PrivacyCAType pca_type, | 359 chromeos::attestation::PrivacyCAType pca_type, |
| 359 attestation::AttestationCertificateProfile certificate_profile, | 360 attestation::AttestationCertificateProfile certificate_profile, |
| 360 const std::string& user_id, | 361 const user_manager::UserID& user_id, |
| 361 const std::string& request_origin, | 362 const std::string& request_origin, |
| 362 const AsyncMethodCallback& callback) { | 363 const AsyncMethodCallback& callback) { |
| 363 ReturnAsyncMethodResult(callback, true); | 364 ReturnAsyncMethodResult(callback, true); |
| 364 } | 365 } |
| 365 | 366 |
| 366 void FakeCryptohomeClient::AsyncTpmAttestationFinishCertRequest( | 367 void FakeCryptohomeClient::AsyncTpmAttestationFinishCertRequest( |
| 367 const std::string& pca_response, | 368 const std::string& pca_response, |
| 368 attestation::AttestationKeyType key_type, | 369 attestation::AttestationKeyType key_type, |
| 369 const std::string& user_id, | 370 const user_manager::UserID& user_id, |
| 370 const std::string& key_name, | 371 const std::string& key_name, |
| 371 const AsyncMethodCallback& callback) { | 372 const AsyncMethodCallback& callback) { |
| 372 ReturnAsyncMethodResult(callback, true); | 373 ReturnAsyncMethodResult(callback, true); |
| 373 } | 374 } |
| 374 | 375 |
| 375 void FakeCryptohomeClient::TpmAttestationDoesKeyExist( | 376 void FakeCryptohomeClient::TpmAttestationDoesKeyExist( |
| 376 attestation::AttestationKeyType key_type, | 377 attestation::AttestationKeyType key_type, |
| 377 const std::string& user_id, | 378 const user_manager::UserID& user_id, |
| 378 const std::string& key_name, | 379 const std::string& key_name, |
| 379 const BoolDBusMethodCallback& callback) { | 380 const BoolDBusMethodCallback& callback) { |
| 380 base::MessageLoop::current()->PostTask( | 381 base::MessageLoop::current()->PostTask( |
| 381 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); | 382 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); |
| 382 } | 383 } |
| 383 | 384 |
| 384 void FakeCryptohomeClient::TpmAttestationGetCertificate( | 385 void FakeCryptohomeClient::TpmAttestationGetCertificate( |
| 385 attestation::AttestationKeyType key_type, | 386 attestation::AttestationKeyType key_type, |
| 386 const std::string& user_id, | 387 const user_manager::UserID& user_id, |
| 387 const std::string& key_name, | 388 const std::string& key_name, |
| 388 const DataMethodCallback& callback) { | 389 const DataMethodCallback& callback) { |
| 389 base::MessageLoop::current()->PostTask( | 390 base::MessageLoop::current()->PostTask( |
| 390 FROM_HERE, | 391 FROM_HERE, |
| 391 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); | 392 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); |
| 392 } | 393 } |
| 393 | 394 |
| 394 void FakeCryptohomeClient::TpmAttestationGetPublicKey( | 395 void FakeCryptohomeClient::TpmAttestationGetPublicKey( |
| 395 attestation::AttestationKeyType key_type, | 396 attestation::AttestationKeyType key_type, |
| 396 const std::string& user_id, | 397 const user_manager::UserID& user_id, |
| 397 const std::string& key_name, | 398 const std::string& key_name, |
| 398 const DataMethodCallback& callback) { | 399 const DataMethodCallback& callback) { |
| 399 base::MessageLoop::current()->PostTask( | 400 base::MessageLoop::current()->PostTask( |
| 400 FROM_HERE, | 401 FROM_HERE, |
| 401 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); | 402 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); |
| 402 } | 403 } |
| 403 | 404 |
| 404 void FakeCryptohomeClient::TpmAttestationRegisterKey( | 405 void FakeCryptohomeClient::TpmAttestationRegisterKey( |
| 405 attestation::AttestationKeyType key_type, | 406 attestation::AttestationKeyType key_type, |
| 406 const std::string& user_id, | 407 const user_manager::UserID& user_id, |
| 407 const std::string& key_name, | 408 const std::string& key_name, |
| 408 const AsyncMethodCallback& callback) { | 409 const AsyncMethodCallback& callback) { |
| 409 ReturnAsyncMethodResult(callback, true); | 410 ReturnAsyncMethodResult(callback, true); |
| 410 } | 411 } |
| 411 | 412 |
| 412 void FakeCryptohomeClient::TpmAttestationSignEnterpriseChallenge( | 413 void FakeCryptohomeClient::TpmAttestationSignEnterpriseChallenge( |
| 413 attestation::AttestationKeyType key_type, | 414 attestation::AttestationKeyType key_type, |
| 414 const std::string& user_id, | 415 const user_manager::UserID& user_id, |
| 415 const std::string& key_name, | 416 const std::string& key_name, |
| 416 const std::string& domain, | 417 const std::string& domain, |
| 417 const std::string& device_id, | 418 const std::string& device_id, |
| 418 attestation::AttestationChallengeOptions options, | 419 attestation::AttestationChallengeOptions options, |
| 419 const std::string& challenge, | 420 const std::string& challenge, |
| 420 const AsyncMethodCallback& callback) { | 421 const AsyncMethodCallback& callback) { |
| 421 ReturnAsyncMethodResult(callback, true); | 422 ReturnAsyncMethodResult(callback, true); |
| 422 } | 423 } |
| 423 | 424 |
| 424 void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge( | 425 void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge( |
| 425 attestation::AttestationKeyType key_type, | 426 attestation::AttestationKeyType key_type, |
| 426 const std::string& user_id, | 427 const user_manager::UserID& user_id, |
| 427 const std::string& key_name, | 428 const std::string& key_name, |
| 428 const std::string& challenge, | 429 const std::string& challenge, |
| 429 const AsyncMethodCallback& callback) { | 430 const AsyncMethodCallback& callback) { |
| 430 ReturnAsyncMethodResult(callback, true); | 431 ReturnAsyncMethodResult(callback, true); |
| 431 } | 432 } |
| 432 | 433 |
| 433 void FakeCryptohomeClient::TpmAttestationGetKeyPayload( | 434 void FakeCryptohomeClient::TpmAttestationGetKeyPayload( |
| 434 attestation::AttestationKeyType key_type, | 435 attestation::AttestationKeyType key_type, |
| 435 const std::string& user_id, | 436 const user_manager::UserID& user_id, |
| 436 const std::string& key_name, | 437 const std::string& key_name, |
| 437 const DataMethodCallback& callback) { | 438 const DataMethodCallback& callback) { |
| 438 base::MessageLoop::current()->PostTask( | 439 base::MessageLoop::current()->PostTask( |
| 439 FROM_HERE, | 440 FROM_HERE, |
| 440 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); | 441 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); |
| 441 } | 442 } |
| 442 | 443 |
| 443 void FakeCryptohomeClient::TpmAttestationSetKeyPayload( | 444 void FakeCryptohomeClient::TpmAttestationSetKeyPayload( |
| 444 attestation::AttestationKeyType key_type, | 445 attestation::AttestationKeyType key_type, |
| 445 const std::string& user_id, | 446 const user_manager::UserID& user_id, |
| 446 const std::string& key_name, | 447 const std::string& key_name, |
| 447 const std::string& payload, | 448 const std::string& payload, |
| 448 const BoolDBusMethodCallback& callback) { | 449 const BoolDBusMethodCallback& callback) { |
| 449 base::MessageLoop::current()->PostTask( | 450 base::MessageLoop::current()->PostTask( |
| 450 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); | 451 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); |
| 451 } | 452 } |
| 452 | 453 |
| 453 void FakeCryptohomeClient::TpmAttestationDeleteKeys( | 454 void FakeCryptohomeClient::TpmAttestationDeleteKeys( |
| 454 attestation::AttestationKeyType key_type, | 455 attestation::AttestationKeyType key_type, |
| 455 const std::string& user_id, | 456 const user_manager::UserID& user_id, |
| 456 const std::string& key_prefix, | 457 const std::string& key_prefix, |
| 457 const BoolDBusMethodCallback& callback) { | 458 const BoolDBusMethodCallback& callback) { |
| 458 base::MessageLoop::current()->PostTask( | 459 base::MessageLoop::current()->PostTask( |
| 459 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); | 460 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); |
| 460 } | 461 } |
| 461 | 462 |
| 462 void FakeCryptohomeClient::GetKeyDataEx( | 463 void FakeCryptohomeClient::GetKeyDataEx( |
| 463 const cryptohome::AccountIdentifier& id, | 464 const cryptohome::AccountIdentifier& id, |
| 464 const cryptohome::AuthorizationRequest& auth, | 465 const cryptohome::AuthorizationRequest& auth, |
| 465 const cryptohome::GetKeyDataRequest& request, | 466 const cryptohome::GetKeyDataRequest& request, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 479 } | 480 } |
| 480 | 481 |
| 481 void FakeCryptohomeClient::MountEx( | 482 void FakeCryptohomeClient::MountEx( |
| 482 const cryptohome::AccountIdentifier& id, | 483 const cryptohome::AccountIdentifier& id, |
| 483 const cryptohome::AuthorizationRequest& auth, | 484 const cryptohome::AuthorizationRequest& auth, |
| 484 const cryptohome::MountRequest& request, | 485 const cryptohome::MountRequest& request, |
| 485 const ProtobufMethodCallback& callback) { | 486 const ProtobufMethodCallback& callback) { |
| 486 cryptohome::BaseReply reply; | 487 cryptohome::BaseReply reply; |
| 487 cryptohome::MountReply* mount = | 488 cryptohome::MountReply* mount = |
| 488 reply.MutableExtension(cryptohome::MountReply::reply); | 489 reply.MutableExtension(cryptohome::MountReply::reply); |
| 489 mount->set_sanitized_username(GetStubSanitizedUsername(id.email())); | 490 const user_manager::UserID user_id(std::string() /* gaia_id */, id.email()); |
| 491 mount->set_sanitized_username(GetStubSanitizedUsername(user_id)); |
| 490 ReturnProtobufMethodCallback(reply, callback); | 492 ReturnProtobufMethodCallback(reply, callback); |
| 491 } | 493 } |
| 492 | 494 |
| 493 void FakeCryptohomeClient::AddKeyEx( | 495 void FakeCryptohomeClient::AddKeyEx( |
| 494 const cryptohome::AccountIdentifier& id, | 496 const cryptohome::AccountIdentifier& id, |
| 495 const cryptohome::AuthorizationRequest& auth, | 497 const cryptohome::AuthorizationRequest& auth, |
| 496 const cryptohome::AddKeyRequest& request, | 498 const cryptohome::AddKeyRequest& request, |
| 497 const ProtobufMethodCallback& callback) { | 499 const ProtobufMethodCallback& callback) { |
| 498 cryptohome::BaseReply reply; | 500 cryptohome::BaseReply reply; |
| 499 ReturnProtobufMethodCallback(reply, callback); | 501 ReturnProtobufMethodCallback(reply, callback); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 FROM_HERE, | 598 FROM_HERE, |
| 597 base::Bind(async_call_status_data_handler_, | 599 base::Bind(async_call_status_data_handler_, |
| 598 async_call_id_, | 600 async_call_id_, |
| 599 true, | 601 true, |
| 600 std::string())); | 602 std::string())); |
| 601 } | 603 } |
| 602 ++async_call_id_; | 604 ++async_call_id_; |
| 603 } | 605 } |
| 604 | 606 |
| 605 } // namespace chromeos | 607 } // namespace chromeos |
| OLD | NEW |