diff options
author | Chad Brubaker <cbrubaker@google.com> | 2015-12-10 18:32:40 -0800 |
---|---|---|
committer | Chad Brubaker <cbrubaker@google.com> | 2015-12-10 18:32:40 -0800 |
commit | dd586a46c9ce5f9790ae097f491b088300603452 (patch) | |
tree | cefe97f62997a073963487d04650be77fcc0a0f3 /tests/NetworkSecurityConfigTest/src | |
parent | 9613157d5efd09be07a0074a0122dd69265ca70f (diff) |
Check for null hostnames in RootTrustManager
Even if the hostname aware method is called if the hostname is null then
the destination is unknown and the configuration can be ambiguous.
Change-Id: I7cacbd57a42604933fdc882371f143dc0a20902d
Diffstat (limited to 'tests/NetworkSecurityConfigTest/src')
-rw-r--r-- | tests/NetworkSecurityConfigTest/src/android/security/net/config/XmlConfigTests.java | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/NetworkSecurityConfigTest/src/android/security/net/config/XmlConfigTests.java b/tests/NetworkSecurityConfigTest/src/android/security/net/config/XmlConfigTests.java index 998bb681dd24..35e3ef4c38cc 100644 --- a/tests/NetworkSecurityConfigTest/src/android/security/net/config/XmlConfigTests.java +++ b/tests/NetworkSecurityConfigTest/src/android/security/net/config/XmlConfigTests.java @@ -22,6 +22,7 @@ import android.test.MoreAsserts; import android.util.ArraySet; import android.util.Pair; import java.io.IOException; +import java.net.InetAddress; import java.net.Socket; import java.net.URL; import java.security.KeyStore; @@ -34,6 +35,7 @@ import java.util.Set; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLHandshakeException; +import javax.net.ssl.SSLSocket; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; @@ -103,6 +105,15 @@ public class XmlConfigTests extends AndroidTestCase { TestUtils.assertConnectionFails(context, "developer.android.com", 443); TestUtils.assertUrlConnectionFails(context, "google.com", 443); TestUtils.assertUrlConnectionSucceeds(context, "android.com", 443); + // Check that sockets created without the hostname fail with per-domain configs + SSLSocket socket = (SSLSocket) context.getSocketFactory() + .createSocket(InetAddress.getByName("android.com"), 443); + try { + socket.startHandshake(); + socket.getInputStream(); + fail(); + } catch (IOException expected) { + } } public void testBasicPinning() throws Exception { |