Search in sources :

Example 6 with MethodSubnegotiationResults

use of com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults in project jargyle by jh3nd3rs0n.

the class Socks5RequestFirewallRule method applyTo.

@Override
public void applyTo(final Rule.Context context) {
    FirewallRuleAction firewallRuleAction = this.getFirewallRuleAction();
    Context cntxt = (Context) context;
    cntxt.setFirewallRuleAction(firewallRuleAction);
    LogAction logAction = this.getLogAction();
    if (logAction == null) {
        return;
    }
    String clientAddress = cntxt.getClientAddress();
    MethodSubnegotiationResults methSubnegotiationResults = cntxt.getMethodSubnegotiationResults();
    String user = methSubnegotiationResults.getUser();
    String possibleUser = (user != null) ? String.format(" (%s)", user) : "";
    if (firewallRuleAction.equals(FirewallRuleAction.ALLOW)) {
        logAction.invoke(String.format("SOCKS5 request from %s%s is allowed based on the " + "following firewall rule and context: %s, %s", clientAddress, possibleUser, this, context));
    } else if (firewallRuleAction.equals(FirewallRuleAction.DENY)) {
        logAction.invoke(String.format("SOCKS5 request from %s%s is denied based on the " + "following firewall rule and context: %s, %s", clientAddress, possibleUser, this, context));
    }
}
Also used : LogAction(com.github.jh3nd3rs0n.jargyle.server.LogAction) MethodSubnegotiationResults(com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults)

Example 7 with MethodSubnegotiationResults

use of com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults in project jargyle by jh3nd3rs0n.

the class Socks5RequestRoutingRule method applyTo.

@Override
public void applyTo(final Rule.Context context) {
    String routeId = this.getRouteIdSelector().select();
    if (routeId == null) {
        return;
    }
    Context cntxt = (Context) context;
    Routes routes = cntxt.getRoutes();
    Route route = routes.get(routeId);
    if (route == null) {
        return;
    }
    cntxt.setRoute(route);
    LogAction logAction = this.getLogAction();
    if (logAction == null) {
        return;
    }
    String clientAddress = cntxt.getClientAddress();
    MethodSubnegotiationResults methSubnegotiationResults = cntxt.getMethodSubnegotiationResults();
    String user = methSubnegotiationResults.getUser();
    String possibleUser = (user != null) ? String.format(" (%s)", user) : "";
    logAction.invoke(String.format("SOCKS5 request route '%s' for %s%s is selected from the " + "following routing rule and context: %s, %s", routeId, clientAddress, possibleUser, this, context));
}
Also used : LogAction(com.github.jh3nd3rs0n.jargyle.server.LogAction) MethodSubnegotiationResults(com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults) Routes(com.github.jh3nd3rs0n.jargyle.server.Routes) Route(com.github.jh3nd3rs0n.jargyle.server.Route)

Example 8 with MethodSubnegotiationResults

use of com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults in project jargyle by jh3nd3rs0n.

the class Socks5UdpFirewallRule method applyTo.

@Override
public void applyTo(final Rule.Context context) {
    FirewallRuleAction firewallRuleAction = this.getFirewallRuleAction();
    Context cntxt = (Context) context;
    cntxt.setFirewallRuleAction(firewallRuleAction);
    LogAction logAction = this.getLogAction();
    if (logAction == null) {
        return;
    }
    String clientAddress = cntxt.getClientAddress();
    MethodSubnegotiationResults methSubnegotiationResults = cntxt.getMethodSubnegotiationResults();
    String peerAddress = cntxt.getPeerAddress();
    String user = methSubnegotiationResults.getUser();
    String possibleUser = (user != null) ? String.format(" (%s)", user) : "";
    if (firewallRuleAction.equals(FirewallRuleAction.ALLOW)) {
        logAction.invoke(String.format("Traffic between client %s%s and peer %s is allowed based " + "on the following firewall rule and context: %s, %s", clientAddress, possibleUser, peerAddress, this, context));
    } else if (firewallRuleAction.equals(FirewallRuleAction.DENY)) {
        logAction.invoke(String.format("Traffic between client %s%s and peer %s is denied based " + "on the following firewall rule and context: %s, %s", clientAddress, possibleUser, peerAddress, this, context));
    }
}
Also used : LogAction(com.github.jh3nd3rs0n.jargyle.server.LogAction) MethodSubnegotiationResults(com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults)

Aggregations

MethodSubnegotiationResults (com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults)8 LogAction (com.github.jh3nd3rs0n.jargyle.server.LogAction)4 Socks5Request (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request)3 Route (com.github.jh3nd3rs0n.jargyle.server.Route)1 Routes (com.github.jh3nd3rs0n.jargyle.server.Routes)1 Socks5Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply)1