mirror of
https://github.com/vanhoefm/fragattacks.git
synced 2024-11-28 18:28:23 -05:00
tests: Use proper temp files for dynamically created config
Replace the hardcoded /tmp filenames for generated ACL and BSS configuration files with proper temporary files from tempfile.mkstemp() to avoid conflicts with existing files or with parallel uses. Remove ACL files from the local directory at the end of each test case. BSS files are currently left behind, but can be cleaned up separately if needed for non-VM testing (VM testing has those on ramdrive so they get dropped automatically at the end) and for remote devices. Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
6998ef48c8
commit
af9d8c758d
@ -10,6 +10,7 @@ import time
|
||||
import logging
|
||||
import binascii
|
||||
import struct
|
||||
import tempfile
|
||||
import wpaspy
|
||||
import remotehost
|
||||
import utils
|
||||
@ -764,10 +765,10 @@ def send_file(apdev, src, dst):
|
||||
return hapd_global.send_file(src, dst)
|
||||
|
||||
def acl_file(dev, apdev, conf):
|
||||
filename = os.path.join("/tmp", conf)
|
||||
fd, filename = tempfile.mkstemp(dir='/tmp', prefix=conf + '-')
|
||||
f = os.fdopen(fd, 'w')
|
||||
|
||||
if conf == 'hostapd.macaddr':
|
||||
with open(filename, 'w') as f:
|
||||
mac0 = dev[0].get_status_field("address")
|
||||
f.write(mac0 + '\n')
|
||||
f.write("02:00:00:00:00:12\n")
|
||||
@ -777,13 +778,11 @@ def acl_file(dev, apdev, conf):
|
||||
f.write("01:01:01:01:01:01\n")
|
||||
f.write("03:01:01:01:01:03\n")
|
||||
elif conf == 'hostapd.accept':
|
||||
with open(filename, 'w') as f:
|
||||
mac0 = dev[0].get_status_field("address")
|
||||
mac1 = dev[1].get_status_field("address")
|
||||
f.write(mac0 + " 1\n")
|
||||
f.write(mac1 + " 2\n")
|
||||
elif conf == 'hostapd.accept2':
|
||||
with open(filename, 'w') as f:
|
||||
mac0 = dev[0].get_status_field("address")
|
||||
mac1 = dev[1].get_status_field("address")
|
||||
mac2 = dev[2].get_status_field("address")
|
||||
@ -791,6 +790,8 @@ def acl_file(dev, apdev, conf):
|
||||
f.write(mac1 + " 2\n")
|
||||
f.write(mac2 + " 3\n")
|
||||
else:
|
||||
f.close()
|
||||
os.unlink(filename)
|
||||
return conf
|
||||
|
||||
return filename
|
||||
@ -803,12 +804,11 @@ def bssid_inc(apdev, inc=1):
|
||||
return bssid
|
||||
|
||||
def cfg_file(apdev, conf, ifname=None):
|
||||
# put cfg file in /tmp directory
|
||||
fname = os.path.join("/tmp", conf)
|
||||
|
||||
match = re.search(r'^bss-.+', conf)
|
||||
if match:
|
||||
with open(fname, 'w') as f:
|
||||
# put cfg file in /tmp directory
|
||||
fd, fname = tempfile.mkstemp(dir='/tmp', prefix=conf + '-')
|
||||
f = os.fdopen(fd, 'w')
|
||||
idx = ''.join(filter(str.isdigit, conf.split('-')[-1]))
|
||||
if ifname is None:
|
||||
ifname = apdev['ifname']
|
||||
@ -830,7 +830,7 @@ def cfg_file(apdev, conf, ifname=None):
|
||||
else:
|
||||
bssid = bssid_inc(apdev, int(idx) - 1)
|
||||
f.write("bssid=%s\n" % bssid)
|
||||
else:
|
||||
return conf
|
||||
|
||||
return fname
|
||||
|
||||
return conf
|
||||
|
@ -353,6 +353,8 @@ def test_ap_ft_vlan(dev, apdev):
|
||||
run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, conndev="brvlan1")
|
||||
if "[WPA2-FT/PSK-CCMP]" not in dev[0].request("SCAN_RESULTS"):
|
||||
raise Exception("Scan results missing RSN element info")
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
def test_ap_ft_vlan_disconnected(dev, apdev):
|
||||
"""WPA2-PSK-FT AP with VLAN and local key generation"""
|
||||
@ -377,6 +379,8 @@ def test_ap_ft_vlan_disconnected(dev, apdev):
|
||||
run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, conndev="brvlan1")
|
||||
if "[WPA2-FT/PSK-CCMP]" not in dev[0].request("SCAN_RESULTS"):
|
||||
raise Exception("Scan results missing RSN element info")
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
def test_ap_ft_vlan_2(dev, apdev):
|
||||
"""WPA2-PSK-FT AP with VLAN and dest-AP does not have VLAN info locally"""
|
||||
@ -398,6 +402,8 @@ def test_ap_ft_vlan_2(dev, apdev):
|
||||
force_initial_conn_to_first_ap=True)
|
||||
if "[WPA2-FT/PSK-CCMP]" not in dev[0].request("SCAN_RESULTS"):
|
||||
raise Exception("Scan results missing RSN element info")
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
def test_ap_ft_many(dev, apdev):
|
||||
"""WPA2-PSK-FT AP multiple times"""
|
||||
@ -431,6 +437,8 @@ def test_ap_ft_many_vlan(dev, apdev):
|
||||
|
||||
run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, roams=50,
|
||||
conndev="brvlan1")
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
def test_ap_ft_mixed(dev, apdev):
|
||||
"""WPA2-PSK-FT mixed-mode AP"""
|
||||
@ -735,6 +743,8 @@ def test_ap_ft_vlan_over_ds(dev, apdev):
|
||||
conndev="brvlan1")
|
||||
check_mib(dev[0], [("dot11RSNAAuthenticationSuiteRequested", "00-0f-ac-4"),
|
||||
("dot11RSNAAuthenticationSuiteSelected", "00-0f-ac-4")])
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
def test_ap_ft_over_ds_many(dev, apdev):
|
||||
"""WPA2-PSK-FT AP over DS multiple times"""
|
||||
@ -768,6 +778,8 @@ def test_ap_ft_vlan_over_ds_many(dev, apdev):
|
||||
|
||||
run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
|
||||
roams=50, conndev="brvlan1")
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
@remote_compatible
|
||||
def test_ap_ft_over_ds_unknown_target(dev, apdev):
|
||||
@ -978,6 +990,8 @@ def test_ap_ft_over_ds_pull_vlan(dev, apdev):
|
||||
|
||||
run_roams(dev[0], apdev, hapd0, hapd1, ssid, passphrase, over_ds=True,
|
||||
conndev="brvlan1")
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
def start_ft_sae(dev, apdev, wpa_ptk_rekey=None, sae_pwe=None):
|
||||
if "SAE" not in dev.get_capability("auth_alg"):
|
||||
|
@ -158,6 +158,8 @@ def test_ap_acl_accept(dev, apdev):
|
||||
ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
|
||||
if ev is not None:
|
||||
raise Exception("Unexpected association")
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
def test_ap_acl_deny(dev, apdev):
|
||||
"""MAC ACL deny list"""
|
||||
@ -175,6 +177,8 @@ def test_ap_acl_deny(dev, apdev):
|
||||
ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
|
||||
if ev is not None:
|
||||
raise Exception("Unexpected association")
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
def test_ap_acl_mgmt(dev, apdev):
|
||||
"""MAC ACL accept/deny management"""
|
||||
@ -247,6 +251,8 @@ def test_ap_acl_mgmt(dev, apdev):
|
||||
hapd.request("DENY_ACL ADD_MAC " + dev[0].own_addr())
|
||||
dev[0].wait_disconnected()
|
||||
dev[0].request("DISCONNECT")
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
@remote_compatible
|
||||
def test_ap_wds_sta(dev, apdev):
|
||||
|
@ -39,6 +39,8 @@ def test_ap_vlan_open(dev, apdev):
|
||||
hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1")
|
||||
hwsim_utils.test_connectivity_iface(dev[1], hapd, "brvlan2")
|
||||
hwsim_utils.test_connectivity(dev[2], hapd)
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
def test_ap_vlan_file_open(dev, apdev):
|
||||
"""AP VLAN with open network and vlan_file mapping"""
|
||||
@ -56,6 +58,8 @@ def test_ap_vlan_file_open(dev, apdev):
|
||||
hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1")
|
||||
hwsim_utils.test_connectivity_iface(dev[1], hapd, "brvlan2")
|
||||
hwsim_utils.test_connectivity(dev[2], hapd)
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
def test_ap_vlan_file_open2(dev, apdev):
|
||||
"""AP VLAN with open network and vlan_file mapping (2)"""
|
||||
@ -73,6 +77,8 @@ def test_ap_vlan_file_open2(dev, apdev):
|
||||
hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1")
|
||||
hwsim_utils.test_connectivity_iface(dev[1], hapd, "brvlan2")
|
||||
hwsim_utils.test_connectivity_iface(dev[2], hapd, "hwsimbr3")
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
def test_ap_vlan_file_parsing(dev, apdev, params):
|
||||
"""hostapd vlan_file/mac_file parsing"""
|
||||
@ -132,6 +138,8 @@ def test_ap_vlan_wpa2(dev, apdev):
|
||||
hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1")
|
||||
hwsim_utils.test_connectivity_iface(dev[1], hapd, "brvlan2")
|
||||
hwsim_utils.test_connectivity(dev[2], hapd)
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
def test_ap_vlan_wpa2_radius(dev, apdev):
|
||||
"""AP VLAN with WPA2-Enterprise and RADIUS attributes"""
|
||||
@ -201,6 +209,8 @@ def test_ap_vlan_wpa2_radius_local(dev, apdev):
|
||||
hwsim_utils.test_connectivity_iface(dev[0], hapd, "test_br_vlan1")
|
||||
hwsim_utils.test_connectivity_iface(dev[1], hapd, "test_br_vlan2")
|
||||
hwsim_utils.test_connectivity(dev[2], hapd)
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
def test_ap_vlan_wpa2_radius_id_change(dev, apdev):
|
||||
"""AP VLAN with WPA2-Enterprise and RADIUS attributes changing VLANID"""
|
||||
@ -364,6 +374,8 @@ def test_ap_vlan_tagged(dev, apdev):
|
||||
hwsim_utils.test_connectivity_iface(dev[0], hapd, "brlo.1")
|
||||
hwsim_utils.test_connectivity_iface(dev[1], hapd, "brlo.2")
|
||||
hwsim_utils.test_connectivity(dev[2], hapd)
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
def ap_vlan_iface_cleanup_multibss_cleanup():
|
||||
subprocess.call(['ifconfig', 'dummy0', 'down'],
|
||||
@ -632,6 +644,8 @@ def test_ap_vlan_without_station(dev, apdev, p):
|
||||
|
||||
dev[0].request("DISCONNECT")
|
||||
dev[0].wait_disconnected()
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
finally:
|
||||
subprocess.call(['ip', 'link', 'set', 'dev', 'brvlan1', 'down'])
|
||||
@ -741,6 +755,8 @@ def test_ap_vlan_reconnect(dev, apdev):
|
||||
dev[0].connect("test-vlan", psk="12345678", scan_freq="2412")
|
||||
hapd.wait_sta()
|
||||
hwsim_utils.test_connectivity_iface(dev[0], hapd, "brvlan1")
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
def test_ap_vlan_psk(dev, apdev, params):
|
||||
"""AP VLAN based on PSK/passphrase"""
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger()
|
||||
import os
|
||||
from remotehost import remote_compatible
|
||||
import hostapd
|
||||
import hwsim_utils
|
||||
@ -295,6 +296,8 @@ def test_hapd_ctrl_set_deny_mac_file(dev, apdev):
|
||||
ev = dev[1].wait_event(["CTRL-EVENT-DISCONNECTED"], 1)
|
||||
if ev is not None:
|
||||
raise Exception("Unexpected disconnection")
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
def test_hapd_ctrl_set_accept_mac_file(dev, apdev):
|
||||
"""hostapd and SET accept_mac_file ctrl_iface command"""
|
||||
@ -312,6 +315,8 @@ def test_hapd_ctrl_set_accept_mac_file(dev, apdev):
|
||||
ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], 1)
|
||||
if ev is not None:
|
||||
raise Exception("Unexpected disconnection")
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
def test_hapd_ctrl_set_accept_mac_file_vlan(dev, apdev):
|
||||
"""hostapd and SET accept_mac_file ctrl_iface command (VLAN ID)"""
|
||||
@ -327,6 +332,8 @@ def test_hapd_ctrl_set_accept_mac_file_vlan(dev, apdev):
|
||||
raise Exception("Unexpected SET failure")
|
||||
dev[1].wait_disconnected(timeout=15)
|
||||
dev[0].wait_disconnected(timeout=15)
|
||||
if filename.startswith('/tmp/'):
|
||||
os.unlink(filename)
|
||||
|
||||
@remote_compatible
|
||||
def test_hapd_ctrl_set_error_cases(dev, apdev):
|
||||
|
Loading…
Reference in New Issue
Block a user