mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2025-01-30 00:34:03 -05:00
tests: Validate GO Negotiation status code
Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
809079d3ea
commit
f7b1a75036
@ -11,7 +11,7 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
import hwsim_utils
|
import hwsim_utils
|
||||||
|
|
||||||
def go_neg_pin_authorized(i_dev, r_dev, i_intent=None, r_intent=None, expect_failure=False):
|
def go_neg_pin_authorized(i_dev, r_dev, i_intent=None, r_intent=None, expect_failure=False, i_go_neg_status=None):
|
||||||
r_dev.p2p_listen()
|
r_dev.p2p_listen()
|
||||||
i_dev.p2p_listen()
|
i_dev.p2p_listen()
|
||||||
pin = r_dev.wps_read_pin()
|
pin = r_dev.wps_read_pin()
|
||||||
@ -23,6 +23,11 @@ def go_neg_pin_authorized(i_dev, r_dev, i_intent=None, r_intent=None, expect_fai
|
|||||||
logger.debug("r_res: " + str(r_res))
|
logger.debug("r_res: " + str(r_res))
|
||||||
r_dev.dump_monitor()
|
r_dev.dump_monitor()
|
||||||
i_dev.dump_monitor()
|
i_dev.dump_monitor()
|
||||||
|
if i_go_neg_status:
|
||||||
|
if i_res['result'] != 'go-neg-failed':
|
||||||
|
raise Exception("Expected GO Negotiation failure not reported")
|
||||||
|
if i_res['status'] != i_go_neg_status:
|
||||||
|
raise Exception("Expected GO Negotiation status not seen")
|
||||||
if expect_failure:
|
if expect_failure:
|
||||||
return
|
return
|
||||||
logger.info("Group formed")
|
logger.info("Group formed")
|
||||||
@ -45,7 +50,7 @@ def test_grpform2(dev):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def test_both_go_intent_15(dev):
|
def test_both_go_intent_15(dev):
|
||||||
go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=15, expect_failure=True)
|
go_neg_pin_authorized(i_dev=dev[0], i_intent=15, r_dev=dev[1], r_intent=15, expect_failure=True, i_go_neg_status=9)
|
||||||
|
|
||||||
def add_tests(tests):
|
def add_tests(tests):
|
||||||
tests.append(test_grpform)
|
tests.append(test_grpform)
|
||||||
|
@ -82,7 +82,22 @@ class WpaSupplicant:
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def group_form_result(self, ev):
|
def group_form_result(self, ev, expect_failure=False):
|
||||||
|
if expect_failure:
|
||||||
|
if "P2P-GROUP-STARTED" in ev:
|
||||||
|
raise Exception("Group formation succeeded when expecting failure")
|
||||||
|
exp = r'<.>(P2P-GO-NEG-FAILURE) status=([0-9]*)'
|
||||||
|
s = re.split(exp, ev)
|
||||||
|
if len(s) < 3:
|
||||||
|
return None
|
||||||
|
res = {}
|
||||||
|
res['result'] = 'go-neg-failed'
|
||||||
|
res['status'] = int(s[2])
|
||||||
|
return res
|
||||||
|
|
||||||
|
if "P2P-GROUP-STARTED" not in ev:
|
||||||
|
raise Exception("No P2P-GROUP-STARTED event seen")
|
||||||
|
|
||||||
exp = r'<.>(P2P-GROUP-STARTED) ([^ ]*) ([^ ]*) ssid="(.*)" freq=([0-9]*) ((?:psk=.*)|(?:passphrase=".*")) go_dev_addr=([0-9a-f:]*)'
|
exp = r'<.>(P2P-GROUP-STARTED) ([^ ]*) ([^ ]*) ssid="(.*)" freq=([0-9]*) ((?:psk=.*)|(?:passphrase=".*")) go_dev_addr=([0-9a-f:]*)'
|
||||||
s = re.split(exp, ev)
|
s = re.split(exp, ev)
|
||||||
if len(s) < 8:
|
if len(s) < 8:
|
||||||
@ -114,15 +129,13 @@ class WpaSupplicant:
|
|||||||
raise Exception("P2P_CONNECT (auth) failed")
|
raise Exception("P2P_CONNECT (auth) failed")
|
||||||
|
|
||||||
def p2p_go_neg_auth_result(self, timeout=1, expect_failure=False):
|
def p2p_go_neg_auth_result(self, timeout=1, expect_failure=False):
|
||||||
ev = self.wait_event("P2P-GROUP-STARTED", timeout);
|
ev = self.wait_event(["P2P-GROUP-STARTED","P2P-GO-NEG-FAILURE"], timeout);
|
||||||
if ev is None:
|
if ev is None:
|
||||||
if expect_failure:
|
if expect_failure:
|
||||||
return None
|
return None
|
||||||
raise Exception("Group formation timed out")
|
raise Exception("Group formation timed out")
|
||||||
self.dump_monitor()
|
self.dump_monitor()
|
||||||
if expect_failure:
|
return self.group_form_result(ev, expect_failure)
|
||||||
raise Exception("Group formation succeeded when expecting failure")
|
|
||||||
return self.group_form_result(ev)
|
|
||||||
|
|
||||||
def p2p_go_neg_init(self, peer, pin, method, timeout=0, go_intent=None, expect_failure=False):
|
def p2p_go_neg_init(self, peer, pin, method, timeout=0, go_intent=None, expect_failure=False):
|
||||||
if not self.discover_peer(peer):
|
if not self.discover_peer(peer):
|
||||||
@ -135,18 +148,16 @@ class WpaSupplicant:
|
|||||||
if timeout == 0:
|
if timeout == 0:
|
||||||
self.dump_monitor()
|
self.dump_monitor()
|
||||||
return None
|
return None
|
||||||
ev = self.wait_event("P2P-GROUP-STARTED", timeout)
|
ev = self.wait_event(["P2P-GROUP-STARTED","P2P-GO-NEG-FAILURE"], timeout)
|
||||||
if ev is None:
|
if ev is None:
|
||||||
if expect_failure:
|
if expect_failure:
|
||||||
return None
|
return None
|
||||||
raise Exception("Group formation timed out")
|
raise Exception("Group formation timed out")
|
||||||
self.dump_monitor()
|
self.dump_monitor()
|
||||||
if expect_failure:
|
return self.group_form_result(ev, expect_failure)
|
||||||
raise Exception("Group formation succeeded when expecting failure")
|
|
||||||
return self.group_form_result(ev)
|
|
||||||
raise Exception("P2P_CONNECT failed")
|
raise Exception("P2P_CONNECT failed")
|
||||||
|
|
||||||
def wait_event(self, event, timeout):
|
def wait_event(self, events, timeout):
|
||||||
count = 0
|
count = 0
|
||||||
while count < timeout * 2:
|
while count < timeout * 2:
|
||||||
count = count + 1
|
count = count + 1
|
||||||
@ -154,6 +165,7 @@ class WpaSupplicant:
|
|||||||
while self.mon.pending():
|
while self.mon.pending():
|
||||||
ev = self.mon.recv()
|
ev = self.mon.recv()
|
||||||
logger.debug(self.ifname + ": " + ev)
|
logger.debug(self.ifname + ": " + ev)
|
||||||
|
for event in events:
|
||||||
if event in ev:
|
if event in ev:
|
||||||
return ev
|
return ev
|
||||||
return None
|
return None
|
||||||
|
Loading…
Reference in New Issue
Block a user