test_erp.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  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. if gtk in buf:
  296. get_key_locations(buf, gtk, "GTK")
  297. raise Exception("GTK found from memory")
  298. logger.info("Checking keys in memory after disassociation")
  299. buf = read_process_memory(pid, password)
  300. # Note: Password is still present in network configuration
  301. # Note: PMK is in EAP fast re-auth data
  302. get_key_locations(buf, password, "Password")
  303. get_key_locations(buf, pmk, "PMK")
  304. get_key_locations(buf, msk, "MSK")
  305. get_key_locations(buf, emsk, "EMSK")
  306. get_key_locations(buf, rRK, "rRK")
  307. get_key_locations(buf, rIK, "rIK")
  308. verify_not_present(buf, kck, fname, "KCK")
  309. verify_not_present(buf, kek, fname, "KEK")
  310. verify_not_present(buf, tk, fname, "TK")
  311. verify_not_present(buf, gtk, fname, "GTK")
  312. dev[0].request("RECONNECT")
  313. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  314. if ev is None:
  315. raise Exception("EAP success timed out")
  316. if "EAP re-authentication completed successfully" not in ev:
  317. raise Exception("Did not use ERP")
  318. dev[0].wait_connected(timeout=15, error="Reconnection timed out")
  319. dev[0].request("DISCONNECT")
  320. dev[0].wait_disconnected(timeout=15)
  321. dev[0].relog()
  322. pmk = None
  323. ptk = None
  324. gtk = None
  325. with open(os.path.join(params['logdir'], 'log0'), 'r') as f:
  326. for l in f.readlines():
  327. if "WPA: PMK - hexdump" in l:
  328. val = l.strip().split(':')[3].replace(' ', '')
  329. pmk = binascii.unhexlify(val)
  330. if "WPA: PTK - hexdump" in l:
  331. val = l.strip().split(':')[3].replace(' ', '')
  332. ptk = binascii.unhexlify(val)
  333. if "WPA: GTK in EAPOL-Key - hexdump" in l:
  334. val = l.strip().split(':')[3].replace(' ', '')
  335. gtk = binascii.unhexlify(val)
  336. if not pmk or not ptk or not gtk:
  337. raise Exception("Could not find keys from debug log")
  338. kck = ptk[0:16]
  339. kek = ptk[16:32]
  340. tk = ptk[32:48]
  341. logger.info("Checking keys in memory after ERP and disassociation")
  342. buf = read_process_memory(pid, password)
  343. # Note: Password is still present in network configuration
  344. get_key_locations(buf, password, "Password")
  345. get_key_locations(buf, pmk, "PMK")
  346. get_key_locations(buf, msk, "MSK")
  347. get_key_locations(buf, emsk, "EMSK")
  348. get_key_locations(buf, rRK, "rRK")
  349. get_key_locations(buf, rIK, "rIK")
  350. verify_not_present(buf, kck, fname, "KCK")
  351. verify_not_present(buf, kek, fname, "KEK")
  352. verify_not_present(buf, tk, fname, "TK")
  353. verify_not_present(buf, gtk, fname, "GTK")
  354. dev[0].request("REMOVE_NETWORK all")
  355. logger.info("Checking keys in memory after network profile removal")
  356. buf = read_process_memory(pid, password)
  357. # Note: rRK and rIK are still in memory
  358. get_key_locations(buf, password, "Password")
  359. get_key_locations(buf, pmk, "PMK")
  360. get_key_locations(buf, msk, "MSK")
  361. get_key_locations(buf, emsk, "EMSK")
  362. get_key_locations(buf, rRK, "rRK")
  363. get_key_locations(buf, rIK, "rIK")
  364. verify_not_present(buf, password, fname, "password")
  365. verify_not_present(buf, pmk, fname, "PMK")
  366. verify_not_present(buf, kck, fname, "KCK")
  367. verify_not_present(buf, kek, fname, "KEK")
  368. verify_not_present(buf, tk, fname, "TK")
  369. verify_not_present(buf, gtk, fname, "GTK")
  370. verify_not_present(buf, msk, fname, "MSK")
  371. verify_not_present(buf, emsk, fname, "EMSK")
  372. dev[0].request("ERP_FLUSH")
  373. logger.info("Checking keys in memory after ERP_FLUSH")
  374. buf = read_process_memory(pid, password)
  375. get_key_locations(buf, rRK, "rRK")
  376. get_key_locations(buf, rIK, "rIK")
  377. verify_not_present(buf, rRK, fname, "rRK")
  378. verify_not_present(buf, rIK, fname, "rIK")
  379. def test_erp_anonymous_identity(dev, apdev):
  380. """ERP and anonymous identity"""
  381. check_erp_capa(dev[0])
  382. params = int_eap_server_params()
  383. params['erp_send_reauth_start'] = '1'
  384. params['erp_domain'] = 'example.com'
  385. params['eap_server_erp'] = '1'
  386. params['disable_pmksa_caching'] = '1'
  387. hapd = hostapd.add_ap(apdev[0], params)
  388. dev[0].request("ERP_FLUSH")
  389. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  390. identity="erp-ttls",
  391. anonymous_identity="anonymous@example.com",
  392. password="password",
  393. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  394. erp="1", scan_freq="2412")
  395. for i in range(3):
  396. dev[0].request("DISCONNECT")
  397. dev[0].wait_disconnected(timeout=15)
  398. dev[0].request("RECONNECT")
  399. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  400. if ev is None:
  401. raise Exception("EAP success timed out")
  402. if "EAP re-authentication completed successfully" not in ev:
  403. raise Exception("Did not use ERP")
  404. dev[0].wait_connected(timeout=15, error="Reconnection timed out")
  405. def test_erp_home_realm_oom(dev, apdev):
  406. """ERP and home realm OOM"""
  407. check_erp_capa(dev[0])
  408. params = int_eap_server_params()
  409. params['erp_send_reauth_start'] = '1'
  410. params['erp_domain'] = 'example.com'
  411. params['eap_server_erp'] = '1'
  412. params['disable_pmksa_caching'] = '1'
  413. hapd = hostapd.add_ap(apdev[0], params)
  414. for count in range(1, 3):
  415. with alloc_fail(dev[0], count, "eap_get_realm"):
  416. dev[0].request("ERP_FLUSH")
  417. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  418. identity="erp-ttls@example.com",
  419. anonymous_identity="anonymous@example.com",
  420. password="password",
  421. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  422. erp="1", scan_freq="2412", wait_connect=False)
  423. dev[0].wait_connected(timeout=10)
  424. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  425. dev[0].request("REMOVE_NETWORK all")
  426. dev[0].wait_disconnected()
  427. for count in range(1, 3):
  428. with alloc_fail(dev[0], count, "eap_get_realm"):
  429. dev[0].request("ERP_FLUSH")
  430. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  431. identity="erp-ttls",
  432. anonymous_identity="anonymous@example.com",
  433. password="password",
  434. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  435. erp="1", scan_freq="2412", wait_connect=False)
  436. dev[0].wait_connected(timeout=10)
  437. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  438. dev[0].request("REMOVE_NETWORK all")
  439. dev[0].wait_disconnected()
  440. for count in range(1, 3):
  441. dev[0].request("ERP_FLUSH")
  442. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  443. identity="erp-ttls@example.com",
  444. anonymous_identity="anonymous@example.com",
  445. password="password",
  446. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  447. erp="1", scan_freq="2412", wait_connect=False)
  448. dev[0].wait_connected(timeout=10)
  449. if range > 1:
  450. continue
  451. with alloc_fail(dev[0], count, "eap_get_realm"):
  452. dev[0].request("DISCONNECT")
  453. dev[0].wait_disconnected(timeout=15)
  454. dev[0].request("RECONNECT")
  455. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  456. dev[0].request("REMOVE_NETWORK all")
  457. dev[0].wait_disconnected()
  458. def test_erp_local_errors(dev, apdev):
  459. """ERP and local error cases"""
  460. check_erp_capa(dev[0])
  461. params = int_eap_server_params()
  462. params['erp_send_reauth_start'] = '1'
  463. params['erp_domain'] = 'example.com'
  464. params['eap_server_erp'] = '1'
  465. params['disable_pmksa_caching'] = '1'
  466. hapd = hostapd.add_ap(apdev[0], params)
  467. dev[0].request("ERP_FLUSH")
  468. with alloc_fail(dev[0], 1, "eap_peer_erp_init"):
  469. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  470. identity="erp-ttls@example.com",
  471. anonymous_identity="anonymous@example.com",
  472. password="password",
  473. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  474. erp="1", scan_freq="2412")
  475. dev[0].request("REMOVE_NETWORK all")
  476. dev[0].wait_disconnected()
  477. for count in range(1, 6):
  478. dev[0].request("ERP_FLUSH")
  479. with fail_test(dev[0], count, "hmac_sha256_kdf;eap_peer_erp_init"):
  480. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  481. identity="erp-ttls@example.com",
  482. anonymous_identity="anonymous@example.com",
  483. password="password",
  484. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  485. erp="1", scan_freq="2412")
  486. dev[0].request("REMOVE_NETWORK all")
  487. dev[0].wait_disconnected()
  488. dev[0].request("ERP_FLUSH")
  489. with alloc_fail(dev[0], 1, "eap_msg_alloc;eap_peer_erp_reauth_start"):
  490. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  491. identity="erp-ttls@example.com",
  492. anonymous_identity="anonymous@example.com",
  493. password="password",
  494. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  495. erp="1", scan_freq="2412")
  496. dev[0].request("DISCONNECT")
  497. dev[0].wait_disconnected(timeout=15)
  498. dev[0].request("RECONNECT")
  499. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  500. dev[0].request("REMOVE_NETWORK all")
  501. dev[0].wait_disconnected()
  502. dev[0].request("ERP_FLUSH")
  503. with fail_test(dev[0], 1, "hmac_sha256;eap_peer_erp_reauth_start"):
  504. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  505. identity="erp-ttls@example.com",
  506. anonymous_identity="anonymous@example.com",
  507. password="password",
  508. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  509. erp="1", scan_freq="2412")
  510. dev[0].request("DISCONNECT")
  511. dev[0].wait_disconnected(timeout=15)
  512. dev[0].request("RECONNECT")
  513. wait_fail_trigger(dev[0], "GET_FAIL")
  514. dev[0].request("REMOVE_NETWORK all")
  515. dev[0].wait_disconnected()
  516. dev[0].request("ERP_FLUSH")
  517. with fail_test(dev[0], 1, "hmac_sha256;eap_peer_finish"):
  518. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  519. identity="erp-ttls@example.com",
  520. anonymous_identity="anonymous@example.com",
  521. password="password",
  522. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  523. erp="1", scan_freq="2412")
  524. dev[0].request("DISCONNECT")
  525. dev[0].wait_disconnected(timeout=15)
  526. dev[0].request("RECONNECT")
  527. wait_fail_trigger(dev[0], "GET_FAIL")
  528. dev[0].request("REMOVE_NETWORK all")
  529. dev[0].wait_disconnected()
  530. dev[0].request("ERP_FLUSH")
  531. with alloc_fail(dev[0], 1, "eap_peer_erp_init"):
  532. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  533. identity="erp-ttls@example.com",
  534. anonymous_identity="anonymous@example.com",
  535. password="password",
  536. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  537. erp="1", scan_freq="2412")
  538. dev[0].request("DISCONNECT")
  539. dev[0].wait_disconnected(timeout=15)
  540. dev[0].request("ERP_FLUSH")
  541. with alloc_fail(dev[0], 1, "eap_peer_finish"):
  542. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  543. identity="erp-ttls@example.com",
  544. anonymous_identity="anonymous@example.com",
  545. password="password",
  546. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  547. erp="1", scan_freq="2412")
  548. dev[0].request("DISCONNECT")
  549. dev[0].wait_disconnected(timeout=15)
  550. dev[0].request("RECONNECT")
  551. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  552. dev[0].request("REMOVE_NETWORK all")
  553. dev[0].wait_disconnected()
  554. dev[0].request("ERP_FLUSH")
  555. with fail_test(dev[0], 1, "hmac_sha256_kdf;eap_peer_finish"):
  556. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP", eap="TTLS",
  557. identity="erp-ttls@example.com",
  558. anonymous_identity="anonymous@example.com",
  559. password="password",
  560. ca_cert="auth_serv/ca.pem", phase2="auth=PAP",
  561. erp="1", scan_freq="2412")
  562. dev[0].request("DISCONNECT")
  563. dev[0].wait_disconnected(timeout=15)
  564. dev[0].request("RECONNECT")
  565. wait_fail_trigger(dev[0], "GET_FAIL")
  566. dev[0].request("REMOVE_NETWORK all")
  567. dev[0].wait_disconnected()