Loading core/java/android/security/net/config/XmlConfigSource.java +43 −1 Original line number Original line Diff line number Diff line Loading @@ -339,7 +339,7 @@ public class XmlConfigSource implements ConfigSource { } } if (mDebugBuild) { if (mDebugBuild) { debugConfigBuilder = debugConfigBuilder = parseConfigEntry(parser, seenDomains, null, CONFIG_DEBUG).get(0).first; parseConfigEntry(parser, null, null, CONFIG_DEBUG).get(0).first; } else { } else { XmlUtils.skipCurrentTag(parser); XmlUtils.skipCurrentTag(parser); } } Loading @@ -348,6 +348,11 @@ public class XmlConfigSource implements ConfigSource { XmlUtils.skipCurrentTag(parser); XmlUtils.skipCurrentTag(parser); } } } } // If debug is true and there was no debug-overrides in the file check for an extra // _debug resource. if (mDebugBuild && debugConfigBuilder == null) { debugConfigBuilder = parseDebugOverridesResource(); } // Use the platform default as the parent of the base config for any values not provided // Use the platform default as the parent of the base config for any values not provided // there. If there is no base config use the platform default. // there. If there is no base config use the platform default. Loading Loading @@ -385,6 +390,43 @@ public class XmlConfigSource implements ConfigSource { mDomainMap = configs; mDomainMap = configs; } } private NetworkSecurityConfig.Builder parseDebugOverridesResource() throws IOException, XmlPullParserException, ParserException { Resources resources = mContext.getResources(); String packageName = resources.getResourcePackageName(mResourceId); String entryName = resources.getResourceEntryName(mResourceId); int resId = resources.getIdentifier(entryName + "_debug", "xml", packageName); // No debug-overrides resource was found, nothing to parse. if (resId == 0) { return null; } NetworkSecurityConfig.Builder debugConfigBuilder = null; // Parse debug-overrides out of the _debug resource. try (XmlResourceParser parser = resources.getXml(resId)) { XmlUtils.beginDocument(parser, "network-security-config"); int outerDepth = parser.getDepth(); boolean seenDebugOverrides = false; while (XmlUtils.nextElementWithin(parser, outerDepth)) { if ("debug-overrides".equals(parser.getName())) { if (seenDebugOverrides) { throw new ParserException(parser, "Only one debug-overrides allowed"); } if (mDebugBuild) { debugConfigBuilder = parseConfigEntry(parser, null, null, CONFIG_DEBUG).get(0).first; } else { XmlUtils.skipCurrentTag(parser); } seenDebugOverrides = true; } else { XmlUtils.skipCurrentTag(parser); } } } return debugConfigBuilder; } public static class ParserException extends Exception { public static class ParserException extends Exception { public ParserException(XmlPullParser parser, String message, Throwable cause) { public ParserException(XmlPullParser parser, String message, Throwable cause) { Loading tests/NetworkSecurityConfigTest/res/xml/bad_extra_debug_resource.xml 0 → 100644 +7 −0 Original line number Original line Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <network-security-config> <base-config> <trust-anchors> </trust-anchors> </base-config> </network-security-config> tests/NetworkSecurityConfigTest/res/xml/bad_extra_debug_resource_debug.xml 0 → 100644 +7 −0 Original line number Original line Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- debug-overrides not inside network-security-config should cause a parsing error --> <debug-overrides> <trust-anchors> <certificates src="system" /> </trust-anchors> </debug-overrides> tests/NetworkSecurityConfigTest/res/xml/extra_debug_resource.xml 0 → 100644 +7 −0 Original line number Original line Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <network-security-config> <base-config> <trust-anchors> </trust-anchors> </base-config> </network-security-config> tests/NetworkSecurityConfigTest/res/xml/extra_debug_resource_debug.xml 0 → 100644 +8 −0 Original line number Original line Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <network-security-config> <debug-overrides> <trust-anchors> <certificates src="system" /> </trust-anchors> </debug-overrides> </network-security-config> Loading
core/java/android/security/net/config/XmlConfigSource.java +43 −1 Original line number Original line Diff line number Diff line Loading @@ -339,7 +339,7 @@ public class XmlConfigSource implements ConfigSource { } } if (mDebugBuild) { if (mDebugBuild) { debugConfigBuilder = debugConfigBuilder = parseConfigEntry(parser, seenDomains, null, CONFIG_DEBUG).get(0).first; parseConfigEntry(parser, null, null, CONFIG_DEBUG).get(0).first; } else { } else { XmlUtils.skipCurrentTag(parser); XmlUtils.skipCurrentTag(parser); } } Loading @@ -348,6 +348,11 @@ public class XmlConfigSource implements ConfigSource { XmlUtils.skipCurrentTag(parser); XmlUtils.skipCurrentTag(parser); } } } } // If debug is true and there was no debug-overrides in the file check for an extra // _debug resource. if (mDebugBuild && debugConfigBuilder == null) { debugConfigBuilder = parseDebugOverridesResource(); } // Use the platform default as the parent of the base config for any values not provided // Use the platform default as the parent of the base config for any values not provided // there. If there is no base config use the platform default. // there. If there is no base config use the platform default. Loading Loading @@ -385,6 +390,43 @@ public class XmlConfigSource implements ConfigSource { mDomainMap = configs; mDomainMap = configs; } } private NetworkSecurityConfig.Builder parseDebugOverridesResource() throws IOException, XmlPullParserException, ParserException { Resources resources = mContext.getResources(); String packageName = resources.getResourcePackageName(mResourceId); String entryName = resources.getResourceEntryName(mResourceId); int resId = resources.getIdentifier(entryName + "_debug", "xml", packageName); // No debug-overrides resource was found, nothing to parse. if (resId == 0) { return null; } NetworkSecurityConfig.Builder debugConfigBuilder = null; // Parse debug-overrides out of the _debug resource. try (XmlResourceParser parser = resources.getXml(resId)) { XmlUtils.beginDocument(parser, "network-security-config"); int outerDepth = parser.getDepth(); boolean seenDebugOverrides = false; while (XmlUtils.nextElementWithin(parser, outerDepth)) { if ("debug-overrides".equals(parser.getName())) { if (seenDebugOverrides) { throw new ParserException(parser, "Only one debug-overrides allowed"); } if (mDebugBuild) { debugConfigBuilder = parseConfigEntry(parser, null, null, CONFIG_DEBUG).get(0).first; } else { XmlUtils.skipCurrentTag(parser); } seenDebugOverrides = true; } else { XmlUtils.skipCurrentTag(parser); } } } return debugConfigBuilder; } public static class ParserException extends Exception { public static class ParserException extends Exception { public ParserException(XmlPullParser parser, String message, Throwable cause) { public ParserException(XmlPullParser parser, String message, Throwable cause) { Loading
tests/NetworkSecurityConfigTest/res/xml/bad_extra_debug_resource.xml 0 → 100644 +7 −0 Original line number Original line Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <network-security-config> <base-config> <trust-anchors> </trust-anchors> </base-config> </network-security-config>
tests/NetworkSecurityConfigTest/res/xml/bad_extra_debug_resource_debug.xml 0 → 100644 +7 −0 Original line number Original line Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- debug-overrides not inside network-security-config should cause a parsing error --> <debug-overrides> <trust-anchors> <certificates src="system" /> </trust-anchors> </debug-overrides>
tests/NetworkSecurityConfigTest/res/xml/extra_debug_resource.xml 0 → 100644 +7 −0 Original line number Original line Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <network-security-config> <base-config> <trust-anchors> </trust-anchors> </base-config> </network-security-config>
tests/NetworkSecurityConfigTest/res/xml/extra_debug_resource_debug.xml 0 → 100644 +8 −0 Original line number Original line Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <network-security-config> <debug-overrides> <trust-anchors> <certificates src="system" /> </trust-anchors> </debug-overrides> </network-security-config>