summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenny Root <kroot@android.com>2014-09-30 09:01:18 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-09-30 09:01:19 +0000
commit3a025d3db9334bab5e1e80da7c69a5f69cdd2f84 (patch)
treea05b05264148749f5f1cafef11178757408cdd34
parent76d38635d9eb6b03251913a993f038da1a3759bc (diff)
parent9be69a95272f93d7daa19053c61fae7c3d8ff30d (diff)
downloadlibcore-3a025d3db9334bab5e1e80da7c69a5f69cdd2f84.zip
libcore-3a025d3db9334bab5e1e80da7c69a5f69cdd2f84.tar.gz
libcore-3a025d3db9334bab5e1e80da7c69a5f69cdd2f84.tar.bz2
Merge "Enable hostname verification for absolute hostnames."
-rw-r--r--luni/src/main/java/javax/net/ssl/DefaultHostnameVerifier.java8
-rw-r--r--luni/src/test/java/libcore/javax/net/ssl/DefaultHostnameVerifierTest.java27
2 files changed, 35 insertions, 0 deletions
diff --git a/luni/src/main/java/javax/net/ssl/DefaultHostnameVerifier.java b/luni/src/main/java/javax/net/ssl/DefaultHostnameVerifier.java
index 453dee6..013bf17 100644
--- a/luni/src/main/java/javax/net/ssl/DefaultHostnameVerifier.java
+++ b/luni/src/main/java/javax/net/ssl/DefaultHostnameVerifier.java
@@ -131,6 +131,14 @@ public final class DefaultHostnameVerifier implements HostnameVerifier {
return false;
}
+ if (hostName.endsWith(".") && !cn.endsWith(".")) {
+ // "www.android.com." matches "www.android.com"
+ // This is needed because server certificates do not normally contain absolute names
+ // or patterns. Connections via absolute hostnames should be supported and even
+ // preferred over those via relative hostnames, to avoid DNS suffixes being appended.
+ cn += '.';
+ }
+
cn = cn.toLowerCase(Locale.US);
if (!cn.contains("*")) {
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 100340a..71ccea4 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/DefaultHostnameVerifierTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/DefaultHostnameVerifierTest.java
@@ -153,6 +153,33 @@ public final class DefaultHostnameVerifierTest extends TestCase {
assertFalse(verifier.verifyHostName("imap.google.com", "a*.google.com"));
assertFalse(verifier.verifyHostName("imap.google.com", "ix*.google.com"));
assertTrue(verifier.verifyHostName("imap.google.com", "iMap.Google.Com"));
+ assertTrue(verifier.verifyHostName("weird", "weird"));
+ assertFalse(verifier.verifyHostName("weird", "weird*"));
+ assertFalse(verifier.verifyHostName("weird", "*weird"));
+ assertFalse(verifier.verifyHostName("weird", "weird."));
+ assertFalse(verifier.verifyHostName("weird", "weird*."));
+ assertFalse(verifier.verifyHostName("weird", "weird.*"));
+ }
+
+ public void testVerifyAbsoluteHostName() {
+ assertTrue(verifier.verifyHostName("a.b.c.d.", "a.b.c.d"));
+ assertTrue(verifier.verifyHostName("a.b.c.d.", "*.b.c.d"));
+ assertFalse(verifier.verifyHostName("a.b.c.d.", "*.*.c.d"));
+ assertTrue(verifier.verifyHostName("imap.google.com.", "imap.google.com"));
+ assertFalse(verifier.verifyHostName("imap2.google.com.", "imap.google.com"));
+ assertTrue(verifier.verifyHostName("imap.google.com.", "*.google.com"));
+ assertTrue(verifier.verifyHostName("imap2.google.com.", "*.google.com"));
+ assertFalse(verifier.verifyHostName("imap.google.com.", "*.googl.com"));
+ assertFalse(verifier.verifyHostName("imap2.google2.com.", "*.google3.com"));
+ assertFalse(verifier.verifyHostName("imap.google.com.", "a*.google.com"));
+ assertFalse(verifier.verifyHostName("imap.google.com.", "ix*.google.com"));
+ assertTrue(verifier.verifyHostName("imap.google.com.", "iMap.Google.Com"));
+ assertTrue(verifier.verifyHostName("weird.", "weird"));
+ assertTrue(verifier.verifyHostName("weird.", "weird*"));
+ assertTrue(verifier.verifyHostName("weird.", "*weird"));
+ assertTrue(verifier.verifyHostName("weird.", "weird."));
+ assertTrue(verifier.verifyHostName("weird.", "weird*."));
+ assertFalse(verifier.verifyHostName("weird.", "weird.*"));
}
public void testSubjectOnlyCert() throws Exception {