libcore/support: change TestKeyStore to avoid using getLocalHost()

Use constants instead. InetAddress.getLocalHost() causes
trouble when there is incompatibility between netd and bionic
(see c/147244). This is part of an effort to start running
conscrypt/java.security tests in the buildbot.

Change-Id: I97ccf0a09f11c68e1b1ae2c2da99c2269ad0fe90
diff --git a/support/src/test/java/libcore/java/security/TestKeyStore.java b/support/src/test/java/libcore/java/security/TestKeyStore.java
index bd64360..425cefa 100644
--- a/support/src/test/java/libcore/java/security/TestKeyStore.java
+++ b/support/src/test/java/libcore/java/security/TestKeyStore.java
@@ -31,8 +31,6 @@
 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;
@@ -98,6 +96,9 @@
     }
 
     private static final boolean TEST_MANAGERS = true;
+    private static final byte[] LOCAL_HOST_ADDRESS = { 127, 0, 0, 1 };
+    private static final String LOCAL_HOST_NAME = "localhost";
+
 
     public final KeyStore keyStore;
     public final char[] storePassword;
@@ -156,16 +157,12 @@
                 .signer(ROOT_CA.getPrivateKey("RSA", "RSA"))
                 .rootCa(ROOT_CA.getRootCertificate("RSA"))
                 .build();
-        try {
-            SERVER = new Builder()
-                    .aliasPrefix("server")
-                    .signer(INTERMEDIATE_CA.getPrivateKey("RSA", "RSA"))
-                    .rootCa(INTERMEDIATE_CA.getRootCertificate("RSA"))
-                    .addSubjectAltNameIpAddress(InetAddress.getLocalHost().getAddress())
-                    .build();
-        } catch (UnknownHostException e) {
-            throw new RuntimeException(e);
-        }
+        SERVER = new Builder()
+                .aliasPrefix("server")
+                .signer(INTERMEDIATE_CA.getPrivateKey("RSA", "RSA"))
+                .rootCa(INTERMEDIATE_CA.getRootCertificate("RSA"))
+                .addSubjectAltNameIpAddress(LOCAL_HOST_ADDRESS)
+                .build();
         CLIENT = new TestKeyStore(createClient(INTERMEDIATE_CA.keyStore), null, null);
         CLIENT_CERTIFICATE = new Builder()
                 .aliasPrefix("client")
@@ -529,11 +526,7 @@
         }
 
         private X500Principal localhost() {
-            try {
-                return new X500Principal("CN=" + InetAddress.getLocalHost().getHostName());
-            } catch (UnknownHostException e) {
-                throw new RuntimeException(e);
-            }
+            return new X500Principal("CN=" + LOCAL_HOST_NAME);
         }
     }