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 = [ 52 x for x in required_params if not x.startswith('__') 53 ] + ["wifi_network"] 54 self.unpack_userparams(req_param_names=required_params) 55 56 wutils.wifi_test_device_init(self.dut) 57 wutils.wifi_toggle_state(self.dut, True) 58 wutils.start_wifi_connection_scan_and_ensure_network_found( 59 self.dut, self.wifi_network["SSID"]) 60 wutils.wifi_connect(self.dut, self.wifi_network) 61 time.sleep(3) 62 63 self.vpn_params = {'vpn_username': self.vpn_username, 64 'vpn_password': self.vpn_password, 65 'psk_secret': self.psk_secret, 66 'client_pkcs_file_name': self.client_pkcs_file_name, 67 'cert_path_vpnserver': self.cert_path_vpnserver, 68 'cert_password': self.cert_password} 69 70 def teardown_class(self): 71 """ Reset wifi to make sure VPN tears down cleanly 72 """ 73 wutils.reset_wifi(self.dut) 74 75 def on_fail(self, test_name, begin_time): 76 self.dut.take_bug_report(test_name, begin_time) 77 78 """ Test Cases """ 79 @test_tracker_info(uuid="d2ac5a65-41fb-48de-a0a9-37e589b5456b") 80 def test_legacy_vpn_pptp(self): 81 """ Verify PPTP VPN connection """ 82 vpn = VPN_TYPE.PPTP 83 vpn_profile = nutils.generate_legacy_vpn_profile( 84 self.dut, self.vpn_params, 85 vpn, self.vpn_server_addresses[vpn.name][0], 86 self.ipsec_server_type[2], 87 self.log_path) 88 vpn_addr = self.vpn_verify_addresses[vpn.name][0] 89 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 90 91 @test_tracker_info(uuid="99af78dd-40b8-483a-8344-cd8f67594971") 92 def legacy_vpn_l2tp_ipsec_psk_libreswan(self): 93 """ Verify L2TP IPSec PSK VPN connection to 94 libreSwan server 95 """ 96 vpn = VPN_TYPE.L2TP_IPSEC_PSK 97 vpn_profile = nutils.generate_legacy_vpn_profile( 98 self.dut, self.vpn_params, 99 vpn, self.vpn_server_addresses[vpn.name][2], 100 self.ipsec_server_type[2], 101 self.log_path) 102 vpn_addr = self.vpn_verify_addresses[vpn.name][2] 103 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 104 105 @test_tracker_info(uuid="e67d8c38-92c3-4167-8b6c-a49ef939adce") 106 def legacy_vpn_l2tp_ipsec_rsa_libreswan(self): 107 """ Verify L2TP IPSec RSA VPN connection to 108 libreSwan server 109 """ 110 vpn = VPN_TYPE.L2TP_IPSEC_RSA 111 vpn_profile = nutils.generate_legacy_vpn_profile( 112 self.dut, self.vpn_params, 113 vpn, self.vpn_server_addresses[vpn.name][2], 114 self.ipsec_server_type[2], 115 self.log_path) 116 vpn_addr = self.vpn_verify_addresses[vpn.name][2] 117 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 118 119 @test_tracker_info(uuid="8b3517dc-6a3b-44c2-a85d-bd7b969df3cf") 120 def legacy_vpn_ipsec_xauth_psk_libreswan(self): 121 """ Verify IPSec XAUTH PSK VPN connection to 122 libreSwan server 123 """ 124 vpn = VPN_TYPE.IPSEC_XAUTH_PSK 125 vpn_profile = nutils.generate_legacy_vpn_profile( 126 self.dut, self.vpn_params, 127 vpn, self.vpn_server_addresses[vpn.name][2], 128 self.ipsec_server_type[2], 129 self.log_path) 130 vpn_addr = self.vpn_verify_addresses[vpn.name][2] 131 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 132 133 @test_tracker_info(uuid="abac663d-1d91-4b87-8e94-11c6e44fb07b") 134 def legacy_vpn_ipsec_xauth_rsa_libreswan(self): 135 """ Verify IPSec XAUTH RSA VPN connection to 136 libreSwan server 137 """ 138 vpn = VPN_TYPE.IPSEC_XAUTH_RSA 139 vpn_profile = nutils.generate_legacy_vpn_profile( 140 self.dut, self.vpn_params, 141 vpn, self.vpn_server_addresses[vpn.name][2], 142 self.ipsec_server_type[2], 143 self.log_path) 144 vpn_addr = self.vpn_verify_addresses[vpn.name][2] 145 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 146 147 @test_tracker_info(uuid="84140d24-53c0-4f6c-866f-9d66e04442cc") 148 def test_legacy_vpn_l2tp_ipsec_psk_openswan(self): 149 """ Verify L2TP IPSec PSK VPN connection to 150 openSwan server 151 """ 152 vpn = VPN_TYPE.L2TP_IPSEC_PSK 153 vpn_profile = nutils.generate_legacy_vpn_profile( 154 self.dut, self.vpn_params, 155 vpn, self.vpn_server_addresses[vpn.name][1], 156 self.ipsec_server_type[1], 157 self.log_path) 158 vpn_addr = self.vpn_verify_addresses[vpn.name][1] 159 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 160 161 @test_tracker_info(uuid="f7087592-7eed-465d-bfe3-ed7b6d9d5f9a") 162 def test_legacy_vpn_l2tp_ipsec_rsa_openswan(self): 163 """ Verify L2TP IPSec RSA VPN connection to 164 openSwan server 165 """ 166 vpn = VPN_TYPE.L2TP_IPSEC_RSA 167 vpn_profile = nutils.generate_legacy_vpn_profile( 168 self.dut, self.vpn_params, 169 vpn, self.vpn_server_addresses[vpn.name][1], 170 self.ipsec_server_type[1], 171 self.log_path) 172 vpn_addr = self.vpn_verify_addresses[vpn.name][1] 173 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 174 175 @test_tracker_info(uuid="ed78973b-13ee-4dd4-b998-693ab741c6f8") 176 def test_legacy_vpn_ipsec_xauth_psk_openswan(self): 177 """ Verify IPSec XAUTH PSK VPN connection to 178 openSwan server 179 """ 180 vpn = VPN_TYPE.IPSEC_XAUTH_PSK 181 vpn_profile = nutils.generate_legacy_vpn_profile( 182 self.dut, self.vpn_params, 183 vpn, self.vpn_server_addresses[vpn.name][1], 184 self.ipsec_server_type[1], 185 self.log_path) 186 vpn_addr = self.vpn_verify_addresses[vpn.name][1] 187 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 188 189 @test_tracker_info(uuid="cfd125c4-b64c-4c49-b8e4-fbf05a9be8ec") 190 def test_legacy_vpn_ipsec_xauth_rsa_openswan(self): 191 """ Verify IPSec XAUTH RSA VPN connection to 192 openSwan server 193 """ 194 vpn = VPN_TYPE.IPSEC_XAUTH_RSA 195 vpn_profile = nutils.generate_legacy_vpn_profile( 196 self.dut, self.vpn_params, 197 vpn, self.vpn_server_addresses[vpn.name][1], 198 self.ipsec_server_type[1], 199 self.log_path) 200 vpn_addr = self.vpn_verify_addresses[vpn.name][1] 201 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 202 203 @test_tracker_info(uuid="419370de-0aa1-4a56-8c22-21567fa1cbb7") 204 def test_legacy_vpn_l2tp_ipsec_psk_strongswan(self): 205 """ Verify L2TP IPSec PSk VPN connection to 206 strongSwan server 207 """ 208 vpn = VPN_TYPE.L2TP_IPSEC_PSK 209 vpn_profile = nutils.generate_legacy_vpn_profile( 210 self.dut, self.vpn_params, 211 vpn, self.vpn_server_addresses[vpn.name][0], 212 self.ipsec_server_type[0], 213 self.log_path) 214 vpn_addr = self.vpn_verify_addresses[vpn.name][0] 215 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 216 217 @test_tracker_info(uuid="f7694081-8bd6-4e31-86ec-d538c4ff1f2e") 218 def test_legacy_vpn_l2tp_ipsec_rsa_strongswan(self): 219 """ Verify L2TP IPSec RSA VPN connection to 220 strongSwan server 221 """ 222 vpn = VPN_TYPE.L2TP_IPSEC_RSA 223 vpn_profile = nutils.generate_legacy_vpn_profile( 224 self.dut, self.vpn_params, 225 vpn, self.vpn_server_addresses[vpn.name][0], 226 self.ipsec_server_type[0], 227 self.log_path) 228 vpn_addr = self.vpn_verify_addresses[vpn.name][0] 229 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 230 231 @test_tracker_info(uuid="2f86eb98-1e05-42cb-b6a6-fd90789b6cde") 232 def test_legacy_vpn_ipsec_xauth_psk_strongswan(self): 233 """ Verify IPSec XAUTH PSK connection to 234 strongSwan server 235 """ 236 vpn = VPN_TYPE.IPSEC_XAUTH_PSK 237 vpn_profile = nutils.generate_legacy_vpn_profile( 238 self.dut, self.vpn_params, 239 vpn, self.vpn_server_addresses[vpn.name][0], 240 self.ipsec_server_type[0], 241 self.log_path) 242 vpn_addr = self.vpn_verify_addresses[vpn.name][0] 243 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 244 245 @test_tracker_info(uuid="af0cd7b1-e86c-4327-91b4-e9062758f2cf") 246 def test_legacy_vpn_ipsec_xauth_rsa_strongswan(self): 247 """ Verify IPSec XAUTH RSA connection to 248 strongswan server 249 """ 250 vpn = VPN_TYPE.IPSEC_XAUTH_RSA 251 vpn_profile = nutils.generate_legacy_vpn_profile( 252 self.dut, self.vpn_params, 253 vpn, self.vpn_server_addresses[vpn.name][0], 254 self.ipsec_server_type[0], 255 self.log_path) 256 vpn_addr = self.vpn_verify_addresses[vpn.name][0] 257 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 258 259 @test_tracker_info(uuid="7b970d0a-1c7d-4a5a-b406-4815e190ef26") 260 def test_legacy_vpn_ipsec_hybrid_rsa_strongswan(self): 261 """ Verify IPSec Hybrid RSA connection to 262 strongswan server 263 """ 264 vpn = VPN_TYPE.IPSEC_HYBRID_RSA 265 vpn_profile = nutils.generate_legacy_vpn_profile( 266 self.dut, self.vpn_params, 267 vpn, self.vpn_server_addresses[vpn.name][0], 268 self.ipsec_server_type[0], 269 self.log_path) 270 vpn_addr = self.vpn_verify_addresses[vpn.name][0] 271 nutils.legacy_vpn_connection_test_logic(self.dut, vpn_profile, vpn_addr) 272