test_sigma_dut.py 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086
  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. params["ieee80211w"] = "2"
  222. hapd = hostapd.add_ap(apdev[0], params)
  223. sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
  224. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  225. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,passphrase,%s,type,SAE,encpType,aes-ccmp,keymgmttype,wpa2" % (ifname, "test-sae", "12345678"))
  226. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"))
  227. sigma_dut_wait_connected(ifname)
  228. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  229. if dev[0].get_status_field('sae_group') != '19':
  230. raise Exception("Expected default SAE group not used")
  231. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  232. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  233. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  234. 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"))
  235. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"))
  236. sigma_dut_wait_connected(ifname)
  237. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  238. if dev[0].get_status_field('sae_group') != '20':
  239. raise Exception("Expected SAE group not used")
  240. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  241. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  242. stop_sigma_dut(sigma)
  243. def test_sigma_dut_sae_password(dev, apdev):
  244. """sigma_dut controlled SAE association and long password"""
  245. if "SAE" not in dev[0].get_capability("auth_alg"):
  246. raise HwsimSkip("SAE not supported")
  247. ifname = dev[0].ifname
  248. sigma = start_sigma_dut(ifname)
  249. try:
  250. ssid = "test-sae"
  251. params = hostapd.wpa2_params(ssid=ssid)
  252. params['sae_password'] = 100*'B'
  253. params['wpa_key_mgmt'] = 'SAE'
  254. params["ieee80211w"] = "2"
  255. hapd = hostapd.add_ap(apdev[0], params)
  256. sigma_dut_cmd_check("sta_reset_default,interface,%s" % ifname)
  257. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  258. 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'))
  259. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-sae"))
  260. sigma_dut_wait_connected(ifname)
  261. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  262. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  263. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  264. finally:
  265. stop_sigma_dut(sigma)
  266. def test_sigma_dut_sta_override_rsne(dev, apdev):
  267. """sigma_dut and RSNE override on STA"""
  268. try:
  269. run_sigma_dut_sta_override_rsne(dev, apdev)
  270. finally:
  271. dev[0].set("ignore_old_scan_res", "0")
  272. def run_sigma_dut_sta_override_rsne(dev, apdev):
  273. ifname = dev[0].ifname
  274. sigma = start_sigma_dut(ifname)
  275. ssid = "test-psk"
  276. params = hostapd.wpa2_params(ssid=ssid, passphrase="12345678")
  277. hapd = hostapd.add_ap(apdev[0], params)
  278. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  279. tests = [ "30120100000fac040100000fac040100000fac02",
  280. "30140100000fac040100000fac040100000fac02ffff" ]
  281. for test in tests:
  282. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,type,PSK,passphrase,%s,EncpType,aes-ccmp,KeyMgmtType,wpa2" % (ifname, "test-psk", "12345678"))
  283. sigma_dut_cmd_check("dev_configure_ie,interface,%s,IE_Name,RSNE,Contents,%s" % (ifname, test))
  284. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-psk"))
  285. sigma_dut_wait_connected(ifname)
  286. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  287. dev[0].dump_monitor()
  288. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,%s,type,PSK,passphrase,%s,EncpType,aes-ccmp,KeyMgmtType,wpa2" % (ifname, "test-psk", "12345678"))
  289. sigma_dut_cmd_check("dev_configure_ie,interface,%s,IE_Name,RSNE,Contents,300101" % ifname)
  290. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-psk"))
  291. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"])
  292. if ev is None:
  293. raise Exception("Association rejection not reported")
  294. if "status_code=40" not in ev:
  295. raise Exception("Unexpected status code: " + ev)
  296. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  297. stop_sigma_dut(sigma)
  298. def test_sigma_dut_ap_psk(dev, apdev):
  299. """sigma_dut controlled AP"""
  300. with HWSimRadio() as (radio, iface):
  301. sigma = start_sigma_dut(iface)
  302. try:
  303. sigma_dut_cmd_check("ap_reset_default")
  304. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
  305. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678")
  306. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  307. dev[0].connect("test-psk", psk="12345678", scan_freq="2412")
  308. sigma_dut_cmd_check("ap_reset_default")
  309. finally:
  310. stop_sigma_dut(sigma)
  311. def test_sigma_dut_ap_pskhex(dev, apdev, params):
  312. """sigma_dut controlled AP and PSKHEX"""
  313. logdir = os.path.join(params['logdir'],
  314. "sigma_dut_ap_pskhex.sigma-hostapd")
  315. with HWSimRadio() as (radio, iface):
  316. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  317. try:
  318. psk = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
  319. sigma_dut_cmd_check("ap_reset_default")
  320. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
  321. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSKHEX," + psk)
  322. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  323. dev[0].connect("test-psk", raw_psk=psk, scan_freq="2412")
  324. sigma_dut_cmd_check("ap_reset_default")
  325. finally:
  326. stop_sigma_dut(sigma)
  327. def test_sigma_dut_suite_b(dev, apdev, params):
  328. """sigma_dut controlled STA Suite B"""
  329. check_suite_b_192_capa(dev)
  330. logdir = params['logdir']
  331. with open("auth_serv/ec2-ca.pem", "r") as f:
  332. with open(os.path.join(logdir, "suite_b_ca.pem"), "w") as f2:
  333. f2.write(f.read())
  334. with open("auth_serv/ec2-user.pem", "r") as f:
  335. with open("auth_serv/ec2-user.key", "r") as f2:
  336. with open(os.path.join(logdir, "suite_b.pem"), "w") as f3:
  337. f3.write(f.read())
  338. f3.write(f2.read())
  339. dev[0].flush_scan_cache()
  340. params = suite_b_as_params()
  341. params['ca_cert'] = 'auth_serv/ec2-ca.pem'
  342. params['server_cert'] = 'auth_serv/ec2-server.pem'
  343. params['private_key'] = 'auth_serv/ec2-server.key'
  344. params['openssl_ciphers'] = 'SUITEB192'
  345. hostapd.add_ap(apdev[1], params)
  346. params = { "ssid": "test-suite-b",
  347. "wpa": "2",
  348. "wpa_key_mgmt": "WPA-EAP-SUITE-B-192",
  349. "rsn_pairwise": "GCMP-256",
  350. "group_mgmt_cipher": "BIP-GMAC-256",
  351. "ieee80211w": "2",
  352. "ieee8021x": "1",
  353. 'auth_server_addr': "127.0.0.1",
  354. 'auth_server_port': "18129",
  355. 'auth_server_shared_secret': "radius",
  356. 'nas_identifier': "nas.w1.fi" }
  357. hapd = hostapd.add_ap(apdev[0], params)
  358. ifname = dev[0].ifname
  359. sigma = start_sigma_dut(ifname, cert_path=logdir)
  360. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
  361. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  362. 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,clientCertificate,suite_b.pem,trustedRootCA,suite_b_ca.pem,CertType,ECC" % (ifname, "test-suite-b"))
  363. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-suite-b"))
  364. sigma_dut_wait_connected(ifname)
  365. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  366. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  367. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  368. stop_sigma_dut(sigma)
  369. def test_sigma_dut_suite_b_rsa(dev, apdev, params):
  370. """sigma_dut controlled STA Suite B (RSA)"""
  371. check_suite_b_192_capa(dev)
  372. logdir = params['logdir']
  373. with open("auth_serv/rsa3072-ca.pem", "r") as f:
  374. with open(os.path.join(logdir, "suite_b_ca_rsa.pem"), "w") as f2:
  375. f2.write(f.read())
  376. with open("auth_serv/rsa3072-user.pem", "r") as f:
  377. with open("auth_serv/rsa3072-user.key", "r") as f2:
  378. with open(os.path.join(logdir, "suite_b_rsa.pem"), "w") as f3:
  379. f3.write(f.read())
  380. f3.write(f2.read())
  381. dev[0].flush_scan_cache()
  382. params = suite_b_192_rsa_ap_params()
  383. hapd = hostapd.add_ap(apdev[0], params)
  384. ifname = dev[0].ifname
  385. sigma = start_sigma_dut(ifname, cert_path=logdir)
  386. cmd = "sta_set_security,type,eaptls,interface,%s,ssid,%s,PairwiseCipher,AES-GCMP-256,GroupCipher,AES-GCMP-256,GroupMgntCipher,BIP-GMAC-256,keymgmttype,SuiteB,clientCertificate,suite_b_rsa.pem,trustedRootCA,suite_b_ca_rsa.pem,CertType,RSA" % (ifname, "test-suite-b")
  387. tests = [ "",
  388. ",TLSCipher,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
  389. ",TLSCipher,TLS_DHE_RSA_WITH_AES_256_GCM_SHA384" ]
  390. for extra in tests:
  391. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,PMF" % ifname)
  392. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  393. sigma_dut_cmd_check(cmd + extra)
  394. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s,channel,1" % (ifname, "test-suite-b"))
  395. sigma_dut_wait_connected(ifname)
  396. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  397. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  398. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  399. stop_sigma_dut(sigma)
  400. def test_sigma_dut_ap_suite_b(dev, apdev, params):
  401. """sigma_dut controlled AP Suite B"""
  402. check_suite_b_192_capa(dev)
  403. logdir = os.path.join(params['logdir'],
  404. "sigma_dut_ap_suite_b.sigma-hostapd")
  405. params = suite_b_as_params()
  406. params['ca_cert'] = 'auth_serv/ec2-ca.pem'
  407. params['server_cert'] = 'auth_serv/ec2-server.pem'
  408. params['private_key'] = 'auth_serv/ec2-server.key'
  409. params['openssl_ciphers'] = 'SUITEB192'
  410. hostapd.add_ap(apdev[1], params)
  411. with HWSimRadio() as (radio, iface):
  412. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  413. try:
  414. sigma_dut_cmd_check("ap_reset_default")
  415. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-suite-b,MODE,11ng")
  416. sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,18129,PASSWORD,radius")
  417. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,SuiteB")
  418. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  419. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
  420. ieee80211w="2",
  421. openssl_ciphers="SUITEB192",
  422. eap="TLS", identity="tls user",
  423. ca_cert="auth_serv/ec2-ca.pem",
  424. client_cert="auth_serv/ec2-user.pem",
  425. private_key="auth_serv/ec2-user.key",
  426. pairwise="GCMP-256", group="GCMP-256",
  427. scan_freq="2412")
  428. sigma_dut_cmd_check("ap_reset_default")
  429. finally:
  430. stop_sigma_dut(sigma)
  431. def test_sigma_dut_ap_cipher_gcmp_128(dev, apdev, params):
  432. """sigma_dut controlled AP with GCMP-128/BIP-GMAC-128 cipher"""
  433. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-GCMP-128", "BIP-GMAC-128",
  434. "GCMP")
  435. def test_sigma_dut_ap_cipher_gcmp_256(dev, apdev, params):
  436. """sigma_dut controlled AP with GCMP-256/BIP-GMAC-256 cipher"""
  437. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-GCMP-256", "BIP-GMAC-256",
  438. "GCMP-256")
  439. def test_sigma_dut_ap_cipher_ccmp_128(dev, apdev, params):
  440. """sigma_dut controlled AP with CCMP-128/BIP-CMAC-128 cipher"""
  441. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-128", "BIP-CMAC-128",
  442. "CCMP")
  443. def test_sigma_dut_ap_cipher_ccmp_256(dev, apdev, params):
  444. """sigma_dut controlled AP with CCMP-256/BIP-CMAC-256 cipher"""
  445. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-256", "BIP-CMAC-256",
  446. "CCMP-256")
  447. def test_sigma_dut_ap_cipher_ccmp_gcmp_1(dev, apdev, params):
  448. """sigma_dut controlled AP with CCMP-128+GCMP-256 ciphers (1)"""
  449. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-128 AES-GCMP-256",
  450. "BIP-GMAC-256", "CCMP")
  451. def test_sigma_dut_ap_cipher_ccmp_gcmp_2(dev, apdev, params):
  452. """sigma_dut controlled AP with CCMP-128+GCMP-256 ciphers (2)"""
  453. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-128 AES-GCMP-256",
  454. "BIP-GMAC-256", "GCMP-256", "CCMP")
  455. def test_sigma_dut_ap_cipher_gcmp_256_group_ccmp(dev, apdev, params):
  456. """sigma_dut controlled AP with GCMP-256/CCMP/BIP-GMAC-256 cipher"""
  457. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-GCMP-256", "BIP-GMAC-256",
  458. "GCMP-256", "CCMP", "AES-CCMP-128")
  459. def run_sigma_dut_ap_cipher(dev, apdev, params, ap_pairwise, ap_group_mgmt,
  460. sta_cipher, sta_cipher_group=None, ap_group=None):
  461. check_suite_b_192_capa(dev)
  462. logdir = os.path.join(params['logdir'],
  463. "sigma_dut_ap_cipher.sigma-hostapd")
  464. params = suite_b_as_params()
  465. params['ca_cert'] = 'auth_serv/ec2-ca.pem'
  466. params['server_cert'] = 'auth_serv/ec2-server.pem'
  467. params['private_key'] = 'auth_serv/ec2-server.key'
  468. params['openssl_ciphers'] = 'SUITEB192'
  469. hostapd.add_ap(apdev[1], params)
  470. with HWSimRadio() as (radio, iface):
  471. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  472. try:
  473. sigma_dut_cmd_check("ap_reset_default")
  474. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-suite-b,MODE,11ng")
  475. sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,18129,PASSWORD,radius")
  476. cmd = "ap_set_security,NAME,AP,KEYMGNT,SuiteB,PMF,Required,PairwiseCipher,%s,GroupMgntCipher,%s" % (ap_pairwise, ap_group_mgmt)
  477. if ap_group:
  478. cmd += ",GroupCipher,%s" % ap_group
  479. sigma_dut_cmd_check(cmd)
  480. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  481. if sta_cipher_group is None:
  482. sta_cipher_group = sta_cipher
  483. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
  484. ieee80211w="2",
  485. openssl_ciphers="SUITEB192",
  486. eap="TLS", identity="tls user",
  487. ca_cert="auth_serv/ec2-ca.pem",
  488. client_cert="auth_serv/ec2-user.pem",
  489. private_key="auth_serv/ec2-user.key",
  490. pairwise=sta_cipher, group=sta_cipher_group,
  491. scan_freq="2412")
  492. sigma_dut_cmd_check("ap_reset_default")
  493. finally:
  494. stop_sigma_dut(sigma)
  495. def test_sigma_dut_ap_override_rsne(dev, apdev):
  496. """sigma_dut controlled AP overriding RSNE"""
  497. with HWSimRadio() as (radio, iface):
  498. sigma = start_sigma_dut(iface)
  499. try:
  500. sigma_dut_cmd_check("ap_reset_default")
  501. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
  502. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678")
  503. sigma_dut_cmd_check("dev_configure_ie,NAME,AP,interface,%s,IE_Name,RSNE,Contents,30180100000fac040200ffffffff000fac040100000fac020c00" % iface)
  504. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  505. dev[0].connect("test-psk", psk="12345678", scan_freq="2412")
  506. sigma_dut_cmd_check("ap_reset_default")
  507. finally:
  508. stop_sigma_dut(sigma)
  509. def test_sigma_dut_ap_sae(dev, apdev, params):
  510. """sigma_dut controlled AP with SAE"""
  511. logdir = os.path.join(params['logdir'],
  512. "sigma_dut_ap_sae.sigma-hostapd")
  513. if "SAE" not in dev[0].get_capability("auth_alg"):
  514. raise HwsimSkip("SAE not supported")
  515. with HWSimRadio() as (radio, iface):
  516. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  517. try:
  518. sigma_dut_cmd_check("ap_reset_default")
  519. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  520. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678")
  521. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  522. dev[0].request("SET sae_groups ")
  523. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  524. ieee80211w="2", scan_freq="2412")
  525. if dev[0].get_status_field('sae_group') != '19':
  526. raise Exception("Expected default SAE group not used")
  527. sigma_dut_cmd_check("ap_reset_default")
  528. finally:
  529. stop_sigma_dut(sigma)
  530. def test_sigma_dut_ap_sae_password(dev, apdev, params):
  531. """sigma_dut controlled AP with SAE and long password"""
  532. logdir = os.path.join(params['logdir'],
  533. "sigma_dut_ap_sae_password.sigma-hostapd")
  534. if "SAE" not in dev[0].get_capability("auth_alg"):
  535. raise HwsimSkip("SAE not supported")
  536. with HWSimRadio() as (radio, iface):
  537. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  538. try:
  539. sigma_dut_cmd_check("ap_reset_default")
  540. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  541. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK," + 100*'C')
  542. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  543. dev[0].request("SET sae_groups ")
  544. dev[0].connect("test-sae", key_mgmt="SAE", sae_password=100*'C',
  545. ieee80211w="2", scan_freq="2412")
  546. if dev[0].get_status_field('sae_group') != '19':
  547. raise Exception("Expected default SAE group not used")
  548. sigma_dut_cmd_check("ap_reset_default")
  549. finally:
  550. stop_sigma_dut(sigma)
  551. def test_sigma_dut_ap_sae_group(dev, apdev, params):
  552. """sigma_dut controlled AP with SAE and specific group"""
  553. logdir = os.path.join(params['logdir'],
  554. "sigma_dut_ap_sae_group.sigma-hostapd")
  555. if "SAE" not in dev[0].get_capability("auth_alg"):
  556. raise HwsimSkip("SAE not supported")
  557. with HWSimRadio() as (radio, iface):
  558. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  559. try:
  560. sigma_dut_cmd_check("ap_reset_default")
  561. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  562. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,ECGroupID,20")
  563. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  564. dev[0].request("SET sae_groups ")
  565. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  566. ieee80211w="2", scan_freq="2412")
  567. if dev[0].get_status_field('sae_group') != '20':
  568. raise Exception("Expected SAE group not used")
  569. sigma_dut_cmd_check("ap_reset_default")
  570. finally:
  571. stop_sigma_dut(sigma)
  572. def test_sigma_dut_ap_psk_sae(dev, apdev, params):
  573. """sigma_dut controlled AP with PSK+SAE"""
  574. if "SAE" not in dev[0].get_capability("auth_alg"):
  575. raise HwsimSkip("SAE not supported")
  576. logdir = os.path.join(params['logdir'],
  577. "sigma_dut_ap_psk_sae.sigma-hostapd")
  578. with HWSimRadio() as (radio, iface):
  579. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  580. try:
  581. sigma_dut_cmd_check("ap_reset_default")
  582. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  583. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK-SAE,PSK,12345678")
  584. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  585. dev[2].request("SET sae_groups ")
  586. dev[2].connect("test-sae", key_mgmt="SAE", psk="12345678",
  587. scan_freq="2412", ieee80211w="0", wait_connect=False)
  588. dev[0].request("SET sae_groups ")
  589. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  590. scan_freq="2412", ieee80211w="2")
  591. dev[1].connect("test-sae", psk="12345678", scan_freq="2412")
  592. ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.1)
  593. dev[2].request("DISCONNECT")
  594. if ev is not None:
  595. raise Exception("Unexpected connection without PMF")
  596. sigma_dut_cmd_check("ap_reset_default")
  597. finally:
  598. stop_sigma_dut(sigma)
  599. def test_sigma_dut_owe(dev, apdev):
  600. """sigma_dut controlled OWE station"""
  601. try:
  602. run_sigma_dut_owe(dev, apdev)
  603. finally:
  604. dev[0].set("ignore_old_scan_res", "0")
  605. def run_sigma_dut_owe(dev, apdev):
  606. if "OWE" not in dev[0].get_capability("key_mgmt"):
  607. raise HwsimSkip("OWE not supported")
  608. ifname = dev[0].ifname
  609. sigma = start_sigma_dut(ifname)
  610. try:
  611. params = { "ssid": "owe",
  612. "wpa": "2",
  613. "wpa_key_mgmt": "OWE",
  614. "ieee80211w": "2",
  615. "rsn_pairwise": "CCMP" }
  616. hapd = hostapd.add_ap(apdev[0], params)
  617. bssid = hapd.own_addr()
  618. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  619. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  620. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE" % ifname)
  621. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  622. sigma_dut_wait_connected(ifname)
  623. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  624. dev[0].dump_monitor()
  625. sigma_dut_cmd("sta_reassoc,interface,%s,Channel,1,bssid,%s" % (ifname, bssid))
  626. dev[0].wait_connected()
  627. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  628. dev[0].wait_disconnected()
  629. dev[0].dump_monitor()
  630. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  631. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  632. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,20" % ifname)
  633. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  634. sigma_dut_wait_connected(ifname)
  635. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  636. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  637. dev[0].wait_disconnected()
  638. dev[0].dump_monitor()
  639. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  640. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  641. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,0" % ifname)
  642. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  643. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  644. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  645. if ev is None:
  646. raise Exception("Association not rejected")
  647. if "status_code=77" not in ev:
  648. raise Exception("Unexpected rejection reason: " + ev)
  649. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  650. finally:
  651. stop_sigma_dut(sigma)
  652. def test_sigma_dut_ap_owe(dev, apdev, params):
  653. """sigma_dut controlled AP with OWE"""
  654. logdir = os.path.join(params['logdir'],
  655. "sigma_dut_ap_owe.sigma-hostapd")
  656. if "OWE" not in dev[0].get_capability("key_mgmt"):
  657. raise HwsimSkip("OWE not supported")
  658. with HWSimRadio() as (radio, iface):
  659. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  660. try:
  661. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  662. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
  663. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE")
  664. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  665. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  666. scan_freq="2412")
  667. sigma_dut_cmd_check("ap_reset_default")
  668. finally:
  669. stop_sigma_dut(sigma)
  670. def test_sigma_dut_ap_owe_ecgroupid(dev, apdev):
  671. """sigma_dut controlled AP with OWE and ECGroupID"""
  672. if "OWE" not in dev[0].get_capability("key_mgmt"):
  673. raise HwsimSkip("OWE not supported")
  674. with HWSimRadio() as (radio, iface):
  675. sigma = start_sigma_dut(iface)
  676. try:
  677. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  678. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
  679. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE,ECGroupID,20 21,PMF,Required")
  680. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  681. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  682. owe_group="20", scan_freq="2412")
  683. dev[0].request("REMOVE_NETWORK all")
  684. dev[0].wait_disconnected()
  685. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  686. owe_group="21", scan_freq="2412")
  687. dev[0].request("REMOVE_NETWORK all")
  688. dev[0].wait_disconnected()
  689. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  690. owe_group="19", scan_freq="2412", wait_connect=False)
  691. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  692. dev[0].request("DISCONNECT")
  693. if ev is None:
  694. raise Exception("Association not rejected")
  695. if "status_code=77" not in ev:
  696. raise Exception("Unexpected rejection reason: " + ev)
  697. dev[0].dump_monitor()
  698. sigma_dut_cmd_check("ap_reset_default")
  699. finally:
  700. stop_sigma_dut(sigma)
  701. def test_sigma_dut_ap_owe_transition_mode(dev, apdev, params):
  702. """sigma_dut controlled AP with OWE and transition mode"""
  703. if "OWE" not in dev[0].get_capability("key_mgmt"):
  704. raise HwsimSkip("OWE not supported")
  705. logdir = os.path.join(params['logdir'],
  706. "sigma_dut_ap_owe_transition_mode.sigma-hostapd")
  707. with HWSimRadio() as (radio, iface):
  708. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  709. try:
  710. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  711. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,1,CHANNEL,1,SSID,owe,MODE,11ng")
  712. sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,1,KEYMGNT,OWE")
  713. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,2,CHANNEL,1,SSID,owe,MODE,11ng")
  714. sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,2,KEYMGNT,NONE")
  715. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  716. res1 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,1,Interface,24G")
  717. res2 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,2,Interface,24G")
  718. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  719. scan_freq="2412")
  720. dev[1].connect("owe", key_mgmt="NONE", scan_freq="2412")
  721. if dev[0].get_status_field('bssid') not in res1:
  722. raise Exception("Unexpected ap_get_mac_address WLAN_TAG,1: " + res1)
  723. if dev[1].get_status_field('bssid') not in res2:
  724. raise Exception("Unexpected ap_get_mac_address WLAN_TAG,2: " + res2)
  725. sigma_dut_cmd_check("ap_reset_default")
  726. finally:
  727. stop_sigma_dut(sigma)
  728. def test_sigma_dut_ap_owe_transition_mode_2(dev, apdev, params):
  729. """sigma_dut controlled AP with OWE and transition mode (2)"""
  730. if "OWE" not in dev[0].get_capability("key_mgmt"):
  731. raise HwsimSkip("OWE not supported")
  732. logdir = os.path.join(params['logdir'],
  733. "sigma_dut_ap_owe_transition_mode_2.sigma-hostapd")
  734. with HWSimRadio() as (radio, iface):
  735. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  736. try:
  737. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  738. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,1,CHANNEL,1,SSID,owe,MODE,11ng")
  739. sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,1,KEYMGNT,NONE")
  740. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,2,CHANNEL,1,MODE,11ng")
  741. sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,2,KEYMGNT,OWE")
  742. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  743. res1 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,1,Interface,24G")
  744. res2 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,2,Interface,24G")
  745. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  746. scan_freq="2412")
  747. dev[1].connect("owe", key_mgmt="NONE", scan_freq="2412")
  748. if dev[0].get_status_field('bssid') not in res2:
  749. raise Exception("Unexpected ap_get_mac_address WLAN_TAG,2: " + res1)
  750. if dev[1].get_status_field('bssid') not in res1:
  751. raise Exception("Unexpected ap_get_mac_address WLAN_TAG,1: " + res2)
  752. sigma_dut_cmd_check("ap_reset_default")
  753. finally:
  754. stop_sigma_dut(sigma)
  755. def dpp_init_enrollee(dev, id1):
  756. logger.info("Starting DPP initiator/enrollee in a thread")
  757. time.sleep(1)
  758. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  759. if "OK" not in dev.request(cmd):
  760. raise Exception("Failed to initiate DPP Authentication")
  761. ev = dev.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  762. if ev is None:
  763. raise Exception("DPP configuration not completed (Enrollee)")
  764. logger.info("DPP initiator/enrollee done")
  765. def test_sigma_dut_dpp_qr_resp_1(dev, apdev):
  766. """sigma_dut DPP/QR responder (conf index 1)"""
  767. run_sigma_dut_dpp_qr_resp(dev, apdev, 1)
  768. def test_sigma_dut_dpp_qr_resp_2(dev, apdev):
  769. """sigma_dut DPP/QR responder (conf index 2)"""
  770. run_sigma_dut_dpp_qr_resp(dev, apdev, 2)
  771. def test_sigma_dut_dpp_qr_resp_3(dev, apdev):
  772. """sigma_dut DPP/QR responder (conf index 3)"""
  773. run_sigma_dut_dpp_qr_resp(dev, apdev, 3)
  774. def test_sigma_dut_dpp_qr_resp_4(dev, apdev):
  775. """sigma_dut DPP/QR responder (conf index 4)"""
  776. run_sigma_dut_dpp_qr_resp(dev, apdev, 4)
  777. def test_sigma_dut_dpp_qr_resp_5(dev, apdev):
  778. """sigma_dut DPP/QR responder (conf index 5)"""
  779. run_sigma_dut_dpp_qr_resp(dev, apdev, 5)
  780. def test_sigma_dut_dpp_qr_resp_6(dev, apdev):
  781. """sigma_dut DPP/QR responder (conf index 6)"""
  782. run_sigma_dut_dpp_qr_resp(dev, apdev, 6)
  783. def test_sigma_dut_dpp_qr_resp_7(dev, apdev):
  784. """sigma_dut DPP/QR responder (conf index 7)"""
  785. run_sigma_dut_dpp_qr_resp(dev, apdev, 7)
  786. def test_sigma_dut_dpp_qr_resp_chan_list(dev, apdev):
  787. """sigma_dut DPP/QR responder (channel list override)"""
  788. run_sigma_dut_dpp_qr_resp(dev, apdev, 1, chan_list='81/2 81/6 81/1',
  789. listen_chan=2)
  790. def run_sigma_dut_dpp_qr_resp(dev, apdev, conf_idx, chan_list=None,
  791. listen_chan=None):
  792. check_dpp_capab(dev[0])
  793. check_dpp_capab(dev[1])
  794. sigma = start_sigma_dut(dev[0].ifname)
  795. try:
  796. cmd = "dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR"
  797. if chan_list:
  798. cmd += ",DPPChannelList," + chan_list
  799. res = sigma_dut_cmd(cmd)
  800. if "status,COMPLETE" not in res:
  801. raise Exception("dev_exec_action did not succeed: " + res)
  802. hex = res.split(',')[3]
  803. uri = hex.decode('hex')
  804. logger.info("URI from sigma_dut: " + uri)
  805. res = dev[1].request("DPP_QR_CODE " + uri)
  806. if "FAIL" in res:
  807. raise Exception("Failed to parse QR Code URI")
  808. id1 = int(res)
  809. t = threading.Thread(target=dpp_init_enrollee, args=(dev[1], id1))
  810. t.start()
  811. 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
  812. if listen_chan:
  813. cmd += ",DPPListenChannel," + str(listen_chan)
  814. res = sigma_dut_cmd(cmd, timeout=10)
  815. t.join()
  816. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  817. raise Exception("Unexpected result: " + res)
  818. finally:
  819. stop_sigma_dut(sigma)
  820. def test_sigma_dut_dpp_qr_init_enrollee(dev, apdev):
  821. """sigma_dut DPP/QR initiator as Enrollee"""
  822. check_dpp_capab(dev[0])
  823. check_dpp_capab(dev[1])
  824. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  825. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  826. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  827. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  828. params = { "ssid": "DPPNET01",
  829. "wpa": "2",
  830. "ieee80211w": "2",
  831. "wpa_key_mgmt": "DPP",
  832. "rsn_pairwise": "CCMP",
  833. "dpp_connector": ap_connector,
  834. "dpp_csign": csign_pub,
  835. "dpp_netaccesskey": ap_netaccesskey }
  836. try:
  837. hapd = hostapd.add_ap(apdev[0], params)
  838. except:
  839. raise HwsimSkip("DPP not supported")
  840. sigma = start_sigma_dut(dev[0].ifname)
  841. try:
  842. dev[0].set("dpp_config_processing", "2")
  843. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  844. res = dev[1].request(cmd);
  845. if "FAIL" in res:
  846. raise Exception("Failed to add configurator")
  847. conf_id = int(res)
  848. addr = dev[1].own_addr().replace(':', '')
  849. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  850. res = dev[1].request(cmd)
  851. if "FAIL" in res:
  852. raise Exception("Failed to generate bootstrapping info")
  853. id0 = int(res)
  854. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  855. dev[1].set("dpp_configurator_params",
  856. " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id));
  857. cmd = "DPP_LISTEN 2437 role=configurator"
  858. if "OK" not in dev[1].request(cmd):
  859. raise Exception("Failed to start listen operation")
  860. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  861. if "status,COMPLETE" not in res:
  862. raise Exception("dev_exec_action did not succeed: " + res)
  863. 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)
  864. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  865. raise Exception("Unexpected result: " + res)
  866. finally:
  867. dev[0].set("dpp_config_processing", "0")
  868. stop_sigma_dut(sigma)
  869. def test_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev):
  870. """sigma_dut DPP/QR (mutual) initiator as Enrollee"""
  871. run_sigma_dut_dpp_qr_mutual_init_enrollee_check(dev, apdev)
  872. def test_sigma_dut_dpp_qr_mutual_init_enrollee_check(dev, apdev):
  873. """sigma_dut DPP/QR (mutual) initiator as Enrollee (extra check)"""
  874. run_sigma_dut_dpp_qr_mutual_init_enrollee_check(dev, apdev,
  875. extra="DPPAuthDirection,Mutual,")
  876. def run_sigma_dut_dpp_qr_mutual_init_enrollee_check(dev, apdev, extra=''):
  877. check_dpp_capab(dev[0])
  878. check_dpp_capab(dev[1])
  879. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  880. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  881. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  882. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  883. params = { "ssid": "DPPNET01",
  884. "wpa": "2",
  885. "ieee80211w": "2",
  886. "wpa_key_mgmt": "DPP",
  887. "rsn_pairwise": "CCMP",
  888. "dpp_connector": ap_connector,
  889. "dpp_csign": csign_pub,
  890. "dpp_netaccesskey": ap_netaccesskey }
  891. try:
  892. hapd = hostapd.add_ap(apdev[0], params)
  893. except:
  894. raise HwsimSkip("DPP not supported")
  895. sigma = start_sigma_dut(dev[0].ifname)
  896. try:
  897. dev[0].set("dpp_config_processing", "2")
  898. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  899. res = dev[1].request(cmd);
  900. if "FAIL" in res:
  901. raise Exception("Failed to add configurator")
  902. conf_id = int(res)
  903. addr = dev[1].own_addr().replace(':', '')
  904. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  905. res = dev[1].request(cmd)
  906. if "FAIL" in res:
  907. raise Exception("Failed to generate bootstrapping info")
  908. id0 = int(res)
  909. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  910. dev[1].set("dpp_configurator_params",
  911. " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id));
  912. cmd = "DPP_LISTEN 2437 role=configurator qr=mutual"
  913. if "OK" not in dev[1].request(cmd):
  914. raise Exception("Failed to start listen operation")
  915. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  916. if "status,COMPLETE" not in res:
  917. raise Exception("dev_exec_action did not succeed: " + res)
  918. hex = res.split(',')[3]
  919. uri = hex.decode('hex')
  920. logger.info("URI from sigma_dut: " + uri)
  921. res = dev[1].request("DPP_QR_CODE " + uri)
  922. if "FAIL" in res:
  923. raise Exception("Failed to parse QR Code URI")
  924. id1 = int(res)
  925. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  926. if "status,COMPLETE" not in res:
  927. raise Exception("dev_exec_action did not succeed: " + res)
  928. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,%sDPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6,DPPWaitForConnect,Yes" % extra, timeout=10)
  929. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  930. raise Exception("Unexpected result: " + res)
  931. finally:
  932. dev[0].set("dpp_config_processing", "0")
  933. stop_sigma_dut(sigma)
  934. def dpp_init_conf_mutual(dev, id1, conf_id, own_id=None):
  935. time.sleep(1)
  936. logger.info("Starting DPP initiator/configurator in a thread")
  937. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp ssid=%s configurator=%d" % (id1, "DPPNET01".encode("hex"), conf_id)
  938. if own_id is not None:
  939. cmd += " own=%d" % own_id
  940. if "OK" not in dev.request(cmd):
  941. raise Exception("Failed to initiate DPP Authentication")
  942. ev = dev.wait_event(["DPP-CONF-SENT"], timeout=10)
  943. if ev is None:
  944. raise Exception("DPP configuration not completed (Configurator)")
  945. logger.info("DPP initiator/configurator done")
  946. def test_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev):
  947. """sigma_dut DPP/QR (mutual) responder as Enrollee"""
  948. run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev)
  949. def test_sigma_dut_dpp_qr_mutual_resp_enrollee_pending(dev, apdev):
  950. """sigma_dut DPP/QR (mutual) responder as Enrollee (response pending)"""
  951. run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev, ',DPPDelayQRResponse,1')
  952. def run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev, extra=None):
  953. check_dpp_capab(dev[0])
  954. check_dpp_capab(dev[1])
  955. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  956. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  957. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  958. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  959. params = { "ssid": "DPPNET01",
  960. "wpa": "2",
  961. "ieee80211w": "2",
  962. "wpa_key_mgmt": "DPP",
  963. "rsn_pairwise": "CCMP",
  964. "dpp_connector": ap_connector,
  965. "dpp_csign": csign_pub,
  966. "dpp_netaccesskey": ap_netaccesskey }
  967. try:
  968. hapd = hostapd.add_ap(apdev[0], params)
  969. except:
  970. raise HwsimSkip("DPP not supported")
  971. sigma = start_sigma_dut(dev[0].ifname)
  972. try:
  973. dev[0].set("dpp_config_processing", "2")
  974. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  975. res = dev[1].request(cmd);
  976. if "FAIL" in res:
  977. raise Exception("Failed to add configurator")
  978. conf_id = int(res)
  979. addr = dev[1].own_addr().replace(':', '')
  980. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  981. res = dev[1].request(cmd)
  982. if "FAIL" in res:
  983. raise Exception("Failed to generate bootstrapping info")
  984. id0 = int(res)
  985. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  986. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  987. if "status,COMPLETE" not in res:
  988. raise Exception("dev_exec_action did not succeed: " + res)
  989. hex = res.split(',')[3]
  990. uri = hex.decode('hex')
  991. logger.info("URI from sigma_dut: " + uri)
  992. res = dev[1].request("DPP_QR_CODE " + uri)
  993. if "FAIL" in res:
  994. raise Exception("Failed to parse QR Code URI")
  995. id1 = int(res)
  996. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  997. if "status,COMPLETE" not in res:
  998. raise Exception("dev_exec_action did not succeed: " + res)
  999. t = threading.Thread(target=dpp_init_conf_mutual,
  1000. args=(dev[1], id1, conf_id, id0))
  1001. t.start()
  1002. cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,20,DPPWaitForConnect,Yes"
  1003. if extra:
  1004. cmd += extra
  1005. res = sigma_dut_cmd(cmd, timeout=25)
  1006. t.join()
  1007. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  1008. raise Exception("Unexpected result: " + res)
  1009. finally:
  1010. dev[0].set("dpp_config_processing", "0")
  1011. stop_sigma_dut(sigma)
  1012. def dpp_resp_conf_mutual(dev, conf_id, uri):
  1013. logger.info("Starting DPP responder/configurator in a thread")
  1014. dev.set("dpp_configurator_params",
  1015. " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id));
  1016. cmd = "DPP_LISTEN 2437 role=configurator qr=mutual"
  1017. if "OK" not in dev.request(cmd):
  1018. raise Exception("Failed to initiate DPP listen")
  1019. if uri:
  1020. ev = dev.wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=10)
  1021. if ev is None:
  1022. raise Exception("QR Code scan for mutual authentication not requested")
  1023. res = dev.request("DPP_QR_CODE " + uri)
  1024. if "FAIL" in res:
  1025. raise Exception("Failed to parse QR Code URI")
  1026. ev = dev.wait_event(["DPP-CONF-SENT"], timeout=10)
  1027. if ev is None:
  1028. raise Exception("DPP configuration not completed (Configurator)")
  1029. logger.info("DPP responder/configurator done")
  1030. def test_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev):
  1031. """sigma_dut DPP/QR (mutual) initiator as Enrollee"""
  1032. run_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev, False)
  1033. def test_sigma_dut_dpp_qr_mutual_init_enrollee_pending(dev, apdev):
  1034. """sigma_dut DPP/QR (mutual) initiator as Enrollee (response pending)"""
  1035. run_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev, True)
  1036. def run_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev, resp_pending):
  1037. check_dpp_capab(dev[0])
  1038. check_dpp_capab(dev[1])
  1039. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  1040. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  1041. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  1042. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  1043. params = { "ssid": "DPPNET01",
  1044. "wpa": "2",
  1045. "ieee80211w": "2",
  1046. "wpa_key_mgmt": "DPP",
  1047. "rsn_pairwise": "CCMP",
  1048. "dpp_connector": ap_connector,
  1049. "dpp_csign": csign_pub,
  1050. "dpp_netaccesskey": ap_netaccesskey }
  1051. try:
  1052. hapd = hostapd.add_ap(apdev[0], params)
  1053. except:
  1054. raise HwsimSkip("DPP not supported")
  1055. sigma = start_sigma_dut(dev[0].ifname)
  1056. try:
  1057. dev[0].set("dpp_config_processing", "2")
  1058. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  1059. res = dev[1].request(cmd);
  1060. if "FAIL" in res:
  1061. raise Exception("Failed to add configurator")
  1062. conf_id = int(res)
  1063. addr = dev[1].own_addr().replace(':', '')
  1064. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1065. res = dev[1].request(cmd)
  1066. if "FAIL" in res:
  1067. raise Exception("Failed to generate bootstrapping info")
  1068. id0 = int(res)
  1069. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1070. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  1071. if "status,COMPLETE" not in res:
  1072. raise Exception("dev_exec_action did not succeed: " + res)
  1073. hex = res.split(',')[3]
  1074. uri = hex.decode('hex')
  1075. logger.info("URI from sigma_dut: " + uri)
  1076. if not resp_pending:
  1077. res = dev[1].request("DPP_QR_CODE " + uri)
  1078. if "FAIL" in res:
  1079. raise Exception("Failed to parse QR Code URI")
  1080. uri = None
  1081. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1082. if "status,COMPLETE" not in res:
  1083. raise Exception("dev_exec_action did not succeed: " + res)
  1084. t = threading.Thread(target=dpp_resp_conf_mutual,
  1085. args=(dev[1], conf_id, uri))
  1086. t.start()
  1087. time.sleep(1)
  1088. cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,10,DPPWaitForConnect,Yes"
  1089. res = sigma_dut_cmd(cmd, timeout=15)
  1090. t.join()
  1091. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  1092. raise Exception("Unexpected result: " + res)
  1093. finally:
  1094. dev[0].set("dpp_config_processing", "0")
  1095. stop_sigma_dut(sigma)
  1096. def test_sigma_dut_dpp_qr_init_enrollee_psk(dev, apdev):
  1097. """sigma_dut DPP/QR initiator as Enrollee (PSK)"""
  1098. check_dpp_capab(dev[0])
  1099. check_dpp_capab(dev[1])
  1100. params = hostapd.wpa2_params(ssid="DPPNET01",
  1101. passphrase="ThisIsDppPassphrase")
  1102. hapd = hostapd.add_ap(apdev[0], params)
  1103. sigma = start_sigma_dut(dev[0].ifname)
  1104. try:
  1105. dev[0].set("dpp_config_processing", "2")
  1106. cmd = "DPP_CONFIGURATOR_ADD"
  1107. res = dev[1].request(cmd);
  1108. if "FAIL" in res:
  1109. raise Exception("Failed to add configurator")
  1110. conf_id = int(res)
  1111. addr = dev[1].own_addr().replace(':', '')
  1112. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1113. res = dev[1].request(cmd)
  1114. if "FAIL" in res:
  1115. raise Exception("Failed to generate bootstrapping info")
  1116. id0 = int(res)
  1117. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1118. dev[1].set("dpp_configurator_params",
  1119. " conf=sta-psk ssid=%s pass=%s configurator=%d" % ("DPPNET01".encode("hex"), "ThisIsDppPassphrase".encode("hex"), conf_id));
  1120. cmd = "DPP_LISTEN 2437 role=configurator"
  1121. if "OK" not in dev[1].request(cmd):
  1122. raise Exception("Failed to start listen operation")
  1123. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1124. if "status,COMPLETE" not in res:
  1125. raise Exception("dev_exec_action did not succeed: " + res)
  1126. 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)
  1127. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkConnectResult,OK" not in res:
  1128. raise Exception("Unexpected result: " + res)
  1129. finally:
  1130. dev[0].set("dpp_config_processing", "0")
  1131. stop_sigma_dut(sigma)
  1132. def test_sigma_dut_dpp_qr_init_configurator_1(dev, apdev):
  1133. """sigma_dut DPP/QR initiator as Configurator (conf index 1)"""
  1134. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 1)
  1135. def test_sigma_dut_dpp_qr_init_configurator_2(dev, apdev):
  1136. """sigma_dut DPP/QR initiator as Configurator (conf index 2)"""
  1137. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 2)
  1138. def test_sigma_dut_dpp_qr_init_configurator_3(dev, apdev):
  1139. """sigma_dut DPP/QR initiator as Configurator (conf index 3)"""
  1140. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 3)
  1141. def test_sigma_dut_dpp_qr_init_configurator_4(dev, apdev):
  1142. """sigma_dut DPP/QR initiator as Configurator (conf index 4)"""
  1143. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 4)
  1144. def test_sigma_dut_dpp_qr_init_configurator_5(dev, apdev):
  1145. """sigma_dut DPP/QR initiator as Configurator (conf index 5)"""
  1146. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 5)
  1147. def test_sigma_dut_dpp_qr_init_configurator_6(dev, apdev):
  1148. """sigma_dut DPP/QR initiator as Configurator (conf index 6)"""
  1149. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 6)
  1150. def test_sigma_dut_dpp_qr_init_configurator_7(dev, apdev):
  1151. """sigma_dut DPP/QR initiator as Configurator (conf index 7)"""
  1152. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 7)
  1153. def test_sigma_dut_dpp_qr_init_configurator_both(dev, apdev):
  1154. """sigma_dut DPP/QR initiator as Configurator or Enrollee (conf index 1)"""
  1155. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 1, "Both")
  1156. def test_sigma_dut_dpp_qr_init_configurator_neg_freq(dev, apdev):
  1157. """sigma_dut DPP/QR initiator as Configurator (neg_freq)"""
  1158. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 1, extra='DPPSubsequentChannel,81/11')
  1159. def run_sigma_dut_dpp_qr_init_configurator(dev, apdev, conf_idx,
  1160. prov_role="Configurator",
  1161. extra=None):
  1162. check_dpp_capab(dev[0])
  1163. check_dpp_capab(dev[1])
  1164. sigma = start_sigma_dut(dev[0].ifname)
  1165. try:
  1166. addr = dev[1].own_addr().replace(':', '')
  1167. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1168. res = dev[1].request(cmd)
  1169. if "FAIL" in res:
  1170. raise Exception("Failed to generate bootstrapping info")
  1171. id0 = int(res)
  1172. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1173. cmd = "DPP_LISTEN 2437 role=enrollee"
  1174. if "OK" not in dev[1].request(cmd):
  1175. raise Exception("Failed to start listen operation")
  1176. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1177. if "status,COMPLETE" not in res:
  1178. raise Exception("dev_exec_action did not succeed: " + res)
  1179. 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)
  1180. if extra:
  1181. cmd += "," + extra
  1182. res = sigma_dut_cmd(cmd)
  1183. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1184. raise Exception("Unexpected result: " + res)
  1185. finally:
  1186. stop_sigma_dut(sigma)
  1187. def test_sigma_dut_dpp_pkex_init_configurator(dev, apdev):
  1188. """sigma_dut DPP/PKEX initiator as Configurator"""
  1189. check_dpp_capab(dev[0])
  1190. check_dpp_capab(dev[1])
  1191. sigma = start_sigma_dut(dev[0].ifname)
  1192. try:
  1193. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1194. res = dev[1].request(cmd)
  1195. if "FAIL" in res:
  1196. raise Exception("Failed to generate bootstrapping info")
  1197. id1 = int(res)
  1198. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id1)
  1199. res = dev[1].request(cmd)
  1200. if "FAIL" in res:
  1201. raise Exception("Failed to set PKEX data (responder)")
  1202. cmd = "DPP_LISTEN 2437 role=enrollee"
  1203. if "OK" not in dev[1].request(cmd):
  1204. raise Exception("Failed to start listen operation")
  1205. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6")
  1206. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1207. raise Exception("Unexpected result: " + res)
  1208. finally:
  1209. stop_sigma_dut(sigma)
  1210. def dpp_init_conf(dev, id1, conf, conf_id, extra):
  1211. logger.info("Starting DPP initiator/configurator in a thread")
  1212. cmd = "DPP_AUTH_INIT peer=%d conf=%s %s configurator=%d" % (id1, conf, extra, conf_id)
  1213. if "OK" not in dev.request(cmd):
  1214. raise Exception("Failed to initiate DPP Authentication")
  1215. ev = dev.wait_event(["DPP-CONF-SENT"], timeout=5)
  1216. if ev is None:
  1217. raise Exception("DPP configuration not completed (Configurator)")
  1218. logger.info("DPP initiator/configurator done")
  1219. def test_sigma_dut_ap_dpp_qr(dev, apdev, params):
  1220. """sigma_dut controlled AP (DPP)"""
  1221. run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-dpp", "sta-dpp")
  1222. def test_sigma_dut_ap_dpp_qr_legacy(dev, apdev, params):
  1223. """sigma_dut controlled AP (legacy)"""
  1224. run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-psk", "sta-psk",
  1225. extra="pass=%s" % "qwertyuiop".encode("hex"))
  1226. def test_sigma_dut_ap_dpp_qr_legacy_psk(dev, apdev, params):
  1227. """sigma_dut controlled AP (legacy)"""
  1228. run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-psk", "sta-psk",
  1229. extra="psk=%s" % (32*"12"))
  1230. def run_sigma_dut_ap_dpp_qr(dev, apdev, params, ap_conf, sta_conf, extra=""):
  1231. check_dpp_capab(dev[0])
  1232. logdir = os.path.join(params['logdir'], "sigma_dut_ap_dpp_qr.sigma-hostapd")
  1233. with HWSimRadio() as (radio, iface):
  1234. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  1235. try:
  1236. sigma_dut_cmd_check("ap_reset_default,program,DPP")
  1237. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  1238. if "status,COMPLETE" not in res:
  1239. raise Exception("dev_exec_action did not succeed: " + res)
  1240. hex = res.split(',')[3]
  1241. uri = hex.decode('hex')
  1242. logger.info("URI from sigma_dut: " + uri)
  1243. cmd = "DPP_CONFIGURATOR_ADD"
  1244. res = dev[0].request(cmd);
  1245. if "FAIL" in res:
  1246. raise Exception("Failed to add configurator")
  1247. conf_id = int(res)
  1248. res = dev[0].request("DPP_QR_CODE " + uri)
  1249. if "FAIL" in res:
  1250. raise Exception("Failed to parse QR Code URI")
  1251. id1 = int(res)
  1252. t = threading.Thread(target=dpp_init_conf,
  1253. args=(dev[0], id1, ap_conf, conf_id, extra))
  1254. t.start()
  1255. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6")
  1256. t.join()
  1257. if "ConfResult,OK" not in res:
  1258. raise Exception("Unexpected result: " + res)
  1259. addr = dev[1].own_addr().replace(':', '')
  1260. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1261. res = dev[1].request(cmd)
  1262. if "FAIL" in res:
  1263. raise Exception("Failed to generate bootstrapping info")
  1264. id1 = int(res)
  1265. uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
  1266. res = dev[0].request("DPP_QR_CODE " + uri1)
  1267. if "FAIL" in res:
  1268. raise Exception("Failed to parse QR Code URI")
  1269. id0b = int(res)
  1270. dev[1].set("dpp_config_processing", "2")
  1271. cmd = "DPP_LISTEN 2412"
  1272. if "OK" not in dev[1].request(cmd):
  1273. raise Exception("Failed to start listen operation")
  1274. cmd = "DPP_AUTH_INIT peer=%d conf=%s %s configurator=%d" % (id0b, sta_conf, extra, conf_id)
  1275. if "OK" not in dev[0].request(cmd):
  1276. raise Exception("Failed to initiate DPP Authentication")
  1277. dev[1].wait_connected()
  1278. sigma_dut_cmd_check("ap_reset_default")
  1279. finally:
  1280. dev[1].set("dpp_config_processing", "0")
  1281. stop_sigma_dut(sigma)
  1282. def test_sigma_dut_ap_dpp_pkex_responder(dev, apdev, params):
  1283. """sigma_dut controlled AP as DPP PKEX responder"""
  1284. check_dpp_capab(dev[0])
  1285. logdir = os.path.join(params['logdir'],
  1286. "sigma_dut_ap_dpp_pkex_responder.sigma-hostapd")
  1287. with HWSimRadio() as (radio, iface):
  1288. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  1289. try:
  1290. run_sigma_dut_ap_dpp_pkex_responder(dev, apdev)
  1291. finally:
  1292. stop_sigma_dut(sigma)
  1293. def dpp_init_conf_pkex(dev, conf_id):
  1294. logger.info("Starting DPP PKEX initiator/configurator in a thread")
  1295. time.sleep(1.5)
  1296. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1297. res = dev.request(cmd)
  1298. if "FAIL" in res:
  1299. raise Exception("Failed to generate bootstrapping info")
  1300. id = int(res)
  1301. cmd = "DPP_PKEX_ADD own=%d init=1 conf=ap-dpp configurator=%d code=password" % (id, conf_id)
  1302. res = dev.request(cmd)
  1303. if "FAIL" in res:
  1304. raise Exception("Failed to initiate DPP PKEX")
  1305. ev = dev.wait_event(["DPP-CONF-SENT"], timeout=5)
  1306. if ev is None:
  1307. raise Exception("DPP configuration not completed (Configurator)")
  1308. logger.info("DPP initiator/configurator done")
  1309. def run_sigma_dut_ap_dpp_pkex_responder(dev, apdev):
  1310. sigma_dut_cmd_check("ap_reset_default,program,DPP")
  1311. cmd = "DPP_CONFIGURATOR_ADD"
  1312. res = dev[0].request(cmd);
  1313. if "FAIL" in res:
  1314. raise Exception("Failed to add configurator")
  1315. conf_id = int(res)
  1316. t = threading.Thread(target=dpp_init_conf_pkex, args=(dev[0], conf_id))
  1317. t.start()
  1318. 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)
  1319. t.join()
  1320. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1321. raise Exception("Unexpected result: " + res)
  1322. sigma_dut_cmd_check("ap_reset_default")
  1323. def dpp_proto_init(dev, id1):
  1324. time.sleep(1)
  1325. logger.info("Starting DPP initiator/configurator in a thread")
  1326. cmd = "DPP_CONFIGURATOR_ADD"
  1327. res = dev.request(cmd);
  1328. if "FAIL" in res:
  1329. raise Exception("Failed to add configurator")
  1330. conf_id = int(res)
  1331. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  1332. if "OK" not in dev.request(cmd):
  1333. raise Exception("Failed to initiate DPP Authentication")
  1334. def test_sigma_dut_dpp_proto_initiator(dev, apdev):
  1335. """sigma_dut DPP protocol testing - Initiator"""
  1336. check_dpp_capab(dev[0])
  1337. check_dpp_capab(dev[1])
  1338. tests = [ ("InvalidValue", "AuthenticationRequest", "WrappedData",
  1339. "BootstrapResult,OK,AuthResult,Errorsent",
  1340. None),
  1341. ("InvalidValue", "AuthenticationConfirm", "WrappedData",
  1342. "BootstrapResult,OK,AuthResult,Errorsent",
  1343. None),
  1344. ("MissingAttribute", "AuthenticationRequest", "InitCapabilities",
  1345. "BootstrapResult,OK,AuthResult,Errorsent",
  1346. "Missing or invalid I-capabilities"),
  1347. ("InvalidValue", "AuthenticationConfirm", "InitAuthTag",
  1348. "BootstrapResult,OK,AuthResult,Errorsent",
  1349. "Mismatching Initiator Authenticating Tag"),
  1350. ("MissingAttribute", "ConfigurationResponse", "EnrolleeNonce",
  1351. "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent",
  1352. "Missing or invalid Enrollee Nonce attribute") ]
  1353. for step, frame, attr, result, fail in tests:
  1354. dev[0].request("FLUSH")
  1355. dev[1].request("FLUSH")
  1356. sigma = start_sigma_dut(dev[0].ifname)
  1357. try:
  1358. run_sigma_dut_dpp_proto_initiator(dev, step, frame, attr, result,
  1359. fail)
  1360. finally:
  1361. stop_sigma_dut(sigma)
  1362. def run_sigma_dut_dpp_proto_initiator(dev, step, frame, attr, result, fail):
  1363. addr = dev[1].own_addr().replace(':', '')
  1364. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1365. res = dev[1].request(cmd)
  1366. if "FAIL" in res:
  1367. raise Exception("Failed to generate bootstrapping info")
  1368. id0 = int(res)
  1369. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1370. cmd = "DPP_LISTEN 2437 role=enrollee"
  1371. if "OK" not in dev[1].request(cmd):
  1372. raise Exception("Failed to start listen operation")
  1373. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1374. if "status,COMPLETE" not in res:
  1375. raise Exception("dev_exec_action did not succeed: " + res)
  1376. 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),
  1377. timeout=10)
  1378. if result not in res:
  1379. raise Exception("Unexpected result: " + res)
  1380. if fail:
  1381. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1382. if ev is None or fail not in ev:
  1383. raise Exception("Failure not reported correctly: " + str(ev))
  1384. dev[1].request("DPP_STOP_LISTEN")
  1385. dev[0].dump_monitor()
  1386. dev[1].dump_monitor()
  1387. def test_sigma_dut_dpp_proto_responder(dev, apdev):
  1388. """sigma_dut DPP protocol testing - Responder"""
  1389. check_dpp_capab(dev[0])
  1390. check_dpp_capab(dev[1])
  1391. tests = [ ("MissingAttribute", "AuthenticationResponse", "DPPStatus",
  1392. "BootstrapResult,OK,AuthResult,Errorsent",
  1393. "Missing or invalid required DPP Status attribute"),
  1394. ("MissingAttribute", "ConfigurationRequest", "EnrolleeNonce",
  1395. "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent",
  1396. "Missing or invalid Enrollee Nonce attribute") ]
  1397. for step, frame, attr, result, fail in tests:
  1398. dev[0].request("FLUSH")
  1399. dev[1].request("FLUSH")
  1400. sigma = start_sigma_dut(dev[0].ifname)
  1401. try:
  1402. run_sigma_dut_dpp_proto_responder(dev, step, frame, attr, result,
  1403. fail)
  1404. finally:
  1405. stop_sigma_dut(sigma)
  1406. def run_sigma_dut_dpp_proto_responder(dev, step, frame, attr, result, fail):
  1407. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  1408. if "status,COMPLETE" not in res:
  1409. raise Exception("dev_exec_action did not succeed: " + res)
  1410. hex = res.split(',')[3]
  1411. uri = hex.decode('hex')
  1412. logger.info("URI from sigma_dut: " + uri)
  1413. res = dev[1].request("DPP_QR_CODE " + uri)
  1414. if "FAIL" in res:
  1415. raise Exception("Failed to parse QR Code URI")
  1416. id1 = int(res)
  1417. t = threading.Thread(target=dpp_proto_init, args=(dev[1], id1))
  1418. t.start()
  1419. 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)
  1420. t.join()
  1421. if result not in res:
  1422. raise Exception("Unexpected result: " + res)
  1423. if fail:
  1424. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1425. if ev is None or fail not in ev:
  1426. raise Exception("Failure not reported correctly:" + str(ev))
  1427. dev[1].request("DPP_STOP_LISTEN")
  1428. dev[0].dump_monitor()
  1429. dev[1].dump_monitor()
  1430. def test_sigma_dut_dpp_proto_stop_at_initiator(dev, apdev):
  1431. """sigma_dut DPP protocol testing - Stop at RX on Initiator"""
  1432. check_dpp_capab(dev[0])
  1433. check_dpp_capab(dev[1])
  1434. tests = [ ("AuthenticationResponse",
  1435. "BootstrapResult,OK,AuthResult,Errorsent",
  1436. None),
  1437. ("ConfigurationRequest",
  1438. "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent",
  1439. None)]
  1440. for frame, result, fail in tests:
  1441. dev[0].request("FLUSH")
  1442. dev[1].request("FLUSH")
  1443. sigma = start_sigma_dut(dev[0].ifname)
  1444. try:
  1445. run_sigma_dut_dpp_proto_stop_at_initiator(dev, frame, result, fail)
  1446. finally:
  1447. stop_sigma_dut(sigma)
  1448. def run_sigma_dut_dpp_proto_stop_at_initiator(dev, frame, result, fail):
  1449. addr = dev[1].own_addr().replace(':', '')
  1450. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1451. res = dev[1].request(cmd)
  1452. if "FAIL" in res:
  1453. raise Exception("Failed to generate bootstrapping info")
  1454. id0 = int(res)
  1455. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1456. cmd = "DPP_LISTEN 2437 role=enrollee"
  1457. if "OK" not in dev[1].request(cmd):
  1458. raise Exception("Failed to start listen operation")
  1459. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1460. if "status,COMPLETE" not in res:
  1461. raise Exception("dev_exec_action did not succeed: " + res)
  1462. 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,Timeout,DPPFrameType,%s" % (frame))
  1463. if result not in res:
  1464. raise Exception("Unexpected result: " + res)
  1465. if fail:
  1466. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1467. if ev is None or fail not in ev:
  1468. raise Exception("Failure not reported correctly: " + str(ev))
  1469. dev[1].request("DPP_STOP_LISTEN")
  1470. dev[0].dump_monitor()
  1471. dev[1].dump_monitor()
  1472. def test_sigma_dut_dpp_proto_stop_at_responder(dev, apdev):
  1473. """sigma_dut DPP protocol testing - Stop at RX on Responder"""
  1474. check_dpp_capab(dev[0])
  1475. check_dpp_capab(dev[1])
  1476. tests = [ ("AuthenticationRequest",
  1477. "BootstrapResult,OK,AuthResult,Errorsent",
  1478. None),
  1479. ("AuthenticationConfirm",
  1480. "BootstrapResult,OK,AuthResult,Errorsent",
  1481. None) ]
  1482. for frame, result, fail in tests:
  1483. dev[0].request("FLUSH")
  1484. dev[1].request("FLUSH")
  1485. sigma = start_sigma_dut(dev[0].ifname)
  1486. try:
  1487. run_sigma_dut_dpp_proto_stop_at_responder(dev, frame, result, fail)
  1488. finally:
  1489. stop_sigma_dut(sigma)
  1490. def run_sigma_dut_dpp_proto_stop_at_responder(dev, frame, result, fail):
  1491. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  1492. if "status,COMPLETE" not in res:
  1493. raise Exception("dev_exec_action did not succeed: " + res)
  1494. hex = res.split(',')[3]
  1495. uri = hex.decode('hex')
  1496. logger.info("URI from sigma_dut: " + uri)
  1497. res = dev[1].request("DPP_QR_CODE " + uri)
  1498. if "FAIL" in res:
  1499. raise Exception("Failed to parse QR Code URI")
  1500. id1 = int(res)
  1501. t = threading.Thread(target=dpp_proto_init, args=(dev[1], id1))
  1502. t.start()
  1503. 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,Timeout,DPPFrameType,%s" % (frame), timeout=10)
  1504. t.join()
  1505. if result not in res:
  1506. raise Exception("Unexpected result: " + res)
  1507. if fail:
  1508. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1509. if ev is None or fail not in ev:
  1510. raise Exception("Failure not reported correctly:" + str(ev))
  1511. dev[1].request("DPP_STOP_LISTEN")
  1512. dev[0].dump_monitor()
  1513. dev[1].dump_monitor()
  1514. def dpp_proto_init_pkex(dev):
  1515. time.sleep(1)
  1516. logger.info("Starting DPP PKEX initiator/configurator in a thread")
  1517. cmd = "DPP_CONFIGURATOR_ADD"
  1518. res = dev.request(cmd);
  1519. if "FAIL" in res:
  1520. raise Exception("Failed to add configurator")
  1521. conf_id = int(res)
  1522. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1523. res = dev.request(cmd)
  1524. if "FAIL" in res:
  1525. raise Exception("Failed to generate bootstrapping info")
  1526. id = int(res)
  1527. cmd = "DPP_PKEX_ADD own=%d init=1 conf=sta-dpp configurator=%d code=secret" % (id, conf_id)
  1528. if "FAIL" in dev.request(cmd):
  1529. raise Exception("Failed to initiate DPP PKEX")
  1530. def test_sigma_dut_dpp_proto_initiator_pkex(dev, apdev):
  1531. """sigma_dut DPP protocol testing - Initiator (PKEX)"""
  1532. check_dpp_capab(dev[0])
  1533. check_dpp_capab(dev[1])
  1534. tests = [ ("InvalidValue", "PKEXCRRequest", "WrappedData",
  1535. "BootstrapResult,Errorsent",
  1536. None),
  1537. ("MissingAttribute", "PKEXExchangeRequest", "FiniteCyclicGroup",
  1538. "BootstrapResult,Errorsent",
  1539. "Missing or invalid Finite Cyclic Group attribute"),
  1540. ("MissingAttribute", "PKEXCRRequest", "BSKey",
  1541. "BootstrapResult,Errorsent",
  1542. "No valid peer bootstrapping key found") ]
  1543. for step, frame, attr, result, fail in tests:
  1544. dev[0].request("FLUSH")
  1545. dev[1].request("FLUSH")
  1546. sigma = start_sigma_dut(dev[0].ifname)
  1547. try:
  1548. run_sigma_dut_dpp_proto_initiator_pkex(dev, step, frame, attr,
  1549. result, fail)
  1550. finally:
  1551. stop_sigma_dut(sigma)
  1552. def run_sigma_dut_dpp_proto_initiator_pkex(dev, step, frame, attr, result, fail):
  1553. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1554. res = dev[1].request(cmd)
  1555. if "FAIL" in res:
  1556. raise Exception("Failed to generate bootstrapping info")
  1557. id1 = int(res)
  1558. cmd = "DPP_PKEX_ADD own=%d code=secret" % (id1)
  1559. res = dev[1].request(cmd)
  1560. if "FAIL" in res:
  1561. raise Exception("Failed to set PKEX data (responder)")
  1562. cmd = "DPP_LISTEN 2437 role=enrollee"
  1563. if "OK" not in dev[1].request(cmd):
  1564. raise Exception("Failed to start listen operation")
  1565. 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))
  1566. if result not in res:
  1567. raise Exception("Unexpected result: " + res)
  1568. if fail:
  1569. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1570. if ev is None or fail not in ev:
  1571. raise Exception("Failure not reported correctly: " + str(ev))
  1572. dev[1].request("DPP_STOP_LISTEN")
  1573. dev[0].dump_monitor()
  1574. dev[1].dump_monitor()
  1575. def test_sigma_dut_dpp_proto_responder_pkex(dev, apdev):
  1576. """sigma_dut DPP protocol testing - Responder (PKEX)"""
  1577. check_dpp_capab(dev[0])
  1578. check_dpp_capab(dev[1])
  1579. tests = [ ("InvalidValue", "PKEXCRResponse", "WrappedData",
  1580. "BootstrapResult,Errorsent",
  1581. None),
  1582. ("MissingAttribute", "PKEXExchangeResponse", "DPPStatus",
  1583. "BootstrapResult,Errorsent",
  1584. "No DPP Status attribute"),
  1585. ("MissingAttribute", "PKEXCRResponse", "BSKey",
  1586. "BootstrapResult,Errorsent",
  1587. "No valid peer bootstrapping key found") ]
  1588. for step, frame, attr, result, fail in tests:
  1589. dev[0].request("FLUSH")
  1590. dev[1].request("FLUSH")
  1591. sigma = start_sigma_dut(dev[0].ifname)
  1592. try:
  1593. run_sigma_dut_dpp_proto_responder_pkex(dev, step, frame, attr,
  1594. result, fail)
  1595. finally:
  1596. stop_sigma_dut(sigma)
  1597. def run_sigma_dut_dpp_proto_responder_pkex(dev, step, frame, attr, result, fail):
  1598. t = threading.Thread(target=dpp_proto_init_pkex, args=(dev[1],))
  1599. t.start()
  1600. 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)
  1601. t.join()
  1602. if result not in res:
  1603. raise Exception("Unexpected result: " + res)
  1604. if fail:
  1605. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1606. if ev is None or fail not in ev:
  1607. raise Exception("Failure not reported correctly:" + str(ev))
  1608. dev[1].request("DPP_STOP_LISTEN")
  1609. dev[0].dump_monitor()
  1610. dev[1].dump_monitor()
  1611. def init_sigma_dut_dpp_proto_peer_disc_req(dev, apdev):
  1612. check_dpp_capab(dev[0])
  1613. check_dpp_capab(dev[1])
  1614. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  1615. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  1616. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  1617. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  1618. params = { "ssid": "DPPNET01",
  1619. "wpa": "2",
  1620. "ieee80211w": "2",
  1621. "wpa_key_mgmt": "DPP",
  1622. "rsn_pairwise": "CCMP",
  1623. "dpp_connector": ap_connector,
  1624. "dpp_csign": csign_pub,
  1625. "dpp_netaccesskey": ap_netaccesskey }
  1626. try:
  1627. hapd = hostapd.add_ap(apdev[0], params)
  1628. except:
  1629. raise HwsimSkip("DPP not supported")
  1630. dev[0].set("dpp_config_processing", "2")
  1631. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  1632. res = dev[1].request(cmd);
  1633. if "FAIL" in res:
  1634. raise Exception("Failed to add configurator")
  1635. conf_id = int(res)
  1636. addr = dev[1].own_addr().replace(':', '')
  1637. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1638. res = dev[1].request(cmd)
  1639. if "FAIL" in res:
  1640. raise Exception("Failed to generate bootstrapping info")
  1641. id0 = int(res)
  1642. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1643. dev[1].set("dpp_configurator_params",
  1644. " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id));
  1645. cmd = "DPP_LISTEN 2437 role=configurator"
  1646. if "OK" not in dev[1].request(cmd):
  1647. raise Exception("Failed to start listen operation")
  1648. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1649. if "status,COMPLETE" not in res:
  1650. raise Exception("dev_exec_action did not succeed: " + res)
  1651. def test_sigma_dut_dpp_proto_peer_disc_req(dev, apdev):
  1652. """sigma_dut DPP protocol testing - Peer Discovery Request"""
  1653. sigma = start_sigma_dut(dev[0].ifname)
  1654. try:
  1655. init_sigma_dut_dpp_proto_peer_disc_req(dev, apdev)
  1656. 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)
  1657. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Errorsent" not in res:
  1658. raise Exception("Unexpected result: " + res)
  1659. finally:
  1660. dev[0].set("dpp_config_processing", "0")
  1661. stop_sigma_dut(sigma)
  1662. def test_sigma_dut_dpp_self_config(dev, apdev):
  1663. """sigma_dut DPP Configurator enrolling an AP and using self-configuration"""
  1664. check_dpp_capab(dev[0])
  1665. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  1666. check_dpp_capab(hapd)
  1667. sigma = start_sigma_dut(dev[0].ifname)
  1668. try:
  1669. dev[0].set("dpp_config_processing", "2")
  1670. addr = hapd.own_addr().replace(':', '')
  1671. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1672. res = hapd.request(cmd)
  1673. if "FAIL" in res:
  1674. raise Exception("Failed to generate bootstrapping info")
  1675. id = int(res)
  1676. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id)
  1677. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri.encode('hex'))
  1678. if "status,COMPLETE" not in res:
  1679. raise Exception("dev_exec_action did not succeed: " + res)
  1680. 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")
  1681. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1682. raise Exception("Unexpected result: " + res)
  1683. update_hapd_config(hapd)
  1684. 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"
  1685. res = sigma_dut_cmd(cmd, timeout=10)
  1686. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  1687. raise Exception("Unexpected result: " + res)
  1688. finally:
  1689. stop_sigma_dut(sigma)
  1690. dev[0].set("dpp_config_processing", "0")
  1691. def test_sigma_dut_ap_dpp_self_config(dev, apdev, params):
  1692. """sigma_dut DPP AP Configurator using self-configuration"""
  1693. logdir = os.path.join(params['logdir'],
  1694. "sigma_dut_ap_dpp_self_config.sigma-hostapd")
  1695. with HWSimRadio() as (radio, iface):
  1696. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  1697. try:
  1698. run_sigma_dut_ap_dpp_self_config(dev, apdev)
  1699. finally:
  1700. stop_sigma_dut(sigma)
  1701. dev[0].set("dpp_config_processing", "0")
  1702. def run_sigma_dut_ap_dpp_self_config(dev, apdev):
  1703. check_dpp_capab(dev[0])
  1704. sigma_dut_cmd_check("ap_reset_default,program,DPP")
  1705. 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)
  1706. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1707. raise Exception("Unexpected result: " + res)
  1708. dev[0].set("dpp_config_processing", "2")
  1709. addr = dev[0].own_addr().replace(':', '')
  1710. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/11 mac=" + addr
  1711. res = dev[0].request(cmd)
  1712. if "FAIL" in res:
  1713. raise Exception("Failed to generate bootstrapping info")
  1714. id = int(res)
  1715. uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
  1716. cmd = "DPP_LISTEN 2462 role=enrollee"
  1717. if "OK" not in dev[0].request(cmd):
  1718. raise Exception("Failed to start listen operation")
  1719. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri.encode('hex'))
  1720. if "status,COMPLETE" not in res:
  1721. raise Exception("dev_exec_action did not succeed: " + res)
  1722. 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"
  1723. res = sigma_dut_cmd(cmd)
  1724. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1725. raise Exception("Unexpected result: " + res)
  1726. dev[0].wait_connected()
  1727. dev[0].request("DISCONNECT")
  1728. dev[0].wait_disconnected()
  1729. sigma_dut_cmd_check("ap_reset_default")
  1730. def test_sigma_dut_preconfigured_profile(dev, apdev):
  1731. """sigma_dut controlled connection using preconfigured profile"""
  1732. try:
  1733. run_sigma_dut_preconfigured_profile(dev, apdev)
  1734. finally:
  1735. dev[0].set("ignore_old_scan_res", "0")
  1736. def run_sigma_dut_preconfigured_profile(dev, apdev):
  1737. ifname = dev[0].ifname
  1738. sigma = start_sigma_dut(ifname)
  1739. params = hostapd.wpa2_params(ssid="test-psk", passphrase="12345678")
  1740. hapd = hostapd.add_ap(apdev[0], params)
  1741. dev[0].connect("test-psk", psk="12345678", scan_freq="2412",
  1742. only_add_network=True)
  1743. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  1744. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s" % (ifname, "test-psk"))
  1745. sigma_dut_wait_connected(ifname)
  1746. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  1747. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  1748. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  1749. stop_sigma_dut(sigma)
  1750. def test_sigma_dut_wps_pbc(dev, apdev):
  1751. """sigma_dut and WPS PBC Enrollee"""
  1752. try:
  1753. run_sigma_dut_wps_pbc(dev, apdev)
  1754. finally:
  1755. dev[0].set("ignore_old_scan_res", "0")
  1756. def run_sigma_dut_wps_pbc(dev, apdev):
  1757. ssid = "test-wps-conf"
  1758. hapd = hostapd.add_ap(apdev[0],
  1759. { "ssid": "wps", "eap_server": "1", "wps_state": "2",
  1760. "wpa_passphrase": "12345678", "wpa": "2",
  1761. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  1762. hapd.request("WPS_PBC")
  1763. ifname = dev[0].ifname
  1764. sigma = start_sigma_dut(ifname)
  1765. cmd = "start_wps_registration,interface,%s" % ifname
  1766. cmd += ",WpsRole,Enrollee"
  1767. cmd += ",WpsConfigMethod,PBC"
  1768. sigma_dut_cmd_check(cmd, timeout=15)
  1769. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  1770. hapd.disable()
  1771. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  1772. stop_sigma_dut(sigma)
  1773. dev[0].flush_scan_cache()
  1774. def test_sigma_dut_sta_scan_bss(dev, apdev):
  1775. """sigma_dut sta_scan_bss"""
  1776. hapd = hostapd.add_ap(apdev[0], { "ssid": "test" })
  1777. sigma = start_sigma_dut(dev[0].ifname)
  1778. try:
  1779. cmd = "sta_scan_bss,Interface,%s,BSSID,%s" % (dev[0].ifname, \
  1780. hapd.own_addr())
  1781. res = sigma_dut_cmd(cmd, timeout=10)
  1782. if "ssid,test,bsschannel,1" not in res:
  1783. raise Exception("Unexpected result: " + res)
  1784. finally:
  1785. stop_sigma_dut(sigma)