• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2#   Copyright 2020 - The Android Open Source Project
3#
4#   Licensed under the Apache License, Version 2.0 (the "License");
5#   you may not use this file except in compliance with the License.
6#   You may obtain a copy of the License at
7#
8#       http://www.apache.org/licenses/LICENSE-2.0
9#
10#   Unless required by applicable law or agreed to in writing, software
11#   distributed under the License is distributed on an "AS IS" BASIS,
12#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13#   See the License for the specific language governing permissions and
14#   limitations under the License.
15
16import time
17
18from acts.controllers.openwrt_ap import MOBLY_CONTROLLER_CONFIG_NAME as OPENWRT
19from acts.test_decorators import test_tracker_info
20from acts_contrib.test_utils.net import connectivity_const
21from acts_contrib.test_utils.net import net_test_utils as nutils
22from acts_contrib.test_utils.wifi import wifi_test_utils as wutils
23from acts_contrib.test_utils.wifi.WifiBaseTest import WifiBaseTest
24
25
26VPN_CONST = connectivity_const.VpnProfile
27VPN_TYPE = connectivity_const.VpnProfileType
28VPN_PARAMS = connectivity_const.VpnReqParams
29
30
31class IKEv2VpnOverWifiTest(WifiBaseTest):
32  """IKEv2 VPN tests."""
33
34  def setup_class(self):
35    """Setup wi-fi connection and unpack params."""
36    self.dut = self.android_devices[0]
37    req_params = dir(VPN_PARAMS)
38    req_params = [
39      x for x in req_params if not x.startswith("__")
40    ]
41    opt_params = ["wifi_network", "vpn_cert_country",
42            "vpn_cert_org", "configure_OpenWrt"]
43    self.unpack_userparams(req_param_names=req_params,
44                 opt_param_names=opt_params)
45
46    wutils.wifi_test_device_init(self.dut)
47    wutils.wifi_toggle_state(self.dut, True)
48    if OPENWRT in self.user_params:
49      self.openwrt = self.access_points[0]
50      if hasattr(self, "configure_OpenWrt") and self.configure_OpenWrt == "skip":
51        self.dut.log.info("Skip configure Wifi interface due to config setup.")
52      else:
53        self.configure_openwrt_ap_and_start(wpa_network=True)
54        self.wifi_network = self.openwrt.get_wifi_network()
55      # Wait for OpenWrt statement update
56      time.sleep(10)
57      self.openwrt.network_setting.setup_vpn_l2tp_server(
58        self.vpn_server_hostname,
59        self.vpn_verify_addresses["IKEV2_IPSEC_RSA"][0],
60        self.vpn_username,
61        self.vpn_password,
62        self.vpn_identity,
63        "ikev2-server",
64        self.vpn_cert_country,
65        self.vpn_cert_org
66      )
67    wutils.start_wifi_connection_scan_and_ensure_network_found(
68      self.dut, self.wifi_network["SSID"])
69    wutils.wifi_connect(self.dut, self.wifi_network)
70    time.sleep(3)
71
72    self.vpn_params = {"vpn_username": self.vpn_username,
73               "vpn_password": self.vpn_password,
74               "psk_secret": self.psk_secret,
75               "client_pkcs_file_name": self.client_pkcs_file_name,
76               "cert_path_vpnserver": self.cert_path_vpnserver,
77               "cert_password": self.cert_password,
78               "vpn_identity": self.vpn_identity}
79
80  def teardown_class(self):
81    wutils.reset_wifi(self.dut)
82
83  def on_fail(self, test_name, begin_time):
84    self.dut.take_bug_report(test_name, begin_time)
85
86  ### Helper methods ###
87
88  def _test_ikev2_vpn(self, vpn, hostname=None):
89    """Verify IKEv2 VPN connection.
90
91    Args:
92      vpn: type of VPN.
93      hostname: hostname or IP address of the server.
94    """
95    server_addr = self.vpn_server_addresses[vpn.name][0]
96    self.vpn_params["server_addr"] = server_addr
97    if not hostname:
98      hostname = server_addr
99    vpn_addr = self.vpn_verify_addresses[vpn.name][0]
100    vpn_profile = nutils.generate_ikev2_vpn_profile(
101        self.dut, self.vpn_params, vpn, hostname, self.log_path)
102    nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr)
103
104  ### Test cases ###
105
106  @test_tracker_info(uuid="4991755c-321d-4e9a-ada9-fc821a35bb5b")
107  def test_ikev2_psk_vpn_wifi(self):
108    self._test_ikev2_vpn(VPN_TYPE.IKEV2_IPSEC_PSK)
109
110  @test_tracker_info(uuid="04d88575-7b96-4746-bff8-a1d6841e202e")
111  def test_ikev2_mschapv2_vpn_wifi(self):
112    self._test_ikev2_vpn(VPN_TYPE.IKEV2_IPSEC_USER_PASS)
113
114  @test_tracker_info(uuid="e65f8a3e-f807-4493-822e-377dd6fa89cd")
115  def test_ikev2_rsa_vpn_wifi(self):
116    self._test_ikev2_vpn(VPN_TYPE.IKEV2_IPSEC_RSA)
117
118  @test_tracker_info(uuid="bdd8a967-8dac-4e48-87b7-2ce9f7d32158")
119  def test_ikev2_psk_vpn_wifi_with_hostname(self):
120    self._test_ikev2_vpn(VPN_TYPE.IKEV2_IPSEC_PSK,
121                         self.vpn_server_hostname)
122
123  @test_tracker_info(uuid="19692520-c123-4b42-8549-08dda9c4873e")
124  def test_ikev2_mschapv2_vpn_wifi_with_hostname(self):
125    self._test_ikev2_vpn(VPN_TYPE.IKEV2_IPSEC_USER_PASS,
126                         self.vpn_server_hostname)
127
128  @test_tracker_info(uuid="bdaaf6e3-6671-4533-baba-2951009c7d69")
129  def test_ikev2_rsa_vpn_wifi_with_hostname(self):
130    self._test_ikev2_vpn(VPN_TYPE.IKEV2_IPSEC_RSA,
131                         self.vpn_server_hostname)
132