Fix the detection of encrypted data. See #655
This commit is contained in:
parent
0c82f5d2e5
commit
52d64afa2f
@ -55,18 +55,17 @@ public class PortUnificationServerHandler extends FrameDecoder {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
|
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception {
|
||||||
|
// Will use the first 5 bytes to detect a protocol.
|
||||||
// Will use the first two bytes to detect a protocol.
|
if (buffer.readableBytes() < 5) {
|
||||||
if (buffer.readableBytes() < 2) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isSsl(buffer)) {
|
||||||
|
enableSsl(ctx);
|
||||||
|
} else {
|
||||||
final int magic1 = buffer.getUnsignedByte(buffer.readerIndex());
|
final int magic1 = buffer.getUnsignedByte(buffer.readerIndex());
|
||||||
final int magic2 = buffer.getUnsignedByte(buffer.readerIndex() + 1);
|
final int magic2 = buffer.getUnsignedByte(buffer.readerIndex() + 1);
|
||||||
|
if (isGzip(magic1, magic2)) {
|
||||||
if (isSsl(magic1)) {
|
|
||||||
enableSsl(ctx);
|
|
||||||
} else if (isGzip(magic1, magic2)) {
|
|
||||||
enableGzip(ctx);
|
enableGzip(ctx);
|
||||||
} else if (isHttp(magic1, magic2)) {
|
} else if (isHttp(magic1, magic2)) {
|
||||||
switchToHttp(ctx);
|
switchToHttp(ctx);
|
||||||
@ -78,19 +77,15 @@ public class PortUnificationServerHandler extends FrameDecoder {
|
|||||||
ctx.getChannel().close();
|
ctx.getChannel().close();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Forward the current read buffer as is to the new handlers.
|
// Forward the current read buffer as is to the new handlers.
|
||||||
return buffer.readBytes(buffer.readableBytes());
|
return buffer.readBytes(buffer.readableBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSsl(int magic1) {
|
private boolean isSsl(ChannelBuffer buffer) {
|
||||||
if (detectSsl) {
|
if (detectSsl) {
|
||||||
switch (magic1) {
|
return SslHandler.isEncrypted(buffer);
|
||||||
case 20: case 21: case 22: case 23: case 255:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return magic1 >= 128;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user