From 3bb2a8104285cb253c9d4e1a52804fa053f5bd46 Mon Sep 17 00:00:00 2001 From: Les Lee Date: Wed, 9 Mar 2022 16:28:30 +0800 Subject: [PATCH] wifi setting: Add psk length check Frameworks move psk ascii password length check from API level to framework internal. Add the check code in Setting side to avoid breaking the unit test. Bug: 223513510 Test: atest -c WifiUtilsTest Change-Id: I7c78eb367fdcbbc11bbb7169ba8f2edc720ad071 --- src/com/android/settings/wifi/WifiUtils.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/com/android/settings/wifi/WifiUtils.java b/src/com/android/settings/wifi/WifiUtils.java index 6f955b2120a..10277927019 100644 --- a/src/com/android/settings/wifi/WifiUtils.java +++ b/src/com/android/settings/wifi/WifiUtils.java @@ -41,6 +41,8 @@ public class WifiUtils extends com.android.settingslib.wifi.WifiUtils { private static final int SSID_ASCII_MIN_LENGTH = 1; private static final int SSID_ASCII_MAX_LENGTH = 32; + private static final int PSK_PASSPHRASE_ASCII_MIN_LENGTH = 8; + private static final int PSK_PASSPHRASE_ASCII_MAX_LENGTH = 63; public static boolean isSSIDTooLong(String ssid) { if (TextUtils.isEmpty(ssid)) { @@ -62,6 +64,13 @@ public class WifiUtils extends com.android.settingslib.wifi.WifiUtils { public static boolean isHotspotPasswordValid(String password, int securityType) { final SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder(); try { + if (securityType == SoftApConfiguration.SECURITY_TYPE_WPA2_PSK + || securityType == SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION) { + if (password.length() < PSK_PASSPHRASE_ASCII_MIN_LENGTH + || password.length() > PSK_PASSPHRASE_ASCII_MAX_LENGTH) { + return false; + } + } configBuilder.setPassphrase(password, securityType); } catch (IllegalArgumentException e) { return false;