3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-25 17:59:25 +01:00

auto-t: fix rekey/reauth logic in a few ways

The rekey/reauth logic was broken in a few different ways.

For rekeys the event list was not being reset so any past 4-way
handshake would allow the call to pass. This actually removes
the need for the sleep in the extended key ID test because the
actual handshake event is waited for correctly.

For both rekeys and reauths, just waiting for the EAP/handshake
events was not enough. Without checking if the client got
disconnected we essentially allow a full disconnect and reconnect,
meaning the rekey/reauth failed.

Now a 'disallow' array can be passed to wait_for_event which will
throw an exception if any events in that array are encountered
while waiting for the target event.
This commit is contained in:
James Prestwood 2022-06-24 16:07:38 -07:00 committed by Denis Kenzior
parent 53e8bf4cb0
commit 267feb94b0
2 changed files with 10 additions and 8 deletions

View File

@ -50,8 +50,6 @@ class Test(unittest.TestCase):
testutil.test_iface_operstate() testutil.test_iface_operstate()
testutil.test_ifaces_connected() testutil.test_ifaces_connected()
wd.wait(0.5)
device.disconnect() device.disconnect()
condition = 'not obj.connected' condition = 'not obj.connected'

View File

@ -102,23 +102,26 @@ class HostapdCLI(object):
return True return True
def _poll_event(self, event): def _poll_event(self, event, disallow):
# Look through the list (most recent is first) until the even is found. # Look through the list (most recent is first) until the even is found.
# Once found consume this event and any older ones as to not # Once found consume this event and any older ones as to not
# accidentally trigger a false positive later on. # accidentally trigger a false positive later on.
for idx, e in enumerate(self.events): for idx, e in enumerate(self.events):
for d in disallow:
if d in e:
raise Exception('Event %s found while waiting for %s' % (d, event))
if event in e: if event in e:
self.events = self.events[:idx] self.events = self.events[:idx]
return e return e
return False return False
def wait_for_event(self, event, timeout=10): def wait_for_event(self, event, timeout=10, disallow=[]):
if event == 'AP-ENABLED': if event == 'AP-ENABLED':
if self.enabled: if self.enabled:
return 'AP-ENABLED' return 'AP-ENABLED'
return ctx.non_block_wait(self._poll_event, timeout, event, return ctx.non_block_wait(self._poll_event, timeout, event, disallow,
exception=TimeoutError("waiting for event")) exception=TimeoutError("waiting for event"))
def _data_available(self): def _data_available(self):
@ -166,8 +169,8 @@ class HostapdCLI(object):
self.events = [] self.events = []
cmd = 'EAPOL_REAUTH ' + client_address cmd = 'EAPOL_REAUTH ' + client_address
self.ctrl_sock.sendall(cmd.encode('utf-8')) self.ctrl_sock.sendall(cmd.encode('utf-8'))
self.wait_for_event('CTRL-EVENT-EAP-STARTED') self.wait_for_event('CTRL-EVENT-EAP-STARTED', disallow=['AP-STA-DISCONNECTED'])
self.wait_for_event('CTRL-EVENT-EAP-SUCCESS') self.wait_for_event('CTRL-EVENT-EAP-SUCCESS', disallow=['AP-STA-DISCONNECTED'])
def reload(self): def reload(self):
# Seemingly all three commands needed for the instance to notice # Seemingly all three commands needed for the instance to notice
@ -234,7 +237,8 @@ class HostapdCLI(object):
if address: if address:
cmd = 'REKEY_PTK %s' % address cmd = 'REKEY_PTK %s' % address
self.ctrl_sock.sendall(cmd.encode('utf-8')) self.ctrl_sock.sendall(cmd.encode('utf-8'))
self.wait_for_event('EAPOL-4WAY-HS-COMPLETED') self.events = []
self.wait_for_event('EAPOL-4WAY-HS-COMPLETED', disallow=['AP-STA-DISCONNECTED'])
return return
cmd = 'REKEY_GTK' cmd = 'REKEY_GTK'