From 547450702efd233213f953ba2213bb38803c34c3 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Wed, 8 Jun 2011 17:33:13 -0700 Subject: Use the same host name in the SSL cert as in mockwebserver. MockWebServer had to revert to getLocalHost() since 'getLoopbackAddress() doesn't exist on Java 6 and MockWebServer wants to work on Java 6. Tested on host and device without problem. Change-Id: Ib083ec393d34b2378da579ffc7b6a71d599f9d22 --- support/src/test/java/libcore/java/security/TestKeyStore.java | 9 +++++++-- support/src/test/java/libcore/javax/net/ssl/TestSSLContext.java | 6 ++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/support/src/test/java/libcore/java/security/TestKeyStore.java b/support/src/test/java/libcore/java/security/TestKeyStore.java index 17b8be5..30e40fb 100644 --- a/support/src/test/java/libcore/java/security/TestKeyStore.java +++ b/support/src/test/java/libcore/java/security/TestKeyStore.java @@ -30,13 +30,14 @@ import java.io.ByteArrayInputStream; import java.io.PrintStream; import java.math.BigInteger; import java.net.InetAddress; +import java.net.UnknownHostException; import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; +import java.security.KeyStore; import java.security.KeyStore.PasswordProtection; import java.security.KeyStore.PrivateKeyEntry; import java.security.KeyStore.TrustedCertificateEntry; -import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.Principal; @@ -438,7 +439,11 @@ public final class TestKeyStore extends Assert { } private X500Principal localhost() { - return new X500Principal("CN=" + InetAddress.getLoopbackAddress().getHostName()); + try { + return new X500Principal("CN=" + InetAddress.getLocalHost().getHostName()); + } catch (UnknownHostException e) { + throw new RuntimeException(e); + } } } diff --git a/support/src/test/java/libcore/javax/net/ssl/TestSSLContext.java b/support/src/test/java/libcore/javax/net/ssl/TestSSLContext.java index e1af9e2..5c424bc 100644 --- a/support/src/test/java/libcore/javax/net/ssl/TestSSLContext.java +++ b/support/src/test/java/libcore/javax/net/ssl/TestSSLContext.java @@ -18,7 +18,6 @@ package libcore.javax.net.ssl; import java.io.IOException; import java.net.InetAddress; -import java.net.InetSocketAddress; import java.net.Socket; import java.net.UnknownHostException; import java.security.KeyStore; @@ -176,9 +175,8 @@ public final class TestSSLContext extends Assert { try { SSLServerSocket serverSocket = (SSLServerSocket) serverContext.getServerSocketFactory().createServerSocket(0); - InetSocketAddress sa = (InetSocketAddress) serverSocket.getLocalSocketAddress(); - InetAddress host = sa.getAddress(); - int port = sa.getPort(); + InetAddress host = InetAddress.getLocalHost(); + int port = serverSocket.getLocalPort(); return new TestSSLContext(clientKeyStore, clientStorePassword, serverKeyStore, serverStorePassword, -- cgit v1.1