Not logged in. · Lost password · Register
Forum: MatriX RSS
Avatar
royamit281 #1
Member since Jul 2011 · 3 posts
Group memberships: Members
Show profile · Link to this post
Subject: Authentication of Chat client using MatriX
Dear Alex,

I am totaly new to XMPP. I am a Student and need to submit a project to my collage . i have googled through and found the MAtriX is the only SDK available for developing any XMPP based application / Client / Server .

I have downloaded your sample and tested the Client with the Google , client working extremely fine.

Thanks for the Great Example  and Supports for the new Developers / Students who wat to learn XMPP.

I have gone throug the Forum for one of my issuse , i didnt found any solution.

I am developing a small Chat server with different moblie clients , i have found to samples code one for Android and second for iPhone.

and i have also gone through with your agsXMPP server sample , i have stucked in one place.

when ever a client is connected to the server it sends the authentication , instead of password it sends digest (as MD5 or SAH1).


I have also gone through one of ur solution for the same post and u have provided some explanation .

i didnt got the point .

I will be really gratefull to u if u can provide me some help.
Avatar
Alex #2
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
The authentication is described here in the RFC's http://xmpp.org/rfcs/rfc6120.html#sasl
I suggest to advertise only the SASL PLAIN mechanism first. SASL PLAIN is very easy to implement because it sends only Base64(char(0) + username + char(0) + password). All existing clients should support SASL PLAIN.

Alex
Avatar
royamit281 #3
Member since Jul 2011 · 3 posts
Group memberships: Members
Show profile · Link to this post
Hi,

i did a try and my client is sending :

<iq id="7JTNw-22" type="set" xmlns="jabber:client">
  <query xmlns="jabber:iq:auth">
    <username>royamit218</username>
    <digest>c3b6c99b79858c3b4defd3bd3c59902eaff6f7f0</digest>
    <resource>test</resource>
  </query>
</iq>

IPhone

<iq type="set" xmlns="jabber:client">
  <query xmlns="jabber:iq:auth">
    <username>viral.vora@quipment.in</username>
    <resource>5DF6546D-57E3-4FBF-B7F7-675BE868A8EE</resource>
    <digest>cbc509c9264d19d40408bbd160633ff414c065c7</digest>
  </query>
</iq>


In this the XML which i am receiving from one of the android and iPhone chat client.

my actual password is QUip@2011

and when i try to Decrypet using



public static string Sha1HashHex(string pass)
        {
            var hash = Sha1HashBytes(pass);
            return HexToString(hash);
        }
       
        public static byte[] Sha1HashBytes(string pass)
        {
            var bytes = Encoding.UTF8.GetBytes(pass);
            return Sha1HashBytes(bytes);
        }
       
        public static byte[] Sha1HashBytes(byte[] pass)
        {
            using (var sha = new SHA1Managed())
            {
                return sha.ComputeHash(pass);
            }
        }

        public static string HexToString(byte[] buf)
        {
            var sb = new StringBuilder();
            foreach (byte b in buf)
            {
                sb.Append(b.ToString("x2"));
            }
            return sb.ToString();
        }


the output is ad4b7601d2f17e10808c28531c682ee0eea321be.

Android : c3b6c99b79858c3b4defd3bd3c59902eaff6f7f0
iPhone :  a89cee6d3c862470746ed5aed4958d85349d736d


And both the above keys are different from different clients.


i have passed only the password to the method (Sha1HashHex).

i have took this code from the forum. some one has the same issue. and u have also specified that we have to use the stream id + password .

And i am also confused why the Digests for two clients are different as the password is same for the clients

Can u please provide me any code samples / Guidence so that i can achive  this.
Avatar
Alex #4
Member since Feb 2003 · 4297 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
your client is sending the old obsoleted Non-SASL Authentication.
Its either doing this because your server code has bugs or the client has bugs.
Please try other existing clients, I would prefer desktop clients to get started.

Alex
Avatar
royamit281 #5
Member since Jul 2011 · 3 posts
Group memberships: Members
Show profile · Link to this post
Thanks ,


But both the client is working perfectly with GTalk

My Server Code:

if (iq.Query.GetType() == typeof(Auth))
            {
                Auth auth = iq.Query as Auth;
                switch (iq.Type)
                {
                    case IqType.get:
                        ////if(usersCollection.ContainsKey(auth.Username) && usersCollection[auth.Username] == auth.Password)
                        {
                            iq.SwitchDirection();
                            iq.Type = IqType.result;
                            auth.Add(new XmppXElement("Password"));
                            auth.Add(new XmppXElement("digest"));
                            Send(iq.ToString(false));                        
                         }
                            break;
                        }

                    case IqType.set:
                        // Here we should verify the authentication credentials
                       
                        isWorkerRunning = false;
                        if (this.objChatServerDAL.VerifyChatUser(auth.Username.Trim(), auth.Digest.Trim()))
                        {
                            isWorkerRunning = false;
                            if (!ChatServerSettings.activeSocketCollection.ContainsKey(auth.Username.Trim()))
                            {
                                ChatServerSettings.activeSocketCollection.Add(auth.Username.Trim(), this.mainSock);
                            }
                            else
                            {
                                //// Re assign the Socket in Case the Socket get Disposed.
                                ChatServerSettings.activeSocketCollection[auth.Username.Trim()] = this.mainSock;
                                if (DisplayData != null)
                                {
                                    DisplayData("\r\n");
                                    DisplayData("NOTIFICATION : Reassigning the Socket");
                                }

                                Logger.Log("Reassigning the Socket : ");
                            }
                            this.contactList = this.objChatServerDAL.GetAllEntityList(auth.Username.Trim());
                            iq.SwitchDirection();
                            iq.Type = IqType.result;
                            iq.Query = null;
                            Send(iq.ToString(false));
                            isWorkerRunning = true;
                        }
                        else
                        {
                            AuthIq Authiq = new AuthIq()
                            {
                                Error = new Error()
                                {
                                    Condition = Matrix.Xmpp.Base.ErrorCondition.NotAuthorized,
                                    Type = Matrix.Xmpp.Base.ErrorType.auth
                                },                               
                                From = "ChatServer",
                                To = iq.To
                            };
                            Send(Authiq.ToString(false));
                            if (DisplayData != null)
                            {
                                DisplayData("\r\n");
                                DisplayData("SEND : " + "Not Authorized User : " + auth.Username);
                            }

                            Logger.Log("Not Authorized User : " + auth.Username);

                        }
                        break;
                }

            }
            else if (iq.Query.GetType() == typeof(Roster))
            {
                ProcessRosterIQ(iq, id);
            }

I have also tried your client sample its not sending digest instead of it its is sending a plain password
Avatar
roymanish1982 #6
Member since Mar 2011 · 20 posts
Group memberships: Members
Show profile · Link to this post
Dear Alex,

Can u please suggest some way to overcome this issue.
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Forum: MatriX RSS