Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 820fbf9f authored by Martin Brabham's avatar Martin Brabham
Browse files

Add NameDbModule as dependency

Bug: 162984360
Tag: #gd-refactor
Test: cert/run --host SecurityTest
Test: atest --host bluetooth_test_gd
Test: Manual testing with hybrid stack
Change-Id: I6524577d1395d8fb82f5ec5ed6a53fe7dac97f06
parent baee26c4
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -56,7 +56,8 @@ void SecurityManagerImpl::DispatchPairingHandler(
          std::move(callback),
          user_interface_,
          user_interface_handler_,
          "TODO: grab device name properly");
          record->GetPseudoAddress()->ToString(),
          name_db_module_);
      break;
    }
    default:
@@ -626,7 +627,8 @@ SecurityManagerImpl::SecurityManagerImpl(
    channel::SecurityManagerChannel* security_manager_channel,
    hci::HciLayer* hci_layer,
    hci::AclManager* acl_manager,
    storage::StorageModule* storage_module)
    storage::StorageModule* storage_module,
    neighbor::NameDbModule* name_db_module)
    : security_handler_(security_handler),
      l2cap_le_module_(l2cap_le_module),
      l2cap_manager_le_(l2cap_le_module_->GetFixedChannelManager()),
@@ -636,7 +638,8 @@ SecurityManagerImpl::SecurityManagerImpl(
      acl_manager_(acl_manager),
      storage_module_(storage_module),
      security_record_storage_(storage_module, security_handler),
      security_database_(security_record_storage_) {
      security_database_(security_record_storage_),
      name_db_module_(name_db_module) {
  Init();

  l2cap_manager_le_->RegisterService(
+4 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include "l2cap/classic/security_enforcement_interface.h"
#include "l2cap/le/l2cap_le_module.h"
#include "l2cap/le/security_enforcement_interface.h"
#include "neighbor/name_db.h"
#include "os/handler.h"
#include "security/channel/security_manager_channel.h"
#include "security/initial_informations.h"
@@ -57,7 +58,8 @@ class SecurityManagerImpl : public channel::ISecurityManagerChannelListener, pub
      channel::SecurityManagerChannel* security_manager_channel,
      hci::HciLayer* hci_layer,
      hci::AclManager* acl_manager,
      storage::StorageModule* storage_module);
      storage::StorageModule* storage_module,
      neighbor::NameDbModule* name_db_module);

  ~SecurityManagerImpl() {
    /* L2CAP layer doesn't guarantee to send the registered OnCloseCallback during shutdown. Cleanup the remaining
@@ -239,6 +241,7 @@ class SecurityManagerImpl : public channel::ISecurityManagerChannelListener, pub
  storage::StorageModule* storage_module_ __attribute__((unused));
  record::SecurityRecordStorage security_record_storage_;
  record::SecurityRecordDatabase security_database_;
  neighbor::NameDbModule* name_db_module_;
  std::unordered_map<hci::Address, std::shared_ptr<pairing::PairingHandler>> pairing_handler_map_;
  hci::IoCapability local_io_capability_ = kDefaultIoCapability;
  hci::AuthenticationRequirements local_authentication_requirements_ = kDefaultAuthenticationRequirements;
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include "security/pairing/classic_pairing_handler.h"

#include "common/bind.h"
#include "neighbor/name.h"

namespace bluetooth {
namespace security {
+19 −9
Original line number Diff line number Diff line
@@ -35,17 +35,27 @@ namespace pairing {

class ClassicPairingHandler : public PairingHandler {
 public:
  ClassicPairingHandler(channel::SecurityManagerChannel* security_manager_channel,
                        std::shared_ptr<record::SecurityRecord> record, os::Handler* security_handler,
  ClassicPairingHandler(
      channel::SecurityManagerChannel* security_manager_channel,
      std::shared_ptr<record::SecurityRecord> record,
      os::Handler* security_handler,
      common::OnceCallback<void(hci::Address, PairingResultOrFailure)> complete_callback,
                        UI* user_interface, os::Handler* user_interface_handler, std::string device_name)
      : PairingHandler(security_manager_channel, std::move(record)), security_handler_(security_handler),
        remote_io_capability_(hci::IoCapability::DISPLAY_YES_NO), remote_oob_present_(hci::OobDataPresent::NOT_PRESENT),
      UI* user_interface,
      os::Handler* user_interface_handler,
      std::string device_name,
      neighbor::NameDbModule* name_db_module)
      : PairingHandler(security_manager_channel, std::move(record), name_db_module),
        security_handler_(security_handler),
        remote_io_capability_(hci::IoCapability::DISPLAY_YES_NO),
        remote_oob_present_(hci::OobDataPresent::NOT_PRESENT),
        remote_authentication_requirements_(hci::AuthenticationRequirements::DEDICATED_BONDING_MITM_PROTECTION),
        local_io_capability_(hci::IoCapability::DISPLAY_YES_NO), local_oob_present_(hci::OobDataPresent::NOT_PRESENT),
        local_io_capability_(hci::IoCapability::DISPLAY_YES_NO),
        local_oob_present_(hci::OobDataPresent::NOT_PRESENT),
        local_authentication_requirements_(hci::AuthenticationRequirements::DEDICATED_BONDING_MITM_PROTECTION),
        complete_callback_(std::move(complete_callback)), user_interface_(user_interface),
        user_interface_handler_(user_interface_handler), device_name_(std::move(device_name)) {}
        complete_callback_(std::move(complete_callback)),
        user_interface_(user_interface),
        user_interface_handler_(user_interface_handler),
        device_name_(std::move(device_name)) {}

  ~ClassicPairingHandler() override = default;

+14 −3
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@
#include "security/initial_informations.h"
#include "security/smp_packets.h"
#include "security/test/fake_hci_layer.h"
#include "security/test/fake_name_db.h"
#include "security/test/fake_security_interface.h"

namespace bluetooth {
@@ -138,13 +139,21 @@ class ClassicPairingHandlerTest : public ::testing::Test {
 protected:
  void SetUp() override {
    hci_layer_ = new FakeHciLayer();
    name_db_module_ = new FakeNameDbModule();
    fake_registry_.InjectTestModule(&FakeHciLayer::Factory, hci_layer_);
    fake_registry_.InjectTestModule(&neighbor::NameDbModule::Factory, name_db_module_);
    handler_ = fake_registry_.GetTestModuleHandler(&FakeHciLayer::Factory);
    channel_ = new FakeSecurityManagerChannel(handler_, hci_layer_);
    security_record_ = std::make_shared<record::SecurityRecord>(device_);
    pairing_handler_ = new pairing::ClassicPairingHandler(channel_, security_record_, handler_,
                                                          common::Bind(&pairing_complete_callback), user_interface_,
                                                          user_interface_handler_, "Fake name");
    pairing_handler_ = new pairing::ClassicPairingHandler(
        channel_,
        security_record_,
        handler_,
        common::Bind(&pairing_complete_callback),
        user_interface_,
        user_interface_handler_,
        "Fake name",
        name_db_module_);
    channel_callback_ = new SecurityManagerChannelCallback(pairing_handler_);
    channel_->SetChannelListener(channel_callback_);
    security_interface_ = new FakeSecurityInterface(handler_, channel_);
@@ -163,6 +172,7 @@ class ClassicPairingHandlerTest : public ::testing::Test {

  void synchronize() {
    fake_registry_.SynchronizeModuleHandler(&FakeHciLayer::Factory, std::chrono::milliseconds(20));
    fake_registry_.SynchronizeModuleHandler(&FakeNameDbModule::Factory, std::chrono::milliseconds(20));
  }

  void ReceiveLinkKeyRequest(hci::AddressWithType device) {
@@ -210,6 +220,7 @@ class ClassicPairingHandlerTest : public ::testing::Test {
  UI* user_interface_;
  os::Handler* user_interface_handler_;
  l2cap::classic::SecurityInterface* security_interface_ = nullptr;
  FakeNameDbModule* name_db_module_ = nullptr;
};

// Security Manager Boot Sequence (Required for SSP, these are already set at boot time)
Loading