summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJong Wook Kim <jongwook@google.com>2018-01-24 11:04:08 -0800
committerJong Wook Kim <jongwook@google.com>2018-03-09 03:03:53 -0800
commitbe1a7e114f0378bed4194f9aeb02c49cda2be29b (patch)
treeda53ea8a597c4df36ed3ccb3d8077c51f72b07b0 /tests
parent42f26dd680949e1d418d79f9cb0dc234ffd0d9ea (diff)
WifiConfigManager: Mask Randomized MAC Address
Mask out the Randomized MAC Address from WifiConfiguration object when it is being provided through public WifiManager API's. The randomized MAC address should only be used by the WifiStateMachine when connecting to a network to determine which MAC address to use. Bug: 72508588 Test: Unittest Change-Id: I6f2794a25100dc9b4b53f8a61db116ad6272405f
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java77
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java11
2 files changed, 80 insertions, 8 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index eedfef5f3..7ba8ef96e 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -1454,6 +1454,68 @@ public class WifiConfigManagerTest {
}
/**
+ * Verifies that randomized MAC address is masked out to "0:0:0:0:0:0" when we return
+ * external configs except when explicitly asked for MAC address.
+ */
+ @Test
+ public void testGetConfiguredNetworksMasksRandomizedMac() {
+ WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
+ NetworkUpdateResult result = verifyAddNetworkToWifiConfigManager(config);
+
+ MacAddress testMac = MacAddress.createRandomUnicastAddress();
+ mWifiConfigManager.setNetworkRandomizedMacAddress(result.getNetworkId(), testMac);
+
+ // Verify that randomized MAC address is masked in retrieved network configs.
+ WifiConfiguration configWithMaskedRandomizedMac = mWifiConfigManager
+ .getConfiguredNetwork(result.getNetworkId());
+ assertRandomizedMacAddressMaskedInWifiConfiguration(configWithMaskedRandomizedMac);
+
+ configWithMaskedRandomizedMac = mWifiConfigManager
+ .getConfiguredNetworkWithPassword(result.getNetworkId());
+ assertRandomizedMacAddressMaskedInWifiConfiguration(configWithMaskedRandomizedMac);
+
+ // Ensure that the MAC address is present when asked for config with MAC address.
+ WifiConfiguration configWithRandomizedMac = mWifiConfigManager
+ .getConfiguredNetworkWithoutMasking(result.getNetworkId());
+ assertEquals(testMac, configWithRandomizedMac.getRandomizedMacAddress());
+ }
+
+ /**
+ * Verifies that passwords are masked out when we return external configs except when
+ * explicitly asked for them.
+ */
+ @Test
+ public void testGetConfiguredNetworksMasksPasswords() {
+ WifiConfiguration networkWithPasswords = WifiConfigurationTestUtil.createEapNetwork();
+ networkWithPasswords.wepKeys = WifiConfigurationTestUtil.TEST_WEP_KEYS;
+ networkWithPasswords.preSharedKey = WifiConfigurationTestUtil.TEST_PSK;
+ networkWithPasswords.enterpriseConfig.setPassword(
+ WifiConfigurationTestUtil.TEST_EAP_PASSWORD);
+
+ NetworkUpdateResult result = verifyAddNetworkToWifiConfigManager(networkWithPasswords);
+
+ // All of these passwords must be masked in this retrieved network config.
+ WifiConfiguration retrievedNetworkWithMaskedPassword =
+ mWifiConfigManager.getConfiguredNetwork(result.getNetworkId());
+ assertPasswordsMaskedInWifiConfiguration(retrievedNetworkWithMaskedPassword);
+
+ // Ensure that the passwords are present when asked for configs with passwords.
+ WifiConfiguration retrievedNetworkWithPassword =
+ mWifiConfigManager.getConfiguredNetworkWithPassword(result.getNetworkId());
+ assertEquals(networkWithPasswords.preSharedKey, retrievedNetworkWithPassword.preSharedKey);
+ assertEquals(networkWithPasswords.wepKeys, retrievedNetworkWithPassword.wepKeys);
+ assertEquals(networkWithPasswords.enterpriseConfig.getPassword(),
+ retrievedNetworkWithPassword.enterpriseConfig.getPassword());
+
+ retrievedNetworkWithPassword =
+ mWifiConfigManager.getConfiguredNetworkWithoutMasking(result.getNetworkId());
+ assertEquals(networkWithPasswords.preSharedKey, retrievedNetworkWithPassword.preSharedKey);
+ assertEquals(networkWithPasswords.wepKeys, retrievedNetworkWithPassword.wepKeys);
+ assertEquals(networkWithPasswords.enterpriseConfig.getPassword(),
+ retrievedNetworkWithPassword.enterpriseConfig.getPassword());
+ }
+
+ /**
* Verifies the ordering of network list generated using
* {@link WifiConfigManager#retrievePnoNetworkList()}.
*/
@@ -3457,15 +3519,16 @@ public class WifiConfigManagerTest {
// Verify that internal randomized MAC address does not change from
// from setting external randomized MAC address
MacAddress originalMac = originalConfig.getOrCreateRandomizedMacAddress();
- WifiConfiguration retrievedConfig =
- mWifiConfigManager.getConfiguredNetwork(result.getNetworkId());
+ WifiConfiguration retrievedConfig = mWifiConfigManager
+ .getConfiguredNetworkWithoutMasking(result.getNetworkId());
assertNotEquals(originalMac, retrievedConfig.getRandomizedMacAddress());
// Verify that changing randomized MAC address through setNetworkRandomizedMacAddress
// changes the internal randomized MAC address
MacAddress newMac = MacAddress.createRandomUnicastAddress();
mWifiConfigManager.setNetworkRandomizedMacAddress(result.getNetworkId(), newMac);
- retrievedConfig = mWifiConfigManager.getConfiguredNetwork(result.getNetworkId());
+ retrievedConfig = mWifiConfigManager
+ .getConfiguredNetworkWithoutMasking(result.getNetworkId());
assertEquals(newMac, retrievedConfig.getRandomizedMacAddress());
}
@@ -3732,6 +3795,14 @@ public class WifiConfigManagerTest {
}
}
+ private void assertRandomizedMacAddressMaskedInWifiConfiguration(
+ WifiConfiguration configuration) {
+ MacAddress randomizedMacAddress = configuration.getRandomizedMacAddress();
+ if (randomizedMacAddress != null) {
+ assertEquals(MacAddress.ALL_ZEROS_ADDRESS, randomizedMacAddress);
+ }
+ }
+
/**
* Verifies that the network was present in the network change broadcast and returns the
* change reason.
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index 75e8fbc5f..bc0958785 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -891,7 +891,7 @@ public class WifiStateMachineTest {
.thenReturn(new NetworkUpdateResult(0));
when(mWifiConfigManager.getSavedNetworks()).thenReturn(Arrays.asList(config));
when(mWifiConfigManager.getConfiguredNetwork(0)).thenReturn(config);
- when(mWifiConfigManager.getConfiguredNetworkWithPassword(0)).thenReturn(config);
+ when(mWifiConfigManager.getConfiguredNetworkWithoutMasking(0)).thenReturn(config);
mLooper.startAutoDispatch();
mWsm.syncAddOrUpdateNetwork(mWsmAsyncChannel, config);
@@ -943,8 +943,8 @@ public class WifiStateMachineTest {
.thenReturn(true);
when(mWifiConfigManager.getConfiguredNetwork(eq(config.networkId)))
.thenReturn(config);
- when(mWifiConfigManager.getConfiguredNetworkWithPassword(eq(config.networkId)))
- .thenReturn(config);
+ when(mWifiConfigManager.getConfiguredNetworkWithoutMasking(
+ eq(config.networkId))).thenReturn(config);
verify(mWifiNative).removeAllNetworks(WIFI_IFACE_NAME);
verify(mScanRequestProxy).enableScanningForHiddenNetworks(true);
@@ -958,7 +958,7 @@ public class WifiStateMachineTest {
verify(mWifiConfigManager).enableNetwork(eq(config.networkId), eq(true), anyInt());
verify(mWifiConnectivityManager).setUserConnectChoice(eq(config.networkId));
verify(mWifiConnectivityManager).prepareForForcedConnection(eq(config.networkId));
- verify(mWifiConfigManager).getConfiguredNetworkWithPassword(eq(config.networkId));
+ verify(mWifiConfigManager).getConfiguredNetworkWithoutMasking(eq(config.networkId));
verify(mWifiNative).connectToNetwork(eq(WIFI_IFACE_NAME), eq(config));
}
@@ -966,7 +966,8 @@ public class WifiStateMachineTest {
verify(mWifiConfigManager).enableNetwork(eq(config.networkId), eq(true), anyInt());
verify(mWifiConnectivityManager).setUserConnectChoice(eq(config.networkId));
verify(mWifiConnectivityManager).prepareForForcedConnection(eq(config.networkId));
- verify(mWifiConfigManager, never()).getConfiguredNetworkWithPassword(eq(config.networkId));
+ verify(mWifiConfigManager, never())
+ .getConfiguredNetworkWithoutMasking(eq(config.networkId));
verify(mWifiNative, never()).connectToNetwork(eq(WIFI_IFACE_NAME), eq(config));
}