2013-03-30 12:47:22 +01:00
|
|
|
# Protected management frames tests
|
|
|
|
# Copyright (c) 2013, Jouni Malinen <j@w1.fi>
|
|
|
|
#
|
|
|
|
# This software may be distributed under the terms of the BSD license.
|
|
|
|
# See README for more details.
|
|
|
|
|
|
|
|
import time
|
|
|
|
import subprocess
|
|
|
|
import logging
|
2013-10-31 11:46:42 +01:00
|
|
|
logger = logging.getLogger()
|
2013-03-30 12:47:22 +01:00
|
|
|
|
|
|
|
import hwsim_utils
|
|
|
|
import hostapd
|
|
|
|
from wlantest import Wlantest
|
2014-03-13 00:27:40 +01:00
|
|
|
from wpasupplicant import WpaSupplicant
|
2013-03-30 12:47:22 +01:00
|
|
|
|
2013-03-31 15:16:37 +02:00
|
|
|
def test_ap_pmf_required(dev, apdev):
|
2013-03-30 12:47:22 +01:00
|
|
|
"""WPA2-PSK AP with PMF required"""
|
|
|
|
ssid = "test-pmf-required"
|
|
|
|
params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
|
|
|
|
params["wpa_key_mgmt"] = "WPA-PSK-SHA256";
|
|
|
|
params["ieee80211w"] = "2";
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2016-05-19 15:06:49 +02:00
|
|
|
Wlantest.setup(hapd)
|
|
|
|
wt = Wlantest()
|
|
|
|
wt.flush()
|
|
|
|
wt.add_passphrase("12345678")
|
2014-03-22 17:57:44 +01:00
|
|
|
key_mgmt = hapd.get_config()['key_mgmt']
|
|
|
|
if key_mgmt.split(' ')[0] != "WPA-PSK-SHA256":
|
|
|
|
raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
|
2013-03-31 15:16:37 +02:00
|
|
|
dev[0].connect(ssid, psk="12345678", ieee80211w="1",
|
2013-11-02 10:22:16 +01:00
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2014-04-26 16:18:37 +02:00
|
|
|
if "[WPA2-PSK-SHA256-CCMP]" not in dev[0].request("SCAN_RESULTS"):
|
|
|
|
raise Exception("Scan results missing RSN element info")
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], hapd)
|
2013-03-31 15:16:37 +02:00
|
|
|
dev[1].connect(ssid, psk="12345678", ieee80211w="2",
|
2013-11-02 10:22:16 +01:00
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[1], hapd)
|
2013-03-30 14:31:50 +01:00
|
|
|
hapd.request("SA_QUERY " + dev[0].p2p_interface_addr())
|
|
|
|
hapd.request("SA_QUERY " + dev[1].p2p_interface_addr())
|
2013-03-31 15:16:37 +02:00
|
|
|
wt.require_ap_pmf_mandatory(apdev[0]['bssid'])
|
|
|
|
wt.require_sta_pmf(apdev[0]['bssid'], dev[0].p2p_interface_addr())
|
|
|
|
wt.require_sta_pmf_mandatory(apdev[0]['bssid'], dev[1].p2p_interface_addr())
|
2013-03-30 14:31:50 +01:00
|
|
|
time.sleep(0.1)
|
2013-03-31 15:16:37 +02:00
|
|
|
if wt.get_sta_counter("valid_saqueryresp_tx", apdev[0]['bssid'],
|
2013-03-30 14:31:50 +01:00
|
|
|
dev[0].p2p_interface_addr()) < 1:
|
|
|
|
raise Exception("STA did not reply to SA Query")
|
2013-03-31 15:16:37 +02:00
|
|
|
if wt.get_sta_counter("valid_saqueryresp_tx", apdev[0]['bssid'],
|
2013-03-30 14:31:50 +01:00
|
|
|
dev[1].p2p_interface_addr()) < 1:
|
|
|
|
raise Exception("STA did not reply to SA Query")
|
2013-03-30 12:47:22 +01:00
|
|
|
|
2013-03-31 15:16:37 +02:00
|
|
|
def test_ap_pmf_optional(dev, apdev):
|
2013-03-30 12:47:22 +01:00
|
|
|
"""WPA2-PSK AP with PMF optional"""
|
|
|
|
ssid = "test-pmf-optional"
|
|
|
|
params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
|
|
|
|
params["wpa_key_mgmt"] = "WPA-PSK";
|
|
|
|
params["ieee80211w"] = "1";
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2016-05-19 15:06:49 +02:00
|
|
|
Wlantest.setup(hapd)
|
|
|
|
wt = Wlantest()
|
|
|
|
wt.flush()
|
|
|
|
wt.add_passphrase("12345678")
|
2013-03-31 15:16:37 +02:00
|
|
|
dev[0].connect(ssid, psk="12345678", ieee80211w="1",
|
2013-11-02 10:22:16 +01:00
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], hapd)
|
2013-03-31 15:16:37 +02:00
|
|
|
dev[1].connect(ssid, psk="12345678", ieee80211w="2",
|
2013-11-02 10:22:16 +01:00
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[1], hapd)
|
2013-03-31 15:16:37 +02:00
|
|
|
wt.require_ap_pmf_optional(apdev[0]['bssid'])
|
|
|
|
wt.require_sta_pmf(apdev[0]['bssid'], dev[0].p2p_interface_addr())
|
|
|
|
wt.require_sta_pmf_mandatory(apdev[0]['bssid'], dev[1].p2p_interface_addr())
|
2013-03-30 12:47:22 +01:00
|
|
|
|
2013-03-31 15:16:37 +02:00
|
|
|
def test_ap_pmf_optional_2akm(dev, apdev):
|
2013-03-30 12:47:22 +01:00
|
|
|
"""WPA2-PSK AP with PMF optional (2 AKMs)"""
|
|
|
|
ssid = "test-pmf-optional-2akm"
|
|
|
|
params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
|
|
|
|
params["wpa_key_mgmt"] = "WPA-PSK WPA-PSK-SHA256";
|
|
|
|
params["ieee80211w"] = "1";
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2016-05-19 15:06:49 +02:00
|
|
|
Wlantest.setup(hapd)
|
|
|
|
wt = Wlantest()
|
|
|
|
wt.flush()
|
|
|
|
wt.add_passphrase("12345678")
|
2013-03-31 15:16:37 +02:00
|
|
|
dev[0].connect(ssid, psk="12345678", ieee80211w="1",
|
2013-11-02 10:22:16 +01:00
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], hapd)
|
2013-03-31 15:16:37 +02:00
|
|
|
dev[1].connect(ssid, psk="12345678", ieee80211w="2",
|
2013-11-02 10:22:16 +01:00
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[1], hapd)
|
2013-03-31 15:16:37 +02:00
|
|
|
wt.require_ap_pmf_optional(apdev[0]['bssid'])
|
|
|
|
wt.require_sta_pmf(apdev[0]['bssid'], dev[0].p2p_interface_addr())
|
|
|
|
wt.require_sta_key_mgmt(apdev[0]['bssid'], dev[0].p2p_interface_addr(),
|
|
|
|
"PSK-SHA256")
|
|
|
|
wt.require_sta_pmf_mandatory(apdev[0]['bssid'], dev[1].p2p_interface_addr())
|
|
|
|
wt.require_sta_key_mgmt(apdev[0]['bssid'], dev[1].p2p_interface_addr(),
|
|
|
|
"PSK-SHA256")
|
2013-03-30 12:47:22 +01:00
|
|
|
|
2013-03-31 15:16:37 +02:00
|
|
|
def test_ap_pmf_negative(dev, apdev):
|
2013-03-30 12:47:22 +01:00
|
|
|
"""WPA2-PSK AP without PMF (negative test)"""
|
|
|
|
ssid = "test-pmf-negative"
|
2016-05-19 15:06:49 +02:00
|
|
|
params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
|
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
|
|
|
Wlantest.setup(hapd)
|
2013-03-30 12:47:22 +01:00
|
|
|
wt = Wlantest()
|
|
|
|
wt.flush()
|
|
|
|
wt.add_passphrase("12345678")
|
2013-03-31 15:16:37 +02:00
|
|
|
dev[0].connect(ssid, psk="12345678", ieee80211w="1",
|
2013-11-02 10:22:16 +01:00
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[0], hapd)
|
2013-03-30 12:47:22 +01:00
|
|
|
try:
|
2013-03-31 15:16:37 +02:00
|
|
|
dev[1].connect(ssid, psk="12345678", ieee80211w="2",
|
2013-11-02 10:22:16 +01:00
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2014-10-19 16:54:49 +02:00
|
|
|
hwsim_utils.test_connectivity(dev[1], hapd)
|
2013-03-30 12:47:22 +01:00
|
|
|
raise Exception("PMF required STA connected to no PMF AP")
|
|
|
|
except Exception, e:
|
|
|
|
logger.debug("Ignore expected exception: " + str(e))
|
2013-03-31 15:16:37 +02:00
|
|
|
wt.require_ap_no_pmf(apdev[0]['bssid'])
|
2014-03-13 00:27:40 +01:00
|
|
|
|
|
|
|
def test_ap_pmf_assoc_comeback(dev, apdev):
|
|
|
|
"""WPA2-PSK AP with PMF association comeback"""
|
|
|
|
ssid = "assoc-comeback"
|
|
|
|
params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
|
|
|
|
params["wpa_key_mgmt"] = "WPA-PSK-SHA256";
|
|
|
|
params["ieee80211w"] = "2";
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2016-05-19 15:06:49 +02:00
|
|
|
Wlantest.setup(hapd)
|
|
|
|
wt = Wlantest()
|
|
|
|
wt.flush()
|
|
|
|
wt.add_passphrase("12345678")
|
2014-03-13 00:27:40 +01:00
|
|
|
dev[0].connect(ssid, psk="12345678", ieee80211w="1",
|
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
|
|
|
hapd.set("ext_mgmt_frame_handling", "1")
|
|
|
|
dev[0].request("DISCONNECT")
|
2014-12-20 10:51:30 +01:00
|
|
|
dev[0].wait_disconnected(timeout=10)
|
2014-03-13 00:27:40 +01:00
|
|
|
hapd.set("ext_mgmt_frame_handling", "0")
|
|
|
|
dev[0].request("REASSOCIATE")
|
2014-12-20 10:51:30 +01:00
|
|
|
dev[0].wait_connected(timeout=10, error="Timeout on re-connection")
|
2014-03-13 00:27:40 +01:00
|
|
|
if wt.get_sta_counter("assocresp_comeback", apdev[0]['bssid'],
|
|
|
|
dev[0].p2p_interface_addr()) < 1:
|
|
|
|
raise Exception("AP did not use association comeback request")
|
|
|
|
|
2014-04-05 23:05:06 +02:00
|
|
|
def test_ap_pmf_assoc_comeback2(dev, apdev):
|
|
|
|
"""WPA2-PSK AP with PMF association comeback (using DROP_SA)"""
|
|
|
|
ssid = "assoc-comeback"
|
|
|
|
params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
|
|
|
|
params["wpa_key_mgmt"] = "WPA-PSK";
|
|
|
|
params["ieee80211w"] = "1";
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2016-05-19 15:06:49 +02:00
|
|
|
Wlantest.setup(hapd)
|
|
|
|
wt = Wlantest()
|
|
|
|
wt.flush()
|
|
|
|
wt.add_passphrase("12345678")
|
2014-04-05 23:05:06 +02:00
|
|
|
dev[0].connect(ssid, psk="12345678", ieee80211w="2",
|
|
|
|
key_mgmt="WPA-PSK", proto="WPA2", scan_freq="2412")
|
|
|
|
if "OK" not in dev[0].request("DROP_SA"):
|
|
|
|
raise Exception("DROP_SA failed")
|
|
|
|
dev[0].request("REASSOCIATE")
|
2014-12-20 10:51:30 +01:00
|
|
|
dev[0].wait_connected(timeout=10, error="Timeout on re-connection")
|
2014-04-05 23:05:06 +02:00
|
|
|
if wt.get_sta_counter("reassocresp_comeback", apdev[0]['bssid'],
|
|
|
|
dev[0].p2p_interface_addr()) < 1:
|
|
|
|
raise Exception("AP did not use reassociation comeback request")
|
|
|
|
|
2014-03-13 00:27:40 +01:00
|
|
|
def test_ap_pmf_sta_sa_query(dev, apdev):
|
|
|
|
"""WPA2-PSK AP with station using SA Query"""
|
|
|
|
ssid = "assoc-comeback"
|
2015-02-04 10:30:32 +01:00
|
|
|
addr = dev[0].own_addr()
|
2014-03-13 00:27:40 +01:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="use_monitor=1")
|
|
|
|
id = wpas.add_network()
|
|
|
|
wpas.set_network(id, "mode", "2")
|
|
|
|
wpas.set_network_quoted(id, "ssid", ssid)
|
|
|
|
wpas.set_network(id, "proto", "WPA2")
|
|
|
|
wpas.set_network(id, "key_mgmt", "WPA-PSK-SHA256")
|
|
|
|
wpas.set_network(id, "ieee80211w", "2")
|
|
|
|
wpas.set_network_quoted(id, "psk", "12345678")
|
|
|
|
wpas.set_network(id, "pairwise", "CCMP")
|
|
|
|
wpas.set_network(id, "group", "CCMP")
|
|
|
|
wpas.set_network(id, "frequency", "2412")
|
|
|
|
wpas.connect_network(id)
|
2015-02-04 10:30:32 +01:00
|
|
|
bssid = wpas.own_addr()
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2014-03-13 00:27:40 +01:00
|
|
|
|
2016-05-19 15:06:49 +02:00
|
|
|
Wlantest.setup(wpas)
|
|
|
|
wt = Wlantest()
|
|
|
|
wt.flush()
|
|
|
|
wt.add_passphrase("12345678")
|
|
|
|
|
2014-03-13 00:27:40 +01:00
|
|
|
dev[0].connect(ssid, psk="12345678", ieee80211w="1",
|
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2014-03-13 00:27:40 +01:00
|
|
|
wpas.request("DEAUTHENTICATE " + addr + " test=0")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2014-03-13 00:27:40 +01:00
|
|
|
wpas.request("DISASSOCIATE " + addr + " test=0")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2014-03-13 00:27:40 +01:00
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1)
|
|
|
|
if ev is not None:
|
|
|
|
raise Exception("Unexpected disconnection")
|
|
|
|
|
|
|
|
wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2014-03-13 00:27:40 +01:00
|
|
|
wpas.request("DISASSOCIATE " + addr + " reason=7 test=0")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2014-03-13 00:27:40 +01:00
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1)
|
|
|
|
if ev is not None:
|
|
|
|
raise Exception("Unexpected disconnection")
|
|
|
|
if wt.get_sta_counter("valid_saqueryreq_tx", bssid, addr) < 1:
|
|
|
|
raise Exception("STA did not send SA Query")
|
|
|
|
if wt.get_sta_counter("valid_saqueryresp_rx", bssid, addr) < 1:
|
|
|
|
raise Exception("AP did not reply to SA Query")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2014-03-22 17:57:44 +01:00
|
|
|
|
2015-01-16 00:13:59 +01:00
|
|
|
def test_ap_pmf_sta_sa_query_no_response(dev, apdev):
|
|
|
|
"""WPA2-PSK AP with station using SA Query and getting no response"""
|
|
|
|
ssid = "assoc-comeback"
|
2015-05-05 11:36:49 +02:00
|
|
|
addr = dev[0].own_addr()
|
2015-01-16 00:13:59 +01:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="use_monitor=1")
|
|
|
|
id = wpas.add_network()
|
|
|
|
wpas.set_network(id, "mode", "2")
|
|
|
|
wpas.set_network_quoted(id, "ssid", ssid)
|
|
|
|
wpas.set_network(id, "proto", "WPA2")
|
|
|
|
wpas.set_network(id, "key_mgmt", "WPA-PSK-SHA256")
|
|
|
|
wpas.set_network(id, "ieee80211w", "2")
|
|
|
|
wpas.set_network_quoted(id, "psk", "12345678")
|
|
|
|
wpas.set_network(id, "pairwise", "CCMP")
|
|
|
|
wpas.set_network(id, "group", "CCMP")
|
|
|
|
wpas.set_network(id, "frequency", "2412")
|
|
|
|
wpas.connect_network(id)
|
2015-02-04 10:30:32 +01:00
|
|
|
bssid = wpas.own_addr()
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2015-01-16 00:13:59 +01:00
|
|
|
|
|
|
|
dev[0].connect(ssid, psk="12345678", ieee80211w="1",
|
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2015-01-16 00:13:59 +01:00
|
|
|
wpas.request("DEAUTHENTICATE " + addr + " test=0")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2015-01-16 00:13:59 +01:00
|
|
|
wpas.request("DISASSOCIATE " + addr + " test=0")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2015-01-16 00:13:59 +01:00
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1)
|
|
|
|
if ev is not None:
|
|
|
|
raise Exception("Unexpected disconnection")
|
|
|
|
|
|
|
|
wpas.request("SET ext_mgmt_frame_handling 1")
|
|
|
|
wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2015-01-16 00:13:59 +01:00
|
|
|
wpas.request("DISASSOCIATE " + addr + " reason=7 test=0")
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2015-01-16 00:13:59 +01:00
|
|
|
dev[0].wait_disconnected()
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2015-01-16 00:13:59 +01:00
|
|
|
wpas.request("SET ext_mgmt_frame_handling 0")
|
|
|
|
dev[0].wait_connected()
|
2015-10-04 00:42:42 +02:00
|
|
|
wpas.dump_monitor()
|
2015-01-16 00:13:59 +01:00
|
|
|
|
2014-06-19 19:59:46 +02:00
|
|
|
def test_ap_pmf_sta_unprot_deauth_burst(dev, apdev):
|
|
|
|
"""WPA2-PSK AP with station receiving burst of unprotected Deauthentication frames"""
|
|
|
|
ssid = "deauth-attack"
|
2015-02-04 10:30:32 +01:00
|
|
|
addr = dev[0].own_addr()
|
2014-06-19 19:59:46 +02:00
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="use_monitor=1")
|
|
|
|
id = wpas.add_network()
|
|
|
|
wpas.set_network(id, "mode", "2")
|
|
|
|
wpas.set_network_quoted(id, "ssid", ssid)
|
|
|
|
wpas.set_network(id, "proto", "WPA2")
|
|
|
|
wpas.set_network(id, "key_mgmt", "WPA-PSK-SHA256")
|
|
|
|
wpas.set_network(id, "ieee80211w", "2")
|
|
|
|
wpas.set_network_quoted(id, "psk", "12345678")
|
|
|
|
wpas.set_network(id, "pairwise", "CCMP")
|
|
|
|
wpas.set_network(id, "group", "CCMP")
|
|
|
|
wpas.set_network(id, "frequency", "2412")
|
|
|
|
wpas.connect_network(id)
|
2015-05-05 11:36:49 +02:00
|
|
|
bssid = wpas.own_addr()
|
2014-06-19 19:59:46 +02:00
|
|
|
|
2016-05-19 15:06:49 +02:00
|
|
|
Wlantest.setup(wpas)
|
|
|
|
wt = Wlantest()
|
|
|
|
wt.flush()
|
|
|
|
wt.add_passphrase("12345678")
|
|
|
|
|
2014-06-19 19:59:46 +02:00
|
|
|
dev[0].connect(ssid, psk="12345678", ieee80211w="1",
|
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
|
|
|
|
|
|
|
for i in range(0, 10):
|
|
|
|
wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0")
|
|
|
|
wpas.request("DISASSOCIATE " + addr + " reason=7 test=0")
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1)
|
|
|
|
if ev is not None:
|
|
|
|
raise Exception("Unexpected disconnection")
|
|
|
|
num_req = wt.get_sta_counter("valid_saqueryreq_tx", bssid, addr)
|
|
|
|
num_resp = wt.get_sta_counter("valid_saqueryresp_rx", bssid, addr)
|
|
|
|
if num_req < 1:
|
|
|
|
raise Exception("STA did not send SA Query")
|
|
|
|
if num_resp < 1:
|
|
|
|
raise Exception("AP did not reply to SA Query")
|
|
|
|
if num_req > 1:
|
|
|
|
raise Exception("STA initiated too many SA Query procedures (%d)" % num_req)
|
|
|
|
|
|
|
|
time.sleep(10)
|
|
|
|
for i in range(0, 5):
|
|
|
|
wpas.request("DEAUTHENTICATE " + addr + " reason=6 test=0")
|
|
|
|
wpas.request("DISASSOCIATE " + addr + " reason=7 test=0")
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=1)
|
|
|
|
if ev is not None:
|
|
|
|
raise Exception("Unexpected disconnection")
|
|
|
|
num_req = wt.get_sta_counter("valid_saqueryreq_tx", bssid, addr)
|
|
|
|
num_resp = wt.get_sta_counter("valid_saqueryresp_rx", bssid, addr)
|
|
|
|
if num_req != 2 or num_resp != 2:
|
|
|
|
raise Exception("Unexpected number of SA Query procedures (req=%d resp=%d)" % (num_req, num_resp))
|
|
|
|
|
2014-03-22 17:57:44 +01:00
|
|
|
def test_ap_pmf_required_eap(dev, apdev):
|
|
|
|
"""WPA2-EAP AP with PMF required"""
|
|
|
|
ssid = "test-pmf-required-eap"
|
|
|
|
params = hostapd.wpa2_eap_params(ssid=ssid)
|
|
|
|
params["wpa_key_mgmt"] = "WPA-EAP-SHA256";
|
|
|
|
params["ieee80211w"] = "2";
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2014-03-22 17:57:44 +01:00
|
|
|
key_mgmt = hapd.get_config()['key_mgmt']
|
|
|
|
if key_mgmt.split(' ')[0] != "WPA-EAP-SHA256":
|
|
|
|
raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
|
|
|
|
dev[0].connect("test-pmf-required-eap", key_mgmt="WPA-EAP-SHA256",
|
|
|
|
ieee80211w="2", eap="PSK", identity="psk.user@example.com",
|
2015-06-06 16:13:21 +02:00
|
|
|
password_hex="0123456789abcdef0123456789abcdef",
|
|
|
|
scan_freq="2412")
|
|
|
|
dev[1].connect("test-pmf-required-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
|
|
|
|
ieee80211w="1", eap="PSK", identity="psk.user@example.com",
|
|
|
|
password_hex="0123456789abcdef0123456789abcdef",
|
|
|
|
scan_freq="2412")
|
|
|
|
|
|
|
|
def test_ap_pmf_optional_eap(dev, apdev):
|
|
|
|
"""WPA2EAP AP with PMF optional"""
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
|
|
|
|
params["ieee80211w"] = "1";
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2015-06-06 16:13:21 +02:00
|
|
|
dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
|
|
|
|
identity="pap user", anonymous_identity="ttls",
|
|
|
|
password="password",
|
|
|
|
ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
|
|
|
|
ieee80211w="1", scan_freq="2412")
|
|
|
|
dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP WPA-EAP-SHA256",
|
|
|
|
eap="TTLS", identity="pap user", anonymous_identity="ttls",
|
|
|
|
password="password",
|
|
|
|
ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
|
|
|
|
ieee80211w="2", scan_freq="2412")
|
2014-11-14 19:56:43 +01:00
|
|
|
|
|
|
|
def test_ap_pmf_required_sha1(dev, apdev):
|
|
|
|
"""WPA2-PSK AP with PMF required with SHA1 AKM"""
|
|
|
|
ssid = "test-pmf-required-sha1"
|
|
|
|
params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
|
|
|
|
params["wpa_key_mgmt"] = "WPA-PSK";
|
|
|
|
params["ieee80211w"] = "2";
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2016-05-19 15:06:49 +02:00
|
|
|
Wlantest.setup(hapd)
|
|
|
|
wt = Wlantest()
|
|
|
|
wt.flush()
|
|
|
|
wt.add_passphrase("12345678")
|
2014-11-14 19:56:43 +01:00
|
|
|
key_mgmt = hapd.get_config()['key_mgmt']
|
|
|
|
if key_mgmt.split(' ')[0] != "WPA-PSK":
|
|
|
|
raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
|
|
|
|
dev[0].connect(ssid, psk="12345678", ieee80211w="2",
|
|
|
|
key_mgmt="WPA-PSK", proto="WPA2", scan_freq="2412")
|
|
|
|
if "[WPA2-PSK-CCMP]" not in dev[0].request("SCAN_RESULTS"):
|
|
|
|
raise Exception("Scan results missing RSN element info")
|
|
|
|
hwsim_utils.test_connectivity(dev[0], hapd)
|
2015-02-19 15:37:12 +01:00
|
|
|
|
|
|
|
def test_ap_pmf_toggle(dev, apdev):
|
|
|
|
"""WPA2-PSK AP with PMF optional and changing PMF on reassociation"""
|
|
|
|
try:
|
|
|
|
_test_ap_pmf_toggle(dev, apdev)
|
|
|
|
finally:
|
|
|
|
dev[0].request("SET reassoc_same_bss_optim 0")
|
|
|
|
|
|
|
|
def _test_ap_pmf_toggle(dev, apdev):
|
|
|
|
ssid = "test-pmf-optional"
|
|
|
|
params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
|
|
|
|
params["wpa_key_mgmt"] = "WPA-PSK";
|
|
|
|
params["ieee80211w"] = "1";
|
|
|
|
params["assoc_sa_query_max_timeout"] = "1"
|
|
|
|
params["assoc_sa_query_retry_timeout"] = "1"
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2016-05-19 15:06:49 +02:00
|
|
|
Wlantest.setup(hapd)
|
|
|
|
wt = Wlantest()
|
|
|
|
wt.flush()
|
|
|
|
wt.add_passphrase("12345678")
|
2015-02-19 15:37:12 +01:00
|
|
|
bssid = apdev[0]['bssid']
|
|
|
|
addr = dev[0].own_addr()
|
|
|
|
dev[0].request("SET reassoc_same_bss_optim 1")
|
|
|
|
id = dev[0].connect(ssid, psk="12345678", ieee80211w="1",
|
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412")
|
|
|
|
wt.require_ap_pmf_optional(bssid)
|
|
|
|
wt.require_sta_pmf(bssid, addr)
|
|
|
|
sta = hapd.get_sta(addr)
|
|
|
|
if '[MFP]' not in sta['flags']:
|
|
|
|
raise Exception("MFP flag not present for STA")
|
|
|
|
|
|
|
|
dev[0].set_network(id, "ieee80211w", "0")
|
|
|
|
dev[0].request("REASSOCIATE")
|
|
|
|
dev[0].wait_connected()
|
|
|
|
wt.require_sta_no_pmf(bssid, addr)
|
|
|
|
sta = hapd.get_sta(addr)
|
|
|
|
if '[MFP]' in sta['flags']:
|
|
|
|
raise Exception("MFP flag unexpectedly present for STA")
|
|
|
|
cmd = subprocess.Popen(['iw', 'dev', apdev[0]['ifname'], 'station', 'get',
|
|
|
|
addr], stdout=subprocess.PIPE)
|
|
|
|
(data,err) = cmd.communicate()
|
|
|
|
if "yes" in [l for l in data.splitlines() if "MFP" in l][0]:
|
|
|
|
raise Exception("Kernel STA entry had MFP enabled")
|
|
|
|
|
|
|
|
dev[0].set_network(id, "ieee80211w", "1")
|
|
|
|
dev[0].request("REASSOCIATE")
|
|
|
|
dev[0].wait_connected()
|
|
|
|
wt.require_sta_pmf(bssid, addr)
|
|
|
|
sta = hapd.get_sta(addr)
|
|
|
|
if '[MFP]' not in sta['flags']:
|
|
|
|
raise Exception("MFP flag not present for STA")
|
|
|
|
cmd = subprocess.Popen(['iw', 'dev', apdev[0]['ifname'], 'station', 'get',
|
|
|
|
addr], stdout=subprocess.PIPE)
|
|
|
|
(data,err) = cmd.communicate()
|
|
|
|
if "yes" not in [l for l in data.splitlines() if "MFP" in l][0]:
|
|
|
|
raise Exception("Kernel STA entry did not have MFP enabled")
|
2015-10-25 14:13:53 +01:00
|
|
|
|
|
|
|
def test_ap_pmf_required_sta_no_pmf(dev, apdev):
|
|
|
|
"""WPA2-PSK AP with PMF required and PMF disabled on STA"""
|
|
|
|
ssid = "test-pmf-required"
|
|
|
|
params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
|
|
|
|
params["wpa_key_mgmt"] = "WPA-PSK-SHA256";
|
|
|
|
params["ieee80211w"] = "2";
|
2016-03-30 10:55:56 +02:00
|
|
|
hapd = hostapd.add_ap(apdev[0], params)
|
2015-10-25 14:13:53 +01:00
|
|
|
|
|
|
|
# Disable PMF on the station and try to connect
|
|
|
|
dev[0].connect(ssid, psk="12345678", ieee80211w="0",
|
|
|
|
key_mgmt="WPA-PSK WPA-PSK-SHA256", proto="WPA2",
|
|
|
|
scan_freq="2412", wait_connect=False)
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND",
|
|
|
|
"CTRL-EVENT-ASSOC-REJECT"], timeout=2)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("No connection result")
|
|
|
|
if "CTRL-EVENT-ASSOC-REJECT" in ev:
|
|
|
|
raise Exception("Tried to connect to PMF required AP without PMF enabled")
|
|
|
|
dev[0].request("REMOVE_NETWORK all")
|