diff options
author | Luis Hector Chavez <lhchavez@google.com> | 2016-07-27 16:55:22 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-07-27 16:55:22 +0000 |
commit | f2ca567778792d1e1ac829fdd4bea4d41132c14f (patch) | |
tree | 24ea13efaa9cf9b5d7a1bff78d56d5cd84c9655a | |
parent | 238108426819c3bfb053cf520f54b48d03897072 (diff) | |
parent | d5e311423cb6d13bbeddbc6648c2bff597b4f4d8 (diff) | |
download | tpm-f2ca567778792d1e1ac829fdd4bea4d41132c14f.tar.gz |
tpm_manager/trunks: Update libchrome APIs to r405848 am: 39e701593e
am: d5e311423c
Change-Id: Iae06c20630942760e6ca6846d4a96557b94722b4
-rw-r--r-- | tpm_manager/server/binder_service_test.cc | 5 | ||||
-rw-r--r-- | tpm_manager/server/tpm_manager_service_test.cc | 130 | ||||
-rw-r--r-- | trunks/background_command_transceiver.cc | 5 | ||||
-rw-r--r-- | trunks/tpm_state_impl.cc | 16 | ||||
-rw-r--r-- | trunks/trunks_client_test.cc | 6 |
5 files changed, 90 insertions, 72 deletions
diff --git a/tpm_manager/server/binder_service_test.cc b/tpm_manager/server/binder_service_test.cc index 1415019..648f924 100644 --- a/tpm_manager/server/binder_service_test.cc +++ b/tpm_manager/server/binder_service_test.cc @@ -55,7 +55,10 @@ class BinderServiceTest : public testing::Test { base::Callback<void(const ResponseProtobufType&)> GetCallback( ResponseProtobufType* proto) { return base::Bind( - [proto](const ResponseProtobufType& response) { *proto = response; }); + [](ResponseProtobufType* proto, const ResponseProtobufType& response) { + *proto = response; + }, + base::Unretained(proto)); } protected: diff --git a/tpm_manager/server/tpm_manager_service_test.cc b/tpm_manager/server/tpm_manager_service_test.cc index cd0d0f0..f23729a 100644 --- a/tpm_manager/server/tpm_manager_service_test.cc +++ b/tpm_manager/server/tpm_manager_service_test.cc @@ -63,9 +63,12 @@ class TpmManagerServiceTest : public testing::Test { void RunServiceWorkerAndQuit() { // Run out the service worker loop by posting a new command and waiting for // the response. - auto callback = [this](const GetTpmStatusReply& reply) { Quit(); }; + auto callback = [](decltype(this) test, const GetTpmStatusReply& reply) { + test->Quit(); + }; GetTpmStatusRequest request; - service_->GetTpmStatus(request, base::Bind(callback)); + service_->GetTpmStatus(request, + base::Bind(callback, base::Unretained(this))); Run(); } @@ -120,12 +123,12 @@ TEST_F(TpmManagerServiceTest_NoWaitForOwnership, TakeOwnershipAfterAutoInitialize) { EXPECT_CALL(mock_tpm_initializer_, InitializeTpm()).Times(AtLeast(2)); SetupService(); - auto callback = [this](const TakeOwnershipReply& reply) { + auto callback = [](decltype(this) test, const TakeOwnershipReply& reply) { EXPECT_EQ(STATUS_SUCCESS, reply.status()); - Quit(); + test->Quit(); }; TakeOwnershipRequest request; - service_->TakeOwnership(request, base::Bind(callback)); + service_->TakeOwnership(request, base::Bind(callback, base::Unretained(this))); Run(); } @@ -149,7 +152,7 @@ TEST_F(TpmManagerServiceTest, GetTpmStatusSuccess) { EXPECT_CALL(mock_local_data_store_, Read(_)) .WillRepeatedly(DoAll(SetArgPointee<0>(local_data), Return(true))); - auto callback = [this](const GetTpmStatusReply& reply) { + auto callback = [](decltype(this) test, const GetTpmStatusReply& reply) { EXPECT_EQ(STATUS_SUCCESS, reply.status()); EXPECT_TRUE(reply.enabled()); EXPECT_TRUE(reply.owned()); @@ -158,16 +161,16 @@ TEST_F(TpmManagerServiceTest, GetTpmStatusSuccess) { EXPECT_EQ(6, reply.dictionary_attack_threshold()); EXPECT_TRUE(reply.dictionary_attack_lockout_in_effect()); EXPECT_EQ(7, reply.dictionary_attack_lockout_seconds_remaining()); - Quit(); + test->Quit(); }; GetTpmStatusRequest request; - service_->GetTpmStatus(request, base::Bind(callback)); + service_->GetTpmStatus(request, base::Bind(callback, base::Unretained(this))); Run(); } TEST_F(TpmManagerServiceTest, GetTpmStatusLocalDataFailure) { EXPECT_CALL(mock_local_data_store_, Read(_)).WillRepeatedly(Return(false)); - auto callback = [this](const GetTpmStatusReply& reply) { + auto callback = [](decltype(this) test, const GetTpmStatusReply& reply) { EXPECT_EQ(STATUS_SUCCESS, reply.status()); EXPECT_TRUE(reply.enabled()); EXPECT_TRUE(reply.owned()); @@ -176,10 +179,10 @@ TEST_F(TpmManagerServiceTest, GetTpmStatusLocalDataFailure) { EXPECT_TRUE(reply.has_dictionary_attack_threshold()); EXPECT_TRUE(reply.has_dictionary_attack_lockout_in_effect()); EXPECT_TRUE(reply.has_dictionary_attack_lockout_seconds_remaining()); - Quit(); + test->Quit(); }; GetTpmStatusRequest request; - service_->GetTpmStatus(request, base::Bind(callback)); + service_->GetTpmStatus(request, base::Bind(callback, base::Unretained(this))); Run(); } @@ -187,7 +190,7 @@ TEST_F(TpmManagerServiceTest, GetTpmStatusNoTpm) { EXPECT_CALL(mock_tpm_status_, IsTpmEnabled()).WillRepeatedly(Return(false)); EXPECT_CALL(mock_tpm_status_, GetDictionaryAttackInfo(_, _, _, _)) .WillRepeatedly(Return(false)); - auto callback = [this](const GetTpmStatusReply& reply) { + auto callback = [](decltype(this) test, const GetTpmStatusReply& reply) { EXPECT_EQ(STATUS_SUCCESS, reply.status()); EXPECT_FALSE(reply.enabled()); EXPECT_TRUE(reply.owned()); @@ -196,69 +199,69 @@ TEST_F(TpmManagerServiceTest, GetTpmStatusNoTpm) { EXPECT_FALSE(reply.has_dictionary_attack_threshold()); EXPECT_FALSE(reply.has_dictionary_attack_lockout_in_effect()); EXPECT_FALSE(reply.has_dictionary_attack_lockout_seconds_remaining()); - Quit(); + test->Quit(); }; GetTpmStatusRequest request; - service_->GetTpmStatus(request, base::Bind(callback)); + service_->GetTpmStatus(request, base::Bind(callback, base::Unretained(this))); Run(); } TEST_F(TpmManagerServiceTest, TakeOwnershipSuccess) { // Make sure InitializeTpm doesn't get multiple calls. EXPECT_CALL(mock_tpm_initializer_, InitializeTpm()).Times(1); - auto callback = [this](const TakeOwnershipReply& reply) { + auto callback = [](decltype(this) test, const TakeOwnershipReply& reply) { EXPECT_EQ(STATUS_SUCCESS, reply.status()); - Quit(); + test->Quit(); }; TakeOwnershipRequest request; - service_->TakeOwnership(request, base::Bind(callback)); + service_->TakeOwnership(request, base::Bind(callback, base::Unretained(this))); Run(); } TEST_F(TpmManagerServiceTest, TakeOwnershipFailure) { EXPECT_CALL(mock_tpm_initializer_, InitializeTpm()) .WillRepeatedly(Return(false)); - auto callback = [this](const TakeOwnershipReply& reply) { + auto callback = [](decltype(this) test, const TakeOwnershipReply& reply) { EXPECT_EQ(STATUS_DEVICE_ERROR, reply.status()); - Quit(); + test->Quit(); }; TakeOwnershipRequest request; - service_->TakeOwnership(request, base::Bind(callback)); + service_->TakeOwnership(request, base::Bind(callback, base::Unretained(this))); Run(); } TEST_F(TpmManagerServiceTest, TakeOwnershipNoTpm) { EXPECT_CALL(mock_tpm_status_, IsTpmEnabled()).WillRepeatedly(Return(false)); - auto callback = [this](const TakeOwnershipReply& reply) { + auto callback = [](decltype(this) test, const TakeOwnershipReply& reply) { EXPECT_EQ(STATUS_NOT_AVAILABLE, reply.status()); - Quit(); + test->Quit(); }; TakeOwnershipRequest request; - service_->TakeOwnership(request, base::Bind(callback)); + service_->TakeOwnership(request, base::Bind(callback, base::Unretained(this))); Run(); } TEST_F(TpmManagerServiceTest, RemoveOwnerDependencyReadFailure) { EXPECT_CALL(mock_local_data_store_, Read(_)).WillRepeatedly(Return(false)); - auto callback = [this](const RemoveOwnerDependencyReply& reply) { + auto callback = [](decltype(this) test, const RemoveOwnerDependencyReply& reply) { EXPECT_EQ(STATUS_DEVICE_ERROR, reply.status()); - Quit(); + test->Quit(); }; RemoveOwnerDependencyRequest request; request.set_owner_dependency(kOwnerDependency); - service_->RemoveOwnerDependency(request, base::Bind(callback)); + service_->RemoveOwnerDependency(request, base::Bind(callback, base::Unretained(this))); Run(); } TEST_F(TpmManagerServiceTest, RemoveOwnerDependencyWriteFailure) { EXPECT_CALL(mock_local_data_store_, Write(_)).WillRepeatedly(Return(false)); - auto callback = [this](const RemoveOwnerDependencyReply& reply) { + auto callback = [](decltype(this) test, const RemoveOwnerDependencyReply& reply) { EXPECT_EQ(STATUS_DEVICE_ERROR, reply.status()); - Quit(); + test->Quit(); }; RemoveOwnerDependencyRequest request; request.set_owner_dependency(kOwnerDependency); - service_->RemoveOwnerDependency(request, base::Bind(callback)); + service_->RemoveOwnerDependency(request, base::Bind(callback, base::Unretained(this))); Run(); } @@ -271,17 +274,20 @@ TEST_F(TpmManagerServiceTest, RemoveOwnerDependencyNotCleared) { .WillOnce(DoAll(SetArgPointee<0>(local_data), Return(true))); EXPECT_CALL(mock_local_data_store_, Write(_)) .WillOnce(DoAll(SaveArg<0>(&local_data), Return(true))); - auto callback = [this, &local_data](const RemoveOwnerDependencyReply& reply) { + auto callback = [](decltype(this) test, LocalData* local_data, + const RemoveOwnerDependencyReply& reply) { EXPECT_EQ(STATUS_SUCCESS, reply.status()); - EXPECT_EQ(1, local_data.owner_dependency_size()); - EXPECT_EQ(kOtherDependency, local_data.owner_dependency(0)); - EXPECT_TRUE(local_data.has_owner_password()); - EXPECT_EQ(kOwnerPassword, local_data.owner_password()); - Quit(); + EXPECT_EQ(1, local_data->owner_dependency_size()); + EXPECT_EQ(kOtherDependency, local_data->owner_dependency(0)); + EXPECT_TRUE(local_data->has_owner_password()); + EXPECT_EQ(kOwnerPassword, local_data->owner_password()); + test->Quit(); }; RemoveOwnerDependencyRequest request; request.set_owner_dependency(kOwnerDependency); - service_->RemoveOwnerDependency(request, base::Bind(callback)); + service_->RemoveOwnerDependency(request, + base::Bind(callback, base::Unretained(this), + base::Unretained(&local_data))); Run(); } @@ -293,15 +299,18 @@ TEST_F(TpmManagerServiceTest, RemoveOwnerDependencyCleared) { .WillOnce(DoAll(SetArgPointee<0>(local_data), Return(true))); EXPECT_CALL(mock_local_data_store_, Write(_)) .WillOnce(DoAll(SaveArg<0>(&local_data), Return(true))); - auto callback = [this, &local_data](const RemoveOwnerDependencyReply& reply) { + auto callback = [](decltype(this) test, LocalData* local_data, + const RemoveOwnerDependencyReply& reply) { EXPECT_EQ(STATUS_SUCCESS, reply.status()); - EXPECT_EQ(0, local_data.owner_dependency_size()); - EXPECT_FALSE(local_data.has_owner_password()); - Quit(); + EXPECT_EQ(0, local_data->owner_dependency_size()); + EXPECT_FALSE(local_data->has_owner_password()); + test->Quit(); }; RemoveOwnerDependencyRequest request; request.set_owner_dependency(kOwnerDependency); - service_->RemoveOwnerDependency(request, base::Bind(callback)); + service_->RemoveOwnerDependency(request, + base::Bind(callback, base::Unretained(this), + base::Unretained(&local_data))); Run(); } @@ -313,17 +322,19 @@ TEST_F(TpmManagerServiceTest, RemoveOwnerDependencyNotPresent) { .WillOnce(DoAll(SetArgPointee<0>(local_data), Return(true))); EXPECT_CALL(mock_local_data_store_, Write(_)) .WillOnce(DoAll(SaveArg<0>(&local_data), Return(true))); - auto callback = [this, &local_data](const RemoveOwnerDependencyReply& reply) { + auto callback = [](decltype(this) test, const LocalData& local_data, + const RemoveOwnerDependencyReply& reply) { EXPECT_EQ(STATUS_SUCCESS, reply.status()); EXPECT_EQ(1, local_data.owner_dependency_size()); EXPECT_EQ(kOwnerDependency, local_data.owner_dependency(0)); EXPECT_TRUE(local_data.has_owner_password()); EXPECT_EQ(kOwnerPassword, local_data.owner_password()); - Quit(); + test->Quit(); }; RemoveOwnerDependencyRequest request; request.set_owner_dependency(kOtherDependency); - service_->RemoveOwnerDependency(request, base::Bind(callback)); + service_->RemoveOwnerDependency( + request, base::Bind(callback, base::Unretained(this), local_data)); Run(); } @@ -336,9 +347,9 @@ TEST_F(TpmManagerServiceTest, DefineSpaceFailure) { EXPECT_CALL(mock_tpm_nvram_, DefineSpace(nvram_index, nvram_size, attributes, auth_value, policy)) .WillRepeatedly(Return(NVRAM_RESULT_INVALID_PARAMETER)); - auto callback = [this](const DefineSpaceReply& reply) { + auto callback = [](decltype(this) test, const DefineSpaceReply& reply) { EXPECT_EQ(NVRAM_RESULT_INVALID_PARAMETER, reply.result()); - Quit(); + test->Quit(); }; DefineSpaceRequest request; request.set_index(nvram_index); @@ -346,7 +357,7 @@ TEST_F(TpmManagerServiceTest, DefineSpaceFailure) { request.add_attributes(NVRAM_BOOT_WRITE_LOCK); request.set_policy(policy); request.set_authorization_value(auth_value); - service_->DefineSpace(request, base::Bind(callback)); + service_->DefineSpace(request, base::Bind(callback, base::Unretained(this))); Run(); } @@ -356,12 +367,12 @@ TEST_F(TpmManagerServiceTest, DefineSpaceSuccess) { auto define_callback = [](const DefineSpaceReply& reply) { EXPECT_EQ(NVRAM_RESULT_SUCCESS, reply.result()); }; - auto list_callback = [nvram_index](const ListSpacesReply& reply) { + auto list_callback = [](uint32_t nvram_index, const ListSpacesReply& reply) { EXPECT_EQ(NVRAM_RESULT_SUCCESS, reply.result()); EXPECT_EQ(1, reply.index_list_size()); EXPECT_EQ(nvram_index, reply.index_list(0)); }; - auto info_callback = [nvram_size](const GetSpaceInfoReply& reply) { + auto info_callback = [](uint32_t nvram_size, const GetSpaceInfoReply& reply) { EXPECT_EQ(NVRAM_RESULT_SUCCESS, reply.result()); EXPECT_EQ(nvram_size, reply.size()); }; @@ -370,20 +381,20 @@ TEST_F(TpmManagerServiceTest, DefineSpaceSuccess) { define_request.set_size(nvram_size); service_->DefineSpace(define_request, base::Bind(define_callback)); ListSpacesRequest list_request; - service_->ListSpaces(list_request, base::Bind(list_callback)); + service_->ListSpaces(list_request, base::Bind(list_callback, nvram_index)); GetSpaceInfoRequest info_request; info_request.set_index(nvram_index); - service_->GetSpaceInfo(info_request, base::Bind(info_callback)); + service_->GetSpaceInfo(info_request, base::Bind(info_callback, nvram_size)); RunServiceWorkerAndQuit(); } TEST_F(TpmManagerServiceTest, DestroyUnitializedNvram) { - auto callback = [this](const DestroySpaceReply& reply) { + auto callback = [](decltype(this) test, const DestroySpaceReply& reply) { EXPECT_EQ(NVRAM_RESULT_SPACE_DOES_NOT_EXIST, reply.result()); - Quit(); + test->Quit(); }; DestroySpaceRequest request; - service_->DestroySpace(request, base::Bind(callback)); + service_->DestroySpace(request, base::Bind(callback, base::Unretained(this))); Run(); } @@ -481,12 +492,12 @@ TEST_F(TpmManagerServiceTest, WriteBeforeAfterLock) { } TEST_F(TpmManagerServiceTest, ReadUninitializedNvram) { - auto callback = [this](const ReadSpaceReply& reply) { + auto callback = [](decltype(this) test, const ReadSpaceReply& reply) { EXPECT_EQ(NVRAM_RESULT_SPACE_DOES_NOT_EXIST, reply.result()); - Quit(); + test->Quit(); }; ReadSpaceRequest request; - service_->ReadSpace(request, base::Bind(callback)); + service_->ReadSpace(request, base::Bind(callback, base::Unretained(this))); Run(); } @@ -499,7 +510,8 @@ TEST_F(TpmManagerServiceTest, ReadWriteSpaceSuccess) { auto write_callback = [](const WriteSpaceReply& reply) { EXPECT_EQ(NVRAM_RESULT_SUCCESS, reply.result()); }; - auto read_callback = [nvram_data](const ReadSpaceReply& reply) { + auto read_callback = [](const std::string& nvram_data, + const ReadSpaceReply& reply) { EXPECT_EQ(NVRAM_RESULT_SUCCESS, reply.result()); EXPECT_EQ(nvram_data, reply.data()); }; @@ -513,7 +525,7 @@ TEST_F(TpmManagerServiceTest, ReadWriteSpaceSuccess) { service_->WriteSpace(write_request, base::Bind(write_callback)); ReadSpaceRequest read_request; read_request.set_index(nvram_index); - service_->ReadSpace(read_request, base::Bind(read_callback)); + service_->ReadSpace(read_request, base::Bind(read_callback, nvram_data)); RunServiceWorkerAndQuit(); } diff --git a/trunks/background_command_transceiver.cc b/trunks/background_command_transceiver.cc index 4a62e7d..51858ca 100644 --- a/trunks/background_command_transceiver.cc +++ b/trunks/background_command_transceiver.cc @@ -78,8 +78,9 @@ std::string BackgroundCommandTransceiver::SendCommandAndWait( const std::string& command) { if (task_runner_.get()) { std::string response; - base::WaitableEvent response_ready(true, // manual_reset - false); // initially_signaled + base::WaitableEvent response_ready( + base::WaitableEvent::ResetPolicy::MANUAL, + base::WaitableEvent::InitialState::NOT_SIGNALED); ResponseCallback callback = base::Bind(&AssignAndSignal, &response, &response_ready); // Use SendCommandTask instead of binding to next_transceiver_ directly to diff --git a/trunks/tpm_state_impl.cc b/trunks/tpm_state_impl.cc index e453cae..358f3e2 100644 --- a/trunks/tpm_state_impl.cc +++ b/trunks/tpm_state_impl.cc @@ -224,8 +224,8 @@ TPM_RC TpmStateImpl::GetCapability(const CapabilityCallback& callback, } TPM_RC TpmStateImpl::CacheTpmProperties() { - CapabilityCallback callback = - base::Bind([this](const TPMU_CAPABILITIES& capability_data) { + CapabilityCallback callback = base::Bind( + [](TpmStateImpl* impl, const TPMU_CAPABILITIES& capability_data) { uint32_t next_property = 0; for (uint32_t i = 0; i < capability_data.tpm_properties.count && i < MAX_TPM_PROPERTIES; @@ -234,11 +234,11 @@ TPM_RC TpmStateImpl::CacheTpmProperties() { capability_data.tpm_properties.tpm_property[i]; VLOG(1) << "TPM Property 0x" << std::hex << property.property << " = 0x" << property.value; - tpm_properties_[property.property] = property.value; + impl->tpm_properties_[property.property] = property.value; next_property = property.property + 1; } return next_property; - }); + }, base::Unretained(this)); if (tpm_properties_.empty()) { TPM_RC result = GetCapability(callback, TPM_CAP_TPM_PROPERTIES, PT_FIXED, MAX_TPM_PROPERTIES); @@ -251,8 +251,8 @@ TPM_RC TpmStateImpl::CacheTpmProperties() { } TPM_RC TpmStateImpl::CacheAlgorithmProperties() { - CapabilityCallback callback = - base::Bind([this](const TPMU_CAPABILITIES& capability_data) { + CapabilityCallback callback = base::Bind( + [](TpmStateImpl* impl, const TPMU_CAPABILITIES& capability_data) { uint32_t next_property = 0; for (uint32_t i = 0; i < capability_data.algorithms.count && i < MAX_CAP_ALGS; ++i) { @@ -260,11 +260,11 @@ TPM_RC TpmStateImpl::CacheAlgorithmProperties() { capability_data.algorithms.alg_properties[i]; VLOG(1) << "Algorithm Properties 0x" << std::hex << property.alg << " = 0x" << property.alg_properties; - algorithm_properties_[property.alg] = property.alg_properties; + impl->algorithm_properties_[property.alg] = property.alg_properties; next_property = property.alg + 1; } return next_property; - }); + }, base::Unretained(this)); if (algorithm_properties_.empty()) { return GetCapability(callback, TPM_CAP_ALGS, TPM_ALG_FIRST, MAX_CAP_ALGS); } diff --git a/trunks/trunks_client_test.cc b/trunks/trunks_client_test.cc index 74b4305..371e16c 100644 --- a/trunks/trunks_client_test.cc +++ b/trunks/trunks_client_test.cc @@ -832,7 +832,8 @@ bool TrunksClientTest::NvramTest(const std::string& owner_password) { return false; } // Setup auto-cleanup of the NVRAM space. - auto cleanup = [&session, &owner_password, &utility, index]() { + auto cleanup = [](HmacSession* session, const std::string& owner_password, + TpmUtility* utility, uint32_t index) { session->SetEntityAuthorizationValue(owner_password); TPM_RC result = utility->DestroyNVSpace(index, session->GetDelegate()); if (result != TPM_RC_SUCCESS) { @@ -851,7 +852,8 @@ bool TrunksClientTest::NvramTest(const std::string& owner_password) { private: base::Closure callback_; bool cancel_ = false; - } scoper(base::Bind(cleanup)); + } scoper(base::Bind(cleanup, base::Unretained(session.get()), owner_password, + base::Unretained(utility.get()), index)); session->SetEntityAuthorizationValue(owner_password); result = utility->WriteNVSpace(index, 0, nv_data, true /*owner*/, |