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