test_erp.py 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 start_erp_as(apdev):
  64. params = { "ssid": "as", "beacon_int": "2000",
  65. "radius_server_clients": "auth_serv/radius_clients.conf",
  66. "radius_server_auth_port": '18128',
  67. "eap_server": "1",
  68. "eap_user_file": "auth_serv/eap_user.conf",
  69. "ca_cert": "auth_serv/ca.pem",
  70. "server_cert": "auth_serv/server.pem",
  71. "private_key": "auth_serv/server.key",
  72. "eap_sim_db": "unix:/tmp/hlr_auc_gw.sock",
  73. "dh_file": "auth_serv/dh.conf",
  74. "pac_opaque_encr_key": "000102030405060708090a0b0c0d0e0f",
  75. "eap_fast_a_id": "101112131415161718191a1b1c1d1e1f",
  76. "eap_fast_a_id_info": "test server",
  77. "eap_server_erp": "1",
  78. "erp_domain": "example.com" }
  79. hostapd.add_ap(apdev['ifname'], params)
  80. def test_erp_radius(dev, apdev):
  81. """ERP enabled on RADIUS server and peer"""
  82. capab = dev[0].get_capability("erp")
  83. if not capab or 'ERP' not in capab:
  84. return "skip"
  85. start_erp_as(apdev[1])
  86. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  87. params['auth_server_port'] = "18128"
  88. params['erp_send_reauth_start'] = '1'
  89. params['erp_domain'] = 'example.com'
  90. params['disable_pmksa_caching'] = '1'
  91. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  92. dev[0].request("ERP_FLUSH")
  93. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  94. eap="PSK", identity="psk.user@example.com",
  95. password_hex="0123456789abcdef0123456789abcdef",
  96. erp="1", scan_freq="2412")
  97. for i in range(3):
  98. dev[0].request("DISCONNECT")
  99. ev = dev[0].wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=15)
  100. if ev is None:
  101. raise Exception("Disconnection timed out")
  102. dev[0].request("RECONNECT")
  103. ev = dev[0].wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  104. if ev is None:
  105. raise Exception("EAP success timed out")
  106. if "EAP re-authentication completed successfully" not in ev:
  107. raise Exception("Did not use ERP")
  108. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  109. if ev is None:
  110. raise Exception("Reconnection timed out")
  111. def erp_test(dev, hapd, **kwargs):
  112. hapd.dump_monitor()
  113. dev.dump_monitor()
  114. dev.request("ERP_FLUSH")
  115. id = dev.connect("test-wpa2-eap", key_mgmt="WPA-EAP", erp="1",
  116. scan_freq="2412", **kwargs)
  117. dev.request("DISCONNECT")
  118. ev = dev.wait_event(["CTRL-EVENT-DISCONNECTED"], timeout=15)
  119. if ev is None:
  120. raise Exception("Disconnection timed out")
  121. hapd.dump_monitor()
  122. dev.request("RECONNECT")
  123. ev = dev.wait_event(["CTRL-EVENT-EAP-SUCCESS"], timeout=15)
  124. if ev is None:
  125. raise Exception("EAP success timed out")
  126. if "EAP re-authentication completed successfully" not in ev:
  127. raise Exception("Did not use ERP")
  128. ev = dev.wait_event(["CTRL-EVENT-CONNECTED"], timeout=15)
  129. if ev is None:
  130. raise Exception("Reconnection timed out")
  131. ev = hapd.wait_event([ "AP-STA-CONNECTED" ], timeout=5)
  132. if ev is None:
  133. raise Exception("No connection event received from hostapd")
  134. dev.request("DISCONNECT")
  135. def test_erp_radius_eap_methods(dev, apdev):
  136. """ERP enabled on RADIUS server and peer"""
  137. capab = dev[0].get_capability("erp")
  138. if not capab or 'ERP' not in capab:
  139. return "skip"
  140. start_erp_as(apdev[1])
  141. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  142. params['auth_server_port'] = "18128"
  143. params['erp_send_reauth_start'] = '1'
  144. params['erp_domain'] = 'example.com'
  145. params['disable_pmksa_caching'] = '1'
  146. hapd = hostapd.add_ap(apdev[0]['ifname'], params)
  147. erp_test(dev[0], hapd, eap="AKA", identity="0232010000000000@example.com",
  148. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581:000000000123")
  149. erp_test(dev[0], hapd, eap="AKA'", identity="6555444333222111@example.com",
  150. password="5122250214c33e723a5dd523fc145fc0:981d464c7c52eb6e5036234984ad0bcf:000000000123")
  151. # TODO: EKE getSession
  152. #erp_test(dev[0], hapd, eap="EKE", identity="erp-eke@example.com",
  153. # password="hello")
  154. erp_test(dev[0], hapd, eap="FAST", identity="erp-fast@example.com",
  155. password="password", ca_cert="auth_serv/ca.pem", phase2="auth=GTC",
  156. phase1="fast_provisioning=2", pac_file="blob://fast_pac_auth_erp")
  157. erp_test(dev[0], hapd, eap="GPSK", identity="erp-gpsk@example.com",
  158. password="abcdefghijklmnop0123456789abcdef")
  159. erp_test(dev[0], hapd, eap="PAX", identity="erp-pax@example.com",
  160. password_hex="0123456789abcdef0123456789abcdef")
  161. # TODO: PEAP (EMSK)
  162. #erp_test(dev[0], hapd, eap="PEAP", identity="erp-peap@example.com",
  163. # password="password", ca_cert="auth_serv/ca.pem",
  164. # phase2="auth=MSCHAPV2")
  165. erp_test(dev[0], hapd, eap="PSK", identity="erp-psk@example.com",
  166. password_hex="0123456789abcdef0123456789abcdef")
  167. erp_test(dev[0], hapd, eap="PWD", identity="erp-pwd@example.com",
  168. password="secret password")
  169. erp_test(dev[0], hapd, eap="SAKE", identity="erp-sake@example.com",
  170. password_hex="0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef")
  171. erp_test(dev[0], hapd, eap="SIM", identity="1232010000000000@example.com",
  172. password="90dca4eda45b53cf0f12d7c9c3bc6a89:cb9cccc4b9258e6dca4760379fb82581")
  173. erp_test(dev[0], hapd, eap="TLS", identity="erp-tls@example.com",
  174. ca_cert="auth_serv/ca.pem", client_cert="auth_serv/user.pem",
  175. private_key="auth_serv/user.key")
  176. erp_test(dev[0], hapd, eap="TTLS", identity="erp-ttls@example.com",
  177. password="password", ca_cert="auth_serv/ca.pem", phase2="auth=PAP")