test_authsrv.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. # hostapd authentication server tests
  2. # Copyright (c) 2017, Jouni Malinen
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. import hostapd
  7. from utils import alloc_fail, fail_test, wait_fail_trigger
  8. def authsrv_params():
  9. params = { "ssid": "as", "beacon_int": "2000",
  10. "radius_server_clients": "auth_serv/radius_clients.conf",
  11. "radius_server_auth_port": '18128',
  12. "eap_server": "1",
  13. "eap_user_file": "auth_serv/eap_user.conf",
  14. "eap_sim_db": "unix:/tmp/hlr_auc_gw.sock",
  15. "ca_cert": "auth_serv/ca.pem",
  16. "server_cert": "auth_serv/server.pem",
  17. "private_key": "auth_serv/server.key",
  18. "eap_message": "hello" }
  19. return params;
  20. def test_authsrv_oom(dev, apdev):
  21. """Authentication server OOM"""
  22. params = authsrv_params()
  23. authsrv = hostapd.add_ap(apdev[1], params)
  24. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  25. params['auth_server_port'] = "18128"
  26. hapd = hostapd.add_ap(apdev[0], params)
  27. dev[0].scan_for_bss(hapd.own_addr(), 2412)
  28. with alloc_fail(authsrv, 1, "hostapd_radius_get_eap_user"):
  29. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  30. eap="TTLS", identity="user",
  31. anonymous_identity="ttls", password="password",
  32. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC",
  33. wait_connect=False, scan_freq="2412")
  34. ev = dev[0].wait_event(["CTRL-EVENT-EAP-FAILURE"], timeout=10)
  35. if ev is None:
  36. raise Exception("EAP failure not reported")
  37. dev[0].request("REMOVE_NETWORK all")
  38. dev[0].wait_disconnected()
  39. dev[0].dump_monitor()
  40. with alloc_fail(authsrv, 1, "srv_log"):
  41. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  42. eap="TTLS", identity="user",
  43. anonymous_identity="ttls", password="password",
  44. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC",
  45. scan_freq="2412")
  46. dev[0].request("REMOVE_NETWORK all")
  47. dev[0].wait_disconnected()
  48. dev[0].dump_monitor()
  49. with alloc_fail(authsrv, 1, "radius_server_new_session"):
  50. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  51. eap="TTLS", identity="user",
  52. anonymous_identity="ttls", password="password",
  53. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC",
  54. wait_connect=False, scan_freq="2412")
  55. dev[0].wait_disconnected()
  56. dev[0].request("REMOVE_NETWORK all")
  57. dev[0].dump_monitor()
  58. for count in range(1, 3):
  59. with alloc_fail(authsrv, count, "=radius_server_get_new_session"):
  60. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  61. eap="TTLS", identity="user",
  62. anonymous_identity="ttls", password="password",
  63. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC",
  64. wait_connect=False, scan_freq="2412")
  65. dev[0].wait_disconnected()
  66. dev[0].request("REMOVE_NETWORK all")
  67. dev[0].dump_monitor()
  68. with alloc_fail(authsrv, 1, "eap_server_sm_init"):
  69. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  70. eap="TTLS", identity="user",
  71. anonymous_identity="ttls", password="password",
  72. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC",
  73. wait_connect=False, scan_freq="2412")
  74. dev[0].wait_disconnected()
  75. dev[0].request("REMOVE_NETWORK all")
  76. dev[0].dump_monitor()
  77. tests = [ "radius_server_encapsulate_eap",
  78. "radius_server_receive_auth" ]
  79. for t in tests:
  80. with alloc_fail(authsrv, 1, t):
  81. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  82. eap="TTLS", identity="user",
  83. anonymous_identity="ttls", password="password",
  84. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC",
  85. wait_connect=False, scan_freq="2412")
  86. wait_fail_trigger(authsrv, "GET_ALLOC_FAIL")
  87. dev[0].request("REMOVE_NETWORK all")
  88. dev[0].wait_disconnected()
  89. dev[0].dump_monitor()
  90. tests = [ "radius_msg_add_attr;radius_server_encapsulate_eap",
  91. "radius_msg_add_eap;radius_server_encapsulate_eap",
  92. "radius_msg_finish_srv;radius_server_encapsulate_eap" ]
  93. for t in tests:
  94. with fail_test(authsrv, 1, t):
  95. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  96. eap="TTLS", identity="user",
  97. anonymous_identity="ttls", password="password",
  98. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC",
  99. wait_connect=False, scan_freq="2412")
  100. wait_fail_trigger(authsrv, "GET_FAIL")
  101. dev[0].request("REMOVE_NETWORK all")
  102. dev[0].wait_disconnected()
  103. dev[0].dump_monitor()
  104. with alloc_fail(authsrv, 1, "radius_server_get_new_session"):
  105. with fail_test(authsrv, 1, "radius_msg_add_eap;radius_server_reject"):
  106. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  107. eap="TTLS", identity="user",
  108. anonymous_identity="ttls", password="password",
  109. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC",
  110. wait_connect=False, scan_freq="2412")
  111. wait_fail_trigger(authsrv, "GET_FAIL")
  112. dev[0].request("REMOVE_NETWORK all")
  113. dev[0].wait_disconnected()
  114. dev[0].dump_monitor()
  115. with alloc_fail(authsrv, 1, "radius_server_get_new_session"):
  116. with fail_test(authsrv, 1,
  117. "radius_msg_finish_srv;radius_server_reject"):
  118. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  119. eap="TTLS", identity="user",
  120. anonymous_identity="ttls", password="password",
  121. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC",
  122. wait_connect=False, scan_freq="2412")
  123. wait_fail_trigger(authsrv, "GET_FAIL")
  124. dev[0].request("REMOVE_NETWORK all")
  125. dev[0].wait_disconnected()
  126. dev[0].dump_monitor()
  127. authsrv.disable()
  128. with alloc_fail(authsrv, 1, "radius_server_init;hostapd_setup_radius_srv"):
  129. if "FAIL" not in authsrv.request("ENABLE"):
  130. raise Exception("ENABLE succeeded during OOM")
  131. with alloc_fail(authsrv, 2, "radius_server_init;hostapd_setup_radius_srv"):
  132. authsrv.request("ENABLE")
  133. # This is actually allowed to continue even though memory allocation
  134. # fails.
  135. authsrv.disable()
  136. for count in range(1, 4):
  137. with alloc_fail(authsrv, count,
  138. "radius_server_read_clients;radius_server_init;hostapd_setup_radius_srv"):
  139. if "FAIL" not in authsrv.request("ENABLE"):
  140. raise Exception("ENABLE succeeded during OOM")
  141. with alloc_fail(authsrv, 1, "eloop_sock_table_add_sock;radius_server_init;hostapd_setup_radius_srv"):
  142. if "FAIL" not in authsrv.request("ENABLE"):
  143. raise Exception("ENABLE succeeded during OOM")
  144. with alloc_fail(authsrv, 1, "tls_init;authsrv_init"):
  145. if "FAIL" not in authsrv.request("ENABLE"):
  146. raise Exception("ENABLE succeeded during OOM")
  147. for count in range(1, 3):
  148. with alloc_fail(authsrv, count, "eap_sim_db_init;authsrv_init"):
  149. if "FAIL" not in authsrv.request("ENABLE"):
  150. raise Exception("ENABLE succeeded during OOM")
  151. def test_authsrv_errors_1(dev, apdev):
  152. """Authentication server errors (1)"""
  153. params = authsrv_params()
  154. params["eap_user_file"] = "sqlite:auth_serv/does-not-exist/does-not-exist"
  155. authsrv = hostapd.add_ap(apdev[1], params, no_enable=True)
  156. if "FAIL" not in authsrv.request("ENABLE"):
  157. raise Exception("ENABLE succeeded with invalid SQLite EAP user file")
  158. def test_authsrv_errors_2(dev, apdev):
  159. """Authentication server errors (2)"""
  160. params = authsrv_params()
  161. params["radius_server_clients"] = "auth_serv/does-not-exist"
  162. authsrv = hostapd.add_ap(apdev[1], params, no_enable=True)
  163. if "FAIL" not in authsrv.request("ENABLE"):
  164. raise Exception("ENABLE succeeded with invalid RADIUS client file")
  165. def test_authsrv_errors_3(dev, apdev):
  166. """Authentication server errors (3)"""
  167. params = authsrv_params()
  168. params["eap_sim_db"] = "unix:/tmp/hlr_auc_gw.sock db=auth_serv/does-not-exist/does-not-exist"
  169. authsrv = hostapd.add_ap(apdev[1], params, no_enable=True)
  170. if "FAIL" not in authsrv.request("ENABLE"):
  171. raise Exception("ENABLE succeeded with invalid RADIUS client file")
  172. def test_authsrv_testing_options(dev, apdev):
  173. """Authentication server and testing options"""
  174. params = authsrv_params()
  175. authsrv = hostapd.add_ap(apdev[1], params)
  176. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  177. params['auth_server_port'] = "18128"
  178. hapd = hostapd.add_ap(apdev[0], params)
  179. dev[0].scan_for_bss(hapd.own_addr(), 2412)
  180. # The first two would be fine to run with any server build; the rest are
  181. # actually supposed to fail, but they don't fail when using a server build
  182. # that does not support the TLS protocol tests.
  183. tests = [ "foo@test-unknown",
  184. "foo@test-tls-unknown",
  185. "foo@test-tls-1",
  186. "foo@test-tls-2",
  187. "foo@test-tls-3",
  188. "foo@test-tls-4",
  189. "foo@test-tls-5",
  190. "foo@test-tls-6",
  191. "foo@test-tls-7",
  192. "foo@test-tls-8" ]
  193. for t in tests:
  194. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  195. eap="TTLS", identity="user",
  196. anonymous_identity=t,
  197. password="password",
  198. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC",
  199. scan_freq="2412")
  200. dev[0].request("REMOVE_NETWORK all")
  201. dev[0].wait_disconnected()
  202. def test_authsrv_unknown_user(dev, apdev):
  203. """Authentication server and unknown user"""
  204. params = authsrv_params()
  205. params["eap_user_file"] = "auth_serv/eap_user_vlan.conf"
  206. authsrv = hostapd.add_ap(apdev[1], params)
  207. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  208. params['auth_server_port'] = "18128"
  209. hapd = hostapd.add_ap(apdev[0], params)
  210. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  211. eap="TTLS", identity="user",
  212. anonymous_identity="ttls", password="password",
  213. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC",
  214. wait_connect=False, scan_freq="2412")
  215. dev[0].wait_disconnected()
  216. dev[0].request("REMOVE_NETWORK all")
  217. def test_authsrv_unknown_client(dev, apdev):
  218. """Authentication server and unknown user"""
  219. params = authsrv_params()
  220. params["radius_server_clients"] = "auth_serv/radius_clients_none.conf"
  221. authsrv = hostapd.add_ap(apdev[1], params)
  222. params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
  223. params['auth_server_port'] = "18128"
  224. hapd = hostapd.add_ap(apdev[0], params)
  225. # RADIUS SRV: Unknown client 127.0.0.1 - packet ignored
  226. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  227. eap="TTLS", identity="user",
  228. anonymous_identity="ttls", password="password",
  229. ca_cert="auth_serv/ca.pem", phase2="autheap=GTC",
  230. wait_connect=False, scan_freq="2412")
  231. ev = dev[0].wait_event(["CTRL-EVENT-EAP-STARTED"], timeout=10)
  232. if ev is None:
  233. raise Exception("EAP not started")
  234. dev[0].request("REMOVE_NETWORK all")