public static boolean shouldAuthenticate(final Socket socket) throws IOException {
  final byte[] bufferSent=new byte[4];
  bufferSent[0]=SOCKS_VERSION;
  bufferSent[1]=(byte)ACCEPTABLE_METHODS;
  bufferSent[2]=(byte)NO_AUTHENTICATION_REQUIRED_METHOD;
  bufferSent[3]=(byte)USERNAME_PASSWORD_METHOD;
  final OutputStream outputStream=socket.getOutputStream();
  outputStream.write(bufferSent);
  outputStream.flush();
  LOGGER.trace("{}",MiscUtil.buildLogString(bufferSent,false));
  final InputStream inputStream=socket.getInputStream();
  final byte[] receivedData=read2Bytes(inputStream);
  LOGGER.trace("{}",MiscUtil.buildLogString(receivedData,true));
  if (receivedData[0] != (int)SOCKS_VERSION) {
    throw new SocksException("Remote server don't support SOCKS5");
  }
  final byte command=receivedData[1];
  if (command != NO_AUTHENTICATION_REQUIRED_METHOD && command != USERNAME_PASSWORD_METHOD) {
    throw new SocksException("requested authentication method not supported: " + command);
  }
  return command == USERNAME_PASSWORD_METHOD;
}

public static boolean shouldAuthenticate ( final Socket socket ) throws IOException { final byte [ ] bufferSent = new byte [ 4 ] ; bufferSent [ 0 ] = SOCKS_VERSION ; bufferSent [ 1 ] = ( byte ) ACCEPTABLE_METHODS ; bufferSent [ 2 ] = ( byte ) NO_AUTHENTICATION_REQUIRED_METHOD ; bufferSent [ 3 ] = ( byte ) USERNAME_PASSWORD_METHOD ; final OutputStream outputStream = socket . getOutputStream ( ) ; outputStream . write ( bufferSent ) ; outputStream . flush ( ) ; LOGGER . trace ( "{}" , MiscUtil . buildLogString ( bufferSent , false ) ) ; final InputStream inputStream = socket . getInputStream ( ) ; final byte [ ] receivedData = read2Bytes ( inputStream ) ; LOGGER . trace ( "{}" , MiscUtil . buildLogString ( receivedData , true ) ) ; if ( receivedData [ 0 ] != ( int ) SOCKS_VERSION ) { throw new SocksException ( "Remote server don't support SOCKS5" ) ; } final byte command = receivedData [ 1 ] ; if ( command != NO_AUTHENTICATION_REQUIRED_METHOD && command != USERNAME_PASSWORD_METHOD ) { throw new SocksException ( "requested authentication method not supported: " + command ) ; } return command == USERNAME_PASSWORD_METHOD ; }
performs an authentication method request to see how the proxy server wants to authenticate . gssapi is not supported , only anonymous and user / password authentication .
