Home / Class/ Socks5ProxyServer Class — netty Architecture

Socks5ProxyServer Class — netty Architecture

Architecture documentation for the Socks5ProxyServer class in Socks5ProxyServer.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  4ce3d27a_ac4f_d75e_9e95_827c8f6a2894["Socks5ProxyServer"]
  2b2df286_a481_d3ed_6921_e4b21fd7f37c["Socks5ProxyServer.java"]
  4ce3d27a_ac4f_d75e_9e95_827c8f6a2894 -->|defined in| 2b2df286_a481_d3ed_6921_e4b21fd7f37c
  3393870a_033e_96cf_abe3_627cf0ac5a95["Socks5ProxyServer()"]
  4ce3d27a_ac4f_d75e_9e95_827c8f6a2894 -->|method| 3393870a_033e_96cf_abe3_627cf0ac5a95
  357dc209_699d_29da_568a_14b35df3ca19["configure()"]
  4ce3d27a_ac4f_d75e_9e95_827c8f6a2894 -->|method| 357dc209_699d_29da_568a_14b35df3ca19
  296d9c5e_12d0_8d1b_d9da_27490a48a43b["authenticate()"]
  4ce3d27a_ac4f_d75e_9e95_827c8f6a2894 -->|method| 296d9c5e_12d0_8d1b_d9da_27490a48a43b

Relationship Graph

Source Code

handler-proxy/src/test/java/io/netty/handler/proxy/Socks5ProxyServer.java lines 53–236

final class Socks5ProxyServer extends ProxyServer {

    private static final String ENCODER = "encoder";
    private static final String DECODER = "decoder";
    private byte privateAuthMethod;
    private byte[] privateToken;

    Socks5ProxyServer(boolean useSsl, TestMode testMode, InetSocketAddress destination) {
        super(useSsl, testMode, destination);
    }

    Socks5ProxyServer(
            boolean useSsl, TestMode testMode, InetSocketAddress destination, String username, String password) {
        super(useSsl, testMode, destination, username, password);
    }

    Socks5ProxyServer(
            boolean useSsl, TestMode testMode, InetSocketAddress destination, byte privateAuthMethod,
            byte[] privateToken) {
        super(useSsl, testMode, destination);
        this.privateAuthMethod = privateAuthMethod;
        this.privateToken = privateToken;
    }

    @Override
    protected void configure(SocketChannel ch) throws Exception {
        ChannelPipeline p = ch.pipeline();
        switch (testMode) {
        case INTERMEDIARY:
            p.addLast(DECODER, new Socks5InitialRequestDecoder());
            p.addLast(ENCODER, Socks5ServerEncoder.DEFAULT);
            p.addLast(new Socks5IntermediaryHandler());
            break;
        case TERMINAL:
            p.addLast(DECODER, new Socks5InitialRequestDecoder());
            p.addLast(ENCODER, Socks5ServerEncoder.DEFAULT);
            p.addLast(new Socks5TerminalHandler());
            break;
        case UNRESPONSIVE:
            p.addLast(UnresponsiveHandler.INSTANCE);
            break;
        }
    }

    boolean authenticate(ChannelHandlerContext ctx, Object msg) {
        if (username == null && privateToken == null) {
            ctx.pipeline().replace(DECODER, DECODER, new Socks5CommandRequestDecoder());
            ctx.write(new DefaultSocks5InitialResponse(Socks5AuthMethod.NO_AUTH));
            return true;
        }

        if (msg instanceof Socks5InitialRequest) {
            Socks5InitialRequest initialRequest = (Socks5InitialRequest) msg;

            if (privateToken != null) {
                // Check if the client requested our private auth method
                boolean hasPrivateMethod = false;
                for (Socks5AuthMethod method : initialRequest.authMethods()) {
                    if (method.byteValue() == privateAuthMethod) {
                        hasPrivateMethod = true;
                        break;
                    }
                }

                if (hasPrivateMethod) {
                    ctx.pipeline().replace(DECODER, DECODER, new Socks5PrivateAuthRequestDecoder());
                    ctx.write(new DefaultSocks5InitialResponse(Socks5AuthMethod.valueOf(privateAuthMethod)));
                    return false;
                }
            }

            if (username != null) {
                ctx.pipeline().replace(DECODER, DECODER, new Socks5PasswordAuthRequestDecoder());
                ctx.write(new DefaultSocks5InitialResponse(Socks5AuthMethod.PASSWORD));
                return false;
            }

            // Neither private nor password auth was matched
            ctx.pipeline().replace(DECODER, DECODER, new Socks5PasswordAuthRequestDecoder());
            ctx.write(new DefaultSocks5InitialResponse(Socks5AuthMethod.PASSWORD));
            return false;

Frequently Asked Questions

What is the Socks5ProxyServer class?
Socks5ProxyServer is a class in the netty codebase, defined in handler-proxy/src/test/java/io/netty/handler/proxy/Socks5ProxyServer.java.
Where is Socks5ProxyServer defined?
Socks5ProxyServer is defined in handler-proxy/src/test/java/io/netty/handler/proxy/Socks5ProxyServer.java at line 53.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free