test_sigma_dut.py 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989
  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. if "SAE" not in dev[0].get_capability("auth_alg"):
  510. raise HwsimSkip("SAE not supported")
  511. with HWSimRadio() as (radio, iface):
  512. sigma = start_sigma_dut(iface)
  513. try:
  514. sigma_dut_cmd_check("ap_reset_default")
  515. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  516. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678")
  517. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  518. dev[0].request("SET sae_groups ")
  519. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  520. scan_freq="2412")
  521. if dev[0].get_status_field('sae_group') != '19':
  522. raise Exception("Expected default SAE group not used")
  523. sigma_dut_cmd_check("ap_reset_default")
  524. finally:
  525. stop_sigma_dut(sigma)
  526. def test_sigma_dut_ap_sae_password(dev, apdev):
  527. """sigma_dut controlled AP with SAE and long password"""
  528. if "SAE" not in dev[0].get_capability("auth_alg"):
  529. raise HwsimSkip("SAE not supported")
  530. with HWSimRadio() as (radio, iface):
  531. sigma = start_sigma_dut(iface)
  532. try:
  533. sigma_dut_cmd_check("ap_reset_default")
  534. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  535. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK," + 100*'C')
  536. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  537. dev[0].request("SET sae_groups ")
  538. dev[0].connect("test-sae", key_mgmt="SAE", sae_password=100*'C',
  539. scan_freq="2412")
  540. if dev[0].get_status_field('sae_group') != '19':
  541. raise Exception("Expected default SAE group not used")
  542. sigma_dut_cmd_check("ap_reset_default")
  543. finally:
  544. stop_sigma_dut(sigma)
  545. def test_sigma_dut_ap_sae_group(dev, apdev):
  546. """sigma_dut controlled AP with SAE and specific group"""
  547. if "SAE" not in dev[0].get_capability("auth_alg"):
  548. raise HwsimSkip("SAE not supported")
  549. with HWSimRadio() as (radio, iface):
  550. sigma = start_sigma_dut(iface)
  551. try:
  552. sigma_dut_cmd_check("ap_reset_default")
  553. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  554. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-SAE,PSK,12345678,ECGroupID,20")
  555. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  556. dev[0].request("SET sae_groups ")
  557. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  558. scan_freq="2412")
  559. if dev[0].get_status_field('sae_group') != '20':
  560. raise Exception("Expected SAE group not used")
  561. sigma_dut_cmd_check("ap_reset_default")
  562. finally:
  563. stop_sigma_dut(sigma)
  564. def test_sigma_dut_ap_psk_sae(dev, apdev):
  565. """sigma_dut controlled AP with PSK+SAE"""
  566. if "SAE" not in dev[0].get_capability("auth_alg"):
  567. raise HwsimSkip("SAE not supported")
  568. with HWSimRadio() as (radio, iface):
  569. sigma = start_sigma_dut(iface)
  570. try:
  571. sigma_dut_cmd_check("ap_reset_default")
  572. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,test-sae,MODE,11ng")
  573. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,WPA2-PSK-SAE,PSK,12345678")
  574. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  575. dev[0].request("SET sae_groups ")
  576. dev[0].connect("test-sae", key_mgmt="SAE", psk="12345678",
  577. scan_freq="2412")
  578. dev[1].connect("test-sae", psk="12345678", scan_freq="2412")
  579. sigma_dut_cmd_check("ap_reset_default")
  580. finally:
  581. stop_sigma_dut(sigma)
  582. def test_sigma_dut_owe(dev, apdev):
  583. """sigma_dut controlled OWE station"""
  584. try:
  585. run_sigma_dut_owe(dev, apdev)
  586. finally:
  587. dev[0].set("ignore_old_scan_res", "0")
  588. def run_sigma_dut_owe(dev, apdev):
  589. if "OWE" not in dev[0].get_capability("key_mgmt"):
  590. raise HwsimSkip("OWE not supported")
  591. ifname = dev[0].ifname
  592. sigma = start_sigma_dut(ifname)
  593. try:
  594. params = { "ssid": "owe",
  595. "wpa": "2",
  596. "wpa_key_mgmt": "OWE",
  597. "rsn_pairwise": "CCMP" }
  598. hapd = hostapd.add_ap(apdev[0], params)
  599. bssid = hapd.own_addr()
  600. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  601. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  602. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE" % ifname)
  603. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  604. sigma_dut_wait_connected(ifname)
  605. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  606. dev[0].dump_monitor()
  607. sigma_dut_cmd("sta_reassoc,interface,%s,Channel,1,bssid,%s" % (ifname, bssid))
  608. dev[0].wait_connected()
  609. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  610. dev[0].wait_disconnected()
  611. dev[0].dump_monitor()
  612. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  613. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  614. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,20" % ifname)
  615. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  616. sigma_dut_wait_connected(ifname)
  617. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  618. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  619. dev[0].wait_disconnected()
  620. dev[0].dump_monitor()
  621. sigma_dut_cmd_check("sta_reset_default,interface,%s,prog,WPA3" % ifname)
  622. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  623. sigma_dut_cmd_check("sta_set_security,interface,%s,ssid,owe,Type,OWE,ECGroupID,0" % ifname)
  624. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,owe,channel,1" % ifname)
  625. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  626. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  627. if ev is None:
  628. raise Exception("Association not rejected")
  629. if "status_code=77" not in ev:
  630. raise Exception("Unexpected rejection reason: " + ev)
  631. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  632. finally:
  633. stop_sigma_dut(sigma)
  634. def test_sigma_dut_ap_owe(dev, apdev):
  635. """sigma_dut controlled AP with OWE"""
  636. if "OWE" not in dev[0].get_capability("key_mgmt"):
  637. raise HwsimSkip("OWE not supported")
  638. with HWSimRadio() as (radio, iface):
  639. sigma = start_sigma_dut(iface)
  640. try:
  641. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  642. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
  643. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE")
  644. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  645. dev[0].connect("owe", key_mgmt="OWE", scan_freq="2412")
  646. sigma_dut_cmd_check("ap_reset_default")
  647. finally:
  648. stop_sigma_dut(sigma)
  649. def test_sigma_dut_ap_owe_ecgroupid(dev, apdev):
  650. """sigma_dut controlled AP with OWE and ECGroupID"""
  651. if "OWE" not in dev[0].get_capability("key_mgmt"):
  652. raise HwsimSkip("OWE not supported")
  653. with HWSimRadio() as (radio, iface):
  654. sigma = start_sigma_dut(iface)
  655. try:
  656. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  657. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,CHANNEL,1,SSID,owe,MODE,11ng")
  658. sigma_dut_cmd_check("ap_set_security,NAME,AP,KEYMGNT,OWE,ECGroupID,20 21,PMF,Required")
  659. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  660. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  661. owe_group="20", scan_freq="2412")
  662. dev[0].request("REMOVE_NETWORK all")
  663. dev[0].wait_disconnected()
  664. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  665. owe_group="21", scan_freq="2412")
  666. dev[0].request("REMOVE_NETWORK all")
  667. dev[0].wait_disconnected()
  668. dev[0].connect("owe", key_mgmt="OWE", ieee80211w="2",
  669. owe_group="19", scan_freq="2412", wait_connect=False)
  670. ev = dev[0].wait_event(["CTRL-EVENT-ASSOC-REJECT"], timeout=10)
  671. dev[0].request("DISCONNECT")
  672. if ev is None:
  673. raise Exception("Association not rejected")
  674. if "status_code=77" not in ev:
  675. raise Exception("Unexpected rejection reason: " + ev)
  676. dev[0].dump_monitor()
  677. sigma_dut_cmd_check("ap_reset_default")
  678. finally:
  679. stop_sigma_dut(sigma)
  680. def test_sigma_dut_ap_owe_transition_mode(dev, apdev, params):
  681. """sigma_dut controlled AP with OWE and transition mode"""
  682. if "OWE" not in dev[0].get_capability("key_mgmt"):
  683. raise HwsimSkip("OWE not supported")
  684. logdir = os.path.join(params['logdir'],
  685. "sigma_dut_ap_owe_transition_mode.sigma-hostapd")
  686. with HWSimRadio() as (radio, iface):
  687. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  688. try:
  689. sigma_dut_cmd_check("ap_reset_default,NAME,AP,Program,WPA3")
  690. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,1,CHANNEL,1,SSID,owe,MODE,11ng")
  691. sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,1,KEYMGNT,OWE")
  692. sigma_dut_cmd_check("ap_set_wireless,NAME,AP,WLAN_TAG,2,CHANNEL,1,SSID,owe,MODE,11ng")
  693. sigma_dut_cmd_check("ap_set_security,NAME,AP,WLAN_TAG,2,KEYMGNT,NONE")
  694. sigma_dut_cmd_check("ap_config_commit,NAME,AP")
  695. res1 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,1,Interface,24G")
  696. res2 = sigma_dut_cmd_check("ap_get_mac_address,NAME,AP,WLAN_TAG,2,Interface,24G")
  697. dev[0].connect("owe", key_mgmt="OWE", scan_freq="2412")
  698. dev[1].connect("owe", key_mgmt="NONE", scan_freq="2412")
  699. if dev[0].get_status_field('bssid') not in res1:
  700. raise Exception("Unexpected ap_get_mac_address WLAN_TAG,1: " + res1)
  701. if dev[1].get_status_field('bssid') not in res2:
  702. raise Exception("Unexpected ap_get_mac_address WLAN_TAG,2: " + res2)
  703. sigma_dut_cmd_check("ap_reset_default")
  704. finally:
  705. stop_sigma_dut(sigma)
  706. def dpp_init_enrollee(dev, id1):
  707. logger.info("Starting DPP initiator/enrollee in a thread")
  708. time.sleep(1)
  709. cmd = "DPP_AUTH_INIT peer=%d role=enrollee" % id1
  710. if "OK" not in dev.request(cmd):
  711. raise Exception("Failed to initiate DPP Authentication")
  712. ev = dev.wait_event(["DPP-CONF-RECEIVED"], timeout=5)
  713. if ev is None:
  714. raise Exception("DPP configuration not completed (Enrollee)")
  715. logger.info("DPP initiator/enrollee done")
  716. def test_sigma_dut_dpp_qr_resp_1(dev, apdev):
  717. """sigma_dut DPP/QR responder (conf index 1)"""
  718. run_sigma_dut_dpp_qr_resp(dev, apdev, 1)
  719. def test_sigma_dut_dpp_qr_resp_2(dev, apdev):
  720. """sigma_dut DPP/QR responder (conf index 2)"""
  721. run_sigma_dut_dpp_qr_resp(dev, apdev, 2)
  722. def test_sigma_dut_dpp_qr_resp_3(dev, apdev):
  723. """sigma_dut DPP/QR responder (conf index 3)"""
  724. run_sigma_dut_dpp_qr_resp(dev, apdev, 3)
  725. def test_sigma_dut_dpp_qr_resp_4(dev, apdev):
  726. """sigma_dut DPP/QR responder (conf index 4)"""
  727. run_sigma_dut_dpp_qr_resp(dev, apdev, 4)
  728. def test_sigma_dut_dpp_qr_resp_chan_list(dev, apdev):
  729. """sigma_dut DPP/QR responder (channel list override)"""
  730. run_sigma_dut_dpp_qr_resp(dev, apdev, 1, chan_list='81/2 81/6 81/1',
  731. listen_chan=2)
  732. def run_sigma_dut_dpp_qr_resp(dev, apdev, conf_idx, chan_list=None,
  733. listen_chan=None):
  734. check_dpp_capab(dev[0])
  735. check_dpp_capab(dev[1])
  736. sigma = start_sigma_dut(dev[0].ifname)
  737. try:
  738. cmd = "dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR"
  739. if chan_list:
  740. cmd += ",DPPChannelList," + chan_list
  741. res = sigma_dut_cmd(cmd)
  742. if "status,COMPLETE" not in res:
  743. raise Exception("dev_exec_action did not succeed: " + res)
  744. hex = res.split(',')[3]
  745. uri = hex.decode('hex')
  746. logger.info("URI from sigma_dut: " + uri)
  747. res = dev[1].request("DPP_QR_CODE " + uri)
  748. if "FAIL" in res:
  749. raise Exception("Failed to parse QR Code URI")
  750. id1 = int(res)
  751. t = threading.Thread(target=dpp_init_enrollee, args=(dev[1], id1))
  752. t.start()
  753. 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
  754. if listen_chan:
  755. cmd += ",DPPListenChannel," + str(listen_chan)
  756. res = sigma_dut_cmd(cmd, timeout=10)
  757. t.join()
  758. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  759. raise Exception("Unexpected result: " + res)
  760. finally:
  761. stop_sigma_dut(sigma)
  762. def test_sigma_dut_dpp_qr_init_enrollee(dev, apdev):
  763. """sigma_dut DPP/QR initiator as Enrollee"""
  764. check_dpp_capab(dev[0])
  765. check_dpp_capab(dev[1])
  766. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  767. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  768. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  769. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  770. params = { "ssid": "DPPNET01",
  771. "wpa": "2",
  772. "wpa_key_mgmt": "DPP",
  773. "rsn_pairwise": "CCMP",
  774. "dpp_connector": ap_connector,
  775. "dpp_csign": csign_pub,
  776. "dpp_netaccesskey": ap_netaccesskey }
  777. try:
  778. hapd = hostapd.add_ap(apdev[0], params)
  779. except:
  780. raise HwsimSkip("DPP not supported")
  781. sigma = start_sigma_dut(dev[0].ifname)
  782. try:
  783. dev[0].set("dpp_config_processing", "2")
  784. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  785. res = dev[1].request(cmd);
  786. if "FAIL" in res:
  787. raise Exception("Failed to add configurator")
  788. conf_id = int(res)
  789. addr = dev[1].own_addr().replace(':', '')
  790. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  791. res = dev[1].request(cmd)
  792. if "FAIL" in res:
  793. raise Exception("Failed to generate bootstrapping info")
  794. id0 = int(res)
  795. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  796. dev[1].set("dpp_configurator_params",
  797. " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id));
  798. cmd = "DPP_LISTEN 2437 role=configurator"
  799. if "OK" not in dev[1].request(cmd):
  800. raise Exception("Failed to start listen operation")
  801. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  802. if "status,COMPLETE" not in res:
  803. raise Exception("dev_exec_action did not succeed: " + res)
  804. 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)
  805. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  806. raise Exception("Unexpected result: " + res)
  807. finally:
  808. dev[0].set("dpp_config_processing", "0")
  809. stop_sigma_dut(sigma)
  810. def test_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev):
  811. """sigma_dut DPP/QR (mutual) initiator as Enrollee"""
  812. run_sigma_dut_dpp_qr_mutual_init_enrollee_check(dev, apdev)
  813. def test_sigma_dut_dpp_qr_mutual_init_enrollee_check(dev, apdev):
  814. """sigma_dut DPP/QR (mutual) initiator as Enrollee (extra check)"""
  815. run_sigma_dut_dpp_qr_mutual_init_enrollee_check(dev, apdev,
  816. extra="DPPAuthDirection,Mutual,")
  817. def run_sigma_dut_dpp_qr_mutual_init_enrollee_check(dev, apdev, extra=''):
  818. check_dpp_capab(dev[0])
  819. check_dpp_capab(dev[1])
  820. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  821. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  822. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  823. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  824. params = { "ssid": "DPPNET01",
  825. "wpa": "2",
  826. "wpa_key_mgmt": "DPP",
  827. "rsn_pairwise": "CCMP",
  828. "dpp_connector": ap_connector,
  829. "dpp_csign": csign_pub,
  830. "dpp_netaccesskey": ap_netaccesskey }
  831. try:
  832. hapd = hostapd.add_ap(apdev[0], params)
  833. except:
  834. raise HwsimSkip("DPP not supported")
  835. sigma = start_sigma_dut(dev[0].ifname)
  836. try:
  837. dev[0].set("dpp_config_processing", "2")
  838. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  839. res = dev[1].request(cmd);
  840. if "FAIL" in res:
  841. raise Exception("Failed to add configurator")
  842. conf_id = int(res)
  843. addr = dev[1].own_addr().replace(':', '')
  844. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  845. res = dev[1].request(cmd)
  846. if "FAIL" in res:
  847. raise Exception("Failed to generate bootstrapping info")
  848. id0 = int(res)
  849. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  850. dev[1].set("dpp_configurator_params",
  851. " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id));
  852. cmd = "DPP_LISTEN 2437 role=configurator qr=mutual"
  853. if "OK" not in dev[1].request(cmd):
  854. raise Exception("Failed to start listen operation")
  855. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  856. if "status,COMPLETE" not in res:
  857. raise Exception("dev_exec_action did not succeed: " + res)
  858. hex = res.split(',')[3]
  859. uri = hex.decode('hex')
  860. logger.info("URI from sigma_dut: " + uri)
  861. res = dev[1].request("DPP_QR_CODE " + uri)
  862. if "FAIL" in res:
  863. raise Exception("Failed to parse QR Code URI")
  864. id1 = int(res)
  865. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  866. if "status,COMPLETE" not in res:
  867. raise Exception("dev_exec_action did not succeed: " + res)
  868. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,%sDPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6,DPPWaitForConnect,Yes" % extra, timeout=10)
  869. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  870. raise Exception("Unexpected result: " + res)
  871. finally:
  872. dev[0].set("dpp_config_processing", "0")
  873. stop_sigma_dut(sigma)
  874. def dpp_init_conf_mutual(dev, id1, conf_id, own_id=None):
  875. time.sleep(1)
  876. logger.info("Starting DPP initiator/configurator in a thread")
  877. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp ssid=%s configurator=%d" % (id1, "DPPNET01".encode("hex"), conf_id)
  878. if own_id is not None:
  879. cmd += " own=%d" % own_id
  880. if "OK" not in dev.request(cmd):
  881. raise Exception("Failed to initiate DPP Authentication")
  882. ev = dev.wait_event(["DPP-CONF-SENT"], timeout=10)
  883. if ev is None:
  884. raise Exception("DPP configuration not completed (Configurator)")
  885. logger.info("DPP initiator/configurator done")
  886. def test_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev):
  887. """sigma_dut DPP/QR (mutual) responder as Enrollee"""
  888. run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev)
  889. def test_sigma_dut_dpp_qr_mutual_resp_enrollee_pending(dev, apdev):
  890. """sigma_dut DPP/QR (mutual) responder as Enrollee (response pending)"""
  891. run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev, ',DPPDelayQRResponse,1')
  892. def run_sigma_dut_dpp_qr_mutual_resp_enrollee(dev, apdev, extra=None):
  893. check_dpp_capab(dev[0])
  894. check_dpp_capab(dev[1])
  895. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  896. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  897. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  898. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  899. params = { "ssid": "DPPNET01",
  900. "wpa": "2",
  901. "wpa_key_mgmt": "DPP",
  902. "rsn_pairwise": "CCMP",
  903. "dpp_connector": ap_connector,
  904. "dpp_csign": csign_pub,
  905. "dpp_netaccesskey": ap_netaccesskey }
  906. try:
  907. hapd = hostapd.add_ap(apdev[0], params)
  908. except:
  909. raise HwsimSkip("DPP not supported")
  910. sigma = start_sigma_dut(dev[0].ifname)
  911. try:
  912. dev[0].set("dpp_config_processing", "2")
  913. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  914. res = dev[1].request(cmd);
  915. if "FAIL" in res:
  916. raise Exception("Failed to add configurator")
  917. conf_id = int(res)
  918. addr = dev[1].own_addr().replace(':', '')
  919. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  920. res = dev[1].request(cmd)
  921. if "FAIL" in res:
  922. raise Exception("Failed to generate bootstrapping info")
  923. id0 = int(res)
  924. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  925. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  926. if "status,COMPLETE" not in res:
  927. raise Exception("dev_exec_action did not succeed: " + res)
  928. hex = res.split(',')[3]
  929. uri = hex.decode('hex')
  930. logger.info("URI from sigma_dut: " + uri)
  931. res = dev[1].request("DPP_QR_CODE " + uri)
  932. if "FAIL" in res:
  933. raise Exception("Failed to parse QR Code URI")
  934. id1 = int(res)
  935. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  936. if "status,COMPLETE" not in res:
  937. raise Exception("dev_exec_action did not succeed: " + res)
  938. t = threading.Thread(target=dpp_init_conf_mutual,
  939. args=(dev[1], id1, conf_id, id0))
  940. t.start()
  941. cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Mutual,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,20,DPPWaitForConnect,Yes"
  942. if extra:
  943. cmd += extra
  944. res = sigma_dut_cmd(cmd, timeout=25)
  945. t.join()
  946. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  947. raise Exception("Unexpected result: " + res)
  948. finally:
  949. dev[0].set("dpp_config_processing", "0")
  950. stop_sigma_dut(sigma)
  951. def dpp_resp_conf_mutual(dev, conf_id, uri):
  952. logger.info("Starting DPP responder/configurator in a thread")
  953. dev.set("dpp_configurator_params",
  954. " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id));
  955. cmd = "DPP_LISTEN 2437 role=configurator qr=mutual"
  956. if "OK" not in dev.request(cmd):
  957. raise Exception("Failed to initiate DPP listen")
  958. if uri:
  959. ev = dev.wait_event(["DPP-SCAN-PEER-QR-CODE"], timeout=10)
  960. if ev is None:
  961. raise Exception("QR Code scan for mutual authentication not requested")
  962. res = dev.request("DPP_QR_CODE " + uri)
  963. if "FAIL" in res:
  964. raise Exception("Failed to parse QR Code URI")
  965. ev = dev.wait_event(["DPP-CONF-SENT"], timeout=10)
  966. if ev is None:
  967. raise Exception("DPP configuration not completed (Configurator)")
  968. logger.info("DPP responder/configurator done")
  969. def test_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev):
  970. """sigma_dut DPP/QR (mutual) initiator as Enrollee"""
  971. run_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev, False)
  972. def test_sigma_dut_dpp_qr_mutual_init_enrollee_pending(dev, apdev):
  973. """sigma_dut DPP/QR (mutual) initiator as Enrollee (response pending)"""
  974. run_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev, True)
  975. def run_sigma_dut_dpp_qr_mutual_init_enrollee(dev, apdev, resp_pending):
  976. check_dpp_capab(dev[0])
  977. check_dpp_capab(dev[1])
  978. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  979. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  980. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  981. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  982. params = { "ssid": "DPPNET01",
  983. "wpa": "2",
  984. "wpa_key_mgmt": "DPP",
  985. "rsn_pairwise": "CCMP",
  986. "dpp_connector": ap_connector,
  987. "dpp_csign": csign_pub,
  988. "dpp_netaccesskey": ap_netaccesskey }
  989. try:
  990. hapd = hostapd.add_ap(apdev[0], params)
  991. except:
  992. raise HwsimSkip("DPP not supported")
  993. sigma = start_sigma_dut(dev[0].ifname)
  994. try:
  995. dev[0].set("dpp_config_processing", "2")
  996. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  997. res = dev[1].request(cmd);
  998. if "FAIL" in res:
  999. raise Exception("Failed to add configurator")
  1000. conf_id = int(res)
  1001. addr = dev[1].own_addr().replace(':', '')
  1002. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1003. res = dev[1].request(cmd)
  1004. if "FAIL" in res:
  1005. raise Exception("Failed to generate bootstrapping info")
  1006. id0 = int(res)
  1007. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1008. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  1009. if "status,COMPLETE" not in res:
  1010. raise Exception("dev_exec_action did not succeed: " + res)
  1011. hex = res.split(',')[3]
  1012. uri = hex.decode('hex')
  1013. logger.info("URI from sigma_dut: " + uri)
  1014. if not resp_pending:
  1015. res = dev[1].request("DPP_QR_CODE " + uri)
  1016. if "FAIL" in res:
  1017. raise Exception("Failed to parse QR Code URI")
  1018. uri = None
  1019. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1020. if "status,COMPLETE" not in res:
  1021. raise Exception("dev_exec_action did not succeed: " + res)
  1022. t = threading.Thread(target=dpp_resp_conf_mutual,
  1023. args=(dev[1], conf_id, uri))
  1024. t.start()
  1025. time.sleep(1)
  1026. cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,10,DPPWaitForConnect,Yes"
  1027. res = sigma_dut_cmd(cmd, timeout=15)
  1028. t.join()
  1029. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  1030. raise Exception("Unexpected result: " + res)
  1031. finally:
  1032. dev[0].set("dpp_config_processing", "0")
  1033. stop_sigma_dut(sigma)
  1034. def test_sigma_dut_dpp_qr_init_enrollee_psk(dev, apdev):
  1035. """sigma_dut DPP/QR initiator as Enrollee (PSK)"""
  1036. check_dpp_capab(dev[0])
  1037. check_dpp_capab(dev[1])
  1038. params = hostapd.wpa2_params(ssid="DPPNET01",
  1039. passphrase="ThisIsDppPassphrase")
  1040. hapd = hostapd.add_ap(apdev[0], params)
  1041. sigma = start_sigma_dut(dev[0].ifname)
  1042. try:
  1043. dev[0].set("dpp_config_processing", "2")
  1044. cmd = "DPP_CONFIGURATOR_ADD"
  1045. res = dev[1].request(cmd);
  1046. if "FAIL" in res:
  1047. raise Exception("Failed to add configurator")
  1048. conf_id = int(res)
  1049. addr = dev[1].own_addr().replace(':', '')
  1050. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1051. res = dev[1].request(cmd)
  1052. if "FAIL" in res:
  1053. raise Exception("Failed to generate bootstrapping info")
  1054. id0 = int(res)
  1055. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1056. dev[1].set("dpp_configurator_params",
  1057. " conf=sta-psk ssid=%s pass=%s configurator=%d" % ("DPPNET01".encode("hex"), "ThisIsDppPassphrase".encode("hex"), conf_id));
  1058. cmd = "DPP_LISTEN 2437 role=configurator"
  1059. if "OK" not in dev[1].request(cmd):
  1060. raise Exception("Failed to start listen operation")
  1061. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1062. if "status,COMPLETE" not in res:
  1063. raise Exception("dev_exec_action did not succeed: " + res)
  1064. 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)
  1065. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkConnectResult,OK" not in res:
  1066. raise Exception("Unexpected result: " + res)
  1067. finally:
  1068. dev[0].set("dpp_config_processing", "0")
  1069. stop_sigma_dut(sigma)
  1070. def test_sigma_dut_dpp_qr_init_configurator_1(dev, apdev):
  1071. """sigma_dut DPP/QR initiator as Configurator (conf index 1)"""
  1072. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 1)
  1073. def test_sigma_dut_dpp_qr_init_configurator_2(dev, apdev):
  1074. """sigma_dut DPP/QR initiator as Configurator (conf index 2)"""
  1075. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 2)
  1076. def test_sigma_dut_dpp_qr_init_configurator_3(dev, apdev):
  1077. """sigma_dut DPP/QR initiator as Configurator (conf index 3)"""
  1078. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 3)
  1079. def test_sigma_dut_dpp_qr_init_configurator_4(dev, apdev):
  1080. """sigma_dut DPP/QR initiator as Configurator (conf index 4)"""
  1081. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 4)
  1082. def test_sigma_dut_dpp_qr_init_configurator_both(dev, apdev):
  1083. """sigma_dut DPP/QR initiator as Configurator or Enrollee (conf index 1)"""
  1084. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 1, "Both")
  1085. def test_sigma_dut_dpp_qr_init_configurator_neg_freq(dev, apdev):
  1086. """sigma_dut DPP/QR initiator as Configurator (neg_freq)"""
  1087. run_sigma_dut_dpp_qr_init_configurator(dev, apdev, 1, extra='DPPSubsequentChannel,81/11')
  1088. def run_sigma_dut_dpp_qr_init_configurator(dev, apdev, conf_idx,
  1089. prov_role="Configurator",
  1090. extra=None):
  1091. check_dpp_capab(dev[0])
  1092. check_dpp_capab(dev[1])
  1093. sigma = start_sigma_dut(dev[0].ifname)
  1094. try:
  1095. addr = dev[1].own_addr().replace(':', '')
  1096. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1097. res = dev[1].request(cmd)
  1098. if "FAIL" in res:
  1099. raise Exception("Failed to generate bootstrapping info")
  1100. id0 = int(res)
  1101. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1102. cmd = "DPP_LISTEN 2437 role=enrollee"
  1103. if "OK" not in dev[1].request(cmd):
  1104. raise Exception("Failed to start listen operation")
  1105. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1106. if "status,COMPLETE" not in res:
  1107. raise Exception("dev_exec_action did not succeed: " + res)
  1108. cmd = "dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,%s,DPPConfIndex,%d,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6" % (prov_role, conf_idx)
  1109. if extra:
  1110. cmd += "," + extra
  1111. res = sigma_dut_cmd(cmd)
  1112. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1113. raise Exception("Unexpected result: " + res)
  1114. finally:
  1115. stop_sigma_dut(sigma)
  1116. def test_sigma_dut_dpp_pkex_init_configurator(dev, apdev):
  1117. """sigma_dut DPP/PKEX initiator as Configurator"""
  1118. check_dpp_capab(dev[0])
  1119. check_dpp_capab(dev[1])
  1120. sigma = start_sigma_dut(dev[0].ifname)
  1121. try:
  1122. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1123. res = dev[1].request(cmd)
  1124. if "FAIL" in res:
  1125. raise Exception("Failed to generate bootstrapping info")
  1126. id1 = int(res)
  1127. cmd = "DPP_PKEX_ADD own=%d identifier=test code=secret" % (id1)
  1128. res = dev[1].request(cmd)
  1129. if "FAIL" in res:
  1130. raise Exception("Failed to set PKEX data (responder)")
  1131. cmd = "DPP_LISTEN 2437 role=enrollee"
  1132. if "OK" not in dev[1].request(cmd):
  1133. raise Exception("Failed to start listen operation")
  1134. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,PKEX,DPPPKEXCodeIdentifier,test,DPPPKEXCode,secret,DPPTimeout,6")
  1135. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1136. raise Exception("Unexpected result: " + res)
  1137. finally:
  1138. stop_sigma_dut(sigma)
  1139. def dpp_init_conf(dev, id1, conf, conf_id, extra):
  1140. logger.info("Starting DPP initiator/configurator in a thread")
  1141. cmd = "DPP_AUTH_INIT peer=%d conf=%s %s configurator=%d" % (id1, conf, extra, conf_id)
  1142. if "OK" not in dev.request(cmd):
  1143. raise Exception("Failed to initiate DPP Authentication")
  1144. ev = dev.wait_event(["DPP-CONF-SENT"], timeout=5)
  1145. if ev is None:
  1146. raise Exception("DPP configuration not completed (Configurator)")
  1147. logger.info("DPP initiator/configurator done")
  1148. def test_sigma_dut_ap_dpp_qr(dev, apdev, params):
  1149. """sigma_dut controlled AP (DPP)"""
  1150. run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-dpp", "sta-dpp")
  1151. def test_sigma_dut_ap_dpp_qr_legacy(dev, apdev, params):
  1152. """sigma_dut controlled AP (legacy)"""
  1153. run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-psk", "sta-psk",
  1154. extra="pass=%s" % "qwertyuiop".encode("hex"))
  1155. def test_sigma_dut_ap_dpp_qr_legacy_psk(dev, apdev, params):
  1156. """sigma_dut controlled AP (legacy)"""
  1157. run_sigma_dut_ap_dpp_qr(dev, apdev, params, "ap-psk", "sta-psk",
  1158. extra="psk=%s" % (32*"12"))
  1159. def run_sigma_dut_ap_dpp_qr(dev, apdev, params, ap_conf, sta_conf, extra=""):
  1160. check_dpp_capab(dev[0])
  1161. logdir = os.path.join(params['logdir'], "sigma_dut_ap_dpp_qr.sigma-hostapd")
  1162. with HWSimRadio() as (radio, iface):
  1163. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  1164. try:
  1165. sigma_dut_cmd_check("ap_reset_default,program,DPP")
  1166. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  1167. if "status,COMPLETE" not in res:
  1168. raise Exception("dev_exec_action did not succeed: " + res)
  1169. hex = res.split(',')[3]
  1170. uri = hex.decode('hex')
  1171. logger.info("URI from sigma_dut: " + uri)
  1172. cmd = "DPP_CONFIGURATOR_ADD"
  1173. res = dev[0].request(cmd);
  1174. if "FAIL" in res:
  1175. raise Exception("Failed to add configurator")
  1176. conf_id = int(res)
  1177. res = dev[0].request("DPP_QR_CODE " + uri)
  1178. if "FAIL" in res:
  1179. raise Exception("Failed to parse QR Code URI")
  1180. id1 = int(res)
  1181. t = threading.Thread(target=dpp_init_conf,
  1182. args=(dev[0], id1, ap_conf, conf_id, extra))
  1183. t.start()
  1184. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPBS,QR,DPPTimeout,6")
  1185. t.join()
  1186. if "ConfResult,OK" not in res:
  1187. raise Exception("Unexpected result: " + res)
  1188. addr = dev[1].own_addr().replace(':', '')
  1189. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1190. res = dev[1].request(cmd)
  1191. if "FAIL" in res:
  1192. raise Exception("Failed to generate bootstrapping info")
  1193. id1 = int(res)
  1194. uri1 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id1)
  1195. res = dev[0].request("DPP_QR_CODE " + uri1)
  1196. if "FAIL" in res:
  1197. raise Exception("Failed to parse QR Code URI")
  1198. id0b = int(res)
  1199. dev[1].set("dpp_config_processing", "2")
  1200. cmd = "DPP_LISTEN 2412"
  1201. if "OK" not in dev[1].request(cmd):
  1202. raise Exception("Failed to start listen operation")
  1203. cmd = "DPP_AUTH_INIT peer=%d conf=%s %s configurator=%d" % (id0b, sta_conf, extra, conf_id)
  1204. if "OK" not in dev[0].request(cmd):
  1205. raise Exception("Failed to initiate DPP Authentication")
  1206. dev[1].wait_connected()
  1207. sigma_dut_cmd_check("ap_reset_default")
  1208. finally:
  1209. dev[1].set("dpp_config_processing", "0")
  1210. stop_sigma_dut(sigma)
  1211. def test_sigma_dut_ap_dpp_pkex_responder(dev, apdev, params):
  1212. """sigma_dut controlled AP as DPP PKEX responder"""
  1213. check_dpp_capab(dev[0])
  1214. logdir = os.path.join(params['logdir'],
  1215. "sigma_dut_ap_dpp_pkex_responder.sigma-hostapd")
  1216. with HWSimRadio() as (radio, iface):
  1217. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  1218. try:
  1219. run_sigma_dut_ap_dpp_pkex_responder(dev, apdev)
  1220. finally:
  1221. stop_sigma_dut(sigma)
  1222. def dpp_init_conf_pkex(dev, conf_id):
  1223. logger.info("Starting DPP PKEX initiator/configurator in a thread")
  1224. time.sleep(1.5)
  1225. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1226. res = dev.request(cmd)
  1227. if "FAIL" in res:
  1228. raise Exception("Failed to generate bootstrapping info")
  1229. id = int(res)
  1230. cmd = "DPP_PKEX_ADD own=%d init=1 conf=ap-dpp configurator=%d code=password" % (id, conf_id)
  1231. res = dev.request(cmd)
  1232. if "FAIL" in res:
  1233. raise Exception("Failed to initiate DPP PKEX")
  1234. ev = dev.wait_event(["DPP-CONF-SENT"], timeout=5)
  1235. if ev is None:
  1236. raise Exception("DPP configuration not completed (Configurator)")
  1237. logger.info("DPP initiator/configurator done")
  1238. def run_sigma_dut_ap_dpp_pkex_responder(dev, apdev):
  1239. sigma_dut_cmd_check("ap_reset_default,program,DPP")
  1240. cmd = "DPP_CONFIGURATOR_ADD"
  1241. res = dev[0].request(cmd);
  1242. if "FAIL" in res:
  1243. raise Exception("Failed to add configurator")
  1244. conf_id = int(res)
  1245. t = threading.Thread(target=dpp_init_conf_pkex, args=(dev[0], conf_id))
  1246. t.start()
  1247. 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)
  1248. t.join()
  1249. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1250. raise Exception("Unexpected result: " + res)
  1251. sigma_dut_cmd_check("ap_reset_default")
  1252. def dpp_proto_init(dev, id1):
  1253. time.sleep(1)
  1254. logger.info("Starting DPP initiator/configurator in a thread")
  1255. cmd = "DPP_CONFIGURATOR_ADD"
  1256. res = dev.request(cmd);
  1257. if "FAIL" in res:
  1258. raise Exception("Failed to add configurator")
  1259. conf_id = int(res)
  1260. cmd = "DPP_AUTH_INIT peer=%d conf=sta-dpp configurator=%d" % (id1, conf_id)
  1261. if "OK" not in dev.request(cmd):
  1262. raise Exception("Failed to initiate DPP Authentication")
  1263. def test_sigma_dut_dpp_proto_initiator(dev, apdev):
  1264. """sigma_dut DPP protocol testing - Initiator"""
  1265. check_dpp_capab(dev[0])
  1266. check_dpp_capab(dev[1])
  1267. tests = [ ("InvalidValue", "AuthenticationRequest", "WrappedData",
  1268. "BootstrapResult,OK,AuthResult,Errorsent",
  1269. None),
  1270. ("InvalidValue", "AuthenticationConfirm", "WrappedData",
  1271. "BootstrapResult,OK,AuthResult,Errorsent",
  1272. None),
  1273. ("MissingAttribute", "AuthenticationRequest", "InitCapabilities",
  1274. "BootstrapResult,OK,AuthResult,Errorsent",
  1275. "Missing or invalid I-capabilities"),
  1276. ("InvalidValue", "AuthenticationConfirm", "InitAuthTag",
  1277. "BootstrapResult,OK,AuthResult,Errorsent",
  1278. "Mismatching Initiator Authenticating Tag"),
  1279. ("MissingAttribute", "ConfigurationResponse", "EnrolleeNonce",
  1280. "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent",
  1281. "Missing or invalid Enrollee Nonce attribute") ]
  1282. for step, frame, attr, result, fail in tests:
  1283. dev[0].request("FLUSH")
  1284. dev[1].request("FLUSH")
  1285. sigma = start_sigma_dut(dev[0].ifname)
  1286. try:
  1287. run_sigma_dut_dpp_proto_initiator(dev, step, frame, attr, result,
  1288. fail)
  1289. finally:
  1290. stop_sigma_dut(sigma)
  1291. def run_sigma_dut_dpp_proto_initiator(dev, step, frame, attr, result, fail):
  1292. addr = dev[1].own_addr().replace(':', '')
  1293. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1294. res = dev[1].request(cmd)
  1295. if "FAIL" in res:
  1296. raise Exception("Failed to generate bootstrapping info")
  1297. id0 = int(res)
  1298. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1299. cmd = "DPP_LISTEN 2437 role=enrollee"
  1300. if "OK" not in dev[1].request(cmd):
  1301. raise Exception("Failed to start listen operation")
  1302. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1303. if "status,COMPLETE" not in res:
  1304. raise Exception("dev_exec_action did not succeed: " + res)
  1305. 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))
  1306. if result not in res:
  1307. raise Exception("Unexpected result: " + res)
  1308. if fail:
  1309. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1310. if ev is None or fail not in ev:
  1311. raise Exception("Failure not reported correctly: " + str(ev))
  1312. dev[1].request("DPP_STOP_LISTEN")
  1313. dev[0].dump_monitor()
  1314. dev[1].dump_monitor()
  1315. def test_sigma_dut_dpp_proto_responder(dev, apdev):
  1316. """sigma_dut DPP protocol testing - Responder"""
  1317. check_dpp_capab(dev[0])
  1318. check_dpp_capab(dev[1])
  1319. tests = [ ("MissingAttribute", "AuthenticationResponse", "DPPStatus",
  1320. "BootstrapResult,OK,AuthResult,Errorsent",
  1321. "Missing or invalid required DPP Status attribute"),
  1322. ("MissingAttribute", "ConfigurationRequest", "EnrolleeNonce",
  1323. "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent",
  1324. "Missing or invalid Enrollee Nonce attribute") ]
  1325. for step, frame, attr, result, fail in tests:
  1326. dev[0].request("FLUSH")
  1327. dev[1].request("FLUSH")
  1328. sigma = start_sigma_dut(dev[0].ifname)
  1329. try:
  1330. run_sigma_dut_dpp_proto_responder(dev, step, frame, attr, result,
  1331. fail)
  1332. finally:
  1333. stop_sigma_dut(sigma)
  1334. def run_sigma_dut_dpp_proto_responder(dev, step, frame, attr, result, fail):
  1335. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  1336. if "status,COMPLETE" not in res:
  1337. raise Exception("dev_exec_action did not succeed: " + res)
  1338. hex = res.split(',')[3]
  1339. uri = hex.decode('hex')
  1340. logger.info("URI from sigma_dut: " + uri)
  1341. res = dev[1].request("DPP_QR_CODE " + uri)
  1342. if "FAIL" in res:
  1343. raise Exception("Failed to parse QR Code URI")
  1344. id1 = int(res)
  1345. t = threading.Thread(target=dpp_proto_init, args=(dev[1], id1))
  1346. t.start()
  1347. 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)
  1348. t.join()
  1349. if result not in res:
  1350. raise Exception("Unexpected result: " + res)
  1351. if fail:
  1352. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1353. if ev is None or fail not in ev:
  1354. raise Exception("Failure not reported correctly:" + str(ev))
  1355. dev[1].request("DPP_STOP_LISTEN")
  1356. dev[0].dump_monitor()
  1357. dev[1].dump_monitor()
  1358. def test_sigma_dut_dpp_proto_stop_at_initiator(dev, apdev):
  1359. """sigma_dut DPP protocol testing - Stop at RX on Initiator"""
  1360. check_dpp_capab(dev[0])
  1361. check_dpp_capab(dev[1])
  1362. tests = [ ("AuthenticationResponse",
  1363. "BootstrapResult,OK,AuthResult,Errorsent",
  1364. None),
  1365. ("ConfigurationRequest",
  1366. "BootstrapResult,OK,AuthResult,OK,ConfResult,Errorsent",
  1367. None)]
  1368. for frame, result, fail in tests:
  1369. dev[0].request("FLUSH")
  1370. dev[1].request("FLUSH")
  1371. sigma = start_sigma_dut(dev[0].ifname)
  1372. try:
  1373. run_sigma_dut_dpp_proto_stop_at_initiator(dev, frame, result, fail)
  1374. finally:
  1375. stop_sigma_dut(sigma)
  1376. def run_sigma_dut_dpp_proto_stop_at_initiator(dev, frame, result, fail):
  1377. addr = dev[1].own_addr().replace(':', '')
  1378. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1379. res = dev[1].request(cmd)
  1380. if "FAIL" in res:
  1381. raise Exception("Failed to generate bootstrapping info")
  1382. id0 = int(res)
  1383. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1384. cmd = "DPP_LISTEN 2437 role=enrollee"
  1385. if "OK" not in dev[1].request(cmd):
  1386. raise Exception("Failed to start listen operation")
  1387. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1388. if "status,COMPLETE" not in res:
  1389. raise Exception("dev_exec_action did not succeed: " + res)
  1390. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6,DPPStep,Timeout,DPPFrameType,%s" % (frame))
  1391. if result not in res:
  1392. raise Exception("Unexpected result: " + res)
  1393. if fail:
  1394. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1395. if ev is None or fail not in ev:
  1396. raise Exception("Failure not reported correctly: " + str(ev))
  1397. dev[1].request("DPP_STOP_LISTEN")
  1398. dev[0].dump_monitor()
  1399. dev[1].dump_monitor()
  1400. def test_sigma_dut_dpp_proto_stop_at_responder(dev, apdev):
  1401. """sigma_dut DPP protocol testing - Stop at RX on Responder"""
  1402. check_dpp_capab(dev[0])
  1403. check_dpp_capab(dev[1])
  1404. tests = [ ("AuthenticationRequest",
  1405. "BootstrapResult,OK,AuthResult,Errorsent",
  1406. None),
  1407. ("AuthenticationConfirm",
  1408. "BootstrapResult,OK,AuthResult,Errorsent",
  1409. None) ]
  1410. for frame, result, fail in tests:
  1411. dev[0].request("FLUSH")
  1412. dev[1].request("FLUSH")
  1413. sigma = start_sigma_dut(dev[0].ifname)
  1414. try:
  1415. run_sigma_dut_dpp_proto_stop_at_responder(dev, frame, result, fail)
  1416. finally:
  1417. stop_sigma_dut(sigma)
  1418. def run_sigma_dut_dpp_proto_stop_at_responder(dev, frame, result, fail):
  1419. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,GetLocalBootstrap,DPPCryptoIdentifier,P-256,DPPBS,QR")
  1420. if "status,COMPLETE" not in res:
  1421. raise Exception("dev_exec_action did not succeed: " + res)
  1422. hex = res.split(',')[3]
  1423. uri = hex.decode('hex')
  1424. logger.info("URI from sigma_dut: " + uri)
  1425. res = dev[1].request("DPP_QR_CODE " + uri)
  1426. if "FAIL" in res:
  1427. raise Exception("Failed to parse QR Code URI")
  1428. id1 = int(res)
  1429. t = threading.Thread(target=dpp_proto_init, args=(dev[1], id1))
  1430. t.start()
  1431. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Responder,DPPAuthDirection,Single,DPPProvisioningRole,Enrollee,DPPConfIndex,1,DPPSigningKeyECC,P-256,DPPConfEnrolleeRole,STA,DPPBS,QR,DPPTimeout,6,DPPStep,Timeout,DPPFrameType,%s" % (frame), timeout=10)
  1432. t.join()
  1433. if result not in res:
  1434. raise Exception("Unexpected result: " + res)
  1435. if fail:
  1436. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1437. if ev is None or fail not in ev:
  1438. raise Exception("Failure not reported correctly:" + str(ev))
  1439. dev[1].request("DPP_STOP_LISTEN")
  1440. dev[0].dump_monitor()
  1441. dev[1].dump_monitor()
  1442. def dpp_proto_init_pkex(dev):
  1443. time.sleep(1)
  1444. logger.info("Starting DPP PKEX initiator/configurator in a thread")
  1445. cmd = "DPP_CONFIGURATOR_ADD"
  1446. res = dev.request(cmd);
  1447. if "FAIL" in res:
  1448. raise Exception("Failed to add configurator")
  1449. conf_id = int(res)
  1450. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1451. res = dev.request(cmd)
  1452. if "FAIL" in res:
  1453. raise Exception("Failed to generate bootstrapping info")
  1454. id = int(res)
  1455. cmd = "DPP_PKEX_ADD own=%d init=1 conf=sta-dpp configurator=%d code=secret" % (id, conf_id)
  1456. if "FAIL" in dev.request(cmd):
  1457. raise Exception("Failed to initiate DPP PKEX")
  1458. def test_sigma_dut_dpp_proto_initiator_pkex(dev, apdev):
  1459. """sigma_dut DPP protocol testing - Initiator (PKEX)"""
  1460. check_dpp_capab(dev[0])
  1461. check_dpp_capab(dev[1])
  1462. tests = [ ("InvalidValue", "PKEXCRRequest", "WrappedData",
  1463. "BootstrapResult,Errorsent",
  1464. None),
  1465. ("MissingAttribute", "PKEXExchangeRequest", "FiniteCyclicGroup",
  1466. "BootstrapResult,Errorsent",
  1467. "Missing or invalid Finite Cyclic Group attribute"),
  1468. ("MissingAttribute", "PKEXCRRequest", "BSKey",
  1469. "BootstrapResult,Errorsent",
  1470. "No valid peer bootstrapping key found") ]
  1471. for step, frame, attr, result, fail in tests:
  1472. dev[0].request("FLUSH")
  1473. dev[1].request("FLUSH")
  1474. sigma = start_sigma_dut(dev[0].ifname)
  1475. try:
  1476. run_sigma_dut_dpp_proto_initiator_pkex(dev, step, frame, attr,
  1477. result, fail)
  1478. finally:
  1479. stop_sigma_dut(sigma)
  1480. def run_sigma_dut_dpp_proto_initiator_pkex(dev, step, frame, attr, result, fail):
  1481. cmd = "DPP_BOOTSTRAP_GEN type=pkex"
  1482. res = dev[1].request(cmd)
  1483. if "FAIL" in res:
  1484. raise Exception("Failed to generate bootstrapping info")
  1485. id1 = int(res)
  1486. cmd = "DPP_PKEX_ADD own=%d code=secret" % (id1)
  1487. res = dev[1].request(cmd)
  1488. if "FAIL" in res:
  1489. raise Exception("Failed to set PKEX data (responder)")
  1490. cmd = "DPP_LISTEN 2437 role=enrollee"
  1491. if "OK" not in dev[1].request(cmd):
  1492. raise Exception("Failed to start listen operation")
  1493. 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))
  1494. if result not in res:
  1495. raise Exception("Unexpected result: " + res)
  1496. if fail:
  1497. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1498. if ev is None or fail not in ev:
  1499. raise Exception("Failure not reported correctly: " + str(ev))
  1500. dev[1].request("DPP_STOP_LISTEN")
  1501. dev[0].dump_monitor()
  1502. dev[1].dump_monitor()
  1503. def test_sigma_dut_dpp_proto_responder_pkex(dev, apdev):
  1504. """sigma_dut DPP protocol testing - Responder (PKEX)"""
  1505. check_dpp_capab(dev[0])
  1506. check_dpp_capab(dev[1])
  1507. tests = [ ("InvalidValue", "PKEXCRResponse", "WrappedData",
  1508. "BootstrapResult,Errorsent",
  1509. None),
  1510. ("MissingAttribute", "PKEXExchangeResponse", "DPPStatus",
  1511. "BootstrapResult,Errorsent",
  1512. "No DPP Status attribute"),
  1513. ("MissingAttribute", "PKEXCRResponse", "BSKey",
  1514. "BootstrapResult,Errorsent",
  1515. "No valid peer bootstrapping key found") ]
  1516. for step, frame, attr, result, fail in tests:
  1517. dev[0].request("FLUSH")
  1518. dev[1].request("FLUSH")
  1519. sigma = start_sigma_dut(dev[0].ifname)
  1520. try:
  1521. run_sigma_dut_dpp_proto_responder_pkex(dev, step, frame, attr,
  1522. result, fail)
  1523. finally:
  1524. stop_sigma_dut(sigma)
  1525. def run_sigma_dut_dpp_proto_responder_pkex(dev, step, frame, attr, result, fail):
  1526. t = threading.Thread(target=dpp_proto_init_pkex, args=(dev[1],))
  1527. t.start()
  1528. 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)
  1529. t.join()
  1530. if result not in res:
  1531. raise Exception("Unexpected result: " + res)
  1532. if fail:
  1533. ev = dev[1].wait_event(["DPP-FAIL"], timeout=5)
  1534. if ev is None or fail not in ev:
  1535. raise Exception("Failure not reported correctly:" + str(ev))
  1536. dev[1].request("DPP_STOP_LISTEN")
  1537. dev[0].dump_monitor()
  1538. dev[1].dump_monitor()
  1539. def init_sigma_dut_dpp_proto_peer_disc_req(dev, apdev):
  1540. check_dpp_capab(dev[0])
  1541. check_dpp_capab(dev[1])
  1542. csign = "30770201010420768240a3fc89d6662d9782f120527fe7fb9edc6366ab0b9c7dde96125cfd250fa00a06082a8648ce3d030107a144034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  1543. csign_pub = "3059301306072a8648ce3d020106082a8648ce3d030107034200042908e1baf7bf413cc66f9e878a03e8bb1835ba94b033dbe3d6969fc8575d5eb5dfda1cb81c95cee21d0cd7d92ba30541ffa05cb6296f5dd808b0c1c2a83c0708"
  1544. ap_connector = "eyJ0eXAiOiJkcHBDb24iLCJraWQiOiJwYWtZbXVzd1dCdWpSYTl5OEsweDViaTVrT3VNT3dzZHRlaml2UG55ZHZzIiwiYWxnIjoiRVMyNTYifQ.eyJncm91cHMiOlt7Imdyb3VwSWQiOiIqIiwibmV0Um9sZSI6ImFwIn1dLCJuZXRBY2Nlc3NLZXkiOnsia3R5IjoiRUMiLCJjcnYiOiJQLTI1NiIsIngiOiIybU5vNXZuRkI5bEw3d1VWb1hJbGVPYzBNSEE1QXZKbnpwZXZULVVTYzVNIiwieSI6IlhzS3dqVHJlLTg5WWdpU3pKaG9CN1haeUttTU05OTl3V2ZaSVl0bi01Q3MifX0.XhjFpZgcSa7G2lHy0OCYTvaZFRo5Hyx6b7g7oYyusLC7C_73AJ4_BxEZQVYJXAtDuGvb3dXSkHEKxREP9Q6Qeg"
  1545. ap_netaccesskey = "30770201010420ceba752db2ad5200fa7bc565b9c05c69b7eb006751b0b329b0279de1c19ca67ca00a06082a8648ce3d030107a14403420004da6368e6f9c507d94bef0515a1722578e73430703902f267ce97af4fe51273935ec2b08d3adefbcf588224b3261a01ed76722a630cf7df7059f64862d9fee42b"
  1546. params = { "ssid": "DPPNET01",
  1547. "wpa": "2",
  1548. "wpa_key_mgmt": "DPP",
  1549. "rsn_pairwise": "CCMP",
  1550. "dpp_connector": ap_connector,
  1551. "dpp_csign": csign_pub,
  1552. "dpp_netaccesskey": ap_netaccesskey }
  1553. try:
  1554. hapd = hostapd.add_ap(apdev[0], params)
  1555. except:
  1556. raise HwsimSkip("DPP not supported")
  1557. dev[0].set("dpp_config_processing", "2")
  1558. cmd = "DPP_CONFIGURATOR_ADD key=" + csign
  1559. res = dev[1].request(cmd);
  1560. if "FAIL" in res:
  1561. raise Exception("Failed to add configurator")
  1562. conf_id = int(res)
  1563. addr = dev[1].own_addr().replace(':', '')
  1564. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/6 mac=" + addr
  1565. res = dev[1].request(cmd)
  1566. if "FAIL" in res:
  1567. raise Exception("Failed to generate bootstrapping info")
  1568. id0 = int(res)
  1569. uri0 = dev[1].request("DPP_BOOTSTRAP_GET_URI %d" % id0)
  1570. dev[1].set("dpp_configurator_params",
  1571. " conf=sta-dpp ssid=%s configurator=%d" % ("DPPNET01".encode("hex"), conf_id));
  1572. cmd = "DPP_LISTEN 2437 role=configurator"
  1573. if "OK" not in dev[1].request(cmd):
  1574. raise Exception("Failed to start listen operation")
  1575. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri0.encode('hex'))
  1576. if "status,COMPLETE" not in res:
  1577. raise Exception("dev_exec_action did not succeed: " + res)
  1578. def test_sigma_dut_dpp_proto_peer_disc_req(dev, apdev):
  1579. """sigma_dut DPP protocol testing - Peer Discovery Request"""
  1580. sigma = start_sigma_dut(dev[0].ifname)
  1581. try:
  1582. init_sigma_dut_dpp_proto_peer_disc_req(dev, apdev)
  1583. 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)
  1584. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,Errorsent" not in res:
  1585. raise Exception("Unexpected result: " + res)
  1586. finally:
  1587. dev[0].set("dpp_config_processing", "0")
  1588. stop_sigma_dut(sigma)
  1589. def test_sigma_dut_dpp_self_config(dev, apdev):
  1590. """sigma_dut DPP Configurator enrolling an AP and using self-configuration"""
  1591. check_dpp_capab(dev[0])
  1592. hapd = hostapd.add_ap(apdev[0], { "ssid": "unconfigured" })
  1593. check_dpp_capab(hapd)
  1594. sigma = start_sigma_dut(dev[0].ifname)
  1595. try:
  1596. dev[0].set("dpp_config_processing", "2")
  1597. addr = hapd.own_addr().replace(':', '')
  1598. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/1 mac=" + addr
  1599. res = hapd.request(cmd)
  1600. if "FAIL" in res:
  1601. raise Exception("Failed to generate bootstrapping info")
  1602. id = int(res)
  1603. uri = hapd.request("DPP_BOOTSTRAP_GET_URI %d" % id)
  1604. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri.encode('hex'))
  1605. if "status,COMPLETE" not in res:
  1606. raise Exception("dev_exec_action did not succeed: " + res)
  1607. 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")
  1608. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1609. raise Exception("Unexpected result: " + res)
  1610. update_hapd_config(hapd)
  1611. 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"
  1612. res = sigma_dut_cmd(cmd, timeout=10)
  1613. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK,NetworkIntroResult,OK,NetworkConnectResult,OK" not in res:
  1614. raise Exception("Unexpected result: " + res)
  1615. finally:
  1616. stop_sigma_dut(sigma)
  1617. dev[0].set("dpp_config_processing", "0")
  1618. def test_sigma_dut_ap_dpp_self_config(dev, apdev, params):
  1619. """sigma_dut DPP AP Configurator using self-configuration"""
  1620. logdir = os.path.join(params['logdir'],
  1621. "sigma_dut_ap_dpp_self_config.sigma-hostapd")
  1622. with HWSimRadio() as (radio, iface):
  1623. sigma = start_sigma_dut(iface, hostapd_logdir=logdir)
  1624. try:
  1625. run_sigma_dut_ap_dpp_self_config(dev, apdev)
  1626. finally:
  1627. stop_sigma_dut(sigma)
  1628. dev[0].set("dpp_config_processing", "0")
  1629. def run_sigma_dut_ap_dpp_self_config(dev, apdev):
  1630. check_dpp_capab(dev[0])
  1631. sigma_dut_cmd_check("ap_reset_default,program,DPP")
  1632. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,AutomaticDPP,DPPAuthRole,Initiator,DPPAuthDirection,Single,DPPProvisioningRole,Configurator,DPPConfEnrolleeRole,AP,DPPBS,QR,DPPConfIndex,1,DPPSelfConfigure,Yes,DPPTimeout,6", timeout=10)
  1633. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1634. raise Exception("Unexpected result: " + res)
  1635. dev[0].set("dpp_config_processing", "2")
  1636. addr = dev[0].own_addr().replace(':', '')
  1637. cmd = "DPP_BOOTSTRAP_GEN type=qrcode chan=81/11 mac=" + addr
  1638. res = dev[0].request(cmd)
  1639. if "FAIL" in res:
  1640. raise Exception("Failed to generate bootstrapping info")
  1641. id = int(res)
  1642. uri = dev[0].request("DPP_BOOTSTRAP_GET_URI %d" % id)
  1643. cmd = "DPP_LISTEN 2462 role=enrollee"
  1644. if "OK" not in dev[0].request(cmd):
  1645. raise Exception("Failed to start listen operation")
  1646. res = sigma_dut_cmd("dev_exec_action,program,DPP,DPPActionType,SetPeerBootstrap,DPPBootstrappingdata,%s,DPPBS,QR" % uri.encode('hex'))
  1647. if "status,COMPLETE" not in res:
  1648. raise Exception("dev_exec_action did not succeed: " + res)
  1649. 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"
  1650. res = sigma_dut_cmd(cmd)
  1651. if "BootstrapResult,OK,AuthResult,OK,ConfResult,OK" not in res:
  1652. raise Exception("Unexpected result: " + res)
  1653. dev[0].wait_connected()
  1654. dev[0].request("DISCONNECT")
  1655. dev[0].wait_disconnected()
  1656. sigma_dut_cmd_check("ap_reset_default")
  1657. def test_sigma_dut_preconfigured_profile(dev, apdev):
  1658. """sigma_dut controlled connection using preconfigured profile"""
  1659. try:
  1660. run_sigma_dut_preconfigured_profile(dev, apdev)
  1661. finally:
  1662. dev[0].set("ignore_old_scan_res", "0")
  1663. def run_sigma_dut_preconfigured_profile(dev, apdev):
  1664. ifname = dev[0].ifname
  1665. sigma = start_sigma_dut(ifname)
  1666. params = hostapd.wpa2_params(ssid="test-psk", passphrase="12345678")
  1667. hapd = hostapd.add_ap(apdev[0], params)
  1668. dev[0].connect("test-psk", psk="12345678", scan_freq="2412",
  1669. only_add_network=True)
  1670. sigma_dut_cmd_check("sta_set_ip_config,interface,%s,dhcp,0,ip,127.0.0.11,mask,255.255.255.0" % ifname)
  1671. sigma_dut_cmd_check("sta_associate,interface,%s,ssid,%s" % (ifname, "test-psk"))
  1672. sigma_dut_wait_connected(ifname)
  1673. sigma_dut_cmd_check("sta_get_ip_config,interface," + ifname)
  1674. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  1675. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  1676. stop_sigma_dut(sigma)
  1677. def test_sigma_dut_wps_pbc(dev, apdev):
  1678. """sigma_dut and WPS PBC Enrollee"""
  1679. try:
  1680. run_sigma_dut_wps_pbc(dev, apdev)
  1681. finally:
  1682. dev[0].set("ignore_old_scan_res", "0")
  1683. def run_sigma_dut_wps_pbc(dev, apdev):
  1684. ssid = "test-wps-conf"
  1685. hapd = hostapd.add_ap(apdev[0],
  1686. { "ssid": "wps", "eap_server": "1", "wps_state": "2",
  1687. "wpa_passphrase": "12345678", "wpa": "2",
  1688. "wpa_key_mgmt": "WPA-PSK", "rsn_pairwise": "CCMP" })
  1689. hapd.request("WPS_PBC")
  1690. ifname = dev[0].ifname
  1691. sigma = start_sigma_dut(ifname)
  1692. cmd = "start_wps_registration,interface,%s" % ifname
  1693. cmd += ",WpsRole,Enrollee"
  1694. cmd += ",WpsConfigMethod,PBC"
  1695. sigma_dut_cmd_check(cmd, timeout=15)
  1696. sigma_dut_cmd_check("sta_disconnect,interface," + ifname)
  1697. hapd.disable()
  1698. sigma_dut_cmd_check("sta_reset_default,interface," + ifname)
  1699. stop_sigma_dut(sigma)
  1700. dev[0].flush_scan_cache()