test_erp.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. # EAP Re-authentication Protocol (ERP) tests
  2. # Copyright (c) 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 logging
  7. logger = logging.getLogger()
  8. import hostapd
  9. from test_ap_eap import int_eap_server_params
  10. def test_erp_initiate_reauth_start(dev, apdev):
  11. """Authenticator sending EAP-Initiate/Re-auth-Start, but ERP disabled on peer"""
  12. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  13. params['erp_send_reauth_start'] = '1'
  14. params['erp_domain'] = 'example.com'
  15. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  16. dev[0].request("ERP_FLUSH")
  17. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  18. eap="PAX", identity="pax.user@example.com",
  19. password_hex="0123456789abcdef0123456789abcdef",
  20. scan_freq="2412")
  21. def test_erp_enabled_on_server(dev, apdev):
  22. """ERP enabled on internal EAP server, but disabled on peer"""
  23. params = int_eap_server_params()
  24. params['erp_send_reauth_start'] = '1'
  25. params['erp_domain'] = 'example.com'
  26. params['eap_server_erp'] = '1'
  27. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  28. dev[0].request("ERP_FLUSH")
  29. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  30. eap="PAX", identity="pax.user@example.com",
  31. password_hex="0123456789abcdef0123456789abcdef",
  32. scan_freq="2412")
  33. def test_erp(dev, apdev):
  34. """ERP enabled on server and peer"""
  35. capab = dev[0].get_capability("erp")
  36. if not capab or 'ERP' not in capab:
  37. return "skip"
  38. params = int_eap_server_params()
  39. params['erp_send_reauth_start'] = '1'
  40. params['erp_domain'] = 'example.com'
  41. params['eap_server_erp'] = '1'
  42. params['disable_pmksa_caching'] = '1'
  43. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  44. dev[0].request("ERP_FLUSH")
  45. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  46. eap="PSK", identity="psk.user@example.com",
  47. password_hex="0123456789abcdef0123456789abcdef",
  48. erp="1", scan_freq="2412")
  49. for i in range(3):
  50. dev[0].request("DISCONNECT")
  51. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=15)
  52. if ev is None:
  53. raise Exception("Disconnection timed out")
  54. dev[0].request("RECONNECT")
  55. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  56. if ev is None:
  57. raise Exception("EAP success timed out")
  58. if "EAP re-authentication completed successfully" not in ev:
  59. raise Exception("Did not use ERP")
  60. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  61. if ev is None:
  62. raise Exception("Reconnection timed out")
  63. def test_erp_server_no_match(dev, apdev):
  64. """ERP enabled on server and peer, but server has no key match"""
  65. capab = dev[0].get_capability("erp")
  66. if not capab or 'ERP' not in capab:
  67. return "skip"
  68. params = int_eap_server_params()
  69. params['erp_send_reauth_start'] = '1'
  70. params['erp_domain'] = 'example.com'
  71. params['eap_server_erp'] = '1'
  72. params['disable_pmksa_caching'] = '1'
  73. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  74. dev[0].request("ERP_FLUSH")
  75. id = dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  76. eap="PSK", identity="psk.user@example.com",
  77. password_hex="0123456789abcdef0123456789abcdef",
  78. erp="1", scan_freq="2412")
  79. dev[0].request("DISCONNECT")
  80. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=15)
  81. if ev is None:
  82. raise Exception("Disconnection timed out")
  83. hapd.request("ERP_FLUSH")
  84. dev[0].request("RECONNECT")
  85. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS",
  86. "CTRL-EVENT-EAP-FAILURE"], timeout=15)
  87. if ev is None:
  88. raise Exception("EAP result timed out")
  89. if "CTRL-EVENT-EAP-SUCCESS" in ev:
  90. raise Exception("Unexpected EAP success")
  91. dev[0].request("DISCONNECT")
  92. dev[0].select_network(id)
  93. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  94. if ev is None:
  95. raise Exception("EAP success timed out")
  96. if "EAP re-authentication completed successfully" in ev:
  97. raise Exception("Unexpected use of ERP")
  98. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  99. if ev is None:
  100. raise Exception("Reconnection timed out")
  101. def start_erp_as(apdev):
  102. params = { "ssid": "as", "beacon_int": "2000",
  103. "radius_server_clients": "auth_serv/radius_clients.conf",
  104. "radius_server_auth_port": '18128',
  105. "eap_server": "1",
  106. "eap_user_file": "auth_serv/eap_user.conf",
  107. "ca_cert": "auth_serv/ca.pem",
  108. "server_cert": "auth_serv/server.pem",
  109. "private_key": "auth_serv/server.key",
  110. "eap_sim_db": "unix:/tmp/hlr_auc_gw.sock",
  111. "dh_file": "auth_serv/dh.conf",
  112. "pac_opaque_encr_key": "000102030405060708090a0b0c0d0e0f",
  113. "eap_fast_a_id": "101112131415161718191a1b1c1d1e1f",
  114. "eap_fast_a_id_info": "test server",
  115. "eap_server_erp": "1",
  116. "erp_domain": "example.com" }
  117. hostapd.add_ap(apdev['ifname'], params)
  118. def test_erp_radius(dev, apdev):
  119. """ERP enabled on RADIUS server and peer"""
  120. capab = dev[0].get_capability("erp")
  121. if not capab or 'ERP' not in capab:
  122. return "skip"
  123. start_erp_as(apdev[1])
  124. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  125. params['auth_server_port'] = "18128"
  126. params['erp_send_reauth_start'] = '1'
  127. params['erp_domain'] = 'example.com'
  128. params['disable_pmksa_caching'] = '1'
  129. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  130. dev[0].request("ERP_FLUSH")
  131. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  132. eap="PSK", identity="psk.user@example.com",
  133. password_hex="0123456789abcdef0123456789abcdef",
  134. erp="1", scan_freq="2412")
  135. for i in range(3):
  136. dev[0].request("DISCONNECT")
  137. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=15)
  138. if ev is None:
  139. raise Exception("Disconnection timed out")
  140. dev[0].request("RECONNECT")
  141. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  142. if ev is None:
  143. raise Exception("EAP success timed out")
  144. if "EAP re-authentication completed successfully" not in ev:
  145. raise Exception("Did not use ERP")
  146. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  147. if ev is None:
  148. raise Exception("Reconnection timed out")
  149. def erp_test(dev, hapd, **kwargs):
  150. hapd.dump_monitor()
  151. dev.dump_monitor()
  152. dev.request("ERP_FLUSH")
  153. id = dev.connect("test-wpa2-eap", key_mgmt="WPA-EAP", erp="1",
  154. scan_freq="2412", **kwargs)
  155. dev.request("DISCONNECT")
  156. ev = dev.wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=15)
  157. if ev is None:
  158. raise Exception("Disconnection timed out")
  159. hapd.dump_monitor()
  160. dev.request("RECONNECT")
  161. ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  162. if ev is None:
  163. raise Exception("EAP success timed out")
  164. if "EAP re-authentication completed successfully" not in ev:
  165. raise Exception("Did not use ERP")
  166. ev = dev.wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  167. if ev is None:
  168. raise Exception("Reconnection timed out")
  169. ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
  170. if ev is None:
  171. raise Exception("No connection event received from hostapd")
  172. dev.request("DISCONNECT")
  173. def test_erp_radius_eap_methods(dev, apdev):
  174. """ERP enabled on RADIUS server and peer"""
  175. capab = dev[0].get_capability("erp")
  176. if not capab or 'ERP' not in capab:
  177. return "skip"
  178. start_erp_as(apdev[1])
  179. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  180. params['auth_server_port'] = "18128"
  181. params['erp_send_reauth_start'] = '1'
  182. params['erp_domain'] = 'example.com'
  183. params['disable_pmksa_caching'] = '1'
  184. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  185. erp_test(dev[0], hapd, eap="AKA", identity="0232010000000000@example.com",
  186. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  187. erp_test(dev[0], hapd, eap="AKA'", identity="6555444333222111@example.com",
  188. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  189. # TODO: EKE getSession
  190. #erp_test(dev[0], hapd, eap="EKE", identity="erp-eke@example.com",
  191. # password="hello")
  192. erp_test(dev[0], hapd, eap="FAST", identity="erp-fast@example.com",
  193. password="password", ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  194. phase1="fast_provisioning=2", pac_file="blob://fast_pac_auth_erp")
  195. erp_test(dev[0], hapd, eap="GPSK", identity="erp-gpsk@example.com",
  196. password="abcdefghijklmnop0123456789abcdef")
  197. erp_test(dev[0], hapd, eap="PAX", identity="erp-pax@example.com",
  198. password_hex="0123456789abcdef0123456789abcdef")
  199. # TODO: PEAP (EMSK)
  200. #erp_test(dev[0], hapd, eap="PEAP", identity="erp-peap@example.com",
  201. # password="password", ca_cert="auth_serv/ca.pem",
  202. # phase2="auth=MSCHAPV2")
  203. erp_test(dev[0], hapd, eap="PSK", identity="erp-psk@example.com",
  204. password_hex="0123456789abcdef0123456789abcdef")
  205. erp_test(dev[0], hapd, eap="PWD", identity="erp-pwd@example.com",
  206. password="secret password")
  207. erp_test(dev[0], hapd, eap="SAKE", identity="erp-sake@example.com",
  208. password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
  209. erp_test(dev[0], hapd, eap="SIM", identity="1232010000000000@example.com",
  210. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  211. erp_test(dev[0], hapd, eap="TLS", identity="erp-tls@example.com",
  212. ca_cert="auth_serv/ca.pem", client_cert="auth_serv/user.pem",
  213. private_key="auth_serv/user.key")
  214. erp_test(dev[0], hapd, eap="TTLS", identity="erp-ttls@example.com",
  215. password="password", ca_cert="auth_serv/ca.pem", phase2="auth=PAP")