diff options
author | Jesse Wilson <jessewilson@google.com> | 2011-12-20 12:38:53 -0500 |
---|---|---|
committer | Jesse Wilson <jessewilson@google.com> | 2011-12-20 12:47:16 -0500 |
commit | 27c744cc67c7b155bd2d47551205fb1720e7e196 (patch) | |
tree | 4da961dc6809125f500d875d6bb942700a082ab2 /luni | |
parent | abe4e615f473b387b1c00a738062a7c428f05a33 (diff) | |
download | libcore-27c744cc67c7b155bd2d47551205fb1720e7e196.zip libcore-27c744cc67c7b155bd2d47551205fb1720e7e196.tar.gz libcore-27c744cc67c7b155bd2d47551205fb1720e7e196.tar.bz2 |
Support in-memory HTTPS session caching for wrapped sockets.
Previously we couldn't reuse sessions with HttpsURLConnection
because the host was incorrect (getInetAddress returns null
for wrapped sockets) and because the compression method was
different (NULL vs. ZLIB).
This improves HttpsURLConnection request/response time on
localhost from ~275ms to ~145ms (without connection pooling).
Change-Id: I97bc343326658690b00589c0c804c2378b91ae61
Diffstat (limited to 'luni')
-rw-r--r-- | luni/src/main/java/org/apache/harmony/xnet/provider/jsse/NativeCrypto.java | 4 | ||||
-rw-r--r-- | luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java | 50 |
2 files changed, 26 insertions, 28 deletions
diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/NativeCrypto.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/NativeCrypto.java index 5e759c1..b56289b 100644 --- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/NativeCrypto.java +++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/NativeCrypto.java @@ -436,8 +436,8 @@ public final class NativeCrypto { return cipherSuites; } - private static final String SUPPORTED_COMPRESSION_METHOD_ZLIB = "ZLIB"; - private static final String SUPPORTED_COMPRESSION_METHOD_NULL = "NULL"; + public static final String SUPPORTED_COMPRESSION_METHOD_ZLIB = "ZLIB"; + public static final String SUPPORTED_COMPRESSION_METHOD_NULL = "NULL"; private static final String[] SUPPORTED_COMPRESSION_METHODS = { SUPPORTED_COMPRESSION_METHOD_ZLIB, SUPPORTED_COMPRESSION_METHOD_NULL }; diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java index d4681ae..4076655 100644 --- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java +++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSocketImpl.java @@ -18,7 +18,6 @@ package org.apache.harmony.xnet.provider.jsse; import dalvik.system.BlockGuard; import dalvik.system.CloseGuard; - import java.io.FileDescriptor; import java.io.IOException; import java.io.InputStream; @@ -194,14 +193,12 @@ public class OpenSSLSocketImpl * Gets the suitable session reference from the session cache container. */ private OpenSSLSessionImpl getCachedClientSession(ClientSessionContext sessionContext) { - if (super.getInetAddress() == null || - super.getInetAddress().getHostAddress() == null || - super.getInetAddress().getHostName() == null) { + String hostName = getPeerHostName(); + int port = getPeerPort(); + if (hostName == null) { return null; } - OpenSSLSessionImpl session = (OpenSSLSessionImpl) sessionContext.getSession( - super.getInetAddress().getHostName(), - super.getPort()); + OpenSSLSessionImpl session = (OpenSSLSessionImpl) sessionContext.getSession(hostName, port); if (session == null) { return null; } @@ -231,15 +228,17 @@ public class OpenSSLSocketImpl } String compressionMethod = session.getCompressionMethod(); - boolean compressionMethodFound = false; - for (String enabledCompressionMethod : enabledCompressionMethods) { - if (compressionMethod.equals(enabledCompressionMethod)) { - compressionMethodFound = true; - break; + if (!compressionMethod.equals(NativeCrypto.SUPPORTED_COMPRESSION_METHOD_NULL)) { + boolean compressionMethodFound = false; + for (String enabledCompressionMethod : enabledCompressionMethods) { + if (compressionMethod.equals(enabledCompressionMethod)) { + compressionMethodFound = true; + break; + } + } + if (!compressionMethodFound) { + return null; } - } - if (!compressionMethodFound) { - return null; } return session; @@ -428,17 +427,8 @@ public class OpenSSLSocketImpl = createCertChain(NativeCrypto.SSL_get_certificate(sslNativePointer)); X509Certificate[] peerCertificates = createCertChain(NativeCrypto.SSL_get_peer_cert_chain(sslNativePointer)); - if (wrappedHost == null) { - sslSession = new OpenSSLSessionImpl(sslSessionNativePointer, - localCertificates, peerCertificates, - super.getInetAddress().getHostName(), - super.getPort(), sessionContext); - } else { - sslSession = new OpenSSLSessionImpl(sslSessionNativePointer, - localCertificates, peerCertificates, - wrappedHost, wrappedPort, - sessionContext); - } + sslSession = new OpenSSLSessionImpl(sslSessionNativePointer, localCertificates, + peerCertificates, getPeerHostName(), getPeerPort(), sessionContext); // if not, putSession later in handshakeCompleted() callback if (handshakeCompleted) { sessionContext.putSession(sslSession); @@ -466,6 +456,14 @@ public class OpenSSLSocketImpl } } + private String getPeerHostName() { + return wrappedHost == null ? super.getInetAddress().getHostName() : wrappedHost; + } + + private int getPeerPort() { + return wrappedHost == null ? super.getPort() : wrappedPort; + } + /** * Return a possibly null array of X509Certificates given the * possibly null array of DER encoded bytes. |