Make sure to notify handshake success even if SSLEngine is closed
Related:e9685ea45a
Motivation: SslHandler.unwrap() does not evaluate the handshake status of SSLEngine.unwrap() when the status of SSLEngine.unwrap() is CLOSED. It is not correct because the status does not reflect the state of the handshake currently in progress, accoding to the API documentation of SSLEngineResult.Status. Also, sslCloseFuture can be notified earlier than handshake notification because we call sslCloseFuture.trySuccess() before evaluating handshake status. Modifications: - Notify sslCloseFuture after the unwrap loop is finished - Add more assertions to SocketSslEchoTest Result: Potentially fix the regression caused by: -e9685ea45a
This commit is contained in:
parent
3cd94822f5
commit
e72b2235fb
@ -930,6 +930,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean wrapLater = false;
|
boolean wrapLater = false;
|
||||||
|
boolean notifyClosure = false;
|
||||||
ByteBuf decodeOut = allocate(ctx, initialOutAppBufCapacity);
|
ByteBuf decodeOut = allocate(ctx, initialOutAppBufCapacity);
|
||||||
try {
|
try {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -941,8 +942,7 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
|||||||
|
|
||||||
if (status == Status.CLOSED) {
|
if (status == Status.CLOSED) {
|
||||||
// notify about the CLOSED state of the SSLEngine. See #137
|
// notify about the CLOSED state of the SSLEngine. See #137
|
||||||
sslCloseFuture.trySuccess(ctx.channel());
|
notifyClosure = true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (handshakeStatus) {
|
switch (handshakeStatus) {
|
||||||
@ -984,6 +984,10 @@ public class SslHandler extends ByteToMessageDecoder implements ChannelOutboundH
|
|||||||
if (wrapLater) {
|
if (wrapLater) {
|
||||||
wrap(ctx, true);
|
wrap(ctx, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (notifyClosure) {
|
||||||
|
sslCloseFuture.trySuccess(ctx.channel());
|
||||||
|
}
|
||||||
} catch (SSLException e) {
|
} catch (SSLException e) {
|
||||||
setHandshakeFailure(e);
|
setHandshakeFailure(e);
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -315,8 +315,7 @@ public class SocketSslEchoTest extends AbstractSocketTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void channelActive(ChannelHandlerContext ctx)
|
public void channelActive(ChannelHandlerContext ctx) throws Exception {
|
||||||
throws Exception {
|
|
||||||
channel = ctx.channel();
|
channel = ctx.channel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,7 +344,10 @@ public class SocketSslEchoTest extends AbstractSocketTest {
|
|||||||
counter > data.length / 2 && renegoFuture == null) {
|
counter > data.length / 2 && renegoFuture == null) {
|
||||||
|
|
||||||
SslHandler sslHandler = ctx.pipeline().get(SslHandler.class);
|
SslHandler sslHandler = ctx.pipeline().get(SslHandler.class);
|
||||||
|
|
||||||
Future<Channel> hf = sslHandler.handshakeFuture();
|
Future<Channel> hf = sslHandler.handshakeFuture();
|
||||||
|
assertThat(hf.isDone(), is(true));
|
||||||
|
|
||||||
renegoFuture = sslHandler.renegotiate();
|
renegoFuture = sslHandler.renegotiate();
|
||||||
assertThat(renegoFuture, is(not(sameInstance(hf))));
|
assertThat(renegoFuture, is(not(sameInstance(hf))));
|
||||||
assertThat(renegoFuture, is(sameInstance(sslHandler.handshakeFuture())));
|
assertThat(renegoFuture, is(sameInstance(sslHandler.handshakeFuture())));
|
||||||
@ -366,13 +368,13 @@ public class SocketSslEchoTest extends AbstractSocketTest {
|
|||||||
@Override
|
@Override
|
||||||
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
|
||||||
if (evt instanceof SslHandshakeCompletionEvent) {
|
if (evt instanceof SslHandshakeCompletionEvent) {
|
||||||
|
assertSame(SslHandshakeCompletionEvent.SUCCESS, evt);
|
||||||
negoCounter ++;
|
negoCounter ++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void exceptionCaught(ChannelHandlerContext ctx,
|
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||||
Throwable cause) throws Exception {
|
|
||||||
if (logger.isWarnEnabled()) {
|
if (logger.isWarnEnabled()) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Unexpected exception from the " +
|
"Unexpected exception from the " +
|
||||||
|
Loading…
Reference in New Issue
Block a user