diff --git a/src/main/java/libcore/io/Base64.java b/src/main/java/libcore/io/Base64.java index 867c76b9a886..96d3b9d9727e 100644 --- a/src/main/java/libcore/io/Base64.java +++ b/src/main/java/libcore/io/Base64.java @@ -21,7 +21,7 @@ package libcore.io; -import libcore.util.Charsets; +import java.io.UnsupportedEncodingException; import libcore.util.EmptyArray; /** @@ -156,6 +156,10 @@ public static String encode(byte[] in) { out[index++] = '='; break; } - return new String(out, 0, index, Charsets.US_ASCII); + try { + return new String(out, 0, index, "US-ASCII"); + } catch (UnsupportedEncodingException e) { + throw new AssertionError(e); + } } } diff --git a/src/main/java/libcore/net/MimeUtils.java b/src/main/java/libcore/net/MimeUtils.java index 65cfd0dd579d..76193ff2dc07 100644 --- a/src/main/java/libcore/net/MimeUtils.java +++ b/src/main/java/libcore/net/MimeUtils.java @@ -434,7 +434,7 @@ private MimeUtils() { * @return True iff there is a mimeType entry in the map. */ public static boolean hasMimeType(String mimeType) { - if (mimeType == null || mimeType.isEmpty()) { + if (mimeType == null || mimeType.length() == 0) { return false; } return MIME_TYPE_TO_EXTENSION_MAP.containsKey(mimeType); @@ -446,7 +446,7 @@ public static boolean hasMimeType(String mimeType) { * @return The MIME type for the given extension or null iff there is none. */ public static String guessMimeTypeFromExtension(String extension) { - if (extension == null || extension.isEmpty()) { + if (extension == null || extension.length() == 0) { return null; } return EXTENSION_TO_MIME_TYPE_MAP.get(extension); @@ -458,7 +458,7 @@ public static String guessMimeTypeFromExtension(String extension) { * @return True iff there is an extension entry in the map. */ public static boolean hasExtension(String extension) { - if (extension == null || extension.isEmpty()) { + if (extension == null || extension.length() == 0) { return false; } return EXTENSION_TO_MIME_TYPE_MAP.containsKey(extension); @@ -472,7 +472,7 @@ public static boolean hasExtension(String extension) { * @return The extension for the given MIME type or null iff there is none. */ public static String guessExtensionFromMimeType(String mimeType) { - if (mimeType == null || mimeType.isEmpty()) { + if (mimeType == null || mimeType.length() == 0) { return null; } return MIME_TYPE_TO_EXTENSION_MAP.get(mimeType); diff --git a/src/main/java/libcore/net/http/HttpConnection.java b/src/main/java/libcore/net/http/HttpConnection.java index c3fb2a9d52df..6d5b7d8e8edf 100644 --- a/src/main/java/libcore/net/http/HttpConnection.java +++ b/src/main/java/libcore/net/http/HttpConnection.java @@ -37,7 +37,6 @@ import javax.net.ssl.SSLSocketFactory; import libcore.io.IoUtils; import libcore.net.spdy.SpdyConnection; -import libcore.util.Charsets; import libcore.util.Libcore; import libcore.util.Objects; @@ -229,7 +228,7 @@ public SSLSocket setupSecureSocket(SSLSocketFactory sslSocketFactory, HttpConnectionPool.INSTANCE.share(this); } else if (!Arrays.equals(selectedProtocol, HTTP_11)) { throw new IOException("Unexpected NPN transport " - + new String(selectedProtocol, Charsets.ISO_8859_1)); + + new String(selectedProtocol, "ISO-8859-1")); } } diff --git a/src/main/java/libcore/net/http/HttpResponseCache.java b/src/main/java/libcore/net/http/HttpResponseCache.java index c7982679a569..13d540e85a51 100644 --- a/src/main/java/libcore/net/http/HttpResponseCache.java +++ b/src/main/java/libcore/net/http/HttpResponseCache.java @@ -28,6 +28,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; import java.io.Writer; import java.net.CacheRequest; import java.net.CacheResponse; @@ -84,10 +85,12 @@ public HttpResponseCache(File directory, long maxSize) throws IOException { private String uriToKey(URI uri) { try { MessageDigest messageDigest = MessageDigest.getInstance("MD5"); - byte[] md5bytes = messageDigest.digest(uri.toString().getBytes(Charsets.UTF_8)); + byte[] md5bytes = messageDigest.digest(uri.toString().getBytes("UTF-8")); return IntegralToString.bytesToHexString(md5bytes, false); } catch (NoSuchAlgorithmException e) { throw new AssertionError(e); + } catch (UnsupportedEncodingException e) { + throw new AssertionError(e); } } @@ -381,7 +384,7 @@ public Entry(InputStream in) throws IOException { if (isHttps()) { String blank = Streams.readAsciiLine(in); - if (!blank.isEmpty()) { + if (blank.length() != 0) { throw new IOException("expected \"\" but was \"" + blank + "\""); } cipherSuite = Streams.readAsciiLine(in); @@ -472,7 +475,7 @@ private Certificate[] readCertArray(InputStream in) throws IOException { Certificate[] result = new Certificate[length]; for (int i = 0; i < result.length; i++) { String line = Streams.readAsciiLine(in); - byte[] bytes = Base64.decode(line.getBytes(Charsets.US_ASCII)); + byte[] bytes = Base64.decode(line.getBytes("US-ASCII")); result[i] = certificateFactory.generateCertificate( new ByteArrayInputStream(bytes)); } diff --git a/src/main/java/libcore/net/http/HttpTransport.java b/src/main/java/libcore/net/http/HttpTransport.java index 869e8035ecd3..d3073497898e 100644 --- a/src/main/java/libcore/net/http/HttpTransport.java +++ b/src/main/java/libcore/net/http/HttpTransport.java @@ -25,7 +25,6 @@ import java.net.CookieHandler; import java.net.URL; import libcore.io.Streams; -import libcore.util.Charsets; import libcore.util.Libcore; final class HttpTransport implements Transport { @@ -126,7 +125,7 @@ public void writeRequestHeaders() throws IOException { int contentLength = httpEngine.requestHeaders.getContentLength(); RawHeaders headersToSend = getNetworkRequestHeaders(); - byte[] bytes = headersToSend.toHeaderString().getBytes(Charsets.ISO_8859_1); + byte[] bytes = headersToSend.toHeaderString().getBytes("ISO-8859-1"); if (contentLength != -1 && bytes.length + contentLength <= MAX_REQUEST_BUFFER_LENGTH) { requestOut = new BufferedOutputStream(socketOut, bytes.length + contentLength); @@ -196,7 +195,7 @@ private RawHeaders getTunnelNetworkRequestHeaders() { private void readHeaders(RawHeaders headers) throws IOException { // parse the result headers until the first blank line String line; - while (!(line = Streams.readAsciiLine(socketIn)).isEmpty()) { + while ((line = Streams.readAsciiLine(socketIn)).length() != 0) { headers.addLine(line); } diff --git a/src/main/java/libcore/net/http/HttpURLConnectionImpl.java b/src/main/java/libcore/net/http/HttpURLConnectionImpl.java index dcf58c220f9f..99a6ac4f1510 100644 --- a/src/main/java/libcore/net/http/HttpURLConnectionImpl.java +++ b/src/main/java/libcore/net/http/HttpURLConnectionImpl.java @@ -31,7 +31,6 @@ import java.net.Proxy; import java.net.SocketPermission; import java.net.URL; -import libcore.util.Charsets; import java.security.Permission; import java.util.List; import java.util.Map; @@ -444,7 +443,7 @@ private String getAuthorizationCredentials(RawHeaders responseHeaders, String ch // base64 encode the username and password String usernameAndPassword = auth.getUserName() + ":" + new String(auth.getPassword()); - byte[] bytes = usernameAndPassword.getBytes(Charsets.ISO_8859_1); + byte[] bytes = usernameAndPassword.getBytes("ISO-8859-1"); String encoded = Base64.encode(bytes); return challenge.scheme + " " + encoded; } diff --git a/src/main/java/libcore/net/http/RawHeaders.java b/src/main/java/libcore/net/http/RawHeaders.java index cd1b44fc9870..642c61d1f87b 100644 --- a/src/main/java/libcore/net/http/RawHeaders.java +++ b/src/main/java/libcore/net/http/RawHeaders.java @@ -344,7 +344,7 @@ public List toNameValueBlock() { String value = namesAndValues.get(i + 1); // TODO: promote this check to where names and values are created - if (name.isEmpty() || value.isEmpty() + if (name.length() == 0 || value.length() == 0 || name.indexOf('\0') != -1 || value.indexOf('\0') != -1) { throw new IllegalArgumentException("Unexpected header: " + name + ": " + value); } diff --git a/src/main/java/libcore/net/http/ResponseHeaders.java b/src/main/java/libcore/net/http/ResponseHeaders.java index 0776bb9d2ca9..236ce8764238 100644 --- a/src/main/java/libcore/net/http/ResponseHeaders.java +++ b/src/main/java/libcore/net/http/ResponseHeaders.java @@ -17,7 +17,6 @@ package libcore.net.http; import java.net.HttpURLConnection; -import libcore.util.ResponseSource; import java.net.URI; import java.util.Collections; import java.util.Date; @@ -27,6 +26,7 @@ import java.util.TreeSet; import java.util.concurrent.TimeUnit; import libcore.util.Objects; +import libcore.util.ResponseSource; /** * Parsed HTTP response headers. diff --git a/src/main/java/libcore/net/http/SpdyTransport.java b/src/main/java/libcore/net/http/SpdyTransport.java index 547658cbf50b..d550ef716c3c 100644 --- a/src/main/java/libcore/net/http/SpdyTransport.java +++ b/src/main/java/libcore/net/http/SpdyTransport.java @@ -16,14 +16,14 @@ package libcore.net.http; -import libcore.net.spdy.SpdyConnection; -import libcore.net.spdy.SpdyStream; import java.io.IOException; import java.io.InputStream; import java.io.InterruptedIOException; import java.io.OutputStream; import java.net.CacheRequest; import java.util.List; +import libcore.net.spdy.SpdyConnection; +import libcore.net.spdy.SpdyStream; final class SpdyTransport implements Transport { private final HttpEngine httpEngine; diff --git a/src/main/java/libcore/net/spdy/SpdyReader.java b/src/main/java/libcore/net/spdy/SpdyReader.java index 9540b230ab5d..38557c95b435 100644 --- a/src/main/java/libcore/net/spdy/SpdyReader.java +++ b/src/main/java/libcore/net/spdy/SpdyReader.java @@ -20,6 +20,7 @@ import java.io.EOFException; import java.io.IOException; import java.io.InputStream; +import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; @@ -34,7 +35,7 @@ */ final class SpdyReader { public static final Charset UTF_8 = Charset.forName("UTF-8"); - public static final byte[] DICTIONARY = ("" + private static final String DICTIONARY_STRING = "" + "optionsgetheadpostputdeletetraceacceptaccept-charsetaccept-encodingaccept-" + "languageauthorizationexpectfromhostif-modified-sinceif-matchif-none-matchi" + "f-rangeif-unmodifiedsincemax-forwardsproxy-authorizationrangerefererteuser" @@ -47,7 +48,15 @@ final class SpdyReader { + "ndayTuesdayWednesdayThursdayFridaySaturdaySundayJanFebMarAprMayJunJulAugSe" + "pOctNovDecchunkedtext/htmlimage/pngimage/jpgimage/gifapplication/xmlapplic" + "ation/xhtmltext/plainpublicmax-agecharset=iso-8859-1utf-8gzipdeflateHTTP/1" - + ".1statusversionurl\0").getBytes(UTF_8); + + ".1statusversionurl\0"; + public static final byte[] DICTIONARY; + static { + try { + DICTIONARY = DICTIONARY_STRING.getBytes("UTF-8"); + } catch (UnsupportedEncodingException e) { + throw new AssertionError(e); + } + } public final DataInputStream in; public int flags; @@ -184,7 +193,7 @@ private List readNameValueBlock(int length) throws IOException { for (int i = 0; i < numberOfPairs; i++) { String name = readString(); String values = readString(); - if (name.isEmpty() || values.isEmpty()) { + if (name.length() == 0 || values.length() == 0) { throw new IOException(); // TODO: PROTOCOL ERROR } entries.add(name); @@ -206,6 +215,6 @@ private String readString() throws DataFormatException, IOException { int length = nameValueBlockIn.readShort(); byte[] bytes = new byte[length]; Streams.readFully(nameValueBlockIn, bytes); - return new String(bytes, 0, length, UTF_8); + return new String(bytes, 0, length, "UTF-8"); } } diff --git a/src/main/java/libcore/net/spdy/SpdyServer.java b/src/main/java/libcore/net/spdy/SpdyServer.java index 4a3f827a5320..52af83c01ba9 100644 --- a/src/main/java/libcore/net/spdy/SpdyServer.java +++ b/src/main/java/libcore/net/spdy/SpdyServer.java @@ -80,7 +80,7 @@ private void send404(SpdyStream stream, String path) throws IOException { ); OutputStream out = stream.reply(responseHeaders); String text = "Not found: " + path; - out.write(text.getBytes()); + out.write(text.getBytes("UTF-8")); out.close(); } diff --git a/src/main/java/libcore/net/spdy/SpdyStream.java b/src/main/java/libcore/net/spdy/SpdyStream.java index bb1192cc8021..4588a4a1ba26 100644 --- a/src/main/java/libcore/net/spdy/SpdyStream.java +++ b/src/main/java/libcore/net/spdy/SpdyStream.java @@ -20,11 +20,12 @@ import java.io.InputStream; import java.io.InterruptedIOException; import java.io.OutputStream; -import static java.nio.ByteOrder.BIG_ENDIAN; import java.util.List; import libcore.io.Streams; import libcore.util.Libcore; +import static java.nio.ByteOrder.BIG_ENDIAN; + /** * A logical bidirectional stream. */ diff --git a/src/main/java/libcore/net/spdy/SpdyWriter.java b/src/main/java/libcore/net/spdy/SpdyWriter.java index cfd8a047d2e7..5bc46449e7af 100644 --- a/src/main/java/libcore/net/spdy/SpdyWriter.java +++ b/src/main/java/libcore/net/spdy/SpdyWriter.java @@ -101,7 +101,7 @@ private void writeNameValueBlockToBuffer() throws IOException { nameValueBlockOut.writeShort(numberOfPairs); for (String s : nameValueBlock) { nameValueBlockOut.writeShort(s.length()); - nameValueBlockOut.write(s.getBytes(SpdyReader.UTF_8)); + nameValueBlockOut.write(s.getBytes("UTF-8")); } nameValueBlockOut.flush(); } diff --git a/src/main/java/libcore/util/Libcore.java b/src/main/java/libcore/util/Libcore.java index 63ab921fa7e1..3cf1ae3e4bca 100644 --- a/src/main/java/libcore/util/Libcore.java +++ b/src/main/java/libcore/util/Libcore.java @@ -2,7 +2,9 @@ import java.io.File; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.Socket; import java.net.SocketException; import java.net.URI; @@ -23,87 +25,120 @@ public final class Libcore { private Libcore() { } + private static boolean useAndroidTlsApis; + private static Class openSslSocketClass; + private static Method setEnabledCompressionMethods; + private static Method setUseSessionTickets; + private static Method setHostname; + private static boolean android23TlsOptionsAvailable; + private static Method setNpnProtocols; + private static Method getNpnSelectedProtocol; + private static boolean android41TlsOptionsAvailable; + + static { + try { + openSslSocketClass = Class.forName( + "org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl"); + useAndroidTlsApis = true; + setEnabledCompressionMethods = openSslSocketClass.getMethod( + "setEnabledCompressionMethods", String[].class); + setUseSessionTickets = openSslSocketClass.getMethod( + "setUseSessionTickets", boolean.class); + setHostname = openSslSocketClass.getMethod("setHostname", String.class); + android23TlsOptionsAvailable = true; + setNpnProtocols = openSslSocketClass.getMethod("setNpnProtocols", byte[].class); + getNpnSelectedProtocol = openSslSocketClass.getMethod("getNpnSelectedProtocol"); + android41TlsOptionsAvailable = true; + } catch (ClassNotFoundException ignored) { + // This isn't an Android runtime. + } catch (NoSuchMethodException ignored) { + // This Android runtime is missing some optional TLS options. + } + } + public static void makeTlsTolerant(SSLSocket socket, String socketHost, boolean tlsTolerant) { if (!tlsTolerant) { socket.setEnabledProtocols(new String[] {"SSLv3"}); return; } - try { - Class openSslSocketClass = Class.forName( - "org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl"); - if (openSslSocketClass.isInstance(socket)) { - openSslSocketClass.getMethod("setEnabledCompressionMethods", String[].class) - .invoke(socket, new Object[] {new String[] {"ZLIB"}}); - openSslSocketClass.getMethod("setUseSessionTickets", boolean.class) - .invoke(socket, true); - openSslSocketClass.getMethod("setHostname", String.class) - .invoke(socket, socketHost); + if (android23TlsOptionsAvailable && openSslSocketClass.isInstance(socket)) { + // This is Android: use reflection on OpenSslSocketImpl. + try { + String[] compressionMethods = {"ZLIB"}; + setEnabledCompressionMethods.invoke(socket, + new Object[] { compressionMethods }); + setUseSessionTickets.invoke(socket, true); + setHostname.invoke(socket, socketHost); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new AssertionError(e); } - } catch (ClassNotFoundException ignored) { - // TODO: support the RI's socket classes - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { - throw new AssertionError(e); } } + /** + * Returns the negotiated protocol, or null if no protocol was negotiated. + */ public static byte[] getNpnSelectedProtocol(SSLSocket socket) { - // First try Android's APIs. - try { - Class openSslSocketClass = Class.forName( - "org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl"); - return (byte[]) openSslSocketClass.getMethod("getNpnSelectedProtocol").invoke(socket); - } catch (ClassNotFoundException ignored) { - // this isn't Android; fall through to try OpenJDK with Jetty - } catch (IllegalAccessException e) { - throw new AssertionError(); - } catch (InvocationTargetException e) { - throw new AssertionError(); - } catch (NoSuchMethodException e) { - throw new AssertionError(); - } - - // Next try OpenJDK. - JettyNpnProvider provider = (JettyNpnProvider) NextProtoNego.get(socket); - if (!provider.unsupported && provider.selected == null) { - throw new IllegalStateException("No callback received. Is NPN configured properly?"); + if (useAndroidTlsApis) { + // This is Android: use reflection on OpenSslSocketImpl. + if (android41TlsOptionsAvailable && openSslSocketClass.isInstance(socket)) { + try { + return (byte[]) getNpnSelectedProtocol.invoke(socket); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } catch (IllegalAccessException e) { + throw new AssertionError(e); + } + } + return null; + } else { + // This is OpenJDK: use JettyNpnProvider. + JettyNpnProvider provider = (JettyNpnProvider) NextProtoNego.get(socket); + if (!provider.unsupported && provider.selected == null) { + throw new IllegalStateException( + "No callback received. Is NPN configured properly?"); + } + try { + return provider.unsupported + ? null + : provider.selected.getBytes("US-ASCII"); + } catch (UnsupportedEncodingException e) { + throw new AssertionError(e); + } } - return provider.unsupported - ? null - : provider.selected.getBytes(Charsets.US_ASCII); } public static void setNpnProtocols(SSLSocket socket, byte[] npnProtocols) { - // First try Android's APIs. - try { - Class openSslSocketClass = Class.forName( - "org.apache.harmony.xnet.provider.jsse.OpenSSLSocketImpl"); - openSslSocketClass.getMethod("setNpnProtocols", byte[].class) - .invoke(socket, npnProtocols); - } catch (ClassNotFoundException ignored) { - // this isn't Android; fall through to try OpenJDK with Jetty - } catch (IllegalAccessException e) { - throw new AssertionError(); - } catch (InvocationTargetException e) { - throw new AssertionError(); - } catch (NoSuchMethodException e) { - throw new AssertionError(); - } - - // Next try OpenJDK. - List strings = new ArrayList(); - for (int i = 0; i < npnProtocols.length;) { - int length = npnProtocols[i++]; - strings.add(new String(npnProtocols, i, length, Charsets.US_ASCII)); - i += length; + if (useAndroidTlsApis) { + // This is Android: use reflection on OpenSslSocketImpl. + if (android41TlsOptionsAvailable && openSslSocketClass.isInstance(socket)) { + try { + setNpnProtocols.invoke(socket, new Object[] { npnProtocols }); + } catch (IllegalAccessException e) { + throw new AssertionError(e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } + } + } else { + // This is OpenJDK: use JettyNpnProvider. + try { + List strings = new ArrayList(); + for (int i = 0; i < npnProtocols.length;) { + int length = npnProtocols[i++]; + strings.add(new String(npnProtocols, i, length, "US-ASCII")); + i += length; + } + JettyNpnProvider provider = new JettyNpnProvider(); + provider.protocols = strings; + NextProtoNego.put(socket, provider); + } catch (UnsupportedEncodingException e) { + throw new AssertionError(e); + } } - JettyNpnProvider provider = new JettyNpnProvider(); - provider.protocols = strings; - NextProtoNego.put(socket, provider); } private static class JettyNpnProvider diff --git a/src/test/java/libcore/net/http/URLConnectionTest.java b/src/test/java/libcore/net/http/URLConnectionTest.java index 993135c20f9d..6df8f530fb6c 100644 --- a/src/test/java/libcore/net/http/URLConnectionTest.java +++ b/src/test/java/libcore/net/http/URLConnectionTest.java @@ -548,7 +548,7 @@ public void testContentDisagreesWithChunkedHeader() throws IOException { mockResponse.setChunkedBody("abc", 3); ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); bytesOut.write(mockResponse.getBody()); - bytesOut.write("\r\nYOU SHOULD NOT SEE THIS".getBytes()); + bytesOut.write("\r\nYOU SHOULD NOT SEE THIS".getBytes("UTF-8")); mockResponse.setBody(bytesOut.toByteArray()); mockResponse.clearHeaders(); mockResponse.addHeader("Transfer-encoding: chunked"); diff --git a/src/test/java/libcore/net/spdy/SpdyConnectionTest.java b/src/test/java/libcore/net/spdy/SpdyConnectionTest.java index 206a561e7fad..09172fa4c3b7 100644 --- a/src/test/java/libcore/net/spdy/SpdyConnectionTest.java +++ b/src/test/java/libcore/net/spdy/SpdyConnectionTest.java @@ -37,7 +37,7 @@ public void testClientCreatesStreamAndServerReplies() throws Exception { SpdyWriter replyData = peer.sendFrame(); replyData.flags = SpdyConnection.FLAG_FIN; replyData.streamId = 1; - replyData.data("robot".getBytes()); + replyData.data("robot".getBytes("UTF-8")); peer.acceptFrame(); peer.play(); @@ -50,7 +50,7 @@ public void testClientCreatesStreamAndServerReplies() throws Exception { assertEquals("robot", reader.readLine()); assertEquals(null, reader.readLine()); OutputStream out = stream.getOutputStream(); - out.write("c3po".getBytes()); + out.write("c3po".getBytes("UTF-8")); out.close(); // verify the peer received what was expected @@ -60,7 +60,7 @@ public void testClientCreatesStreamAndServerReplies() throws Exception { assertEquals(0, synStream.reader.associatedStreamId); assertEquals(Arrays.asList("b", "banana"), synStream.reader.nameValueBlock); MockSpdyPeer.InFrame requestData = peer.takeFrame(); - assertTrue(Arrays.equals("c3po".getBytes(), requestData.data)); + assertTrue(Arrays.equals("c3po".getBytes("UTF-8"), requestData.data)); } public void testServerCreatesStreamAndClientReplies() throws Exception { diff --git a/src/test/java/libcore/net/ssl/SslContextBuilder.java b/src/test/java/libcore/net/ssl/SslContextBuilder.java index a227a0f831ce..d88ca9c9288c 100644 --- a/src/test/java/libcore/net/ssl/SslContextBuilder.java +++ b/src/test/java/libcore/net/ssl/SslContextBuilder.java @@ -28,7 +28,6 @@ import java.security.cert.Certificate; import java.security.cert.X509Certificate; import java.util.Date; -import java.util.concurrent.TimeUnit; import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManagerFactory; @@ -48,9 +47,10 @@ public final class SslContextBuilder { Security.addProvider(new BouncyCastleProvider()); } + private static final long ONE_DAY_MILLIS = 1000L * 60 * 60 * 24; private final String hostName; private long notBefore = System.currentTimeMillis(); - private long notAfter = System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1); + private long notAfter = System.currentTimeMillis() + ONE_DAY_MILLIS; /** * @param hostName the subject of the host. For TLS this should be the @@ -120,7 +120,7 @@ private KeyStore newEmptyKeyStore(char[] password) throws GeneralSecurityExcepti keyStore.load(in, password); return keyStore; } catch (IOException e) { - throw new AssertionError(); + throw new AssertionError(e); } } }