]> git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_sae.py
tests: Add more details on sae_bignum_failure logs
[thirdparty/hostap.git] / tests / hwsim / test_sae.py
1 # Test cases for SAE
2 # Copyright (c) 2013-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 from remotehost import remote_compatible
8 import binascii
9 import os
10 import time
11 import logging
12 logger = logging.getLogger()
13
14 import hwsim_utils
15 import hostapd
16 from wpasupplicant import WpaSupplicant
17 from utils import HwsimSkip, alloc_fail, fail_test, wait_fail_trigger
18 from test_ap_psk import find_wpas_process, read_process_memory, verify_not_present, get_key_locations
19
20 @remote_compatible
21 def test_sae(dev, apdev):
22 """SAE with default group"""
23 if "SAE" not in dev[0].get_capability("auth_alg"):
24 raise HwsimSkip("SAE not supported")
25 params = hostapd.wpa2_params(ssid="test-sae",
26 passphrase="12345678")
27 params['wpa_key_mgmt'] = 'SAE'
28 hapd = hostapd.add_ap(apdev[0], params)
29 key_mgmt = hapd.get_config()['key_mgmt']
30 if key_mgmt.split(' ')[0] != "SAE":
31 raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
32
33 dev[0].request("SET sae_groups ")
34 id = dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
35 scan_freq="2412")
36 if dev[0].get_status_field('sae_group') != '19':
37 raise Exception("Expected default SAE group not used")
38 bss = dev[0].get_bss(apdev[0]['bssid'])
39 if 'flags' not in bss:
40 raise Exception("Could not get BSS flags from BSS table")
41 if "[WPA2-SAE-CCMP]" not in bss['flags']:
42 raise Exception("Unexpected BSS flags: " + bss['flags'])
43
44 res = hapd.request("STA-FIRST")
45 if "sae_group=19" not in res.splitlines():
46 raise Exception("hostapd STA output did not specify SAE group")
47
48 @remote_compatible
49 def test_sae_password_ecc(dev, apdev):
50 """SAE with number of different passwords (ECC)"""
51 if "SAE" not in dev[0].get_capability("auth_alg"):
52 raise HwsimSkip("SAE not supported")
53 params = hostapd.wpa2_params(ssid="test-sae",
54 passphrase="12345678")
55 params['wpa_key_mgmt'] = 'SAE'
56 hapd = hostapd.add_ap(apdev[0], params)
57
58 dev[0].request("SET sae_groups 19")
59
60 for i in range(10):
61 password = "12345678-" + str(i)
62 hapd.set("wpa_passphrase", password)
63 dev[0].connect("test-sae", psk=password, key_mgmt="SAE",
64 scan_freq="2412")
65 dev[0].request("REMOVE_NETWORK all")
66 dev[0].wait_disconnected()
67
68 @remote_compatible
69 def test_sae_password_ffc(dev, apdev):
70 """SAE with number of different passwords (FFC)"""
71 if "SAE" not in dev[0].get_capability("auth_alg"):
72 raise HwsimSkip("SAE not supported")
73 params = hostapd.wpa2_params(ssid="test-sae",
74 passphrase="12345678")
75 params['wpa_key_mgmt'] = 'SAE'
76 params['sae_groups'] = '22'
77 hapd = hostapd.add_ap(apdev[0], params)
78
79 dev[0].request("SET sae_groups 22")
80
81 for i in range(10):
82 password = "12345678-" + str(i)
83 hapd.set("wpa_passphrase", password)
84 dev[0].connect("test-sae", psk=password, key_mgmt="SAE",
85 scan_freq="2412")
86 dev[0].request("REMOVE_NETWORK all")
87 dev[0].wait_disconnected()
88
89 @remote_compatible
90 def test_sae_pmksa_caching(dev, apdev):
91 """SAE and PMKSA caching"""
92 if "SAE" not in dev[0].get_capability("auth_alg"):
93 raise HwsimSkip("SAE not supported")
94 params = hostapd.wpa2_params(ssid="test-sae",
95 passphrase="12345678")
96 params['wpa_key_mgmt'] = 'SAE'
97 hapd = hostapd.add_ap(apdev[0], params)
98
99 dev[0].request("SET sae_groups ")
100 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
101 scan_freq="2412")
102 ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
103 if ev is None:
104 raise Exception("No connection event received from hostapd")
105 dev[0].request("DISCONNECT")
106 dev[0].wait_disconnected()
107 dev[0].request("RECONNECT")
108 dev[0].wait_connected(timeout=15, error="Reconnect timed out")
109 if dev[0].get_status_field('sae_group') is not None:
110 raise Exception("SAE group claimed to have been used")
111
112 @remote_compatible
113 def test_sae_pmksa_caching_disabled(dev, apdev):
114 """SAE and PMKSA caching disabled"""
115 if "SAE" not in dev[0].get_capability("auth_alg"):
116 raise HwsimSkip("SAE not supported")
117 params = hostapd.wpa2_params(ssid="test-sae",
118 passphrase="12345678")
119 params['wpa_key_mgmt'] = 'SAE'
120 params['disable_pmksa_caching'] = '1'
121 hapd = hostapd.add_ap(apdev[0], params)
122
123 dev[0].request("SET sae_groups ")
124 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
125 scan_freq="2412")
126 ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
127 if ev is None:
128 raise Exception("No connection event received from hostapd")
129 dev[0].request("DISCONNECT")
130 dev[0].wait_disconnected()
131 dev[0].request("RECONNECT")
132 dev[0].wait_connected(timeout=15, error="Reconnect timed out")
133 if dev[0].get_status_field('sae_group') != '19':
134 raise Exception("Expected default SAE group not used")
135
136 def test_sae_groups(dev, apdev):
137 """SAE with all supported groups"""
138 if "SAE" not in dev[0].get_capability("auth_alg"):
139 raise HwsimSkip("SAE not supported")
140 # This is the full list of supported groups, but groups 14-16 (2048-4096 bit
141 # MODP) and group 21 (521-bit random ECP group) are a bit too slow on some
142 # VMs and can result in hitting the mac80211 authentication timeout, so
143 # allow them to fail and just report such failures in the debug log.
144 sae_groups = [ 19, 25, 26, 20, 21, 2, 5, 14, 15, 16, 22, 23, 24 ]
145 tls = dev[0].request("GET tls_library")
146 if tls.startswith("OpenSSL") and "build=OpenSSL 1.0.2" in tls and "run=OpenSSL 1.0.2" in tls:
147 logger.info("Add Brainpool EC groups since OpenSSL is new enough")
148 sae_groups += [ 27, 28, 29, 30 ]
149 heavy_groups = [ 14, 15, 16 ]
150 groups = [str(g) for g in sae_groups]
151 params = hostapd.wpa2_params(ssid="test-sae-groups",
152 passphrase="12345678")
153 params['wpa_key_mgmt'] = 'SAE'
154 params['sae_groups'] = ' '.join(groups)
155 hostapd.add_ap(apdev[0], params)
156
157 for g in groups:
158 logger.info("Testing SAE group " + g)
159 dev[0].request("SET sae_groups " + g)
160 id = dev[0].connect("test-sae-groups", psk="12345678", key_mgmt="SAE",
161 scan_freq="2412", wait_connect=False)
162 if int(g) in heavy_groups:
163 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=5)
164 if ev is None:
165 logger.info("No connection with heavy SAE group %s did not connect - likely hitting timeout in mac80211" % g)
166 dev[0].remove_network(id)
167 time.sleep(0.1)
168 dev[0].dump_monitor()
169 continue
170 logger.info("Connection with heavy SAE group " + g)
171 else:
172 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=10)
173 if ev is None:
174 if "BoringSSL" in tls and int(g) in [ 25 ]:
175 logger.info("Ignore connection failure with group " + g + " with BoringSSL")
176 dev[0].remove_network(id)
177 dev[0].dump_monitor()
178 continue
179 raise Exception("Connection timed out with group " + g)
180 if dev[0].get_status_field('sae_group') != g:
181 raise Exception("Expected SAE group not used")
182 dev[0].remove_network(id)
183 dev[0].wait_disconnected()
184 dev[0].dump_monitor()
185
186 @remote_compatible
187 def test_sae_group_nego(dev, apdev):
188 """SAE group negotiation"""
189 if "SAE" not in dev[0].get_capability("auth_alg"):
190 raise HwsimSkip("SAE not supported")
191 params = hostapd.wpa2_params(ssid="test-sae-group-nego",
192 passphrase="12345678")
193 params['wpa_key_mgmt'] = 'SAE'
194 params['sae_groups'] = '19'
195 hostapd.add_ap(apdev[0], params)
196
197 dev[0].request("SET sae_groups 25 26 20 19")
198 dev[0].connect("test-sae-group-nego", psk="12345678", key_mgmt="SAE",
199 scan_freq="2412")
200 if dev[0].get_status_field('sae_group') != '19':
201 raise Exception("Expected SAE group not used")
202
203 @remote_compatible
204 def test_sae_anti_clogging(dev, apdev):
205 """SAE anti clogging"""
206 if "SAE" not in dev[0].get_capability("auth_alg"):
207 raise HwsimSkip("SAE not supported")
208 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
209 params['wpa_key_mgmt'] = 'SAE'
210 params['sae_anti_clogging_threshold'] = '1'
211 hostapd.add_ap(apdev[0], params)
212
213 dev[0].request("SET sae_groups ")
214 dev[1].request("SET sae_groups ")
215 id = {}
216 for i in range(0, 2):
217 dev[i].scan(freq="2412")
218 id[i] = dev[i].connect("test-sae", psk="12345678", key_mgmt="SAE",
219 scan_freq="2412", only_add_network=True)
220 for i in range(0, 2):
221 dev[i].select_network(id[i])
222 for i in range(0, 2):
223 dev[i].wait_connected(timeout=10)
224
225 def test_sae_forced_anti_clogging(dev, apdev):
226 """SAE anti clogging (forced)"""
227 if "SAE" not in dev[0].get_capability("auth_alg"):
228 raise HwsimSkip("SAE not supported")
229 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
230 params['wpa_key_mgmt'] = 'SAE WPA-PSK'
231 params['sae_anti_clogging_threshold'] = '0'
232 hostapd.add_ap(apdev[0], params)
233 dev[2].connect("test-sae", psk="12345678", scan_freq="2412")
234 for i in range(0, 2):
235 dev[i].request("SET sae_groups ")
236 dev[i].connect("test-sae", psk="12345678", key_mgmt="SAE",
237 scan_freq="2412")
238
239 def test_sae_mixed(dev, apdev):
240 """Mixed SAE and non-SAE network"""
241 if "SAE" not in dev[0].get_capability("auth_alg"):
242 raise HwsimSkip("SAE not supported")
243 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
244 params['wpa_key_mgmt'] = 'SAE WPA-PSK'
245 params['sae_anti_clogging_threshold'] = '0'
246 hostapd.add_ap(apdev[0], params)
247
248 dev[2].connect("test-sae", psk="12345678", scan_freq="2412")
249 for i in range(0, 2):
250 dev[i].request("SET sae_groups ")
251 dev[i].connect("test-sae", psk="12345678", key_mgmt="SAE",
252 scan_freq="2412")
253
254 def test_sae_and_psk(dev, apdev):
255 """SAE and PSK enabled in network profile"""
256 if "SAE" not in dev[0].get_capability("auth_alg"):
257 raise HwsimSkip("SAE not supported")
258 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
259 params['wpa_key_mgmt'] = 'SAE'
260 hostapd.add_ap(apdev[0], params)
261
262 dev[0].request("SET sae_groups ")
263 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE WPA-PSK",
264 scan_freq="2412")
265
266 def test_sae_and_psk2(dev, apdev):
267 """SAE and PSK enabled in network profile (use PSK)"""
268 if "SAE" not in dev[0].get_capability("auth_alg"):
269 raise HwsimSkip("SAE not supported")
270 params = hostapd.wpa2_params(ssid="test-psk", passphrase="12345678")
271 hostapd.add_ap(apdev[0], params)
272
273 dev[0].request("SET sae_groups ")
274 dev[0].connect("test-psk", psk="12345678", key_mgmt="SAE WPA-PSK",
275 scan_freq="2412")
276
277 def test_sae_mixed_mfp(dev, apdev):
278 """Mixed SAE and non-SAE network and MFP required with SAE"""
279 if "SAE" not in dev[0].get_capability("auth_alg"):
280 raise HwsimSkip("SAE not supported")
281 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
282 params['wpa_key_mgmt'] = 'SAE WPA-PSK'
283 params["ieee80211w"] = "1"
284 params['sae_require_mfp'] = '1'
285 hostapd.add_ap(apdev[0], params)
286
287 dev[0].request("SET sae_groups ")
288 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE", ieee80211w="2",
289 scan_freq="2412")
290 dev[0].dump_monitor()
291
292 dev[1].request("SET sae_groups ")
293 dev[1].connect("test-sae", psk="12345678", key_mgmt="SAE", ieee80211w="0",
294 scan_freq="2412", wait_connect=False)
295 ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED",
296 "CTRL-EVENT-ASSOC-REJECT"], timeout=10)
297 if ev is None:
298 raise Exception("No connection result reported")
299 if "CTRL-EVENT-ASSOC-REJECT" not in ev:
300 raise Exception("SAE connection without MFP was not rejected")
301 if "status_code=31" not in ev:
302 raise Exception("Unexpected status code in rejection: " + ev)
303 dev[1].request("DISCONNECT")
304 dev[1].dump_monitor()
305
306 dev[2].connect("test-sae", psk="12345678", ieee80211w="0", scan_freq="2412")
307 dev[2].dump_monitor()
308
309 @remote_compatible
310 def test_sae_missing_password(dev, apdev):
311 """SAE and missing password"""
312 if "SAE" not in dev[0].get_capability("auth_alg"):
313 raise HwsimSkip("SAE not supported")
314 params = hostapd.wpa2_params(ssid="test-sae",
315 passphrase="12345678")
316 params['wpa_key_mgmt'] = 'SAE'
317 hapd = hostapd.add_ap(apdev[0], params)
318
319 dev[0].request("SET sae_groups ")
320 id = dev[0].connect("test-sae",
321 raw_psk="46b4a73b8a951ad53ebd2e0afdb9c5483257edd4c21d12b7710759da70945858",
322 key_mgmt="SAE", scan_freq="2412", wait_connect=False)
323 ev = dev[0].wait_event(['CTRL-EVENT-SSID-TEMP-DISABLED'], timeout=10)
324 if ev is None:
325 raise Exception("Invalid network not temporarily disabled")
326
327
328 def test_sae_key_lifetime_in_memory(dev, apdev, params):
329 """SAE and key lifetime in memory"""
330 if "SAE" not in dev[0].get_capability("auth_alg"):
331 raise HwsimSkip("SAE not supported")
332 password = "5ad144a7c1f5a5503baa6fa01dabc15b1843e8c01662d78d16b70b5cd23cf8b"
333 p = hostapd.wpa2_params(ssid="test-sae", passphrase=password)
334 p['wpa_key_mgmt'] = 'SAE'
335 hapd = hostapd.add_ap(apdev[0], p)
336
337 pid = find_wpas_process(dev[0])
338
339 dev[0].request("SET sae_groups ")
340 id = dev[0].connect("test-sae", psk=password, key_mgmt="SAE",
341 scan_freq="2412")
342
343 # The decrypted copy of GTK is freed only after the CTRL-EVENT-CONNECTED
344 # event has been delivered, so verify that wpa_supplicant has returned to
345 # eloop before reading process memory.
346 time.sleep(1)
347 dev[0].ping()
348 buf = read_process_memory(pid, password)
349
350 dev[0].request("DISCONNECT")
351 dev[0].wait_disconnected()
352
353 dev[0].relog()
354 sae_k = None
355 sae_keyseed = None
356 sae_kck = None
357 pmk = None
358 ptk = None
359 gtk = None
360 with open(os.path.join(params['logdir'], 'log0'), 'r') as f:
361 for l in f.readlines():
362 if "SAE: k - hexdump" in l:
363 val = l.strip().split(':')[3].replace(' ', '')
364 sae_k = binascii.unhexlify(val)
365 if "SAE: keyseed - hexdump" in l:
366 val = l.strip().split(':')[3].replace(' ', '')
367 sae_keyseed = binascii.unhexlify(val)
368 if "SAE: KCK - hexdump" in l:
369 val = l.strip().split(':')[3].replace(' ', '')
370 sae_kck = binascii.unhexlify(val)
371 if "SAE: PMK - hexdump" in l:
372 val = l.strip().split(':')[3].replace(' ', '')
373 pmk = binascii.unhexlify(val)
374 if "WPA: PTK - hexdump" in l:
375 val = l.strip().split(':')[3].replace(' ', '')
376 ptk = binascii.unhexlify(val)
377 if "WPA: Group Key - hexdump" in l:
378 val = l.strip().split(':')[3].replace(' ', '')
379 gtk = binascii.unhexlify(val)
380 if not sae_k or not sae_keyseed or not sae_kck or not pmk or not ptk or not gtk:
381 raise Exception("Could not find keys from debug log")
382 if len(gtk) != 16:
383 raise Exception("Unexpected GTK length")
384
385 kck = ptk[0:16]
386 kek = ptk[16:32]
387 tk = ptk[32:48]
388
389 fname = os.path.join(params['logdir'],
390 'sae_key_lifetime_in_memory.memctx-')
391
392 logger.info("Checking keys in memory while associated")
393 get_key_locations(buf, password, "Password")
394 get_key_locations(buf, pmk, "PMK")
395 if password not in buf:
396 raise HwsimSkip("Password not found while associated")
397 if pmk not in buf:
398 raise HwsimSkip("PMK not found while associated")
399 if kck not in buf:
400 raise Exception("KCK not found while associated")
401 if kek not in buf:
402 raise Exception("KEK not found while associated")
403 #if tk in buf:
404 # raise Exception("TK found from memory")
405 verify_not_present(buf, sae_k, fname, "SAE(k)")
406 verify_not_present(buf, sae_keyseed, fname, "SAE(keyseed)")
407 verify_not_present(buf, sae_kck, fname, "SAE(KCK)")
408
409 logger.info("Checking keys in memory after disassociation")
410 buf = read_process_memory(pid, password)
411
412 # Note: Password is still present in network configuration
413 # Note: PMK is in PMKSA cache
414
415 get_key_locations(buf, password, "Password")
416 get_key_locations(buf, pmk, "PMK")
417 verify_not_present(buf, kck, fname, "KCK")
418 verify_not_present(buf, kek, fname, "KEK")
419 verify_not_present(buf, tk, fname, "TK")
420 if gtk in buf:
421 get_key_locations(buf, gtk, "GTK")
422 verify_not_present(buf, gtk, fname, "GTK")
423 verify_not_present(buf, sae_k, fname, "SAE(k)")
424 verify_not_present(buf, sae_keyseed, fname, "SAE(keyseed)")
425 verify_not_present(buf, sae_kck, fname, "SAE(KCK)")
426
427 dev[0].request("PMKSA_FLUSH")
428 logger.info("Checking keys in memory after PMKSA cache flush")
429 buf = read_process_memory(pid, password)
430 get_key_locations(buf, password, "Password")
431 get_key_locations(buf, pmk, "PMK")
432 verify_not_present(buf, pmk, fname, "PMK")
433
434 dev[0].request("REMOVE_NETWORK all")
435
436 logger.info("Checking keys in memory after network profile removal")
437 buf = read_process_memory(pid, password)
438
439 get_key_locations(buf, password, "Password")
440 get_key_locations(buf, pmk, "PMK")
441 verify_not_present(buf, password, fname, "password")
442 verify_not_present(buf, pmk, fname, "PMK")
443 verify_not_present(buf, kck, fname, "KCK")
444 verify_not_present(buf, kek, fname, "KEK")
445 verify_not_present(buf, tk, fname, "TK")
446 verify_not_present(buf, gtk, fname, "GTK")
447 verify_not_present(buf, sae_k, fname, "SAE(k)")
448 verify_not_present(buf, sae_keyseed, fname, "SAE(keyseed)")
449 verify_not_present(buf, sae_kck, fname, "SAE(KCK)")
450
451 @remote_compatible
452 def test_sae_oom_wpas(dev, apdev):
453 """SAE and OOM in wpa_supplicant"""
454 if "SAE" not in dev[0].get_capability("auth_alg"):
455 raise HwsimSkip("SAE not supported")
456 params = hostapd.wpa2_params(ssid="test-sae",
457 passphrase="12345678")
458 params['wpa_key_mgmt'] = 'SAE'
459 hapd = hostapd.add_ap(apdev[0], params)
460
461 dev[0].request("SET sae_groups 25")
462 tls = dev[0].request("GET tls_library")
463 if "BoringSSL" in tls:
464 dev[0].request("SET sae_groups 26")
465 with alloc_fail(dev[0], 1, "sae_set_group"):
466 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
467 scan_freq="2412")
468 dev[0].request("REMOVE_NETWORK all")
469
470 dev[0].request("SET sae_groups ")
471 with alloc_fail(dev[0], 2, "sae_set_group"):
472 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
473 scan_freq="2412")
474 dev[0].request("REMOVE_NETWORK all")
475
476 with alloc_fail(dev[0], 1, "wpabuf_alloc;sme_auth_build_sae_commit"):
477 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
478 scan_freq="2412")
479 dev[0].request("REMOVE_NETWORK all")
480
481 with alloc_fail(dev[0], 1, "wpabuf_alloc;sme_auth_build_sae_confirm"):
482 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
483 scan_freq="2412", wait_connect=False)
484 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
485 dev[0].request("REMOVE_NETWORK all")
486
487 with alloc_fail(dev[0], 1, "=sme_authenticate"):
488 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
489 scan_freq="2412", wait_connect=False)
490 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
491 dev[0].request("REMOVE_NETWORK all")
492
493 with alloc_fail(dev[0], 1, "radio_add_work;sme_authenticate"):
494 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
495 scan_freq="2412", wait_connect=False)
496 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
497 dev[0].request("REMOVE_NETWORK all")
498
499 @remote_compatible
500 def test_sae_proto_ecc(dev, apdev):
501 """SAE protocol testing (ECC)"""
502 if "SAE" not in dev[0].get_capability("auth_alg"):
503 raise HwsimSkip("SAE not supported")
504 params = hostapd.wpa2_params(ssid="test-sae",
505 passphrase="12345678")
506 params['wpa_key_mgmt'] = 'SAE'
507 hapd = hostapd.add_ap(apdev[0], params)
508 bssid = apdev[0]['bssid']
509
510 dev[0].request("SET sae_groups 19")
511
512 tests = [ ("Confirm mismatch",
513 "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
514 "0000800edebc3f260dc1fe7e0b20888af2b8a3316252ec37388a8504e25b73dc4240"),
515 ("Commit without even full cyclic group field",
516 "13",
517 None),
518 ("Too short commit",
519 "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02",
520 None),
521 ("Invalid commit scalar (0)",
522 "1300" + "0000000000000000000000000000000000000000000000000000000000000000" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
523 None),
524 ("Invalid commit scalar (1)",
525 "1300" + "0000000000000000000000000000000000000000000000000000000000000001" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
526 None),
527 ("Invalid commit scalar (> r)",
528 "1300" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
529 None),
530 ("Commit element not on curve",
531 "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728d0000000000000000000000000000000000000000000000000000000000000000",
532 None),
533 ("Invalid commit element (y coordinate > P)",
534 "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
535 None),
536 ("Invalid commit element (x coordinate > P)",
537 "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
538 None),
539 ("Different group in commit",
540 "1400" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
541 None),
542 ("Too short confirm",
543 "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
544 "0000800edebc3f260dc1fe7e0b20888af2b8a3316252ec37388a8504e25b73dc42")]
545 for (note, commit, confirm) in tests:
546 logger.info(note)
547 dev[0].scan_for_bss(bssid, freq=2412)
548 hapd.set("ext_mgmt_frame_handling", "1")
549 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
550 scan_freq="2412", wait_connect=False)
551
552 logger.info("Commit")
553 for i in range(0, 10):
554 req = hapd.mgmt_rx()
555 if req is None:
556 raise Exception("MGMT RX wait timed out (commit)")
557 if req['subtype'] == 11:
558 break
559 req = None
560 if not req:
561 raise Exception("Authentication frame (commit) not received")
562
563 hapd.dump_monitor()
564 resp = {}
565 resp['fc'] = req['fc']
566 resp['da'] = req['sa']
567 resp['sa'] = req['da']
568 resp['bssid'] = req['bssid']
569 resp['payload'] = binascii.unhexlify("030001000000" + commit)
570 hapd.mgmt_tx(resp)
571
572 if confirm:
573 logger.info("Confirm")
574 for i in range(0, 10):
575 req = hapd.mgmt_rx()
576 if req is None:
577 raise Exception("MGMT RX wait timed out (confirm)")
578 if req['subtype'] == 11:
579 break
580 req = None
581 if not req:
582 raise Exception("Authentication frame (confirm) not received")
583
584 hapd.dump_monitor()
585 resp = {}
586 resp['fc'] = req['fc']
587 resp['da'] = req['sa']
588 resp['sa'] = req['da']
589 resp['bssid'] = req['bssid']
590 resp['payload'] = binascii.unhexlify("030002000000" + confirm)
591 hapd.mgmt_tx(resp)
592
593 time.sleep(0.1)
594 dev[0].request("REMOVE_NETWORK all")
595 hapd.set("ext_mgmt_frame_handling", "0")
596 hapd.dump_monitor()
597
598 @remote_compatible
599 def test_sae_proto_ffc(dev, apdev):
600 """SAE protocol testing (FFC)"""
601 if "SAE" not in dev[0].get_capability("auth_alg"):
602 raise HwsimSkip("SAE not supported")
603 params = hostapd.wpa2_params(ssid="test-sae",
604 passphrase="12345678")
605 params['wpa_key_mgmt'] = 'SAE'
606 hapd = hostapd.add_ap(apdev[0], params)
607 bssid = apdev[0]['bssid']
608
609 dev[0].request("SET sae_groups 2")
610
611 tests = [ ("Confirm mismatch",
612 "0200" + "0c70519d874e3e4930a917cc5e17ea7a26028211159f217bab28b8d6c56691805e49f03249b2c6e22c7c9f86b30e04ccad2deedd5e5108ae07b737c00001c59cd0eb08b1dfc7f1b06a1542e2b6601a963c066e0c65940983a03917ae57a101ce84b5cbbc76ff33ebb990aac2e54aa0f0ab6ec0a58113d927683502b2cb2347d2" + "a8c00117493cdffa5dd671e934bc9cb1a69f39e25e9dd9cd9afd3aea2441a0f5491211c7ba50a753563f9ce943b043557cb71193b28e86ed9544f4289c471bf91b70af5c018cf4663e004165b0fd0bc1d8f3f78adf42eee92bcbc55246fd3ee9f107ab965dc7d4986f23eb71d616ebfe6bfe0a6c1ac5dc1718acee17c9a17486",
613 "0000f3116a9731f1259622e3eb55d4b3b50ba16f8c5f5565b28e609b180c51460251"),
614 ("Too short commit",
615 "0200" + "0c70519d874e3e4930a917cc5e17ea7a26028211159f217bab28b8d6c56691805e49f03249b2c6e22c7c9f86b30e04ccad2deedd5e5108ae07b737c00001c59cd0eb08b1dfc7f1b06a1542e2b6601a963c066e0c65940983a03917ae57a101ce84b5cbbc76ff33ebb990aac2e54aa0f0ab6ec0a58113d927683502b2cb2347d2" + "a8c00117493cdffa5dd671e934bc9cb1a69f39e25e9dd9cd9afd3aea2441a0f5491211c7ba50a753563f9ce943b043557cb71193b28e86ed9544f4289c471bf91b70af5c018cf4663e004165b0fd0bc1d8f3f78adf42eee92bcbc55246fd3ee9f107ab965dc7d4986f23eb71d616ebfe6bfe0a6c1ac5dc1718acee17c9a174",
616 None),
617 ("Invalid element (0) in commit",
618 "0200" + "0c70519d874e3e4930a917cc5e17ea7a26028211159f217bab28b8d6c56691805e49f03249b2c6e22c7c9f86b30e04ccad2deedd5e5108ae07b737c00001c59cd0eb08b1dfc7f1b06a1542e2b6601a963c066e0c65940983a03917ae57a101ce84b5cbbc76ff33ebb990aac2e54aa0f0ab6ec0a58113d927683502b2cb2347d2" + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
619 None),
620 ("Invalid element (1) in commit",
621 "0200" + "0c70519d874e3e4930a917cc5e17ea7a26028211159f217bab28b8d6c56691805e49f03249b2c6e22c7c9f86b30e04ccad2deedd5e5108ae07b737c00001c59cd0eb08b1dfc7f1b06a1542e2b6601a963c066e0c65940983a03917ae57a101ce84b5cbbc76ff33ebb990aac2e54aa0f0ab6ec0a58113d927683502b2cb2347d2" + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
622 None),
623 ("Invalid element (> P) in commit",
624 "0200" + "0c70519d874e3e4930a917cc5e17ea7a26028211159f217bab28b8d6c56691805e49f03249b2c6e22c7c9f86b30e04ccad2deedd5e5108ae07b737c00001c59cd0eb08b1dfc7f1b06a1542e2b6601a963c066e0c65940983a03917ae57a101ce84b5cbbc76ff33ebb990aac2e54aa0f0ab6ec0a58113d927683502b2cb2347d2" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
625 None) ]
626 for (note, commit, confirm) in tests:
627 logger.info(note)
628 dev[0].scan_for_bss(bssid, freq=2412)
629 hapd.set("ext_mgmt_frame_handling", "1")
630 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
631 scan_freq="2412", wait_connect=False)
632
633 logger.info("Commit")
634 for i in range(0, 10):
635 req = hapd.mgmt_rx()
636 if req is None:
637 raise Exception("MGMT RX wait timed out (commit)")
638 if req['subtype'] == 11:
639 break
640 req = None
641 if not req:
642 raise Exception("Authentication frame (commit) not received")
643
644 hapd.dump_monitor()
645 resp = {}
646 resp['fc'] = req['fc']
647 resp['da'] = req['sa']
648 resp['sa'] = req['da']
649 resp['bssid'] = req['bssid']
650 resp['payload'] = binascii.unhexlify("030001000000" + commit)
651 hapd.mgmt_tx(resp)
652
653 if confirm:
654 logger.info("Confirm")
655 for i in range(0, 10):
656 req = hapd.mgmt_rx()
657 if req is None:
658 raise Exception("MGMT RX wait timed out (confirm)")
659 if req['subtype'] == 11:
660 break
661 req = None
662 if not req:
663 raise Exception("Authentication frame (confirm) not received")
664
665 hapd.dump_monitor()
666 resp = {}
667 resp['fc'] = req['fc']
668 resp['da'] = req['sa']
669 resp['sa'] = req['da']
670 resp['bssid'] = req['bssid']
671 resp['payload'] = binascii.unhexlify("030002000000" + confirm)
672 hapd.mgmt_tx(resp)
673
674 time.sleep(0.1)
675 dev[0].request("REMOVE_NETWORK all")
676 hapd.set("ext_mgmt_frame_handling", "0")
677 hapd.dump_monitor()
678
679 def test_sae_proto_confirm_replay(dev, apdev):
680 """SAE protocol testing - Confirm replay"""
681 if "SAE" not in dev[0].get_capability("auth_alg"):
682 raise HwsimSkip("SAE not supported")
683 params = hostapd.wpa2_params(ssid="test-sae",
684 passphrase="12345678")
685 params['wpa_key_mgmt'] = 'SAE'
686 hapd = hostapd.add_ap(apdev[0], params)
687 bssid = apdev[0]['bssid']
688
689 dev[0].request("SET sae_groups 19")
690
691 dev[0].scan_for_bss(bssid, freq=2412)
692 hapd.set("ext_mgmt_frame_handling", "1")
693 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
694 scan_freq="2412", wait_connect=False)
695
696 logger.info("Commit")
697 for i in range(0, 10):
698 req = hapd.mgmt_rx()
699 if req is None:
700 raise Exception("MGMT RX wait timed out (commit)")
701 if req['subtype'] == 11:
702 break
703 req = None
704 if not req:
705 raise Exception("Authentication frame (commit) not received")
706
707 bssid = hapd.own_addr().replace(':', '')
708 addr = dev[0].own_addr().replace(':', '')
709 hdr = "b0003a01" + bssid + addr + bssid + "1000"
710
711 hapd.dump_monitor()
712 hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + req['frame'].encode('hex'))
713
714 logger.info("Confirm")
715 for i in range(0, 10):
716 req = hapd.mgmt_rx()
717 if req is None:
718 raise Exception("MGMT RX wait timed out (confirm)")
719 if req['subtype'] == 11:
720 break
721 req = None
722 if not req:
723 raise Exception("Authentication frame (confirm) not received")
724
725 hapd.dump_monitor()
726 hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + req['frame'].encode('hex'))
727
728 logger.info("Replay Confirm")
729 hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + req['frame'].encode('hex'))
730
731 logger.info("Association Request")
732 for i in range(0, 10):
733 req = hapd.mgmt_rx()
734 if req is None:
735 raise Exception("MGMT RX wait timed out (AssocReq)")
736 if req['subtype'] == 0:
737 break
738 req = None
739 if not req:
740 raise Exception("Association Request frame not received")
741
742 hapd.dump_monitor()
743 hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + req['frame'].encode('hex'))
744 ev = hapd.wait_event(["MGMT-TX-STATUS"], timeout=5)
745 if ev is None:
746 raise Exception("Management frame TX status not reported (1)")
747 if "stype=1 ok=1" not in ev:
748 raise Exception("Unexpected management frame TX status (1): " + ev)
749 cmd = "MGMT_TX_STATUS_PROCESS %s" % (" ".join(ev.split(' ')[1:4]))
750 if "OK" not in hapd.request(cmd):
751 raise Exception("MGMT_TX_STATUS_PROCESS failed")
752
753 hapd.set("ext_mgmt_frame_handling", "0")
754
755 dev[0].wait_connected()
756
757 def test_sae_proto_hostapd(dev, apdev):
758 """SAE protocol testing with hostapd"""
759 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
760 params['wpa_key_mgmt'] = 'SAE'
761 params['sae_groups'] = "19 65535"
762 hapd = hostapd.add_ap(apdev[0], params)
763 hapd.set("ext_mgmt_frame_handling", "1")
764 bssid = hapd.own_addr().replace(':', '')
765 addr = "020000000000"
766 addr2 = "020000000001"
767 hdr = "b0003a01" + bssid + addr + bssid + "1000"
768 hdr2 = "b0003a01" + bssid + addr2 + bssid + "1000"
769 group = "1300"
770 scalar = "f7df19f4a7fef1d3b895ea1de150b7c5a7a705c8ebb31a52b623e0057908bd93"
771 element_x = "21931572027f2e953e2a49fab3d992944102cc95aa19515fc068b394fb25ae3c"
772 element_y = "cb4eeb94d7b0b789abfdb73a67ab9d6d5efa94dd553e0e724a6289821cbce530"
773 hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + "030001000000" + group + scalar + element_x + element_y)
774 # "SAE: Not enough data for scalar"
775 hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + "030001000000" + group + scalar[:-2])
776 # "SAE: Do not allow group to be changed"
777 hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + "030001000000" + "ffff" + scalar[:-2])
778 # "SAE: Unsupported Finite Cyclic Group 65535"
779 hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr2 + "030001000000" + "ffff" + scalar[:-2])
780
781 @remote_compatible
782 def test_sae_no_ffc_by_default(dev, apdev):
783 """SAE and default groups rejecting FFC"""
784 if "SAE" not in dev[0].get_capability("auth_alg"):
785 raise HwsimSkip("SAE not supported")
786 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
787 params['wpa_key_mgmt'] = 'SAE'
788 hapd = hostapd.add_ap(apdev[0], params)
789
790 dev[0].request("SET sae_groups 5")
791 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE", scan_freq="2412",
792 wait_connect=False)
793 ev = dev[0].wait_event(["SME: Trying to authenticate"], timeout=3)
794 if ev is None:
795 raise Exception("Did not try to authenticate")
796 ev = dev[0].wait_event(["SME: Trying to authenticate"], timeout=3)
797 if ev is None:
798 raise Exception("Did not try to authenticate (2)")
799 dev[0].request("REMOVE_NETWORK all")
800
801 def sae_reflection_attack(apdev, dev, group):
802 if "SAE" not in dev.get_capability("auth_alg"):
803 raise HwsimSkip("SAE not supported")
804 params = hostapd.wpa2_params(ssid="test-sae",
805 passphrase="no-knowledge-of-passphrase")
806 params['wpa_key_mgmt'] = 'SAE'
807 hapd = hostapd.add_ap(apdev, params)
808 bssid = apdev['bssid']
809
810 dev.scan_for_bss(bssid, freq=2412)
811 hapd.set("ext_mgmt_frame_handling", "1")
812
813 dev.request("SET sae_groups %d" % group)
814 dev.connect("test-sae", psk="reflection-attack", key_mgmt="SAE",
815 scan_freq="2412", wait_connect=False)
816
817 # Commit
818 for i in range(0, 10):
819 req = hapd.mgmt_rx()
820 if req is None:
821 raise Exception("MGMT RX wait timed out")
822 if req['subtype'] == 11:
823 break
824 req = None
825 if not req:
826 raise Exception("Authentication frame not received")
827
828 resp = {}
829 resp['fc'] = req['fc']
830 resp['da'] = req['sa']
831 resp['sa'] = req['da']
832 resp['bssid'] = req['bssid']
833 resp['payload'] = req['payload']
834 hapd.mgmt_tx(resp)
835
836 # Confirm
837 req = hapd.mgmt_rx(timeout=0.5)
838 if req is not None:
839 if req['subtype'] == 11:
840 raise Exception("Unexpected Authentication frame seen")
841
842 @remote_compatible
843 def test_sae_reflection_attack_ecc(dev, apdev):
844 """SAE reflection attack (ECC)"""
845 sae_reflection_attack(apdev[0], dev[0], 19)
846
847 @remote_compatible
848 def test_sae_reflection_attack_ffc(dev, apdev):
849 """SAE reflection attack (FFC)"""
850 sae_reflection_attack(apdev[0], dev[0], 5)
851
852 def sae_reflection_attack_internal(apdev, dev, group):
853 if "SAE" not in dev.get_capability("auth_alg"):
854 raise HwsimSkip("SAE not supported")
855 params = hostapd.wpa2_params(ssid="test-sae",
856 passphrase="no-knowledge-of-passphrase")
857 params['wpa_key_mgmt'] = 'SAE'
858 params['sae_reflection_attack'] = '1'
859 hapd = hostapd.add_ap(apdev, params)
860 bssid = apdev['bssid']
861
862 dev.scan_for_bss(bssid, freq=2412)
863 dev.request("SET sae_groups %d" % group)
864 dev.connect("test-sae", psk="reflection-attack", key_mgmt="SAE",
865 scan_freq="2412", wait_connect=False)
866 ev = dev.wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
867 if ev is not None:
868 raise Exception("Unexpected connection")
869
870 @remote_compatible
871 def test_sae_reflection_attack_ecc_internal(dev, apdev):
872 """SAE reflection attack (ECC) - internal"""
873 sae_reflection_attack_internal(apdev[0], dev[0], 19)
874
875 @remote_compatible
876 def test_sae_reflection_attack_ffc_internal(dev, apdev):
877 """SAE reflection attack (FFC) - internal"""
878 sae_reflection_attack_internal(apdev[0], dev[0], 5)
879
880 @remote_compatible
881 def test_sae_commit_override(dev, apdev):
882 """SAE commit override (hostapd)"""
883 if "SAE" not in dev[0].get_capability("auth_alg"):
884 raise HwsimSkip("SAE not supported")
885 params = hostapd.wpa2_params(ssid="test-sae",
886 passphrase="12345678")
887 params['wpa_key_mgmt'] = 'SAE'
888 params['sae_commit_override'] = '13ffbad00d215867a7c5ff37d87bb9bdb7cb116e520f71e8d7a794ca2606d537ddc6c099c40e7a25372b80a8fd443cd7dd222c8ea21b8ef372d4b3e316c26a73fd999cc79ad483eb826e7b3893ea332da68fa13224bcdeb4fb18b0584dd100a2c514'
889 hapd = hostapd.add_ap(apdev[0], params)
890 dev[0].request("SET sae_groups ")
891 dev[0].connect("test-sae", psk="test-sae", key_mgmt="SAE",
892 scan_freq="2412", wait_connect=False)
893 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
894 if ev is not None:
895 raise Exception("Unexpected connection")
896
897 @remote_compatible
898 def test_sae_commit_override2(dev, apdev):
899 """SAE commit override (wpa_supplicant)"""
900 if "SAE" not in dev[0].get_capability("auth_alg"):
901 raise HwsimSkip("SAE not supported")
902 params = hostapd.wpa2_params(ssid="test-sae",
903 passphrase="12345678")
904 params['wpa_key_mgmt'] = 'SAE'
905 hapd = hostapd.add_ap(apdev[0], params)
906 dev[0].request("SET sae_groups ")
907 dev[0].set('sae_commit_override', '13ffbad00d215867a7c5ff37d87bb9bdb7cb116e520f71e8d7a794ca2606d537ddc6c099c40e7a25372b80a8fd443cd7dd222c8ea21b8ef372d4b3e316c26a73fd999cc79ad483eb826e7b3893ea332da68fa13224bcdeb4fb18b0584dd100a2c514')
908 dev[0].connect("test-sae", psk="test-sae", key_mgmt="SAE",
909 scan_freq="2412", wait_connect=False)
910 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
911 if ev is not None:
912 raise Exception("Unexpected connection")
913
914 @remote_compatible
915 def test_sae_anti_clogging_proto(dev, apdev):
916 """SAE anti clogging protocol testing"""
917 if "SAE" not in dev[0].get_capability("auth_alg"):
918 raise HwsimSkip("SAE not supported")
919 params = hostapd.wpa2_params(ssid="test-sae",
920 passphrase="no-knowledge-of-passphrase")
921 params['wpa_key_mgmt'] = 'SAE'
922 hapd = hostapd.add_ap(apdev[0], params)
923 bssid = apdev[0]['bssid']
924
925 dev[0].scan_for_bss(bssid, freq=2412)
926 hapd.set("ext_mgmt_frame_handling", "1")
927
928 dev[0].request("SET sae_groups ")
929 dev[0].connect("test-sae", psk="anti-cloggign", key_mgmt="SAE",
930 scan_freq="2412", wait_connect=False)
931
932 # Commit
933 for i in range(0, 10):
934 req = hapd.mgmt_rx()
935 if req is None:
936 raise Exception("MGMT RX wait timed out")
937 if req['subtype'] == 11:
938 break
939 req = None
940 if not req:
941 raise Exception("Authentication frame not received")
942
943 resp = {}
944 resp['fc'] = req['fc']
945 resp['da'] = req['sa']
946 resp['sa'] = req['da']
947 resp['bssid'] = req['bssid']
948 resp['payload'] = binascii.unhexlify("030001004c00" + "ffff00")
949 hapd.mgmt_tx(resp)
950
951 # Confirm (not received due to DH group being rejected)
952 req = hapd.mgmt_rx(timeout=0.5)
953 if req is not None:
954 if req['subtype'] == 11:
955 raise Exception("Unexpected Authentication frame seen")
956
957 @remote_compatible
958 def test_sae_no_random(dev, apdev):
959 """SAE and no random numbers available"""
960 if "SAE" not in dev[0].get_capability("auth_alg"):
961 raise HwsimSkip("SAE not supported")
962 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
963 params['wpa_key_mgmt'] = 'SAE'
964 hapd = hostapd.add_ap(apdev[0], params)
965
966 dev[0].request("SET sae_groups ")
967 tests = [ (1, "os_get_random;sae_get_rand"),
968 (1, "os_get_random;get_rand_1_to_p_1"),
969 (1, "os_get_random;get_random_qr_qnr"),
970 (1, "os_get_random;sae_derive_pwe_ecc") ]
971 for count, func in tests:
972 with fail_test(dev[0], count, func):
973 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
974 scan_freq="2412")
975 dev[0].request("REMOVE_NETWORK all")
976 dev[0].wait_disconnected()
977
978 @remote_compatible
979 def test_sae_pwe_failure(dev, apdev):
980 """SAE and pwe failure"""
981 if "SAE" not in dev[0].get_capability("auth_alg"):
982 raise HwsimSkip("SAE not supported")
983 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
984 params['wpa_key_mgmt'] = 'SAE'
985 params['sae_groups'] = '19 5'
986 hapd = hostapd.add_ap(apdev[0], params)
987
988 dev[0].request("SET sae_groups 19")
989 with fail_test(dev[0], 1, "hmac_sha256_vector;sae_derive_pwe_ecc"):
990 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
991 scan_freq="2412")
992 dev[0].request("REMOVE_NETWORK all")
993 dev[0].wait_disconnected()
994 with fail_test(dev[0], 1, "sae_test_pwd_seed_ecc"):
995 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
996 scan_freq="2412")
997 dev[0].request("REMOVE_NETWORK all")
998 dev[0].wait_disconnected()
999
1000 dev[0].request("SET sae_groups 5")
1001 with fail_test(dev[0], 1, "hmac_sha256_vector;sae_derive_pwe_ffc"):
1002 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
1003 scan_freq="2412")
1004 dev[0].request("REMOVE_NETWORK all")
1005 dev[0].wait_disconnected()
1006
1007 dev[0].request("SET sae_groups 5")
1008 with fail_test(dev[0], 1, "sae_test_pwd_seed_ffc"):
1009 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
1010 scan_freq="2412")
1011 dev[0].request("REMOVE_NETWORK all")
1012 dev[0].wait_disconnected()
1013 with fail_test(dev[0], 2, "sae_test_pwd_seed_ffc"):
1014 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
1015 scan_freq="2412")
1016 dev[0].request("REMOVE_NETWORK all")
1017 dev[0].wait_disconnected()
1018
1019 @remote_compatible
1020 def test_sae_bignum_failure(dev, apdev):
1021 """SAE and bignum failure"""
1022 if "SAE" not in dev[0].get_capability("auth_alg"):
1023 raise HwsimSkip("SAE not supported")
1024 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
1025 params['wpa_key_mgmt'] = 'SAE'
1026 params['sae_groups'] = '19 5 22'
1027 hapd = hostapd.add_ap(apdev[0], params)
1028
1029 dev[0].request("SET sae_groups 19")
1030 tests = [ (1, "crypto_bignum_init_set;get_rand_1_to_p_1"),
1031 (1, "crypto_bignum_init;is_quadratic_residue_blind"),
1032 (1, "crypto_bignum_mulmod;is_quadratic_residue_blind"),
1033 (2, "crypto_bignum_mulmod;is_quadratic_residue_blind"),
1034 (3, "crypto_bignum_mulmod;is_quadratic_residue_blind"),
1035 (1, "crypto_bignum_legendre;is_quadratic_residue_blind"),
1036 (1, "crypto_bignum_init_set;sae_test_pwd_seed_ecc"),
1037 (1, "crypto_ec_point_compute_y_sqr;sae_test_pwd_seed_ecc"),
1038 (1, "crypto_bignum_init_set;get_random_qr_qnr"),
1039 (1, "crypto_bignum_to_bin;sae_derive_pwe_ecc"),
1040 (1, "crypto_ec_point_init;sae_derive_pwe_ecc"),
1041 (1, "crypto_ec_point_solve_y_coord;sae_derive_pwe_ecc"),
1042 (1, "crypto_ec_point_init;sae_derive_commit_element_ecc"),
1043 (1, "crypto_ec_point_mul;sae_derive_commit_element_ecc"),
1044 (1, "crypto_ec_point_invert;sae_derive_commit_element_ecc"),
1045 (1, "crypto_bignum_init;=sae_derive_commit"),
1046 (1, "crypto_ec_point_init;sae_derive_k_ecc"),
1047 (1, "crypto_ec_point_mul;sae_derive_k_ecc"),
1048 (1, "crypto_ec_point_add;sae_derive_k_ecc"),
1049 (2, "crypto_ec_point_mul;sae_derive_k_ecc"),
1050 (1, "crypto_ec_point_to_bin;sae_derive_k_ecc"),
1051 (1, "crypto_bignum_legendre;get_random_qr_qnr"),
1052 (1, "sha256_prf;sae_derive_keys"),
1053 (1, "crypto_bignum_init;sae_derive_keys"),
1054 (1, "crypto_bignum_init_set;sae_parse_commit_scalar"),
1055 (1, "crypto_bignum_to_bin;sae_parse_commit_element_ecc"),
1056 (1, "crypto_ec_point_from_bin;sae_parse_commit_element_ecc") ]
1057 for count, func in tests:
1058 with fail_test(dev[0], count, func):
1059 hapd.request("NOTE STA failure testing %d:%s" % (count, func))
1060 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
1061 scan_freq="2412", wait_connect=False)
1062 wait_fail_trigger(dev[0], "GET_FAIL")
1063 dev[0].request("REMOVE_NETWORK all")
1064 dev[0].dump_monitor()
1065 hapd.dump_monitor()
1066
1067 dev[0].request("SET sae_groups 5")
1068 tests = [ (1, "crypto_bignum_init_set;sae_set_group"),
1069 (2, "crypto_bignum_init_set;sae_set_group"),
1070 (1, "crypto_bignum_init_set;sae_get_rand"),
1071 (1, "crypto_bignum_init_set;sae_test_pwd_seed_ffc"),
1072 (1, "crypto_bignum_exptmod;sae_test_pwd_seed_ffc"),
1073 (1, "crypto_bignum_init;sae_derive_pwe_ffc"),
1074 (1, "crypto_bignum_init;sae_derive_commit_element_ffc"),
1075 (1, "crypto_bignum_exptmod;sae_derive_commit_element_ffc"),
1076 (1, "crypto_bignum_inverse;sae_derive_commit_element_ffc"),
1077 (1, "crypto_bignum_init;sae_derive_k_ffc"),
1078 (1, "crypto_bignum_exptmod;sae_derive_k_ffc"),
1079 (1, "crypto_bignum_mulmod;sae_derive_k_ffc"),
1080 (2, "crypto_bignum_exptmod;sae_derive_k_ffc"),
1081 (1, "crypto_bignum_to_bin;sae_derive_k_ffc"),
1082 (1, "crypto_bignum_init_set;sae_parse_commit_element_ffc"),
1083 (1, "crypto_bignum_init;sae_parse_commit_element_ffc"),
1084 (2, "crypto_bignum_init_set;sae_parse_commit_element_ffc"),
1085 (1, "crypto_bignum_exptmod;sae_parse_commit_element_ffc") ]
1086 for count, func in tests:
1087 with fail_test(dev[0], count, func):
1088 hapd.request("NOTE STA failure testing %d:%s" % (count, func))
1089 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
1090 scan_freq="2412", wait_connect=False)
1091 wait_fail_trigger(dev[0], "GET_FAIL")
1092 dev[0].request("REMOVE_NETWORK all")
1093 dev[0].dump_monitor()
1094 hapd.dump_monitor()
1095
1096 dev[0].request("SET sae_groups 22")
1097 tests = [ (1, "crypto_bignum_init_set;sae_test_pwd_seed_ffc"),
1098 (1, "crypto_bignum_sub;sae_test_pwd_seed_ffc"),
1099 (1, "crypto_bignum_div;sae_test_pwd_seed_ffc") ]
1100 for count, func in tests:
1101 with fail_test(dev[0], count, func):
1102 hapd.request("NOTE STA failure testing %d:%s" % (count, func))
1103 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
1104 scan_freq="2412", wait_connect=False)
1105 wait_fail_trigger(dev[0], "GET_FAIL")
1106 dev[0].request("REMOVE_NETWORK all")
1107 dev[0].dump_monitor()
1108 hapd.dump_monitor()
1109
1110 def test_sae_invalid_anti_clogging_token_req(dev, apdev):
1111 """SAE and invalid anti-clogging token request"""
1112 if "SAE" not in dev[0].get_capability("auth_alg"):
1113 raise HwsimSkip("SAE not supported")
1114 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
1115 params['wpa_key_mgmt'] = 'SAE'
1116 # Beacon more frequently since Probe Request frames are practically ignored
1117 # in this test setup (ext_mgmt_frame_handled=1 on hostapd side) and
1118 # wpa_supplicant scans may end up getting ignored if no new results are
1119 # available due to the missing Probe Response frames.
1120 params['beacon_int'] = '20'
1121 hapd = hostapd.add_ap(apdev[0], params)
1122 bssid = apdev[0]['bssid']
1123
1124 dev[0].request("SET sae_groups 19")
1125 dev[0].scan_for_bss(bssid, freq=2412)
1126 hapd.set("ext_mgmt_frame_handling", "1")
1127 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
1128 scan_freq="2412", wait_connect=False)
1129 ev = dev[0].wait_event(["SME: Trying to authenticate"])
1130 if ev is None:
1131 raise Exception("No authentication attempt seen (1)")
1132 dev[0].dump_monitor()
1133
1134 for i in range(0, 10):
1135 req = hapd.mgmt_rx()
1136 if req is None:
1137 raise Exception("MGMT RX wait timed out (commit)")
1138 if req['subtype'] == 11:
1139 break
1140 req = None
1141 if not req:
1142 raise Exception("Authentication frame (commit) not received")
1143
1144 hapd.dump_monitor()
1145 resp = {}
1146 resp['fc'] = req['fc']
1147 resp['da'] = req['sa']
1148 resp['sa'] = req['da']
1149 resp['bssid'] = req['bssid']
1150 resp['payload'] = binascii.unhexlify("030001004c0013")
1151 hapd.mgmt_tx(resp)
1152 ev = hapd.wait_event(["MGMT-TX-STATUS"], timeout=5)
1153 if ev is None:
1154 raise Exception("Management frame TX status not reported (1)")
1155 if "stype=11 ok=1" not in ev:
1156 raise Exception("Unexpected management frame TX status (1): " + ev)
1157
1158 ev = dev[0].wait_event(["SME: Trying to authenticate"])
1159 if ev is None:
1160 raise Exception("No authentication attempt seen (2)")
1161 dev[0].dump_monitor()
1162
1163 for i in range(0, 10):
1164 req = hapd.mgmt_rx()
1165 if req is None:
1166 raise Exception("MGMT RX wait timed out (commit) (2)")
1167 if req['subtype'] == 11:
1168 break
1169 req = None
1170 if not req:
1171 raise Exception("Authentication frame (commit) not received (2)")
1172
1173 hapd.dump_monitor()
1174 resp = {}
1175 resp['fc'] = req['fc']
1176 resp['da'] = req['sa']
1177 resp['sa'] = req['da']
1178 resp['bssid'] = req['bssid']
1179 resp['payload'] = binascii.unhexlify("030001000100")
1180 hapd.mgmt_tx(resp)
1181 ev = hapd.wait_event(["MGMT-TX-STATUS"], timeout=5)
1182 if ev is None:
1183 raise Exception("Management frame TX status not reported (1)")
1184 if "stype=11 ok=1" not in ev:
1185 raise Exception("Unexpected management frame TX status (1): " + ev)
1186
1187 ev = dev[0].wait_event(["SME: Trying to authenticate"])
1188 if ev is None:
1189 raise Exception("No authentication attempt seen (3)")
1190 dev[0].dump_monitor()
1191
1192 dev[0].request("DISCONNECT")
1193
1194 def test_sae_password(dev, apdev):
1195 """SAE and sae_password in hostapd configuration"""
1196 if "SAE" not in dev[0].get_capability("auth_alg"):
1197 raise HwsimSkip("SAE not supported")
1198 params = hostapd.wpa2_params(ssid="test-sae",
1199 passphrase="12345678")
1200 params['wpa_key_mgmt'] = 'SAE WPA-PSK'
1201 params['sae_password'] = "sae-password"
1202 hapd = hostapd.add_ap(apdev[0], params)
1203
1204 dev[0].request("SET sae_groups ")
1205 dev[0].connect("test-sae", psk="sae-password", key_mgmt="SAE",
1206 scan_freq="2412")
1207 dev[1].connect("test-sae", psk="12345678", scan_freq="2412")
1208 dev[2].request("SET sae_groups ")
1209 dev[2].connect("test-sae", sae_password="sae-password", key_mgmt="SAE",
1210 scan_freq="2412")
1211
1212 def test_sae_password_short(dev, apdev):
1213 """SAE and short password"""
1214 if "SAE" not in dev[0].get_capability("auth_alg"):
1215 raise HwsimSkip("SAE not supported")
1216 params = hostapd.wpa2_params(ssid="test-sae")
1217 params['wpa_key_mgmt'] = 'SAE'
1218 params['sae_password'] = "secret"
1219 hapd = hostapd.add_ap(apdev[0], params)
1220
1221 dev[0].request("SET sae_groups ")
1222 dev[0].connect("test-sae", sae_password="secret", key_mgmt="SAE",
1223 scan_freq="2412")
1224
1225 def test_sae_password_long(dev, apdev):
1226 """SAE and long password"""
1227 if "SAE" not in dev[0].get_capability("auth_alg"):
1228 raise HwsimSkip("SAE not supported")
1229 params = hostapd.wpa2_params(ssid="test-sae")
1230 params['wpa_key_mgmt'] = 'SAE'
1231 params['sae_password'] = 100*"A"
1232 hapd = hostapd.add_ap(apdev[0], params)
1233
1234 dev[0].request("SET sae_groups ")
1235 dev[0].connect("test-sae", sae_password=100*"A", key_mgmt="SAE",
1236 scan_freq="2412")
1237
1238 def test_sae_connect_cmd(dev, apdev):
1239 """SAE with connect command"""
1240 wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
1241 wpas.interface_add("wlan5", drv_params="force_connect_cmd=1")
1242 if "SAE" not in wpas.get_capability("auth_alg"):
1243 raise HwsimSkip("SAE not supported")
1244 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
1245 params['wpa_key_mgmt'] = 'SAE'
1246 hapd = hostapd.add_ap(apdev[0], params)
1247
1248 wpas.request("SET sae_groups ")
1249 wpas.connect("test-sae", psk="12345678", key_mgmt="SAE",
1250 scan_freq="2412", wait_connect=False)
1251 # mac80211_hwsim does not support SAE offload, so accept both a successful
1252 # connection and association rejection.
1253 ev = wpas.wait_event(["CTRL-EVENT-CONNECTED", "CTRL-EVENT-ASSOC-REJECT",
1254 "Association request to the driver failed"],
1255 timeout=15)
1256 if ev is None:
1257 raise Exception("No connection result reported")
1258
1259 def test_sae_password_id(dev, apdev):
1260 """SAE and password identifier"""
1261 if "SAE" not in dev[0].get_capability("auth_alg"):
1262 raise HwsimSkip("SAE not supported")
1263 params = hostapd.wpa2_params(ssid="test-sae")
1264 params['wpa_key_mgmt'] = 'SAE'
1265 params['sae_password'] = [ 'secret|mac=ff:ff:ff:ff:ff:ff|id=pw id',
1266 'foo|mac=02:02:02:02:02:02',
1267 'another secret|mac=ff:ff:ff:ff:ff:ff|id=' + 29*'A' ]
1268 hapd = hostapd.add_ap(apdev[0], params)
1269
1270 dev[0].request("SET sae_groups ")
1271 dev[0].connect("test-sae", sae_password="secret", sae_password_id="pw id",
1272 key_mgmt="SAE", scan_freq="2412")
1273 dev[0].request("REMOVE_NETWORK all")
1274 dev[0].wait_disconnected()
1275
1276 # SAE Password Identifier element with the exact same length as the
1277 # optional Anti-Clogging Token field
1278 dev[0].connect("test-sae", sae_password="another secret",
1279 sae_password_id=29*'A',
1280 key_mgmt="SAE", scan_freq="2412")
1281 dev[0].request("REMOVE_NETWORK all")
1282 dev[0].wait_disconnected()
1283
1284 dev[0].connect("test-sae", sae_password="secret", sae_password_id="unknown",
1285 key_mgmt="SAE", scan_freq="2412", wait_connect=False)
1286
1287 ev = dev[0].wait_event(["CTRL-EVENT-SAE-UNKNOWN-PASSWORD-IDENTIFIER"],
1288 timeout=10)
1289 if ev is None:
1290 raise Exception("Unknown password identifier not reported")
1291 dev[0].request("REMOVE_NETWORK all")
1292
1293 def test_sae_forced_anti_clogging_pw_id(dev, apdev):
1294 """SAE anti clogging (forced and Password Identifier)"""
1295 if "SAE" not in dev[0].get_capability("auth_alg"):
1296 raise HwsimSkip("SAE not supported")
1297 params = hostapd.wpa2_params(ssid="test-sae")
1298 params['wpa_key_mgmt'] = 'SAE'
1299 params['sae_anti_clogging_threshold'] = '0'
1300 params['sae_password'] = 'secret|id=' + 29*'A'
1301 hostapd.add_ap(apdev[0], params)
1302 for i in range(0, 2):
1303 dev[i].request("SET sae_groups ")
1304 dev[i].connect("test-sae", sae_password="secret",
1305 sae_password_id=29*'A', key_mgmt="SAE", scan_freq="2412")
1306
1307 def test_sae_reauth(dev, apdev):
1308 """SAE reauthentication"""
1309 if "SAE" not in dev[0].get_capability("auth_alg"):
1310 raise HwsimSkip("SAE not supported")
1311 params = hostapd.wpa2_params(ssid="test-sae",
1312 passphrase="12345678")
1313 params['wpa_key_mgmt'] = 'SAE'
1314 params["ieee80211w"] = "2"
1315 hapd = hostapd.add_ap(apdev[0], params)
1316
1317 dev[0].request("SET sae_groups ")
1318 id = dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
1319 ieee80211w="2", scan_freq="2412")
1320
1321 hapd.set("ext_mgmt_frame_handling", "1")
1322 dev[0].request("DISCONNECT")
1323 dev[0].wait_disconnected(timeout=10)
1324 hapd.set("ext_mgmt_frame_handling", "0")
1325 dev[0].request("PMKSA_FLUSH")
1326 dev[0].request("REASSOCIATE")
1327 dev[0].wait_connected(timeout=10, error="Timeout on re-connection")