def client_connect(self, wd, dev): condition = 'not obj.scanning' wd.wait_for_object_condition(dev, condition) if not dev.get_ordered_networks(): dev.scan() condition = 'obj.scanning' wd.wait_for_object_condition(dev, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(dev, condition) ordered_network = dev.get_ordered_network('TestAP1') self.assertEqual(ordered_network.type, NetworkType.psk) psk_agent = PSKAgent('Password1') wd.register_psk_agent(psk_agent) ordered_network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) wd.unregister_psk_agent(psk_agent) testutil.test_iface_operstate(dev.name) testutil.test_ifaces_connected( list(hostapd.hostapd_map.keys())[0], dev.name) dev.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition)
def test_connection_success(self): wd = IWD() psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network('ssidCCMP') self.assertEqual(ordered_network.type, NetworkType.psk) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) wd.unregister_psk_agent(psk_agent)
def validate_connection(self, wd, ssid, autoconnect, throws=None, use_agent=False): if use_agent: psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) self.assertIsNotNone(devices) device = devices[0] condition = 'obj.scanning' wd.wait_for_object_condition(device, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) if autoconnect: self.check_autoconnect(wd, device, ssid, throws) else: self.check_connect(wd, device, ssid, throws) if use_agent: wd.unregister_psk_agent(psk_agent)
def validate_connection(self, wd): hostapd = None for hostapd_if in list(hostapd_map.values()): hpd = HostapdCLI(hostapd_if) if hpd.get_config_value('ssid') == 'ssidEAP-PWD': hostapd = hpd break self.assertIsNotNone(hostapd) psk_agent = PSKAgent('eap-pwd-identity', ('eap-pwd-identity', 'secret123')) wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) self.assertIsNotNone(devices) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_networks = device.get_ordered_networks() ordered_network = None for o_n in ordered_networks: if o_n.name == "ssidEAP-PWD": ordered_network = o_n break self.assertEqual(ordered_network.name, "ssidEAP-PWD") self.assertEqual(ordered_network.type, NetworkType.eap) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) hostapd.eapol_reauth(device.address) wd.wait(10) condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) wd.unregister_psk_agent(psk_agent)
def validate_connection(self, wd, ssid, autoconnect, throws, use_agent, wait_periodic_scan): if use_agent: psk_agent = PSKAgent(["secret123"], ('domain\\User', 'Password')) wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) self.assertIsNotNone(devices) device = devices[0] if autoconnect: condition = 'obj.scanning' wd.wait_for_object_condition(device, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) self.check_autoconnect_hidden_network(wd, device, ssid, throws) else: if wait_periodic_scan: condition = 'obj.scanning' wd.wait_for_object_condition(device, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) self.check_connect_hidden_network(wd, device, ssid, throws) if use_agent: wd.unregister_psk_agent(psk_agent)
def test_connection_success(self): hostapd = None for wname in wiphy_map: wiphy = wiphy_map[wname] intf = list(wiphy.values())[0] if intf.use == 'hostapd': hostapd = HostapdCLI(intf) break hwsim = Hwsim() wd = IWD() psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_networks = device.get_ordered_networks() ordered_network = ordered_networks[0] self.assertEqual(ordered_network.name, "ssidCCMP") self.assertEqual(ordered_network.type, NetworkType.psk) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) # Make AP go down ungracefully, when hostapd comes back up it should # send an unprotected disassociate frame so the client will re-auth. # This will kick off the SA Query procedure hostapd.ungraceful_restart() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) # IWD should now try and re-connect to the AP condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) wd.unregister_psk_agent(psk_agent)
def test_connection_failure(self): wd = IWD() dev1, dev2 = wd.list_devices(2) self.client_connect(wd, dev1) dev1.start_ap('TestAP2', 'Password2') try: condition = 'not obj.scanning' wd.wait_for_object_condition(dev2, condition) dev2.scan() condition = 'obj.scanning' wd.wait_for_object_condition(dev2, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(dev2, condition) ordered_networks = dev2.get_ordered_networks() networks = {n.name: n for n in ordered_networks} self.assertEqual(networks['TestAP1'].type, NetworkType.psk) self.assertEqual(networks['TestAP2'].type, NetworkType.psk) psk_agent = PSKAgent('InvalidPassword') wd.register_psk_agent(psk_agent) with self.assertRaises(iwd.FailedEx): networks['TestAP2'].network_object.connect() wd.unregister_psk_agent(psk_agent) finally: dev1.stop_ap() # Finally test dev1 can go to client mode and connect again self.client_connect(wd, dev1)
def stage_iwd(self, wd, config_dir): psk_agent = PSKAgent(['secret123', 'secret123', 'secret123']) wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) self.assertIsNotNone(devices) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) if config_dir == '/tmp/IWD-MFP2': self.check_mfp_connection(wd, device, 'ssidMFP0', True) else: self.check_mfp_connection(wd, device, 'ssidMFP0', False) self.check_mfp_connection(wd, device, 'ssidMFP1', False) if config_dir == '/tmp/IWD-MFP0': self.check_mfp_connection(wd, device, 'ssidMFP2', True) else: self.check_mfp_connection(wd, device, 'ssidMFP2', False) wd.unregister_psk_agent(psk_agent)
def validate_connection(self, wd): hostapd = HostapdCLI(config='ssidEAP-TTLS-MSCHAPv2.conf') self.assertIsNotNone(hostapd) psk_agent = PSKAgent('abc', ('user', 'incorrect_password')) wd.register_psk_agent(psk_agent) device = wd.list_devices(1)[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_networks = device.get_ordered_networks() ordered_network = ordered_networks[0] self.assertEqual(ordered_network.name, "ssidEAP-TTLS-MSCHAPv2") self.assertEqual(ordered_network.type, NetworkType.eap) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) with self.assertRaises(iwd.FailedEx): ordered_network.network_object.connect() wd.unregister_psk_agent(psk_agent)
def test_connection_success(self): wd = IWD(True) psk_agent = PSKAgent("InvalidSecret") wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) self.assertIsNotNone(devices) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_networks = device.get_ordered_networks() network = [x for x in ordered_networks if x.name == "ssidSAE"][0] self.assertIsNotNone(network) self.assertEqual(network.name, "ssidSAE") self.assertEqual(network.type, NetworkType.psk) condition = 'not obj.connected' wd.wait_for_object_condition(network.network_object, condition) with self.assertRaises(iwd.FailedEx): network.network_object.connect() wd.unregister_psk_agent(psk_agent) del wd
def test_connection_success(self): wd = IWD() psk_agent = PSKAgent("InvalidPassword") wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) self.assertIsNotNone(devices) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_networks = device.get_ordered_networks() ordered_network = ordered_networks[0] self.assertEqual(ordered_network.name, "ssidCCMP") self.assertEqual(ordered_network.type, NetworkType.psk) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) with self.assertRaises(iwd.FailedEx): ordered_network.network_object.connect() wd.unregister_psk_agent(psk_agent)
def test_connection_success(self): wd = IWD() devices = wd.list_devices(1) device = devices[0] device.disconnect() condition = 'obj.state == DeviceState.disconnected' wd.wait_for_object_condition(device, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) if not device.get_ordered_networks(): device.scan() condition = 'obj.scanning' wd.wait_for_object_condition(device, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network("ssidCCMP") self.assertEqual(ordered_network.type, NetworkType.psk) network = ordered_network.network_object # 0 chars psk_agent = PSKAgent("") wd.register_psk_agent(psk_agent) self.assertRaises(iwd.InvalidFormatEx, network.connect) wd.unregister_psk_agent(psk_agent) # 7 chars psk_agent = PSKAgent("a" * 7) wd.register_psk_agent(psk_agent) self.assertRaises(iwd.InvalidFormatEx, network.connect) wd.unregister_psk_agent(psk_agent) # 64 chars psk_agent = PSKAgent("a" * 64) wd.register_psk_agent(psk_agent) self.assertRaises(iwd.InvalidFormatEx, network.connect) wd.unregister_psk_agent(psk_agent) # 64k chars psk_agent = PSKAgent("a" * 65536) wd.register_psk_agent(psk_agent) self.assertRaises(iwd.InvalidFormatEx, network.connect) wd.unregister_psk_agent(psk_agent)
def test_connection_success(self): hapd = HostapdCLI(config='ssidFILS-256.conf') wd = IWD(True) psk_agent = PSKAgent('*****@*****.**', ('*****@*****.**', 'secret123')) wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network('ssidFILS-256') self.assertEqual(ordered_network.type, NetworkType.eap) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) testutil.test_iface_operstate() testutil.test_ifaces_connected(device.name, hapd.ifname) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network = device.get_ordered_network('ssidFILS-256') self.assertEqual(ordered_network.type, NetworkType.eap) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) testutil.test_iface_operstate() testutil.test_ifaces_connected(device.name, hapd.ifname) device.disconnect() wd.unregister_psk_agent(psk_agent)
def test_connection_success(self): wd = IWD() dev1, dev2 = wd.list_devices(2) dev1.disconnect() dev2.disconnect() self.client_connect(wd, dev1) dev1.start_ap('TestAP2', 'Password2') try: condition = 'not obj.scanning' wd.wait_for_object_condition(dev2, condition) dev2.scan() condition = 'obj.scanning' wd.wait_for_object_condition(dev2, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(dev2, condition) ordered_networks = dev2.get_ordered_networks() self.assertEqual(len(ordered_networks), 2) networks = {n.name: n for n in ordered_networks} self.assertEqual(networks['TestAP1'].type, NetworkType.psk) self.assertEqual(networks['TestAP2'].type, NetworkType.psk) psk_agent = PSKAgent('Password2') wd.register_psk_agent(psk_agent) try: dev2.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(dev2, condition) except: pass networks['TestAP2'].network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(networks['TestAP2'].network_object, condition) testutil.test_iface_operstate(dev2.name) testutil.test_ifaces_connected(dev1.name, dev2.name) wd.unregister_psk_agent(psk_agent) dev2.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(networks['TestAP2'].network_object, condition) finally: dev1.stop_ap() # Finally test dev1 can go to client mode and connect again self.client_connect(wd, dev1)
def test_connection_success(self): networks = [] wd = IWD(True) psk_agent = PSKAgent(["secret123"] * 4) wd.register_psk_agent(psk_agent) devices = wd.list_devices(4) self.assertIsNotNone(devices) for d in devices: condition = 'not obj.scanning' wd.wait_for_object_condition(d, condition) d.scan() for d in devices: condition = 'not obj.scanning' wd.wait_for_object_condition(d, condition) for i in range(len(devices)): ordered_networks = devices[i].get_ordered_networks() network = [ x for x in ordered_networks if x.name == "ssidSAE-Clogging" ][0] self.assertIsNotNone(network) self.assertEqual(network.name, "ssidSAE-Clogging") self.assertEqual(network.type, NetworkType.psk) networks.append(network) condition = 'not obj.connected' wd.wait_for_object_condition(network.network_object, condition) for n in networks: n.network_object.connect(wait=False) for n in networks: condition = 'obj.connected' wd.wait_for_object_condition(n.network_object, condition) for d in devices: d.wait_for_connected() for d in devices: d.disconnect() for n in networks: condition = 'not obj.connected' wd.wait_for_object_condition(n.network_object, condition) wd.unregister_psk_agent(psk_agent) del wd
def test_connection_success(self): hostapd = None for hostapd_if in list(hostapd_map.values()): hpd = HostapdCLI(hostapd_if) if hpd.get_config_value('ssid') == 'ssidEAP-TTLS-MSCHAP': hostapd = hpd break self.assertIsNotNone(hostapd) wd = IWD() psk_agent = PSKAgent('abc', ('user', 'testpasswd')) wd.register_psk_agent(psk_agent) device = wd.list_devices(1)[0]; condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_networks = device.get_ordered_networks() ordered_network = ordered_networks[0] self.assertEqual(ordered_network.name, "ssidEAP-TTLS-MSCHAP") self.assertEqual(ordered_network.type, NetworkType.eap) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) hostapd.eapol_reauth(device.address) wd.wait(10) condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) testutil.test_iface_operstate() testutil.test_ifaces_connected() device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) wd.unregister_psk_agent(psk_agent)
def test_connection_success(self): wd = IWD(True) psk_agent = PSKAgent('*****@*****.**', ('*****@*****.**', 'testpasswd')) wd.register_psk_agent(psk_agent) try: self.validate_connection(wd) finally: wd.unregister_psk_agent(psk_agent)
def test_connection_success(self): hwsim = Hwsim() hostapd = HostapdCLI(config='ssidCCMP.conf') radio = hwsim.get_radio('rad0') wd = IWD() psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network('ssidCCMP') self.assertEqual(ordered_network.type, NetworkType.psk) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) # TODO: for some reason hostapd does not respond to SA query if done # too soon after connection. sleep(1) # Spoof a disassociate frame. This will kick off SA Query procedure. hwsim.spoof_disassociate(radio, hostapd.get_freq(), device.address) # sleep to ensure hostapd responds and SA Query does not timeout sleep(4) # Since disassociate was spoofed we should still be connected condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) wd.unregister_psk_agent(psk_agent)
def test_connection_success(self): hwsim = Hwsim() bss_radio = hwsim.get_radio('rad0') rule0 = hwsim.rules.create() rule0.source = bss_radio.addresses[0] rule0.bidirectional = True wd = IWD(True) hapd = HostapdCLI(config='ssidHotspot.conf') psk_agent = PSKAgent('abc', ('domain\\user', 'testpasswd')) wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) device = devices[0] # We are dependent on a periodic scan here. We want to wait for this # because this is the first opportunity IWD has to do ANQP. Once ANQP # has been done once the network is set up and we cannot simulate the # 'Connect() before ANQP' race condition anymore. condition = 'obj.scanning' wd.wait_for_object_condition(device, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network('Hotspot') self.assertEqual(ordered_network.type, NetworkType.eap) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) # Force the case where ANQP does not finish before Connect() comes in rule0.delay = 100 ordered_network.network_object.connect() rule0.delay = 1 condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) testutil.test_iface_operstate() testutil.test_ifaces_connected(device.name, hapd.ifname) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) wd.unregister_psk_agent(psk_agent)
def test_connection_success(self): hostapd_if = None for hostapd in list(hostapd_map.values()): if hostapd.config == 'ssidSAE.conf': hostapd_if = hostapd.name wd = IWD(True) psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) self.assertIsNotNone(devices) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_networks = device.get_ordered_networks() network = [x for x in ordered_networks if x.name == "ssidSAE"][0] self.assertIsNotNone(network) self.assertEqual(network.name, "ssidSAE") self.assertEqual(network.type, NetworkType.psk) condition = 'not obj.connected' wd.wait_for_object_condition(network.network_object, condition) network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(network.network_object, condition) wd.wait(2) testutil.test_iface_operstate(intf=device.name) testutil.test_ifaces_connected(if0=device.name, if1=hostapd_if) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(network.network_object, condition) wd.unregister_psk_agent(psk_agent) del wd
def validate_connection(self, wd): hwsim = Hwsim() bss_radio = hwsim.get_radio('rad0') psk_agent = PSKAgent(["secret123", "secret123"]) wd.register_psk_agent(psk_agent) devices = wd.list_devices(4) # These devices aren't used in this test, this makes logs a bit nicer # since these devices would presumably start autoconnecting. devices[1].disconnect() devices[2].disconnect() devices[3].disconnect() self.assertIsNotNone(devices) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) network = device.get_ordered_network('ssidSAE') self.assertEqual(network.type, NetworkType.psk) condition = 'not obj.connected' wd.wait_for_object_condition(network.network_object, condition) rule0 = hwsim.rules.create() rule0.source = bss_radio.addresses[0] rule0.bidirectional = True rule0.drop = True rule0.prefix = 'b0' wd.wait(1) print(rule0) with self.assertRaises(iwd.FailedEx): network.network_object.connect() condition = 'not obj.connected' wd.wait_for_object_condition(network.network_object, condition) rule0.prefix = '00' with self.assertRaises(iwd.FailedEx): network.network_object.connect() wd.unregister_psk_agent(psk_agent)
def test_connection_with_own_agent(self): wd = IWD() psk_agent = PSKAgent("secret_ssid1") wd.register_psk_agent(psk_agent) self.check_connection(wd, 'ssid1') wd.unregister_psk_agent(psk_agent) IWD.clear_storage()
def test_connection_success(self): hwsim = Hwsim() hostapd = HostapdCLI(config='ssidCCMP.conf') radio = hwsim.get_radio('rad0') wd = IWD() psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network('ssidCCMP', scan_if_needed=True) self.assertEqual(ordered_network.type, NetworkType.psk) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) # Ensure IWD is not scanning. This causes problems with mac80211_hwsim # where CMD_FRAME will fail during a scan. This is due to the frame not # having the same frequency as the radio (since hwsim is off-channel) if device.scanning: condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) # Spoof a disassociate frame. This will kick off SA Query procedure. hwsim.spoof_disassociate(radio, hostapd.get_freq(), device.address) # sleep to ensure hostapd responds and SA Query does not timeout sleep(4) # Since disassociate was spoofed we should still be connected condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) wd.unregister_psk_agent(psk_agent)
def test_connection_success(self): hostapd = HostapdCLI(config='ssidCCMP.conf') wd = IWD() psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network('ssidCCMP') self.assertEqual(ordered_network.type, NetworkType.psk) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) # Make AP go down ungracefully, when hostapd comes back up it should # send an unprotected disassociate frame so the client will re-auth. # This will kick off the SA Query procedure hostapd.ungraceful_restart() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) # IWD should now try and re-connect to the AP condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) hostapd.wait_for_event('AP-STA-CONNECTED') device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) wd.unregister_psk_agent(psk_agent)
def validate_connection(self, wd): hostapd_if = None for hostapd in hostapd_map.values(): if hostapd.config == 'ssidSAE.conf': hostapd_if = hostapd.name psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) devices = wd.list_devices(4) self.assertIsNotNone(devices) device = devices[0] # These devices aren't used in this test, this makes logs a bit nicer # since these devices would presumably start autoconnecting. devices[1].disconnect() devices[2].disconnect() devices[3].disconnect() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) network = device.get_ordered_network('ssidSAE') self.assertEqual(network.type, NetworkType.psk) condition = 'not obj.connected' wd.wait_for_object_condition(network.network_object, condition) network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(network.network_object, condition) wd.wait(2) testutil.test_iface_operstate(intf=device.name) testutil.test_ifaces_connected(if0=device.name, if1=hostapd_if) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(network.network_object, condition) wd.unregister_psk_agent(psk_agent)
def validate_connection(self, wd): hostapd = HostapdCLI(config='ssidEAP-TTLS-MSCHAPv2.conf') self.assertIsNotNone(hostapd) psk_agent = PSKAgent('abc', ('domain\\user', 'testpasswd')) wd.register_psk_agent(psk_agent) device = wd.list_devices(1)[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_networks = device.get_ordered_networks() ordered_network = ordered_networks[0] self.assertEqual(ordered_network.name, "ssidEAP-TTLS-MSCHAPv2") self.assertEqual(ordered_network.type, NetworkType.eap) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) hostapd.eapol_reauth(device.address) hostapd.wait_for_event('CTRL-EVENT-EAP-STARTED') hostapd.wait_for_event('CTRL-EVENT-EAP-SUCCESS') condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) testutil.test_iface_operstate() testutil.test_ifaces_connected() device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) wd.unregister_psk_agent(psk_agent)
def do_test_connection_success(self, ssid, passphrase=None): wd = IWD() if passphrase: psk_agent = PSKAgent(passphrase) wd.register_psk_agent(psk_agent) hostapd_ifname = None for ifname in hostapd.hostapd_map: if ssid + '.conf' in hostapd.hostapd_map[ifname].config: hostapd_ifname = ifname break devices = wd.list_devices(1) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) if not device.get_ordered_networks(): device.scan() condition = 'obj.scanning' wd.wait_for_object_condition(device, condition) condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_networks = device.get_ordered_networks() ordered_network = [n for n in ordered_networks if n.name == ssid][0] self.assertEqual(ordered_network.type, NetworkType.eap) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) testutil.test_iface_operstate() testutil.test_ifaces_connected(hostapd_ifname, 'wln3') device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) if passphrase: wd.unregister_psk_agent(psk_agent)
def validate_connection(self, wd): networks = [] psk_agent = PSKAgent(["secret123"] * 4) wd.register_psk_agent(psk_agent) devices = wd.list_devices(4) self.assertIsNotNone(devices) for d in devices: condition = 'not obj.scanning' wd.wait_for_object_condition(d, condition) d.scan() for d in devices: condition = 'not obj.scanning' wd.wait_for_object_condition(d, condition) for i in range(len(devices)): network = devices[i].get_ordered_network('ssidSAE-Clogging') self.assertEqual(network.type, NetworkType.psk) networks.append(network) condition = 'not obj.connected' wd.wait_for_object_condition(network.network_object, condition) for n in networks: n.network_object.connect(wait=False) for d in devices: condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(d, condition) for d in devices: condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(d, condition) for d in devices: d.disconnect() for n in networks: condition = 'not obj.connected' wd.wait_for_object_condition(n.network_object, condition) wd.unregister_psk_agent(psk_agent)
def test_connection_success(self): hwsim = Hwsim() non_ht_hostapd = HostapdCLI(config='non-ht-vht.conf') ht_hostapd = HostapdCLI(config='ht.conf') vht_hostapd = HostapdCLI(config='vht.conf') non_ht_radio = hwsim.get_radio('rad0') ht_radio = hwsim.get_radio('rad1') vht_radio = hwsim.get_radio('rad2') self.assertIsNotNone(non_ht_hostapd) self.assertIsNotNone(ht_hostapd) self.assertIsNotNone(vht_hostapd) rule0 = hwsim.rules.create() rule0.source = vht_radio.addresses[0] rule0.bidirectional = True rule0.signal = -2000 rule1 = hwsim.rules.create() rule1.source = ht_radio.addresses[0] rule1.bidirectional = True rule1.signal = -2000 rule2 = hwsim.rules.create() rule2.source = non_ht_radio.addresses[0] rule2.bidirectional = True rule2.signal = -2000 wd = IWD() psk_agent = PSKAgent("secret123") wd.register_psk_agent(psk_agent) device = wd.list_devices(1)[0] self.do_connect(wd, device, vht_hostapd) # lower VHT BSS signal, HT should now be preferred rule0.signal = -6000 self.do_connect(wd, device, ht_hostapd) # lower HT BSS signal, basic rate BSS should now be preferred rule1.signal = -6000 self.do_connect(wd, device, non_ht_hostapd) wd.unregister_psk_agent(psk_agent)
def validate_connection(self, wd): hostapd = HostapdCLI(config='ssidEAP-PWD.conf') self.assertIsNotNone(hostapd) psk_agent = PSKAgent('eap-pwd-identity', ('eap-pwd-identity', 'secret123')) wd.register_psk_agent(psk_agent) devices = wd.list_devices(1) self.assertIsNotNone(devices) device = devices[0] condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) device.scan() condition = 'not obj.scanning' wd.wait_for_object_condition(device, condition) ordered_network = device.get_ordered_network('ssidEAP-PWD') self.assertEqual(ordered_network.type, NetworkType.eap) condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) ordered_network.network_object.connect() condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) hostapd.eapol_reauth(device.address) hostapd.wait_for_event('CTRL-EVENT-EAP-STARTED') hostapd.wait_for_event('CTRL-EVENT-EAP-SUCCESS') condition = 'obj.state == DeviceState.connected' wd.wait_for_object_condition(device, condition) device.disconnect() condition = 'not obj.connected' wd.wait_for_object_condition(ordered_network.network_object, condition) wd.unregister_psk_agent(psk_agent)