use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request in project jargyle by jh3nd3rs0n.
the class Socks5ReplyFirewallRule method appliesTo.
@Override
public boolean appliesTo(final Rule.Context context) {
if (!(context instanceof Context)) {
return false;
}
Context cntxt = (Context) context;
if (cntxt.getFirewallRuleAction() != null) {
return false;
}
MethodSubnegotiationResults methSubnegotiationResults = cntxt.getMethodSubnegotiationResults();
Socks5Request socks5Req = cntxt.getSocks5Request();
Socks5Reply socks5Rep = cntxt.getSocks5Reply();
if (this.clientAddressRange != null && !this.clientAddressRange.contains(cntxt.getClientAddress())) {
return false;
}
if (this.socksServerAddressRange != null && !this.socksServerAddressRange.contains(cntxt.getSocksServerAddress())) {
return false;
}
if (this.method != null && !this.method.equals(methSubnegotiationResults.getMethod())) {
return false;
}
if (this.user != null && !this.user.equals(methSubnegotiationResults.getUser())) {
return false;
}
if (this.command != null && !this.command.equals(socks5Req.getCommand())) {
return false;
}
if (this.desiredDestinationAddressRange != null && !this.desiredDestinationAddressRange.contains(socks5Req.getDesiredDestinationAddress())) {
return false;
}
if (this.desiredDestinationPortRange != null && !this.desiredDestinationPortRange.contains(Port.newInstance(socks5Req.getDesiredDestinationPort()))) {
return false;
}
if (this.serverBoundAddressRange != null && !this.serverBoundAddressRange.contains(socks5Rep.getServerBoundAddress())) {
return false;
}
if (this.serverBoundPortRange != null && !this.serverBoundPortRange.contains(Port.newInstance(socks5Rep.getServerBoundPort()))) {
return false;
}
return true;
}
use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request in project jargyle by jh3nd3rs0n.
the class Socks5RequestFirewallRule method appliesTo.
@Override
public boolean appliesTo(final Rule.Context context) {
if (!(context instanceof Context)) {
return false;
}
Context cntxt = (Context) context;
if (cntxt.getFirewallRuleAction() != null) {
return false;
}
MethodSubnegotiationResults methSubnegotiationResults = cntxt.getMethodSubnegotiationResults();
Socks5Request socks5Req = cntxt.getSocks5Request();
if (this.clientAddressRange != null && !this.clientAddressRange.contains(cntxt.getClientAddress())) {
return false;
}
if (this.socksServerAddressRange != null && !this.socksServerAddressRange.contains(cntxt.getSocksServerAddress())) {
return false;
}
if (this.method != null && !this.method.equals(methSubnegotiationResults.getMethod())) {
return false;
}
if (this.user != null && !this.user.equals(methSubnegotiationResults.getUser())) {
return false;
}
if (this.command != null && !this.command.equals(socks5Req.getCommand())) {
return false;
}
if (this.desiredDestinationAddressRange != null && !this.desiredDestinationAddressRange.contains(socks5Req.getDesiredDestinationAddress())) {
return false;
}
if (this.desiredDestinationPortRange != null && !this.desiredDestinationPortRange.contains(Port.newInstance(socks5Req.getDesiredDestinationPort()))) {
return false;
}
return true;
}
use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request in project jargyle by jh3nd3rs0n.
the class Socks5Worker method run.
public void run() throws IOException {
this.clientFacingInputStream = this.clientFacingSocket.getInputStream();
Method method = this.negotiateMethod();
if (method == null) {
return;
}
MethodSubnegotiationResults methodSubnegotiationResults = this.doMethodSubnegotiation(method);
if (methodSubnegotiationResults == null) {
return;
}
Socket socket = methodSubnegotiationResults.getSocket();
this.clientFacingInputStream = socket.getInputStream();
this.clientFacingSocket = socket;
this.socks5WorkerContext = new Socks5WorkerContext(new WorkerContext(this.clientFacingSocket, this.socks5WorkerContext.getConfiguration(), this.socks5WorkerContext.getRoute(), this.socks5WorkerContext.getRoutes(), this.socks5WorkerContext.getClientFacingDtlsDatagramSocketFactory()));
Socks5Request socks5Request = this.newSocks5Request();
if (socks5Request == null) {
return;
}
if (!this.canAllowSocks5Request(new Socks5RequestFirewallRule.Context(this.clientFacingSocket.getInetAddress().getHostAddress(), this.clientFacingSocket.getLocalAddress().getHostAddress(), methodSubnegotiationResults, socks5Request))) {
return;
}
Route route = this.selectRoute(new Socks5RequestRoutingRule.Context(this.clientFacingSocket.getInetAddress().getHostAddress(), this.clientFacingSocket.getLocalAddress().getHostAddress(), methodSubnegotiationResults, socks5Request, this.socks5WorkerContext.getRoutes()));
if (route == null) {
return;
}
this.socks5WorkerContext = new Socks5WorkerContext(new WorkerContext(this.socks5WorkerContext.getClientFacingSocket(), this.socks5WorkerContext.getConfiguration(), route, this.socks5WorkerContext.getRoutes(), this.socks5WorkerContext.getClientFacingDtlsDatagramSocketFactory()));
Socks5RequestWorkerContext socks5RequestWorkerContext = new Socks5RequestWorkerContext(this.socks5WorkerContext, methodSubnegotiationResults, socks5Request);
Socks5RequestWorker socks5RequestWorker = this.newSocks5RequestWorker(socks5RequestWorkerContext);
socks5RequestWorker.run();
}
use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request in project jargyle by jh3nd3rs0n.
the class Socks5Worker method newSocks5Request.
private Socks5Request newSocks5Request() {
Socks5Request socks5Request = null;
try {
socks5Request = Socks5Request.newInstanceFrom(this.clientFacingInputStream);
} catch (AddressTypeNotSupportedException e) {
LOGGER.debug(ObjectLogMessageHelper.objectLogMessage(this, "Unable to parse the SOCKS5 request"), e);
Socks5Reply socks5Rep = Socks5Reply.newFailureInstance(Reply.ADDRESS_TYPE_NOT_SUPPORTED);
this.socks5WorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
return null;
} catch (CommandNotSupportedException e) {
LOGGER.debug(ObjectLogMessageHelper.objectLogMessage(this, "Unable to parse the SOCKS5 request"), e);
Socks5Reply socks5Rep = Socks5Reply.newFailureInstance(Reply.COMMAND_NOT_SUPPORTED);
this.socks5WorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
return null;
} catch (IOException e) {
ClientFacingIOExceptionLoggingHelper.log(LOGGER, ObjectLogMessageHelper.objectLogMessage(this, "Error in parsing the SOCKS5 request"), e);
return null;
}
LOGGER.debug(ObjectLogMessageHelper.objectLogMessage(this, "Received %s", socks5Request.toString()));
return socks5Request;
}
use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request in project jargyle by jh3nd3rs0n.
the class Socks5RequestRoutingRule method appliesTo.
@Override
public boolean appliesTo(final Rule.Context context) {
if (!(context instanceof Context)) {
return false;
}
Context cntxt = (Context) context;
if (cntxt.getRoute() != null) {
return false;
}
MethodSubnegotiationResults methSubnegotiationResults = cntxt.getMethodSubnegotiationResults();
Socks5Request socks5Req = cntxt.getSocks5Request();
if (this.clientAddressRange != null && !this.clientAddressRange.contains(cntxt.getClientAddress())) {
return false;
}
if (this.socksServerAddressRange != null && !this.socksServerAddressRange.contains(cntxt.getSocksServerAddress())) {
return false;
}
if (this.method != null && !this.method.equals(methSubnegotiationResults.getMethod())) {
return false;
}
if (this.user != null && !this.user.equals(methSubnegotiationResults.getUser())) {
return false;
}
if (this.command != null && !this.command.equals(socks5Req.getCommand())) {
return false;
}
if (this.desiredDestinationAddressRange != null && !this.desiredDestinationAddressRange.contains(socks5Req.getDesiredDestinationAddress())) {
return false;
}
if (this.desiredDestinationPortRange != null && !this.desiredDestinationPortRange.contains(Port.newInstance(socks5Req.getDesiredDestinationPort()))) {
return false;
}
return true;
}
Aggregations