Commit df4f0d59 authored by Leo Lai's avatar Leo Lai Committed by Chromium LUCI CQ

TpmChallengeKeySubtleImpl use TpmManagerClient to check status.

we are migrating tpm status calls to TpmManagerClient.

BUG=b:172748724
TEST=unit_tests.

Change-Id: I8638acb35dc21e2a1103d377fd9c4b328383a25e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2579934Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Commit-Queue: Leo Lai <cylai@google.com>
Cr-Commit-Position: refs/heads/master@{#835570}
parent cbc28ee2
......@@ -28,7 +28,8 @@
#include "chromeos/dbus/attestation/attestation_client.h"
#include "chromeos/dbus/attestation/interface.pb.h"
#include "chromeos/dbus/constants/attestation_constants.h"
#include "chromeos/dbus/cryptohome/cryptohome_client.h"
#include "chromeos/dbus/tpm_manager/tpm_manager.pb.h"
#include "chromeos/dbus/tpm_manager/tpm_manager_client.h"
#include "chromeos/settings/cros_settings_names.h"
#include "chromeos/tpm/install_attributes.h"
#include "components/pref_registry/pref_registry_syncable.h"
......@@ -418,9 +419,11 @@ void TpmChallengeKeySubtleImpl::GetEnrollmentPreparationsCallback(
}
if (!AttestationClient::IsAttestationPrepared(reply)) {
CryptohomeClient::Get()->TpmIsEnabled(base::BindOnce(
&TpmChallengeKeySubtleImpl::PrepareKeyErrorHandlerCallback,
weak_factory_.GetWeakPtr()));
TpmManagerClient::Get()->GetTpmNonsensitiveStatus(
::tpm_manager::GetTpmNonsensitiveStatusRequest(),
base::BindOnce(
&TpmChallengeKeySubtleImpl::PrepareKeyErrorHandlerCallback,
weak_factory_.GetWeakPtr()));
return;
}
......@@ -433,15 +436,16 @@ void TpmChallengeKeySubtleImpl::GetEnrollmentPreparationsCallback(
}
void TpmChallengeKeySubtleImpl::PrepareKeyErrorHandlerCallback(
base::Optional<bool> is_tpm_enabled) {
const ::tpm_manager::GetTpmNonsensitiveStatusReply& reply) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!is_tpm_enabled.has_value()) {
if (reply.status() != ::tpm_manager::STATUS_SUCCESS) {
LOG(ERROR) << "Failed to get TPM status; status: " << reply.status();
std::move(callback_).Run(Result::MakeError(ResultCode::kDbusError));
return;
}
if (is_tpm_enabled.value()) {
if (reply.is_enabled()) {
std::move(callback_).Run(
Result::MakeError(ResultCode::kResetRequiredError));
} else {
......
......@@ -19,7 +19,7 @@
#include "chromeos/dbus/attestation/attestation_client.h"
#include "chromeos/dbus/attestation/interface.pb.h"
#include "chromeos/dbus/constants/attestation_constants.h"
#include "chromeos/dbus/cryptohome/cryptohome_client.h"
#include "chromeos/dbus/tpm_manager/tpm_manager.pb.h"
#include "components/account_id/account_id.h"
#include "components/user_manager/user.h"
......@@ -204,7 +204,8 @@ class TpmChallengeKeySubtleImpl final : public TpmChallengeKeySubtle {
void GetEnrollmentPreparationsCallback(
const ::attestation::GetEnrollmentPreparationsReply& reply);
void PrepareKeyErrorHandlerCallback(base::Optional<bool> is_tpm_enabled);
void PrepareKeyErrorHandlerCallback(
const ::tpm_manager::GetTpmNonsensitiveStatusReply& reply);
void DoesKeyExistCallback(const ::attestation::GetKeyInfoReply& reply);
void AskForUserConsent(base::OnceCallback<void(bool)> callback) const;
void AskForUserConsentCallback(bool result);
......
......@@ -29,6 +29,7 @@
#include "chromeos/dbus/attestation/interface.pb.h"
#include "chromeos/dbus/constants/attestation_constants.h"
#include "chromeos/dbus/cryptohome/fake_cryptohome_client.h"
#include "chromeos/dbus/tpm_manager/tpm_manager_client.h"
#include "components/prefs/pref_service.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/test/browser_task_environment.h"
......@@ -207,6 +208,7 @@ class TpmChallengeKeySubtleTest : public ::testing::Test {
TpmChallengeKeySubtleTest::TpmChallengeKeySubtleTest()
: testing_profile_manager_(TestingBrowserProcess::GetGlobal()) {
::chromeos::TpmManagerClient::InitializeFake();
::chromeos::AttestationClient::InitializeFake();
CHECK(testing_profile_manager_.SetUp());
......@@ -220,6 +222,7 @@ TpmChallengeKeySubtleTest::TpmChallengeKeySubtleTest()
TpmChallengeKeySubtleTest::~TpmChallengeKeySubtleTest() {
::chromeos::AttestationClient::Shutdown();
::chromeos::TpmManagerClient::Shutdown();
}
void TpmChallengeKeySubtleTest::InitSigninProfile() {
......@@ -472,7 +475,10 @@ TEST_F(TpmChallengeKeySubtleTest, AttestationUnsupported) {
chromeos::AttestationClient::Get()
->GetTestInterface()
->ConfigureEnrollmentPreparations(false);
cryptohome_client_.set_tpm_is_enabled(false);
chromeos::TpmManagerClient::Get()
->GetTestInterface()
->mutable_nonsensitive_status_reply()
->set_is_enabled(false);
RunOneStepAndExpect(
KEY_DEVICE, /*will_register_key=*/false, kEmptyKeyName,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment