Search in sources :

Example 1 with MethodEncapsulation

use of com.github.jh3nd3rs0n.jargyle.transport.socks5.MethodEncapsulation in project jargyle by jh3nd3rs0n.

the class Socks5Client method doMethodSubnegotiation.

protected MethodEncapsulation doMethodSubnegotiation(final Method method, final Socket connectedInternalSocket) throws IOException {
    MethodSubnegotiator methodSubnegotiator = MethodSubnegotiator.getInstance(method);
    MethodEncapsulation methodEncapsulation = null;
    try {
        methodEncapsulation = methodSubnegotiator.subnegotiate(connectedInternalSocket, this);
    } catch (IOException e) {
        SocksClientExceptionThrowingHelper.throwAsSocksClientException(e, this);
    }
    return new SocksClientExceptionThrowingMethodEncapsulation(this, methodEncapsulation);
}
Also used : MethodEncapsulation(com.github.jh3nd3rs0n.jargyle.transport.socks5.MethodEncapsulation) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 2 with MethodEncapsulation

use of com.github.jh3nd3rs0n.jargyle.transport.socks5.MethodEncapsulation in project jargyle by jh3nd3rs0n.

the class Socks5HostResolver method resolve.

@Override
public InetAddress resolve(final String host) throws IOException {
    if (host == null) {
        return InetAddress.getLoopbackAddress();
    }
    Properties properties = this.socks5Client.getProperties();
    AddressType addressType = AddressType.valueForString(host);
    if (!addressType.equals(AddressType.DOMAINNAME) || !properties.getValue(Socks5PropertySpecConstants.SOCKS5_RESOLVE_USE_RESOLVE_COMMAND).booleanValue()) {
        return InetAddress.getByName(host);
    }
    Socket socket = this.socks5Client.newInternalSocket();
    this.socks5Client.configureInternalSocket(socket);
    Socket sock = this.socks5Client.getConnectedInternalSocket(socket, true);
    Method method = this.socks5Client.negotiateMethod(sock);
    MethodEncapsulation methodEncapsulation = this.socks5Client.doMethodSubnegotiation(method, sock);
    Socket sck = methodEncapsulation.getSocket();
    Socks5Request socks5Req = Socks5Request.newInstance(Command.RESOLVE, host, 0);
    this.socks5Client.sendSocks5Request(socks5Req, sck);
    Socks5Reply socks5Rep = null;
    try {
        socks5Rep = this.socks5Client.receiveSocks5Reply(sck);
    } catch (FailureSocks5ReplyException e) {
        Reply reply = e.getFailureSocks5Reply().getReply();
        if (reply.equals(Reply.HOST_UNREACHABLE)) {
            throw new UnknownHostException(host);
        } else {
            throw e;
        }
    }
    InetAddress inetAddress = InetAddress.getByName(socks5Rep.getServerBoundAddress());
    return InetAddress.getByAddress(host, inetAddress.getAddress());
}
Also used : MethodEncapsulation(com.github.jh3nd3rs0n.jargyle.transport.socks5.MethodEncapsulation) Socks5Request(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request) UnknownHostException(java.net.UnknownHostException) Socks5Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply) Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply) Socks5Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply) Method(com.github.jh3nd3rs0n.jargyle.transport.socks5.Method) Properties(com.github.jh3nd3rs0n.jargyle.client.Properties) AddressType(com.github.jh3nd3rs0n.jargyle.transport.socks5.AddressType) InetAddress(java.net.InetAddress) Socket(java.net.Socket)

Aggregations

MethodEncapsulation (com.github.jh3nd3rs0n.jargyle.transport.socks5.MethodEncapsulation)2 Properties (com.github.jh3nd3rs0n.jargyle.client.Properties)1 AddressType (com.github.jh3nd3rs0n.jargyle.transport.socks5.AddressType)1 Method (com.github.jh3nd3rs0n.jargyle.transport.socks5.Method)1 Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply)1 Socks5Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply)1 Socks5Request (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 InetAddress (java.net.InetAddress)1 Socket (java.net.Socket)1 UnknownHostException (java.net.UnknownHostException)1