test_sae.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. # Test cases for SAE
  2. # Copyright (c) 2013-2014, 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. import binascii
  7. import os
  8. import time
  9. import subprocess
  10. import logging
  11. logger = logging.getLogger()
  12. import hwsim_utils
  13. import hostapd
  14. from utils import HwsimSkip, alloc_fail
  15. from test_ap_psk import find_wpas_process, read_process_memory, verify_not_present, get_key_locations
  16. def test_sae(dev, apdev):
  17. """SAE with default group"""
  18. if "SAE" not in dev[0].get_capability("auth_alg"):
  19. raise HwsimSkip("SAE not supported")
  20. params = hostapd.wpa2_params(ssid="test-sae",
  21. passphrase="12345678")
  22. params['wpa_key_mgmt'] = 'SAE'
  23. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  24. key_mgmt = hapd.get_config()['key_mgmt']
  25. if key_mgmt.split(' ')[0] != "SAE":
  26. raise Exception("Unexpected GET_CONFIG(key_mgmt): " + key_mgmt)
  27. dev[0].request("SET sae_groups ")
  28. id = dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
  29. scan_freq="2412")
  30. if dev[0].get_status_field('sae_group') != '19':
  31. raise Exception("Expected default SAE group not used")
  32. bss = dev[0].get_bss(apdev[0]['bssid'])
  33. if 'flags' not in bss:
  34. raise Exception("Could not get BSS flags from BSS table")
  35. if "[WPA2-SAE-CCMP]" not in bss['flags']:
  36. raise Exception("Unexpected BSS flags: " + bss['flags'])
  37. def test_sae_pmksa_caching(dev, apdev):
  38. """SAE and PMKSA caching"""
  39. if "SAE" not in dev[0].get_capability("auth_alg"):
  40. raise HwsimSkip("SAE not supported")
  41. params = hostapd.wpa2_params(ssid="test-sae",
  42. passphrase="12345678")
  43. params['wpa_key_mgmt'] = 'SAE'
  44. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  45. dev[0].request("SET sae_groups ")
  46. dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
  47. scan_freq="2412")
  48. ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
  49. if ev is None:
  50. raise Exception("No connection event received from hostapd")
  51. dev[0].request("DISCONNECT")
  52. dev[0].wait_disconnected()
  53. dev[0].request("RECONNECT")
  54. dev[0].wait_connected(timeout=15, error="Reconnect timed out")
  55. if dev[0].get_status_field('sae_group') is not None:
  56. raise Exception("SAE group claimed to have been used")
  57. def test_sae_pmksa_caching_disabled(dev, apdev):
  58. """SAE and PMKSA caching disabled"""
  59. if "SAE" not in dev[0].get_capability("auth_alg"):
  60. raise HwsimSkip("SAE not supported")
  61. params = hostapd.wpa2_params(ssid="test-sae",
  62. passphrase="12345678")
  63. params['wpa_key_mgmt'] = 'SAE'
  64. params['disable_pmksa_caching'] = '1'
  65. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  66. dev[0].request("SET sae_groups ")
  67. dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
  68. scan_freq="2412")
  69. ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
  70. if ev is None:
  71. raise Exception("No connection event received from hostapd")
  72. dev[0].request("DISCONNECT")
  73. dev[0].wait_disconnected()
  74. dev[0].request("RECONNECT")
  75. dev[0].wait_connected(timeout=15, error="Reconnect timed out")
  76. if dev[0].get_status_field('sae_group') != '19':
  77. raise Exception("Expected default SAE group not used")
  78. def test_sae_groups(dev, apdev):
  79. """SAE with all supported groups"""
  80. if "SAE" not in dev[0].get_capability("auth_alg"):
  81. raise HwsimSkip("SAE not supported")
  82. # This would be the full list of supported groups, but groups 14-16
  83. # (2048-4096 bit MODP) are a bit too slow on some VMs and can result in
  84. # hitting mac80211 authentication timeout, so skip them for now.
  85. #sae_groups = [ 19, 25, 26, 20, 21, 2, 5, 14, 15, 16, 22, 23, 24 ]
  86. sae_groups = [ 19, 25, 26, 20, 21, 2, 5, 22, 23, 24 ]
  87. groups = [str(g) for g in sae_groups]
  88. params = hostapd.wpa2_params(ssid="test-sae-groups",
  89. passphrase="12345678")
  90. params['wpa_key_mgmt'] = 'SAE'
  91. params['sae_groups'] = ' '.join(groups)
  92. hostapd.add_ap(apdev[0]['ifname'], params)
  93. for g in groups:
  94. logger.info("Testing SAE group " + g)
  95. dev[0].request("SET sae_groups " + g)
  96. id = dev[0].connect("test-sae-groups", psk="12345678", key_mgmt="SAE",
  97. scan_freq="2412")
  98. if dev[0].get_status_field('sae_group') != g:
  99. raise Exception("Expected SAE group not used")
  100. dev[0].remove_network(id)
  101. def test_sae_group_nego(dev, apdev):
  102. """SAE group negotiation"""
  103. if "SAE" not in dev[0].get_capability("auth_alg"):
  104. raise HwsimSkip("SAE not supported")
  105. params = hostapd.wpa2_params(ssid="test-sae-group-nego",
  106. passphrase="12345678")
  107. params['wpa_key_mgmt'] = 'SAE'
  108. params['sae_groups'] = '19'
  109. hostapd.add_ap(apdev[0]['ifname'], params)
  110. dev[0].request("SET sae_groups 25 26 20 19")
  111. dev[0].connect("test-sae-group-nego", psk="12345678", key_mgmt="SAE",
  112. scan_freq="2412")
  113. if dev[0].get_status_field('sae_group') != '19':
  114. raise Exception("Expected SAE group not used")
  115. def test_sae_anti_clogging(dev, apdev):
  116. """SAE anti clogging"""
  117. if "SAE" not in dev[0].get_capability("auth_alg"):
  118. raise HwsimSkip("SAE not supported")
  119. params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
  120. params['wpa_key_mgmt'] = 'SAE'
  121. params['sae_anti_clogging_threshold'] = '1'
  122. hostapd.add_ap(apdev[0]['ifname'], params)
  123. dev[0].request("SET sae_groups ")
  124. dev[1].request("SET sae_groups ")
  125. id = {}
  126. for i in range(0, 2):
  127. dev[i].scan(freq="2412")
  128. id[i] = dev[i].connect("test-sae", psk="12345678", key_mgmt="SAE",
  129. scan_freq="2412", only_add_network=True)
  130. for i in range(0, 2):
  131. dev[i].select_network(id[i])
  132. for i in range(0, 2):
  133. dev[i].wait_connected(timeout=10)
  134. def test_sae_forced_anti_clogging(dev, apdev):
  135. """SAE anti clogging (forced)"""
  136. if "SAE" not in dev[0].get_capability("auth_alg"):
  137. raise HwsimSkip("SAE not supported")
  138. params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
  139. params['wpa_key_mgmt'] = 'SAE WPA-PSK'
  140. params['sae_anti_clogging_threshold'] = '0'
  141. hostapd.add_ap(apdev[0]['ifname'], params)
  142. dev[2].connect("test-sae", psk="12345678", scan_freq="2412")
  143. for i in range(0, 2):
  144. dev[i].request("SET sae_groups ")
  145. dev[i].connect("test-sae", psk="12345678", key_mgmt="SAE",
  146. scan_freq="2412")
  147. def test_sae_mixed(dev, apdev):
  148. """Mixed SAE and non-SAE network"""
  149. if "SAE" not in dev[0].get_capability("auth_alg"):
  150. raise HwsimSkip("SAE not supported")
  151. params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
  152. params['wpa_key_mgmt'] = 'SAE WPA-PSK'
  153. params['sae_anti_clogging_threshold'] = '0'
  154. hostapd.add_ap(apdev[0]['ifname'], params)
  155. dev[2].connect("test-sae", psk="12345678", scan_freq="2412")
  156. for i in range(0, 2):
  157. dev[i].request("SET sae_groups ")
  158. dev[i].connect("test-sae", psk="12345678", key_mgmt="SAE",
  159. scan_freq="2412")
  160. def test_sae_missing_password(dev, apdev):
  161. """SAE and missing password"""
  162. if "SAE" not in dev[0].get_capability("auth_alg"):
  163. raise HwsimSkip("SAE not supported")
  164. params = hostapd.wpa2_params(ssid="test-sae",
  165. passphrase="12345678")
  166. params['wpa_key_mgmt'] = 'SAE'
  167. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  168. dev[0].request("SET sae_groups ")
  169. id = dev[0].connect("test-sae",
  170. raw_psk="46b4a73b8a951ad53ebd2e0afdb9c5483257edd4c21d12b7710759da70945858",
  171. key_mgmt="SAE", scan_freq="2412", wait_connect=False)
  172. ev = dev[0].wait_event(['CTRL-EVENT-SSID-TEMP-DISABLED'], timeout=10)
  173. if ev is None:
  174. raise Exception("Invalid network not temporarily disabled")
  175. def test_sae_key_lifetime_in_memory(dev, apdev, params):
  176. """SAE and key lifetime in memory"""
  177. if "SAE" not in dev[0].get_capability("auth_alg"):
  178. raise HwsimSkip("SAE not supported")
  179. password = "5ad144a7c1f5a5503baa6fa01dabc15b1843e8c01662d78d16b70b5cd23cf8b"
  180. p = hostapd.wpa2_params(ssid="test-sae", passphrase=password)
  181. p['wpa_key_mgmt'] = 'SAE'
  182. hapd = hostapd.add_ap(apdev[0]['ifname'], p)
  183. pid = find_wpas_process(dev[0])
  184. dev[0].request("SET sae_groups ")
  185. id = dev[0].connect("test-sae", psk=password, key_mgmt="SAE",
  186. scan_freq="2412")
  187. time.sleep(1)
  188. buf = read_process_memory(pid, password)
  189. dev[0].request("DISCONNECT")
  190. dev[0].wait_disconnected()
  191. dev[0].relog()
  192. sae_k = None
  193. sae_keyseed = None
  194. sae_kck = None
  195. pmk = None
  196. ptk = None
  197. gtk = None
  198. with open(os.path.join(params['logdir'], 'log0'), 'r') as f:
  199. for l in f.readlines():
  200. if "SAE: k - hexdump" in l:
  201. val = l.strip().split(':')[3].replace(' ', '')
  202. sae_k = binascii.unhexlify(val)
  203. if "SAE: keyseed - hexdump" in l:
  204. val = l.strip().split(':')[3].replace(' ', '')
  205. sae_keyseed = binascii.unhexlify(val)
  206. if "SAE: KCK - hexdump" in l:
  207. val = l.strip().split(':')[3].replace(' ', '')
  208. sae_kck = binascii.unhexlify(val)
  209. if "SAE: PMK - hexdump" in l:
  210. val = l.strip().split(':')[3].replace(' ', '')
  211. pmk = binascii.unhexlify(val)
  212. if "WPA: PTK - hexdump" in l:
  213. val = l.strip().split(':')[3].replace(' ', '')
  214. ptk = binascii.unhexlify(val)
  215. if "WPA: Group Key - hexdump" in l:
  216. val = l.strip().split(':')[3].replace(' ', '')
  217. gtk = binascii.unhexlify(val)
  218. if not sae_k or not sae_keyseed or not sae_kck or not pmk or not ptk or not gtk:
  219. raise Exception("Could not find keys from debug log")
  220. if len(gtk) != 16:
  221. raise Exception("Unexpected GTK length")
  222. kck = ptk[0:16]
  223. kek = ptk[16:32]
  224. tk = ptk[32:48]
  225. fname = os.path.join(params['logdir'],
  226. 'sae_key_lifetime_in_memory.memctx-')
  227. logger.info("Checking keys in memory while associated")
  228. get_key_locations(buf, password, "Password")
  229. get_key_locations(buf, pmk, "PMK")
  230. if password not in buf:
  231. raise HwsimSkip("Password not found while associated")
  232. if pmk not in buf:
  233. raise HwsimSkip("PMK not found while associated")
  234. if kck not in buf:
  235. raise Exception("KCK not found while associated")
  236. if kek not in buf:
  237. raise Exception("KEK not found while associated")
  238. if tk in buf:
  239. raise Exception("TK found from memory")
  240. if gtk in buf:
  241. raise Exception("GTK found from memory")
  242. verify_not_present(buf, sae_k, fname, "SAE(k)")
  243. verify_not_present(buf, sae_keyseed, fname, "SAE(keyseed)")
  244. verify_not_present(buf, sae_kck, fname, "SAE(KCK)")
  245. logger.info("Checking keys in memory after disassociation")
  246. buf = read_process_memory(pid, password)
  247. # Note: Password is still present in network configuration
  248. # Note: PMK is in PMKSA cache
  249. get_key_locations(buf, password, "Password")
  250. get_key_locations(buf, pmk, "PMK")
  251. verify_not_present(buf, kck, fname, "KCK")
  252. verify_not_present(buf, kek, fname, "KEK")
  253. verify_not_present(buf, tk, fname, "TK")
  254. verify_not_present(buf, gtk, fname, "GTK")
  255. verify_not_present(buf, sae_k, fname, "SAE(k)")
  256. verify_not_present(buf, sae_keyseed, fname, "SAE(keyseed)")
  257. verify_not_present(buf, sae_kck, fname, "SAE(KCK)")
  258. dev[0].request("PMKSA_FLUSH")
  259. logger.info("Checking keys in memory after PMKSA cache flush")
  260. buf = read_process_memory(pid, password)
  261. get_key_locations(buf, password, "Password")
  262. get_key_locations(buf, pmk, "PMK")
  263. verify_not_present(buf, pmk, fname, "PMK")
  264. dev[0].request("REMOVE_NETWORK all")
  265. logger.info("Checking keys in memory after network profile removal")
  266. buf = read_process_memory(pid, password)
  267. get_key_locations(buf, password, "Password")
  268. get_key_locations(buf, pmk, "PMK")
  269. verify_not_present(buf, password, fname, "password")
  270. verify_not_present(buf, pmk, fname, "PMK")
  271. verify_not_present(buf, kck, fname, "KCK")
  272. verify_not_present(buf, kek, fname, "KEK")
  273. verify_not_present(buf, tk, fname, "TK")
  274. verify_not_present(buf, gtk, fname, "GTK")
  275. verify_not_present(buf, sae_k, fname, "SAE(k)")
  276. verify_not_present(buf, sae_keyseed, fname, "SAE(keyseed)")
  277. verify_not_present(buf, sae_kck, fname, "SAE(KCK)")
  278. def test_sae_oom_wpas(dev, apdev):
  279. """SAE and OOM in wpa_supplicant"""
  280. if "SAE" not in dev[0].get_capability("auth_alg"):
  281. raise HwsimSkip("SAE not supported")
  282. params = hostapd.wpa2_params(ssid="test-sae",
  283. passphrase="12345678")
  284. params['wpa_key_mgmt'] = 'SAE'
  285. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  286. dev[0].request("SET sae_groups 25")
  287. with alloc_fail(dev[0], 1, "sae_set_group"):
  288. dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
  289. scan_freq="2412")
  290. dev[0].request("REMOVE_NETWORK all")
  291. dev[0].request("SET sae_groups ")
  292. with alloc_fail(dev[0], 2, "sae_set_group"):
  293. dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
  294. scan_freq="2412")
  295. dev[0].request("REMOVE_NETWORK all")
  296. def test_sae_proto_ecc(dev, apdev):
  297. """SAE protocol testing (ECC)"""
  298. if "SAE" not in dev[0].get_capability("auth_alg"):
  299. raise HwsimSkip("SAE not supported")
  300. params = hostapd.wpa2_params(ssid="test-sae",
  301. passphrase="12345678")
  302. params['wpa_key_mgmt'] = 'SAE'
  303. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  304. bssid = apdev[0]['bssid']
  305. dev[0].request("SET sae_groups 19")
  306. tests = [ ("Confirm mismatch",
  307. "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
  308. "0000800edebc3f260dc1fe7e0b20888af2b8a3316252ec37388a8504e25b73dc4240"),
  309. ("Commit without even full cyclic group field",
  310. "13",
  311. None),
  312. ("Too short commit",
  313. "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02",
  314. None),
  315. ("Invalid commit scalar (0)",
  316. "1300" + "0000000000000000000000000000000000000000000000000000000000000000" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
  317. None),
  318. ("Invalid commit scalar (> r)",
  319. "1300" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
  320. None),
  321. ("Commit element not on curve",
  322. "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728d0000000000000000000000000000000000000000000000000000000000000000",
  323. None),
  324. ("Invalid commit element (y coordinate > P)",
  325. "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
  326. None),
  327. ("Invalid commit element (x coordinate > P)",
  328. "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
  329. None),
  330. ("Different group in commit",
  331. "1400" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
  332. None),
  333. ("Too short confirm",
  334. "1300" + "033d3635b39666ed427fd4a3e7d37acec2810afeaf1687f746a14163ff0e6d03" + "559cb8928db4ce4e3cbd6555e837591995e5ebe503ef36b503d9ca519d63728dd3c7c676b8e8081831b6bc3a64bdf136061a7de175e17d1965bfa41983ed02f8",
  335. "0000800edebc3f260dc1fe7e0b20888af2b8a3316252ec37388a8504e25b73dc42")]
  336. for (note, commit, confirm) in tests:
  337. logger.info(note)
  338. dev[0].scan_for_bss(bssid, freq=2412)
  339. hapd.set("ext_mgmt_frame_handling", "1")
  340. dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
  341. scan_freq="2412", wait_connect=False)
  342. logger.info("Commit")
  343. for i in range(0, 10):
  344. req = hapd.mgmt_rx()
  345. if req is None:
  346. raise Exception("MGMT RX wait timed out (commit)")
  347. if req['subtype'] == 11:
  348. break
  349. req = None
  350. if not req:
  351. raise Exception("Authentication frame (commit) not received")
  352. hapd.dump_monitor()
  353. resp = {}
  354. resp['fc'] = req['fc']
  355. resp['da'] = req['sa']
  356. resp['sa'] = req['da']
  357. resp['bssid'] = req['bssid']
  358. resp['payload'] = binascii.unhexlify("030001000000" + commit)
  359. hapd.mgmt_tx(resp)
  360. if confirm:
  361. logger.info("Confirm")
  362. for i in range(0, 10):
  363. req = hapd.mgmt_rx()
  364. if req is None:
  365. raise Exception("MGMT RX wait timed out (confirm)")
  366. if req['subtype'] == 11:
  367. break
  368. req = None
  369. if not req:
  370. raise Exception("Authentication frame (confirm) not received")
  371. hapd.dump_monitor()
  372. resp = {}
  373. resp['fc'] = req['fc']
  374. resp['da'] = req['sa']
  375. resp['sa'] = req['da']
  376. resp['bssid'] = req['bssid']
  377. resp['payload'] = binascii.unhexlify("030002000000" + confirm)
  378. hapd.mgmt_tx(resp)
  379. time.sleep(0.1)
  380. dev[0].request("REMOVE_NETWORK all")
  381. hapd.set("ext_mgmt_frame_handling", "0")
  382. hapd.dump_monitor()
  383. def test_sae_proto_ffc(dev, apdev):
  384. """SAE protocol testing (FFC)"""
  385. if "SAE" not in dev[0].get_capability("auth_alg"):
  386. raise HwsimSkip("SAE not supported")
  387. params = hostapd.wpa2_params(ssid="test-sae",
  388. passphrase="12345678")
  389. params['wpa_key_mgmt'] = 'SAE'
  390. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  391. bssid = apdev[0]['bssid']
  392. dev[0].request("SET sae_groups 2")
  393. tests = [ ("Confirm mismatch",
  394. "0200" + "0c70519d874e3e4930a917cc5e17ea7a26028211159f217bab28b8d6c56691805e49f03249b2c6e22c7c9f86b30e04ccad2deedd5e5108ae07b737c00001c59cd0eb08b1dfc7f1b06a1542e2b6601a963c066e0c65940983a03917ae57a101ce84b5cbbc76ff33ebb990aac2e54aa0f0ab6ec0a58113d927683502b2cb2347d2" + "a8c00117493cdffa5dd671e934bc9cb1a69f39e25e9dd9cd9afd3aea2441a0f5491211c7ba50a753563f9ce943b043557cb71193b28e86ed9544f4289c471bf91b70af5c018cf4663e004165b0fd0bc1d8f3f78adf42eee92bcbc55246fd3ee9f107ab965dc7d4986f23eb71d616ebfe6bfe0a6c1ac5dc1718acee17c9a17486",
  395. "0000f3116a9731f1259622e3eb55d4b3b50ba16f8c5f5565b28e609b180c51460251"),
  396. ("Too short commit",
  397. "0200" + "0c70519d874e3e4930a917cc5e17ea7a26028211159f217bab28b8d6c56691805e49f03249b2c6e22c7c9f86b30e04ccad2deedd5e5108ae07b737c00001c59cd0eb08b1dfc7f1b06a1542e2b6601a963c066e0c65940983a03917ae57a101ce84b5cbbc76ff33ebb990aac2e54aa0f0ab6ec0a58113d927683502b2cb2347d2" + "a8c00117493cdffa5dd671e934bc9cb1a69f39e25e9dd9cd9afd3aea2441a0f5491211c7ba50a753563f9ce943b043557cb71193b28e86ed9544f4289c471bf91b70af5c018cf4663e004165b0fd0bc1d8f3f78adf42eee92bcbc55246fd3ee9f107ab965dc7d4986f23eb71d616ebfe6bfe0a6c1ac5dc1718acee17c9a174",
  398. None),
  399. ("Invalid element (0) in commit",
  400. "0200" + "0c70519d874e3e4930a917cc5e17ea7a26028211159f217bab28b8d6c56691805e49f03249b2c6e22c7c9f86b30e04ccad2deedd5e5108ae07b737c00001c59cd0eb08b1dfc7f1b06a1542e2b6601a963c066e0c65940983a03917ae57a101ce84b5cbbc76ff33ebb990aac2e54aa0f0ab6ec0a58113d927683502b2cb2347d2" + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
  401. None),
  402. ("Invalid element (1) in commit",
  403. "0200" + "0c70519d874e3e4930a917cc5e17ea7a26028211159f217bab28b8d6c56691805e49f03249b2c6e22c7c9f86b30e04ccad2deedd5e5108ae07b737c00001c59cd0eb08b1dfc7f1b06a1542e2b6601a963c066e0c65940983a03917ae57a101ce84b5cbbc76ff33ebb990aac2e54aa0f0ab6ec0a58113d927683502b2cb2347d2" + "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001",
  404. None),
  405. ("Invalid element (> P) in commit",
  406. "0200" + "0c70519d874e3e4930a917cc5e17ea7a26028211159f217bab28b8d6c56691805e49f03249b2c6e22c7c9f86b30e04ccad2deedd5e5108ae07b737c00001c59cd0eb08b1dfc7f1b06a1542e2b6601a963c066e0c65940983a03917ae57a101ce84b5cbbc76ff33ebb990aac2e54aa0f0ab6ec0a58113d927683502b2cb2347d2" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
  407. None) ]
  408. for (note, commit, confirm) in tests:
  409. logger.info(note)
  410. dev[0].scan_for_bss(bssid, freq=2412)
  411. hapd.set("ext_mgmt_frame_handling", "1")
  412. dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE",
  413. scan_freq="2412", wait_connect=False)
  414. logger.info("Commit")
  415. for i in range(0, 10):
  416. req = hapd.mgmt_rx()
  417. if req is None:
  418. raise Exception("MGMT RX wait timed out (commit)")
  419. if req['subtype'] == 11:
  420. break
  421. req = None
  422. if not req:
  423. raise Exception("Authentication frame (commit) not received")
  424. hapd.dump_monitor()
  425. resp = {}
  426. resp['fc'] = req['fc']
  427. resp['da'] = req['sa']
  428. resp['sa'] = req['da']
  429. resp['bssid'] = req['bssid']
  430. resp['payload'] = binascii.unhexlify("030001000000" + commit)
  431. hapd.mgmt_tx(resp)
  432. if confirm:
  433. logger.info("Confirm")
  434. for i in range(0, 10):
  435. req = hapd.mgmt_rx()
  436. if req is None:
  437. raise Exception("MGMT RX wait timed out (confirm)")
  438. if req['subtype'] == 11:
  439. break
  440. req = None
  441. if not req:
  442. raise Exception("Authentication frame (confirm) not received")
  443. hapd.dump_monitor()
  444. resp = {}
  445. resp['fc'] = req['fc']
  446. resp['da'] = req['sa']
  447. resp['sa'] = req['da']
  448. resp['bssid'] = req['bssid']
  449. resp['payload'] = binascii.unhexlify("030002000000" + confirm)
  450. hapd.mgmt_tx(resp)
  451. time.sleep(0.1)
  452. dev[0].request("REMOVE_NETWORK all")
  453. hapd.set("ext_mgmt_frame_handling", "0")
  454. hapd.dump_monitor()
  455. def test_sae_no_ffc_by_default(dev, apdev):
  456. """SAE and default groups rejecting FFC"""
  457. if "SAE" not in dev[0].get_capability("auth_alg"):
  458. raise HwsimSkip("SAE not supported")
  459. params = hostapd.wpa2_params(ssid="test-sae", passphrase="12345678")
  460. params['wpa_key_mgmt'] = 'SAE'
  461. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  462. dev[0].request("SET sae_groups 5")
  463. dev[0].connect("test-sae", psk="12345678", key_mgmt="SAE", scan_freq="2412",
  464. wait_connect=False)
  465. ev = dev[0].wait_event(["SME: Trying to authenticate"], timeout=3)
  466. if ev is None:
  467. raise Exception("Did not try to authenticate")
  468. ev = dev[0].wait_event(["SME: Trying to authenticate"], timeout=3)
  469. if ev is None:
  470. raise Exception("Did not try to authenticate (2)")
  471. dev[0].request("REMOVE_NETWORK all")
  472. def sae_reflection_attack(apdev, dev, group):
  473. if "SAE" not in dev.get_capability("auth_alg"):
  474. raise HwsimSkip("SAE not supported")
  475. params = hostapd.wpa2_params(ssid="test-sae",
  476. passphrase="no-knowledge-of-passphrase")
  477. params['wpa_key_mgmt'] = 'SAE'
  478. hapd = hostapd.add_ap(apdev['ifname'], params)
  479. bssid = apdev['bssid']
  480. dev.scan_for_bss(bssid, freq=2412)
  481. hapd.set("ext_mgmt_frame_handling", "1")
  482. dev.request("SET sae_groups %d" % group)
  483. dev.connect("test-sae", psk="reflection-attack", key_mgmt="SAE",
  484. scan_freq="2412", wait_connect=False)
  485. # Commit
  486. for i in range(0, 10):
  487. req = hapd.mgmt_rx()
  488. if req is None:
  489. raise Exception("MGMT RX wait timed out")
  490. if req['subtype'] == 11:
  491. break
  492. req = None
  493. if not req:
  494. raise Exception("Authentication frame not received")
  495. resp = {}
  496. resp['fc'] = req['fc']
  497. resp['da'] = req['sa']
  498. resp['sa'] = req['da']
  499. resp['bssid'] = req['bssid']
  500. resp['payload'] = req['payload']
  501. hapd.mgmt_tx(resp)
  502. # Confirm
  503. req = hapd.mgmt_rx(timeout=0.5)
  504. if req is not None:
  505. if req['subtype'] == 11:
  506. raise Exception("Unexpected Authentication frame seen")
  507. def test_sae_reflection_attack_ecc(dev, apdev):
  508. """SAE reflection attack (ECC)"""
  509. sae_reflection_attack(apdev[0], dev[0], 19)
  510. def test_sae_reflection_attack_ffc(dev, apdev):
  511. """SAE reflection attack (FFC)"""
  512. sae_reflection_attack(apdev[0], dev[0], 5)