public static Socks5CommandType valueOf(byte b) { switch (b) { case 0x01: return CONNECT; case 0x02: return BIND; case 0x03: return UDP_ASSOCIATE; } return new Socks5CommandType(b); }
public static Socks5PasswordAuthStatus valueOf(byte b) { switch (b) { case 0x00: return SUCCESS; case (byte) 0xFF: return FAILURE; } return new Socks5PasswordAuthStatus(b); }
public static Socks5AddressType valueOf(byte b) { switch (b) { case 0x01: return IPv4; case 0x03: return DOMAIN; case 0x04: return IPv6; } return new Socks5AddressType(b); }
private void encodeCommandRequest(Socks5CommandRequest msg, ByteBuf out) throws Exception { out.writeByte(msg.version().byteValue()); out.writeByte(msg.type().byteValue()); out.writeByte(0x00); final Socks5AddressType dstAddrType = msg.dstAddrType(); out.writeByte(dstAddrType.byteValue()); addressEncoder.encodeAddress(dstAddrType, msg.dstAddr(), out); out.writeShort(msg.dstPort()); } }
private void handleCommandRequest(ChannelHandlerContext ctx, final Socks5CommandRequest commandRequest) { if (commandRequest.type().equals(Socks5CommandType.CONNECT)) { forwardConnection(ctx, new Socks5ConnectHandler(server, mockServerLogger, commandRequest.dstAddr(), commandRequest.dstPort()), commandRequest.dstAddr(), commandRequest.dstPort()); ctx.fireChannelRead(commandRequest); } else { ctx.writeAndFlush(new DefaultSocks5CommandResponse(Socks5CommandStatus.COMMAND_UNSUPPORTED, Socks5AddressType.DOMAIN, "", 0)).addListener(ChannelFutureListener.CLOSE); } } }
private void encodeCommandResponse(Socks5CommandResponse msg, ByteBuf out) throws Exception { out.writeByte(msg.version().byteValue()); out.writeByte(msg.status().byteValue()); out.writeByte(0x00); final Socks5AddressType bndAddrType = msg.bndAddrType(); out.writeByte(bndAddrType.byteValue()); addressEncoder.encodeAddress(bndAddrType, msg.bndAddr(), out); out.writeShort(msg.bndPort()); } }
private void handlePasswordAuthRequest(ChannelHandlerContext ctx, Socks5PasswordAuthRequest passwordAuthRequest) { String username = ConfigurationProperties.proxyAuthenticationUsername(); String password = ConfigurationProperties.proxyAuthenticationPassword(); // we need the null-check again here, in case the properties got unset between init and auth request if (!username.isEmpty() && !password.isEmpty() && username.equals(passwordAuthRequest.username()) && password.equals(passwordAuthRequest.password())) { ctx.pipeline().replace(Socks5PasswordAuthRequestDecoder.class, null, new Socks5CommandRequestDecoder()); ctx.write(new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.SUCCESS)); } else { ctx.writeAndFlush(new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.FAILURE)).addListener(ChannelFutureListener.CLOSE); } }
private void fail(List<Object> out, Exception cause) { if (!(cause instanceof DecoderException)) { cause = new DecoderException(cause); } checkpoint(State.FAILURE); Socks5Message m = new DefaultSocks5CommandResponse( Socks5CommandStatus.FAILURE, Socks5AddressType.IPv4, null, 0); m.setDecoderResult(DecoderResult.failure(cause)); out.add(m); } }
private void fail(List<Object> out, Exception cause) { if (!(cause instanceof DecoderException)) { cause = new DecoderException(cause); } checkpoint(State.FAILURE); Socks5Message m = new DefaultSocks5InitialResponse(Socks5AuthMethod.UNACCEPTED); m.setDecoderResult(DecoderResult.failure(cause)); out.add(m); } }
private void answerInitialRequest(ChannelHandlerContext ctx, Socks5InitialRequest initialRequest, Socks5AuthMethod requiredAuthMethod, ChannelHandler nextRequestDecoder) { ctx.pipeline().remove(Socks5InitialRequestDecoder.class); for (Socks5AuthMethod authMethod : initialRequest.authMethods()) { if (requiredAuthMethod.equals(authMethod)) { ctx.pipeline().addFirst(nextRequestDecoder); ctx.write(new DefaultSocks5InitialResponse(requiredAuthMethod)); return; } } ctx.write(new DefaultSocks5InitialResponse(Socks5AuthMethod.UNACCEPTED)); }
private static void encodeAuthMethodResponse(Socks5InitialResponse msg, ByteBuf out) { out.writeByte(msg.version().byteValue()); out.writeByte(msg.authMethod().byteValue()); }
private void fail(List<Object> out, Exception cause) { if (!(cause instanceof DecoderException)) { cause = new DecoderException(cause); } checkpoint(State.FAILURE); Socks5Message m = new DefaultSocks5CommandRequest( Socks5CommandType.CONNECT, Socks5AddressType.IPv4, "0.0.0.0", 1); m.setDecoderResult(DecoderResult.failure(cause)); out.add(m); } }
private void fail(List<Object> out, Exception cause) { if (!(cause instanceof DecoderException)) { cause = new DecoderException(cause); } checkpoint(State.FAILURE); Socks5Message m = new DefaultSocks5PasswordAuthRequest("", ""); m.setDecoderResult(DecoderResult.failure(cause)); out.add(m); } }
private void fail(List<Object> out, Exception cause) { if (!(cause instanceof DecoderException)) { cause = new DecoderException(cause); } checkpoint(State.FAILURE); Socks5Message m = new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.FAILURE); m.setDecoderResult(DecoderResult.failure(cause)); out.add(m); } }
private void fail(List<Object> out, Exception cause) { if (!(cause instanceof DecoderException)) { cause = new DecoderException(cause); } checkpoint(State.FAILURE); Socks5Message m = new DefaultSocks5InitialRequest(Socks5AuthMethod.NO_AUTH); m.setDecoderResult(DecoderResult.failure(cause)); out.add(m); } }
protected Object failureResponse(Object request) { return new DefaultSocks5CommandResponse(Socks5CommandStatus.FAILURE, Socks5AddressType.DOMAIN, "", 0); } }
public static Socks5AuthMethod valueOf(byte b) { switch (b) { case 0x00: return NO_AUTH; case 0x01: return GSSAPI; case 0x02: return PASSWORD; case (byte) 0xFF: return UNACCEPTED; } return new Socks5AuthMethod(b); }
public static Socks5CommandStatus valueOf(byte b) { switch (b) { case 0x00: return SUCCESS; case 0x01: return FAILURE; case 0x02: return FORBIDDEN; case 0x03: return NETWORK_UNREACHABLE; case 0x04: return HOST_UNREACHABLE; case 0x05: return CONNECTION_REFUSED; case 0x06: return TTL_EXPIRED; case 0x07: return COMMAND_UNSUPPORTED; case 0x08: return ADDRESS_UNSUPPORTED; } return new Socks5CommandStatus(b); }
protected Object successResponse(Object request) { return new DefaultSocks5CommandResponse(Socks5CommandStatus.SUCCESS, Socks5AddressType.DOMAIN, "", 0); }