Commit b0a774c4 authored by James Hawkins's avatar James Hawkins Committed by Commit Bot

components/cryptauth: Remove unused bluetooth_address field from RemoteDevice.

R=hansberry@chromium.org

Bug: 829039
Test: none
Change-Id: I4216ffa94963a3f2bfdab08b73dd135fd78f4007
Reviewed-on: https://chromium-review.googlesource.com/1012981
Commit-Queue: James Hawkins <jhawkins@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551021}
parent 71a2cc1b
......@@ -153,7 +153,8 @@ void EasyUnlockServiceRegular::OnRemoteDevicesLoaded(
dict->SetString("name", device.name);
dict->SetString("psk", b64_psk);
dict->SetString("bluetoothAddress", device.bluetooth_address);
// TODO(jhawkins): Remove the bluetoothAddress field from this proto.
dict->SetString("bluetoothAddress", std::string());
dict->SetString("permitId", "permit://google.com/easyunlock/v1/" +
proximity_auth_client()->GetAccountId());
dict->SetString("permitRecord.id", b64_public_key);
......
......@@ -511,8 +511,8 @@ void EasyUnlockServiceSignin::OnUserDataLoaded(
// making that assumption here.
cryptauth::RemoteDevice remote_device(
account_id.GetUserEmail(), std::string(), decoded_public_key,
device.bluetooth_address, decoded_psk, true /* unlock_key */,
false /* supports_mobile_hotspot */, 0L /* last_update_time_millis */);
decoded_psk, true /* unlock_key */, false /* supports_mobile_hotspot */,
0L /* last_update_time_millis */);
if (!device.serialized_beacon_seeds.empty()) {
PA_LOG(INFO) << "Deserializing BeaconSeeds: "
......@@ -527,8 +527,7 @@ void EasyUnlockServiceSignin::OnUserDataLoaded(
PA_LOG(INFO) << "Loaded Remote Device:\n"
<< " user id: " << remote_device.user_id << "\n"
<< " name: " << remote_device.name << "\n"
<< " public key" << device.public_key << "\n"
<< " bt_addr:" << remote_device.bluetooth_address;
<< " public key" << device.public_key;
}
SetProximityAuthDevices(account_id, remote_devices);
......
......@@ -379,14 +379,14 @@ void EasyUnlockPrivateFindSetupConnectionFunction::
void EasyUnlockPrivateFindSetupConnectionFunction::OnConnectionFound(
std::unique_ptr<cryptauth::Connection> connection) {
// Connection are not persistent by default.
std::string device_address = connection->remote_device().bluetooth_address;
bool persistent = false;
int connection_id =
GetConnectionManager(browser_context())
->AddConnection(extension(), std::move(connection), persistent);
// TODO(jhawkins): Remove the deviceAddress parameter from the API.
Respond(
ArgumentList(easy_unlock_private::FindSetupConnection::Results::Create(
connection_id, device_address)));
connection_id, /* device_address */ std::string())));
}
ExtensionFunction::ResponseAction
......
......@@ -99,18 +99,6 @@ TEST(ProximityAuthMessengerImplTest, SupportsSignIn_ProtocolVersionThreeOne) {
EXPECT_TRUE(messenger.SupportsSignIn());
}
TEST(ProximityAuthMessengerImplTest, SupportsSignIn_EmptyBluetoothAddress) {
cryptauth::RemoteDevice ble_remote_device =
cryptauth::CreateLERemoteDeviceForTest();
ble_remote_device.bluetooth_address = "";
TestMessenger messenger(std::unique_ptr<cryptauth::Connection>(
new cryptauth::FakeConnection(ble_remote_device)));
messenger.GetFakeSecureContext()->set_protocol_version(
cryptauth::SecureContext::PROTOCOL_VERSION_THREE_ONE);
EXPECT_TRUE(messenger.SupportsSignIn());
}
TEST(ProximityAuthMessengerImplTest,
OnConnectionStatusChanged_ConnectionDisconnects) {
TestMessenger messenger;
......
......@@ -54,9 +54,8 @@ void CompareRemoteDeviceLists(const RemoteDeviceList& list1,
// Creates a RemoteDevice object for |user_id| with |name|.
RemoteDevice CreateRemoteDevice(const std::string& user_id,
const std::string& name) {
return RemoteDevice(user_id, name + "_pk", name, name + "_btaddr",
name + "_psk", true /* unlock_key */,
true /* supports_mobile_hotspot */,
return RemoteDevice(user_id, name + "_pk", name, name + "_psk",
true /* unlock_key */, true /* supports_mobile_hotspot */,
0 /* last_update_time_millis */);
}
......
......@@ -37,7 +37,6 @@ namespace {
const char kRemoteDeviceUserId[] = "example@gmail.com";
const char kRemoteDevicePublicKey[] = "Remote Public Key";
const char kRemoteDeviceName[] = "LGE Nexus 5";
const char kBluetoothAddress[] = "AA:BB:CC:DD:EE:FF";
const char kPersistentSymmetricKey[] = "PSK";
// The proximity threshold corresponds to a RSSI of -70.
......@@ -94,7 +93,6 @@ class ProximityAuthProximityMonitorImplTest : public testing::Test {
remote_device_(kRemoteDeviceUserId,
kRemoteDeviceName,
kRemoteDevicePublicKey,
kBluetoothAddress,
kPersistentSymmetricKey,
true /* unlock_key */,
true /* mobile_hotspot_supported */,
......@@ -104,7 +102,7 @@ class ProximityAuthProximityMonitorImplTest : public testing::Test {
monitor_(&connection_, pref_manager_.get()),
task_runner_(new base::TestSimpleTaskRunner()),
thread_task_runner_handle_(task_runner_) {
ON_CALL(*bluetooth_adapter_, GetDevice(kBluetoothAddress))
ON_CALL(*bluetooth_adapter_, GetDevice(std::string()))
.WillByDefault(Return(&remote_bluetooth_device_));
ON_CALL(remote_bluetooth_device_, GetConnectionInfo(_))
.WillByDefault(SaveArg<0>(&connection_info_callback_));
......@@ -294,7 +292,7 @@ TEST_F(ProximityAuthProximityMonitorImplTest,
EXPECT_TRUE(monitor_.IsUnlockAllowed());
// Simulate it being forgotten.
ON_CALL(*bluetooth_adapter_, GetDevice(kBluetoothAddress))
ON_CALL(*bluetooth_adapter_, GetDevice(std::string()))
.WillByDefault(Return(nullptr));
EXPECT_CALL(observer_, OnProximityStateChanged());
RunPendingTasks();
......@@ -358,7 +356,7 @@ TEST_F(ProximityAuthProximityMonitorImplTest,
// Note: A device without a recorded name will have "Unknown" as its name.
cryptauth::RemoteDevice unnamed_remote_device(
kRemoteDeviceUserId, "" /* name */, kRemoteDevicePublicKey,
kBluetoothAddress, kPersistentSymmetricKey, true /* unlock_key */,
kPersistentSymmetricKey, true /* unlock_key */,
true /* supports_mobile_hotspot */, 0 /* last_update_time_millis */);
cryptauth::FakeConnection connection(unnamed_remote_device);
......
......@@ -40,8 +40,7 @@ RemoteDeviceLifeCycleImpl::RemoteDeviceLifeCycleImpl(
RemoteDeviceLifeCycleImpl::~RemoteDeviceLifeCycleImpl() {}
void RemoteDeviceLifeCycleImpl::Start() {
PA_LOG(INFO) << "Life cycle for " << remote_device_.bluetooth_address
<< " started.";
PA_LOG(INFO) << "Life cycle for " << remote_device_.name << " started.";
DCHECK(state_ == RemoteDeviceLifeCycle::State::STOPPED);
FindConnection();
}
......
......@@ -249,8 +249,6 @@ TEST_F(ProximityAuthRemoteDeviceLifeCycleImplTest, GetRemoteDevice) {
EXPECT_EQ(expected_remote_device.user_id, remote_device.user_id);
EXPECT_EQ(expected_remote_device.name, remote_device.name);
EXPECT_EQ(expected_remote_device.public_key, remote_device.public_key);
EXPECT_EQ(expected_remote_device.bluetooth_address,
remote_device.bluetooth_address);
EXPECT_EQ(expected_remote_device.persistent_symmetric_key,
remote_device.persistent_symmetric_key);
}
......
......@@ -612,8 +612,7 @@ ProximityAuthWebUIHandler::IneligibleDeviceToDictionary(
}
void ProximityAuthWebUIHandler::CleanUpRemoteDeviceLifeCycle() {
PA_LOG(INFO) << "Cleaning up connection to " << selected_remote_device_.name
<< " [" << selected_remote_device_.bluetooth_address << "]";
PA_LOG(INFO) << "Cleaning up connection to " << selected_remote_device_.name;
life_cycle_.reset();
selected_remote_device_ = cryptauth::RemoteDevice();
last_remote_status_update_.reset();
......
......@@ -50,10 +50,6 @@ void Connection::RemoveObserver(ConnectionObserver* observer) {
observers_.RemoveObserver(observer);
}
std::string Connection::GetDeviceAddress() {
return remote_device_.bluetooth_address;
}
void Connection::SetStatus(Status status) {
if (status_ == status)
return;
......
......@@ -58,7 +58,7 @@ class Connection {
virtual void Disconnect() = 0;
// The bluetooth address of the connected device.
virtual std::string GetDeviceAddress();
virtual std::string GetDeviceAddress() = 0;
Status status() const { return status_; }
......
......@@ -30,6 +30,7 @@ class MockConnection : public Connection {
MOCK_METHOD1(SetPaused, void(bool paused));
MOCK_METHOD0(Connect, void());
MOCK_METHOD0(Disconnect, void());
MOCK_METHOD0(GetDeviceAddress, std::string());
MOCK_METHOD0(CancelConnectionAttempt, void());
MOCK_METHOD1(SendMessageImplProxy, void(WireMessage* message));
MOCK_METHOD1(DeserializeWireMessageProxy,
......@@ -114,6 +115,7 @@ TEST(CryptAuthConnectionTest, SendMessage_FailsWhenNotConnected) {
StrictMock<MockConnection> connection;
connection.SetStatus(Connection::IN_PROGRESS);
EXPECT_CALL(connection, GetDeviceAddress()).Times(1);
EXPECT_CALL(connection, SendMessageImplProxy(_)).Times(0);
connection.SendMessage(std::unique_ptr<WireMessage>());
}
......@@ -220,6 +222,7 @@ TEST(CryptAuthConnectionTest,
StrictMock<MockConnectionObserver> observer;
connection.AddObserver(&observer);
EXPECT_CALL(connection, GetDeviceAddress()).Times(1);
EXPECT_CALL(observer, OnMessageReceived(_, _)).Times(0);
connection.OnBytesReceived(std::string());
}
......
......@@ -22,8 +22,7 @@ extern const int64_t kTestRemoteDeviceLastUpdateTimeMillis;
// Returns a BLE RemoteDevice used for tests.
inline RemoteDevice CreateLERemoteDeviceForTest() {
return RemoteDevice(kTestRemoteDeviceUserId, kTestRemoteDeviceName,
kTestRemoteDevicePublicKey,
kTestRemoteDeviceBluetoothAddress, kTestRemoteDevicePSK,
kTestRemoteDevicePublicKey, kTestRemoteDevicePSK,
kTestRemoteDeviceUnlockKey,
kTestRemoteDeviceSupportsMobileHotspot,
kTestRemoteDeviceLastUpdateTimeMillis);
......@@ -32,8 +31,7 @@ inline RemoteDevice CreateLERemoteDeviceForTest() {
// Returns a classic Bluetooth RemoteDevice used for tests.
inline RemoteDevice CreateClassicRemoteDeviceForTest() {
return RemoteDevice(kTestRemoteDeviceUserId, kTestRemoteDeviceName,
kTestRemoteDevicePublicKey,
kTestRemoteDeviceBluetoothAddress, kTestRemoteDevicePSK,
kTestRemoteDevicePublicKey, kTestRemoteDevicePSK,
kTestRemoteDeviceUnlockKey,
kTestRemoteDeviceSupportsMobileHotspot,
kTestRemoteDeviceLastUpdateTimeMillis);
......
......@@ -77,6 +77,7 @@ class FakeConnection : public Connection {
void Disconnect() override {
SetStatus(Connection::Status::DISCONNECTED);
}
std::string GetDeviceAddress() override { return std::string(); }
using Connection::OnBytesReceived;
......
......@@ -38,6 +38,10 @@ void FakeConnection::Disconnect() {
SetStatus(DISCONNECTED);
}
std::string FakeConnection::GetDeviceAddress() {
return std::string();
}
void FakeConnection::AddObserver(ConnectionObserver* observer) {
observers_.push_back(observer);
Connection::AddObserver(observer);
......
......@@ -22,6 +22,7 @@ class FakeConnection : public Connection {
// Connection:
void Connect() override;
void Disconnect() override;
std::string GetDeviceAddress() override;
void AddObserver(ConnectionObserver* observer) override;
void RemoveObserver(ConnectionObserver* observer) override;
......
......@@ -40,7 +40,6 @@ RemoteDevice::RemoteDevice()
RemoteDevice::RemoteDevice(const std::string& user_id,
const std::string& name,
const std::string& public_key,
const std::string& bluetooth_address,
const std::string& persistent_symmetric_key,
bool unlock_key,
bool supports_mobile_hotspot,
......@@ -48,7 +47,6 @@ RemoteDevice::RemoteDevice(const std::string& user_id,
: user_id(user_id),
name(name),
public_key(public_key),
bluetooth_address(bluetooth_address),
persistent_symmetric_key(persistent_symmetric_key),
unlock_key(unlock_key),
supports_mobile_hotspot(supports_mobile_hotspot),
......
......@@ -17,7 +17,6 @@ struct RemoteDevice {
std::string user_id;
std::string name;
std::string public_key;
std::string bluetooth_address;
std::string persistent_symmetric_key;
bool unlock_key;
bool supports_mobile_hotspot;
......@@ -32,7 +31,6 @@ struct RemoteDevice {
RemoteDevice(const std::string& user_id,
const std::string& name,
const std::string& public_key,
const std::string& bluetooth_address,
const std::string& persistent_symmetric_key,
bool unlock_key,
bool supports_mobile_hotspot,
......
......@@ -105,9 +105,9 @@ void RemoteDeviceLoader::OnPSKDerived(
<< ", " << remaining_devices_.size() << " keys remaining.";
cryptauth::RemoteDevice remote_device(
user_id_, device.friendly_device_name(), device.public_key(),
device.bluetooth_address(), psk, device.unlock_key(),
device.mobile_hotspot_supported(), device.last_update_time_millis());
user_id_, device.friendly_device_name(), device.public_key(), psk,
device.unlock_key(), device.mobile_hotspot_supported(),
device.last_update_time_millis());
if (should_load_beacon_seeds_) {
std::vector<BeaconSeed> beacon_seeds;
......
......@@ -21,7 +21,6 @@ namespace {
// Prefixes for RemoteDevice fields.
const char kDeviceNamePrefix[] = "device";
const char kPublicKeyPrefix[] = "pk";
const char kBluetoothAddressPrefix[] = "11:22:33:44:55:0";
// The id of the user who the remote devices belong to.
const char kUserId[] = "example@gmail.com";
......@@ -40,8 +39,6 @@ cryptauth::ExternalDeviceInfo CreateDeviceInfo(const std::string& suffix) {
cryptauth::ExternalDeviceInfo device_info;
device_info.set_friendly_device_name(std::string(kDeviceNamePrefix) + suffix);
device_info.set_public_key(std::string(kPublicKeyPrefix) + suffix);
device_info.set_bluetooth_address(std::string(kBluetoothAddressPrefix) +
suffix);
device_info.add_beacon_seeds();
BeaconSeed* beacon_seed = device_info.mutable_beacon_seeds(0);
beacon_seed->set_start_time_millis(kBeaconSeedStartTimeMs);
......@@ -208,73 +205,4 @@ TEST_F(CryptAuthRemoteDeviceLoaderTest, LastUpdateTimeMillis) {
EXPECT_EQ(2000, remote_devices_[1].last_update_time_millis);
}
TEST_F(CryptAuthRemoteDeviceLoaderTest, LoadOneDeviceWithAddress) {
std::vector<cryptauth::ExternalDeviceInfo> device_infos(1,
CreateDeviceInfo("0"));
RemoteDeviceLoader loader(device_infos, user_private_key_, kUserId,
std::move(secure_message_delegate_));
std::vector<cryptauth::RemoteDevice> result;
EXPECT_CALL(*this, LoadCompleted());
loader.Load(
false, base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded,
base::Unretained(this)));
EXPECT_EQ(1u, remote_devices_.size());
EXPECT_FALSE(remote_devices_[0].persistent_symmetric_key.empty());
EXPECT_EQ(device_infos[0].friendly_device_name(), remote_devices_[0].name);
EXPECT_EQ(device_infos[0].public_key(), remote_devices_[0].public_key);
EXPECT_EQ(device_infos[0].bluetooth_address(),
remote_devices_[0].bluetooth_address);
EXPECT_EQ(0u, remote_devices_[0].beacon_seeds.size());
}
TEST_F(CryptAuthRemoteDeviceLoaderTest, LoadOneDeviceWithoutAddress) {
std::vector<cryptauth::ExternalDeviceInfo> device_infos(1,
CreateDeviceInfo("0"));
device_infos[0].set_bluetooth_address(std::string());
RemoteDeviceLoader loader(device_infos, user_private_key_, kUserId,
std::move(secure_message_delegate_));
std::vector<cryptauth::RemoteDevice> result;
EXPECT_CALL(*this, LoadCompleted());
loader.Load(
false, base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded,
base::Unretained(this)));
EXPECT_EQ(1u, remote_devices_.size());
EXPECT_FALSE(remote_devices_[0].persistent_symmetric_key.empty());
EXPECT_EQ(device_infos[0].friendly_device_name(), remote_devices_[0].name);
EXPECT_EQ(device_infos[0].public_key(), remote_devices_[0].public_key);
EXPECT_EQ("", remote_devices_[0].bluetooth_address);
}
TEST_F(CryptAuthRemoteDeviceLoaderTest, LoadThreeRemoteDevices) {
std::vector<cryptauth::ExternalDeviceInfo> device_infos;
device_infos.push_back(CreateDeviceInfo("0"));
device_infos.push_back(CreateDeviceInfo("1"));
device_infos.push_back(CreateDeviceInfo("2"));
// Devices 0 and 1 do not have a Bluetooth address, but device 2 does.
device_infos[0].set_bluetooth_address(std::string());
device_infos[1].set_bluetooth_address(std::string());
RemoteDeviceLoader loader(device_infos, user_private_key_, kUserId,
std::move(secure_message_delegate_));
EXPECT_CALL(*this, LoadCompleted());
loader.Load(
false, base::Bind(&CryptAuthRemoteDeviceLoaderTest::OnRemoteDevicesLoaded,
base::Unretained(this)));
EXPECT_EQ(3u, remote_devices_.size());
for (size_t i = 0; i < 3; ++i) {
EXPECT_FALSE(remote_devices_[i].persistent_symmetric_key.empty());
EXPECT_EQ(device_infos[i].friendly_device_name(), remote_devices_[i].name);
EXPECT_EQ(device_infos[i].public_key(), remote_devices_[i].public_key);
EXPECT_EQ(device_infos[i].bluetooth_address(),
remote_devices_[i].bluetooth_address);
}
}
} // namespace cryptauth
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