From f50550926a7bddc24adf822876f35812d7d8c7be Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Tue, 7 Mar 2017 08:53:31 -0800 Subject: SupplicantStaNetworkHal: Add support for raw psk |config.preSharedKey| can either be a quoted ascii passphrase or a raw psk hexstring. Handle these 2 scenarios and call the corresponding HIDL methods. Bug: 36013886 Test: Added Unit tests Test: Connected to networks with both raw psk and passphrase. Change-Id: Ifaf31a7ce864aa0f6e86020ec5207ea8dee09205 --- .../server/wifi/SupplicantStaNetworkHalTest.java | 46 ++++++++++++++++++++-- .../server/wifi/WifiConfigurationTestUtil.java | 2 +- 2 files changed, 44 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java index 3c8425a4f..b48d2b667 100644 --- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java @@ -18,7 +18,9 @@ package com.android.server.wifi; import static org.junit.Assert.*; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.any; +import static org.mockito.Mockito.anyString; import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -91,13 +93,35 @@ public class SupplicantStaNetworkHalTest { } /** - * Tests the saving/loading of WifiConfiguration to wpa_supplicant. + * Tests the saving/loading of WifiConfiguration to wpa_supplicant with psk passphrase. */ @Test - public void testPskNetworkWifiConfigurationSaveLoad() throws Exception { + public void testPskPassphraseNetworkWifiConfigurationSaveLoad() throws Exception { WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); config.requirePMF = true; testWifiConfigurationSaveLoad(config); + verify(mISupplicantStaNetworkMock).setPskPassphrase(anyString()); + verify(mISupplicantStaNetworkMock) + .getPskPassphrase(any(ISupplicantStaNetwork.getPskPassphraseCallback.class)); + verify(mISupplicantStaNetworkMock, never()).setPsk(any(byte[].class)); + verify(mISupplicantStaNetworkMock, never()) + .getPsk(any(ISupplicantStaNetwork.getPskCallback.class)); + } + + /** + * Tests the saving/loading of WifiConfiguration to wpa_supplicant with raw psk. + */ + @Test + public void testPskNetworkWifiConfigurationSaveLoad() throws Exception { + WifiConfiguration config = WifiConfigurationTestUtil.createPskNetwork(); + config.preSharedKey = "945ef00c463c2a7c2496376b13263d1531366b46377179a4b17b393687450779"; + testWifiConfigurationSaveLoad(config); + verify(mISupplicantStaNetworkMock).setPsk(any(byte[].class)); + verify(mISupplicantStaNetworkMock) + .getPsk(any(ISupplicantStaNetwork.getPskCallback.class)); + verify(mISupplicantStaNetworkMock, never()).setPskPassphrase(anyString()); + verify(mISupplicantStaNetworkMock) + .getPskPassphrase(any(ISupplicantStaNetwork.getPskPassphraseCallback.class)); } /** @@ -824,7 +848,7 @@ public class SupplicantStaNetworkHalTest { }).when(mISupplicantStaNetworkMock) .getRequirePmf(any(ISupplicantStaNetwork.getRequirePmfCallback.class)); - /** PSK pass phrase*/ + /** PSK passphrase */ doAnswer(new AnswerWithArguments() { public SupplicantStatus answer(String pskPassphrase) throws RemoteException { mSupplicantVariables.pskPassphrase = pskPassphrase; @@ -839,6 +863,21 @@ public class SupplicantStaNetworkHalTest { }).when(mISupplicantStaNetworkMock) .getPskPassphrase(any(ISupplicantStaNetwork.getPskPassphraseCallback.class)); + /** PSK */ + doAnswer(new AnswerWithArguments() { + public SupplicantStatus answer(byte[] psk) throws RemoteException { + mSupplicantVariables.psk = psk; + return mStatusSuccess; + } + }).when(mISupplicantStaNetworkMock).setPsk(any(byte[].class)); + doAnswer(new AnswerWithArguments() { + public void answer(ISupplicantStaNetwork.getPskCallback cb) + throws RemoteException { + cb.onValues(mStatusSuccess, mSupplicantVariables.psk); + } + }).when(mISupplicantStaNetworkMock) + .getPsk(any(ISupplicantStaNetwork.getPskCallback.class)); + /** WEP keys **/ doAnswer(new AnswerWithArguments() { public SupplicantStatus answer(int keyIdx, ArrayList key) throws RemoteException { @@ -1234,6 +1273,7 @@ public class SupplicantStaNetworkHalTest { public String idStr; public int updateIdentifier; public String pskPassphrase; + public byte[] psk; public ArrayList[] wepKey = new ArrayList[4]; public int wepTxKeyIdx; public int eapMethod = -1; diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java index dba4d2f00..6b411dad5 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java @@ -61,7 +61,7 @@ public class WifiConfigurationTestUtil { public static final int TEST_NETWORK_ID = -1; public static final int TEST_UID = 5; public static final String TEST_SSID = "WifiConfigurationTestUtilSSID"; - public static final String TEST_PSK = "WifiConfigurationTestUtilPsk"; + public static final String TEST_PSK = "\"WifiConfigurationTestUtilPsk\""; public static final String[] TEST_WEP_KEYS = {"\"WifiConfigurationTestUtilWep1\"", "\"WifiConfigurationTestUtilWep2\"", "45342312ab", "45342312ab45342312ab34ac12"}; -- cgit v1.2.3 From a63ab49c1d20d7a698537b5253d172a8dffc235f Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Tue, 7 Mar 2017 09:22:00 -0800 Subject: WifiConfigManager: Add quotes back for psk For user's who lost the quotes around their ASCII psk passphrase, add them back to be backward compatible. Bug: 36008106 Test: Unit tests Test: Verified manually updating a device which had previously lost it's quotes around psk. Change-Id: I6ef8ea2059ff044ba9e57d46bb50aa5ee7dcad9b --- .../android/server/wifi/WifiConfigManagerTest.java | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index 4a2c4c288..a00458726 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -2496,6 +2496,47 @@ public class WifiConfigManagerTest { .switchUserStoreAndRead(any(WifiConfigStore.StoreFile.class)); } + /** + * Verifies the loading of networks using {@link WifiConfigManager#loadFromStore()}: + * - Adds quotes around unquoted ascii PSKs when loading form store. + * - Loads asciis quoted PSKs as they are. + * - Loads base64 encoded as they are. + */ + @Test + public void testUnquotedAsciiPassphraseLoadFromStore() throws Exception { + WifiConfiguration pskNetworkWithNoQuotes = WifiConfigurationTestUtil.createPskNetwork(); + pskNetworkWithNoQuotes.preSharedKey = "pskWithNoQuotes"; + WifiConfiguration pskNetworkWithQuotes = WifiConfigurationTestUtil.createPskNetwork(); + pskNetworkWithQuotes.preSharedKey = "\"pskWithQuotes\""; + WifiConfiguration pskNetworkWithHexString = WifiConfigurationTestUtil.createPskNetwork(); + pskNetworkWithHexString.preSharedKey = + "945ef00c463c2a7c2496376b13263d1531366b46377179a4b17b393687450779"; + + List sharedNetworks = new ArrayList() {{ + add(new WifiConfiguration(pskNetworkWithQuotes)); + add(new WifiConfiguration(pskNetworkWithNoQuotes)); + add(new WifiConfiguration(pskNetworkWithHexString)); + }}; + setupStoreDataForRead(sharedNetworks, new ArrayList<>(), new HashSet()); + assertTrue(mWifiConfigManager.loadFromStore()); + + verify(mWifiConfigStore).read(); + verify(mWifiConfigStoreLegacy, never()).read(); + + List retrievedNetworks = + mWifiConfigManager.getConfiguredNetworksWithPasswords(); + + // The network with no quotes should now have quotes, the others should remain the same. + pskNetworkWithNoQuotes.preSharedKey = "\"pskWithNoQuotes\""; + List expectedNetworks = new ArrayList() {{ + add(pskNetworkWithQuotes); + add(pskNetworkWithNoQuotes); + add(pskNetworkWithHexString); + }}; + WifiConfigurationTestUtil.assertConfigurationsEqualForConfigStore( + expectedNetworks, retrievedNetworks); + } + /** * Verifies that the last user selected network parameter is set when * {@link WifiConfigManager#enableNetwork(int, boolean, int)} with disableOthers flag is set -- cgit v1.2.3