/// <summary>
        /// </summary>
        /// <param name="e"> </param>
        public override void Parse(Node e)
        {
            if (e.GetType() == typeof (Challenge))
            {
                var c = e as Challenge;

                var step1 = new Step1(c.TextBase64);
                if (step1.Rspauth == null)
                {
                    // response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">dXNlcm5hbWU9ImduYXVjayIscmVhbG09IiIsbm9uY2U9IjM4MDQzMjI1MSIsY25vbmNlPSIxNDE4N2MxMDUyODk3N2RiMjZjOWJhNDE2ZDgwNDI4MSIsbmM9MDAwMDAwMDEscW9wPWF1dGgsZGlnZXN0LXVyaT0ieG1wcC9qYWJiZXIucnUiLGNoYXJzZXQ9dXRmLTgscmVzcG9uc2U9NDcwMTI5NDU4Y2EwOGVjYjhhYTIxY2UzMDhhM2U5Nzc
                    var s2 = new Step2(step1, base.Username, base.Password, base.Server);
                    var r = new Response(s2.ToString());
                    //base.XmppClientConnection.Send(r);
                }
                else
                {
                    // SEND: <response xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>
                    //base.XmppClientConnection.Send(new Response());
                }
            }
        }
        private void ProcessResponse(XmppStream stream, Response response, XmppHandlerContext context)
        {
            AuthData authStep;
            lock (authData)
            {
                authData.TryGetValue(stream.Id, out authStep);
            }

            if (authStep == null)
            {
                context.Sender.SendToAndClose(stream, XmppFailureError.TemporaryAuthFailure);
                return;
            }

            if (authStep.Step == AuthStep.Step1)
            {
                var challenge = ProcessStep1(stream, response, context);
                if (challenge != null)
                {
                    context.Sender.SendTo(stream, challenge);
                    authStep.DoStep();
                }
                else
                {
                    context.Sender.SendToAndClose(stream, XmppFailureError.NotAuthorized);
                }
            }
            else if (authStep.Step == AuthStep.Step2)
            {
                var success = ProcessStep2(stream, response, context);
                context.Sender.SendTo(stream, success);
            }
            else
            {
                context.Sender.SendToAndClose(stream, XmppFailureError.TemporaryAuthFailure);
            }
        }
 private Success ProcessStep2(XmppStream stream, Response response, XmppHandlerContext ctx)
 {
     lock (authData)
     {
         stream.Authenticate(authData[stream.Id].UserName);
         authData.Remove(stream.Id);
     }
     ctx.Sender.ResetStream(stream);
     return new Success();
 }
        private Challenge ProcessStep1(XmppStream stream, Response response, XmppHandlerContext ctx)
        {
            var step = new Step2(response.TextBase64);
            var userName = step.Username;
            var user = ctx.UserManager.GetUser(new Jid(userName, stream.Domain, null));

            log.DebugFormat("User {0} {1}. Realm={2}", userName, user == null ? "not found" : user.ToString(), step.Realm);

            if (user != null && string.Compare(stream.Domain, step.Realm, StringComparison.OrdinalIgnoreCase) == 0)
            {
                if (step.Authorize(userName, user.Password))
                {
                    log.DebugFormat("User authorized");
                    lock (authData)
                    {
                        authData[stream.Id].UserName = userName;
                    }
                    var challenge = new Challenge();
                    challenge.TextBase64 = string.Format("rspauth={0}", step.CalculateResponse(userName, user.Password, string.Empty));
                    return challenge;
                }
                else
                {
                    log.DebugFormat("User not authorized");
                }
            }
            return null;
        }
Example #5
0
        private void ProcessResponse(XmppStream stream, Response response, XmppHandlerContext context)
        {
            AuthData authStep;
            lock (authData)
            {
                authData.TryGetValue(stream.Id, out authStep);
            }

            if (authStep == null)
            {
                context.Sender.SendToAndClose(stream, XmppFailureError.TemporaryAuthFailure);
                return;
            }
            if (!authStep.IsPlain)
            {
                if (authStep.Step == AuthStep.Step1)
                {
                    var challenge = ProcessStep1(stream, response, context);
                    if (challenge != null)
                    {
                        context.Sender.SendTo(stream, challenge);
                        authStep.DoStep();
                    }
                    else
                    {
                        context.Sender.SendToAndClose(stream, XmppFailureError.NotAuthorized);
                    }
                }
                else if (authStep.Step == AuthStep.Step2)
                {
                    var success = ProcessStep2(stream, response, context);
                    context.Sender.SendTo(stream, success);
                }
                else
                {
                    context.Sender.SendToAndClose(stream, XmppFailureError.TemporaryAuthFailure);
                }
            }
            else
            {
                if (authStep.IsAuth)
                {
                    lock (authData)
                    {
                        stream.Authenticate(authData[stream.Id].UserName);
                        authData.Remove(stream.Id);
                    }
                    log.DebugFormat("User authorized");
                    context.Sender.ResetStream(stream);
                    context.Sender.SendTo(stream, new Success());
                }
                else
                {
                    log.DebugFormat("User not authorized");
                    context.Sender.SendTo(stream, new Failure(FailureCondition.not_authorized));
                }
            }
        }