test_sigma_dut.py 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. # Test cases for sigma_dut
  2. # Copyright (c) 2017, Qualcomm Atheros, Inc.
  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 os
  9. import socket
  10. import subprocess
  11. import time
  12. import hostapd
  13. from utils import HwsimSkip
  14. from hwsim import HWSimRadio
  15. from test_suite_b import check_suite_b_192_capa, suite_b_as_params, suite_b_192_rsa_ap_params
  16. def check_sigma_dut():
  17. if not os.path.exists("./sigma_dut"):
  18. raise HwsimSkip("sigma_dut not available")
  19. def sigma_dut_cmd(cmd, port=9000):
  20. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
  21. socket.IPPROTO_TCP)
  22. sock.settimeout(2)
  23. addr = ('127.0.0.1', port)
  24. sock.connect(addr)
  25. sock.send(cmd + "\r\n")
  26. try:
  27. res = sock.recv(1000)
  28. running = False
  29. done = False
  30. for line in res.splitlines():
  31. if line.startswith("status,RUNNING"):
  32. running = True
  33. elif line.startswith("status,INVALID"):
  34. done = True
  35. elif line.startswith("status,ERROR"):
  36. done = True
  37. elif line.startswith("status,COMPLETE"):
  38. done = True
  39. if running and not done:
  40. # Read the actual response
  41. res = sock.recv(1000)
  42. except:
  43. res = ''
  44. pass
  45. sock.close()
  46. res = res.rstrip()
  47. logger.debug("sigma_dut: '%s' --> '%s'" % (cmd, res))
  48. return res
  49. def sigma_dut_cmd_check(cmd):
  50. res = sigma_dut_cmd(cmd)
  51. if "COMPLETE" not in res:
  52. raise Exception("sigma_dut command failed: " + cmd)
  53. return res
  54. def start_sigma_dut(ifname, debug=False, hostapd_logdir=None, cert_path=None):
  55. check_sigma_dut()
  56. cmd = [ './sigma_dut',
  57. '-M', ifname,
  58. '-S', ifname,
  59. '-F', '../../hostapd/hostapd',
  60. '-G',
  61. '-j', ifname ]
  62. if debug:
  63. cmd += [ '-d' ]
  64. if hostapd_logdir:
  65. cmd += [ '-H', hostapd_logdir ]
  66. if cert_path:
  67. cmd += [ '-C', cert_path ]
  68. sigma = subprocess.Popen(cmd, stdout=subprocess.PIPE,
  69. stderr=subprocess.PIPE)
  70. for i in range(20):
  71. try:
  72. res = sigma_dut_cmd("HELLO")
  73. break
  74. except:
  75. time.sleep(0.05)
  76. return sigma
  77. def stop_sigma_dut(sigma):
  78. sigma.terminate()
  79. sigma.wait()
  80. out, err = sigma.communicate()
  81. logger.debug("sigma_dut stdout: " + str(out))
  82. logger.debug("sigma_dut stderr: " + str(err))
  83. def sigma_dut_wait_connected(ifname):
  84. for i in range(50):
  85. res = sigma_dut_cmd("sta_is_connected,interface," + ifname)
  86. if "connected,1" in res:
  87. break
  88. time.sleep(0.2)
  89. if i == 49:
  90. raise Exception("Connection did not complete")
  91. def test_sigma_dut_basic(dev, apdev):
  92. """sigma_dut basic functionality"""
  93. sigma = start_sigma_dut(dev[0].ifname)
  94. res = sigma_dut_cmd("UNKNOWN")
  95. if "status,INVALID,errorCode,Unknown command" not in res:
  96. raise Exception("Unexpected sigma_dut response to unknown command")
  97. tests = [ ("ca_get_version", "status,COMPLETE,version,1.0"),
  98. ("device_get_info", "status,COMPLETE,vendor"),
  99. ("device_list_interfaces,interfaceType,foo", "status,ERROR"),
  100. ("device_list_interfaces,interfaceType,802.11",
  101. "status,COMPLETE,interfaceType,802.11,interfaceID," + dev[0].ifname) ]
  102. for cmd, response in tests:
  103. res = sigma_dut_cmd(cmd)
  104. if response not in res:
  105. raise Exception("Unexpected %s response: %s" % (cmd, res))
  106. stop_sigma_dut(sigma)
  107. def test_sigma_dut_open(dev, apdev):
  108. """sigma_dut controlled open network association"""
  109. try:
  110. run_sigma_dut_open(dev, apdev)
  111. finally:
  112. dev[0].set("ignore_old_scan_res", "0")
  113. def run_sigma_dut_open(dev, apdev):
  114. ifname = dev[0].ifname
  115. sigma = start_sigma_dut(ifname)
  116. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  117. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  118. sigma_dut_cmd_check("sta_set_encryption,interface,%s,ssid,%s,encpType,none" % (ifname, "open"))
  119. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s" % (ifname, "open"))
  120. sigma_dut_wait_connected(ifname)
  121. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  122. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  123. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  124. stop_sigma_dut(sigma)
  125. def test_sigma_dut_psk_pmf(dev, apdev):
  126. """sigma_dut controlled PSK+PMF association"""
  127. try:
  128. run_sigma_dut_psk_pmf(dev, apdev)
  129. finally:
  130. dev[0].set("ignore_old_scan_res", "0")
  131. def run_sigma_dut_psk_pmf(dev, apdev):
  132. ifname = dev[0].ifname
  133. sigma = start_sigma_dut(ifname)
  134. ssid = "test-pmf-required"
  135. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  136. params["wpa_key_mgmt"] = "WPA-PSK-SHA256"
  137. params["ieee80211w"] = "2"
  138. hapd = hostapd.add_ap(apdev[0], params)
  139. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
  140. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  141. sigma_dut_cmd_check("sta_set_psk,interface,%s,ssid,%s,passphrase,%s,encpType,aes-ccmp,keymgmttype,wpa2,PMF,Required" % (ifname, "test-pmf-required", "12345678"))
  142. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-pmf-required"))
  143. sigma_dut_wait_connected(ifname)
  144. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  145. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  146. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  147. stop_sigma_dut(sigma)
  148. def test_sigma_dut_psk_pmf_bip_cmac_128(dev, apdev):
  149. """sigma_dut controlled PSK+PMF association with BIP-CMAC-128"""
  150. try:
  151. run_sigma_dut_psk_pmf_cipher(dev, apdev, "BIP-CMAC-128", "AES-128-CMAC")
  152. finally:
  153. dev[0].set("ignore_old_scan_res", "0")
  154. def test_sigma_dut_psk_pmf_bip_cmac_256(dev, apdev):
  155. """sigma_dut controlled PSK+PMF association with BIP-CMAC-256"""
  156. try:
  157. run_sigma_dut_psk_pmf_cipher(dev, apdev, "BIP-CMAC-256", "BIP-CMAC-256")
  158. finally:
  159. dev[0].set("ignore_old_scan_res", "0")
  160. def test_sigma_dut_psk_pmf_bip_gmac_128(dev, apdev):
  161. """sigma_dut controlled PSK+PMF association with BIP-GMAC-128"""
  162. try:
  163. run_sigma_dut_psk_pmf_cipher(dev, apdev, "BIP-GMAC-128", "BIP-GMAC-128")
  164. finally:
  165. dev[0].set("ignore_old_scan_res", "0")
  166. def test_sigma_dut_psk_pmf_bip_gmac_256(dev, apdev):
  167. """sigma_dut controlled PSK+PMF association with BIP-GMAC-256"""
  168. try:
  169. run_sigma_dut_psk_pmf_cipher(dev, apdev, "BIP-GMAC-256", "BIP-GMAC-256")
  170. finally:
  171. dev[0].set("ignore_old_scan_res", "0")
  172. def test_sigma_dut_psk_pmf_bip_gmac_256_mismatch(dev, apdev):
  173. """sigma_dut controlled PSK+PMF association with BIP-GMAC-256 mismatch"""
  174. try:
  175. run_sigma_dut_psk_pmf_cipher(dev, apdev, "BIP-GMAC-256", "AES-128-CMAC",
  176. failure=True)
  177. finally:
  178. dev[0].set("ignore_old_scan_res", "0")
  179. def run_sigma_dut_psk_pmf_cipher(dev, apdev, sigma_cipher, hostapd_cipher,
  180. failure=False):
  181. ifname = dev[0].ifname
  182. sigma = start_sigma_dut(ifname)
  183. ssid = "test-pmf-required"
  184. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  185. params["wpa_key_mgmt"] = "WPA-PSK-SHA256"
  186. params["ieee80211w"] = "2"
  187. params["group_mgmt_cipher"] = hostapd_cipher
  188. hapd = hostapd.add_ap(apdev[0], params)
  189. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
  190. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  191. sigma_dut_cmd_check("sta_set_psk,interface,%s,ssid,%s,passphrase,%s,encpType,aes-ccmp,keymgmttype,wpa2,PMF,Required,GroupMgntCipher,%s" % (ifname, "test-pmf-required", "12345678", sigma_cipher))
  192. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-pmf-required"))
  193. if failure:
  194. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND",
  195. "CTRL-EVENT-CONNECTED"], timeout=10)
  196. if ev is None:
  197. raise Exception("Network selection result not indicated")
  198. if "CTRL-EVENT-CONNECTED" in ev:
  199. raise Exception("Unexpected connection")
  200. res = sigma_dut_cmd("sta_is_connected,interface," + ifname)
  201. if "connected,1" in res:
  202. raise Exception("Connection reported")
  203. else:
  204. sigma_dut_wait_connected(ifname)
  205. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  206. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  207. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  208. stop_sigma_dut(sigma)
  209. def test_sigma_dut_sae(dev, apdev):
  210. """sigma_dut controlled SAE association"""
  211. if "SAE" not in dev[0].get_capability("auth_alg"):
  212. raise HwsimSkip("SAE not supported")
  213. ifname = dev[0].ifname
  214. sigma = start_sigma_dut(ifname)
  215. ssid = "test-sae"
  216. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  217. params['wpa_key_mgmt'] = 'SAE'
  218. hapd = hostapd.add_ap(apdev[0], params)
  219. sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
  220. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  221. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", "12345678"))
  222. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"))
  223. sigma_dut_wait_connected(ifname)
  224. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  225. if dev[0].get_status_field('sae_group') != '19':
  226. raise Exception("Expected default SAE group not used")
  227. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  228. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  229. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  230. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2,ECGroupID,20" % (ifname, "test-sae", "12345678"))
  231. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"))
  232. sigma_dut_wait_connected(ifname)
  233. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  234. if dev[0].get_status_field('sae_group') != '20':
  235. raise Exception("Expected SAE group not used")
  236. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  237. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  238. stop_sigma_dut(sigma)
  239. def test_sigma_dut_sta_override_rsne(dev, apdev):
  240. """sigma_dut and RSNE override on STA"""
  241. try:
  242. run_sigma_dut_sta_override_rsne(dev, apdev)
  243. finally:
  244. dev[0].set("ignore_old_scan_res", "0")
  245. def run_sigma_dut_sta_override_rsne(dev, apdev):
  246. ifname = dev[0].ifname
  247. sigma = start_sigma_dut(ifname)
  248. ssid = "test-psk"
  249. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  250. hapd = hostapd.add_ap(apdev[0], params)
  251. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  252. tests = [ "30120100000fac040100000fac040100000fac02",
  253. "30140100000fac040100000fac040100000fac02ffff" ]
  254. for test in tests:
  255. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,type,PSK,passphrase,%s,EncpType,aes-ccmp,KeyMgmtType,wpa2" % (ifname, "test-psk", "12345678"))
  256. sigma_dut_cmd_check("dev_configure_ie,interface,%s,IE_Name,RSNE,Contents,%s" % (ifname, test))
  257. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-psk"))
  258. sigma_dut_wait_connected(ifname)
  259. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  260. dev[0].dump_monitor()
  261. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,type,PSK,passphrase,%s,EncpType,aes-ccmp,KeyMgmtType,wpa2" % (ifname, "test-psk", "12345678"))
  262. sigma_dut_cmd_check("dev_configure_ie,interface,%s,IE_Name,RSNE,Contents,300101" % ifname)
  263. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-psk"))
  264. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  265. if ev is None:
  266. raise Exception("Association rejection not reported")
  267. if "status_code=40" not in ev:
  268. raise Exception("Unexpected status code: " + ev)
  269. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  270. stop_sigma_dut(sigma)
  271. def test_sigma_dut_ap_psk(dev, apdev):
  272. """sigma_dut controlled AP"""
  273. with HWSimRadio() as (radio, iface):
  274. sigma = start_sigma_dut(iface)
  275. try:
  276. sigma_dut_cmd_check("ap_reset_default")
  277. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
  278. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678")
  279. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  280. dev[0].connect("test-psk", psk="12345678", scan_freq="2412")
  281. sigma_dut_cmd_check("ap_reset_default")
  282. finally:
  283. stop_sigma_dut(sigma)
  284. def test_sigma_dut_suite_b(dev, apdev, params):
  285. """sigma_dut controlled STA Suite B"""
  286. check_suite_b_192_capa(dev)
  287. logdir = params['logdir']
  288. with open("auth_serv/ec2-ca.pem", "r") as f:
  289. with open(os.path.join(logdir, "suite_b_ca.pem"), "w") as f2:
  290. f2.write(f.read())
  291. with open("auth_serv/ec2-user.pem", "r") as f:
  292. with open("auth_serv/ec2-user.key", "r") as f2:
  293. with open(os.path.join(logdir, "suite_b.pem"), "w") as f3:
  294. f3.write(f.read())
  295. f3.write(f2.read())
  296. dev[0].flush_scan_cache()
  297. params = suite_b_as_params()
  298. params['ca_cert'] = 'auth_serv/ec2-ca.pem'
  299. params['server_cert'] = 'auth_serv/ec2-server.pem'
  300. params['private_key'] = 'auth_serv/ec2-server.key'
  301. params['openssl_ciphers'] = 'SUITEB192'
  302. hostapd.add_ap(apdev[1], params)
  303. params = { "ssid": "test-suite-b",
  304. "wpa": "2",
  305. "wpa_key_mgmt": "WPA-EAP-SUITE-B-192",
  306. "rsn_pairwise": "GCMP-256",
  307. "group_mgmt_cipher": "BIP-GMAC-256",
  308. "ieee80211w": "2",
  309. "ieee8021x": "1",
  310. 'auth_server_addr': "127.0.0.1",
  311. 'auth_server_port': "18129",
  312. 'auth_server_shared_secret': "radius",
  313. 'nas_identifier': "nas.w1.fi" }
  314. hapd = hostapd.add_ap(apdev[0], params)
  315. ifname = dev[0].ifname
  316. sigma = start_sigma_dut(ifname, cert_path=logdir)
  317. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
  318. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  319. sigma_dut_cmd_check("sta_set_security,type,eaptls,interface,%s,ssid,%s,PairwiseCipher,AES-GCMP-256,GroupCipher,AES-GCMP-256,GroupMgntCipher,BIP-GMAC-256,keymgmttype,SuiteB,PMF,Required,clientCertificate,suite_b.pem,trustedRootCA,suite_b_ca.pem,CertType,ECC" % (ifname, "test-suite-b"))
  320. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-suite-b"))
  321. sigma_dut_wait_connected(ifname)
  322. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  323. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  324. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  325. stop_sigma_dut(sigma)
  326. def test_sigma_dut_suite_b_rsa(dev, apdev, params):
  327. """sigma_dut controlled STA Suite B (RSA)"""
  328. check_suite_b_192_capa(dev)
  329. logdir = params['logdir']
  330. with open("auth_serv/rsa3072-ca.pem", "r") as f:
  331. with open(os.path.join(logdir, "suite_b_ca_rsa.pem"), "w") as f2:
  332. f2.write(f.read())
  333. with open("auth_serv/rsa3072-user.pem", "r") as f:
  334. with open("auth_serv/rsa3072-user.key", "r") as f2:
  335. with open(os.path.join(logdir, "suite_b_rsa.pem"), "w") as f3:
  336. f3.write(f.read())
  337. f3.write(f2.read())
  338. dev[0].flush_scan_cache()
  339. params = suite_b_192_rsa_ap_params()
  340. hapd = hostapd.add_ap(apdev[0], params)
  341. ifname = dev[0].ifname
  342. sigma = start_sigma_dut(ifname, cert_path=logdir)
  343. cmd = "sta_set_security,type,eaptls,interface,%s,ssid,%s,PairwiseCipher,AES-GCMP-256,GroupCipher,AES-GCMP-256,GroupMgntCipher,BIP-GMAC-256,keymgmttype,SuiteB,PMF,Required,clientCertificate,suite_b_rsa.pem,trustedRootCA,suite_b_ca_rsa.pem,CertType,RSA" % (ifname, "test-suite-b")
  344. tests = [ "",
  345. ",TLSCipher,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
  346. ",TLSCipher,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" ]
  347. for extra in tests:
  348. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
  349. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  350. sigma_dut_cmd_check(cmd + extra)
  351. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-suite-b"))
  352. sigma_dut_wait_connected(ifname)
  353. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  354. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  355. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  356. stop_sigma_dut(sigma)
  357. def test_sigma_dut_ap_suite_b(dev, apdev, params):
  358. """sigma_dut controlled AP Suite B"""
  359. check_suite_b_192_capa(dev)
  360. logdir = os.path.join(params['logdir'],
  361. "sigma_dut_ap_suite_b.sigma-hostapd")
  362. params = suite_b_as_params()
  363. params['ca_cert'] = 'auth_serv/ec2-ca.pem'
  364. params['server_cert'] = 'auth_serv/ec2-server.pem'
  365. params['private_key'] = 'auth_serv/ec2-server.key'
  366. params['openssl_ciphers'] = 'SUITEB192'
  367. hostapd.add_ap(apdev[1], params)
  368. with HWSimRadio() as (radio, iface):
  369. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  370. try:
  371. sigma_dut_cmd_check("ap_reset_default")
  372. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-suite-b,MODE,11ng")
  373. sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,18129,PASSWORD,radius")
  374. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,SuiteB,PMF,Required")
  375. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  376. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
  377. ieee80211w="2",
  378. openssl_ciphers="SUITEB192",
  379. eap="TLS", identity="tls user",
  380. ca_cert="auth_serv/ec2-ca.pem",
  381. client_cert="auth_serv/ec2-user.pem",
  382. private_key="auth_serv/ec2-user.key",
  383. pairwise="GCMP-256", group="GCMP-256",
  384. scan_freq="2412")
  385. sigma_dut_cmd_check("ap_reset_default")
  386. finally:
  387. stop_sigma_dut(sigma)
  388. def test_sigma_dut_ap_cipher_gcmp_128(dev, apdev, params):
  389. """sigma_dut controlled AP with GCMP-128/BIP-GMAC-128 cipher"""
  390. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-GCMP-128", "BIP-GMAC-128",
  391. "GCMP")
  392. def test_sigma_dut_ap_cipher_gcmp_256(dev, apdev, params):
  393. """sigma_dut controlled AP with GCMP-256/BIP-GMAC-256 cipher"""
  394. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-GCMP-256", "BIP-GMAC-256",
  395. "GCMP-256")
  396. def test_sigma_dut_ap_cipher_ccmp_128(dev, apdev, params):
  397. """sigma_dut controlled AP with CCMP-128/BIP-CMAC-128 cipher"""
  398. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-128", "BIP-CMAC-128",
  399. "CCMP")
  400. def test_sigma_dut_ap_cipher_ccmp_256(dev, apdev, params):
  401. """sigma_dut controlled AP with CCMP-256/BIP-CMAC-256 cipher"""
  402. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-256", "BIP-CMAC-256",
  403. "CCMP-256")
  404. def run_sigma_dut_ap_cipher(dev, apdev, params, ap_pairwise, ap_group_mgmt,
  405. sta_cipher):
  406. check_suite_b_192_capa(dev)
  407. logdir = os.path.join(params['logdir'],
  408. "sigma_dut_ap_cipher.sigma-hostapd")
  409. params = suite_b_as_params()
  410. params['ca_cert'] = 'auth_serv/ec2-ca.pem'
  411. params['server_cert'] = 'auth_serv/ec2-server.pem'
  412. params['private_key'] = 'auth_serv/ec2-server.key'
  413. params['openssl_ciphers'] = 'SUITEB192'
  414. hostapd.add_ap(apdev[1], params)
  415. with HWSimRadio() as (radio, iface):
  416. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  417. try:
  418. sigma_dut_cmd_check("ap_reset_default")
  419. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-suite-b,MODE,11ng")
  420. sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,18129,PASSWORD,radius")
  421. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,SuiteB,PMF,Required,PairwiseCipher,%s,GroupMgntCipher,%s" % (ap_pairwise, ap_group_mgmt))
  422. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  423. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
  424. ieee80211w="2",
  425. openssl_ciphers="SUITEB192",
  426. eap="TLS", identity="tls user",
  427. ca_cert="auth_serv/ec2-ca.pem",
  428. client_cert="auth_serv/ec2-user.pem",
  429. private_key="auth_serv/ec2-user.key",
  430. pairwise=sta_cipher, group=sta_cipher,
  431. scan_freq="2412")
  432. sigma_dut_cmd_check("ap_reset_default")
  433. finally:
  434. stop_sigma_dut(sigma)
  435. def test_sigma_dut_ap_override_rsne(dev, apdev):
  436. """sigma_dut controlled AP overriding RSNE"""
  437. with HWSimRadio() as (radio, iface):
  438. sigma = start_sigma_dut(iface)
  439. try:
  440. sigma_dut_cmd_check("ap_reset_default")
  441. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
  442. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678")
  443. sigma_dut_cmd_check("dev_configure_ie,NAME,AP,interface,%s,IE_Name,RSNE,Contents,30180100000fac040200ffffffff000fac040100000fac020c00" % iface)
  444. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  445. dev[0].connect("test-psk", psk="12345678", scan_freq="2412")
  446. sigma_dut_cmd_check("ap_reset_default")
  447. finally:
  448. stop_sigma_dut(sigma)
  449. def test_sigma_dut_ap_sae(dev, apdev):
  450. """sigma_dut controlled AP with SAE"""
  451. with HWSimRadio() as (radio, iface):
  452. sigma = start_sigma_dut(iface)
  453. try:
  454. sigma_dut_cmd_check("ap_reset_default")
  455. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  456. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678")
  457. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  458. dev[0].request("SET sae_groups ")
  459. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  460. scan_freq="2412")
  461. if dev[0].get_status_field('sae_group') != '19':
  462. raise Exception("Expected default SAE group not used")
  463. sigma_dut_cmd_check("ap_reset_default")
  464. finally:
  465. stop_sigma_dut(sigma)
  466. def test_sigma_dut_ap_sae_group(dev, apdev):
  467. """sigma_dut controlled AP with SAE and specific group"""
  468. with HWSimRadio() as (radio, iface):
  469. sigma = start_sigma_dut(iface)
  470. try:
  471. sigma_dut_cmd_check("ap_reset_default")
  472. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  473. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,ECGroupID,20")
  474. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  475. dev[0].request("SET sae_groups ")
  476. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  477. scan_freq="2412")
  478. if dev[0].get_status_field('sae_group') != '20':
  479. raise Exception("Expected SAE group not used")
  480. sigma_dut_cmd_check("ap_reset_default")
  481. finally:
  482. stop_sigma_dut(sigma)
  483. def test_sigma_dut_ap_psk_sae(dev, apdev):
  484. """sigma_dut controlled AP with PSK+SAE"""
  485. with HWSimRadio() as (radio, iface):
  486. sigma = start_sigma_dut(iface)
  487. try:
  488. sigma_dut_cmd_check("ap_reset_default")
  489. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  490. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK-SAE,PSK,12345678")
  491. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  492. dev[0].request("SET sae_groups ")
  493. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  494. scan_freq="2412")
  495. dev[1].connect("test-sae", psk="12345678", scan_freq="2412")
  496. sigma_dut_cmd_check("ap_reset_default")
  497. finally:
  498. stop_sigma_dut(sigma)
  499. def test_sigma_dut_owe(dev, apdev):
  500. """sigma_dut controlled OWE station"""
  501. try:
  502. run_sigma_dut_owe(dev, apdev)
  503. finally:
  504. dev[0].set("ignore_old_scan_res", "0")
  505. def run_sigma_dut_owe(dev, apdev):
  506. if "OWE" not in dev[0].get_capability("key_mgmt"):
  507. raise HwsimSkip("OWE not supported")
  508. ifname = dev[0].ifname
  509. sigma = start_sigma_dut(ifname)
  510. try:
  511. params = { "ssid": "owe",
  512. "wpa": "2",
  513. "wpa_key_mgmt": "OWE",
  514. "rsn_pairwise": "CCMP" }
  515. hapd = hostapd.add_ap(apdev[0], params)
  516. bssid = hapd.own_addr()
  517. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  518. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  519. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE" % ifname)
  520. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  521. sigma_dut_wait_connected(ifname)
  522. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  523. dev[0].dump_monitor()
  524. sigma_dut_cmd("sta_reassoc,interface,%s,Channel,1,bssid,%s" % (ifname, bssid))
  525. dev[0].wait_connected()
  526. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  527. dev[0].wait_disconnected()
  528. dev[0].dump_monitor()
  529. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  530. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  531. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,20" % ifname)
  532. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  533. sigma_dut_wait_connected(ifname)
  534. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  535. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  536. dev[0].wait_disconnected()
  537. dev[0].dump_monitor()
  538. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  539. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  540. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,0" % ifname)
  541. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  542. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  543. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  544. if ev is None:
  545. raise Exception("Association not rejected")
  546. if "status_code=77" not in ev:
  547. raise Exception("Unexpected rejection reason: " + ev)
  548. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  549. finally:
  550. stop_sigma_dut(sigma)
  551. def test_sigma_dut_ap_owe(dev, apdev):
  552. """sigma_dut controlled AP with OWE"""
  553. if "OWE" not in dev[0].get_capability("key_mgmt"):
  554. raise HwsimSkip("OWE not supported")
  555. with HWSimRadio() as (radio, iface):
  556. sigma = start_sigma_dut(iface)
  557. try:
  558. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  559. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
  560. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE")
  561. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  562. dev[0].connect("owe", key_mgmt="OWE", scan_freq="2412")
  563. sigma_dut_cmd_check("ap_reset_default")
  564. finally:
  565. stop_sigma_dut(sigma)
  566. def test_sigma_dut_ap_owe_ecgroupid(dev, apdev):
  567. """sigma_dut controlled AP with OWE and ECGroupID"""
  568. if "OWE" not in dev[0].get_capability("key_mgmt"):
  569. raise HwsimSkip("OWE not supported")
  570. with HWSimRadio() as (radio, iface):
  571. sigma = start_sigma_dut(iface)
  572. try:
  573. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  574. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
  575. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE,ECGroupID,20 21,PMF,Required")
  576. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  577. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  578. owe_group="20", scan_freq="2412")
  579. dev[0].request("REMOVE_NETWORK all")
  580. dev[0].wait_disconnected()
  581. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  582. owe_group="21", scan_freq="2412")
  583. dev[0].request("REMOVE_NETWORK all")
  584. dev[0].wait_disconnected()
  585. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  586. owe_group="19", scan_freq="2412", wait_connect=False)
  587. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  588. dev[0].request("DISCONNECT")
  589. if ev is None:
  590. raise Exception("Association not rejected")
  591. if "status_code=77" not in ev:
  592. raise Exception("Unexpected rejection reason: " + ev)
  593. dev[0].dump_monitor()
  594. sigma_dut_cmd_check("ap_reset_default")
  595. finally:
  596. stop_sigma_dut(sigma)
  597. def test_sigma_dut_ap_owe_transition_mode(dev, apdev, params):
  598. """sigma_dut controlled AP with OWE and transition mode"""
  599. if "OWE" not in dev[0].get_capability("key_mgmt"):
  600. raise HwsimSkip("OWE not supported")
  601. logdir = os.path.join(params['logdir'],
  602. "sigma_dut_ap_owe_transition_mode.sigma-hostapd")
  603. with HWSimRadio() as (radio, iface):
  604. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  605. try:
  606. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  607. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,1,CHANNEL,1,SSID,owe,MODE,11ng")
  608. sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,1,KEYMGNT,OWE")
  609. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,2,CHANNEL,1,SSID,owe,MODE,11ng")
  610. sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,2,KEYMGNT,NONE")
  611. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  612. dev[0].connect("owe", key_mgmt="OWE", scan_freq="2412")
  613. dev[1].connect("owe", key_mgmt="NONE", scan_freq="2412")
  614. sigma_dut_cmd_check("ap_reset_default")
  615. finally:
  616. stop_sigma_dut(sigma)