コード例 #1
0
        private void processIncommingXFR()
        {
            while (incommingXFRQueue.Count > 0)
            {
                MSNMessage message = incommingXFRQueue.Dequeue();

                try
                {
                    #region process command
                    //XFR 12 SB 207.46.26.161:1863 CKI 1790215149.6727142.1184104\r\n
                    String        address      = message.getData()[1].Replace(":1863", "");
                    int           port         = 1863;
                    String        authCode     = message.getData()[3].ToString();
                    String        trID         = message.getTrID().ToString();
                    List <String> initialUsers = newConversationContacts[trID.ToString()];
                    #endregion

                    #region try to find existing switchboard to connect to
                    MSNSwitchboard existingAddTo = null;
                    for (int i = 0; i < activeSwitchboards.Count; i++)
                    {
                        MSNSwitchboard testSwitchboard  = (MSNSwitchboard)activeSwitchboards[i];
                        List <String>  switchboardUsers = testSwitchboard.getConnectedUsers();

                        #region test initial users = switchboardUsers
                        int checkCounter = 0;
                        for (int x = 0; x < initialUsers.Count; x++)
                        {
                            for (int y = 0; y < switchboardUsers.Count; y++)
                            {
                                if (initialUsers[x].Equals(switchboardUsers[y].ToString()))
                                {
                                    checkCounter++;
                                }
                            }
                        }

                        bool usersEqual = false;
                        if (initialUsers.Count == switchboardUsers.Count && checkCounter == initialUsers.Count)
                        {
                            usersEqual = true;
                        }
                        #endregion

                        if (usersEqual)
                        {
                            existingAddTo = testSwitchboard;
                            existingAddTo.reconnect(address, port, authCode, initialUsers);

                            if (SwitchboardReCreated != null)
                            {
                                SwitchboardReCreated(existingAddTo);
                            }
                        }
                    }
                    #endregion

                    #region build switchboard (and load plugins) if no existing switchboard
                    if (existingAddTo == null)
                    {
                        MSNSwitchboard s = new MSNSwitchboard(controller, address, port, authCode, initialUsers);

                        activeSwitchboards.Add(s);

                        if (SwitchboardCreated != null)
                        {
                            SwitchboardCreated(s);
                        }
                    }
                    #endregion
                }
                catch (Exception)
                {
                    Console.WriteLine("Error processing XFR message in MSNSwitchboardController.processXFR(), message = " + message.ToString());
                }
            }
        }
コード例 #2
0
ファイル: MSNAuthentication.cs プロジェクト: zethon/remindme
        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
        }
コード例 #3
0
        private void processIncommingRNG()
        {
            while (incommingRNGQueue.Count > 0)
            {
                MSNMessage message = incommingRNGQueue.Dequeue();

                try
                {
                    #region process command
                    //RNG 11752013 207.46.108.38:1863 CKI 849102291.520491113 [email protected] Example%20Name\r\n
                    String   address      = message.getData()[0].Replace(":1863", "");
                    int      port         = 1863;
                    String   authCode     = message.getData()[2];
                    String   rngTrID      = message.getTrID().ToString();
                    String[] initialUsers = new String[] { message.getData()[3] };
                    #endregion

                    #region try to find existing switchboard to connect to
                    MSNSwitchboard existingAddTo = null;
                    for (int i = 0; i < activeSwitchboards.Count; i++)
                    {
                        MSNSwitchboard testSwitchboard  = (MSNSwitchboard)activeSwitchboards[i];
                        List <String>  switchboardUsers = testSwitchboard.getConnectedUsers();

                        #region test initial users = switchboardUsers
                        int checkCounter = 0;
                        for (int x = 0; x < initialUsers.Length; x++)
                        {
                            for (int y = 0; y < switchboardUsers.Count; y++)
                            {
                                if (initialUsers[x].Equals(switchboardUsers[y].ToString()))
                                {
                                    checkCounter++;
                                }
                            }
                        }

                        bool usersEqual = false;
                        if (initialUsers.Length == switchboardUsers.Count && checkCounter == initialUsers.Length)
                        {
                            usersEqual = true;
                        }
                        #endregion

                        if (usersEqual)
                        {
                            existingAddTo = testSwitchboard;
                            existingAddTo.reconnect(address, port, authCode, rngTrID);

                            if (SwitchboardReCreated != null)
                            {
                                SwitchboardReCreated(existingAddTo);
                            }
                        }
                    }
                    #endregion

                    #region build switchboard (and load plugins) if no existing switchboard found
                    if (existingAddTo == null)
                    {
                        MSNSwitchboard s = new MSNSwitchboard(controller, address, port, authCode, rngTrID);

                        activeSwitchboards.Add(s);

                        if (SwitchboardCreated != null)
                        {
                            SwitchboardCreated(s);
                        }
                    }
                    #endregion
                }
                catch (Exception)
                {
                    Console.WriteLine("Error processing RNG message in MSNSwitchboardController.processRNG(), message = " + message.ToString());
                }
            }
        }