]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_ap_config.py
tests: Additional sae_password parsing coverage
[thirdparty/hostap.git] / tests / hwsim / test_ap_config.py
1 # hostapd configuration tests
2 # Copyright (c) 2014-2016, Jouni Malinen <j@w1.fi>
3 #
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
6
7 import os
8 import signal
9 import time
10 import logging
11 logger = logging.getLogger(__name__)
12 import subprocess
13
14 from remotehost import remote_compatible
15 import hostapd
16 from utils import alloc_fail, fail_test
17
18 @remote_compatible
19 def test_ap_config_errors(dev, apdev):
20 """Various hostapd configuration errors"""
21
22 # IEEE 802.11d without country code
23 params = {"ssid": "foo", "ieee80211d": "1"}
24 hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
25 if "FAIL" not in hapd.request("ENABLE"):
26 raise Exception("Unexpected ENABLE success (ieee80211d without country_code)")
27 hostapd.remove_bss(apdev[0])
28
29 # IEEE 802.11h without IEEE 802.11d
30 params = {"ssid": "foo", "ieee80211h": "1"}
31 hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
32 if "FAIL" not in hapd.request("ENABLE"):
33 raise Exception("Unexpected ENABLE success (ieee80211h without ieee80211d")
34 hostapd.remove_bss(apdev[0])
35
36 # Power Constraint without IEEE 802.11d
37 params = {"ssid": "foo", "local_pwr_constraint": "1"}
38 hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
39 if "FAIL" not in hapd.request("ENABLE"):
40 raise Exception("Unexpected ENABLE success (local_pwr_constraint without ieee80211d)")
41 hostapd.remove_bss(apdev[0])
42
43 # Spectrum management without Power Constraint
44 params = {"ssid": "foo", "spectrum_mgmt_required": "1"}
45 hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
46 if "FAIL" not in hapd.request("ENABLE"):
47 raise Exception("Unexpected ENABLE success (spectrum_mgmt_required without local_pwr_constraint)")
48 hostapd.remove_bss(apdev[0])
49
50 # IEEE 802.1X without authentication server
51 params = {"ssid": "foo", "ieee8021x": "1"}
52 hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
53 if "FAIL" not in hapd.request("ENABLE"):
54 raise Exception("Unexpected ENABLE success (ieee8021x)")
55 hostapd.remove_bss(apdev[0])
56
57 # RADIUS-PSK without macaddr_acl=2
58 params = hostapd.wpa2_params(ssid="foo", passphrase="12345678")
59 params["wpa_psk_radius"] = "1"
60 hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
61 if "FAIL" not in hapd.request("ENABLE"):
62 raise Exception("Unexpected ENABLE success (wpa_psk_radius)")
63 hostapd.remove_bss(apdev[0])
64
65 # FT without NAS-Identifier
66 params = {"wpa": "2",
67 "wpa_key_mgmt": "FT-PSK",
68 "rsn_pairwise": "CCMP",
69 "wpa_passphrase": "12345678"}
70 hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
71 if "FAIL" not in hapd.request("ENABLE"):
72 raise Exception("Unexpected ENABLE success (FT without nas_identifier)")
73 hostapd.remove_bss(apdev[0])
74
75 # Hotspot 2.0 without WPA2/CCMP
76 params = hostapd.wpa2_params(ssid="foo")
77 params['wpa_key_mgmt'] = "WPA-EAP"
78 params['ieee8021x'] = "1"
79 params['auth_server_addr'] = "127.0.0.1"
80 params['auth_server_port'] = "1812"
81 params['auth_server_shared_secret'] = "radius"
82 params['interworking'] = "1"
83 params['hs20'] = "1"
84 params['wpa'] = "1"
85 hapd = hostapd.add_ap(apdev[0], params, no_enable=True)
86 if "FAIL" not in hapd.request("ENABLE"):
87 raise Exception("Unexpected ENABLE success (HS 2.0 without WPA2/CCMP)")
88 hostapd.remove_bss(apdev[0])
89
90 def test_ap_config_reload(dev, apdev, params):
91 """hostapd configuration reload"""
92 hapd = hostapd.add_ap(apdev[0], {"ssid": "foo"})
93 hapd.set("ssid", "foobar")
94 with open(os.path.join(params['logdir'], 'hostapd-test.pid'), "r") as f:
95 pid = int(f.read())
96 os.kill(pid, signal.SIGHUP)
97 time.sleep(0.1)
98 dev[0].connect("foobar", key_mgmt="NONE", scan_freq="2412")
99 hapd.set("ssid", "foo")
100 os.kill(pid, signal.SIGHUP)
101 dev[0].wait_disconnected()
102 dev[0].request("DISCONNECT")
103
104 def test_ap_config_reload_file(dev, apdev, params):
105 """hostapd configuration reload from file"""
106 hapd = hostapd.add_iface(apdev[0], "bss-1.conf")
107 hapd.enable()
108 hapd.set("ssid", "foobar")
109 with open(os.path.join(params['logdir'], 'hostapd-test.pid'), "r") as f:
110 pid = int(f.read())
111 os.kill(pid, signal.SIGHUP)
112 time.sleep(0.1)
113 dev[0].connect("foobar", key_mgmt="NONE", scan_freq="2412")
114 hapd.set("ssid", "foo")
115 os.kill(pid, signal.SIGHUP)
116 dev[0].wait_disconnected()
117 dev[0].request("DISCONNECT")
118
119 def test_ap_config_reload_file_while_disabled(dev, apdev, params):
120 """hostapd configuration reload from file when disabled"""
121 hapd = hostapd.add_iface(apdev[0], "bss-1.conf")
122 hapd.enable()
123 ev = hapd.wait_event(["AP-ENABLED"], timeout=3)
124 if ev is None:
125 raise Exception("AP-ENABLED event not reported")
126 hapd.set("ssid", "foobar")
127 with open(os.path.join(params['logdir'], 'hostapd-test.pid'), "r") as f:
128 pid = int(f.read())
129 hapd.disable()
130 ev = hapd.wait_event(["AP-DISABLED"], timeout=3)
131 if ev is None:
132 raise Exception("AP-DISABLED event not reported")
133 hapd.dump_monitor()
134 os.kill(pid, signal.SIGHUP)
135 time.sleep(0.1)
136 hapd.enable()
137 dev[0].connect("foobar", key_mgmt="NONE", scan_freq="2412")
138
139 def write_hostapd_config(conffile, ifname, ssid, ht=True, bss2=False):
140 with open(conffile, "w") as f:
141 f.write("driver=nl80211\n")
142 f.write("hw_mode=g\n")
143 f.write("channel=1\n")
144 if ht:
145 f.write("ieee80211n=1\n")
146 f.write("interface=" + ifname + "\n")
147 f.write("ssid=" + ssid + "\n")
148 if bss2:
149 f.write("bss=" + ifname + "_2\n")
150 f.write("ssid=" + ssid + "-2\n")
151
152 def test_ap_config_reload_on_sighup(dev, apdev, params):
153 """hostapd configuration reload modification from file on SIGHUP"""
154 run_ap_config_reload_on_sighup(dev, apdev, params)
155
156 def test_ap_config_reload_on_sighup_no_ht(dev, apdev, params):
157 """hostapd configuration reload modification from file on SIGHUP (no HT)"""
158 run_ap_config_reload_on_sighup(dev, apdev, params, ht=False)
159
160 def run_ap_config_reload_on_sighup(dev, apdev, params, ht=True):
161 name = "ap_config_reload_on_sighup"
162 if not ht:
163 name += "_no_ht"
164 pidfile = os.path.join(params['logdir'], name + "-hostapd.pid")
165 logfile = os.path.join(params['logdir'], name + "-hostapd-log")
166 conffile = os.path.join(os.getcwd(), params['logdir'],
167 name + "-hostapd.conf")
168 prg = os.path.join(params['logdir'], 'alt-hostapd/hostapd/hostapd')
169 if not os.path.exists(prg):
170 prg = '../../hostapd/hostapd'
171 write_hostapd_config(conffile, apdev[0]['ifname'], "test-1", ht=ht)
172 cmd = [prg, '-B', '-dddt', '-P', pidfile, '-f', logfile, conffile]
173 res = subprocess.check_call(cmd)
174 if res != 0:
175 raise Exception("Could not start hostapd: %s" % str(res))
176
177 dev[0].connect("test-1", key_mgmt="NONE", scan_freq="2412")
178 dev[0].request("REMOVE_NETWORK all")
179 dev[0].wait_disconnected()
180
181 write_hostapd_config(conffile, apdev[0]['ifname'], "test-2", ht=ht)
182 with open(pidfile, "r") as f:
183 pid = int(f.read())
184 os.kill(pid, signal.SIGHUP)
185
186 time.sleep(0.1)
187 dev[0].flush_scan_cache()
188
189 dev[0].connect("test-2", key_mgmt="NONE", scan_freq="2412")
190 bss = dev[0].get_bss(apdev[0]['bssid'])
191 dev[0].request("REMOVE_NETWORK all")
192 dev[0].wait_disconnected()
193
194 os.kill(pid, signal.SIGTERM)
195 removed = False
196 for i in range(20):
197 time.sleep(0.1)
198 if not os.path.exists(pidfile):
199 removed = True
200 break
201 if not removed:
202 raise Exception("hostapd PID file not removed on SIGTERM")
203
204 if ht and "dd180050f202" not in bss['ie']:
205 raise Exception("Missing WMM IE after reload")
206 if not ht and "dd180050f202" in bss['ie']:
207 raise Exception("Unexpected WMM IE after reload")
208
209 def test_ap_config_reload_on_sighup_bss_changes(dev, apdev, params):
210 """hostapd configuration reload modification from file on SIGHUP with bss remove/add"""
211 name = "ap_config_reload_on_sighup_bss_changes"
212 pidfile = os.path.join(params['logdir'], name + "-hostapd.pid")
213 logfile = os.path.join(params['logdir'], name + "-hostapd-log")
214 conffile = os.path.join(os.getcwd(), params['logdir'],
215 name + "-hostapd.conf")
216 prg = os.path.join(params['logdir'], 'alt-hostapd/hostapd/hostapd')
217 if not os.path.exists(prg):
218 prg = '../../hostapd/hostapd'
219 write_hostapd_config(conffile, apdev[0]['ifname'], "test", bss2=True)
220 cmd = [prg, '-B', '-dddt', '-P', pidfile, '-f', logfile, conffile]
221 res = subprocess.check_call(cmd)
222 if res != 0:
223 raise Exception("Could not start hostapd: %s" % str(res))
224
225 dev[0].connect("test", key_mgmt="NONE", scan_freq="2412",
226 wait_connect=False)
227 dev[1].connect("test-2", key_mgmt="NONE", scan_freq="2412")
228 dev[0].wait_connected()
229 dev[0].request("REMOVE_NETWORK all")
230 dev[1].request("REMOVE_NETWORK all")
231 dev[0].wait_disconnected()
232 dev[1].wait_disconnected()
233 dev[0].dump_monitor()
234 dev[1].dump_monitor()
235
236 write_hostapd_config(conffile, apdev[0]['ifname'], "test-a", bss2=False)
237 with open(pidfile, "r") as f:
238 pid = int(f.read())
239 os.kill(pid, signal.SIGHUP)
240
241 time.sleep(0.5)
242 dev[0].flush_scan_cache()
243
244 dev[0].connect("test-a", key_mgmt="NONE", scan_freq="2412")
245 dev[0].request("REMOVE_NETWORK all")
246 dev[0].wait_disconnected()
247 dev[0].dump_monitor()
248
249 write_hostapd_config(conffile, apdev[0]['ifname'], "test-b", bss2=True)
250 os.kill(pid, signal.SIGHUP)
251
252 time.sleep(0.5)
253 dev[0].flush_scan_cache()
254 dev[1].flush_scan_cache()
255
256 dev[0].connect("test-b", key_mgmt="NONE", scan_freq="2412",
257 wait_connect=False)
258 dev[1].connect("test-b-2", key_mgmt="NONE", scan_freq="2412")
259 dev[0].wait_connected()
260 dev[0].request("REMOVE_NETWORK all")
261 dev[1].request("REMOVE_NETWORK all")
262 dev[0].wait_disconnected()
263 dev[1].wait_disconnected()
264 dev[0].dump_monitor()
265 dev[1].dump_monitor()
266
267 os.kill(pid, signal.SIGTERM)
268
269 def test_ap_config_reload_before_enable(dev, apdev, params):
270 """hostapd configuration reload before enable"""
271 hapd = hostapd.add_iface(apdev[0], "bss-1.conf")
272 with open(os.path.join(params['logdir'], 'hostapd-test.pid'), "r") as f:
273 pid = int(f.read())
274 os.kill(pid, signal.SIGHUP)
275 hapd.ping()
276
277 def test_ap_config_sigusr1(dev, apdev, params):
278 """hostapd SIGUSR1"""
279 hapd = hostapd.add_ap(apdev[0], {"ssid": "foobar"})
280 with open(os.path.join(params['logdir'], 'hostapd-test.pid'), "r") as f:
281 pid = int(f.read())
282 os.kill(pid, signal.SIGUSR1)
283 dev[0].connect("foobar", key_mgmt="NONE", scan_freq="2412")
284 os.kill(pid, signal.SIGUSR1)
285
286 def test_ap_config_invalid_value(dev, apdev, params):
287 """Ignoring invalid hostapd configuration parameter updates"""
288 hapd = hostapd.add_ap(apdev[0], {"ssid": "test"}, no_enable=True)
289 not_exist = "/tmp/hostapd-test/does-not-exist"
290 tests = [("driver", "foobar"),
291 ("ssid2", "Q"),
292 ("macaddr_acl", "255"),
293 ("accept_mac_file", not_exist),
294 ("deny_mac_file", not_exist),
295 ("eapol_version", "255"),
296 ("eap_user_file", not_exist),
297 ("wep_key_len_broadcast", "-1"),
298 ("wep_key_len_unicast", "-1"),
299 ("wep_rekey_period", "-1"),
300 ("eap_rekey_period", "-1"),
301 ("radius_client_addr", "foo"),
302 ("acs_chan_bias", "-1:0.8"),
303 ("acs_chan_bias", "1"),
304 ("acs_chan_bias", "1:p"),
305 ("acs_chan_bias", "1:-0.8"),
306 ("acs_chan_bias", "1:0.8p"),
307 ("dtim_period", "0"),
308 ("bss_load_update_period", "-1"),
309 ("send_probe_response", "255"),
310 ("beacon_rate", "ht:-1"),
311 ("beacon_rate", "ht:32"),
312 ("beacon_rate", "vht:-1"),
313 ("beacon_rate", "vht:10"),
314 ("beacon_rate", "9"),
315 ("beacon_rate", "10001"),
316 ("vlan_file", not_exist),
317 ("bss", ""),
318 ("bssid", "foo"),
319 ("extra_cred", not_exist),
320 ("anqp_elem", "265"),
321 ("anqp_elem", "265"),
322 ("anqp_elem", "265:1"),
323 ("anqp_elem", "265:1q"),
324 ("fst_priority", ""),
325 ("fils_cache_id", "q"),
326 ("venue_url", "foo"),
327 ("venue_url", "1:" + 255*"a"),
328 ("sae_password", "secret|mac=qq"),
329 ("unknown-item", "foo")]
330 for field, val in tests:
331 if "FAIL" not in hapd.request("SET %s %s" % (field, val)):
332 raise Exception("Invalid %s accepted" % field)
333 hapd.enable()
334 dev[0].connect("test", key_mgmt="NONE", scan_freq="2412")
335
336 def test_ap_config_eap_user_file_parsing(dev, apdev, params):
337 """hostapd eap_user_file parsing"""
338 tmp = os.path.join(params['logdir'], 'ap_config_eap_user_file_parsing.tmp')
339 hapd = hostapd.add_ap(apdev[0], {"ssid": "foobar"})
340
341 for i in range(2):
342 if "OK" not in hapd.request("SET eap_user_file auth_serv/eap_user.conf"):
343 raise Exception("eap_user_file rejected")
344
345 tests = ["#\n\n*\tTLS\nradius_accept_attr=:",
346 "foo\n",
347 "\"foo\n",
348 "\"foo\"\n",
349 "\"foo\" FOOBAR\n",
350 "\"foo\" " + 10*"TLS," + "TLS \"\n",
351 "\"foo\" TLS \nfoo\n",
352 "\"foo\" PEAP hash:foo\n",
353 "\"foo\" PEAP hash:8846f7eaee8fb117ad06bdd830b7586q\n",
354 "\"foo\" PEAP 01020\n",
355 "\"foo\" PEAP 010q\n"
356 '"pwd" PWD ssha1:\n',
357 '"pwd" PWD ssha1:' + 20*'00' + '\n',
358 '"pwd" PWD ssha256:\n',
359 '"pwd" PWD ssha512:\n',
360 '"pwd" PWD ssha1:' + 20*'00' + 'qq\n',
361 '"pwd" PWD ssha1:' + 19*'00' + 'qq00\n',
362 "\"foo\" TLS\nradius_accept_attr=123:x:012\n",
363 "\"foo\" TLS\nradius_accept_attr=123:x:012q\n",
364 "\"foo\" TLS\nradius_accept_attr=123:Q:01\n",
365 "\"foo\" TLS\nradius_accept_attr=123\nfoo\n"]
366 for t in tests:
367 with open(tmp, "w") as f:
368 f.write(t)
369 if "FAIL" not in hapd.request("SET eap_user_file " + tmp):
370 raise Exception("Invalid eap_user_file accepted")
371
372 tests = [("\"foo\" TLS\n", 2, "hostapd_config_read_eap_user"),
373 ("\"foo\" PEAP \"foo\"\n", 3, "hostapd_config_read_eap_user"),
374 ("\"foo\" PEAP hash:8846f7eaee8fb117ad06bdd830b75861\n", 3,
375 "hostapd_config_read_eap_user"),
376 ("\"foo\" PEAP 0102\n", 3, "hostapd_config_read_eap_user"),
377 ("\"foo\" TLS\nradius_accept_attr=123\n", 1,
378 "=hostapd_parse_radius_attr"),
379 ("\"foo\" TLS\nradius_accept_attr=123\n", 1,
380 "wpabuf_alloc;hostapd_parse_radius_attr"),
381 ("\"foo\" TLS\nradius_accept_attr=123:s:foo\n", 2,
382 "hostapd_parse_radius_attr"),
383 ("\"foo\" TLS\nradius_accept_attr=123:x:0102\n", 2,
384 "hostapd_parse_radius_attr"),
385 ("\"foo\" TLS\nradius_accept_attr=123:d:1\n", 2,
386 "hostapd_parse_radius_attr"),
387 ('"pwd" PWD ssha1:046239e0660a59015231082a071c803e9f5848ae42eaccb4c08c97ae397bc879c4b071b9088ee715\n', 1, "hostapd_config_eap_user_salted"),
388 ('"pwd" PWD ssha1:046239e0660a59015231082a071c803e9f5848ae42eaccb4c08c97ae397bc879c4b071b9088ee715\n', 2, "hostapd_config_eap_user_salted"),
389 ("* TLS\n", 1, "hostapd_config_read_eap_user")]
390 for t, count, func in tests:
391 with alloc_fail(hapd, count, func):
392 with open(tmp, "w") as f:
393 f.write(t)
394 if "FAIL" not in hapd.request("SET eap_user_file " + tmp):
395 raise Exception("eap_user_file accepted during OOM")
396
397 def test_ap_config_set_oom(dev, apdev):
398 """hostapd configuration parsing OOM"""
399 hapd = hostapd.add_ap(apdev[0], {"ssid": "foobar"})
400
401 tests = [(1, "hostapd_parse_das_client",
402 "SET radius_das_client 192.168.1.123 pw"),
403 (1, "hostapd_config_read_wep", "SET wep_key0 \"hello\""),
404 (1, "hostapd_config_read_wep", "SET wep_key0 0102030405"),
405 (1, "hostapd_parse_chanlist", "SET chanlist 1 6 11-13"),
406 (1, "hostapd_config_bss", "SET bss foo"),
407 (2, "hostapd_config_bss", "SET bss foo"),
408 (3, "hostapd_config_bss", "SET bss foo"),
409 (1, "add_r0kh",
410 "SET r0kh 02:01:02:03:04:05 r0kh-1.example.com 000102030405060708090a0b0c0d0e0f"),
411 (1, "add_r1kh",
412 "SET r1kh 02:01:02:03:04:05 02:11:22:33:44:55 000102030405060708090a0b0c0d0e0f"),
413 (1, "parse_roaming_consortium", "SET roaming_consortium 021122"),
414 (1, "parse_lang_string", "SET venue_name eng:Example venue"),
415 (1, "parse_3gpp_cell_net",
416 "SET anqp_3gpp_cell_net 244,91;310,026;234,56"),
417 (1, "parse_nai_realm", "SET nai_realm 0,example.com;example.net"),
418 (2, "parse_nai_realm", "SET nai_realm 0,example.com;example.net"),
419 (1, "parse_anqp_elem", "SET anqp_elem 265:0000"),
420 (2, "parse_anqp_elem", "SET anqp_elem 266:000000"),
421 (1, "parse_venue_url", "SET venue_url 1:http://example.com/"),
422 (1, "hs20_parse_operator_icon", "SET operator_icon icon"),
423 (2, "hs20_parse_operator_icon", "SET operator_icon icon"),
424 (1, "hs20_parse_conn_capab", "SET hs20_conn_capab 1:0:2"),
425 (1, "hs20_parse_wan_metrics",
426 "SET hs20_wan_metrics 01:8000:1000:80:240:3000"),
427 (1, "hs20_parse_icon",
428 "SET hs20_icon 32:32:eng:image/png:icon32:/tmp/icon32.png"),
429 (1, "hs20_parse_osu_server_uri",
430 "SET osu_server_uri https://example.com/osu/"),
431 (1, "hostapd_config_parse_acs_chan_bias",
432 "SET acs_chan_bias 1:0.8 6:0.8 11:0.8"),
433 (2, "hostapd_config_parse_acs_chan_bias",
434 "SET acs_chan_bias 1:0.8 6:0.8 11:0.8"),
435 (1, "parse_wpabuf_hex", "SET vendor_elements 01020304"),
436 (1, "parse_fils_realm", "SET fils_realm example.com"),
437 (1, "parse_sae_password", "SET sae_password secret"),
438 (2, "parse_sae_password", "SET sae_password secret"),
439 (2, "parse_sae_password", "SET sae_password secret|id=pw"),
440 (3, "parse_sae_password", "SET sae_password secret|id=pw"),
441 (1, "hostapd_config_fill",
442 "SET pac_opaque_encr_key 000102030405060708090a0b0c0d0e0f"),
443 (1, "hostapd_config_fill", "SET eap_message hello"),
444 (1, "hostapd_config_fill",
445 "SET wpa_psk 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"),
446 (1, "hostapd_config_fill", "SET time_zone EST5"),
447 (1, "hostapd_config_fill",
448 "SET network_auth_type 02http://www.example.com/redirect/"),
449 (1, "hostapd_config_fill", "SET domain_name example.com"),
450 (1, "hostapd_config_fill", "SET hs20_operating_class 5173"),
451 (1, "hostapd_config_fill", "SET own_ie_override 11223344"),
452 (1, "hostapd_parse_intlist", "SET sae_groups 19 25"),
453 (1, "hostapd_parse_intlist", "SET basic_rates 10 20 55 110"),
454 (1, "hostapd_parse_intlist", "SET supported_rates 10 20 55 110")]
455 for count, func, cmd in tests:
456 with alloc_fail(hapd, count, func):
457 if "FAIL" not in hapd.request(cmd):
458 raise Exception("Command accepted during OOM: " + cmd)
459
460 hapd.set("hs20_icon", "32:32:eng:image/png:icon32:/tmp/icon32.png")
461 hapd.set("hs20_conn_capab", "1:0:2")
462 hapd.set("nai_realm", "0,example.com;example.net")
463 hapd.set("venue_name", "eng:Example venue")
464 hapd.set("roaming_consortium", "021122")
465 hapd.set("osu_server_uri", "https://example.com/osu/")
466 hapd.set("vendor_elements", "01020304")
467 hapd.set("vendor_elements", "01020304")
468 hapd.set("vendor_elements", "")
469 hapd.set("lci", "11223344")
470 hapd.set("civic", "11223344")
471 hapd.set("lci", "")
472 hapd.set("civic", "")
473
474 tests = [(1, "hs20_parse_icon",
475 "SET hs20_icon 32:32:eng:image/png:icon32:/tmp/icon32.png"),
476 (1, "parse_roaming_consortium", "SET roaming_consortium 021122"),
477 (2, "parse_nai_realm", "SET nai_realm 0,example.com;example.net"),
478 (1, "parse_lang_string", "SET venue_name eng:Example venue"),
479 (1, "hs20_parse_osu_server_uri",
480 "SET osu_server_uri https://example.com/osu/"),
481 (1, "hs20_parse_osu_nai", "SET osu_nai anonymous@example.com"),
482 (1, "hs20_parse_osu_nai2", "SET osu_nai2 anonymous@example.com"),
483 (1, "hostapd_parse_intlist", "SET osu_method_list 1 0"),
484 (1, "hs20_parse_osu_icon", "SET osu_icon icon32"),
485 (2, "hs20_parse_osu_icon", "SET osu_icon icon32"),
486 (2, "hs20_parse_osu_icon", "SET osu_icon icon32"),
487 (1, "hs20_parse_conn_capab", "SET hs20_conn_capab 1:0:2")]
488 for count, func, cmd in tests:
489 with alloc_fail(hapd, count, func):
490 if "FAIL" not in hapd.request(cmd):
491 raise Exception("Command accepted during OOM (2): " + cmd)
492
493 tests = [(1, "parse_fils_realm", "SET fils_realm example.com")]
494 for count, func, cmd in tests:
495 with fail_test(hapd, count, func):
496 if "FAIL" not in hapd.request(cmd):
497 raise Exception("Command accepted during FAIL_TEST: " + cmd)
498
499 def test_ap_config_set_errors(dev, apdev):
500 """hostapd configuration parsing errors"""
501 hapd = hostapd.add_ap(apdev[0], {"ssid": "foobar"})
502 hapd.set("wep_key0", '"hello"')
503 hapd.set("wep_key1", '"hello"')
504 hapd.set("wep_key0", '')
505 hapd.set("wep_key0", '"hello"')
506 if "FAIL" not in hapd.request("SET wep_key1 \"hello\""):
507 raise Exception("SET wep_key1 allowed to override existing key")
508 hapd.set("wep_key1", '')
509 hapd.set("wep_key1", '"hello"')
510
511 hapd.set("auth_server_addr", "127.0.0.1")
512 hapd.set("acct_server_addr", "127.0.0.1")
513
514 tests = ["SET eap_reauth_period -1",
515 "SET fst_llt ",
516 "SET auth_server_addr_replace foo",
517 "SET acct_server_addr_replace foo"]
518 for t in tests:
519 if "FAIL" not in hapd.request(t):
520 raise Exception("Invalid command accepted: " + t)
521
522 # Deprecated entries
523 hapd.set("tx_queue_after_beacon_aifs", '2')
524 hapd.set("tx_queue_beacon_aifs", '2')
525 hapd.set("tx_queue_data9_aifs", '2')
526 hapd.set("debug", '1')
527 hapd.set("dump_file", '/tmp/hostapd-test-dump')
528 hapd.set("eap_authenticator", '0')
529 hapd.set("radio_measurements", '0')
530 hapd.set("radio_measurements", '1')
531
532 # Various extra coverage (not really errors)
533 hapd.set("logger_syslog_level", '1')
534 hapd.set("logger_syslog", '0')
535 hapd.set("tls_flags", "[ALLOW-SIGN-RSA-MD5][DISABLE-TIME-CHECKS][DISABLE-TLSv1.0]")
536
537 for i in range(50000):
538 if "OK" not in hapd.request("SET hs20_conn_capab 17:5060:0"):
539 logger.info("hs20_conn_capab limit at %d" % i)
540 break
541 if i < 1000 or i >= 49999:
542 raise Exception("hs20_conn_capab limit not seen")