Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9663c317 authored by huiwan's avatar huiwan Committed by Michael Bestas
Browse files

Settings[Wifi]: fix the input invalid length for WEP encryption.

Add following check for WEP password:
        WEP40, WEP104, WEP128 -- 5, 13, 16
        HEX -- 10, 26, 32, character&number only

Change-Id: Ia76583f23ed860fcce7ff80f7bc7a70579c1bb88
CRs-Fixed: 1115766
parent c78a1d17
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -400,7 +400,7 @@ public class WifiConfigController implements TextWatcher,

        if (mPasswordView != null
                && ((mAccessPointSecurity == AccessPoint.SECURITY_WEP
                        && mPasswordView.length() == 0)
                    && !isWepPskValid(mPasswordView.getText().toString(), mPasswordView.length()))
                    || (mAccessPointSecurity == AccessPoint.SECURITY_PSK
                           && mPasswordView.length() < 8))) {
            passwordInvalid = true;
@@ -497,8 +497,8 @@ public class WifiConfigController implements TextWatcher,
                if (mPasswordView.length() != 0) {
                    int length = mPasswordView.length();
                    String password = mPasswordView.getText().toString();
                    // WEP-40, WEP-104, and 256-bit WEP (WEP-232?)
                    if ((length == 10 || length == 26 || length == 58)
                    // WEP-40, WEP-104, and WEP128
                    if ((length == 10 || length == 26 || length == 32)
                            && password.matches("[0-9A-Fa-f]*")) {
                        config.wepKeys[0] = password;
                    } else {
@@ -1329,4 +1329,16 @@ public class WifiConfigController implements TextWatcher,
            mSimDisplayNames.add(displayname);
        }
    }

    private boolean isWepPskValid(String psk, int pskLength) {
        if (psk == null || pskLength <= 0) return false;

        // WEP40 or WEP104 or WEP128
        if (pskLength == 5 || pskLength == 13 || pskLength == 16
                ||((pskLength == 10 || pskLength == 26 || pskLength == 32)  // HEX format
                    && psk.matches("[0-9A-Fa-f]*"))) {
            return true;
        }
        return false;
    }
}
 No newline at end of file