OSDN Git Service

packages/apps/Settings: Add logic and strings to support WPA3 and OWE
authorHai Shalom <haishalom@google.com>
Tue, 16 Oct 2018 21:17:15 +0000 (14:17 -0700)
committerHai Shalom <haishalom@google.com>
Tue, 6 Nov 2018 00:40:07 +0000 (16:40 -0800)
Add and update Wi-Fi security strings, and add logic to enable WPA3
and OWE. Modified WPA2-PSK to WPA2-Personal, and added WPA3-Personal,
Enhanced Open and WPA3-Enterprise.

Bug: 112195778
Test: Basic functional tests
Change-Id: Ia97761a7f0a9e2fee768dfaf3578a2f1090d29c6

res/values/arrays.xml
src/com/android/settings/wifi/WifiConfigController.java
src/com/android/settings/wifi/WifiSettings.java
tests/robotests/src/com/android/settings/wifi/tether/WifiTetherSecurityPreferenceControllerTest.java

index 94d915c..c3faaba 100644 (file)
     <string-array name="wifi_security">
         <!-- The Wi-Fi network does not have any security. -->
         <item>@string/wifi_security_none</item>
+        <item translatable="false">@string/wifi_security_owe</item>
         <item translatable="false">@string/wifi_security_wep</item>
         <item translatable="false">@string/wifi_security_psk_generic</item>
+        <item translatable="false">@string/wifi_security_sae</item>
         <item translatable="false">@string/wifi_security_eap</item>
-
+        <item translatable="false">@string/wifi_security_eap_suiteb</item>
     </string-array>
 
     <!-- Match this with the constants in AccessPoint. --> <skip />
         <item>@string/wifi_security_none</item>
         <item translatable="false">@string/wifi_security_wep</item>
         <item translatable="false">@string/wifi_security_psk_generic</item>
+        <item translatable="false">@string/wifi_security_sae</item>
     </string-array>
 
     <!-- Security types for wireless tether -->
index 4b93fc1..70837a6 100644 (file)
@@ -454,6 +454,13 @@ public class WifiConfigController implements TextWatcher,
         return false;
     }
 
+    boolean isValidSaePassword(String password) {
+        if (password.length() >= 1 && password.length() <= 63) {
+            return true;
+        }
+        return false;
+    }
+
     boolean isSubmittable() {
         boolean enabled = false;
         boolean passwordInvalid = false;
@@ -461,7 +468,9 @@ public class WifiConfigController implements TextWatcher,
                 && ((mAccessPointSecurity == AccessPoint.SECURITY_WEP
                         && mPasswordView.length() == 0)
                     || (mAccessPointSecurity == AccessPoint.SECURITY_PSK
-                           && !isValidPsk(mPasswordView.getText().toString())))) {
+                           && !isValidPsk(mPasswordView.getText().toString()))
+                    || (mAccessPointSecurity == AccessPoint.SECURITY_SAE
+                        && !isValidSaePassword(mPasswordView.getText().toString())))) {
             passwordInvalid = true;
         }
         if ((mSsidView != null && mSsidView.length() == 0)
@@ -475,7 +484,9 @@ public class WifiConfigController implements TextWatcher,
         } else {
             enabled = ipAndProxyFieldsAreValid();
         }
