Commit 5e5f14e8 authored by Leo Lai's avatar Leo Lai Committed by Commit Bot

use AttestationClient to preparations in PlatformVerificationFlow

We are deprecating attestation methods by CryptohomeClient.

BUG=b:158955123
TEST=unit_tests and browser_tests.

Change-Id: I4a302a38cf48060352477f48775aa5d2a0f27b35
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2466004Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Commit-Queue: Leo Lai <cylai@google.com>
Cr-Commit-Position: refs/heads/master@{#819709}
parent faa06ab5
...@@ -3853,6 +3853,8 @@ source_set("unit_tests") { ...@@ -3853,6 +3853,8 @@ source_set("unit_tests") {
"//chromeos/cryptohome:test_support", "//chromeos/cryptohome:test_support",
"//chromeos/dbus:lorgnette_proto", "//chromeos/dbus:lorgnette_proto",
"//chromeos/dbus:test_support", "//chromeos/dbus:test_support",
"//chromeos/dbus/attestation",
"//chromeos/dbus/attestation:attestation_proto",
"//chromeos/dbus/authpolicy", "//chromeos/dbus/authpolicy",
"//chromeos/dbus/cryptohome", "//chromeos/dbus/cryptohome",
"//chromeos/dbus/cryptohome:attestation_proto", "//chromeos/dbus/cryptohome:attestation_proto",
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/chromeos/settings/device_settings_service.h" #include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chromeos/dbus/attestation/fake_attestation_client.h"
#include "chromeos/dbus/cryptohome/fake_cryptohome_client.h" #include "chromeos/dbus/cryptohome/fake_cryptohome_client.h"
#include "components/policy/proto/chrome_device_policy.pb.h" #include "components/policy/proto/chrome_device_policy.pb.h"
#include "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
...@@ -64,7 +65,8 @@ class AttestationDevicePolicyTest ...@@ -64,7 +65,8 @@ class AttestationDevicePolicyTest
PlatformVerificationFlow::Result SyncContentProtectionAttestation() { PlatformVerificationFlow::Result SyncContentProtectionAttestation() {
scoped_refptr<PlatformVerificationFlow> verifier( scoped_refptr<PlatformVerificationFlow> verifier(
new PlatformVerificationFlow( new PlatformVerificationFlow(
nullptr, nullptr, chromeos::FakeCryptohomeClient::Get(), nullptr)); nullptr, nullptr, chromeos::FakeCryptohomeClient::Get(),
chromeos::FakeAttestationClient::Get(), nullptr));
verifier->ChallengePlatformKey( verifier->ChallengePlatformKey(
browser()->tab_strip_model()->GetActiveWebContents(), "fake_service_id", browser()->tab_strip_model()->GetActiveWebContents(), "fake_service_id",
"fake_challenge", "fake_challenge",
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include "chromeos/cryptohome/async_method_caller.h" #include "chromeos/cryptohome/async_method_caller.h"
#include "chromeos/cryptohome/cryptohome_parameters.h" #include "chromeos/cryptohome/cryptohome_parameters.h"
#include "chromeos/dbus/attestation/attestation.pb.h" #include "chromeos/dbus/attestation/attestation.pb.h"
#include "chromeos/dbus/attestation/attestation_client.h"
#include "chromeos/dbus/attestation/interface.pb.h"
#include "chromeos/dbus/cryptohome/cryptohome_client.h" #include "chromeos/dbus/cryptohome/cryptohome_client.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "components/content_settings/core/browser/host_content_settings_map.h" #include "components/content_settings/core/browser/host_content_settings_map.h"
...@@ -52,22 +54,6 @@ const char kAttestationAvailableHistogram[] = ...@@ -52,22 +54,6 @@ const char kAttestationAvailableHistogram[] =
"ChromeOS.PlatformVerification.Available"; "ChromeOS.PlatformVerification.Available";
const int kOpportunisticRenewalThresholdInDays = 30; const int kOpportunisticRenewalThresholdInDays = 30;
// A callback method to handle DBus errors.
// `on_success` and `on_failure` are called mutally exclusively,
// and `context` is moved into the chosen callback.
template <typename ContextT>
void DBusCallback(base::OnceCallback<void(ContextT, bool)> on_success,
base::OnceCallback<void(ContextT)> on_failure,
ContextT context,
base::Optional<bool> result) {
if (result.has_value()) {
std::move(on_success).Run(std::move(context), result.value());
} else {
LOG(ERROR) << "PlatformVerificationFlow: DBus call failed!";
std::move(on_failure).Run(std::move(context));
}
}
// A helper to call a ChallengeCallback with an error result. // A helper to call a ChallengeCallback with an error result.
void ReportError( void ReportError(
PlatformVerificationFlow::ChallengeCallback callback, PlatformVerificationFlow::ChallengeCallback callback,
...@@ -153,6 +139,7 @@ PlatformVerificationFlow::PlatformVerificationFlow() ...@@ -153,6 +139,7 @@ PlatformVerificationFlow::PlatformVerificationFlow()
: attestation_flow_(NULL), : attestation_flow_(NULL),
async_caller_(cryptohome::AsyncMethodCaller::GetInstance()), async_caller_(cryptohome::AsyncMethodCaller::GetInstance()),
cryptohome_client_(CryptohomeClient::Get()), cryptohome_client_(CryptohomeClient::Get()),
attestation_client_(AttestationClient::Get()),
delegate_(NULL), delegate_(NULL),
timeout_delay_(base::TimeDelta::FromSeconds(kTimeoutInSeconds)) { timeout_delay_(base::TimeDelta::FromSeconds(kTimeoutInSeconds)) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
...@@ -168,10 +155,12 @@ PlatformVerificationFlow::PlatformVerificationFlow( ...@@ -168,10 +155,12 @@ PlatformVerificationFlow::PlatformVerificationFlow(
AttestationFlow* attestation_flow, AttestationFlow* attestation_flow,
cryptohome::AsyncMethodCaller* async_caller, cryptohome::AsyncMethodCaller* async_caller,
CryptohomeClient* cryptohome_client, CryptohomeClient* cryptohome_client,
AttestationClient* attestation_client,
Delegate* delegate) Delegate* delegate)
: attestation_flow_(attestation_flow), : attestation_flow_(attestation_flow),
async_caller_(async_caller), async_caller_(async_caller),
cryptohome_client_(cryptohome_client), cryptohome_client_(cryptohome_client),
attestation_client_(attestation_client),
delegate_(delegate), delegate_(delegate),
timeout_delay_(base::TimeDelta::FromSeconds(kTimeoutInSeconds)) { timeout_delay_(base::TimeDelta::FromSeconds(kTimeoutInSeconds)) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
...@@ -227,18 +216,23 @@ void PlatformVerificationFlow::ChallengePlatformKey( ...@@ -227,18 +216,23 @@ void PlatformVerificationFlow::ChallengePlatformKey(
std::move(callback)); std::move(callback));
// Check if the device has been prepared to use attestation. // Check if the device has been prepared to use attestation.
cryptohome_client_->TpmAttestationIsPrepared(base::BindOnce( ::attestation::GetEnrollmentPreparationsRequest request;
&DBusCallback<ChallengeContext>, attestation_client_->GetEnrollmentPreparations(
base::Bind(&PlatformVerificationFlow::OnAttestationPrepared, this), request, base::BindOnce(&PlatformVerificationFlow::OnAttestationPrepared,
base::Bind([](ChallengeContext context) { this, std::move(context)));
ReportError(std::move(context).callback, INTERNAL_ERROR);
}),
std::move(context)));
} }
void PlatformVerificationFlow::OnAttestationPrepared( void PlatformVerificationFlow::OnAttestationPrepared(
ChallengeContext context, ChallengeContext context,
bool attestation_prepared) { const ::attestation::GetEnrollmentPreparationsReply& reply) {
if (reply.status() != ::attestation::STATUS_SUCCESS) {
LOG(ERROR)
<< "Platform verification failed to check if attestation is prepared.";
ReportError(std::move(context).callback, INTERNAL_ERROR);
return;
}
const bool attestation_prepared =
AttestationClient::IsAttestationPrepared(reply);
UMA_HISTOGRAM_BOOLEAN(kAttestationAvailableHistogram, attestation_prepared); UMA_HISTOGRAM_BOOLEAN(kAttestationAvailableHistogram, attestation_prepared);
if (!attestation_prepared) { if (!attestation_prepared) {
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chromeos/dbus/attestation/interface.pb.h"
#include "chromeos/dbus/constants/attestation_constants.h" #include "chromeos/dbus/constants/attestation_constants.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -33,6 +34,7 @@ class User; ...@@ -33,6 +34,7 @@ class User;
namespace chromeos { namespace chromeos {
class AttestationClient;
class CryptohomeClient; class CryptohomeClient;
namespace attestation { namespace attestation {
...@@ -130,6 +132,7 @@ class PlatformVerificationFlow ...@@ -130,6 +132,7 @@ class PlatformVerificationFlow
PlatformVerificationFlow(AttestationFlow* attestation_flow, PlatformVerificationFlow(AttestationFlow* attestation_flow,
cryptohome::AsyncMethodCaller* async_caller, cryptohome::AsyncMethodCaller* async_caller,
CryptohomeClient* cryptohome_client, CryptohomeClient* cryptohome_client,
AttestationClient* attestation_client,
Delegate* delegate); Delegate* delegate);
// Invokes an asynchronous operation to challenge a platform key. Any user // Invokes an asynchronous operation to challenge a platform key. Any user
...@@ -174,10 +177,10 @@ class PlatformVerificationFlow ...@@ -174,10 +177,10 @@ class PlatformVerificationFlow
~PlatformVerificationFlow(); ~PlatformVerificationFlow();
// Callback for attestation preparation. The arguments to ChallengePlatformKey // Callback for attestation preparation. The arguments to ChallengePlatformKey
// are in |context|, and |attestation_prepared| specifies whether attestation // are in |context|, and |reply| is the result of |GetEnrollmentPreparations|.
// has been prepared on this device. void OnAttestationPrepared(
void OnAttestationPrepared(ChallengeContext context, ChallengeContext context,
bool attestation_prepared); const ::attestation::GetEnrollmentPreparationsReply& reply);
// Initiates the flow to get a platform key certificate. The arguments to // Initiates the flow to get a platform key certificate. The arguments to
// ChallengePlatformKey are in |context|. |account_id| identifies the user // ChallengePlatformKey are in |context|. |account_id| identifies the user
...@@ -193,11 +196,11 @@ class PlatformVerificationFlow ...@@ -193,11 +196,11 @@ class PlatformVerificationFlow
// completes. The arguments to ChallengePlatformKey are in |context|. // completes. The arguments to ChallengePlatformKey are in |context|.
// |account_id| identifies the user for which the certificate was requested. // |account_id| identifies the user for which the certificate was requested.
// |operation_success| is true iff the certificate request operation // |operation_success| is true iff the certificate request operation
// succeeded. |certificate_chain| holds the certificate for the platform key // succeeded. |certificate_chain| holds the certificate for the platform
// on success. If the certificate request was successful, this method invokes // key on success. If the certificate request was successful, this method
// a request to sign the challenge. If the operation timed out prior to this // invokes a request to sign the challenge. If the operation timed out
// method being called, this method does nothing - notably, the callback is // prior to this method being called, this method does nothing - notably,
// not invoked. // the callback is not invoked.
void OnCertificateReady( void OnCertificateReady(
scoped_refptr<base::RefCountedData<ChallengeContext>> context, scoped_refptr<base::RefCountedData<ChallengeContext>> context,
const AccountId& account_id, const AccountId& account_id,
...@@ -243,7 +246,8 @@ class PlatformVerificationFlow ...@@ -243,7 +246,8 @@ class PlatformVerificationFlow
AttestationFlow* attestation_flow_; AttestationFlow* attestation_flow_;
std::unique_ptr<AttestationFlow> default_attestation_flow_; std::unique_ptr<AttestationFlow> default_attestation_flow_;
cryptohome::AsyncMethodCaller* async_caller_; cryptohome::AsyncMethodCaller* async_caller_;
CryptohomeClient* cryptohome_client_; CryptohomeClient* const cryptohome_client_;
AttestationClient* const attestation_client_;
Delegate* delegate_; Delegate* delegate_;
std::unique_ptr<Delegate> default_delegate_; std::unique_ptr<Delegate> default_delegate_;
base::TimeDelta timeout_delay_; base::TimeDelta timeout_delay_;
......
...@@ -20,7 +20,8 @@ ...@@ -20,7 +20,8 @@
#include "chromeos/attestation/mock_attestation_flow.h" #include "chromeos/attestation/mock_attestation_flow.h"
#include "chromeos/cryptohome/mock_async_method_caller.h" #include "chromeos/cryptohome/mock_async_method_caller.h"
#include "chromeos/dbus/attestation/attestation.pb.h" #include "chromeos/dbus/attestation/attestation.pb.h"
#include "chromeos/dbus/cryptohome/fake_cryptohome_client.h" #include "chromeos/dbus/attestation/fake_attestation_client.h"
#include "chromeos/dbus/attestation/interface.pb.h"
#include "chromeos/settings/cros_settings_names.h" #include "chromeos/settings/cros_settings_names.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -102,14 +103,21 @@ class PlatformVerificationFlowTest : public ::testing::Test { ...@@ -102,14 +103,21 @@ class PlatformVerificationFlowTest : public ::testing::Test {
: certificate_status_(ATTESTATION_SUCCESS), : certificate_status_(ATTESTATION_SUCCESS),
fake_certificate_index_(0), fake_certificate_index_(0),
sign_challenge_success_(true), sign_challenge_success_(true),
result_(PlatformVerificationFlow::INTERNAL_ERROR) {} result_(PlatformVerificationFlow::INTERNAL_ERROR) {
::chromeos::AttestationClient::InitializeFake();
}
~PlatformVerificationFlowTest() override {
::chromeos::AttestationClient::Shutdown();
}
void SetUp() { void SetUp() {
// Create a verifier for tests to call. // Create a verifier for tests to call.
verifier_ = new PlatformVerificationFlow(&mock_attestation_flow_, // We don't need cryptohome_client in unittests because it is only needed
&mock_async_caller_, // for real AttestationFlow and in unittests we uses mocked one.
&fake_cryptohome_client_, verifier_ = new PlatformVerificationFlow(
&fake_delegate_); &mock_attestation_flow_, &mock_async_caller_,
/*cryptohome_client=*/nullptr, AttestationClient::Get(),
&fake_delegate_);
// Create callbacks for tests to use with verifier_. // Create callbacks for tests to use with verifier_.
settings_helper_.ReplaceDeviceSettingsProviderWithStub(); settings_helper_.ReplaceDeviceSettingsProviderWithStub();
...@@ -184,7 +192,6 @@ class PlatformVerificationFlowTest : public ::testing::Test { ...@@ -184,7 +192,6 @@ class PlatformVerificationFlowTest : public ::testing::Test {
content::BrowserTaskEnvironment task_environment_; content::BrowserTaskEnvironment task_environment_;
StrictMock<MockAttestationFlow> mock_attestation_flow_; StrictMock<MockAttestationFlow> mock_attestation_flow_;
cryptohome::MockAsyncMethodCaller mock_async_caller_; cryptohome::MockAsyncMethodCaller mock_async_caller_;
chromeos::FakeCryptohomeClient fake_cryptohome_client_;
FakeDelegate fake_delegate_; FakeDelegate fake_delegate_;
ScopedCrosSettingsTestHelper settings_helper_; ScopedCrosSettingsTestHelper settings_helper_;
scoped_refptr<PlatformVerificationFlow> verifier_; scoped_refptr<PlatformVerificationFlow> verifier_;
...@@ -259,7 +266,20 @@ TEST_F(PlatformVerificationFlowTest, ChallengeSigningError) { ...@@ -259,7 +266,20 @@ TEST_F(PlatformVerificationFlowTest, ChallengeSigningError) {
} }
TEST_F(PlatformVerificationFlowTest, DBusFailure) { TEST_F(PlatformVerificationFlowTest, DBusFailure) {
fake_cryptohome_client_.SetServiceIsAvailable(false); chromeos::AttestationClient::Get()
->GetTestInterface()
->ConfigureEnrollmentPreparationsStatus(::attestation::STATUS_DBUS_ERROR);
verifier_->ChallengePlatformKey(nullptr, kTestID, kTestChallenge,
CreateChallengeCallback());
base::RunLoop().RunUntilIdle();
EXPECT_EQ(PlatformVerificationFlow::INTERNAL_ERROR, result_);
}
TEST_F(PlatformVerificationFlowTest, AttestationServiceInternalError) {
chromeos::AttestationClient::Get()
->GetTestInterface()
->ConfigureEnrollmentPreparationsStatus(
::attestation::STATUS_UNEXPECTED_DEVICE_ERROR);
verifier_->ChallengePlatformKey(nullptr, kTestID, kTestChallenge, verifier_->ChallengePlatformKey(nullptr, kTestID, kTestChallenge,
CreateChallengeCallback()); CreateChallengeCallback());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
...@@ -380,8 +400,9 @@ TEST_F(PlatformVerificationFlowTest, UnsupportedMode) { ...@@ -380,8 +400,9 @@ TEST_F(PlatformVerificationFlowTest, UnsupportedMode) {
} }
TEST_F(PlatformVerificationFlowTest, AttestationNotPrepared) { TEST_F(PlatformVerificationFlowTest, AttestationNotPrepared) {
fake_cryptohome_client_.set_tpm_attestation_is_enrolled(false); chromeos::AttestationClient::Get()
fake_cryptohome_client_.set_tpm_attestation_is_prepared(false); ->GetTestInterface()
->ConfigureEnrollmentPreparations(false);
verifier_->ChallengePlatformKey(nullptr, kTestID, kTestChallenge, verifier_->ChallengePlatformKey(nullptr, kTestID, kTestChallenge,
CreateChallengeCallback()); CreateChallengeCallback());
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
......
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