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

Commit 5aa95553 authored by Quang Anh Luong's avatar Quang Anh Luong Committed by Quang Luong
Browse files

Do not auto-downgrade WPA3->Transition mode if password too short

Hotspot security is auto-downgraded from WPA3->Transition mode if the
band is changed from 6Ghz -> 2.4/5GHz. However, Transition mode requires
a password of 8 chars or more, but WPA3 SAE does not. Avoid changing the
security type if the current password is less than 8 chars.

Flag: EXEMPT minor bugfix

Bug: 366452667
Test: atest WifiHotspotRepositoryTest
Change-Id: I1abadd59966e170b51899782746b9f14e33e6186
parent a4b27574
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -356,10 +356,11 @@ public class WifiHotspotRepository {
                log("setSpeedType(), setBand(BAND_2GHZ)");
                configBuilder.setBand(BAND_2GHZ);
            }
            // Set the security type back to WPA2/WPA3 if we're moving from 6GHz to something else.
            if ((config.getBand() & BAND_6GHZ) != 0) {
                configBuilder.setPassphrase(
                        generatePassword(config), SECURITY_TYPE_WPA3_SAE_TRANSITION);
            // Set the security type back to WPA2/WPA3 if the password is at least 8 characters and
            // we're moving from 6GHz to something else.
            String passphrase = generatePassword(config);
            if ((passphrase.length() >= 8) && (config.getBand() & BAND_6GHZ) != 0) {
                configBuilder.setPassphrase(passphrase, SECURITY_TYPE_WPA3_SAE_TRANSITION);
            }
        }
        setSoftApConfiguration(configBuilder.build());
+28 −5
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ import java.util.Arrays;
public class WifiHotspotRepositoryTest {
    static final String WIFI_SSID = "wifi_ssid";
    static final String WIFI_PASSWORD = "wifi_password";
    static final String WIFI_PASSWORD_SHORT = "wifi";

    static final int WIFI_5GHZ_BAND_PREFERRED = BAND_2GHZ_5GHZ;
    static final int WIFI_6GHZ_BAND_PREFERRED = BAND_2GHZ_5GHZ_6GHZ;
@@ -477,7 +478,7 @@ public class WifiHotspotRepositoryTest {

    @Test
    public void setSpeedType_2g5ghzTo6ghz_setConfigSecurityToWpa3() {
        mockConfig(SPEED_2GHZ_5GHZ, SECURITY_TYPE_WPA3_SAE_TRANSITION);
        mockConfig(SPEED_2GHZ_5GHZ, SECURITY_TYPE_WPA3_SAE_TRANSITION, WIFI_PASSWORD);

        mRepository.setSpeedType(SPEED_6GHZ);

@@ -497,10 +498,32 @@ public class WifiHotspotRepositoryTest {
        SparseIntArray channels = mSoftApConfigCaptor.getValue().getChannels();
        assertThat(channels.get(BAND_2GHZ, CHANNEL_NOT_FOUND)).isNotEqualTo(CHANNEL_NOT_FOUND);
        assertThat(channels.get(BAND_2GHZ_5GHZ, CHANNEL_NOT_FOUND)).isNotEqualTo(CHANNEL_NOT_FOUND);
    }

    @Test
    public void setSpeedType_6ghzTo2g5ghzWith8CharPassphrase_changesSecurityToWpa3Transition() {
        mockConfigSpeedType(SPEED_6GHZ);
        mRepository.mIsDualBand = true;

        mRepository.setSpeedType(SPEED_2GHZ_5GHZ);

        verify(mWifiManager).setSoftApConfiguration(mSoftApConfigCaptor.capture());
        assertThat(mSoftApConfigCaptor.getValue().getSecurityType())
                .isEqualTo(SECURITY_TYPE_WPA3_SAE_TRANSITION);
    }

    @Test
    public void setSpeedType_6ghzTo2g5ghzWithLessThan8CharPassphrase_doesNotChangeSecurity() {
        mockConfig(SECURITY_TYPE_WPA3_SAE, SPEED_6GHZ, WIFI_PASSWORD_SHORT);
        mRepository.mIsDualBand = true;

        mRepository.setSpeedType(SPEED_2GHZ_5GHZ);

        verify(mWifiManager).setSoftApConfiguration(mSoftApConfigCaptor.capture());
        assertThat(mSoftApConfigCaptor.getValue().getSecurityType())
                .isEqualTo(SECURITY_TYPE_WPA3_SAE);
    }

    @Test
    public void setSpeedType_2ghzTo5ghz_setConfigBandTo5ghzPreferred() {
        mockConfigSpeedType(SPEED_2GHZ);
@@ -784,18 +807,18 @@ public class WifiHotspotRepositoryTest {
    }

    private void mockConfigSecurityType(int securityType) {
        mockConfig(securityType, SPEED_2GHZ);
        mockConfig(securityType, SPEED_2GHZ,
                (securityType == SECURITY_TYPE_OPEN) ? null : WIFI_PASSWORD);
    }

    private void mockConfigSpeedType(int speedType) {
        mockConfig(SECURITY_TYPE_WPA3_SAE, speedType);
        mockConfig(SECURITY_TYPE_WPA3_SAE, speedType, WIFI_PASSWORD);
    }

    private void mockConfig(int securityType, int speedType) {
    private void mockConfig(int securityType, int speedType, String passphrase) {
        SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder();
        // Security Type
        doReturn(securityType).when(mSecurityType).getValue();
        String passphrase = (securityType == SECURITY_TYPE_OPEN) ? null : WIFI_PASSWORD;
        configBuilder.setPassphrase(passphrase, securityType).build();

        // Speed Type