2013-12-29 18:25:42 +01:00
|
|
|
# WPA2-Enterprise PMKSA caching tests
|
2014-03-15 10:52:11 +01:00
|
|
|
# Copyright (c) 2013-2014, Jouni Malinen <j@w1.fi>
|
2013-12-29 18:25:42 +01:00
|
|
|
#
|
|
|
|
# This software may be distributed under the terms of the BSD license.
|
|
|
|
# See README for more details.
|
|
|
|
|
|
|
|
import logging
|
|
|
|
logger = logging.getLogger()
|
2014-03-15 10:52:11 +01:00
|
|
|
import subprocess
|
2014-03-09 23:51:14 +01:00
|
|
|
import time
|
2013-12-29 18:25:42 +01:00
|
|
|
|
|
|
|
import hostapd
|
2014-04-12 21:52:41 +02:00
|
|
|
from wpasupplicant import WpaSupplicant
|
2015-01-29 23:14:57 +01:00
|
|
|
from utils import alloc_fail
|
2014-03-15 10:52:11 +01:00
|
|
|
from test_ap_eap import eap_connect
|
2013-12-29 18:25:42 +01:00
|
|
|
|
|
|
|
def test_pmksa_cache_on_roam_back(dev, apdev):
|
|
|
|
"""PMKSA cache to skip EAP on reassociation back to same AP"""
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache")
|
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
bssid = apdev[0]['bssid']
|
|
|
|
dev[0].connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP",
|
|
|
|
eap="GPSK", identity="gpsk user",
|
|
|
|
password="abcdefghijklmnop0123456789abcdef",
|
|
|
|
scan_freq="2412")
|
|
|
|
pmksa = dev[0].get_pmksa(bssid)
|
|
|
|
if pmksa is None:
|
|
|
|
raise Exception("No PMKSA cache entry created")
|
|
|
|
if pmksa['opportunistic'] != '0':
|
|
|
|
raise Exception("Unexpected opportunistic PMKSA cache entry")
|
|
|
|
|
|
|
|
hostapd.add_ap(apdev[1]['ifname'], params)
|
|
|
|
bssid2 = apdev[1]['bssid']
|
|
|
|
|
|
|
|
dev[0].dump_monitor()
|
|
|
|
logger.info("Roam to AP2")
|
2014-05-13 23:12:40 +02:00
|
|
|
# It can take some time for the second AP to become ready to reply to Probe
|
|
|
|
# Request frames especially under heavy CPU load, so allow couple of rounds
|
|
|
|
# of scanning to avoid reporting errors incorrectly just because of scans
|
|
|
|
# not having seen the target AP.
|
|
|
|
for i in range(0, 10):
|
|
|
|
dev[0].scan(freq="2412")
|
|
|
|
if dev[0].get_bss(bssid2) is not None:
|
|
|
|
break
|
|
|
|
logger.info("Scan again to find target AP")
|
2013-12-29 18:25:42 +01:00
|
|
|
dev[0].request("ROAM " + bssid2)
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("EAP success timed out")
|
2014-12-20 10:51:30 +01:00
|
|
|
dev[0].wait_connected(timeout=10, error="Roaming timed out")
|
2013-12-29 18:25:42 +01:00
|
|
|
pmksa2 = dev[0].get_pmksa(bssid2)
|
|
|
|
if pmksa2 is None:
|
|
|
|
raise Exception("No PMKSA cache entry found")
|
|
|
|
if pmksa2['opportunistic'] != '0':
|
|
|
|
raise Exception("Unexpected opportunistic PMKSA cache entry")
|
|
|
|
|
|
|
|
dev[0].dump_monitor()
|
|
|
|
logger.info("Roam back to AP1")
|
|
|
|
dev[0].scan(freq="2412")
|
|
|
|
dev[0].request("ROAM " + bssid)
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
|
|
|
|
"CTRL-EVENT-CONNECTED"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Roaming with the AP timed out")
|
|
|
|
if "CTRL-EVENT-EAP-STARTED" in ev:
|
|
|
|
raise Exception("Unexpected EAP exchange")
|
|
|
|
pmksa1b = dev[0].get_pmksa(bssid)
|
|
|
|
if pmksa1b is None:
|
|
|
|
raise Exception("No PMKSA cache entry found")
|
|
|
|
if pmksa['pmkid'] != pmksa1b['pmkid']:
|
|
|
|
raise Exception("Unexpected PMKID change for AP1")
|
|
|
|
|
2014-09-27 09:50:19 +02:00
|
|
|
dev[0].dump_monitor()
|
|
|
|
if "FAIL" in dev[0].request("PMKSA_FLUSH"):
|
|
|
|
raise Exception("PMKSA_FLUSH failed")
|
|
|
|
if dev[0].get_pmksa(bssid) is not None or dev[0].get_pmksa(bssid2) is not None:
|
|
|
|
raise Exception("PMKSA_FLUSH did not remove PMKSA entries")
|
2014-12-20 10:51:30 +01:00
|
|
|
dev[0].wait_disconnected(timeout=5)
|
|
|
|
dev[0].wait_connected(timeout=15, error="Reconnection timed out")
|
2014-09-27 09:50:19 +02:00
|
|
|
|
2013-12-29 18:25:42 +01:00
|
|
|
def test_pmksa_cache_opportunistic_only_on_sta(dev, apdev):
|
|
|
|
"""Opportunistic PMKSA caching enabled only on station"""
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache")
|
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
bssid = apdev[0]['bssid']
|
|
|
|
dev[0].connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP",
|
|
|
|
eap="GPSK", identity="gpsk user",
|
|
|
|
password="abcdefghijklmnop0123456789abcdef", okc=True,
|
|
|
|
scan_freq="2412")
|
|
|
|
pmksa = dev[0].get_pmksa(bssid)
|
|
|
|
if pmksa is None:
|
|
|
|
raise Exception("No PMKSA cache entry created")
|
|
|
|
if pmksa['opportunistic'] != '0':
|
|
|
|
raise Exception("Unexpected opportunistic PMKSA cache entry")
|
|
|
|
|
|
|
|
hostapd.add_ap(apdev[1]['ifname'], params)
|
|
|
|
bssid2 = apdev[1]['bssid']
|
|
|
|
|
|
|
|
dev[0].dump_monitor()
|
|
|
|
logger.info("Roam to AP2")
|
|
|
|
dev[0].scan(freq="2412")
|
|
|
|
dev[0].request("ROAM " + bssid2)
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("EAP success timed out")
|
2014-12-20 10:51:30 +01:00
|
|
|
dev[0].wait_connected(timeout=10, error="Roaming timed out")
|
2013-12-29 18:25:42 +01:00
|
|
|
pmksa2 = dev[0].get_pmksa(bssid2)
|
|
|
|
if pmksa2 is None:
|
|
|
|
raise Exception("No PMKSA cache entry found")
|
|
|
|
if pmksa2['opportunistic'] != '0':
|
|
|
|
raise Exception("Unexpected opportunistic PMKSA cache entry")
|
|
|
|
|
|
|
|
dev[0].dump_monitor()
|
|
|
|
logger.info("Roam back to AP1")
|
|
|
|
dev[0].scan(freq="2412")
|
|
|
|
dev[0].request("ROAM " + bssid)
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
|
|
|
|
"CTRL-EVENT-CONNECTED"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Roaming with the AP timed out")
|
|
|
|
if "CTRL-EVENT-EAP-STARTED" in ev:
|
|
|
|
raise Exception("Unexpected EAP exchange")
|
|
|
|
pmksa1b = dev[0].get_pmksa(bssid)
|
|
|
|
if pmksa1b is None:
|
|
|
|
raise Exception("No PMKSA cache entry found")
|
|
|
|
if pmksa['pmkid'] != pmksa1b['pmkid']:
|
|
|
|
raise Exception("Unexpected PMKID change for AP1")
|
|
|
|
|
|
|
|
def test_pmksa_cache_opportunistic(dev, apdev):
|
|
|
|
"""Opportunistic PMKSA caching"""
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache")
|
|
|
|
params['okc'] = "1"
|
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
bssid = apdev[0]['bssid']
|
|
|
|
dev[0].connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP",
|
|
|
|
eap="GPSK", identity="gpsk user",
|
|
|
|
password="abcdefghijklmnop0123456789abcdef", okc=True,
|
|
|
|
scan_freq="2412")
|
|
|
|
pmksa = dev[0].get_pmksa(bssid)
|
|
|
|
if pmksa is None:
|
|
|
|
raise Exception("No PMKSA cache entry created")
|
|
|
|
if pmksa['opportunistic'] != '0':
|
|
|
|
raise Exception("Unexpected opportunistic PMKSA cache entry")
|
|
|
|
|
|
|
|
hostapd.add_ap(apdev[1]['ifname'], params)
|
|
|
|
bssid2 = apdev[1]['bssid']
|
|
|
|
|
|
|
|
dev[0].dump_monitor()
|
|
|
|
logger.info("Roam to AP2")
|
|
|
|
dev[0].scan(freq="2412")
|
|
|
|
dev[0].request("ROAM " + bssid2)
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
|
|
|
|
"CTRL-EVENT-CONNECTED"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Roaming with the AP timed out")
|
|
|
|
if "CTRL-EVENT-EAP-STARTED" in ev:
|
|
|
|
raise Exception("Unexpected EAP exchange")
|
|
|
|
pmksa2 = dev[0].get_pmksa(bssid2)
|
|
|
|
if pmksa2 is None:
|
|
|
|
raise Exception("No PMKSA cache entry created")
|
|
|
|
|
|
|
|
dev[0].dump_monitor()
|
|
|
|
logger.info("Roam back to AP1")
|
|
|
|
dev[0].scan(freq="2412")
|
|
|
|
dev[0].request("ROAM " + bssid)
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
|
|
|
|
"CTRL-EVENT-CONNECTED"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Roaming with the AP timed out")
|
|
|
|
if "CTRL-EVENT-EAP-STARTED" in ev:
|
|
|
|
raise Exception("Unexpected EAP exchange")
|
|
|
|
|
|
|
|
pmksa1b = dev[0].get_pmksa(bssid)
|
|
|
|
if pmksa1b is None:
|
|
|
|
raise Exception("No PMKSA cache entry found")
|
|
|
|
if pmksa['pmkid'] != pmksa1b['pmkid']:
|
|
|
|
raise Exception("Unexpected PMKID change for AP1")
|
|
|
|
|
2014-04-12 21:52:41 +02:00
|
|
|
def test_pmksa_cache_opportunistic_connect(dev, apdev):
|
|
|
|
"""Opportunistic PMKSA caching with connect API"""
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache")
|
|
|
|
params['okc'] = "1"
|
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
bssid = apdev[0]['bssid']
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
|
|
|
|
wpas.connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP",
|
|
|
|
eap="GPSK", identity="gpsk user",
|
|
|
|
password="abcdefghijklmnop0123456789abcdef", okc=True,
|
|
|
|
scan_freq="2412")
|
|
|
|
pmksa = wpas.get_pmksa(bssid)
|
|
|
|
if pmksa is None:
|
|
|
|
raise Exception("No PMKSA cache entry created")
|
|
|
|
if pmksa['opportunistic'] != '0':
|
|
|
|
raise Exception("Unexpected opportunistic PMKSA cache entry")
|
|
|
|
|
|
|
|
hostapd.add_ap(apdev[1]['ifname'], params)
|
|
|
|
bssid2 = apdev[1]['bssid']
|
|
|
|
|
|
|
|
wpas.dump_monitor()
|
|
|
|
logger.info("Roam to AP2")
|
2014-12-14 18:15:48 +01:00
|
|
|
wpas.scan_for_bss(bssid2, freq="2412")
|
2014-04-12 21:52:41 +02:00
|
|
|
wpas.request("ROAM " + bssid2)
|
|
|
|
ev = wpas.wait_event(["CTRL-EVENT-EAP-STARTED",
|
|
|
|
"CTRL-EVENT-CONNECTED"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Roaming with the AP timed out")
|
|
|
|
if "CTRL-EVENT-EAP-STARTED" in ev:
|
|
|
|
raise Exception("Unexpected EAP exchange")
|
|
|
|
pmksa2 = wpas.get_pmksa(bssid2)
|
|
|
|
if pmksa2 is None:
|
|
|
|
raise Exception("No PMKSA cache entry created")
|
|
|
|
|
|
|
|
wpas.dump_monitor()
|
|
|
|
logger.info("Roam back to AP1")
|
|
|
|
wpas.scan(freq="2412")
|
|
|
|
wpas.request("ROAM " + bssid)
|
|
|
|
ev = wpas.wait_event(["CTRL-EVENT-EAP-STARTED",
|
|
|
|
"CTRL-EVENT-CONNECTED"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Roaming with the AP timed out")
|
|
|
|
if "CTRL-EVENT-EAP-STARTED" in ev:
|
|
|
|
raise Exception("Unexpected EAP exchange")
|
|
|
|
|
|
|
|
pmksa1b = wpas.get_pmksa(bssid)
|
|
|
|
if pmksa1b is None:
|
|
|
|
raise Exception("No PMKSA cache entry found")
|
|
|
|
if pmksa['pmkid'] != pmksa1b['pmkid']:
|
|
|
|
raise Exception("Unexpected PMKID change for AP1")
|
|
|
|
|
2013-12-29 18:25:42 +01:00
|
|
|
def test_pmksa_cache_expiration(dev, apdev):
|
|
|
|
"""PMKSA cache entry expiration"""
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache")
|
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
bssid = apdev[0]['bssid']
|
|
|
|
dev[0].request("SET dot11RSNAConfigPMKLifetime 10")
|
|
|
|
dev[0].connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP",
|
|
|
|
eap="GPSK", identity="gpsk user",
|
|
|
|
password="abcdefghijklmnop0123456789abcdef",
|
|
|
|
scan_freq="2412")
|
|
|
|
pmksa = dev[0].get_pmksa(bssid)
|
|
|
|
if pmksa is None:
|
|
|
|
raise Exception("No PMKSA cache entry created")
|
|
|
|
logger.info("Wait for PMKSA cache entry to expire")
|
|
|
|
ev = dev[0].wait_event(["WPA: Key negotiation completed",
|
|
|
|
"CTRL-EVENT-DISCONNECTED"], timeout=15)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("No EAP reauthentication seen")
|
|
|
|
if "CTRL-EVENT-DISCONNECTED" in ev:
|
|
|
|
raise Exception("Unexpected disconnection")
|
|
|
|
pmksa2 = dev[0].get_pmksa(bssid)
|
|
|
|
if pmksa['pmkid'] == pmksa2['pmkid']:
|
2014-04-05 17:09:10 +02:00
|
|
|
raise Exception("PMKID did not change")
|
|
|
|
|
|
|
|
def test_pmksa_cache_expiration_disconnect(dev, apdev):
|
|
|
|
"""PMKSA cache entry expiration (disconnect)"""
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache")
|
|
|
|
hapd = hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
bssid = apdev[0]['bssid']
|
|
|
|
dev[0].request("SET dot11RSNAConfigPMKLifetime 2")
|
|
|
|
dev[0].request("SET dot11RSNAConfigPMKReauthThreshold 100")
|
|
|
|
dev[0].connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP",
|
|
|
|
eap="GPSK", identity="gpsk user",
|
|
|
|
password="abcdefghijklmnop0123456789abcdef",
|
|
|
|
scan_freq="2412")
|
|
|
|
pmksa = dev[0].get_pmksa(bssid)
|
|
|
|
if pmksa is None:
|
|
|
|
raise Exception("No PMKSA cache entry created")
|
|
|
|
hapd.request("SET auth_server_shared_secret incorrect")
|
|
|
|
logger.info("Wait for PMKSA cache entry to expire")
|
|
|
|
ev = dev[0].wait_event(["WPA: Key negotiation completed",
|
|
|
|
"CTRL-EVENT-DISCONNECTED"], timeout=15)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("No EAP reauthentication seen")
|
|
|
|
if "CTRL-EVENT-DISCONNECTED" not in ev:
|
|
|
|
raise Exception("Missing disconnection")
|
|
|
|
hapd.request("SET auth_server_shared_secret radius")
|
|
|
|
ev = dev[0].wait_event(["WPA: Key negotiation completed"], timeout=15)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("No EAP reauthentication seen")
|
|
|
|
pmksa2 = dev[0].get_pmksa(bssid)
|
|
|
|
if pmksa['pmkid'] == pmksa2['pmkid']:
|
2013-12-29 18:25:42 +01:00
|
|
|
raise Exception("PMKID did not change")
|
2014-03-09 23:51:14 +01:00
|
|
|
|
|
|
|
def test_pmksa_cache_and_cui(dev, apdev):
|
|
|
|
"""PMKSA cache and Chargeable-User-Identity"""
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="cui")
|
|
|
|
params['radius_request_cui'] = '1'
|
|
|
|
params['acct_server_addr'] = "127.0.0.1"
|
|
|
|
params['acct_server_port'] = "1813"
|
|
|
|
params['acct_server_shared_secret'] = "radius"
|
2015-01-18 14:47:56 +01:00
|
|
|
hapd = hostapd.add_ap(apdev[0]['ifname'], params)
|
2014-03-09 23:51:14 +01:00
|
|
|
bssid = apdev[0]['bssid']
|
|
|
|
dev[0].connect("cui", proto="RSN", key_mgmt="WPA-EAP",
|
|
|
|
eap="GPSK", identity="gpsk-cui",
|
|
|
|
password="abcdefghijklmnop0123456789abcdef",
|
|
|
|
scan_freq="2412")
|
|
|
|
pmksa = dev[0].get_pmksa(bssid)
|
|
|
|
if pmksa is None:
|
|
|
|
raise Exception("No PMKSA cache entry created")
|
2015-01-18 14:47:56 +01:00
|
|
|
ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("No connection event received from hostapd")
|
2014-03-09 23:51:14 +01:00
|
|
|
|
|
|
|
dev[0].dump_monitor()
|
|
|
|
logger.info("Disconnect and reconnect to the same AP")
|
|
|
|
dev[0].request("DISCONNECT")
|
2015-01-18 14:47:56 +01:00
|
|
|
dev[0].wait_disconnected()
|
2014-03-09 23:51:14 +01:00
|
|
|
dev[0].request("RECONNECT")
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
|
|
|
|
"CTRL-EVENT-CONNECTED"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Reconnect timed out")
|
|
|
|
if "CTRL-EVENT-EAP-STARTED" in ev:
|
|
|
|
raise Exception("Unexpected EAP exchange")
|
|
|
|
pmksa1b = dev[0].get_pmksa(bssid)
|
|
|
|
if pmksa1b is None:
|
|
|
|
raise Exception("No PMKSA cache entry found")
|
|
|
|
if pmksa['pmkid'] != pmksa1b['pmkid']:
|
|
|
|
raise Exception("Unexpected PMKID change for AP1")
|
|
|
|
|
|
|
|
dev[0].request("REAUTHENTICATE")
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("EAP success timed out")
|
|
|
|
for i in range(0, 20):
|
|
|
|
state = dev[0].get_status_field("wpa_state")
|
|
|
|
if state == "COMPLETED":
|
|
|
|
break
|
|
|
|
time.sleep(0.1)
|
|
|
|
if state != "COMPLETED":
|
|
|
|
raise Exception("Reauthentication did not complete")
|
2014-03-15 10:52:11 +01:00
|
|
|
|
|
|
|
def test_pmksa_cache_preauth(dev, apdev):
|
|
|
|
"""RSN pre-authentication to generate PMKSA cache entry"""
|
|
|
|
try:
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
|
|
|
|
params['bridge'] = 'ap-br0'
|
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
2015-02-06 23:22:32 +01:00
|
|
|
subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
|
|
|
|
subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
|
2014-03-15 10:52:11 +01:00
|
|
|
eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com",
|
|
|
|
password_hex="0123456789abcdef0123456789abcdef")
|
|
|
|
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
|
|
|
|
params['bridge'] = 'ap-br0'
|
|
|
|
params['rsn_preauth'] = '1'
|
|
|
|
params['rsn_preauth_interfaces'] = 'ap-br0'
|
|
|
|
hostapd.add_ap(apdev[1]['ifname'], params)
|
|
|
|
bssid1 = apdev[1]['bssid']
|
|
|
|
dev[0].scan(freq="2412")
|
|
|
|
success = False
|
2014-03-20 23:13:33 +01:00
|
|
|
status_seen = False
|
2014-03-15 10:52:11 +01:00
|
|
|
for i in range(0, 50):
|
2014-03-20 23:13:33 +01:00
|
|
|
if not status_seen:
|
|
|
|
status = dev[0].request("STATUS")
|
|
|
|
if "Pre-authentication EAPOL state machines:" in status:
|
|
|
|
status_seen = True
|
2014-03-15 10:52:11 +01:00
|
|
|
time.sleep(0.1)
|
|
|
|
pmksa = dev[0].get_pmksa(bssid1)
|
|
|
|
if pmksa:
|
|
|
|
success = True
|
|
|
|
break
|
|
|
|
if not success:
|
|
|
|
raise Exception("No PMKSA cache entry created from pre-authentication")
|
2014-03-20 23:13:33 +01:00
|
|
|
if not status_seen:
|
|
|
|
raise Exception("Pre-authentication EAPOL status was not available")
|
2014-03-15 10:52:11 +01:00
|
|
|
|
|
|
|
dev[0].scan(freq="2412")
|
2014-04-26 16:18:37 +02:00
|
|
|
if "[WPA2-EAP-CCMP-preauth]" not in dev[0].request("SCAN_RESULTS"):
|
|
|
|
raise Exception("Scan results missing RSN element info")
|
2014-03-15 10:52:11 +01:00
|
|
|
dev[0].request("ROAM " + bssid1)
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
|
|
|
|
"CTRL-EVENT-CONNECTED"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Roaming with the AP timed out")
|
|
|
|
if "CTRL-EVENT-EAP-STARTED" in ev:
|
|
|
|
raise Exception("Unexpected EAP exchange")
|
|
|
|
pmksa2 = dev[0].get_pmksa(bssid1)
|
|
|
|
if pmksa2 is None:
|
|
|
|
raise Exception("No PMKSA cache entry")
|
|
|
|
if pmksa['pmkid'] != pmksa2['pmkid']:
|
|
|
|
raise Exception("Unexpected PMKID change")
|
|
|
|
|
|
|
|
finally:
|
2015-02-06 23:22:32 +01:00
|
|
|
subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'])
|
|
|
|
subprocess.call(['brctl', 'delbr', 'ap-br0'])
|
2014-10-04 18:05:10 +02:00
|
|
|
|
2015-04-10 14:49:45 +02:00
|
|
|
def test_pmksa_cache_preauth_vlan_enabled(dev, apdev):
|
|
|
|
"""RSN pre-authentication to generate PMKSA cache entry (dynamic_vlan optional but station without VLAN set)"""
|
|
|
|
try:
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
|
|
|
|
params['bridge'] = 'ap-br0'
|
|
|
|
params['dynamic_vlan'] = '1'
|
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
|
|
|
|
subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
|
|
|
|
eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com",
|
|
|
|
password_hex="0123456789abcdef0123456789abcdef")
|
|
|
|
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
|
|
|
|
params['bridge'] = 'ap-br0'
|
|
|
|
params['rsn_preauth'] = '1'
|
|
|
|
params['rsn_preauth_interfaces'] = 'ap-br0'
|
|
|
|
params['dynamic_vlan'] = '1'
|
|
|
|
hostapd.add_ap(apdev[1]['ifname'], params)
|
|
|
|
bssid1 = apdev[1]['bssid']
|
|
|
|
dev[0].scan(freq="2412")
|
|
|
|
success = False
|
|
|
|
status_seen = False
|
|
|
|
for i in range(0, 50):
|
|
|
|
if not status_seen:
|
|
|
|
status = dev[0].request("STATUS")
|
|
|
|
if "Pre-authentication EAPOL state machines:" in status:
|
|
|
|
status_seen = True
|
|
|
|
time.sleep(0.1)
|
|
|
|
pmksa = dev[0].get_pmksa(bssid1)
|
|
|
|
if pmksa:
|
|
|
|
success = True
|
|
|
|
break
|
|
|
|
if not success:
|
|
|
|
raise Exception("No PMKSA cache entry created from pre-authentication")
|
|
|
|
if not status_seen:
|
|
|
|
raise Exception("Pre-authentication EAPOL status was not available")
|
|
|
|
|
|
|
|
dev[0].scan(freq="2412")
|
|
|
|
if "[WPA2-EAP-CCMP-preauth]" not in dev[0].request("SCAN_RESULTS"):
|
|
|
|
raise Exception("Scan results missing RSN element info")
|
|
|
|
dev[0].request("ROAM " + bssid1)
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
|
|
|
|
"CTRL-EVENT-CONNECTED"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Roaming with the AP timed out")
|
|
|
|
if "CTRL-EVENT-EAP-STARTED" in ev:
|
|
|
|
raise Exception("Unexpected EAP exchange")
|
|
|
|
pmksa2 = dev[0].get_pmksa(bssid1)
|
|
|
|
if pmksa2 is None:
|
|
|
|
raise Exception("No PMKSA cache entry")
|
|
|
|
if pmksa['pmkid'] != pmksa2['pmkid']:
|
|
|
|
raise Exception("Unexpected PMKID change")
|
|
|
|
|
|
|
|
finally:
|
|
|
|
subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'])
|
|
|
|
subprocess.call(['brctl', 'delbr', 'ap-br0'])
|
|
|
|
|
|
|
|
def test_pmksa_cache_preauth_vlan_used(dev, apdev):
|
|
|
|
"""RSN pre-authentication to generate PMKSA cache entry (station with VLAN set)"""
|
|
|
|
try:
|
|
|
|
subprocess.call(['brctl', 'addbr', 'brvlan1'])
|
|
|
|
subprocess.call(['brctl', 'setfd', 'brvlan1', '0'])
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
|
|
|
|
params['bridge'] = 'ap-br0'
|
|
|
|
params['dynamic_vlan'] = '1'
|
|
|
|
params['vlan_file'] = 'hostapd.wlan3.vlan'
|
|
|
|
hapd = hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
|
|
|
|
subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
|
|
|
|
eap_connect(dev[0], apdev[0], "PAX", "vlan1",
|
|
|
|
password_hex="0123456789abcdef0123456789abcdef")
|
|
|
|
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
|
|
|
|
params['bridge'] = 'ap-br0'
|
|
|
|
params['rsn_preauth'] = '1'
|
|
|
|
params['rsn_preauth_interfaces'] = 'brvlan1'
|
|
|
|
params['dynamic_vlan'] = '1'
|
|
|
|
params['vlan_file'] = 'hostapd.wlan4.vlan'
|
|
|
|
hostapd.add_ap(apdev[1]['ifname'], params)
|
|
|
|
bssid1 = apdev[1]['bssid']
|
|
|
|
dev[0].scan(freq="2412")
|
|
|
|
success = False
|
|
|
|
status_seen = False
|
|
|
|
for i in range(0, 50):
|
|
|
|
if not status_seen:
|
|
|
|
status = dev[0].request("STATUS")
|
|
|
|
if "Pre-authentication EAPOL state machines:" in status:
|
|
|
|
status_seen = True
|
|
|
|
time.sleep(0.1)
|
|
|
|
pmksa = dev[0].get_pmksa(bssid1)
|
|
|
|
if pmksa:
|
|
|
|
success = True
|
|
|
|
break
|
|
|
|
if not success:
|
|
|
|
raise Exception("No PMKSA cache entry created from pre-authentication")
|
|
|
|
if not status_seen:
|
|
|
|
raise Exception("Pre-authentication EAPOL status was not available")
|
|
|
|
|
|
|
|
dev[0].scan(freq="2412")
|
|
|
|
if "[WPA2-EAP-CCMP-preauth]" not in dev[0].request("SCAN_RESULTS"):
|
|
|
|
raise Exception("Scan results missing RSN element info")
|
|
|
|
dev[0].request("ROAM " + bssid1)
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
|
|
|
|
"CTRL-EVENT-CONNECTED"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Roaming with the AP timed out")
|
|
|
|
if "CTRL-EVENT-EAP-STARTED" in ev:
|
|
|
|
raise Exception("Unexpected EAP exchange")
|
|
|
|
pmksa2 = dev[0].get_pmksa(bssid1)
|
|
|
|
if pmksa2 is None:
|
|
|
|
raise Exception("No PMKSA cache entry")
|
|
|
|
if pmksa['pmkid'] != pmksa2['pmkid']:
|
|
|
|
raise Exception("Unexpected PMKID change")
|
|
|
|
|
|
|
|
# Disconnect the STA from both APs to avoid forceful ifdown by the
|
|
|
|
# test script on a VLAN that this has an associated STA. That used to
|
|
|
|
# trigger a mac80211 warning.
|
|
|
|
dev[0].request("DISCONNECT")
|
|
|
|
hapd.request("DISABLE")
|
|
|
|
|
|
|
|
finally:
|
|
|
|
subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'],
|
|
|
|
stderr=open('/dev/null', 'w'))
|
|
|
|
subprocess.call(['ip', 'link', 'set', 'dev', 'brvlan1', 'down'])
|
|
|
|
subprocess.call(['ip', 'link', 'set', 'dev', 'wlan3.1', 'down'],
|
|
|
|
stderr=open('/dev/null', 'w'))
|
|
|
|
subprocess.call(['ip', 'link', 'set', 'dev', 'wlan4.1', 'down'],
|
|
|
|
stderr=open('/dev/null', 'w'))
|
|
|
|
subprocess.call(['brctl', 'delif', 'brvlan1', 'wlan3.1'],
|
|
|
|
stderr=open('/dev/null', 'w'))
|
|
|
|
subprocess.call(['brctl', 'delif', 'brvlan1', 'wlan4.1'],
|
|
|
|
stderr=open('/dev/null', 'w'))
|
|
|
|
subprocess.call(['brctl', 'delbr', 'ap-br0'],
|
|
|
|
stderr=open('/dev/null', 'w'))
|
|
|
|
subprocess.call(['brctl', 'delbr', 'brvlan1'])
|
|
|
|
|
2014-10-04 18:05:10 +02:00
|
|
|
def test_pmksa_cache_disabled(dev, apdev):
|
|
|
|
"""PMKSA cache disabling on AP"""
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache")
|
|
|
|
params['disable_pmksa_caching'] = '1'
|
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
bssid = apdev[0]['bssid']
|
|
|
|
dev[0].connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP",
|
|
|
|
eap="GPSK", identity="gpsk user",
|
|
|
|
password="abcdefghijklmnop0123456789abcdef",
|
|
|
|
scan_freq="2412")
|
|
|
|
|
|
|
|
hostapd.add_ap(apdev[1]['ifname'], params)
|
|
|
|
bssid2 = apdev[1]['bssid']
|
|
|
|
|
|
|
|
dev[0].dump_monitor()
|
|
|
|
logger.info("Roam to AP2")
|
|
|
|
dev[0].scan_for_bss(bssid2, freq="2412")
|
|
|
|
dev[0].request("ROAM " + bssid2)
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("EAP success timed out")
|
2014-12-20 10:51:30 +01:00
|
|
|
dev[0].wait_connected(timeout=10, error="Roaming timed out")
|
2014-10-04 18:05:10 +02:00
|
|
|
|
|
|
|
dev[0].dump_monitor()
|
|
|
|
logger.info("Roam back to AP1")
|
|
|
|
dev[0].scan(freq="2412")
|
|
|
|
dev[0].request("ROAM " + bssid)
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
|
|
|
|
"CTRL-EVENT-CONNECTED"], timeout=20)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Roaming with the AP timed out")
|
|
|
|
if "CTRL-EVENT-CONNECTED" in ev:
|
|
|
|
raise Exception("EAP exchange missing")
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=20)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Roaming with the AP timed out")
|
2014-10-04 18:38:55 +02:00
|
|
|
|
|
|
|
def test_pmksa_cache_ap_expiration(dev, apdev):
|
|
|
|
"""PMKSA cache entry expiring on AP"""
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache")
|
2015-01-18 14:47:56 +01:00
|
|
|
hapd = hostapd.add_ap(apdev[0]['ifname'], params)
|
2014-10-04 18:38:55 +02:00
|
|
|
bssid = apdev[0]['bssid']
|
|
|
|
dev[0].connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP",
|
|
|
|
eap="GPSK", identity="gpsk-user-session-timeout",
|
|
|
|
password="abcdefghijklmnop0123456789abcdef",
|
|
|
|
scan_freq="2412")
|
2015-01-18 14:47:56 +01:00
|
|
|
ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("No connection event received from hostapd")
|
2014-10-04 18:38:55 +02:00
|
|
|
dev[0].request("DISCONNECT")
|
|
|
|
time.sleep(5)
|
|
|
|
dev[0].dump_monitor()
|
|
|
|
dev[0].request("RECONNECT")
|
|
|
|
ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED",
|
|
|
|
"CTRL-EVENT-CONNECTED"], timeout=20)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Roaming with the AP timed out")
|
|
|
|
if "CTRL-EVENT-CONNECTED" in ev:
|
|
|
|
raise Exception("EAP exchange missing")
|
2014-12-20 10:51:30 +01:00
|
|
|
dev[0].wait_connected(timeout=20, error="Reconnect timed out")
|
2014-10-04 18:38:55 +02:00
|
|
|
dev[0].dump_monitor()
|
2014-12-20 10:51:30 +01:00
|
|
|
dev[0].wait_disconnected(timeout=20)
|
|
|
|
dev[0].wait_connected(timeout=20, error="Reassociation timed out")
|
2014-10-04 21:39:16 +02:00
|
|
|
|
|
|
|
def test_pmksa_cache_multiple_sta(dev, apdev):
|
|
|
|
"""PMKSA cache with multiple stations"""
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache")
|
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
bssid = apdev[0]['bssid']
|
|
|
|
dev[0].connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP",
|
|
|
|
eap="GPSK", identity="gpsk-user-session-timeout",
|
|
|
|
password="abcdefghijklmnop0123456789abcdef",
|
|
|
|
scan_freq="2412")
|
|
|
|
dev[1].connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP",
|
|
|
|
eap="GPSK", identity="gpsk user",
|
|
|
|
password="abcdefghijklmnop0123456789abcdef",
|
|
|
|
scan_freq="2412")
|
|
|
|
dev[2].connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP",
|
|
|
|
eap="GPSK", identity="gpsk-user-session-timeout",
|
|
|
|
password="abcdefghijklmnop0123456789abcdef",
|
|
|
|
scan_freq="2412")
|
|
|
|
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5")
|
|
|
|
wpas.connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP",
|
|
|
|
eap="GPSK", identity="gpsk user",
|
|
|
|
password="abcdefghijklmnop0123456789abcdef",
|
|
|
|
scan_freq="2412")
|
|
|
|
|
|
|
|
hostapd.add_ap(apdev[1]['ifname'], params)
|
|
|
|
bssid2 = apdev[1]['bssid']
|
|
|
|
|
|
|
|
logger.info("Roam to AP2")
|
|
|
|
for sta in [ dev[1], dev[0], dev[2], wpas ]:
|
|
|
|
sta.dump_monitor()
|
|
|
|
sta.scan_for_bss(bssid2, freq="2412")
|
|
|
|
sta.request("ROAM " + bssid2)
|
|
|
|
ev = sta.wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("EAP success timed out")
|
2014-12-20 10:51:30 +01:00
|
|
|
sta.wait_connected(timeout=10, error="Roaming timed out")
|
2014-10-04 21:39:16 +02:00
|
|
|
|
|
|
|
logger.info("Roam back to AP1")
|
|
|
|
for sta in [ dev[1], wpas, dev[0], dev[2] ]:
|
|
|
|
sta.dump_monitor()
|
|
|
|
sta.scan(freq="2412")
|
|
|
|
sta.dump_monitor()
|
|
|
|
sta.request("ROAM " + bssid)
|
2014-12-20 10:51:30 +01:00
|
|
|
sta.wait_connected(timeout=10, error="Roaming timed out")
|
2014-10-04 21:39:16 +02:00
|
|
|
sta.dump_monitor()
|
|
|
|
|
|
|
|
time.sleep(4)
|
|
|
|
|
|
|
|
logger.info("Roam back to AP2")
|
|
|
|
for sta in [ dev[1], wpas, dev[0], dev[2] ]:
|
|
|
|
sta.dump_monitor()
|
|
|
|
sta.scan(freq="2412")
|
|
|
|
sta.dump_monitor()
|
|
|
|
sta.request("ROAM " + bssid2)
|
2014-12-20 10:51:30 +01:00
|
|
|
sta.wait_connected(timeout=10, error="Roaming timed out")
|
2014-10-04 21:39:16 +02:00
|
|
|
sta.dump_monitor()
|
2014-10-04 21:59:01 +02:00
|
|
|
|
|
|
|
def test_pmksa_cache_opportunistic_multiple_sta(dev, apdev):
|
|
|
|
"""Opportunistic PMKSA caching with multiple stations"""
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache")
|
|
|
|
params['okc'] = "1"
|
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
bssid = apdev[0]['bssid']
|
|
|
|
wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
|
|
|
|
wpas.interface_add("wlan5")
|
|
|
|
for sta in [ dev[0], dev[1], dev[2], wpas ]:
|
|
|
|
sta.connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP",
|
|
|
|
eap="GPSK", identity="gpsk user",
|
|
|
|
password="abcdefghijklmnop0123456789abcdef", okc=True,
|
|
|
|
scan_freq="2412")
|
|
|
|
|
|
|
|
hostapd.add_ap(apdev[1]['ifname'], params)
|
|
|
|
bssid2 = apdev[1]['bssid']
|
|
|
|
|
|
|
|
logger.info("Roam to AP2")
|
|
|
|
for sta in [ dev[2], dev[0], wpas, dev[1] ]:
|
|
|
|
sta.dump_monitor()
|
|
|
|
sta.scan_for_bss(bssid2, freq="2412")
|
2014-12-20 12:37:08 +01:00
|
|
|
if "OK" not in sta.request("ROAM " + bssid2):
|
|
|
|
raise Exception("ROAM command failed")
|
2014-10-04 21:59:01 +02:00
|
|
|
ev = sta.wait_event(["CTRL-EVENT-EAP-STARTED",
|
|
|
|
"CTRL-EVENT-CONNECTED"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Roaming with the AP timed out")
|
|
|
|
if "CTRL-EVENT-EAP-STARTED" in ev:
|
|
|
|
raise Exception("Unexpected EAP exchange")
|
|
|
|
pmksa2 = sta.get_pmksa(bssid2)
|
|
|
|
if pmksa2 is None:
|
|
|
|
raise Exception("No PMKSA cache entry created")
|
|
|
|
|
|
|
|
logger.info("Roam back to AP1")
|
|
|
|
for sta in [ dev[0], dev[1], dev[2], wpas ]:
|
|
|
|
sta.dump_monitor()
|
|
|
|
sta.scan_for_bss(bssid, freq="2412")
|
|
|
|
sta.request("ROAM " + bssid)
|
|
|
|
ev = sta.wait_event(["CTRL-EVENT-EAP-STARTED",
|
|
|
|
"CTRL-EVENT-CONNECTED"], timeout=10)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("Roaming with the AP timed out")
|
|
|
|
if "CTRL-EVENT-EAP-STARTED" in ev:
|
|
|
|
raise Exception("Unexpected EAP exchange")
|
2015-01-29 23:14:57 +01:00
|
|
|
|
|
|
|
def test_pmksa_cache_preauth_oom(dev, apdev):
|
|
|
|
"""RSN pre-authentication to generate PMKSA cache entry and OOM"""
|
|
|
|
try:
|
|
|
|
_test_pmksa_cache_preauth_oom(dev, apdev)
|
|
|
|
finally:
|
|
|
|
subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'down'])
|
|
|
|
subprocess.call(['brctl', 'delbr', 'ap-br0'])
|
|
|
|
|
|
|
|
def _test_pmksa_cache_preauth_oom(dev, apdev):
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
|
|
|
|
params['bridge'] = 'ap-br0'
|
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
subprocess.call(['brctl', 'setfd', 'ap-br0', '0'])
|
|
|
|
subprocess.call(['ip', 'link', 'set', 'dev', 'ap-br0', 'up'])
|
|
|
|
eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com",
|
|
|
|
password_hex="0123456789abcdef0123456789abcdef",
|
|
|
|
bssid=apdev[0]['bssid'])
|
|
|
|
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
|
|
|
|
params['bridge'] = 'ap-br0'
|
|
|
|
params['rsn_preauth'] = '1'
|
|
|
|
params['rsn_preauth_interfaces'] = 'ap-br0'
|
|
|
|
hapd = hostapd.add_ap(apdev[1]['ifname'], params)
|
|
|
|
bssid1 = apdev[1]['bssid']
|
|
|
|
|
|
|
|
tests = [ (1, "rsn_preauth_receive"),
|
|
|
|
(2, "rsn_preauth_receive"),
|
|
|
|
(1, "rsn_preauth_send") ]
|
|
|
|
for test in tests:
|
|
|
|
with alloc_fail(hapd, test[0], test[1]):
|
|
|
|
dev[0].scan_for_bss(bssid1, freq="2412")
|
|
|
|
if "OK" not in dev[0].request("PREAUTH " + bssid1):
|
|
|
|
raise Exception("PREAUTH failed")
|
|
|
|
|
|
|
|
success = False
|
|
|
|
count = 0
|
|
|
|
for i in range(50):
|
|
|
|
time.sleep(0.1)
|
|
|
|
pmksa = dev[0].get_pmksa(bssid1)
|
|
|
|
if pmksa:
|
|
|
|
success = True
|
|
|
|
break
|
|
|
|
state = hapd.request('GET_ALLOC_FAIL')
|
|
|
|
if state.startswith('0:'):
|
|
|
|
count += 1
|
|
|
|
if count > 2:
|
|
|
|
break
|
|
|
|
logger.info("PMKSA cache success: " + str(success))
|
|
|
|
|
|
|
|
dev[0].request("PMKSA_FLUSH")
|
|
|
|
dev[0].wait_disconnected()
|
|
|
|
dev[0].wait_connected()
|
|
|
|
dev[0].dump_monitor()
|
2015-01-31 12:26:46 +01:00
|
|
|
|
|
|
|
def test_pmksa_cache_size_limit(dev, apdev):
|
|
|
|
"""PMKSA cache size limit in wpa_supplicant"""
|
|
|
|
try:
|
|
|
|
_test_pmksa_cache_size_limit(dev, apdev)
|
|
|
|
finally:
|
|
|
|
try:
|
|
|
|
hapd = hostapd.HostapdGlobal()
|
|
|
|
hapd.flush()
|
|
|
|
hapd.remove(apdev[0]['ifname'])
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache")
|
|
|
|
bssid = apdev[0]['bssid']
|
|
|
|
params['bssid'] = bssid
|
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
|
|
|
|
def _test_pmksa_cache_size_limit(dev, apdev):
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-pmksa-cache")
|
|
|
|
id = dev[0].connect("test-pmksa-cache", proto="RSN", key_mgmt="WPA-EAP",
|
|
|
|
eap="GPSK", identity="gpsk user",
|
|
|
|
password="abcdefghijklmnop0123456789abcdef",
|
|
|
|
scan_freq="2412", only_add_network=True)
|
|
|
|
for i in range(33):
|
|
|
|
bssid = apdev[0]['bssid'][0:15] + "%02x" % i
|
|
|
|
logger.info("Iteration with BSSID " + bssid)
|
|
|
|
params['bssid'] = bssid
|
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
dev[0].request("BSS_FLUSH 0")
|
|
|
|
dev[0].scan_for_bss(bssid, freq=2412, only_new=True)
|
|
|
|
dev[0].select_network(id)
|
|
|
|
dev[0].wait_connected()
|
|
|
|
dev[0].request("DISCONNECT")
|
|
|
|
dev[0].wait_disconnected()
|
|
|
|
dev[0].dump_monitor()
|
|
|
|
entries = len(dev[0].request("PMKSA").splitlines()) - 1
|
|
|
|
if i == 32:
|
|
|
|
if entries != 32:
|
|
|
|
raise Exception("Unexpected number of PMKSA entries after expected removal of the oldest entry")
|
|
|
|
elif i + 1 != entries:
|
|
|
|
raise Exception("Unexpected number of PMKSA entries")
|
|
|
|
|
|
|
|
hapd = hostapd.HostapdGlobal()
|
|
|
|
hapd.flush()
|
|
|
|
hapd.remove(apdev[0]['ifname'])
|
2015-01-31 12:35:31 +01:00
|
|
|
|
|
|
|
def test_pmksa_cache_preauth_timeout(dev, apdev):
|
|
|
|
"""RSN pre-authentication timing out"""
|
|
|
|
try:
|
|
|
|
_test_pmksa_cache_preauth_timeout(dev, apdev)
|
|
|
|
finally:
|
|
|
|
dev[0].request("SET dot11RSNAConfigSATimeout 60")
|
|
|
|
|
|
|
|
def _test_pmksa_cache_preauth_timeout(dev, apdev):
|
|
|
|
dev[0].request("SET dot11RSNAConfigSATimeout 1")
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
|
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com",
|
|
|
|
password_hex="0123456789abcdef0123456789abcdef",
|
|
|
|
bssid=apdev[0]['bssid'])
|
|
|
|
if "OK" not in dev[0].request("PREAUTH f2:11:22:33:44:55"):
|
|
|
|
raise Exception("PREAUTH failed")
|
|
|
|
ev = dev[0].wait_event(["RSN: pre-authentication with"], timeout=5)
|
|
|
|
if ev is None:
|
|
|
|
raise Exception("No timeout event seen")
|
|
|
|
if "timed out" not in ev:
|
|
|
|
raise Exception("Unexpected event: " + ev)
|
2015-01-31 12:45:52 +01:00
|
|
|
|
|
|
|
def test_pmksa_cache_preauth_wpas_oom(dev, apdev):
|
|
|
|
"""RSN pre-authentication OOM in wpa_supplicant"""
|
|
|
|
params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
|
|
|
|
hostapd.add_ap(apdev[0]['ifname'], params)
|
|
|
|
eap_connect(dev[0], apdev[0], "PAX", "pax.user@example.com",
|
|
|
|
password_hex="0123456789abcdef0123456789abcdef",
|
|
|
|
bssid=apdev[0]['bssid'])
|
|
|
|
for i in range(1, 11):
|
|
|
|
with alloc_fail(dev[0], i, "rsn_preauth_init"):
|
|
|
|
res = dev[0].request("PREAUTH f2:11:22:33:44:55").strip()
|
|
|
|
logger.info("Iteration %d - PREAUTH command results: %s" % (i, res))
|
|
|
|
for j in range(10):
|
|
|
|
state = dev[0].request('GET_ALLOC_FAIL')
|
|
|
|
if state.startswith('0:'):
|
|
|
|
break
|
|
|
|
time.sleep(0.05)
|