tests: DPP Controller in hostapd

Signed-off-by: Jouni Malinen <jouni@codeaurora.org>
This commit is contained in:
Jouni Malinen 2020-08-25 15:54:19 +03:00 committed by Jouni Malinen
parent 7ddb71224b
commit 255e29fcae

View file

@ -4774,7 +4774,7 @@ def test_dpp_tcp(dev, apdev, params):
prefix = "dpp_tcp"
cap_lo = os.path.join(params['logdir'], prefix + ".lo.pcap")
try:
run_dpp_tcp(dev, apdev, cap_lo)
run_dpp_tcp(dev[0], dev[1], cap_lo)
finally:
dev[1].request("DPP_CONTROLLER_STOP")
@ -4783,7 +4783,7 @@ def test_dpp_tcp_port(dev, apdev, params):
prefix = "dpp_tcp_port"
cap_lo = os.path.join(params['logdir'], prefix + ".lo.pcap")
try:
run_dpp_tcp(dev, apdev, cap_lo, port="23456")
run_dpp_tcp(dev[0], dev[1], cap_lo, port="23456")
finally:
dev[1].request("DPP_CONTROLLER_STOP")
@ -4791,24 +4791,30 @@ def test_dpp_tcp_mutual(dev, apdev, params):
"""DPP over TCP (mutual)"""
cap_lo = os.path.join(params['prefix'], ".lo.pcap")
try:
run_dpp_tcp(dev, apdev, cap_lo, mutual=True)
run_dpp_tcp(dev[0], dev[1], cap_lo, mutual=True)
finally:
dev[1].request("DPP_CONTROLLER_STOP")
def run_dpp_tcp(dev, apdev, cap_lo, port=None, mutual=False):
check_dpp_capab(dev[0])
check_dpp_capab(dev[1])
def test_dpp_tcp_mutual_hostapd_conf(dev, apdev, params):
"""DPP over TCP (mutual, hostapd as Configurator)"""
cap_lo = os.path.join(params['prefix'], ".lo.pcap")
hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured"})
run_dpp_tcp(dev[0], hapd, cap_lo, mutual=True)
def run_dpp_tcp(dev0, dev1, cap_lo, port=None, mutual=False):
check_dpp_capab(dev0)
check_dpp_capab(dev1)
wt = WlantestCapture('lo', cap_lo)
time.sleep(1)
# Controller
conf_id = dev[1].dpp_configurator_add()
dev[1].set("dpp_configurator_params",
" conf=sta-dpp configurator=%d" % conf_id)
id_c = dev[1].dpp_bootstrap_gen()
uri_c = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id_c)
res = dev[1].request("DPP_BOOTSTRAP_INFO %d" % id_c)
conf_id = dev1.dpp_configurator_add()
dev1.set("dpp_configurator_params",
" conf=sta-dpp configurator=%d" % conf_id)
id_c = dev1.dpp_bootstrap_gen()
uri_c = dev1.request("DPP_BOOTSTRAP_GET_URI %d" % id_c)
res = dev1.request("DPP_BOOTSTRAP_INFO %d" % id_c)
pkhash = None
for line in res.splitlines():
name, value = line.split('=')
@ -4822,35 +4828,35 @@ def run_dpp_tcp(dev, apdev, cap_lo, port=None, mutual=False):
req += " tcp_port=" + port
if mutual:
req += " qr=mutual"
id0 = dev[0].dpp_bootstrap_gen()
uri0 = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
id0 = dev0.dpp_bootstrap_gen()
uri0 = dev0.request("DPP_BOOTSTRAP_GET_URI %d" % id0)
own = id0
else:
own = None
if "OK" not in dev[1].request(req):
if "OK" not in dev1.request(req):
raise Exception("Failed to start Controller")
# Initiate from Enrollee with broadcast DPP Authentication Request
dev[0].dpp_auth_init(uri=uri_c, own=own, role="enrollee",
tcp_addr="127.0.0.1", tcp_port=port)
dev0.dpp_auth_init(uri=uri_c, own=own, role="enrollee",
tcp_addr="127.0.0.1", tcp_port=port)
if mutual:
ev = dev[0].wait_event(["DPP-RESPONSE-PENDING"], timeout=5)
ev = dev0.wait_event(["DPP-RESPONSE-PENDING"], timeout=5)
if ev is None:
raise Exception("Pending response not reported")
ev = dev[1].wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=5)
ev = dev1.wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=5)
if ev is None:
raise Exception("QR Code scan for mutual authentication not requested")
id1 = dev[1].dpp_qr_code(uri0)
id1 = dev1.dpp_qr_code(uri0)
ev = dev[0].wait_event(["DPP-AUTH-DIRECTION"], timeout=5)
ev = dev0.wait_event(["DPP-AUTH-DIRECTION"], timeout=5)
if ev is None:
raise Exception("DPP authentication direction not indicated (Initiator)")
if "mutual=1" not in ev:
raise Exception("Mutual authentication not used")
wait_auth_success(dev[1], dev[0], configurator=dev[1], enrollee=dev[0],
wait_auth_success(dev1, dev0, configurator=dev1, enrollee=dev0,
allow_enrollee_failure=True,
allow_configurator_failure=True)
time.sleep(0.5)
@ -4860,31 +4866,37 @@ def test_dpp_tcp_conf_init(dev, apdev, params):
"""DPP over TCP (Configurator initiates)"""
cap_lo = os.path.join(params['prefix'], ".lo.pcap")
try:
run_dpp_tcp_conf_init(dev, apdev, cap_lo)
run_dpp_tcp_conf_init(dev[0], dev[1], cap_lo)
finally:
dev[1].request("DPP_CONTROLLER_STOP")
def run_dpp_tcp_conf_init(dev, apdev, cap_lo, port=None):
check_dpp_capab(dev[0], min_ver=2)
check_dpp_capab(dev[1], min_ver=2)
def test_dpp_tcp_conf_init_hostapd_enrollee(dev, apdev, params):
"""DPP over TCP (Configurator initiates, hostapd as Enrollee)"""
cap_lo = os.path.join(params['prefix'], ".lo.pcap")
hapd = hostapd.add_ap(apdev[0], {"ssid": "unconfigured"})
run_dpp_tcp_conf_init(dev[0], hapd, cap_lo, conf="ap-dpp")
def run_dpp_tcp_conf_init(dev0, dev1, cap_lo, port=None, conf="sta-dpp"):
check_dpp_capab(dev0, min_ver=2)
check_dpp_capab(dev1, min_ver=2)
wt = WlantestCapture('lo', cap_lo)
time.sleep(1)
id_c = dev[1].dpp_bootstrap_gen()
uri_c = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id_c)
res = dev[1].request("DPP_BOOTSTRAP_INFO %d" % id_c)
id_c = dev1.dpp_bootstrap_gen()
uri_c = dev1.request("DPP_BOOTSTRAP_GET_URI %d" % id_c)
res = dev1.request("DPP_BOOTSTRAP_INFO %d" % id_c)
req = "DPP_CONTROLLER_START role=enrollee"
if port:
req += " tcp_port=" + port
if "OK" not in dev[1].request(req):
if "OK" not in dev1.request(req):
raise Exception("Failed to start Controller")
conf_id = dev[0].dpp_configurator_add()
dev[0].dpp_auth_init(uri=uri_c, role="configurator", conf="sta-dpp",
configurator=conf_id,
tcp_addr="127.0.0.1", tcp_port=port)
wait_auth_success(dev[0], dev[1], configurator=dev[0], enrollee=dev[1],
conf_id = dev0.dpp_configurator_add()
dev0.dpp_auth_init(uri=uri_c, role="configurator", conf=conf,
configurator=conf_id,
tcp_addr="127.0.0.1", tcp_port=port)
wait_auth_success(dev1, dev0, configurator=dev0, enrollee=dev1,
allow_enrollee_failure=True,
allow_configurator_failure=True)
time.sleep(0.5)