test_erp.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. # EAP Re-authentication Protocol (ERP) tests
  2. # Copyright (c) 2014-2015, 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 logging
  8. logger = logging.getLogger()
  9. import os
  10. import time
  11. import hostapd
  12. from utils import HwsimSkip, alloc_fail, fail_test, wait_fail_trigger
  13. from test_ap_eap import int_eap_server_params
  14. from test_ap_psk import find_wpas_process, read_process_memory, verify_not_present, get_key_locations
  15. def check_erp_capa(dev):
  16. capab = dev.get_capability("erp")
  17. if not capab or 'ERP' not in capab:
  18. raise HwsimSkip("ERP not supported in the build")
  19. def test_erp_initiate_reauth_start(dev, apdev):
  20. """Authenticator sending EAP-Initiate/Re-auth-Start, but ERP disabled on peer"""
  21. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  22. params['erp_send_reauth_start'] = '1'
  23. params['erp_domain'] = 'example.com'
  24. hapd = hostapd.add_ap(apdev[0], params)
  25. dev[0].request("ERP_FLUSH")
  26. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  27. eap="PAX", identity="pax.user@example.com",
  28. password_hex="0123456789abcdef0123456789abcdef",
  29. scan_freq="2412")
  30. def test_erp_enabled_on_server(dev, apdev):
  31. """ERP enabled on internal EAP server, but disabled on peer"""
  32. params = int_eap_server_params()
  33. params['erp_send_reauth_start'] = '1'
  34. params['erp_domain'] = 'example.com'
  35. params['eap_server_erp'] = '1'
  36. hapd = hostapd.add_ap(apdev[0], params)
  37. dev[0].request("ERP_FLUSH")
  38. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  39. eap="PAX", identity="pax.user@example.com",
  40. password_hex="0123456789abcdef0123456789abcdef",
  41. scan_freq="2412")
  42. def test_erp(dev, apdev):
  43. """ERP enabled on server and peer"""
  44. check_erp_capa(dev[0])
  45. params = int_eap_server_params()
  46. params['erp_send_reauth_start'] = '1'
  47. params['erp_domain'] = 'example.com'
  48. params['eap_server_erp'] = '1'
  49. params['disable_pmksa_caching'] = '1'
  50. hapd = hostapd.add_ap(apdev[0], params)
  51. dev[0].request("ERP_FLUSH")
  52. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  53. eap="PSK", identity="psk.user@example.com",
  54. password_hex="0123456789abcdef0123456789abcdef",
  55. erp="1", scan_freq="2412")
  56. for i in range(3):
  57. dev[0].request("DISCONNECT")
  58. dev[0].wait_disconnected(timeout=15)
  59. dev[0].request("RECONNECT")
  60. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  61. if ev is None:
  62. raise Exception("EAP success timed out")
  63. if "EAP re-authentication completed successfully" not in ev:
  64. raise Exception("Did not use ERP")
  65. dev[0].wait_connected(timeout=15, error="Reconnection timed out")
  66. def test_erp_server_no_match(dev, apdev):
  67. """ERP enabled on server and peer, but server has no key match"""
  68. check_erp_capa(dev[0])
  69. params = int_eap_server_params()
  70. params['erp_send_reauth_start'] = '1'
  71. params['erp_domain'] = 'example.com'
  72. params['eap_server_erp'] = '1'
  73. params['disable_pmksa_caching'] = '1'
  74. hapd = hostapd.add_ap(apdev[0], params)
  75. dev[0].request("ERP_FLUSH")
  76. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  77. eap="PSK", identity="psk.user@example.com",
  78. password_hex="0123456789abcdef0123456789abcdef",
  79. erp="1", scan_freq="2412")
  80. dev[0].request("DISCONNECT")
  81. dev[0].wait_disconnected(timeout=15)
  82. hapd.request("ERP_FLUSH")
  83. dev[0].request("RECONNECT")
  84. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS",
  85. "CTRL-EVENT-EAP-FAILURE"], timeout=15)
  86. if ev is None:
  87. raise Exception("EAP result timed out")
  88. if "CTRL-EVENT-EAP-SUCCESS" in ev:
  89. raise Exception("Unexpected EAP success")
  90. dev[0].request("DISCONNECT")
  91. dev[0].select_network(id)
  92. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  93. if ev is None:
  94. raise Exception("EAP success timed out")
  95. if "EAP re-authentication completed successfully" in ev:
  96. raise Exception("Unexpected use of ERP")
  97. dev[0].wait_connected(timeout=15, error="Reconnection timed out")
  98. def start_erp_as(apdev, erp_domain="example.com", msk_dump=None):
  99. params = { "ssid": "as", "beacon_int": "2000",
  100. "radius_server_clients": "auth_serv/radius_clients.conf",
  101. "radius_server_auth_port": '18128',
  102. "eap_server": "1",
  103. "eap_user_file": "auth_serv/eap_user.conf",
  104. "ca_cert": "auth_serv/ca.pem",
  105. "server_cert": "auth_serv/server.pem",
  106. "private_key": "auth_serv/server.key",
  107. "eap_sim_db": "unix:/tmp/hlr_auc_gw.sock",
  108. "dh_file": "auth_serv/dh.conf",
  109. "pac_opaque_encr_key": "000102030405060708090a0b0c0d0e0f",
  110. "eap_fast_a_id": "101112131415161718191a1b1c1d1e1f",
  111. "eap_fast_a_id_info": "test server",
  112. "eap_server_erp": "1",
  113. "erp_domain": erp_domain }
  114. if msk_dump:
  115. params["dump_msk_file"] = msk_dump
  116. return hostapd.add_ap(apdev, params)
  117. def test_erp_radius(dev, apdev):
  118. """ERP enabled on RADIUS server and peer"""
  119. check_erp_capa(dev[0])
  120. start_erp_as(apdev[1])
  121. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  122. params['auth_server_port'] = "18128"
  123. params['erp_send_reauth_start'] = '1'
  124. params['erp_domain'] = 'example.com'
  125. params['disable_pmksa_caching'] = '1'
  126. hapd = hostapd.add_ap(apdev[0], params)
  127. dev[0].request("ERP_FLUSH")
  128. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  129. eap="PSK", identity="psk.user@example.com",
  130. password_hex="0123456789abcdef0123456789abcdef",
  131. erp="1", scan_freq="2412")
  132. for i in range(3):
  133. dev[0].request("DISCONNECT")
  134. dev[0].wait_disconnected(timeout=15)
  135. dev[0].request("RECONNECT")
  136. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  137. if ev is None:
  138. raise Exception("EAP success timed out")
  139. if "EAP re-authentication completed successfully" not in ev:
  140. raise Exception("Did not use ERP")
  141. dev[0].wait_connected(timeout=15, error="Reconnection timed out")
  142. def erp_test(dev, hapd, **kwargs):
  143. res = dev.get_capability("eap")
  144. if kwargs['eap'] not in res:
  145. logger.info("Skip ERP test with %s due to missing support" % kwargs['eap'])
  146. return
  147. hapd.dump_monitor()
  148. dev.dump_monitor()
  149. dev.request("ERP_FLUSH")
  150. id = dev.connect("test-wpa2-eap", key_mgmt="WPA-EAP", erp="1",
  151. scan_freq="2412", **kwargs)
  152. dev.request("DISCONNECT")
  153. dev.wait_disconnected(timeout=15)
  154. hapd.dump_monitor()
  155. dev.request("RECONNECT")
  156. ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  157. if ev is None:
  158. raise Exception("EAP success timed out")
  159. if "EAP re-authentication completed successfully" not in ev:
  160. raise Exception("Did not use ERP")
  161. dev.wait_connected(timeout=15, error="Reconnection timed out")
  162. ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
  163. if ev is None:
  164. raise Exception("No connection event received from hostapd")
  165. dev.request("DISCONNECT")
  166. def test_erp_radius_eap_methods(dev, apdev):
  167. """ERP enabled on RADIUS server and peer"""
  168. check_erp_capa(dev[0])
  169. eap_methods = dev[0].get_capability("eap")
  170. start_erp_as(apdev[1])
  171. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  172. params['auth_server_port'] = "18128"
  173. params['erp_send_reauth_start'] = '1'
  174. params['erp_domain'] = 'example.com'
  175. params['disable_pmksa_caching'] = '1'
  176. hapd = hostapd.add_ap(apdev[0], params)
  177. erp_test(dev[0], hapd, eap="AKA", identity="0232010000000000@example.com",
  178. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  179. erp_test(dev[0], hapd, eap="AKA'", identity="6555444333222111@example.com",
  180. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  181. erp_test(dev[0], hapd, eap="EKE", identity="erp-eke@example.com",
  182. password="hello")
  183. if "FAST" in eap_methods:
  184. erp_test(dev[0], hapd, eap="FAST", identity="erp-fast@example.com",
  185. password="password", ca_cert="auth_serv/ca.pem",
  186. phase2="auth=GTC",
  187. phase1="fast_provisioning=2",
  188. pac_file="blob://fast_pac_auth_erp")
  189. erp_test(dev[0], hapd, eap="GPSK", identity="erp-gpsk@example.com",
  190. password="abcdefghijklmnop0123456789abcdef")
  191. erp_test(dev[0], hapd, eap="IKEV2", identity="erp-ikev2@example.com",
  192. password="password")
  193. erp_test(dev[0], hapd, eap="PAX", identity="erp-pax@example.com",
  194. password_hex="0123456789abcdef0123456789abcdef")
  195. # TODO: PEAP (EMSK)
  196. #if "MSCHAPV2" in eap_methods:
  197. # erp_test(dev[0], hapd, eap="PEAP", identity="erp-peap@example.com",
  198. # password="password", ca_cert="auth_serv/ca.pem",
  199. # phase2="auth=MSCHAPV2")
  200. erp_test(dev[0], hapd, eap="PSK", identity="erp-psk@example.com",
  201. password_hex="0123456789abcdef0123456789abcdef")
  202. if "PWD" in eap_methods:
  203. erp_test(dev[0], hapd, eap="PWD", identity="erp-pwd@example.com",
  204. password="secret password")
  205. erp_test(dev[0], hapd, eap="SAKE", identity="erp-sake@example.com",
  206. password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
  207. erp_test(dev[0], hapd, eap="SIM", identity="1232010000000000@example.com",
  208. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  209. erp_test(dev[0], hapd, eap="TLS", identity="erp-tls@example.com",
  210. ca_cert="auth_serv/ca.pem", client_cert="auth_serv/user.pem",
  211. private_key="auth_serv/user.key")
  212. erp_test(dev[0], hapd, eap="TTLS", identity="erp-ttls@example.com",
  213. password="password", ca_cert="auth_serv/ca.pem", phase2="auth=PAP")
  214. def test_erp_key_lifetime_in_memory(dev, apdev, params):
  215. """ERP and key lifetime in memory"""
  216. check_erp_capa(dev[0])
  217. p = int_eap_server_params()
  218. p['erp_send_reauth_start'] = '1'
  219. p['erp_domain'] = 'example.com'
  220. p['eap_server_erp'] = '1'
  221. p['disable_pmksa_caching'] = '1'
  222. hapd = hostapd.add_ap(apdev[0], p)
  223. password = "63d2d21ac3c09ed567ee004a34490f1d16e7fa5835edf17ddba70a63f1a90a25"
  224. pid = find_wpas_process(dev[0])
  225. dev[0].request("ERP_FLUSH")
  226. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  227. identity="pap-secret@example.com", password=password,
  228. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  229. erp="1", scan_freq="2412")
  230. # The decrypted copy of GTK is freed only after the CTRL-EVENT-CONNECTED
  231. # event has been delivered, so verify that wpa_supplicant has returned to
  232. # eloop before reading process memory.
  233. time.sleep(1)
  234. dev[0].ping()
  235. buf = read_process_memory(pid, password)
  236. dev[0].request("DISCONNECT")
  237. dev[0].wait_disconnected(timeout=15)
  238. dev[0].relog()
  239. msk = None
  240. emsk = None
  241. rRK = None
  242. rIK = None
  243. pmk = None
  244. ptk = None
  245. gtk = None
  246. with open(os.path.join(params['logdir'], 'log0'), 'r') as f:
  247. for l in f.readlines():
  248. if "EAP-TTLS: Derived key - hexdump" in l:
  249. val = l.strip().split(':')[3].replace(' ', '')
  250. msk = binascii.unhexlify(val)
  251. if "EAP-TTLS: Derived EMSK - hexdump" in l:
  252. val = l.strip().split(':')[3].replace(' ', '')
  253. emsk = binascii.unhexlify(val)
  254. if "EAP: ERP rRK - hexdump" in l:
  255. val = l.strip().split(':')[3].replace(' ', '')
  256. rRK = binascii.unhexlify(val)
  257. if "EAP: ERP rIK - hexdump" in l:
  258. val = l.strip().split(':')[3].replace(' ', '')
  259. rIK = binascii.unhexlify(val)
  260. if "WPA: PMK - hexdump" in l:
  261. val = l.strip().split(':')[3].replace(' ', '')
  262. pmk = binascii.unhexlify(val)
  263. if "WPA: PTK - hexdump" in l:
  264. val = l.strip().split(':')[3].replace(' ', '')
  265. ptk = binascii.unhexlify(val)
  266. if "WPA: Group Key - hexdump" in l:
  267. val = l.strip().split(':')[3].replace(' ', '')
  268. gtk = binascii.unhexlify(val)
  269. if not msk or not emsk or not rIK or not rRK or not pmk or not ptk or not gtk:
  270. raise Exception("Could not find keys from debug log")
  271. if len(gtk) != 16:
  272. raise Exception("Unexpected GTK length")
  273. kck = ptk[0:16]
  274. kek = ptk[16:32]
  275. tk = ptk[32:48]
  276. fname = os.path.join(params['logdir'],
  277. 'erp_key_lifetime_in_memory.memctx-')
  278. logger.info("Checking keys in memory while associated")
  279. get_key_locations(buf, password, "Password")
  280. get_key_locations(buf, pmk, "PMK")
  281. get_key_locations(buf, msk, "MSK")
  282. get_key_locations(buf, emsk, "EMSK")
  283. get_key_locations(buf, rRK, "rRK")
  284. get_key_locations(buf, rIK, "rIK")
  285. if password not in buf:
  286. raise HwsimSkip("Password not found while associated")
  287. if pmk not in buf:
  288. raise HwsimSkip("PMK not found while associated")
  289. if kck not in buf:
  290. raise Exception("KCK not found while associated")
  291. if kek not in buf:
  292. raise Exception("KEK not found while associated")
  293. #if tk in buf:
  294. # raise Exception("TK found from memory")
  295. logger.info("Checking keys in memory after disassociation")
  296. buf = read_process_memory(pid, password)
  297. # Note: Password is still present in network configuration
  298. # Note: PMK is in EAP fast re-auth data
  299. get_key_locations(buf, password, "Password")
  300. get_key_locations(buf, pmk, "PMK")
  301. get_key_locations(buf, msk, "MSK")
  302. get_key_locations(buf, emsk, "EMSK")
  303. get_key_locations(buf, rRK, "rRK")
  304. get_key_locations(buf, rIK, "rIK")
  305. verify_not_present(buf, kck, fname, "KCK")
  306. verify_not_present(buf, kek, fname, "KEK")
  307. verify_not_present(buf, tk, fname, "TK")
  308. if gtk in buf:
  309. get_key_locations(buf, gtk, "GTK")
  310. verify_not_present(buf, gtk, fname, "GTK")
  311. dev[0].request("RECONNECT")
  312. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  313. if ev is None:
  314. raise Exception("EAP success timed out")
  315. if "EAP re-authentication completed successfully" not in ev:
  316. raise Exception("Did not use ERP")
  317. dev[0].wait_connected(timeout=15, error="Reconnection timed out")
  318. dev[0].request("DISCONNECT")
  319. dev[0].wait_disconnected(timeout=15)
  320. dev[0].relog()
  321. pmk = None
  322. ptk = None
  323. gtk = None
  324. with open(os.path.join(params['logdir'], 'log0'), 'r') as f:
  325. for l in f.readlines():
  326. if "WPA: PMK - hexdump" in l:
  327. val = l.strip().split(':')[3].replace(' ', '')
  328. pmk = binascii.unhexlify(val)
  329. if "WPA: PTK - hexdump" in l:
  330. val = l.strip().split(':')[3].replace(' ', '')
  331. ptk = binascii.unhexlify(val)
  332. if "WPA: GTK in EAPOL-Key - hexdump" in l:
  333. val = l.strip().split(':')[3].replace(' ', '')
  334. gtk = binascii.unhexlify(val)
  335. if not pmk or not ptk or not gtk:
  336. raise Exception("Could not find keys from debug log")
  337. kck = ptk[0:16]
  338. kek = ptk[16:32]
  339. tk = ptk[32:48]
  340. logger.info("Checking keys in memory after ERP and disassociation")
  341. buf = read_process_memory(pid, password)
  342. # Note: Password is still present in network configuration
  343. get_key_locations(buf, password, "Password")
  344. get_key_locations(buf, pmk, "PMK")
  345. get_key_locations(buf, msk, "MSK")
  346. get_key_locations(buf, emsk, "EMSK")
  347. get_key_locations(buf, rRK, "rRK")
  348. get_key_locations(buf, rIK, "rIK")
  349. verify_not_present(buf, kck, fname, "KCK")
  350. verify_not_present(buf, kek, fname, "KEK")
  351. verify_not_present(buf, tk, fname, "TK")
  352. verify_not_present(buf, gtk, fname, "GTK")
  353. dev[0].request("REMOVE_NETWORK all")
  354. logger.info("Checking keys in memory after network profile removal")
  355. buf = read_process_memory(pid, password)
  356. # Note: rRK and rIK are still in memory
  357. get_key_locations(buf, password, "Password")
  358. get_key_locations(buf, pmk, "PMK")
  359. get_key_locations(buf, msk, "MSK")
  360. get_key_locations(buf, emsk, "EMSK")
  361. get_key_locations(buf, rRK, "rRK")
  362. get_key_locations(buf, rIK, "rIK")
  363. verify_not_present(buf, password, fname, "password")
  364. verify_not_present(buf, pmk, fname, "PMK")
  365. verify_not_present(buf, kck, fname, "KCK")
  366. verify_not_present(buf, kek, fname, "KEK")
  367. verify_not_present(buf, tk, fname, "TK")
  368. verify_not_present(buf, gtk, fname, "GTK")
  369. verify_not_present(buf, msk, fname, "MSK")
  370. verify_not_present(buf, emsk, fname, "EMSK")
  371. dev[0].request("ERP_FLUSH")
  372. logger.info("Checking keys in memory after ERP_FLUSH")
  373. buf = read_process_memory(pid, password)
  374. get_key_locations(buf, rRK, "rRK")
  375. get_key_locations(buf, rIK, "rIK")
  376. verify_not_present(buf, rRK, fname, "rRK")
  377. verify_not_present(buf, rIK, fname, "rIK")
  378. def test_erp_anonymous_identity(dev, apdev):
  379. """ERP and anonymous identity"""
  380. check_erp_capa(dev[0])
  381. params = int_eap_server_params()
  382. params['erp_send_reauth_start'] = '1'
  383. params['erp_domain'] = 'example.com'
  384. params['eap_server_erp'] = '1'
  385. params['disable_pmksa_caching'] = '1'
  386. hapd = hostapd.add_ap(apdev[0], params)
  387. dev[0].request("ERP_FLUSH")
  388. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  389. identity="erp-ttls",
  390. anonymous_identity="anonymous@example.com",
  391. password="password",
  392. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  393. erp="1", scan_freq="2412")
  394. for i in range(3):
  395. dev[0].request("DISCONNECT")
  396. dev[0].wait_disconnected(timeout=15)
  397. dev[0].request("RECONNECT")
  398. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  399. if ev is None:
  400. raise Exception("EAP success timed out")
  401. if "EAP re-authentication completed successfully" not in ev:
  402. raise Exception("Did not use ERP")
  403. dev[0].wait_connected(timeout=15, error="Reconnection timed out")
  404. def test_erp_home_realm_oom(dev, apdev):
  405. """ERP and home realm OOM"""
  406. check_erp_capa(dev[0])
  407. params = int_eap_server_params()
  408. params['erp_send_reauth_start'] = '1'
  409. params['erp_domain'] = 'example.com'
  410. params['eap_server_erp'] = '1'
  411. params['disable_pmksa_caching'] = '1'
  412. hapd = hostapd.add_ap(apdev[0], params)
  413. for count in range(1, 3):
  414. with alloc_fail(dev[0], count, "eap_get_realm"):
  415. dev[0].request("ERP_FLUSH")
  416. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  417. identity="erp-ttls@example.com",
  418. anonymous_identity="anonymous@example.com",
  419. password="password",
  420. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  421. erp="1", scan_freq="2412", wait_connect=False)
  422. dev[0].wait_connected(timeout=10)
  423. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  424. dev[0].request("REMOVE_NETWORK all")
  425. dev[0].wait_disconnected()
  426. for count in range(1, 3):
  427. with alloc_fail(dev[0], count, "eap_get_realm"):
  428. dev[0].request("ERP_FLUSH")
  429. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  430. identity="erp-ttls",
  431. anonymous_identity="anonymous@example.com",
  432. password="password",
  433. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  434. erp="1", scan_freq="2412", wait_connect=False)
  435. dev[0].wait_connected(timeout=10)
  436. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  437. dev[0].request("REMOVE_NETWORK all")
  438. dev[0].wait_disconnected()
  439. for count in range(1, 3):
  440. dev[0].request("ERP_FLUSH")
  441. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  442. identity="erp-ttls@example.com",
  443. anonymous_identity="anonymous@example.com",
  444. password="password",
  445. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  446. erp="1", scan_freq="2412", wait_connect=False)
  447. dev[0].wait_connected(timeout=10)
  448. if range > 1:
  449. continue
  450. with alloc_fail(dev[0], count, "eap_get_realm"):
  451. dev[0].request("DISCONNECT")
  452. dev[0].wait_disconnected(timeout=15)
  453. dev[0].request("RECONNECT")
  454. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  455. dev[0].request("REMOVE_NETWORK all")
  456. dev[0].wait_disconnected()
  457. def test_erp_local_errors(dev, apdev):
  458. """ERP and local error cases"""
  459. check_erp_capa(dev[0])
  460. params = int_eap_server_params()
  461. params['erp_send_reauth_start'] = '1'
  462. params['erp_domain'] = 'example.com'
  463. params['eap_server_erp'] = '1'
  464. params['disable_pmksa_caching'] = '1'
  465. hapd = hostapd.add_ap(apdev[0], params)
  466. dev[0].request("ERP_FLUSH")
  467. with alloc_fail(dev[0], 1, "eap_peer_erp_init"):
  468. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  469. identity="erp-ttls@example.com",
  470. anonymous_identity="anonymous@example.com",
  471. password="password",
  472. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  473. erp="1", scan_freq="2412")
  474. dev[0].request("REMOVE_NETWORK all")
  475. dev[0].wait_disconnected()
  476. for count in range(1, 6):
  477. dev[0].request("ERP_FLUSH")
  478. with fail_test(dev[0], count, "hmac_sha256_kdf;eap_peer_erp_init"):
  479. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  480. identity="erp-ttls@example.com",
  481. anonymous_identity="anonymous@example.com",
  482. password="password",
  483. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  484. erp="1", scan_freq="2412")
  485. dev[0].request("REMOVE_NETWORK all")
  486. dev[0].wait_disconnected()
  487. dev[0].request("ERP_FLUSH")
  488. with alloc_fail(dev[0], 1, "eap_msg_alloc;eap_peer_erp_reauth_start"):
  489. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  490. identity="erp-ttls@example.com",
  491. anonymous_identity="anonymous@example.com",
  492. password="password",
  493. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  494. erp="1", scan_freq="2412")
  495. dev[0].request("DISCONNECT")
  496. dev[0].wait_disconnected(timeout=15)
  497. dev[0].request("RECONNECT")
  498. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  499. dev[0].request("REMOVE_NETWORK all")
  500. dev[0].wait_disconnected()
  501. dev[0].request("ERP_FLUSH")
  502. with fail_test(dev[0], 1, "hmac_sha256;eap_peer_erp_reauth_start"):
  503. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  504. identity="erp-ttls@example.com",
  505. anonymous_identity="anonymous@example.com",
  506. password="password",
  507. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  508. erp="1", scan_freq="2412")
  509. dev[0].request("DISCONNECT")
  510. dev[0].wait_disconnected(timeout=15)
  511. dev[0].request("RECONNECT")
  512. wait_fail_trigger(dev[0], "GET_FAIL")
  513. dev[0].request("REMOVE_NETWORK all")
  514. dev[0].wait_disconnected()
  515. dev[0].request("ERP_FLUSH")
  516. with fail_test(dev[0], 1, "hmac_sha256;eap_peer_finish"):
  517. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  518. identity="erp-ttls@example.com",
  519. anonymous_identity="anonymous@example.com",
  520. password="password",
  521. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  522. erp="1", scan_freq="2412")
  523. dev[0].request("DISCONNECT")
  524. dev[0].wait_disconnected(timeout=15)
  525. dev[0].request("RECONNECT")
  526. wait_fail_trigger(dev[0], "GET_FAIL")
  527. dev[0].request("REMOVE_NETWORK all")
  528. dev[0].wait_disconnected()
  529. dev[0].request("ERP_FLUSH")
  530. with alloc_fail(dev[0], 1, "eap_peer_erp_init"):
  531. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  532. identity="erp-ttls@example.com",
  533. anonymous_identity="anonymous@example.com",
  534. password="password",
  535. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  536. erp="1", scan_freq="2412")
  537. dev[0].request("DISCONNECT")
  538. dev[0].wait_disconnected(timeout=15)
  539. dev[0].request("ERP_FLUSH")
  540. with alloc_fail(dev[0], 1, "eap_peer_finish"):
  541. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  542. identity="erp-ttls@example.com",
  543. anonymous_identity="anonymous@example.com",
  544. password="password",
  545. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  546. erp="1", scan_freq="2412")
  547. dev[0].request("DISCONNECT")
  548. dev[0].wait_disconnected(timeout=15)
  549. dev[0].request("RECONNECT")
  550. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  551. dev[0].request("REMOVE_NETWORK all")
  552. dev[0].wait_disconnected()
  553. dev[0].request("ERP_FLUSH")
  554. with fail_test(dev[0], 1, "hmac_sha256_kdf;eap_peer_finish"):
  555. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  556. identity="erp-ttls@example.com",
  557. anonymous_identity="anonymous@example.com",
  558. password="password",
  559. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  560. erp="1", scan_freq="2412")
  561. dev[0].request("DISCONNECT")
  562. dev[0].wait_disconnected(timeout=15)
  563. dev[0].request("RECONNECT")
  564. wait_fail_trigger(dev[0], "GET_FAIL")
  565. dev[0].request("REMOVE_NETWORK all")
  566. dev[0].wait_disconnected()