Commit 840f5cbd authored by tengs's avatar tengs Committed by Commit bot

[EasyUnlock] Delete components/proximity_auth/ble directory.

This code was used in our old BLE protocol, which is now obsolete.

Review-Url: https://codereview.chromium.org/2843443003
Cr-Commit-Position: refs/heads/master@{#467914}
parent 905b7630
...@@ -1959,7 +1959,6 @@ split_static_library("browser") { ...@@ -1959,7 +1959,6 @@ split_static_library("browser") {
"//chrome/common/extensions/api:api_registration", "//chrome/common/extensions/api:api_registration",
"//chrome/common/extensions/api:extensions_features", "//chrome/common/extensions/api:extensions_features",
"//components/drive", "//components/drive",
"//components/proximity_auth/ble",
"//extensions/components/javascript_dialog_extensions_client", "//extensions/components/javascript_dialog_extensions_client",
"//media/cast:net", "//media/cast:net",
] ]
......
...@@ -849,7 +849,6 @@ static_library("extensions") { ...@@ -849,7 +849,6 @@ static_library("extensions") {
"//components/policy/core/browser", "//components/policy/core/browser",
"//components/pref_registry", "//components/pref_registry",
"//components/proximity_auth", "//components/proximity_auth",
"//components/proximity_auth/ble",
"//components/proximity_auth/logging", "//components/proximity_auth/logging",
"//components/proxy_config", "//components/proxy_config",
"//components/rappor", "//components/rappor",
......
# Copyright 2014 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//testing/test.gni")
static_library("ble") {
sources = [
"bluetooth_low_energy_connection.cc",
"bluetooth_low_energy_connection.h",
"bluetooth_low_energy_device_whitelist.cc",
"bluetooth_low_energy_device_whitelist.h",
"pref_names.cc",
"pref_names.h",
]
deps = [
"//base",
"//components/cryptauth",
"//components/cryptauth/ble",
"//components/prefs",
"//components/proximity_auth/logging",
# TODO(https://crbug.com/562683): This component has a circular dependency
# with the root proximity auth target. It is whitelisted in that target for
# includes.
#"//components/proximity_auth",
"//device/bluetooth",
"//net",
]
public_deps = [
"//components/cryptauth/proto",
]
}
source_set("unit_tests") {
testonly = true
sources = [
"bluetooth_low_energy_connection_unittest.cc",
"bluetooth_low_energy_device_whitelist_unittest.cc",
]
configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
deps = [
":ble",
"//base/test:test_support",
"//components/cryptauth",
"//components/cryptauth:test_support",
"//components/cryptauth/ble:ble",
"//components/prefs:test_support",
"//components/proximity_auth:test_support",
"//device/bluetooth:mocks",
"//testing/gmock",
"//testing/gtest",
]
public_deps = [
"//components/cryptauth/proto",
]
}
msarda@chromium.org
sacomoto@chromium.org
tengs@chromium.org
khorimoto@chromium.org
hansberry@chromium.org
# COMPONENT: UI>ProximityAuth
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/proximity_auth/ble/bluetooth_low_energy_device_whitelist.h"
#include <vector>
#include "base/macros.h"
#include "base/values.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/proximity_auth/ble/pref_names.h"
#include "components/proximity_auth/logging/logging.h"
namespace proximity_auth {
BluetoothLowEnergyDeviceWhitelist::BluetoothLowEnergyDeviceWhitelist(
PrefService* pref_service)
: pref_service_(pref_service) {
}
BluetoothLowEnergyDeviceWhitelist::~BluetoothLowEnergyDeviceWhitelist() {
}
// static
void BluetoothLowEnergyDeviceWhitelist::RegisterPrefs(
PrefRegistrySimple* registry) {
registry->RegisterDictionaryPref(prefs::kBluetoothLowEnergyDeviceWhitelist);
}
bool BluetoothLowEnergyDeviceWhitelist::HasDeviceWithAddress(
const std::string& bluetooth_address) const {
return pref_service_->GetDictionary(prefs::kBluetoothLowEnergyDeviceWhitelist)
->HasKey(bluetooth_address);
}
bool BluetoothLowEnergyDeviceWhitelist::HasDeviceWithPublicKey(
const std::string& public_key) const {
return !GetDeviceAddress(public_key).empty();
}
std::string BluetoothLowEnergyDeviceWhitelist::GetDevicePublicKey(
const std::string& bluetooth_address) const {
std::string public_key;
GetWhitelistPrefs()->GetStringWithoutPathExpansion(bluetooth_address,
&public_key);
return public_key;
}
std::string BluetoothLowEnergyDeviceWhitelist::GetDeviceAddress(
const std::string& public_key) const {
const base::DictionaryValue* device_whitelist = GetWhitelistPrefs();
for (base::DictionaryValue::Iterator it(*device_whitelist); !it.IsAtEnd();
it.Advance()) {
std::string value_string;
DCHECK(it.value().IsType(base::Value::Type::STRING));
if (it.value().GetAsString(&value_string) && value_string == public_key)
return it.key();
}
return std::string();
}
std::vector<std::string> BluetoothLowEnergyDeviceWhitelist::GetPublicKeys()
const {
std::vector<std::string> public_keys;
const base::DictionaryValue* device_whitelist = GetWhitelistPrefs();
for (base::DictionaryValue::Iterator it(*device_whitelist); !it.IsAtEnd();
it.Advance()) {
std::string value_string;
DCHECK(it.value().IsType(base::Value::Type::STRING));
it.value().GetAsString(&value_string);
public_keys.push_back(value_string);
}
return public_keys;
}
void BluetoothLowEnergyDeviceWhitelist::AddOrUpdateDevice(
const std::string& bluetooth_address,
const std::string& public_key) {
if (HasDeviceWithPublicKey(public_key) &&
GetDeviceAddress(public_key) != bluetooth_address) {
PA_LOG(WARNING) << "Two devices with different bluetooth address, but the "
"same public key were added: " << public_key;
RemoveDeviceWithPublicKey(public_key);
}
DictionaryPrefUpdate device_whitelist_update(
pref_service_, prefs::kBluetoothLowEnergyDeviceWhitelist);
device_whitelist_update->SetStringWithoutPathExpansion(bluetooth_address,
public_key);
}
bool BluetoothLowEnergyDeviceWhitelist::RemoveDeviceWithAddress(
const std::string& bluetooth_address) {
DictionaryPrefUpdate device_whitelist_update(
pref_service_, prefs::kBluetoothLowEnergyDeviceWhitelist);
return device_whitelist_update->RemoveWithoutPathExpansion(bluetooth_address,
nullptr);
}
bool BluetoothLowEnergyDeviceWhitelist::RemoveDeviceWithPublicKey(
const std::string& public_key) {
return RemoveDeviceWithAddress(GetDeviceAddress(public_key));
}
const base::DictionaryValue*
BluetoothLowEnergyDeviceWhitelist::GetWhitelistPrefs() const {
return pref_service_->GetDictionary(
prefs::kBluetoothLowEnergyDeviceWhitelist);
}
} // namespace proximity_auth
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WHITELIST_H
#define COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_LOW_ENERGY_WHITELIST_H
#include <memory>
#include <string>
#include <vector>
#include "base/macros.h"
class PrefRegistrySimple;
class PrefService;
namespace base {
class DictionaryValue;
} // namespace base
namespace proximity_auth {
// This class stores a persistent set of whitelisted bluetooth devices
// represented by pairs (bluetooth_address, public_key). The class enforces a
// bijective mapping: no two device share the same bluetooth_address or
// the same public_key.
class BluetoothLowEnergyDeviceWhitelist {
public:
// Creates a device whitelist backed by preferences registered in
// |pref_service| (persistent across browser restarts). |pref_service| should
// have been registered using RegisterPrefs(). Not owned, must out live this
// instance.
explicit BluetoothLowEnergyDeviceWhitelist(PrefService* pref_service);
virtual ~BluetoothLowEnergyDeviceWhitelist();
// Registers the prefs used by this class to the given |pref_service|.
static void RegisterPrefs(PrefRegistrySimple* registry);
// Virtual for testing
virtual bool HasDeviceWithAddress(const std::string& bluetooth_address) const;
bool HasDeviceWithPublicKey(const std::string& public_key) const;
std::string GetDevicePublicKey(const std::string& bluetooth_address) const;
std::string GetDeviceAddress(const std::string& public_key) const;
std::vector<std::string> GetPublicKeys() const;
// Adds a device with |bluetooth_address| and |public_key|. The
// bluetooth_address <-> public_key mapping is unique, i.e. if there is
// another device with same bluetooth address or public key that device will
// be replaced.
void AddOrUpdateDevice(const std::string& bluetooth_address,
const std::string& public_key);
// Removes the unique device with |bluetooth_address| (|public_key|). Returns
// false if no device was found.
bool RemoveDeviceWithAddress(const std::string& bluetooth_address);
bool RemoveDeviceWithPublicKey(const std::string& public_key);
private:
const base::DictionaryValue* GetWhitelistPrefs() const;
// Contains perferences that outlive the lifetime of this object and across
// process restarts.
// Not owned and must outlive this instance.
PrefService* pref_service_;
DISALLOW_COPY_AND_ASSIGN(BluetoothLowEnergyDeviceWhitelist);
};
} // namespace proximity_auth
#endif // COMPONENTS_PROXIMITY_AUTH_BLE_BLUETOOTH_WHITELIST_H
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/proximity_auth/ble/bluetooth_low_energy_device_whitelist.h"
#include <algorithm>
#include <string>
#include <vector>
#include "base/macros.h"
#include "components/prefs/testing_pref_service.h"
#include "components/proximity_auth/ble/pref_names.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace proximity_auth {
namespace {
const char kBluetoothAddress1[] = "11:22:33:44:55:66";
const char kPublicKey1[] = "public key 1";
const char kBluetoothAddress2[] = "22:33:44:55:66:77";
const char kPublicKey2[] = "public key 2";
} // namespace
class ProximityAuthBluetoothLowEnergyDeviceWhitelistTest
: public testing::Test {
protected:
ProximityAuthBluetoothLowEnergyDeviceWhitelistTest() {}
void SetUp() override {
BluetoothLowEnergyDeviceWhitelist::RegisterPrefs(pref_service_.registry());
}
void CheckWhitelistedDevice(
const std::string& bluetooth_address,
const std::string& public_key,
BluetoothLowEnergyDeviceWhitelist& device_whitelist) {
EXPECT_TRUE(device_whitelist.HasDeviceWithAddress(bluetooth_address));
EXPECT_EQ(device_whitelist.GetDevicePublicKey(bluetooth_address),
public_key);
EXPECT_TRUE(device_whitelist.HasDeviceWithPublicKey(public_key));
EXPECT_EQ(device_whitelist.GetDeviceAddress(public_key), bluetooth_address);
}
TestingPrefServiceSimple pref_service_;
private:
DISALLOW_COPY_AND_ASSIGN(ProximityAuthBluetoothLowEnergyDeviceWhitelistTest);
};
TEST_F(ProximityAuthBluetoothLowEnergyDeviceWhitelistTest, RegisterPrefs) {
TestingPrefServiceSimple pref_service;
BluetoothLowEnergyDeviceWhitelist::RegisterPrefs(pref_service.registry());
EXPECT_TRUE(
pref_service.FindPreference(prefs::kBluetoothLowEnergyDeviceWhitelist));
}
TEST_F(ProximityAuthBluetoothLowEnergyDeviceWhitelistTest, AddDevice) {
BluetoothLowEnergyDeviceWhitelist device_whitelist(&pref_service_);
device_whitelist.AddOrUpdateDevice(kBluetoothAddress1, kPublicKey1);
CheckWhitelistedDevice(kBluetoothAddress1, kPublicKey1, device_whitelist);
}
TEST_F(ProximityAuthBluetoothLowEnergyDeviceWhitelistTest,
AddDevice_TwoDevicesWithSameAddress) {
BluetoothLowEnergyDeviceWhitelist device_whitelist(&pref_service_);
device_whitelist.AddOrUpdateDevice(kBluetoothAddress1, kPublicKey1);
CheckWhitelistedDevice(kBluetoothAddress1, kPublicKey1, device_whitelist);
device_whitelist.AddOrUpdateDevice(kBluetoothAddress1, kPublicKey2);
CheckWhitelistedDevice(kBluetoothAddress1, kPublicKey2, device_whitelist);
EXPECT_FALSE(device_whitelist.HasDeviceWithPublicKey(kPublicKey1));
}
TEST_F(ProximityAuthBluetoothLowEnergyDeviceWhitelistTest,
AddDevice_TwoDevicesWithSamePublicKey) {
BluetoothLowEnergyDeviceWhitelist device_whitelist(&pref_service_);
device_whitelist.AddOrUpdateDevice(kBluetoothAddress1, kPublicKey1);
CheckWhitelistedDevice(kBluetoothAddress1, kPublicKey1, device_whitelist);
device_whitelist.AddOrUpdateDevice(kBluetoothAddress2, kPublicKey1);
CheckWhitelistedDevice(kBluetoothAddress2, kPublicKey1, device_whitelist);
EXPECT_FALSE(device_whitelist.HasDeviceWithAddress(kBluetoothAddress1));
}
TEST_F(ProximityAuthBluetoothLowEnergyDeviceWhitelistTest,
RemoveDeviceWithAddress) {
BluetoothLowEnergyDeviceWhitelist device_whitelist(&pref_service_);
device_whitelist.AddOrUpdateDevice(kBluetoothAddress1, kPublicKey1);
CheckWhitelistedDevice(kBluetoothAddress1, kPublicKey1, device_whitelist);
ASSERT_TRUE(device_whitelist.RemoveDeviceWithAddress(kBluetoothAddress1));
EXPECT_FALSE(device_whitelist.HasDeviceWithAddress(kBluetoothAddress1));
EXPECT_FALSE(device_whitelist.HasDeviceWithPublicKey(kPublicKey1));
}
TEST_F(ProximityAuthBluetoothLowEnergyDeviceWhitelistTest,
RemoveDeviceWithAddress_DeviceNotPresent) {
BluetoothLowEnergyDeviceWhitelist device_whitelist(&pref_service_);
device_whitelist.AddOrUpdateDevice(kBluetoothAddress1, kPublicKey1);
CheckWhitelistedDevice(kBluetoothAddress1, kPublicKey1, device_whitelist);
ASSERT_FALSE(device_whitelist.RemoveDeviceWithAddress(kBluetoothAddress2));
EXPECT_TRUE(device_whitelist.HasDeviceWithAddress(kBluetoothAddress1));
EXPECT_TRUE(device_whitelist.HasDeviceWithPublicKey(kPublicKey1));
}
TEST_F(ProximityAuthBluetoothLowEnergyDeviceWhitelistTest,
RemoveDeviceWithPublicKey) {
BluetoothLowEnergyDeviceWhitelist device_whitelist(&pref_service_);
device_whitelist.AddOrUpdateDevice(kBluetoothAddress1, kPublicKey1);
CheckWhitelistedDevice(kBluetoothAddress1, kPublicKey1, device_whitelist);
ASSERT_TRUE(device_whitelist.RemoveDeviceWithPublicKey(kPublicKey1));
EXPECT_FALSE(device_whitelist.HasDeviceWithAddress(kBluetoothAddress1));
EXPECT_FALSE(device_whitelist.HasDeviceWithPublicKey(kPublicKey1));
}
TEST_F(ProximityAuthBluetoothLowEnergyDeviceWhitelistTest,
RemoveDeviceWithPublicKey_DeviceNotPresent) {
BluetoothLowEnergyDeviceWhitelist device_whitelist(&pref_service_);
device_whitelist.AddOrUpdateDevice(kBluetoothAddress1, kPublicKey1);
CheckWhitelistedDevice(kBluetoothAddress1, kPublicKey1, device_whitelist);
ASSERT_FALSE(device_whitelist.RemoveDeviceWithPublicKey(kPublicKey2));
EXPECT_TRUE(device_whitelist.HasDeviceWithAddress(kBluetoothAddress1));
EXPECT_TRUE(device_whitelist.HasDeviceWithPublicKey(kPublicKey1));
}
TEST_F(ProximityAuthBluetoothLowEnergyDeviceWhitelistTest, GetPublicKeys) {
BluetoothLowEnergyDeviceWhitelist device_whitelist(&pref_service_);
device_whitelist.AddOrUpdateDevice(kBluetoothAddress1, kPublicKey1);
CheckWhitelistedDevice(kBluetoothAddress1, kPublicKey1, device_whitelist);
device_whitelist.AddOrUpdateDevice(kBluetoothAddress2, kPublicKey2);
CheckWhitelistedDevice(kBluetoothAddress2, kPublicKey2, device_whitelist);
std::vector<std::string> public_keys = device_whitelist.GetPublicKeys();
// Note: it's not guarantee that the order in |public_key| is the same as
// insertion, so directly comparing vectors would not work.
EXPECT_TRUE(public_keys.size() == 2);
EXPECT_TRUE(std::find(public_keys.begin(), public_keys.end(), kPublicKey1) !=
public_keys.end());
EXPECT_TRUE(std::find(public_keys.begin(), public_keys.end(), kPublicKey2) !=
public_keys.end());
}
} // namespace proximity_auth
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/proximity_auth/ble/pref_names.h"
namespace proximity_auth {
namespace prefs {
// The dictionary containing whitelisted BLE devices used by
// proximity_auth::BluetoothLowEnergyDeviceWhitelist.
const char kBluetoothLowEnergyDeviceWhitelist[] =
"proximity_auth_bluetooth_low_energy_device_whitelist";
} // namespace prefs
} // namespace proximity_auth
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PROXIMITY_AUTH_BLE_PREF_NAMES_H
#define COMPONENTS_PROXIMITY_AUTH_BLE_PREF_NAMES_H
namespace proximity_auth {
namespace prefs {
extern const char kBluetoothLowEnergyDeviceWhitelist[];
} // namespace prefs
} // proximity_auth
#endif // COMPONENTS_PROXIMITY_AUTH_BLE_PREF_NAMES_H
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