io.netty.handler.codec.socksx.v4.Socks4CommandStatus Java Examples

The following examples show how to use io.netty.handler.codec.socksx.v4.Socks4CommandStatus. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SocksProxyHandler.java    From nitmproxy with MIT License 6 votes vote down vote up
private void onSocksSuccess(ChannelHandlerContext ctx, Socks4CommandRequest request) {
    Address serverAddr = new Address(request.dstAddr(), request.dstPort());
    createServerChannel(ctx, serverAddr).addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
            if (future.isSuccess()) {
                ConnectionInfo newConnectionInfo = new ConnectionInfo(
                        connectionInfo.getClientAddr(), serverAddr);
                ctx.writeAndFlush(new DefaultSocks4CommandResponse(
                        Socks4CommandStatus.SUCCESS,
                        request.dstAddr(),
                        request.dstPort()));

                onServerConnected(ctx, newConnectionInfo, future.channel());
            } else {
                ctx.channel().writeAndFlush(new DefaultSocks4CommandResponse(
                        Socks4CommandStatus.REJECTED_OR_FAILED,
                        request.dstAddr(),
                        request.dstPort()));
                ctx.close();
            }
        }
    });
}
 
Example #2
Source File: ProxyClientIntegrationTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Test
void testProxy_protocolUpgrade_notSharableExceptionNotThrown() throws Exception {
    DYNAMIC_HANDLER.setWriteCustomizer((ctx, msg, promise) -> {
        ctx.write(new DefaultSocks4CommandResponse(Socks4CommandStatus.REJECTED_OR_FAILED), promise);
    });
    final ClientFactory clientFactory = ClientFactory.builder().proxyConfig(
            ProxyConfig.socks4(socksProxyServer.address())).build();
    final WebClient webClient = WebClient.builder(SessionProtocol.HTTP, backendServer.httpEndpoint())
                                         .factory(clientFactory)
                                         .decorator(LoggingClient.newDecorator())
                                         .build();
    final CompletableFuture<AggregatedHttpResponse> responseFuture =
            webClient.get(PROXY_PATH).aggregate();
    assertThatThrownBy(responseFuture::join).isInstanceOf(CompletionException.class)
                                            .hasCauseInstanceOf(UnprocessedRequestException.class)
                                            .hasRootCauseInstanceOf(ProxyConnectException.class);
    clientFactory.close();
}
 
Example #3
Source File: ProxyClientIntegrationTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@Test
void testProxy_responseFailure_throwsException() throws Exception {
    DYNAMIC_HANDLER.setWriteCustomizer((ctx, msg, promise) -> {
        ctx.write(new DefaultSocks4CommandResponse(Socks4CommandStatus.REJECTED_OR_FAILED), promise);
    });
    final ClientFactory clientFactory = ClientFactory.builder().proxyConfig(
            ProxyConfig.socks4(socksProxyServer.address())).build();
    final WebClient webClient = WebClient.builder(H1C, backendServer.httpEndpoint())
                                         .factory(clientFactory)
                                         .decorator(LoggingClient.newDecorator())
                                         .build();
    final CompletableFuture<AggregatedHttpResponse> responseFuture =
            webClient.get(PROXY_PATH).aggregate();

    assertThatThrownBy(responseFuture::join).isInstanceOf(CompletionException.class)
                                            .hasCauseInstanceOf(UnprocessedRequestException.class)
                                            .hasRootCauseInstanceOf(ProxyConnectException.class);
    clientFactory.close();
}
 
Example #4
Source File: ProxyToServerConnection.java    From PowerTunnel with MIT License 5 votes vote down vote up
@Override
void read(ConnectionFlow flow, Object msg) {
    removeHandlerIfPresent(SOCKS_ENCODER_NAME);
    removeHandlerIfPresent(SOCKS_DECODER_NAME);
    if (msg instanceof Socks4CommandResponse) {
        if (((Socks4CommandResponse) msg).status() == Socks4CommandStatus.SUCCESS) {
            flow.advance();
            return;
        }
    }
    flow.fail();
}
 
Example #5
Source File: Socks4ProxyHandler.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean handleResponse(ChannelHandlerContext ctx, Object response) throws Exception {
    final Socks4CommandResponse res = (Socks4CommandResponse) response;
    final Socks4CommandStatus status = res.status();
    if (status == Socks4CommandStatus.SUCCESS) {
        return true;
    }

    throw new ProxyConnectException(exceptionMessage("status: " + status));
}