test_tnc.py 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. # -*- coding: utf-8 -*-
  2. # TNC tests
  3. # Copyright (c) 2014-2015, Jouni Malinen <j@w1.fi>
  4. #
  5. # This software may be distributed under the terms of the BSD license.
  6. # See README for more details.
  7. import os.path
  8. import hostapd
  9. from utils import HwsimSkip, alloc_fail, fail_test, wait_fail_trigger
  10. from test_ap_eap import int_eap_server_params, check_eap_capa
  11. def test_tnc_peap_soh(dev, apdev):
  12. """TNC PEAP-SoH"""
  13. params = int_eap_server_params()
  14. params["tnc"] = "1"
  15. hostapd.add_ap(apdev[0], params)
  16. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  17. eap="PEAP", identity="user", password="password",
  18. ca_cert="auth_serv/ca.pem",
  19. phase1="peapver=0 tnc=soh cryptobinding=0",
  20. phase2="auth=MSCHAPV2",
  21. scan_freq="2412", wait_connect=False)
  22. dev[0].wait_connected(timeout=10)
  23. dev[1].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  24. eap="PEAP", identity="user", password="password",
  25. ca_cert="auth_serv/ca.pem",
  26. phase1="peapver=0 tnc=soh1 cryptobinding=1",
  27. phase2="auth=MSCHAPV2",
  28. scan_freq="2412", wait_connect=False)
  29. dev[1].wait_connected(timeout=10)
  30. dev[2].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  31. eap="PEAP", identity="user", password="password",
  32. ca_cert="auth_serv/ca.pem",
  33. phase1="peapver=0 tnc=soh2 cryptobinding=2",
  34. phase2="auth=MSCHAPV2",
  35. scan_freq="2412", wait_connect=False)
  36. dev[2].wait_connected(timeout=10)
  37. def test_tnc_peap_soh_errors(dev, apdev):
  38. """TNC PEAP-SoH local error cases"""
  39. params = int_eap_server_params()
  40. params["tnc"] = "1"
  41. hostapd.add_ap(apdev[0], params)
  42. tests = [ (1, "tncc_build_soh"),
  43. (1, "eap_msg_alloc;=eap_peap_phase2_request") ]
  44. for count, func in tests:
  45. with alloc_fail(dev[0], count, func):
  46. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  47. eap="PEAP", identity="user", password="password",
  48. ca_cert="auth_serv/ca.pem",
  49. phase1="peapver=0 tnc=soh cryptobinding=0",
  50. phase2="auth=MSCHAPV2",
  51. scan_freq="2412", wait_connect=False)
  52. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL")
  53. dev[0].request("REMOVE_NETWORK all")
  54. dev[0].wait_disconnected()
  55. with fail_test(dev[0], 1, "os_get_random;tncc_build_soh"):
  56. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  57. eap="PEAP", identity="user", password="password",
  58. ca_cert="auth_serv/ca.pem",
  59. phase1="peapver=0 tnc=soh cryptobinding=0",
  60. phase2="auth=MSCHAPV2",
  61. scan_freq="2412", wait_connect=False)
  62. wait_fail_trigger(dev[0], "GET_FAIL")
  63. dev[0].request("REMOVE_NETWORK all")
  64. dev[0].wait_disconnected()
  65. def test_tnc_ttls(dev, apdev):
  66. """TNC TTLS"""
  67. check_eap_capa(dev[0], "MSCHAPV2")
  68. params = int_eap_server_params()
  69. params["tnc"] = "1"
  70. hostapd.add_ap(apdev[0], params)
  71. if not os.path.exists("tnc/libhostap_imc.so"):
  72. raise HwsimSkip("No IMC installed")
  73. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  74. eap="TTLS", identity="DOMAIN\mschapv2 user",
  75. anonymous_identity="ttls", password="password",
  76. phase2="auth=MSCHAPV2",
  77. ca_cert="auth_serv/ca.pem",
  78. scan_freq="2412", wait_connect=False)
  79. dev[0].wait_connected(timeout=10)
  80. def test_tnc_ttls_fragmentation(dev, apdev):
  81. """TNC TTLS with fragmentation"""
  82. check_eap_capa(dev[0], "MSCHAPV2")
  83. params = int_eap_server_params()
  84. params["tnc"] = "1"
  85. params["fragment_size"] = "150"
  86. hostapd.add_ap(apdev[0], params)
  87. if not os.path.exists("tnc/libhostap_imc.so"):
  88. raise HwsimSkip("No IMC installed")
  89. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  90. eap="TTLS", identity="DOMAIN\mschapv2 user",
  91. anonymous_identity="ttls", password="password",
  92. phase2="auth=MSCHAPV2",
  93. ca_cert="auth_serv/ca.pem",
  94. fragment_size="150",
  95. scan_freq="2412", wait_connect=False)
  96. dev[0].wait_connected(timeout=10)
  97. def test_tnc_ttls_errors(dev, apdev):
  98. """TNC TTLS local error cases"""
  99. if not os.path.exists("tnc/libhostap_imc.so"):
  100. raise HwsimSkip("No IMC installed")
  101. check_eap_capa(dev[0], "MSCHAPV2")
  102. params = int_eap_server_params()
  103. params["tnc"] = "1"
  104. params["fragment_size"] = "150"
  105. hostapd.add_ap(apdev[0], params)
  106. tests = [ (1, "eap_ttls_process_phase2_eap;eap_ttls_process_tnc_start",
  107. "DOMAIN\mschapv2 user", "auth=MSCHAPV2"),
  108. (1, "eap_ttls_process_phase2_eap;eap_ttls_process_tnc_start",
  109. "mschap user", "auth=MSCHAP"),
  110. (1, "=eap_tnc_init", "chap user", "auth=CHAP"),
  111. (1, "tncc_init;eap_tnc_init", "pap user", "auth=PAP"),
  112. (1, "eap_msg_alloc;eap_tnc_build_frag_ack",
  113. "pap user", "auth=PAP"),
  114. (1, "eap_msg_alloc;eap_tnc_build_msg",
  115. "pap user", "auth=PAP"),
  116. (1, "wpabuf_alloc;=eap_tnc_process_fragment",
  117. "pap user", "auth=PAP"),
  118. (1, "eap_msg_alloc;=eap_tnc_process", "pap user", "auth=PAP"),
  119. (1, "wpabuf_alloc;=eap_tnc_process", "pap user", "auth=PAP"),
  120. (1, "dup_binstr;tncc_process_if_tnccs", "pap user", "auth=PAP"),
  121. (1, "tncc_get_base64;tncc_process_if_tnccs",
  122. "pap user", "auth=PAP"),
  123. (1, "tncc_if_tnccs_start", "pap user", "auth=PAP"),
  124. (1, "tncc_if_tnccs_end", "pap user", "auth=PAP"),
  125. (1, "tncc_parse_imc", "pap user", "auth=PAP"),
  126. (2, "tncc_parse_imc", "pap user", "auth=PAP"),
  127. (3, "tncc_parse_imc", "pap user", "auth=PAP"),
  128. (1, "os_readfile;tncc_read_config", "pap user", "auth=PAP"),
  129. (1, "tncc_init", "pap user", "auth=PAP"),
  130. (1, "TNC_TNCC_ReportMessageTypes", "pap user", "auth=PAP"),
  131. (1, "base64_gen_encode;?base64_encode;TNC_TNCC_SendMessage",
  132. "pap user", "auth=PAP"),
  133. (1, "=TNC_TNCC_SendMessage", "pap user", "auth=PAP"),
  134. (1, "tncc_get_base64;tncc_process_if_tnccs",
  135. "pap user", "auth=PAP") ]
  136. for count, func, identity, phase2 in tests:
  137. with alloc_fail(dev[0], count, func):
  138. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  139. scan_freq="2412",
  140. eap="TTLS", anonymous_identity="ttls",
  141. identity=identity, password="password",
  142. ca_cert="auth_serv/ca.pem", phase2=phase2,
  143. fragment_size="150", wait_connect=False)
  144. ev = dev[0].wait_event(["CTRL-EVENT-EAP-PROPOSED-METHOD"],
  145. timeout=15)
  146. if ev is None:
  147. raise Exception("Timeout on EAP start")
  148. wait_fail_trigger(dev[0], "GET_ALLOC_FAIL",
  149. note="Allocation failure not triggered for: %d:%s" % (count, func))
  150. dev[0].request("REMOVE_NETWORK all")
  151. dev[0].wait_disconnected()
  152. dev[0].dump_monitor()
  153. def test_tnc_fast(dev, apdev):
  154. """TNC FAST"""
  155. check_eap_capa(dev[0], "FAST")
  156. params = int_eap_server_params()
  157. params["tnc"] = "1"
  158. params["pac_opaque_encr_key"] ="000102030405060708090a0b0c0d0e00"
  159. params["eap_fast_a_id"] = "101112131415161718191a1b1c1d1e00"
  160. params["eap_fast_a_id_info"] = "test server2"
  161. hostapd.add_ap(apdev[0], params)
  162. if not os.path.exists("tnc/libhostap_imc.so"):
  163. raise HwsimSkip("No IMC installed")
  164. dev[0].connect("test-wpa2-eap", key_mgmt="WPA-EAP",
  165. eap="FAST", identity="user",
  166. anonymous_identity="FAST", password="password",
  167. phase2="auth=GTC",
  168. phase1="fast_provisioning=2",
  169. pac_file="blob://fast_pac_auth_tnc",
  170. ca_cert="auth_serv/ca.pem",
  171. scan_freq="2412", wait_connect=False)
  172. dev[0].wait_connected(timeout=10)