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

Commit 1360b517 authored by Martin Brabham's avatar Martin Brabham
Browse files

Introduce ConfirmationData

ConfirmationData is an object to contain information
for passing to the UI via Display* functions defined
in the class Ui.

This consolidates the required function signature from 2-3 arguments
down to a single argument.  Additionally, we gain a feature
for putting and getting extra data.  This extra data mechanism
will allow for the SecurityModule to pass information to the shim
such as:

    - IO Capability
    - Authentication Requirements
    - MITM bit

It is required that we map these in the shim and pass them back to
BTA in order to drive the BTA state machine properly.

BYPASS_INCLUSIVE_LANGUAGE_REASON="following bluetooth specification terms"

Bug: 162984360
Tag: #gd-refactor
Test: cert/run --host SecurityTest
Change-Id: I30b19fb5a3d5fa3462cf4fdc5f47df5d5bb4c478
parent 09d1ba66
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -339,8 +339,10 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, public
    ui_events_.OnIncomingEvent(display_yes_no);
  }

  virtual void DisplayConfirmValue(const bluetooth::hci::AddressWithType& peer, std::string name,
                                   uint32_t numeric_value) {
  virtual void DisplayConfirmValue(ConfirmationData data) {
    const bluetooth::hci::AddressWithType& peer = data.GetAddressWithType();
    std::string name = data.GetName();
    uint32_t numeric_value = data.GetNumericValue();
    LOG_INFO("%s value = 0x%x", peer.ToString().c_str(), numeric_value);
    UiMsg display_with_value;
    *display_with_value.mutable_peer() = ToFacadeAddressWithType(peer);
@@ -350,7 +352,9 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, public
    ui_events_.OnIncomingEvent(display_with_value);
  }

  void DisplayYesNoDialog(const bluetooth::hci::AddressWithType& peer, std::string name) override {
  void DisplayYesNoDialog(ConfirmationData data) override {
    const bluetooth::hci::AddressWithType& peer = data.GetAddressWithType();
    std::string name = data.GetName();
    LOG_INFO("%s", peer.ToString().c_str());
    UiMsg display_yes_no;
    *display_yes_no.mutable_peer() = ToFacadeAddressWithType(peer);
@@ -359,7 +363,10 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, public
    ui_events_.OnIncomingEvent(display_yes_no);
  }

  void DisplayPasskey(const bluetooth::hci::AddressWithType& peer, std::string name, uint32_t passkey) override {
  void DisplayPasskey(ConfirmationData data) override {
    const bluetooth::hci::AddressWithType& peer = data.GetAddressWithType();
    std::string name = data.GetName();
    uint32_t passkey = data.GetNumericValue();
    LOG_INFO("%s value = 0x%x", peer.ToString().c_str(), passkey);
    UiMsg display_passkey;
    *display_passkey.mutable_peer() = ToFacadeAddressWithType(peer);
@@ -369,7 +376,9 @@ class SecurityModuleFacadeService : public SecurityModuleFacade::Service, public
    ui_events_.OnIncomingEvent(display_passkey);
  }

  void DisplayEnterPasskeyDialog(const bluetooth::hci::AddressWithType& peer, std::string name) override {
  void DisplayEnterPasskeyDialog(ConfirmationData data) override {
    const bluetooth::hci::AddressWithType& peer = data.GetAddressWithType();
    std::string name = data.GetName();
    LOG_INFO("%s", peer.ToString().c_str());
    UiMsg display_passkey_input;
    *display_passkey_input.mutable_peer() = ToFacadeAddressWithType(peer);
+8 −8
Original line number Diff line number Diff line
@@ -26,26 +26,26 @@ namespace pairing {

void ClassicPairingHandler::NotifyUiDisplayYesNo(uint32_t numeric_value) {
  ASSERT(user_interface_handler_ != nullptr);
  user_interface_handler_->CallOn(
      user_interface_, &UI::DisplayConfirmValue, *GetRecord()->GetPseudoAddress(), device_name_, numeric_value);
  ConfirmationData data(*GetRecord()->GetPseudoAddress(), device_name_, numeric_value);
  user_interface_handler_->CallOn(user_interface_, &UI::DisplayConfirmValue, data);
}

void ClassicPairingHandler::NotifyUiDisplayYesNo() {
  ASSERT(user_interface_handler_ != nullptr);
  user_interface_handler_->CallOn(
      user_interface_, &UI::DisplayYesNoDialog, *GetRecord()->GetPseudoAddress(), device_name_);
  ConfirmationData data(*GetRecord()->GetPseudoAddress(), device_name_);
  user_interface_handler_->CallOn(user_interface_, &UI::DisplayYesNoDialog, data);
}

void ClassicPairingHandler::NotifyUiDisplayPasskey(uint32_t passkey) {
  ASSERT(user_interface_handler_ != nullptr);
  user_interface_handler_->CallOn(
      user_interface_, &UI::DisplayPasskey, *GetRecord()->GetPseudoAddress(), device_name_, passkey);
  ConfirmationData data(*GetRecord()->GetPseudoAddress(), device_name_, passkey);
  user_interface_handler_->CallOn(user_interface_, &UI::DisplayPasskey, data);
}

void ClassicPairingHandler::NotifyUiDisplayPasskeyInput() {
  ASSERT(user_interface_handler_ != nullptr);
  user_interface_handler_->CallOn(
      user_interface_, &UI::DisplayEnterPasskeyDialog, *GetRecord()->GetPseudoAddress(), device_name_);
  ConfirmationData data(*GetRecord()->GetPseudoAddress(), device_name_);
  user_interface_handler_->CallOn(user_interface_, &UI::DisplayEnterPasskeyDialog, data);
}

void ClassicPairingHandler::NotifyUiDisplayCancel() {
+7 −6
Original line number Diff line number Diff line
@@ -93,12 +93,13 @@ LegacyStage1ResultOrFailure PairingHandlerLe::LegacyPasskeyEntry(const InitialIn
    constexpr uint32_t PASSKEY_MAX = 999999;
    if (passkey > PASSKEY_MAX) passkey >>= 1;

    i.user_interface_handler->Post(common::BindOnce(&UI::DisplayConfirmValue, common::Unretained(i.user_interface),
                                                    i.remote_connection_address, i.remote_name, passkey));
    ConfirmationData data(i.remote_connection_address, i.remote_name, passkey);
    i.user_interface_handler->Post(
        common::BindOnce(&UI::DisplayConfirmValue, common::Unretained(i.user_interface), data));
  } else {
    i.user_interface_handler->Post(common::BindOnce(&UI::DisplayEnterPasskeyDialog,
                                                    common::Unretained(i.user_interface), i.remote_connection_address,
                                                    i.remote_name));
    ConfirmationData data(i.remote_connection_address, i.remote_name);
    i.user_interface_handler->Post(
        common::BindOnce(&UI::DisplayEnterPasskeyDialog, common::Unretained(i.user_interface), data));
    std::optional<PairingEvent> response = WaitUiPasskey();
    if (!response) return PairingFailure("Passkey did not arrive!");

+9 −8
Original line number Diff line number Diff line
@@ -288,13 +288,13 @@ Stage1ResultOrFailure PairingHandlerLe::SecureConnectionsPasskeyEntry(const Init
    constexpr uint32_t PASSKEY_MAX = 999999;
    while (passkey > PASSKEY_MAX) passkey >>= 1;

    i.user_interface_handler->Post(common::BindOnce(&UI::DisplayPasskey, common::Unretained(i.user_interface),
                                                    i.remote_connection_address, i.remote_name, passkey));
    ConfirmationData data(i.remote_connection_address, i.remote_name, passkey);
    i.user_interface_handler->Post(common::BindOnce(&UI::DisplayPasskey, common::Unretained(i.user_interface), data));

  } else if (my_iocaps == IoCapability::KEYBOARD_ONLY || remote_iocaps == IoCapability::DISPLAY_ONLY) {
    i.user_interface_handler->Post(common::BindOnce(&UI::DisplayEnterPasskeyDialog,
                                                    common::Unretained(i.user_interface), i.remote_connection_address,
                                                    i.remote_name));
    ConfirmationData data(i.remote_connection_address, i.remote_name);
    i.user_interface_handler->Post(
        common::BindOnce(&UI::DisplayEnterPasskeyDialog, common::Unretained(i.user_interface), data));
    std::optional<PairingEvent> response = WaitUiPasskey();
    if (!response) return PairingFailure("Passkey did not arrive!");

@@ -409,8 +409,9 @@ Stage1ResultOrFailure PairingHandlerLe::SecureConnectionsNumericComparison(const

  uint32_t number_to_display = crypto_toolbox::g2((uint8_t*)PKa.x.data(), (uint8_t*)PKb.x.data(), Na, Nb);

  i.user_interface_handler->Post(common::BindOnce(&UI::DisplayConfirmValue, common::Unretained(i.user_interface),
                                                  i.remote_connection_address, i.remote_name, number_to_display));
  ConfirmationData data(i.remote_connection_address, i.remote_name, number_to_display);
  i.user_interface_handler->Post(
      common::BindOnce(&UI::DisplayConfirmValue, common::Unretained(i.user_interface), data));

  std::optional<PairingEvent> confirmyesno = WaitUiConfirmYesNo();
  if (!confirmyesno || confirmyesno->ui_value == 0) {
+7 −6
Original line number Diff line number Diff line
@@ -32,12 +32,13 @@ class UIMock : public UI {
  UIMock() {}
  ~UIMock() override = default;

  MOCK_METHOD2(DisplayPairingPrompt, void(const bluetooth::hci::AddressWithType&, std::string));
  MOCK_METHOD1(Cancel, void(const bluetooth::hci::AddressWithType&));
  MOCK_METHOD3(DisplayConfirmValue, void(const bluetooth::hci::AddressWithType&, std::string, uint32_t));
  MOCK_METHOD2(DisplayYesNoDialog, void(const bluetooth::hci::AddressWithType&, std::string));
  MOCK_METHOD2(DisplayEnterPasskeyDialog, void(const bluetooth::hci::AddressWithType&, std::string));
  MOCK_METHOD3(DisplayPasskey, void(const bluetooth::hci::AddressWithType&, std::string, uint32_t));
  // Convert these to accept ConfirmationData
  MOCK_METHOD2(DisplayPairingPrompt, void(const bluetooth::hci::AddressWithType& address, std::string name));
  MOCK_METHOD1(Cancel, void(const bluetooth::hci::AddressWithType& address));
  MOCK_METHOD1(DisplayConfirmValue, void(ConfirmationData));
  MOCK_METHOD1(DisplayYesNoDialog, void(ConfirmationData));
  MOCK_METHOD1(DisplayEnterPasskeyDialog, void(ConfirmationData));
  MOCK_METHOD1(DisplayPasskey, void(ConfirmationData));

 private:
  DISALLOW_COPY_AND_ASSIGN(UIMock);
Loading