Android Open Source - Orlib User Password Authentication






From Project

Back to project page Orlib.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project Orlib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package net.sourceforge.jsocks.socks;
//from   w w  w.j a  v a  2s. c  om
/**
  SOCKS5 User Password authentication scheme.
*/
public class UserPasswordAuthentication implements Authentication{

   /**SOCKS ID for User/Password authentication method*/
   public final static int METHOD_ID = 2;

   String userName, password;
   byte[] request;

   /**
     Create an instance of UserPasswordAuthentication.
     @param userName User Name to send to SOCKS server.
     @param password Password to send to SOCKS server.
   */
   public UserPasswordAuthentication(String userName,String password){
     this.userName = userName;
     this.password = password;
     formRequest();
   }
   /** Get the user name.
   @return User name.
   */
   public String getUser(){
     return userName;
   }
   /** Get password
   @return Password
   */
   public String getPassword(){
     return password;
   }
   /**
    Does User/Password authentication as defined in rfc1929.
    @return An array containnig in, out streams, or null if authentication
    fails.
   */
   public Object[] doSocksAuthentication(int methodId,
                                         java.net.Socket proxySocket)
                   throws java.io.IOException{

      if(methodId != METHOD_ID) return null;

      java.io.InputStream in = proxySocket.getInputStream();
      java.io.OutputStream out = proxySocket.getOutputStream();

      out.write(request);
      int version = in.read();
      if(version < 0) return null; //Server closed connection
      int status = in.read();
      if(status != 0) return null; //Server closed connection, or auth failed.

      return new Object[] {in,out};
   }

//Private methods
//////////////////

/** Convert UserName password in to binary form, ready to be send to server*/
   private void formRequest(){
      byte[] user_bytes = userName.getBytes();
      byte[] password_bytes = password.getBytes();

      request = new byte[3+user_bytes.length+password_bytes.length];
      request[0] = (byte) 1; 
      request[1] = (byte) user_bytes.length;
      System.arraycopy(user_bytes,0,request,2,user_bytes.length);
      request[2+user_bytes.length] = (byte) password_bytes.length;
      System.arraycopy(password_bytes,0,
                       request,3+user_bytes.length,password_bytes.length);
   }
}




Java Source Code List

info.guardianproject.net.SocksSocketFactory.java
info.guardianproject.net.http.HttpManager.java
info.guardianproject.net.http.ModSSLSocketFactory.java
info.guardianproject.net.http.MyDefaultClientConnectionOperator.java
info.guardianproject.net.http.MyThreadSafeClientConnManager.java
info.guardianproject.net.http.SocksHttpClient.java
net.sourceforge.jsocks.SOCKS.java
net.sourceforge.jsocks.SocksServerException.java
net.sourceforge.jsocks.socks.AuthenticationException.java
net.sourceforge.jsocks.socks.AuthenticationNone.java
net.sourceforge.jsocks.socks.Authentication.java
net.sourceforge.jsocks.socks.InetRange.java
net.sourceforge.jsocks.socks.ProxyMessage.java
net.sourceforge.jsocks.socks.ProxyServer.java
net.sourceforge.jsocks.socks.Proxy.java
net.sourceforge.jsocks.socks.Socks4Message.java
net.sourceforge.jsocks.socks.Socks4Proxy.java
net.sourceforge.jsocks.socks.Socks5DatagramSocket.java
net.sourceforge.jsocks.socks.Socks5Message.java
net.sourceforge.jsocks.socks.Socks5Proxy.java
net.sourceforge.jsocks.socks.SocksException.java
net.sourceforge.jsocks.socks.SocksServerSocket.java
net.sourceforge.jsocks.socks.SocksSocket.java
net.sourceforge.jsocks.socks.UDPEncapsulation.java
net.sourceforge.jsocks.socks.UDPRelayServer.java
net.sourceforge.jsocks.socks.UserPasswordAuthentication.java
net.sourceforge.jsocks.socks.server.IdentAuthenticator.java
net.sourceforge.jsocks.socks.server.Ident.java
net.sourceforge.jsocks.socks.server.ServerAuthenticatorNone.java
net.sourceforge.jsocks.socks.server.ServerAuthenticator.java
net.sourceforge.jsocks.socks.server.UserPasswordAuthenticator.java
net.sourceforge.jsocks.socks.server.UserValidation.java
orlib.sample.OrlibMainActivity.java