Exemplo n.º 1
0
        private void HandleUsrS(NotificationConnection c, Command cmd)
        {
            Md5AuthDetails auth       = c.AuthDetails as Md5AuthDetails;
            String         chResponse = cmd.Params[2];

            if (auth == null)
            {
                // ordinarily that would be an Exception condition
                Command response = new Command(Error.AuthenticationFailed, cmd.TrId);
                Server.Send(c, response);
            }
            else
            {
                User user;
                if (AuthenticationService.AuthenticateMd5(auth.UserHandle, auth.Challenge, chResponse, out user) == AuthenticationResult.Success)
                {
                    Command responseOk = new Command(Verb.Usr, cmd.TrId, "OK", user.UserHandle, user.FriendlyName);
                    Server.Send(c, responseOk);

                    ///////////////////////////////////////
                    // The client will now send SYN

                    // create a session, which is implicit; just bind the user to the connection
                    user.Status             = Status.Hdn;         // no-longer NLN
                    user.NotificationServer = Server;

                    c.User = user;
                }
                else
                {
                    Command responseFail = new Command(Error.AuthenticationFailed, cmd.TrId);
                    Server.Send(c, responseFail);
                }
            }
        }
Exemplo n.º 2
0
        private void HandleUsrS(DispatchConnection c, Command cmd)
        {
            Md5AuthDetails auth       = c.AuthDetails as Md5AuthDetails;
            String         chResponse = cmd.Params[2];

            if (auth == null)
            {
                // ordinarily that would be an Exception condition
                Command response = new Command(Error.AuthenticationFailed, cmd.TrId);
                Server.Send(c, response);
            }
            else
            {
                User user;
                if (AuthenticationService.AuthenticateMd5(auth.UserHandle, auth.Challenge, chResponse, out user) == AuthenticationResult.Success)
                {
                    Command responseOk = new Command(Verb.Usr, cmd.TrId, "OK", user.UserHandle, user.FriendlyName);
                    Server.Send(c, responseOk);

                    /////////////////////////////
                    // Send XFR, otherwise client will use this Dispatch server as a notification server (it starts by sending SYN)
                    // note that the official client deviates from the IETF draft by requiring an additional "0" parameter on the XFR command

                    // curiously, it seems MSN Messenger 1.x caches the last Notification server and reconnects to it directly
                    // in which case you don't send an XFR and instead begin the rest of an NS server's duties

                    String sendTo = NotificationServer.Instance.GetEndPointForClient(c.Socket.LocalEndPoint).ToString();

                    Command responseXfr = new Command(Verb.Xfr, cmd.TrId, "NS", sendTo, "0");
                    Server.Send(c, responseXfr);
                }
                else
                {
                    Command response = new Command(Error.AuthenticationFailed, cmd.TrId);
                    Server.Send(c, response);
                }
            }
        }