SupplicantStaNetworkHalTest.java revision c7a4b6706fa09042bb36a64036d86d88eb6e4126
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 */ 16package com.android.server.wifi; 17 18import static org.junit.Assert.*; 19import static org.mockito.Mockito.any; 20import static org.mockito.Mockito.doAnswer; 21import static org.mockito.Mockito.when; 22 23import android.app.test.MockAnswerUtil.AnswerWithArguments; 24import android.content.Context; 25import android.hardware.wifi.supplicant.V1_0.ISupplicantNetwork; 26import android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetwork; 27import android.hardware.wifi.supplicant.V1_0.SupplicantStatus; 28import android.hardware.wifi.supplicant.V1_0.SupplicantStatusCode; 29import android.net.wifi.WifiConfiguration; 30import android.net.wifi.WifiEnterpriseConfig; 31import android.os.RemoteException; 32import android.text.TextUtils; 33 34import com.android.internal.R; 35import com.android.server.wifi.util.NativeUtil; 36 37import org.junit.Before; 38import org.junit.Test; 39import org.mockito.Mock; 40import org.mockito.MockitoAnnotations; 41 42import java.util.ArrayList; 43import java.util.HashMap; 44import java.util.Map; 45 46/** 47 * Unit tests for SupplicantStaNetworkHal 48 */ 49public class SupplicantStaNetworkHalTest { 50 private static final String TAG = "SupplicantStaNetworkHalTest"; 51 52 private SupplicantStaNetworkHal mSupplicantNetwork; 53 private SupplicantStatus mStatusSuccess; 54 private SupplicantStatus mStatusFailure; 55 @Mock private ISupplicantStaNetwork mISupplicantStaNetworkMock; 56 @Mock private Context mContext; 57 @Mock private WifiMonitor mWifiMonitor; 58 private SupplicantNetworkVariables mSupplicantVariables; 59 private MockResources mResources; 60 61 @Before 62 public void setUp() throws Exception { 63 MockitoAnnotations.initMocks(this); 64 mStatusSuccess = createSupplicantStatus(SupplicantStatusCode.SUCCESS); 65 mStatusFailure = createSupplicantStatus(SupplicantStatusCode.FAILURE_UNKNOWN); 66 mSupplicantVariables = new SupplicantNetworkVariables(); 67 setupISupplicantNetworkMock(); 68 69 mResources = new MockResources(); 70 when(mContext.getResources()).thenReturn(mResources); 71 createSupplicantStaNetwork(); 72 } 73 74 /** 75 * Tests the saving of WifiConfiguration to wpa_supplicant. 76 */ 77 @Test 78 public void testOpenNetworkWifiConfigurationSaveLoad() throws Exception { 79 WifiConfiguration config = WifiConfigurationTestUtil.createOpenHiddenNetwork(); 80 config.updateIdentifier = "45"; 81 testWifiConfigurationSaveLoad(config); 82 } 83 84 /** 85 * Tests the saving/loading of WifiConfiguration to wpa_supplicant. 86 */ 87 @Test 88 public void testPskNetworkWifiConfigurationSaveLoad() throws Exception { 89 WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); 90 config.requirePMF = true; 91 testWifiConfigurationSaveLoad(config); 92 } 93 94 /** 95 * Tests the saving/loading of WifiConfiguration to wpa_supplicant. 96 */ 97 @Test 98 public void testWepNetworkWifiConfigurationSaveLoad() throws Exception { 99 WifiConfiguration config = WifiConfigurationTestUtil.createWepHiddenNetwork(); 100 config.BSSID = "34:45:19:09:45"; 101 testWifiConfigurationSaveLoad(config); 102 } 103 104 /** 105 * Tests the saving of WifiConfiguration to wpa_supplicant. 106 */ 107 @Test 108 public void testEapPeapGtcNetworkWifiConfigurationSaveLoad() throws Exception { 109 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 110 config.enterpriseConfig = 111 WifiConfigurationTestUtil.createPEAPWifiEnterpriseConfigWithGTCPhase2(); 112 testWifiConfigurationSaveLoad(config); 113 } 114 115 /** 116 * Tests the saving of WifiConfiguration to wpa_supplicant. 117 */ 118 @Test 119 public void testEapTlsNoneNetworkWifiConfigurationSaveLoad() throws Exception { 120 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 121 config.enterpriseConfig = 122 WifiConfigurationTestUtil.createTLSWifiEnterpriseConfigWithNonePhase2(); 123 testWifiConfigurationSaveLoad(config); 124 } 125 126 /** 127 * Tests the saving of WifiConfiguration to wpa_supplicant. 128 */ 129 @Test 130 public void testEapTlsNoneClientCertNetworkWifiConfigurationSaveLoad() throws Exception { 131 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 132 config.enterpriseConfig = 133 WifiConfigurationTestUtil.createTLSWifiEnterpriseConfigWithNonePhase2(); 134 config.enterpriseConfig.setClientCertificateAlias("test_alias"); 135 testWifiConfigurationSaveLoad(config); 136 } 137 138 /** 139 * Tests the loading of network ID. 140 */ 141 @Test 142 public void testNetworkIdLoad() throws Exception { 143 WifiConfiguration config = WifiConfigurationTestUtil.createWepHiddenNetwork(); 144 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 145 146 // Modify the supplicant variable directly. 147 mSupplicantVariables.networkId = 5; 148 WifiConfiguration loadConfig = new WifiConfiguration(); 149 Map<String, String> networkExtras = new HashMap<>(); 150 assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 151 assertEquals(mSupplicantVariables.networkId, loadConfig.networkId); 152 } 153 154 /** 155 * Tests the failure to load ssid aborts the loading of network variables. 156 */ 157 @Test 158 public void testSsidLoadFailure() throws Exception { 159 WifiConfiguration config = WifiConfigurationTestUtil.createWepHiddenNetwork(); 160 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 161 162 doAnswer(new AnswerWithArguments() { 163 public void answer(ISupplicantStaNetwork.getSsidCallback cb) throws RemoteException { 164 cb.onValues(mStatusFailure, mSupplicantVariables.ssid); 165 } 166 }).when(mISupplicantStaNetworkMock) 167 .getSsid(any(ISupplicantStaNetwork.getSsidCallback.class)); 168 169 WifiConfiguration loadConfig = new WifiConfiguration(); 170 Map<String, String> networkExtras = new HashMap<>(); 171 assertFalse(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 172 } 173 174 /** 175 * Tests the failure to save ssid. 176 */ 177 @Test 178 public void testSsidSaveFailure() throws Exception { 179 WifiConfiguration config = WifiConfigurationTestUtil.createWepHiddenNetwork(); 180 181 doAnswer(new AnswerWithArguments() { 182 public SupplicantStatus answer(ArrayList<Byte> ssid) throws RemoteException { 183 return mStatusFailure; 184 } 185 }).when(mISupplicantStaNetworkMock).setSsid(any(ArrayList.class)); 186 187 assertFalse(mSupplicantNetwork.saveWifiConfiguration(config)); 188 } 189 190 /** 191 * Tests the failure to save invalid key mgmt (unknown bit set in the 192 * {@link WifiConfiguration#allowedKeyManagement} being saved). 193 */ 194 @Test 195 public void testInvalidKeyMgmtSaveFailure() throws Exception { 196 WifiConfiguration config = WifiConfigurationTestUtil.createWepHiddenNetwork(); 197 config.allowedKeyManagement.set(10); 198 try { 199 assertFalse(mSupplicantNetwork.saveWifiConfiguration(config)); 200 } catch (IllegalArgumentException e) { 201 return; 202 } 203 assertTrue(false); 204 } 205 206 /** 207 * Tests the failure to load invalid key mgmt (unkown bit set in the supplicant network key_mgmt 208 * variable read). 209 */ 210 @Test 211 public void testInvalidKeyMgmtLoadFailure() throws Exception { 212 WifiConfiguration config = WifiConfigurationTestUtil.createWepHiddenNetwork(); 213 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 214 215 // Modify the supplicant variable directly. 216 mSupplicantVariables.keyMgmtMask = 0xFFFFF; 217 WifiConfiguration loadConfig = new WifiConfiguration(); 218 Map<String, String> networkExtras = new HashMap<>(); 219 try { 220 assertFalse(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 221 } catch (IllegalArgumentException e) { 222 return; 223 } 224 assertTrue(false); 225 } 226 227 /** 228 * Tests the failure to save invalid bssid (less than 6 bytes in the 229 * {@link WifiConfiguration#BSSID} being saved). 230 */ 231 @Test 232 public void testInvalidBssidSaveFailure() throws Exception { 233 WifiConfiguration config = WifiConfigurationTestUtil.createWepHiddenNetwork(); 234 config.getNetworkSelectionStatus().setNetworkSelectionBSSID("45:34:23:12"); 235 try { 236 assertFalse(mSupplicantNetwork.saveWifiConfiguration(config)); 237 } catch (IllegalArgumentException e) { 238 return; 239 } 240 assertTrue(false); 241 } 242 243 /** 244 * Tests the failure to load invalid bssid (less than 6 bytes in the supplicant bssid variable 245 * read). 246 */ 247 @Test 248 public void testInvalidBssidLoadFailure() throws Exception { 249 WifiConfiguration config = WifiConfigurationTestUtil.createWepHiddenNetwork(); 250 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 251 252 // Modify the supplicant variable directly. 253 mSupplicantVariables.bssid = new byte[3]; 254 WifiConfiguration loadConfig = new WifiConfiguration(); 255 Map<String, String> networkExtras = new HashMap<>(); 256 try { 257 assertFalse(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 258 } catch (IllegalArgumentException e) { 259 return; 260 } 261 assertTrue(false); 262 } 263 264 /** 265 * Tests the loading of invalid ssid from wpa_supplicant. 266 */ 267 @Test 268 public void testInvalidSsidLoadFailure() throws Exception { 269 WifiConfiguration config = WifiConfigurationTestUtil.createWepHiddenNetwork(); 270 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 271 272 // Modify the supplicant variable directly. 273 mSupplicantVariables.ssid = null; 274 275 WifiConfiguration loadConfig = new WifiConfiguration(); 276 Map<String, String> networkExtras = new HashMap<>(); 277 assertFalse(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 278 } 279 280 /** 281 * Tests the loading of invalid eap method from wpa_supplicant. 282 * Invalid eap method is assumed to be a non enterprise network. So, the loading should 283 * succeed as a non-enterprise network. 284 */ 285 @Test 286 public void testInvalidEapMethodLoadFailure() throws Exception { 287 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 288 config.enterpriseConfig = 289 WifiConfigurationTestUtil.createPEAPWifiEnterpriseConfigWithGTCPhase2(); 290 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 291 292 // Modify the supplicant variable directly. 293 mSupplicantVariables.eapMethod = -1; 294 295 WifiConfiguration loadConfig = new WifiConfiguration(); 296 Map<String, String> networkExtras = new HashMap<>(); 297 assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 298 } 299 300 /** 301 * Tests the loading of invalid eap phase2 method from wpa_supplicant. 302 */ 303 @Test 304 public void testInvalidEapPhase2MethodLoadFailure() throws Exception { 305 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 306 config.enterpriseConfig = 307 WifiConfigurationTestUtil.createPEAPWifiEnterpriseConfigWithGTCPhase2(); 308 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 309 310 // Modify the supplicant variable directly. 311 mSupplicantVariables.eapPhase2Method = -1; 312 313 WifiConfiguration loadConfig = new WifiConfiguration(); 314 Map<String, String> networkExtras = new HashMap<>(); 315 assertFalse(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 316 } 317 318 /** 319 * Tests the parsing of GSM auth response parameters. 320 */ 321 @Test 322 public void testSendNetworkEapSimGsmAuthResponseWith2KcSresPair() throws Exception { 323 final byte[] kc = new byte[]{0x45, 0x45, 0x32, 0x34, 0x45, 0x10, 0x34, 0x12}; 324 final byte[] sres = new byte[]{0x12, 0x10, 0x32, 0x23}; 325 // Send 2 kc/sres pair for this request. 326 String paramsStr = ":kc:" + NativeUtil.hexStringFromByteArray(kc) 327 + ":sres:" + NativeUtil.hexStringFromByteArray(sres) 328 + ":kc:" + NativeUtil.hexStringFromByteArray(kc) 329 + ":sres:" + NativeUtil.hexStringFromByteArray(sres); 330 331 doAnswer(new AnswerWithArguments() { 332 public SupplicantStatus answer( 333 ArrayList<ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams> params) 334 throws RemoteException { 335 assertEquals(2, params.size()); 336 assertArrayEquals(kc, params.get(0).kc); 337 assertArrayEquals(sres, params.get(0).sres); 338 assertArrayEquals(kc, params.get(1).kc); 339 assertArrayEquals(sres, params.get(1).sres); 340 return mStatusSuccess; 341 } 342 }).when(mISupplicantStaNetworkMock).sendNetworkEapSimGsmAuthResponse(any(ArrayList.class)); 343 344 assertTrue(mSupplicantNetwork.sendNetworkEapSimGsmAuthResponse(paramsStr)); 345 } 346 347 /** 348 * Tests the parsing of GSM auth response parameters. 349 */ 350 @Test 351 public void testSendNetworkEapSimGsmAuthResponseWith3KcSresPair() throws Exception { 352 final byte[] kc1 = new byte[]{0x45, 0x45, 0x32, 0x34, 0x45, 0x10, 0x34, 0x12}; 353 final byte[] sres1 = new byte[]{0x12, 0x10, 0x32, 0x23}; 354 final byte[] kc2 = new byte[]{0x45, 0x34, 0x12, 0x34, 0x45, 0x10, 0x34, 0x12}; 355 final byte[] sres2 = new byte[]{0x12, 0x23, 0x12, 0x23}; 356 final byte[] kc3 = new byte[]{0x25, 0x34, 0x12, 0x14, 0x45, 0x10, 0x34, 0x12}; 357 final byte[] sres3 = new byte[]{0x42, 0x23, 0x22, 0x23}; 358 // Send 3 kc/sres pair for this request. 359 String paramsStr = ":kc:" + NativeUtil.hexStringFromByteArray(kc1) 360 + ":sres:" + NativeUtil.hexStringFromByteArray(sres1) 361 + ":kc:" + NativeUtil.hexStringFromByteArray(kc2) 362 + ":sres:" + NativeUtil.hexStringFromByteArray(sres2) 363 + ":kc:" + NativeUtil.hexStringFromByteArray(kc3) 364 + ":sres:" + NativeUtil.hexStringFromByteArray(sres3); 365 366 doAnswer(new AnswerWithArguments() { 367 public SupplicantStatus answer( 368 ArrayList<ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams> params) 369 throws RemoteException { 370 assertEquals(3, params.size()); 371 assertArrayEquals(kc1, params.get(0).kc); 372 assertArrayEquals(sres1, params.get(0).sres); 373 assertArrayEquals(kc2, params.get(1).kc); 374 assertArrayEquals(sres2, params.get(1).sres); 375 assertArrayEquals(kc3, params.get(2).kc); 376 assertArrayEquals(sres3, params.get(2).sres); 377 return mStatusSuccess; 378 } 379 }).when(mISupplicantStaNetworkMock).sendNetworkEapSimGsmAuthResponse(any(ArrayList.class)); 380 381 assertTrue(mSupplicantNetwork.sendNetworkEapSimGsmAuthResponse(paramsStr)); 382 } 383 384 /** 385 * Tests the parsing of invalid GSM auth response parameters (invalid kc & sres lengths). 386 */ 387 @Test 388 public void testSendInvalidKcSresLenNetworkEapSimGsmAuthResponse() throws Exception { 389 final byte[] kc1 = new byte[]{0x45, 0x45, 0x32, 0x34, 0x45, 0x10, 0x34}; 390 final byte[] sres1 = new byte[]{0x12, 0x10, 0x23}; 391 final byte[] kc2 = new byte[]{0x45, 0x34, 0x12, 0x34, 0x45, 0x10, 0x34, 0x12}; 392 final byte[] sres2 = new byte[]{0x12, 0x23, 0x12, 0x23}; 393 // Send 2 kc/sres pair for this request. 394 String paramsStr = ":kc:" + NativeUtil.hexStringFromByteArray(kc1) 395 + ":sres:" + NativeUtil.hexStringFromByteArray(sres1) 396 + ":kc:" + NativeUtil.hexStringFromByteArray(kc2) 397 + ":sres:" + NativeUtil.hexStringFromByteArray(sres2); 398 399 doAnswer(new AnswerWithArguments() { 400 public SupplicantStatus answer( 401 ArrayList<ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams> params) 402 throws RemoteException { 403 return mStatusSuccess; 404 } 405 }).when(mISupplicantStaNetworkMock).sendNetworkEapSimGsmAuthResponse(any(ArrayList.class)); 406 407 assertFalse(mSupplicantNetwork.sendNetworkEapSimGsmAuthResponse(paramsStr)); 408 } 409 410 /** 411 * Tests the parsing of invalid GSM auth response parameters (invalid number of kc/sres pairs). 412 */ 413 @Test 414 public void testSendInvalidKcSresPairNumNetworkEapSimGsmAuthResponse() throws Exception { 415 final byte[] kc = new byte[]{0x45, 0x34, 0x12, 0x34, 0x45, 0x10, 0x34, 0x12}; 416 final byte[] sres = new byte[]{0x12, 0x23, 0x12, 0x23}; 417 // Send 1 kc/sres pair for this request. 418 String paramsStr = ":kc:" + NativeUtil.hexStringFromByteArray(kc) 419 + ":sres:" + NativeUtil.hexStringFromByteArray(sres); 420 421 doAnswer(new AnswerWithArguments() { 422 public SupplicantStatus answer( 423 ArrayList<ISupplicantStaNetwork.NetworkResponseEapSimGsmAuthParams> params) 424 throws RemoteException { 425 return mStatusSuccess; 426 } 427 }).when(mISupplicantStaNetworkMock).sendNetworkEapSimGsmAuthResponse(any(ArrayList.class)); 428 429 assertFalse(mSupplicantNetwork.sendNetworkEapSimGsmAuthResponse(paramsStr)); 430 } 431 432 /** 433 * Tests the parsing of UMTS auth response parameters. 434 */ 435 @Test 436 public void testSendNetworkEapSimUmtsAuthResponse() throws Exception { 437 final byte[] ik = new byte[]{0x45, 0x45, 0x32, 0x34, 0x45, 0x10, 0x34, 0x12, 0x23, 0x34, 438 0x33, 0x23, 0x34, 0x10, 0x40, 0x34}; 439 final byte[] ck = new byte[]{0x12, 0x10, 0x32, 0x23, 0x45, 0x10, 0x34, 0x12, 0x23, 0x34, 440 0x33, 0x23, 0x34, 0x10, 0x40, 0x34}; 441 final byte[] res = new byte[]{0x12, 0x10, 0x32, 0x23, 0x45, 0x10, 0x34, 0x12, 0x23, 0x34}; 442 String paramsStr = ":ik:" + NativeUtil.hexStringFromByteArray(ik) 443 + ":ck:" + NativeUtil.hexStringFromByteArray(ck) 444 + ":res:" + NativeUtil.hexStringFromByteArray(res); 445 446 doAnswer(new AnswerWithArguments() { 447 public SupplicantStatus answer( 448 ISupplicantStaNetwork.NetworkResponseEapSimUmtsAuthParams params) 449 throws RemoteException { 450 assertArrayEquals(ik, params.ik); 451 assertArrayEquals(ck, params.ck); 452 // Convert to arraylist before comparison. 453 ArrayList<Byte> resList = new ArrayList<>(); 454 for (byte b : res) { 455 resList.add(b); 456 } 457 assertEquals(resList, params.res); 458 return mStatusSuccess; 459 } 460 }).when(mISupplicantStaNetworkMock).sendNetworkEapSimUmtsAuthResponse( 461 any(ISupplicantStaNetwork.NetworkResponseEapSimUmtsAuthParams.class)); 462 463 assertTrue(mSupplicantNetwork.sendNetworkEapSimUmtsAuthResponse(paramsStr)); 464 } 465 466 /** 467 * Tests the parsing of invalid UMTS auth response parameters (invalid ik, ck lengths). 468 */ 469 @Test 470 public void testSendInvalidNetworkEapSimUmtsAuthResponse() throws Exception { 471 final byte[] ik = new byte[]{0x45, 0x45, 0x32, 0x34, 0x45, 0x10, 0x34, 0x12}; 472 final byte[] ck = new byte[]{0x12, 0x10, 0x32, 0x23, 0x45, 0x10, 0x34, 0x12, 0x23, 0x34, 473 0x33, 0x23, 0x34, 0x10, 0x40}; 474 final byte[] res = new byte[]{0x12, 0x10, 0x32, 0x23, 0x45, 0x10, 0x34, 0x12, 0x23, 0x34}; 475 String paramsStr = ":ik:" + NativeUtil.hexStringFromByteArray(ik) 476 + ":ck:" + NativeUtil.hexStringFromByteArray(ck) 477 + ":res:" + NativeUtil.hexStringFromByteArray(res); 478 479 doAnswer(new AnswerWithArguments() { 480 public SupplicantStatus answer( 481 ISupplicantStaNetwork.NetworkResponseEapSimUmtsAuthParams params) 482 throws RemoteException { 483 return mStatusSuccess; 484 } 485 }).when(mISupplicantStaNetworkMock).sendNetworkEapSimUmtsAuthResponse( 486 any(ISupplicantStaNetwork.NetworkResponseEapSimUmtsAuthParams.class)); 487 488 assertFalse(mSupplicantNetwork.sendNetworkEapSimUmtsAuthResponse(paramsStr)); 489 } 490 491 /** 492 * Tests the parsing of UMTS auts response parameters. 493 */ 494 @Test 495 public void testSendNetworkEapSimUmtsAutsResponse() throws Exception { 496 final byte[] auts = new byte[]{0x45, 0x45, 0x32, 0x34, 0x45, 0x10, 0x34, 0x12, 0x23, 0x34, 497 0x33, 0x23, 0x34, 0x10}; 498 String paramsStr = ":" + NativeUtil.hexStringFromByteArray(auts); 499 500 doAnswer(new AnswerWithArguments() { 501 public SupplicantStatus answer(byte[] params) 502 throws RemoteException { 503 assertArrayEquals(auts, params); 504 return mStatusSuccess; 505 } 506 }).when(mISupplicantStaNetworkMock).sendNetworkEapSimUmtsAutsResponse(any(byte[].class)); 507 508 assertTrue(mSupplicantNetwork.sendNetworkEapSimUmtsAutsResponse(paramsStr)); 509 } 510 511 /** 512 * Tests the parsing of invalid UMTS auts response parameters (invalid auts length). 513 */ 514 @Test 515 public void testSendInvalidNetworkEapSimUmtsAutsResponse() throws Exception { 516 final byte[] auts = new byte[]{0x45, 0x45, 0x32, 0x34, 0x45, 0x10, 0x34, 0x12, 0x23}; 517 String paramsStr = ":" + NativeUtil.hexStringFromByteArray(auts); 518 519 doAnswer(new AnswerWithArguments() { 520 public SupplicantStatus answer(byte[] params) 521 throws RemoteException { 522 assertArrayEquals(auts, params); 523 return mStatusSuccess; 524 } 525 }).when(mISupplicantStaNetworkMock).sendNetworkEapSimUmtsAutsResponse(any(byte[].class)); 526 527 assertFalse(mSupplicantNetwork.sendNetworkEapSimUmtsAutsResponse(paramsStr)); 528 } 529 530 /** 531 * Tests the parsing of identity string. 532 */ 533 @Test 534 public void testSendNetworkEapIdentityResponse() throws Exception { 535 final String identityStr = "test@test.com"; 536 537 doAnswer(new AnswerWithArguments() { 538 public SupplicantStatus answer(ArrayList<Byte> identity) 539 throws RemoteException { 540 assertEquals(identityStr, NativeUtil.stringFromByteArrayList(identity)); 541 return mStatusSuccess; 542 } 543 }).when(mISupplicantStaNetworkMock).sendNetworkEapIdentityResponse(any(ArrayList.class)); 544 545 assertTrue(mSupplicantNetwork.sendNetworkEapIdentityResponse(identityStr)); 546 } 547 548 /** 549 * Tests the addition of FT flags when the device supports it. 550 */ 551 @Test 552 public void testAddFtPskFlags() throws Exception { 553 mResources.setBoolean(R.bool.config_wifi_fast_bss_transition_enabled, true); 554 createSupplicantStaNetwork(); 555 556 WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); 557 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 558 559 // Check the supplicant variables to ensure that we have added the FT flags. 560 assertTrue((mSupplicantVariables.keyMgmtMask & ISupplicantStaNetwork.KeyMgmtMask.FT_PSK) 561 == ISupplicantStaNetwork.KeyMgmtMask.FT_PSK); 562 563 WifiConfiguration loadConfig = new WifiConfiguration(); 564 Map<String, String> networkExtras = new HashMap<>(); 565 assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 566 // The FT flags should be stripped out when reading it back. 567 WifiConfigurationTestUtil.assertConfigurationEqualForSupplicant(config, loadConfig); 568 } 569 570 /** 571 * Tests the addition of FT flags when the device supports it. 572 */ 573 @Test 574 public void testAddFtEapFlags() throws Exception { 575 mResources.setBoolean(R.bool.config_wifi_fast_bss_transition_enabled, true); 576 createSupplicantStaNetwork(); 577 578 WifiConfiguration config = WifiConfigurationTestUtil.createEapNetwork(); 579 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 580 581 // Check the supplicant variables to ensure that we have added the FT flags. 582 assertTrue((mSupplicantVariables.keyMgmtMask & ISupplicantStaNetwork.KeyMgmtMask.FT_EAP) 583 == ISupplicantStaNetwork.KeyMgmtMask.FT_EAP); 584 585 WifiConfiguration loadConfig = new WifiConfiguration(); 586 Map<String, String> networkExtras = new HashMap<>(); 587 assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 588 // The FT flags should be stripped out when reading it back. 589 WifiConfigurationTestUtil.assertConfigurationEqualForSupplicant(config, loadConfig); 590 } 591 592 private void testWifiConfigurationSaveLoad(WifiConfiguration config) { 593 assertTrue(mSupplicantNetwork.saveWifiConfiguration(config)); 594 WifiConfiguration loadConfig = new WifiConfiguration(); 595 Map<String, String> networkExtras = new HashMap<>(); 596 assertTrue(mSupplicantNetwork.loadWifiConfiguration(loadConfig, networkExtras)); 597 WifiConfigurationTestUtil.assertConfigurationEqualForSupplicant(config, loadConfig); 598 assertEquals(config.configKey(), 599 networkExtras.get(SupplicantStaNetworkHal.ID_STRING_KEY_CONFIG_KEY)); 600 assertEquals( 601 config.creatorUid, 602 Integer.parseInt(networkExtras.get( 603 SupplicantStaNetworkHal.ID_STRING_KEY_CREATOR_UID))); 604 // There is no getter for this one, so check the supplicant variable. 605 if (!TextUtils.isEmpty(config.updateIdentifier)) { 606 assertEquals(Integer.parseInt(config.updateIdentifier), 607 mSupplicantVariables.updateIdentifier); 608 } 609 // There is no getter for this one, so check the supplicant variable. 610 String oppKeyCaching = 611 config.enterpriseConfig.getFieldValue(WifiEnterpriseConfig.OPP_KEY_CACHING); 612 if (!TextUtils.isEmpty(oppKeyCaching)) { 613 assertEquals( 614 Integer.parseInt(oppKeyCaching) == 1 ? true : false, 615 mSupplicantVariables.eapProactiveKeyCaching); 616 } 617 } 618 619 /** 620 * Sets up the HIDL interface mock with all the setters/getter values. 621 * Note: This only sets up the mock to return success on all methods. 622 */ 623 private void setupISupplicantNetworkMock() throws Exception { 624 /** SSID */ 625 doAnswer(new AnswerWithArguments() { 626 public SupplicantStatus answer(ArrayList<Byte> ssid) throws RemoteException { 627 mSupplicantVariables.ssid = ssid; 628 return mStatusSuccess; 629 } 630 }).when(mISupplicantStaNetworkMock).setSsid(any(ArrayList.class)); 631 doAnswer(new AnswerWithArguments() { 632 public void answer(ISupplicantStaNetwork.getSsidCallback cb) throws RemoteException { 633 cb.onValues(mStatusSuccess, mSupplicantVariables.ssid); 634 } 635 }).when(mISupplicantStaNetworkMock) 636 .getSsid(any(ISupplicantStaNetwork.getSsidCallback.class)); 637 638 /** Network Id */ 639 doAnswer(new AnswerWithArguments() { 640 public void answer(ISupplicantNetwork.getIdCallback cb) throws RemoteException { 641 cb.onValues(mStatusSuccess, mSupplicantVariables.networkId); 642 } 643 }).when(mISupplicantStaNetworkMock).getId(any(ISupplicantNetwork.getIdCallback.class)); 644 645 /** BSSID */ 646 doAnswer(new AnswerWithArguments() { 647 public SupplicantStatus answer(byte[] bssid) throws RemoteException { 648 mSupplicantVariables.bssid = bssid; 649 return mStatusSuccess; 650 } 651 }).when(mISupplicantStaNetworkMock).setBssid(any(byte[].class)); 652 doAnswer(new AnswerWithArguments() { 653 public void answer(ISupplicantStaNetwork.getBssidCallback cb) throws RemoteException { 654 cb.onValues(mStatusSuccess, mSupplicantVariables.bssid); 655 } 656 }).when(mISupplicantStaNetworkMock) 657 .getBssid(any(ISupplicantStaNetwork.getBssidCallback.class)); 658 659 /** Scan SSID (Is Hidden Network?) */ 660 doAnswer(new AnswerWithArguments() { 661 public SupplicantStatus answer(boolean enable) throws RemoteException { 662 mSupplicantVariables.scanSsid = enable; 663 return mStatusSuccess; 664 } 665 }).when(mISupplicantStaNetworkMock).setScanSsid(any(boolean.class)); 666 doAnswer(new AnswerWithArguments() { 667 public void answer(ISupplicantStaNetwork.getScanSsidCallback cb) 668 throws RemoteException { 669 cb.onValues(mStatusSuccess, mSupplicantVariables.scanSsid); 670 } 671 }).when(mISupplicantStaNetworkMock) 672 .getScanSsid(any(ISupplicantStaNetwork.getScanSsidCallback.class)); 673 674 /** Require PMF*/ 675 doAnswer(new AnswerWithArguments() { 676 public SupplicantStatus answer(boolean enable) throws RemoteException { 677 mSupplicantVariables.requirePmf = enable; 678 return mStatusSuccess; 679 } 680 }).when(mISupplicantStaNetworkMock).setRequirePmf(any(boolean.class)); 681 doAnswer(new AnswerWithArguments() { 682 public void answer(ISupplicantStaNetwork.getRequirePmfCallback cb) 683 throws RemoteException { 684 cb.onValues(mStatusSuccess, mSupplicantVariables.requirePmf); 685 } 686 }).when(mISupplicantStaNetworkMock) 687 .getRequirePmf(any(ISupplicantStaNetwork.getRequirePmfCallback.class)); 688 689 /** PSK pass phrase*/ 690 doAnswer(new AnswerWithArguments() { 691 public SupplicantStatus answer(String pskPassphrase) throws RemoteException { 692 mSupplicantVariables.pskPassphrase = pskPassphrase; 693 return mStatusSuccess; 694 } 695 }).when(mISupplicantStaNetworkMock).setPskPassphrase(any(String.class)); 696 doAnswer(new AnswerWithArguments() { 697 public void answer(ISupplicantStaNetwork.getPskPassphraseCallback cb) 698 throws RemoteException { 699 cb.onValues(mStatusSuccess, mSupplicantVariables.pskPassphrase); 700 } 701 }).when(mISupplicantStaNetworkMock) 702 .getPskPassphrase(any(ISupplicantStaNetwork.getPskPassphraseCallback.class)); 703 704 /** WEP keys **/ 705 doAnswer(new AnswerWithArguments() { 706 public SupplicantStatus answer(int keyIdx, ArrayList<Byte> key) throws RemoteException { 707 mSupplicantVariables.wepKey[keyIdx] = key; 708 return mStatusSuccess; 709 } 710 }).when(mISupplicantStaNetworkMock).setWepKey(any(int.class), any(ArrayList.class)); 711 doAnswer(new AnswerWithArguments() { 712 public void answer(int keyIdx, ISupplicantStaNetwork.getWepKeyCallback cb) 713 throws RemoteException { 714 cb.onValues(mStatusSuccess, mSupplicantVariables.wepKey[keyIdx]); 715 } 716 }).when(mISupplicantStaNetworkMock) 717 .getWepKey(any(int.class), any(ISupplicantStaNetwork.getWepKeyCallback.class)); 718 719 doAnswer(new AnswerWithArguments() { 720 public SupplicantStatus answer(int keyIdx) throws RemoteException { 721 mSupplicantVariables.wepTxKeyIdx = keyIdx; 722 return mStatusSuccess; 723 } 724 }).when(mISupplicantStaNetworkMock).setWepTxKeyIdx(any(int.class)); 725 doAnswer(new AnswerWithArguments() { 726 public void answer(ISupplicantStaNetwork.getWepTxKeyIdxCallback cb) 727 throws RemoteException { 728 cb.onValues(mStatusSuccess, mSupplicantVariables.wepTxKeyIdx); 729 } 730 }).when(mISupplicantStaNetworkMock) 731 .getWepTxKeyIdx(any(ISupplicantStaNetwork.getWepTxKeyIdxCallback.class)); 732 733 /** allowedKeyManagement */ 734 doAnswer(new AnswerWithArguments() { 735 public SupplicantStatus answer(int mask) throws RemoteException { 736 mSupplicantVariables.keyMgmtMask = mask; 737 return mStatusSuccess; 738 } 739 }).when(mISupplicantStaNetworkMock).setKeyMgmt(any(int.class)); 740 doAnswer(new AnswerWithArguments() { 741 public void answer(ISupplicantStaNetwork.getKeyMgmtCallback cb) throws RemoteException { 742 cb.onValues(mStatusSuccess, mSupplicantVariables.keyMgmtMask); 743 } 744 }).when(mISupplicantStaNetworkMock) 745 .getKeyMgmt(any(ISupplicantStaNetwork.getKeyMgmtCallback.class)); 746 747 /** allowedProtocols */ 748 doAnswer(new AnswerWithArguments() { 749 public SupplicantStatus answer(int mask) throws RemoteException { 750 mSupplicantVariables.protoMask = mask; 751 return mStatusSuccess; 752 } 753 }).when(mISupplicantStaNetworkMock).setProto(any(int.class)); 754 doAnswer(new AnswerWithArguments() { 755 public void answer(ISupplicantStaNetwork.getProtoCallback cb) throws RemoteException { 756 cb.onValues(mStatusSuccess, mSupplicantVariables.protoMask); 757 } 758 }).when(mISupplicantStaNetworkMock) 759 .getProto(any(ISupplicantStaNetwork.getProtoCallback.class)); 760 761 /** allowedAuthAlgorithms */ 762 doAnswer(new AnswerWithArguments() { 763 public SupplicantStatus answer(int mask) throws RemoteException { 764 mSupplicantVariables.authAlgMask = mask; 765 return mStatusSuccess; 766 } 767 }).when(mISupplicantStaNetworkMock).setAuthAlg(any(int.class)); 768 doAnswer(new AnswerWithArguments() { 769 public void answer(ISupplicantStaNetwork.getAuthAlgCallback cb) throws RemoteException { 770 cb.onValues(mStatusSuccess, mSupplicantVariables.authAlgMask); 771 } 772 }).when(mISupplicantStaNetworkMock) 773 .getAuthAlg(any(ISupplicantStaNetwork.getAuthAlgCallback.class)); 774 775 /** allowedGroupCiphers */ 776 doAnswer(new AnswerWithArguments() { 777 public SupplicantStatus answer(int mask) throws RemoteException { 778 mSupplicantVariables.groupCipherMask = mask; 779 return mStatusSuccess; 780 } 781 }).when(mISupplicantStaNetworkMock).setGroupCipher(any(int.class)); 782 doAnswer(new AnswerWithArguments() { 783 public void answer(ISupplicantStaNetwork.getGroupCipherCallback cb) 784 throws RemoteException { 785 cb.onValues(mStatusSuccess, mSupplicantVariables.groupCipherMask); 786 } 787 }).when(mISupplicantStaNetworkMock) 788 .getGroupCipher(any(ISupplicantStaNetwork.getGroupCipherCallback.class)); 789 790 /** allowedPairwiseCiphers */ 791 doAnswer(new AnswerWithArguments() { 792 public SupplicantStatus answer(int mask) throws RemoteException { 793 mSupplicantVariables.pairwiseCipherMask = mask; 794 return mStatusSuccess; 795 } 796 }).when(mISupplicantStaNetworkMock).setPairwiseCipher(any(int.class)); 797 doAnswer(new AnswerWithArguments() { 798 public void answer(ISupplicantStaNetwork.getPairwiseCipherCallback cb) 799 throws RemoteException { 800 cb.onValues(mStatusSuccess, mSupplicantVariables.pairwiseCipherMask); 801 } 802 }).when(mISupplicantStaNetworkMock) 803 .getPairwiseCipher(any(ISupplicantStaNetwork.getPairwiseCipherCallback.class)); 804 805 /** metadata: idstr */ 806 doAnswer(new AnswerWithArguments() { 807 public SupplicantStatus answer(String idStr) throws RemoteException { 808 mSupplicantVariables.idStr = idStr; 809 return mStatusSuccess; 810 } 811 }).when(mISupplicantStaNetworkMock).setIdStr(any(String.class)); 812 doAnswer(new AnswerWithArguments() { 813 public void answer(ISupplicantStaNetwork.getIdStrCallback cb) throws RemoteException { 814 cb.onValues(mStatusSuccess, mSupplicantVariables.idStr); 815 } 816 }).when(mISupplicantStaNetworkMock) 817 .getIdStr(any(ISupplicantStaNetwork.getIdStrCallback.class)); 818 819 /** UpdateIdentifier */ 820 doAnswer(new AnswerWithArguments() { 821 public SupplicantStatus answer(int identifier) throws RemoteException { 822 mSupplicantVariables.updateIdentifier = identifier; 823 return mStatusSuccess; 824 } 825 }).when(mISupplicantStaNetworkMock).setUpdateIdentifier(any(int.class)); 826 827 /** EAP method */ 828 doAnswer(new AnswerWithArguments() { 829 public SupplicantStatus answer(int method) throws RemoteException { 830 mSupplicantVariables.eapMethod = method; 831 return mStatusSuccess; 832 } 833 }).when(mISupplicantStaNetworkMock).setEapMethod(any(int.class)); 834 doAnswer(new AnswerWithArguments() { 835 public void answer(ISupplicantStaNetwork.getEapMethodCallback cb) 836 throws RemoteException { 837 // When not set, return failure. 838 if (mSupplicantVariables.eapMethod == -1) { 839 cb.onValues(mStatusFailure, mSupplicantVariables.eapMethod); 840 } else { 841 cb.onValues(mStatusSuccess, mSupplicantVariables.eapMethod); 842 } 843 } 844 }).when(mISupplicantStaNetworkMock) 845 .getEapMethod(any(ISupplicantStaNetwork.getEapMethodCallback.class)); 846 847 /** EAP Phase 2 method */ 848 doAnswer(new AnswerWithArguments() { 849 public SupplicantStatus answer(int method) throws RemoteException { 850 mSupplicantVariables.eapPhase2Method = method; 851 return mStatusSuccess; 852 } 853 }).when(mISupplicantStaNetworkMock).setEapPhase2Method(any(int.class)); 854 doAnswer(new AnswerWithArguments() { 855 public void answer(ISupplicantStaNetwork.getEapPhase2MethodCallback cb) 856 throws RemoteException { 857 // When not set, return failure. 858 if (mSupplicantVariables.eapPhase2Method == -1) { 859 cb.onValues(mStatusFailure, mSupplicantVariables.eapPhase2Method); 860 } else { 861 cb.onValues(mStatusSuccess, mSupplicantVariables.eapPhase2Method); 862 } 863 } 864 }).when(mISupplicantStaNetworkMock) 865 .getEapPhase2Method(any(ISupplicantStaNetwork.getEapPhase2MethodCallback.class)); 866 867 /** EAP Identity */ 868 doAnswer(new AnswerWithArguments() { 869 public SupplicantStatus answer(ArrayList<Byte> identity) throws RemoteException { 870 mSupplicantVariables.eapIdentity = identity; 871 return mStatusSuccess; 872 } 873 }).when(mISupplicantStaNetworkMock).setEapIdentity(any(ArrayList.class)); 874 doAnswer(new AnswerWithArguments() { 875 public void answer(ISupplicantStaNetwork.getEapIdentityCallback cb) 876 throws RemoteException { 877 cb.onValues(mStatusSuccess, mSupplicantVariables.eapIdentity); 878 } 879 }).when(mISupplicantStaNetworkMock) 880 .getEapIdentity(any(ISupplicantStaNetwork.getEapIdentityCallback.class)); 881 882 /** EAP Anonymous Identity */ 883 doAnswer(new AnswerWithArguments() { 884 public SupplicantStatus answer(ArrayList<Byte> identity) throws RemoteException { 885 mSupplicantVariables.eapAnonymousIdentity = identity; 886 return mStatusSuccess; 887 } 888 }).when(mISupplicantStaNetworkMock).setEapAnonymousIdentity(any(ArrayList.class)); 889 doAnswer(new AnswerWithArguments() { 890 public void answer(ISupplicantStaNetwork.getEapAnonymousIdentityCallback cb) 891 throws RemoteException { 892 cb.onValues(mStatusSuccess, mSupplicantVariables.eapAnonymousIdentity); 893 } 894 }).when(mISupplicantStaNetworkMock) 895 .getEapAnonymousIdentity( 896 any(ISupplicantStaNetwork.getEapAnonymousIdentityCallback.class)); 897 898 /** EAP Password */ 899 doAnswer(new AnswerWithArguments() { 900 public SupplicantStatus answer(ArrayList<Byte> password) throws RemoteException { 901 mSupplicantVariables.eapPassword = password; 902 return mStatusSuccess; 903 } 904 }).when(mISupplicantStaNetworkMock).setEapPassword(any(ArrayList.class)); 905 doAnswer(new AnswerWithArguments() { 906 public void answer(ISupplicantStaNetwork.getEapPasswordCallback cb) 907 throws RemoteException { 908 cb.onValues(mStatusSuccess, mSupplicantVariables.eapPassword); 909 } 910 }).when(mISupplicantStaNetworkMock) 911 .getEapPassword(any(ISupplicantStaNetwork.getEapPasswordCallback.class)); 912 913 /** EAP Client Cert */ 914 doAnswer(new AnswerWithArguments() { 915 public SupplicantStatus answer(String cert) throws RemoteException { 916 mSupplicantVariables.eapClientCert = cert; 917 return mStatusSuccess; 918 } 919 }).when(mISupplicantStaNetworkMock).setEapClientCert(any(String.class)); 920 doAnswer(new AnswerWithArguments() { 921 public void answer(ISupplicantStaNetwork.getEapClientCertCallback cb) 922 throws RemoteException { 923 cb.onValues(mStatusSuccess, mSupplicantVariables.eapClientCert); 924 } 925 }).when(mISupplicantStaNetworkMock) 926 .getEapClientCert(any(ISupplicantStaNetwork.getEapClientCertCallback.class)); 927 928 /** EAP CA Cert */ 929 doAnswer(new AnswerWithArguments() { 930 public SupplicantStatus answer(String cert) throws RemoteException { 931 mSupplicantVariables.eapCACert = cert; 932 return mStatusSuccess; 933 } 934 }).when(mISupplicantStaNetworkMock).setEapCACert(any(String.class)); 935 doAnswer(new AnswerWithArguments() { 936 public void answer(ISupplicantStaNetwork.getEapCACertCallback cb) 937 throws RemoteException { 938 cb.onValues(mStatusSuccess, mSupplicantVariables.eapCACert); 939 } 940 }).when(mISupplicantStaNetworkMock) 941 .getEapCACert(any(ISupplicantStaNetwork.getEapCACertCallback.class)); 942 943 /** EAP Subject Match */ 944 doAnswer(new AnswerWithArguments() { 945 public SupplicantStatus answer(String match) throws RemoteException { 946 mSupplicantVariables.eapSubjectMatch = match; 947 return mStatusSuccess; 948 } 949 }).when(mISupplicantStaNetworkMock).setEapSubjectMatch(any(String.class)); 950 doAnswer(new AnswerWithArguments() { 951 public void answer(ISupplicantStaNetwork.getEapSubjectMatchCallback cb) 952 throws RemoteException { 953 cb.onValues(mStatusSuccess, mSupplicantVariables.eapSubjectMatch); 954 } 955 }).when(mISupplicantStaNetworkMock) 956 .getEapSubjectMatch(any(ISupplicantStaNetwork.getEapSubjectMatchCallback.class)); 957 958 /** EAP Engine */ 959 doAnswer(new AnswerWithArguments() { 960 public SupplicantStatus answer(boolean enable) throws RemoteException { 961 mSupplicantVariables.eapEngine = enable; 962 return mStatusSuccess; 963 } 964 }).when(mISupplicantStaNetworkMock).setEapEngine(any(boolean.class)); 965 doAnswer(new AnswerWithArguments() { 966 public void answer(ISupplicantStaNetwork.getEapEngineCallback cb) 967 throws RemoteException { 968 cb.onValues(mStatusSuccess, mSupplicantVariables.eapEngine); 969 } 970 }).when(mISupplicantStaNetworkMock) 971 .getEapEngine(any(ISupplicantStaNetwork.getEapEngineCallback.class)); 972 973 /** EAP Engine ID */ 974 doAnswer(new AnswerWithArguments() { 975 public SupplicantStatus answer(String id) throws RemoteException { 976 mSupplicantVariables.eapEngineID = id; 977 return mStatusSuccess; 978 } 979 }).when(mISupplicantStaNetworkMock).setEapEngineID(any(String.class)); 980 doAnswer(new AnswerWithArguments() { 981 public void answer(ISupplicantStaNetwork.getEapEngineIDCallback cb) 982 throws RemoteException { 983 cb.onValues(mStatusSuccess, mSupplicantVariables.eapEngineID); 984 } 985 }).when(mISupplicantStaNetworkMock) 986 .getEapEngineID(any(ISupplicantStaNetwork.getEapEngineIDCallback.class)); 987 988 /** EAP Private Key */ 989 doAnswer(new AnswerWithArguments() { 990 public SupplicantStatus answer(String key) throws RemoteException { 991 mSupplicantVariables.eapPrivateKey = key; 992 return mStatusSuccess; 993 } 994 }).when(mISupplicantStaNetworkMock).setEapPrivateKey(any(String.class)); 995 doAnswer(new AnswerWithArguments() { 996 public void answer(ISupplicantStaNetwork.getEapPrivateKeyCallback cb) 997 throws RemoteException { 998 cb.onValues(mStatusSuccess, mSupplicantVariables.eapPrivateKey); 999 } 1000 }).when(mISupplicantStaNetworkMock) 1001 .getEapPrivateKey(any(ISupplicantStaNetwork.getEapPrivateKeyCallback.class)); 1002 1003 /** EAP Alt Subject Match */ 1004 doAnswer(new AnswerWithArguments() { 1005 public SupplicantStatus answer(String match) throws RemoteException { 1006 mSupplicantVariables.eapAltSubjectMatch = match; 1007 return mStatusSuccess; 1008 } 1009 }).when(mISupplicantStaNetworkMock).setEapAltSubjectMatch(any(String.class)); 1010 doAnswer(new AnswerWithArguments() { 1011 public void answer(ISupplicantStaNetwork.getEapAltSubjectMatchCallback cb) 1012 throws RemoteException { 1013 cb.onValues(mStatusSuccess, mSupplicantVariables.eapAltSubjectMatch); 1014 } 1015 }).when(mISupplicantStaNetworkMock) 1016 .getEapAltSubjectMatch( 1017 any(ISupplicantStaNetwork.getEapAltSubjectMatchCallback.class)); 1018 1019 /** EAP Domain Suffix Match */ 1020 doAnswer(new AnswerWithArguments() { 1021 public SupplicantStatus answer(String match) throws RemoteException { 1022 mSupplicantVariables.eapDomainSuffixMatch = match; 1023 return mStatusSuccess; 1024 } 1025 }).when(mISupplicantStaNetworkMock).setEapDomainSuffixMatch(any(String.class)); 1026 doAnswer(new AnswerWithArguments() { 1027 public void answer(ISupplicantStaNetwork.getEapDomainSuffixMatchCallback cb) 1028 throws RemoteException { 1029 cb.onValues(mStatusSuccess, mSupplicantVariables.eapDomainSuffixMatch); 1030 } 1031 }).when(mISupplicantStaNetworkMock) 1032 .getEapDomainSuffixMatch( 1033 any(ISupplicantStaNetwork.getEapDomainSuffixMatchCallback.class)); 1034 1035 /** EAP CA Path*/ 1036 doAnswer(new AnswerWithArguments() { 1037 public SupplicantStatus answer(String path) throws RemoteException { 1038 mSupplicantVariables.eapCAPath = path; 1039 return mStatusSuccess; 1040 } 1041 }).when(mISupplicantStaNetworkMock).setEapCAPath(any(String.class)); 1042 doAnswer(new AnswerWithArguments() { 1043 public void answer(ISupplicantStaNetwork.getEapCAPathCallback cb) 1044 throws RemoteException { 1045 cb.onValues(mStatusSuccess, mSupplicantVariables.eapCAPath); 1046 } 1047 }).when(mISupplicantStaNetworkMock) 1048 .getEapCAPath(any(ISupplicantStaNetwork.getEapCAPathCallback.class)); 1049 1050 /** EAP Proactive Key Caching */ 1051 doAnswer(new AnswerWithArguments() { 1052 public SupplicantStatus answer(boolean enable) throws RemoteException { 1053 mSupplicantVariables.eapProactiveKeyCaching = enable; 1054 return mStatusSuccess; 1055 } 1056 }).when(mISupplicantStaNetworkMock).setProactiveKeyCaching(any(boolean.class)); 1057 } 1058 1059 private SupplicantStatus createSupplicantStatus(int code) { 1060 SupplicantStatus status = new SupplicantStatus(); 1061 status.code = code; 1062 return status; 1063 } 1064 1065 /** 1066 * Need this for tests which wants to manipulate context before creating the instance. 1067 */ 1068 private void createSupplicantStaNetwork() { 1069 mSupplicantNetwork = 1070 new SupplicantStaNetworkHal(mISupplicantStaNetworkMock, mContext, mWifiMonitor); 1071 } 1072 1073 // Private class to to store/inspect values set via the HIDL mock. 1074 private class SupplicantNetworkVariables { 1075 public ArrayList<Byte> ssid; 1076 public int networkId; 1077 public byte[/* 6 */] bssid; 1078 public int keyMgmtMask; 1079 public int protoMask; 1080 public int authAlgMask; 1081 public int groupCipherMask; 1082 public int pairwiseCipherMask; 1083 public boolean scanSsid; 1084 public boolean requirePmf; 1085 public String idStr; 1086 public int updateIdentifier; 1087 public String pskPassphrase; 1088 public ArrayList<Byte>[] wepKey = new ArrayList[4]; 1089 public int wepTxKeyIdx; 1090 public int eapMethod = -1; 1091 public int eapPhase2Method = -1; 1092 public ArrayList<Byte> eapIdentity; 1093 public ArrayList<Byte> eapAnonymousIdentity; 1094 public ArrayList<Byte> eapPassword; 1095 public String eapCACert; 1096 public String eapCAPath; 1097 public String eapClientCert; 1098 public String eapPrivateKey; 1099 public String eapSubjectMatch; 1100 public String eapAltSubjectMatch; 1101 public boolean eapEngine; 1102 public String eapEngineID; 1103 public String eapDomainSuffixMatch; 1104 public boolean eapProactiveKeyCaching; 1105 } 1106} 1107