Class SslConnection
- All Implemented Interfaces:
Closeable,AutoCloseable,Connection,Connection.UpgradeTo
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 getDecryptedEndPoint() 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 SslConnection.DecryptedEndPoint.fill(ByteBuffer) and SslConnection.DecryptedEndPoint.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 : AbstractEndPoint.fillInterested(Callback) and
AbstractEndPoint.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 Class Summary
Nested ClassesNested classes/interfaces inherited from interface org.eclipse.jetty.io.Connection
Connection.Listener, Connection.UpgradeFrom, Connection.UpgradeTo -
Constructor Summary
ConstructorsConstructorDescriptionSslConnection(ByteBufferPool byteBufferPool, Executor executor, EndPoint endPoint, SSLEngine sslEngine) SslConnection(ByteBufferPool byteBufferPool, Executor executor, EndPoint endPoint, SSLEngine sslEngine, boolean useDirectBuffersForEncryption, boolean useDirectBuffersForDecryption) SslConnection(RetainableByteBufferPool retainableByteBufferPool, ByteBufferPool byteBufferPool, Executor executor, EndPoint endPoint, SSLEngine sslEngine, boolean useDirectBuffersForEncryption, boolean useDirectBuffersForDecryption) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddHandshakeListener(SslHandshakeListener listener) voidclose()Performs a logical close of this connection.longlongintbooleanbooleanprotected intnetworkFill(ByteBuffer input) protected booleannetworkFlush(ByteBuffer output) protected SslConnection.DecryptedEndPointvoidCallback method invoked when this connection is closed.voidCallback method invoked when the endpoint is ready to be read.voidonFillInterestedFailed(Throwable cause) Callback method invoked when the endpoint failed to be ready to be read.booleanCallback method invoked upon an idle timeout event.voidonOpen()Callback method invoked when this connection is opened.voidonUpgradeTo(ByteBuffer buffer) Invoked during anupgradeto receive a buffer containing bytes that have not been consumed by the upgrade-from connection, and that must be consumed by this connection.booleanremoveHandshakeListener(SslHandshakeListener listener) voidsetRenegotiationAllowed(boolean renegotiationAllowed) voidsetRenegotiationLimit(int renegotiationLimit) voidsetRequireCloseMessage(boolean requireCloseMessage) Sets whether it is required that a peer send the TLSclose_notifymessage to indicate the will to close the connection, otherwise it may be interpreted as a truncation attack.protected SSLEngineResultunwrap(SSLEngine sslEngine, ByteBuffer input, ByteBuffer output) protected SSLEngineResultwrap(SSLEngine sslEngine, ByteBuffer[] input, ByteBuffer output) Methods inherited from class org.eclipse.jetty.io.AbstractConnection
addEventListener, failedCallback, fillInterested, getCreatedTimeStamp, getEndPoint, getExecutor, getInputBufferSize, getMessagesIn, getMessagesOut, isFillInterested, onReadTimeout, removeEventListener, setInputBufferSize, toString, tryFillInterested
-
Constructor Details
-
SslConnection
public SslConnection(ByteBufferPool byteBufferPool, Executor executor, EndPoint endPoint, SSLEngine sslEngine) -
SslConnection
public SslConnection(ByteBufferPool byteBufferPool, Executor executor, EndPoint endPoint, SSLEngine sslEngine, boolean useDirectBuffersForEncryption, boolean useDirectBuffersForDecryption) -
SslConnection
public SslConnection(RetainableByteBufferPool retainableByteBufferPool, ByteBufferPool byteBufferPool, Executor executor, EndPoint endPoint, SSLEngine sslEngine, boolean useDirectBuffersForEncryption, boolean useDirectBuffersForDecryption)
-
-
Method Details
-
getBytesIn
public long getBytesIn()- Specified by:
getBytesInin interfaceConnection- Overrides:
getBytesInin classAbstractConnection
-
getBytesOut
public long getBytesOut()- Specified by:
getBytesOutin interfaceConnection- Overrides:
getBytesOutin classAbstractConnection
-
addHandshakeListener
-
removeHandshakeListener
-
newDecryptedEndPoint
-
getSSLEngine
-
getDecryptedEndPoint
-
isRenegotiationAllowed
public boolean isRenegotiationAllowed() -
setRenegotiationAllowed
public void setRenegotiationAllowed(boolean renegotiationAllowed) -
getRenegotiationLimit
public int getRenegotiationLimit()- 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.
-
setRenegotiationLimit
public void setRenegotiationLimit(int renegotiationLimit) - Parameters:
renegotiationLimit- 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.
-
isRequireCloseMessage
public boolean isRequireCloseMessage()- Returns:
- whether peers must send the TLS
close_notifymessage
-
setRequireCloseMessage
public void setRequireCloseMessage(boolean requireCloseMessage) Sets whether it is required that a peer send the TLS
close_notifymessage to indicate the will to close the connection, otherwise it may be interpreted as a truncation attack.This option is only useful on clients, since typically servers cannot accept connection-delimited content that may be truncated.
- Parameters:
requireCloseMessage- whether peers must send the TLSclose_notifymessage
-
onUpgradeTo
Description copied from interface:Connection.UpgradeToInvoked during an
upgradeto receive a buffer containing bytes that have not been consumed by the upgrade-from connection, and that must be consumed by this connection.- Specified by:
onUpgradeToin interfaceConnection.UpgradeTo- Parameters:
buffer- 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.
-
onOpen
public void onOpen()Description copied from interface:ConnectionCallback method invoked when this connection is opened.
Creators of the connection implementation are responsible for calling this method.
- Specified by:
onOpenin interfaceConnection- Overrides:
onOpenin classAbstractConnection
-
onClose
Description copied from interface:ConnectionCallback method invoked when this connection is closed.
Creators of the connection implementation are responsible for calling this method.
- Specified by:
onClosein interfaceConnection- Overrides:
onClosein classAbstractConnection- Parameters:
cause- The cause of the close or null for a normal close
-
close
public void close()Description copied from interface:ConnectionPerforms a logical close of this connection.
For simple connections, this may just mean to delegate the close to the associated
EndPointbut, for example, SSL connections should write the SSL close message before closing the associatedEndPoint.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceConnection- Overrides:
closein classAbstractConnection
-
onIdleExpired
public boolean onIdleExpired()Description copied from interface:ConnectionCallback method invoked upon an idle timeout event.
Implementations of this method may return true to indicate that the idle timeout handling should proceed normally, typically failing the EndPoint and causing it to be closed.
When false is returned, the handling of the idle timeout event is halted immediately and the EndPoint left in the state it was before the idle timeout event.
- Specified by:
onIdleExpiredin interfaceConnection- Overrides:
onIdleExpiredin classAbstractConnection- Returns:
- true to let the EndPoint handle the idle timeout, false to tell the EndPoint to halt the handling of the idle timeout.
-
onFillable
public void onFillable()Description copied from class:AbstractConnectionCallback method invoked when the endpoint is ready to be read.
- Specified by:
onFillablein classAbstractConnection- See Also:
-
onFillInterestedFailed
Description copied from class:AbstractConnectionCallback method invoked when the endpoint failed to be ready to be read.
- Overrides:
onFillInterestedFailedin classAbstractConnection- Parameters:
cause- the exception that caused the failure
-
wrap
protected SSLEngineResult wrap(SSLEngine sslEngine, ByteBuffer[] input, ByteBuffer output) throws SSLException - Throws:
SSLException
-
unwrap
protected SSLEngineResult unwrap(SSLEngine sslEngine, ByteBuffer input, ByteBuffer output) throws SSLException - Throws:
SSLException
-
toConnectionString
- Overrides:
toConnectionStringin classAbstractConnection
-
networkFill
- Throws:
IOException
-
networkFlush
- Throws:
IOException
-