Ejemplo n.º 1
0
            private void ProcessAuth(agsXMPP.protocol.sasl.Auth auth)
            {

                this.clientMechanismType = auth.MechanismType;
                if (this.clientMechanismType == agsXMPP.protocol.sasl.MechanismType.PLAIN)
                {
                    string tempAuth = auth.TextBase64;

                    string[] authInfo = tempAuth.Split(new char[] { '\0' });

                    System.Collections.Generic.List<string> infos = new System.Collections.Generic.List<string>();
                    foreach (string strTemp in authInfo)
                    {
                        if (strTemp != string.Empty)
                        {
                            infos.Add(strTemp);
                        }
                    }

                    Jid tempJID = new Jid(infos[0]);
                    string strUserName = null;
                    if (tempJID.User == null)
                    {
                        strUserName = tempJID.Server;
                    }
                    else
                    {
                        strUserName = tempJID.User;
                    }

                    string strPassword = infos[1];

                    foreach (Account account in m_Server.AccountManager.Accounts)
                    {

                        if (account.UserID != strUserName)
                        {
                            continue;
                        }

                        if (account.Password == strPassword)
                        {
                            m_AuthenticatedClient = true;

                            this.m_ClientAccount = account;

                            break;
                        }

                        break;
                    }

                    if (this.m_AuthenticatedClient)
                    {
                        agsXMPP.protocol.sasl.Success success = new agsXMPP.protocol.sasl.Success();
                        Send(success);
                        m_StreamParser.Reset();
                    }
                    else
                    {
                        StringBuilder sb = new StringBuilder();
                        agsXMPP.protocol.sasl.Failure failure = new agsXMPP.protocol.sasl.Failure();
                        failure.AddTag("not-authorized");
                        sb.Append(failure.ToString());

                        Send(sb.ToString());

                        sb.Remove(0, sb.Length);
                        sb.Append("</stream:stream>");

                        Send(sb.ToString());

                        EndClientConnection();


                    }
                    return;

                }

                agsXMPP.protocol.sasl.Challenge challenge = new agsXMPP.protocol.sasl.Challenge();
                challenge.TextBase64 = "realm=\"" + "localhost" + "\",nonce=\"OA6MG9tEQGm2hh\",qop=\"auth\",charset=utf-8,algorithm=md5-sess";
                Send(challenge);
            }
Ejemplo n.º 2
0
            //private bool SendToAllResource(Account account, Element msg)
            //{
            //    bool bSend = false;
            //    if (this.m_Server.ClientConnections.ContainsKey(account))
            //    {
            //        Dictionary<string, XmppSeverConnection> connections = this.m_Server.ClientConnections[account];
            //        foreach (KeyValuePair<string, XmppSeverConnection> connection in connections)
            //        {
            //            bSend = true;
            //            connection.Value.Send(msg);
            //        }
            //    }

            //    return bSend;
            //}

            private void ProcessResponse(agsXMPP.protocol.sasl.Response response)
            {
                string strResponse = response.TextBase64.Trim();

                if (strResponse == string.Empty)
                {
                    agsXMPP.protocol.sasl.Success success = new agsXMPP.protocol.sasl.Success();
                    Send(success);
                    m_StreamParser.Reset();

                    m_AuthenticatedClient = true;

                    //if (this.OnClientStart != null)
                    //{
                    //    this.OnClientStart(this.m_ClientAccount, this);
                    //}

                }
                else
                {
                    if (!this.m_AuthenticatedClient && this.clientMechanismType == agsXMPP.protocol.sasl.MechanismType.DIGEST_MD5)
                    {
                        agsXMPP.sasl.DigestMD5.Step2 step2 = new agsXMPP.sasl.DigestMD5.Step2(strResponse);
                        string strOldResponse = step2.Response;
                        foreach (Account account in m_Server.AccountManager.Accounts)
                        {
                            //this.m_Server.ClientConnections[account] = 
                            if (step2.Username == account.UserID.ToLower())
                            {
                                step2.Password = account.Password;
                                step2.GenerateResponse();
                                string strNewResponse = step2.Response;

                                if (strOldResponse == strNewResponse)
                                {
                                    agsXMPP.protocol.sasl.Challenge challenge = new agsXMPP.protocol.sasl.Challenge();
                                    challenge.TextBase64 = "rspauth=ea40f60335c427b5527b84dbabcdfffd";
                                    Send(challenge);

                                    this.m_ClientAccount = account;

                                    return;
                                }
                                else
                                {
                                    StringBuilder sb = new StringBuilder();

                                    agsXMPP.protocol.sasl.Failure failure = new agsXMPP.protocol.sasl.Failure();
                                    failure.AddTag("not-authorized");
                                    sb.Append(failure.ToString());

                                    Send(sb.ToString());

                                    sb.Remove(0, sb.Length);
                                    sb.Append("</stream:stream>");

                                    Send(sb.ToString());

                                    EndClientConnection();

                                    return;

                                }
                            }
                        }
                    }
                    else
                    {

                    }
                }

            }