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

Commit b602606e authored by Jakub Pawlowski's avatar Jakub Pawlowski Committed by Myles Watson
Browse files

LE Security Cert Test: Set the initiator address correctly

Tag: #gd-refactor
Bug: 155399771
Test: gd/cert/run --host --test_filter=LeSecurityTest
Change-Id: If23576800e5e1d3cfa6958f51ad3aff5647fa10a
parent 01b62d81
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -51,9 +51,11 @@ class LeSecurityTest(GdBaseTestClass):
        self.cert_security = PyLeSecurity(self.cert)

        self.dut_address = common.BluetoothAddressWithType(
            address=common.BluetoothAddress(address=bytes(b'0D:05:04:03:02:01')), type=common.RANDOM_DEVICE_ADDRESS)
            address=common.BluetoothAddress(address=bytes(b'DD:05:04:03:02:01')), type=common.RANDOM_DEVICE_ADDRESS)
        self.dut.security.SetLeInitiatorAddress(self.dut_address)
        self.cert_address = common.BluetoothAddressWithType(
            address=common.BluetoothAddress(address=bytes(b'55:11:FF:AA:33:22')), type=common.RANDOM_DEVICE_ADDRESS)
            address=common.BluetoothAddress(address=bytes(b'C5:11:FF:AA:33:22')), type=common.RANDOM_DEVICE_ADDRESS)
        self.cert.security.SetLeInitiatorAddress(self.cert_address)

    def teardown_test(self):
        self.dut_security.close()
+11 −0
Original line number Diff line number Diff line
@@ -123,6 +123,17 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, public
    return ::grpc::Status::OK;
  }

  ::grpc::Status SetLeInitiatorAddress(
      ::grpc::ServerContext* context,
      const facade::BluetoothAddressWithType* request,
      ::google::protobuf::Empty* response) override {
    hci::Address peer;
    ASSERT(hci::Address::FromString(request->address().address(), peer));
    hci::AddressType peer_type = static_cast<hci::AddressType>(request->type());
    security_module_->GetSecurityManager()->SetLeInitiatorAddress(hci::AddressWithType(peer, peer_type));
    return ::grpc::Status::OK;
  }

  void DisplayPairingPrompt(const bluetooth::hci::AddressWithType& peer, std::string name) {
    LOG_INFO("%s", peer.ToString().c_str());
    UiMsg display_yes_no;
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ service SecurityModuleFacade {
  rpc SetIoCapability(IoCapabilityMessage) returns (google.protobuf.Empty) {}
  rpc SetAuthenticationRequirements(AuthenticationRequirementsMessage) returns (google.protobuf.Empty) {}
  rpc SetOobDataPresent(OobDataMessage) returns (google.protobuf.Empty) {}
  rpc SetLeInitiatorAddress(facade.BluetoothAddressWithType) returns (google.protobuf.Empty) {}
  rpc SendUiCallback(UiCallbackMsg) returns (google.protobuf.Empty) {}
  rpc FetchUiEvents(google.protobuf.Empty) returns (stream UiMsg) {}
  rpc FetchBondEvents(google.protobuf.Empty) returns (stream BondMsg) {}
+19 −5
Original line number Diff line number Diff line
@@ -118,6 +118,15 @@ void SecurityManagerImpl::SetUserInterfaceHandler(UI* user_interface, os::Handle
  user_interface_handler_ = handler;
}

void SecurityManagerImpl::SetLeInitiatorAddress(hci::AddressWithType address) {
  acl_manager_->SetPrivacyPolicyForInitiatorAddress(
      hci::LeAddressRotator::AddressPolicy::USE_STATIC_ADDRESS,
      address,
      crypto_toolbox::Octet16{},
      std::chrono::milliseconds{0},
      std::chrono::milliseconds{0});
}

void SecurityManagerImpl::RegisterCallbackListener(ISecurityManagerListener* listener, os::Handler* handler) {
  for (auto it = listeners_.begin(); it != listeners_.end(); ++it) {
    if (it->first == listener) {
@@ -393,14 +402,19 @@ void SecurityManagerImpl::OnConnectionFailureLe(bluetooth::l2cap::le::FixedChann
  NotifyDeviceBondFailed(pending_le_pairing_.address_, PairingFailure("Connection establishment failed"));
}

SecurityManagerImpl::SecurityManagerImpl(os::Handler* security_handler, l2cap::le::L2capLeModule* l2cap_le_module,
SecurityManagerImpl::SecurityManagerImpl(
    os::Handler* security_handler,
    l2cap::le::L2capLeModule* l2cap_le_module,
    channel::SecurityManagerChannel* security_manager_channel,
                                         hci::HciLayer* hci_layer)
    : security_handler_(security_handler), l2cap_le_module_(l2cap_le_module),
    hci::HciLayer* hci_layer,
    hci::AclManager* acl_manager)
    : security_handler_(security_handler),
      l2cap_le_module_(l2cap_le_module),
      l2cap_manager_le_(l2cap_le_module_->GetFixedChannelManager()),
      hci_security_interface_le_(
          hci_layer->GetLeSecurityInterface(security_handler_->BindOn(this, &SecurityManagerImpl::OnHciLeEvent))),
      security_manager_channel_(security_manager_channel) {
      security_manager_channel_(security_manager_channel),
      acl_manager_(acl_manager) {
  Init();

  l2cap_manager_le_->RegisterService(
+12 −2
Original line number Diff line number Diff line
@@ -46,8 +46,12 @@ namespace internal {

class SecurityManagerImpl : public channel::ISecurityManagerChannelListener, public UICallbacks {
 public:
  explicit SecurityManagerImpl(os::Handler* security_handler, l2cap::le::L2capLeModule* l2cap_le_module,
                               channel::SecurityManagerChannel* security_manager_channel, hci::HciLayer* hci_layer);
  explicit SecurityManagerImpl(
      os::Handler* security_handler,
      l2cap::le::L2capLeModule* l2cap_le_module,
      channel::SecurityManagerChannel* security_manager_channel,
      hci::HciLayer* hci_layer,
      hci::AclManager* acl_manager);
  ~SecurityManagerImpl() = default;

  // All APIs must be invoked in SM layer handler
@@ -97,6 +101,11 @@ class SecurityManagerImpl : public channel::ISecurityManagerChannelListener, pub
   */
  void SetUserInterfaceHandler(UI* user_interface, os::Handler* handler);

  /**
   * Specify the initiator address used for LE transport, used for tests only.
   */
  void SetLeInitiatorAddress(hci::AddressWithType address);

  /**
   * Register to listen for callback events from SecurityManager
   *
@@ -177,6 +186,7 @@ class SecurityManagerImpl : public channel::ISecurityManagerChannelListener, pub
  std::unique_ptr<l2cap::le::FixedChannelManager> l2cap_manager_le_;
  hci::LeSecurityInterface* hci_security_interface_le_ __attribute__((unused));
  channel::SecurityManagerChannel* security_manager_channel_;
  hci::AclManager* acl_manager_;
  record::SecurityRecordDatabase security_database_;
  std::unordered_map<hci::Address, std::shared_ptr<pairing::PairingHandler>> pairing_handler_map_;
  hci::IoCapability local_io_capability_ = kDefaultIoCapability;
Loading