1# 2# Copyright 2016 - 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 logging 17import os 18import pprint 19import re 20import time 21import urllib.request 22 23from acts import asserts 24from acts import base_test 25from acts import test_runner 26from acts.controllers import adb 27from acts.test_decorators import test_tracker_info 28from acts.test_utils.net import connectivity_const 29from acts.test_utils.net import net_test_utils as nutils 30from acts.test_utils.wifi import wifi_test_utils as wutils 31from acts.test_utils.wifi.WifiBaseTest import WifiBaseTest 32 33VPN_CONST = connectivity_const.VpnProfile 34VPN_TYPE = connectivity_const.VpnProfileType 35VPN_PARAMS = connectivity_const.VpnReqParams 36 37 38class LegacyVpnTest(WifiBaseTest): 39 """ Tests for Legacy VPN in Android 40 41 Testbed requirement: 42 1. One Android device 43 2. A Wi-Fi network that can reach the VPN servers 44 """ 45 46 def setup_class(self): 47 """ Setup wi-fi connection and unpack params 48 """ 49 self.dut = self.android_devices[0] 50 required_params = dir(VPN_PARAMS) 51 required_params = [x for x in required_params if not x.startswith('__')] 52 optional_params = ["reference_networks", "wpa_networks",] 53 self.unpack_userparams(req_param_names=required_params, 54 opt_param_names=optional_params) 55 if "AccessPoint" in self.user_params: 56 self.legacy_configure_ap_and_start(wpa_network=True) 57 asserts.assert_true(len(self.reference_networks) > 0, 58 "Need at least one reference network with psk.") 59 self.wifi_network = self.reference_networks[0]["2g"] 60 wutils.wifi_test_device_init(self.dut) 61 wutils.wifi_toggle_state(self.dut, True) 62 wutils.wifi_connect(self.dut, self.wifi_network) 63 time.sleep(3) 64 65 self.vpn_params = {'vpn_username': self.vpn_username, 66 'vpn_password': self.vpn_password, 67 'psk_secret': self.psk_secret, 68 'client_pkcs_file_name': self.client_pkcs_file_name, 69 'cert_path_vpnserver': self.cert_path_vpnserver, 70 'cert_password': self.cert_password} 71 72 def teardown_class(self): 73 """ Reset wifi to make sure VPN tears down cleanly 74 """ 75 wutils.reset_wifi(self.dut) 76 77 def on_fail(self, test_name, begin_time): 78 self.dut.take_bug_report(test_name, begin_time) 79 80 """ Test Cases """ 81 @test_tracker_info(uuid="d2ac5a65-41fb-48de-a0a9-37e589b5456b") 82 def test_legacy_vpn_pptp(self): 83 """ Verify PPTP VPN connection """ 84 vpn = VPN_TYPE.PPTP 85 vpn_profile = nutils.generate_legacy_vpn_profile( 86 self.dut, self.vpn_params, 87 vpn, self.vpn_server_addresses[vpn.name][0], 88 self.ipsec_server_type[2], 89 self.log_path) 90 vpn_addr = self.vpn_verify_addresses[vpn.name][0] 91 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 92 93 @test_tracker_info(uuid="99af78dd-40b8-483a-8344-cd8f67594971") 94 def legacy_vpn_l2tp_ipsec_psk_libreswan(self): 95 """ Verify L2TP IPSec PSK VPN connection to 96 libreSwan server 97 """ 98 vpn = VPN_TYPE.L2TP_IPSEC_PSK 99 vpn_profile = nutils.generate_legacy_vpn_profile( 100 self.dut, self.vpn_params, 101 vpn, self.vpn_server_addresses[vpn.name][2], 102 self.ipsec_server_type[2], 103 self.log_path) 104 vpn_addr = self.vpn_verify_addresses[vpn.name][2] 105 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 106 107 @test_tracker_info(uuid="e67d8c38-92c3-4167-8b6c-a49ef939adce") 108 def legacy_vpn_l2tp_ipsec_rsa_libreswan(self): 109 """ Verify L2TP IPSec RSA VPN connection to 110 libreSwan server 111 """ 112 vpn = VPN_TYPE.L2TP_IPSEC_RSA 113 vpn_profile = nutils.generate_legacy_vpn_profile( 114 self.dut, self.vpn_params, 115 vpn, self.vpn_server_addresses[vpn.name][2], 116 self.ipsec_server_type[2], 117 self.log_path) 118 vpn_addr = self.vpn_verify_addresses[vpn.name][2] 119 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 120 121 @test_tracker_info(uuid="8b3517dc-6a3b-44c2-a85d-bd7b969df3cf") 122 def legacy_vpn_ipsec_xauth_psk_libreswan(self): 123 """ Verify IPSec XAUTH PSK VPN connection to 124 libreSwan server 125 """ 126 vpn = VPN_TYPE.IPSEC_XAUTH_PSK 127 vpn_profile = nutils.generate_legacy_vpn_profile( 128 self.dut, self.vpn_params, 129 vpn, self.vpn_server_addresses[vpn.name][2], 130 self.ipsec_server_type[2], 131 self.log_path) 132 vpn_addr = self.vpn_verify_addresses[vpn.name][2] 133 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 134 135 @test_tracker_info(uuid="abac663d-1d91-4b87-8e94-11c6e44fb07b") 136 def legacy_vpn_ipsec_xauth_rsa_libreswan(self): 137 """ Verify IPSec XAUTH RSA VPN connection to 138 libreSwan server 139 """ 140 vpn = VPN_TYPE.IPSEC_XAUTH_RSA 141 vpn_profile = nutils.generate_legacy_vpn_profile( 142 self.dut, self.vpn_params, 143 vpn, self.vpn_server_addresses[vpn.name][2], 144 self.ipsec_server_type[2], 145 self.log_path) 146 vpn_addr = self.vpn_verify_addresses[vpn.name][2] 147 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 148 149 @test_tracker_info(uuid="84140d24-53c0-4f6c-866f-9d66e04442cc") 150 def test_legacy_vpn_l2tp_ipsec_psk_openswan(self): 151 """ Verify L2TP IPSec PSK VPN connection to 152 openSwan server 153 """ 154 vpn = VPN_TYPE.L2TP_IPSEC_PSK 155 vpn_profile = nutils.generate_legacy_vpn_profile( 156 self.dut, self.vpn_params, 157 vpn, self.vpn_server_addresses[vpn.name][1], 158 self.ipsec_server_type[1], 159 self.log_path) 160 vpn_addr = self.vpn_verify_addresses[vpn.name][1] 161 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 162 163 @test_tracker_info(uuid="f7087592-7eed-465d-bfe3-ed7b6d9d5f9a") 164 def test_legacy_vpn_l2tp_ipsec_rsa_openswan(self): 165 """ Verify L2TP IPSec RSA VPN connection to 166 openSwan server 167 """ 168 vpn = VPN_TYPE.L2TP_IPSEC_RSA 169 vpn_profile = nutils.generate_legacy_vpn_profile( 170 self.dut, self.vpn_params, 171 vpn, self.vpn_server_addresses[vpn.name][1], 172 self.ipsec_server_type[1], 173 self.log_path) 174 vpn_addr = self.vpn_verify_addresses[vpn.name][1] 175 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 176 177 @test_tracker_info(uuid="ed78973b-13ee-4dd4-b998-693ab741c6f8") 178 def test_legacy_vpn_ipsec_xauth_psk_openswan(self): 179 """ Verify IPSec XAUTH PSK VPN connection to 180 openSwan server 181 """ 182 vpn = VPN_TYPE.IPSEC_XAUTH_PSK 183 vpn_profile = nutils.generate_legacy_vpn_profile( 184 self.dut, self.vpn_params, 185 vpn, self.vpn_server_addresses[vpn.name][1], 186 self.ipsec_server_type[1], 187 self.log_path) 188 vpn_addr = self.vpn_verify_addresses[vpn.name][1] 189 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 190 191 @test_tracker_info(uuid="cfd125c4-b64c-4c49-b8e4-fbf05a9be8ec") 192 def test_legacy_vpn_ipsec_xauth_rsa_openswan(self): 193 """ Verify IPSec XAUTH RSA VPN connection to 194 openSwan server 195 """ 196 vpn = VPN_TYPE.IPSEC_XAUTH_RSA 197 vpn_profile = nutils.generate_legacy_vpn_profile( 198 self.dut, self.vpn_params, 199 vpn, self.vpn_server_addresses[vpn.name][1], 200 self.ipsec_server_type[1], 201 self.log_path) 202 vpn_addr = self.vpn_verify_addresses[vpn.name][1] 203 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 204 205 @test_tracker_info(uuid="419370de-0aa1-4a56-8c22-21567fa1cbb7") 206 def test_legacy_vpn_l2tp_ipsec_psk_strongswan(self): 207 """ Verify L2TP IPSec PSk VPN connection to 208 strongSwan server 209 """ 210 vpn = VPN_TYPE.L2TP_IPSEC_PSK 211 vpn_profile = nutils.generate_legacy_vpn_profile( 212 self.dut, self.vpn_params, 213 vpn, self.vpn_server_addresses[vpn.name][0], 214 self.ipsec_server_type[0], 215 self.log_path) 216 vpn_addr = self.vpn_verify_addresses[vpn.name][0] 217 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 218 219 @test_tracker_info(uuid="f7694081-8bd6-4e31-86ec-d538c4ff1f2e") 220 def test_legacy_vpn_l2tp_ipsec_rsa_strongswan(self): 221 """ Verify L2TP IPSec RSA VPN connection to 222 strongSwan server 223 """ 224 vpn = VPN_TYPE.L2TP_IPSEC_RSA 225 vpn_profile = nutils.generate_legacy_vpn_profile( 226 self.dut, self.vpn_params, 227 vpn, self.vpn_server_addresses[vpn.name][0], 228 self.ipsec_server_type[0], 229 self.log_path) 230 vpn_addr = self.vpn_verify_addresses[vpn.name][0] 231 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 232 233 @test_tracker_info(uuid="2f86eb98-1e05-42cb-b6a6-fd90789b6cde") 234 def test_legacy_vpn_ipsec_xauth_psk_strongswan(self): 235 """ Verify IPSec XAUTH PSK connection to 236 strongSwan server 237 """ 238 vpn = VPN_TYPE.IPSEC_XAUTH_PSK 239 vpn_profile = nutils.generate_legacy_vpn_profile( 240 self.dut, self.vpn_params, 241 vpn, self.vpn_server_addresses[vpn.name][0], 242 self.ipsec_server_type[0], 243 self.log_path) 244 vpn_addr = self.vpn_verify_addresses[vpn.name][0] 245 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 246 247 @test_tracker_info(uuid="af0cd7b1-e86c-4327-91b4-e9062758f2cf") 248 def test_legacy_vpn_ipsec_xauth_rsa_strongswan(self): 249 """ Verify IPSec XAUTH RSA connection to 250 strongswan server 251 """ 252 vpn = VPN_TYPE.IPSEC_XAUTH_RSA 253 vpn_profile = nutils.generate_legacy_vpn_profile( 254 self.dut, self.vpn_params, 255 vpn, self.vpn_server_addresses[vpn.name][0], 256 self.ipsec_server_type[0], 257 self.log_path) 258 vpn_addr = self.vpn_verify_addresses[vpn.name][0] 259 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 260 261 @test_tracker_info(uuid="7b970d0a-1c7d-4a5a-b406-4815e190ef26") 262 def test_legacy_vpn_ipsec_hybrid_rsa_strongswan(self): 263 """ Verify IPSec Hybrid RSA connection to 264 strongswan server 265 """ 266 vpn = VPN_TYPE.IPSEC_HYBRID_RSA 267 vpn_profile = nutils.generate_legacy_vpn_profile( 268 self.dut, self.vpn_params, 269 vpn, self.vpn_server_addresses[vpn.name][0], 270 self.ipsec_server_type[0], 271 self.log_path) 272 vpn_addr = self.vpn_verify_addresses[vpn.name][0] 273 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 274