diff options
author | Peter Qiu <zqiu@google.com> | 2017-02-23 11:32:33 -0800 |
---|---|---|
committer | Peter Qiu <zqiu@google.com> | 2017-03-02 14:12:21 -0800 |
commit | 5e4822d5dba15e45c5ff43dfba3ac7803b3f4e28 (patch) | |
tree | 54fddbc687ab2e6f03623f54dd656e12dc11e7bc /tests/wifitests/src/com/android/server/wifi/hotspot2 | |
parent | 498d406fbe956b1b9789a8739f6d7de9caaa851c (diff) | |
download | android_frameworks_opt_net_wifi-5e4822d5dba15e45c5ff43dfba3ac7803b3f4e28.tar.gz android_frameworks_opt_net_wifi-5e4822d5dba15e45c5ff43dfba3ac7803b3f4e28.tar.bz2 android_frameworks_opt_net_wifi-5e4822d5dba15e45c5ff43dfba3ac7803b3f4e28.zip |
hotspot2: migrate legacy Passpoint configurations
When the legacy Passpoint configuration is read from the legacy
store, it will represented as WifiConfiguration and stored in the
share store. When the owner of the legacy Passpoint configuration
logs in, the configuration will be converted to PasspointConfiguration
and added to PasspointManager, then persist to the user store in the
new format.
Bug: 34206769
Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh
Test: manually upgrade a bullhead containing Boingo and Global Reach
Passpoint profiles from N to O, verify configurations are
maintained and still able to connect to those APs
Change-Id: Idcd858326968463cea0cdc99452ba67b13d2ac77
Diffstat (limited to 'tests/wifitests/src/com/android/server/wifi/hotspot2')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java | 233 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java | 144 |
2 files changed, 370 insertions, 7 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java index 46815abf0..8def58ccf 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java @@ -39,11 +39,14 @@ import static org.mockito.MockitoAnnotations.initMocks; import android.content.Context; import android.content.Intent; import android.net.wifi.EAPConstants; +import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiEnterpriseConfig; import android.net.wifi.hotspot2.PasspointConfiguration; import android.net.wifi.hotspot2.pps.Credential; import android.net.wifi.hotspot2.pps.HomeSp; import android.os.UserHandle; import android.test.suitebuilder.annotation.SmallTest; +import android.util.Base64; import android.util.Pair; import com.android.server.wifi.Clock; @@ -64,6 +67,7 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -187,7 +191,7 @@ public class PasspointManagerTest { userCredential.setUsername("username"); userCredential.setPassword("password"); userCredential.setEapType(EAPConstants.EAP_TTLS); - userCredential.setNonEapInnerMethod("MS-CHAP"); + userCredential.setNonEapInnerMethod(Credential.UserCredential.AUTH_METHOD_MSCHAP); credential.setUserCredential(userCredential); config.setCredential(credential); return config; @@ -645,4 +649,231 @@ public class PasspointManagerTest { verify(mWifiConfigManager).saveToStore(true); reset(mWifiConfigManager); } + + /** + * Verify that a PasspointProvider with expected PasspointConfiguration will be installed when + * adding a legacy Passpoint configuration containing a valid user credential. + * + * @throws Exception + */ + @Test + public void addLegacyPasspointConfigWithUserCredential() throws Exception { + // Test data. + String fqdn = "test.com"; + String friendlyName = "Friendly Name"; + long[] rcOIs = new long[] {0x1234L, 0x2345L}; + String realm = "realm.com"; + String username = "username"; + String password = "password"; + byte[] base64EncodedPw = + Base64.encode(password.getBytes(StandardCharsets.UTF_8), Base64.DEFAULT); + String encodedPasswordStr = new String(base64EncodedPw, StandardCharsets.UTF_8); + String caCertificateAlias = "CaCert"; + + // Setup WifiConfiguration for legacy Passpoint configuraiton. + WifiConfiguration wifiConfig = new WifiConfiguration(); + wifiConfig.FQDN = fqdn; + wifiConfig.providerFriendlyName = friendlyName; + wifiConfig.roamingConsortiumIds = rcOIs; + wifiConfig.enterpriseConfig.setIdentity(username); + wifiConfig.enterpriseConfig.setPassword(password); + wifiConfig.enterpriseConfig.setRealm(realm); + wifiConfig.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TTLS); + wifiConfig.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.PAP); + wifiConfig.enterpriseConfig.setCaCertificateAlias(caCertificateAlias); + + // Setup expected {@link PasspointConfiguration} + PasspointConfiguration passpointConfig = new PasspointConfiguration(); + HomeSp homeSp = new HomeSp(); + homeSp.setFqdn(fqdn); + homeSp.setFriendlyName(friendlyName); + homeSp.setRoamingConsortiumOis(rcOIs); + passpointConfig.setHomeSp(homeSp); + Credential credential = new Credential(); + Credential.UserCredential userCredential = new Credential.UserCredential(); + userCredential.setUsername(username); + userCredential.setPassword(encodedPasswordStr); + userCredential.setEapType(EAPConstants.EAP_TTLS); + userCredential.setNonEapInnerMethod("PAP"); + credential.setUserCredential(userCredential); + credential.setRealm(realm); + passpointConfig.setCredential(credential); + + assertTrue(PasspointManager.addLegacyPasspointConfig(wifiConfig)); + verifyInstalledConfig(passpointConfig); + } + + /** + * Verify that adding a legacy Passpoint configuration containing user credential will + * fail when client certificate is not provided. + * + * @throws Exception + */ + @Test + public void addLegacyPasspointConfigWithUserCredentialWithoutCaCert() throws Exception { + // Test data. + String fqdn = "test.com"; + String friendlyName = "Friendly Name"; + long[] rcOIs = new long[] {0x1234L, 0x2345L}; + String realm = "realm.com"; + String username = "username"; + String password = "password"; + byte[] base64EncodedPw = + Base64.encode(password.getBytes(StandardCharsets.UTF_8), Base64.DEFAULT); + String encodedPasswordStr = new String(base64EncodedPw, StandardCharsets.UTF_8); + + // Setup WifiConfiguration for legacy Passpoint configuraiton. + WifiConfiguration wifiConfig = new WifiConfiguration(); + wifiConfig.FQDN = fqdn; + wifiConfig.providerFriendlyName = friendlyName; + wifiConfig.roamingConsortiumIds = rcOIs; + wifiConfig.enterpriseConfig.setIdentity(username); + wifiConfig.enterpriseConfig.setPassword(password); + wifiConfig.enterpriseConfig.setRealm(realm); + wifiConfig.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TTLS); + wifiConfig.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.PAP); + + assertFalse(PasspointManager.addLegacyPasspointConfig(wifiConfig)); + } + + /** + * Verify that a PasspointProvider with expected PasspointConfiguration will be installed when + * adding a legacy Passpoint configuration containing a valid SIM credential. + * + * @throws Exception + */ + @Test + public void addLegacyPasspointConfigWithSimCredential() throws Exception { + // Test data. + String fqdn = "test.com"; + String friendlyName = "Friendly Name"; + long[] rcOIs = new long[] {0x1234L, 0x2345L}; + String realm = "realm.com"; + String imsi = "1234"; + + // Setup WifiConfiguration for legacy Passpoint configuraiton. + WifiConfiguration wifiConfig = new WifiConfiguration(); + wifiConfig.FQDN = fqdn; + wifiConfig.providerFriendlyName = friendlyName; + wifiConfig.roamingConsortiumIds = rcOIs; + wifiConfig.enterpriseConfig.setRealm(realm); + wifiConfig.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.SIM); + wifiConfig.enterpriseConfig.setPlmn(imsi); + + // Setup expected {@link PasspointConfiguration} + PasspointConfiguration passpointConfig = new PasspointConfiguration(); + HomeSp homeSp = new HomeSp(); + homeSp.setFqdn(fqdn); + homeSp.setFriendlyName(friendlyName); + homeSp.setRoamingConsortiumOis(rcOIs); + passpointConfig.setHomeSp(homeSp); + Credential credential = new Credential(); + Credential.SimCredential simCredential = new Credential.SimCredential(); + simCredential.setEapType(EAPConstants.EAP_SIM); + simCredential.setImsi(imsi); + credential.setSimCredential(simCredential); + credential.setRealm(realm); + passpointConfig.setCredential(credential); + + assertTrue(PasspointManager.addLegacyPasspointConfig(wifiConfig)); + verifyInstalledConfig(passpointConfig); + } + + /** + * Verify that a PasspointProvider with expected PasspointConfiguration will be installed when + * adding a legacy Passpoint configuration containing a valid certificate credential. + * + * @throws Exception + */ + @Test + public void addLegacyPasspointConfigWithCertCredential() throws Exception { + // Test data. + String fqdn = "test.com"; + String friendlyName = "Friendly Name"; + long[] rcOIs = new long[] {0x1234L, 0x2345L}; + String realm = "realm.com"; + String caCertificateAlias = "CaCert"; + String clientCertificateAlias = "ClientCert"; + + // Setup WifiConfiguration for legacy Passpoint configuraiton. + WifiConfiguration wifiConfig = new WifiConfiguration(); + wifiConfig.FQDN = fqdn; + wifiConfig.providerFriendlyName = friendlyName; + wifiConfig.roamingConsortiumIds = rcOIs; + wifiConfig.enterpriseConfig.setRealm(realm); + wifiConfig.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TLS); + wifiConfig.enterpriseConfig.setCaCertificateAlias(caCertificateAlias); + wifiConfig.enterpriseConfig.setClientCertificateAlias(clientCertificateAlias); + + // Setup expected {@link PasspointConfiguration} + PasspointConfiguration passpointConfig = new PasspointConfiguration(); + HomeSp homeSp = new HomeSp(); + homeSp.setFqdn(fqdn); + homeSp.setFriendlyName(friendlyName); + homeSp.setRoamingConsortiumOis(rcOIs); + passpointConfig.setHomeSp(homeSp); + Credential credential = new Credential(); + Credential.CertificateCredential certCredential = new Credential.CertificateCredential(); + certCredential.setCertType(Credential.CertificateCredential.CERT_TYPE_X509V3); + credential.setCertCredential(certCredential); + credential.setRealm(realm); + passpointConfig.setCredential(credential); + + assertTrue(PasspointManager.addLegacyPasspointConfig(wifiConfig)); + verifyInstalledConfig(passpointConfig); + } + + /** + * Verify that adding a legacy Passpoint configuration containing certificate credential will + * fail when CA certificate is not provided. + * + * @throws Exception + */ + @Test + public void addLegacyPasspointConfigWithCertCredentialWithoutCaCert() throws Exception { + // Test data. + String fqdn = "test.com"; + String friendlyName = "Friendly Name"; + long[] rcOIs = new long[] {0x1234L, 0x2345L}; + String realm = "realm.com"; + String clientCertificateAlias = "ClientCert"; + + // Setup WifiConfiguration for legacy Passpoint configuraiton. + WifiConfiguration wifiConfig = new WifiConfiguration(); + wifiConfig.FQDN = fqdn; + wifiConfig.providerFriendlyName = friendlyName; + wifiConfig.roamingConsortiumIds = rcOIs; + wifiConfig.enterpriseConfig.setRealm(realm); + wifiConfig.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TLS); + wifiConfig.enterpriseConfig.setClientCertificateAlias(clientCertificateAlias); + + assertFalse(PasspointManager.addLegacyPasspointConfig(wifiConfig)); + } + + /** + * Verify that adding a legacy Passpoint configuration containing certificate credential will + * fail when client certificate is not provided. + * + * @throws Exception + */ + @Test + public void addLegacyPasspointConfigWithCertCredentialWithoutClientCert() throws Exception { + // Test data. + String fqdn = "test.com"; + String friendlyName = "Friendly Name"; + long[] rcOIs = new long[] {0x1234L, 0x2345L}; + String realm = "realm.com"; + String caCertificateAlias = "CaCert"; + + // Setup WifiConfiguration for legacy Passpoint configuraiton. + WifiConfiguration wifiConfig = new WifiConfiguration(); + wifiConfig.FQDN = fqdn; + wifiConfig.providerFriendlyName = friendlyName; + wifiConfig.roamingConsortiumIds = rcOIs; + wifiConfig.enterpriseConfig.setRealm(realm); + wifiConfig.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TLS); + wifiConfig.enterpriseConfig.setCaCertificateAlias(caCertificateAlias); + + assertFalse(PasspointManager.addLegacyPasspointConfig(wifiConfig)); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java index 15f92583e..7551bc049 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointProviderTest.java @@ -351,7 +351,7 @@ public class PasspointProviderTest { config.setHomeSp(homeSp); Credential credential = new Credential(); Credential.UserCredential userCredential = new Credential.UserCredential(); - userCredential.setNonEapInnerMethod("MS-CHAP-V2"); + userCredential.setNonEapInnerMethod(Credential.UserCredential.AUTH_METHOD_MSCHAPV2); credential.setUserCredential(userCredential); config.setCredential(credential); mProvider = createProvider(config); @@ -383,7 +383,7 @@ public class PasspointProviderTest { Credential credential = new Credential(); credential.setRealm(testRealm); Credential.UserCredential userCredential = new Credential.UserCredential(); - userCredential.setNonEapInnerMethod("MS-CHAP-V2"); + userCredential.setNonEapInnerMethod(Credential.UserCredential.AUTH_METHOD_MSCHAPV2); credential.setUserCredential(userCredential); config.setCredential(credential); mProvider = createProvider(config); @@ -419,7 +419,7 @@ public class PasspointProviderTest { Credential credential = new Credential(); credential.setRealm(testRealm); Credential.UserCredential userCredential = new Credential.UserCredential(); - userCredential.setNonEapInnerMethod("MS-CHAP-V2"); + userCredential.setNonEapInnerMethod(Credential.UserCredential.AUTH_METHOD_MSCHAPV2); credential.setUserCredential(userCredential); config.setCredential(credential); mProvider = createProvider(config); @@ -482,7 +482,7 @@ public class PasspointProviderTest { config.setHomeSp(homeSp); Credential credential = new Credential(); Credential.UserCredential userCredential = new Credential.UserCredential(); - userCredential.setNonEapInnerMethod("MS-CHAP-V2"); + userCredential.setNonEapInnerMethod(Credential.UserCredential.AUTH_METHOD_MSCHAPV2); credential.setUserCredential(userCredential); config.setCredential(credential); mProvider = createProvider(config); @@ -541,7 +541,7 @@ public class PasspointProviderTest { Credential credential = new Credential(); credential.setRealm(testRealm); Credential.UserCredential userCredential = new Credential.UserCredential(); - userCredential.setNonEapInnerMethod("MS-CHAP-V2"); + userCredential.setNonEapInnerMethod(Credential.UserCredential.AUTH_METHOD_MSCHAPV2); credential.setUserCredential(userCredential); config.setCredential(credential); mProvider = createProvider(config); @@ -628,7 +628,7 @@ public class PasspointProviderTest { Credential.UserCredential userCredential = new Credential.UserCredential(); userCredential.setUsername(username); userCredential.setPassword(encodedPasswordStr); - userCredential.setNonEapInnerMethod("MS-CHAP-V2"); + userCredential.setNonEapInnerMethod(Credential.UserCredential.AUTH_METHOD_MSCHAPV2); credential.setUserCredential(userCredential); credential.setCaCertificate(FakeKeys.CA_CERT0); config.setCredential(credential); @@ -762,4 +762,136 @@ public class PasspointProviderTest { assertEquals(WifiEnterpriseConfig.Eap.SIM, wifiEnterpriseConfig.getEapMethod()); assertEquals(imsi, wifiEnterpriseConfig.getPlmn()); } + + /** + * Verify that an expected {@link PasspointConfiguration} will be returned when converting + * from a {@link WifiConfiguration} containing an user credential. + * + * @throws Exception + */ + @Test + public void convertFromWifiConfigWithUserCredential() throws Exception { + // Test data. + String fqdn = "test.com"; + String friendlyName = "Friendly Name"; + long[] rcOIs = new long[] {0x1234L, 0x2345L}; + String realm = "realm.com"; + String username = "username"; + String password = "password"; + byte[] base64EncodedPw = + Base64.encode(password.getBytes(StandardCharsets.UTF_8), Base64.DEFAULT); + String encodedPasswordStr = new String(base64EncodedPw, StandardCharsets.UTF_8); + + // Setup WifiConfiguration for legacy Passpoint configuraiton. + WifiConfiguration wifiConfig = new WifiConfiguration(); + wifiConfig.FQDN = fqdn; + wifiConfig.providerFriendlyName = friendlyName; + wifiConfig.roamingConsortiumIds = rcOIs; + wifiConfig.enterpriseConfig.setIdentity(username); + wifiConfig.enterpriseConfig.setPassword(password); + wifiConfig.enterpriseConfig.setRealm(realm); + wifiConfig.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TTLS); + wifiConfig.enterpriseConfig.setPhase2Method(WifiEnterpriseConfig.Phase2.PAP); + + // Setup expected {@link PasspointConfiguration} + PasspointConfiguration passpointConfig = new PasspointConfiguration(); + HomeSp homeSp = new HomeSp(); + homeSp.setFqdn(fqdn); + homeSp.setFriendlyName(friendlyName); + homeSp.setRoamingConsortiumOis(rcOIs); + passpointConfig.setHomeSp(homeSp); + Credential credential = new Credential(); + Credential.UserCredential userCredential = new Credential.UserCredential(); + userCredential.setUsername(username); + userCredential.setPassword(encodedPasswordStr); + userCredential.setEapType(EAPConstants.EAP_TTLS); + userCredential.setNonEapInnerMethod("PAP"); + credential.setUserCredential(userCredential); + credential.setRealm(realm); + passpointConfig.setCredential(credential); + + assertEquals(passpointConfig, PasspointProvider.convertFromWifiConfig(wifiConfig)); + } + + /** + * Verify that an expected {@link PasspointConfiguration} will be returned when converting + * from a {@link WifiConfiguration} containing a SIM credential. + * + * @throws Exception + */ + @Test + public void convertFromWifiConfigWithSimCredential() throws Exception { + // Test data. + String fqdn = "test.com"; + String friendlyName = "Friendly Name"; + long[] rcOIs = new long[] {0x1234L, 0x2345L}; + String realm = "realm.com"; + String imsi = "1234"; + + // Setup WifiConfiguration for legacy Passpoint configuraiton. + WifiConfiguration wifiConfig = new WifiConfiguration(); + wifiConfig.FQDN = fqdn; + wifiConfig.providerFriendlyName = friendlyName; + wifiConfig.roamingConsortiumIds = rcOIs; + wifiConfig.enterpriseConfig.setRealm(realm); + wifiConfig.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.SIM); + wifiConfig.enterpriseConfig.setPlmn(imsi); + + // Setup expected {@link PasspointConfiguration} + PasspointConfiguration passpointConfig = new PasspointConfiguration(); + HomeSp homeSp = new HomeSp(); + homeSp.setFqdn(fqdn); + homeSp.setFriendlyName(friendlyName); + homeSp.setRoamingConsortiumOis(rcOIs); + passpointConfig.setHomeSp(homeSp); + Credential credential = new Credential(); + Credential.SimCredential simCredential = new Credential.SimCredential(); + simCredential.setEapType(EAPConstants.EAP_SIM); + simCredential.setImsi(imsi); + credential.setSimCredential(simCredential); + credential.setRealm(realm); + passpointConfig.setCredential(credential); + + assertEquals(passpointConfig, PasspointProvider.convertFromWifiConfig(wifiConfig)); + } + + /** + * Verify that an expected {@link PasspointConfiguration} will be returned when converting + * from a {@link WifiConfiguration} containing a certificate credential. + * + * @throws Exception + */ + @Test + public void convertFromWifiConfigWithCertCredential() throws Exception { + // Test data. + String fqdn = "test.com"; + String friendlyName = "Friendly Name"; + long[] rcOIs = new long[] {0x1234L, 0x2345L}; + String realm = "realm.com"; + + // Setup WifiConfiguration for legacy Passpoint configuraiton. + WifiConfiguration wifiConfig = new WifiConfiguration(); + wifiConfig.FQDN = fqdn; + wifiConfig.providerFriendlyName = friendlyName; + wifiConfig.roamingConsortiumIds = rcOIs; + wifiConfig.enterpriseConfig.setRealm(realm); + wifiConfig.enterpriseConfig.setEapMethod(WifiEnterpriseConfig.Eap.TLS); + + // Setup expected {@link PasspointConfiguration} + PasspointConfiguration passpointConfig = new PasspointConfiguration(); + HomeSp homeSp = new HomeSp(); + homeSp.setFqdn(fqdn); + homeSp.setFriendlyName(friendlyName); + homeSp.setRoamingConsortiumOis(rcOIs); + passpointConfig.setHomeSp(homeSp); + Credential credential = new Credential(); + Credential.CertificateCredential certCredential = new Credential.CertificateCredential(); + certCredential.setCertType(Credential.CertificateCredential.CERT_TYPE_X509V3); + credential.setCertCredential(certCredential); + credential.setRealm(realm); + passpointConfig.setCredential(credential); + + assertEquals(passpointConfig, PasspointProvider.convertFromWifiConfig(wifiConfig)); + } + } |