Class Socks5ProxyHandler

All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler, ChannelOutboundHandler

public final class Socks5ProxyHandler extends ProxyHandler
Handler that establishes a blind forwarding proxy tunnel using SOCKS Protocol Version 5.
  • Field Details

    • PROTOCOL

      private static final java.lang.String PROTOCOL
      See Also:
    • AUTH_PASSWORD

      private static final java.lang.String AUTH_PASSWORD
      See Also:
    • AUTH_PRIVATE

      private static final java.lang.String AUTH_PRIVATE
      See Also:
    • NO_PRIVATE_AUTH_METHOD

      private static final byte NO_PRIVATE_AUTH_METHOD
    • INIT_REQUEST_NO_AUTH

      private static final Socks5InitialRequest INIT_REQUEST_NO_AUTH
    • INIT_REQUEST_PASSWORD

      private static final Socks5InitialRequest INIT_REQUEST_PASSWORD
    • username

      private final java.lang.String username
    • password

      private final java.lang.String password
    • privateAuthMethod

      private final byte privateAuthMethod
    • privateToken

      private final byte[] privateToken
    • clientEncoder

      private final Socks5ClientEncoder clientEncoder
    • decoderName

      private java.lang.String decoderName
    • encoderName

      private java.lang.String encoderName
  • Constructor Details

    • Socks5ProxyHandler

      public Socks5ProxyHandler(java.net.SocketAddress proxyAddress)
    • Socks5ProxyHandler

      public Socks5ProxyHandler(java.net.SocketAddress proxyAddress, java.lang.String username, java.lang.String password)
    • Socks5ProxyHandler

      public Socks5ProxyHandler(java.net.SocketAddress proxyAddress, byte privateAuthMethod, byte[] privateToken, Socks5ClientEncoder customEncoder)
      Creates a new SOCKS5 proxy handler with a custom private authentication method.
      Parameters:
      proxyAddress - The address of the SOCKS5 proxy server
      privateAuthMethod - The private authentication method code (must be in range 0x80-0xFE)
      privateToken - The token to use for private authentication
      customEncoder - The custom encoder to use for encoding SOCKS5 messages, if null the Socks5ClientEncoder.DEFAULT will be used
      Throws:
      java.lang.IllegalArgumentException - If privateAuthMethod is not in the valid range
  • Method Details

    • protocol

      public java.lang.String protocol()
      Description copied from class: ProxyHandler
      Returns the name of the proxy protocol in use.
      Specified by:
      protocol in class ProxyHandler
    • authScheme

      public java.lang.String authScheme()
      Description copied from class: ProxyHandler
      Returns the name of the authentication scheme in use.
      Specified by:
      authScheme in class ProxyHandler
    • username

      public java.lang.String username()
    • password

      public java.lang.String password()
    • addCodec

      protected void addCodec(ChannelHandlerContext ctx) throws java.lang.Exception
      Description copied from class: ProxyHandler
      Adds the codec handlers required to communicate with the proxy server.
      Specified by:
      addCodec in class ProxyHandler
      Throws:
      java.lang.Exception
    • removeEncoder

      protected void removeEncoder(ChannelHandlerContext ctx) throws java.lang.Exception
      Description copied from class: ProxyHandler
      Removes the encoders added in ProxyHandler.addCodec(ChannelHandlerContext).
      Specified by:
      removeEncoder in class ProxyHandler
      Throws:
      java.lang.Exception
    • removeDecoder

      protected void removeDecoder(ChannelHandlerContext ctx) throws java.lang.Exception
      Description copied from class: ProxyHandler
      Removes the decoders added in ProxyHandler.addCodec(ChannelHandlerContext).
      Specified by:
      removeDecoder in class ProxyHandler
      Throws:
      java.lang.Exception
    • newInitialMessage

      protected java.lang.Object newInitialMessage(ChannelHandlerContext ctx) throws java.lang.Exception
      Description copied from class: ProxyHandler
      Returns a new message that is sent at first time when the connection to the proxy server has been established.
      Specified by:
      newInitialMessage in class ProxyHandler
      Returns:
      the initial message, or null if the proxy server is expected to send the first message instead
      Throws:
      java.lang.Exception
    • handleResponse

      protected boolean handleResponse(ChannelHandlerContext ctx, java.lang.Object response) throws java.lang.Exception
      Description copied from class: ProxyHandler
      Handles the message received from the proxy server.
      Specified by:
      handleResponse in class ProxyHandler
      Returns:
      true if the connection to the destination has been established, false if the connection to the destination has not been established and more messages are expected from the proxy server
      Throws:
      java.lang.Exception
    • socksAuthMethod

      private Socks5AuthMethod socksAuthMethod()
    • sendConnectCommand

      private void sendConnectCommand(ChannelHandlerContext ctx) throws java.lang.Exception
      Throws:
      java.lang.Exception