Class SOCKSRequest

java.lang.Object
org.bluezoo.gumdrop.socks.SOCKSRequest

public final class SOCKSRequest extends Object
A parsed SOCKS connection request from a client.

Holds the protocol version, command, destination address (as an InetAddress and/or hostname), destination port, and for SOCKS4/4a the userid field.

For SOCKS4a and SOCKS5 domain-name requests, getHost() returns the unresolved hostname and getAddress() returns null until the server resolves the name.

Relevant specifications:

  • SOCKS4 protocol: Request format (VER, CD, DSTPORT, DSTIP, USERID)
  • SOCKS4a: Hostname appended after USERID when DSTIP=0.0.0.x (x≠0)
  • RFC 1928: SOCKS Protocol Version 5
  • RFC 1929: Username/Password Authentication for SOCKS V5
  • RFC 1961: GSS-API Authentication for SOCKS V5
Author:
Chris Burdess
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    SOCKSRequest(byte version, byte command, InetAddress address, String host, int port, String userid, String authenticatedUser)
    Creates a SOCKS request.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the resolved destination address, or null if the request specified a hostname that has not yet been resolved.
    Returns the username authenticated during SOCKS5 authentication, or null if no authentication was performed or for SOCKS4 requests.
    byte
    Returns the command byte.
    Returns the destination hostname from a SOCKS4a or SOCKS5 domain-name request, or null if the request specified a numeric address.
    int
    Returns the destination port.
    Returns the SOCKS4/4a userid field, or null for SOCKS5 requests.
    byte
    Returns the SOCKS protocol version (0x04 or 0x05).
    boolean
    Returns whether this is a SOCKS4a request (SOCKS4 with server-side DNS resolution).
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • SOCKSRequest

      public SOCKSRequest(byte version, byte command, InetAddress address, String host, int port, String userid, String authenticatedUser)
      Creates a SOCKS request.
      Parameters:
      version - the SOCKS version (0x04 or 0x05); SOCKS4 §Request VER / RFC 1928 §4 VER
      command - the command byte; SOCKS4 §Request CD / RFC 1928 §4 CMD
      address - the resolved destination address, or null if only a hostname was provided; SOCKS4 §Request DSTIP / RFC 1928 §4+§5 DST.ADDR
      host - the destination hostname, or null if only an address was provided; SOCKS4a (DSTIP=0.0.0.x) / RFC 1928 §4+§5 DST.ADDR (ATYP 0x03)
      port - the destination port; SOCKS4 §Request DSTPORT / RFC 1928 §4 DST.PORT
      userid - the SOCKS4 userid field, or null for SOCKS5; SOCKS4 §Request USERID
      authenticatedUser - the authenticated username from SOCKS5 auth, or null if no authentication; RFC 1929 §2 / RFC 1961 §4
  • Method Details

    • getVersion

      public byte getVersion()
      Returns the SOCKS protocol version (0x04 or 0x05). SOCKS4 §Request VER field; RFC 1928 §4 VER field.
      Returns:
      the version byte
    • getCommand

      public byte getCommand()
      Returns the command byte. SOCKS4 §Request CD field; RFC 1928 §4 CMD field.
      Returns:
      the command (CONNECT, BIND, or UDP ASSOCIATE)
    • getAddress

      public InetAddress getAddress()
      Returns the resolved destination address, or null if the request specified a hostname that has not yet been resolved. SOCKS4 §Request DSTIP; RFC 1928 §4+§5 DST.ADDR (ATYP 0x01 IPv4, 0x04 IPv6).
      Returns:
      the destination address, or null
    • getHost

      public String getHost()
      Returns the destination hostname from a SOCKS4a or SOCKS5 domain-name request, or null if the request specified a numeric address. SOCKS4a: hostname appended after USERID when DSTIP=0.0.0.x (x≠0); RFC 1928 §4+§5 DST.ADDR (ATYP 0x03 domain name).
      Returns:
      the destination hostname, or null
    • getPort

      public int getPort()
      Returns the destination port. SOCKS4 §Request DSTPORT; RFC 1928 §4 DST.PORT.
      Returns:
      the port number
    • getUserid

      public String getUserid()
      Returns the SOCKS4/4a userid field, or null for SOCKS5 requests. SOCKS4 §Request USERID (null-terminated string).
      Returns:
      the userid, or null
    • getAuthenticatedUser

      public String getAuthenticatedUser()
      Returns the username authenticated during SOCKS5 authentication, or null if no authentication was performed or for SOCKS4 requests. RFC 1929 §2 (username/password auth); RFC 1961 §4 (GSS-API principal).
      Returns:
      the authenticated username, or null
    • isSOCKS4a

      public boolean isSOCKS4a()
      Returns whether this is a SOCKS4a request (SOCKS4 with server-side DNS resolution). SOCKS4a: DSTIP=0.0.0.x with x≠0 signals that the hostname is appended after USERID for server-side DNS resolution.
      Returns:
      true if SOCKS4a
    • toString

      public String toString()
      Overrides:
      toString in class Object