Remove unnecessary code from SslHandler
- Remove CloseNotifyListener which was used only to reduce the noisy logging. - Instead, simply do a string match. - Fixes #1608
This commit is contained in:
parent
faf8b76b5a
commit
6791984146
@ -181,7 +181,6 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
|||||||
|
|
||||||
private final LazyChannelPromise handshakePromise = new LazyChannelPromise();
|
private final LazyChannelPromise handshakePromise = new LazyChannelPromise();
|
||||||
private final LazyChannelPromise sslCloseFuture = new LazyChannelPromise();
|
private final LazyChannelPromise sslCloseFuture = new LazyChannelPromise();
|
||||||
private final CloseNotifyListener closeNotifyWriteListener = new CloseNotifyListener();
|
|
||||||
private final Deque<PendingWrite> pendingUnencryptedWrites = new ArrayDeque<PendingWrite>();
|
private final Deque<PendingWrite> pendingUnencryptedWrites = new ArrayDeque<PendingWrite>();
|
||||||
|
|
||||||
private int packetLength;
|
private int packetLength;
|
||||||
@ -318,7 +317,6 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
engine.closeOutbound();
|
engine.closeOutbound();
|
||||||
future.addListener(closeNotifyWriteListener);
|
|
||||||
try {
|
try {
|
||||||
write(ctx, Unpooled.EMPTY_BUFFER, future);
|
write(ctx, Unpooled.EMPTY_BUFFER, future);
|
||||||
flush(ctx);
|
flush(ctx);
|
||||||
@ -394,8 +392,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
|
public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
|
||||||
throws Exception {
|
|
||||||
pendingUnencryptedWrites.add(new PendingWrite((ByteBuf) msg, promise));
|
pendingUnencryptedWrites.add(new PendingWrite((ByteBuf) msg, promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -807,7 +804,8 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
|||||||
RecyclableArrayList out = RecyclableArrayList.newInstance();
|
RecyclableArrayList out = RecyclableArrayList.newInstance();
|
||||||
try {
|
try {
|
||||||
unwrap(ctx, Unpooled.EMPTY_BUFFER.nioBuffer(), out);
|
unwrap(ctx, Unpooled.EMPTY_BUFFER.nioBuffer(), out);
|
||||||
for (int i = 0; i < out.size(); i++) {
|
final int size = out.size();
|
||||||
|
for (int i = 0; i < size; i++) {
|
||||||
ctx.fireChannelRead(out.get(i));
|
ctx.fireChannelRead(out.get(i));
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@ -918,7 +916,6 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
|||||||
// is managing.
|
// is managing.
|
||||||
engine.closeOutbound();
|
engine.closeOutbound();
|
||||||
|
|
||||||
final boolean disconnected = cause instanceof ClosedChannelException;
|
|
||||||
try {
|
try {
|
||||||
engine.closeInbound();
|
engine.closeInbound();
|
||||||
} catch (SSLException e) {
|
} catch (SSLException e) {
|
||||||
@ -926,13 +923,9 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
|||||||
// this all the time.
|
// this all the time.
|
||||||
//
|
//
|
||||||
// See https://github.com/netty/netty/issues/1340
|
// See https://github.com/netty/netty/issues/1340
|
||||||
if (!disconnected) {
|
String msg = e.getMessage();
|
||||||
logger.debug("SSLEngine.closeInbound() raised an exception after a handshake failure.", e);
|
if (msg == null || !msg.contains("possible truncation attack")) {
|
||||||
} else if (!closeNotifyWriteListener.done) {
|
logger.debug("SSLEngine.closeInbound() raised an exception.", e);
|
||||||
logger.debug("SSLEngine.closeInbound() raised an exception due to closed connection.", e);
|
|
||||||
} else {
|
|
||||||
// cause == null && sentCloseNotify
|
|
||||||
// closeInbound() will raise an exception with bogus truncation attack warning.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
notifyHandshakeFailure(cause);
|
notifyHandshakeFailure(cause);
|
||||||
@ -965,7 +958,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
|||||||
|
|
||||||
engine.closeOutbound();
|
engine.closeOutbound();
|
||||||
|
|
||||||
ChannelPromise closeNotifyFuture = ctx.newPromise().addListener(closeNotifyWriteListener);
|
ChannelPromise closeNotifyFuture = ctx.newPromise();
|
||||||
write(ctx, Unpooled.EMPTY_BUFFER, closeNotifyFuture);
|
write(ctx, Unpooled.EMPTY_BUFFER, closeNotifyFuture);
|
||||||
flush(ctx);
|
flush(ctx);
|
||||||
safeClose(ctx, closeNotifyFuture, promise);
|
safeClose(ctx, closeNotifyFuture, promise);
|
||||||
@ -1077,20 +1070,6 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final class CloseNotifyListener implements ChannelFutureListener {
|
|
||||||
boolean done;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void operationComplete(ChannelFuture future) throws Exception {
|
|
||||||
if (future.isSuccess()) {
|
|
||||||
if (done) {
|
|
||||||
throw new IllegalStateException("notified twice");
|
|
||||||
}
|
|
||||||
done = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class LazyChannelPromise extends DefaultPromise<Channel> {
|
private final class LazyChannelPromise extends DefaultPromise<Channel> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user