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

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


                    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());
                            ctx.pipeline().remove(this);
                            ctx.fireChannelRead(socksRequest);
                        } else {
                            ctx.close();
View Full Code Here


                        SocksServerUtils.closeOnFlush(ctx.channel());
                    }
                }
            });
        } else if (message instanceof Socks5CmdRequest) {
            final Socks5CmdRequest request = (Socks5CmdRequest) message;
            Promise<Channel> promise = ctx.executor().newPromise();
            promise.addListener(
                    new GenericFutureListener<Future<Channel>>() {
                        @Override
                        public void operationComplete(final Future<Channel> future) throws Exception {
                            final Channel outboundChannel = future.getNow();
                            if (future.isSuccess()) {
                                ctx.channel().writeAndFlush(
                                        new Socks5CmdResponse(Socks5CmdStatus.SUCCESS, request.addressType())
                                ).addListener(new ChannelFutureListener() {
                                            @Override
                                            public void operationComplete(ChannelFuture channelFuture) {
                                                ctx.pipeline().remove(SocksServerConnectHandler.this);
                                                outboundChannel.pipeline().addLast(new RelayHandler(ctx.channel()));
                                                ctx.pipeline().addLast(new RelayHandler(outboundChannel));
                                            }
                                        }
                                );
                            } else {
                                ctx.channel().writeAndFlush(
                                        new Socks5CmdResponse(Socks5CmdStatus.FAILURE, request.addressType()));
                                SocksServerUtils.closeOnFlush(ctx.channel());
                            }
                        }
                    });

            final Channel inboundChannel = ctx.channel();
            b.group(inboundChannel.eventLoop())
                    .channel(NioSocketChannel.class)
                    .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000)
                    .option(ChannelOption.SO_KEEPALIVE, true)
                    .handler(new DirectClientHandler(promise));

            b.connect(request.host(), request.port()).addListener(new ChannelFutureListener() {
                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    if (future.isSuccess()) {
                        // Connection established use handler provided results
                    } else {
                        // Close the connection if the connection attempt has failed.
                        ctx.channel().writeAndFlush(
                                new Socks5CmdResponse(Socks5CmdStatus.FAILURE, request.addressType()));
                        SocksServerUtils.closeOnFlush(ctx.channel());
                    }
                }
            });
        } else {
View Full Code Here

            if (!authenticated) {
                authenticated = authenticate(ctx, msg);
                return false;
            }

            Socks5CmdRequest req = (Socks5CmdRequest) msg;
            assertThat(req.cmdType(), is(Socks5CmdType.CONNECT));

            Socks5CmdResponse res;
            res = new Socks5CmdResponse(Socks5CmdStatus.SUCCESS, Socks5AddressType.IPv4);
            intermediaryDestination = new InetSocketAddress(req.host(), req.port());

            ctx.write(res);
            ctx.pipeline().remove(Socks5MessageEncoder.class);

            return true;
View Full Code Here

            if (!authenticated) {
                authenticated = authenticate(ctx, msg);
                return false;
            }

            Socks5CmdRequest req = (Socks5CmdRequest) msg;
            assertThat(req.cmdType(), is(Socks5CmdType.CONNECT));

            ctx.pipeline().addBefore(ctx.name(), "lineDecoder", new LineBasedFrameDecoder(64, false, true));

            Socks5CmdResponse res;
            boolean sendGreeting = false;
            if (!req.host().equals(destination.getHostString()) ||
                       req.port() != destination.getPort()) {
                res = new Socks5CmdResponse(Socks5CmdStatus.FORBIDDEN, Socks5AddressType.IPv4);
            } else {
                res = new Socks5CmdResponse(Socks5CmdStatus.SUCCESS, Socks5AddressType.IPv4);
                sendGreeting = true;
            }
View Full Code Here

                        exceptionMessage("unknown address type: " + StringUtil.simpleClassName(rhost)));
            }
        }

        ctx.pipeline().addBefore(encoderName, decoderName, new Socks5CmdResponseDecoder());
        sendToProxyServer(new Socks5CmdRequest(Socks5CmdType.CONNECT, addrType, rhost, raddr.getPort()));
    }
