YourPaste - For your paste! Archive - Tools - Login

AuthTWN.java

Posted by unknown on Mon 7 Jul 2008 23:19 260 views - Syntax: Java - Expires: never - Report - IMG - Download -

  1. import java.net.*;
  2. import java.io.*;
  3. import javax.net.*;
  4. import javax.net.ssl.*;
  5.  
  6. class AuthTWN {
  7.         String TWNServ = "loginnet.passport.com";
  8.         String TWNPage = "/RST.srf";
  9.         String USRName = "";
  10.         String USRPass = "";
  11.        
  12.         String ReturnVal;
  13.  
  14.         public void AuthTWN() {
  15.                
  16.         }
  17.        
  18.         public String GetIt(String Email, String Password, String Challenge) {
  19.                 try {
  20.                         this.USRName = URLEncoder.encode(Email,"UTF-8");
  21.                         this.USRPass = URLEncoder.encode(Password,"UTF-8");
  22.                        
  23.                         SSLSocketFactory ssl = (SSLSocketFactory) SSLSocketFactory.getDefault();
  24.                         SSLSocket socket = (SSLSocket) ssl.createSocket(this.TWNServ, 443);
  25.                        
  26.                         InputStream is = socket.getInputStream();
  27.                         InputStreamReader isr = new InputStreamReader(is);
  28.                         BufferedReader br = new BufferedReader(isr);
  29.                        
  30.                         OutputStream os = socket.getOutputStream();
  31.                         OutputStreamWriter osw = new OutputStreamWriter(os);
  32.                         PrintWriter pw = new PrintWriter(osw);
  33.  
  34.                         StringBuffer buf = new StringBuffer();
  35.                         StringBuffer buf2 = new StringBuffer();
  36.                        
  37.                         Challenge = URLDecoder.decode(Challenge, "UTF-8");
  38.                         Challenge = Challenge.replaceAll(",", "&");
  39.                         Challenge = Challenge.replaceAll("&", "&");
  40.                        
  41.                         buf2.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
  42.                         buf2.append("<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:wsse=\"http://schemas.xmlsoap.org/ws/2003/06/secext\" xmlns:saml=\"urn:oasis:names:tc:SAML:1.0:assertion\" xmlns:wsp=\"http://schemas.xmlsoap.org/ws/2002/12/policy\" xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" xmlns:wsa=\"http://schemas.xmlsoap.org/ws/2004/03/addressing\" xmlns:wssc=\"http://schemas.xmlsoap.org/ws/2004/04/sc\" xmlns:wst=\"http://schemas.xmlsoap.org/ws/2004/04/trust\"><Header>");
  43.                         buf2.append("<ps:AuthInfo xmlns:ps=\"http://schemas.microsoft.com/Passport/SoapServices/PPCRL\" Id=\"PPAuthInfo\">");
  44.                         buf2.append("<ps:HostingApp>{7108E71A-9926-4FCB-BCC9-9A9D3F32E423}</ps:HostingApp>");
  45.                         buf2.append("<ps:BinaryVersion>4</ps:BinaryVersion>");
  46.                         buf2.append("<ps:UIVersion>1</ps:UIVersion>");
  47.                         buf2.append("<ps:Cookies></ps:Cookies>");
  48.                         buf2.append("<ps:RequestParams>AQAAAAIAAABsYwQAAAAzMDg0</ps:RequestParams>");
  49.                         buf2.append("</ps:AuthInfo>");
  50.                         buf2.append("<wsse:Security>");
  51.                         buf2.append("<wsse:UsernameToken Id=\"user\">");
  52.                         buf2.append("<wsse:Username>" + Email + "</wsse:Username>");
  53.                         buf2.append("<wsse:Password>" + Password + "</wsse:Password>");
  54.                         buf2.append("</wsse:UsernameToken>");
  55.                         buf2.append("</wsse:Security>");
  56.                         buf2.append("</Header>");
  57.                         buf2.append("<Body>");
  58.                         buf2.append("<ps:RequestMultipleSecurityTokens xmlns:ps=\"http://schemas.microsoft.com/Passport/SoapServices/PPCRL\" Id=\"RSTS\">");
  59.                         buf2.append("<wst:RequestSecurityToken Id=\"RST0\">");
  60.                         buf2.append("<wst:RequestType>http://schemas.xmlsoap.org/ws/2004/04/security/trust/Issue</wst:RequestType>");
  61.                         buf2.append("<wsp:AppliesTo>");
  62.                         buf2.append("<wsa:EndpointReference>");
  63.                         buf2.append("<wsa:Address>http://Passport.NET/tb</wsa:Address>");
  64.                         buf2.append("</wsa:EndpointReference>");
  65.                         buf2.append("</wsp:AppliesTo>");
  66.                         buf2.append("</wst:RequestSecurityToken>");
  67.                         buf2.append("<wst:RequestSecurityToken Id=\"RST1\">");
  68.                         buf2.append("<wst:RequestType>http://schemas.xmlsoap.org/ws/2004/04/security/trust/Issue</wst:RequestType>");
  69.                         buf2.append("<wsp:AppliesTo>");
  70.                         buf2.append("<wsa:EndpointReference>");
  71.                         buf2.append("<wsa:Address>messenger.msn.com</wsa:Address>");
  72.                         buf2.append("</wsa:EndpointReference>");
  73.                         buf2.append("</wsp:AppliesTo>");
  74.                         buf2.append("<wsse:PolicyReference URI=\"?" + Challenge + "\"></wsse:PolicyReference>");
  75.                         buf2.append("</wst:RequestSecurityToken>");
  76.                         buf2.append("</ps:RequestMultipleSecurityTokens>");
  77.                         buf2.append("</Body></Envelope>");
  78.                        
  79.                         buf.append("POST " + TWNPage + " HTTP/1.1" + "\r\n");
  80.                         buf.append("Accept: text/*" + "\r\n");
  81.                         buf.append("User-Agent: TomsMSNBot/3.0" + "\r\n");
  82.                         buf.append("Host: " + TWNServ + "\r\n");
  83.                         buf.append("Content-Length: " + buf2.length() + "\r\n");
  84.                         buf.append("Connection: Keep-Alive" + "\r\n");
  85.                         buf.append("Cache-Control: no-cache" + "\r\n");
  86.                         buf.append("\r\n");
  87.                         buf.append(buf2.toString());
  88.                         pw.print(buf.toString());
  89.                         pw.flush();
  90.                        
  91.                         buf = new StringBuffer();
  92.                         buf2 = null;
  93.                        
  94.                         boolean DoLoop = true;
  95.                         int Length = 0;
  96.                        
  97.                         while(DoLoop) {
  98.                                 String str = br.readLine();
  99.                                 if(str.substring(0,15).equals("Content-Length:")) {
  100.                                         String[] DataArray = str.split(" ");
  101.                                         Length = Integer.parseInt(DataArray[1]) + 2;
  102.                                         for(int i = 0; i < Length; i++) {
  103.                                                 int c = br.read();
  104.                                                 buf.append((char) c);
  105.                                         }
  106.                                        
  107.                                         String data = buf.toString();
  108.                                         String[] temp = data.split("BinarySecurityToken");
  109.                                         data = temp[1];
  110.                                         data = data.substring(15, (data.length()-7));
  111.                                        
  112.                                         data = data.replaceAll("&amp;", "&");
  113.                                        
  114.                                         this.ReturnVal = data;
  115.                                        
  116.                                         DoLoop = false;
  117.                                 }
  118.                         }
  119.                 }
  120.                 catch(Exception e) {
  121.                        
  122.                 }
  123.                 finally {
  124.                         return this.ReturnVal;
  125.                 }
  126.         }
  127. }

Comments


Name:
Comment:

© 2008 YourPaste.net - Disclaimer