def test_le_ad_scan_dut_scans(self): privacy_policy = le_initiator_address_facade.PrivacyPolicy( address_policy=le_initiator_address_facade.AddressPolicy. USE_STATIC_ADDRESS, address_with_type=common.BluetoothAddressWithType( address=common.BluetoothAddress( address=bytes(b'D0:05:04:03:02:01')), type=common.RANDOM_DEVICE_ADDRESS), rotation_irk= b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', minimum_rotation_time=0, maximum_rotation_time=0) self.dut.hci_le_initiator_address.SetPrivacyPolicyForInitiatorAddress( privacy_policy) cert_privacy_policy = le_initiator_address_facade.PrivacyPolicy( address_policy=le_initiator_address_facade.AddressPolicy. USE_STATIC_ADDRESS, address_with_type=common.BluetoothAddressWithType( address=common.BluetoothAddress( address=bytes(b'C0:05:04:03:02:01')), type=common.RANDOM_DEVICE_ADDRESS), rotation_irk= b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', minimum_rotation_time=0, maximum_rotation_time=0) self.cert.hci_le_initiator_address.SetPrivacyPolicyForInitiatorAddress( cert_privacy_policy) with EventStream( # DUT Scans self.dut.hci_le_scanning_manager.StartScan( empty_proto.Empty())) as advertising_event_stream: # CERT Advertises gap_name = hci_packets.GapData() gap_name.data_type = hci_packets.GapDataType.COMPLETE_LOCAL_NAME gap_name.data = list(bytes(b'Im_The_CERT!')) gap_data = le_advertising_facade.GapDataMsg( data=bytes(gap_name.Serialize())) config = le_advertising_facade.AdvertisingConfig( advertisement=[gap_data], interval_min=512, interval_max=768, event_type=le_advertising_facade.AdvertisingEventType.ADV_IND, address_type=common.RANDOM_DEVICE_ADDRESS, channel_map=7, filter_policy=le_advertising_facade.AdvertisingFilterPolicy. ALL_DEVICES) request = le_advertising_facade.CreateAdvertiserRequest( config=config) create_response = self.cert.hci_le_advertising_manager.CreateAdvertiser( request) advertising_event_stream.assert_event_occurs( lambda packet: b'Im_The_CERT' in packet.event) remove_request = le_advertising_facade.RemoveAdvertiserRequest( advertiser_id=create_response.advertiser_id) self.cert.hci_le_advertising_manager.RemoveAdvertiser( remove_request)
def setup_test(self): super().setup_test() self.dut_l2cap = PyLeL2cap(self.dut) self.cert_l2cap = CertLeL2cap(self.cert) self.dut_address = common.BluetoothAddressWithType( address=common.BluetoothAddress( address=bytes(b'D0:05:04:03:02:01')), type=common.RANDOM_DEVICE_ADDRESS) self.cert_address = common.BluetoothAddressWithType( address=common.BluetoothAddress( address=bytes(b'C0:11:FF:AA:33:22')), type=common.RANDOM_DEVICE_ADDRESS) dut_privacy_policy = le_initiator_address_facade.PrivacyPolicy( address_policy=le_initiator_address_facade.AddressPolicy. USE_STATIC_ADDRESS, address_with_type=self.dut_address, rotation_irk= b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', minimum_rotation_time=0, maximum_rotation_time=0) self.dut_l2cap._device.hci_le_initiator_address.SetPrivacyPolicyForInitiatorAddress( dut_privacy_policy) privacy_policy = le_initiator_address_facade.PrivacyPolicy( address_policy=le_initiator_address_facade.AddressPolicy. USE_STATIC_ADDRESS, address_with_type=self.cert_address, rotation_irk= b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', minimum_rotation_time=0, maximum_rotation_time=0) self.cert_l2cap._device.hci_le_initiator_address.SetPrivacyPolicyForInitiatorAddress( privacy_policy)
def setup_test(self): super().setup_test() self.dut_address = self.dut.hci_controller.GetMacAddressSimple() cert_address = common.BluetoothAddress( address=self.cert.controller_read_only_property.ReadLocalAddress(empty_proto.Empty()).address) self.dut_l2cap = PyL2cap(self.dut, cert_address) self.cert_l2cap = CertL2cap(self.cert) self.dut_le_l2cap = PyLeL2cap(self.dut) self.cert_le_l2cap = CertLeL2cap(self.cert) self.dut_le_address = common.BluetoothAddressWithType( address=common.BluetoothAddress(address=bytes(b'D0:05:04:03:02:01')), type=common.RANDOM_DEVICE_ADDRESS) self.cert_address = common.BluetoothAddressWithType( address=common.BluetoothAddress(address=bytes(b'C0:11:FF:AA:33:22')), type=common.RANDOM_DEVICE_ADDRESS) dut_privacy_policy = le_initiator_address_facade.PrivacyPolicy( address_policy=le_initiator_address_facade.AddressPolicy.USE_STATIC_ADDRESS, address_with_type=self.dut_le_address, rotation_irk=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', minimum_rotation_time=0, maximum_rotation_time=0) self.dut_l2cap._device.hci_le_initiator_address.SetPrivacyPolicyForInitiatorAddress(dut_privacy_policy) privacy_policy = le_initiator_address_facade.PrivacyPolicy( address_policy=le_initiator_address_facade.AddressPolicy.USE_STATIC_ADDRESS, address_with_type=self.cert_address, rotation_irk=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', minimum_rotation_time=0, maximum_rotation_time=0) self.cert_le_l2cap._device.hci_le_initiator_address.SetPrivacyPolicyForInitiatorAddress(privacy_policy)
def setup_test(self): super().setup_test() self.dut_security = PyLeSecurity(self.dut) self.cert_security = PyLeSecurity(self.cert) self.dut_hci = PyHci(self.dut) self.dut_address = common.BluetoothAddressWithType( address=common.BluetoothAddress( address=bytes(b'DD:05:04:03:02:01')), type=common.RANDOM_DEVICE_ADDRESS) privacy_policy = le_initiator_address_facade.PrivacyPolicy( address_policy=le_initiator_address_facade.AddressPolicy. USE_STATIC_ADDRESS, address_with_type=self.dut_address) self.dut.security.SetLeInitiatorAddressPolicy(privacy_policy) self.cert_address = common.BluetoothAddressWithType( address=common.BluetoothAddress( address=bytes(b'C5:11:FF:AA:33:22')), type=common.RANDOM_DEVICE_ADDRESS) cert_privacy_policy = le_initiator_address_facade.PrivacyPolicy( address_policy=le_initiator_address_facade.AddressPolicy. USE_STATIC_ADDRESS, address_with_type=self.cert_address) self.cert.security.SetLeInitiatorAddressPolicy(cert_privacy_policy)
def test_dut_connects_public_address_cancelled(self): self.dut.hci_le_initiator_address.SetPrivacyPolicyForInitiatorAddress( le_initiator_address_facade.PrivacyPolicy( address_policy=le_initiator_address_facade.AddressPolicy. USE_PUBLIC_ADDRESS)) self.dut_connects(check_address=False) self.send_receive_and_check()
def setup_test(self): super().setup_test() self.dut.neighbor.EnablePageScan( neighbor_facade.EnableMsg(enabled=True)) self.cert.neighbor.EnablePageScan( neighbor_facade.EnableMsg(enabled=True)) self.dut.name = b'DUT Device' self.dut.address = self.dut.hci_controller.GetMacAddress( empty_proto.Empty()).address self.cert.name = b'Cert Device' self.cert.address = self.cert.hci_controller.GetMacAddress( empty_proto.Empty()).address # TODO(optedoblivion): Make this happen in PySecurity or GdDevice self.dut.hci_controller.WriteLocalName( controller_facade.NameMsg(name=self.dut.name)) self.cert.hci_controller.WriteLocalName( controller_facade.NameMsg(name=self.cert.name)) self.dut_security = PySecurity(self.dut) self.cert_security = CertSecurity(self.cert) self.dut_address = common.BluetoothAddressWithType( address=common.BluetoothAddress( address=bytes(b'DD:05:04:03:02:01')), type=common.RANDOM_DEVICE_ADDRESS) privacy_policy = le_initiator_address_facade.PrivacyPolicy( address_policy=le_initiator_address_facade.AddressPolicy. USE_STATIC_ADDRESS, address_with_type=self.dut_address) self.dut.security.SetLeInitiatorAddressPolicy(privacy_policy)
def set_cert_privacy_policy_with_random_address(self, random_address): private_policy = le_initiator_address_facade.PrivacyPolicy( address_policy=le_initiator_address_facade.AddressPolicy. USE_STATIC_ADDRESS, address_with_type=common.BluetoothAddressWithType( address=common.BluetoothAddress( address=bytes(random_address, encoding='utf8')), type=common.RANDOM_DEVICE_ADDRESS)) self.cert.hci_le_initiator_address.SetPrivacyPolicyForInitiatorAddress( private_policy)
def set_privacy_policy_static(self): self.dut_address = b'd0:05:04:03:02:01' private_policy = le_initiator_address_facade.PrivacyPolicy( address_policy=le_initiator_address_facade.AddressPolicy. USE_STATIC_ADDRESS, address_with_type=common.BluetoothAddressWithType( address=common.BluetoothAddress( address=bytes(self.dut_address)), type=common.RANDOM_DEVICE_ADDRESS)) self.dut.hci_le_initiator_address.SetPrivacyPolicyForInitiatorAddress( private_policy)
def test_dut_connects_non_resolvable_address(self): privacy_policy = le_initiator_address_facade.PrivacyPolicy( address_policy=le_initiator_address_facade.AddressPolicy. USE_NON_RESOLVABLE_ADDRESS, rotation_irk= b'\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f', minimum_rotation_time=8 * 60 * 1000, maximum_rotation_time=14 * 60 * 1000) self.dut.hci_le_initiator_address.SetPrivacyPolicyForInitiatorAddress( privacy_policy) self.dut_connects(check_address=False) self.send_receive_and_check()
def test_dut_connects_resolvable_address(self): privacy_policy = le_initiator_address_facade.PrivacyPolicy( address_policy=le_initiator_address_facade.AddressPolicy. USE_RESOLVABLE_ADDRESS, rotation_irk= b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f', minimum_rotation_time=7 * 60 * 1000, maximum_rotation_time=15 * 60 * 1000) self.dut.hci_le_initiator_address.SetPrivacyPolicyForInitiatorAddress( privacy_policy) self.dut_connects(check_address=False) self.send_receive_and_check()
def set_cert_privacy_policy_with_public_address(self): public_address_bytes = self.cert.hci_controller.GetMacAddress( empty_proto.Empty()).address private_policy = le_initiator_address_facade.PrivacyPolicy( address_policy=le_initiator_address_facade.AddressPolicy. USE_PUBLIC_ADDRESS, address_with_type=common.BluetoothAddressWithType( address=common.BluetoothAddress(address=public_address_bytes), type=common.PUBLIC_DEVICE_ADDRESS)) self.cert.hci_le_initiator_address.SetPrivacyPolicyForInitiatorAddress( private_policy) # Bluetooth MAC address must be upper case return public_address_bytes.decode('utf-8').upper()