-        if (mAccessPointSecurity == AccessPoint.SECURITY_EAP && mEapCaCertSpinner != null
+        if ((mAccessPointSecurity == AccessPoint.SECURITY_EAP ||
+                mAccessPointSecurity == AccessPoint.SECURITY_EAP_SUITE_B)
+                && mEapCaCertSpinner != null
                 && mView.findViewById(R.id.l_ca_cert).getVisibility() != View.GONE) {
             String caCertSelection = (String) mEapCaCertSpinner.getSelectedItem();
             if (caCertSelection.equals(mUnspecifiedCertString)) {
@@ -492,7 +503,9 @@ public class WifiConfigController implements TextWatcher,
                 enabled = false;
             }
         }
-        if (mAccessPointSecurity == AccessPoint.SECURITY_EAP && mEapUserCertSpinner != null
+        if ((mAccessPointSecurity == AccessPoint.SECURITY_EAP ||
+                mAccessPointSecurity == AccessPoint.SECURITY_EAP_SUITE_B)
+                && mEapUserCertSpinner != null
                 && mView.findViewById(R.id.l_user_cert).getVisibility() != View.GONE
                 && mEapUserCertSpinner.getSelectedItem().equals(mUnspecifiedCertString)) {
             // Disallow submit if the user has not selected a user certificate for an EAP network
@@ -590,8 +603,18 @@ public class WifiConfigController implements TextWatcher,
                 break;
 
             case AccessPoint.SECURITY_EAP:
+            case AccessPoint.SECURITY_EAP_SUITE_B:
                 config.allowedKeyManagement.set(KeyMgmt.WPA_EAP);
                 config.allowedKeyManagement.set(KeyMgmt.IEEE8021X);
+                if (mAccessPointSecurity == AccessPoint.SECURITY_EAP_SUITE_B) {
+                    config.allowedKeyManagement.set(KeyMgmt.SUITE_B_192);
+                    config.requirePMF = true;
+                    config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.GCMP_256);
+                    config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.GCMP_256);
+                    config.allowedGroupMgmtCiphers.set(WifiConfiguration.GroupMgmtCipher
+                            .BIP_GMAC_256);
+                    config.allowedSuiteBCiphers.set(WifiConfiguration.SuiteBCipher.ECDHE_RSA);
+                }
                 config.enterpriseConfig = new WifiEnterpriseConfig();
                 int eapMethod = mEapMethodSpinner.getSelectedItemPosition();
                 int phase2Method = mPhase2Spinner.getSelectedItemPosition();
@@ -700,6 +723,20 @@ public class WifiConfigController implements TextWatcher,
                     config.enterpriseConfig.setPassword(mPasswordView.getText().toString());
                 }
                 break;
+            case AccessPoint.SECURITY_SAE:
+                config.allowedKeyManagement.set(KeyMgmt.SAE);
+                config.requirePMF = true;
+                if (mPasswordView.length() != 0) {
+                    String password = mPasswordView.getText().toString();
+                    config.preSharedKey = '"' + password + '"';
+                }
+                break;
+
+            case AccessPoint.SECURITY_OWE:
+                config.allowedKeyManagement.set(KeyMgmt.OWE);
+                config.requirePMF = true;
+                break;
+
             default:
                 return null;
         }
@@ -851,7 +888,8 @@ public class WifiConfigController implements TextWatcher,
     }
 
     private void showSecurityFields() {
-        if (mAccessPointSecurity == AccessPoint.SECURITY_NONE) {
+        if (mAccessPointSecurity == AccessPoint.SECURITY_NONE ||
+                  mAccessPointSecurity == AccessPoint.SECURITY_OWE) {
             mView.findViewById(R.id.security_fields).setVisibility(View.GONE);
             return;
         }
@@ -870,7 +908,8 @@ public class WifiConfigController implements TextWatcher,
             }
         }
 
-        if (mAccessPointSecurity != AccessPoint.SECURITY_EAP) {
+        if (mAccessPointSecurity != AccessPoint.SECURITY_EAP &&
+                mAccessPointSecurity != AccessPoint.SECURITY_EAP_SUITE_B) {
             mView.findViewById(R.id.eap).setVisibility(View.GONE);
             return;
         }
index f097d5b..1c9a5e1 100644 (file)
@@ -488,7 +488,8 @@ public class WifiSettings extends RestrictedSettingsFragment
                 menu.add(Menu.NONE, MENU_ID_MODIFY, 0, R.string.wifi_menu_modify);
                 NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());
                 if (nfcAdapter != null && nfcAdapter.isEnabled() &&
-                        mSelectedAccessPoint.getSecurity() != AccessPoint.SECURITY_NONE) {
+                        (!(mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_NONE) ||
+                                (mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_OWE))) {
                     // Only allow writing of NFC tags for password-protected networks.
                     menu.add(Menu.NONE, MENU_ID_WRITE_NFC, 0, R.string.wifi_menu_write_to_nfc);
                 }
