Search in sources :

Example 1 with Methods

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

the class Socks5Client method negotiateMethod.

protected Method negotiateMethod(final Socket connectedInternalSocket) throws IOException {
    Methods methods = this.getProperties().getValue(Socks5PropertySpecConstants.SOCKS5_METHODS);
    ClientMethodSelectionMessage cmsm = ClientMethodSelectionMessage.newInstance(methods);
    Method method = null;
    try {
        InputStream inputStream = connectedInternalSocket.getInputStream();
        OutputStream outputStream = connectedInternalSocket.getOutputStream();
        outputStream.write(cmsm.toByteArray());
        outputStream.flush();
        ServerMethodSelectionMessage smsm = ServerMethodSelectionMessage.newInstanceFrom(inputStream);
        method = smsm.getMethod();
    } catch (IOException e) {
        SocksClientExceptionThrowingHelper.throwAsSocksClientException(e, this);
    }
    return method;
}
Also used : ServerMethodSelectionMessage(com.github.jh3nd3rs0n.jargyle.transport.socks5.ServerMethodSelectionMessage) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Method(com.github.jh3nd3rs0n.jargyle.transport.socks5.Method) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ClientMethodSelectionMessage(com.github.jh3nd3rs0n.jargyle.transport.socks5.ClientMethodSelectionMessage) Methods(com.github.jh3nd3rs0n.jargyle.transport.socks5.Methods)

Example 2 with Methods

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

the class Socks5Worker method negotiateMethod.

private Method negotiateMethod() {
    InputStream in = new SequenceInputStream(new ByteArrayInputStream(new byte[] { Version.V5.byteValue() }), this.clientFacingInputStream);
    ClientMethodSelectionMessage cmsm = null;
    try {
        cmsm = ClientMethodSelectionMessage.newInstanceFrom(in);
    } catch (IOException e) {
        ClientFacingIOExceptionLoggingHelper.log(LOGGER, ObjectLogMessageHelper.objectLogMessage(this, "Error in parsing the method selection message " + "from the client"), e);
        return null;
    }
    LOGGER.debug(ObjectLogMessageHelper.objectLogMessage(this, "Received %s", cmsm.toString()));
    Method method = null;
    Methods methods = this.settings.getLastValue(Socks5SettingSpecConstants.SOCKS5_METHODS);
    for (Method meth : methods.toList()) {
        if (cmsm.getMethods().contains(meth)) {
            method = meth;
            break;
        }
    }
    if (method == null) {
        method = Method.NO_ACCEPTABLE_METHODS;
    }
    ServerMethodSelectionMessage smsm = ServerMethodSelectionMessage.newInstance(method);
    LOGGER.debug(ObjectLogMessageHelper.objectLogMessage(this, "Sending %s", smsm.toString()));
    try {
        this.socks5WorkerContext.writeThenFlush(smsm.toByteArray());
    } catch (IOException e) {
        ClientFacingIOExceptionLoggingHelper.log(LOGGER, ObjectLogMessageHelper.objectLogMessage(this, "Error in writing the method selection message to " + "the client"), e);
        return null;
    }
    return smsm.getMethod();
}
Also used : ServerMethodSelectionMessage(com.github.jh3nd3rs0n.jargyle.transport.socks5.ServerMethodSelectionMessage) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Method(com.github.jh3nd3rs0n.jargyle.transport.socks5.Method) ClientMethodSelectionMessage(com.github.jh3nd3rs0n.jargyle.transport.socks5.ClientMethodSelectionMessage) Methods(com.github.jh3nd3rs0n.jargyle.transport.socks5.Methods)

Aggregations

ClientMethodSelectionMessage (com.github.jh3nd3rs0n.jargyle.transport.socks5.ClientMethodSelectionMessage)2 Method (com.github.jh3nd3rs0n.jargyle.transport.socks5.Method)2 Methods (com.github.jh3nd3rs0n.jargyle.transport.socks5.Methods)2 ServerMethodSelectionMessage (com.github.jh3nd3rs0n.jargyle.transport.socks5.ServerMethodSelectionMessage)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 OutputStream (java.io.OutputStream)1 SequenceInputStream (java.io.SequenceInputStream)1 UncheckedIOException (java.io.UncheckedIOException)1