test_sigma_dut.py 73 KB

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