test_sigma_dut.py 93 KB

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