Top Description Inners Fields Constructors Methods
org.eclipse.jetty.io.ssl

public Class SslConnection

extends AbstractConnection
implements UpgradeTo
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.io.Connection.UpgradeTo
Imports
java.io.IOException, java.net.SocketAddress, java.nio.ByteBuffer, java.security.cert.X509Certificate, java.util.ArrayList, .List, java.util.concurrent.Executor, .TimeoutException, java.util.concurrent.atomic.AtomicLong, .AtomicReference, java.util.function.ToIntFunction, javax.net.ssl.SSLEngine, .SSLEngineResult, .SSLEngineResult.HandshakeStatus, .SSLEngineResult.Status, .SSLException, .SSLHandshakeException, .SSLSession, org.eclipse.jetty.io.AbstractConnection, .AbstractEndPoint, .ByteBufferPool, .Connection, .EndPoint, .RetainableByteBuffer, .WriteFlusher, org.eclipse.jetty.util.BufferUtil, .Callback, .ExceptionUtil, .IO, .StringUtil, org.eclipse.jetty.util.ssl.SslContextFactory, org.eclipse.jetty.util.thread.AutoLock, .Invocable, org.slf4j.Logger, .LoggerFactory

A Connection that acts as an interceptor between an EndPoint providing SSL encrypted data and another consumer of an EndPoint (typically an Connection like HttpConnection) that wants unencrypted data.

The connector uses an EndPoint (typically SocketChannelEndPoint) as it's source/sink of encrypted data. It then provides an endpoint via getSslEndPoint() to expose a source/sink of unencrypted data to another connection (eg HttpConnection).

The design of this class is based on a clear separation between the passive methods, which do not block nor schedule any asynchronous callbacks, and active methods that do schedule asynchronous callbacks.

The passive methods are SslEndPoint#fill(ByteBuffer) and SslEndPoint#flush(ByteBuffer...). They make best effort attempts to progress the connection using only calls to the encrypted EndPoint#fill(ByteBuffer) and EndPoint#flush(ByteBuffer...) methods. They will never block nor schedule any readInterest or write callbacks. If a fill/flush cannot progress either because of network congestion or waiting for an SSL handshake message, then the fill/flush will simply return with zero bytes filled/flushed. Specifically, if a flush cannot proceed because it needs to receive a handshake message, then the flush will attempt to fill bytes from the encrypted endpoint, but if insufficient bytes are read it will NOT call EndPoint#fillInterested(Callback).

It is only the active methods : SslEndPoint#fillInterested(Callback) and SslEndPoint#write(Callback, ByteBuffer...) that may schedule callbacks by calling the encrypted EndPoint#fillInterested(Callback) and EndPoint#write(Callback, ByteBuffer...) methods. For normal data handling, the decrypted fillInterest method will result in an encrypted fillInterest and a decrypted write will result in an encrypted write. However, due to SSL handshaking requirements, it is also possible for a decrypted fill to call the encrypted write and for the decrypted flush to call the encrypted fillInterested methods.

