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

Commit 6692e6da authored by Martin Brabham's avatar Martin Brabham
Browse files

{Py,Cert}Security: Add function to input pin code

Additionally, update the send_ui_callback to be internal
only.

Bug: 162984360
Tag: #gd-refactor
Test: cert/run --host SecurityTest
Change-Id: I088e55c883412e78accfb0d478ed0b2080871881
parent 8bcbc697
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ class PySecurity(Closable):
            auth_reqs, "ERROR"))
        self._device.security.SetAuthenticationRequirements(AuthenticationRequirementsMessage(requirement=auth_reqs))

    def send_ui_callback(self, address, callback_type, b, uid):
    def __send_ui_callback(self, address, callback_type, b, uid, pin):
        """
            Send a callback from the UI as if the user pressed a button on the dialog
        """
@@ -135,6 +135,7 @@ class PySecurity(Closable):
                message_type=callback_type,
                boolean=b,
                unique_id=uid,
                pin=bytes(pin),
                address=common.BluetoothAddressWithType(
                    address=common.BluetoothAddress(address=address),
                    type=common.BluetoothAddressTypeEnum.PUBLIC_DEVICE_ADDRESS)))
@@ -183,7 +184,14 @@ class PySecurity(Closable):
        assertThat(self._ui_event_stream).emits(get_unique_id)
        return passkey

    def on_user_input(self, cert_address, reply_boolean, expected_ui_event):
    def input_pin(self, cert_address, pin):
        """
            Respond to the UI event
        """
        self.on_user_input(
            cert_address=cert_address, reply_boolean=True, expected_ui_event=UiMsgType.DISPLAY_PIN_ENTRY, pin=pin)

    def on_user_input(self, cert_address, reply_boolean, expected_ui_event, pin=[]):
        """
            Respond to the UI event
        """
@@ -201,8 +209,8 @@ class PySecurity(Closable):

        logging.debug("DUT: Waiting for expected UI event")
        assertThat(self._ui_event_stream).emits(get_unique_id)
        # TODO(optedoblivion): Make UiCallbackType dynamic for PASSKEY when added
        self.send_ui_callback(cert_address, UiCallbackType.YES_NO, reply_boolean, ui_id)
        callback_type = UiCallbackType.YES_NO if len(pin) == 0 else UiCallbackType.PIN
        self.__send_ui_callback(cert_address, callback_type, reply_boolean, ui_id, pin)

    def get_address(self):
        return self._device.address
+20 −1
Original line number Diff line number Diff line
@@ -74,6 +74,9 @@ class CertSecurity(PySecurity):

    _hci = None

    MAX_PIN_LENGTH = 16
    MIN_PIN_LENGTH = 1

    def _enqueue_hci_command(self, command, expect_complete):
        if (expect_complete):
            self._hci.send_command_with_complete(command)
@@ -230,7 +233,23 @@ class CertSecurity(PySecurity):
            True)
        self._enqueue_hci_command(hci_packets.UserPasskeyRequestReplyBuilder(peer, passkey), True)

    def send_ui_callback(self, address, callback_type, b, uid):
    def input_pin(self, address, pin):
        """
            Pretend to answer the pairing dialog as a user
        """
        if len(pin) > self.MAX_PIN_LENGTH or len(pin) < self.MIN_PIN_LENGTH:
            raise Exception("Pin code must be within range")
        logging.info("Cert: Waiting for PIN request")
        assertThat(self._hci_event_stream).emits(HciMatchers.EventWithCode(hci_packets.EventCode.PIN_CODE_REQUEST))
        logging.info("Cert: Send user input PIN %s for %s" % (pin.decode(), address))
        peer = address.decode('utf-8')
        pin_list = list(pin)
        # Pad
        for i in range(self.MAX_PIN_LENGTH - len(pin_list)):
            pin_list.append(0)
        self._enqueue_hci_command(hci_packets.PinCodeRequestReplyBuilder(peer, len(pin), pin_list), True)

    def __send_ui_callback(self, address, callback_type, b, uid, pin):
        """
            Pretend to answer the pairing dailog as a user
        """