fix socks5-auth subnegotiation version handling
Conflicts: codec-socks/src/main/java/io/netty/codec/socks/SocksAuthRequestDecoder.java
This commit is contained in:
parent
717bde05e2
commit
32f2122e64
@ -28,6 +28,7 @@ import java.nio.charset.CharsetEncoder;
|
|||||||
*/
|
*/
|
||||||
public final class SocksAuthRequest extends SocksRequest {
|
public final class SocksAuthRequest extends SocksRequest {
|
||||||
private static final CharsetEncoder asciiEncoder = CharsetUtil.getEncoder(CharsetUtil.US_ASCII);
|
private static final CharsetEncoder asciiEncoder = CharsetUtil.getEncoder(CharsetUtil.US_ASCII);
|
||||||
|
private static final SubnegotiationVersion SUBNEGOTIATION_VERSION = SubnegotiationVersion.AUTH_PASSWORD;
|
||||||
private final String username;
|
private final String username;
|
||||||
private final String password;
|
private final String password;
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ public final class SocksAuthRequest extends SocksRequest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
||||||
byteBuf.writeByte(getProtocolVersion().getByteValue());
|
byteBuf.writeByte(SUBNEGOTIATION_VERSION.getByteValue());
|
||||||
byteBuf.writeByte(username.length());
|
byteBuf.writeByte(username.length());
|
||||||
byteBuf.writeBytes(username.getBytes(CharsetUtil.US_ASCII));
|
byteBuf.writeBytes(username.getBytes(CharsetUtil.US_ASCII));
|
||||||
byteBuf.writeByte(password.length());
|
byteBuf.writeByte(password.length());
|
||||||
|
@ -31,7 +31,7 @@ public class SocksAuthRequestDecoder extends ReplayingDecoder<SocksRequest, Sock
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SocksMessage.ProtocolVersion version;
|
private SocksMessage.SubnegotiationVersion version;
|
||||||
private int fieldLength;
|
private int fieldLength;
|
||||||
private String username;
|
private String username;
|
||||||
private String password;
|
private String password;
|
||||||
@ -45,8 +45,8 @@ public class SocksAuthRequestDecoder extends ReplayingDecoder<SocksRequest, Sock
|
|||||||
public SocksRequest decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
|
public SocksRequest decode(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
|
||||||
switch (state()) {
|
switch (state()) {
|
||||||
case CHECK_PROTOCOL_VERSION: {
|
case CHECK_PROTOCOL_VERSION: {
|
||||||
version = SocksMessage.ProtocolVersion.fromByte(byteBuf.readByte());
|
version = SocksMessage.SubnegotiationVersion.fromByte(byteBuf.readByte());
|
||||||
if (version != SocksMessage.ProtocolVersion.SOCKS5) {
|
if (version != SocksMessage.SubnegotiationVersion.AUTH_PASSWORD) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
checkpoint(State.READ_USERNAME);
|
checkpoint(State.READ_USERNAME);
|
||||||
|
@ -24,7 +24,7 @@ import io.netty.buffer.ByteBuf;
|
|||||||
* @see SocksAuthResponseDecoder
|
* @see SocksAuthResponseDecoder
|
||||||
*/
|
*/
|
||||||
public final class SocksAuthResponse extends SocksResponse {
|
public final class SocksAuthResponse extends SocksResponse {
|
||||||
|
private static final SubnegotiationVersion SUBNEGOTIATION_VERSION = SubnegotiationVersion.AUTH_PASSWORD;
|
||||||
private final AuthStatus authStatus;
|
private final AuthStatus authStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,7 +52,7 @@ public final class SocksAuthResponse extends SocksResponse {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
||||||
byteBuf.writeByte(getProtocolVersion().getByteValue());
|
byteBuf.writeByte(SUBNEGOTIATION_VERSION.getByteValue());
|
||||||
byteBuf.writeByte(authStatus.getByteValue());
|
byteBuf.writeByte(authStatus.getByteValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public class SocksAuthResponseDecoder extends ReplayingDecoder<SocksResponse, So
|
|||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SocksMessage.ProtocolVersion version;
|
private SocksMessage.SubnegotiationVersion version;
|
||||||
private SocksMessage.AuthStatus authStatus;
|
private SocksMessage.AuthStatus authStatus;
|
||||||
private SocksResponse msg = SocksCommonUtils.UNKNOWN_SOCKS_RESPONSE;
|
private SocksResponse msg = SocksCommonUtils.UNKNOWN_SOCKS_RESPONSE;
|
||||||
|
|
||||||
@ -42,8 +42,8 @@ public class SocksAuthResponseDecoder extends ReplayingDecoder<SocksResponse, So
|
|||||||
public SocksResponse decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception {
|
public SocksResponse decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception {
|
||||||
switch (state()) {
|
switch (state()) {
|
||||||
case CHECK_PROTOCOL_VERSION: {
|
case CHECK_PROTOCOL_VERSION: {
|
||||||
version = SocksMessage.ProtocolVersion.fromByte(byteBuf.readByte());
|
version = SocksMessage.SubnegotiationVersion.fromByte(byteBuf.readByte());
|
||||||
if (version != SocksMessage.ProtocolVersion.SOCKS5) {
|
if (version != SocksMessage.SubnegotiationVersion.AUTH_PASSWORD) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
checkpoint(State.READ_AUTH_RESPONSE);
|
checkpoint(State.READ_AUTH_RESPONSE);
|
||||||
|
@ -210,6 +210,30 @@ public abstract class SocksMessage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum SubnegotiationVersion {
|
||||||
|
AUTH_PASSWORD((byte) 0x01),
|
||||||
|
UNKNOWN((byte) 0xff);
|
||||||
|
|
||||||
|
private final byte b;
|
||||||
|
|
||||||
|
private SubnegotiationVersion(byte b) {
|
||||||
|
this.b = b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SubnegotiationVersion fromByte(byte b) {
|
||||||
|
for (SubnegotiationVersion code : values()) {
|
||||||
|
if (code.b == b) {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte getByteValue() {
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link ProtocolVersion} of this {@link SocksMessage}
|
* Returns the {@link ProtocolVersion} of this {@link SocksMessage}
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user