diff options
3 files changed, 97 insertions, 8 deletions
diff --git a/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java b/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java index 0507a8867..cfbbfad0e 100644 --- a/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java +++ b/service/java/com/android/server/wifi/SupplicantStaNetworkHal.java @@ -207,13 +207,6 @@ public class SupplicantStaNetworkHal { config.wepKeys[i] = NativeUtil.bytesToHexOrQuotedString(mWepKey); } } - /** PSK pass phrase */ - config.preSharedKey = null; - if (getPskPassphrase() && !TextUtils.isEmpty(mPskPassphrase)) { - config.preSharedKey = NativeUtil.addEnclosingQuotes(mPskPassphrase); - } else if (getPsk() && !ArrayUtils.isEmpty(mPsk)) { - config.preSharedKey = NativeUtil.hexStringFromByteArray(mPsk); - } /* Do not read SAE password */ /** allowedKeyManagement */ if (getKeyMgmt()) { @@ -247,6 +240,18 @@ public class SupplicantStaNetworkHal { supplicantToWifiConfigurationGroupMgmtCipherMask(mGroupMgmtCipherMask); } + /** PSK pass phrase */ + config.preSharedKey = null; + if (getPskPassphrase() && !TextUtils.isEmpty(mPskPassphrase)) { + if (config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WAPI_PSK)) { + config.preSharedKey = mPskPassphrase; + } else { + config.preSharedKey = NativeUtil.addEnclosingQuotes(mPskPassphrase); + } + } else if (getPsk() && !ArrayUtils.isEmpty(mPsk)) { + config.preSharedKey = NativeUtil.hexStringFromByteArray(mPsk); + } /* Do not read SAE password */ + /** metadata: idstr */ if (getIdStr() && !TextUtils.isEmpty(mIdStr)) { Map<String, String> metadata = parseNetworkExtra(mIdStr); @@ -302,7 +307,12 @@ public class SupplicantStaNetworkHal { // For PSK, this can either be quoted ASCII passphrase or hex string for raw psk. // For SAE, password must be a quoted ASCII string if (config.preSharedKey != null) { - if (config.preSharedKey.startsWith("\"")) { + if (config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WAPI_PSK)) { + if (!setPskPassphrase(config.preSharedKey)) { + Log.e(TAG, "failed to set wapi psk passphrase"); + return false; + } + } else if (config.preSharedKey.startsWith("\"")) { if (config.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.SAE)) { /* WPA3 case, field is SAE Password */ if (!setSaePassword( diff --git a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java index 49ae7a756..6f0de57e2 100644 --- a/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SupplicantStaNetworkHalTest.java @@ -412,6 +412,23 @@ public class SupplicantStaNetworkHalTest extends WifiBaseTest { * Tests the saving of WifiConfiguration to wpa_supplicant. */ @Test + public void testWapiPskHexNetworkWifiConfigurationSaveLoad() throws Exception { + // Now expose the V1.3 ISupplicantStaNetwork + createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_3); + + WifiConfiguration config = WifiConfigurationTestUtil.createWapiPskNetwork(); + + config.preSharedKey = + "1234567890abcdef0" + + "1234567890abcdef0"; + // WAPI should accept a hex bytes whose length is not exact 32. + testWifiConfigurationSaveLoad(config); + } + + /** + * Tests the saving of WifiConfiguration to wpa_supplicant. + */ + @Test public void testWapiCertNetworkWifiConfigurationSaveLoad() throws Exception { // Now expose the V1.3 ISupplicantStaNetwork createSupplicantStaNetwork(SupplicantStaNetworkVersion.V1_3); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index f1ebd981a..9e9ae1cb4 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -339,6 +339,68 @@ public class WifiConfigManagerTest extends WifiBaseTest { } /** + * Verifies the addition of a WAPI-PSK network using + * {@link WifiConfigManager#addOrUpdateNetwork(WifiConfiguration, int)} + */ + @Test + public void testAddWapiPskNetwork() { + WifiConfiguration wapiPskNetwork = WifiConfigurationTestUtil.createWapiPskNetwork(); + List<WifiConfiguration> networks = new ArrayList<>(); + networks.add(wapiPskNetwork); + + verifyAddNetworkToWifiConfigManager(wapiPskNetwork); + + List<WifiConfiguration> retrievedNetworks = + mWifiConfigManager.getConfiguredNetworksWithPasswords(); + WifiConfigurationTestUtil.assertConfigurationsEqualForConfigManagerAddOrUpdate( + networks, retrievedNetworks); + // Ensure that the newly added network is disabled. + assertEquals(WifiConfiguration.Status.DISABLED, retrievedNetworks.get(0).status); + } + + /** + * Verifies the addition of a WAPI-PSK network with hex bytes using + * {@link WifiConfigManager#addOrUpdateNetwork(WifiConfiguration, int)} + */ + @Test + public void testAddWapiPskHexNetwork() { + WifiConfiguration wapiPskNetwork = WifiConfigurationTestUtil.createWapiPskNetwork(); + wapiPskNetwork.preSharedKey = + "123456780abcdef0123456780abcdef0"; + List<WifiConfiguration> networks = new ArrayList<>(); + networks.add(wapiPskNetwork); + + verifyAddNetworkToWifiConfigManager(wapiPskNetwork); + + List<WifiConfiguration> retrievedNetworks = + mWifiConfigManager.getConfiguredNetworksWithPasswords(); + WifiConfigurationTestUtil.assertConfigurationsEqualForConfigManagerAddOrUpdate( + networks, retrievedNetworks); + // Ensure that the newly added network is disabled. + assertEquals(WifiConfiguration.Status.DISABLED, retrievedNetworks.get(0).status); + } + + /** + * Verifies the addition of a WAPI-CERT network using + * {@link WifiConfigManager#addOrUpdateNetwork(WifiConfiguration, int)} + */ + @Test + public void testAddWapiCertNetwork() { + WifiConfiguration wapiCertNetwork = WifiConfigurationTestUtil.createWapiCertNetwork(); + List<WifiConfiguration> networks = new ArrayList<>(); + networks.add(wapiCertNetwork); + + verifyAddNetworkToWifiConfigManager(wapiCertNetwork); + + List<WifiConfiguration> retrievedNetworks = + mWifiConfigManager.getConfiguredNetworksWithPasswords(); + WifiConfigurationTestUtil.assertConfigurationsEqualForConfigManagerAddOrUpdate( + networks, retrievedNetworks); + // Ensure that the newly added network is disabled. + assertEquals(WifiConfiguration.Status.DISABLED, retrievedNetworks.get(0).status); + } + + /** * Verifies the addition of a single network when the corresponding ephemeral network exists. */ @Test |