test_sigma_dut.py 74 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604
  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 test_sigma_dut_ap_cipher_ccmp_gcmp_1(dev, apdev, params):
  430. """sigma_dut controlled AP with CCMP-128+GCMP-256 ciphers (1)"""
  431. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-128 AES-GCMP-256",
  432. "BIP-GMAC-256", "CCMP")
  433. def test_sigma_dut_ap_cipher_ccmp_gcmp_2(dev, apdev, params):
  434. """sigma_dut controlled AP with CCMP-128+GCMP-256 ciphers (2)"""
  435. run_sigma_dut_ap_cipher(dev, apdev, params, "AES-CCMP-128 AES-GCMP-256",
  436. "BIP-GMAC-256", "GCMP-256", "CCMP")
  437. def run_sigma_dut_ap_cipher(dev, apdev, params, ap_pairwise, ap_group_mgmt,
  438. sta_cipher, sta_cipher_group=None):
  439. check_suite_b_192_capa(dev)
  440. logdir = os.path.join(params['logdir'],
  441. "sigma_dut_ap_cipher.sigma-hostapd")
  442. params = suite_b_as_params()
  443. params['ca_cert'] = 'auth_serv/ec2-ca.pem'
  444. params['server_cert'] = 'auth_serv/ec2-server.pem'
  445. params['private_key'] = 'auth_serv/ec2-server.key'
  446. params['openssl_ciphers'] = 'SUITEB192'
  447. hostapd.add_ap(apdev[1], params)
  448. with HWSimRadio() as (radio, iface):
  449. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  450. try:
  451. sigma_dut_cmd_check("ap_reset_default")
  452. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-suite-b,MODE,11ng")
  453. sigma_dut_cmd_check("ap_set_radius,NAME,AP,IPADDR,127.0.0.1,PORT,18129,PASSWORD,radius")
  454. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,SuiteB,PMF,Required,PairwiseCipher,%s,GroupMgntCipher,%s" % (ap_pairwise, ap_group_mgmt))
  455. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  456. if sta_cipher_group is None:
  457. sta_cipher_group = sta_cipher
  458. dev[0].connect("test-suite-b", key_mgmt="WPA-EAP-SUITE-B-192",
  459. ieee80211w="2",
  460. openssl_ciphers="SUITEB192",
  461. eap="TLS", identity="tls user",
  462. ca_cert="auth_serv/ec2-ca.pem",
  463. client_cert="auth_serv/ec2-user.pem",
  464. private_key="auth_serv/ec2-user.key",
  465. pairwise=sta_cipher, group=sta_cipher_group,
  466. scan_freq="2412")
  467. sigma_dut_cmd_check("ap_reset_default")
  468. finally:
  469. stop_sigma_dut(sigma)
  470. def test_sigma_dut_ap_override_rsne(dev, apdev):
  471. """sigma_dut controlled AP overriding RSNE"""
  472. with HWSimRadio() as (radio, iface):
  473. sigma = start_sigma_dut(iface)
  474. try:
  475. sigma_dut_cmd_check("ap_reset_default")
  476. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-psk,MODE,11ng")
  477. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK,PSK,12345678")
  478. sigma_dut_cmd_check("dev_configure_ie,NAME,AP,interface,%s,IE_Name,RSNE,Contents,30180100000fac040200ffffffff000fac040100000fac020c00" % iface)
  479. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  480. dev[0].connect("test-psk", psk="12345678", scan_freq="2412")
  481. sigma_dut_cmd_check("ap_reset_default")
  482. finally:
  483. stop_sigma_dut(sigma)
  484. def test_sigma_dut_ap_sae(dev, apdev):
  485. """sigma_dut controlled AP with SAE"""
  486. with HWSimRadio() as (radio, iface):
  487. sigma = start_sigma_dut(iface)
  488. try:
  489. sigma_dut_cmd_check("ap_reset_default")
  490. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  491. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678")
  492. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  493. dev[0].request("SET sae_groups ")
  494. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  495. scan_freq="2412")
  496. if dev[0].get_status_field('sae_group') != '19':
  497. raise Exception("Expected default SAE group not used")
  498. sigma_dut_cmd_check("ap_reset_default")
  499. finally:
  500. stop_sigma_dut(sigma)
  501. def test_sigma_dut_ap_sae_password(dev, apdev):
  502. """sigma_dut controlled AP with SAE and long password"""
  503. with HWSimRadio() as (radio, iface):
  504. sigma = start_sigma_dut(iface)
  505. try:
  506. sigma_dut_cmd_check("ap_reset_default")
  507. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  508. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK," + 100*'C')
  509. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  510. dev[0].request("SET sae_groups ")
  511. dev[0].connect("test-sae", key_mgmt="SAE", sae_password=100*'C',
  512. scan_freq="2412")
  513. if dev[0].get_status_field('sae_group') != '19':
  514. raise Exception("Expected default SAE group not used")
  515. sigma_dut_cmd_check("ap_reset_default")
  516. finally:
  517. stop_sigma_dut(sigma)
  518. def test_sigma_dut_ap_sae_group(dev, apdev):
  519. """sigma_dut controlled AP with SAE and specific group"""
  520. with HWSimRadio() as (radio, iface):
  521. sigma = start_sigma_dut(iface)
  522. try:
  523. sigma_dut_cmd_check("ap_reset_default")
  524. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  525. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,ECGroupID,20")
  526. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  527. dev[0].request("SET sae_groups ")
  528. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  529. scan_freq="2412")
  530. if dev[0].get_status_field('sae_group') != '20':
  531. raise Exception("Expected SAE group not used")
  532. sigma_dut_cmd_check("ap_reset_default")
  533. finally:
  534. stop_sigma_dut(sigma)
  535. def test_sigma_dut_ap_psk_sae(dev, apdev):
  536. """sigma_dut controlled AP with PSK+SAE"""
  537. with HWSimRadio() as (radio, iface):
  538. sigma = start_sigma_dut(iface)
  539. try:
  540. sigma_dut_cmd_check("ap_reset_default")
  541. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  542. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK-SAE,PSK,12345678")
  543. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  544. dev[0].request("SET sae_groups ")
  545. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  546. scan_freq="2412")
  547. dev[1].connect("test-sae", psk="12345678", scan_freq="2412")
  548. sigma_dut_cmd_check("ap_reset_default")
  549. finally:
  550. stop_sigma_dut(sigma)
  551. def test_sigma_dut_owe(dev, apdev):
  552. """sigma_dut controlled OWE station"""
  553. try:
  554. run_sigma_dut_owe(dev, apdev)
  555. finally:
  556. dev[0].set("ignore_old_scan_res", "0")
  557. def run_sigma_dut_owe(dev, apdev):
  558. if "OWE" not in dev[0].get_capability("key_mgmt"):
  559. raise HwsimSkip("OWE not supported")
  560. ifname = dev[0].ifname
  561. sigma = start_sigma_dut(ifname)
  562. try:
  563. params = { "ssid": "owe",
  564. "wpa": "2",
  565. "wpa_key_mgmt": "OWE",
  566. "rsn_pairwise": "CCMP" }
  567. hapd = hostapd.add_ap(apdev[0], params)
  568. bssid = hapd.own_addr()
  569. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  570. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  571. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE" % ifname)
  572. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  573. sigma_dut_wait_connected(ifname)
  574. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  575. dev[0].dump_monitor()
  576. sigma_dut_cmd("sta_reassoc,interface,%s,Channel,1,bssid,%s" % (ifname, bssid))
  577. dev[0].wait_connected()
  578. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  579. dev[0].wait_disconnected()
  580. dev[0].dump_monitor()
  581. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  582. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  583. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,20" % ifname)
  584. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  585. sigma_dut_wait_connected(ifname)
  586. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  587. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  588. dev[0].wait_disconnected()
  589. dev[0].dump_monitor()
  590. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  591. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  592. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,0" % ifname)
  593. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  594. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  595. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  596. if ev is None:
  597. raise Exception("Association not rejected")
  598. if "status_code=77" not in ev:
  599. raise Exception("Unexpected rejection reason: " + ev)
  600. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  601. finally:
  602. stop_sigma_dut(sigma)
  603. def test_sigma_dut_ap_owe(dev, apdev):
  604. """sigma_dut controlled AP with OWE"""
  605. if "OWE" not in dev[0].get_capability("key_mgmt"):
  606. raise HwsimSkip("OWE not supported")
  607. with HWSimRadio() as (radio, iface):
  608. sigma = start_sigma_dut(iface)
  609. try:
  610. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  611. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
  612. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE")
  613. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  614. dev[0].connect("owe", key_mgmt="OWE", scan_freq="2412")
  615. sigma_dut_cmd_check("ap_reset_default")
  616. finally:
  617. stop_sigma_dut(sigma)
  618. def test_sigma_dut_ap_owe_ecgroupid(dev, apdev):
  619. """sigma_dut controlled AP with OWE and ECGroupID"""
  620. if "OWE" not in dev[0].get_capability("key_mgmt"):
  621. raise HwsimSkip("OWE not supported")
  622. with HWSimRadio() as (radio, iface):
  623. sigma = start_sigma_dut(iface)
  624. try:
  625. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  626. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
  627. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE,ECGroupID,20 21,PMF,Required")
  628. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  629. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  630. owe_group="20", scan_freq="2412")
  631. dev[0].request("REMOVE_NETWORK all")
  632. dev[0].wait_disconnected()
  633. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  634. owe_group="21", scan_freq="2412")
  635. dev[0].request("REMOVE_NETWORK all")
  636. dev[0].wait_disconnected()
  637. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  638. owe_group="19", scan_freq="2412", wait_connect=False)
  639. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  640. dev[0].request("DISCONNECT")
  641. if ev is None:
  642. raise Exception("Association not rejected")
  643. if "status_code=77" not in ev:
  644. raise Exception("Unexpected rejection reason: " + ev)
  645. dev[0].dump_monitor()
  646. sigma_dut_cmd_check("ap_reset_default")
  647. finally:
  648. stop_sigma_dut(sigma)
  649. def test_sigma_dut_ap_owe_transition_mode(dev, apdev, params):
  650. """sigma_dut controlled AP with OWE and transition mode"""
  651. if "OWE" not in dev[0].get_capability("key_mgmt"):
  652. raise HwsimSkip("OWE not supported")
  653. logdir = os.path.join(params['logdir'],
  654. "sigma_dut_ap_owe_transition_mode.sigma-hostapd")
  655. with HWSimRadio() as (radio, iface):
  656. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  657. try:
  658. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  659. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,1,CHANNEL,1,SSID,owe,MODE,11ng")
  660. sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,1,KEYMGNT,OWE")
  661. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,2,CHANNEL,1,SSID,owe,MODE,11ng")
  662. sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,2,KEYMGNT,NONE")
  663. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  664. res1 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,1,Interface,24G")
  665. res2 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,2,Interface,24G")
  666. dev[0].connect("owe", key_mgmt="OWE", scan_freq="2412")
  667. dev[1].connect("owe", key_mgmt="NONE", scan_freq="2412")
  668. if dev[0].get_status_field('bssid') not in res1:
  669. raise Exception("Unexpected ap_get_mac_address WLAN_TAG,1: " + res1)
  670. if dev[1].get_status_field('bssid') not in res2:
  671. raise Exception("Unexpected ap_get_mac_address WLAN_TAG,2: " + res2)
  672. sigma_dut_cmd_check("ap_reset_default")
  673. finally:
  674. stop_sigma_dut(sigma)
  675. def dpp_init_enrollee(dev, id1):
  676. logger.info("Starting DPP initiator/enrollee in a thread")
  677. time.sleep(1)
  678. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  679. if "OK" not in dev.request(cmd):
  680. raise Exception("Failed to initiate DPP Authentication")
  681. ev = dev.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  682. if ev is None:
  683. raise Exception("DPP configuration not completed (Enrollee)")
  684. logger.info("DPP initiator/enrollee done")
  685. def test_sigma_dut_dpp_qr_resp_1(dev, apdev):
  686. """sigma_dut DPP/QR responder (conf index 1)"""
  687. run_sigma_dut_dpp_qr_resp(dev, apdev, 1)
  688. def test_sigma_dut_dpp_qr_resp_2(dev, apdev):
  689. """sigma_dut DPP/QR responder (conf index 2)"""
  690. run_sigma_dut_dpp_qr_resp(dev, apdev, 2)
  691. def test_sigma_dut_dpp_qr_resp_3(dev, apdev):
  692. """sigma_dut DPP/QR responder (conf index 3)"""
  693. run_sigma_dut_dpp_qr_resp(dev, apdev, 3)
  694. def test_sigma_dut_dpp_qr_resp_4(dev, apdev):
  695. """sigma_dut DPP/QR responder (conf index 4)"""
  696. run_sigma_dut_dpp_qr_resp(dev, apdev, 4)
  697. def test_sigma_dut_dpp_qr_resp_chan_list(dev, apdev):
  698. """sigma_dut DPP/QR responder (channel list override)"""
  699. run_sigma_dut_dpp_qr_resp(dev, apdev, 1, chan_list='81/2 81/6 81/1',
  700. listen_chan=2)
  701. def run_sigma_dut_dpp_qr_resp(dev, apdev, conf_idx, chan_list=None,
  702. listen_chan=None):
  703. check_dpp_capab(dev[0])
  704. check_dpp_capab(dev[1])
  705. sigma = start_sigma_dut(dev[0].ifname)
  706. try:
  707. cmd = "dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR"
  708. if chan_list:
  709. cmd += ",DPPChannelList," + chan_list
  710. res = sigma_dut_cmd(cmd)
  711. if "status,COMPLETE" not in res:
  712. raise Exception("dev_exec_action did not succeed: " + res)
  713. hex = res.split(',')[3]
  714. uri = hex.decode('hex')
  715. logger.info("URI from sigma_dut: " + uri)
  716. res = dev[1].request("DPP_QR_CODE " + uri)
  717. if "FAIL" in res:
  718. raise Exception("Failed to parse QR Code URI")
  719. id1 = int(res)
  720. t = threading.Thread(target=dpp_init_enrollee, args=(dev[1], id1))
  721. t.start()
  722. 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
  723. if listen_chan:
  724. cmd += ",DPPListenChannel," + str(listen_chan)
  725. res = sigma_dut_cmd(cmd, timeout=10)
  726. t.join()
  727. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  728. raise Exception("Unexpected result: " + res)
  729. finally:
  730. stop_sigma_dut(sigma)
  731. def test_sigma_dut_dpp_qr_init_enrollee(dev, apdev):
  732. """sigma_dut DPP/QR initiator as Enrollee"""
  733. check_dpp_capab(dev[0])
  734. check_dpp_capab(dev[1])
  735. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  736. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  737. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  738. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  739. params = { "ssid": "DPPNET01",
  740. "wpa": "2",
  741. "wpa_key_mgmt": "DPP",
  742. "rsn_pairwise": "CCMP",
  743. "dpp_connector": ap_connector,
  744. "dpp_csign": csign_pub,
  745. "dpp_netaccesskey": ap_netaccesskey }
  746. try:
  747. hapd = hostapd.add_ap(apdev[0], params)
  748. except:
  749. raise HwsimSkip("DPP not supported")
  750. sigma = start_sigma_dut(dev[0].ifname)
  751. try:
  752. dev[0].set("dpp_config_processing", "2")
  753. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  754. res = dev[1].request(cmd);
  755. if "FAIL" in res:
  756. raise Exception("Failed to add configurator")
  757. conf_id = int(res)
  758. addr = dev[1].own_addr().replace(':', '')
  759. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  760. res = dev[1].request(cmd)
  761. if "FAIL" in res:
  762. raise Exception("Failed to generate bootstrapping info")
  763. id0 = int(res)
  764. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  765. dev[1].set("dpp_configurator_params",
  766. " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id));
  767. cmd = "DPP_LISTEN 2437 role=configurator"
  768. if "OK" not in dev[1].request(cmd):
  769. raise Exception("Failed to start listen operation")
  770. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  771. if "status,COMPLETE" not in res:
  772. raise Exception("dev_exec_action did not succeed: " + res)
  773. 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)
  774. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  775. raise Exception("Unexpected result: " + res)
  776. finally:
  777. dev[0].set("dpp_config_processing", "0")
  778. stop_sigma_dut(sigma)
  779. def test_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev):
  780. """sigma_dut DPP/QR (mutual) initiator as Enrollee"""
  781. check_dpp_capab(dev[0])
  782. check_dpp_capab(dev[1])
  783. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  784. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  785. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  786. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  787. params = { "ssid": "DPPNET01",
  788. "wpa": "2",
  789. "wpa_key_mgmt": "DPP",
  790. "rsn_pairwise": "CCMP",
  791. "dpp_connector": ap_connector,
  792. "dpp_csign": csign_pub,
  793. "dpp_netaccesskey": ap_netaccesskey }
  794. try:
  795. hapd = hostapd.add_ap(apdev[0], params)
  796. except:
  797. raise HwsimSkip("DPP not supported")
  798. sigma = start_sigma_dut(dev[0].ifname)
  799. try:
  800. dev[0].set("dpp_config_processing", "2")
  801. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  802. res = dev[1].request(cmd);
  803. if "FAIL" in res:
  804. raise Exception("Failed to add configurator")
  805. conf_id = int(res)
  806. addr = dev[1].own_addr().replace(':', '')
  807. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  808. res = dev[1].request(cmd)
  809. if "FAIL" in res:
  810. raise Exception("Failed to generate bootstrapping info")
  811. id0 = int(res)
  812. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  813. dev[1].set("dpp_configurator_params",
  814. " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id));
  815. cmd = "DPP_LISTEN 2437 role=configurator qr=mutual"
  816. if "OK" not in dev[1].request(cmd):
  817. raise Exception("Failed to start listen operation")
  818. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  819. if "status,COMPLETE" not in res:
  820. raise Exception("dev_exec_action did not succeed: " + res)
  821. hex = res.split(',')[3]
  822. uri = hex.decode('hex')
  823. logger.info("URI from sigma_dut: " + uri)
  824. res = dev[1].request("DPP_QR_CODE " + uri)
  825. if "FAIL" in res:
  826. raise Exception("Failed to parse QR Code URI")
  827. id1 = int(res)
  828. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  829. if "status,COMPLETE" not in res:
  830. raise Exception("dev_exec_action did not succeed: " + res)
  831. 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)
  832. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  833. raise Exception("Unexpected result: " + res)
  834. finally:
  835. dev[0].set("dpp_config_processing", "0")
  836. stop_sigma_dut(sigma)
  837. def dpp_init_conf_mutual(dev, id1, conf_id, own_id=None):
  838. time.sleep(1)
  839. logger.info("Starting DPP initiator/configurator in a thread")
  840. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp ssid=%s configurator=%d" % (id1, "DPPNET01".encode("hex"), conf_id)
  841. if own_id is not None:
  842. cmd += " own=%d" % own_id
  843. if "OK" not in dev.request(cmd):
  844. raise Exception("Failed to initiate DPP Authentication")
  845. ev = dev.wait_event(["DPP-CONF-SENT"], timeout=10)
  846. if ev is None:
  847. raise Exception("DPP configuration not completed (Configurator)")
  848. logger.info("DPP initiator/configurator done")
  849. def test_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev):
  850. """sigma_dut DPP/QR (mutual) responder as Enrollee"""
  851. run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev)
  852. def test_sigma_dut_dpp_qr_mutual_resp_enrollee_pending(dev, apdev):
  853. """sigma_dut DPP/QR (mutual) responder as Enrollee (response pending)"""
  854. run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev, ',DPPDelayQRResponse,1')
  855. def run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev, extra=None):
  856. check_dpp_capab(dev[0])
  857. check_dpp_capab(dev[1])
  858. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  859. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  860. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  861. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  862. params = { "ssid": "DPPNET01",
  863. "wpa": "2",
  864. "wpa_key_mgmt": "DPP",
  865. "rsn_pairwise": "CCMP",
  866. "dpp_connector": ap_connector,
  867. "dpp_csign": csign_pub,
  868. "dpp_netaccesskey": ap_netaccesskey }
  869. try:
  870. hapd = hostapd.add_ap(apdev[0], params)
  871. except:
  872. raise HwsimSkip("DPP not supported")
  873. sigma = start_sigma_dut(dev[0].ifname)
  874. try:
  875. dev[0].set("dpp_config_processing", "2")
  876. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  877. res = dev[1].request(cmd);
  878. if "FAIL" in res:
  879. raise Exception("Failed to add configurator")
  880. conf_id = int(res)
  881. addr = dev[1].own_addr().replace(':', '')
  882. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  883. res = dev[1].request(cmd)
  884. if "FAIL" in res:
  885. raise Exception("Failed to generate bootstrapping info")
  886. id0 = int(res)
  887. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  888. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  889. if "status,COMPLETE" not in res:
  890. raise Exception("dev_exec_action did not succeed: " + res)
  891. hex = res.split(',')[3]
  892. uri = hex.decode('hex')
  893. logger.info("URI from sigma_dut: " + uri)
  894. res = dev[1].request("DPP_QR_CODE " + uri)
  895. if "FAIL" in res:
  896. raise Exception("Failed to parse QR Code URI")
  897. id1 = int(res)
  898. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  899. if "status,COMPLETE" not in res:
  900. raise Exception("dev_exec_action did not succeed: " + res)
  901. t = threading.Thread(target=dpp_init_conf_mutual,
  902. args=(dev[1], id1, conf_id, id0))
  903. t.start()
  904. cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,20,DPPWaitForConnect,Yes"
  905. if extra:
  906. cmd += extra
  907. res = sigma_dut_cmd(cmd, timeout=25)
  908. t.join()
  909. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  910. raise Exception("Unexpected result: " + res)
  911. finally:
  912. dev[0].set("dpp_config_processing", "0")
  913. stop_sigma_dut(sigma)
  914. def test_sigma_dut_dpp_qr_init_enrollee_psk(dev, apdev):
  915. """sigma_dut DPP/QR initiator as Enrollee (PSK)"""
  916. check_dpp_capab(dev[0])
  917. check_dpp_capab(dev[1])
  918. params = hostapd.wpa2_params(ssid="DPPNET01",
  919. passphrase="ThisIsDppPassphrase")
  920. hapd = hostapd.add_ap(apdev[0], params)
  921. sigma = start_sigma_dut(dev[0].ifname)
  922. try:
  923. dev[0].set("dpp_config_processing", "2")
  924. cmd = "DPP_CONFIGURATOR_ADD"
  925. res = dev[1].request(cmd);
  926. if "FAIL" in res:
  927. raise Exception("Failed to add configurator")
  928. conf_id = int(res)
  929. addr = dev[1].own_addr().replace(':', '')
  930. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  931. res = dev[1].request(cmd)
  932. if "FAIL" in res:
  933. raise Exception("Failed to generate bootstrapping info")
  934. id0 = int(res)
  935. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  936. dev[1].set("dpp_configurator_params",
  937. " conf=sta-psk ssid=%s pass=%s configurator=%d" % ("DPPNET01".encode("hex"), "ThisIsDppPassphrase".encode("hex"), conf_id));
  938. cmd = "DPP_LISTEN 2437 role=configurator"
  939. if "OK" not in dev[1].request(cmd):
  940. raise Exception("Failed to start listen operation")
  941. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  942. if "status,COMPLETE" not in res:
  943. raise Exception("dev_exec_action did not succeed: " + res)
  944. 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)
  945. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkConnectResult,OK" not in res:
  946. raise Exception("Unexpected result: " + res)
  947. finally:
  948. dev[0].set("dpp_config_processing", "0")
  949. stop_sigma_dut(sigma)
  950. def test_sigma_dut_dpp_qr_init_configurator_1(dev, apdev):
  951. """sigma_dut DPP/QR initiator as Configurator (conf index 1)"""
  952. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 1)
  953. def test_sigma_dut_dpp_qr_init_configurator_2(dev, apdev):
  954. """sigma_dut DPP/QR initiator as Configurator (conf index 2)"""
  955. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 2)
  956. def test_sigma_dut_dpp_qr_init_configurator_3(dev, apdev):
  957. """sigma_dut DPP/QR initiator as Configurator (conf index 3)"""
  958. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 3)
  959. def test_sigma_dut_dpp_qr_init_configurator_4(dev, apdev):
  960. """sigma_dut DPP/QR initiator as Configurator (conf index 4)"""
  961. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 4)
  962. def run_sigma_dut_dpp_qr_init_configurator(dev, apdev, conf_idx):
  963. check_dpp_capab(dev[0])
  964. check_dpp_capab(dev[1])
  965. sigma = start_sigma_dut(dev[0].ifname)
  966. try:
  967. addr = dev[1].own_addr().replace(':', '')
  968. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  969. res = dev[1].request(cmd)
  970. if "FAIL" in res:
  971. raise Exception("Failed to generate bootstrapping info")
  972. id0 = int(res)
  973. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  974. cmd = "DPP_LISTEN 2437 role=enrollee"
  975. if "OK" not in dev[1].request(cmd):
  976. raise Exception("Failed to start listen operation")
  977. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  978. if "status,COMPLETE" not in res:
  979. raise Exception("dev_exec_action did not succeed: " + res)
  980. 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)
  981. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  982. raise Exception("Unexpected result: " + res)
  983. finally:
  984. stop_sigma_dut(sigma)
  985. def test_sigma_dut_dpp_pkex_init_configurator(dev, apdev):
  986. """sigma_dut DPP/PKEX initiator as Configurator"""
  987. check_dpp_capab(dev[0])
  988. check_dpp_capab(dev[1])
  989. sigma = start_sigma_dut(dev[0].ifname)
  990. try:
  991. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  992. res = dev[1].request(cmd)
  993. if "FAIL" in res:
  994. raise Exception("Failed to generate bootstrapping info")
  995. id1 = int(res)
  996. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id1)
  997. res = dev[1].request(cmd)
  998. if "FAIL" in res:
  999. raise Exception("Failed to set PKEX data (responder)")
  1000. cmd = "DPP_LISTEN 2437 role=enrollee"
  1001. if "OK" not in dev[1].request(cmd):
  1002. raise Exception("Failed to start listen operation")
  1003. 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")
  1004. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1005. raise Exception("Unexpected result: " + res)
  1006. finally:
  1007. stop_sigma_dut(sigma)
  1008. def dpp_init_conf(dev, id1, conf, conf_id, extra):
  1009. logger.info("Starting DPP initiator/configurator in a thread")
  1010. cmd = "DPP_AUTH_INIT peer=%d conf=%s %s configurator=%d" % (id1, conf, extra, conf_id)
  1011. if "OK" not in dev.request(cmd):
  1012. raise Exception("Failed to initiate DPP Authentication")
  1013. ev = dev.wait_event(["DPP-CONF-SENT"], timeout=5)
  1014. if ev is None:
  1015. raise Exception("DPP configuration not completed (Configurator)")
  1016. logger.info("DPP initiator/configurator done")
  1017. def test_sigma_dut_ap_dpp_qr(dev, apdev, params):
  1018. """sigma_dut controlled AP (DPP)"""
  1019. run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-dpp", "sta-dpp")
  1020. def test_sigma_dut_ap_dpp_qr_legacy(dev, apdev, params):
  1021. """sigma_dut controlled AP (legacy)"""
  1022. run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-psk", "sta-psk",
  1023. extra="pass=%s" % "qwertyuiop".encode("hex"))
  1024. def test_sigma_dut_ap_dpp_qr_legacy_psk(dev, apdev, params):
  1025. """sigma_dut controlled AP (legacy)"""
  1026. run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-psk", "sta-psk",
  1027. extra="psk=%s" % (32*"12"))
  1028. def run_sigma_dut_ap_dpp_qr(dev, apdev, params, ap_conf, sta_conf, extra=""):
  1029. logdir = os.path.join(params['logdir'], "sigma_dut_ap_dpp_qr.sigma-hostapd")
  1030. with HWSimRadio() as (radio, iface):
  1031. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  1032. try:
  1033. sigma_dut_cmd_check("ap_reset_default,program,DPP")
  1034. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  1035. if "status,COMPLETE" not in res:
  1036. raise Exception("dev_exec_action did not succeed: " + res)
  1037. hex = res.split(',')[3]
  1038. uri = hex.decode('hex')
  1039. logger.info("URI from sigma_dut: " + uri)
  1040. cmd = "DPP_CONFIGURATOR_ADD"
  1041. res = dev[0].request(cmd);
  1042. if "FAIL" in res:
  1043. raise Exception("Failed to add configurator")
  1044. conf_id = int(res)
  1045. res = dev[0].request("DPP_QR_CODE " + uri)
  1046. if "FAIL" in res:
  1047. raise Exception("Failed to parse QR Code URI")
  1048. id1 = int(res)
  1049. t = threading.Thread(target=dpp_init_conf,
  1050. args=(dev[0], id1, ap_conf, conf_id, extra))
  1051. t.start()
  1052. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6")
  1053. t.join()
  1054. if "ConfResult,OK" not in res:
  1055. raise Exception("Unexpected result: " + res)
  1056. addr = dev[1].own_addr().replace(':', '')
  1057. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1058. res = dev[1].request(cmd)
  1059. if "FAIL" in res:
  1060. raise Exception("Failed to generate bootstrapping info")
  1061. id1 = int(res)
  1062. uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
  1063. res = dev[0].request("DPP_QR_CODE " + uri1)
  1064. if "FAIL" in res:
  1065. raise Exception("Failed to parse QR Code URI")
  1066. id0b = int(res)
  1067. dev[1].set("dpp_config_processing", "2")
  1068. cmd = "DPP_LISTEN 2412"
  1069. if "OK" not in dev[1].request(cmd):
  1070. raise Exception("Failed to start listen operation")
  1071. cmd = "DPP_AUTH_INIT peer=%d conf=%s %s configurator=%d" % (id0b, sta_conf, extra, conf_id)
  1072. if "OK" not in dev[0].request(cmd):
  1073. raise Exception("Failed to initiate DPP Authentication")
  1074. dev[1].wait_connected()
  1075. sigma_dut_cmd_check("ap_reset_default")
  1076. finally:
  1077. dev[1].set("dpp_config_processing", "0")
  1078. stop_sigma_dut(sigma)
  1079. def test_sigma_dut_ap_dpp_pkex_responder(dev, apdev, params):
  1080. """sigma_dut controlled AP as DPP PKEX responder"""
  1081. logdir = os.path.join(params['logdir'],
  1082. "sigma_dut_ap_dpp_pkex_responder.sigma-hostapd")
  1083. with HWSimRadio() as (radio, iface):
  1084. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  1085. try:
  1086. run_sigma_dut_ap_dpp_pkex_responder(dev, apdev)
  1087. finally:
  1088. stop_sigma_dut(sigma)
  1089. def dpp_init_conf_pkex(dev, conf_id):
  1090. logger.info("Starting DPP PKEX initiator/configurator in a thread")
  1091. time.sleep(1.5)
  1092. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1093. res = dev.request(cmd)
  1094. if "FAIL" in res:
  1095. raise Exception("Failed to generate bootstrapping info")
  1096. id = int(res)
  1097. cmd = "DPP_PKEX_ADD own=%d init=1 conf=ap-dpp configurator=%d code=password" % (id, conf_id)
  1098. res = dev.request(cmd)
  1099. if "FAIL" in res:
  1100. raise Exception("Failed to initiate DPP PKEX")
  1101. ev = dev.wait_event(["DPP-CONF-SENT"], timeout=5)
  1102. if ev is None:
  1103. raise Exception("DPP configuration not completed (Configurator)")
  1104. logger.info("DPP initiator/configurator done")
  1105. def run_sigma_dut_ap_dpp_pkex_responder(dev, apdev):
  1106. sigma_dut_cmd_check("ap_reset_default,program,DPP")
  1107. cmd = "DPP_CONFIGURATOR_ADD"
  1108. res = dev[0].request(cmd);
  1109. if "FAIL" in res:
  1110. raise Exception("Failed to add configurator")
  1111. conf_id = int(res)
  1112. t = threading.Thread(target=dpp_init_conf_pkex, args=(dev[0], conf_id))
  1113. t.start()
  1114. 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)
  1115. t.join()
  1116. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1117. raise Exception("Unexpected result: " + res)
  1118. sigma_dut_cmd_check("ap_reset_default")
  1119. def dpp_proto_init(dev, id1):
  1120. time.sleep(1)
  1121. logger.info("Starting DPP initiator/configurator in a thread")
  1122. cmd = "DPP_CONFIGURATOR_ADD"
  1123. res = dev.request(cmd);
  1124. if "FAIL" in res:
  1125. raise Exception("Failed to add configurator")
  1126. conf_id = int(res)
  1127. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  1128. if "OK" not in dev.request(cmd):
  1129. raise Exception("Failed to initiate DPP Authentication")
  1130. def test_sigma_dut_dpp_proto_initiator(dev, apdev):
  1131. """sigma_dut DPP protocol testing - Initiator"""
  1132. check_dpp_capab(dev[0])
  1133. check_dpp_capab(dev[1])
  1134. tests = [ ("InvalidValue", "AuthenticationRequest", "WrappedData",
  1135. "BootstrapResult,OK,AuthResult,Errorsent",
  1136. None),
  1137. ("InvalidValue", "AuthenticationConfirm", "WrappedData",
  1138. "BootstrapResult,OK,AuthResult,Errorsent",
  1139. None),
  1140. ("MissingAttribute", "AuthenticationRequest", "InitCapabilities",
  1141. "BootstrapResult,OK,AuthResult,Errorsent",
  1142. "Missing or invalid I-capabilities"),
  1143. ("InvalidValue", "AuthenticationConfirm", "InitAuthTag",
  1144. "BootstrapResult,OK,AuthResult,Errorsent",
  1145. "Mismatching Initiator Authenticating Tag"),
  1146. ("MissingAttribute", "ConfigurationResponse", "EnrolleeNonce",
  1147. "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent",
  1148. "Missing or invalid Enrollee Nonce attribute") ]
  1149. for step, frame, attr, result, fail in tests:
  1150. dev[0].request("FLUSH")
  1151. dev[1].request("FLUSH")
  1152. sigma = start_sigma_dut(dev[0].ifname)
  1153. try:
  1154. run_sigma_dut_dpp_proto_initiator(dev, step, frame, attr, result,
  1155. fail)
  1156. finally:
  1157. stop_sigma_dut(sigma)
  1158. def run_sigma_dut_dpp_proto_initiator(dev, step, frame, attr, result, fail):
  1159. addr = dev[1].own_addr().replace(':', '')
  1160. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1161. res = dev[1].request(cmd)
  1162. if "FAIL" in res:
  1163. raise Exception("Failed to generate bootstrapping info")
  1164. id0 = int(res)
  1165. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1166. cmd = "DPP_LISTEN 2437 role=enrollee"
  1167. if "OK" not in dev[1].request(cmd):
  1168. raise Exception("Failed to start listen operation")
  1169. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1170. if "status,COMPLETE" not in res:
  1171. raise Exception("dev_exec_action did not succeed: " + res)
  1172. 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))
  1173. if result not in res:
  1174. raise Exception("Unexpected result: " + res)
  1175. if fail:
  1176. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1177. if ev is None or fail not in ev:
  1178. raise Exception("Failure not reported correctly: " + str(ev))
  1179. dev[1].request("DPP_STOP_LISTEN")
  1180. dev[0].dump_monitor()
  1181. dev[1].dump_monitor()
  1182. def test_sigma_dut_dpp_proto_responder(dev, apdev):
  1183. """sigma_dut DPP protocol testing - Responder"""
  1184. check_dpp_capab(dev[0])
  1185. check_dpp_capab(dev[1])
  1186. tests = [ ("MissingAttribute", "AuthenticationResponse", "DPPStatus",
  1187. "BootstrapResult,OK,AuthResult,Errorsent",
  1188. "Missing or invalid required DPP Status attribute"),
  1189. ("MissingAttribute", "ConfigurationRequest", "EnrolleeNonce",
  1190. "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent",
  1191. "Missing or invalid Enrollee Nonce attribute") ]
  1192. for step, frame, attr, result, fail in tests:
  1193. dev[0].request("FLUSH")
  1194. dev[1].request("FLUSH")
  1195. sigma = start_sigma_dut(dev[0].ifname)
  1196. try:
  1197. run_sigma_dut_dpp_proto_responder(dev, step, frame, attr, result,
  1198. fail)
  1199. finally:
  1200. stop_sigma_dut(sigma)
  1201. def run_sigma_dut_dpp_proto_responder(dev, step, frame, attr, result, fail):
  1202. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  1203. if "status,COMPLETE" not in res:
  1204. raise Exception("dev_exec_action did not succeed: " + res)
  1205. hex = res.split(',')[3]
  1206. uri = hex.decode('hex')
  1207. logger.info("URI from sigma_dut: " + uri)
  1208. res = dev[1].request("DPP_QR_CODE " + uri)
  1209. if "FAIL" in res:
  1210. raise Exception("Failed to parse QR Code URI")
  1211. id1 = int(res)
  1212. t = threading.Thread(target=dpp_proto_init, args=(dev[1], id1))
  1213. t.start()
  1214. 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)
  1215. t.join()
  1216. if result not in res:
  1217. raise Exception("Unexpected result: " + res)
  1218. if fail:
  1219. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1220. if ev is None or fail not in ev:
  1221. raise Exception("Failure not reported correctly:" + str(ev))
  1222. dev[1].request("DPP_STOP_LISTEN")
  1223. dev[0].dump_monitor()
  1224. dev[1].dump_monitor()
  1225. def dpp_proto_init_pkex(dev):
  1226. time.sleep(1)
  1227. logger.info("Starting DPP PKEX initiator/configurator in a thread")
  1228. cmd = "DPP_CONFIGURATOR_ADD"
  1229. res = dev.request(cmd);
  1230. if "FAIL" in res:
  1231. raise Exception("Failed to add configurator")
  1232. conf_id = int(res)
  1233. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1234. res = dev.request(cmd)
  1235. if "FAIL" in res:
  1236. raise Exception("Failed to generate bootstrapping info")
  1237. id = int(res)
  1238. cmd = "DPP_PKEX_ADD own=%d init=1 conf=sta-dpp configurator=%d code=secret" % (id, conf_id)
  1239. if "FAIL" in dev.request(cmd):
  1240. raise Exception("Failed to initiate DPP PKEX")
  1241. def test_sigma_dut_dpp_proto_initiator_pkex(dev, apdev):
  1242. """sigma_dut DPP protocol testing - Initiator (PKEX)"""
  1243. check_dpp_capab(dev[0])
  1244. check_dpp_capab(dev[1])
  1245. tests = [ ("InvalidValue", "PKEXCRRequest", "WrappedData",
  1246. "BootstrapResult,Errorsent",
  1247. None),
  1248. ("MissingAttribute", "PKEXExchangeRequest", "FiniteCyclicGroup",
  1249. "BootstrapResult,Errorsent",
  1250. "Missing or invalid Finite Cyclic Group attribute"),
  1251. ("MissingAttribute", "PKEXCRRequest", "BSKey",
  1252. "BootstrapResult,Errorsent",
  1253. "No valid peer bootstrapping key found") ]
  1254. for step, frame, attr, result, fail in tests:
  1255. dev[0].request("FLUSH")
  1256. dev[1].request("FLUSH")
  1257. sigma = start_sigma_dut(dev[0].ifname)
  1258. try:
  1259. run_sigma_dut_dpp_proto_initiator_pkex(dev, step, frame, attr,
  1260. result, fail)
  1261. finally:
  1262. stop_sigma_dut(sigma)
  1263. def run_sigma_dut_dpp_proto_initiator_pkex(dev, step, frame, attr, result, fail):
  1264. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1265. res = dev[1].request(cmd)
  1266. if "FAIL" in res:
  1267. raise Exception("Failed to generate bootstrapping info")
  1268. id1 = int(res)
  1269. cmd = "DPP_PKEX_ADD own=%d code=secret" % (id1)
  1270. res = dev[1].request(cmd)
  1271. if "FAIL" in res:
  1272. raise Exception("Failed to set PKEX data (responder)")
  1273. cmd = "DPP_LISTEN 2437 role=enrollee"
  1274. if "OK" not in dev[1].request(cmd):
  1275. raise Exception("Failed to start listen operation")
  1276. 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))
  1277. if result not in res:
  1278. raise Exception("Unexpected result: " + res)
  1279. if fail:
  1280. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1281. if ev is None or fail not in ev:
  1282. raise Exception("Failure not reported correctly: " + str(ev))
  1283. dev[1].request("DPP_STOP_LISTEN")
  1284. dev[0].dump_monitor()
  1285. dev[1].dump_monitor()
  1286. def test_sigma_dut_dpp_proto_responder_pkex(dev, apdev):
  1287. """sigma_dut DPP protocol testing - Responder (PKEX)"""
  1288. check_dpp_capab(dev[0])
  1289. check_dpp_capab(dev[1])
  1290. tests = [ ("InvalidValue", "PKEXCRResponse", "WrappedData",
  1291. "BootstrapResult,Errorsent",
  1292. None),
  1293. ("MissingAttribute", "PKEXExchangeResponse", "DPPStatus",
  1294. "BootstrapResult,Errorsent",
  1295. "No DPP Status attribute"),
  1296. ("MissingAttribute", "PKEXCRResponse", "BSKey",
  1297. "BootstrapResult,Errorsent",
  1298. "No valid peer bootstrapping key found") ]
  1299. for step, frame, attr, result, fail in tests:
  1300. dev[0].request("FLUSH")
  1301. dev[1].request("FLUSH")
  1302. sigma = start_sigma_dut(dev[0].ifname)
  1303. try:
  1304. run_sigma_dut_dpp_proto_responder_pkex(dev, step, frame, attr,
  1305. result, fail)
  1306. finally:
  1307. stop_sigma_dut(sigma)
  1308. def run_sigma_dut_dpp_proto_responder_pkex(dev, step, frame, attr, result, fail):
  1309. t = threading.Thread(target=dpp_proto_init_pkex, args=(dev[1],))
  1310. t.start()
  1311. 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)
  1312. t.join()
  1313. if result not in res:
  1314. raise Exception("Unexpected result: " + res)
  1315. if fail:
  1316. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1317. if ev is None or fail not in ev:
  1318. raise Exception("Failure not reported correctly:" + str(ev))
  1319. dev[1].request("DPP_STOP_LISTEN")
  1320. dev[0].dump_monitor()
  1321. dev[1].dump_monitor()
  1322. def init_sigma_dut_dpp_proto_peer_disc_req(dev, apdev):
  1323. check_dpp_capab(dev[0])
  1324. check_dpp_capab(dev[1])
  1325. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  1326. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  1327. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  1328. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  1329. params = { "ssid": "DPPNET01",
  1330. "wpa": "2",
  1331. "wpa_key_mgmt": "DPP",
  1332. "rsn_pairwise": "CCMP",
  1333. "dpp_connector": ap_connector,
  1334. "dpp_csign": csign_pub,
  1335. "dpp_netaccesskey": ap_netaccesskey }
  1336. try:
  1337. hapd = hostapd.add_ap(apdev[0], params)
  1338. except:
  1339. raise HwsimSkip("DPP not supported")
  1340. dev[0].set("dpp_config_processing", "2")
  1341. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  1342. res = dev[1].request(cmd);
  1343. if "FAIL" in res:
  1344. raise Exception("Failed to add configurator")
  1345. conf_id = int(res)
  1346. addr = dev[1].own_addr().replace(':', '')
  1347. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1348. res = dev[1].request(cmd)
  1349. if "FAIL" in res:
  1350. raise Exception("Failed to generate bootstrapping info")
  1351. id0 = int(res)
  1352. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1353. dev[1].set("dpp_configurator_params",
  1354. " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id));
  1355. cmd = "DPP_LISTEN 2437 role=configurator"
  1356. if "OK" not in dev[1].request(cmd):
  1357. raise Exception("Failed to start listen operation")
  1358. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1359. if "status,COMPLETE" not in res:
  1360. raise Exception("dev_exec_action did not succeed: " + res)
  1361. def test_sigma_dut_dpp_proto_peer_disc_req(dev, apdev):
  1362. """sigma_dut DPP protocol testing - Peer Discovery Request"""
  1363. sigma = start_sigma_dut(dev[0].ifname)
  1364. try:
  1365. init_sigma_dut_dpp_proto_peer_disc_req(dev, apdev)
  1366. 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)
  1367. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Errorsent" not in res:
  1368. raise Exception("Unexpected result: " + res)
  1369. finally:
  1370. dev[0].set("dpp_config_processing", "0")
  1371. stop_sigma_dut(sigma)