Skip to content

Commit

Permalink
Fixes #9326 - Rename DecryptedEndPoint to SslEndPoint.
Browse files Browse the repository at this point in the history
Signed-off-by: Simone Bordet <[email protected]>
  • Loading branch information
sbordet committed Feb 8, 2023
1 parent b87f938 commit d2fe1ba
Show file tree
Hide file tree
Showing 20 changed files with 79 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@ circle application
network - SocketChannelEndPoint
SocketChannelEndPoint - SslConnection
SslConnection -- DecryptedEndPoint
DecryptedEndPoint - HttpConnection
SslConnection -- SslEndPoint
SslEndPoint - HttpConnection
HttpConnection - application
----

Bytes read by the `SocketChannelEndPoint` will be interpreted as TLS bytes by the `SslConnection`, then decrypted and made available to the `DecryptedEndPoint` (a component part of `SslConnection`), which will then provide them to `HttpConnection`.
Bytes read by the `SocketChannelEndPoint` will be interpreted as TLS bytes by the `SslConnection`, then decrypted and made available to the `SslEndPoint` (a component part of `SslConnection`), which will then provide them to `HttpConnection`.

The application writes bytes through the `HttpConnection` to the `DecryptedEndPoint`, which will encrypt them through the `SslConnection` and write the encrypted bytes to the `SocketChannelEndPoint`.
The application writes bytes through the `HttpConnection` to the `SslEndPoint`, which will encrypt them through the `SslConnection` and write the encrypted bytes to the `SocketChannelEndPoint`.

