am af634dae: am 18c077b3: am 08855205: am 77a7e48a: Fix a bug in DefaultHostnameVerifier wildcard handling.
* commit 'af634dae00b4241c17c8cf19389ccecb9da5c97b':
Fix a bug in DefaultHostnameVerifier wildcard handling.
diff --git a/luni/src/main/java/javax/net/ssl/DefaultHostnameVerifier.java b/luni/src/main/java/javax/net/ssl/DefaultHostnameVerifier.java
index fa11371..fd84c3e 100644
--- a/luni/src/main/java/javax/net/ssl/DefaultHostnameVerifier.java
+++ b/luni/src/main/java/javax/net/ssl/DefaultHostnameVerifier.java
@@ -137,7 +137,7 @@
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"
}
diff --git a/luni/src/test/java/libcore/javax/net/ssl/DefaultHostnameVerifierTest.java b/luni/src/test/java/libcore/javax/net/ssl/DefaultHostnameVerifierTest.java
index e1c9fe3..feecebe 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/DefaultHostnameVerifierTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/DefaultHostnameVerifierTest.java
@@ -114,15 +114,18 @@
public void testWildcardMatchesWildcardSuffix() {
assertTrue(verifier.verifyHostName("b.c.d", "*.b.c.d"));
assertTrue(verifier.verifyHostName("imap.google.com", "*.imap.google.com"));
+ assertFalse(verifier.verifyHostName("imap.google.com.au", "*.imap.google.com"));
}
public void testWildcardMatchingSubstring() {
assertTrue(verifier.verifyHostName("b.c.d", "b*.c.d"));
assertTrue(verifier.verifyHostName("imap.google.com", "ima*.google.com"));
+ assertFalse(verifier.verifyHostName("imap.google.com.au", "ima*.google.com"));
}
public void testWildcardMatchingEmptySubstring() {
assertTrue(verifier.verifyHostName("imap.google.com", "imap*.google.com"));
+ assertFalse(verifier.verifyHostName("imap.google.com.au", "imap*.google.com"));
}
public void testWildcardMatchesChildDomain() {