Only parse the packet length once per encrypted packet. See #658
This commit is contained in:
parent
52d64afa2f
commit
b75ab6171c
@ -208,6 +208,8 @@ public class SslHandler extends FrameDecoder
|
|||||||
|
|
||||||
private boolean closeOnSSLException;
|
private boolean closeOnSSLException;
|
||||||
|
|
||||||
|
private int packetLength = Integer.MIN_VALUE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance.
|
* Creates a new instance.
|
||||||
*
|
*
|
||||||
@ -758,10 +760,11 @@ public class SslHandler extends FrameDecoder
|
|||||||
protected Object decode(
|
protected Object decode(
|
||||||
final ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
|
final ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
|
||||||
|
|
||||||
|
// Check if the packet length was parsed yet, if so we can skip the parsing
|
||||||
|
if (packetLength == Integer.MIN_VALUE) {
|
||||||
if (buffer.readableBytes() < 5) {
|
if (buffer.readableBytes() < 5) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int packetLength = getEncryptedPacketLength(buffer);
|
int packetLength = getEncryptedPacketLength(buffer);
|
||||||
|
|
||||||
if (packetLength == -1) {
|
if (packetLength == -1) {
|
||||||
@ -769,6 +772,7 @@ public class SslHandler extends FrameDecoder
|
|||||||
NotSslRecordException e = new NotSslRecordException(
|
NotSslRecordException e = new NotSslRecordException(
|
||||||
"not an SSL/TLS record: " + ChannelBuffers.hexDump(buffer));
|
"not an SSL/TLS record: " + ChannelBuffers.hexDump(buffer));
|
||||||
buffer.skipBytes(buffer.readableBytes());
|
buffer.skipBytes(buffer.readableBytes());
|
||||||
|
|
||||||
if (closeOnSSLException) {
|
if (closeOnSSLException) {
|
||||||
// first trigger the exception and then close the channel
|
// first trigger the exception and then close the channel
|
||||||
fireExceptionCaught(ctx, e);
|
fireExceptionCaught(ctx, e);
|
||||||
@ -783,6 +787,8 @@ public class SslHandler extends FrameDecoder
|
|||||||
}
|
}
|
||||||
|
|
||||||
assert packetLength > 0;
|
assert packetLength > 0;
|
||||||
|
this.packetLength = packetLength;
|
||||||
|
}
|
||||||
|
|
||||||
if (buffer.readableBytes() < packetLength) {
|
if (buffer.readableBytes() < packetLength) {
|
||||||
return null;
|
return null;
|
||||||
@ -804,7 +810,13 @@ public class SslHandler extends FrameDecoder
|
|||||||
// before calling the user code.
|
// before calling the user code.
|
||||||
final int packetOffset = buffer.readerIndex();
|
final int packetOffset = buffer.readerIndex();
|
||||||
buffer.skipBytes(packetLength);
|
buffer.skipBytes(packetLength);
|
||||||
|
try {
|
||||||
return unwrap(ctx, channel, buffer, packetOffset, packetLength);
|
return unwrap(ctx, channel, buffer, packetOffset, packetLength);
|
||||||
|
} finally {
|
||||||
|
// reset the packet length so it will be parsed again on the next call
|
||||||
|
packetLength = Integer.MIN_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user