1 /* 2 * Copyright (C) 2017 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 */ 16 package com.android.server.wifi; 17 18 import static org.junit.Assert.assertArrayEquals; 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertFalse; 21 import static org.junit.Assert.assertNotNull; 22 import static org.junit.Assert.assertNull; 23 import static org.junit.Assert.assertTrue; 24 import static org.junit.Assume.assumeTrue; 25 import static org.mockito.ArgumentMatchers.anyBoolean; 26 import static org.mockito.ArgumentMatchers.anyByte; 27 import static org.mockito.Matchers.eq; 28 import static org.mockito.Mockito.any; 29 import static org.mockito.Mockito.anyString; 30 import static org.mockito.Mockito.doAnswer; 31 import static org.mockito.Mockito.never; 32 import static org.mockito.Mockito.verify; 33 import static org.mockito.Mockito.when; 34 35 import android.app.test.MockAnswerUtil.AnswerWithArguments; 36 import android.content.Context; 37 import android.hardware.wifi.supplicant.V1_0.ISupplicantNetwork; 38 import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetwork; 39 import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetworkCallback; 40 import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetworkCallback.NetworkRequestEapSimGsmAuthParams; 41 import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetworkCallback.NetworkRequestEapSimUmtsAuthParams; 42 import android.hardware.wifi.supplicant.V1_0.SupplicantStatus; 43 import android.hardware.wifi.supplicant.V1_0.SupplicantStatusCode; 44 import android.net.wifi.WifiConfiguration; 45 import android.net.wifi.WifiEnterpriseConfig; 46 import android.net.wifi.WifiManager; 47 import android.os.RemoteException; 48 import android.text.TextUtils; 49 50 import androidx.test.filters.SmallTest; 51 52 import com.android.modules.utils.build.SdkLevel; 53 import com.android.server.wifi.util.NativeUtil; 54 import com.android.wifi.resources.R; 55 56 import org.junit.Before; 57 import org.junit.Test; 58 import org.mockito.Mock; 59 import org.mockito.MockitoAnnotations; 60 61 import java.util.ArrayList; 62 import java.util.BitSet; 63 import java.util.HashMap; 64 import java.util.Map; 65 import java.util.Random; 66 67 /** 68 * Unit tests for SupplicantStaNetworkHal 69 */ 70 @SmallTest 71 public class SupplicantStaNetworkHalTest extends WifiBaseTest { 72 private static final String IFACE_NAME = "wlan0"; 73 private static final Map<String, String> NETWORK_EXTRAS_VALUES = new HashMap<>(); 74 static { 75 NETWORK_EXTRAS_VALUES.put("key1", "value1"); 76 NETWORK_EXTRAS_VALUES.put("key2", "value2"); 77 } 78 private static final String NETWORK_EXTRAS_SERIALIZED = 79 "%7B%22key1%22%3A%22value1%22%2C%22key2%22%3A%22value2%22%7D"; 80 private static final String ANONYMOUS_IDENTITY = "aaa@bbb.cc.ddd"; 81 82 private SupplicantStaNetworkHal mSupplicantNetwork; 83 private SupplicantStatus mStatusSuccess; 84 private SupplicantStatus mStatusFailure; 85 private android.hardware.wifi.supplicant.V1_4.SupplicantStatus mStatusSuccessV14; 86 private android.hardware.wifi.supplicant.V1_4.SupplicantStatus mStatusFailureV14; 87 @Mock private ISupplicantStaNetwork mISupplicantStaNetworkMock; 88 @Mock 89 private android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork mISupplicantStaNetworkV12; 90 @Mock 91 private android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork mISupplicantStaNetworkV13; 92 @Mock 93 private android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork mISupplicantStaNetworkV14; 94 @Mock private Context mContext; 95 @Mock private WifiMonitor mWifiMonitor; 96 @Mock private WifiGlobals mWifiGlobals; 97 private long mAdvanceKeyMgmtFeatures = 0; 98 99 private SupplicantNetworkVariables mSupplicantVariables; 100 private MockResources mResources; 101 private ISupplicantStaNetworkCallback mISupplicantStaNetworkCallback; 102 private android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetworkCallback 103 mISupplicantStaNetworkCallbackV14; 104 private static final String TEST_DECORATED_IDENTITY_PREFIX = "androidwifi.dev!"; 105 106 enum SupplicantStaNetworkVersion { 107 V1_0, 108 V1_1, 109 V1_2, 110 V1_3, 111 V1_4, 112 } 113 114 /** 115 * Spy used to return the V1_2 ISupplicantStaNetwork mock object to simulate the 1.2 HAL running 116 * on the device. 117 */ 118 private class SupplicantStaNetworkHalSpyV1_2 extends SupplicantStaNetworkHal { SupplicantStaNetworkHalSpyV1_2(ISupplicantStaNetwork iSupplicantStaNetwork, String ifaceName, Context context, WifiMonitor monitor, WifiGlobals wifiGlobals, long advanceKeyMgmtFeatures)119 SupplicantStaNetworkHalSpyV1_2(ISupplicantStaNetwork iSupplicantStaNetwork, 120 String ifaceName, 121 Context context, WifiMonitor monitor, WifiGlobals wifiGlobals, 122 long advanceKeyMgmtFeatures) { 123 super(iSupplicantStaNetwork, ifaceName, context, monitor, wifiGlobals, 124 advanceKeyMgmtFeatures); 125 } 126 127 @Override 128 protected android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork getSupplicantStaNetworkForV1_2Mockable()129 getSupplicantStaNetworkForV1_2Mockable() { 130 return mISupplicantStaNetworkV12; 131 } 132 } 133 134 /** 135 * Spy used to return the V1_3 ISupplicantStaNetwork mock object to simulate the 1.3 HAL running 136 * on the device. 137 */ 138 private class SupplicantStaNetworkHalSpyV1_3 extends SupplicantStaNetworkHalSpyV1_2 { SupplicantStaNetworkHalSpyV1_3(ISupplicantStaNetwork iSupplicantStaNetwork, String ifaceName, Context context, WifiMonitor monitor, WifiGlobals wifiGlobals, long advanceKeyMgmtFeatures)139 SupplicantStaNetworkHalSpyV1_3(ISupplicantStaNetwork iSupplicantStaNetwork, 140 String ifaceName, 141 Context context, WifiMonitor monitor, WifiGlobals wifiGlobals, 142 long advanceKeyMgmtFeatures) { 143 super(iSupplicantStaNetwork, ifaceName, context, monitor, wifiGlobals, 144 advanceKeyMgmtFeatures); 145 } 146 147 @Override 148 protected android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork getSupplicantStaNetworkForV1_3Mockable()149 getSupplicantStaNetworkForV1_3Mockable() { 150 return mISupplicantStaNetworkV13; 151 } 152 } 153 154 /** 155 * Spy used to return the V1_4 ISupplicantStaNetwork mock object to simulate the 1.4 HAL running 156 * on the device. 157 */ 158 private class SupplicantStaNetworkHalSpyV1_4 extends SupplicantStaNetworkHalSpyV1_3 { SupplicantStaNetworkHalSpyV1_4(ISupplicantStaNetwork iSupplicantStaNetwork, String ifaceName, Context context, WifiMonitor monitor, WifiGlobals wifiGlobals, long advanceKeyMgmtFeatures)159 SupplicantStaNetworkHalSpyV1_4(ISupplicantStaNetwork iSupplicantStaNetwork, 160 String ifaceName, 161 Context context, WifiMonitor monitor, WifiGlobals wifiGlobals, 162 long advanceKeyMgmtFeatures) { 163 super(iSupplicantStaNetwork, ifaceName, context, monitor, wifiGlobals, 164 advanceKeyMgmtFeatures); 165 } 166 167 @Override 168 protected android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork getSupplicantStaNetworkForV1_4Mockable()169 getSupplicantStaNetworkForV1_4Mockable() { 170 return mISupplicantStaNetworkV14; 171 } 172 } 173 174 @Before setUp()175 public void setUp() throws Exception { 176 MockitoAnnotations.initMocks(this); 177 mStatusSuccess = createSupplicantStatus(SupplicantStatusCode.SUCCESS); 178 mStatusFailure = createSupplicantStatus(SupplicantStatusCode.FAILURE_UNKNOWN); 179 mStatusSuccessV14 = createSupplicantStatusV1_4( 180 android.hardware.wifi.supplicant.V1_4.SupplicantStatusCode.SUCCESS); 181 mStatusFailureV14 = createSupplicantStatusV1_4( 182 android.hardware.wifi.supplicant.V1_4.SupplicantStatusCode.FAILURE_UNKNOWN); 183 mSupplicantVariables = new SupplicantNetworkVariables(); 184 setupISupplicantNetworkMock(); 185 186 mResources = new MockResources(); 187 when(mContext.getResources()).thenReturn(mResources); 188 when(mWifiGlobals.isWpa3SaeUpgradeOffloadEnabled()).thenReturn(true); 189 190 mAdvanceKeyMgmtFeatures |= WifiManager.WIFI_FEATURE_WPA3_SUITE_B; 191 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_0); 192 } 193 194 /** 195 * Tests the saving of WifiConfiguration to wpa_supplicant. 196 */ 197 @Test testOweNetworkWifiConfigurationSaveLoad()198 public void testOweNetworkWifiConfigurationSaveLoad() throws Exception { 199 // Now expose the V1.2 ISupplicantStaNetwork 200 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_2); 201 202 WifiConfiguration config = WifiConfigurationTestUtil.createOweNetwork(); 203 config.updateIdentifier = "46"; 204 testWifiConfigurationSaveLoad(config); 205 } 206 207 /** 208 * Tests the saving of WifiConfiguration to wpa_supplicant. 209 */ 210 @Test testOpenNetworkWifiConfigurationSaveLoad()211 public void testOpenNetworkWifiConfigurationSaveLoad() throws Exception { 212 WifiConfiguration config = WifiConfigurationTestUtil.createOpenHiddenNetwork(); 213 config.updateIdentifier = "45"; 214 testWifiConfigurationSaveLoad(config); 215 } 216 217 /** 218 * Tests the saving/loading of WifiConfiguration to wpa_supplicant with SAE password. 219 */ 220 @Test testSaePasswordNetworkWifiConfigurationSaveLoad()221 public void testSaePasswordNetworkWifiConfigurationSaveLoad() throws Exception { 222 // Now expose the V1.2 ISupplicantStaNetwork 223 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_2); 224 225 WifiConfiguration config = WifiConfigurationTestUtil.createSaeNetwork(); 226 testWifiConfigurationSaveLoad(config); 227 verify(mISupplicantStaNetworkV12).setSaePassword(any(String.class)); 228 verify(mISupplicantStaNetworkV12, never()) 229 .getSaePassword(any(android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 230 .getSaePasswordCallback.class)); 231 verify(mISupplicantStaNetworkV12, never()) 232 .getPskPassphrase(any(ISupplicantStaNetwork.getPskPassphraseCallback.class)); 233 verify(mISupplicantStaNetworkV12, never()).setPsk(any(byte[].class)); 234 verify(mISupplicantStaNetworkV12, never()) 235 .getPsk(any(ISupplicantStaNetwork.getPskCallback.class)); 236 } 237 238 /** 239 * Tests the saving/loading of WifiConfiguration to wpa_supplicant with psk passphrase. 240 */ 241 @Test testPskPassphraseNetworkWifiConfigurationSaveLoad()242 public void testPskPassphraseNetworkWifiConfigurationSaveLoad() throws Exception { 243 WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); 244 245 // Set the new defaults 246 testWifiConfigurationSaveLoad(config); 247 verify(mISupplicantStaNetworkMock).setPskPassphrase(anyString()); 248 verify(mISupplicantStaNetworkMock) 249 .getPskPassphrase(any(ISupplicantStaNetwork.getPskPassphraseCallback.class)); 250 verify(mISupplicantStaNetworkMock, never()).setPsk(any(byte[].class)); 251 verify(mISupplicantStaNetworkMock, never()) 252 .getPsk(any(ISupplicantStaNetwork.getPskCallback.class)); 253 verify(mISupplicantStaNetworkMock) 254 .setPairwiseCipher(ISupplicantStaNetwork.PairwiseCipherMask.TKIP 255 | ISupplicantStaNetwork.PairwiseCipherMask.CCMP); 256 verify(mISupplicantStaNetworkMock) 257 .setGroupCipher(ISupplicantStaNetwork.GroupCipherMask.WEP40 258 | ISupplicantStaNetwork.GroupCipherMask.WEP104 259 | ISupplicantStaNetwork.GroupCipherMask.TKIP 260 | ISupplicantStaNetwork.GroupCipherMask.CCMP); 261 } 262 263 /** 264 * Tests the saving/loading of WifiConfiguration to wpa_supplicant with raw psk. 265 */ 266 @Test testPskNetworkWifiConfigurationSaveLoad()267 public void testPskNetworkWifiConfigurationSaveLoad() throws Exception { 268 WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); 269 config.preSharedKey = "945ef00c463c2a7c2496376b13263d1531366b46377179a4b17b393687450779"; 270 testWifiConfigurationSaveLoad(config); 271 verify(mISupplicantStaNetworkMock).setPsk(any(byte[].class)); 272 verify(mISupplicantStaNetworkMock) 273 .getPsk(any(ISupplicantStaNetwork.getPskCallback.class)); 274 verify(mISupplicantStaNetworkMock, never()).setPskPassphrase(anyString()); 275 verify(mISupplicantStaNetworkMock) 276 .getPskPassphrase(any(ISupplicantStaNetwork.getPskPassphraseCallback.class)); 277 } 278 279 /** 280 * Tests the saving of WifiConfiguration to wpa_supplicant removes enclosing quotes of psk 281 * passphrase 282 */ 283 @Test testPskNetworkWifiConfigurationSaveRemovesPskQuotes()284 public void testPskNetworkWifiConfigurationSaveRemovesPskQuotes() throws Exception { 285 WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); 286 config.preSharedKey = "\"quoted_psd\""; 287 // Assume that the default params is used for this test. 288 config.getNetworkSelectionStatus().setCandidateSecurityParams( 289 config.getDefaultSecurityParams()); 290 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 291 assertEquals(mSupplicantVariables.pskPassphrase, 292 NativeUtil.removeEnclosingQuotes(config.preSharedKey)); 293 } 294 295 /** 296 * Tests the saving/loading of WifiConfiguration to wpa_supplicant. 297 */ 298 @Test testWepNetworkWifiConfigurationSaveLoad()299 public void testWepNetworkWifiConfigurationSaveLoad() throws Exception { 300 WifiConfiguration config = WifiConfigurationTestUtil.createWepHiddenNetwork(); 301 config.BSSID = " *NOT USED* "; // we want the other bssid! 302 config.getNetworkSelectionStatus().setNetworkSelectionBSSID("34:45:19:09:45:66"); 303 testWifiConfigurationSaveLoad(config); 304 } 305 306 /** 307 * Tests the saving of WifiConfiguration to wpa_supplicant. 308 */ 309 @Test testEapPeapGtcNetworkWifiConfigurationSaveLoad()310 public void testEapPeapGtcNetworkWifiConfigurationSaveLoad() throws Exception { 311 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 312 config.enterpriseConfig = 313 WifiConfigurationTestUtil.createPEAPWifiEnterpriseConfigWithGTCPhase2(); 314 testWifiConfigurationSaveLoad(config); 315 } 316 317 /** 318 * Tests the saving of WifiConfiguration to wpa_supplicant. 319 */ 320 @Test testEapTlsNoneNetworkWifiConfigurationSaveLoad()321 public void testEapTlsNoneNetworkWifiConfigurationSaveLoad() throws Exception { 322 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 323 config.enterpriseConfig = 324 WifiConfigurationTestUtil.createTLSWifiEnterpriseConfigWithNonePhase2(); 325 testWifiConfigurationSaveLoad(config); 326 } 327 328 /** 329 * Tests the saving of WifiConfiguration to wpa_supplicant. 330 */ 331 @Test testEapTlsNoneClientCertNetworkWifiConfigurationSaveLoad()332 public void testEapTlsNoneClientCertNetworkWifiConfigurationSaveLoad() throws Exception { 333 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 334 config.enterpriseConfig = 335 WifiConfigurationTestUtil.createTLSWifiEnterpriseConfigWithNonePhase2(); 336 config.enterpriseConfig.setClientCertificateAlias("test_alias"); 337 testWifiConfigurationSaveLoad(config); 338 } 339 340 /** 341 * Tests the saving of WifiConfiguration to wpa_supplicant. 342 */ 343 @Test testEapTlsNoneClientCertNetworkWithOcspWifiConfigurationSaveLoad()344 public void testEapTlsNoneClientCertNetworkWithOcspWifiConfigurationSaveLoad() 345 throws Exception { 346 // Now expose the V1.3 ISupplicantStaNetwork 347 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_3); 348 349 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 350 config.enterpriseConfig = 351 WifiConfigurationTestUtil.createTLSWifiEnterpriseConfigWithNonePhase2(); 352 config.enterpriseConfig.setClientCertificateAlias("test_alias"); 353 config.enterpriseConfig.setOcsp(WifiEnterpriseConfig.OCSP_REQUIRE_CERT_STATUS); 354 testWifiConfigurationSaveLoad(config); 355 } 356 357 /** 358 * Tests the saving of WifiConfiguration to wpa_supplicant. 359 */ 360 @Test testEapTlsAkaNetworkWifiConfigurationSaveLoad()361 public void testEapTlsAkaNetworkWifiConfigurationSaveLoad() throws Exception { 362 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 363 config.enterpriseConfig = 364 WifiConfigurationTestUtil.createTLSWifiEnterpriseConfigWithAkaPhase2(); 365 testWifiConfigurationSaveLoad(config); 366 } 367 368 /** 369 * Tests the saving/loading of WifiConfiguration to wpa_supplicant with Suite-B-192 370 */ 371 @Test testEapSuiteBRsaNetworkWifiConfigurationSaveLoad()372 public void testEapSuiteBRsaNetworkWifiConfigurationSaveLoad() throws Exception { 373 // Now expose the V1.2 ISupplicantStaNetwork 374 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_2); 375 376 WifiConfiguration config = WifiConfigurationTestUtil.createEapSuiteBNetwork(); 377 config.enableSuiteBCiphers(false, true); 378 379 testWifiConfigurationSaveLoad(config); 380 verify(mISupplicantStaNetworkV12, never()).enableSuiteBEapOpenSslCiphers(); 381 verify(mISupplicantStaNetworkV12).enableTlsSuiteBEapPhase1Param(anyBoolean()); 382 383 verify(mISupplicantStaNetworkV12, never()).setSaePassword(any(String.class)); 384 verify(mISupplicantStaNetworkV12, never()) 385 .getSaePassword(any(android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 386 .getSaePasswordCallback.class)); 387 verify(mISupplicantStaNetworkV12, never()) 388 .getPskPassphrase(any(ISupplicantStaNetwork.getPskPassphraseCallback.class)); 389 verify(mISupplicantStaNetworkV12, never()).setPsk(any(byte[].class)); 390 verify(mISupplicantStaNetworkV12, never()) 391 .getPsk(any(ISupplicantStaNetwork.getPskCallback.class)); 392 } 393 394 /** 395 * Tests the saving/loading of WifiConfiguration to wpa_supplicant with Suite-B-192 396 */ 397 @Test testEapSuiteBEcdsaNetworkWifiConfigurationSaveLoad()398 public void testEapSuiteBEcdsaNetworkWifiConfigurationSaveLoad() throws Exception { 399 // Now expose the V1.2 ISupplicantStaNetwork 400 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_2); 401 402 WifiConfiguration config = WifiConfigurationTestUtil.createEapSuiteBNetwork(); 403 config.enableSuiteBCiphers(true, false); 404 405 testWifiConfigurationSaveLoad(config); 406 verify(mISupplicantStaNetworkV12).enableSuiteBEapOpenSslCiphers(); 407 verify(mISupplicantStaNetworkV12, never()) 408 .enableTlsSuiteBEapPhase1Param(any(boolean.class)); 409 410 verify(mISupplicantStaNetworkV12, never()).setSaePassword(any(String.class)); 411 verify(mISupplicantStaNetworkV12, never()) 412 .getSaePassword(any(android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 413 .getSaePasswordCallback.class)); 414 verify(mISupplicantStaNetworkV12, never()) 415 .getPskPassphrase(any(ISupplicantStaNetwork.getPskPassphraseCallback.class)); 416 verify(mISupplicantStaNetworkV12, never()).setPsk(any(byte[].class)); 417 verify(mISupplicantStaNetworkV12, never()) 418 .getPsk(any(ISupplicantStaNetwork.getPskCallback.class)); 419 } 420 421 /** 422 * Tests the saving/loading of WifiConfiguration with FILS AKM 423 * to wpa_supplicant. 424 */ 425 @Test testTLSWifiEnterpriseConfigWithFilsEapErp()426 public void testTLSWifiEnterpriseConfigWithFilsEapErp() throws Exception { 427 // Now expose the V1.3 ISupplicantStaNetwork 428 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_3); 429 430 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 431 config.enterpriseConfig = 432 WifiConfigurationTestUtil.createTLSWifiEnterpriseConfigWithNonePhase2(); 433 config.enableFils(true, false); 434 config.enterpriseConfig.setFieldValue(WifiEnterpriseConfig.EAP_ERP, "1"); 435 testWifiConfigurationSaveLoad(config); 436 // Check the supplicant variables to ensure that we have added the FILS AKM. 437 assertTrue((mSupplicantVariables.keyMgmtMask & android.hardware.wifi.supplicant.V1_3 438 .ISupplicantStaNetwork.KeyMgmtMask.FILS_SHA256) 439 == android.hardware.wifi.supplicant.V1_3 440 .ISupplicantStaNetwork.KeyMgmtMask.FILS_SHA256); 441 verify(mISupplicantStaNetworkV13).setEapErp(eq(true)); 442 } 443 444 /** 445 * Tests the saving of WifiConfiguration to wpa_supplicant. 446 */ 447 @Test testWapiPskNetworkWifiConfigurationSaveLoad()448 public void testWapiPskNetworkWifiConfigurationSaveLoad() throws Exception { 449 // Now expose the V1.3 ISupplicantStaNetwork 450 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_3); 451 452 WifiConfiguration config = WifiConfigurationTestUtil.createWapiPskNetwork(); 453 testWifiConfigurationSaveLoad(config); 454 } 455 456 /** 457 * Tests the saving of WifiConfiguration to wpa_supplicant. 458 */ 459 @Test testWapiPskHexNetworkWifiConfigurationSaveLoad()460 public void testWapiPskHexNetworkWifiConfigurationSaveLoad() throws Exception { 461 // Now expose the V1.3 ISupplicantStaNetwork 462 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_3); 463 464 WifiConfiguration config = WifiConfigurationTestUtil.createWapiPskNetwork(); 465 466 config.preSharedKey = 467 "1234567890abcdef0" 468 + "1234567890abcdef0"; 469 // WAPI should accept a hex bytes whose length is not exact 32. 470 testWifiConfigurationSaveLoad(config); 471 } 472 473 /** 474 * Tests the saving of WifiConfiguration to wpa_supplicant. 475 */ 476 @Test testWapiCertNetworkWifiConfigurationSaveLoad()477 public void testWapiCertNetworkWifiConfigurationSaveLoad() throws Exception { 478 // Now expose the V1.3 ISupplicantStaNetwork 479 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_3); 480 481 WifiConfiguration config = WifiConfigurationTestUtil.createWapiCertNetwork(); 482 testWifiConfigurationSaveLoad(config); 483 } 484 485 /** 486 * Tests the failure to save ssid. 487 */ 488 @Test testSsidSaveFailure()489 public void testSsidSaveFailure() throws Exception { 490 WifiConfiguration config = WifiConfigurationTestUtil.createWepHiddenNetwork(); 491 492 doAnswer(new AnswerWithArguments() { 493 public SupplicantStatus answer(ArrayList<Byte> ssid) throws RemoteException { 494 return mStatusFailure; 495 } 496 }).when(mISupplicantStaNetworkMock).setSsid(any(ArrayList.class)); 497 498 // Assume that the default params is used for this test. 499 config.getNetworkSelectionStatus().setCandidateSecurityParams( 500 config.getDefaultSecurityParams()); 501 assertFalse(mSupplicantNetwork.saveWifiConfiguration(config)); 502 } 503 504 /** 505 * Tests the failure to save invalid bssid (less than 6 bytes in the 506 * {@link WifiConfiguration#BSSID} being saved). 507 */ 508 @Test testInvalidBssidSaveFailure()509 public void testInvalidBssidSaveFailure() throws Exception { 510 WifiConfiguration config = WifiConfigurationTestUtil.createWepHiddenNetwork(); 511 config.getNetworkSelectionStatus().setNetworkSelectionBSSID("45:34:23:12"); 512 // Assume that the default params is used for this test. 513 config.getNetworkSelectionStatus().setCandidateSecurityParams( 514 config.getDefaultSecurityParams()); 515 try { 516 assertFalse(mSupplicantNetwork.saveWifiConfiguration(config)); 517 } catch (IllegalArgumentException e) { 518 return; 519 } 520 assertTrue(false); 521 } 522 523 /** 524 * Tests the parsing of GSM auth response parameters. 525 */ 526 @Test testSendNetworkEapSimGsmAuthResponseWith2KcSresPair()527 public void testSendNetworkEapSimGsmAuthResponseWith2KcSresPair() throws Exception { 528 final byte[] kc = new byte[]{0x45, 0x45, 0x32, 0x34, 0x45, 0x10, 0x34, 0x12}; 529 final byte[] sres = new byte[]{0x12, 0x10, 0x32, 0x23}; 530 // Send 2 kc/sres pair for this request. 531 String paramsStr = ":" + NativeUtil.hexStringFromByteArray(kc) 532 + ":" + NativeUtil.hexStringFromByteArray(sres) 533 + ":" + NativeUtil.hexStringFromByteArray(kc) 534 + ":" + NativeUtil.hexStringFromByteArray(sres); 535 536 doAnswer(new AnswerWithArguments() { 537 public SupplicantStatus answer( 538 ArrayList<ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams> params) 539 throws RemoteException { 540 assertEquals(2, params.size()); 541 assertArrayEquals(kc, params.get(0).kc); 542 assertArrayEquals(sres, params.get(0).sres); 543 assertArrayEquals(kc, params.get(1).kc); 544 assertArrayEquals(sres, params.get(1).sres); 545 return mStatusSuccess; 546 } 547 }).when(mISupplicantStaNetworkMock).sendNetworkEapSimGsmAuthResponse(any(ArrayList.class)); 548 549 assertTrue(mSupplicantNetwork.sendNetworkEapSimGsmAuthResponse(paramsStr)); 550 } 551 552 /** 553 * Tests the parsing of GSM auth response parameters. 554 */ 555 @Test testSendNetworkEapSimGsmAuthResponseWith3KcSresPair()556 public void testSendNetworkEapSimGsmAuthResponseWith3KcSresPair() throws Exception { 557 final byte[] kc1 = new byte[]{0x45, 0x45, 0x32, 0x34, 0x45, 0x10, 0x34, 0x12}; 558 final byte[] sres1 = new byte[]{0x12, 0x10, 0x32, 0x23}; 559 final byte[] kc2 = new byte[]{0x45, 0x34, 0x12, 0x34, 0x45, 0x10, 0x34, 0x12}; 560 final byte[] sres2 = new byte[]{0x12, 0x23, 0x12, 0x23}; 561 final byte[] kc3 = new byte[]{0x25, 0x34, 0x12, 0x14, 0x45, 0x10, 0x34, 0x12}; 562 final byte[] sres3 = new byte[]{0x42, 0x23, 0x22, 0x23}; 563 // Send 3 kc/sres pair for this request. 564 String paramsStr = ":" + NativeUtil.hexStringFromByteArray(kc1) 565 + ":" + NativeUtil.hexStringFromByteArray(sres1) 566 + ":" + NativeUtil.hexStringFromByteArray(kc2) 567 + ":" + NativeUtil.hexStringFromByteArray(sres2) 568 + ":" + NativeUtil.hexStringFromByteArray(kc3) 569 + ":" + NativeUtil.hexStringFromByteArray(sres3); 570 571 doAnswer(new AnswerWithArguments() { 572 public SupplicantStatus answer( 573 ArrayList<ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams> params) 574 throws RemoteException { 575 assertEquals(3, params.size()); 576 assertArrayEquals(kc1, params.get(0).kc); 577 assertArrayEquals(sres1, params.get(0).sres); 578 assertArrayEquals(kc2, params.get(1).kc); 579 assertArrayEquals(sres2, params.get(1).sres); 580 assertArrayEquals(kc3, params.get(2).kc); 581 assertArrayEquals(sres3, params.get(2).sres); 582 return mStatusSuccess; 583 } 584 }).when(mISupplicantStaNetworkMock).sendNetworkEapSimGsmAuthResponse(any(ArrayList.class)); 585 586 assertTrue(mSupplicantNetwork.sendNetworkEapSimGsmAuthResponse(paramsStr)); 587 } 588 589 /** 590 * Tests the parsing of invalid GSM auth response parameters (invalid kc & sres lengths). 591 */ 592 @Test testSendInvalidKcSresLenNetworkEapSimGsmAuthResponse()593 public void testSendInvalidKcSresLenNetworkEapSimGsmAuthResponse() throws Exception { 594 final byte[] kc1 = new byte[]{0x45, 0x45, 0x32, 0x34, 0x45, 0x10, 0x34}; 595 final byte[] sres1 = new byte[]{0x12, 0x10, 0x23}; 596 final byte[] kc2 = new byte[]{0x45, 0x34, 0x12, 0x34, 0x45, 0x10, 0x34, 0x12}; 597 final byte[] sres2 = new byte[]{0x12, 0x23, 0x12, 0x23}; 598 // Send 2 kc/sres pair for this request. 599 String paramsStr = ":" + NativeUtil.hexStringFromByteArray(kc1) 600 + ":" + NativeUtil.hexStringFromByteArray(sres1) 601 + ":" + NativeUtil.hexStringFromByteArray(kc2) 602 + ":" + NativeUtil.hexStringFromByteArray(sres2); 603 604 doAnswer(new AnswerWithArguments() { 605 public SupplicantStatus answer( 606 ArrayList<ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams> params) 607 throws RemoteException { 608 return mStatusSuccess; 609 } 610 }).when(mISupplicantStaNetworkMock).sendNetworkEapSimGsmAuthResponse(any(ArrayList.class)); 611 612 assertFalse(mSupplicantNetwork.sendNetworkEapSimGsmAuthResponse(paramsStr)); 613 } 614 615 /** 616 * Tests the parsing of invalid GSM auth response parameters (invalid number of kc/sres pairs). 617 */ 618 @Test testSendInvalidKcSresPairNumNetworkEapSimGsmAuthResponse()619 public void testSendInvalidKcSresPairNumNetworkEapSimGsmAuthResponse() throws Exception { 620 final byte[] kc = new byte[]{0x45, 0x34, 0x12, 0x34, 0x45, 0x10, 0x34, 0x12}; 621 final byte[] sres = new byte[]{0x12, 0x23, 0x12, 0x23}; 622 // Send 1 kc/sres pair for this request. 623 String paramsStr = ":" + NativeUtil.hexStringFromByteArray(kc) 624 + ":" + NativeUtil.hexStringFromByteArray(sres); 625 626 doAnswer(new AnswerWithArguments() { 627 public SupplicantStatus answer( 628 ArrayList<ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams> params) 629 throws RemoteException { 630 return mStatusSuccess; 631 } 632 }).when(mISupplicantStaNetworkMock).sendNetworkEapSimGsmAuthResponse(any(ArrayList.class)); 633 634 assertFalse(mSupplicantNetwork.sendNetworkEapSimGsmAuthResponse(paramsStr)); 635 } 636 637 /** 638 * Tests the parsing of UMTS auth response parameters. 639 */ 640 @Test testSendNetworkEapSimUmtsAuthResponse()641 public void testSendNetworkEapSimUmtsAuthResponse() throws Exception { 642 final byte[] ik = new byte[]{0x45, 0x45, 0x32, 0x34, 0x45, 0x10, 0x34, 0x12, 0x23, 0x34, 643 0x33, 0x23, 0x34, 0x10, 0x40, 0x34}; 644 final byte[] ck = new byte[]{0x12, 0x10, 0x32, 0x23, 0x45, 0x10, 0x34, 0x12, 0x23, 0x34, 645 0x33, 0x23, 0x34, 0x10, 0x40, 0x34}; 646 final byte[] res = new byte[]{0x12, 0x10, 0x32, 0x23, 0x45, 0x10, 0x34, 0x12, 0x23, 0x34}; 647 String paramsStr = ":" + NativeUtil.hexStringFromByteArray(ik) 648 + ":" + NativeUtil.hexStringFromByteArray(ck) 649 + ":" + NativeUtil.hexStringFromByteArray(res); 650 651 doAnswer(new AnswerWithArguments() { 652 public SupplicantStatus answer( 653 ISupplicantStaNetwork.NetworkResponseEapSimUmtsAuthParams params) 654 throws RemoteException { 655 assertArrayEquals(ik, params.ik); 656 assertArrayEquals(ck, params.ck); 657 // Convert to arraylist before comparison. 658 ArrayList<Byte> resList = new ArrayList<>(); 659 for (byte b : res) { 660 resList.add(b); 661 } 662 assertEquals(resList, params.res); 663 return mStatusSuccess; 664 } 665 }).when(mISupplicantStaNetworkMock).sendNetworkEapSimUmtsAuthResponse( 666 any(ISupplicantStaNetwork.NetworkResponseEapSimUmtsAuthParams.class)); 667 668 assertTrue(mSupplicantNetwork.sendNetworkEapSimUmtsAuthResponse(paramsStr)); 669 } 670 671 /** 672 * Tests the parsing of invalid UMTS auth response parameters (invalid ik, ck lengths). 673 */ 674 @Test testSendInvalidNetworkEapSimUmtsAuthResponse()675 public void testSendInvalidNetworkEapSimUmtsAuthResponse() throws Exception { 676 final byte[] ik = new byte[]{0x45, 0x45, 0x32, 0x34, 0x45, 0x10, 0x34, 0x12}; 677 final byte[] ck = new byte[]{0x12, 0x10, 0x32, 0x23, 0x45, 0x10, 0x34, 0x12, 0x23, 0x34, 678 0x33, 0x23, 0x34, 0x10, 0x40}; 679 final byte[] res = new byte[]{0x12, 0x10, 0x32, 0x23, 0x45, 0x10, 0x34, 0x12, 0x23, 0x34}; 680 String paramsStr = ":" + NativeUtil.hexStringFromByteArray(ik) 681 + ":" + NativeUtil.hexStringFromByteArray(ck) 682 + ":" + NativeUtil.hexStringFromByteArray(res); 683 684 doAnswer(new AnswerWithArguments() { 685 public SupplicantStatus answer( 686 ISupplicantStaNetwork.NetworkResponseEapSimUmtsAuthParams params) 687 throws RemoteException { 688 return mStatusSuccess; 689 } 690 }).when(mISupplicantStaNetworkMock).sendNetworkEapSimUmtsAuthResponse( 691 any(ISupplicantStaNetwork.NetworkResponseEapSimUmtsAuthParams.class)); 692 693 assertFalse(mSupplicantNetwork.sendNetworkEapSimUmtsAuthResponse(paramsStr)); 694 } 695 696 /** 697 * Tests the parsing of UMTS auts response parameters. 698 */ 699 @Test testSendNetworkEapSimUmtsAutsResponse()700 public void testSendNetworkEapSimUmtsAutsResponse() throws Exception { 701 final byte[] auts = new byte[]{0x45, 0x45, 0x32, 0x34, 0x45, 0x10, 0x34, 0x12, 0x23, 0x34, 702 0x33, 0x23, 0x34, 0x10}; 703 String paramsStr = ":" + NativeUtil.hexStringFromByteArray(auts); 704 705 doAnswer(new AnswerWithArguments() { 706 public SupplicantStatus answer(byte[] params) 707 throws RemoteException { 708 assertArrayEquals(auts, params); 709 return mStatusSuccess; 710 } 711 }).when(mISupplicantStaNetworkMock).sendNetworkEapSimUmtsAutsResponse(any(byte[].class)); 712 713 assertTrue(mSupplicantNetwork.sendNetworkEapSimUmtsAutsResponse(paramsStr)); 714 } 715 716 /** 717 * Tests the parsing of invalid UMTS auts response parameters (invalid auts length). 718 */ 719 @Test testSendInvalidNetworkEapSimUmtsAutsResponse()720 public void testSendInvalidNetworkEapSimUmtsAutsResponse() throws Exception { 721 final byte[] auts = new byte[]{0x45, 0x45, 0x32, 0x34, 0x45, 0x10, 0x34, 0x12, 0x23}; 722 String paramsStr = ":" + NativeUtil.hexStringFromByteArray(auts); 723 724 doAnswer(new AnswerWithArguments() { 725 public SupplicantStatus answer(byte[] params) 726 throws RemoteException { 727 assertArrayEquals(auts, params); 728 return mStatusSuccess; 729 } 730 }).when(mISupplicantStaNetworkMock).sendNetworkEapSimUmtsAutsResponse(any(byte[].class)); 731 732 assertFalse(mSupplicantNetwork.sendNetworkEapSimUmtsAutsResponse(paramsStr)); 733 } 734 735 /** 736 * Tests the parsing of identity string. 737 */ 738 @Test testSendNetworkEapIdentityResponse()739 public void testSendNetworkEapIdentityResponse() throws Exception { 740 final String identityStr = "test@test.com"; 741 final String encryptedIdentityStr = "test2@test.com"; 742 doAnswer(new AnswerWithArguments() { 743 public SupplicantStatus answer(ArrayList<Byte> identity) 744 throws RemoteException { 745 assertEquals(identityStr, NativeUtil.stringFromByteArrayList(identity)); 746 return mStatusSuccess; 747 } 748 }).when(mISupplicantStaNetworkMock).sendNetworkEapIdentityResponse(any(ArrayList.class)); 749 750 assertTrue(mSupplicantNetwork.sendNetworkEapIdentityResponse(identityStr, 751 encryptedIdentityStr)); 752 verify(mISupplicantStaNetworkV12, never()).sendNetworkEapIdentityResponse_1_1( 753 any(ArrayList.class), any(ArrayList.class)); 754 755 // Now expose the V1.2 ISupplicantStaNetwork 756 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_2); 757 doAnswer(new AnswerWithArguments() { 758 public SupplicantStatus answer(ArrayList<Byte> identity, 759 ArrayList<Byte> encryptedIdentity) 760 throws RemoteException { 761 assertEquals(identityStr, NativeUtil.stringFromByteArrayList(identity)); 762 assertEquals(encryptedIdentityStr, 763 NativeUtil.stringFromByteArrayList(encryptedIdentity)); 764 return mStatusSuccess; 765 } 766 }).when(mISupplicantStaNetworkV12).sendNetworkEapIdentityResponse_1_1(any(ArrayList.class), 767 any(ArrayList.class)); 768 assertTrue(mSupplicantNetwork.sendNetworkEapIdentityResponse(identityStr, 769 encryptedIdentityStr)); 770 } 771 772 /** 773 * Tests the addition of FT flags when the device supports it. 774 */ 775 @Test testAddFtPskFlags()776 public void testAddFtPskFlags() throws Exception { 777 mResources.setBoolean(R.bool.config_wifi_fast_bss_transition_enabled, true); 778 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_0); 779 780 WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); 781 // Assume that the default params is used for this test. 782 config.getNetworkSelectionStatus().setCandidateSecurityParams( 783 config.getDefaultSecurityParams()); 784 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 785 786 // Check the supplicant variables to ensure that we have added the FT flags. 787 assertTrue((mSupplicantVariables.keyMgmtMask & ISupplicantStaNetwork.KeyMgmtMask.FT_PSK) 788 == ISupplicantStaNetwork.KeyMgmtMask.FT_PSK); 789 790 WifiConfiguration loadConfig = new WifiConfiguration(); 791 Map<String, String> networkExtras = new HashMap<>(); 792 assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 793 // The FT flags should be stripped out when reading it back. 794 WifiConfigurationTestUtil.assertConfigurationEqualForSupplicant(config, loadConfig); 795 } 796 797 /** 798 * Tests the addition of FT flags when the device supports it. 799 */ 800 @Test testAddFtEapFlags()801 public void testAddFtEapFlags() throws Exception { 802 mResources.setBoolean(R.bool.config_wifi_fast_bss_transition_enabled, true); 803 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_0); 804 805 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 806 // Assume that the default params is used for this test. 807 config.getNetworkSelectionStatus().setCandidateSecurityParams( 808 config.getDefaultSecurityParams()); 809 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 810 811 // Check the supplicant variables to ensure that we have added the FT flags. 812 assertTrue((mSupplicantVariables.keyMgmtMask & ISupplicantStaNetwork.KeyMgmtMask.FT_EAP) 813 == ISupplicantStaNetwork.KeyMgmtMask.FT_EAP); 814 815 WifiConfiguration loadConfig = new WifiConfiguration(); 816 Map<String, String> networkExtras = new HashMap<>(); 817 assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 818 // The FT flags should be stripped out when reading it back. 819 WifiConfigurationTestUtil.assertConfigurationEqualForSupplicant(config, loadConfig); 820 } 821 822 /** 823 * Tests the addition of SHA256 flags (WPA_PSK_SHA256) 824 */ 825 @Test testAddPskSha256Flags()826 public void testAddPskSha256Flags() throws Exception { 827 WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); 828 // Now expose the V1.2 ISupplicantStaNetwork 829 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_2); 830 // Assume that the default params is used for this test. 831 config.getNetworkSelectionStatus().setCandidateSecurityParams( 832 config.getDefaultSecurityParams()); 833 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 834 835 // Check the supplicant variables to ensure that we have added the SHA256 flags. 836 assertTrue((mSupplicantVariables.keyMgmtMask 837 & android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork.KeyMgmtMask 838 .WPA_PSK_SHA256) == android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 839 .KeyMgmtMask.WPA_PSK_SHA256); 840 841 WifiConfiguration loadConfig = new WifiConfiguration(); 842 Map<String, String> networkExtras = new HashMap<>(); 843 assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 844 // The SHA256 flags should be stripped out when reading it back. 845 WifiConfigurationTestUtil.assertConfigurationEqualForSupplicant(config, loadConfig); 846 } 847 848 /** 849 * Tests the addition of SHA256 flags (WPA_EAP_SHA256) 850 */ 851 @Test testAddEapSha256Flags()852 public void testAddEapSha256Flags() throws Exception { 853 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 854 // Now expose the V1.2 ISupplicantStaNetwork 855 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_2); 856 // Assume that the default params is used for this test. 857 config.getNetworkSelectionStatus().setCandidateSecurityParams( 858 config.getDefaultSecurityParams()); 859 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 860 861 // Check the supplicant variables to ensure that we have added the SHA256 flags. 862 assertTrue((mSupplicantVariables.keyMgmtMask 863 & android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork.KeyMgmtMask 864 .WPA_EAP_SHA256) == android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 865 .KeyMgmtMask.WPA_EAP_SHA256); 866 867 WifiConfiguration loadConfig = new WifiConfiguration(); 868 Map<String, String> networkExtras = new HashMap<>(); 869 assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 870 // The SHA256 flags should be stripped out when reading it back. 871 WifiConfigurationTestUtil.assertConfigurationEqualForSupplicant(config, loadConfig); 872 } 873 874 /** 875 * Tests the addition of SHA256 flags (WPA_PSK_SHA256) is ignored on HAL v1.1 or lower 876 */ 877 @Test testAddPskSha256FlagsHal1_1OrLower()878 public void testAddPskSha256FlagsHal1_1OrLower() throws Exception { 879 WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); 880 // Assume that the default params is used for this test. 881 config.getNetworkSelectionStatus().setCandidateSecurityParams( 882 config.getDefaultSecurityParams()); 883 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 884 885 // Check the supplicant variables to ensure that we have NOT added the SHA256 flags. 886 assertFalse((mSupplicantVariables.keyMgmtMask 887 & android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork.KeyMgmtMask 888 .WPA_PSK_SHA256) == android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 889 .KeyMgmtMask.WPA_PSK_SHA256); 890 } 891 892 /** 893 * Tests the addition of SHA256 flags (WPA_EAP_SHA256) is ignored on HAL v1.1 or lower 894 */ 895 @Test testAddEapSha256FlagsHal1_1OrLower()896 public void testAddEapSha256FlagsHal1_1OrLower() throws Exception { 897 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 898 // Assume that the default params is used for this test. 899 config.getNetworkSelectionStatus().setCandidateSecurityParams( 900 config.getDefaultSecurityParams()); 901 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 902 903 // Check the supplicant variables to ensure that we have NOT added the SHA256 flags. 904 assertFalse((mSupplicantVariables.keyMgmtMask 905 & android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork.KeyMgmtMask 906 .WPA_EAP_SHA256) == android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 907 .KeyMgmtMask.WPA_EAP_SHA256); 908 } 909 910 /** 911 * Tests OCSP status is ignored on HAL v1.2 or lower 912 */ 913 @Test testOcspStatusHal1_2OrLower()914 public void testOcspStatusHal1_2OrLower() throws Exception { 915 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 916 config.enterpriseConfig = 917 WifiConfigurationTestUtil.createTLSWifiEnterpriseConfigWithNonePhase2(); 918 config.enterpriseConfig.setClientCertificateAlias("test_alias"); 919 config.enterpriseConfig.setOcsp(WifiEnterpriseConfig.OCSP_REQUIRE_CERT_STATUS); 920 921 // Assume that the default params is used for this test. 922 config.getNetworkSelectionStatus().setCandidateSecurityParams( 923 config.getDefaultSecurityParams()); 924 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 925 926 // Check the supplicant variables to ensure that we have NOT change the OCSP status. 927 assertEquals(WifiEnterpriseConfig.OCSP_NONE, mSupplicantVariables.ocsp); 928 } 929 930 /** 931 * Tests the addition of multiple AKM when the device supports it. 932 */ 933 @Test testAddPskSaeAkmWhenAutoUpgradeOffloadIsSupported()934 public void testAddPskSaeAkmWhenAutoUpgradeOffloadIsSupported() throws Exception { 935 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_2); 936 937 WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); 938 config.getNetworkSelectionStatus().setCandidateSecurityParams( 939 config.getDefaultSecurityParams()); 940 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 941 942 // Check the supplicant variables to ensure that we have added the FT flags. 943 assertEquals(ISupplicantStaNetwork.KeyMgmtMask.WPA_PSK, 944 (mSupplicantVariables.keyMgmtMask & ISupplicantStaNetwork.KeyMgmtMask.WPA_PSK)); 945 assertEquals(android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork.KeyMgmtMask.SAE, 946 (mSupplicantVariables.keyMgmtMask & android.hardware.wifi.supplicant.V1_2 947 .ISupplicantStaNetwork.KeyMgmtMask.SAE)); 948 949 WifiConfiguration loadConfig = new WifiConfiguration(); 950 Map<String, String> networkExtras = new HashMap<>(); 951 assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 952 // The additional SAE AMK should be stripped out when reading it back. 953 WifiConfigurationTestUtil.assertConfigurationEqualForSupplicant(config, loadConfig); 954 } 955 956 /** 957 * Tests the addition of multiple AKM when the device does not support it. 958 */ 959 @Test testAddPskSaeAkmWhenAutoUpgradeOffloadIsNotSupported()960 public void testAddPskSaeAkmWhenAutoUpgradeOffloadIsNotSupported() throws Exception { 961 when(mWifiGlobals.isWpa3SaeUpgradeOffloadEnabled()).thenReturn(false); 962 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_2); 963 964 WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); 965 config.getNetworkSelectionStatus().setCandidateSecurityParams( 966 config.getDefaultSecurityParams()); 967 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 968 969 // Check the supplicant variables to ensure that we have added the FT flags. 970 assertEquals(ISupplicantStaNetwork.KeyMgmtMask.WPA_PSK, 971 (mSupplicantVariables.keyMgmtMask & ISupplicantStaNetwork.KeyMgmtMask.WPA_PSK)); 972 assertEquals(0, 973 (mSupplicantVariables.keyMgmtMask & android.hardware.wifi.supplicant.V1_2 974 .ISupplicantStaNetwork.KeyMgmtMask.SAE)); 975 976 WifiConfiguration loadConfig = new WifiConfiguration(); 977 Map<String, String> networkExtras = new HashMap<>(); 978 assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 979 WifiConfigurationTestUtil.assertConfigurationEqualForSupplicant(config, loadConfig); 980 } 981 982 /** 983 * Tests the retrieval of WPS NFC token. 984 */ 985 @Test testGetWpsNfcConfigurationToken()986 public void testGetWpsNfcConfigurationToken() throws Exception { 987 final ArrayList<Byte> token = new ArrayList<>(); 988 token.add(Byte.valueOf((byte) 0x45)); 989 token.add(Byte.valueOf((byte) 0x34)); 990 991 doAnswer(new AnswerWithArguments() { 992 public void answer(ISupplicantStaNetwork.getWpsNfcConfigurationTokenCallback cb) 993 throws RemoteException { 994 cb.onValues(mStatusSuccess, token); 995 } 996 }).when(mISupplicantStaNetworkMock) 997 .getWpsNfcConfigurationToken( 998 any(ISupplicantStaNetwork.getWpsNfcConfigurationTokenCallback.class)); 999 1000 assertEquals("4534", mSupplicantNetwork.getWpsNfcConfigurationToken()); 1001 } 1002 1003 /** 1004 * Tests that callback registration failure triggers a failure in saving network config. 1005 */ 1006 @Test testSaveFailureDueToCallbackReg()1007 public void testSaveFailureDueToCallbackReg() throws Exception { 1008 when(mISupplicantStaNetworkMock.registerCallback(any(ISupplicantStaNetworkCallback.class))) 1009 .thenReturn(mStatusFailure); 1010 WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); 1011 // Assume that the default params is used for this test. 1012 config.getNetworkSelectionStatus().setCandidateSecurityParams( 1013 config.getDefaultSecurityParams()); 1014 assertFalse(mSupplicantNetwork.saveWifiConfiguration(config)); 1015 } 1016 1017 /** 1018 * Tests that callback registration failure triggers a failure in saving network config. 1019 */ 1020 @Test testSaveFailureDueToCallbackRegV1_4()1021 public void testSaveFailureDueToCallbackRegV1_4() throws Exception { 1022 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_4); 1023 when(mISupplicantStaNetworkV14.registerCallback_1_4(any( 1024 android.hardware.wifi.supplicant.V1_4 1025 .ISupplicantStaNetworkCallback.class))) 1026 .thenReturn(mStatusFailureV14); 1027 WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); 1028 // Assume that the default params is used for this test. 1029 config.getNetworkSelectionStatus().setCandidateSecurityParams( 1030 config.getDefaultSecurityParams()); 1031 assertFalse(mSupplicantNetwork.saveWifiConfiguration(config)); 1032 } 1033 1034 /** 1035 * Tests the network gsm auth callback. 1036 */ 1037 @Test testNetworkEapGsmAuthCallback()1038 public void testNetworkEapGsmAuthCallback() throws Exception { 1039 WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); 1040 // Assume that the default params is used for this test. 1041 config.getNetworkSelectionStatus().setCandidateSecurityParams( 1042 config.getDefaultSecurityParams()); 1043 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 1044 assertNotNull(mISupplicantStaNetworkCallback); 1045 1046 // Now trigger eap gsm callback and ensure that the event is broadcast via WifiMonitor. 1047 NetworkRequestEapSimGsmAuthParams params = new NetworkRequestEapSimGsmAuthParams(); 1048 Random random = new Random(); 1049 byte[] rand1 = new byte[16]; 1050 byte[] rand2 = new byte[16]; 1051 byte[] rand3 = new byte[16]; 1052 random.nextBytes(rand1); 1053 random.nextBytes(rand2); 1054 random.nextBytes(rand3); 1055 params.rands.add(rand1); 1056 params.rands.add(rand2); 1057 params.rands.add(rand3); 1058 1059 String[] expectedRands = { 1060 NativeUtil.hexStringFromByteArray(rand1), NativeUtil.hexStringFromByteArray(rand2), 1061 NativeUtil.hexStringFromByteArray(rand3) 1062 }; 1063 1064 mISupplicantStaNetworkCallback.onNetworkEapSimGsmAuthRequest(params); 1065 verify(mWifiMonitor).broadcastNetworkGsmAuthRequestEvent( 1066 eq(IFACE_NAME), eq(config.networkId), eq(config.SSID), eq(expectedRands)); 1067 } 1068 1069 /** 1070 * Tests the network umts auth callback. 1071 */ 1072 @Test testNetworkEapUmtsAuthCallback()1073 public void testNetworkEapUmtsAuthCallback() throws Exception { 1074 WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); 1075 // Assume that the default params is used for this test. 1076 config.getNetworkSelectionStatus().setCandidateSecurityParams( 1077 config.getDefaultSecurityParams()); 1078 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 1079 assertNotNull(mISupplicantStaNetworkCallback); 1080 1081 // Now trigger eap gsm callback and ensure that the event is broadcast via WifiMonitor. 1082 NetworkRequestEapSimUmtsAuthParams params = new NetworkRequestEapSimUmtsAuthParams(); 1083 Random random = new Random(); 1084 random.nextBytes(params.autn); 1085 random.nextBytes(params.rand); 1086 1087 String[] expectedRands = { 1088 NativeUtil.hexStringFromByteArray(params.rand), 1089 NativeUtil.hexStringFromByteArray(params.autn) 1090 }; 1091 1092 mISupplicantStaNetworkCallback.onNetworkEapSimUmtsAuthRequest(params); 1093 verify(mWifiMonitor).broadcastNetworkUmtsAuthRequestEvent( 1094 eq(IFACE_NAME), eq(config.networkId), eq(config.SSID), eq(expectedRands)); 1095 } 1096 1097 /** 1098 * Tests the network identity callback. 1099 */ 1100 @Test testNetworkIdentityCallback()1101 public void testNetworkIdentityCallback() throws Exception { 1102 WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); 1103 // Assume that the default params is used for this test. 1104 config.getNetworkSelectionStatus().setCandidateSecurityParams( 1105 config.getDefaultSecurityParams()); 1106 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 1107 assertNotNull(mISupplicantStaNetworkCallback); 1108 1109 // Now trigger identity request callback and ensure that the event is broadcast via 1110 // WifiMonitor. 1111 mISupplicantStaNetworkCallback.onNetworkEapIdentityRequest(); 1112 verify(mWifiMonitor).broadcastNetworkIdentityRequestEvent( 1113 eq(IFACE_NAME), eq(config.networkId), eq(config.SSID)); 1114 } 1115 testWifiConfigurationSaveLoad(WifiConfiguration config)1116 private void testWifiConfigurationSaveLoad(WifiConfiguration config) { 1117 if (mSupplicantNetwork.getSupplicantStaNetworkForV1_2Mockable() == null) { 1118 // Clear unsupported settings in HAL v1.0 1119 config.allowedPairwiseCiphers.clear(WifiConfiguration.PairwiseCipher.GCMP_256); 1120 config.allowedGroupCiphers.clear(WifiConfiguration.GroupCipher.GCMP_256); 1121 } 1122 if (mSupplicantNetwork.getSupplicantStaNetworkForV1_3Mockable() == null) { 1123 // Clear unsupported settings in HAL v1.0 1124 config.allowedPairwiseCiphers.clear(WifiConfiguration.PairwiseCipher.SMS4); 1125 config.allowedGroupCiphers.clear(WifiConfiguration.GroupCipher.SMS4); 1126 } 1127 if (mSupplicantNetwork.getSupplicantStaNetworkForV1_4Mockable() == null) { 1128 // Clear unsupported settings in HAL v1.0 1129 config.allowedPairwiseCiphers.clear(WifiConfiguration.PairwiseCipher.GCMP_128); 1130 config.allowedGroupCiphers.clear(WifiConfiguration.GroupCipher.GCMP_128); 1131 } 1132 // Assume that the default params is used for this test. 1133 config.getNetworkSelectionStatus().setCandidateSecurityParams( 1134 config.getDefaultSecurityParams()); 1135 // Save the configuration using the default supplicant network HAL v1.0 1136 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 1137 WifiConfiguration loadConfig = new WifiConfiguration(); 1138 Map<String, String> networkExtras = new HashMap<>(); 1139 assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 1140 WifiConfigurationTestUtil.assertConfigurationEqualForSupplicant(config, loadConfig); 1141 assertEquals(config.getProfileKey(), 1142 networkExtras.get(SupplicantStaNetworkHal.ID_STRING_KEY_CONFIG_KEY)); 1143 assertEquals( 1144 config.creatorUid, 1145 Integer.parseInt(networkExtras.get( 1146 SupplicantStaNetworkHal.ID_STRING_KEY_CREATOR_UID))); 1147 // There is no getter for this one, so check the supplicant variable. 1148 if (!TextUtils.isEmpty(config.updateIdentifier)) { 1149 assertEquals(Integer.parseInt(config.updateIdentifier), 1150 mSupplicantVariables.updateIdentifier); 1151 } 1152 // There is no getter for this one, so check the supplicant variable. 1153 String oppKeyCaching = 1154 config.enterpriseConfig.getFieldValue(WifiEnterpriseConfig.OPP_KEY_CACHING); 1155 if (!TextUtils.isEmpty(oppKeyCaching)) { 1156 assertEquals( 1157 Integer.parseInt(oppKeyCaching) == 1 ? true : false, 1158 mSupplicantVariables.eapProactiveKeyCaching); 1159 } 1160 // There is no getter for this one, so check the supplicant variable. 1161 String eapErp = 1162 config.enterpriseConfig.getFieldValue(WifiEnterpriseConfig.EAP_ERP); 1163 if (!TextUtils.isEmpty(eapErp)) { 1164 assertEquals( 1165 Integer.parseInt(eapErp) == 1 ? true : false, 1166 mSupplicantVariables.eapErp); 1167 } 1168 } 1169 1170 /** 1171 * Verifies that createNetworkExtra() & parseNetworkExtra correctly writes a serialized and 1172 * URL-encoded JSON object. 1173 */ 1174 @Test testNetworkExtra()1175 public void testNetworkExtra() { 1176 assertEquals(NETWORK_EXTRAS_SERIALIZED, 1177 SupplicantStaNetworkHal.createNetworkExtra(NETWORK_EXTRAS_VALUES)); 1178 assertEquals(NETWORK_EXTRAS_VALUES, 1179 SupplicantStaNetworkHal.parseNetworkExtra(NETWORK_EXTRAS_SERIALIZED)); 1180 } 1181 1182 /** 1183 * Verifies that fetachEapAnonymousIdentity() can get the anonymous identity from supplicant. 1184 */ 1185 @Test testFetchEapAnonymousIdentity()1186 public void testFetchEapAnonymousIdentity() { 1187 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 1188 config.enterpriseConfig.setAnonymousIdentity(ANONYMOUS_IDENTITY); 1189 // Assume that the default params is used for this test. 1190 config.getNetworkSelectionStatus().setCandidateSecurityParams( 1191 config.getDefaultSecurityParams()); 1192 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 1193 assertEquals(ANONYMOUS_IDENTITY, mSupplicantNetwork.fetchEapAnonymousIdentity()); 1194 } 1195 1196 /** Verifies that setPmkCache can set PMK cache 1197 * 1198 */ 1199 @Test testSetPmkCache()1200 public void testSetPmkCache() { 1201 // Now expose the V1.3 ISupplicantStaNetwork 1202 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_3); 1203 1204 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 1205 config.enterpriseConfig = 1206 WifiConfigurationTestUtil.createTLSWifiEnterpriseConfigWithNonePhase2(); 1207 // Assume that the default params is used for this test. 1208 config.getNetworkSelectionStatus().setCandidateSecurityParams( 1209 config.getDefaultSecurityParams()); 1210 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 1211 1212 ArrayList<Byte> serializedData = new ArrayList<>(); 1213 assertTrue(mSupplicantNetwork.setPmkCache(serializedData)); 1214 assertEquals(serializedData, mSupplicantVariables.serializedPmkCache); 1215 } 1216 1217 /** 1218 * Tests PMK cache is not set on HAL v1.2 or lower 1219 */ 1220 @Test testSetPmkCacheHal1_2OrLower()1221 public void testSetPmkCacheHal1_2OrLower() throws Exception { 1222 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 1223 config.enterpriseConfig = 1224 WifiConfigurationTestUtil.createTLSWifiEnterpriseConfigWithNonePhase2(); 1225 // Assume that the default params is used for this test. 1226 config.getNetworkSelectionStatus().setCandidateSecurityParams( 1227 config.getDefaultSecurityParams()); 1228 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 1229 1230 ArrayList<Byte> serializedData = new ArrayList<>(); 1231 assertFalse(mSupplicantNetwork.setPmkCache(serializedData)); 1232 assertNull(mSupplicantVariables.serializedPmkCache); 1233 } 1234 1235 /** Verifies that setSaeH2eMode works on HAL 1.4 or newer */ 1236 @Test testEnableSaeH2eOnlyMode()1237 public void testEnableSaeH2eOnlyMode() throws Exception { 1238 when(mWifiGlobals.isWpa3SaeH2eSupported()).thenReturn(true); 1239 // Now expose the V1.4 ISupplicantStaNetwork 1240 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_4); 1241 1242 WifiConfiguration config = WifiConfigurationTestUtil.createSaeNetwork(); 1243 config.enableSaeH2eOnlyMode(true); 1244 // Assume that the default params is used for this test. 1245 config.getNetworkSelectionStatus().setCandidateSecurityParams( 1246 config.getDefaultSecurityParams()); 1247 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 1248 verify(mISupplicantStaNetworkV14).setSaeH2eMode( 1249 eq(android.hardware.wifi.supplicant.V1_4 1250 .ISupplicantStaNetwork.SaeH2eMode.H2E_MANDATORY)); 1251 } 1252 1253 /** Verifies that setSaeH2eMode works on HAL 1.4 or newer */ 1254 @Test testDisableSaeH2eOnlyMode()1255 public void testDisableSaeH2eOnlyMode() throws Exception { 1256 when(mWifiGlobals.isWpa3SaeH2eSupported()).thenReturn(true); 1257 // Now expose the V1.4 ISupplicantStaNetwork 1258 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_4); 1259 1260 WifiConfiguration config = WifiConfigurationTestUtil.createSaeNetwork(); 1261 config.enableSaeH2eOnlyMode(false); 1262 // Assume that the default params is used for this test. 1263 config.getNetworkSelectionStatus().setCandidateSecurityParams( 1264 config.getDefaultSecurityParams()); 1265 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 1266 verify(mISupplicantStaNetworkV14).setSaeH2eMode( 1267 eq(android.hardware.wifi.supplicant.V1_4 1268 .ISupplicantStaNetwork.SaeH2eMode.H2E_OPTIONAL)); 1269 } 1270 1271 /** Verifies that setSaeH2eMode works on HAL 1.4 or newer */ 1272 @Test testDisableSaeH2eOnlyModeWhenH2eNotSupported()1273 public void testDisableSaeH2eOnlyModeWhenH2eNotSupported() throws Exception { 1274 when(mWifiGlobals.isWpa3SaeH2eSupported()).thenReturn(false); 1275 // Now expose the V1.4 ISupplicantStaNetwork 1276 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_4); 1277 1278 WifiConfiguration config = WifiConfigurationTestUtil.createSaeNetwork(); 1279 config.enableSaeH2eOnlyMode(false); 1280 // Assume that the default params is used for this test. 1281 config.getNetworkSelectionStatus().setCandidateSecurityParams( 1282 config.getDefaultSecurityParams()); 1283 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 1284 verify(mISupplicantStaNetworkV14).setSaeH2eMode( 1285 eq(android.hardware.wifi.supplicant.V1_4 1286 .ISupplicantStaNetwork.SaeH2eMode.DISABLED)); 1287 } 1288 1289 /** Verifies that setSaeH2eMode won't break 1.3 or older HAL. */ 1290 @Test testSaeH2eOnlyModeWithHal1_3OrLower()1291 public void testSaeH2eOnlyModeWithHal1_3OrLower() throws Exception { 1292 when(mWifiGlobals.isWpa3SaeH2eSupported()).thenReturn(true); 1293 // Now expose the V1.3 ISupplicantStaNetwork 1294 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_3); 1295 1296 WifiConfiguration config = WifiConfigurationTestUtil.createSaeNetwork(); 1297 config.enableSaeH2eOnlyMode(true); 1298 // Assume that the default params is used for this test. 1299 config.getNetworkSelectionStatus().setCandidateSecurityParams( 1300 config.getDefaultSecurityParams()); 1301 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 1302 verify(mISupplicantStaNetworkV14, never()).setSaeH2eMode(anyByte()); 1303 } 1304 1305 /** 1306 * Tests the saving/loading of WifiConfiguration to wpa_supplicant with psk passphrase for 1307 * HAL v1.2 or higher 1308 */ 1309 @Test testSaeNetworkWifiConfigurationSaveLoad1_4OrHigher()1310 public void testSaeNetworkWifiConfigurationSaveLoad1_4OrHigher() throws Exception { 1311 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_4); 1312 WifiConfiguration config = WifiConfigurationTestUtil.createSaeNetwork(); 1313 1314 // Set the new defaults 1315 testWifiConfigurationSaveLoad(config); 1316 verify(mISupplicantStaNetworkV12).setSaePassword(anyString()); 1317 verify(mISupplicantStaNetworkV12, never()) 1318 .getSaePassword(any(android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1319 .getSaePasswordCallback.class)); 1320 verify(mISupplicantStaNetworkMock, never()).setPsk(any(byte[].class)); 1321 verify(mISupplicantStaNetworkMock, never()) 1322 .getPsk(any(ISupplicantStaNetwork.getPskCallback.class)); 1323 1324 verify(mISupplicantStaNetworkV14) 1325 .setPairwiseCipher_1_4(ISupplicantStaNetwork.PairwiseCipherMask.CCMP 1326 | android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork 1327 .PairwiseCipherMask.GCMP_128 1328 | android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1329 .PairwiseCipherMask.GCMP_256); 1330 verify(mISupplicantStaNetworkV14) 1331 .setGroupCipher_1_4(ISupplicantStaNetwork.GroupCipherMask.CCMP 1332 | android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork 1333 .GroupCipherMask.GCMP_128 1334 | android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1335 .GroupCipherMask.GCMP_256); 1336 } 1337 putAllSupportingPairwiseCiphersAndReturnExpectedHalCiphersValue( WifiConfiguration config, SupplicantStaNetworkVersion version)1338 private int putAllSupportingPairwiseCiphersAndReturnExpectedHalCiphersValue( 1339 WifiConfiguration config, 1340 SupplicantStaNetworkVersion version) { 1341 int halMaskValue = 0; 1342 1343 // The default security params is used in the test. 1344 BitSet allowedPairwiseCiphers = config.getDefaultSecurityParams() 1345 .getAllowedPairwiseCiphers(); 1346 // These are supported from v1.4 1347 if (allowedPairwiseCiphers.get(WifiConfiguration.PairwiseCipher.GCMP_128) 1348 && version.ordinal() >= SupplicantStaNetworkVersion.V1_4.ordinal()) { 1349 halMaskValue |= android.hardware.wifi.supplicant 1350 .V1_4.ISupplicantStaNetwork 1351 .PairwiseCipherMask.GCMP_128; 1352 } 1353 1354 // These are supported from v1.3 1355 if (allowedPairwiseCiphers.get(WifiConfiguration.PairwiseCipher.SMS4) 1356 && version.ordinal() >= SupplicantStaNetworkVersion.V1_3.ordinal()) { 1357 halMaskValue |= android.hardware.wifi.supplicant 1358 .V1_3.ISupplicantStaNetwork 1359 .PairwiseCipherMask.SMS4; 1360 } 1361 1362 // These are supported from v1.2 1363 if (allowedPairwiseCiphers.get(WifiConfiguration.PairwiseCipher.GCMP_256) 1364 && version.ordinal() >= SupplicantStaNetworkVersion.V1_2.ordinal()) { 1365 halMaskValue |= android.hardware.wifi.supplicant 1366 .V1_2.ISupplicantStaNetwork 1367 .PairwiseCipherMask.GCMP_256; 1368 } 1369 1370 // There are supported from v1.0 1371 if (allowedPairwiseCiphers.get(WifiConfiguration.PairwiseCipher.CCMP)) { 1372 halMaskValue |= ISupplicantStaNetwork.PairwiseCipherMask.CCMP; 1373 } 1374 1375 return halMaskValue; 1376 } 1377 putAllSupportingGroupCiphersAndReturnExpectedHalCiphersValue( WifiConfiguration config, SupplicantStaNetworkVersion version)1378 private int putAllSupportingGroupCiphersAndReturnExpectedHalCiphersValue( 1379 WifiConfiguration config, 1380 SupplicantStaNetworkVersion version) { 1381 int halMaskValue = 0; 1382 // The default security params is used in the test. 1383 BitSet allowedGroupCiphers = config.getDefaultSecurityParams().getAllowedGroupCiphers(); 1384 1385 // These are supported from v1.4 1386 if (allowedGroupCiphers.get(WifiConfiguration.GroupCipher.GCMP_128) 1387 && version.ordinal() >= SupplicantStaNetworkVersion.V1_4.ordinal()) { 1388 halMaskValue |= android.hardware.wifi.supplicant 1389 .V1_4.ISupplicantStaNetwork 1390 .GroupCipherMask.GCMP_128; 1391 } 1392 1393 // These are supported from v1.2 1394 if (allowedGroupCiphers.get(WifiConfiguration.GroupCipher.GCMP_256) 1395 && version.ordinal() >= SupplicantStaNetworkVersion.V1_2.ordinal()) { 1396 halMaskValue |= android.hardware.wifi.supplicant 1397 .V1_2.ISupplicantStaNetwork 1398 .GroupCipherMask.GCMP_256; 1399 } 1400 1401 // There are supported from v1.0 1402 if (allowedGroupCiphers.get(WifiConfiguration.GroupCipher.CCMP)) { 1403 halMaskValue |= ISupplicantStaNetwork.GroupCipherMask.CCMP; 1404 } 1405 1406 return halMaskValue; 1407 } 1408 1409 /** 1410 * Tests the saving/loading of WifiConfiguration with 1411 * unsupporting GCMP-256 ciphers for V1.2 HAL. 1412 * 1413 * GCMP-256 is supported only if WPA3 SUITE-B is supported. 1414 */ 1415 @Test testUnsupportingGcmp256Ciphers1_2OrHigher()1416 public void testUnsupportingGcmp256Ciphers1_2OrHigher() 1417 throws Exception { 1418 mAdvanceKeyMgmtFeatures = 0; 1419 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_2); 1420 WifiConfiguration config = WifiConfigurationTestUtil.createSaeNetwork(); 1421 int expectedHalPairwiseCiphers = 1422 putAllSupportingPairwiseCiphersAndReturnExpectedHalCiphersValue(config, 1423 SupplicantStaNetworkVersion.V1_2); 1424 expectedHalPairwiseCiphers &= ~android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1425 .PairwiseCipherMask.GCMP_256; 1426 int expectedHalGroupCiphers = 1427 putAllSupportingGroupCiphersAndReturnExpectedHalCiphersValue(config, 1428 SupplicantStaNetworkVersion.V1_2); 1429 expectedHalGroupCiphers &= ~android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1430 .GroupCipherMask.GCMP_256; 1431 1432 // Assume that the default params is used for this test. 1433 config.getNetworkSelectionStatus().setCandidateSecurityParams( 1434 config.getDefaultSecurityParams()); 1435 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 1436 WifiConfiguration loadConfig = new WifiConfiguration(); 1437 Map<String, String> networkExtras = new HashMap<>(); 1438 assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 1439 1440 verify(mISupplicantStaNetworkV12).setPairwiseCipher_1_2(expectedHalPairwiseCiphers); 1441 verify(mISupplicantStaNetworkV12).setGroupCipher_1_2(expectedHalGroupCiphers); 1442 } 1443 testUnsupportingCiphers(SupplicantStaNetworkVersion version)1444 private void testUnsupportingCiphers(SupplicantStaNetworkVersion version) throws Exception { 1445 createSupplicantStaNetwork(version); 1446 WifiConfiguration config = WifiConfigurationTestUtil.createSaeNetwork(); 1447 int expectedHalPairwiseCiphers = 1448 putAllSupportingPairwiseCiphersAndReturnExpectedHalCiphersValue(config, version); 1449 int expectedHalGroupCiphers = 1450 putAllSupportingGroupCiphersAndReturnExpectedHalCiphersValue(config, version); 1451 1452 // Assume that the default params is used for this test. 1453 config.getNetworkSelectionStatus().setCandidateSecurityParams( 1454 config.getDefaultSecurityParams()); 1455 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 1456 WifiConfiguration loadConfig = new WifiConfiguration(); 1457 Map<String, String> networkExtras = new HashMap<>(); 1458 assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 1459 1460 switch (version) { 1461 case V1_0: 1462 // No new cipher added in V1.1 1463 case V1_1: 1464 verify(mISupplicantStaNetworkMock) 1465 .setPairwiseCipher(expectedHalPairwiseCiphers); 1466 verify(mISupplicantStaNetworkMock) 1467 .setGroupCipher(expectedHalGroupCiphers); 1468 break; 1469 case V1_2: 1470 verify(mISupplicantStaNetworkV12) 1471 .setPairwiseCipher_1_2(expectedHalPairwiseCiphers); 1472 verify(mISupplicantStaNetworkV12) 1473 .setGroupCipher_1_2(expectedHalGroupCiphers); 1474 break; 1475 case V1_3: 1476 verify(mISupplicantStaNetworkV13) 1477 .setPairwiseCipher_1_3(expectedHalPairwiseCiphers); 1478 verify(mISupplicantStaNetworkV13) 1479 .setGroupCipher_1_3(expectedHalGroupCiphers); 1480 break; 1481 case V1_4: 1482 verify(mISupplicantStaNetworkV14) 1483 .setPairwiseCipher_1_4(expectedHalPairwiseCiphers); 1484 verify(mISupplicantStaNetworkV14) 1485 .setGroupCipher_1_4(expectedHalGroupCiphers); 1486 break; 1487 } 1488 } 1489 1490 /** 1491 * Tests the saving/loading of WifiConfiguration with unsupporting ciphers for V1.2 HAL. 1492 */ 1493 @Test testUnsupportingCiphers1_2()1494 public void testUnsupportingCiphers1_2() throws Exception { 1495 testUnsupportingCiphers(SupplicantStaNetworkVersion.V1_2); 1496 } 1497 1498 /** 1499 * Tests the saving/loading of WifiConfiguration with unsupporting ciphers for V1.3 HAL. 1500 */ 1501 @Test testUnsupportingCiphers1_3()1502 public void testUnsupportingCiphers1_3() throws Exception { 1503 testUnsupportingCiphers(SupplicantStaNetworkVersion.V1_3); 1504 } 1505 1506 /** 1507 * Tests the saving/loading of WifiConfiguration with unsupporting ciphers for V1.4 HAL. 1508 */ 1509 @Test testUnsupportingCiphers1_4()1510 public void testUnsupportingCiphers1_4() throws Exception { 1511 testUnsupportingCiphers(SupplicantStaNetworkVersion.V1_4); 1512 } 1513 1514 /** 1515 * Tests the appending decorated identity prefix to anonymous identity and saving to 1516 * wpa_supplicant. 1517 */ 1518 @Test testEapNetworkSetsDecoratedIdentityPrefix()1519 public void testEapNetworkSetsDecoratedIdentityPrefix() throws Exception { 1520 assumeTrue(SdkLevel.isAtLeastS()); 1521 createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_4); 1522 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 1523 config.enterpriseConfig.setAnonymousIdentity(ANONYMOUS_IDENTITY); 1524 config.enterpriseConfig.setDecoratedIdentityPrefix(TEST_DECORATED_IDENTITY_PREFIX); 1525 // Assume that the default params is used for this test. 1526 config.getNetworkSelectionStatus().setCandidateSecurityParams( 1527 config.getDefaultSecurityParams()); 1528 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 1529 WifiConfiguration loadConfig = new WifiConfiguration(); 1530 Map<String, String> networkExtras = new HashMap<>(); 1531 assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 1532 assertEquals(TEST_DECORATED_IDENTITY_PREFIX 1533 + config.enterpriseConfig.getAnonymousIdentity(), 1534 loadConfig.enterpriseConfig.getAnonymousIdentity()); 1535 assertEquals(TEST_DECORATED_IDENTITY_PREFIX + ANONYMOUS_IDENTITY, 1536 mSupplicantNetwork.fetchEapAnonymousIdentity()); 1537 } 1538 1539 /** 1540 * Sets up the HIDL interface mock with all the setters/getter values. 1541 * Note: This only sets up the mock to return success on all methods. 1542 */ setupISupplicantNetworkMock()1543 private void setupISupplicantNetworkMock() throws Exception { 1544 /** SSID */ 1545 doAnswer(new AnswerWithArguments() { 1546 public SupplicantStatus answer(ArrayList<Byte> ssid) throws RemoteException { 1547 mSupplicantVariables.ssid = ssid; 1548 return mStatusSuccess; 1549 } 1550 }).when(mISupplicantStaNetworkMock).setSsid(any(ArrayList.class)); 1551 doAnswer(new AnswerWithArguments() { 1552 public void answer(ISupplicantStaNetwork.getSsidCallback cb) throws RemoteException { 1553 cb.onValues(mStatusSuccess, mSupplicantVariables.ssid); 1554 } 1555 }).when(mISupplicantStaNetworkMock) 1556 .getSsid(any(ISupplicantStaNetwork.getSsidCallback.class)); 1557 1558 /** Network Id */ 1559 doAnswer(new AnswerWithArguments() { 1560 public void answer(ISupplicantNetwork.getIdCallback cb) throws RemoteException { 1561 cb.onValues(mStatusSuccess, mSupplicantVariables.networkId); 1562 } 1563 }).when(mISupplicantStaNetworkMock).getId(any(ISupplicantNetwork.getIdCallback.class)); 1564 1565 /** BSSID */ 1566 doAnswer(new AnswerWithArguments() { 1567 public SupplicantStatus answer(byte[] bssid) throws RemoteException { 1568 mSupplicantVariables.bssid = bssid; 1569 return mStatusSuccess; 1570 } 1571 }).when(mISupplicantStaNetworkMock).setBssid(any(byte[].class)); 1572 doAnswer(new AnswerWithArguments() { 1573 public void answer(ISupplicantStaNetwork.getBssidCallback cb) throws RemoteException { 1574 cb.onValues(mStatusSuccess, mSupplicantVariables.bssid); 1575 } 1576 }).when(mISupplicantStaNetworkMock) 1577 .getBssid(any(ISupplicantStaNetwork.getBssidCallback.class)); 1578 1579 /** Scan SSID (Is Hidden Network?) */ 1580 doAnswer(new AnswerWithArguments() { 1581 public SupplicantStatus answer(boolean enable) throws RemoteException { 1582 mSupplicantVariables.scanSsid = enable; 1583 return mStatusSuccess; 1584 } 1585 }).when(mISupplicantStaNetworkMock).setScanSsid(any(boolean.class)); 1586 doAnswer(new AnswerWithArguments() { 1587 public void answer(ISupplicantStaNetwork.getScanSsidCallback cb) 1588 throws RemoteException { 1589 cb.onValues(mStatusSuccess, mSupplicantVariables.scanSsid); 1590 } 1591 }).when(mISupplicantStaNetworkMock) 1592 .getScanSsid(any(ISupplicantStaNetwork.getScanSsidCallback.class)); 1593 1594 /** Require PMF*/ 1595 doAnswer(new AnswerWithArguments() { 1596 public SupplicantStatus answer(boolean enable) throws RemoteException { 1597 mSupplicantVariables.requirePmf = enable; 1598 return mStatusSuccess; 1599 } 1600 }).when(mISupplicantStaNetworkMock).setRequirePmf(any(boolean.class)); 1601 doAnswer(new AnswerWithArguments() { 1602 public void answer(ISupplicantStaNetwork.getRequirePmfCallback cb) 1603 throws RemoteException { 1604 cb.onValues(mStatusSuccess, mSupplicantVariables.requirePmf); 1605 } 1606 }).when(mISupplicantStaNetworkMock) 1607 .getRequirePmf(any(ISupplicantStaNetwork.getRequirePmfCallback.class)); 1608 1609 /** SAE password */ 1610 doAnswer(new AnswerWithArguments() { 1611 public SupplicantStatus answer(String saePassword) throws RemoteException { 1612 mSupplicantVariables.pskPassphrase = saePassword; 1613 return mStatusSuccess; 1614 } 1615 }).when(mISupplicantStaNetworkV12).setSaePassword(any(String.class)); 1616 doAnswer(new AnswerWithArguments() { 1617 public void answer(ISupplicantStaNetwork.getPskPassphraseCallback cb) 1618 throws RemoteException { 1619 cb.onValues(mStatusSuccess, mSupplicantVariables.pskPassphrase); 1620 } 1621 }).when(mISupplicantStaNetworkV12) 1622 .getSaePassword(any(android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1623 .getSaePasswordCallback.class)); 1624 1625 /** PSK passphrase */ 1626 doAnswer(new AnswerWithArguments() { 1627 public SupplicantStatus answer(String pskPassphrase) throws RemoteException { 1628 mSupplicantVariables.pskPassphrase = pskPassphrase; 1629 return mStatusSuccess; 1630 } 1631 }).when(mISupplicantStaNetworkMock).setPskPassphrase(any(String.class)); 1632 doAnswer(new AnswerWithArguments() { 1633 public void answer(ISupplicantStaNetwork.getPskPassphraseCallback cb) 1634 throws RemoteException { 1635 cb.onValues(mStatusSuccess, mSupplicantVariables.pskPassphrase); 1636 } 1637 }).when(mISupplicantStaNetworkMock) 1638 .getPskPassphrase(any(ISupplicantStaNetwork.getPskPassphraseCallback.class)); 1639 1640 /** PSK */ 1641 doAnswer(new AnswerWithArguments() { 1642 public SupplicantStatus answer(byte[] psk) throws RemoteException { 1643 mSupplicantVariables.psk = psk; 1644 return mStatusSuccess; 1645 } 1646 }).when(mISupplicantStaNetworkMock).setPsk(any(byte[].class)); 1647 doAnswer(new AnswerWithArguments() { 1648 public void answer(ISupplicantStaNetwork.getPskCallback cb) 1649 throws RemoteException { 1650 cb.onValues(mStatusSuccess, mSupplicantVariables.psk); 1651 } 1652 }).when(mISupplicantStaNetworkMock) 1653 .getPsk(any(ISupplicantStaNetwork.getPskCallback.class)); 1654 1655 /** WEP keys **/ 1656 doAnswer(new AnswerWithArguments() { 1657 public SupplicantStatus answer(int keyIdx, ArrayList<Byte> key) throws RemoteException { 1658 mSupplicantVariables.wepKey[keyIdx] = key; 1659 return mStatusSuccess; 1660 } 1661 }).when(mISupplicantStaNetworkMock).setWepKey(any(int.class), any(ArrayList.class)); 1662 doAnswer(new AnswerWithArguments() { 1663 public void answer(int keyIdx, ISupplicantStaNetwork.getWepKeyCallback cb) 1664 throws RemoteException { 1665 cb.onValues(mStatusSuccess, mSupplicantVariables.wepKey[keyIdx]); 1666 } 1667 }).when(mISupplicantStaNetworkMock) 1668 .getWepKey(any(int.class), any(ISupplicantStaNetwork.getWepKeyCallback.class)); 1669 1670 doAnswer(new AnswerWithArguments() { 1671 public SupplicantStatus answer(int keyIdx) throws RemoteException { 1672 mSupplicantVariables.wepTxKeyIdx = keyIdx; 1673 return mStatusSuccess; 1674 } 1675 }).when(mISupplicantStaNetworkMock).setWepTxKeyIdx(any(int.class)); 1676 doAnswer(new AnswerWithArguments() { 1677 public void answer(ISupplicantStaNetwork.getWepTxKeyIdxCallback cb) 1678 throws RemoteException { 1679 cb.onValues(mStatusSuccess, mSupplicantVariables.wepTxKeyIdx); 1680 } 1681 }).when(mISupplicantStaNetworkMock) 1682 .getWepTxKeyIdx(any(ISupplicantStaNetwork.getWepTxKeyIdxCallback.class)); 1683 1684 /** allowedKeyManagement */ 1685 doAnswer(new AnswerWithArguments() { 1686 public SupplicantStatus answer(int mask) throws RemoteException { 1687 mSupplicantVariables.keyMgmtMask = mask; 1688 return mStatusSuccess; 1689 } 1690 }).when(mISupplicantStaNetworkMock).setKeyMgmt(any(int.class)); 1691 doAnswer(new AnswerWithArguments() { 1692 public void answer(ISupplicantStaNetwork.getKeyMgmtCallback cb) throws RemoteException { 1693 cb.onValues(mStatusSuccess, mSupplicantVariables.keyMgmtMask); 1694 } 1695 }).when(mISupplicantStaNetworkMock) 1696 .getKeyMgmt(any(ISupplicantStaNetwork.getKeyMgmtCallback.class)); 1697 1698 /** allowedKeyManagement v1.2 */ 1699 doAnswer(new AnswerWithArguments() { 1700 public SupplicantStatus answer(int mask) throws RemoteException { 1701 mSupplicantVariables.keyMgmtMask = mask; 1702 return mStatusSuccess; 1703 } 1704 }).when(mISupplicantStaNetworkV12).setKeyMgmt_1_2(any(int.class)); 1705 doAnswer(new AnswerWithArguments() { 1706 public void answer(ISupplicantStaNetwork.getKeyMgmtCallback cb) throws RemoteException { 1707 cb.onValues(mStatusSuccess, mSupplicantVariables.keyMgmtMask); 1708 } 1709 }).when(mISupplicantStaNetworkV12) 1710 .getKeyMgmt_1_2(any(android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1711 .getKeyMgmt_1_2Callback.class)); 1712 1713 /** allowedKeyManagement v1.3 */ 1714 doAnswer(new AnswerWithArguments() { 1715 public SupplicantStatus answer(int mask) throws RemoteException { 1716 mSupplicantVariables.keyMgmtMask = mask; 1717 return mStatusSuccess; 1718 } 1719 }).when(mISupplicantStaNetworkV13).setKeyMgmt_1_3(any(int.class)); 1720 doAnswer(new AnswerWithArguments() { 1721 public void answer(android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 1722 .getKeyMgmt_1_3Callback cb) throws RemoteException { 1723 cb.onValues(mStatusSuccess, mSupplicantVariables.keyMgmtMask); 1724 } 1725 }).when(mISupplicantStaNetworkV13) 1726 .getKeyMgmt_1_3(any(android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 1727 .getKeyMgmt_1_3Callback.class)); 1728 1729 /** allowedProtocols */ 1730 doAnswer(new AnswerWithArguments() { 1731 public SupplicantStatus answer(int mask) throws RemoteException { 1732 mSupplicantVariables.protoMask = mask; 1733 return mStatusSuccess; 1734 } 1735 }).when(mISupplicantStaNetworkMock).setProto(any(int.class)); 1736 doAnswer(new AnswerWithArguments() { 1737 public void answer(ISupplicantStaNetwork.getProtoCallback cb) throws RemoteException { 1738 cb.onValues(mStatusSuccess, mSupplicantVariables.protoMask); 1739 } 1740 }).when(mISupplicantStaNetworkMock) 1741 .getProto(any(ISupplicantStaNetwork.getProtoCallback.class)); 1742 1743 /** allowedProtocols v1.3*/ 1744 doAnswer(new AnswerWithArguments() { 1745 public SupplicantStatus answer(int mask) throws RemoteException { 1746 mSupplicantVariables.protoMask = mask; 1747 return mStatusSuccess; 1748 } 1749 }).when(mISupplicantStaNetworkV13).setProto_1_3(any(int.class)); 1750 doAnswer(new AnswerWithArguments() { 1751 public void answer(android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 1752 .getProto_1_3Callback cb) throws RemoteException { 1753 cb.onValues(mStatusSuccess, mSupplicantVariables.protoMask); 1754 } 1755 }).when(mISupplicantStaNetworkV13) 1756 .getProto_1_3(any(android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 1757 .getProto_1_3Callback.class)); 1758 1759 /** allowedAuthAlgorithms */ 1760 doAnswer(new AnswerWithArguments() { 1761 public SupplicantStatus answer(int mask) throws RemoteException { 1762 mSupplicantVariables.authAlgMask = mask; 1763 return mStatusSuccess; 1764 } 1765 }).when(mISupplicantStaNetworkMock).setAuthAlg(any(int.class)); 1766 doAnswer(new AnswerWithArguments() { 1767 public void answer(ISupplicantStaNetwork.getAuthAlgCallback cb) throws RemoteException { 1768 cb.onValues(mStatusSuccess, mSupplicantVariables.authAlgMask); 1769 } 1770 }).when(mISupplicantStaNetworkMock) 1771 .getAuthAlg(any(ISupplicantStaNetwork.getAuthAlgCallback.class)); 1772 1773 /** allowedGroupCiphers */ 1774 doAnswer(new AnswerWithArguments() { 1775 public SupplicantStatus answer(int mask) throws RemoteException { 1776 mSupplicantVariables.groupCipherMask = mask; 1777 return mStatusSuccess; 1778 } 1779 }).when(mISupplicantStaNetworkMock).setGroupCipher(any(int.class)); 1780 doAnswer(new AnswerWithArguments() { 1781 public void answer(ISupplicantStaNetwork.getGroupCipherCallback cb) 1782 throws RemoteException { 1783 cb.onValues(mStatusSuccess, mSupplicantVariables.groupCipherMask); 1784 } 1785 }).when(mISupplicantStaNetworkMock) 1786 .getGroupCipher(any(ISupplicantStaNetwork.getGroupCipherCallback.class)); 1787 1788 /** allowedGroupCiphers v1.2*/ 1789 doAnswer(new AnswerWithArguments() { 1790 public SupplicantStatus answer(int mask) throws RemoteException { 1791 mSupplicantVariables.groupCipherMask = mask; 1792 return mStatusSuccess; 1793 } 1794 }).when(mISupplicantStaNetworkV12).setGroupCipher_1_2(any(int.class)); 1795 doAnswer(new AnswerWithArguments() { 1796 public void answer(ISupplicantStaNetwork.getGroupCipherCallback cb) 1797 throws RemoteException { 1798 cb.onValues(mStatusSuccess, mSupplicantVariables.groupCipherMask); 1799 } 1800 }).when(mISupplicantStaNetworkV12) 1801 .getGroupCipher_1_2(any(android.hardware.wifi.supplicant.V1_2.ISupplicantStaNetwork 1802 .getGroupCipher_1_2Callback.class)); 1803 1804 /** allowedGroupCiphers v1.3*/ 1805 doAnswer(new AnswerWithArguments() { 1806 public SupplicantStatus answer(int mask) throws RemoteException { 1807 mSupplicantVariables.groupCipherMask = mask; 1808 return mStatusSuccess; 1809 } 1810 }).when(mISupplicantStaNetworkV13).setGroupCipher_1_3(any(int.class)); 1811 doAnswer(new AnswerWithArguments() { 1812 public void answer(android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 1813 .getGroupCipher_1_3Callback cb) 1814 throws RemoteException { 1815 cb.onValues(mStatusSuccess, mSupplicantVariables.groupCipherMask); 1816 } 1817 }).when(mISupplicantStaNetworkV13) 1818 .getGroupCipher_1_3(any(android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 1819 .getGroupCipher_1_3Callback.class)); 1820 1821 /** allowedGroupCiphers v1.4 */ 1822 doAnswer(new AnswerWithArguments() { 1823 public android.hardware.wifi.supplicant.V1_4.SupplicantStatus 1824 answer(int mask) throws RemoteException { 1825 mSupplicantVariables.groupCipherMask = mask; 1826 return mStatusSuccessV14; 1827 } 1828 }).when(mISupplicantStaNetworkV14).setGroupCipher_1_4(any(int.class)); 1829 doAnswer(new AnswerWithArguments() { 1830 public void answer(android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork 1831 .getGroupCipher_1_4Callback cb) 1832 throws RemoteException { 1833 cb.onValues(mStatusSuccessV14, mSupplicantVariables.groupCipherMask); 1834 } 1835 }).when(mISupplicantStaNetworkV14) 1836 .getGroupCipher_1_4(any(android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork 1837 .getGroupCipher_1_4Callback.class)); 1838 1839 /** allowedPairwiseCiphers */ 1840 doAnswer(new AnswerWithArguments() { 1841 public SupplicantStatus answer(int mask) throws RemoteException { 1842 mSupplicantVariables.pairwiseCipherMask = mask; 1843 return mStatusSuccess; 1844 } 1845 }).when(mISupplicantStaNetworkMock).setPairwiseCipher(any(int.class)); 1846 doAnswer(new AnswerWithArguments() { 1847 public void answer(ISupplicantStaNetwork.getPairwiseCipherCallback cb) 1848 throws RemoteException { 1849 cb.onValues(mStatusSuccess, mSupplicantVariables.pairwiseCipherMask); 1850 } 1851 }).when(mISupplicantStaNetworkMock) 1852 .getPairwiseCipher(any(ISupplicantStaNetwork.getPairwiseCipherCallback.class)); 1853 1854 /** allowedPairwiseCiphers v1.2 */ 1855 doAnswer(new AnswerWithArguments() { 1856 public SupplicantStatus answer(int mask) throws RemoteException { 1857 mSupplicantVariables.pairwiseCipherMask = mask; 1858 return mStatusSuccess; 1859 } 1860 }).when(mISupplicantStaNetworkV12).setPairwiseCipher_1_2(any(int.class)); 1861 doAnswer(new AnswerWithArguments() { 1862 public void answer(ISupplicantStaNetwork.getPairwiseCipherCallback cb) 1863 throws RemoteException { 1864 cb.onValues(mStatusSuccess, mSupplicantVariables.pairwiseCipherMask); 1865 } 1866 }).when(mISupplicantStaNetworkV12) 1867 .getPairwiseCipher_1_2(any(android.hardware.wifi.supplicant.V1_2 1868 .ISupplicantStaNetwork.getPairwiseCipher_1_2Callback.class)); 1869 1870 /** allowedPairwiseCiphers v1.3 */ 1871 doAnswer(new AnswerWithArguments() { 1872 public SupplicantStatus answer(int mask) throws RemoteException { 1873 mSupplicantVariables.pairwiseCipherMask = mask; 1874 return mStatusSuccess; 1875 } 1876 }).when(mISupplicantStaNetworkV13).setPairwiseCipher_1_3(any(int.class)); 1877 doAnswer(new AnswerWithArguments() { 1878 public void answer(android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 1879 .getPairwiseCipher_1_3Callback cb) 1880 throws RemoteException { 1881 cb.onValues(mStatusSuccess, mSupplicantVariables.pairwiseCipherMask); 1882 } 1883 }).when(mISupplicantStaNetworkV13) 1884 .getPairwiseCipher_1_3(any(android.hardware.wifi.supplicant.V1_3 1885 .ISupplicantStaNetwork.getPairwiseCipher_1_3Callback.class)); 1886 1887 /** allowedPairwiseCiphers v1.4 */ 1888 doAnswer(new AnswerWithArguments() { 1889 public android.hardware.wifi.supplicant.V1_4.SupplicantStatus 1890 answer(int mask) throws RemoteException { 1891 mSupplicantVariables.pairwiseCipherMask = mask; 1892 return mStatusSuccessV14; 1893 } 1894 }).when(mISupplicantStaNetworkV14).setPairwiseCipher_1_4(any(int.class)); 1895 doAnswer(new AnswerWithArguments() { 1896 public void answer(android.hardware.wifi.supplicant.V1_4.ISupplicantStaNetwork 1897 .getPairwiseCipher_1_4Callback cb) 1898 throws RemoteException { 1899 cb.onValues(mStatusSuccessV14, mSupplicantVariables.pairwiseCipherMask); 1900 } 1901 }).when(mISupplicantStaNetworkV14) 1902 .getPairwiseCipher_1_4(any(android.hardware.wifi.supplicant.V1_4 1903 .ISupplicantStaNetwork.getPairwiseCipher_1_4Callback.class)); 1904 1905 /** allowedGroupManagementCiphers v1.2 */ 1906 doAnswer(new AnswerWithArguments() { 1907 public SupplicantStatus answer(int mask) throws RemoteException { 1908 mSupplicantVariables.groupManagementCipherMask = mask; 1909 return mStatusSuccess; 1910 } 1911 }).when(mISupplicantStaNetworkV12).setGroupMgmtCipher(any(int.class)); 1912 doAnswer(new AnswerWithArguments() { 1913 public void answer(android.hardware.wifi.supplicant.V1_2 1914 .ISupplicantStaNetwork.getGroupMgmtCipherCallback cb) 1915 throws RemoteException { 1916 cb.onValues(mStatusSuccess, mSupplicantVariables.groupManagementCipherMask); 1917 } 1918 }).when(mISupplicantStaNetworkV12) 1919 .getGroupMgmtCipher(any(android.hardware.wifi.supplicant.V1_2 1920 .ISupplicantStaNetwork.getGroupMgmtCipherCallback.class)); 1921 1922 /** metadata: idstr */ 1923 doAnswer(new AnswerWithArguments() { 1924 public SupplicantStatus answer(String idStr) throws RemoteException { 1925 mSupplicantVariables.idStr = idStr; 1926 return mStatusSuccess; 1927 } 1928 }).when(mISupplicantStaNetworkMock).setIdStr(any(String.class)); 1929 doAnswer(new AnswerWithArguments() { 1930 public void answer(ISupplicantStaNetwork.getIdStrCallback cb) throws RemoteException { 1931 cb.onValues(mStatusSuccess, mSupplicantVariables.idStr); 1932 } 1933 }).when(mISupplicantStaNetworkMock) 1934 .getIdStr(any(ISupplicantStaNetwork.getIdStrCallback.class)); 1935 1936 /** UpdateIdentifier */ 1937 doAnswer(new AnswerWithArguments() { 1938 public SupplicantStatus answer(int identifier) throws RemoteException { 1939 mSupplicantVariables.updateIdentifier = identifier; 1940 return mStatusSuccess; 1941 } 1942 }).when(mISupplicantStaNetworkMock).setUpdateIdentifier(any(int.class)); 1943 1944 /** EAP method */ 1945 doAnswer(new AnswerWithArguments() { 1946 public SupplicantStatus answer(int method) throws RemoteException { 1947 mSupplicantVariables.eapMethod = method; 1948 return mStatusSuccess; 1949 } 1950 }).when(mISupplicantStaNetworkMock).setEapMethod(any(int.class)); 1951 doAnswer(new AnswerWithArguments() { 1952 public void answer(ISupplicantStaNetwork.getEapMethodCallback cb) 1953 throws RemoteException { 1954 // When not set, return failure. 1955 if (mSupplicantVariables.eapMethod == -1) { 1956 cb.onValues(mStatusFailure, mSupplicantVariables.eapMethod); 1957 } else { 1958 cb.onValues(mStatusSuccess, mSupplicantVariables.eapMethod); 1959 } 1960 } 1961 }).when(mISupplicantStaNetworkMock) 1962 .getEapMethod(any(ISupplicantStaNetwork.getEapMethodCallback.class)); 1963 1964 /** EAP Phase 2 method */ 1965 doAnswer(new AnswerWithArguments() { 1966 public SupplicantStatus answer(int method) throws RemoteException { 1967 mSupplicantVariables.eapPhase2Method = method; 1968 return mStatusSuccess; 1969 } 1970 }).when(mISupplicantStaNetworkMock).setEapPhase2Method(any(int.class)); 1971 doAnswer(new AnswerWithArguments() { 1972 public void answer(ISupplicantStaNetwork.getEapPhase2MethodCallback cb) 1973 throws RemoteException { 1974 // When not set, return failure. 1975 if (mSupplicantVariables.eapPhase2Method == -1) { 1976 cb.onValues(mStatusFailure, mSupplicantVariables.eapPhase2Method); 1977 } else { 1978 cb.onValues(mStatusSuccess, mSupplicantVariables.eapPhase2Method); 1979 } 1980 } 1981 }).when(mISupplicantStaNetworkMock) 1982 .getEapPhase2Method(any(ISupplicantStaNetwork.getEapPhase2MethodCallback.class)); 1983 1984 /** EAP Identity */ 1985 doAnswer(new AnswerWithArguments() { 1986 public SupplicantStatus answer(ArrayList<Byte> identity) throws RemoteException { 1987 mSupplicantVariables.eapIdentity = identity; 1988 return mStatusSuccess; 1989 } 1990 }).when(mISupplicantStaNetworkMock).setEapIdentity(any(ArrayList.class)); 1991 doAnswer(new AnswerWithArguments() { 1992 public void answer(ISupplicantStaNetwork.getEapIdentityCallback cb) 1993 throws RemoteException { 1994 cb.onValues(mStatusSuccess, mSupplicantVariables.eapIdentity); 1995 } 1996 }).when(mISupplicantStaNetworkMock) 1997 .getEapIdentity(any(ISupplicantStaNetwork.getEapIdentityCallback.class)); 1998 1999 /** EAP Anonymous Identity */ 2000 doAnswer(new AnswerWithArguments() { 2001 public SupplicantStatus answer(ArrayList<Byte> identity) throws RemoteException { 2002 mSupplicantVariables.eapAnonymousIdentity = identity; 2003 return mStatusSuccess; 2004 } 2005 }).when(mISupplicantStaNetworkMock).setEapAnonymousIdentity(any(ArrayList.class)); 2006 doAnswer(new AnswerWithArguments() { 2007 public void answer(ISupplicantStaNetwork.getEapAnonymousIdentityCallback cb) 2008 throws RemoteException { 2009 cb.onValues(mStatusSuccess, mSupplicantVariables.eapAnonymousIdentity); 2010 } 2011 }).when(mISupplicantStaNetworkMock) 2012 .getEapAnonymousIdentity( 2013 any(ISupplicantStaNetwork.getEapAnonymousIdentityCallback.class)); 2014 2015 /** EAP Password */ 2016 doAnswer(new AnswerWithArguments() { 2017 public SupplicantStatus answer(ArrayList<Byte> password) throws RemoteException { 2018 mSupplicantVariables.eapPassword = password; 2019 return mStatusSuccess; 2020 } 2021 }).when(mISupplicantStaNetworkMock).setEapPassword(any(ArrayList.class)); 2022 doAnswer(new AnswerWithArguments() { 2023 public void answer(ISupplicantStaNetwork.getEapPasswordCallback cb) 2024 throws RemoteException { 2025 cb.onValues(mStatusSuccess, mSupplicantVariables.eapPassword); 2026 } 2027 }).when(mISupplicantStaNetworkMock) 2028 .getEapPassword(any(ISupplicantStaNetwork.getEapPasswordCallback.class)); 2029 2030 /** EAP Client Cert */ 2031 doAnswer(new AnswerWithArguments() { 2032 public SupplicantStatus answer(String cert) throws RemoteException { 2033 mSupplicantVariables.eapClientCert = cert; 2034 return mStatusSuccess; 2035 } 2036 }).when(mISupplicantStaNetworkMock).setEapClientCert(any(String.class)); 2037 doAnswer(new AnswerWithArguments() { 2038 public void answer(ISupplicantStaNetwork.getEapClientCertCallback cb) 2039 throws RemoteException { 2040 cb.onValues(mStatusSuccess, mSupplicantVariables.eapClientCert); 2041 } 2042 }).when(mISupplicantStaNetworkMock) 2043 .getEapClientCert(any(ISupplicantStaNetwork.getEapClientCertCallback.class)); 2044 2045 /** EAP CA Cert */ 2046 doAnswer(new AnswerWithArguments() { 2047 public SupplicantStatus answer(String cert) throws RemoteException { 2048 mSupplicantVariables.eapCACert = cert; 2049 return mStatusSuccess; 2050 } 2051 }).when(mISupplicantStaNetworkMock).setEapCACert(any(String.class)); 2052 doAnswer(new AnswerWithArguments() { 2053 public void answer(ISupplicantStaNetwork.getEapCACertCallback cb) 2054 throws RemoteException { 2055 cb.onValues(mStatusSuccess, mSupplicantVariables.eapCACert); 2056 } 2057 }).when(mISupplicantStaNetworkMock) 2058 .getEapCACert(any(ISupplicantStaNetwork.getEapCACertCallback.class)); 2059 2060 /** EAP Subject Match */ 2061 doAnswer(new AnswerWithArguments() { 2062 public SupplicantStatus answer(String match) throws RemoteException { 2063 mSupplicantVariables.eapSubjectMatch = match; 2064 return mStatusSuccess; 2065 } 2066 }).when(mISupplicantStaNetworkMock).setEapSubjectMatch(any(String.class)); 2067 doAnswer(new AnswerWithArguments() { 2068 public void answer(ISupplicantStaNetwork.getEapSubjectMatchCallback cb) 2069 throws RemoteException { 2070 cb.onValues(mStatusSuccess, mSupplicantVariables.eapSubjectMatch); 2071 } 2072 }).when(mISupplicantStaNetworkMock) 2073 .getEapSubjectMatch(any(ISupplicantStaNetwork.getEapSubjectMatchCallback.class)); 2074 2075 /** EAP Engine */ 2076 doAnswer(new AnswerWithArguments() { 2077 public SupplicantStatus answer(boolean enable) throws RemoteException { 2078 mSupplicantVariables.eapEngine = enable; 2079 return mStatusSuccess; 2080 } 2081 }).when(mISupplicantStaNetworkMock).setEapEngine(any(boolean.class)); 2082 doAnswer(new AnswerWithArguments() { 2083 public void answer(ISupplicantStaNetwork.getEapEngineCallback cb) 2084 throws RemoteException { 2085 cb.onValues(mStatusSuccess, mSupplicantVariables.eapEngine); 2086 } 2087 }).when(mISupplicantStaNetworkMock) 2088 .getEapEngine(any(ISupplicantStaNetwork.getEapEngineCallback.class)); 2089 2090 /** EAP Engine ID */ 2091 doAnswer(new AnswerWithArguments() { 2092 public SupplicantStatus answer(String id) throws RemoteException { 2093 mSupplicantVariables.eapEngineID = id; 2094 return mStatusSuccess; 2095 } 2096 }).when(mISupplicantStaNetworkMock).setEapEngineID(any(String.class)); 2097 doAnswer(new AnswerWithArguments() { 2098 public void answer(ISupplicantStaNetwork.getEapEngineIDCallback cb) 2099 throws RemoteException { 2100 cb.onValues(mStatusSuccess, mSupplicantVariables.eapEngineID); 2101 } 2102 }).when(mISupplicantStaNetworkMock) 2103 .getEapEngineID(any(ISupplicantStaNetwork.getEapEngineIDCallback.class)); 2104 2105 /** EAP Private Key */ 2106 doAnswer(new AnswerWithArguments() { 2107 public SupplicantStatus answer(String key) throws RemoteException { 2108 mSupplicantVariables.eapPrivateKeyId = key; 2109 return mStatusSuccess; 2110 } 2111 }).when(mISupplicantStaNetworkMock).setEapPrivateKeyId(any(String.class)); 2112 doAnswer(new AnswerWithArguments() { 2113 public void answer(ISupplicantStaNetwork.getEapPrivateKeyIdCallback cb) 2114 throws RemoteException { 2115 cb.onValues(mStatusSuccess, mSupplicantVariables.eapPrivateKeyId); 2116 } 2117 }).when(mISupplicantStaNetworkMock) 2118 .getEapPrivateKeyId(any(ISupplicantStaNetwork.getEapPrivateKeyIdCallback.class)); 2119 2120 /** EAP Alt Subject Match */ 2121 doAnswer(new AnswerWithArguments() { 2122 public SupplicantStatus answer(String match) throws RemoteException { 2123 mSupplicantVariables.eapAltSubjectMatch = match; 2124 return mStatusSuccess; 2125 } 2126 }).when(mISupplicantStaNetworkMock).setEapAltSubjectMatch(any(String.class)); 2127 doAnswer(new AnswerWithArguments() { 2128 public void answer(ISupplicantStaNetwork.getEapAltSubjectMatchCallback cb) 2129 throws RemoteException { 2130 cb.onValues(mStatusSuccess, mSupplicantVariables.eapAltSubjectMatch); 2131 } 2132 }).when(mISupplicantStaNetworkMock) 2133 .getEapAltSubjectMatch( 2134 any(ISupplicantStaNetwork.getEapAltSubjectMatchCallback.class)); 2135 2136 /** EAP Domain Suffix Match */ 2137 doAnswer(new AnswerWithArguments() { 2138 public SupplicantStatus answer(String match) throws RemoteException { 2139 mSupplicantVariables.eapDomainSuffixMatch = match; 2140 return mStatusSuccess; 2141 } 2142 }).when(mISupplicantStaNetworkMock).setEapDomainSuffixMatch(any(String.class)); 2143 doAnswer(new AnswerWithArguments() { 2144 public void answer(ISupplicantStaNetwork.getEapDomainSuffixMatchCallback cb) 2145 throws RemoteException { 2146 cb.onValues(mStatusSuccess, mSupplicantVariables.eapDomainSuffixMatch); 2147 } 2148 }).when(mISupplicantStaNetworkMock) 2149 .getEapDomainSuffixMatch( 2150 any(ISupplicantStaNetwork.getEapDomainSuffixMatchCallback.class)); 2151 2152 /** EAP CA Path*/ 2153 doAnswer(new AnswerWithArguments() { 2154 public SupplicantStatus answer(String path) throws RemoteException { 2155 mSupplicantVariables.eapCAPath = path; 2156 return mStatusSuccess; 2157 } 2158 }).when(mISupplicantStaNetworkMock).setEapCAPath(any(String.class)); 2159 doAnswer(new AnswerWithArguments() { 2160 public void answer(ISupplicantStaNetwork.getEapCAPathCallback cb) 2161 throws RemoteException { 2162 cb.onValues(mStatusSuccess, mSupplicantVariables.eapCAPath); 2163 } 2164 }).when(mISupplicantStaNetworkMock) 2165 .getEapCAPath(any(ISupplicantStaNetwork.getEapCAPathCallback.class)); 2166 2167 /** EAP Proactive Key Caching */ 2168 doAnswer(new AnswerWithArguments() { 2169 public SupplicantStatus answer(boolean enable) throws RemoteException { 2170 mSupplicantVariables.eapProactiveKeyCaching = enable; 2171 return mStatusSuccess; 2172 } 2173 }).when(mISupplicantStaNetworkMock).setProactiveKeyCaching(any(boolean.class)); 2174 2175 /** Callback registration */ 2176 doAnswer(new AnswerWithArguments() { 2177 public SupplicantStatus answer(ISupplicantStaNetworkCallback cb) 2178 throws RemoteException { 2179 mISupplicantStaNetworkCallback = cb; 2180 return mStatusSuccess; 2181 } 2182 }).when(mISupplicantStaNetworkMock) 2183 .registerCallback(any(ISupplicantStaNetworkCallback.class)); 2184 2185 /** Callback registration */ 2186 doAnswer(new AnswerWithArguments() { 2187 public android.hardware.wifi.supplicant.V1_4.SupplicantStatus answer( 2188 android.hardware.wifi.supplicant.V1_4 2189 .ISupplicantStaNetworkCallback cb) 2190 throws RemoteException { 2191 mISupplicantStaNetworkCallbackV14 = cb; 2192 return mStatusSuccessV14; 2193 } 2194 }).when(mISupplicantStaNetworkV14) 2195 .registerCallback_1_4(any( 2196 android.hardware.wifi.supplicant.V1_4 2197 .ISupplicantStaNetworkCallback.class)); 2198 2199 /** Suite-B*/ 2200 doAnswer(new AnswerWithArguments() { 2201 public SupplicantStatus answer(boolean enable) throws RemoteException { 2202 return mStatusSuccess; 2203 } 2204 }).when(mISupplicantStaNetworkV12).enableTlsSuiteBEapPhase1Param(any(boolean.class)); 2205 2206 doAnswer(new AnswerWithArguments() { 2207 public SupplicantStatus answer() throws RemoteException { 2208 return mStatusSuccess; 2209 } 2210 }).when(mISupplicantStaNetworkV12).enableSuiteBEapOpenSslCiphers(); 2211 2212 /** OCSP */ 2213 doAnswer(new AnswerWithArguments() { 2214 public SupplicantStatus answer(int ocsp) throws RemoteException { 2215 mSupplicantVariables.ocsp = ocsp; 2216 return mStatusSuccess; 2217 } 2218 }).when(mISupplicantStaNetworkV13).setOcsp(any(int.class)); 2219 doAnswer(new AnswerWithArguments() { 2220 public void answer( 2221 android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork.getOcspCallback cb) 2222 throws RemoteException { 2223 cb.onValues(mStatusSuccess, mSupplicantVariables.ocsp); 2224 } 2225 }).when(mISupplicantStaNetworkV13) 2226 .getOcsp(any(android.hardware.wifi.supplicant.V1_3.ISupplicantStaNetwork 2227 .getOcspCallback.class)); 2228 2229 /** PMK cache */ 2230 doAnswer(new AnswerWithArguments() { 2231 public SupplicantStatus answer(ArrayList<Byte> serializedData) throws RemoteException { 2232 mSupplicantVariables.serializedPmkCache = serializedData; 2233 return mStatusSuccess; 2234 } 2235 }).when(mISupplicantStaNetworkV13).setPmkCache(any(ArrayList.class)); 2236 2237 /** WAPI Cert */ 2238 doAnswer(new AnswerWithArguments() { 2239 public SupplicantStatus answer(String cert) throws RemoteException { 2240 mSupplicantVariables.wapiCertSuite = cert; 2241 return mStatusSuccess; 2242 } 2243 }).when(mISupplicantStaNetworkV13).setWapiCertSuite(any(String.class)); 2244 doAnswer(new AnswerWithArguments() { 2245 public void answer(android.hardware.wifi.supplicant.V1_3 2246 .ISupplicantStaNetwork.getWapiCertSuiteCallback cb) 2247 throws RemoteException { 2248 cb.onValues(mStatusSuccess, mSupplicantVariables.wapiCertSuite); 2249 } 2250 }).when(mISupplicantStaNetworkV13) 2251 .getWapiCertSuite(any(android.hardware.wifi.supplicant.V1_3 2252 .ISupplicantStaNetwork.getWapiCertSuiteCallback.class)); 2253 2254 /** EAP ERP */ 2255 doAnswer(new AnswerWithArguments() { 2256 public SupplicantStatus answer(boolean enable) throws RemoteException { 2257 mSupplicantVariables.eapErp = enable; 2258 return mStatusSuccess; 2259 } 2260 }).when(mISupplicantStaNetworkV13).setEapErp(any(boolean.class)); 2261 2262 /** setSaeH2eMode */ 2263 doAnswer(new AnswerWithArguments() { 2264 public android.hardware.wifi.supplicant.V1_4.SupplicantStatus 2265 answer(byte mode) throws RemoteException { 2266 mSupplicantVariables.saeH2eMode = mode; 2267 return mStatusSuccessV14; 2268 } 2269 }).when(mISupplicantStaNetworkV14).setSaeH2eMode(any(byte.class)); 2270 } 2271 createSupplicantStatus(int code)2272 private SupplicantStatus createSupplicantStatus(int code) { 2273 SupplicantStatus status = new SupplicantStatus(); 2274 status.code = code; 2275 return status; 2276 } 2277 2278 private android.hardware.wifi.supplicant.V1_4.SupplicantStatus createSupplicantStatusV1_4(int code)2279 createSupplicantStatusV1_4(int code) { 2280 android.hardware.wifi.supplicant.V1_4.SupplicantStatus status = 2281 new android.hardware.wifi.supplicant.V1_4.SupplicantStatus(); 2282 status.code = code; 2283 return status; 2284 } 2285 2286 /** 2287 * Need this for tests which wants to manipulate context before creating the instance. 2288 */ createSupplicantStaNetwork(SupplicantStaNetworkVersion version)2289 private void createSupplicantStaNetwork(SupplicantStaNetworkVersion version) { 2290 switch (version) { 2291 case V1_0: 2292 mSupplicantNetwork = new SupplicantStaNetworkHal( 2293 mISupplicantStaNetworkMock, IFACE_NAME, mContext, mWifiMonitor, 2294 mWifiGlobals, mAdvanceKeyMgmtFeatures); 2295 break; 2296 case V1_2: 2297 mSupplicantNetwork = new SupplicantStaNetworkHalSpyV1_2( 2298 mISupplicantStaNetworkMock, IFACE_NAME, mContext, mWifiMonitor, 2299 mWifiGlobals, mAdvanceKeyMgmtFeatures); 2300 break; 2301 case V1_3: 2302 mSupplicantNetwork = new SupplicantStaNetworkHalSpyV1_3( 2303 mISupplicantStaNetworkMock, IFACE_NAME, mContext, mWifiMonitor, 2304 mWifiGlobals, mAdvanceKeyMgmtFeatures); 2305 break; 2306 case V1_4: 2307 mSupplicantNetwork = new SupplicantStaNetworkHalSpyV1_4( 2308 mISupplicantStaNetworkMock, IFACE_NAME, mContext, mWifiMonitor, 2309 mWifiGlobals, mAdvanceKeyMgmtFeatures); 2310 break; 2311 } 2312 mSupplicantNetwork.enableVerboseLogging(true); 2313 } 2314 2315 // Private class to to store/inspect values set via the HIDL mock. 2316 private class SupplicantNetworkVariables { 2317 public ArrayList<Byte> ssid; 2318 public int networkId; 2319 public byte[/* 6 */] bssid; 2320 public int keyMgmtMask; 2321 public int protoMask; 2322 public int authAlgMask; 2323 public int groupCipherMask; 2324 public int pairwiseCipherMask; 2325 public int groupManagementCipherMask; 2326 public boolean scanSsid; 2327 public boolean requirePmf; 2328 public String idStr; 2329 public int updateIdentifier; 2330 public String pskPassphrase; 2331 public byte[] psk; 2332 public ArrayList<Byte>[] wepKey = new ArrayList[4]; 2333 public int wepTxKeyIdx; 2334 public int eapMethod = -1; 2335 public int eapPhase2Method = -1; 2336 public ArrayList<Byte> eapIdentity; 2337 public ArrayList<Byte> eapAnonymousIdentity; 2338 public ArrayList<Byte> eapPassword; 2339 public String eapCACert; 2340 public String eapCAPath; 2341 public String eapClientCert; 2342 public String eapPrivateKeyId; 2343 public String eapSubjectMatch; 2344 public String eapAltSubjectMatch; 2345 public boolean eapEngine; 2346 public String eapEngineID; 2347 public String eapDomainSuffixMatch; 2348 public boolean eapProactiveKeyCaching; 2349 public int ocsp; 2350 public ArrayList<Byte> serializedPmkCache; 2351 public String wapiCertSuite; 2352 public boolean eapErp; 2353 public byte saeH2eMode; 2354 } 2355 } 2356