Class Socks5LogicHandler

    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • SELECTED_AUTH_METHOD

        private static final java.lang.String SELECTED_AUTH_METHOD
        The selected authentication method attribute key.
      • HANDSHAKE_STEP

        private static final java.lang.String HANDSHAKE_STEP
        The current step in the handshake attribute key.
      • GSS_CONTEXT

        private static final java.lang.String GSS_CONTEXT
        The Java GSS-API context attribute key.
      • GSS_TOKEN

        private static final java.lang.String GSS_TOKEN
        Last GSS token received attribute key.
    • Method Detail

      • doHandshake

        public void doHandshake​(IoFilter.NextFilter nextFilter)
        Performs the handshake process.
        Parameters:
        nextFilter - the next filter
      • encodeInitialGreetingPacket

        private IoBuffer encodeInitialGreetingPacket​(SocksProxyRequest request)
        Encodes the initial greeting packet.
        Parameters:
        request - the socks proxy request data
        Returns:
        the encoded buffer
      • encodeProxyRequestPacket

        private IoBuffer encodeProxyRequestPacket​(SocksProxyRequest request)
        Encodes the proxy authorization request packet.
        Parameters:
        request - the socks proxy request data
        Returns:
        the encoded buffer
      • encodeAuthenticationPacket

        private IoBuffer encodeAuthenticationPacket​(SocksProxyRequest request)
                                             throws org.ietf.jgss.GSSException
        Encodes the authentication packet for supported authentication methods.
        Parameters:
        request - the socks proxy request data
        Returns:
        the encoded buffer, if null then authentication step is over and handshake process can jump immediately to the next step without waiting for a server reply.
        Throws:
        org.ietf.jgss.GSSException - when something fails while using GSSAPI
      • encodeGSSAPIAuthenticationPacket

        private IoBuffer encodeGSSAPIAuthenticationPacket​(SocksProxyRequest request)
                                                   throws org.ietf.jgss.GSSException
        Encodes the authentication packet for supported authentication methods.
        Parameters:
        request - the socks proxy request data
        Returns:
        the encoded buffer
        Throws:
        org.ietf.jgss.GSSException - when something fails while using GSSAPI
      • writeRequest

        private void writeRequest​(IoFilter.NextFilter nextFilter,
                                  SocksProxyRequest request,
                                  int step)
        Encodes a SOCKS5 request and writes it to the next filter so it can be sent to the proxy server.
        Parameters:
        nextFilter - the next filter
        request - the request to send.
        step - the current step in the handshake process
      • messageReceived

        public void messageReceived​(IoFilter.NextFilter nextFilter,
                                    IoBuffer buf)
        Handles incoming data during the handshake process. Should consume only the handshake data from the buffer, leaving any extra data in place.
        Parameters:
        nextFilter - the next filter
        buf - the buffered data received
      • handleResponse

        protected void handleResponse​(IoFilter.NextFilter nextFilter,
                                      IoBuffer buf,
                                      int step)
                               throws java.lang.Exception
        Handle a SOCKS v5 response from the proxy server.
        Parameters:
        nextFilter - the next filter
        buf - the buffered data received
        step - the current step in the authentication process
        Throws:
        java.lang.Exception - If something went wrong
      • closeSession

        protected void closeSession​(java.lang.String message)
        Closes the session. If any GSSContext is present in the session then it is closed.
        Overrides:
        closeSession in class AbstractProxyLogicHandler
        Parameters:
        message - the error message