| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/location.h" | 12 #include "base/location.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "chromeos/chromeos_paths.h" | 17 #include "chromeos/chromeos_paths.h" |
| 18 #include "chromeos/attestation/attestation.pb.h" | |
| 19 #include "chromeos/dbus/cryptohome/key.pb.h" | 18 #include "chromeos/dbus/cryptohome/key.pb.h" |
| 20 #include "chromeos/dbus/cryptohome/rpc.pb.h" | 19 #include "chromeos/dbus/cryptohome/rpc.pb.h" |
| 21 #include "third_party/cros_system_api/dbus/service_constants.h" | 20 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 22 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h" | 21 #include "third_party/protobuf/src/google/protobuf/io/coded_stream.h" |
| 23 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream.h" | 22 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream.h" |
| 24 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite
.h" | 23 #include "third_party/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite
.h" |
| 25 | 24 |
| 26 namespace chromeos { | 25 namespace chromeos { |
| 27 | 26 |
| 28 namespace { | |
| 29 // Signature nonces are twenty bytes. This matches the attestation code. | |
| 30 constexpr char kTwentyBytesNonce[] = "+addtwentybytesnonce"; | |
| 31 // A symbolic signature. | |
| 32 constexpr char kSignature[] = "signed"; | |
| 33 } // namespace | |
| 34 | |
| 35 FakeCryptohomeClient::FakeCryptohomeClient() | 27 FakeCryptohomeClient::FakeCryptohomeClient() |
| 36 : service_is_available_(true), | 28 : service_is_available_(true), |
| 37 async_call_id_(1), | 29 async_call_id_(1), |
| 38 unmount_result_(true), | 30 unmount_result_(true), |
| 39 system_salt_(GetStubSystemSalt()), | 31 system_salt_(GetStubSystemSalt()), |
| 40 weak_ptr_factory_(this) { | 32 weak_ptr_factory_(this) { |
| 41 base::FilePath cache_path; | 33 base::FilePath cache_path; |
| 42 locked_ = PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, &cache_path) && | 34 locked_ = PathService::Get(chromeos::FILE_INSTALL_ATTRIBUTES, &cache_path) && |
| 43 base::PathExists(cache_path); | 35 base::PathExists(cache_path); |
| 44 } | 36 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 | 73 |
| 82 bool FakeCryptohomeClient::Unmount(bool* success) { | 74 bool FakeCryptohomeClient::Unmount(bool* success) { |
| 83 *success = unmount_result_; | 75 *success = unmount_result_; |
| 84 return true; | 76 return true; |
| 85 } | 77 } |
| 86 | 78 |
| 87 void FakeCryptohomeClient::AsyncCheckKey( | 79 void FakeCryptohomeClient::AsyncCheckKey( |
| 88 const cryptohome::Identification& cryptohome_id, | 80 const cryptohome::Identification& cryptohome_id, |
| 89 const std::string& key, | 81 const std::string& key, |
| 90 const AsyncMethodCallback& callback) { | 82 const AsyncMethodCallback& callback) { |
| 91 ReturnAsyncMethodResult(callback); | 83 ReturnAsyncMethodResult(callback, false); |
| 92 } | 84 } |
| 93 | 85 |
| 94 void FakeCryptohomeClient::AsyncMigrateKey( | 86 void FakeCryptohomeClient::AsyncMigrateKey( |
| 95 const cryptohome::Identification& cryptohome_id, | 87 const cryptohome::Identification& cryptohome_id, |
| 96 const std::string& from_key, | 88 const std::string& from_key, |
| 97 const std::string& to_key, | 89 const std::string& to_key, |
| 98 const AsyncMethodCallback& callback) { | 90 const AsyncMethodCallback& callback) { |
| 99 ReturnAsyncMethodResult(callback); | 91 ReturnAsyncMethodResult(callback, false); |
| 100 } | 92 } |
| 101 | 93 |
| 102 void FakeCryptohomeClient::AsyncRemove( | 94 void FakeCryptohomeClient::AsyncRemove( |
| 103 const cryptohome::Identification& cryptohome_id, | 95 const cryptohome::Identification& cryptohome_id, |
| 104 const AsyncMethodCallback& callback) { | 96 const AsyncMethodCallback& callback) { |
| 105 ReturnAsyncMethodResult(callback); | 97 ReturnAsyncMethodResult(callback, false); |
| 106 } | 98 } |
| 107 | 99 |
| 108 void FakeCryptohomeClient::RenameCryptohome( | 100 void FakeCryptohomeClient::RenameCryptohome( |
| 109 const cryptohome::Identification& cryptohome_id_from, | 101 const cryptohome::Identification& cryptohome_id_from, |
| 110 const cryptohome::Identification& cryptohome_id_to, | 102 const cryptohome::Identification& cryptohome_id_to, |
| 111 const ProtobufMethodCallback& callback) { | 103 const ProtobufMethodCallback& callback) { |
| 112 cryptohome::BaseReply reply; | 104 cryptohome::BaseReply reply; |
| 113 ReturnProtobufMethodCallback(reply, callback); | 105 ReturnProtobufMethodCallback(reply, callback); |
| 114 } | 106 } |
| 115 | 107 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 144 std::string FakeCryptohomeClient::BlockingGetSanitizedUsername( | 136 std::string FakeCryptohomeClient::BlockingGetSanitizedUsername( |
| 145 const cryptohome::Identification& cryptohome_id) { | 137 const cryptohome::Identification& cryptohome_id) { |
| 146 return GetStubSanitizedUsername(cryptohome_id); | 138 return GetStubSanitizedUsername(cryptohome_id); |
| 147 } | 139 } |
| 148 | 140 |
| 149 void FakeCryptohomeClient::AsyncMount( | 141 void FakeCryptohomeClient::AsyncMount( |
| 150 const cryptohome::Identification& cryptohome_id, | 142 const cryptohome::Identification& cryptohome_id, |
| 151 const std::string& key, | 143 const std::string& key, |
| 152 int flags, | 144 int flags, |
| 153 const AsyncMethodCallback& callback) { | 145 const AsyncMethodCallback& callback) { |
| 154 ReturnAsyncMethodResult(callback); | 146 ReturnAsyncMethodResult(callback, false); |
| 155 } | 147 } |
| 156 | 148 |
| 157 void FakeCryptohomeClient::AsyncAddKey( | 149 void FakeCryptohomeClient::AsyncAddKey( |
| 158 const cryptohome::Identification& cryptohome_id, | 150 const cryptohome::Identification& cryptohome_id, |
| 159 const std::string& key, | 151 const std::string& key, |
| 160 const std::string& new_key, | 152 const std::string& new_key, |
| 161 const AsyncMethodCallback& callback) { | 153 const AsyncMethodCallback& callback) { |
| 162 ReturnAsyncMethodResult(callback); | 154 ReturnAsyncMethodResult(callback, false); |
| 163 } | 155 } |
| 164 | 156 |
| 165 void FakeCryptohomeClient::AsyncMountGuest( | 157 void FakeCryptohomeClient::AsyncMountGuest( |
| 166 const AsyncMethodCallback& callback) { | 158 const AsyncMethodCallback& callback) { |
| 167 ReturnAsyncMethodResult(callback); | 159 ReturnAsyncMethodResult(callback, false); |
| 168 } | 160 } |
| 169 | 161 |
| 170 void FakeCryptohomeClient::AsyncMountPublic( | 162 void FakeCryptohomeClient::AsyncMountPublic( |
| 171 const cryptohome::Identification& public_mount_id, | 163 const cryptohome::Identification& public_mount_id, |
| 172 int flags, | 164 int flags, |
| 173 const AsyncMethodCallback& callback) { | 165 const AsyncMethodCallback& callback) { |
| 174 ReturnAsyncMethodResult(callback); | 166 ReturnAsyncMethodResult(callback, false); |
| 175 } | 167 } |
| 176 | 168 |
| 177 void FakeCryptohomeClient::TpmIsReady( | 169 void FakeCryptohomeClient::TpmIsReady( |
| 178 const BoolDBusMethodCallback& callback) { | 170 const BoolDBusMethodCallback& callback) { |
| 179 base::ThreadTaskRunnerHandle::Get()->PostTask( | 171 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 180 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); | 172 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); |
| 181 } | 173 } |
| 182 | 174 |
| 183 void FakeCryptohomeClient::TpmIsEnabled( | 175 void FakeCryptohomeClient::TpmIsEnabled( |
| 184 const BoolDBusMethodCallback& callback) { | 176 const BoolDBusMethodCallback& callback) { |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 | 359 |
| 368 void FakeCryptohomeClient::TpmAttestationIsEnrolled( | 360 void FakeCryptohomeClient::TpmAttestationIsEnrolled( |
| 369 const BoolDBusMethodCallback& callback) { | 361 const BoolDBusMethodCallback& callback) { |
| 370 base::ThreadTaskRunnerHandle::Get()->PostTask( | 362 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 371 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); | 363 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true)); |
| 372 } | 364 } |
| 373 | 365 |
| 374 void FakeCryptohomeClient::AsyncTpmAttestationCreateEnrollRequest( | 366 void FakeCryptohomeClient::AsyncTpmAttestationCreateEnrollRequest( |
| 375 chromeos::attestation::PrivacyCAType pca_type, | 367 chromeos::attestation::PrivacyCAType pca_type, |
| 376 const AsyncMethodCallback& callback) { | 368 const AsyncMethodCallback& callback) { |
| 377 ReturnAsyncMethodData(callback, std::string()); | 369 ReturnAsyncMethodResult(callback, true); |
| 378 } | 370 } |
| 379 | 371 |
| 380 void FakeCryptohomeClient::AsyncTpmAttestationEnroll( | 372 void FakeCryptohomeClient::AsyncTpmAttestationEnroll( |
| 381 chromeos::attestation::PrivacyCAType pca_type, | 373 chromeos::attestation::PrivacyCAType pca_type, |
| 382 const std::string& pca_response, | 374 const std::string& pca_response, |
| 383 const AsyncMethodCallback& callback) { | 375 const AsyncMethodCallback& callback) { |
| 384 ReturnAsyncMethodResult(callback); | 376 ReturnAsyncMethodResult(callback, false); |
| 385 } | 377 } |
| 386 | 378 |
| 387 void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest( | 379 void FakeCryptohomeClient::AsyncTpmAttestationCreateCertRequest( |
| 388 chromeos::attestation::PrivacyCAType pca_type, | 380 chromeos::attestation::PrivacyCAType pca_type, |
| 389 attestation::AttestationCertificateProfile certificate_profile, | 381 attestation::AttestationCertificateProfile certificate_profile, |
| 390 const cryptohome::Identification& cryptohome_id, | 382 const cryptohome::Identification& cryptohome_id, |
| 391 const std::string& request_origin, | 383 const std::string& request_origin, |
| 392 const AsyncMethodCallback& callback) { | 384 const AsyncMethodCallback& callback) { |
| 393 ReturnAsyncMethodData(callback, std::string()); | 385 ReturnAsyncMethodResult(callback, true); |
| 394 } | 386 } |
| 395 | 387 |
| 396 void FakeCryptohomeClient::AsyncTpmAttestationFinishCertRequest( | 388 void FakeCryptohomeClient::AsyncTpmAttestationFinishCertRequest( |
| 397 const std::string& pca_response, | 389 const std::string& pca_response, |
| 398 attestation::AttestationKeyType key_type, | 390 attestation::AttestationKeyType key_type, |
| 399 const cryptohome::Identification& cryptohome_id, | 391 const cryptohome::Identification& cryptohome_id, |
| 400 const std::string& key_name, | 392 const std::string& key_name, |
| 401 const AsyncMethodCallback& callback) { | 393 const AsyncMethodCallback& callback) { |
| 402 ReturnAsyncMethodData(callback, std::string()); | 394 ReturnAsyncMethodResult(callback, true); |
| 403 } | 395 } |
| 404 | 396 |
| 405 void FakeCryptohomeClient::TpmAttestationDoesKeyExist( | 397 void FakeCryptohomeClient::TpmAttestationDoesKeyExist( |
| 406 attestation::AttestationKeyType key_type, | 398 attestation::AttestationKeyType key_type, |
| 407 const cryptohome::Identification& cryptohome_id, | 399 const cryptohome::Identification& cryptohome_id, |
| 408 const std::string& key_name, | 400 const std::string& key_name, |
| 409 const BoolDBusMethodCallback& callback) { | 401 const BoolDBusMethodCallback& callback) { |
| 410 base::ThreadTaskRunnerHandle::Get()->PostTask( | 402 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 411 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); | 403 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false)); |
| 412 } | 404 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 429 base::ThreadTaskRunnerHandle::Get()->PostTask( | 421 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 430 FROM_HERE, | 422 FROM_HERE, |
| 431 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); | 423 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); |
| 432 } | 424 } |
| 433 | 425 |
| 434 void FakeCryptohomeClient::TpmAttestationRegisterKey( | 426 void FakeCryptohomeClient::TpmAttestationRegisterKey( |
| 435 attestation::AttestationKeyType key_type, | 427 attestation::AttestationKeyType key_type, |
| 436 const cryptohome::Identification& cryptohome_id, | 428 const cryptohome::Identification& cryptohome_id, |
| 437 const std::string& key_name, | 429 const std::string& key_name, |
| 438 const AsyncMethodCallback& callback) { | 430 const AsyncMethodCallback& callback) { |
| 439 ReturnAsyncMethodData(callback, std::string()); | 431 ReturnAsyncMethodResult(callback, true); |
| 440 } | 432 } |
| 441 | 433 |
| 442 void FakeCryptohomeClient::TpmAttestationSignEnterpriseChallenge( | 434 void FakeCryptohomeClient::TpmAttestationSignEnterpriseChallenge( |
| 443 attestation::AttestationKeyType key_type, | 435 attestation::AttestationKeyType key_type, |
| 444 const cryptohome::Identification& cryptohome_id, | 436 const cryptohome::Identification& cryptohome_id, |
| 445 const std::string& key_name, | 437 const std::string& key_name, |
| 446 const std::string& domain, | 438 const std::string& domain, |
| 447 const std::string& device_id, | 439 const std::string& device_id, |
| 448 attestation::AttestationChallengeOptions options, | 440 attestation::AttestationChallengeOptions options, |
| 449 const std::string& challenge, | 441 const std::string& challenge, |
| 450 const AsyncMethodCallback& callback) { | 442 const AsyncMethodCallback& callback) { |
| 451 ReturnAsyncMethodData(callback, std::string()); | 443 ReturnAsyncMethodResult(callback, true); |
| 452 } | 444 } |
| 453 | 445 |
| 454 void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge( | 446 void FakeCryptohomeClient::TpmAttestationSignSimpleChallenge( |
| 455 attestation::AttestationKeyType key_type, | 447 attestation::AttestationKeyType key_type, |
| 456 const cryptohome::Identification& cryptohome_id, | 448 const cryptohome::Identification& cryptohome_id, |
| 457 const std::string& key_name, | 449 const std::string& key_name, |
| 458 const std::string& challenge, | 450 const std::string& challenge, |
| 459 const AsyncMethodCallback& callback) { | 451 const AsyncMethodCallback& callback) { |
| 460 chromeos::attestation::SignedData signed_data; | 452 ReturnAsyncMethodResult(callback, true); |
| 461 signed_data.set_data(challenge + kTwentyBytesNonce); | |
| 462 signed_data.set_signature(kSignature); | |
| 463 ReturnAsyncMethodData(callback, signed_data.SerializeAsString()); | |
| 464 } | 453 } |
| 465 | 454 |
| 466 void FakeCryptohomeClient::TpmAttestationGetKeyPayload( | 455 void FakeCryptohomeClient::TpmAttestationGetKeyPayload( |
| 467 attestation::AttestationKeyType key_type, | 456 attestation::AttestationKeyType key_type, |
| 468 const cryptohome::Identification& cryptohome_id, | 457 const cryptohome::Identification& cryptohome_id, |
| 469 const std::string& key_name, | 458 const std::string& key_name, |
| 470 const DataMethodCallback& callback) { | 459 const DataMethodCallback& callback) { |
| 471 base::ThreadTaskRunnerHandle::Get()->PostTask( | 460 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 472 FROM_HERE, | 461 FROM_HERE, |
| 473 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); | 462 base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, false, std::string())); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 } | 581 } |
| 593 | 582 |
| 594 void FakeCryptohomeClient::ReturnProtobufMethodCallback( | 583 void FakeCryptohomeClient::ReturnProtobufMethodCallback( |
| 595 const cryptohome::BaseReply& reply, | 584 const cryptohome::BaseReply& reply, |
| 596 const ProtobufMethodCallback& callback) { | 585 const ProtobufMethodCallback& callback) { |
| 597 base::ThreadTaskRunnerHandle::Get()->PostTask( | 586 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 598 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true, reply)); | 587 FROM_HERE, base::Bind(callback, DBUS_METHOD_CALL_SUCCESS, true, reply)); |
| 599 } | 588 } |
| 600 | 589 |
| 601 void FakeCryptohomeClient::ReturnAsyncMethodResult( | 590 void FakeCryptohomeClient::ReturnAsyncMethodResult( |
| 602 const AsyncMethodCallback& callback) { | 591 const AsyncMethodCallback& callback, |
| 592 bool returns_data) { |
| 603 base::ThreadTaskRunnerHandle::Get()->PostTask( | 593 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 604 FROM_HERE, | 594 FROM_HERE, |
| 605 base::Bind(&FakeCryptohomeClient::ReturnAsyncMethodResultInternal, | 595 base::Bind(&FakeCryptohomeClient::ReturnAsyncMethodResultInternal, |
| 606 weak_ptr_factory_.GetWeakPtr(), callback)); | 596 weak_ptr_factory_.GetWeakPtr(), callback, returns_data)); |
| 607 } | |
| 608 | |
| 609 void FakeCryptohomeClient::ReturnAsyncMethodData( | |
| 610 const AsyncMethodCallback& callback, | |
| 611 const std::string& data) { | |
| 612 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 613 FROM_HERE, | |
| 614 base::Bind(&FakeCryptohomeClient::ReturnAsyncMethodDataInternal, | |
| 615 weak_ptr_factory_.GetWeakPtr(), callback, data)); | |
| 616 } | 597 } |
| 617 | 598 |
| 618 void FakeCryptohomeClient::ReturnAsyncMethodResultInternal( | 599 void FakeCryptohomeClient::ReturnAsyncMethodResultInternal( |
| 619 const AsyncMethodCallback& callback) { | 600 const AsyncMethodCallback& callback, |
| 601 bool returns_data) { |
| 620 callback.Run(async_call_id_); | 602 callback.Run(async_call_id_); |
| 621 if (!async_call_status_handler_.is_null()) { | 603 if (!returns_data && !async_call_status_handler_.is_null()) { |
| 622 base::ThreadTaskRunnerHandle::Get()->PostTask( | 604 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 623 FROM_HERE, base::Bind(async_call_status_handler_, async_call_id_, true, | 605 FROM_HERE, base::Bind(async_call_status_handler_, async_call_id_, true, |
| 624 cryptohome::MOUNT_ERROR_NONE)); | 606 cryptohome::MOUNT_ERROR_NONE)); |
| 625 } | 607 } else if (returns_data && !async_call_status_data_handler_.is_null()) { |
| 626 ++async_call_id_; | |
| 627 } | |
| 628 | |
| 629 void FakeCryptohomeClient::ReturnAsyncMethodDataInternal( | |
| 630 const AsyncMethodCallback& callback, | |
| 631 const std::string& data) { | |
| 632 callback.Run(async_call_id_); | |
| 633 if (!async_call_status_data_handler_.is_null()) { | |
| 634 base::ThreadTaskRunnerHandle::Get()->PostTask( | 608 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 635 FROM_HERE, base::Bind(async_call_status_data_handler_, async_call_id_, | 609 FROM_HERE, base::Bind(async_call_status_data_handler_, async_call_id_, |
| 636 true, data)); | 610 true, std::string())); |
| 637 } | 611 } |
| 638 ++async_call_id_; | 612 ++async_call_id_; |
| 639 } | 613 } |
| 640 | 614 |
| 641 } // namespace chromeos | 615 } // namespace chromeos |
| OLD | NEW |