test_peerkey.py 2.7 KB

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