From 221cd9e93b94def60aa4a5adbdd3bfa91502bdc8 Mon Sep 17 00:00:00 2001 From: Jimmy Chen Date: Wed, 11 Dec 2019 15:40:42 +0800 Subject: p2p: validate the network name of a group The network name of a group is also used as the SSID. The network name must also comply normal SSID naming rules. Bug: 144472136 Test: atest FrameworksWifiTests Change-Id: I63f23fdb51a1e96019025e860832f1db7ec99fd0 --- .../server/wifi/p2p/WifiP2pServiceImpl.java | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'service') diff --git a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java index 3f3745664..055fa72ef 100644 --- a/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java +++ b/service/java/com/android/server/wifi/p2p/WifiP2pServiceImpl.java @@ -100,6 +100,7 @@ import com.android.server.wifi.util.WifiPermissionsWrapper; import java.io.FileDescriptor; import java.io.PrintWriter; import java.net.InetAddress; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -148,6 +149,11 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { android.Manifest.permission.ACCESS_WIFI_STATE }; + // Maximum number of bytes allowed for a network name, i.e. SSID. + private static final int MAX_NETWORK_NAME_BYTES = 32; + // Minimum number of bytes for a network name, i.e. DIRECT-xy. + private static final int MIN_NETWORK_NAME_BYTES = 9; + // Two minutes comes from the wpa_supplicant setting private static final int GROUP_CREATING_WAIT_TIME_MS = 120 * 1000; private static int sGroupCreatingTimeoutIndex = 0; @@ -3254,6 +3260,23 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { return false; } + /** + * Check the network name complies standard SSID naming rules. + * + * The network name of a group is also the broadcasting SSID, + * as a result, the network name must complies standard SSID naming + * rules. + */ + private boolean isValidNetworkName(String networkName) { + if (TextUtils.isEmpty(networkName)) return false; + + byte[] ssidBytes = networkName.getBytes(StandardCharsets.UTF_8); + if (ssidBytes.length < MIN_NETWORK_NAME_BYTES) return false; + if (ssidBytes.length > MAX_NETWORK_NAME_BYTES) return false; + + return true; + } + /** * A config is valid as a group if it has network name and passphrase. * Supplicant can construct a group on the fly for creating a group with specified config @@ -3264,7 +3287,7 @@ public class WifiP2pServiceImpl extends IWifiP2pManager.Stub { private boolean isConfigValidAsGroup(WifiP2pConfig config) { if (config == null) return false; if (TextUtils.isEmpty(config.deviceAddress)) return false; - if (!TextUtils.isEmpty(config.networkName) + if (isValidNetworkName(config.networkName) && !TextUtils.isEmpty(config.passphrase)) { return true; } -- cgit v1.2.3