diff options
author | Alex Klyubin <klyubin@google.com> | 2014-11-18 17:45:01 -0800 |
---|---|---|
committer | Alex Klyubin <klyubin@google.com> | 2014-11-18 19:54:52 -0800 |
commit | a03ec4ced2b11f9eae6cbeeedb1db2b1b29fafb1 (patch) | |
tree | 53b38e00ddd4e770868f3755e658ed80fc757177 | |
parent | cc168fec727bd90ca6582e21a59ec5d718cebf7a (diff) | |
download | okhttp-a03ec4ced2b11f9eae6cbeeedb1db2b1b29fafb1.tar.gz |
Fix a bug in OkHostnameVerifier wildcard handling.
Wildcard domain name patterns of the form *.remainder are supposed to
match domain names that exactly match the remainder. Due to a bug,
the match was not exact but rather a prefix match: domain names
starting with the remainder would match too.
This CL fixes the issue.
Bug: 18432707
Change-Id: I2639ff51cabcbd395d4f30a9c69f9895738e0acf
-rw-r--r-- | okhttp-tests/src/test/java/com/squareup/okhttp/internal/tls/HostnameVerifierTest.java | 1 | ||||
-rw-r--r-- | okhttp/src/main/java/com/squareup/okhttp/internal/tls/OkHostnameVerifier.java | 2 |
2 files changed, 2 insertions, 1 deletions
diff --git a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/tls/HostnameVerifierTest.java b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/tls/HostnameVerifierTest.java index f1decc8..82b1952 100644 --- a/okhttp-tests/src/test/java/com/squareup/okhttp/internal/tls/HostnameVerifierTest.java +++ b/okhttp-tests/src/test/java/com/squareup/okhttp/internal/tls/HostnameVerifierTest.java @@ -293,6 +293,7 @@ public final class HostnameVerifierTest { assertTrue(verifier.verify("www.foo.com", session)); assertTrue(verifier.verify("\u82b1\u5b50.foo.com", session)); assertFalse(verifier.verify("a.b.foo.com", session)); + assertFalse(verifier.verify("foo.com.au", session)); } @Test public void verifyWilcardCnOnTld() throws Exception { diff --git a/okhttp/src/main/java/com/squareup/okhttp/internal/tls/OkHostnameVerifier.java b/okhttp/src/main/java/com/squareup/okhttp/internal/tls/OkHostnameVerifier.java index a08773f..21e539c 100644 --- a/okhttp/src/main/java/com/squareup/okhttp/internal/tls/OkHostnameVerifier.java +++ b/okhttp/src/main/java/com/squareup/okhttp/internal/tls/OkHostnameVerifier.java @@ -162,7 +162,7 @@ public final class OkHostnameVerifier implements HostnameVerifier { return hostName.equals(cn); } - if (cn.startsWith("*.") && hostName.regionMatches(0, cn, 2, cn.length() - 2)) { + if (cn.startsWith("*.") && hostName.equals(cn.substring(2))) { return true; // "*.foo.com" matches "foo.com" } |