diff options
author | Chad Brubaker <cbrubaker@google.com> | 2015-11-09 13:38:51 -0800 |
---|---|---|
committer | Chad Brubaker <cbrubaker@google.com> | 2015-11-10 12:40:00 -0800 |
commit | 08d36202daeb3e668911c9902edb61b6894f822e (patch) | |
tree | 72dee75fd1be13ff12ecbde62647d9e376b72f16 /tests/NetworkSecurityConfigTest/src | |
parent | 749501e88e5fa6bdc6594a9db5c232e31bdda867 (diff) |
Add support for debug-overrides configuration
Debug overrides are only used if the application is debuggable in
order to help local debugging and development by trusting additional
CAs. In a non-debuggable version of the application the debug-overrides
are ignored.
Trust anchors in the debug override configuration have two key
differences from those in base-config and domain-config:
1) trust anchors in the debug-overrides are trusted for all connections
in addition to any trust anchors included in the relevant base/domain
configs.
2) By default trust anchors in the debug config override pins, as their
purpose is for connecting to non-standard servers for debugging and
testing and those servers should not be pinned in the production
configuration.
Change-Id: I15ee98eae182be0ffaa49b06bc5e1c6c3d22baee
Diffstat (limited to 'tests/NetworkSecurityConfigTest/src')
-rw-r--r-- | tests/NetworkSecurityConfigTest/src/android/security/net/config/XmlConfigTests.java | 65 |
1 files changed, 65 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 f52a27995854..43fa830f733e 100644 --- a/tests/NetworkSecurityConfigTest/src/android/security/net/config/XmlConfigTests.java +++ b/tests/NetworkSecurityConfigTest/src/android/security/net/config/XmlConfigTests.java @@ -26,6 +26,7 @@ import java.net.Socket; import java.net.URL; import java.util.ArrayList; import java.util.Collections; +import java.util.Set; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLHandshakeException; @@ -33,6 +34,8 @@ import javax.net.ssl.TrustManager; public class XmlConfigTests extends AndroidTestCase { + private final static String DEBUG_CA_SUBJ = "O=AOSP, CN=Test debug CA"; + public void testEmptyConfigFile() throws Exception { XmlConfigSource source = new XmlConfigSource(getContext(), R.xml.empty_config); ApplicationConfig appConfig = new ApplicationConfig(source); @@ -274,6 +277,68 @@ public class XmlConfigTests extends AndroidTestCase { assertFalse(child.isCleartextTrafficPermitted()); } + public void testDebugOverridesDisabled() throws Exception { + XmlConfigSource source = new XmlConfigSource(getContext(), R.xml.debug_basic, false); + ApplicationConfig appConfig = new ApplicationConfig(source); + NetworkSecurityConfig config = appConfig.getConfigForHostname(""); + Set<TrustAnchor> anchors = config.getTrustAnchors(); + MoreAsserts.assertEmpty(anchors); + SSLContext context = TestUtils.getSSLContext(source); + TestUtils.assertConnectionFails(context, "android.com", 443); + TestUtils.assertConnectionFails(context, "developer.android.com", 443); + } + + public void testBasicDebugOverrides() throws Exception { + XmlConfigSource source = new XmlConfigSource(getContext(), R.xml.debug_basic, true); + ApplicationConfig appConfig = new ApplicationConfig(source); + NetworkSecurityConfig config = appConfig.getConfigForHostname(""); + Set<TrustAnchor> anchors = config.getTrustAnchors(); + MoreAsserts.assertNotEmpty(anchors); + for (TrustAnchor anchor : anchors) { + assertTrue(anchor.overridesPins); + } + SSLContext context = TestUtils.getSSLContext(source); + TestUtils.assertConnectionSucceeds(context, "android.com", 443); + TestUtils.assertConnectionSucceeds(context, "developer.android.com", 443); + } + + public void testDebugOverridesWithDomain() throws Exception { + XmlConfigSource source = new XmlConfigSource(getContext(), R.xml.debug_domain, true); + ApplicationConfig appConfig = new ApplicationConfig(source); + NetworkSecurityConfig config = appConfig.getConfigForHostname("android.com"); + Set<TrustAnchor> anchors = config.getTrustAnchors(); + boolean foundDebugCA = false; + for (TrustAnchor anchor : anchors) { + if (anchor.certificate.getSubjectDN().toString().equals(DEBUG_CA_SUBJ)) { + foundDebugCA = true; + assertTrue(anchor.overridesPins); + } + } + assertTrue(foundDebugCA); + SSLContext context = TestUtils.getSSLContext(source); + TestUtils.assertConnectionSucceeds(context, "android.com", 443); + TestUtils.assertConnectionSucceeds(context, "developer.android.com", 443); + } + + public void testDebugInherit() throws Exception { + XmlConfigSource source = new XmlConfigSource(getContext(), R.xml.debug_domain, true); + ApplicationConfig appConfig = new ApplicationConfig(source); + NetworkSecurityConfig config = appConfig.getConfigForHostname("android.com"); + Set<TrustAnchor> anchors = config.getTrustAnchors(); + boolean foundDebugCA = false; + for (TrustAnchor anchor : anchors) { + if (anchor.certificate.getSubjectDN().toString().equals(DEBUG_CA_SUBJ)) { + foundDebugCA = true; + assertTrue(anchor.overridesPins); + } + } + assertTrue(foundDebugCA); + assertTrue(anchors.size() > 1); + SSLContext context = TestUtils.getSSLContext(source); + TestUtils.assertConnectionSucceeds(context, "android.com", 443); + TestUtils.assertConnectionSucceeds(context, "developer.android.com", 443); + } + private void testBadConfig(int configId) throws Exception { try { XmlConfigSource source = new XmlConfigSource(getContext(), configId); |