View Full Code Here

                switch (((Socks5Request) socksRequest).requestType()) {
                    case INIT: {
                        // auth support example
                        //ctx.pipeline().addFirst(new SocksV5AuthRequestDecoder());
                        //ctx.write(new SocksV5InitResponse(SocksV5AuthScheme.AUTH_PASSWORD));
                        ctx.pipeline().addFirst(new Socks5CmdRequestDecoder());
                        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) {
View Full Code Here

        }
    }

    private boolean authenticate(ChannelHandlerContext ctx, Object msg) {
        if (username == null) {
            ctx.pipeline().addBefore("encoder", "decoder", new Socks5CmdRequestDecoder());
            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());
View Full Code Here

                        @Override
                        public void operationComplete(final Future<Channel> future) throws Exception {
                            final Channel outboundChannel = future.getNow();
                            if (future.isSuccess()) {
                                ctx.channel().writeAndFlush(
                                        new Socks5CmdResponse(Socks5CmdStatus.SUCCESS, request.addressType())
                                ).addListener(new ChannelFutureListener() {
                                            @Override
                                            public void operationComplete(ChannelFuture channelFuture) {
                                                ctx.pipeline().remove(SocksServerConnectHandler.this);
                                                outboundChannel.pipeline().addLast(new RelayHandler(ctx.channel()));
                                                ctx.pipeline().addLast(new RelayHandler(outboundChannel));
                                            }
                                        }
                                );
                            } else {
                                ctx.channel().writeAndFlush(
                                        new Socks5CmdResponse(Socks5CmdStatus.FAILURE, request.addressType()));
                                SocksServerUtils.closeOnFlush(ctx.channel());
                            }
                        }
                    });

            final Channel inboundChannel = ctx.channel();
            b.group(inboundChannel.eventLoop())
                    .channel(NioSocketChannel.class)
                    .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000)
                    .option(ChannelOption.SO_KEEPALIVE, true)
                    .handler(new DirectClientHandler(promise));

            b.connect(request.host(), request.port()).addListener(new ChannelFutureListener() {
                @Override
                public void operationComplete(ChannelFuture future) throws Exception {
                    if (future.isSuccess()) {
                        // Connection established use handler provided results
                    } else {
                        // Close the connection if the connection attempt has failed.
                        ctx.channel().writeAndFlush(
                                new Socks5CmdResponse(Socks5CmdStatus.FAILURE, request.addressType()));
                        SocksServerUtils.closeOnFlush(ctx.channel());
                    }
                }
            });
        } else {
View Full Code Here

            }

            Socks5CmdRequest req = (Socks5CmdRequest) msg;
            assertThat(req.cmdType(), is(Socks5CmdType.CONNECT));

            Socks5CmdResponse res;
            res = new Socks5CmdResponse(Socks5CmdStatus.SUCCESS, Socks5AddressType.IPv4);
            intermediaryDestination = new InetSocketAddress(req.host(), req.port());

            ctx.write(res);
            ctx.pipeline().remove(Socks5MessageEncoder.class);
View Full Code Here

            Socks5CmdRequest req = (Socks5CmdRequest) msg;
            assertThat(req.cmdType(), is(Socks5CmdType.CONNECT));

            ctx.pipeline().addBefore(ctx.name(), "lineDecoder", new LineBasedFrameDecoder(64, false, true));

            Socks5CmdResponse res;
            boolean sendGreeting = false;
            if (!req.host().equals(destination.getHostString()) ||
                       req.port() != destination.getPort()) {
                res = new Socks5CmdResponse(Socks5CmdStatus.FORBIDDEN, Socks5AddressType.IPv4);
            } else {
                res = new Socks5CmdResponse(Socks5CmdStatus.SUCCESS, Socks5AddressType.IPv4);
                sendGreeting = true;
            }

            ctx.write(res);
            ctx.pipeline().remove(Socks5MessageEncoder.class);
View Full Code Here

TOP

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

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.