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

Commit 465bba90 authored by Jimmy Chen's avatar Jimmy Chen
Browse files

Wifi: validate the wep key specified by the key index

WEP supports multiple keys and wifi should check the corresponding one,
but not always the first one.

Bug: 140541572
Test: atest FrameworksWifiApiTests
Change-Id: I0aa653db069b2811e1d6ede7f34bd7150b16d64c
parent 08c2f021
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -1766,7 +1766,10 @@ public class AccessPoint implements Comparable<AccessPoint> {
        if (config.allowedKeyManagement.get(KeyMgmt.OWE)) {
            return SECURITY_OWE;
        }
        return (config.wepKeys[0] != null) ? SECURITY_WEP : SECURITY_NONE;
        return (config.wepTxKeyIndex >= 0
                && config.wepTxKeyIndex < config.wepKeys.length
                && config.wepKeys[config.wepTxKeyIndex] != null)
                ? SECURITY_WEP : SECURITY_NONE;
    }

    public static String securityToString(int security, int pskType) {
+2 −1
Original line number Diff line number Diff line
@@ -2428,7 +2428,8 @@ public class WifiConfiguration implements Parcelable {
        } else if (allowedKeyManagement.get(KeyMgmt.WPA_EAP)
                || allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
            key = SSID + KeyMgmt.strings[KeyMgmt.WPA_EAP];
        } else if (wepKeys[0] != null) {
        } else if (wepTxKeyIndex >= 0 && wepTxKeyIndex < wepKeys.length
                && wepKeys[wepTxKeyIndex] != null) {
            key = SSID + "WEP";
        } else if (allowedKeyManagement.get(KeyMgmt.OWE)) {
            key = SSID + KeyMgmt.strings[KeyMgmt.OWE];
+16 −0
Original line number Diff line number Diff line
@@ -270,7 +270,23 @@ public class WifiConfigurationTest {
        config.allowedKeyManagement.clear();
        assertEquals(mSsid + "WEP", config.getSsidAndSecurityTypeString());

        // set WEP key and give a valid index.
        config.wepKeys[0] = null;
        config.wepKeys[2] = "TestWep";
        config.wepTxKeyIndex = 2;
        config.allowedKeyManagement.clear();
        assertEquals(mSsid + "WEP", config.getSsidAndSecurityTypeString());

        // set WEP key but does not give a valid index.
        config.wepKeys[0] = null;
        config.wepKeys[2] = "TestWep";
        config.wepTxKeyIndex = 0;
        config.allowedKeyManagement.clear();
        config.allowedKeyManagement.set(KeyMgmt.OWE);
        assertEquals(mSsid + KeyMgmt.strings[KeyMgmt.OWE], config.getSsidAndSecurityTypeString());

        config.wepKeys[0] = null;
        config.wepTxKeyIndex = 0;
        config.allowedKeyManagement.clear();
        config.allowedKeyManagement.set(KeyMgmt.OWE);
        assertEquals(mSsid + KeyMgmt.strings[KeyMgmt.OWE], config.getSsidAndSecurityTypeString());