Commit 00a566f5 authored by Leo Lai's avatar Leo Lai Committed by Commit Bot

use AttestationClient for enrollment status

We are deprecating attestation methods by CryptohomeClient.

BUG=b:158955123
TEST=unit_tests and browser_tests.

Change-Id: Ib7662537bce5f1b833de91ebfb189d5d71f8c3d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2467638
Commit-Queue: Leo Lai <cylai@google.com>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821609}
parent f3a2c2f8
...@@ -123,25 +123,29 @@ void AttestationFlow::GetCertificate( ...@@ -123,25 +123,29 @@ void AttestationFlow::GetCertificate(
// If this device has not enrolled with the Privacy CA, we need to do that // If this device has not enrolled with the Privacy CA, we need to do that
// first. Once enrolled we can proceed with the certificate request. // first. Once enrolled we can proceed with the certificate request.
cryptohome_client_->TpmAttestationIsEnrolled(base::BindOnce( attestation_client_->GetStatus(
&AttestationFlow::OnEnrollmentCheckComplete, weak_factory_.GetWeakPtr(), ::attestation::GetStatusRequest(),
std::move(start_certificate_request))); base::BindOnce(&AttestationFlow::OnEnrollmentCheckComplete,
weak_factory_.GetWeakPtr(),
std::move(start_certificate_request)));
} }
void AttestationFlow::OnEnrollmentCheckComplete( void AttestationFlow::OnEnrollmentCheckComplete(
base::OnceCallback<void(bool)> callback, base::OnceCallback<void(bool)> callback,
base::Optional<bool> result) { const ::attestation::GetStatusReply& reply) {
if (!result) { if (reply.status() != ::attestation::STATUS_SUCCESS) {
LOG(ERROR) << "Attestation: Failed to check enrollment state."; LOG(ERROR) << "Attestation: Failed to check enrollment state. Status: "
<< reply.status();
std::move(callback).Run(false); std::move(callback).Run(false);
return; return;
} }
if (*result) { if (reply.enrolled()) {
std::move(callback).Run(true); std::move(callback).Run(true);
return; return;
} }
// The device is not enrolled; check if it's enrollment prepared.
base::TimeTicks end_time = base::TimeTicks::Now() + ready_timeout_; base::TimeTicks end_time = base::TimeTicks::Now() + ready_timeout_;
WaitForAttestationPrepared(end_time, std::move(callback)); WaitForAttestationPrepared(end_time, std::move(callback));
} }
......
...@@ -126,14 +126,14 @@ class COMPONENT_EXPORT(CHROMEOS_ATTESTATION) AttestationFlow { ...@@ -126,14 +126,14 @@ class COMPONENT_EXPORT(CHROMEOS_ATTESTATION) AttestationFlow {
CertificateCallback callback); CertificateCallback callback);
private: private:
// Handles the result of a call to TpmAttestationIsEnrolled. Reports success // Handles the result of a call to `GetStatus()` for enrollment status.
// if enrollment is complete and otherwise starts the process. // Reports success if enrollment is complete and otherwise starts the process.
// //
// Parameters // Parameters
// callback - Called with the success or failure of the enrollment. // callback - Called with the success or failure of the enrollment.
// result - Result of TpmAttestationIsEnrolled(). // result - Result of `GetStatus()`, which contains `enrolled` field.
void OnEnrollmentCheckComplete(base::OnceCallback<void(bool)> callback, void OnEnrollmentCheckComplete(base::OnceCallback<void(bool)> callback,
base::Optional<bool> result); const ::attestation::GetStatusReply& reply);
// Asynchronously waits for attestation to be ready and start enrollment once // Asynchronously waits for attestation to be ready and start enrollment once
// it is. If attestation is not ready by the time the flow's timeout is // it is. If attestation is not ready by the time the flow's timeout is
......
...@@ -78,9 +78,13 @@ TEST_F(AttestationFlowTest, GetCertificate) { ...@@ -78,9 +78,13 @@ TEST_F(AttestationFlowTest, GetCertificate) {
// Verify the order of calls in a sequence. // Verify the order of calls in a sequence.
Sequence flow_order; Sequence flow_order;
// Use DBusCallbackFalse so the full enrollment flow is triggered. FakeCryptohomeClient client;
chromeos::FakeCryptohomeClient client; // Set the enrollment status as `false` so the full enrollment flow is
client.set_tpm_attestation_is_enrolled(false); // triggered.
chromeos::AttestationClient::Get()
->GetTestInterface()
->mutable_status_reply()
->set_enrolled(false);
chromeos::AttestationClient::Get() chromeos::AttestationClient::Get()
->GetTestInterface() ->GetTestInterface()
->ConfigureEnrollmentPreparations(true); ->ConfigureEnrollmentPreparations(true);
...@@ -166,9 +170,12 @@ TEST_F(AttestationFlowTest, GetCertificate_Ecc) { ...@@ -166,9 +170,12 @@ TEST_F(AttestationFlowTest, GetCertificate_Ecc) {
Sequence flow_order; Sequence flow_order;
FakeCryptohomeClient client; FakeCryptohomeClient client;
// Set the enrollment status as |false| so the full enrollment flow is // Set the enrollment status as `false` so the full enrollment flow is
// triggered. // triggered.
client.set_tpm_attestation_is_enrolled(false); chromeos::AttestationClient::Get()
->GetTestInterface()
->mutable_status_reply()
->set_enrolled(false);
chromeos::AttestationClient::Get() chromeos::AttestationClient::Get()
->GetTestInterface() ->GetTestInterface()
->ConfigureEnrollmentPreparations(true); ->ConfigureEnrollmentPreparations(true);
...@@ -253,7 +260,10 @@ TEST_F(AttestationFlowTest, GetCertificate_Attestation_Not_Prepared) { ...@@ -253,7 +260,10 @@ TEST_F(AttestationFlowTest, GetCertificate_Attestation_Not_Prepared) {
Sequence flow_order; Sequence flow_order;
FakeCryptohomeClient client; FakeCryptohomeClient client;
client.set_tpm_attestation_is_enrolled(false); chromeos::AttestationClient::Get()
->GetTestInterface()
->mutable_status_reply()
->set_enrolled(false);
chromeos::AttestationClient::Get() chromeos::AttestationClient::Get()
->GetTestInterface() ->GetTestInterface()
->ConfigureEnrollmentPreparationsSequence({false, true}); ->ConfigureEnrollmentPreparationsSequence({false, true});
...@@ -340,7 +350,10 @@ TEST_F(AttestationFlowTest, GetCertificate_Attestation_Never_Prepared) { ...@@ -340,7 +350,10 @@ TEST_F(AttestationFlowTest, GetCertificate_Attestation_Never_Prepared) {
async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE);
chromeos::FakeCryptohomeClient client; chromeos::FakeCryptohomeClient client;
client.set_tpm_attestation_is_enrolled(false); chromeos::AttestationClient::Get()
->GetTestInterface()
->mutable_status_reply()
->set_enrolled(false);
chromeos::AttestationClient::Get() chromeos::AttestationClient::Get()
->GetTestInterface() ->GetTestInterface()
->ConfigureEnrollmentPreparations(false); ->ConfigureEnrollmentPreparations(false);
...@@ -375,7 +388,10 @@ TEST_F(AttestationFlowTest, GetCertificate_Attestation_Never_Confirm_Prepared) { ...@@ -375,7 +388,10 @@ TEST_F(AttestationFlowTest, GetCertificate_Attestation_Never_Confirm_Prepared) {
async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE);
chromeos::FakeCryptohomeClient client; chromeos::FakeCryptohomeClient client;
client.set_tpm_attestation_is_enrolled(false); chromeos::AttestationClient::Get()
->GetTestInterface()
->mutable_status_reply()
->set_enrolled(false);
chromeos::AttestationClient::Get() chromeos::AttestationClient::Get()
->GetTestInterface() ->GetTestInterface()
->ConfigureEnrollmentPreparationsStatus( ->ConfigureEnrollmentPreparationsStatus(
...@@ -413,7 +429,10 @@ TEST_F(AttestationFlowTest, GetCertificate_NoEK) { ...@@ -413,7 +429,10 @@ TEST_F(AttestationFlowTest, GetCertificate_NoEK) {
.Times(1); .Times(1);
chromeos::FakeCryptohomeClient client; chromeos::FakeCryptohomeClient client;
client.set_tpm_attestation_is_enrolled(false); chromeos::AttestationClient::Get()
->GetTestInterface()
->mutable_status_reply()
->set_enrolled(false);
chromeos::AttestationClient::Get() chromeos::AttestationClient::Get()
->GetTestInterface() ->GetTestInterface()
->ConfigureEnrollmentPreparations(true); ->ConfigureEnrollmentPreparations(true);
...@@ -444,7 +463,10 @@ TEST_F(AttestationFlowTest, GetCertificate_EKRejected) { ...@@ -444,7 +463,10 @@ TEST_F(AttestationFlowTest, GetCertificate_EKRejected) {
.Times(1); .Times(1);
chromeos::FakeCryptohomeClient client; chromeos::FakeCryptohomeClient client;
client.set_tpm_attestation_is_enrolled(false); chromeos::AttestationClient::Get()
->GetTestInterface()
->mutable_status_reply()
->set_enrolled(false);
chromeos::AttestationClient::Get() chromeos::AttestationClient::Get()
->GetTestInterface() ->GetTestInterface()
->ConfigureEnrollmentPreparations(true); ->ConfigureEnrollmentPreparations(true);
...@@ -486,7 +508,10 @@ TEST_F(AttestationFlowTest, GetCertificate_FailEnroll) { ...@@ -486,7 +508,10 @@ TEST_F(AttestationFlowTest, GetCertificate_FailEnroll) {
.WillOnce(WithArgs<2>(Invoke(AsyncCallbackFalse))); .WillOnce(WithArgs<2>(Invoke(AsyncCallbackFalse)));
chromeos::FakeCryptohomeClient client; chromeos::FakeCryptohomeClient client;
client.set_tpm_attestation_is_enrolled(false); chromeos::AttestationClient::Get()
->GetTestInterface()
->mutable_status_reply()
->set_enrolled(false);
chromeos::AttestationClient::Get() chromeos::AttestationClient::Get()
->GetTestInterface() ->GetTestInterface()
->ConfigureEnrollmentPreparations(true); ->ConfigureEnrollmentPreparations(true);
...@@ -516,6 +541,10 @@ TEST_F(AttestationFlowTest, GetCertificate_FailEnroll) { ...@@ -516,6 +541,10 @@ TEST_F(AttestationFlowTest, GetCertificate_FailEnroll) {
} }
TEST_F(AttestationFlowTest, GetMachineCertificateAlreadyEnrolled) { TEST_F(AttestationFlowTest, GetMachineCertificateAlreadyEnrolled) {
chromeos::AttestationClient::Get()
->GetTestInterface()
->mutable_status_reply()
->set_enrolled(true);
StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
...@@ -569,6 +598,10 @@ TEST_F(AttestationFlowTest, GetMachineCertificateAlreadyEnrolled) { ...@@ -569,6 +598,10 @@ TEST_F(AttestationFlowTest, GetMachineCertificateAlreadyEnrolled) {
} }
TEST_F(AttestationFlowTest, GetEnrollmentCertificateAlreadyEnrolled) { TEST_F(AttestationFlowTest, GetEnrollmentCertificateAlreadyEnrolled) {
chromeos::AttestationClient::Get()
->GetTestInterface()
->mutable_status_reply()
->set_enrolled(true);
StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
chromeos::AttestationClient::Get() chromeos::AttestationClient::Get()
...@@ -621,6 +654,10 @@ TEST_F(AttestationFlowTest, GetEnrollmentCertificateAlreadyEnrolled) { ...@@ -621,6 +654,10 @@ TEST_F(AttestationFlowTest, GetEnrollmentCertificateAlreadyEnrolled) {
} }
TEST_F(AttestationFlowTest, GetCertificate_FailCreateCertRequest) { TEST_F(AttestationFlowTest, GetCertificate_FailCreateCertRequest) {
chromeos::AttestationClient::Get()
->GetTestInterface()
->mutable_status_reply()
->set_enrolled(true);
StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE); async_caller.SetUp(false, cryptohome::MOUNT_ERROR_NONE);
chromeos::AttestationClient::Get() chromeos::AttestationClient::Get()
...@@ -656,6 +693,10 @@ TEST_F(AttestationFlowTest, GetCertificate_FailCreateCertRequest) { ...@@ -656,6 +693,10 @@ TEST_F(AttestationFlowTest, GetCertificate_FailCreateCertRequest) {
} }
TEST_F(AttestationFlowTest, GetCertificate_CertRequestRejected) { TEST_F(AttestationFlowTest, GetCertificate_CertRequestRejected) {
chromeos::AttestationClient::Get()
->GetTestInterface()
->mutable_status_reply()
->set_enrolled(true);
StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
chromeos::FakeCryptohomeClient client; chromeos::FakeCryptohomeClient client;
...@@ -696,6 +737,10 @@ TEST_F(AttestationFlowTest, GetCertificate_CertRequestRejected) { ...@@ -696,6 +737,10 @@ TEST_F(AttestationFlowTest, GetCertificate_CertRequestRejected) {
} }
TEST_F(AttestationFlowTest, GetCertificate_CertRequestBadRequest) { TEST_F(AttestationFlowTest, GetCertificate_CertRequestBadRequest) {
chromeos::AttestationClient::Get()
->GetTestInterface()
->mutable_status_reply()
->set_enrolled(true);
StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
...@@ -748,7 +793,10 @@ TEST_F(AttestationFlowTest, GetCertificate_FailIsEnrolled) { ...@@ -748,7 +793,10 @@ TEST_F(AttestationFlowTest, GetCertificate_FailIsEnrolled) {
StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
chromeos::FakeCryptohomeClient client; chromeos::FakeCryptohomeClient client;
client.SetServiceIsAvailable(false); chromeos::AttestationClient::Get()
->GetTestInterface()
->mutable_status_reply()
->set_status(::attestation::STATUS_DBUS_ERROR);
// We're not expecting any server calls in this case; StrictMock will verify. // We're not expecting any server calls in this case; StrictMock will verify.
std::unique_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>()); std::unique_ptr<MockServerProxy> proxy(new StrictMock<MockServerProxy>());
...@@ -770,6 +818,10 @@ TEST_F(AttestationFlowTest, GetCertificate_FailIsEnrolled) { ...@@ -770,6 +818,10 @@ TEST_F(AttestationFlowTest, GetCertificate_FailIsEnrolled) {
} }
TEST_F(AttestationFlowTest, GetCertificate_CheckExisting) { TEST_F(AttestationFlowTest, GetCertificate_CheckExisting) {
chromeos::AttestationClient::Get()
->GetTestInterface()
->mutable_status_reply()
->set_enrolled(true);
StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE); async_caller.SetUp(true, cryptohome::MOUNT_ERROR_NONE);
chromeos::AttestationClient::Get() chromeos::AttestationClient::Get()
...@@ -821,6 +873,10 @@ TEST_F(AttestationFlowTest, GetCertificate_CheckExisting) { ...@@ -821,6 +873,10 @@ TEST_F(AttestationFlowTest, GetCertificate_CheckExisting) {
} }
TEST_F(AttestationFlowTest, GetCertificate_AlreadyExists) { TEST_F(AttestationFlowTest, GetCertificate_AlreadyExists) {
chromeos::AttestationClient::Get()
->GetTestInterface()
->mutable_status_reply()
->set_enrolled(true);
// We're not expecting any async calls in this case; StrictMock will verify. // We're not expecting any async calls in this case; StrictMock will verify.
StrictMock<cryptohome::MockAsyncMethodCaller> async_caller; StrictMock<cryptohome::MockAsyncMethodCaller> async_caller;
......
...@@ -92,6 +92,9 @@ class COMPONENT_EXPORT(CHROMEOS_DBUS_ATTESTATION) AttestationClient { ...@@ -92,6 +92,9 @@ class COMPONENT_EXPORT(CHROMEOS_DBUS_ATTESTATION) AttestationClient {
virtual void ConfigureEnrollmentPreparationsStatus( virtual void ConfigureEnrollmentPreparationsStatus(
::attestation::AttestationStatus status) = 0; ::attestation::AttestationStatus status) = 0;
// Gets the mutable |GetStatusReply| that is returned when queried.
virtual ::attestation::GetStatusReply* mutable_status_reply() = 0;
// Allowlists |request| so the certificate requests that comes in afterwards // Allowlists |request| so the certificate requests that comes in afterwards
// will get a fake certificate. If any alias of |request| has been // will get a fake certificate. If any alias of |request| has been
// allowlisted this functions performs no-ops. // allowlisted this functions performs no-ops.
......
...@@ -45,7 +45,9 @@ bool GetCertificateRequestEqual(::attestation::GetCertificateRequest r1, ...@@ -45,7 +45,9 @@ bool GetCertificateRequestEqual(::attestation::GetCertificateRequest r1,
} // namespace } // namespace
FakeAttestationClient::FakeAttestationClient() = default; FakeAttestationClient::FakeAttestationClient() {
status_reply_.set_enrolled(true);
}
FakeAttestationClient::~FakeAttestationClient() = default; FakeAttestationClient::~FakeAttestationClient() = default;
...@@ -143,7 +145,7 @@ void FakeAttestationClient::GetEnrollmentPreparations( ...@@ -143,7 +145,7 @@ void FakeAttestationClient::GetEnrollmentPreparations(
void FakeAttestationClient::GetStatus( void FakeAttestationClient::GetStatus(
const ::attestation::GetStatusRequest& request, const ::attestation::GetStatusRequest& request,
GetStatusCallback callback) { GetStatusCallback callback) {
NOTIMPLEMENTED(); PostProtoResponse(std::move(callback), status_reply_);
} }
void FakeAttestationClient::Verify(const ::attestation::VerifyRequest& request, void FakeAttestationClient::Verify(const ::attestation::VerifyRequest& request,
...@@ -198,8 +200,10 @@ void FakeAttestationClient::GetCertificate( ...@@ -198,8 +200,10 @@ void FakeAttestationClient::GetCertificate(
reply.set_status( reply.set_status(
::attestation::AttestationStatus::STATUS_UNEXPECTED_DEVICE_ERROR); ::attestation::AttestationStatus::STATUS_UNEXPECTED_DEVICE_ERROR);
is_enrolled_ |= request.shall_trigger_enrollment(); if (request.shall_trigger_enrollment()) {
if (!is_enrolled_) { status_reply_.set_enrolled(true);
}
if (!status_reply_.enrolled()) {
PostProtoResponse(std::move(callback), reply); PostProtoResponse(std::move(callback), reply);
return; return;
} }
...@@ -302,6 +306,10 @@ void FakeAttestationClient::ConfigureEnrollmentPreparationsStatus( ...@@ -302,6 +306,10 @@ void FakeAttestationClient::ConfigureEnrollmentPreparationsStatus(
preparations_status_ = status; preparations_status_ = status;
} }
::attestation::GetStatusReply* FakeAttestationClient::mutable_status_reply() {
return &status_reply_;
}
void FakeAttestationClient::AllowlistCertificateRequest( void FakeAttestationClient::AllowlistCertificateRequest(
const ::attestation::GetCertificateRequest& request) { const ::attestation::GetCertificateRequest& request) {
for (const auto& req : allowlisted_requests_) { for (const auto& req : allowlisted_requests_) {
......
...@@ -99,6 +99,7 @@ class COMPONENT_EXPORT(CHROMEOS_DBUS_ATTESTATION) FakeAttestationClient ...@@ -99,6 +99,7 @@ class COMPONENT_EXPORT(CHROMEOS_DBUS_ATTESTATION) FakeAttestationClient
std::deque<bool> sequence) override; std::deque<bool> sequence) override;
void ConfigureEnrollmentPreparationsStatus( void ConfigureEnrollmentPreparationsStatus(
::attestation::AttestationStatus status) override; ::attestation::AttestationStatus status) override;
::attestation::GetStatusReply* mutable_status_reply() override;
void AllowlistCertificateRequest( void AllowlistCertificateRequest(
const ::attestation::GetCertificateRequest& request) override; const ::attestation::GetCertificateRequest& request) override;
void AllowlistLegacyCreateCertificateRequest( void AllowlistLegacyCreateCertificateRequest(
...@@ -126,7 +127,7 @@ class COMPONENT_EXPORT(CHROMEOS_DBUS_ATTESTATION) FakeAttestationClient ...@@ -126,7 +127,7 @@ class COMPONENT_EXPORT(CHROMEOS_DBUS_ATTESTATION) FakeAttestationClient
bool is_prepared_ = true; bool is_prepared_ = true;
std::deque<bool> preparation_sequences_; std::deque<bool> preparation_sequences_;
bool is_enrolled_ = false; ::attestation::GetStatusReply status_reply_;
::attestation::CreateCertificateRequestReply certificate_request_reply_; ::attestation::CreateCertificateRequestReply certificate_request_reply_;
......
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