summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-10-22 15:37:41 -0700
committerRoshan Pius <rpius@google.com>2019-11-14 11:18:28 -0800
commit6237115f3c6ae723eb3927640c843714793fbe59 (patch)
treefb37f3972b128ab1bc399e0e4854050681e62173 /service
parenta161d62d9baac95a087cb3252d51c1fd101d24fa (diff)
WifiConfigStore: Encrypt credentials for networks (2/4)
Plumb the EncryptionUtil & version info to the XmlUtil classes that actually handle the serialization/deserialization of data. Also, created a helper class to serialize/deserialize EncryptedData class. Bug: 140485110 Test: atest com.android.server.wifi Change-Id: I92846f1fb63f3b85892750b195a535bcfdc03e2c Merged-In: I92846f1fb63f3b85892750b195a535bcfdc03e2c
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/NetworkListStoreData.java48
-rw-r--r--service/java/com/android/server/wifi/NetworkSuggestionStoreData.java49
-rw-r--r--service/java/com/android/server/wifi/WifiConfigStore.java5
-rw-r--r--service/java/com/android/server/wifi/util/XmlUtil.java100
4 files changed, 156 insertions, 46 deletions
diff --git a/service/java/com/android/server/wifi/NetworkListStoreData.java b/service/java/com/android/server/wifi/NetworkListStoreData.java
index 981e97c7e..4f2f36b9b 100644
--- a/service/java/com/android/server/wifi/NetworkListStoreData.java
+++ b/service/java/com/android/server/wifi/NetworkListStoreData.java
@@ -16,6 +16,8 @@
package com.android.server.wifi;
+import static com.android.server.wifi.WifiConfigStore.ENCRYPT_CREDENTIALS_CONFIG_STORE_DATA_VERSION;
+
import android.annotation.NonNull;
import android.content.Context;
import android.net.IpConfiguration;
@@ -71,7 +73,7 @@ public abstract class NetworkListStoreData implements WifiConfigStore.StoreData
public void serializeData(XmlSerializer out,
@NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
- serializeNetworkList(out, mConfigurations);
+ serializeNetworkList(out, mConfigurations, encryptionUtil);
}
@Override
@@ -83,7 +85,7 @@ public abstract class NetworkListStoreData implements WifiConfigStore.StoreData
if (in == null) {
return;
}
- mConfigurations = parseNetworkList(in, outerTagDepth);
+ mConfigurations = parseNetworkList(in, outerTagDepth, version, encryptionUtil);
}
@Override
@@ -123,33 +125,38 @@ public abstract class NetworkListStoreData implements WifiConfigStore.StoreData
*
* @param out The output stream to serialize the data to
* @param networkList The network list to serialize
+ * @param encryptionUtil Instance of {@link WifiConfigStoreEncryptionUtil}
* @throws XmlPullParserException
* @throws IOException
*/
- private void serializeNetworkList(XmlSerializer out, List<WifiConfiguration> networkList)
+ private void serializeNetworkList(XmlSerializer out, List<WifiConfiguration> networkList,
+ @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
if (networkList == null) {
return;
}
for (WifiConfiguration network : networkList) {
- serializeNetwork(out, network);
+ serializeNetwork(out, network, encryptionUtil);
}
}
/**
* Serialize a {@link WifiConfiguration} to an output stream in XML format.
- * @param out
- * @param config
+ *
+ * @param out The output stream to serialize the data to
+ * @param config The network config to serialize
+ * @param encryptionUtil Instance of {@link WifiConfigStoreEncryptionUtil}
* @throws XmlPullParserException
* @throws IOException
*/
- private void serializeNetwork(XmlSerializer out, WifiConfiguration config)
+ private void serializeNetwork(XmlSerializer out, WifiConfiguration config,
+ @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
XmlUtil.writeNextSectionStart(out, XML_TAG_SECTION_HEADER_NETWORK);
// Serialize WifiConfiguration.
XmlUtil.writeNextSectionStart(out, XML_TAG_SECTION_HEADER_WIFI_CONFIGURATION);
- WifiConfigurationXmlUtil.writeToXmlForConfigStore(out, config);
+ WifiConfigurationXmlUtil.writeToXmlForConfigStore(out, config, encryptionUtil);
XmlUtil.writeNextSectionEnd(out, XML_TAG_SECTION_HEADER_WIFI_CONFIGURATION);
// Serialize network selection status.
@@ -167,7 +174,7 @@ public abstract class NetworkListStoreData implements WifiConfigStore.StoreData
&& config.enterpriseConfig.getEapMethod() != WifiEnterpriseConfig.Eap.NONE) {
XmlUtil.writeNextSectionStart(
out, XML_TAG_SECTION_HEADER_WIFI_ENTERPRISE_CONFIGURATION);
- WifiEnterpriseConfigXmlUtil.writeToXml(out, config.enterpriseConfig);
+ WifiEnterpriseConfigXmlUtil.writeToXml(out, config.enterpriseConfig, encryptionUtil);
XmlUtil.writeNextSectionEnd(out, XML_TAG_SECTION_HEADER_WIFI_ENTERPRISE_CONFIGURATION);
}
@@ -179,11 +186,15 @@ public abstract class NetworkListStoreData implements WifiConfigStore.StoreData
*
* @param in The input stream to read from
* @param outerTagDepth The XML tag depth of the outer XML block
+ * @param version Version of config store file.
+ * @param encryptionUtil Instance of {@link WifiConfigStoreEncryptionUtil}
* @return List of {@link WifiConfiguration}
* @throws XmlPullParserException
* @throws IOException
*/
- private List<WifiConfiguration> parseNetworkList(XmlPullParser in, int outerTagDepth)
+ private List<WifiConfiguration> parseNetworkList(XmlPullParser in, int outerTagDepth,
+ @WifiConfigStore.Version int version,
+ @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
List<WifiConfiguration> networkList = new ArrayList<>();
while (XmlUtil.gotoNextSectionWithNameOrEnd(in, XML_TAG_SECTION_HEADER_NETWORK,
@@ -191,7 +202,8 @@ public abstract class NetworkListStoreData implements WifiConfigStore.StoreData
// Try/catch only runtime exceptions (like illegal args), any XML/IO exceptions are
// fatal and should abort the entire loading process.
try {
- WifiConfiguration config = parseNetwork(in, outerTagDepth + 1);
+ WifiConfiguration config =
+ parseNetwork(in, outerTagDepth + 1, version, encryptionUtil);
networkList.add(config);
} catch (RuntimeException e) {
// Failed to parse this network, skip it.
@@ -206,11 +218,15 @@ public abstract class NetworkListStoreData implements WifiConfigStore.StoreData
*
* @param in The input stream to read from
* @param outerTagDepth The XML tag depth of the outer XML block
+ * @param version Version of config store file.
+ * @param encryptionUtil Instance of {@link WifiConfigStoreEncryptionUtil}
* @return {@link WifiConfiguration}
* @throws XmlPullParserException
* @throws IOException
*/
- private WifiConfiguration parseNetwork(XmlPullParser in, int outerTagDepth)
+ private WifiConfiguration parseNetwork(XmlPullParser in, int outerTagDepth,
+ @WifiConfigStore.Version int version,
+ @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
Pair<String, WifiConfiguration> parsedConfig = null;
NetworkSelectionStatus status = null;
@@ -225,7 +241,9 @@ public abstract class NetworkListStoreData implements WifiConfigStore.StoreData
throw new XmlPullParserException("Detected duplicate tag for: "
+ XML_TAG_SECTION_HEADER_WIFI_CONFIGURATION);
}
- parsedConfig = WifiConfigurationXmlUtil.parseFromXml(in, outerTagDepth + 1);
+ parsedConfig = WifiConfigurationXmlUtil.parseFromXml(in, outerTagDepth + 1,
+ version >= ENCRYPT_CREDENTIALS_CONFIG_STORE_DATA_VERSION,
+ encryptionUtil);
break;
case XML_TAG_SECTION_HEADER_NETWORK_STATUS:
if (status != null) {
@@ -247,7 +265,9 @@ public abstract class NetworkListStoreData implements WifiConfigStore.StoreData
+ XML_TAG_SECTION_HEADER_WIFI_ENTERPRISE_CONFIGURATION);
}
enterpriseConfig =
- WifiEnterpriseConfigXmlUtil.parseFromXml(in, outerTagDepth + 1);
+ WifiEnterpriseConfigXmlUtil.parseFromXml(in, outerTagDepth + 1,
+ version >= ENCRYPT_CREDENTIALS_CONFIG_STORE_DATA_VERSION,
+ encryptionUtil);
break;
default:
throw new XmlPullParserException("Unknown tag under "
diff --git a/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java b/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java
index e9503b7e4..fc0c55b5a 100644
--- a/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java
+++ b/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java
@@ -16,6 +16,8 @@
package com.android.server.wifi;
+import static com.android.server.wifi.WifiConfigStore.ENCRYPT_CREDENTIALS_CONFIG_STORE_DATA_VERSION;
+
import android.annotation.NonNull;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiEnterpriseConfig;
@@ -103,7 +105,7 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
public void serializeData(XmlSerializer out,
@NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
- serializeNetworkSuggestionsMap(out, mDataSource.toSerialize());
+ serializeNetworkSuggestionsMap(out, mDataSource.toSerialize(), encryptionUtil);
}
@Override
@@ -115,7 +117,8 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
if (in == null) {
return;
}
- mDataSource.fromDeserialized(parseNetworkSuggestionsMap(in, outerTagDepth));
+ mDataSource.fromDeserialized(
+ parseNetworkSuggestionsMap(in, outerTagDepth, version, encryptionUtil));
}
@Override
@@ -145,7 +148,8 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
* @throws IOException
*/
private void serializeNetworkSuggestionsMap(
- XmlSerializer out, final Map<String, PerAppInfo> networkSuggestionsMap)
+ XmlSerializer out, final Map<String, PerAppInfo> networkSuggestionsMap,
+ @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
if (networkSuggestionsMap == null) {
return;
@@ -160,7 +164,7 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
XmlUtil.writeNextValue(out, XML_TAG_SUGGESTOR_PACKAGE_NAME, packageName);
XmlUtil.writeNextValue(out, XML_TAG_SUGGESTOR_HAS_USER_APPROVED, hasUserApproved);
XmlUtil.writeNextValue(out, XML_TAG_SUGGESTOR_MAX_SIZE, maxSize);
- serializeExtNetworkSuggestions(out, networkSuggestions);
+ serializeExtNetworkSuggestions(out, networkSuggestions, encryptionUtil);
XmlUtil.writeNextSectionEnd(out, XML_TAG_SECTION_HEADER_NETWORK_SUGGESTION_PER_APP);
}
}
@@ -172,10 +176,11 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
* @throws IOException
*/
private void serializeExtNetworkSuggestions(
- XmlSerializer out, final Set<ExtendedWifiNetworkSuggestion> extNetworkSuggestions)
+ XmlSerializer out, final Set<ExtendedWifiNetworkSuggestion> extNetworkSuggestions,
+ @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
for (ExtendedWifiNetworkSuggestion extNetworkSuggestion : extNetworkSuggestions) {
- serializeNetworkSuggestion(out, extNetworkSuggestion.wns);
+ serializeNetworkSuggestion(out, extNetworkSuggestion.wns, encryptionUtil);
}
}
@@ -186,13 +191,15 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
* @throws IOException
*/
private void serializeNetworkSuggestion(XmlSerializer out,
- final WifiNetworkSuggestion suggestion)
+ final WifiNetworkSuggestion suggestion,
+ @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
XmlUtil.writeNextSectionStart(out, XML_TAG_SECTION_HEADER_NETWORK_SUGGESTION);
// Serialize WifiConfiguration.
XmlUtil.writeNextSectionStart(out, XML_TAG_SECTION_HEADER_WIFI_CONFIGURATION);
- WifiConfigurationXmlUtil.writeToXmlForConfigStore(out, suggestion.wifiConfiguration);
+ WifiConfigurationXmlUtil.writeToXmlForConfigStore(
+ out, suggestion.wifiConfiguration, encryptionUtil);
XmlUtil.writeNextSectionEnd(out, XML_TAG_SECTION_HEADER_WIFI_CONFIGURATION);
// Serialize enterprise configuration for enterprise networks.
if (suggestion.wifiConfiguration.enterpriseConfig != null
@@ -201,7 +208,7 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
XmlUtil.writeNextSectionStart(
out, XML_TAG_SECTION_HEADER_WIFI_ENTERPRISE_CONFIGURATION);
XmlUtil.WifiEnterpriseConfigXmlUtil.writeToXml(
- out, suggestion.wifiConfiguration.enterpriseConfig);
+ out, suggestion.wifiConfiguration.enterpriseConfig, encryptionUtil);
XmlUtil.writeNextSectionEnd(out, XML_TAG_SECTION_HEADER_WIFI_ENTERPRISE_CONFIGURATION);
}
@@ -223,7 +230,9 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
* @throws XmlPullParserException
* @throws IOException
*/
- private Map<String, PerAppInfo> parseNetworkSuggestionsMap(XmlPullParser in, int outerTagDepth)
+ private Map<String, PerAppInfo> parseNetworkSuggestionsMap(XmlPullParser in, int outerTagDepth,
+ @WifiConfigStore.Version int version,
+ @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
Map<String, PerAppInfo> networkSuggestionsMap = new HashMap<>();
while (XmlUtil.gotoNextSectionWithNameOrEnd(
@@ -238,7 +247,8 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
int maxSize = (int) XmlUtil.readNextValueWithName(in, XML_TAG_SUGGESTOR_MAX_SIZE);
PerAppInfo perAppInfo = new PerAppInfo(packageName);
Set<ExtendedWifiNetworkSuggestion> extNetworkSuggestions =
- parseExtNetworkSuggestions(in, outerTagDepth + 1, perAppInfo);
+ parseExtNetworkSuggestions(
+ in, outerTagDepth + 1, version, encryptionUtil, perAppInfo);
perAppInfo.hasUserApproved = hasUserApproved;
perAppInfo.maxSize = maxSize;
perAppInfo.extNetworkSuggestions.addAll(extNetworkSuggestions);
@@ -258,7 +268,8 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
* @throws IOException
*/
private Set<ExtendedWifiNetworkSuggestion> parseExtNetworkSuggestions(
- XmlPullParser in, int outerTagDepth, PerAppInfo perAppInfo)
+ XmlPullParser in, int outerTagDepth, @WifiConfigStore.Version int version,
+ @NonNull WifiConfigStoreEncryptionUtil encryptionUtil, PerAppInfo perAppInfo)
throws XmlPullParserException, IOException {
Set<ExtendedWifiNetworkSuggestion> extNetworkSuggestions = new HashSet<>();
while (XmlUtil.gotoNextSectionWithNameOrEnd(
@@ -267,7 +278,7 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
// fatal and should abort the entire loading process.
try {
WifiNetworkSuggestion networkSuggestion =
- parseNetworkSuggestion(in, outerTagDepth + 1);
+ parseNetworkSuggestion(in, outerTagDepth + 1, version, encryptionUtil);
extNetworkSuggestions.add(ExtendedWifiNetworkSuggestion.fromWns(
networkSuggestion, perAppInfo));
} catch (RuntimeException e) {
@@ -284,7 +295,9 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
* @throws XmlPullParserException
* @throws IOException
*/
- private WifiNetworkSuggestion parseNetworkSuggestion(XmlPullParser in, int outerTagDepth)
+ private WifiNetworkSuggestion parseNetworkSuggestion(XmlPullParser in, int outerTagDepth,
+ @WifiConfigStore.Version int version,
+ @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
Pair<String, WifiConfiguration> parsedConfig = null;
WifiEnterpriseConfig enterpriseConfig = null;
@@ -329,7 +342,9 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
+ XML_TAG_SECTION_HEADER_WIFI_CONFIGURATION);
}
parsedConfig = WifiConfigurationXmlUtil.parseFromXml(
- in, outerTagDepth + 1);
+ in, outerTagDepth + 1,
+ version >= ENCRYPT_CREDENTIALS_CONFIG_STORE_DATA_VERSION,
+ encryptionUtil);
break;
case XML_TAG_SECTION_HEADER_WIFI_ENTERPRISE_CONFIGURATION:
if (enterpriseConfig != null) {
@@ -337,7 +352,9 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
+ XML_TAG_SECTION_HEADER_WIFI_ENTERPRISE_CONFIGURATION);
}
enterpriseConfig = XmlUtil.WifiEnterpriseConfigXmlUtil.parseFromXml(
- in, outerTagDepth + 1);
+ in, outerTagDepth + 1,
+ version >= ENCRYPT_CREDENTIALS_CONFIG_STORE_DATA_VERSION,
+ encryptionUtil);
break;
default:
throw new XmlPullParserException("Unknown tag under "
diff --git a/service/java/com/android/server/wifi/WifiConfigStore.java b/service/java/com/android/server/wifi/WifiConfigStore.java
index efe4a4c8d..dee52a795 100644
--- a/service/java/com/android/server/wifi/WifiConfigStore.java
+++ b/service/java/com/android/server/wifi/WifiConfigStore.java
@@ -100,8 +100,6 @@ public class WifiConfigStore {
private static final String XML_TAG_DOCUMENT_HEADER = "WifiConfigStoreData";
private static final String XML_TAG_VERSION = "Version";
private static final String XML_TAG_HEADER_INTEGRITY = "Integrity";
- private static final String XML_TAG_INTEGRITY_ENCRYPTED_DATA = "EncryptedData";
- private static final String XML_TAG_INTEGRITY_IV = "IV";
/**
* Current config store data version. This will be incremented for any additions.
*/
@@ -669,8 +667,7 @@ public class WifiConfigStore {
private static void parseAndDiscardIntegrityDataFromXml(XmlPullParser in, int outerTagDepth)
throws XmlPullParserException, IOException {
XmlUtil.gotoNextSectionWithName(in, XML_TAG_HEADER_INTEGRITY, outerTagDepth);
- XmlUtil.readNextValueWithName(in, XML_TAG_INTEGRITY_ENCRYPTED_DATA);
- XmlUtil.readNextValueWithName(in, XML_TAG_INTEGRITY_IV);
+ XmlUtil.EncryptedDataXmlUtil.parseFromXml(in, outerTagDepth + 1);
}
/**
diff --git a/service/java/com/android/server/wifi/util/XmlUtil.java b/service/java/com/android/server/wifi/util/XmlUtil.java
index 188d3b5c7..292c7929a 100644
--- a/service/java/com/android/server/wifi/util/XmlUtil.java
+++ b/service/java/com/android/server/wifi/util/XmlUtil.java
@@ -16,6 +16,8 @@
package com.android.server.wifi.util;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.net.IpConfiguration;
import android.net.IpConfiguration.IpAssignment;
import android.net.IpConfiguration.ProxySettings;
@@ -380,11 +382,13 @@ public class XmlUtil {
* Write the Configuration data elements that are common for backup & config store to the
* XML stream.
*
- * @param out XmlSerializer instance pointing to the XML stream.
+ * @param out XmlSerializer instance pointing to the XML stream.
* @param configuration WifiConfiguration object to be serialized.
+ * @param encryptionUtil Instance of {@link EncryptedDataXmlUtil}.
*/
public static void writeCommonElementsToXml(
- XmlSerializer out, WifiConfiguration configuration)
+ XmlSerializer out, WifiConfiguration configuration,
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
XmlUtil.writeNextValue(out, XML_TAG_CONFIG_KEY, configuration.configKey());
XmlUtil.writeNextValue(out, XML_TAG_SSID, configuration.SSID);
@@ -428,7 +432,7 @@ public class XmlUtil {
*/
public static void writeToXmlForBackup(XmlSerializer out, WifiConfiguration configuration)
throws XmlPullParserException, IOException {
- writeCommonElementsToXml(out, configuration);
+ writeCommonElementsToXml(out, configuration, null);
XmlUtil.writeNextValue(out, XML_TAG_METERED_OVERRIDE, configuration.meteredOverride);
}
@@ -436,13 +440,15 @@ public class XmlUtil {
* Write the Configuration data elements for config store from the provided Configuration
* to the XML stream.
*
- * @param out XmlSerializer instance pointing to the XML stream.
+ * @param out XmlSerializer instance pointing to the XML stream.
* @param configuration WifiConfiguration object to be serialized.
+ * @param encryptionUtil Instance of {@link EncryptedDataXmlUtil}.
*/
public static void writeToXmlForConfigStore(
- XmlSerializer out, WifiConfiguration configuration)
+ XmlSerializer out, WifiConfiguration configuration,
+ @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
- writeCommonElementsToXml(out, configuration);
+ writeCommonElementsToXml(out, configuration, encryptionUtil);
XmlUtil.writeNextValue(out, XML_TAG_STATUS, configuration.status);
XmlUtil.writeNextValue(out, XML_TAG_FQDN, configuration.FQDN);
XmlUtil.writeNextValue(
@@ -509,13 +515,16 @@ public class XmlUtil {
* Note: This is used for parsing both backup data and config store data. Looping through
* the tags make it easy to add or remove elements in the future versions if needed.
*
- * @param in XmlPullParser instance pointing to the XML stream.
+ * @param in XmlPullParser instance pointing to the XML stream.
* @param outerTagDepth depth of the outer tag in the XML document.
+ * @param areCredentialsEncrypted Whether credentials are encrypted or not.
+ * @param encryptionUtil Instance of {@link EncryptedDataXmlUtil}.
* @return Pair<Config key, WifiConfiguration object> if parsing is successful,
* null otherwise.
*/
public static Pair<String, WifiConfiguration> parseFromXml(
- XmlPullParser in, int outerTagDepth)
+ XmlPullParser in, int outerTagDepth, boolean areCredentialsEncrypted,
+ @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
WifiConfiguration configuration = new WifiConfiguration();
String configKeyInData = null;
@@ -1022,10 +1031,12 @@ public class XmlUtil {
* Write the WifiEnterpriseConfig data elements from the provided config to the XML
* stream.
*
- * @param out XmlSerializer instance pointing to the XML stream.
+ * @param out XmlSerializer instance pointing to the XML stream.
* @param enterpriseConfig WifiEnterpriseConfig object to be serialized.
+ * @param encryptionUtil Instance of {@link EncryptedDataXmlUtil}.
*/
- public static void writeToXml(XmlSerializer out, WifiEnterpriseConfig enterpriseConfig)
+ public static void writeToXml(XmlSerializer out, WifiEnterpriseConfig enterpriseConfig,
+ @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
XmlUtil.writeNextValue(out, XML_TAG_IDENTITY,
enterpriseConfig.getFieldValue(WifiEnterpriseConfig.IDENTITY_KEY));
@@ -1060,11 +1071,15 @@ public class XmlUtil {
/**
* Parses the data elements from the provided XML stream to a WifiEnterpriseConfig object.
*
- * @param in XmlPullParser instance pointing to the XML stream.
+ * @param in XmlPullParser instance pointing to the XML stream.
* @param outerTagDepth depth of the outer tag in the XML document.
+ * @param areCredentialsEncrypted Whether credentials are encrypted or not.
+ * @param encryptionUtil Instance of {@link EncryptedDataXmlUtil}.
* @return WifiEnterpriseConfig object if parsing is successful, null otherwise.
*/
- public static WifiEnterpriseConfig parseFromXml(XmlPullParser in, int outerTagDepth)
+ public static WifiEnterpriseConfig parseFromXml(XmlPullParser in, int outerTagDepth,
+ boolean areCredentialsEncrypted,
+ @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig();
@@ -1144,5 +1159,66 @@ public class XmlUtil {
return enterpriseConfig;
}
}
+
+ /**
+ * Utility class to serialize and deseriaize {@link EncryptedData} object to XML &
+ * vice versa. This is used by {@link com.android.server.wifi.WifiConfigStore} module.
+ */
+ public static class EncryptedDataXmlUtil {
+ /**
+ * List of XML tags corresponding to EncryptedData object elements.
+ */
+ private static final String XML_TAG_ENCRYPTED_DATA = "EncryptedData";
+ private static final String XML_TAG_IV = "IV";
+
+ /**
+ * Write the NetworkSelectionStatus data elements from the provided status to the XML
+ * stream.
+ *
+ * @param out XmlSerializer instance pointing to the XML stream.
+ * @param encryptedData EncryptedData object to be serialized.
+ */
+ public static void writeToXml(XmlSerializer out, EncryptedData encryptedData)
+ throws XmlPullParserException, IOException {
+ XmlUtil.writeNextValue(
+ out, XML_TAG_ENCRYPTED_DATA, encryptedData.getEncryptedData());
+ XmlUtil.writeNextValue(out, XML_TAG_IV, encryptedData.getIv());
+ }
+
+ /**
+ * Parses the EncryptedData data elements from the provided XML stream to a
+ * EncryptedData object.
+ *
+ * @param in XmlPullParser instance pointing to the XML stream.
+ * @param outerTagDepth depth of the outer tag in the XML document.
+ * @return EncryptedData object if parsing is successful, null otherwise.
+ */
+ public static EncryptedData parseFromXml(XmlPullParser in, int outerTagDepth)
+ throws XmlPullParserException, IOException {
+ byte[] encryptedData = null;
+ byte[] iv = null;
+
+ // Loop through and parse out all the elements from the stream within this section.
+ while (!XmlUtil.isNextSectionEnd(in, outerTagDepth)) {
+ String[] valueName = new String[1];
+ Object value = XmlUtil.readCurrentValue(in, valueName);
+ if (valueName[0] == null) {
+ throw new XmlPullParserException("Missing value name");
+ }
+ switch (valueName[0]) {
+ case XML_TAG_ENCRYPTED_DATA:
+ encryptedData = (byte[]) value;
+ break;
+ case XML_TAG_IV:
+ iv = (byte[]) value;
+ break;
+ default:
+ throw new XmlPullParserException(
+ "Unknown value name found: " + valueName[0]);
+ }
+ }
+ return new EncryptedData(encryptedData, iv);
+ }
+ }
}