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

Commit 187671df authored by Martin Brabham's avatar Martin Brabham Committed by Gerrit Code Review
Browse files

Merge changes from topic "gd_security_shim"

* changes:
  Add NameDbModule as dependency
  Additional trigger on IO Capability Response
  BTIF DM: Shim out link key management functions
parents 1b584540 820fbf9f
Loading
Loading
Loading
Loading
+65 −45
Original line number Diff line number Diff line
@@ -509,7 +509,7 @@ static void btif_update_remote_properties(const RawAddress& bdaddr,
                                          tBT_DEVICE_TYPE device_type) {
  int num_properties = 0;
  bt_property_t properties[3];
  bt_status_t status;
  bt_status_t status = BT_STATUS_UNHANDLED;
  uint32_t cod;
  bt_device_type_t dev_type;

@@ -519,10 +519,12 @@ static void btif_update_remote_properties(const RawAddress& bdaddr,
  if (strlen((const char*)bd_name)) {
    BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties], BT_PROPERTY_BDNAME,
                               strlen((char*)bd_name), bd_name);
    if (!bluetooth::shim::is_gd_security_enabled()) {
      status = btif_storage_set_remote_device_property(
          &bdaddr, &properties[num_properties]);
      ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device name",
              status);
    }
    num_properties++;
  }

@@ -545,10 +547,13 @@ static void btif_update_remote_properties(const RawAddress& bdaddr,

  BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
                             BT_PROPERTY_CLASS_OF_DEVICE, sizeof(cod), &cod);
  status = btif_storage_set_remote_device_property(&bdaddr,
                                                   &properties[num_properties]);

  if (!bluetooth::shim::is_gd_security_enabled()) {
    status = btif_storage_set_remote_device_property(
        &bdaddr, &properties[num_properties]);
    ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device class",
            status);
  }
  num_properties++;

  /* device type */
@@ -557,18 +562,21 @@ static void btif_update_remote_properties(const RawAddress& bdaddr,
  BTIF_STORAGE_FILL_PROPERTY(&prop_name, BT_PROPERTY_TYPE_OF_DEVICE,
                             sizeof(uint8_t), &remote_dev_type);
  if (btif_storage_get_remote_device_property(&bdaddr, &prop_name) ==
      BT_STATUS_SUCCESS)
      BT_STATUS_SUCCESS) {
    dev_type = (bt_device_type_t)(remote_dev_type | device_type);
  else
  } else {
    dev_type = (bt_device_type_t)device_type;
  }

  BTIF_STORAGE_FILL_PROPERTY(&properties[num_properties],
                             BT_PROPERTY_TYPE_OF_DEVICE, sizeof(dev_type),
                             &dev_type);
  status = btif_storage_set_remote_device_property(&bdaddr,
                                                   &properties[num_properties]);
  if (!bluetooth::shim::is_gd_security_enabled()) {
    status = btif_storage_set_remote_device_property(
        &bdaddr, &properties[num_properties]);
    ASSERTC(status == BT_STATUS_SUCCESS, "failed to save remote device type",
            status);
  }
  num_properties++;

  invoke_remote_device_properties_cb(status, bdaddr, num_properties,
@@ -885,6 +893,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
                   p_auth_cmpl->key_present);

  RawAddress bd_addr = p_auth_cmpl->bd_addr;
  if (!bluetooth::shim::is_gd_security_enabled()) {
    if ((p_auth_cmpl->success) && (p_auth_cmpl->key_present)) {
      if ((p_auth_cmpl->key_type < HCI_LKEY_TYPE_DEBUG_COMB) ||
          (p_auth_cmpl->key_type == HCI_LKEY_TYPE_AUTH_COMB) ||
@@ -911,6 +920,7 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
        }
      }
    }
  }

  if (p_auth_cmpl->success) {
    // We could have received a new link key without going through the pairing
@@ -928,7 +938,9 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
      return;
    }

    if (!bluetooth::shim::is_gd_security_enabled()) {
      btif_storage_set_remote_addr_type(&bd_addr, p_auth_cmpl->addr_type);
    }
    btif_update_remote_properties(p_auth_cmpl->bd_addr, p_auth_cmpl->bd_name,
                                  NULL, p_auth_cmpl->dev_type);
    pairing_cb.timeout_retries = 0;
@@ -1005,16 +1017,22 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
        break;

      case HCI_ERR_PAIRING_NOT_ALLOWED:
        is_bonded_device_removed =
            (btif_storage_remove_bonded_device(&bd_addr) == BT_STATUS_SUCCESS);
        if (!bluetooth::shim::is_gd_security_enabled()) {
          is_bonded_device_removed = (btif_storage_remove_bonded_device(
                                          &bd_addr) == BT_STATUS_SUCCESS);
        } else {
          is_bonded_device_removed = true;
        }
        status = BT_STATUS_AUTH_REJECTED;
        break;

      /* map the auth failure codes, so we can retry pairing if necessary */
      case HCI_ERR_AUTH_FAILURE:
      case HCI_ERR_KEY_MISSING:
        is_bonded_device_removed =
            (btif_storage_remove_bonded_device(&bd_addr) == BT_STATUS_SUCCESS);
        is_bonded_device_removed = (bluetooth::shim::is_gd_security_enabled())
                                       ? true
                                       : (btif_storage_remove_bonded_device(
                                              &bd_addr) == BT_STATUS_SUCCESS);
        [[fallthrough]];
      case HCI_ERR_HOST_REJECT_SECURITY:
      case HCI_ERR_ENCRY_MODE_NOT_ACCEPTABLE:
@@ -1045,8 +1063,10 @@ static void btif_dm_auth_cmpl_evt(tBTA_DM_AUTH_CMPL* p_auth_cmpl) {
      /* Remove Device as bonded in nvram as authentication failed */
      BTIF_TRACE_DEBUG("%s(): removing hid pointing device from nvram",
                       __func__);
      is_bonded_device_removed =
          (btif_storage_remove_bonded_device(&bd_addr) == BT_STATUS_SUCCESS);
      is_bonded_device_removed = (bluetooth::shim::is_gd_security_enabled())
                                     ? true
                                     : (btif_storage_remove_bonded_device(
                                            &bd_addr) == BT_STATUS_SUCCESS);
    }
    // Report bond state change to java only if we are bonding to a device or
    // a device is removed from the pairing list.
+7 −4
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:
@@ -230,7 +231,7 @@ void SecurityManagerImpl::HandleEvent(T packet) {
    auto bd_addr = packet.GetBdAddr();
    auto event_code = packet.GetEventCode();

    if (event_code != hci::EventCode::LINK_KEY_REQUEST) {
    if (event_code != hci::EventCode::LINK_KEY_REQUEST || event_code != hci::EventCode::IO_CAPABILITY_RESPONSE) {
      LOG_ERROR("No classic pairing handler for device '%s' ready for command %s ", bd_addr.ToString().c_str(),
                hci::EventCodeText(event_code).c_str());
      return;
@@ -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;

Loading