Commit d687ea9e authored by Ryan Hansberry's avatar Ryan Hansberry Committed by Commit Bot

[CrOS Multidevice] ChromeProximityAuthClient: conditionally use DeviceSyncClient.

ChromeProximityAuthClient now uses either CryptAuthService or DeviceSyncClient
to get remote device info or perform Cryptauth calls, depending on whether the
chromeos::features::kMultiDeviceApi is enabled. Once the migration to DeviceSyncClient
has been completed across all of Smart Lock, code that references CryptAuthService will
be removed.

This is one of many future CLs which are migrating Smart Lock to use
DeviceSync Mojo API instead of directly using the CryptAuth API.

TBR=jhawkins@chromium.org

Bug: 824568, 752273, 848956
Change-Id: If78959aa2a0ef6dc9433bca29649ab2d837114a1
Reviewed-on: https://chromium-review.googlesource.com/1102161
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567546}
parent 245e6851
......@@ -11,6 +11,7 @@
#include "base/version.h"
#include "build/build_config.h"
#include "chrome/browser/chromeos/cryptauth/chrome_cryptauth_service_factory.h"
#include "chrome/browser/chromeos/device_sync/device_sync_client_factory.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_regular.h"
#include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_service_signin_chromeos.h"
......@@ -18,7 +19,9 @@
#include "chrome/browser/profiles/profile_window.h"
#include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chromeos/chromeos_features.h"
#include "chromeos/components/proximity_auth/logging/logging.h"
#include "chromeos/services/device_sync/public/cpp/device_sync_client.h"
#include "components/cryptauth/cryptauth_client_impl.h"
#include "components/cryptauth/cryptauth_device_manager.h"
#include "components/cryptauth/cryptauth_enrollment_manager.h"
......@@ -72,7 +75,7 @@ void ChromeProximityAuthClient::GetChallengeForUserAndDevice(
EasyUnlockService* easy_unlock_service = EasyUnlockService::Get(profile_);
if (easy_unlock_service->GetType() == EasyUnlockService::TYPE_REGULAR) {
PA_LOG(ERROR) << "Unable to get challenge when user is logged in.";
callback.Run(std::string());
callback.Run(std::string() /* challenge */);
return;
}
......@@ -92,37 +95,53 @@ ChromeProximityAuthClient::GetPrefManager() {
std::unique_ptr<cryptauth::CryptAuthClientFactory>
ChromeProximityAuthClient::CreateCryptAuthClientFactory() {
DCHECK(!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
return GetCryptAuthService()->CreateCryptAuthClientFactory();
}
cryptauth::DeviceClassifier ChromeProximityAuthClient::GetDeviceClassifier() {
DCHECK(!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
return GetCryptAuthService()->GetDeviceClassifier();
}
std::string ChromeProximityAuthClient::GetAccountId() {
DCHECK(!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
return GetCryptAuthService()->GetAccountId();
}
cryptauth::CryptAuthEnrollmentManager*
ChromeProximityAuthClient::GetCryptAuthEnrollmentManager() {
DCHECK(!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
return GetCryptAuthService()->GetCryptAuthEnrollmentManager();
}
cryptauth::CryptAuthDeviceManager*
ChromeProximityAuthClient::GetCryptAuthDeviceManager() {
DCHECK(!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
return GetCryptAuthService()->GetCryptAuthDeviceManager();
}
std::string ChromeProximityAuthClient::GetLocalDevicePublicKey() {
if (base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi)) {
return GetDeviceSyncClient()->GetLocalDeviceMetadata()->public_key();
} else {
cryptauth::LocalDeviceDataProvider provider(GetCryptAuthService());
std::string local_public_key;
provider.GetLocalDeviceData(&local_public_key, nullptr);
return local_public_key;
}
}
cryptauth::CryptAuthService* ChromeProximityAuthClient::GetCryptAuthService() {
DCHECK(!base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
return ChromeCryptAuthServiceFactory::GetInstance()->GetForBrowserContext(
profile_);
}
std::string ChromeProximityAuthClient::GetLocalDevicePublicKey() {
cryptauth::LocalDeviceDataProvider provider(GetCryptAuthService());
std::string local_public_key;
provider.GetLocalDeviceData(&local_public_key, nullptr);
return local_public_key;
device_sync::DeviceSyncClient*
ChromeProximityAuthClient::GetDeviceSyncClient() {
DCHECK(base::FeatureList::IsEnabled(chromeos::features::kMultiDeviceApi));
return device_sync::DeviceSyncClientFactory::GetForProfile(profile_);
}
} // namespace chromeos
......@@ -16,6 +16,10 @@ class CryptAuthService;
namespace chromeos {
namespace device_sync {
class DeviceSyncClient;
} // namespace device_sync
// A Chrome-specific implementation of the ProximityAuthClient interface.
// There is one |ChromeProximityAuthClient| per |Profile|.
class ChromeProximityAuthClient : public proximity_auth::ProximityAuthClient {
......@@ -27,6 +31,12 @@ class ChromeProximityAuthClient : public proximity_auth::ProximityAuthClient {
std::string GetAuthenticatedUsername() const override;
void UpdateScreenlockState(proximity_auth::ScreenlockState state) override;
void FinalizeUnlock(bool success) override;
void FinalizeSignin(const std::string& secret) override;
void GetChallengeForUserAndDevice(
const std::string& user_id,
const std::string& remote_public_key,
const std::string& nonce,
base::Callback<void(const std::string& challenge)> callback) override;
proximity_auth::ProximityAuthPrefManager* GetPrefManager() override;
std::unique_ptr<cryptauth::CryptAuthClientFactory>
CreateCryptAuthClientFactory() override;
......@@ -35,16 +45,11 @@ class ChromeProximityAuthClient : public proximity_auth::ProximityAuthClient {
cryptauth::CryptAuthEnrollmentManager* GetCryptAuthEnrollmentManager()
override;
cryptauth::CryptAuthDeviceManager* GetCryptAuthDeviceManager() override;
void FinalizeSignin(const std::string& secret) override;
void GetChallengeForUserAndDevice(
const std::string& user_id,
const std::string& remote_public_key,
const std::string& nonce,
base::Callback<void(const std::string& challenge)> callback) override;
std::string GetLocalDevicePublicKey() override;
private:
cryptauth::CryptAuthService* GetCryptAuthService();
device_sync::DeviceSyncClient* GetDeviceSyncClient();
Profile* const profile_;
......
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