Package io.netty.handler.codec.socksx.v5

Examples of io.netty.handler.codec.socksx.v5.Socks5InitRequestTest


        return authScheme;
    }

    private void sendConnectCommand(ChannelHandlerContext ctx) throws Exception {
        InetSocketAddress raddr = destinationAddress();
        Socks5AddressType addrType;
        String rhost;
        if (raddr.isUnresolved()) {
            addrType = Socks5AddressType.DOMAIN;
            rhost = raddr.getHostString();
        } else {
View Full Code Here


            ctx.pipeline().addBefore("encoder", "decoder", new Socks5AuthRequestDecoder());
            ctx.write(new Socks5InitResponse(Socks5AuthScheme.AUTH_PASSWORD));
            return false;
        }

        Socks5AuthRequest req = (Socks5AuthRequest) msg;
        if (req.username().equals(username) && req.password().equals(password)) {
            ctx.pipeline().addBefore("encoder", "decoder", new Socks5CmdRequestDecoder());
            ctx.write(new Socks5AuthResponse(Socks5AuthStatus.SUCCESS));
            return true;
        }
View Full Code Here

                break;
            case AUTH_PASSWORD:
                // In case of password authentication, send an authentication request.
                ctx.pipeline().addBefore(encoderName, decoderName, new Socks5AuthResponseDecoder());
                sendToProxyServer(
                        new Socks5AuthRequest(username != null? username : "", password != null? password : ""));
                break;
            default:
                // Should never reach here.
                throw new Error();
            }
View Full Code Here

            ctx.write(new Socks5InitResponse(Socks5AuthScheme.NO_AUTH));
            return true;
        }

        if (msg instanceof Socks5InitRequest) {
            ctx.pipeline().addBefore("encoder", "decoder", new Socks5AuthRequestDecoder());
            ctx.write(new Socks5InitResponse(Socks5AuthScheme.AUTH_PASSWORD));
            return false;
        }

        Socks5AuthRequest req = (Socks5AuthRequest) msg;
        if (req.username().equals(username) && req.password().equals(password)) {
            ctx.pipeline().addBefore("encoder", "decoder", new Socks5CmdRequestDecoder());
            ctx.write(new Socks5AuthResponse(Socks5AuthStatus.SUCCESS));
            return true;
        }

        ctx.pipeline().addBefore("encoder", "decoder", new Socks5AuthRequestDecoder());
        ctx.write(new Socks5AuthResponse(Socks5AuthStatus.FAILURE));
        return false;
    }
View Full Code Here

                        ctx.write(new Socks5InitResponse(Socks5AuthScheme.NO_AUTH));
                        break;
                    }
                    case AUTH:
                        ctx.pipeline().addFirst(new Socks5CmdRequestDecoder());
                        ctx.write(new Socks5AuthResponse(Socks5AuthStatus.SUCCESS));
                        break;
                    case CMD:
                        Socks5CmdRequest socks5CmdRequest = (Socks5CmdRequest) socksRequest;
                        if (socks5CmdRequest.cmdType() == Socks5CmdType.CONNECT) {
                            ctx.pipeline().addLast(new SocksServerConnectHandler());
View Full Code Here

        }

        Socks5AuthRequest req = (Socks5AuthRequest) msg;
        if (req.username().equals(username) && req.password().equals(password)) {
            ctx.pipeline().addBefore("encoder", "decoder", new Socks5CmdRequestDecoder());
            ctx.write(new Socks5AuthResponse(Socks5AuthStatus.SUCCESS));
            return true;
        }

        ctx.pipeline().addBefore("encoder", "decoder", new Socks5AuthRequestDecoder());
        ctx.write(new Socks5AuthResponse(Socks5AuthStatus.FAILURE));
        return false;
    }
View Full Code Here

            return false;
        }

        if (response instanceof Socks5AuthResponse) {
            // Received an authentication response from the server.
            Socks5AuthResponse res = (Socks5AuthResponse) response;
            if (res.authStatus() != Socks5AuthStatus.SUCCESS) {
                throw new ProxyConnectException(exceptionMessage("authStatus: " + res.authStatus()));
            }

            sendConnectCommand(ctx);
            return false;
        }

        // This should be the last message from the server.
        Socks5CmdResponse res = (Socks5CmdResponse) response;
        if (res.cmdStatus() != Socks5CmdStatus.SUCCESS) {
            throw new ProxyConnectException(exceptionMessage("cmdStatus: " + res.cmdStatus()));
        }

        return true;
    }
View Full Code Here

            case NO_AUTH:
                sendConnectCommand(ctx);
                break;
            case AUTH_PASSWORD:
                // In case of password authentication, send an authentication request.
                ctx.pipeline().addBefore(encoderName, decoderName, new Socks5AuthResponseDecoder());
                sendToProxyServer(
                        new Socks5AuthRequest(username != null? username : "", password != null? password : ""));
                break;
            default:
                // Should never reach here.
View Full Code Here

    @Override
    protected boolean handleResponse(ChannelHandlerContext ctx, Object response) throws Exception {
        if (response instanceof Socks5InitResponse) {
            Socks5InitResponse res = (Socks5InitResponse) response;
            Socks5AuthScheme authScheme = socksAuthScheme();

            if (res.authScheme() != Socks5AuthScheme.NO_AUTH && authScheme != res.authScheme()) {
                // Server did not allow unauthenticated access nor accept the requested authentication scheme.
                throw new ProxyConnectException(exceptionMessage("unexpected authScheme: " + res.authScheme()));
            }
View Full Code Here

        return true;
    }

    private Socks5AuthScheme socksAuthScheme() {
        Socks5AuthScheme authScheme;
        if (username == null && password == null) {
            authScheme = Socks5AuthScheme.NO_AUTH;
        } else {
            authScheme = Socks5AuthScheme.AUTH_PASSWORD;
        }
View Full Code Here

TOP

Related Classes of io.netty.handler.codec.socksx.v5.Socks5InitRequestTest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.