test_peerkey.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # PeerKey tests
  2. # Copyright (c) 2013, 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. import logging
  7. logger = logging.getLogger()
  8. import time
  9. import hwsim_utils
  10. import hostapd
  11. from wlantest import Wlantest
  12. def test_peerkey(dev, apdev):
  13. """RSN AP and PeerKey between two STAs"""
  14. ssid = "test-peerkey"
  15. passphrase = "12345678"
  16. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  17. params['peerkey'] = "1"
  18. hostapd.add_ap(apdev[0]['ifname'], params)
  19. dev[0].connect(ssid, psk=passphrase, scan_freq="2412", peerkey=True)
  20. dev[1].connect(ssid, psk=passphrase, scan_freq="2412", peerkey=True)
  21. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  22. dev[0].request("STKSTART " + dev[1].p2p_interface_addr())
  23. time.sleep(0.5)
  24. # NOTE: Actual use of the direct link (DLS) is not supported in
  25. # mac80211_hwsim, so this operation fails at setting the keys after
  26. # successfully completed 4-way handshake. This test case does allow the
  27. # key negotiation part to be tested for coverage, though.
  28. def test_peerkey_unknown_peer(dev, apdev):
  29. """RSN AP and PeerKey attempt with unknown peer"""
  30. ssid = "test-peerkey"
  31. passphrase = "12345678"
  32. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  33. params['peerkey'] = "1"
  34. hostapd.add_ap(apdev[0]['ifname'], params)
  35. dev[0].connect(ssid, psk=passphrase, scan_freq="2412", peerkey=True)
  36. dev[1].connect(ssid, psk=passphrase, scan_freq="2412", peerkey=True)
  37. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  38. dev[0].request("STKSTART " + dev[2].p2p_interface_addr())
  39. time.sleep(0.5)
  40. def test_peerkey_pairwise_mismatch(dev, apdev):
  41. """RSN TKIP+CCMP AP and PeerKey between two STAs using different ciphers"""
  42. wt = Wlantest()
  43. wt.flush()
  44. wt.add_passphrase("12345678")
  45. ssid = "test-peerkey"
  46. passphrase = "12345678"
  47. params = hostapd.wpa2_params(ssid=ssid, passphrase=passphrase)
  48. params['peerkey'] = "1"
  49. params['rsn_pairwise'] = "TKIP CCMP"
  50. hostapd.add_ap(apdev[0]['ifname'], params)
  51. dev[0].connect(ssid, psk=passphrase, scan_freq="2412", peerkey=True,
  52. pairwise="CCMP")
  53. dev[1].connect(ssid, psk=passphrase, scan_freq="2412", peerkey=True,
  54. pairwise="TKIP")
  55. hwsim_utils.test_connectivity_sta(dev[0], dev[1])
  56. dev[0].request("STKSTART " + dev[1].p2p_interface_addr())
  57. time.sleep(0.5)
  58. dev[1].request("STKSTART " + dev[0].p2p_interface_addr())
  59. time.sleep(0.5)