MOST IMPORTANTLY, the encrypted callbacks from the active methods (#onFillable() and WriteFlusher#completeWrite()) do no filling or flushing themselves. Instead they simple make the callbacks to the decrypted callbacks, so that the passive encrypted fill/flush will be called again and make another best effort attempt to progress the connection.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum
private static enum
private static enum
private abstract class
public class

Field Summary

Modifier and TypeField and Description
private final ByteBufferPool
private final AtomicLong
private final AtomicLong
private boolean
private final boolean
private RetainableByteBuffer
private final boolean
private RetainableByteBuffer
private RetainableByteBuffer
private SslConnection.FillState
private SslConnection.FlushState
private final AtomicReference<SslConnection.HandshakeState>
private final AutoLock
private boolean
private int
private boolean
private final Runnable
private final SslContextFactory
private final SslConnection.SslEndPoint
private final SSLEngine
private final Callback
private boolean
private final List<SslHandshakeListener>
private static final Logger
private static final String

Constructor Summary

AccessConstructor and Description
public
SslConnection(ByteBufferPool byteBufferPool, Executor executor, EndPoint endPoint, SSLEngine sslEngine)

Deprecated
public
SslConnection(ByteBufferPool byteBufferPool, Executor executor, SslContextFactory sslContextFactory, EndPoint endPoint, SSLEngine sslEngine)

public
SslConnection(ByteBufferPool byteBufferPool, Executor executor, EndPoint endPoint, SSLEngine sslEngine, boolean useDirectBuffersForEncryption, boolean useDirectBuffersForDecryption)

Deprecated
public
SslConnection(ByteBufferPool byteBufferPool, Executor executor, SslContextFactory sslContextFactory, EndPoint endPoint, SSLEngine sslEngine, boolean useDirectBuffersForEncryption, boolean useDirectBuffersForDecryption)

Method Summary

Modifier and TypeMethod and Description
private void
private void
public void
public void
close()

Overrides org.eclipse.jetty.io.AbstractConnection.close.

Implements org.eclipse.jetty.io.Connection.close.

Performs a logical close of this connection.

private void
private void
private int
private int
public long
public long
private int
public int

Returns:

The number of renegotiations allowed for this connection. When the limit is 0 renegotiation will be denied. If the limit is less than 0 then no limit is applied.
getRenegotiationLimit
()

public SslConnection.SslEndPoint
public SSLEngine
private boolean
private boolean
private boolean
public boolean
public boolean

Returns:

whether peers must send the TLS close_notify message
isRequireCloseMessage
()

protected int
protected boolean
protected SslConnection.SslEndPoint
public void
onClose(Throwable
The cause of the close or null for a normal close
cause
)

Overrides org.eclipse.jetty.io.AbstractConnection.onClose.

Implements org.eclipse.jetty.io.Connection.onClose.

Callback method invoked when this connection is closed.

public void
onFillable()

Implements abstract org.eclipse.jetty.io.AbstractConnection.onFillable.

Callback method invoked when the endpoint is ready to be read.

public void
onFillInterestedFailed(Throwable
the exception that caused the failure
cause
)

Overrides org.eclipse.jetty.io.AbstractConnection.onFillInterestedFailed.

Callback method invoked when the endpoint failed to be ready to be read.

public boolean
onIdleExpired(TimeoutException timeoutException)

Overrides org.eclipse.jetty.io.AbstractConnection.onIdleExpired.

Implements org.eclipse.jetty.io.Connection.onIdleExpired.

Callback method invoked upon an idle timeout event.

public void
onOpen()

Overrides org.eclipse.jetty.io.AbstractConnection.onOpen.

Implements org.eclipse.jetty.io.Connection.onOpen.

Callback method invoked when this connection is opened.

public void
onUpgradeTo(ByteBuffer
a non-null buffer of unconsumed bytes received from the upgrade-from connection. The buffer does not belong to any pool and should be discarded after having consumed its bytes.
buffer
)

Implements org.eclipse.jetty.io.Connection.UpgradeTo.onUpgradeTo.

Invoked during an upgrade to receive a buffer containing bytes that have not been consumed by the upgrade-from connection, and that must be consumed by this connection.

private void
private void
private void
private void
public boolean
public void
setRenegotiationAllowed(boolean renegotiationAllowed)

public void
setRenegotiationLimit(int
The number of renegotiations allowed for this connection. When the limit is 0 renegotiation will be denied. If the limit is less than 0 then no limit is applied. Default -1.
renegotiationLimit
)

public void
setRequireCloseMessage(boolean
whether peers must send the TLS close_notify message
requireCloseMessage
)

Sets whether it is required that a peer send the TLS close_notify message to indicate the will to close the connection, otherwise it may be interpreted as a truncation attack.

public String
protected SSLEngineResult
unwrap(SSLEngine sslEngine, ByteBuffer input, ByteBuffer output)

protected SSLEngineResult
wrap(SSLEngine sslEngine, ByteBuffer[] input, ByteBuffer output)

Inherited from org.eclipse.jetty.io.AbstractConnection:
addEventListenerfailedCallbackfillInterestedgetCreatedTimeStampgetEndPointgetExecutorgetInputBufferSizegetInvocationTypegetMessagesIngetMessagesOutisFillInterestedonReadTimeoutremoveEventListenersetInputBufferSizetoStringtryFillInterested