[[pg-server-io-arch-connection-factory-detecting]]
==== Choosing `ConnectionFactory` via Bytes Detection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public void writeLine(String line, Callback callback)
if (failure == null)
{
// Unwrap the SslConnection to access the "line" APIs in TelnetConnection.
TelnetConnection connection = (TelnetConnection)sslConnection.getDecryptedEndPoint().getConnection();
TelnetConnection connection = (TelnetConnection)sslConnection.getSslEndPoint().getConnection();
// Register a listener that receives string lines.
connection.onLine(line -> System.getLogger("app").log(INFO, "line: {0}", line));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.eclipse.jetty.alpn.client.ALPNClientConnection;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.ssl.ALPNProcessor;
import org.eclipse.jetty.io.ssl.SslConnection;
import org.eclipse.jetty.io.ssl.SslConnection.SslEndPoint;
import org.eclipse.jetty.io.ssl.SslHandshakeListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -55,8 +55,8 @@ public void configure(SSLEngine sslEngine, Connection connection)
ALPNClientConnection alpn = (ALPNClientConnection)connection;
String[] protocols = alpn.getProtocols().toArray(new String[0]);
Conscrypt.setApplicationProtocols(sslEngine, protocols);
((SslConnection.DecryptedEndPoint)connection.getEndPoint()).getSslConnection()
.addHandshakeListener(new ALPNListener(alpn));
SslEndPoint sslEndPoint = (SslEndPoint)connection.getEndPoint();
sslEndPoint.getSslConnection().addHandshakeListener(new ALPNListener(alpn));
}
catch (RuntimeException x)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.eclipse.jetty.alpn.server.ALPNServerConnection;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.ssl.ALPNProcessor;
import org.eclipse.jetty.io.ssl.SslConnection.DecryptedEndPoint;
import org.eclipse.jetty.io.ssl.SslConnection.SslEndPoint;
import org.eclipse.jetty.io.ssl.SslHandshakeListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -74,7 +74,8 @@ private final class ALPNCallback extends ApplicationProtocolSelector implements
private ALPNCallback(ALPNServerConnection connection)
{
alpnConnection = connection;
((DecryptedEndPoint)alpnConnection.getEndPoint()).getSslConnection().addHandshakeListener(this);
SslEndPoint sslEndPoint = (SslEndPoint)alpnConnection.getEndPoint();
sslEndPoint.getSslConnection().addHandshakeListener(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.eclipse.jetty.alpn.client.ALPNClientConnection;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.ssl.ALPNProcessor;
import org.eclipse.jetty.io.ssl.SslConnection.DecryptedEndPoint;
import org.eclipse.jetty.io.ssl.SslConnection.SslEndPoint;
import org.eclipse.jetty.io.ssl.SslHandshakeListener;
import org.eclipse.jetty.util.JavaVersion;
import org.slf4j.Logger;
Expand Down Expand Up @@ -52,8 +52,8 @@ public void configure(SSLEngine sslEngine, Connection connection)
List<String> protocols = alpn.getProtocols();
sslParameters.setApplicationProtocols(protocols.toArray(new String[0]));
sslEngine.setSSLParameters(sslParameters);
((DecryptedEndPoint)connection.getEndPoint()).getSslConnection()
.addHandshakeListener(new ALPNListener(alpn));
SslEndPoint sslEndPoint = (SslEndPoint)connection.getEndPoint();
sslEndPoint.getSslConnection().addHandshakeListener(new ALPNListener(alpn));
}

private static final class ALPNListener implements SslHandshakeListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.eclipse.jetty.alpn.server.ALPNServerConnection;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.ssl.ALPNProcessor;
import org.eclipse.jetty.io.ssl.SslConnection;
import org.eclipse.jetty.io.ssl.SslConnection.SslEndPoint;
import org.eclipse.jetty.io.ssl.SslHandshakeListener;
import org.eclipse.jetty.util.JavaVersion;
import org.slf4j.Logger;
Expand Down Expand Up @@ -57,7 +57,8 @@ private static final class ALPNCallback implements BiFunction<SSLEngine, List<St
private ALPNCallback(ALPNServerConnection connection)
{
alpnConnection = connection;
((SslConnection.DecryptedEndPoint)alpnConnection.getEndPoint()).getSslConnection().addHandshakeListener(this);
SslEndPoint sslEndPoint = (SslEndPoint)alpnConnection.getEndPoint();
sslEndPoint.getSslConnection().addHandshakeListener(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void testSslConnectionClosedBeforeFill() throws Exception
SSLEngine sslEngine = sslContextFactory.newSSLEngine();
sslEngine.setUseClientMode(false);
SslConnection sslConnection = new SslConnection(bufferPool, threadPool, endPoint, sslEngine);
EndPoint sslEndPoint = sslConnection.getDecryptedEndPoint();
EndPoint sslEndPoint = sslConnection.getSslEndPoint();
sslEndPoint.setConnection(new AbstractConnection(sslEndPoint, threadPool)
{
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ private void upgrade(ClientConnectionFactory factory, EndPoint endPoint, Map<Str
// Avoid double TLS wrapping. We want to keep the existing
// SslConnection that has already performed the TLS handshake,
// and just upgrade the nested connection.
if (factory instanceof SslClientConnectionFactory && endPoint instanceof SslConnection.DecryptedEndPoint)
factory = ((SslClientConnectionFactory)factory).getClientConnectionFactory();
if (factory instanceof SslClientConnectionFactory sslFactory && endPoint instanceof SslConnection.SslEndPoint)
factory = sslFactory.getClientConnectionFactory();
var newConnection = factory.newConnection(endPoint, context);
endPoint.upgrade(newConnection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ public boolean isPersistent()
@Override
public boolean isSecure()
{
return getEndPoint() instanceof SslConnection.DecryptedEndPoint;
return getEndPoint() instanceof SslConnection.SslEndPoint;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public org.eclipse.jetty.io.Connection newConnection(EndPoint endPoint, Map<Stri

SslConnection sslConnection = newSslConnection(byteBufferPool, executor, endPoint, engine);

EndPoint appEndPoint = sslConnection.getDecryptedEndPoint();
EndPoint appEndPoint = sslConnection.getSslEndPoint();
appEndPoint.setConnection(connectionFactory.newConnection(appEndPoint, context));

sslConnection.addHandshakeListener(new HTTPSHandshakeListener(context));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@
* wants unencrypted data.
* <p>
* The connector uses an {@link EndPoint} (typically SocketChannelEndPoint) as
* it's source/sink of encrypted data. It then provides an endpoint via {@link #getDecryptedEndPoint()} to
* it's source/sink of encrypted data. It then provides an endpoint via {@link #getSslEndPoint()} to
* expose a source/sink of unencrypted data to another connection (eg HttpConnection).
* <p>
* 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.
* <p>
* The passive methods are {@link DecryptedEndPoint#fill(ByteBuffer)} and {@link DecryptedEndPoint#flush(ByteBuffer...)}. They make best
* The passive methods are {@link SslEndPoint#fill(ByteBuffer)} and {@link SslEndPoint#flush(ByteBuffer...)}. They make best
* effort attempts to progress the connection using only calls to the encrypted {@link EndPoint#fill(ByteBuffer)} and {@link 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 {@link EndPoint#fillInterested(Callback)}.
* <p>
* It is only the active methods : {@link DecryptedEndPoint#fillInterested(Callback)} and
* {@link DecryptedEndPoint#write(Callback, ByteBuffer...)} that may schedule callbacks by calling the encrypted
* It is only the active methods : {@link SslEndPoint#fillInterested(Callback)} and
* {@link SslEndPoint#write(Callback, ByteBuffer...)} that may schedule callbacks by calling the encrypted
* {@link EndPoint#fillInterested(Callback)} and {@link 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
Expand Down Expand Up @@ -110,7 +110,7 @@ private enum FlushState
private final AtomicLong _bytesOut = new AtomicLong();
private final ByteBufferPool _bufferPool;
private final SSLEngine _sslEngine;
private final DecryptedEndPoint _decryptedEndPoint;
private final SslEndPoint _sslEndPoint;
private final boolean _encryptedDirectBuffers;
private final boolean _decryptedDirectBuffers;
private RetainableByteBuffer _decryptedInput;
Expand All @@ -128,13 +128,13 @@ private enum FlushState
@Override
public void run()
{
_decryptedEndPoint.getFillInterest().fillable();
_sslEndPoint.getFillInterest().fillable();
}

@Override
public InvocationType getInvocationType()
{
return _decryptedEndPoint.getFillInterest().getCallbackInvocationType();
return _sslEndPoint.getFillInterest().getCallbackInvocationType();
}
};
private final Callback _sslReadCallback = new Callback()
Expand All @@ -154,7 +154,7 @@ public void failed(final Throwable x)
@Override
public InvocationType getInvocationType()
{
return getDecryptedEndPoint().getFillInterest().getCallbackInvocationType();
return getSslEndPoint().getFillInterest().getCallbackInvocationType();
}

@Override
Expand All @@ -177,7 +177,7 @@ public SslConnection(ByteBufferPool byteBufferPool, Executor executor, EndPoint
super(endPoint, executor);
this._bufferPool = byteBufferPool;
this._sslEngine = sslEngine;
this._decryptedEndPoint = newDecryptedEndPoint();
this._sslEndPoint = newSslEndPoint();
this._encryptedDirectBuffers = useDirectBuffersForEncryption;
this._decryptedDirectBuffers = useDirectBuffersForDecryption;
}
Expand All @@ -204,19 +204,19 @@ public boolean removeHandshakeListener(SslHandshakeListener listener)
return handshakeListeners.remove(listener);
}

protected DecryptedEndPoint newDecryptedEndPoint()
protected SslEndPoint newSslEndPoint()
{
return new DecryptedEndPoint();
return new SslEndPoint();
}

public SSLEngine getSSLEngine()
{
return _sslEngine;
}

public DecryptedEndPoint getDecryptedEndPoint()
public SslEndPoint getSslEndPoint()
{
return _decryptedEndPoint;
return _sslEndPoint;
}

public boolean isRenegotiationAllowed()
Expand Down Expand Up @@ -331,26 +331,26 @@ public void onUpgradeTo(ByteBuffer buffer)
public void onOpen()
{
super.onOpen();
getDecryptedEndPoint().getConnection().onOpen();
getSslEndPoint().getConnection().onOpen();
}

@Override
public void onClose(Throwable cause)
{
_decryptedEndPoint.getConnection().onClose(cause);
getSslEndPoint().getConnection().onClose(cause);
super.onClose(cause);
}

@Override
public void close()
{
getDecryptedEndPoint().getConnection().close();
getSslEndPoint().getConnection().close();
}

@Override
public boolean onIdleExpired()
{
return getDecryptedEndPoint().getConnection().onIdleExpired();
return getSslEndPoint().getConnection().onIdleExpired();
}

@Override
Expand All @@ -366,10 +366,10 @@ public void onFillable()
LOG.debug(">c.onFillable {}", SslConnection.this);

// We have received a close handshake, close the end point to send FIN.
if (_decryptedEndPoint.isInputShutdown())
_decryptedEndPoint.close();
if (_sslEndPoint.isInputShutdown())
_sslEndPoint.close();

_decryptedEndPoint.onFillable();
_sslEndPoint.onFillable();

if (LOG.isDebugEnabled())
LOG.debug("<c.onFillable {}", SslConnection.this);
Expand All @@ -378,7 +378,7 @@ public void onFillable()
@Override
public void onFillInterestedFailed(Throwable cause)
{
_decryptedEndPoint.onFillableFail(cause == null ? new IOException() : cause);
_sslEndPoint.onFillableFail(cause == null ? new IOException() : cause);
}

protected SSLEngineResult wrap(SSLEngine sslEngine, ByteBuffer[] input, ByteBuffer output) throws SSLException
Expand All @@ -401,14 +401,14 @@ public String toConnectionString()
b = _decryptedInput == null ? null : _decryptedInput.getByteBuffer();
int di = b == null ? -1 : b.remaining();

Connection connection = _decryptedEndPoint.getConnection();
Connection connection = _sslEndPoint.getConnection();
return String.format("%s@%x{%s,eio=%d/%d,di=%d,fill=%s,flush=%s}~>%s=>%s",
getClass().getSimpleName(),
hashCode(),
_sslEngine.getHandshakeStatus(),
ei, eo, di,
_fillState, _flushState,
_decryptedEndPoint.toEndPointString(),
_sslEndPoint.toEndPointString(),
connection instanceof AbstractConnection ? ((AbstractConnection)connection).toConnectionString() : connection);
}

Expand Down Expand Up @@ -481,12 +481,12 @@ protected boolean networkFlush(ByteBuffer output) throws IOException
return getEndPoint().flush(output);
}

public class DecryptedEndPoint extends AbstractEndPoint implements EndPoint.Wrapper
public class SslEndPoint extends AbstractEndPoint implements EndPoint.Wrapper
{
private final Callback _incompleteWriteCallback = new IncompleteWriteCallback();
private Throwable _failure;

public DecryptedEndPoint()
public SslEndPoint()
{
// Disable idle timeout checking: no scheduler and -1 timeout for this instance.
super(null);
Expand Down Expand Up @@ -824,7 +824,7 @@ public int fill(ByteBuffer buffer) throws IOException
if (_flushState == FlushState.WAIT_FOR_FILL)
{
_flushState = FlushState.IDLE;
getExecutor().execute(() -> _decryptedEndPoint.getWriteFlusher().onFail(failure));
getExecutor().execute(() -> _sslEndPoint.getWriteFlusher().onFail(failure));
}
throw failure;
}
Expand All @@ -835,7 +835,7 @@ public int fill(ByteBuffer buffer) throws IOException
if (_flushState == FlushState.WAIT_FOR_FILL)
{
_flushState = FlushState.IDLE;
getExecutor().execute(() -> _decryptedEndPoint.getWriteFlusher().completeWrite());
getExecutor().execute(() -> _sslEndPoint.getWriteFlusher().completeWrite());
}

if (LOG.isDebugEnabled())
Expand Down Expand Up @@ -1579,9 +1579,9 @@ public void succeeded()
if (interested)
ensureFillInterested();
else if (fillable)
_decryptedEndPoint.getFillInterest().fillable();
_sslEndPoint.getFillInterest().fillable();

_decryptedEndPoint.getWriteFlusher().completeWrite();
_sslEndPoint.getWriteFlusher().completeWrite();
}

@Override
Expand All @@ -1605,15 +1605,15 @@ public void failed(final Throwable x)
getExecutor().execute(() ->
{
if (failFillInterest)
_decryptedEndPoint.getFillInterest().onFail(x);
_decryptedEndPoint.getWriteFlusher().onFail(x);
_sslEndPoint.getFillInterest().onFail(x);
_sslEndPoint.getWriteFlusher().onFail(x);
});
}

@Override
public InvocationType getInvocationType()
{
return _decryptedEndPoint.getWriteFlusher().getCallbackInvocationType();
return _sslEndPoint.getWriteFlusher().getCallbackInvocationType();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -643,8 +643,9 @@ public Connection newConnection(SelectableChannel channel, EndPoint endpoint, Ex
SslConnection sslConnection = new SslConnection(_bufferPool, executor, endpoint, engine);
sslConnection.setRenegotiationAllowed(_sslCtxFactory.isRenegotiationAllowed());
sslConnection.setRenegotiationLimit(_sslCtxFactory.getRenegotiationLimit());
Connection appConnection = _normalScenario.newConnection(channel, sslConnection.getDecryptedEndPoint(), executor, blockAt, writeCount);
sslConnection.getDecryptedEndPoint().setConnection(appConnection);
SslConnection.SslEndPoint sslEndPoint = sslConnection.getSslEndPoint();
Connection appConnection = _normalScenario.newConnection(channel, sslEndPoint, executor, blockAt, writeCount);
sslEndPoint.setConnection(appConnection);
return sslConnection;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ public Connection newConnection(SelectableChannel channel, EndPoint endpoint, Ob
SslConnection sslConnection = new SslConnection(_bufferPool, getExecutor(), endpoint, engine);
sslConnection.setRenegotiationAllowed(_sslCtxFactory.isRenegotiationAllowed());
sslConnection.setRenegotiationLimit(_sslCtxFactory.getRenegotiationLimit());
Connection appConnection = new TestConnection(sslConnection.getDecryptedEndPoint());
sslConnection.getDecryptedEndPoint().setConnection(appConnection);
SslConnection.SslEndPoint sslEndPoint = sslConnection.getSslEndPoint();
Connection appConnection = new TestConnection(sslEndPoint);
sslEndPoint.setConnection(appConnection);
return sslConnection;
}

Expand Down
Loading

0 comments on commit d2fe1ba

Please sign in to comment.