test_sigma_dut.py 95 KB

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