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

Commit 2ba40a33 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Security UI interface cleanup am: 9af45cb8

Change-Id: I31cfb067bcc788dd2075483ccd4fae5816957867
parents acf0086d 9af45cb8
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -89,11 +89,12 @@ 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), passkey));
    i.user_interface_handler->Post(common::BindOnce(&UI::DisplayConfirmValue, common::Unretained(i.user_interface),
                                                    i.remote_connection_address, i.remote_name, passkey));
  } else {
    i.user_interface_handler->Post(
        common::BindOnce(&UI::DisplayEnterPasskeyDialog, common::Unretained(i.user_interface)));
    i.user_interface_handler->Post(common::BindOnce(&UI::DisplayEnterPasskeyDialog,
                                                    common::Unretained(i.user_interface), i.remote_connection_address,
                                                    i.remote_name));
    std::optional<PairingEvent> response = WaitUiPasskey();
    if (!response) return PairingFailure("Passkey did not arrive!");

+7 −6
Original line number Diff line number Diff line
@@ -283,12 +283,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), passkey));
    i.user_interface_handler->Post(common::BindOnce(&UI::DisplayPasskey, common::Unretained(i.user_interface),
                                                    i.remote_connection_address, i.remote_name, passkey));

  } 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.user_interface_handler->Post(common::BindOnce(&UI::DisplayEnterPasskeyDialog,
                                                    common::Unretained(i.user_interface), i.remote_connection_address,
                                                    i.remote_name));
    std::optional<PairingEvent> response = WaitUiPasskey();
    if (!response) return PairingFailure("Passkey did not arrive!");

@@ -403,8 +404,8 @@ 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), number_to_display));
  i.user_interface_handler->Post(common::BindOnce(&UI::DisplayConfirmValue, common::Unretained(i.user_interface),
                                                  i.remote_connection_address, i.remote_name, number_to_display));

  std::optional<PairingEvent> confirmyesno = WaitUiConfirmYesNo();
  if (!confirmyesno || confirmyesno->ui_value == 0) {
+5 −4
Original line number Diff line number Diff line
@@ -33,10 +33,11 @@ class UIMock : public UI {
  ~UIMock() override = default;

  MOCK_METHOD2(DisplayPairingPrompt, void(const bluetooth::hci::AddressWithType&, std::string));
  MOCK_METHOD1(CancelPairingPrompt, void(const bluetooth::hci::AddressWithType&));
  MOCK_METHOD1(DisplayConfirmValue, void(uint32_t));
  MOCK_METHOD0(DisplayEnterPasskeyDialog, void());
  MOCK_METHOD1(DisplayPasskey, void(uint32_t));
  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));

 private:
  DISALLOW_COPY_AND_ASSIGN(UIMock);
