Search in sources :

Example 1 with HostResolver

use of com.github.jh3nd3rs0n.jargyle.client.HostResolver in project jargyle by jh3nd3rs0n.

the class ResolveCommandWorker method run.

@Override
public void run() throws IOException {
    Socks5Reply socks5Rep = null;
    HostResolver hostResolver = this.netObjectFactory.newHostResolver();
    InetAddress inetAddress = null;
    try {
        inetAddress = hostResolver.resolve(this.desiredDestinationAddress);
    } catch (UnknownHostException e) {
        LOGGER.error(ObjectLogMessageHelper.objectLogMessage(this, "Error in resolving the hostname"), e);
        socks5Rep = Socks5Reply.newFailureInstance(Reply.HOST_UNREACHABLE);
        this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
        return;
    } catch (IOException e) {
        LOGGER.error(ObjectLogMessageHelper.objectLogMessage(this, "Error in resolving the hostname"), e);
        socks5Rep = Socks5Reply.newFailureInstance(Reply.GENERAL_SOCKS_SERVER_FAILURE);
        this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
        return;
    }
    String serverBoundAddress = inetAddress.getHostAddress();
    int serverBoundPort = desiredDestinationPort;
    socks5Rep = Socks5Reply.newInstance(Reply.SUCCEEDED, serverBoundAddress, serverBoundPort);
    FirewallRule.Context context = new Socks5ReplyFirewallRule.Context(this.clientFacingSocket.getInetAddress().getHostAddress(), this.clientFacingSocket.getLocalAddress().getHostAddress(), this.methodSubnegotiationResults, this.socks5Request, socks5Rep);
    if (!this.commandWorkerContext.canAllowSocks5Reply(this, context, LOGGER)) {
        return;
    }
    this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
}
Also used : UnknownHostException(java.net.UnknownHostException) Socks5Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply) IOException(java.io.IOException) HostResolver(com.github.jh3nd3rs0n.jargyle.client.HostResolver) InetAddress(java.net.InetAddress) FirewallRule(com.github.jh3nd3rs0n.jargyle.server.rules.impl.FirewallRule) Socks5ReplyFirewallRule(com.github.jh3nd3rs0n.jargyle.server.rules.impl.Socks5ReplyFirewallRule)

Example 2 with HostResolver

use of com.github.jh3nd3rs0n.jargyle.client.HostResolver in project jargyle by jh3nd3rs0n.

the class BindCommandWorker method bindListenSocket.

private boolean bindListenSocket(final ServerSocket listenSocket) {
    Socks5Reply socks5Rep = null;
    HostResolver hostResolver = this.netObjectFactory.newHostResolver();
    try {
        listenSocket.bind(new InetSocketAddress(hostResolver.resolve(this.desiredDestinationAddress), this.desiredDestinationPort));
    } catch (IOException e) {
        LOGGER.error(ObjectLogMessageHelper.objectLogMessage(this, "Error in binding the listen socket"), e);
        socks5Rep = Socks5Reply.newFailureInstance(Reply.GENERAL_SOCKS_SERVER_FAILURE);
        this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
        return false;
    }
    return true;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Socks5Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply) IOException(java.io.IOException) HostResolver(com.github.jh3nd3rs0n.jargyle.client.HostResolver)

Example 3 with HostResolver

use of com.github.jh3nd3rs0n.jargyle.client.HostResolver in project jargyle by jh3nd3rs0n.

the class ConnectCommandWorker method newServerFacingSocket.

private Socket newServerFacingSocket() throws IOException {
    Socks5Reply socks5Rep = null;
    HostResolver hostResolver = this.netObjectFactory.newHostResolver();
    Socket serverFacingSocket = null;
    int connectTimeout = this.settings.getLastValue(Socks5SettingSpecConstants.SOCKS5_ON_CONNECT_SERVER_FACING_CONNECT_TIMEOUT).intValue();
    if (this.settings.getLastValue(Socks5SettingSpecConstants.SOCKS5_ON_CONNECT_PREPARE_SERVER_FACING_SOCKET)) {
        serverFacingSocket = netObjectFactory.newSocket();
        if (!this.configureServerFacingSocket(serverFacingSocket)) {
            return null;
        }
        try {
            serverFacingSocket.connect(new InetSocketAddress(hostResolver.resolve(this.desiredDestinationAddress), this.desiredDestinationPort), connectTimeout);
        } catch (UnknownHostException e) {
            LOGGER.error(ObjectLogMessageHelper.objectLogMessage(this, "Error in connecting the server-facing socket"), e);
            socks5Rep = Socks5Reply.newFailureInstance(Reply.HOST_UNREACHABLE);
            this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
            return null;
        }
    } else {
        Host bindHost = this.settings.getLastValue(Socks5SettingSpecConstants.SOCKS5_ON_CONNECT_SERVER_FACING_BIND_HOST);
        InetAddress bindInetAddress = bindHost.toInetAddress();
        try {
            serverFacingSocket = this.netObjectFactory.newSocket(this.desiredDestinationAddress, this.desiredDestinationPort, bindInetAddress, 0);
        } catch (UnknownHostException e) {
            LOGGER.error(ObjectLogMessageHelper.objectLogMessage(this, "Error in creating the server-facing socket"), e);
            socks5Rep = Socks5Reply.newFailureInstance(Reply.HOST_UNREACHABLE);
            this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
            return null;
        }
    }
    return serverFacingSocket;
}
Also used : UnknownHostException(java.net.UnknownHostException) InetSocketAddress(java.net.InetSocketAddress) Socks5Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply) Host(com.github.jh3nd3rs0n.jargyle.common.net.Host) HostResolver(com.github.jh3nd3rs0n.jargyle.client.HostResolver) InetAddress(java.net.InetAddress) Socket(java.net.Socket)

Aggregations

HostResolver (com.github.jh3nd3rs0n.jargyle.client.HostResolver)3 Socks5Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply)3 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 InetSocketAddress (java.net.InetSocketAddress)2 UnknownHostException (java.net.UnknownHostException)2 Host (com.github.jh3nd3rs0n.jargyle.common.net.Host)1 FirewallRule (com.github.jh3nd3rs0n.jargyle.server.rules.impl.FirewallRule)1 Socks5ReplyFirewallRule (com.github.jh3nd3rs0n.jargyle.server.rules.impl.Socks5ReplyFirewallRule)1 Socket (java.net.Socket)1