Properly handle whitespace in domain entries
Domain entries can contain whitespace (or newlines) which should be ignored to avoid unexpectedly failing to match a domain. Bug: 27816377 Change-Id: I3691aa4abd409e7be97ad0cf1eb0195725e1b0ab
This commit is contained in:
@@ -111,7 +111,7 @@ public class XmlConfigSource implements ConfigSource {
|
||||
if (parser.next() != XmlPullParser.TEXT) {
|
||||
throw new ParserException(parser, "Missing pin digest");
|
||||
}
|
||||
String digest = parser.getText();
|
||||
String digest = parser.getText().trim();
|
||||
byte[] decodedDigest = null;
|
||||
try {
|
||||
decodedDigest = Base64.decode(digest, 0);
|
||||
@@ -168,7 +168,7 @@ public class XmlConfigSource implements ConfigSource {
|
||||
if (parser.next() != XmlPullParser.TEXT) {
|
||||
throw new ParserException(parser, "Domain name missing");
|
||||
}
|
||||
String domain = parser.getText().toLowerCase(Locale.US);
|
||||
String domain = parser.getText().trim().toLowerCase(Locale.US);
|
||||
if (parser.next() != XmlPullParser.END_TAG) {
|
||||
throw new ParserException(parser, "domain contains additional elements");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<network-security-config>
|
||||
<domain-config>
|
||||
<domain>android.com
|
||||
</domain>
|
||||
<domain> developer.android.com </domain>
|
||||
<pin-set>
|
||||
<pin digest="SHA-256"> 7HIpactkIAq2Y49orFOOQKurWxmmSFZhBCoQYcRhJ3Y= </pin>
|
||||
</pin-set>
|
||||
</domain-config>
|
||||
</network-security-config>
|
||||
@@ -464,4 +464,16 @@ public class XmlConfigTests extends AndroidTestCase {
|
||||
} catch (RuntimeException expected) {
|
||||
}
|
||||
}
|
||||
|
||||
public void testDomainWhitespaceTrimming() throws Exception {
|
||||
XmlConfigSource source =
|
||||
new XmlConfigSource(getContext(), R.xml.domain_whitespace, false);
|
||||
ApplicationConfig appConfig = new ApplicationConfig(source);
|
||||
NetworkSecurityConfig defaultConfig = appConfig.getConfigForHostname("");
|
||||
MoreAsserts.assertNotEqual(defaultConfig, appConfig.getConfigForHostname("developer.android.com"));
|
||||
MoreAsserts.assertNotEqual(defaultConfig, appConfig.getConfigForHostname("android.com"));
|
||||
SSLContext context = TestUtils.getSSLContext(source);
|
||||
TestUtils.assertConnectionSucceeds(context, "android.com", 443);
|
||||
TestUtils.assertConnectionSucceeds(context, "developer.android.com", 443);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user