+26 −23
Original line number Diff line number Diff line
@@ -433,8 +433,9 @@ TEST_F(PairingHandlerPairTest, test_secure_connections_numeric_comparison) {

    RecordPairingPromptHandling(slave_user_interface, &pairing_handler_b);

    EXPECT_CALL(slave_user_interface, DisplayConfirmValue(_)).WillOnce(SaveArg<0>(&num_value_slave));
    EXPECT_CALL(master_user_interface, DisplayConfirmValue(_)).WillOnce(Invoke([&](uint32_t num_value) {
    EXPECT_CALL(slave_user_interface, DisplayConfirmValue(_, _, _)).WillOnce(SaveArg<2>(&num_value_slave));
    EXPECT_CALL(master_user_interface, DisplayConfirmValue(_, _, _))
        .WillOnce(Invoke([&](const bluetooth::hci::AddressWithType&, std::string, uint32_t num_value) {
          EXPECT_EQ(num_value_slave, num_value);
          if (num_value_slave == num_value) {
            pairing_handler_a->OnUiAction(PairingEvent::CONFIRM_YESNO, 0x01);
@@ -473,8 +474,9 @@ TEST_F(PairingHandlerPairTest, test_secure_connections_passkey_entry) {

    RecordPairingPromptHandling(slave_user_interface, &pairing_handler_b);

    EXPECT_CALL(slave_user_interface, DisplayPasskey(_)).WillOnce(SaveArg<0>(&passkey));
    EXPECT_CALL(master_user_interface, DisplayEnterPasskeyDialog()).WillOnce(Invoke([&]() {
    EXPECT_CALL(slave_user_interface, DisplayPasskey(_, _, _)).WillOnce(SaveArg<2>(&passkey));
    EXPECT_CALL(master_user_interface, DisplayEnterPasskeyDialog(_, _))
        .WillOnce(Invoke([&](const bluetooth::hci::AddressWithType& address, std::string name) {
          LOG_INFO("Passkey prompt displayed entering passkey: %08x", passkey);
          std::this_thread::sleep_for(1ms);

@@ -622,8 +624,9 @@ TEST_F(PairingHandlerPairTest, test_legacy_passkey_entry) {

    RecordPairingPromptHandling(slave_user_interface, &pairing_handler_b);

    EXPECT_CALL(slave_user_interface, DisplayEnterPasskeyDialog());
    EXPECT_CALL(master_user_interface, DisplayConfirmValue(_)).WillOnce(Invoke([&](uint32_t passkey) {
    EXPECT_CALL(slave_user_interface, DisplayEnterPasskeyDialog(_, _));
    EXPECT_CALL(master_user_interface, DisplayConfirmValue(_, _, _))
        .WillOnce(Invoke([&](const bluetooth::hci::AddressWithType&, std::string, uint32_t passkey) {
          LOG_INFO("Passkey prompt displayed entering passkey: %08x", passkey);
          std::this_thread::sleep_for(1ms);

+12 −8
Original line number Diff line number Diff line
@@ -28,21 +28,25 @@ class UI {
 public:
  virtual ~UI(){};

  /* Remote device tries to initiate pairing, ask user to confirm */
  /* Remote LE device tries to initiate pairing, ask user to confirm */
  virtual void DisplayPairingPrompt(const bluetooth::hci::AddressWithType& address, std::string name) = 0;

  /* Remove the pairing prompt from DisplayPairingPrompt, i.e. remote device disconnected, or some application requested
   * bond with this device */
  virtual void CancelPairingPrompt(const bluetooth::hci::AddressWithType& address) = 0;
  virtual void Cancel(const bluetooth::hci::AddressWithType& address) = 0;

  /* Display value for Comprision */
  virtual void DisplayConfirmValue(uint32_t numeric_value) = 0;
  /* Display value for Comprision, user responds yes/no */
  virtual void DisplayConfirmValue(const bluetooth::hci::AddressWithType& address, std::string name,
                                   uint32_t numeric_value) = 0;

  /* Display Yes/No dialog, Classic pairing, numeric comparison with NoInputNoOutput device */
  virtual void DisplayYesNoDialog(const bluetooth::hci::AddressWithType& address, std::string name) = 0;

  /* Display a dialog box that will let user enter the Passkey */
  virtual void DisplayEnterPasskeyDialog() = 0;
  virtual void DisplayEnterPasskeyDialog(const bluetooth::hci::AddressWithType& address, std::string name) = 0;

  /* Present the passkey value to the user */
  virtual void DisplayPasskey(uint32_t passkey) = 0;
  /* Present the passkey value to the user, user compares with other device */
  virtual void DisplayPasskey(const bluetooth::hci::AddressWithType& address, std::string name, uint32_t passkey) = 0;
};

/* Through this interface, UI provides us with user choices. */
@@ -54,7 +58,7 @@ class UICallbacks {
  virtual void OnPairingPromptAccepted(const bluetooth::hci::AddressWithType& address) = 0;

  /* User confirmed that displayed value matches the value on the other device */
  virtual void OnConfirmYesNo(const bluetooth::hci::AddressWithType& address, bool conformed) = 0;
  virtual void OnConfirmYesNo(const bluetooth::hci::AddressWithType& address, bool confirmed) = 0;

  /* User typed the value displayed on the other device. This is either Passkey or the Confirm value */
  virtual void OnPasskeyEntry(const bluetooth::hci::AddressWithType& address, uint32_t passkey) = 0;
Loading