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