test_sigma_dut.py 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876
  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 threading
  12. import time
  13. import hostapd
  14. from utils import HwsimSkip
  15. from hwsim import HWSimRadio
  16. from test_dpp import check_dpp_capab, update_hapd_config
  17. from test_suite_b import check_suite_b_192_capa, suite_b_as_params, suite_b_192_rsa_ap_params
  18. def check_sigma_dut():
  19. if not os.path.exists("./sigma_dut"):
  20. raise HwsimSkip("sigma_dut not available")
  21. def sigma_dut_cmd(cmd, port=9000, timeout=2):
  22. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM,
  23. socket.IPPROTO_TCP)
  24. sock.settimeout(timeout)
  25. addr = ('127.0.0.1', port)
  26. sock.connect(addr)
  27. sock.send(cmd + "\r\n")
  28. try:
  29. res = sock.recv(1000)
  30. running = False
  31. done = False
  32. for line in res.splitlines():
  33. if line.startswith("status,RUNNING"):
  34. running = True
  35. elif line.startswith("status,INVALID"):
  36. done = True
  37. elif line.startswith("status,ERROR"):
  38. done = True
  39. elif line.startswith("status,COMPLETE"):
  40. done = True
  41. if running and not done:
  42. # Read the actual response
  43. res = sock.recv(1000)
  44. except:
  45. res = ''
  46. pass
  47. sock.close()
  48. res = res.rstrip()
  49. logger.debug("sigma_dut: '%s' --> '%s'" % (cmd, res))
  50. return res
  51. def sigma_dut_cmd_check(cmd, port=9000, timeout=2):
  52. res = sigma_dut_cmd(cmd, port=port, timeout=timeout)
  53. if "COMPLETE" not in res:
  54. raise Exception("sigma_dut command failed: " + cmd)
  55. return res
  56. def start_sigma_dut(ifname, debug=False, hostapd_logdir=None, cert_path=None):
  57. check_sigma_dut()
  58. cmd = [ './sigma_dut',
  59. '-M', ifname,
  60. '-S', ifname,
  61. '-F', '../../hostapd/hostapd',
  62. '-G',
  63. '-w', '/var/run/wpa_supplicant/',
  64. '-j', ifname ]
  65. if debug:
  66. cmd += [ '-d' ]
  67. if hostapd_logdir:
  68. cmd += [ '-H', hostapd_logdir ]
  69. if cert_path:
  70. cmd += [ '-C', cert_path ]
  71. sigma = subprocess.Popen(cmd, stdout=subprocess.PIPE,
  72. stderr=subprocess.PIPE)
  73. for i in range(20):
  74. try:
  75. res = sigma_dut_cmd("HELLO")
  76. break
  77. except:
  78. time.sleep(0.05)
  79. return sigma
  80. def stop_sigma_dut(sigma):
  81. sigma.terminate()
  82. sigma.wait()
  83. out, err = sigma.communicate()
  84. logger.debug("sigma_dut stdout: " + str(out))
  85. logger.debug("sigma_dut stderr: " + str(err))
  86. def sigma_dut_wait_connected(ifname):
  87. for i in range(50):
  88. res = sigma_dut_cmd("sta_is_connected,interface," + ifname)
  89. if "connected,1" in res:
  90. break
  91. time.sleep(0.2)
  92. if i == 49:
  93. raise Exception("Connection did not complete")
  94. def test_sigma_dut_basic(dev, apdev):
  95. """sigma_dut basic functionality"""
  96. sigma = start_sigma_dut(dev[0].ifname)
  97. res = sigma_dut_cmd("UNKNOWN")
  98. if "status,INVALID,errorCode,Unknown command" not in res:
  99. raise Exception("Unexpected sigma_dut response to unknown command")
  100. tests = [ ("ca_get_version", "status,COMPLETE,version,1.0"),
  101. ("device_get_info", "status,COMPLETE,vendor"),
  102. ("device_list_interfaces,interfaceType,foo", "status,ERROR"),
  103. ("device_list_interfaces,interfaceType,802.11",
  104. "status,COMPLETE,interfaceType,802.11,interfaceID," + dev[0].ifname) ]
  105. for cmd, response in tests:
  106. res = sigma_dut_cmd(cmd)
  107. if response not in res:
  108. raise Exception("Unexpected %s response: %s" % (cmd, res))
  109. stop_sigma_dut(sigma)
  110. def test_sigma_dut_open(dev, apdev):
  111. """sigma_dut controlled open network association"""
  112. try:
  113. run_sigma_dut_open(dev, apdev)
  114. finally:
  115. dev[0].set("ignore_old_scan_res", "0")
  116. def run_sigma_dut_open(dev, apdev):
  117. ifname = dev[0].ifname
  118. sigma = start_sigma_dut(ifname)
  119. hapd = hostapd.add_ap(apdev[0], { "ssid": "open" })
  120. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  121. sigma_dut_cmd_check("sta_set_encryption,interface,%s,ssid,%s,encpType,none" % (ifname, "open"))
  122. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s" % (ifname, "open"))
  123. sigma_dut_wait_connected(ifname)
  124. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  125. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  126. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  127. stop_sigma_dut(sigma)
  128. def test_sigma_dut_psk_pmf(dev, apdev):
  129. """sigma_dut controlled PSK+PMF association"""
  130. try:
  131. run_sigma_dut_psk_pmf(dev, apdev)
  132. finally:
  133. dev[0].set("ignore_old_scan_res", "0")
  134. def run_sigma_dut_psk_pmf(dev, apdev):
  135. ifname = dev[0].ifname
  136. sigma = start_sigma_dut(ifname)
  137. ssid = "test-pmf-required"
  138. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  139. params["wpa_key_mgmt"] = "WPA-PSK-SHA256"
  140. params["ieee80211w"] = "2"
  141. hapd = hostapd.add_ap(apdev[0], params)
  142. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
  143. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  144. 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"))
  145. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-pmf-required"))
  146. sigma_dut_wait_connected(ifname)
  147. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  148. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  149. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  150. stop_sigma_dut(sigma)
  151. def test_sigma_dut_psk_pmf_bip_cmac_128(dev, apdev):
  152. """sigma_dut controlled PSK+PMF association with BIP-CMAC-128"""
  153. try:
  154. run_sigma_dut_psk_pmf_cipher(dev, apdev, "BIP-CMAC-128", "AES-128-CMAC")
  155. finally:
  156. dev[0].set("ignore_old_scan_res", "0")
  157. def test_sigma_dut_psk_pmf_bip_cmac_256(dev, apdev):
  158. """sigma_dut controlled PSK+PMF association with BIP-CMAC-256"""
  159. try:
  160. run_sigma_dut_psk_pmf_cipher(dev, apdev, "BIP-CMAC-256", "BIP-CMAC-256")
  161. finally:
  162. dev[0].set("ignore_old_scan_res", "0")
  163. def test_sigma_dut_psk_pmf_bip_gmac_128(dev, apdev):
  164. """sigma_dut controlled PSK+PMF association with BIP-GMAC-128"""
  165. try:
  166. run_sigma_dut_psk_pmf_cipher(dev, apdev, "BIP-GMAC-128", "BIP-GMAC-128")
  167. finally:
  168. dev[0].set("ignore_old_scan_res", "0")
  169. def test_sigma_dut_psk_pmf_bip_gmac_256(dev, apdev):
  170. """sigma_dut controlled PSK+PMF association with BIP-GMAC-256"""
  171. try:
  172. run_sigma_dut_psk_pmf_cipher(dev, apdev, "BIP-GMAC-256", "BIP-GMAC-256")
  173. finally:
  174. dev[0].set("ignore_old_scan_res", "0")
  175. def test_sigma_dut_psk_pmf_bip_gmac_256_mismatch(dev, apdev):
  176. """sigma_dut controlled PSK+PMF association with BIP-GMAC-256 mismatch"""
  177. try:
  178. run_sigma_dut_psk_pmf_cipher(dev, apdev, "BIP-GMAC-256", "AES-128-CMAC",
  179. failure=True)
  180. finally:
  181. dev[0].set("ignore_old_scan_res", "0")
  182. def run_sigma_dut_psk_pmf_cipher(dev, apdev, sigma_cipher, hostapd_cipher,
  183. failure=False):
  184. ifname = dev[0].ifname
  185. sigma = start_sigma_dut(ifname)
  186. ssid = "test-pmf-required"
  187. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  188. params["wpa_key_mgmt"] = "WPA-PSK-SHA256"
  189. params["ieee80211w"] = "2"
  190. params["group_mgmt_cipher"] = hostapd_cipher
  191. hapd = hostapd.add_ap(apdev[0], params)
  192. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
  193. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  194. 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))
  195. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-pmf-required"))
  196. if failure:
  197. ev = dev[0].wait_event(["CTRL-EVENT-NETWORK-NOT-FOUND",
  198. "CTRL-EVENT-CONNECTED"], timeout=10)
  199. if ev is None:
  200. raise Exception("Network selection result not indicated")
  201. if "CTRL-EVENT-CONNECTED" in ev:
  202. raise Exception("Unexpected connection")
  203. res = sigma_dut_cmd("sta_is_connected,interface," + ifname)
  204. if "connected,1" in res:
  205. raise Exception("Connection reported")
  206. else:
  207. sigma_dut_wait_connected(ifname)
  208. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  209. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  210. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  211. stop_sigma_dut(sigma)
  212. def test_sigma_dut_sae(dev, apdev):
  213. """sigma_dut controlled SAE association"""
  214. if "SAE" not in dev[0].get_capability("auth_alg"):
  215. raise HwsimSkip("SAE not supported")
  216. ifname = dev[0].ifname
  217. sigma = start_sigma_dut(ifname)
  218. ssid = "test-sae"
  219. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  220. params['wpa_key_mgmt'] = 'SAE'
  221. hapd = hostapd.add_ap(apdev[0], params)
  222. sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
  223. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  224. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", "12345678"))
  225. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"))
  226. sigma_dut_wait_connected(ifname)
  227. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  228. if dev[0].get_status_field('sae_group') != '19':
  229. raise Exception("Expected default SAE group not used")
  230. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  231. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  232. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  233. 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"))
  234. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"))
  235. sigma_dut_wait_connected(ifname)
  236. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  237. if dev[0].get_status_field('sae_group') != '20':
  238. raise Exception("Expected SAE group not used")
  239. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  240. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  241. stop_sigma_dut(sigma)
  242. def test_sigma_dut_sae_password(dev, apdev):
  243. """sigma_dut controlled SAE association and long password"""
  244. if "SAE" not in dev[0].get_capability("auth_alg"):
  245. raise HwsimSkip("SAE not supported")
  246. ifname = dev[0].ifname
  247. sigma = start_sigma_dut(ifname)
  248. try:
  249. ssid = "test-sae"
  250. params = hostapd.wpa2_params(ssid=ssid)
  251. params['sae_password'] = 100*'B'
  252. params['wpa_key_mgmt'] = 'SAE'
  253. hapd = hostapd.add_ap(apdev[0], params)
  254. sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
  255. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  256. 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'))
  257. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"))
  258. sigma_dut_wait_connected(ifname)
  259. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  260. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  261. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  262. finally:
  263. stop_sigma_dut(sigma)
  264. def test_sigma_dut_sta_override_rsne(dev, apdev):
  265. """sigma_dut and RSNE override on STA"""
  266. try:
  267. run_sigma_dut_sta_override_rsne(dev, apdev)
  268. finally:
  269. dev[0].set("ignore_old_scan_res", "0")
  270. def run_sigma_dut_sta_override_rsne(dev, apdev):
  271. ifname = dev[0].ifname
  272. sigma = start_sigma_dut(ifname)
  273. ssid = "test-psk"
  274. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  275. hapd = hostapd.add_ap(apdev[0], params)
  276. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  277. tests = [ "30120100000fac040100000fac040100000fac02",
  278. "30140100000fac040100000fac040100000fac02ffff" ]
  279. for test in tests:
  280. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,type,PSK,passphrase,%s,EncpType,aes-ccmp,KeyMgmtType,wpa2" % (ifname, "test-psk", "12345678"))
  281. sigma_dut_cmd_check("dev_configure_ie,interface,%s,IE_Name,RSNE,Contents,%s" % (ifname, test))
  282. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-psk"))
  283. sigma_dut_wait_connected(ifname)
  284. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  285. dev[0].dump_monitor()
  286. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,type,PSK,passphrase,%s,EncpType,aes-ccmp,KeyMgmtType,wpa2" % (ifname, "test-psk", "12345678"))
  287. sigma_dut_cmd_check("dev_configure_ie,interface,%s,IE_Name,RSNE,Contents,300101" % ifname)
  288. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-psk"))
  289. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  290. if ev is None:
  291. raise Exception("Association rejection not reported")
  292. if "status_code=40" not in ev:
  293. raise Exception("Unexpected status code: " + ev)
  294. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  295. stop_sigma_dut(sigma)
  296. def test_sigma_dut_ap_psk(dev, apdev):
  297. """sigma_dut controlled AP"""
  298. with HWSimRadio() as (radio, iface):
  299. sigma = start_sigma_dut(iface)
  300. try:
  301. sigma_dut_cmd_check("ap_reset_default")
  302. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
  303. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678")
  304. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  305. dev[0].connect("test-psk", psk="12345678", scan_freq="2412")
  306. sigma_dut_cmd_check("ap_reset_default")
  307. finally:
  308. stop_sigma_dut(sigma)
  309. def test_sigma_dut_ap_pskhex(dev, apdev, params):
  310. """sigma_dut controlled AP and PSKHEX"""
  311. logdir = os.path.join(params['logdir'],
  312. "sigma_dut_ap_pskhex.sigma-hostapd")
  313. with HWSimRadio() as (radio, iface):
  314. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  315. try:
  316. psk = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
  317. sigma_dut_cmd_check("ap_reset_default")
  318. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
  319. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSKHEX," + psk)
  320. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  321. dev[0].connect("test-psk", raw_psk=psk, scan_freq="2412")
  322. sigma_dut_cmd_check("ap_reset_default")
  323. finally:
  324. stop_sigma_dut(sigma)
  325. def test_sigma_dut_suite_b(dev, apdev, params):
  326. """sigma_dut controlled STA Suite B"""
  327. check_suite_b_192_capa(dev)
  328. logdir = params['logdir']
  329. with open("auth_serv/ec2-ca.pem", "r") as f:
  330. with open(os.path.join(logdir, "suite_b_ca.pem"), "w") as f2:
  331. f2.write(f.read())
  332. with open("auth_serv/ec2-user.pem", "r") as f:
  333. with open("auth_serv/ec2-user.key", "r") as f2:
  334. with open(os.path.join(logdir, "suite_b.pem"), "w") as f3:
  335. f3.write(f.read())
  336. f3.write(f2.read())
  337. dev[0].flush_scan_cache()
  338. params = suite_b_as_params()
  339. params['ca_cert'] = 'auth_serv/ec2-ca.pem'
  340. params['server_cert'] = 'auth_serv/ec2-server.pem'
  341. params['private_key'] = 'auth_serv/ec2-server.key'
  342. params['openssl_ciphers'] = 'SUITEB192'
  343. hostapd.add_ap(apdev[1], params)
  344. params = { "ssid": "test-suite-b",
  345. "wpa": "2",
  346. "wpa_key_mgmt": "WPA-EAP-SUITE-B-192",
  347. "rsn_pairwise": "GCMP-256",
  348. "group_mgmt_cipher": "BIP-GMAC-256",
  349. "ieee80211w": "2",
  350. "ieee8021x": "1",
  351. 'auth_server_addr': "127.0.0.1",
  352. 'auth_server_port': "18129",
  353. 'auth_server_shared_secret': "radius",
  354. 'nas_identifier': "nas.w1.fi" }
  355. hapd = hostapd.add_ap(apdev[0], params)
  356. ifname = dev[0].ifname
  357. sigma = start_sigma_dut(ifname, cert_path=logdir)
  358. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
  359. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  360. 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"))
  361. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-suite-b"))
  362. sigma_dut_wait_connected(ifname)
  363. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  364. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  365. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  366. stop_sigma_dut(sigma)
  367. def test_sigma_dut_suite_b_rsa(dev, apdev, params):
  368. """sigma_dut controlled STA Suite B (RSA)"""
  369. check_suite_b_192_capa(dev)
  370. logdir = params['logdir']
  371. with open("auth_serv/rsa3072-ca.pem", "r") as f:
  372. with open(os.path.join(logdir, "suite_b_ca_rsa.pem"), "w") as f2:
  373. f2.write(f.read())
  374. with open("auth_serv/rsa3072-user.pem", "r") as f:
  375. with open("auth_serv/rsa3072-user.key", "r") as f2:
  376. with open(os.path.join(logdir, "suite_b_rsa.pem"), "w") as f3:
  377. f3.write(f.read())
  378. f3.write(f2.read())
  379. dev[0].flush_scan_cache()
  380. params = suite_b_192_rsa_ap_params()
  381. hapd = hostapd.add_ap(apdev[0], params)
  382. ifname = dev[0].ifname
  383. sigma = start_sigma_dut(ifname, cert_path=logdir)
  384. 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")
  385. tests = [ "",
  386. ",TLSCipher,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
  387. ",TLSCipher,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" ]
  388. for extra in tests:
  389. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
  390. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  391. sigma_dut_cmd_check(cmd + extra)
  392. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-suite-b"))
  393. sigma_dut_wait_connected(ifname)
  394. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  395. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  396. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  397. stop_sigma_dut(sigma)
  398. def test_sigma_dut_ap_suite_b(dev, apdev, params):
  399. """sigma_dut controlled AP Suite B"""
  400. check_suite_b_192_capa(dev)
  401. logdir = os.path.join(params['logdir'],
  402. "sigma_dut_ap_suite_b.sigma-hostapd")
  403. params = suite_b_as_params()
  404. params['ca_cert'] = 'auth_serv/ec2-ca.pem'
  405. params['server_cert'] = 'auth_serv/ec2-server.pem'
  406. params['private_key'] = 'auth_serv/ec2-server.key'
  407. params['openssl_ciphers'] = 'SUITEB192'
  408. hostapd.add_ap(apdev[1], params)
  409. with HWSimRadio() as (radio, iface):
  410. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  411. try:
  412. sigma_dut_cmd_check("ap_reset_default")
  413. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-suite-b,MODE,11ng")
  414. sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,18129,PASSWORD,radius")
  415. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,SuiteB,PMF,Required")
  416. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  417. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
  418. ieee80211w="2",
  419. openssl_ciphers="SUITEB192",
  420. eap="TLS", identity="tls user",
  421. ca_cert="auth_serv/ec2-ca.pem",
  422. client_cert="auth_serv/ec2-user.pem",
  423. private_key="auth_serv/ec2-user.key",
  424. pairwise="GCMP-256", group="GCMP-256",
  425. scan_freq="2412")
  426. sigma_dut_cmd_check("ap_reset_default")
  427. finally:
  428. stop_sigma_dut(sigma)
  429. def test_sigma_dut_ap_cipher_gcmp_128(dev, apdev, params):
  430. """sigma_dut controlled AP with GCMP-128/BIP-GMAC-128 cipher"""
  431. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-GCMP-128", "BIP-GMAC-128",
  432. "GCMP")
  433. def test_sigma_dut_ap_cipher_gcmp_256(dev, apdev, params):
  434. """sigma_dut controlled AP with GCMP-256/BIP-GMAC-256 cipher"""
  435. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-GCMP-256", "BIP-GMAC-256",
  436. "GCMP-256")
  437. def test_sigma_dut_ap_cipher_ccmp_128(dev, apdev, params):
  438. """sigma_dut controlled AP with CCMP-128/BIP-CMAC-128 cipher"""
  439. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-128", "BIP-CMAC-128",
  440. "CCMP")
  441. def test_sigma_dut_ap_cipher_ccmp_256(dev, apdev, params):
  442. """sigma_dut controlled AP with CCMP-256/BIP-CMAC-256 cipher"""
  443. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-256", "BIP-CMAC-256",
  444. "CCMP-256")
  445. def test_sigma_dut_ap_cipher_ccmp_gcmp_1(dev, apdev, params):
  446. """sigma_dut controlled AP with CCMP-128+GCMP-256 ciphers (1)"""
  447. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-128 AES-GCMP-256",
  448. "BIP-GMAC-256", "CCMP")
  449. def test_sigma_dut_ap_cipher_ccmp_gcmp_2(dev, apdev, params):
  450. """sigma_dut controlled AP with CCMP-128+GCMP-256 ciphers (2)"""
  451. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-128 AES-GCMP-256",
  452. "BIP-GMAC-256", "GCMP-256", "CCMP")
  453. def test_sigma_dut_ap_cipher_gcmp_256_group_ccmp(dev, apdev, params):
  454. """sigma_dut controlled AP with GCMP-256/CCMP/BIP-GMAC-256 cipher"""
  455. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-GCMP-256", "BIP-GMAC-256",
  456. "GCMP-256", "CCMP", "AES-CCMP-128")
  457. def run_sigma_dut_ap_cipher(dev, apdev, params, ap_pairwise, ap_group_mgmt,
  458. sta_cipher, sta_cipher_group=None, ap_group=None):
  459. check_suite_b_192_capa(dev)
  460. logdir = os.path.join(params['logdir'],
  461. "sigma_dut_ap_cipher.sigma-hostapd")
  462. params = suite_b_as_params()
  463. params['ca_cert'] = 'auth_serv/ec2-ca.pem'
  464. params['server_cert'] = 'auth_serv/ec2-server.pem'
  465. params['private_key'] = 'auth_serv/ec2-server.key'
  466. params['openssl_ciphers'] = 'SUITEB192'
  467. hostapd.add_ap(apdev[1], params)
  468. with HWSimRadio() as (radio, iface):
  469. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  470. try:
  471. sigma_dut_cmd_check("ap_reset_default")
  472. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-suite-b,MODE,11ng")
  473. sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,18129,PASSWORD,radius")
  474. cmd = "ap_set_security,NAME,AP,KEYMGNT,SuiteB,PMF,Required,PairwiseCipher,%s,GroupMgntCipher,%s" % (ap_pairwise, ap_group_mgmt)
  475. if ap_group:
  476. cmd += ",GroupCipher,%s" % ap_group
  477. sigma_dut_cmd_check(cmd)
  478. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  479. if sta_cipher_group is None:
  480. sta_cipher_group = sta_cipher
  481. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
  482. ieee80211w="2",
  483. openssl_ciphers="SUITEB192",
  484. eap="TLS", identity="tls user",
  485. ca_cert="auth_serv/ec2-ca.pem",
  486. client_cert="auth_serv/ec2-user.pem",
  487. private_key="auth_serv/ec2-user.key",
  488. pairwise=sta_cipher, group=sta_cipher_group,
  489. scan_freq="2412")
  490. sigma_dut_cmd_check("ap_reset_default")
  491. finally:
  492. stop_sigma_dut(sigma)
  493. def test_sigma_dut_ap_override_rsne(dev, apdev):
  494. """sigma_dut controlled AP overriding RSNE"""
  495. with HWSimRadio() as (radio, iface):
  496. sigma = start_sigma_dut(iface)
  497. try:
  498. sigma_dut_cmd_check("ap_reset_default")
  499. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
  500. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678")
  501. sigma_dut_cmd_check("dev_configure_ie,NAME,AP,interface,%s,IE_Name,RSNE,Contents,30180100000fac040200ffffffff000fac040100000fac020c00" % iface)
  502. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  503. dev[0].connect("test-psk", psk="12345678", scan_freq="2412")
  504. sigma_dut_cmd_check("ap_reset_default")
  505. finally:
  506. stop_sigma_dut(sigma)
  507. def test_sigma_dut_ap_sae(dev, apdev):
  508. """sigma_dut controlled AP with SAE"""
  509. with HWSimRadio() as (radio, iface):
  510. sigma = start_sigma_dut(iface)
  511. try:
  512. sigma_dut_cmd_check("ap_reset_default")
  513. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  514. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678")
  515. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  516. dev[0].request("SET sae_groups ")
  517. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  518. scan_freq="2412")
  519. if dev[0].get_status_field('sae_group') != '19':
  520. raise Exception("Expected default SAE group not used")
  521. sigma_dut_cmd_check("ap_reset_default")
  522. finally:
  523. stop_sigma_dut(sigma)
  524. def test_sigma_dut_ap_sae_password(dev, apdev):
  525. """sigma_dut controlled AP with SAE and long password"""
  526. with HWSimRadio() as (radio, iface):
  527. sigma = start_sigma_dut(iface)
  528. try:
  529. sigma_dut_cmd_check("ap_reset_default")
  530. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  531. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK," + 100*'C')
  532. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  533. dev[0].request("SET sae_groups ")
  534. dev[0].connect("test-sae", key_mgmt="SAE", sae_password=100*'C',
  535. scan_freq="2412")
  536. if dev[0].get_status_field('sae_group') != '19':
  537. raise Exception("Expected default SAE group not used")
  538. sigma_dut_cmd_check("ap_reset_default")
  539. finally:
  540. stop_sigma_dut(sigma)
  541. def test_sigma_dut_ap_sae_group(dev, apdev):
  542. """sigma_dut controlled AP with SAE and specific group"""
  543. with HWSimRadio() as (radio, iface):
  544. sigma = start_sigma_dut(iface)
  545. try:
  546. sigma_dut_cmd_check("ap_reset_default")
  547. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  548. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,ECGroupID,20")
  549. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  550. dev[0].request("SET sae_groups ")
  551. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  552. scan_freq="2412")
  553. if dev[0].get_status_field('sae_group') != '20':
  554. raise Exception("Expected SAE group not used")
  555. sigma_dut_cmd_check("ap_reset_default")
  556. finally:
  557. stop_sigma_dut(sigma)
  558. def test_sigma_dut_ap_psk_sae(dev, apdev):
  559. """sigma_dut controlled AP with PSK+SAE"""
  560. with HWSimRadio() as (radio, iface):
  561. sigma = start_sigma_dut(iface)
  562. try:
  563. sigma_dut_cmd_check("ap_reset_default")
  564. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  565. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK-SAE,PSK,12345678")
  566. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  567. dev[0].request("SET sae_groups ")
  568. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  569. scan_freq="2412")
  570. dev[1].connect("test-sae", psk="12345678", scan_freq="2412")
  571. sigma_dut_cmd_check("ap_reset_default")
  572. finally:
  573. stop_sigma_dut(sigma)
  574. def test_sigma_dut_owe(dev, apdev):
  575. """sigma_dut controlled OWE station"""
  576. try:
  577. run_sigma_dut_owe(dev, apdev)
  578. finally:
  579. dev[0].set("ignore_old_scan_res", "0")
  580. def run_sigma_dut_owe(dev, apdev):
  581. if "OWE" not in dev[0].get_capability("key_mgmt"):
  582. raise HwsimSkip("OWE not supported")
  583. ifname = dev[0].ifname
  584. sigma = start_sigma_dut(ifname)
  585. try:
  586. params = { "ssid": "owe",
  587. "wpa": "2",
  588. "wpa_key_mgmt": "OWE",
  589. "rsn_pairwise": "CCMP" }
  590. hapd = hostapd.add_ap(apdev[0], params)
  591. bssid = hapd.own_addr()
  592. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  593. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  594. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE" % ifname)
  595. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  596. sigma_dut_wait_connected(ifname)
  597. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  598. dev[0].dump_monitor()
  599. sigma_dut_cmd("sta_reassoc,interface,%s,Channel,1,bssid,%s" % (ifname, bssid))
  600. dev[0].wait_connected()
  601. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  602. dev[0].wait_disconnected()
  603. dev[0].dump_monitor()
  604. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  605. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  606. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,20" % ifname)
  607. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  608. sigma_dut_wait_connected(ifname)
  609. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  610. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  611. dev[0].wait_disconnected()
  612. dev[0].dump_monitor()
  613. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  614. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  615. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,0" % ifname)
  616. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  617. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  618. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  619. if ev is None:
  620. raise Exception("Association not rejected")
  621. if "status_code=77" not in ev:
  622. raise Exception("Unexpected rejection reason: " + ev)
  623. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  624. finally:
  625. stop_sigma_dut(sigma)
  626. def test_sigma_dut_ap_owe(dev, apdev):
  627. """sigma_dut controlled AP with OWE"""
  628. if "OWE" not in dev[0].get_capability("key_mgmt"):
  629. raise HwsimSkip("OWE not supported")
  630. with HWSimRadio() as (radio, iface):
  631. sigma = start_sigma_dut(iface)
  632. try:
  633. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  634. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
  635. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE")
  636. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  637. dev[0].connect("owe", key_mgmt="OWE", scan_freq="2412")
  638. sigma_dut_cmd_check("ap_reset_default")
  639. finally:
  640. stop_sigma_dut(sigma)
  641. def test_sigma_dut_ap_owe_ecgroupid(dev, apdev):
  642. """sigma_dut controlled AP with OWE and ECGroupID"""
  643. if "OWE" not in dev[0].get_capability("key_mgmt"):
  644. raise HwsimSkip("OWE not supported")
  645. with HWSimRadio() as (radio, iface):
  646. sigma = start_sigma_dut(iface)
  647. try:
  648. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  649. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
  650. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE,ECGroupID,20 21,PMF,Required")
  651. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  652. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  653. owe_group="20", scan_freq="2412")
  654. dev[0].request("REMOVE_NETWORK all")
  655. dev[0].wait_disconnected()
  656. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  657. owe_group="21", scan_freq="2412")
  658. dev[0].request("REMOVE_NETWORK all")
  659. dev[0].wait_disconnected()
  660. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  661. owe_group="19", scan_freq="2412", wait_connect=False)
  662. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  663. dev[0].request("DISCONNECT")
  664. if ev is None:
  665. raise Exception("Association not rejected")
  666. if "status_code=77" not in ev:
  667. raise Exception("Unexpected rejection reason: " + ev)
  668. dev[0].dump_monitor()
  669. sigma_dut_cmd_check("ap_reset_default")
  670. finally:
  671. stop_sigma_dut(sigma)
  672. def test_sigma_dut_ap_owe_transition_mode(dev, apdev, params):
  673. """sigma_dut controlled AP with OWE and transition mode"""
  674. if "OWE" not in dev[0].get_capability("key_mgmt"):
  675. raise HwsimSkip("OWE not supported")
  676. logdir = os.path.join(params['logdir'],
  677. "sigma_dut_ap_owe_transition_mode.sigma-hostapd")
  678. with HWSimRadio() as (radio, iface):
  679. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  680. try:
  681. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  682. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,1,CHANNEL,1,SSID,owe,MODE,11ng")
  683. sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,1,KEYMGNT,OWE")
  684. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,2,CHANNEL,1,SSID,owe,MODE,11ng")
  685. sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,2,KEYMGNT,NONE")
  686. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  687. res1 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,1,Interface,24G")
  688. res2 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,2,Interface,24G")
  689. dev[0].connect("owe", key_mgmt="OWE", scan_freq="2412")
  690. dev[1].connect("owe", key_mgmt="NONE", scan_freq="2412")
  691. if dev[0].get_status_field('bssid') not in res1:
  692. raise Exception("Unexpected ap_get_mac_address WLAN_TAG,1: " + res1)
  693. if dev[1].get_status_field('bssid') not in res2:
  694. raise Exception("Unexpected ap_get_mac_address WLAN_TAG,2: " + res2)
  695. sigma_dut_cmd_check("ap_reset_default")
  696. finally:
  697. stop_sigma_dut(sigma)
  698. def dpp_init_enrollee(dev, id1):
  699. logger.info("Starting DPP initiator/enrollee in a thread")
  700. time.sleep(1)
  701. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  702. if "OK" not in dev.request(cmd):
  703. raise Exception("Failed to initiate DPP Authentication")
  704. ev = dev.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  705. if ev is None:
  706. raise Exception("DPP configuration not completed (Enrollee)")
  707. logger.info("DPP initiator/enrollee done")
  708. def test_sigma_dut_dpp_qr_resp_1(dev, apdev):
  709. """sigma_dut DPP/QR responder (conf index 1)"""
  710. run_sigma_dut_dpp_qr_resp(dev, apdev, 1)
  711. def test_sigma_dut_dpp_qr_resp_2(dev, apdev):
  712. """sigma_dut DPP/QR responder (conf index 2)"""
  713. run_sigma_dut_dpp_qr_resp(dev, apdev, 2)
  714. def test_sigma_dut_dpp_qr_resp_3(dev, apdev):
  715. """sigma_dut DPP/QR responder (conf index 3)"""
  716. run_sigma_dut_dpp_qr_resp(dev, apdev, 3)
  717. def test_sigma_dut_dpp_qr_resp_4(dev, apdev):
  718. """sigma_dut DPP/QR responder (conf index 4)"""
  719. run_sigma_dut_dpp_qr_resp(dev, apdev, 4)
  720. def test_sigma_dut_dpp_qr_resp_chan_list(dev, apdev):
  721. """sigma_dut DPP/QR responder (channel list override)"""
  722. run_sigma_dut_dpp_qr_resp(dev, apdev, 1, chan_list='81/2 81/6 81/1',
  723. listen_chan=2)
  724. def run_sigma_dut_dpp_qr_resp(dev, apdev, conf_idx, chan_list=None,
  725. listen_chan=None):
  726. check_dpp_capab(dev[0])
  727. check_dpp_capab(dev[1])
  728. sigma = start_sigma_dut(dev[0].ifname)
  729. try:
  730. cmd = "dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR"
  731. if chan_list:
  732. cmd += ",DPPChannelList," + chan_list
  733. res = sigma_dut_cmd(cmd)
  734. if "status,COMPLETE" not in res:
  735. raise Exception("dev_exec_action did not succeed: " + res)
  736. hex = res.split(',')[3]
  737. uri = hex.decode('hex')
  738. logger.info("URI from sigma_dut: " + uri)
  739. res = dev[1].request("DPP_QR_CODE " + uri)
  740. if "FAIL" in res:
  741. raise Exception("Failed to parse QR Code URI")
  742. id1 = int(res)
  743. t = threading.Thread(target=dpp_init_enrollee, args=(dev[1], id1))
  744. t.start()
  745. cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPConfIndex,%d,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfEnrolleeRole,STA,DPPSigningKeyECC,P-256,DPPBS,QR,DPPTimeout,6" % conf_idx
  746. if listen_chan:
  747. cmd += ",DPPListenChannel," + str(listen_chan)
  748. res = sigma_dut_cmd(cmd, timeout=10)
  749. t.join()
  750. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  751. raise Exception("Unexpected result: " + res)
  752. finally:
  753. stop_sigma_dut(sigma)
  754. def test_sigma_dut_dpp_qr_init_enrollee(dev, apdev):
  755. """sigma_dut DPP/QR initiator as Enrollee"""
  756. check_dpp_capab(dev[0])
  757. check_dpp_capab(dev[1])
  758. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  759. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  760. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  761. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  762. params = { "ssid": "DPPNET01",
  763. "wpa": "2",
  764. "wpa_key_mgmt": "DPP",
  765. "rsn_pairwise": "CCMP",
  766. "dpp_connector": ap_connector,
  767. "dpp_csign": csign_pub,
  768. "dpp_netaccesskey": ap_netaccesskey }
  769. try:
  770. hapd = hostapd.add_ap(apdev[0], params)
  771. except:
  772. raise HwsimSkip("DPP not supported")
  773. sigma = start_sigma_dut(dev[0].ifname)
  774. try:
  775. dev[0].set("dpp_config_processing", "2")
  776. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  777. res = dev[1].request(cmd);
  778. if "FAIL" in res:
  779. raise Exception("Failed to add configurator")
  780. conf_id = int(res)
  781. addr = dev[1].own_addr().replace(':', '')
  782. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  783. res = dev[1].request(cmd)
  784. if "FAIL" in res:
  785. raise Exception("Failed to generate bootstrapping info")
  786. id0 = int(res)
  787. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  788. dev[1].set("dpp_configurator_params",
  789. " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id));
  790. cmd = "DPP_LISTEN 2437 role=configurator"
  791. if "OK" not in dev[1].request(cmd):
  792. raise Exception("Failed to start listen operation")
  793. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  794. if "status,COMPLETE" not in res:
  795. raise Exception("dev_exec_action did not succeed: " + res)
  796. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6,DPPWaitForConnect,Yes", timeout=10)
  797. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  798. raise Exception("Unexpected result: " + res)
  799. finally:
  800. dev[0].set("dpp_config_processing", "0")
  801. stop_sigma_dut(sigma)
  802. def test_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev):
  803. """sigma_dut DPP/QR (mutual) initiator as Enrollee"""
  804. check_dpp_capab(dev[0])
  805. check_dpp_capab(dev[1])
  806. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  807. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  808. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  809. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  810. params = { "ssid": "DPPNET01",
  811. "wpa": "2",
  812. "wpa_key_mgmt": "DPP",
  813. "rsn_pairwise": "CCMP",
  814. "dpp_connector": ap_connector,
  815. "dpp_csign": csign_pub,
  816. "dpp_netaccesskey": ap_netaccesskey }
  817. try:
  818. hapd = hostapd.add_ap(apdev[0], params)
  819. except:
  820. raise HwsimSkip("DPP not supported")
  821. sigma = start_sigma_dut(dev[0].ifname)
  822. try:
  823. dev[0].set("dpp_config_processing", "2")
  824. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  825. res = dev[1].request(cmd);
  826. if "FAIL" in res:
  827. raise Exception("Failed to add configurator")
  828. conf_id = int(res)
  829. addr = dev[1].own_addr().replace(':', '')
  830. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  831. res = dev[1].request(cmd)
  832. if "FAIL" in res:
  833. raise Exception("Failed to generate bootstrapping info")
  834. id0 = int(res)
  835. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  836. dev[1].set("dpp_configurator_params",
  837. " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id));
  838. cmd = "DPP_LISTEN 2437 role=configurator qr=mutual"
  839. if "OK" not in dev[1].request(cmd):
  840. raise Exception("Failed to start listen operation")
  841. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  842. if "status,COMPLETE" not in res:
  843. raise Exception("dev_exec_action did not succeed: " + res)
  844. hex = res.split(',')[3]
  845. uri = hex.decode('hex')
  846. logger.info("URI from sigma_dut: " + uri)
  847. res = dev[1].request("DPP_QR_CODE " + uri)
  848. if "FAIL" in res:
  849. raise Exception("Failed to parse QR Code URI")
  850. id1 = int(res)
  851. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  852. if "status,COMPLETE" not in res:
  853. raise Exception("dev_exec_action did not succeed: " + res)
  854. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6,DPPWaitForConnect,Yes", timeout=10)
  855. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  856. raise Exception("Unexpected result: " + res)
  857. finally:
  858. dev[0].set("dpp_config_processing", "0")
  859. stop_sigma_dut(sigma)
  860. def dpp_init_conf_mutual(dev, id1, conf_id, own_id=None):
  861. time.sleep(1)
  862. logger.info("Starting DPP initiator/configurator in a thread")
  863. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp ssid=%s configurator=%d" % (id1, "DPPNET01".encode("hex"), conf_id)
  864. if own_id is not None:
  865. cmd += " own=%d" % own_id
  866. if "OK" not in dev.request(cmd):
  867. raise Exception("Failed to initiate DPP Authentication")
  868. ev = dev.wait_event(["DPP-CONF-SENT"], timeout=10)
  869. if ev is None:
  870. raise Exception("DPP configuration not completed (Configurator)")
  871. logger.info("DPP initiator/configurator done")
  872. def test_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev):
  873. """sigma_dut DPP/QR (mutual) responder as Enrollee"""
  874. run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev)
  875. def test_sigma_dut_dpp_qr_mutual_resp_enrollee_pending(dev, apdev):
  876. """sigma_dut DPP/QR (mutual) responder as Enrollee (response pending)"""
  877. run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev, ',DPPDelayQRResponse,1')
  878. def run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev, extra=None):
  879. check_dpp_capab(dev[0])
  880. check_dpp_capab(dev[1])
  881. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  882. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  883. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  884. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  885. params = { "ssid": "DPPNET01",
  886. "wpa": "2",
  887. "wpa_key_mgmt": "DPP",
  888. "rsn_pairwise": "CCMP",
  889. "dpp_connector": ap_connector,
  890. "dpp_csign": csign_pub,
  891. "dpp_netaccesskey": ap_netaccesskey }
  892. try:
  893. hapd = hostapd.add_ap(apdev[0], params)
  894. except:
  895. raise HwsimSkip("DPP not supported")
  896. sigma = start_sigma_dut(dev[0].ifname)
  897. try:
  898. dev[0].set("dpp_config_processing", "2")
  899. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  900. res = dev[1].request(cmd);
  901. if "FAIL" in res:
  902. raise Exception("Failed to add configurator")
  903. conf_id = int(res)
  904. addr = dev[1].own_addr().replace(':', '')
  905. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  906. res = dev[1].request(cmd)
  907. if "FAIL" in res:
  908. raise Exception("Failed to generate bootstrapping info")
  909. id0 = int(res)
  910. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  911. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  912. if "status,COMPLETE" not in res:
  913. raise Exception("dev_exec_action did not succeed: " + res)
  914. hex = res.split(',')[3]
  915. uri = hex.decode('hex')
  916. logger.info("URI from sigma_dut: " + uri)
  917. res = dev[1].request("DPP_QR_CODE " + uri)
  918. if "FAIL" in res:
  919. raise Exception("Failed to parse QR Code URI")
  920. id1 = int(res)
  921. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  922. if "status,COMPLETE" not in res:
  923. raise Exception("dev_exec_action did not succeed: " + res)
  924. t = threading.Thread(target=dpp_init_conf_mutual,
  925. args=(dev[1], id1, conf_id, id0))
  926. t.start()
  927. cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,20,DPPWaitForConnect,Yes"
  928. if extra:
  929. cmd += extra
  930. res = sigma_dut_cmd(cmd, timeout=25)
  931. t.join()
  932. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  933. raise Exception("Unexpected result: " + res)
  934. finally:
  935. dev[0].set("dpp_config_processing", "0")
  936. stop_sigma_dut(sigma)
  937. def dpp_resp_conf_mutual(dev, conf_id, uri):
  938. logger.info("Starting DPP responder/configurator in a thread")
  939. dev.set("dpp_configurator_params",
  940. " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id));
  941. cmd = "DPP_LISTEN 2437 role=configurator qr=mutual"
  942. if "OK" not in dev.request(cmd):
  943. raise Exception("Failed to initiate DPP listen")
  944. if uri:
  945. ev = dev.wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=10)
  946. if ev is None:
  947. raise Exception("QR Code scan for mutual authentication not requested")
  948. res = dev.request("DPP_QR_CODE " + uri)
  949. if "FAIL" in res:
  950. raise Exception("Failed to parse QR Code URI")
  951. ev = dev.wait_event(["DPP-CONF-SENT"], timeout=10)
  952. if ev is None:
  953. raise Exception("DPP configuration not completed (Configurator)")
  954. logger.info("DPP responder/configurator done")
  955. def test_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev):
  956. """sigma_dut DPP/QR (mutual) initiator as Enrollee"""
  957. run_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev, False)
  958. def test_sigma_dut_dpp_qr_mutual_init_enrollee_pending(dev, apdev):
  959. """sigma_dut DPP/QR (mutual) initiator as Enrollee (response pending)"""
  960. run_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev, True)
  961. def run_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev, resp_pending):
  962. check_dpp_capab(dev[0])
  963. check_dpp_capab(dev[1])
  964. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  965. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  966. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  967. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  968. params = { "ssid": "DPPNET01",
  969. "wpa": "2",
  970. "wpa_key_mgmt": "DPP",
  971. "rsn_pairwise": "CCMP",
  972. "dpp_connector": ap_connector,
  973. "dpp_csign": csign_pub,
  974. "dpp_netaccesskey": ap_netaccesskey }
  975. try:
  976. hapd = hostapd.add_ap(apdev[0], params)
  977. except:
  978. raise HwsimSkip("DPP not supported")
  979. sigma = start_sigma_dut(dev[0].ifname)
  980. try:
  981. dev[0].set("dpp_config_processing", "2")
  982. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  983. res = dev[1].request(cmd);
  984. if "FAIL" in res:
  985. raise Exception("Failed to add configurator")
  986. conf_id = int(res)
  987. addr = dev[1].own_addr().replace(':', '')
  988. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  989. res = dev[1].request(cmd)
  990. if "FAIL" in res:
  991. raise Exception("Failed to generate bootstrapping info")
  992. id0 = int(res)
  993. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  994. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  995. if "status,COMPLETE" not in res:
  996. raise Exception("dev_exec_action did not succeed: " + res)
  997. hex = res.split(',')[3]
  998. uri = hex.decode('hex')
  999. logger.info("URI from sigma_dut: " + uri)
  1000. if not resp_pending:
  1001. res = dev[1].request("DPP_QR_CODE " + uri)
  1002. if "FAIL" in res:
  1003. raise Exception("Failed to parse QR Code URI")
  1004. uri = None
  1005. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1006. if "status,COMPLETE" not in res:
  1007. raise Exception("dev_exec_action did not succeed: " + res)
  1008. t = threading.Thread(target=dpp_resp_conf_mutual,
  1009. args=(dev[1], conf_id, uri))
  1010. t.start()
  1011. time.sleep(1)
  1012. cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,10,DPPWaitForConnect,Yes"
  1013. res = sigma_dut_cmd(cmd, timeout=15)
  1014. t.join()
  1015. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  1016. raise Exception("Unexpected result: " + res)
  1017. finally:
  1018. dev[0].set("dpp_config_processing", "0")
  1019. stop_sigma_dut(sigma)
  1020. def test_sigma_dut_dpp_qr_init_enrollee_psk(dev, apdev):
  1021. """sigma_dut DPP/QR initiator as Enrollee (PSK)"""
  1022. check_dpp_capab(dev[0])
  1023. check_dpp_capab(dev[1])
  1024. params = hostapd.wpa2_params(ssid="DPPNET01",
  1025. passphrase="ThisIsDppPassphrase")
  1026. hapd = hostapd.add_ap(apdev[0], params)
  1027. sigma = start_sigma_dut(dev[0].ifname)
  1028. try:
  1029. dev[0].set("dpp_config_processing", "2")
  1030. cmd = "DPP_CONFIGURATOR_ADD"
  1031. res = dev[1].request(cmd);
  1032. if "FAIL" in res:
  1033. raise Exception("Failed to add configurator")
  1034. conf_id = int(res)
  1035. addr = dev[1].own_addr().replace(':', '')
  1036. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1037. res = dev[1].request(cmd)
  1038. if "FAIL" in res:
  1039. raise Exception("Failed to generate bootstrapping info")
  1040. id0 = int(res)
  1041. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1042. dev[1].set("dpp_configurator_params",
  1043. " conf=sta-psk ssid=%s pass=%s configurator=%d" % ("DPPNET01".encode("hex"), "ThisIsDppPassphrase".encode("hex"), conf_id));
  1044. cmd = "DPP_LISTEN 2437 role=configurator"
  1045. if "OK" not in dev[1].request(cmd):
  1046. raise Exception("Failed to start listen operation")
  1047. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1048. if "status,COMPLETE" not in res:
  1049. raise Exception("dev_exec_action did not succeed: " + res)
  1050. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6,DPPWaitForConnect,Yes", timeout=10)
  1051. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkConnectResult,OK" not in res:
  1052. raise Exception("Unexpected result: " + res)
  1053. finally:
  1054. dev[0].set("dpp_config_processing", "0")
  1055. stop_sigma_dut(sigma)
  1056. def test_sigma_dut_dpp_qr_init_configurator_1(dev, apdev):
  1057. """sigma_dut DPP/QR initiator as Configurator (conf index 1)"""
  1058. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 1)
  1059. def test_sigma_dut_dpp_qr_init_configurator_2(dev, apdev):
  1060. """sigma_dut DPP/QR initiator as Configurator (conf index 2)"""
  1061. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 2)
  1062. def test_sigma_dut_dpp_qr_init_configurator_3(dev, apdev):
  1063. """sigma_dut DPP/QR initiator as Configurator (conf index 3)"""
  1064. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 3)
  1065. def test_sigma_dut_dpp_qr_init_configurator_4(dev, apdev):
  1066. """sigma_dut DPP/QR initiator as Configurator (conf index 4)"""
  1067. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 4)
  1068. def test_sigma_dut_dpp_qr_init_configurator_both(dev, apdev):
  1069. """sigma_dut DPP/QR initiator as Configurator or Enrollee (conf index 1)"""
  1070. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 1, "Both")
  1071. def test_sigma_dut_dpp_qr_init_configurator_neg_freq(dev, apdev):
  1072. """sigma_dut DPP/QR initiator as Configurator (neg_freq)"""
  1073. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 1, extra='DPPSubsequentChannel,81/11')
  1074. def run_sigma_dut_dpp_qr_init_configurator(dev, apdev, conf_idx,
  1075. prov_role="Configurator",
  1076. extra=None):
  1077. check_dpp_capab(dev[0])
  1078. check_dpp_capab(dev[1])
  1079. sigma = start_sigma_dut(dev[0].ifname)
  1080. try:
  1081. addr = dev[1].own_addr().replace(':', '')
  1082. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1083. res = dev[1].request(cmd)
  1084. if "FAIL" in res:
  1085. raise Exception("Failed to generate bootstrapping info")
  1086. id0 = int(res)
  1087. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1088. cmd = "DPP_LISTEN 2437 role=enrollee"
  1089. if "OK" not in dev[1].request(cmd):
  1090. raise Exception("Failed to start listen operation")
  1091. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1092. if "status,COMPLETE" not in res:
  1093. raise Exception("dev_exec_action did not succeed: " + res)
  1094. cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,%s,DPPConfIndex,%d,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6" % (prov_role, conf_idx)
  1095. if extra:
  1096. cmd += "," + extra
  1097. res = sigma_dut_cmd(cmd)
  1098. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1099. raise Exception("Unexpected result: " + res)
  1100. finally:
  1101. stop_sigma_dut(sigma)
  1102. def test_sigma_dut_dpp_pkex_init_configurator(dev, apdev):
  1103. """sigma_dut DPP/PKEX initiator as Configurator"""
  1104. check_dpp_capab(dev[0])
  1105. check_dpp_capab(dev[1])
  1106. sigma = start_sigma_dut(dev[0].ifname)
  1107. try:
  1108. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1109. res = dev[1].request(cmd)
  1110. if "FAIL" in res:
  1111. raise Exception("Failed to generate bootstrapping info")
  1112. id1 = int(res)
  1113. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id1)
  1114. res = dev[1].request(cmd)
  1115. if "FAIL" in res:
  1116. raise Exception("Failed to set PKEX data (responder)")
  1117. cmd = "DPP_LISTEN 2437 role=enrollee"
  1118. if "OK" not in dev[1].request(cmd):
  1119. raise Exception("Failed to start listen operation")
  1120. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Mutual,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6")
  1121. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1122. raise Exception("Unexpected result: " + res)
  1123. finally:
  1124. stop_sigma_dut(sigma)
  1125. def dpp_init_conf(dev, id1, conf, conf_id, extra):
  1126. logger.info("Starting DPP initiator/configurator in a thread")
  1127. cmd = "DPP_AUTH_INIT peer=%d conf=%s %s configurator=%d" % (id1, conf, extra, conf_id)
  1128. if "OK" not in dev.request(cmd):
  1129. raise Exception("Failed to initiate DPP Authentication")
  1130. ev = dev.wait_event(["DPP-CONF-SENT"], timeout=5)
  1131. if ev is None:
  1132. raise Exception("DPP configuration not completed (Configurator)")
  1133. logger.info("DPP initiator/configurator done")
  1134. def test_sigma_dut_ap_dpp_qr(dev, apdev, params):
  1135. """sigma_dut controlled AP (DPP)"""
  1136. run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-dpp", "sta-dpp")
  1137. def test_sigma_dut_ap_dpp_qr_legacy(dev, apdev, params):
  1138. """sigma_dut controlled AP (legacy)"""
  1139. run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-psk", "sta-psk",
  1140. extra="pass=%s" % "qwertyuiop".encode("hex"))
  1141. def test_sigma_dut_ap_dpp_qr_legacy_psk(dev, apdev, params):
  1142. """sigma_dut controlled AP (legacy)"""
  1143. run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-psk", "sta-psk",
  1144. extra="psk=%s" % (32*"12"))
  1145. def run_sigma_dut_ap_dpp_qr(dev, apdev, params, ap_conf, sta_conf, extra=""):
  1146. logdir = os.path.join(params['logdir'], "sigma_dut_ap_dpp_qr.sigma-hostapd")
  1147. with HWSimRadio() as (radio, iface):
  1148. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  1149. try:
  1150. sigma_dut_cmd_check("ap_reset_default,program,DPP")
  1151. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  1152. if "status,COMPLETE" not in res:
  1153. raise Exception("dev_exec_action did not succeed: " + res)
  1154. hex = res.split(',')[3]
  1155. uri = hex.decode('hex')
  1156. logger.info("URI from sigma_dut: " + uri)
  1157. cmd = "DPP_CONFIGURATOR_ADD"
  1158. res = dev[0].request(cmd);
  1159. if "FAIL" in res:
  1160. raise Exception("Failed to add configurator")
  1161. conf_id = int(res)
  1162. res = dev[0].request("DPP_QR_CODE " + uri)
  1163. if "FAIL" in res:
  1164. raise Exception("Failed to parse QR Code URI")
  1165. id1 = int(res)
  1166. t = threading.Thread(target=dpp_init_conf,
  1167. args=(dev[0], id1, ap_conf, conf_id, extra))
  1168. t.start()
  1169. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6")
  1170. t.join()
  1171. if "ConfResult,OK" not in res:
  1172. raise Exception("Unexpected result: " + res)
  1173. addr = dev[1].own_addr().replace(':', '')
  1174. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1175. res = dev[1].request(cmd)
  1176. if "FAIL" in res:
  1177. raise Exception("Failed to generate bootstrapping info")
  1178. id1 = int(res)
  1179. uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
  1180. res = dev[0].request("DPP_QR_CODE " + uri1)
  1181. if "FAIL" in res:
  1182. raise Exception("Failed to parse QR Code URI")
  1183. id0b = int(res)
  1184. dev[1].set("dpp_config_processing", "2")
  1185. cmd = "DPP_LISTEN 2412"
  1186. if "OK" not in dev[1].request(cmd):
  1187. raise Exception("Failed to start listen operation")
  1188. cmd = "DPP_AUTH_INIT peer=%d conf=%s %s configurator=%d" % (id0b, sta_conf, extra, conf_id)
  1189. if "OK" not in dev[0].request(cmd):
  1190. raise Exception("Failed to initiate DPP Authentication")
  1191. dev[1].wait_connected()
  1192. sigma_dut_cmd_check("ap_reset_default")
  1193. finally:
  1194. dev[1].set("dpp_config_processing", "0")
  1195. stop_sigma_dut(sigma)
  1196. def test_sigma_dut_ap_dpp_pkex_responder(dev, apdev, params):
  1197. """sigma_dut controlled AP as DPP PKEX responder"""
  1198. logdir = os.path.join(params['logdir'],
  1199. "sigma_dut_ap_dpp_pkex_responder.sigma-hostapd")
  1200. with HWSimRadio() as (radio, iface):
  1201. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  1202. try:
  1203. run_sigma_dut_ap_dpp_pkex_responder(dev, apdev)
  1204. finally:
  1205. stop_sigma_dut(sigma)
  1206. def dpp_init_conf_pkex(dev, conf_id):
  1207. logger.info("Starting DPP PKEX initiator/configurator in a thread")
  1208. time.sleep(1.5)
  1209. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1210. res = dev.request(cmd)
  1211. if "FAIL" in res:
  1212. raise Exception("Failed to generate bootstrapping info")
  1213. id = int(res)
  1214. cmd = "DPP_PKEX_ADD own=%d init=1 conf=ap-dpp configurator=%d code=password" % (id, conf_id)
  1215. res = dev.request(cmd)
  1216. if "FAIL" in res:
  1217. raise Exception("Failed to initiate DPP PKEX")
  1218. ev = dev.wait_event(["DPP-CONF-SENT"], timeout=5)
  1219. if ev is None:
  1220. raise Exception("DPP configuration not completed (Configurator)")
  1221. logger.info("DPP initiator/configurator done")
  1222. def run_sigma_dut_ap_dpp_pkex_responder(dev, apdev):
  1223. sigma_dut_cmd_check("ap_reset_default,program,DPP")
  1224. cmd = "DPP_CONFIGURATOR_ADD"
  1225. res = dev[0].request(cmd);
  1226. if "FAIL" in res:
  1227. raise Exception("Failed to add configurator")
  1228. conf_id = int(res)
  1229. t = threading.Thread(target=dpp_init_conf_pkex, args=(dev[0], conf_id))
  1230. t.start()
  1231. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,PKEX,DPPPKEXCode,password,DPPTimeout,6", timeout=10)
  1232. t.join()
  1233. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1234. raise Exception("Unexpected result: " + res)
  1235. sigma_dut_cmd_check("ap_reset_default")
  1236. def dpp_proto_init(dev, id1):
  1237. time.sleep(1)
  1238. logger.info("Starting DPP initiator/configurator in a thread")
  1239. cmd = "DPP_CONFIGURATOR_ADD"
  1240. res = dev.request(cmd);
  1241. if "FAIL" in res:
  1242. raise Exception("Failed to add configurator")
  1243. conf_id = int(res)
  1244. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  1245. if "OK" not in dev.request(cmd):
  1246. raise Exception("Failed to initiate DPP Authentication")
  1247. def test_sigma_dut_dpp_proto_initiator(dev, apdev):
  1248. """sigma_dut DPP protocol testing - Initiator"""
  1249. check_dpp_capab(dev[0])
  1250. check_dpp_capab(dev[1])
  1251. tests = [ ("InvalidValue", "AuthenticationRequest", "WrappedData",
  1252. "BootstrapResult,OK,AuthResult,Errorsent",
  1253. None),
  1254. ("InvalidValue", "AuthenticationConfirm", "WrappedData",
  1255. "BootstrapResult,OK,AuthResult,Errorsent",
  1256. None),
  1257. ("MissingAttribute", "AuthenticationRequest", "InitCapabilities",
  1258. "BootstrapResult,OK,AuthResult,Errorsent",
  1259. "Missing or invalid I-capabilities"),
  1260. ("InvalidValue", "AuthenticationConfirm", "InitAuthTag",
  1261. "BootstrapResult,OK,AuthResult,Errorsent",
  1262. "Mismatching Initiator Authenticating Tag"),
  1263. ("MissingAttribute", "ConfigurationResponse", "EnrolleeNonce",
  1264. "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent",
  1265. "Missing or invalid Enrollee Nonce attribute") ]
  1266. for step, frame, attr, result, fail in tests:
  1267. dev[0].request("FLUSH")
  1268. dev[1].request("FLUSH")
  1269. sigma = start_sigma_dut(dev[0].ifname)
  1270. try:
  1271. run_sigma_dut_dpp_proto_initiator(dev, step, frame, attr, result,
  1272. fail)
  1273. finally:
  1274. stop_sigma_dut(sigma)
  1275. def run_sigma_dut_dpp_proto_initiator(dev, step, frame, attr, result, fail):
  1276. addr = dev[1].own_addr().replace(':', '')
  1277. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1278. res = dev[1].request(cmd)
  1279. if "FAIL" in res:
  1280. raise Exception("Failed to generate bootstrapping info")
  1281. id0 = int(res)
  1282. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1283. cmd = "DPP_LISTEN 2437 role=enrollee"
  1284. if "OK" not in dev[1].request(cmd):
  1285. raise Exception("Failed to start listen operation")
  1286. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1287. if "status,COMPLETE" not in res:
  1288. raise Exception("dev_exec_action did not succeed: " + res)
  1289. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6,DPPStep,%s,DPPFrameType,%s,DPPIEAttribute,%s" % (step, frame, attr))
  1290. if result not in res:
  1291. raise Exception("Unexpected result: " + res)
  1292. if fail:
  1293. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1294. if ev is None or fail not in ev:
  1295. raise Exception("Failure not reported correctly: " + str(ev))
  1296. dev[1].request("DPP_STOP_LISTEN")
  1297. dev[0].dump_monitor()
  1298. dev[1].dump_monitor()
  1299. def test_sigma_dut_dpp_proto_responder(dev, apdev):
  1300. """sigma_dut DPP protocol testing - Responder"""
  1301. check_dpp_capab(dev[0])
  1302. check_dpp_capab(dev[1])
  1303. tests = [ ("MissingAttribute", "AuthenticationResponse", "DPPStatus",
  1304. "BootstrapResult,OK,AuthResult,Errorsent",
  1305. "Missing or invalid required DPP Status attribute"),
  1306. ("MissingAttribute", "ConfigurationRequest", "EnrolleeNonce",
  1307. "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent",
  1308. "Missing or invalid Enrollee Nonce attribute") ]
  1309. for step, frame, attr, result, fail in tests:
  1310. dev[0].request("FLUSH")
  1311. dev[1].request("FLUSH")
  1312. sigma = start_sigma_dut(dev[0].ifname)
  1313. try:
  1314. run_sigma_dut_dpp_proto_responder(dev, step, frame, attr, result,
  1315. fail)
  1316. finally:
  1317. stop_sigma_dut(sigma)
  1318. def run_sigma_dut_dpp_proto_responder(dev, step, frame, attr, result, fail):
  1319. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  1320. if "status,COMPLETE" not in res:
  1321. raise Exception("dev_exec_action did not succeed: " + res)
  1322. hex = res.split(',')[3]
  1323. uri = hex.decode('hex')
  1324. logger.info("URI from sigma_dut: " + uri)
  1325. res = dev[1].request("DPP_QR_CODE " + uri)
  1326. if "FAIL" in res:
  1327. raise Exception("Failed to parse QR Code URI")
  1328. id1 = int(res)
  1329. t = threading.Thread(target=dpp_proto_init, args=(dev[1], id1))
  1330. t.start()
  1331. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6,DPPStep,%s,DPPFrameType,%s,DPPIEAttribute,%s" % (step, frame, attr), timeout=10)
  1332. t.join()
  1333. if result not in res:
  1334. raise Exception("Unexpected result: " + res)
  1335. if fail:
  1336. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1337. if ev is None or fail not in ev:
  1338. raise Exception("Failure not reported correctly:" + str(ev))
  1339. dev[1].request("DPP_STOP_LISTEN")
  1340. dev[0].dump_monitor()
  1341. dev[1].dump_monitor()
  1342. def dpp_proto_init_pkex(dev):
  1343. time.sleep(1)
  1344. logger.info("Starting DPP PKEX initiator/configurator in a thread")
  1345. cmd = "DPP_CONFIGURATOR_ADD"
  1346. res = dev.request(cmd);
  1347. if "FAIL" in res:
  1348. raise Exception("Failed to add configurator")
  1349. conf_id = int(res)
  1350. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1351. res = dev.request(cmd)
  1352. if "FAIL" in res:
  1353. raise Exception("Failed to generate bootstrapping info")
  1354. id = int(res)
  1355. cmd = "DPP_PKEX_ADD own=%d init=1 conf=sta-dpp configurator=%d code=secret" % (id, conf_id)
  1356. if "FAIL" in dev.request(cmd):
  1357. raise Exception("Failed to initiate DPP PKEX")
  1358. def test_sigma_dut_dpp_proto_initiator_pkex(dev, apdev):
  1359. """sigma_dut DPP protocol testing - Initiator (PKEX)"""
  1360. check_dpp_capab(dev[0])
  1361. check_dpp_capab(dev[1])
  1362. tests = [ ("InvalidValue", "PKEXCRRequest", "WrappedData",
  1363. "BootstrapResult,Errorsent",
  1364. None),
  1365. ("MissingAttribute", "PKEXExchangeRequest", "FiniteCyclicGroup",
  1366. "BootstrapResult,Errorsent",
  1367. "Missing or invalid Finite Cyclic Group attribute"),
  1368. ("MissingAttribute", "PKEXCRRequest", "BSKey",
  1369. "BootstrapResult,Errorsent",
  1370. "No valid peer bootstrapping key found") ]
  1371. for step, frame, attr, result, fail in tests:
  1372. dev[0].request("FLUSH")
  1373. dev[1].request("FLUSH")
  1374. sigma = start_sigma_dut(dev[0].ifname)
  1375. try:
  1376. run_sigma_dut_dpp_proto_initiator_pkex(dev, step, frame, attr,
  1377. result, fail)
  1378. finally:
  1379. stop_sigma_dut(sigma)
  1380. def run_sigma_dut_dpp_proto_initiator_pkex(dev, step, frame, attr, result, fail):
  1381. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1382. res = dev[1].request(cmd)
  1383. if "FAIL" in res:
  1384. raise Exception("Failed to generate bootstrapping info")
  1385. id1 = int(res)
  1386. cmd = "DPP_PKEX_ADD own=%d code=secret" % (id1)
  1387. res = dev[1].request(cmd)
  1388. if "FAIL" in res:
  1389. raise Exception("Failed to set PKEX data (responder)")
  1390. cmd = "DPP_LISTEN 2437 role=enrollee"
  1391. if "OK" not in dev[1].request(cmd):
  1392. raise Exception("Failed to start listen operation")
  1393. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCode,secret,DPPTimeout,6,DPPStep,%s,DPPFrameType,%s,DPPIEAttribute,%s" % (step, frame, attr))
  1394. if result not in res:
  1395. raise Exception("Unexpected result: " + res)
  1396. if fail:
  1397. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1398. if ev is None or fail not in ev:
  1399. raise Exception("Failure not reported correctly: " + str(ev))
  1400. dev[1].request("DPP_STOP_LISTEN")
  1401. dev[0].dump_monitor()
  1402. dev[1].dump_monitor()
  1403. def test_sigma_dut_dpp_proto_responder_pkex(dev, apdev):
  1404. """sigma_dut DPP protocol testing - Responder (PKEX)"""
  1405. check_dpp_capab(dev[0])
  1406. check_dpp_capab(dev[1])
  1407. tests = [ ("InvalidValue", "PKEXCRResponse", "WrappedData",
  1408. "BootstrapResult,Errorsent",
  1409. None),
  1410. ("MissingAttribute", "PKEXExchangeResponse", "DPPStatus",
  1411. "BootstrapResult,Errorsent",
  1412. "No DPP Status attribute"),
  1413. ("MissingAttribute", "PKEXCRResponse", "BSKey",
  1414. "BootstrapResult,Errorsent",
  1415. "No valid peer bootstrapping key found") ]
  1416. for step, frame, attr, result, fail in tests:
  1417. dev[0].request("FLUSH")
  1418. dev[1].request("FLUSH")
  1419. sigma = start_sigma_dut(dev[0].ifname)
  1420. try:
  1421. run_sigma_dut_dpp_proto_responder_pkex(dev, step, frame, attr,
  1422. result, fail)
  1423. finally:
  1424. stop_sigma_dut(sigma)
  1425. def run_sigma_dut_dpp_proto_responder_pkex(dev, step, frame, attr, result, fail):
  1426. t = threading.Thread(target=dpp_proto_init_pkex, args=(dev[1],))
  1427. t.start()
  1428. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCode,secret,DPPTimeout,6,DPPStep,%s,DPPFrameType,%s,DPPIEAttribute,%s" % (step, frame, attr), timeout=10)
  1429. t.join()
  1430. if result not in res:
  1431. raise Exception("Unexpected result: " + res)
  1432. if fail:
  1433. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1434. if ev is None or fail not in ev:
  1435. raise Exception("Failure not reported correctly:" + str(ev))
  1436. dev[1].request("DPP_STOP_LISTEN")
  1437. dev[0].dump_monitor()
  1438. dev[1].dump_monitor()
  1439. def init_sigma_dut_dpp_proto_peer_disc_req(dev, apdev):
  1440. check_dpp_capab(dev[0])
  1441. check_dpp_capab(dev[1])
  1442. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  1443. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  1444. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  1445. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  1446. params = { "ssid": "DPPNET01",
  1447. "wpa": "2",
  1448. "wpa_key_mgmt": "DPP",
  1449. "rsn_pairwise": "CCMP",
  1450. "dpp_connector": ap_connector,
  1451. "dpp_csign": csign_pub,
  1452. "dpp_netaccesskey": ap_netaccesskey }
  1453. try:
  1454. hapd = hostapd.add_ap(apdev[0], params)
  1455. except:
  1456. raise HwsimSkip("DPP not supported")
  1457. dev[0].set("dpp_config_processing", "2")
  1458. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  1459. res = dev[1].request(cmd);
  1460. if "FAIL" in res:
  1461. raise Exception("Failed to add configurator")
  1462. conf_id = int(res)
  1463. addr = dev[1].own_addr().replace(':', '')
  1464. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1465. res = dev[1].request(cmd)
  1466. if "FAIL" in res:
  1467. raise Exception("Failed to generate bootstrapping info")
  1468. id0 = int(res)
  1469. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1470. dev[1].set("dpp_configurator_params",
  1471. " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id));
  1472. cmd = "DPP_LISTEN 2437 role=configurator"
  1473. if "OK" not in dev[1].request(cmd):
  1474. raise Exception("Failed to start listen operation")
  1475. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1476. if "status,COMPLETE" not in res:
  1477. raise Exception("dev_exec_action did not succeed: " + res)
  1478. def test_sigma_dut_dpp_proto_peer_disc_req(dev, apdev):
  1479. """sigma_dut DPP protocol testing - Peer Discovery Request"""
  1480. sigma = start_sigma_dut(dev[0].ifname)
  1481. try:
  1482. init_sigma_dut_dpp_proto_peer_disc_req(dev, apdev)
  1483. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6,DPPWaitForConnect,Yes,DPPStep,MissingAttribute,DPPFrameType,PeerDiscoveryRequest,DPPIEAttribute,TransactionID", timeout=10)
  1484. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Errorsent" not in res:
  1485. raise Exception("Unexpected result: " + res)
  1486. finally:
  1487. dev[0].set("dpp_config_processing", "0")
  1488. stop_sigma_dut(sigma)
  1489. def test_sigma_dut_dpp_self_config(dev, apdev):
  1490. """sigma_dut DPP Configurator enrolling an AP and using self-configuration"""
  1491. check_dpp_capab(dev[0])
  1492. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  1493. check_dpp_capab(hapd)
  1494. sigma = start_sigma_dut(dev[0].ifname)
  1495. try:
  1496. dev[0].set("dpp_config_processing", "2")
  1497. addr = hapd.own_addr().replace(':', '')
  1498. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1499. res = hapd.request(cmd)
  1500. if "FAIL" in res:
  1501. raise Exception("Failed to generate bootstrapping info")
  1502. id = int(res)
  1503. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id)
  1504. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri.encode('hex'))
  1505. if "status,COMPLETE" not in res:
  1506. raise Exception("dev_exec_action did not succeed: " + res)
  1507. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,AP,DPPBS,QR,DPPTimeout,6")
  1508. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1509. raise Exception("Unexpected result: " + res)
  1510. update_hapd_config(hapd)
  1511. cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPCryptoIdentifier,P-256,DPPBS,QR,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPAuthDirection,Single,DPPConfIndex,1,DPPTimeout,6,DPPWaitForConnect,Yes,DPPSelfConfigure,Yes"
  1512. res = sigma_dut_cmd(cmd, timeout=10)
  1513. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  1514. raise Exception("Unexpected result: " + res)
  1515. finally:
  1516. stop_sigma_dut(sigma)
  1517. dev[0].set("dpp_config_processing", "0")
  1518. def test_sigma_dut_ap_dpp_self_config(dev, apdev, params):
  1519. """sigma_dut DPP AP Configurator using self-configuration"""
  1520. logdir = os.path.join(params['logdir'],
  1521. "sigma_dut_ap_dpp_self_config.sigma-hostapd")
  1522. with HWSimRadio() as (radio, iface):
  1523. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  1524. try:
  1525. run_sigma_dut_ap_dpp_self_config(dev, apdev)
  1526. finally:
  1527. stop_sigma_dut(sigma)
  1528. dev[0].set("dpp_config_processing", "0")
  1529. def run_sigma_dut_ap_dpp_self_config(dev, apdev):
  1530. check_dpp_capab(dev[0])
  1531. sigma_dut_cmd_check("ap_reset_default,program,DPP")
  1532. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfEnrolleeRole,AP,DPPBS,QR,DPPConfIndex,1,DPPSelfConfigure,Yes,DPPTimeout,6", timeout=10)
  1533. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1534. raise Exception("Unexpected result: " + res)
  1535. dev[0].set("dpp_config_processing", "2")
  1536. addr = dev[0].own_addr().replace(':', '')
  1537. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/11 mac=" + addr
  1538. res = dev[0].request(cmd)
  1539. if "FAIL" in res:
  1540. raise Exception("Failed to generate bootstrapping info")
  1541. id = int(res)
  1542. uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
  1543. cmd = "DPP_LISTEN 2462 role=enrollee"
  1544. if "OK" not in dev[0].request(cmd):
  1545. raise Exception("Failed to start listen operation")
  1546. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri.encode('hex'))
  1547. if "status,COMPLETE" not in res:
  1548. raise Exception("dev_exec_action did not succeed: " + res)
  1549. cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6"
  1550. res = sigma_dut_cmd(cmd)
  1551. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1552. raise Exception("Unexpected result: " + res)
  1553. dev[0].wait_connected()
  1554. dev[0].request("DISCONNECT")
  1555. dev[0].wait_disconnected()
  1556. sigma_dut_cmd_check("ap_reset_default")
  1557. def test_sigma_dut_preconfigured_profile(dev, apdev):
  1558. """sigma_dut controlled connection using preconfigured profile"""
  1559. try:
  1560. run_sigma_dut_preconfigured_profile(dev, apdev)
  1561. finally:
  1562. dev[0].set("ignore_old_scan_res", "0")
  1563. def run_sigma_dut_preconfigured_profile(dev, apdev):
  1564. ifname = dev[0].ifname
  1565. sigma = start_sigma_dut(ifname)
  1566. params = hostapd.wpa2_params(ssid="test-psk", passphrase="12345678")
  1567. hapd = hostapd.add_ap(apdev[0], params)
  1568. dev[0].connect("test-psk", psk="12345678", scan_freq="2412",
  1569. only_add_network=True)
  1570. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  1571. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s" % (ifname, "test-psk"))
  1572. sigma_dut_wait_connected(ifname)
  1573. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  1574. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  1575. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  1576. stop_sigma_dut(sigma)
  1577. def test_sigma_dut_wps_pbc(dev, apdev):
  1578. """sigma_dut and WPS PBC Enrollee"""
  1579. try:
  1580. run_sigma_dut_wps_pbc(dev, apdev)
  1581. finally:
  1582. dev[0].set("ignore_old_scan_res", "0")
  1583. def run_sigma_dut_wps_pbc(dev, apdev):
  1584. ssid = "test-wps-conf"
  1585. hapd = hostapd.add_ap(apdev[0],
  1586. { "ssid": "wps", "eap_server": "1", "wps_state": "2",
  1587. "wpa_passphrase": "12345678", "wpa": "2",
  1588. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  1589. hapd.request("WPS_PBC")
  1590. ifname = dev[0].ifname
  1591. sigma = start_sigma_dut(ifname)
  1592. cmd = "start_wps_registration,interface,%s" % ifname
  1593. cmd += ",WpsRole,Enrollee"
  1594. cmd += ",WpsConfigMethod,PBC"
  1595. sigma_dut_cmd_check(cmd, timeout=15)
  1596. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  1597. hapd.disable()
  1598. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  1599. stop_sigma_dut(sigma)
  1600. dev[0].flush_scan_cache()