Home / Function/ authenticate() — netty Function Reference

authenticate() — netty Function Reference

Architecture documentation for the authenticate() function in Socks5ProxyServer.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  296d9c5e_12d0_8d1b_d9da_27490a48a43b["authenticate()"]
  4ce3d27a_ac4f_d75e_9e95_827c8f6a2894["Socks5ProxyServer"]
  296d9c5e_12d0_8d1b_d9da_27490a48a43b -->|defined in| 4ce3d27a_ac4f_d75e_9e95_827c8f6a2894
  45ff0113_b8f6_78c9_46ff_affe5aeaae55["handleProxyProtocol()"]
  45ff0113_b8f6_78c9_46ff_affe5aeaae55 -->|calls| 296d9c5e_12d0_8d1b_d9da_27490a48a43b
  8d894358_6082_45ac_0214_3983ac1b3788["handleProxyProtocol()"]
  8d894358_6082_45ac_0214_3983ac1b3788 -->|calls| 296d9c5e_12d0_8d1b_d9da_27490a48a43b
  style 296d9c5e_12d0_8d1b_d9da_27490a48a43b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

handler-proxy/src/test/java/io/netty/handler/proxy/Socks5ProxyServer.java lines 97–163

    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;
        }

        if (msg instanceof Socks5PasswordAuthRequest) {
            Socks5PasswordAuthRequest req = (Socks5PasswordAuthRequest) msg;
            if (req.username().equals(username) && req.password().equals(password)) {
                ctx.pipeline().replace(DECODER, DECODER, new Socks5CommandRequestDecoder());
                ctx.write(new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.SUCCESS));
                return true;
            }

            ctx.pipeline().replace(DECODER, DECODER, new Socks5PasswordAuthRequestDecoder());
            ctx.write(new DefaultSocks5PasswordAuthResponse(Socks5PasswordAuthStatus.FAILURE));
            return false;
        }

        if (msg instanceof Socks5PrivateAuthRequest) {
            Socks5PrivateAuthRequest req = (Socks5PrivateAuthRequest) msg;
            if (Arrays.equals(req.privateToken(), privateToken)) {
                ctx.pipeline().replace(DECODER, DECODER, new Socks5CommandRequestDecoder());
                ctx.write(new DefaultSocks5PrivateAuthResponse(Socks5PrivateAuthStatus.SUCCESS));
                return true;
            }

            ctx.pipeline().replace(DECODER, DECODER, new Socks5PrivateAuthRequestDecoder());
            ctx.write(new DefaultSocks5PrivateAuthResponse(Socks5PrivateAuthStatus.FAILURE));
            return false;
        }

        return false;
    }

Domain

Subdomains

Frequently Asked Questions

What does authenticate() do?
authenticate() is a function in the netty codebase, defined in handler-proxy/src/test/java/io/netty/handler/proxy/Socks5ProxyServer.java.
Where is authenticate() defined?
authenticate() is defined in handler-proxy/src/test/java/io/netty/handler/proxy/Socks5ProxyServer.java at line 97.
What calls authenticate()?
authenticate() is called by 2 function(s): handleProxyProtocol, handleProxyProtocol.

Analyze Your Own Codebase

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

Try Supermodel Free