From e7df893234345aefd8efb25e45aa02c39644fcb2 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Fri, 16 Mar 2018 10:55:16 -0700 Subject: WifiBackupRestore: Ignore unkown bitset values from backup CL to clear out any invalid bits in the the various bitsets in the parsed WifiConfiguration from the received backup data. Bug: 73987207 Test: Unit tests Test: Restored backup data from another Pixel device. Change-Id: Ib936a08d9dafc487f485c5054df194b8815042f7 --- .../android/server/wifi/WifiBackupRestoreTest.java | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiBackupRestoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiBackupRestoreTest.java index aa99829b6..d6cce6250 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiBackupRestoreTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiBackupRestoreTest.java @@ -83,6 +83,44 @@ public class WifiBackupRestoreTest { + "" + ""; + // |AllowedKeyMgmt|, |AllowedProtocols|, |AllowedAuthAlgorithms|, |AllowedGroupCiphers| and + // |AllowedPairwiseCiphers| fields have invalid values in them. + private static final String WIFI_BACKUP_DATA_WITH_UNSUPPORTED_VALUES_IN_BITSETS = + "" + + "" + + "" + + "" + + "" + + "" + + ""GoogleGuest-Legacy"NONE" + + ""GoogleGuest-Legacy"" + + "" + + "" + + "" + + "" + + "" + + "" + // Valid Value: 01 + + "0101" + // Valid Value: 03 + + "0b" + // Valid Value: 01 + + "09" + // Valid Value: 0f + + "2f" + // Valid Value: 06 + + "0e" + + "" + + "" + + "" + + "" + + "DHCP" + + "NONE" + + "" + + "" + + "" + + ""; + @Mock WifiPermissionsUtil mWifiPermissionsUtil; private WifiBackupRestore mWifiBackupRestore; private boolean mCheckDump = true; @@ -257,6 +295,59 @@ public class WifiBackupRestoreTest { return config; } + /** + * Verify that restoring of configuration that contains unsupported values in bitsets works + * correctly (unsupported values are ignored). + */ + @Test + public void testConfigurationWithUnsupportedValuesInBitsetsRestore() { + List configurations = new ArrayList<>(); + configurations.add(createNetworkForConfigurationWithUnsupportedValuesInBitsetsInRestore()); + + byte[] backupData = WIFI_BACKUP_DATA_WITH_UNSUPPORTED_VALUES_IN_BITSETS.getBytes(); + List retrievedConfigurations = + mWifiBackupRestore.retrieveConfigurationsFromBackupData(backupData); + WifiConfigurationTestUtil.assertConfigurationsEqualForBackup( + configurations, retrievedConfigurations); + + // No valid data to check in dump. + mCheckDump = false; + } + + /** + * Creates correct WiFiConfiguration that should be parsed out of + * {@link #WIFI_BACKUP_DATA_WITH_UNSUPPORTED_VALUES_IN_BITSETS} configuration which contains + * unsupported values. + * |AllowedKeyMgmt|, |AllowedProtocols|, |AllowedAuthAlgorithms|, |AllowedGroupCiphers| and + * |AllowedPairwiseCiphers| fields have invalid values in them. + */ + private static WifiConfiguration + createNetworkForConfigurationWithUnsupportedValuesInBitsetsInRestore() { + final WifiConfiguration config = new WifiConfiguration(); + config.SSID = "\"GoogleGuest-Legacy\""; + config.wepTxKeyIndex = 0; + config.hiddenSSID = false; + config.requirePMF = false; + config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE); + config.allowedProtocols.set(WifiConfiguration.Protocol.WPA); + config.allowedProtocols.set(WifiConfiguration.Protocol.RSN); + config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); + config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40); + config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104); + config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP); + config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP); + config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP); + config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP); + config.shared = true; + + IpConfiguration ipConfiguration = new IpConfiguration(); + ipConfiguration.setIpAssignment(IpConfiguration.IpAssignment.DHCP); + ipConfiguration.setProxySettings(IpConfiguration.ProxySettings.NONE); + config.setIpConfiguration(ipConfiguration); + + return config; + } + /** * Verify that a single WEP network configuration with only 1 key is serialized & deserialized * correctly. -- cgit v1.2.3