345615 SSL Session caching improvements and test
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@3157 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
01c43b0ffe
commit
e5f549664e
|
@ -14,6 +14,7 @@
|
|||
package org.eclipse.jetty.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
@ -212,15 +213,17 @@ class SelectConnector extends AbstractLifeCycle implements HttpClient.Connector,
|
|||
{
|
||||
if (_sslContext==null)
|
||||
{
|
||||
_sslContext = _httpClient.getSslContextFactory().getSslContext();
|
||||
_enableSslSessionCaching = _httpClient.getSslContextFactory().isEnableSessionCaching();
|
||||
SslContextFactory factory = _httpClient.getSslContextFactory();
|
||||
_sslContext = factory.getSslContext();
|
||||
_enableSslSessionCaching = factory.isEnableSessionCaching();
|
||||
}
|
||||
|
||||
SSLEngine sslEngine = null;
|
||||
if (channel != null && _enableSslSessionCaching)
|
||||
{
|
||||
String peerHost = channel.socket().getInetAddress().getCanonicalHostName();
|
||||
int peerPort = channel.socket().getPort();
|
||||
InetSocketAddress remoteAddr = (InetSocketAddress)channel.socket().getRemoteSocketAddress();
|
||||
String peerHost = remoteAddr.getHostName();
|
||||
int peerPort = remoteAddr.getPort();
|
||||
|
||||
sslEngine = _sslContext.createSSLEngine(peerHost, peerPort);
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ import javax.net.ssl.KeyManager;
|
|||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLEngine;
|
||||
import javax.net.ssl.SSLSessionContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import javax.net.ssl.X509KeyManager;
|
||||
|
@ -149,12 +150,17 @@ public class SslContextFactory extends AbstractLifeCycle
|
|||
private boolean _enableOCSP = false;
|
||||
/** Location of OCSP Responder */
|
||||
private String _ocspResponderURL;
|
||||
|
||||
/** SSL keystore */
|
||||
private KeyStore _keyStore;
|
||||
/** SSL truststore */
|
||||
private KeyStore _trustStore;
|
||||
/** Set to true to enable SSL Session caching */
|
||||
private boolean _enableSessionCaching;
|
||||
/** SSL session cache size */
|
||||
private int _sslSessionCacheSize;
|
||||
/** SSL session timeout */
|
||||
private int _sslSessionTimeout;
|
||||
|
||||
/** SSL context */
|
||||
private SSLContext _context;
|
||||
|
@ -850,6 +856,10 @@ public class SslContextFactory extends AbstractLifeCycle
|
|||
SecureRandom secureRandom = (_secureRandomAlgorithm == null)?null:SecureRandom.getInstance(_secureRandomAlgorithm);
|
||||
_context = (_sslProvider == null)?SSLContext.getInstance(_sslProtocol):SSLContext.getInstance(_sslProtocol,_sslProvider);
|
||||
_context.init(keyManagers,trustManagers,secureRandom);
|
||||
|
||||
SSLSessionContext sslSessionContext = _context.getServerSessionContext();
|
||||
sslSessionContext.setSessionCacheSize(_sslSessionCacheSize);
|
||||
sslSessionContext.setSessionTimeout(_sslSessionTimeout);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1253,4 +1263,40 @@ public class SslContextFactory extends AbstractLifeCycle
|
|||
{
|
||||
_enableSessionCaching = enableSessionCaching;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get SSL session cache size.
|
||||
* @return SSL session cache size
|
||||
*/
|
||||
public int getSslSessionCacheSize()
|
||||
{
|
||||
return _sslSessionCacheSize;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** SEt SSL session cache size.
|
||||
* @param sslSessionCacheSize SSL session cache size to set
|
||||
*/
|
||||
public void setSslSessionCacheSize(int sslSessionCacheSize)
|
||||
{
|
||||
_sslSessionCacheSize = sslSessionCacheSize;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get SSL session timeout.
|
||||
* @return SSL session timeout
|
||||
*/
|
||||
public int getSslSessionTimeout()
|
||||
{
|
||||
return _sslSessionTimeout;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Set SSL session timeout.
|
||||
* @param sslSessionTimeout SSL session timeout to set
|
||||
*/
|
||||
public void setSslSessionTimeout(int sslSessionTimeout)
|
||||
{
|
||||
_sslSessionTimeout = sslSessionTimeout;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
package org.eclipse.jetty.server.ssl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
|
@ -588,8 +589,9 @@ public class SslSelectChannelConnector extends SelectChannelConnector implements
|
|||
{
|
||||
try
|
||||
{
|
||||
String peerHost = channel.socket().getInetAddress().getCanonicalHostName();
|
||||
int peerPort = channel.socket().getPort();
|
||||
InetSocketAddress remoteAddr = (InetSocketAddress)channel.socket().getRemoteSocketAddress();
|
||||
String peerHost = remoteAddr.getHostName();
|
||||
int peerPort = remoteAddr.getPort();
|
||||
|
||||
engine = _sslContextFactory.getSslContext().createSSLEngine(peerHost, peerPort);
|
||||
|
||||
|
|
|
@ -910,7 +910,6 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
protected static class AvailableHandler extends AbstractHandler
|
||||
{
|
||||
public Exchanger<Object> _ex = new Exchanger<Object>();
|
||||
|
@ -1029,6 +1028,38 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDualRequest1() throws Exception
|
||||
{
|
||||
configureServer(new HelloWorldHandler());
|
||||
|
||||
Socket client1=newSocket(HOST,_connector.getLocalPort());
|
||||
Socket client2=newSocket(HOST,_connector.getLocalPort());
|
||||
try
|
||||
{
|
||||
OutputStream os1=client1.getOutputStream();
|
||||
OutputStream os2=client2.getOutputStream();
|
||||
|
||||
os1.write(REQUEST1.getBytes());
|
||||
os2.write(REQUEST1.getBytes());
|
||||
os1.flush();
|
||||
os2.flush();
|
||||
|
||||
// Read the response.
|
||||
String response1=readResponse(client1);
|
||||
String response2=readResponse(client2);
|
||||
|
||||
// Check the response
|
||||
assertEquals("client1",RESPONSE1,response1);
|
||||
assertEquals("client2",RESPONSE1,response2);
|
||||
}
|
||||
finally
|
||||
{
|
||||
client1.close();
|
||||
client2.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read entire response from the client. Close the output.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue