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

Commit 97897fbb authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge changes from topic "gd_security_shim"

* changes:
  GD Security: pipe in determined just_works flag
  GD Security Shim: Make ConfirmationData have strict types
parents f1c903b8 c8931851
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -27,36 +27,36 @@ namespace pairing {
void ClassicPairingHandler::NotifyUiDisplayYesNo(uint32_t numeric_value) {
  ASSERT(user_interface_handler_ != nullptr);
  ConfirmationData data(*GetRecord()->GetPseudoAddress(), device_name_, numeric_value);
  data.PutExtraData("remote_io_caps", hci::IoCapabilityText(remote_io_capability_));
  data.PutExtraData("remote_auth_reqs", hci::AuthenticationRequirementsText(remote_authentication_requirements_));
  data.PutExtraData("remote_oob_data_present", hci::OobDataPresentText(remote_oob_present_));
  data.SetRemoteIoCaps(remote_io_capability_);
  data.SetRemoteAuthReqs(remote_authentication_requirements_);
  data.SetRemoteOobDataPresent(remote_oob_present_);
  user_interface_handler_->CallOn(user_interface_, &UI::DisplayConfirmValue, data);
}

void ClassicPairingHandler::NotifyUiDisplayYesNo() {
  ASSERT(user_interface_handler_ != nullptr);
  ConfirmationData data(*GetRecord()->GetPseudoAddress(), device_name_);
  data.PutExtraData("remote_io_caps", hci::IoCapabilityText(remote_io_capability_));
  data.PutExtraData("remote_auth_reqs", hci::AuthenticationRequirementsText(remote_authentication_requirements_));
  data.PutExtraData("remote_oob_data_present", hci::OobDataPresentText(remote_oob_present_));
  data.SetRemoteIoCaps(remote_io_capability_);
  data.SetRemoteAuthReqs(remote_authentication_requirements_);
  data.SetRemoteOobDataPresent(remote_oob_present_);
  user_interface_handler_->CallOn(user_interface_, &UI::DisplayYesNoDialog, data);
}

void ClassicPairingHandler::NotifyUiDisplayPasskey(uint32_t passkey) {
  ASSERT(user_interface_handler_ != nullptr);
  ConfirmationData data(*GetRecord()->GetPseudoAddress(), device_name_, passkey);
  data.PutExtraData("remote_io_caps", hci::IoCapabilityText(remote_io_capability_));
  data.PutExtraData("remote_auth_reqs", hci::AuthenticationRequirementsText(remote_authentication_requirements_));
  data.PutExtraData("remote_oob_data_present", hci::OobDataPresentText(remote_oob_present_));
  data.SetRemoteIoCaps(remote_io_capability_);
  data.SetRemoteAuthReqs(remote_authentication_requirements_);
  data.SetRemoteOobDataPresent(remote_oob_present_);
  user_interface_handler_->CallOn(user_interface_, &UI::DisplayPasskey, data);
}

void ClassicPairingHandler::NotifyUiDisplayPasskeyInput() {
  ASSERT(user_interface_handler_ != nullptr);
  ConfirmationData data(*GetRecord()->GetPseudoAddress(), device_name_);
  data.PutExtraData("remote_io_caps", hci::IoCapabilityText(remote_io_capability_));
  data.PutExtraData("remote_auth_reqs", hci::AuthenticationRequirementsText(remote_authentication_requirements_));
  data.PutExtraData("remote_oob_data_present", hci::OobDataPresentText(remote_oob_present_));
  data.SetRemoteIoCaps(remote_io_capability_);
  data.SetRemoteAuthReqs(remote_authentication_requirements_);
  data.SetRemoteOobDataPresent(remote_oob_present_);
  user_interface_handler_->CallOn(user_interface_, &UI::DisplayEnterPasskeyDialog, data);
}

+31 −12
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@

#pragma once

#include <unordered_map>

#include "hci/address_with_type.h"

namespace bluetooth {
@@ -45,17 +43,35 @@ class ConfirmationData {
    return numeric_value_;
  }

  void PutExtraData(std::string key, std::string value) {
    extra_data_map_.emplace(key, value);
  hci::IoCapability GetRemoteIoCaps() const {
    return remote_io_caps_;
  }
  void SetRemoteIoCaps(hci::IoCapability remote_io_caps) {
    remote_io_caps_ = remote_io_caps;
  }

  hci::AuthenticationRequirements GetRemoteAuthReqs() const {
    return remote_auth_reqs_;
  }

  void SetRemoteAuthReqs(hci::AuthenticationRequirements remote_auth_reqs) {
    remote_auth_reqs_ = remote_auth_reqs;
  }

  std::string GetExtraData(std::string key) {
    auto entry = extra_data_map_.find(key);
    if (entry == extra_data_map_.end()) {
      LOG_WARN("Unknown key '%s'", key.c_str());
      return "No Data Set for Key";
  hci::OobDataPresent GetRemoteOobDataPresent() const {
    return remote_oob_data_present_;
  }
    return entry->second;

  void SetRemoteOobDataPresent(hci::OobDataPresent remote_oob_data_present) {
    remote_oob_data_present_ = remote_oob_data_present;
  }

  bool IsJustWorks() const {
    return just_works_;
  }

  void SetJustWorks(bool just_works) {
    just_works_ = just_works;
  }

 private:
@@ -66,7 +82,10 @@ class ConfirmationData {

  // TODO(optedoblivion): Revisit after shim/BTA layer is gone
  // Extra data is a hack to get data from the module to the shim
  std::unordered_map<std::string, std::string> extra_data_map_;
  hci::IoCapability remote_io_caps_ = hci::IoCapability::DISPLAY_YES_NO;
  hci::AuthenticationRequirements remote_auth_reqs_ = hci::AuthenticationRequirements::DEDICATED_BONDING;
  hci::OobDataPresent remote_oob_data_present_ = hci::OobDataPresent::NOT_PRESENT;
  bool just_works_ = false;
};

// Through this interface we talk to the user, asking for confirmations/acceptance.
+26 −41
Original line number Diff line number Diff line
@@ -240,42 +240,28 @@ namespace {
std::unordered_map<bluetooth::hci::AddressWithType, bt_bdname_t>
    address_name_map_;

std::unordered_map<std::string, int> gd_legacy_io_caps_map_ = {
    {bluetooth::hci::IoCapabilityText(
         bluetooth::hci::IoCapability::DISPLAY_ONLY),
     BTM_IO_CAP_OUT},
    {bluetooth::hci::IoCapabilityText(
         bluetooth::hci::IoCapability::DISPLAY_YES_NO),
     BTM_IO_CAP_IO},
    {bluetooth::hci::IoCapabilityText(
         bluetooth::hci::IoCapability::KEYBOARD_ONLY),
     BTM_IO_CAP_IN},
    {bluetooth::hci::IoCapabilityText(
         bluetooth::hci::IoCapability::NO_INPUT_NO_OUTPUT),
     BTM_IO_CAP_NONE},
std::unordered_map<bluetooth::hci::IoCapability, int> gd_legacy_io_caps_map_ = {
    {bluetooth::hci::IoCapability::DISPLAY_ONLY, BTM_IO_CAP_OUT},
    {bluetooth::hci::IoCapability::DISPLAY_YES_NO, BTM_IO_CAP_IO},
    {bluetooth::hci::IoCapability::KEYBOARD_ONLY, BTM_IO_CAP_IN},
    {bluetooth::hci::IoCapability::NO_INPUT_NO_OUTPUT, BTM_IO_CAP_NONE},
};

std::unordered_map<std::string, int> gd_legacy_auth_reqs_map_ = {
    {bluetooth::hci::AuthenticationRequirementsText(
         bluetooth::hci::AuthenticationRequirements::NO_BONDING),
std::unordered_map<bluetooth::hci::AuthenticationRequirements, int>
    gd_legacy_auth_reqs_map_ = {
        {bluetooth::hci::AuthenticationRequirements::NO_BONDING,
         BTM_AUTH_SP_NO},
    {bluetooth::hci::AuthenticationRequirementsText(
         bluetooth::hci::AuthenticationRequirements::
             NO_BONDING_MITM_PROTECTION),
        {bluetooth::hci::AuthenticationRequirements::NO_BONDING_MITM_PROTECTION,
         BTM_AUTH_SP_YES},
    {bluetooth::hci::AuthenticationRequirementsText(
         bluetooth::hci::AuthenticationRequirements::DEDICATED_BONDING),
        {bluetooth::hci::AuthenticationRequirements::DEDICATED_BONDING,
         BTM_AUTH_AP_NO},
    {bluetooth::hci::AuthenticationRequirementsText(
         bluetooth::hci::AuthenticationRequirements::
             DEDICATED_BONDING_MITM_PROTECTION),
        {bluetooth::hci::AuthenticationRequirements::
             DEDICATED_BONDING_MITM_PROTECTION,
         BTM_AUTH_AP_YES},
    {bluetooth::hci::AuthenticationRequirementsText(
         bluetooth::hci::AuthenticationRequirements::GENERAL_BONDING),
        {bluetooth::hci::AuthenticationRequirements::GENERAL_BONDING,
         BTM_AUTH_SPGB_NO},
    {bluetooth::hci::AuthenticationRequirementsText(
         bluetooth::hci::AuthenticationRequirements::
             GENERAL_BONDING_MITM_PROTECTION),
        {bluetooth::hci::AuthenticationRequirements::
             GENERAL_BONDING_MITM_PROTECTION,
         BTM_AUTH_SPGB_YES},
};
}
@@ -350,10 +336,9 @@ class ShimUi : public bluetooth::security::UI {
      // Call sp_cback for IO_RSP
      tBTM_SP_IO_RSP io_rsp_evt_data;
      io_rsp_evt_data.bd_addr = bluetooth::ToRawAddress(address.GetAddress());
      io_rsp_evt_data.io_cap =
          gd_legacy_io_caps_map_[data.GetExtraData("remote_io_caps")];
      io_rsp_evt_data.io_cap = gd_legacy_io_caps_map_[data.GetRemoteIoCaps()];
      io_rsp_evt_data.auth_req =
          gd_legacy_auth_reqs_map_[data.GetExtraData("remote_auth_reqs")];
          gd_legacy_auth_reqs_map_[data.GetRemoteAuthReqs()];
      io_rsp_evt_data.auth_req = BTM_AUTH_AP_YES;
      io_rsp_evt_data.oob_data = BTM_OOB_NONE;
      (*bta_callbacks_->p_sp_callback)(BTM_SP_IO_RSP_EVT,
@@ -365,14 +350,12 @@ class ShimUi : public bluetooth::security::UI {
          bluetooth::ToRawAddress(address.GetAddress());
      user_cfm_req_evt_data.cfm_req.num_val = numeric_value;
      // If we pop a dialog then it isn't just_works
      user_cfm_req_evt_data.cfm_req.just_works = false;
      user_cfm_req_evt_data.cfm_req.just_works = data.IsJustWorks();

      address_name_map_.emplace(address, legacy_name);
      memcpy((char*)user_cfm_req_evt_data.cfm_req.bd_name, legacy_name.name,
             BD_NAME_LEN);

      // TODO(optedoblivion): BTA needs a callback for when just works auto
      // accepted (i.e. =true)
      (*bta_callbacks_->p_sp_callback)(BTM_SP_CFM_REQ_EVT,
                                       &user_cfm_req_evt_data);
    }
@@ -380,11 +363,13 @@ class ShimUi : public bluetooth::security::UI {

  void DisplayConfirmValue(bluetooth::security::ConfirmationData data) {
    waiting_for_pairing_prompt_ = false;
    data.SetJustWorks(false);
    HandleConfirm(data);
  }

  void DisplayYesNoDialog(bluetooth::security::ConfirmationData data) {
    waiting_for_pairing_prompt_ = false;
    data.SetJustWorks(true);
    HandleConfirm(data);
  }