test_sigma_dut.py 91 KB

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