]> git.ipfire.org Git - thirdparty/hostap.git/blame - tests/hwsim/test_sae.py
SAE: Allow commit fields to be overridden for testing purposes (STA)
[thirdparty/hostap.git] / tests / hwsim / test_sae.py
CommitLineData
1640a2e4 1# Test cases for SAE
4f6985de 2# Copyright (c) 2013-2016, Jouni Malinen <j@w1.fi>
1640a2e4
JM
3#
4# This software may be distributed under the terms of the BSD license.
5# See README for more details.
6
9fd6804d 7from remotehost import remote_compatible
5b3c40a6
JM
8import binascii
9import os
1640a2e4 10import time
1640a2e4
JM
11import logging
12logger = logging.getLogger()
13
14import hwsim_utils
15import hostapd
51761ba2 16from utils import HwsimSkip, alloc_fail, fail_test, wait_fail_trigger
5b3c40a6 17from test_ap_psk import find_wpas_process, read_process_memory, verify_not_present, get_key_locations
1640a2e4 18
9fd6804d 19@remote_compatible
1640a2e4
JM
20def test_sae(dev, apdev):
21 """SAE with default group"""
b9749b6a
JM
22 if "SAE" not in dev[0].get_capability("auth_alg"):
23 raise HwsimSkip("SAE not supported")
1640a2e4
JM
24 params = hostapd.wpa2_params(ssid="test-sae",
25 passphrase="12345678")
26 params['wpa_key_mgmt'] = 'SAE'
8b8a1864 27 hapd = hostapd.add_ap(apdev[0], params)
65038313
JM
28 key_mgmt = hapd.get_config()['key_mgmt']
29 if key_mgmt.split(' ')[0] != "SAE":
30 raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
1640a2e4
JM
31
32 dev[0].request("SET sae_groups ")
33 id = dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
34 scan_freq="2412")
35 if dev[0].get_status_field('sae_group') != '19':
36 raise Exception("Expected default SAE group not used")
d463c556
JM
37 bss = dev[0].get_bss(apdev[0]['bssid'])
38 if 'flags' not in bss:
39 raise Exception("Could not get BSS flags from BSS table")
40 if "[WPA2-SAE-CCMP]" not in bss['flags']:
41 raise Exception("Unexpected BSS flags: " + bss['flags'])
1640a2e4 42
7b28c408
JM
43 res = hapd.request("STA-FIRST")
44 if "sae_group=19" not in res.splitlines():
45 raise Exception("hostapd STA output did not specify SAE group")
46
9fd6804d 47@remote_compatible
33dcced5
JM
48def test_sae_password_ecc(dev, apdev):
49 """SAE with number of different passwords (ECC)"""
50 if "SAE" not in dev[0].get_capability("auth_alg"):
51 raise HwsimSkip("SAE not supported")
52 params = hostapd.wpa2_params(ssid="test-sae",
53 passphrase="12345678")
54 params['wpa_key_mgmt'] = 'SAE'
8b8a1864 55 hapd = hostapd.add_ap(apdev[0], params)
33dcced5
JM
56
57 dev[0].request("SET sae_groups 19")
58
59 for i in range(10):
60 password = "12345678-" + str(i)
61 hapd.set("wpa_passphrase", password)
62 dev[0].connect("test-sae", psk=password, key_mgmt="SAE",
63 scan_freq="2412")
64 dev[0].request("REMOVE_NETWORK all")
65 dev[0].wait_disconnected()
66
9fd6804d 67@remote_compatible
33dcced5
JM
68def test_sae_password_ffc(dev, apdev):
69 """SAE with number of different passwords (FFC)"""
70 if "SAE" not in dev[0].get_capability("auth_alg"):
71 raise HwsimSkip("SAE not supported")
72 params = hostapd.wpa2_params(ssid="test-sae",
73 passphrase="12345678")
74 params['wpa_key_mgmt'] = 'SAE'
75 params['sae_groups'] = '22'
8b8a1864 76 hapd = hostapd.add_ap(apdev[0], params)
33dcced5
JM
77
78 dev[0].request("SET sae_groups 22")
79
80 for i in range(10):
81 password = "12345678-" + str(i)
82 hapd.set("wpa_passphrase", password)
83 dev[0].connect("test-sae", psk=password, key_mgmt="SAE",
84 scan_freq="2412")
85 dev[0].request("REMOVE_NETWORK all")
86 dev[0].wait_disconnected()
87
9fd6804d 88@remote_compatible
19d3a6e3
JM
89def test_sae_pmksa_caching(dev, apdev):
90 """SAE and PMKSA caching"""
b9749b6a
JM
91 if "SAE" not in dev[0].get_capability("auth_alg"):
92 raise HwsimSkip("SAE not supported")
19d3a6e3
JM
93 params = hostapd.wpa2_params(ssid="test-sae",
94 passphrase="12345678")
95 params['wpa_key_mgmt'] = 'SAE'
8b8a1864 96 hapd = hostapd.add_ap(apdev[0], params)
19d3a6e3
JM
97
98 dev[0].request("SET sae_groups ")
99 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
100 scan_freq="2412")
7cc9a81f
JM
101 ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
102 if ev is None:
103 raise Exception("No connection event received from hostapd")
19d3a6e3 104 dev[0].request("DISCONNECT")
7cc9a81f 105 dev[0].wait_disconnected()
19d3a6e3 106 dev[0].request("RECONNECT")
5f35a5e2 107 dev[0].wait_connected(timeout=15, error="Reconnect timed out")
19d3a6e3
JM
108 if dev[0].get_status_field('sae_group') is not None:
109 raise Exception("SAE group claimed to have been used")
110
9fd6804d 111@remote_compatible
19d3a6e3
JM
112def test_sae_pmksa_caching_disabled(dev, apdev):
113 """SAE and PMKSA caching disabled"""
b9749b6a
JM
114 if "SAE" not in dev[0].get_capability("auth_alg"):
115 raise HwsimSkip("SAE not supported")
19d3a6e3
JM
116 params = hostapd.wpa2_params(ssid="test-sae",
117 passphrase="12345678")
118 params['wpa_key_mgmt'] = 'SAE'
119 params['disable_pmksa_caching'] = '1'
8b8a1864 120 hapd = hostapd.add_ap(apdev[0], params)
19d3a6e3
JM
121
122 dev[0].request("SET sae_groups ")
123 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
124 scan_freq="2412")
7cc9a81f
JM
125 ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
126 if ev is None:
127 raise Exception("No connection event received from hostapd")
19d3a6e3 128 dev[0].request("DISCONNECT")
7cc9a81f 129 dev[0].wait_disconnected()
19d3a6e3 130 dev[0].request("RECONNECT")
5f35a5e2 131 dev[0].wait_connected(timeout=15, error="Reconnect timed out")
19d3a6e3
JM
132 if dev[0].get_status_field('sae_group') != '19':
133 raise Exception("Expected default SAE group not used")
134
1640a2e4
JM
135def test_sae_groups(dev, apdev):
136 """SAE with all supported groups"""
b9749b6a
JM
137 if "SAE" not in dev[0].get_capability("auth_alg"):
138 raise HwsimSkip("SAE not supported")
b1f487cb
JM
139 # This is the full list of supported groups, but groups 14-16 (2048-4096 bit
140 # MODP) and group 21 (521-bit random ECP group) are a bit too slow on some
141 # VMs and can result in hitting the mac80211 authentication timeout, so
142 # allow them to fail and just report such failures in the debug log.
143 sae_groups = [ 19, 25, 26, 20, 21, 2, 5, 14, 15, 16, 22, 23, 24 ]
9e286d5e
JM
144 tls = dev[0].request("GET tls_library")
145 if tls.startswith("OpenSSL") and "build=OpenSSL 1.0.2" in tls and "run=OpenSSL 1.0.2" in tls:
146 logger.info("Add Brainpool EC groups since OpenSSL is new enough")
147 sae_groups += [ 27, 28, 29, 30 ]
b1f487cb 148 heavy_groups = [ 14, 15, 16 ]
1640a2e4
JM
149 groups = [str(g) for g in sae_groups]
150 params = hostapd.wpa2_params(ssid="test-sae-groups",
151 passphrase="12345678")
152 params['wpa_key_mgmt'] = 'SAE'
153 params['sae_groups'] = ' '.join(groups)
8b8a1864 154 hostapd.add_ap(apdev[0], params)
1640a2e4
JM
155
156 for g in groups:
157 logger.info("Testing SAE group " + g)
158 dev[0].request("SET sae_groups " + g)
159 id = dev[0].connect("test-sae-groups", psk="12345678", key_mgmt="SAE",
b1f487cb
JM
160 scan_freq="2412", wait_connect=False)
161 if int(g) in heavy_groups:
162 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=5)
163 if ev is None:
164 logger.info("No connection with heavy SAE group %s did not connect - likely hitting timeout in mac80211" % g)
165 dev[0].remove_network(id)
166 time.sleep(0.1)
167 dev[0].dump_monitor()
168 continue
169 logger.info("Connection with heavy SAE group " + g)
170 else:
a68d1792
JM
171 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=10)
172 if ev is None:
173 if "BoringSSL" in tls and int(g) in [ 25 ]:
174 logger.info("Ignore connection failure with group " + g + " with BoringSSL")
175 dev[0].remove_network(id)
176 dev[0].dump_monitor()
177 continue
178 raise Exception("Connection timed out with group " + g)
1640a2e4
JM
179 if dev[0].get_status_field('sae_group') != g:
180 raise Exception("Expected SAE group not used")
181 dev[0].remove_network(id)
b1f487cb
JM
182 dev[0].wait_disconnected()
183 dev[0].dump_monitor()
1640a2e4 184
9fd6804d 185@remote_compatible
1640a2e4
JM
186def test_sae_group_nego(dev, apdev):
187 """SAE group negotiation"""
b9749b6a
JM
188 if "SAE" not in dev[0].get_capability("auth_alg"):
189 raise HwsimSkip("SAE not supported")
1640a2e4
JM
190 params = hostapd.wpa2_params(ssid="test-sae-group-nego",
191 passphrase="12345678")
192 params['wpa_key_mgmt'] = 'SAE'
193 params['sae_groups'] = '19'
8b8a1864 194 hostapd.add_ap(apdev[0], params)
1640a2e4
JM
195
196 dev[0].request("SET sae_groups 25 26 20 19")
197 dev[0].connect("test-sae-group-nego", psk="12345678", key_mgmt="SAE",
198 scan_freq="2412")
199 if dev[0].get_status_field('sae_group') != '19':
200 raise Exception("Expected SAE group not used")
a6cf5cd6 201
9fd6804d 202@remote_compatible
a6cf5cd6
JM
203def test_sae_anti_clogging(dev, apdev):
204 """SAE anti clogging"""
b9749b6a
JM
205 if "SAE" not in dev[0].get_capability("auth_alg"):
206 raise HwsimSkip("SAE not supported")
a6cf5cd6
JM
207 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
208 params['wpa_key_mgmt'] = 'SAE'
209 params['sae_anti_clogging_threshold'] = '1'
8b8a1864 210 hostapd.add_ap(apdev[0], params)
a6cf5cd6
JM
211
212 dev[0].request("SET sae_groups ")
213 dev[1].request("SET sae_groups ")
214 id = {}
215 for i in range(0, 2):
216 dev[i].scan(freq="2412")
217 id[i] = dev[i].connect("test-sae", psk="12345678", key_mgmt="SAE",
218 scan_freq="2412", only_add_network=True)
219 for i in range(0, 2):
220 dev[i].select_network(id[i])
221 for i in range(0, 2):
5f35a5e2 222 dev[i].wait_connected(timeout=10)
d05ff960
JM
223
224def test_sae_forced_anti_clogging(dev, apdev):
225 """SAE anti clogging (forced)"""
b9749b6a
JM
226 if "SAE" not in dev[0].get_capability("auth_alg"):
227 raise HwsimSkip("SAE not supported")
d05ff960 228 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
fd4709ff 229 params['wpa_key_mgmt'] = 'SAE WPA-PSK'
d05ff960 230 params['sae_anti_clogging_threshold'] = '0'
8b8a1864 231 hostapd.add_ap(apdev[0], params)
fd4709ff 232 dev[2].connect("test-sae", psk="12345678", scan_freq="2412")
d05ff960
JM
233 for i in range(0, 2):
234 dev[i].request("SET sae_groups ")
235 dev[i].connect("test-sae", psk="12345678", key_mgmt="SAE",
236 scan_freq="2412")
237
238def test_sae_mixed(dev, apdev):
239 """Mixed SAE and non-SAE network"""
b9749b6a
JM
240 if "SAE" not in dev[0].get_capability("auth_alg"):
241 raise HwsimSkip("SAE not supported")
d05ff960
JM
242 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
243 params['wpa_key_mgmt'] = 'SAE WPA-PSK'
244 params['sae_anti_clogging_threshold'] = '0'
8b8a1864 245 hostapd.add_ap(apdev[0], params)
d05ff960
JM
246
247 dev[2].connect("test-sae", psk="12345678", scan_freq="2412")
248 for i in range(0, 2):
249 dev[i].request("SET sae_groups ")
250 dev[i].connect("test-sae", psk="12345678", key_mgmt="SAE",
251 scan_freq="2412")
acb63c75 252
9fd6804d 253@remote_compatible
acb63c75
JM
254def test_sae_missing_password(dev, apdev):
255 """SAE and missing password"""
b9749b6a
JM
256 if "SAE" not in dev[0].get_capability("auth_alg"):
257 raise HwsimSkip("SAE not supported")
acb63c75
JM
258 params = hostapd.wpa2_params(ssid="test-sae",
259 passphrase="12345678")
260 params['wpa_key_mgmt'] = 'SAE'
8b8a1864 261 hapd = hostapd.add_ap(apdev[0], params)
acb63c75
JM
262
263 dev[0].request("SET sae_groups ")
264 id = dev[0].connect("test-sae",
265 raw_psk="46b4a73b8a951ad53ebd2e0afdb9c5483257edd4c21d12b7710759da70945858",
266 key_mgmt="SAE", scan_freq="2412", wait_connect=False)
267 ev = dev[0].wait_event(['CTRL-EVENT-SSID-TEMP-DISABLED'], timeout=10)
268 if ev is None:
269 raise Exception("Invalid network not temporarily disabled")
5b3c40a6
JM
270
271
272def test_sae_key_lifetime_in_memory(dev, apdev, params):
273 """SAE and key lifetime in memory"""
b9749b6a
JM
274 if "SAE" not in dev[0].get_capability("auth_alg"):
275 raise HwsimSkip("SAE not supported")
5b3c40a6
JM
276 password = "5ad144a7c1f5a5503baa6fa01dabc15b1843e8c01662d78d16b70b5cd23cf8b"
277 p = hostapd.wpa2_params(ssid="test-sae", passphrase=password)
278 p['wpa_key_mgmt'] = 'SAE'
8b8a1864 279 hapd = hostapd.add_ap(apdev[0], p)
5b3c40a6
JM
280
281 pid = find_wpas_process(dev[0])
282
283 dev[0].request("SET sae_groups ")
284 id = dev[0].connect("test-sae", psk=password, key_mgmt="SAE",
285 scan_freq="2412")
286
8e416cec
JM
287 # The decrypted copy of GTK is freed only after the CTRL-EVENT-CONNECTED
288 # event has been delivered, so verify that wpa_supplicant has returned to
289 # eloop before reading process memory.
54f2cae2 290 time.sleep(1)
8e416cec 291 dev[0].ping()
5b3c40a6
JM
292 buf = read_process_memory(pid, password)
293
294 dev[0].request("DISCONNECT")
295 dev[0].wait_disconnected()
296
297 dev[0].relog()
298 sae_k = None
299 sae_keyseed = None
300 sae_kck = None
301 pmk = None
302 ptk = None
303 gtk = None
304 with open(os.path.join(params['logdir'], 'log0'), 'r') as f:
305 for l in f.readlines():
306 if "SAE: k - hexdump" in l:
307 val = l.strip().split(':')[3].replace(' ', '')
308 sae_k = binascii.unhexlify(val)
309 if "SAE: keyseed - hexdump" in l:
310 val = l.strip().split(':')[3].replace(' ', '')
311 sae_keyseed = binascii.unhexlify(val)
312 if "SAE: KCK - hexdump" in l:
313 val = l.strip().split(':')[3].replace(' ', '')
314 sae_kck = binascii.unhexlify(val)
315 if "SAE: PMK - hexdump" in l:
316 val = l.strip().split(':')[3].replace(' ', '')
317 pmk = binascii.unhexlify(val)
318 if "WPA: PTK - hexdump" in l:
319 val = l.strip().split(':')[3].replace(' ', '')
320 ptk = binascii.unhexlify(val)
321 if "WPA: Group Key - hexdump" in l:
322 val = l.strip().split(':')[3].replace(' ', '')
323 gtk = binascii.unhexlify(val)
324 if not sae_k or not sae_keyseed or not sae_kck or not pmk or not ptk or not gtk:
325 raise Exception("Could not find keys from debug log")
326 if len(gtk) != 16:
327 raise Exception("Unexpected GTK length")
328
329 kck = ptk[0:16]
330 kek = ptk[16:32]
331 tk = ptk[32:48]
332
333 fname = os.path.join(params['logdir'],
334 'sae_key_lifetime_in_memory.memctx-')
335
336 logger.info("Checking keys in memory while associated")
337 get_key_locations(buf, password, "Password")
338 get_key_locations(buf, pmk, "PMK")
339 if password not in buf:
81e787b7 340 raise HwsimSkip("Password not found while associated")
5b3c40a6 341 if pmk not in buf:
81e787b7 342 raise HwsimSkip("PMK not found while associated")
5b3c40a6
JM
343 if kck not in buf:
344 raise Exception("KCK not found while associated")
345 if kek not in buf:
346 raise Exception("KEK not found while associated")
347 if tk in buf:
348 raise Exception("TK found from memory")
349 if gtk in buf:
8eb45bde 350 get_key_locations(buf, gtk, "GTK")
5b3c40a6
JM
351 raise Exception("GTK found from memory")
352 verify_not_present(buf, sae_k, fname, "SAE(k)")
353 verify_not_present(buf, sae_keyseed, fname, "SAE(keyseed)")
354 verify_not_present(buf, sae_kck, fname, "SAE(KCK)")
355
356 logger.info("Checking keys in memory after disassociation")
357 buf = read_process_memory(pid, password)
358
359 # Note: Password is still present in network configuration
360 # Note: PMK is in PMKSA cache
361
362 get_key_locations(buf, password, "Password")
363 get_key_locations(buf, pmk, "PMK")
364 verify_not_present(buf, kck, fname, "KCK")
365 verify_not_present(buf, kek, fname, "KEK")
366 verify_not_present(buf, tk, fname, "TK")
367 verify_not_present(buf, gtk, fname, "GTK")
368 verify_not_present(buf, sae_k, fname, "SAE(k)")
369 verify_not_present(buf, sae_keyseed, fname, "SAE(keyseed)")
370 verify_not_present(buf, sae_kck, fname, "SAE(KCK)")
371
372 dev[0].request("PMKSA_FLUSH")
373 logger.info("Checking keys in memory after PMKSA cache flush")
374 buf = read_process_memory(pid, password)
375 get_key_locations(buf, password, "Password")
376 get_key_locations(buf, pmk, "PMK")
377 verify_not_present(buf, pmk, fname, "PMK")
378
379 dev[0].request("REMOVE_NETWORK all")
380
381 logger.info("Checking keys in memory after network profile removal")
382 buf = read_process_memory(pid, password)
383
384 get_key_locations(buf, password, "Password")
385 get_key_locations(buf, pmk, "PMK")
386 verify_not_present(buf, password, fname, "password")
387 verify_not_present(buf, pmk, fname, "PMK")
388 verify_not_present(buf, kck, fname, "KCK")
389 verify_not_present(buf, kek, fname, "KEK")
390 verify_not_present(buf, tk, fname, "TK")
391 verify_not_present(buf, gtk, fname, "GTK")
392 verify_not_present(buf, sae_k, fname, "SAE(k)")
393 verify_not_present(buf, sae_keyseed, fname, "SAE(keyseed)")
394 verify_not_present(buf, sae_kck, fname, "SAE(KCK)")
eb6d3532 395
9fd6804d 396@remote_compatible
eb6d3532
JM
397def test_sae_oom_wpas(dev, apdev):
398 """SAE and OOM in wpa_supplicant"""
399 if "SAE" not in dev[0].get_capability("auth_alg"):
400 raise HwsimSkip("SAE not supported")
401 params = hostapd.wpa2_params(ssid="test-sae",
402 passphrase="12345678")
403 params['wpa_key_mgmt'] = 'SAE'
8b8a1864 404 hapd = hostapd.add_ap(apdev[0], params)
eb6d3532
JM
405
406 dev[0].request("SET sae_groups 25")
db036ed5
JM
407 tls = dev[0].request("GET tls_library")
408 if "BoringSSL" in tls:
409 dev[0].request("SET sae_groups 26")
eb6d3532
JM
410 with alloc_fail(dev[0], 1, "sae_set_group"):
411 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
412 scan_freq="2412")
413 dev[0].request("REMOVE_NETWORK all")
414
415 dev[0].request("SET sae_groups ")
416 with alloc_fail(dev[0], 2, "sae_set_group"):
417 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
418 scan_freq="2412")
419 dev[0].request("REMOVE_NETWORK all")
5527a391 420
2fd44db7
JM
421 with alloc_fail(dev[0], 1, "wpabuf_alloc;sme_auth_build_sae_commit"):
422 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
423 scan_freq="2412")
424 dev[0].request("REMOVE_NETWORK all")
425
426 with alloc_fail(dev[0], 1, "wpabuf_alloc;sme_auth_build_sae_confirm"):
427 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
428 scan_freq="2412", wait_connect=False)
429 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
430 dev[0].request("REMOVE_NETWORK all")
431
432 with alloc_fail(dev[0], 1, "=sme_authenticate"):
433 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
434 scan_freq="2412", wait_connect=False)
435 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
436 dev[0].request("REMOVE_NETWORK all")
437
438 with alloc_fail(dev[0], 1, "radio_add_work;sme_authenticate"):
439 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
440 scan_freq="2412", wait_connect=False)
441 wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
442 dev[0].request("REMOVE_NETWORK all")
443
9fd6804d 444@remote_compatible
5527a391
JM
445def test_sae_proto_ecc(dev, apdev):
446 """SAE protocol testing (ECC)"""
447 if "SAE" not in dev[0].get_capability("auth_alg"):
448 raise HwsimSkip("SAE not supported")
449 params = hostapd.wpa2_params(ssid="test-sae",
450 passphrase="12345678")
451 params['wpa_key_mgmt'] = 'SAE'
8b8a1864 452 hapd = hostapd.add_ap(apdev[0], params)
5527a391
JM
453 bssid = apdev[0]['bssid']
454
455 dev[0].request("SET sae_groups 19")
456
457 tests = [ ("Confirm mismatch",
458 "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
459 "0000800edebc3f260dc1fe7e0b20888af2b8a3316252ec37388a8504e25b73dc4240"),
460 ("Commit without even full cyclic group field",
461 "13",
462 None),
463 ("Too short commit",
464 "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02",
465 None),
466 ("Invalid commit scalar (0)",
467 "1300" + "0000000000000000000000000000000000000000000000000000000000000000" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
468 None),
17ce7bb9
JM
469 ("Invalid commit scalar (1)",
470 "1300" + "0000000000000000000000000000000000000000000000000000000000000001" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
471 None),
5527a391
JM
472 ("Invalid commit scalar (> r)",
473 "1300" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
474 None),
475 ("Commit element not on curve",
476 "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728d0000000000000000000000000000000000000000000000000000000000000000",
477 None),
478 ("Invalid commit element (y coordinate > P)",
479 "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
480 None),
481 ("Invalid commit element (x coordinate > P)",
482 "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
483 None),
484 ("Different group in commit",
485 "1400" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
486 None),
487 ("Too short confirm",
488 "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
489 "0000800edebc3f260dc1fe7e0b20888af2b8a3316252ec37388a8504e25b73dc42")]
490 for (note, commit, confirm) in tests:
491 logger.info(note)
492 dev[0].scan_for_bss(bssid, freq=2412)
493 hapd.set("ext_mgmt_frame_handling", "1")
494 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
495 scan_freq="2412", wait_connect=False)
496
497 logger.info("Commit")
498 for i in range(0, 10):
499 req = hapd.mgmt_rx()
500 if req is None:
501 raise Exception("MGMT RX wait timed out (commit)")
502 if req['subtype'] == 11:
503 break
504 req = None
505 if not req:
506 raise Exception("Authentication frame (commit) not received")
507
508 hapd.dump_monitor()
509 resp = {}
510 resp['fc'] = req['fc']
511 resp['da'] = req['sa']
512 resp['sa'] = req['da']
513 resp['bssid'] = req['bssid']
514 resp['payload'] = binascii.unhexlify("030001000000" + commit)
515 hapd.mgmt_tx(resp)
516
517 if confirm:
518 logger.info("Confirm")
519 for i in range(0, 10):
520 req = hapd.mgmt_rx()
521 if req is None:
522 raise Exception("MGMT RX wait timed out (confirm)")
523 if req['subtype'] == 11:
524 break
525 req = None
526 if not req:
527 raise Exception("Authentication frame (confirm) not received")
528
529 hapd.dump_monitor()
530 resp = {}
531 resp['fc'] = req['fc']
532 resp['da'] = req['sa']
533 resp['sa'] = req['da']
534 resp['bssid'] = req['bssid']
535 resp['payload'] = binascii.unhexlify("030002000000" + confirm)
536 hapd.mgmt_tx(resp)
537
538 time.sleep(0.1)
539 dev[0].request("REMOVE_NETWORK all")
540 hapd.set("ext_mgmt_frame_handling", "0")
541 hapd.dump_monitor()
542
9fd6804d 543@remote_compatible
5527a391
JM
544def test_sae_proto_ffc(dev, apdev):
545 """SAE protocol testing (FFC)"""
546 if "SAE" not in dev[0].get_capability("auth_alg"):
547 raise HwsimSkip("SAE not supported")
548 params = hostapd.wpa2_params(ssid="test-sae",
549 passphrase="12345678")
550 params['wpa_key_mgmt'] = 'SAE'
8b8a1864 551 hapd = hostapd.add_ap(apdev[0], params)
5527a391
JM
552 bssid = apdev[0]['bssid']
553
554 dev[0].request("SET sae_groups 2")
555
556 tests = [ ("Confirm mismatch",
557 "0200" + "0c70519d874e3e4930a917cc5e17ea7a26028211159f217bab28b8d6c56691805e49f03249b2c6e22c7c9f86b30e04ccad2deedd5e5108ae07b737c00001c59cd0eb08b1dfc7f1b06a1542e2b6601a963c066e0c65940983a03917ae57a101ce84b5cbbc76ff33ebb990aac2e54aa0f0ab6ec0a58113d927683502b2cb2347d2" + "a8c00117493cdffa5dd671e934bc9cb1a69f39e25e9dd9cd9afd3aea2441a0f5491211c7ba50a753563f9ce943b043557cb71193b28e86ed9544f4289c471bf91b70af5c018cf4663e004165b0fd0bc1d8f3f78adf42eee92bcbc55246fd3ee9f107ab965dc7d4986f23eb71d616ebfe6bfe0a6c1ac5dc1718acee17c9a17486",
558 "0000f3116a9731f1259622e3eb55d4b3b50ba16f8c5f5565b28e609b180c51460251"),
559 ("Too short commit",
560 "0200" + "0c70519d874e3e4930a917cc5e17ea7a26028211159f217bab28b8d6c56691805e49f03249b2c6e22c7c9f86b30e04ccad2deedd5e5108ae07b737c00001c59cd0eb08b1dfc7f1b06a1542e2b6601a963c066e0c65940983a03917ae57a101ce84b5cbbc76ff33ebb990aac2e54aa0f0ab6ec0a58113d927683502b2cb2347d2" + "a8c00117493cdffa5dd671e934bc9cb1a69f39e25e9dd9cd9afd3aea2441a0f5491211c7ba50a753563f9ce943b043557cb71193b28e86ed9544f4289c471bf91b70af5c018cf4663e004165b0fd0bc1d8f3f78adf42eee92bcbc55246fd3ee9f107ab965dc7d4986f23eb71d616ebfe6bfe0a6c1ac5dc1718acee17c9a174",
561 None),
562 ("Invalid element (0) in commit",
563 "0200" + "0c70519d874e3e4930a917cc5e17ea7a26028211159f217bab28b8d6c56691805e49f03249b2c6e22c7c9f86b30e04ccad2deedd5e5108ae07b737c00001c59cd0eb08b1dfc7f1b06a1542e2b6601a963c066e0c65940983a03917ae57a101ce84b5cbbc76ff33ebb990aac2e54aa0f0ab6ec0a58113d927683502b2cb2347d2" + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
564 None),
565 ("Invalid element (1) in commit",
566 "0200" + "0c70519d874e3e4930a917cc5e17ea7a26028211159f217bab28b8d6c56691805e49f03249b2c6e22c7c9f86b30e04ccad2deedd5e5108ae07b737c00001c59cd0eb08b1dfc7f1b06a1542e2b6601a963c066e0c65940983a03917ae57a101ce84b5cbbc76ff33ebb990aac2e54aa0f0ab6ec0a58113d927683502b2cb2347d2" + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
567 None),
568 ("Invalid element (> P) in commit",
569 "0200" + "0c70519d874e3e4930a917cc5e17ea7a26028211159f217bab28b8d6c56691805e49f03249b2c6e22c7c9f86b30e04ccad2deedd5e5108ae07b737c00001c59cd0eb08b1dfc7f1b06a1542e2b6601a963c066e0c65940983a03917ae57a101ce84b5cbbc76ff33ebb990aac2e54aa0f0ab6ec0a58113d927683502b2cb2347d2" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
570 None) ]
571 for (note, commit, confirm) in tests:
572 logger.info(note)
573 dev[0].scan_for_bss(bssid, freq=2412)
574 hapd.set("ext_mgmt_frame_handling", "1")
575 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
576 scan_freq="2412", wait_connect=False)
577
578 logger.info("Commit")
579 for i in range(0, 10):
580 req = hapd.mgmt_rx()
581 if req is None:
582 raise Exception("MGMT RX wait timed out (commit)")
583 if req['subtype'] == 11:
584 break
585 req = None
586 if not req:
587 raise Exception("Authentication frame (commit) not received")
588
589 hapd.dump_monitor()
590 resp = {}
591 resp['fc'] = req['fc']
592 resp['da'] = req['sa']
593 resp['sa'] = req['da']
594 resp['bssid'] = req['bssid']
595 resp['payload'] = binascii.unhexlify("030001000000" + commit)
596 hapd.mgmt_tx(resp)
597
598 if confirm:
599 logger.info("Confirm")
600 for i in range(0, 10):
601 req = hapd.mgmt_rx()
602 if req is None:
603 raise Exception("MGMT RX wait timed out (confirm)")
604 if req['subtype'] == 11:
605 break
606 req = None
607 if not req:
608 raise Exception("Authentication frame (confirm) not received")
609
610 hapd.dump_monitor()
611 resp = {}
612 resp['fc'] = req['fc']
613 resp['da'] = req['sa']
614 resp['sa'] = req['da']
615 resp['bssid'] = req['bssid']
616 resp['payload'] = binascii.unhexlify("030002000000" + confirm)
617 hapd.mgmt_tx(resp)
618
619 time.sleep(0.1)
620 dev[0].request("REMOVE_NETWORK all")
621 hapd.set("ext_mgmt_frame_handling", "0")
622 hapd.dump_monitor()
623
7a92dbd7
JM
624def test_sae_proto_hostapd(dev, apdev):
625 """SAE protocol testing with hostapd"""
626 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
627 params['wpa_key_mgmt'] = 'SAE'
628 params['sae_groups'] = "19 65535"
629 hapd = hostapd.add_ap(apdev[0], params)
630 hapd.set("ext_mgmt_frame_handling", "1")
631 bssid = hapd.own_addr().replace(':', '')
632 addr = "020000000000"
633 addr2 = "020000000001"
634 hdr = "b0003a01" + bssid + addr + bssid + "1000"
635 hdr2 = "b0003a01" + bssid + addr2 + bssid + "1000"
636 group = "1300"
637 scalar = "f7df19f4a7fef1d3b895ea1de150b7c5a7a705c8ebb31a52b623e0057908bd93"
638 element_x = "21931572027f2e953e2a49fab3d992944102cc95aa19515fc068b394fb25ae3c"
639 element_y = "cb4eeb94d7b0b789abfdb73a67ab9d6d5efa94dd553e0e724a6289821cbce530"
640 hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + "030001000000" + group + scalar + element_x + element_y)
641 # "SAE: Not enough data for scalar"
642 hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + "030001000000" + group + scalar[:-2])
643 # "SAE: Do not allow group to be changed"
644 hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr + "030001000000" + "ffff" + scalar[:-2])
645 # "SAE: Unsupported Finite Cyclic Group 65535"
646 hapd.request("MGMT_RX_PROCESS freq=2412 datarate=0 ssi_signal=-30 frame=" + hdr2 + "030001000000" + "ffff" + scalar[:-2])
647
9fd6804d 648@remote_compatible
5527a391
JM
649def test_sae_no_ffc_by_default(dev, apdev):
650 """SAE and default groups rejecting FFC"""
651 if "SAE" not in dev[0].get_capability("auth_alg"):
652 raise HwsimSkip("SAE not supported")
653 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
654 params['wpa_key_mgmt'] = 'SAE'
8b8a1864 655 hapd = hostapd.add_ap(apdev[0], params)
5527a391
JM
656
657 dev[0].request("SET sae_groups 5")
658 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE", scan_freq="2412",
659 wait_connect=False)
660 ev = dev[0].wait_event(["SME: Trying to authenticate"], timeout=3)
661 if ev is None:
662 raise Exception("Did not try to authenticate")
663 ev = dev[0].wait_event(["SME: Trying to authenticate"], timeout=3)
664 if ev is None:
665 raise Exception("Did not try to authenticate (2)")
666 dev[0].request("REMOVE_NETWORK all")
939527b5
JM
667
668def sae_reflection_attack(apdev, dev, group):
669 if "SAE" not in dev.get_capability("auth_alg"):
670 raise HwsimSkip("SAE not supported")
671 params = hostapd.wpa2_params(ssid="test-sae",
672 passphrase="no-knowledge-of-passphrase")
673 params['wpa_key_mgmt'] = 'SAE'
afc26df2 674 hapd = hostapd.add_ap(apdev, params)
939527b5
JM
675 bssid = apdev['bssid']
676
677 dev.scan_for_bss(bssid, freq=2412)
678 hapd.set("ext_mgmt_frame_handling", "1")
679
680 dev.request("SET sae_groups %d" % group)
681 dev.connect("test-sae", psk="reflection-attack", key_mgmt="SAE",
682 scan_freq="2412", wait_connect=False)
683
684 # Commit
685 for i in range(0, 10):
686 req = hapd.mgmt_rx()
687 if req is None:
688 raise Exception("MGMT RX wait timed out")
689 if req['subtype'] == 11:
690 break
691 req = None
692 if not req:
693 raise Exception("Authentication frame not received")
694
695 resp = {}
696 resp['fc'] = req['fc']
697 resp['da'] = req['sa']
698 resp['sa'] = req['da']
699 resp['bssid'] = req['bssid']
700 resp['payload'] = req['payload']
701 hapd.mgmt_tx(resp)
702
703 # Confirm
704 req = hapd.mgmt_rx(timeout=0.5)
705 if req is not None:
706 if req['subtype'] == 11:
707 raise Exception("Unexpected Authentication frame seen")
708
9fd6804d 709@remote_compatible
939527b5
JM
710def test_sae_reflection_attack_ecc(dev, apdev):
711 """SAE reflection attack (ECC)"""
712 sae_reflection_attack(apdev[0], dev[0], 19)
713
9fd6804d 714@remote_compatible
939527b5
JM
715def test_sae_reflection_attack_ffc(dev, apdev):
716 """SAE reflection attack (FFC)"""
717 sae_reflection_attack(apdev[0], dev[0], 5)
1965e196 718
1342c47a
JM
719def sae_reflection_attack_internal(apdev, dev, group):
720 if "SAE" not in dev.get_capability("auth_alg"):
721 raise HwsimSkip("SAE not supported")
722 params = hostapd.wpa2_params(ssid="test-sae",
723 passphrase="no-knowledge-of-passphrase")
724 params['wpa_key_mgmt'] = 'SAE'
725 params['sae_reflection_attack'] = '1'
726 hapd = hostapd.add_ap(apdev, params)
727 bssid = apdev['bssid']
728
729 dev.scan_for_bss(bssid, freq=2412)
730 dev.request("SET sae_groups %d" % group)
731 dev.connect("test-sae", psk="reflection-attack", key_mgmt="SAE",
732 scan_freq="2412", wait_connect=False)
733 ev = dev.wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
734 if ev is not None:
735 raise Exception("Unexpected connection")
736
737@remote_compatible
738def test_sae_reflection_attack_ecc_internal(dev, apdev):
739 """SAE reflection attack (ECC) - internal"""
740 sae_reflection_attack_internal(apdev[0], dev[0], 19)
741
742@remote_compatible
743def test_sae_reflection_attack_ffc_internal(dev, apdev):
744 """SAE reflection attack (FFC) - internal"""
745 sae_reflection_attack_internal(apdev[0], dev[0], 5)
746
cd06e266
JM
747@remote_compatible
748def test_sae_commit_override(dev, apdev):
749 """SAE commit override (hostapd)"""
750 if "SAE" not in dev[0].get_capability("auth_alg"):
751 raise HwsimSkip("SAE not supported")
752 params = hostapd.wpa2_params(ssid="test-sae",
753 passphrase="12345678")
754 params['wpa_key_mgmt'] = 'SAE'
755 params['sae_commit_override'] = '13ffbad00d215867a7c5ff37d87bb9bdb7cb116e520f71e8d7a794ca2606d537ddc6c099c40e7a25372b80a8fd443cd7dd222c8ea21b8ef372d4b3e316c26a73fd999cc79ad483eb826e7b3893ea332da68fa13224bcdeb4fb18b0584dd100a2c514'
756 hapd = hostapd.add_ap(apdev[0], params)
757 dev[0].request("SET sae_groups ")
758 dev[0].connect("test-sae", psk="test-sae", key_mgmt="SAE",
759 scan_freq="2412", wait_connect=False)
760 ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
761 if ev is not None:
762 raise Exception("Unexpected connection")
763
9fd6804d 764@remote_compatible
1965e196
JM
765def test_sae_anti_clogging_proto(dev, apdev):
766 """SAE anti clogging protocol testing"""
767 if "SAE" not in dev[0].get_capability("auth_alg"):
768 raise HwsimSkip("SAE not supported")
769 params = hostapd.wpa2_params(ssid="test-sae",
770 passphrase="no-knowledge-of-passphrase")
771 params['wpa_key_mgmt'] = 'SAE'
8b8a1864 772 hapd = hostapd.add_ap(apdev[0], params)
1965e196
JM
773 bssid = apdev[0]['bssid']
774
775 dev[0].scan_for_bss(bssid, freq=2412)
776 hapd.set("ext_mgmt_frame_handling", "1")
777
778 dev[0].request("SET sae_groups ")
779 dev[0].connect("test-sae", psk="anti-cloggign", key_mgmt="SAE",
780 scan_freq="2412", wait_connect=False)
781
782 # Commit
783 for i in range(0, 10):
784 req = hapd.mgmt_rx()
785 if req is None:
786 raise Exception("MGMT RX wait timed out")
787 if req['subtype'] == 11:
788 break
789 req = None
790 if not req:
791 raise Exception("Authentication frame not received")
792
793 resp = {}
794 resp['fc'] = req['fc']
795 resp['da'] = req['sa']
796 resp['sa'] = req['da']
797 resp['bssid'] = req['bssid']
798 resp['payload'] = binascii.unhexlify("030001004c00" + "ffff00")
799 hapd.mgmt_tx(resp)
800
801 # Confirm (not received due to DH group being rejected)
802 req = hapd.mgmt_rx(timeout=0.5)
803 if req is not None:
804 if req['subtype'] == 11:
805 raise Exception("Unexpected Authentication frame seen")
10ba4ae4 806
9fd6804d 807@remote_compatible
10ba4ae4
JM
808def test_sae_no_random(dev, apdev):
809 """SAE and no random numbers available"""
810 if "SAE" not in dev[0].get_capability("auth_alg"):
811 raise HwsimSkip("SAE not supported")
812 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
813 params['wpa_key_mgmt'] = 'SAE'
8b8a1864 814 hapd = hostapd.add_ap(apdev[0], params)
10ba4ae4
JM
815
816 dev[0].request("SET sae_groups ")
817 tests = [ (1, "os_get_random;sae_get_rand"),
818 (1, "os_get_random;get_rand_1_to_p_1"),
819 (1, "os_get_random;get_random_qr_qnr"),
820 (1, "os_get_random;sae_derive_pwe_ecc") ]
821 for count, func in tests:
822 with fail_test(dev[0], count, func):
823 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
824 scan_freq="2412")
825 dev[0].request("REMOVE_NETWORK all")
826 dev[0].wait_disconnected()
4f6985de 827
9fd6804d 828@remote_compatible
4f6985de
JM
829def test_sae_pwe_failure(dev, apdev):
830 """SAE and pwe failure"""
831 if "SAE" not in dev[0].get_capability("auth_alg"):
832 raise HwsimSkip("SAE not supported")
833 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
834 params['wpa_key_mgmt'] = 'SAE'
835 params['sae_groups'] = '19 5'
8b8a1864 836 hapd = hostapd.add_ap(apdev[0], params)
4f6985de
JM
837
838 dev[0].request("SET sae_groups 19")
839 with fail_test(dev[0], 1, "hmac_sha256_vector;sae_derive_pwe_ecc"):
840 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
841 scan_freq="2412")
842 dev[0].request("REMOVE_NETWORK all")
843 dev[0].wait_disconnected()
51761ba2
JM
844 with fail_test(dev[0], 1, "sae_test_pwd_seed_ecc"):
845 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
846 scan_freq="2412")
847 dev[0].request("REMOVE_NETWORK all")
848 dev[0].wait_disconnected()
4f6985de
JM
849
850 dev[0].request("SET sae_groups 5")
851 with fail_test(dev[0], 1, "hmac_sha256_vector;sae_derive_pwe_ffc"):
852 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
853 scan_freq="2412")
854 dev[0].request("REMOVE_NETWORK all")
855 dev[0].wait_disconnected()
856
857 dev[0].request("SET sae_groups 5")
858 with fail_test(dev[0], 1, "sae_test_pwd_seed_ffc"):
859 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
860 scan_freq="2412")
861 dev[0].request("REMOVE_NETWORK all")
862 dev[0].wait_disconnected()
863 with fail_test(dev[0], 2, "sae_test_pwd_seed_ffc"):
864 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
865 scan_freq="2412")
866 dev[0].request("REMOVE_NETWORK all")
867 dev[0].wait_disconnected()
51761ba2 868
9fd6804d 869@remote_compatible
51761ba2
JM
870def test_sae_bignum_failure(dev, apdev):
871 """SAE and bignum failure"""
872 if "SAE" not in dev[0].get_capability("auth_alg"):
873 raise HwsimSkip("SAE not supported")
874 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
875 params['wpa_key_mgmt'] = 'SAE'
876 params['sae_groups'] = '19 5 22'
8b8a1864 877 hapd = hostapd.add_ap(apdev[0], params)
51761ba2
JM
878
879 dev[0].request("SET sae_groups 19")
880 tests = [ (1, "crypto_bignum_init_set;get_rand_1_to_p_1"),
881 (1, "crypto_bignum_init;is_quadratic_residue_blind"),
882 (1, "crypto_bignum_mulmod;is_quadratic_residue_blind"),
883 (2, "crypto_bignum_mulmod;is_quadratic_residue_blind"),
884 (3, "crypto_bignum_mulmod;is_quadratic_residue_blind"),
885 (1, "crypto_bignum_legendre;is_quadratic_residue_blind"),
886 (1, "crypto_bignum_init_set;sae_test_pwd_seed_ecc"),
887 (1, "crypto_ec_point_compute_y_sqr;sae_test_pwd_seed_ecc"),
888 (1, "crypto_bignum_init_set;get_random_qr_qnr"),
889 (1, "crypto_bignum_to_bin;sae_derive_pwe_ecc"),
890 (1, "crypto_ec_point_init;sae_derive_pwe_ecc"),
891 (1, "crypto_ec_point_solve_y_coord;sae_derive_pwe_ecc"),
892 (1, "crypto_ec_point_init;sae_derive_commit_element_ecc"),
893 (1, "crypto_ec_point_mul;sae_derive_commit_element_ecc"),
894 (1, "crypto_ec_point_invert;sae_derive_commit_element_ecc"),
895 (1, "crypto_bignum_init;=sae_derive_commit"),
896 (1, "crypto_ec_point_init;sae_derive_k_ecc"),
897 (1, "crypto_ec_point_mul;sae_derive_k_ecc"),
898 (1, "crypto_ec_point_add;sae_derive_k_ecc"),
899 (2, "crypto_ec_point_mul;sae_derive_k_ecc"),
900 (1, "crypto_ec_point_to_bin;sae_derive_k_ecc"),
901 (1, "crypto_bignum_legendre;get_random_qr_qnr"),
902 (1, "sha256_prf;sae_derive_keys"),
903 (1, "crypto_bignum_init;sae_derive_keys"),
904 (1, "crypto_bignum_init_set;sae_parse_commit_scalar"),
905 (1, "crypto_bignum_to_bin;sae_parse_commit_element_ecc"),
906 (1, "crypto_ec_point_from_bin;sae_parse_commit_element_ecc") ]
907 for count, func in tests:
908 with fail_test(dev[0], count, func):
909 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
910 scan_freq="2412", wait_connect=False)
911 wait_fail_trigger(dev[0], "GET_FAIL")
912 dev[0].request("REMOVE_NETWORK all")
913
914 dev[0].request("SET sae_groups 5")
915 tests = [ (1, "crypto_bignum_init_set;sae_set_group"),
916 (2, "crypto_bignum_init_set;sae_set_group"),
917 (1, "crypto_bignum_init_set;sae_get_rand"),
918 (1, "crypto_bignum_init_set;sae_test_pwd_seed_ffc"),
919 (1, "crypto_bignum_exptmod;sae_test_pwd_seed_ffc"),
920 (1, "crypto_bignum_init;sae_derive_pwe_ffc"),
921 (1, "crypto_bignum_init;sae_derive_commit_element_ffc"),
922 (1, "crypto_bignum_exptmod;sae_derive_commit_element_ffc"),
923 (1, "crypto_bignum_inverse;sae_derive_commit_element_ffc"),
924 (1, "crypto_bignum_init;sae_derive_k_ffc"),
925 (1, "crypto_bignum_exptmod;sae_derive_k_ffc"),
926 (1, "crypto_bignum_mulmod;sae_derive_k_ffc"),
927 (2, "crypto_bignum_exptmod;sae_derive_k_ffc"),
928 (1, "crypto_bignum_to_bin;sae_derive_k_ffc"),
929 (1, "crypto_bignum_init_set;sae_parse_commit_element_ffc"),
930 (1, "crypto_bignum_init;sae_parse_commit_element_ffc"),
931 (2, "crypto_bignum_init_set;sae_parse_commit_element_ffc"),
932 (1, "crypto_bignum_exptmod;sae_parse_commit_element_ffc") ]
933 for count, func in tests:
934 with fail_test(dev[0], count, func):
935 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
936 scan_freq="2412", wait_connect=False)
937 wait_fail_trigger(dev[0], "GET_FAIL")
938 dev[0].request("REMOVE_NETWORK all")
939
940 dev[0].request("SET sae_groups 22")
941 tests = [ (1, "crypto_bignum_init_set;sae_test_pwd_seed_ffc"),
942 (1, "crypto_bignum_sub;sae_test_pwd_seed_ffc"),
943 (1, "crypto_bignum_div;sae_test_pwd_seed_ffc") ]
944 for count, func in tests:
945 with fail_test(dev[0], count, func):
946 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
947 scan_freq="2412", wait_connect=False)
948 wait_fail_trigger(dev[0], "GET_FAIL")
949 dev[0].request("REMOVE_NETWORK all")
28be769b
JM
950
951def test_sae_invalid_anti_clogging_token_req(dev, apdev):
952 """SAE and invalid anti-clogging token request"""
953 if "SAE" not in dev[0].get_capability("auth_alg"):
954 raise HwsimSkip("SAE not supported")
955 params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
956 params['wpa_key_mgmt'] = 'SAE'
957 hapd = hostapd.add_ap(apdev[0], params)
958 bssid = apdev[0]['bssid']
959
960 dev[0].request("SET sae_groups 19")
961 dev[0].scan_for_bss(bssid, freq=2412)
962 hapd.set("ext_mgmt_frame_handling", "1")
963 dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
964 scan_freq="2412", wait_connect=False)
965 ev = dev[0].wait_event(["SME: Trying to authenticate"])
966 if ev is None:
967 raise Exception("No authentication attempt seen")
968 dev[0].dump_monitor()
969
970 for i in range(0, 10):
971 req = hapd.mgmt_rx()
972 if req is None:
973 raise Exception("MGMT RX wait timed out (commit)")
974 if req['subtype'] == 11:
975 break
976 req = None
977 if not req:
978 raise Exception("Authentication frame (commit) not received")
979
980 hapd.dump_monitor()
981 resp = {}
982 resp['fc'] = req['fc']
983 resp['da'] = req['sa']
984 resp['sa'] = req['da']
985 resp['bssid'] = req['bssid']
986 resp['payload'] = binascii.unhexlify("030001004c0013")
987 hapd.mgmt_tx(resp)
988
989 ev = dev[0].wait_event(["SME: Trying to authenticate"])
990 if ev is None:
991 raise Exception("No authentication attempt seen")
992 dev[0].dump_monitor()
993
994 for i in range(0, 10):
995 req = hapd.mgmt_rx()
996 if req is None:
997 raise Exception("MGMT RX wait timed out (commit) (2)")
998 if req['subtype'] == 11:
999 break
1000 req = None
1001 if not req:
1002 raise Exception("Authentication frame (commit) not received (2)")
1003
1004 hapd.dump_monitor()
1005 resp = {}
1006 resp['fc'] = req['fc']
1007 resp['da'] = req['sa']
1008 resp['sa'] = req['da']
1009 resp['bssid'] = req['bssid']
1010 resp['payload'] = binascii.unhexlify("030001000100")
1011 hapd.mgmt_tx(resp)
1012
1013 ev = dev[0].wait_event(["SME: Trying to authenticate"])
1014 if ev is None:
1015 raise Exception("No authentication attempt seen")
1016 dev[0].dump_monitor()
1017
1018 dev[0].request("DISCONNECT")