Search in sources :

Example 6 with SslConnection

use of org.eclipse.jetty.io.ssl.SslConnection in project jetty.project by eclipse.

the class SecureRequestCustomizer method customize.

@Override
public void customize(Connector connector, HttpConfiguration channelConfig, Request request) {
    EndPoint endp = request.getHttpChannel().getEndPoint();
    if (endp instanceof DecryptedEndPoint) {
        SslConnection.DecryptedEndPoint ssl_endp = (DecryptedEndPoint) endp;
        SslConnection sslConnection = ssl_endp.getSslConnection();
        SSLEngine sslEngine = sslConnection.getSSLEngine();
        customize(sslEngine, request);
        if (request.getHttpURI().getScheme() == null)
            request.setScheme(HttpScheme.HTTPS.asString());
    } else if (endp instanceof ProxyConnectionFactory.ProxyEndPoint) {
        ProxyConnectionFactory.ProxyEndPoint proxy = (ProxyConnectionFactory.ProxyEndPoint) endp;
        if (request.getHttpURI().getScheme() == null && proxy.getAttribute(ProxyConnectionFactory.TLS_VERSION) != null)
            request.setScheme(HttpScheme.HTTPS.asString());
    }
    if (HttpScheme.HTTPS.is(request.getScheme()))
        customizeSecure(request);
}
Also used : SslConnection(org.eclipse.jetty.io.ssl.SslConnection) DecryptedEndPoint(org.eclipse.jetty.io.ssl.SslConnection.DecryptedEndPoint) SSLEngine(javax.net.ssl.SSLEngine) DecryptedEndPoint(org.eclipse.jetty.io.ssl.SslConnection.DecryptedEndPoint) DecryptedEndPoint(org.eclipse.jetty.io.ssl.SslConnection.DecryptedEndPoint) EndPoint(org.eclipse.jetty.io.EndPoint)

Example 7 with SslConnection

use of org.eclipse.jetty.io.ssl.SslConnection in project jetty.project by eclipse.

the class SslConnectionTest method testSslConnectionClosedBeforeFill.

@Test
public void testSslConnectionClosedBeforeFill() throws Exception {
    File keyStore = MavenTestingUtils.getTestResourceFile("keystore.jks");
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(keyStore.getAbsolutePath());
    sslContextFactory.setKeyStorePassword("storepwd");
    sslContextFactory.start();
    ByteBufferPool byteBufferPool = new MappedByteBufferPool();
    QueuedThreadPool threadPool = new QueuedThreadPool();
    threadPool.start();
    ByteArrayEndPoint endPoint = new ByteArrayEndPoint();
    SSLEngine sslEngine = sslContextFactory.newSSLEngine();
    sslEngine.setUseClientMode(false);
    SslConnection sslConnection = new SslConnection(byteBufferPool, threadPool, endPoint, sslEngine);
    EndPoint sslEndPoint = sslConnection.getDecryptedEndPoint();
    sslEndPoint.setConnection(new AbstractConnection(sslEndPoint, threadPool) {

        @Override
        public void onFillable() {
        }
    });
    // There are no bytes in the endPoint, so we fill zero.
    // However, this will trigger state changes in SSLEngine
    // that will later cause it to throw ISE("Internal error").
    sslEndPoint.fill(BufferUtil.EMPTY_BUFFER);
    // Close the connection before filling.
    sslEndPoint.shutdownOutput();
    // Put some bytes in the endPoint to trigger
    // the required state changes in SSLEngine.
    byte[] bytes = new byte[] { 0x16, 0x03, 0x03, 0x00, 0x00 };
    endPoint.addInput(ByteBuffer.wrap(bytes));
    // reads from the EndPoint.
    try {
        sslEndPoint.fill(BufferUtil.EMPTY_BUFFER);
        Assert.fail();
    } catch (SSLHandshakeException x) {
    // Expected.
    }
}
Also used : ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) SSLEngine(javax.net.ssl.SSLEngine) ByteArrayEndPoint(org.eclipse.jetty.io.ByteArrayEndPoint) EndPoint(org.eclipse.jetty.io.EndPoint) ByteArrayEndPoint(org.eclipse.jetty.io.ByteArrayEndPoint) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) SslConnection(org.eclipse.jetty.io.ssl.SslConnection) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) QueuedThreadPool(org.eclipse.jetty.util.thread.QueuedThreadPool) AbstractConnection(org.eclipse.jetty.io.AbstractConnection) File(java.io.File) Test(org.junit.Test)

Aggregations

SslConnection (org.eclipse.jetty.io.ssl.SslConnection)7 SSLEngine (javax.net.ssl.SSLEngine)6 EndPoint (org.eclipse.jetty.io.EndPoint)5 File (java.io.File)2 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 AbstractConnection (org.eclipse.jetty.io.AbstractConnection)2 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)2 EOFException (java.io.EOFException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ByteBuffer (java.nio.ByteBuffer)1 SelectionKey (java.nio.channels.SelectionKey)1 SocketChannel (java.nio.channels.SocketChannel)1 Executor (java.util.concurrent.Executor)1 TimeoutException (java.util.concurrent.TimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 ServletInputStream (javax.servlet.ServletInputStream)1 ServletOutputStream (javax.servlet.ServletOutputStream)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1