summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-10-29 09:15:31 -0700
committerRoshan Pius <rpius@google.com>2019-11-14 12:12:58 -0800
commita9ebe48227eb5befd221451a013cbd0a76eac999 (patch)
tree8bb3ec31fbb2e671d51aef48afdc9a1ed6b3fe8a /service
parent09621a42f86690346814c48cf1cdb1f123402e12 (diff)
WifiConfigStore: Encrypt credentials for networks (4/4)
Add a setting to turn on/off encryption. This global setting will be turned on for devices which require encrypted credentials. We don't need to support flipping the global settings back n forth. Only needs to support the one way toggle from off to on once for the lifetime of the device. Bug: 140485110 Test: atest com.android.server.wifi Test: Manual verification - Store a PSK network config on older build - Upgrade to build with this CL - adb shell settings put global niap_mode 1 - Ensured that the psk was read correctly on upgrade - Ensured that the psk was encrypted when stored on disk after upgrade Change-Id: Ibabe0814bfc42a7bf610d18e89a7b82bacfdfeed Merged-In: Ibabe0814bfc42a7bf610d18e89a7b82bacfdfeed
Diffstat (limited to 'service')
-rw-r--r--service/java/com/android/server/wifi/DeletedEphemeralSsidsStoreData.java6
-rw-r--r--service/java/com/android/server/wifi/FrameworkFacade.java12
-rw-r--r--service/java/com/android/server/wifi/NetworkListStoreData.java14
-rw-r--r--service/java/com/android/server/wifi/NetworkRequestStoreData.java6
-rw-r--r--service/java/com/android/server/wifi/NetworkSuggestionStoreData.java18
-rw-r--r--service/java/com/android/server/wifi/RandomizedMacStoreData.java6
-rw-r--r--service/java/com/android/server/wifi/SsidSetStoreData.java6
-rw-r--r--service/java/com/android/server/wifi/WakeupConfigStoreData.java6
-rw-r--r--service/java/com/android/server/wifi/WifiConfigManager.java10
-rw-r--r--service/java/com/android/server/wifi/WifiConfigStore.java41
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java2
-rw-r--r--service/java/com/android/server/wifi/hotspot2/PasspointConfigSharedStoreData.java6
-rw-r--r--service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java6
-rw-r--r--service/java/com/android/server/wifi/util/XmlUtil.java15
14 files changed, 93 insertions, 61 deletions
diff --git a/service/java/com/android/server/wifi/DeletedEphemeralSsidsStoreData.java b/service/java/com/android/server/wifi/DeletedEphemeralSsidsStoreData.java
index 3575ff254..b71d5a023 100644
--- a/service/java/com/android/server/wifi/DeletedEphemeralSsidsStoreData.java
+++ b/service/java/com/android/server/wifi/DeletedEphemeralSsidsStoreData.java
@@ -16,7 +16,7 @@
package com.android.server.wifi;
-import android.annotation.NonNull;
+import android.annotation.Nullable;
import com.android.server.wifi.util.WifiConfigStoreEncryptionUtil;
import com.android.server.wifi.util.XmlUtil;
@@ -48,7 +48,7 @@ public class DeletedEphemeralSsidsStoreData implements WifiConfigStore.StoreData
@Override
public void serializeData(XmlSerializer out,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
if (mSsidToTimeMap != null) {
XmlUtil.writeNextValue(out, XML_TAG_SSID_LIST, mSsidToTimeMap);
@@ -58,7 +58,7 @@ public class DeletedEphemeralSsidsStoreData implements WifiConfigStore.StoreData
@Override
public void deserializeData(XmlPullParser in, int outerTagDepth,
@WifiConfigStore.Version int version,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
// Ignore empty reads.
if (in == null) {
diff --git a/service/java/com/android/server/wifi/FrameworkFacade.java b/service/java/com/android/server/wifi/FrameworkFacade.java
index f3c5d4b3d..4fbe31867 100644
--- a/service/java/com/android/server/wifi/FrameworkFacade.java
+++ b/service/java/com/android/server/wifi/FrameworkFacade.java
@@ -45,6 +45,11 @@ import com.android.server.wifi.util.WifiAsyncChannel;
*/
public class FrameworkFacade {
public static final String TAG = "FrameworkFacade";
+ /**
+ * NIAP global settings flag.
+ * Note: This should be added to {@link android.provider.Settings.Global}.
+ */
+ private static final String NIAP_MODE_SETTINGS_NAME = "niap_mode";
private ActivityManagerInternal mActivityManagerInternal;
@@ -83,6 +88,13 @@ public class FrameworkFacade {
}
/**
+ * Returns whether the device is in NIAP mode or not.
+ */
+ public boolean isNiapModeOn(Context context) {
+ return getIntegerSetting(context, NIAP_MODE_SETTINGS_NAME, 0) == 1;
+ }
+
+ /**
* Helper method for classes to register a ContentObserver
* {@see ContentResolver#registerContentObserver(Uri,boolean,ContentObserver)}.
*
diff --git a/service/java/com/android/server/wifi/NetworkListStoreData.java b/service/java/com/android/server/wifi/NetworkListStoreData.java
index 4f2f36b9b..52e655b1e 100644
--- a/service/java/com/android/server/wifi/NetworkListStoreData.java
+++ b/service/java/com/android/server/wifi/NetworkListStoreData.java
@@ -18,7 +18,7 @@ package com.android.server.wifi;
import static com.android.server.wifi.WifiConfigStore.ENCRYPT_CREDENTIALS_CONFIG_STORE_DATA_VERSION;
-import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.content.Context;
import android.net.IpConfiguration;
import android.net.wifi.WifiConfiguration;
@@ -71,7 +71,7 @@ public abstract class NetworkListStoreData implements WifiConfigStore.StoreData
@Override
public void serializeData(XmlSerializer out,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
serializeNetworkList(out, mConfigurations, encryptionUtil);
}
@@ -79,7 +79,7 @@ public abstract class NetworkListStoreData implements WifiConfigStore.StoreData
@Override
public void deserializeData(XmlPullParser in, int outerTagDepth,
@WifiConfigStore.Version int version,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
// Ignore empty reads.
if (in == null) {
@@ -130,7 +130,7 @@ public abstract class NetworkListStoreData implements WifiConfigStore.StoreData
* @throws IOException
*/
private void serializeNetworkList(XmlSerializer out, List<WifiConfiguration> networkList,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
if (networkList == null) {
return;
@@ -150,7 +150,7 @@ public abstract class NetworkListStoreData implements WifiConfigStore.StoreData
* @throws IOException
*/
private void serializeNetwork(XmlSerializer out, WifiConfiguration config,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
XmlUtil.writeNextSectionStart(out, XML_TAG_SECTION_HEADER_NETWORK);
@@ -194,7 +194,7 @@ public abstract class NetworkListStoreData implements WifiConfigStore.StoreData
*/
private List<WifiConfiguration> parseNetworkList(XmlPullParser in, int outerTagDepth,
@WifiConfigStore.Version int version,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
List<WifiConfiguration> networkList = new ArrayList<>();
while (XmlUtil.gotoNextSectionWithNameOrEnd(in, XML_TAG_SECTION_HEADER_NETWORK,
@@ -226,7 +226,7 @@ public abstract class NetworkListStoreData implements WifiConfigStore.StoreData
*/
private WifiConfiguration parseNetwork(XmlPullParser in, int outerTagDepth,
@WifiConfigStore.Version int version,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
Pair<String, WifiConfiguration> parsedConfig = null;
NetworkSelectionStatus status = null;
diff --git a/service/java/com/android/server/wifi/NetworkRequestStoreData.java b/service/java/com/android/server/wifi/NetworkRequestStoreData.java
index 3a5143f56..7457079ae 100644
--- a/service/java/com/android/server/wifi/NetworkRequestStoreData.java
+++ b/service/java/com/android/server/wifi/NetworkRequestStoreData.java
@@ -16,7 +16,7 @@
package com.android.server.wifi;
-import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.net.MacAddress;
import android.util.Log;
@@ -90,7 +90,7 @@ public class NetworkRequestStoreData implements WifiConfigStore.StoreData {
@Override
public void serializeData(XmlSerializer out,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
serializeApprovedAccessPointsMap(out, mDataSource.toSerialize());
}
@@ -98,7 +98,7 @@ public class NetworkRequestStoreData implements WifiConfigStore.StoreData {
@Override
public void deserializeData(XmlPullParser in, int outerTagDepth,
@WifiConfigStore.Version int version,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
// Ignore empty reads.
if (in == null) {
diff --git a/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java b/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java
index fc0c55b5a..e973bdbe2 100644
--- a/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java
+++ b/service/java/com/android/server/wifi/NetworkSuggestionStoreData.java
@@ -18,7 +18,7 @@ package com.android.server.wifi;
import static com.android.server.wifi.WifiConfigStore.ENCRYPT_CREDENTIALS_CONFIG_STORE_DATA_VERSION;
-import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiEnterpriseConfig;
import android.net.wifi.WifiNetworkSuggestion;
@@ -103,7 +103,7 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
@Override
public void serializeData(XmlSerializer out,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
serializeNetworkSuggestionsMap(out, mDataSource.toSerialize(), encryptionUtil);
}
@@ -111,7 +111,7 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
@Override
public void deserializeData(XmlPullParser in, int outerTagDepth,
@WifiConfigStore.Version int version,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
// Ignore empty reads.
if (in == null) {
@@ -149,7 +149,7 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
*/
private void serializeNetworkSuggestionsMap(
XmlSerializer out, final Map<String, PerAppInfo> networkSuggestionsMap,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
if (networkSuggestionsMap == null) {
return;
@@ -177,7 +177,7 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
*/
private void serializeExtNetworkSuggestions(
XmlSerializer out, final Set<ExtendedWifiNetworkSuggestion> extNetworkSuggestions,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
for (ExtendedWifiNetworkSuggestion extNetworkSuggestion : extNetworkSuggestions) {
serializeNetworkSuggestion(out, extNetworkSuggestion.wns, encryptionUtil);
@@ -192,7 +192,7 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
*/
private void serializeNetworkSuggestion(XmlSerializer out,
final WifiNetworkSuggestion suggestion,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
XmlUtil.writeNextSectionStart(out, XML_TAG_SECTION_HEADER_NETWORK_SUGGESTION);
@@ -232,7 +232,7 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
*/
private Map<String, PerAppInfo> parseNetworkSuggestionsMap(XmlPullParser in, int outerTagDepth,
@WifiConfigStore.Version int version,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
Map<String, PerAppInfo> networkSuggestionsMap = new HashMap<>();
while (XmlUtil.gotoNextSectionWithNameOrEnd(
@@ -269,7 +269,7 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
*/
private Set<ExtendedWifiNetworkSuggestion> parseExtNetworkSuggestions(
XmlPullParser in, int outerTagDepth, @WifiConfigStore.Version int version,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil, PerAppInfo perAppInfo)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil, PerAppInfo perAppInfo)
throws XmlPullParserException, IOException {
Set<ExtendedWifiNetworkSuggestion> extNetworkSuggestions = new HashSet<>();
while (XmlUtil.gotoNextSectionWithNameOrEnd(
@@ -297,7 +297,7 @@ public class NetworkSuggestionStoreData implements WifiConfigStore.StoreData {
*/
private WifiNetworkSuggestion parseNetworkSuggestion(XmlPullParser in, int outerTagDepth,
@WifiConfigStore.Version int version,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
Pair<String, WifiConfiguration> parsedConfig = null;
WifiEnterpriseConfig enterpriseConfig = null;
diff --git a/service/java/com/android/server/wifi/RandomizedMacStoreData.java b/service/java/com/android/server/wifi/RandomizedMacStoreData.java
index 8e47ee7bf..ecbd7177f 100644
--- a/service/java/com/android/server/wifi/RandomizedMacStoreData.java
+++ b/service/java/com/android/server/wifi/RandomizedMacStoreData.java
@@ -16,7 +16,7 @@
package com.android.server.wifi;
-import android.annotation.NonNull;
+import android.annotation.Nullable;
import com.android.server.wifi.util.WifiConfigStoreEncryptionUtil;
import com.android.server.wifi.util.XmlUtil;
@@ -44,7 +44,7 @@ public class RandomizedMacStoreData implements WifiConfigStore.StoreData {
@Override
public void serializeData(XmlSerializer out,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
if (mMacMapping != null) {
XmlUtil.writeNextValue(out, XML_TAG_MAC_MAP, mMacMapping);
@@ -54,7 +54,7 @@ public class RandomizedMacStoreData implements WifiConfigStore.StoreData {
@Override
public void deserializeData(XmlPullParser in, int outerTagDepth,
@WifiConfigStore.Version int version,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
// Ignore empty reads.
if (in == null) {
diff --git a/service/java/com/android/server/wifi/SsidSetStoreData.java b/service/java/com/android/server/wifi/SsidSetStoreData.java
index 1339dae38..36b547cd2 100644
--- a/service/java/com/android/server/wifi/SsidSetStoreData.java
+++ b/service/java/com/android/server/wifi/SsidSetStoreData.java
@@ -16,7 +16,7 @@
package com.android.server.wifi;
-import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.text.TextUtils;
import com.android.server.wifi.util.WifiConfigStoreEncryptionUtil;
@@ -77,7 +77,7 @@ public class SsidSetStoreData implements WifiConfigStore.StoreData {
@Override
public void serializeData(XmlSerializer out,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
Set<String> ssidSet = mDataSource.getSsids();
if (ssidSet != null && !ssidSet.isEmpty()) {
@@ -88,7 +88,7 @@ public class SsidSetStoreData implements WifiConfigStore.StoreData {
@Override
public void deserializeData(XmlPullParser in, int outerTagDepth,
@WifiConfigStore.Version int version,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
// Ignore empty reads.
if (in == null) {
diff --git a/service/java/com/android/server/wifi/WakeupConfigStoreData.java b/service/java/com/android/server/wifi/WakeupConfigStoreData.java
index 1d146a0e1..847d8fbbc 100644
--- a/service/java/com/android/server/wifi/WakeupConfigStoreData.java
+++ b/service/java/com/android/server/wifi/WakeupConfigStoreData.java
@@ -16,7 +16,7 @@
package com.android.server.wifi;
-import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.util.ArraySet;
import android.util.Log;
@@ -97,7 +97,7 @@ public class WakeupConfigStoreData implements StoreData {
@Override
public void serializeData(XmlSerializer out,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
writeFeatureState(out);
@@ -146,7 +146,7 @@ public class WakeupConfigStoreData implements StoreData {
@Override
public void deserializeData(XmlPullParser in, int outerTagDepth,
@WifiConfigStore.Version int version,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
if (!mHasBeenRead) {
Log.d(TAG, "WifiWake user data has been read");
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java
index d1734d445..533155d0c 100644
--- a/service/java/com/android/server/wifi/WifiConfigManager.java
+++ b/service/java/com/android/server/wifi/WifiConfigManager.java
@@ -3131,7 +3131,8 @@ public class WifiConfigManager {
if (mDeferredUserUnlockRead) {
Log.i(TAG, "Handling user unlock before loading from store.");
List<WifiConfigStore.StoreFile> userStoreFiles =
- WifiConfigStore.createUserFiles(mCurrentUserId);
+ WifiConfigStore.createUserFiles(
+ mCurrentUserId, mFrameworkFacade.isNiapModeOn(mContext));
if (userStoreFiles == null) {
Log.wtf(TAG, "Failed to create user store files");
return false;
@@ -3170,7 +3171,8 @@ public class WifiConfigManager {
private boolean loadFromUserStoreAfterUnlockOrSwitch(int userId) {
try {
List<WifiConfigStore.StoreFile> userStoreFiles =
- WifiConfigStore.createUserFiles(userId);
+ WifiConfigStore.createUserFiles(
+ userId, mFrameworkFacade.isNiapModeOn(mContext));
if (userStoreFiles == null) {
Log.e(TAG, "Failed to create user store files");
return false;
@@ -3180,8 +3182,8 @@ public class WifiConfigManager {
Log.wtf(TAG, "Reading from new store failed. All saved private networks are lost!", e);
return false;
} catch (XmlPullParserException e) {
- Log.wtf(TAG, "XML deserialization of store failed. All saved private networks are" +
- "lost!", e);
+ Log.wtf(TAG, "XML deserialization of store failed. All saved private networks are "
+ + "lost!", e);
return false;
}
loadInternalDataFromUserStore(mNetworkListUserStoreData.getConfigurations(),
diff --git a/service/java/com/android/server/wifi/WifiConfigStore.java b/service/java/com/android/server/wifi/WifiConfigStore.java
index 350e8b52f..42d9f82cb 100644
--- a/service/java/com/android/server/wifi/WifiConfigStore.java
+++ b/service/java/com/android/server/wifi/WifiConfigStore.java
@@ -61,6 +61,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
/**
* This class provides a mechanism to save data to persistent store files {@link StoreFile}.
@@ -287,9 +288,11 @@ public class WifiConfigStore {
* @param storeBaseDir Base directory under which the store file is to be stored. The store file
* will be at <storeBaseDir>/wifi/WifiConfigStore.xml.
* @param fileId Identifier for the file. See {@link StoreFileId}.
+ * @param shouldEncryptCredentials Whether to encrypt credentials or not.
* @return new instance of the store file or null if the directory cannot be created.
*/
- private static @Nullable StoreFile createFile(File storeBaseDir, @StoreFileId int fileId) {
+ private static @Nullable StoreFile createFile(File storeBaseDir, @StoreFileId int fileId,
+ boolean shouldEncryptCredentials) {
File storeDir = new File(storeBaseDir, STORE_DIRECTORY_NAME);
if (!storeDir.exists()) {
if (!storeDir.mkdir()) {
@@ -298,18 +301,22 @@ public class WifiConfigStore {
}
}
File file = new File(storeDir, STORE_ID_TO_FILE_NAME.get(fileId));
- WifiConfigStoreEncryptionUtil encryptionUtil =
- new WifiConfigStoreEncryptionUtil(file.getName());
+ WifiConfigStoreEncryptionUtil encryptionUtil = null;
+ if (shouldEncryptCredentials) {
+ encryptionUtil = new WifiConfigStoreEncryptionUtil(file.getName());
+ }
return new StoreFile(file, fileId, encryptionUtil);
}
/**
* Create a new instance of the shared store file.
*
+ * @param shouldEncryptCredentials Whether to encrypt credentials or not.
* @return new instance of the store file or null if the directory cannot be created.
*/
- public static @Nullable StoreFile createSharedFile() {
- return createFile(Environment.getDataMiscDirectory(), STORE_FILE_SHARED_GENERAL);
+ public static @Nullable StoreFile createSharedFile(boolean shouldEncryptCredentials) {
+ return createFile(Environment.getDataMiscDirectory(), STORE_FILE_SHARED_GENERAL,
+ shouldEncryptCredentials);
}
/**
@@ -317,14 +324,18 @@ public class WifiConfigStore {
* The user store file is inside the user's encrypted data directory.
*
* @param userId userId corresponding to the currently logged-in user.
+ * @param shouldEncryptCredentials Whether to encrypt credentials or not.
* @return List of new instances of the store files created or null if the directory cannot be
* created.
*/
- public static @Nullable List<StoreFile> createUserFiles(int userId) {
+ public static @Nullable List<StoreFile> createUserFiles(int userId,
+ boolean shouldEncryptCredentials) {
List<StoreFile> storeFiles = new ArrayList<>();
for (int fileId : Arrays.asList(
STORE_FILE_USER_GENERAL, STORE_FILE_USER_NETWORK_SUGGESTIONS)) {
- StoreFile storeFile = createFile(Environment.getDataMiscCeDirectory(userId), fileId);
+ StoreFile storeFile =
+ createFile(Environment.getDataMiscCeDirectory(userId), fileId,
+ shouldEncryptCredentials);
if (storeFile == null) {
return null;
}
@@ -669,6 +680,13 @@ public class WifiConfigStore {
*/
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
pw.println("Dump of WifiConfigStore");
+ pw.println("WifiConfigStore - Store File Begin ----");
+ Stream.of(Arrays.asList(mSharedStore), mUserStores)
+ .flatMap(List::stream)
+ .forEach((storeFile) -> {
+ pw.print("Name: " + storeFile.mFileName);
+ pw.println(", Credentials encrypted: " + storeFile.getEncryptionUtil() != null);
+ });
pw.println("WifiConfigStore - Store Data Begin ----");
for (StoreData storeData : mStoreDataList) {
pw.print("StoreData =>");
@@ -716,7 +734,7 @@ public class WifiConfigStore {
private final WifiConfigStoreEncryptionUtil mEncryptionUtil;
public StoreFile(File file, @StoreFileId int fileId,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil) {
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil) {
mAtomicFile = new AtomicFile(file);
mFileName = file.getAbsolutePath();
mFileId = fileId;
@@ -735,7 +753,7 @@ public class WifiConfigStore {
/**
* @return Returns the encryption util used for this store file.
*/
- public @NonNull WifiConfigStoreEncryptionUtil getEncryptionUtil() {
+ public @Nullable WifiConfigStoreEncryptionUtil getEncryptionUtil() {
return mEncryptionUtil;
}
@@ -813,7 +831,8 @@ public class WifiConfigStore {
* @param out The output stream to serialize the data to
* @param encryptionUtil Utility to help encrypt any credential data.
*/
- void serializeData(XmlSerializer out, @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ void serializeData(XmlSerializer out,
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException;
/**
@@ -829,7 +848,7 @@ public class WifiConfigStore {
* in the store for them.
*/
void deserializeData(@Nullable XmlPullParser in, int outerTagDepth, @Version int version,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException;
/**
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index fe9ebea17..f7212ddfc 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -241,7 +241,7 @@ public class WifiInjector {
mWifiKeyStore = new WifiKeyStore(mKeyStore);
mWifiConfigStore = new WifiConfigStore(
mContext, clientModeImplLooper, mClock, mWifiMetrics,
- WifiConfigStore.createSharedFile());
+ WifiConfigStore.createSharedFile(mFrameworkFacade.isNiapModeOn(mContext)));
SubscriptionManager subscriptionManager =
mContext.getSystemService(SubscriptionManager.class);
// Config Manager
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointConfigSharedStoreData.java b/service/java/com/android/server/wifi/hotspot2/PasspointConfigSharedStoreData.java
index 9abccb94b..7f5a6b408 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointConfigSharedStoreData.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointConfigSharedStoreData.java
@@ -16,7 +16,7 @@
package com.android.server.wifi.hotspot2;
-import android.annotation.NonNull;
+import android.annotation.Nullable;
import com.android.server.wifi.WifiConfigStore;
import com.android.server.wifi.util.WifiConfigStoreEncryptionUtil;
@@ -76,7 +76,7 @@ public class PasspointConfigSharedStoreData implements WifiConfigStore.StoreData
@Override
public void serializeData(XmlSerializer out,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
serializeShareData(out);
}
@@ -84,7 +84,7 @@ public class PasspointConfigSharedStoreData implements WifiConfigStore.StoreData
@Override
public void deserializeData(XmlPullParser in, int outerTagDepth,
@WifiConfigStore.Version int version,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
// Ignore empty reads.
if (in == null) {
diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java b/service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java
index 1001b1189..123cf8982 100644
--- a/service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java
+++ b/service/java/com/android/server/wifi/hotspot2/PasspointConfigUserStoreData.java
@@ -16,7 +16,7 @@
package com.android.server.wifi.hotspot2;
-import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.net.wifi.hotspot2.PasspointConfiguration;
import android.text.TextUtils;
@@ -106,7 +106,7 @@ public class PasspointConfigUserStoreData implements WifiConfigStore.StoreData {
@Override
public void serializeData(XmlSerializer out,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
serializeUserData(out);
}
@@ -114,7 +114,7 @@ public class PasspointConfigUserStoreData implements WifiConfigStore.StoreData {
@Override
public void deserializeData(XmlPullParser in, int outerTagDepth,
@WifiConfigStore.Version int version,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
// Ignore empty reads.
if (in == null) {
diff --git a/service/java/com/android/server/wifi/util/XmlUtil.java b/service/java/com/android/server/wifi/util/XmlUtil.java
index 6128b0b4c..db0f4289b 100644
--- a/service/java/com/android/server/wifi/util/XmlUtil.java
+++ b/service/java/com/android/server/wifi/util/XmlUtil.java
@@ -16,7 +16,6 @@
package com.android.server.wifi.util;
-import android.annotation.NonNull;
import android.annotation.Nullable;
import android.net.IpConfiguration;
import android.net.IpConfiguration.IpAssignment;
@@ -477,7 +476,7 @@ public class XmlUtil {
*/
public static void writeToXmlForConfigStore(
XmlSerializer out, WifiConfiguration configuration,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
writeCommonElementsToXml(out, configuration, encryptionUtil);
XmlUtil.writeNextValue(out, XML_TAG_STATUS, configuration.status);
@@ -555,7 +554,7 @@ public class XmlUtil {
*/
public static Pair<String, WifiConfiguration> parseFromXml(
XmlPullParser in, int outerTagDepth, boolean shouldExpectEncryptedCredentials,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
WifiConfiguration configuration = new WifiConfiguration();
String configKeyInData = null;
@@ -715,7 +714,7 @@ public class XmlUtil {
}
switch (tagName) {
case XML_TAG_PRE_SHARED_KEY:
- if (!shouldExpectEncryptedCredentials) {
+ if (!shouldExpectEncryptedCredentials || encryptionUtil == null) {
throw new XmlPullParserException(
"Encrypted preSharedKey section not expected");
}
@@ -1094,7 +1093,7 @@ public class XmlUtil {
*/
private static void writePasswordToXml(
XmlSerializer out, String password,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
EncryptedData encryptedData = null;
if (encryptionUtil != null) {
@@ -1124,7 +1123,7 @@ public class XmlUtil {
* @param encryptionUtil Instance of {@link EncryptedDataXmlUtil}.
*/
public static void writeToXml(XmlSerializer out, WifiEnterpriseConfig enterpriseConfig,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
XmlUtil.writeNextValue(out, XML_TAG_IDENTITY,
enterpriseConfig.getFieldValue(WifiEnterpriseConfig.IDENTITY_KEY));
@@ -1168,7 +1167,7 @@ public class XmlUtil {
*/
public static WifiEnterpriseConfig parseFromXml(XmlPullParser in, int outerTagDepth,
boolean shouldExpectEncryptedCredentials,
- @NonNull WifiConfigStoreEncryptionUtil encryptionUtil)
+ @Nullable WifiConfigStoreEncryptionUtil encryptionUtil)
throws XmlPullParserException, IOException {
WifiEnterpriseConfig enterpriseConfig = new WifiEnterpriseConfig();
@@ -1260,7 +1259,7 @@ public class XmlUtil {
}
switch (tagName) {
case XML_TAG_PASSWORD:
- if (!shouldExpectEncryptedCredentials) {
+ if (!shouldExpectEncryptedCredentials || encryptionUtil == null) {
throw new XmlPullParserException(
"encrypted password section not expected");
}