test_ext_password.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # External password storage
  2. # Copyright (c) 2014, Jouni Malinen <j@w1.fi>
  3. #
  4. # This software may be distributed under the terms of the BSD license.
  5. # See README for more details.
  6. from remotehost import remote_compatible
  7. import logging
  8. logger = logging.getLogger()
  9. import hostapd
  10. from utils import skip_with_fips
  11. from wpasupplicant import WpaSupplicant
  12. from test_ap_hs20 import hs20_ap_params
  13. from test_ap_hs20 import interworking_select
  14. from test_ap_hs20 import interworking_connect
  15. @remote_compatible
  16. def test_ext_password_psk(dev, apdev):
  17. """External password storage for PSK"""
  18. params = hostapd.wpa2_params(ssid="ext-pw-psk", passphrase="12345678")
  19. hostapd.add_ap(apdev[0], params)
  20. dev[0].request("SET ext_password_backend test:psk1=12345678")
  21. dev[0].connect("ext-pw-psk", raw_psk="ext:psk1", scan_freq="2412")
  22. def test_ext_password_psk_not_found(dev, apdev):
  23. """External password storage for PSK and PSK not found"""
  24. params = hostapd.wpa2_params(ssid="ext-pw-psk", passphrase="12345678")
  25. hostapd.add_ap(apdev[0], params)
  26. dev[0].request("SET ext_password_backend test:psk1=12345678")
  27. dev[0].connect("ext-pw-psk", raw_psk="ext:psk2", scan_freq="2412",
  28. wait_connect=False)
  29. dev[1].request("SET ext_password_backend test:psk1=1234567")
  30. dev[1].connect("ext-pw-psk", raw_psk="ext:psk1", scan_freq="2412",
  31. wait_connect=False)
  32. dev[2].request("SET ext_password_backend test:psk1=1234567890123456789012345678901234567890123456789012345678901234567890")
  33. dev[2].connect("ext-pw-psk", raw_psk="ext:psk1", scan_freq="2412",
  34. wait_connect=False)
  35. wpas = WpaSupplicant(global_iface='/tmp/wpas-wlan5')
  36. wpas.interface_add("wlan5")
  37. wpas.request("SET ext_password_backend test:psk1=123456789012345678901234567890123456789012345678901234567890123q")
  38. wpas.connect("ext-pw-psk", raw_psk="ext:psk1", scan_freq="2412",
  39. wait_connect=False)
  40. ev = dev[0].wait_event(["CTRL-EVENT-CONNECTED"], timeout=1)
  41. if ev is not None:
  42. raise Exception("Unexpected association")
  43. ev = dev[1].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.1)
  44. if ev is not None:
  45. raise Exception("Unexpected association")
  46. ev = dev[2].wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.1)
  47. if ev is not None:
  48. raise Exception("Unexpected association")
  49. ev = wpas.wait_event(["CTRL-EVENT-CONNECTED"], timeout=0.1)
  50. if ev is not None:
  51. raise Exception("Unexpected association")
  52. def test_ext_password_eap(dev, apdev):
  53. """External password storage for EAP password"""
  54. params = hostapd.wpa2_eap_params(ssid="ext-pw-eap")
  55. hostapd.add_ap(apdev[0], params)
  56. dev[0].request("SET ext_password_backend test:pw0=hello|pw1=password|pw2=secret")
  57. dev[0].connect("ext-pw-eap", key_mgmt="WPA-EAP", eap="PEAP",
  58. identity="user", password_hex="ext:pw1",
  59. ca_cert="auth_serv/ca.pem", phase2="auth=MSCHAPV2",
  60. scan_freq="2412")
  61. def test_ext_password_interworking(dev, apdev):
  62. """External password storage for Interworking network selection"""
  63. skip_with_fips(dev[0])
  64. bssid = apdev[0]['bssid']
  65. params = hs20_ap_params()
  66. hostapd.add_ap(apdev[0], params)
  67. dev[0].hs20_enable()
  68. dev[0].request("SET ext_password_backend test:pw1=password")
  69. id = dev[0].add_cred_values({ 'realm': "example.com",
  70. 'username': "hs20-test" })
  71. dev[0].set_cred(id, "password", "ext:pw1")
  72. interworking_select(dev[0], bssid, freq="2412")
  73. interworking_connect(dev[0], bssid, "TTLS")