@@ -506,7 +507,8 @@ public class WifiSettings extends RestrictedSettingsFragment
                 boolean isSavedNetwork = mSelectedAccessPoint.isSaved();
                 if (isSavedNetwork) {
                     connect(mSelectedAccessPoint.getConfig(), isSavedNetwork);
-                } else if (mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_NONE) {
+                } else if ((mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_NONE) ||
+                        (mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_OWE)) {
                     /** Bypass dialog for unsecured networks */
                     mSelectedAccessPoint.generateOpenNetworkConfig();
                     connect(mSelectedAccessPoint.getConfig(), isSavedNetwork);
@@ -552,7 +554,8 @@ public class WifiSettings extends RestrictedSettingsFragment
              * networks, or Passpoint provided networks.
              */
             WifiConfiguration config = mSelectedAccessPoint.getConfig();
-            if (mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_NONE) {
+            if ((mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_NONE) ||
+                    (mSelectedAccessPoint.getSecurity() == AccessPoint.SECURITY_OWE)) {
                 mSelectedAccessPoint.generateOpenNetworkConfig();
                 connect(mSelectedAccessPoint.getConfig(), mSelectedAccessPoint.isSaved());
             } else if (mSelectedAccessPoint.isSaved() && config != null
@@ -772,7 +775,8 @@ public class WifiSettings extends RestrictedSettingsFragment
                 preference.setKey(key);
                 preference.setOrder(index);
                 if (mOpenSsid != null && mOpenSsid.equals(accessPoint.getSsidStr())
-                        && accessPoint.getSecurity() != AccessPoint.SECURITY_NONE) {
+                        && (accessPoint.getSecurity() != AccessPoint.SECURITY_NONE &&
+                        accessPoint.getSecurity() != AccessPoint.SECURITY_OWE)) {
                     if (!accessPoint.isSaved() || isDisabledByWrongPassword(accessPoint)) {
                         onPreferenceTreeClick(preference);
                         mOpenSsid = null;
index f813185..e8d13df 100644 (file)
@@ -66,7 +66,7 @@ public class WifiTetherSecurityPreferenceControllerTest {
     public void onPreferenceChange_securityValueUpdated() {
         mController.onPreferenceChange(mPreference, WPA2_PSK);
         assertThat(mController.getSecurityType()).isEqualTo(WifiConfiguration.KeyMgmt.WPA2_PSK);
-        assertThat(mPreference.getSummary()).isEqualTo("WPA2 PSK");
+        assertThat(mPreference.getSummary()).isEqualTo("WPA2-Personal");
 
         mController.onPreferenceChange(mPreference, NONE);
         assertThat(mController.getSecurityType()).isEqualTo(WifiConfiguration.KeyMgmt.NONE);
@@ -75,11 +75,11 @@ public class WifiTetherSecurityPreferenceControllerTest {
 
     @Test
     public void updateDisplay_preferenceUpdated() {
-        // test defaulting to WPA2 PSK on new config
+        // test defaulting to WPA2-Personal on new config
         when(mWifiManager.getWifiApConfiguration()).thenReturn(null);
         mController.updateDisplay();
         assertThat(mController.getSecurityType()).isEqualTo(WifiConfiguration.KeyMgmt.WPA2_PSK);
-        assertThat(mPreference.getSummary()).isEqualTo("WPA2 PSK");
+        assertThat(mPreference.getSummary()).isEqualTo("WPA2-Personal");
 
         // test open tether network
         when(mWifiManager.getWifiApConfiguration()).thenReturn(mConfig);
@@ -89,11 +89,11 @@ public class WifiTetherSecurityPreferenceControllerTest {
         assertThat(mController.getSecurityType()).isEqualTo(WifiConfiguration.KeyMgmt.NONE);
         assertThat(mPreference.getSummary()).isEqualTo("None");
 
-        // test WPA2 PSK tether network
+        // test WPA2-Personal tether network
         mConfig.allowedKeyManagement.clear();
         mConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA2_PSK);
         mController.updateDisplay();
         assertThat(mController.getSecurityType()).isEqualTo(WifiConfiguration.KeyMgmt.WPA2_PSK);
-        assertThat(mPreference.getSummary()).isEqualTo("WPA2 PSK");
+        assertThat(mPreference.getSummary()).isEqualTo("WPA2-Personal");
     }
 }