private void loginMSNClientPrivate() { if (LoginStatusChanged != null) { LoginStatusChanged(MSNEnumerations.LoginStatus.LOGGING_IN); } MSNSocketWrapper sw = null; try { sw = authentication.doAuthentication(); masterSocketWrapper = sw; if (LoginStatusChanged != null) { LoginStatusChanged(MSNEnumerations.LoginStatus.LOGGED_IN); } loginThread = null; localClient.FriendlyName = authentication.InitialFriendlyName; } catch (Exception) { if (LoginStatusChanged != null) { LoginStatusChanged(MSNEnumerations.LoginStatus.LOGGED_OUT); } sw = null; loginThread = null; } }
private String getPassportTicket(String ticketString, String version) { MSNSocketWrapper sw = new MSNSocketWrapper("nexus.passport.com", 443, true); #region GET /rdr/pprdr.asp HTTP/1.0\r\n<FLUSH HERE>\r\n MSNMessage outMessage = new MSNMessage("GET /rdr/pprdr.asp HTTP/1.0\r\n\r\n"); sw.send(outMessage); sw.send(new MSNMessage("\r\n")); sw.send(new MSNMessage("\r\n")); //outMessage = new Message("\r\n"); //sw.send(outMessage); #endregion #region process responce MSNMessage inMessage = new MSNMessage("SPOONZ"); while (!inMessage.ToString().Trim().Equals("")) { inMessage = sw.recieve(); //<<< HTTP/1.1 200 OK\r\n //<<< Server: Microsoft-IIS/5.0\r\n //<<< Date: Mon, 02 Jun 2003 11:57:47 GMT\r\n //<<< Connection: close\r\n //<<< PassportURLs: DARealm=Passport.Net,DALogin=login.passport.com/login2.srf,DAReg=http://register.passport.net/uixpwiz.srf,Properties=https://register.passport.net/editprof.srf,Privacy=http://www.passport.com/consumer/privacypolicy.asp,GeneralRedir=http://nexusrdr.passport.com/redir.asp,Help=http://memberservices.passport.net/memberservice.srf,ConfigVersion=11\r\n //<<< Content-Length: 0\r\n //<<< Content-Type: text/html\r\n //<<< Cache-control: private\r\n //<<< \r\n if (inMessage.ToString().StartsWith("PassportURLs:")) { char[] splitTokens = new char[3]; splitTokens[0] = ' '; splitTokens[1] = ','; splitTokens[2] = '='; String[] messageDataTokens = inMessage.ToString().Split(splitTokens); int daLoginIndex = 0; while (!messageDataTokens[daLoginIndex].Equals("DALogin") && daLoginIndex < messageDataTokens.Length) { daLoginIndex++; } if (daLoginIndex >= messageDataTokens.Length - 1) { throw new Exception("No DALogin found in PassportURLs from passport nexus"); } daLoginIndex++; return(getPassportTicket(ticketString, version, messageDataTokens[daLoginIndex].ToString())); } } throw new Exception("No redirect given in getPassportTicket(" + ticketString + ")"); #endregion }
internal MSNSwitchboard(MSNController controller, String addressString, int addressPort, String authenticateString, String rngTrID) //handles conversations started by local client { try { this.controller = controller; #region connect to switchboard try { switchboardSocket = new MSNSocketWrapper(addressString, addressPort, false); if (!switchboardSocket.connected()) { Console.WriteLine("Error making switchboard connection in MSNSwitchboard(" + controller.ToString() + ", " + addressString + ", " + addressPort + ", " + authenticateString + ")"); throw new Exception("Could not connect to switchboard in MSNSwitchboard(" + controller.ToString() + ", " + addressString + ", " + addressPort + ", " + authenticateString + ")"); } } catch (Exception) { Console.WriteLine("Error making switchboard connection in MSNSwitchboard(" + controller.ToString() + ", " + addressString + ", " + addressPort + ", " + authenticateString + ")"); return; } #endregion #region authenticate //ANS 1 [email protected] 1056411141.26158 17342299\r\n switchboardSocket.send(new MSNMessage("ANS " + MSNTrIDGenerator.NextID() + " " + controller.Username + " " + authenticateString + " " + rngTrID + "\r\n")); #endregion #region incommingMessageReadThread incommingMessageHandlerThread = new Thread(new ThreadStart(processIncommingMessageLoop)); incommingMessageHandlerThread.Name = "MSNSwitchboard incomming read thread"; incommingMessageHandlerThread.Start(); #endregion #region incommingMSGThread incommingMSGThread = new Thread(new ThreadStart(incommingMSGLoop)); incommingMSGThread.Name = "Incomming MSG handler thread"; incommingMSGThread.Start(); #endregion #region outgoingMSGThread outgoingMSGThread = new Thread(new ThreadStart(outgoingMSGLoop)); outgoingMSGThread.Name = "Outgoing MSG handler thread"; outgoingMSGThread.Start(); #endregion plugins.ElementAdded += new MSNListenableList <IMSNSwitchboardPlugin> .ElementAddedDelegate(plugins_ElementAdded); } catch (Exception) { Console.WriteLine("Error establishing switchboard session in MSNSwitchboard(" + controller.ToString() + ", " + addressString + ", " + addressPort + ", " + authenticateString + ")"); } }
public void logoutMSNClient() { if (currentStatus.Equals(MSNEnumerations.LoginStatus.LOGGED_IN)) { MSNSocketWrapper sw = masterSocketWrapper; masterSocketWrapper = null; if (LoginStatusChanged != null) { LoginStatusChanged(MSNEnumerations.LoginStatus.LOGGED_OUT); } sw.send(new MSNMessage("OUT")); } }
internal MSNSocketWrapper doAuthentication(String address, int port) { //messenger.hotmail.com:1863 MSNSocketWrapper sw = new MSNSocketWrapper(address, port, false); if (sw.connected() != true) { throw new Exception("Not connecting to messenger.hotmail.com"); } #region negotiate protocol version (VER) #region VER 1 MSNP8 CVR0\r\n MSNMessage outMessage = new MSNMessage("VER " + MSNTrIDGenerator.NextID() + " MSNP9 MSNP8 CVR0\r\n"); sw.send(outMessage); #endregion #region <<< VER 1 MSNP8 CVR0\r\n MSNMessage inMessage = sw.recieve(); if (inMessage.getCommand().Equals("VER") != true) { throw new Exception("VER Expected (" + inMessage.ToString() + ")"); } if (inMessage.getTrID() != outMessage.getTrID()) { throw new Exception("Incorrect TrID reponce in VER (" + inMessage.ToString() + ")"); } String[] messageDataTokens = inMessage.getData(); if (messageDataTokens.Length == 0) { throw new Exception("No data recieved in VER (" + inMessage.ToString() + ")"); } if (messageDataTokens[0].ToString().Equals("0")) { throw new Exception("Protocol MSNP9 MSNP8 CVR0 not supported in VER (" + inMessage.ToString() + ")"); } #endregion #endregion #region negotiate client version (CVR) #region CVR 2 0x0409 win 4.10 i386 MSNMSGR 5.0.0544 MSMSGS [email protected]\r\n outMessage = new MSNMessage("CVR " + MSNTrIDGenerator.NextID() + " 0x0409 win 4.10 i386 MSNMSGR 7.0.0816 MSMSGS " + username + "\r\n"); sw.send(outMessage); #endregion #region CVR 2 7.0.0816 7.0.0816 1.0.0000 http://download.microsoft.com/download/8/a/4/8a42bcae-f533-4468-b871-d2bc8dd32e9e/SETUP9x.EXE http://messenger.msn.com\r\n inMessage = sw.recieve(); if (inMessage.getCommand().Equals("CVR") != true) { throw new Exception("CVR Expected (" + inMessage.ToString() + ")"); } if (inMessage.getTrID() != outMessage.getTrID()) { throw new Exception("Incorrect TrID reponce in CVR (" + inMessage.ToString() + ")"); } messageDataTokens = inMessage.getData(); if (messageDataTokens.Length == 0) { throw new Exception("No data recieved in CVR (" + inMessage.ToString() + ")"); } #endregion #endregion #region get session tpf -> passport session ticket (USR) #region USR 3 TWN I [email protected]\r\n outMessage = new MSNMessage("USR " + MSNTrIDGenerator.NextID() + " TWN I " + username + "\r\n"); sw.send(outMessage); #endregion #region get responce inMessage = sw.recieve(); if (!(inMessage.getCommand().Equals("XFR") == true || inMessage.getCommand().Equals("USR") == true)) { throw new Exception("USR/XFR Expected (" + inMessage.ToString() + ")"); } //HANDLE INITIAL USR if (inMessage.getCommand().Equals("USR")) { String[] data = inMessage.getData(); if (data.Length >= 6) { initialFriendlyName = HttpUtility.UrlDecode(data[4]); } } if (inMessage.getTrID() != outMessage.getTrID()) { throw new Exception("Incorrect TrID reponce in CVR (" + inMessage.ToString() + ")"); } #endregion #region XFR 3 NS 207.46.106.118:1863 0 207.46.104.20:1863\r\n if (inMessage.getCommand().Equals("XFR")) { messageDataTokens = inMessage.getData(); if (messageDataTokens.Length != 4) { throw new Exception("Incorrect data length in XFR (" + inMessage.ToString() + ")"); } try { char[] splitTokens = new char[1]; splitTokens[0] = ':'; String[] addressDataTokens = messageDataTokens[1].Split(splitTokens); String newAddress = addressDataTokens[0]; int newPort = int.Parse(addressDataTokens[1]); return(doAuthentication(newAddress, newPort)); } catch (FormatException) { throw new Exception("Format error in XFR (" + inMessage.ToString() + ")"); } } #endregion String sessionTicket = ""; //First USR #region USR 3 TWN S lc=1033,id=507,tw=40,fs=1,ru=http%3A%2F%2Fmessenger%2Emsn%2Ecom,ct=1062764229,kpp=1,kv=5,ver=2.1.0173.1,tpf=43f8a4c8ed940c04e3740be46c4d1619\r\n if (inMessage.getCommand().Equals("USR")) { String messageStr = inMessage.ToString(); messageStr = messageStr.Replace("\r\n", ""); char[] splitTokens = new char[1]; splitTokens[0] = '='; messageDataTokens = messageStr.Split(splitTokens); String tpf = messageDataTokens[messageDataTokens.Length - 1].ToString(); String ver = messageDataTokens[messageDataTokens.Length - 3].ToString().Replace(",rn", ""); sessionTicket = getPassportTicket(tpf, ver); } #endregion #endregion #region final authentication (USR) #region USR 4 TWN S t=53*1hAu8ADuD3TEwdXoOMi08sD*2!cMrntTwVMTjoB3p6stWTqzbkKZPVQzA5NOt19SLI60PY!b8K4YhC!Ooo5ug$$&p=5eKBBC!yBH6ex5mftp!a9DrSb0B3hU8aqAWpaPn07iCGBw5akemiWSd7t2ot!okPvIR!Wqk!MKvi1IMpxfhkao9wpxlMWYAZ!DqRfACmyQGG112Bp9xrk04!BVBUa9*H9mJLoWw39m63YQRE1yHnYNv08nyz43D3OnMcaCoeSaEHVM7LpR*LWDme29qq2X3j8N\r\n outMessage = new MSNMessage("USR " + MSNTrIDGenerator.NextID() + " TWN S " + sessionTicket + "\r\n"); sw.send(outMessage); #endregion #region USR 4 OK [email protected] example%20display%20name 1 0\r\n inMessage = sw.recieve(); if (inMessage.getCommand().Equals("USR")) { String[] data = inMessage.getData(); if (data.Length >= 3) { initialFriendlyName = HttpUtility.UrlDecode(data[2]); } } if (!inMessage.getCommand().Equals("USR")) { throw new Exception("Unexpected command responce for USR in doAuthentication(" + address + ", " + port + ")"); } if (inMessage.getTrID() != outMessage.getTrID()) { throw new Exception("Unexpected TrID responce for USR in doAuthentication(" + address + ", " + port + ")"); } messageDataTokens = inMessage.getData(); if (messageDataTokens.Length != 5) { throw new Exception("Unexpected length data responce for USR in doAuthentication(" + address + ", " + port + ")"); } if (!messageDataTokens[0].Equals("OK")) { throw new Exception("Unknown failure to authentication for USR in doAuthentication(" + address + ", " + port + ")"); } if (!messageDataTokens[1].Equals(username)) { throw new Exception("Authenticated as incorrect user for USR in doAuthentication(" + address + ", " + port + ")"); } //############################################################################################################################# // AUTHENTICATION PASSED // AUTHENTICATION PASSED // AUTHENTICATION PASSED // AUTHENTICATION PASSED // AUTHENTICATION PASSED // //############################################################################################################################# return(sw); #endregion #endregion }
private String getPassportTicket(String ticketString, String version, String address) { char[] splitTokens = new char[2]; splitTokens[0] = '\\'; splitTokens[1] = '/'; #region process address String[] addressTokens = address.Split(splitTokens); String pageAddress = ""; for (int i = 1; i < addressTokens.Length; i++) { pageAddress += "/" + addressTokens[i]; } #endregion MSNSocketWrapper sw = new MSNSocketWrapper(addressTokens[0], 443, true); #region GET /login2.srf HTTP/1.1\r\n // Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=example%40passport.com,pwd=password,lc=1033,id=507,tw=40,fs=1,ru=http%3A%2F%2Fmessenger%2Emsn%2Ecom,ct=1062764229,kpp=1,kv=5,ver=2.1.0173.1,tpf=43f8a4c8ed940c04e3740be46c4d1619\r\n // Host: login.passport.com\r\n\r\n MSNMessage outMessage = new MSNMessage("GET " + pageAddress + " HTTP/1.1\r\n"); sw.send(outMessage); //outMessage = new Message("Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=" + HttpUtility.UrlEncode(username) + ",pwd=" + password + ",lc=1033,id=507,tw=40,fs=1,ru=http%3A%2F%2Fmessenger%2Emsn%2Ecom,ct=1062764229,kpp=1,kv=5,ver=2.1.0173.1,tpf=" + ticketString + "\r\n"); //outMessage = new Message("Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=" + HttpUtility.UrlEncode(username) + ",pwd=" + HttpUtility.UrlEncode(password) + ",lc=1033,id=507,tw=40,fs=1,ru=http%3A%2F%2Fmessenger%2Emsn%2Ecom,ct=1062764229,kpp=1,kv=5,ver=" + version + ",tpf=" + ticketString + "\r\n"); outMessage = new MSNMessage("Authorization: Passport1.4 OrgVerb=GET,OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom,sign-in=" + HttpUtility.UrlEncode(username) + ",pwd=" + HttpUtility.UrlEncode(password) + ",lc=1033,id=507,tw=40,fs=1,ver=" + version + ",tpf=" + ticketString + "\r\n"); sw.send(outMessage); outMessage = new MSNMessage("Host: login.passport.com\r\n\r\n"); sw.send(outMessage); #endregion #region process responce MSNMessage inMessage = sw.recieve(); if (inMessage.ToString().Equals("HTTP/1.1 302 Found\r\n") == false && inMessage.ToString().Equals("HTTP/1.1 200 OK\r\n") == false) { //throw new Exception("Incorrect username / password in getPassportTicket(" + ticketString + ", " + address + ")"); } while (inMessage.ToString().Equals("\r\n") != true) { inMessage = sw.recieve(); #region successful authentication if (inMessage.ToString().StartsWith("Authentication-Info:") && inMessage.ToString().Contains("da-status=success")) { //Authentication-Info: Passport1.4 da-status=success,tname=MSPAuth,tname=MSPProf,tname=MSPSec,from-PP='t=53*1hAu8ADuD3TEwdXoOMi08sD*2!cMrntTwVMTjoB3p6stWTqzbkKZPVQzA5NOt19SLI60PY!b8K4YhC!Ooo5ug$$&p=5eKBBC!yBH6ex5mftp!a9DrSb0B3hU8aqAWpaPn07iCGBw5akemiWSd7t2ot!okPvIR!Wqk!MKvi1IMpxfhkao9wpxlMWYAZ!DqRfACmyQGG112Bp9xrk04!BVBUa9*H9mJLoWw39m63YQRE1yHnYNv08nyz43D3OnMcaCoeSaEHVM7LpR*LWDme29qq2X3j8N',ru=http://messenger.msn.com\r\n splitTokens = new char[1]; splitTokens[0] = '\''; String[] messageDataTokens = inMessage.ToString().Split(splitTokens); for (int i = 0; i < messageDataTokens.Length; i++) { if (messageDataTokens[i].StartsWith("t=")) { return(messageDataTokens[i]); } } throw new Exception("Unknown authentication ticket in getPassportTicket(" + ticketString + ", " + address + ")"); } #endregion #region redirection if (inMessage.ToString().StartsWith("Location:")) { //Location: https://loginnet.passport.com/login2.srf?lc=1033\r\n return(getPassportTicket(ticketString, version, inMessage.ToString().Replace("Location: ", "").Replace("\r\n", ""))); } #endregion } #endregion throw new Exception("No ticket retrieved from getPassportTicket(" + ticketString + ", " + address); }
internal MSNSwitchboard(MSNController controller, String addressString, int addressPort, String authenticateString, List <String> initialUsers) //handles conversations started by local client { try { this.controller = controller; #region connect to switchboard try { switchboardSocket = new MSNSocketWrapper(addressString, addressPort, false); if (!switchboardSocket.connected()) { Console.WriteLine("Error making switchboard connection in MSNSwitchboard(" + controller.ToString() + ", " + addressString + ", " + addressPort + ", " + authenticateString + ", " + initialUsers.ToString() + ")"); throw new Exception("Could not connect to switchboard in MSNSwitchboard(" + controller.ToString() + ", " + addressString + ", " + addressPort + ", " + authenticateString + ", " + initialUsers.ToString() + ")"); } } catch (Exception) { Console.WriteLine("Error making switchboard connection in MSNSwitchboard(" + controller.ToString() + ", " + addressString + ", " + addressPort + ", " + authenticateString + ", " + initialUsers.ToString() + ")"); return; } #endregion #region authenticate //USR 7 [email protected] 189597.1056411784.29994\r\n switchboardSocket.send(new MSNMessage("USR " + MSNTrIDGenerator.NextID() + " " + controller.Username + " " + authenticateString + "\r\n")); #endregion #region add initial users //CAL 8 [email protected]\r\n if (initialUsers != null) { for (int i = 0; i < initialUsers.Count; i++) { switchboardSocket.send(new MSNMessage("CAL " + MSNTrIDGenerator.NextID() + " " + initialUsers[i] + "\r\n")); } } #endregion #region incommingMessageReadThread incommingMessageHandlerThread = new Thread(new ThreadStart(processIncommingMessageLoop)); incommingMessageHandlerThread.Name = "MSNSwitchboard incomming read thread"; incommingMessageHandlerThread.Start(); #endregion #region incommingMSGThread incommingMSGThread = new Thread(new ThreadStart(incommingMSGLoop)); incommingMSGThread.Name = "Incomming MSG handler thread"; incommingMSGThread.Start(); #endregion #region outgoingMSGThread outgoingMSGThread = new Thread(new ThreadStart(outgoingMSGLoop)); outgoingMSGThread.Name = "Outgoing MSG handler thread"; outgoingMSGThread.Start(); #endregion plugins.ElementAdded += new MSNListenableList <IMSNSwitchboardPlugin> .ElementAddedDelegate(plugins_ElementAdded); } catch (Exception) { //Console.WriteLine("Error establishing switchboard session in MSNSwitchboard(" + controller.ToString() + ", " + addressString + ", " + addressPort + ", " + authenticateString + ", " + initialUsers.ToString() + ")"); } }
internal void reconnect(String addressString, int addressPort, String authenticateString, String rngTrID) { try { activeUsers.Clear(); #region connect to switchboard try { switchboardSocket = new MSNSocketWrapper(addressString, addressPort, false); if (!switchboardSocket.connected()) { Console.WriteLine("Error making switchboard connection in MSNSwitchboard.reconnect(" + addressString + ", " + addressPort + ", " + authenticateString + ")"); throw new Exception("Could not connect to switchboard in MSNSwitchboard.reconnect(" + addressString + ", " + addressPort + ", " + authenticateString + ")"); } } catch (Exception) { Console.WriteLine("Error making switchboard connection in MSNSwitchboard.reconnect(" + addressString + ", " + addressPort + ", " + authenticateString + ")"); return; } #endregion #region authenticate //ANS 1 [email protected] 1056411141.26158 17342299\r\n switchboardSocket.send(new MSNMessage("ANS " + MSNTrIDGenerator.NextID() + " " + controller.Username + " " + authenticateString + " " + rngTrID + "\r\n")); #endregion #region incommingMessageReadThread try { incommingMessageHandlerThread.Abort(); } catch (Exception) { } incommingMessageHandlerThread = new Thread(new ThreadStart(processIncommingMessageLoop)); incommingMessageHandlerThread.Name = "MSNSwitchboard incomming read thread"; incommingMessageHandlerThread.Start(); #endregion #region incommingMSGThread try { incommingMSGThread.Abort(); } catch (Exception) { } incommingMSGThread = new Thread(new ThreadStart(incommingMSGLoop)); incommingMSGThread.Name = "Incomming MSG handler thread"; incommingMSGThread.Start(); #endregion #region outgoingMSGThread try { outgoingMSGThread.Abort(); } catch (Exception) { } outgoingMSGThread = new Thread(new ThreadStart(outgoingMSGLoop)); outgoingMSGThread.Name = "Outgoing MSG handler thread"; outgoingMSGThread.Start(); #endregion } catch (Exception) { Console.WriteLine("Error establishing switchboard session in MSNSwitchboard(" + controller.ToString() + ", " + addressString + ", " + addressPort + ", " + authenticateString + ")"); } }
internal void reconnect(String addressString, int addressPort, String authenticateString, List <String> initialUsers) { try { activeUsers.Clear(); #region connect to switchboard try { switchboardSocket = new MSNSocketWrapper(addressString, addressPort, false); if (!switchboardSocket.connected()) { Console.WriteLine("Error making switchboard connection in MSNSwitchboard(" + controller.ToString() + ", " + addressString + ", " + addressPort + ", " + authenticateString + ", " + initialUsers.ToString() + ")"); throw new Exception("Could not connect to switchboard in MSNSwitchboard(" + controller.ToString() + ", " + addressString + ", " + addressPort + ", " + authenticateString + ", " + initialUsers.ToString() + ")"); } } catch (Exception) { Console.WriteLine("Error making switchboard connection in MSNSwitchboard(" + controller.ToString() + ", " + addressString + ", " + addressPort + ", " + authenticateString + ", " + initialUsers.ToString() + ")"); return; } #endregion #region authenticate //USR 7 [email protected] 189597.1056411784.29994\r\n switchboardSocket.send(new MSNMessage("USR " + MSNTrIDGenerator.NextID() + " " + controller.Username + " " + authenticateString + "\r\n")); #endregion #region add initial users //CAL 8 [email protected]\r\n if (initialUsers != null) { for (int i = 0; i < initialUsers.Count; i++) { switchboardSocket.send(new MSNMessage("CAL " + MSNTrIDGenerator.NextID() + " " + initialUsers[i] + "\r\n")); } } #endregion #region incommingMessageReadThread try { incommingMessageHandlerThread.Abort(); } catch (Exception) { } incommingMessageHandlerThread = new Thread(new ThreadStart(processIncommingMessageLoop)); incommingMessageHandlerThread.Name = "MSNSwitchboard incomming read thread"; incommingMessageHandlerThread.Start(); #endregion #region incommingMSGThread try { incommingMSGThread.Abort(); } catch (Exception) { } incommingMSGThread = new Thread(new ThreadStart(incommingMSGLoop)); incommingMSGThread.Name = "Incomming MSG handler thread"; incommingMSGThread.Start(); #endregion #region outgoingMSGThread try { outgoingMSGThread.Abort(); } catch (Exception) { } outgoingMSGThread = new Thread(new ThreadStart(outgoingMSGLoop)); outgoingMSGThread.Name = "Outgoing MSG handler thread"; outgoingMSGThread.Start(); #endregion } catch (Exception) { Console.WriteLine("Error establishing switchboard session in MSNSwitchboard(" + controller.ToString() + ", " + addressString + ", " + addressPort + ", " + authenticateString + ", " + initialUsers.ToString() + ")"); } }