From e129e6bd27c371a2f395843155b3d505c0fadb77 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Tue, 6 Feb 2018 22:07:57 +0200 Subject: [PATCH] tests: sigma_dut DPP roles incompatible Signed-off-by: Jouni Malinen --- tests/hwsim/test_sigma_dut.py | 94 +++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/tests/hwsim/test_sigma_dut.py b/tests/hwsim/test_sigma_dut.py index 7873dc1fe..0ea7c759c 100644 --- a/tests/hwsim/test_sigma_dut.py +++ b/tests/hwsim/test_sigma_dut.py @@ -1396,6 +1396,100 @@ def run_sigma_dut_dpp_qr_init_configurator(dev, apdev, conf_idx, finally: stop_sigma_dut(sigma) +def test_sigma_dut_dpp_incompatible_roles_init(dev, apdev): + """sigma_dut DPP roles incompatible (Initiator)""" + check_dpp_capab(dev[0]) + check_dpp_capab(dev[1]) + sigma = start_sigma_dut(dev[0].ifname) + try: + res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR") + if "status,COMPLETE" not in res: + raise Exception("dev_exec_action did not succeed: " + res) + hex = res.split(',')[3] + uri = hex.decode('hex') + logger.info("URI from sigma_dut: " + uri) + + res = dev[1].request("DPP_QR_CODE " + uri) + if "FAIL" in res: + raise Exception("Failed to parse QR Code URI") + id1 = int(res) + + addr = dev[1].own_addr().replace(':', '') + cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr + res = dev[1].request(cmd) + if "FAIL" in res: + raise Exception("Failed to generate bootstrapping info") + id0 = int(res) + uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) + + cmd = "DPP_LISTEN 2437 role=enrollee" + if "OK" not in dev[1].request(cmd): + raise Exception("Failed to start listen operation") + + res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex')) + if "status,COMPLETE" not in res: + raise Exception("dev_exec_action did not succeed: " + res) + + cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6" + res = sigma_dut_cmd(cmd) + if "BootstrapResult,OK,AuthResult,ROLES_NOT_COMPATIBLE" not in res: + raise Exception("Unexpected result: " + res) + finally: + stop_sigma_dut(sigma) + +def dpp_init_enrollee_mutual(dev, id1, own_id): + logger.info("Starting DPP initiator/enrollee in a thread") + time.sleep(1) + cmd = "DPP_AUTH_INIT peer=%d own=%d role=enrollee" % (id1, own_id) + if "OK" not in dev.request(cmd): + raise Exception("Failed to initiate DPP Authentication") + ev = dev.wait_event(["DPP-CONF-RECEIVED", + "DPP-NOT-COMPATIBLE"], timeout=5) + if ev is None: + raise Exception("DPP configuration not completed (Enrollee)") + logger.info("DPP initiator/enrollee done") + +def test_sigma_dut_dpp_incompatible_roles_resp(dev, apdev): + """sigma_dut DPP roles incompatible (Responder)""" + check_dpp_capab(dev[0]) + check_dpp_capab(dev[1]) + sigma = start_sigma_dut(dev[0].ifname) + try: + cmd = "dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR" + res = sigma_dut_cmd(cmd) + if "status,COMPLETE" not in res: + raise Exception("dev_exec_action did not succeed: " + res) + hex = res.split(',')[3] + uri = hex.decode('hex') + logger.info("URI from sigma_dut: " + uri) + + res = dev[1].request("DPP_QR_CODE " + uri) + if "FAIL" in res: + raise Exception("Failed to parse QR Code URI") + id1 = int(res) + + addr = dev[1].own_addr().replace(':', '') + cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr + res = dev[1].request(cmd) + if "FAIL" in res: + raise Exception("Failed to generate bootstrapping info") + id0 = int(res) + uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0) + + res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex')) + if "status,COMPLETE" not in res: + raise Exception("dev_exec_action did not succeed: " + res) + + t = threading.Thread(target=dpp_init_enrollee_mutual, args=(dev[1], id1, id0)) + t.start() + cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6" + res = sigma_dut_cmd(cmd, timeout=10) + t.join() + if "BootstrapResult,OK,AuthResult,ROLES_NOT_COMPATIBLE" not in res: + raise Exception("Unexpected result: " + res) + finally: + stop_sigma_dut(sigma) + def test_sigma_dut_dpp_pkex_init_configurator(dev, apdev): """sigma_dut DPP/PKEX initiator as Configurator""" check_dpp_capab(dev[0])