Loading system/gd/cert/matchers.py +36 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,42 @@ class HciMatchers(object): return None return hci_event @staticmethod def LinkKeyRequest(): return lambda event: HciMatchers.EventWithCode(EventCode.LINK_KEY_REQUEST) @staticmethod def IoCapabilityRequest(): return lambda event: HciMatchers.EventWithCode(EventCode.IO_CAPABILITY_REQUEST) @staticmethod def IoCapabilityResponse(): return lambda event: HciMatchers.EventWithCode(EventCode.IO_CAPABILITY_RESPONSE) @staticmethod def UserPasskeyNotification(): return lambda event: HciMatchers.EventWithCode(EventCode.USER_PASSKEY_NOTIFICATION) @staticmethod def UserPasskeyRequest(): return lambda event: HciMatchers.EventWithCode(EventCode.USER_PASSKEY_REQUEST) @staticmethod def UserConfirmationRequest(): return lambda event: HciMatchers.EventWithCode(EventCode.USER_CONFIRMATION_REQUEST) @staticmethod def RemoteHostSupportedFeaturesNotification(): return lambda event: HciMatchers.EventWithCode(EventCode.REMOTE_HOST_SUPPORTED_FEATURES_NOTIFICATION) @staticmethod def LinkKeyNotification(): return lambda event: HciMatchers.EventWithCode(EventCode.LINK_KEY_NOTIFICATION) @staticmethod def SimplePairingComplete(): return lambda event: HciMatchers.EventWithCode(EventCode.SIMPLE_PAIRING_COMPLETE) class NeighborMatchers(object): Loading system/gd/security/cert/cert_security.py +14 −21 Original line number Diff line number Diff line Loading @@ -19,8 +19,10 @@ import logging from bluetooth_packets_python3 import hci_packets from cert.closable import safeClose from cert.event_stream import EventStream from cert.matchers import HciMatchers from cert.py_hci import PyHci from cert.py_security import PySecurity from cert.truth import assertThat from datetime import datetime from google.protobuf import empty_pb2 as empty_proto from hci.facade import facade_pb2 as hci_facade Loading Loading @@ -164,7 +166,7 @@ class CertSecurity(PySecurity): hci_packets.WriteSimplePairingModeBuilder( hci_packets.Enable.ENABLED), True) logging.info("Cert: Waiting for controller response") self._hci_event_stream.assert_event_occurs( assertThat(self._hci_event_stream).emits( lambda msg: b'\x0e\x04\x01\x56\x0c' in msg.event) def accept_pairing(self, dut_address, reply_boolean): Loading @@ -172,28 +174,22 @@ class CertSecurity(PySecurity): Here we handle the pairing events at the HCI level """ logging.info("Cert: Waiting for LINK_KEY_REQUEST") self._hci_event_stream.assert_event_occurs( lambda event: logging.debug(event.event) or hci_packets.EventCode.LINK_KEY_REQUEST in event.event ) assertThat(self._hci_event_stream).emits(HciMatchers.LinkKeyRequest()) logging.info("Cert: Sending LINK_KEY_REQUEST_NEGATIVE_REPLY") self._enqueue_hci_command( hci_packets.LinkKeyRequestNegativeReplyBuilder( dut_address.decode('utf8')), True) logging.info("Cert: Waiting for IO_CAPABILITY_REQUEST") self._hci_event_stream.assert_event_occurs( lambda event: logging.debug(event.event) or hci_packets.EventCode.IO_CAPABILITY_REQUEST in event.event ) assertThat(self._hci_event_stream).emits( HciMatchers.IoCapabilityRequest()) logging.info("Cert: Sending IO_CAPABILITY_REQUEST_REPLY") self._enqueue_hci_command( hci_packets.IoCapabilityRequestReplyBuilder( dut_address.decode('utf8'), self._io_caps, self._oob_data, self._auth_reqs), True) logging.info("Cert: Waiting for USER_CONFIRMATION_REQUEST") self._hci_event_stream.assert_event_occurs( lambda event: logging.debug(event.event) or hci_packets.EventCode.USER_CONFIRMATION_REQUEST in event.event ) assertThat(self._hci_event_stream).emits( HciMatchers.UserConfirmationRequest()) logging.info( "Cert: Sending Simulated User Response '%s'" % reply_boolean) if reply_boolean: Loading @@ -202,13 +198,11 @@ class CertSecurity(PySecurity): hci_packets.UserConfirmationRequestReplyBuilder( dut_address.decode('utf8')), True) logging.info("Cert: Waiting for LINK_KEY_NOTIFICATION") self._hci_event_stream.assert_event_occurs( lambda event: logging.debug(event.event) or hci_packets.EventCode.LINK_KEY_NOTIFICATION in event.event ) assertThat(self._hci_event_stream).emits( HciMatchers.LinkKeyNotification()) logging.info("Cert: Waiting for SIMPLE_PAIRING_COMPLETE") self._hci_event_stream.assert_event_occurs( lambda event: logging.debug(event.event) or hci_packets.EventCode.SIMPLE_PAIRING_COMPLETE in event.event ) assertThat(self._hci_event_stream).emits( HciMatchers.SimplePairingComplete()) else: logging.info( "Cert: Sending USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY") Loading @@ -216,9 +210,8 @@ class CertSecurity(PySecurity): hci_packets.UserConfirmationRequestNegativeReplyBuilder( dut_address.decode('utf8')), True) logging.info("Cert: Waiting for SIMPLE_PAIRING_COMPLETE") self._hci_event_stream.assert_event_occurs( lambda event: logging.debug(event.event) or hci_packets.EventCode.SIMPLE_PAIRING_COMPLETE in event.event ) assertThat(self._hci_event_stream).emits( HciMatchers.SimplePairingComplete()) def on_user_input(self, dut_address, reply_boolean, expected_ui_event): """ Loading Loading
system/gd/cert/matchers.py +36 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,42 @@ class HciMatchers(object): return None return hci_event @staticmethod def LinkKeyRequest(): return lambda event: HciMatchers.EventWithCode(EventCode.LINK_KEY_REQUEST) @staticmethod def IoCapabilityRequest(): return lambda event: HciMatchers.EventWithCode(EventCode.IO_CAPABILITY_REQUEST) @staticmethod def IoCapabilityResponse(): return lambda event: HciMatchers.EventWithCode(EventCode.IO_CAPABILITY_RESPONSE) @staticmethod def UserPasskeyNotification(): return lambda event: HciMatchers.EventWithCode(EventCode.USER_PASSKEY_NOTIFICATION) @staticmethod def UserPasskeyRequest(): return lambda event: HciMatchers.EventWithCode(EventCode.USER_PASSKEY_REQUEST) @staticmethod def UserConfirmationRequest(): return lambda event: HciMatchers.EventWithCode(EventCode.USER_CONFIRMATION_REQUEST) @staticmethod def RemoteHostSupportedFeaturesNotification(): return lambda event: HciMatchers.EventWithCode(EventCode.REMOTE_HOST_SUPPORTED_FEATURES_NOTIFICATION) @staticmethod def LinkKeyNotification(): return lambda event: HciMatchers.EventWithCode(EventCode.LINK_KEY_NOTIFICATION) @staticmethod def SimplePairingComplete(): return lambda event: HciMatchers.EventWithCode(EventCode.SIMPLE_PAIRING_COMPLETE) class NeighborMatchers(object): Loading
system/gd/security/cert/cert_security.py +14 −21 Original line number Diff line number Diff line Loading @@ -19,8 +19,10 @@ import logging from bluetooth_packets_python3 import hci_packets from cert.closable import safeClose from cert.event_stream import EventStream from cert.matchers import HciMatchers from cert.py_hci import PyHci from cert.py_security import PySecurity from cert.truth import assertThat from datetime import datetime from google.protobuf import empty_pb2 as empty_proto from hci.facade import facade_pb2 as hci_facade Loading Loading @@ -164,7 +166,7 @@ class CertSecurity(PySecurity): hci_packets.WriteSimplePairingModeBuilder( hci_packets.Enable.ENABLED), True) logging.info("Cert: Waiting for controller response") self._hci_event_stream.assert_event_occurs( assertThat(self._hci_event_stream).emits( lambda msg: b'\x0e\x04\x01\x56\x0c' in msg.event) def accept_pairing(self, dut_address, reply_boolean): Loading @@ -172,28 +174,22 @@ class CertSecurity(PySecurity): Here we handle the pairing events at the HCI level """ logging.info("Cert: Waiting for LINK_KEY_REQUEST") self._hci_event_stream.assert_event_occurs( lambda event: logging.debug(event.event) or hci_packets.EventCode.LINK_KEY_REQUEST in event.event ) assertThat(self._hci_event_stream).emits(HciMatchers.LinkKeyRequest()) logging.info("Cert: Sending LINK_KEY_REQUEST_NEGATIVE_REPLY") self._enqueue_hci_command( hci_packets.LinkKeyRequestNegativeReplyBuilder( dut_address.decode('utf8')), True) logging.info("Cert: Waiting for IO_CAPABILITY_REQUEST") self._hci_event_stream.assert_event_occurs( lambda event: logging.debug(event.event) or hci_packets.EventCode.IO_CAPABILITY_REQUEST in event.event ) assertThat(self._hci_event_stream).emits( HciMatchers.IoCapabilityRequest()) logging.info("Cert: Sending IO_CAPABILITY_REQUEST_REPLY") self._enqueue_hci_command( hci_packets.IoCapabilityRequestReplyBuilder( dut_address.decode('utf8'), self._io_caps, self._oob_data, self._auth_reqs), True) logging.info("Cert: Waiting for USER_CONFIRMATION_REQUEST") self._hci_event_stream.assert_event_occurs( lambda event: logging.debug(event.event) or hci_packets.EventCode.USER_CONFIRMATION_REQUEST in event.event ) assertThat(self._hci_event_stream).emits( HciMatchers.UserConfirmationRequest()) logging.info( "Cert: Sending Simulated User Response '%s'" % reply_boolean) if reply_boolean: Loading @@ -202,13 +198,11 @@ class CertSecurity(PySecurity): hci_packets.UserConfirmationRequestReplyBuilder( dut_address.decode('utf8')), True) logging.info("Cert: Waiting for LINK_KEY_NOTIFICATION") self._hci_event_stream.assert_event_occurs( lambda event: logging.debug(event.event) or hci_packets.EventCode.LINK_KEY_NOTIFICATION in event.event ) assertThat(self._hci_event_stream).emits( HciMatchers.LinkKeyNotification()) logging.info("Cert: Waiting for SIMPLE_PAIRING_COMPLETE") self._hci_event_stream.assert_event_occurs( lambda event: logging.debug(event.event) or hci_packets.EventCode.SIMPLE_PAIRING_COMPLETE in event.event ) assertThat(self._hci_event_stream).emits( HciMatchers.SimplePairingComplete()) else: logging.info( "Cert: Sending USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY") Loading @@ -216,9 +210,8 @@ class CertSecurity(PySecurity): hci_packets.UserConfirmationRequestNegativeReplyBuilder( dut_address.decode('utf8')), True) logging.info("Cert: Waiting for SIMPLE_PAIRING_COMPLETE") self._hci_event_stream.assert_event_occurs( lambda event: logging.debug(event.event) or hci_packets.EventCode.SIMPLE_PAIRING_COMPLETE in event.event ) assertThat(self._hci_event_stream).emits( HciMatchers.SimplePairingComplete()) def on_user_input(self, dut_address, reply_boolean, expected_ui_event): """ Loading