test_sigma_dut.py 82 KB

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