Search in sources :

Example 56 with ArraySet

use of android.util.ArraySet in project android_frameworks_base by DirtyUnicorns.

the class NetworkSecurityConfigTests method testEmptyPerNetworkSecurityConfig.

public void testEmptyPerNetworkSecurityConfig() throws Exception {
    ArraySet<Pair<Domain, NetworkSecurityConfig>> domainMap = new ArraySet<Pair<Domain, NetworkSecurityConfig>>();
    domainMap.add(new Pair<Domain, NetworkSecurityConfig>(new Domain("android.com", true), getEmptyConfig()));
    NetworkSecurityConfig defaultConfig = getSystemStoreConfig();
    SSLContext context = TestUtils.getSSLContext(new TestConfigSource(domainMap, defaultConfig));
    TestUtils.assertConnectionFails(context, "android.com", 443);
    TestUtils.assertConnectionSucceeds(context, "google.com", 443);
}
Also used : ArraySet(android.util.ArraySet) SSLContext(javax.net.ssl.SSLContext) Pair(android.util.Pair)

Example 57 with ArraySet

use of android.util.ArraySet in project android_frameworks_base by DirtyUnicorns.

the class NetworkSecurityConfigTests method testMostSpecificNetworkSecurityConfig.

public void testMostSpecificNetworkSecurityConfig() throws Exception {
    ArraySet<Pair<Domain, NetworkSecurityConfig>> domainMap = new ArraySet<Pair<Domain, NetworkSecurityConfig>>();
    domainMap.add(new Pair<Domain, NetworkSecurityConfig>(new Domain("android.com", true), getEmptyConfig()));
    domainMap.add(new Pair<Domain, NetworkSecurityConfig>(new Domain("developer.android.com", false), getSystemStoreConfig()));
    SSLContext context = TestUtils.getSSLContext(new TestConfigSource(domainMap, getEmptyConfig()));
    TestUtils.assertConnectionFails(context, "android.com", 443);
    TestUtils.assertConnectionSucceeds(context, "developer.android.com", 443);
}
Also used : ArraySet(android.util.ArraySet) SSLContext(javax.net.ssl.SSLContext) Pair(android.util.Pair)

Example 58 with ArraySet

use of android.util.ArraySet in project android_frameworks_base by DirtyUnicorns.

the class NetworkSecurityConfigTests method testOverridePins.

public void testOverridePins() throws Exception {
    // Use a bad pin + granting the system CA store the ability to override pins.
    ArraySet<Pin> pins = new ArraySet<Pin>();
    pins.add(new Pin("SHA-256", new byte[0]));
    NetworkSecurityConfig domain = new NetworkSecurityConfig.Builder().setPinSet(new PinSet(pins, Long.MAX_VALUE)).addCertificatesEntryRef(new CertificatesEntryRef(SystemCertificateSource.getInstance(), true)).build();
    ArraySet<Pair<Domain, NetworkSecurityConfig>> domainMap = new ArraySet<Pair<Domain, NetworkSecurityConfig>>();
    domainMap.add(new Pair<Domain, NetworkSecurityConfig>(new Domain("android.com", true), domain));
    SSLContext context = TestUtils.getSSLContext(new TestConfigSource(domainMap, getEmptyConfig()));
    TestUtils.assertConnectionSucceeds(context, "android.com", 443);
}
Also used : ArraySet(android.util.ArraySet) SSLContext(javax.net.ssl.SSLContext) Pair(android.util.Pair)

Example 59 with ArraySet

use of android.util.ArraySet in project android_frameworks_base by DirtyUnicorns.

the class NetworkSecurityConfigTests method testSubdomainIncluded.

public void testSubdomainIncluded() throws Exception {
    // First try connecting to a subdomain of a domain entry that includes subdomains.
    ArraySet<Pair<Domain, NetworkSecurityConfig>> domainMap = new ArraySet<Pair<Domain, NetworkSecurityConfig>>();
    domainMap.add(new Pair<Domain, NetworkSecurityConfig>(new Domain("android.com", true), getSystemStoreConfig()));
    SSLContext context = TestUtils.getSSLContext(new TestConfigSource(domainMap, getEmptyConfig()));
    TestUtils.assertConnectionSucceeds(context, "developer.android.com", 443);
    // Now try without including subdomains.
    domainMap = new ArraySet<Pair<Domain, NetworkSecurityConfig>>();
    domainMap.add(new Pair<Domain, NetworkSecurityConfig>(new Domain("android.com", false), getSystemStoreConfig()));
    context = TestUtils.getSSLContext(new TestConfigSource(domainMap, getEmptyConfig()));
    TestUtils.assertConnectionFails(context, "developer.android.com", 443);
}
Also used : ArraySet(android.util.ArraySet) SSLContext(javax.net.ssl.SSLContext) Pair(android.util.Pair)

Example 60 with ArraySet

use of android.util.ArraySet in project android_frameworks_base by DirtyUnicorns.

the class NetworkSecurityConfigTests method testBadPin.

public void testBadPin() throws Exception {
    ArraySet<Pin> pins = new ArraySet<Pin>();
    pins.add(new Pin("SHA-256", new byte[0]));
    NetworkSecurityConfig domain = new NetworkSecurityConfig.Builder().setPinSet(new PinSet(pins, Long.MAX_VALUE)).addCertificatesEntryRef(new CertificatesEntryRef(SystemCertificateSource.getInstance(), false)).build();
    ArraySet<Pair<Domain, NetworkSecurityConfig>> domainMap = new ArraySet<Pair<Domain, NetworkSecurityConfig>>();
    domainMap.add(new Pair<Domain, NetworkSecurityConfig>(new Domain("android.com", true), domain));
    SSLContext context = TestUtils.getSSLContext(new TestConfigSource(domainMap, getSystemStoreConfig()));
    TestUtils.assertConnectionFails(context, "android.com", 443);
    TestUtils.assertConnectionSucceeds(context, "google.com", 443);
}
Also used : ArraySet(android.util.ArraySet) SSLContext(javax.net.ssl.SSLContext) Pair(android.util.Pair)

Aggregations

ArraySet (android.util.ArraySet)521 PublicKey (java.security.PublicKey)94 ArrayList (java.util.ArrayList)87 ComponentName (android.content.ComponentName)82 ArrayMap (android.util.ArrayMap)73 Pair (android.util.Pair)47 RemoteException (android.os.RemoteException)43 ResolveInfo (android.content.pm.ResolveInfo)39 Intent (android.content.Intent)38 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)35 File (java.io.File)33 SSLContext (javax.net.ssl.SSLContext)32 IOException (java.io.IOException)31 PackageManager (android.content.pm.PackageManager)29 UserInfo (android.content.pm.UserInfo)28 ApplicationInfo (android.content.pm.ApplicationInfo)24 Point (android.graphics.Point)24 X509Certificate (java.security.cert.X509Certificate)20 PackageInfo (android.content.pm.PackageInfo)19 Test (org.junit.Test)19