common/src/main/java/HTTPClient/SocksClient.java
/**
     * Negotiates authentication using the username/password protocol
     * (rfc-1929). The username and password should previously have been
     * stored using the scheme "SOCKS5" and realm "USER/PASS"; e.g.
     * AuthorizationInfo.addAuthorization(socks_host, socks_port, "SOCKS5",
     *					  "USER/PASS", null,
     *					  { new NVPair(username, password) });
     *
     */
Negotiates authentication using the username/password protocol
(rfc-1929). The username and password should previously have been
stored using the scheme "SOCKS5" and realm "USER/PASS"; e.g.
Negotiates authentication using the username / password protocol ( rfc - 1929 ) . The username and password should previously have been stored using the scheme " SOCKS5 " and realm " USER / PASS " ; e . g .
private void negotiate_userpwd(InputStream inp, OutputStream out)
	throws SocksException, IOException
    {
	byte[] buffer;
	Log.write(Log.SOCKS, "Socks: Entering authorization subnegotiation" +
			     "; method: Username/Password");
	AuthorizationInfo auth_info;
	try
	{
	    auth_info =
		AuthorizationInfo.getAuthorization(socks_host, socks_port,
						   "SOCKS5", "USER/PASS",
						   null, null, true, false);
	}
	catch (AuthSchemeNotImplException atnie)
	    { auth_info = null; }
	if (auth_info == null)
	    throw new SocksException("No Authorization info for SOCKS found " +
				     "(server requested username/password).");
	NVPair[] unpw = auth_info.getParams();
	if (unpw == null  ||  unpw.length == 0)
	    throw new SocksException("No Username/Password found in " +
				     "authorization info for SOCKS.");
	String user_str = unpw[0].getName();
	String pass_str = unpw[0].getValue();
	Log.write(Log.SOCKS, "Socks: Sending authorization request for user "+
			     user_str);
	byte[] utmp = user_str.getBytes();
	byte[] ptmp = pass_str.getBytes();
	buffer = new byte[1+1+utmp.length+1+ptmp.length];
	buffer[0] = 1;				
	buffer[1] = (byte) utmp.length;				
	System.arraycopy(utmp, 0, buffer, 2, utmp.length);	
	buffer[2+buffer[1]] = (byte) ptmp.length;		
	System.arraycopy(ptmp, 0, buffer, 2+buffer[1]+1, ptmp.length);	
	out.write(buffer);
	int version = inp.read();
	if (version != 1)
	    throw new SocksException("Wrong version received in username/" +
				     "password subnegotiation response: " +
				     version + "; expected: 1");
	int sts = inp.read();
	if (sts != 0)
	    throw new SocksException("Username/Password authentication " +
				     "failed; status: "+sts);
	Log.write(Log.SOCKS, "Socks: Received response; version: " + version +
			     "; status: " + sts);
    }
private void negotiate_userpwd ( InputStream inp , OutputStream out ) throws SocksException , IOException { byte [ ] buffer ; Log . write ( Log . SOCKS , "Socks: Entering authorization subnegotiation" + "; method: Username/Password" ) ; AuthorizationInfo auth_info ; try { auth_info = AuthorizationInfo . getAuthorization ( socks_host , socks_port , "SOCKS5" , "USER/PASS" , null , null , true , false ) ; } catch ( AuthSchemeNotImplException atnie ) { auth_info = null ; } if ( auth_info == null ) throw new SocksException ( "No Authorization info for SOCKS found " + "(server requested username/password)." ) ; NVPair [ ] unpw = auth_info . getParams ( ) ; if ( unpw == null || unpw . length == 0 ) throw new SocksException ( "No Username/Password found in " + "authorization info for SOCKS." ) ; String user_str = unpw [ 0 ] . getName ( ) ; String pass_str = unpw [ 0 ] . getValue ( ) ; Log . write ( Log . SOCKS , "Socks: Sending authorization request for user " + user_str ) ; byte [ ] utmp = user_str . getBytes ( ) ; byte [ ] ptmp = pass_str . getBytes ( ) ; buffer = new byte [ 1 + 1 + utmp . length + 1 + ptmp . length ] ; buffer [ 0 ] = 1 ; buffer [ 1 ] = ( byte ) utmp . length ; System . arraycopy ( utmp , 0 , buffer , 2 , utmp . length ) ; buffer [ 2 + buffer [ 1 ] ] = ( byte ) ptmp . length ; System . arraycopy ( ptmp , 0 , buffer , 2 + buffer [ 1 ] + 1 , ptmp . length ) ; out . write ( buffer ) ; int version = inp . read ( ) ; if ( version != 1 ) throw new SocksException ( "Wrong version received in username/" + "password subnegotiation response: " + version + "; expected: 1" ) ; int sts = inp . read ( ) ; if ( sts != 0 ) throw new SocksException ( "Username/Password authentication " + "failed; status: " + sts ) ; Log . write ( Log . SOCKS , "Socks: Received response; version: " + version + "; status: " + sts ) ; }
Negotiates authentication using the username/password protocol
 (rfc-1929).
Negotiates authentication using the username / password protocol ( rfc - 1929 ) .
// get username/password // send them to server // version 1 (subnegotiation) // Username length // Username // Password length // Password // get reply