test_peerkey.py 2.6 KB

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