test_sigma_dut.py 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  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_sae_password(dev, apdev):
  240. """sigma_dut controlled SAE association and long password"""
  241. if "SAE" not in dev[0].get_capability("auth_alg"):
  242. raise HwsimSkip("SAE not supported")
  243. ifname = dev[0].ifname
  244. sigma = start_sigma_dut(ifname)
  245. try:
  246. ssid = "test-sae"
  247. params = hostapd.wpa2_params(ssid=ssid)
  248. params['sae_password'] = 100*'B'
  249. params['wpa_key_mgmt'] = 'SAE'
  250. hapd = hostapd.add_ap(apdev[0], params)
  251. sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
  252. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  253. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", 100*'B'))
  254. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"))
  255. sigma_dut_wait_connected(ifname)
  256. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  257. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  258. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  259. finally:
  260. stop_sigma_dut(sigma)
  261. def test_sigma_dut_sta_override_rsne(dev, apdev):
  262. """sigma_dut and RSNE override on STA"""
  263. try:
  264. run_sigma_dut_sta_override_rsne(dev, apdev)
  265. finally:
  266. dev[0].set("ignore_old_scan_res", "0")
  267. def run_sigma_dut_sta_override_rsne(dev, apdev):
  268. ifname = dev[0].ifname
  269. sigma = start_sigma_dut(ifname)
  270. ssid = "test-psk"
  271. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  272. hapd = hostapd.add_ap(apdev[0], params)
  273. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  274. tests = [ "30120100000fac040100000fac040100000fac02",
  275. "30140100000fac040100000fac040100000fac02ffff" ]
  276. for test in tests:
  277. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,type,PSK,passphrase,%s,EncpType,aes-ccmp,KeyMgmtType,wpa2" % (ifname, "test-psk", "12345678"))
  278. sigma_dut_cmd_check("dev_configure_ie,interface,%s,IE_Name,RSNE,Contents,%s" % (ifname, test))
  279. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-psk"))
  280. sigma_dut_wait_connected(ifname)
  281. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  282. dev[0].dump_monitor()
  283. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,type,PSK,passphrase,%s,EncpType,aes-ccmp,KeyMgmtType,wpa2" % (ifname, "test-psk", "12345678"))
  284. sigma_dut_cmd_check("dev_configure_ie,interface,%s,IE_Name,RSNE,Contents,300101" % ifname)
  285. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-psk"))
  286. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  287. if ev is None:
  288. raise Exception("Association rejection not reported")
  289. if "status_code=40" not in ev:
  290. raise Exception("Unexpected status code: " + ev)
  291. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  292. stop_sigma_dut(sigma)
  293. def test_sigma_dut_ap_psk(dev, apdev):
  294. """sigma_dut controlled AP"""
  295. with HWSimRadio() as (radio, iface):
  296. sigma = start_sigma_dut(iface)
  297. try:
  298. sigma_dut_cmd_check("ap_reset_default")
  299. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
  300. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678")
  301. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  302. dev[0].connect("test-psk", psk="12345678", scan_freq="2412")
  303. sigma_dut_cmd_check("ap_reset_default")
  304. finally:
  305. stop_sigma_dut(sigma)
  306. def test_sigma_dut_suite_b(dev, apdev, params):
  307. """sigma_dut controlled STA Suite B"""
  308. check_suite_b_192_capa(dev)
  309. logdir = params['logdir']
  310. with open("auth_serv/ec2-ca.pem", "r") as f:
  311. with open(os.path.join(logdir, "suite_b_ca.pem"), "w") as f2:
  312. f2.write(f.read())
  313. with open("auth_serv/ec2-user.pem", "r") as f:
  314. with open("auth_serv/ec2-user.key", "r") as f2:
  315. with open(os.path.join(logdir, "suite_b.pem"), "w") as f3:
  316. f3.write(f.read())
  317. f3.write(f2.read())
  318. dev[0].flush_scan_cache()
  319. params = suite_b_as_params()
  320. params['ca_cert'] = 'auth_serv/ec2-ca.pem'
  321. params['server_cert'] = 'auth_serv/ec2-server.pem'
  322. params['private_key'] = 'auth_serv/ec2-server.key'
  323. params['openssl_ciphers'] = 'SUITEB192'
  324. hostapd.add_ap(apdev[1], params)
  325. params = { "ssid": "test-suite-b",
  326. "wpa": "2",
  327. "wpa_key_mgmt": "WPA-EAP-SUITE-B-192",
  328. "rsn_pairwise": "GCMP-256",
  329. "group_mgmt_cipher": "BIP-GMAC-256",
  330. "ieee80211w": "2",
  331. "ieee8021x": "1",
  332. 'auth_server_addr': "127.0.0.1",
  333. 'auth_server_port': "18129",
  334. 'auth_server_shared_secret': "radius",
  335. 'nas_identifier': "nas.w1.fi" }
  336. hapd = hostapd.add_ap(apdev[0], params)
  337. ifname = dev[0].ifname
  338. sigma = start_sigma_dut(ifname, cert_path=logdir)
  339. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
  340. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  341. 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"))
  342. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-suite-b"))
  343. sigma_dut_wait_connected(ifname)
  344. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  345. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  346. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  347. stop_sigma_dut(sigma)
  348. def test_sigma_dut_suite_b_rsa(dev, apdev, params):
  349. """sigma_dut controlled STA Suite B (RSA)"""
  350. check_suite_b_192_capa(dev)
  351. logdir = params['logdir']
  352. with open("auth_serv/rsa3072-ca.pem", "r") as f:
  353. with open(os.path.join(logdir, "suite_b_ca_rsa.pem"), "w") as f2:
  354. f2.write(f.read())
  355. with open("auth_serv/rsa3072-user.pem", "r") as f:
  356. with open("auth_serv/rsa3072-user.key", "r") as f2:
  357. with open(os.path.join(logdir, "suite_b_rsa.pem"), "w") as f3:
  358. f3.write(f.read())
  359. f3.write(f2.read())
  360. dev[0].flush_scan_cache()
  361. params = suite_b_192_rsa_ap_params()
  362. hapd = hostapd.add_ap(apdev[0], params)
  363. ifname = dev[0].ifname
  364. sigma = start_sigma_dut(ifname, cert_path=logdir)
  365. 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")
  366. tests = [ "",
  367. ",TLSCipher,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
  368. ",TLSCipher,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" ]
  369. for extra in tests:
  370. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
  371. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  372. sigma_dut_cmd_check(cmd + extra)
  373. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-suite-b"))
  374. sigma_dut_wait_connected(ifname)
  375. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  376. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  377. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  378. stop_sigma_dut(sigma)
  379. def test_sigma_dut_ap_suite_b(dev, apdev, params):
  380. """sigma_dut controlled AP Suite B"""
  381. check_suite_b_192_capa(dev)
  382. logdir = os.path.join(params['logdir'],
  383. "sigma_dut_ap_suite_b.sigma-hostapd")
  384. params = suite_b_as_params()
  385. params['ca_cert'] = 'auth_serv/ec2-ca.pem'
  386. params['server_cert'] = 'auth_serv/ec2-server.pem'
  387. params['private_key'] = 'auth_serv/ec2-server.key'
  388. params['openssl_ciphers'] = 'SUITEB192'
  389. hostapd.add_ap(apdev[1], params)
  390. with HWSimRadio() as (radio, iface):
  391. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  392. try:
  393. sigma_dut_cmd_check("ap_reset_default")
  394. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-suite-b,MODE,11ng")
  395. sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,18129,PASSWORD,radius")
  396. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,SuiteB,PMF,Required")
  397. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  398. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
  399. ieee80211w="2",
  400. openssl_ciphers="SUITEB192",
  401. eap="TLS", identity="tls user",
  402. ca_cert="auth_serv/ec2-ca.pem",
  403. client_cert="auth_serv/ec2-user.pem",
  404. private_key="auth_serv/ec2-user.key",
  405. pairwise="GCMP-256", group="GCMP-256",
  406. scan_freq="2412")
  407. sigma_dut_cmd_check("ap_reset_default")
  408. finally:
  409. stop_sigma_dut(sigma)
  410. def test_sigma_dut_ap_cipher_gcmp_128(dev, apdev, params):
  411. """sigma_dut controlled AP with GCMP-128/BIP-GMAC-128 cipher"""
  412. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-GCMP-128", "BIP-GMAC-128",
  413. "GCMP")
  414. def test_sigma_dut_ap_cipher_gcmp_256(dev, apdev, params):
  415. """sigma_dut controlled AP with GCMP-256/BIP-GMAC-256 cipher"""
  416. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-GCMP-256", "BIP-GMAC-256",
  417. "GCMP-256")
  418. def test_sigma_dut_ap_cipher_ccmp_128(dev, apdev, params):
  419. """sigma_dut controlled AP with CCMP-128/BIP-CMAC-128 cipher"""
  420. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-128", "BIP-CMAC-128",
  421. "CCMP")
  422. def test_sigma_dut_ap_cipher_ccmp_256(dev, apdev, params):
  423. """sigma_dut controlled AP with CCMP-256/BIP-CMAC-256 cipher"""
  424. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-256", "BIP-CMAC-256",
  425. "CCMP-256")
  426. def run_sigma_dut_ap_cipher(dev, apdev, params, ap_pairwise, ap_group_mgmt,
  427. sta_cipher):
  428. check_suite_b_192_capa(dev)
  429. logdir = os.path.join(params['logdir'],
  430. "sigma_dut_ap_cipher.sigma-hostapd")
  431. params = suite_b_as_params()
  432. params['ca_cert'] = 'auth_serv/ec2-ca.pem'
  433. params['server_cert'] = 'auth_serv/ec2-server.pem'
  434. params['private_key'] = 'auth_serv/ec2-server.key'
  435. params['openssl_ciphers'] = 'SUITEB192'
  436. hostapd.add_ap(apdev[1], params)
  437. with HWSimRadio() as (radio, iface):
  438. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  439. try:
  440. sigma_dut_cmd_check("ap_reset_default")
  441. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-suite-b,MODE,11ng")
  442. sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,18129,PASSWORD,radius")
  443. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,SuiteB,PMF,Required,PairwiseCipher,%s,GroupMgntCipher,%s" % (ap_pairwise, ap_group_mgmt))
  444. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  445. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
  446. ieee80211w="2",
  447. openssl_ciphers="SUITEB192",
  448. eap="TLS", identity="tls user",
  449. ca_cert="auth_serv/ec2-ca.pem",
  450. client_cert="auth_serv/ec2-user.pem",
  451. private_key="auth_serv/ec2-user.key",
  452. pairwise=sta_cipher, group=sta_cipher,
  453. scan_freq="2412")
  454. sigma_dut_cmd_check("ap_reset_default")
  455. finally:
  456. stop_sigma_dut(sigma)
  457. def test_sigma_dut_ap_override_rsne(dev, apdev):
  458. """sigma_dut controlled AP overriding RSNE"""
  459. with HWSimRadio() as (radio, iface):
  460. sigma = start_sigma_dut(iface)
  461. try:
  462. sigma_dut_cmd_check("ap_reset_default")
  463. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
  464. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678")
  465. sigma_dut_cmd_check("dev_configure_ie,NAME,AP,interface,%s,IE_Name,RSNE,Contents,30180100000fac040200ffffffff000fac040100000fac020c00" % iface)
  466. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  467. dev[0].connect("test-psk", psk="12345678", scan_freq="2412")
  468. sigma_dut_cmd_check("ap_reset_default")
  469. finally:
  470. stop_sigma_dut(sigma)
  471. def test_sigma_dut_ap_sae(dev, apdev):
  472. """sigma_dut controlled AP with SAE"""
  473. with HWSimRadio() as (radio, iface):
  474. sigma = start_sigma_dut(iface)
  475. try:
  476. sigma_dut_cmd_check("ap_reset_default")
  477. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  478. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678")
  479. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  480. dev[0].request("SET sae_groups ")
  481. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  482. scan_freq="2412")
  483. if dev[0].get_status_field('sae_group') != '19':
  484. raise Exception("Expected default SAE group not used")
  485. sigma_dut_cmd_check("ap_reset_default")
  486. finally:
  487. stop_sigma_dut(sigma)
  488. def test_sigma_dut_ap_sae_password(dev, apdev):
  489. """sigma_dut controlled AP with SAE and long password"""
  490. with HWSimRadio() as (radio, iface):
  491. sigma = start_sigma_dut(iface)
  492. try:
  493. sigma_dut_cmd_check("ap_reset_default")
  494. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  495. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK," + 100*'C')
  496. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  497. dev[0].request("SET sae_groups ")
  498. dev[0].connect("test-sae", key_mgmt="SAE", sae_password=100*'C',
  499. scan_freq="2412")
  500. if dev[0].get_status_field('sae_group') != '19':
  501. raise Exception("Expected default SAE group not used")
  502. sigma_dut_cmd_check("ap_reset_default")
  503. finally:
  504. stop_sigma_dut(sigma)
  505. def test_sigma_dut_ap_sae_group(dev, apdev):
  506. """sigma_dut controlled AP with SAE and specific group"""
  507. with HWSimRadio() as (radio, iface):
  508. sigma = start_sigma_dut(iface)
  509. try:
  510. sigma_dut_cmd_check("ap_reset_default")
  511. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  512. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,ECGroupID,20")
  513. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  514. dev[0].request("SET sae_groups ")
  515. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  516. scan_freq="2412")
  517. if dev[0].get_status_field('sae_group') != '20':
  518. raise Exception("Expected SAE group not used")
  519. sigma_dut_cmd_check("ap_reset_default")
  520. finally:
  521. stop_sigma_dut(sigma)
  522. def test_sigma_dut_ap_psk_sae(dev, apdev):
  523. """sigma_dut controlled AP with PSK+SAE"""
  524. with HWSimRadio() as (radio, iface):
  525. sigma = start_sigma_dut(iface)
  526. try:
  527. sigma_dut_cmd_check("ap_reset_default")
  528. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  529. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK-SAE,PSK,12345678")
  530. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  531. dev[0].request("SET sae_groups ")
  532. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  533. scan_freq="2412")
  534. dev[1].connect("test-sae", psk="12345678", scan_freq="2412")
  535. sigma_dut_cmd_check("ap_reset_default")
  536. finally:
  537. stop_sigma_dut(sigma)
  538. def test_sigma_dut_owe(dev, apdev):
  539. """sigma_dut controlled OWE station"""
  540. try:
  541. run_sigma_dut_owe(dev, apdev)
  542. finally:
  543. dev[0].set("ignore_old_scan_res", "0")
  544. def run_sigma_dut_owe(dev, apdev):
  545. if "OWE" not in dev[0].get_capability("key_mgmt"):
  546. raise HwsimSkip("OWE not supported")
  547. ifname = dev[0].ifname
  548. sigma = start_sigma_dut(ifname)
  549. try:
  550. params = { "ssid": "owe",
  551. "wpa": "2",
  552. "wpa_key_mgmt": "OWE",
  553. "rsn_pairwise": "CCMP" }
  554. hapd = hostapd.add_ap(apdev[0], params)
  555. bssid = hapd.own_addr()
  556. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  557. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  558. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE" % ifname)
  559. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  560. sigma_dut_wait_connected(ifname)
  561. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  562. dev[0].dump_monitor()
  563. sigma_dut_cmd("sta_reassoc,interface,%s,Channel,1,bssid,%s" % (ifname, bssid))
  564. dev[0].wait_connected()
  565. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  566. dev[0].wait_disconnected()
  567. dev[0].dump_monitor()
  568. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  569. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  570. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,20" % ifname)
  571. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  572. sigma_dut_wait_connected(ifname)
  573. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  574. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  575. dev[0].wait_disconnected()
  576. dev[0].dump_monitor()
  577. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  578. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  579. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,0" % ifname)
  580. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  581. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  582. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  583. if ev is None:
  584. raise Exception("Association not rejected")
  585. if "status_code=77" not in ev:
  586. raise Exception("Unexpected rejection reason: " + ev)
  587. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  588. finally:
  589. stop_sigma_dut(sigma)
  590. def test_sigma_dut_ap_owe(dev, apdev):
  591. """sigma_dut controlled AP with OWE"""
  592. if "OWE" not in dev[0].get_capability("key_mgmt"):
  593. raise HwsimSkip("OWE not supported")
  594. with HWSimRadio() as (radio, iface):
  595. sigma = start_sigma_dut(iface)
  596. try:
  597. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  598. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
  599. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE")
  600. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  601. dev[0].connect("owe", key_mgmt="OWE", scan_freq="2412")
  602. sigma_dut_cmd_check("ap_reset_default")
  603. finally:
  604. stop_sigma_dut(sigma)
  605. def test_sigma_dut_ap_owe_ecgroupid(dev, apdev):
  606. """sigma_dut controlled AP with OWE and ECGroupID"""
  607. if "OWE" not in dev[0].get_capability("key_mgmt"):
  608. raise HwsimSkip("OWE not supported")
  609. with HWSimRadio() as (radio, iface):
  610. sigma = start_sigma_dut(iface)
  611. try:
  612. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  613. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
  614. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE,ECGroupID,20 21,PMF,Required")
  615. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  616. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  617. owe_group="20", scan_freq="2412")
  618. dev[0].request("REMOVE_NETWORK all")
  619. dev[0].wait_disconnected()
  620. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  621. owe_group="21", scan_freq="2412")
  622. dev[0].request("REMOVE_NETWORK all")
  623. dev[0].wait_disconnected()
  624. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  625. owe_group="19", scan_freq="2412", wait_connect=False)
  626. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  627. dev[0].request("DISCONNECT")
  628. if ev is None:
  629. raise Exception("Association not rejected")
  630. if "status_code=77" not in ev:
  631. raise Exception("Unexpected rejection reason: " + ev)
  632. dev[0].dump_monitor()
  633. sigma_dut_cmd_check("ap_reset_default")
  634. finally:
  635. stop_sigma_dut(sigma)
  636. def test_sigma_dut_ap_owe_transition_mode(dev, apdev, params):
  637. """sigma_dut controlled AP with OWE and transition mode"""
  638. if "OWE" not in dev[0].get_capability("key_mgmt"):
  639. raise HwsimSkip("OWE not supported")
  640. logdir = os.path.join(params['logdir'],
  641. "sigma_dut_ap_owe_transition_mode.sigma-hostapd")
  642. with HWSimRadio() as (radio, iface):
  643. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  644. try:
  645. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  646. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,1,CHANNEL,1,SSID,owe,MODE,11ng")
  647. sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,1,KEYMGNT,OWE")
  648. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,2,CHANNEL,1,SSID,owe,MODE,11ng")
  649. sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,2,KEYMGNT,NONE")
  650. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  651. res1 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,1,Interface,24G")
  652. res2 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,2,Interface,24G")
  653. dev[0].connect("owe", key_mgmt="OWE", scan_freq="2412")
  654. dev[1].connect("owe", key_mgmt="NONE", scan_freq="2412")
  655. if dev[0].get_status_field('bssid') not in res1:
  656. raise Exception("Unexpected ap_get_mac_address WLAN_TAG,1: " + res1)
  657. if dev[1].get_status_field('bssid') not in res2:
  658. raise Exception("Unexpected ap_get_mac_address WLAN_TAG,2: " + res2)
  659. sigma_dut_cmd_check("ap_reset_default")
  660. finally:
  661. stop_sigma_dut(sigma)