[#829] Fix a race in SslHandler which could lead to all types of SSLExceptions, including handshake() failures

This commit is contained in:
Norman Maurer 2012-12-17 13:52:02 +01:00
parent 44938973b4
commit e784a773f7

View File

@ -54,7 +54,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;
import static org.jboss.netty.channel.Channels.*;
import static org.jboss.netty.channel.Channels.fireExceptionCaught;
/**
* Adds <a href="http://en.wikipedia.org/wiki/Transport_Layer_Security">SSL
@ -870,11 +869,10 @@ public class SslHandler extends FrameDecoder
channel.getRemoteAddress()));
offered = true;
} else {
synchronized (handshakeLock) {
SSLEngineResult result = null;
try {
synchronized (handshakeLock) {
result = engine.wrap(outAppBuf, outNetBuf);
}
} finally {
if (!outAppBuf.hasRemaining()) {
pendingUnencryptedWrites.remove();
@ -945,6 +943,7 @@ public class SslHandler extends FrameDecoder
}
}
}
}
} catch (SSLException e) {
success = false;
setHandshakeFailure(channel, e);
@ -1125,7 +1124,6 @@ public class SslHandler extends FrameDecoder
synchronized (handshakeLock) {
result = engine.unwrap(inNetBuf, outAppBuf);
}
// notify about the CLOSED state of the SSLEngine. See #137
if (result.getStatus() == Status.CLOSED) {
@ -1174,7 +1172,7 @@ public class SslHandler extends FrameDecoder
wrap(ctx, channel);
}
}
}
outAppBuf.flip();
if (outAppBuf.hasRemaining()) {