SASL: Bad Protocol

May 26, 2012 at 3:18 PM

Hi,

When I connect to a Server, the last message, I receive:

 

<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
    <bad-protocol /> 
</failure>

 

The Library tried to connect with MD5, what is supported by the server.

Received from Server:

 

<stream:features><mechanisms 
xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
<mechanism>PLAIN</mechanism>
<mechanism>DIGEST-MD5</mechanism>
<mechanism>SCRAM-SHA-1</mechanism>
</mechanisms>
<c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.process-one.net/en/ejabberd/' ver='o8zQAtrb2wELMmZizvbnpvqp5cE='/>
<register xmlns='http://jabber.org/features/iq-register'/>
</stream:features>

Sent to Server:
<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="DIGEST-MD5" />

 

If I force the Library to authenticate via PLAIN (by changing the source code), it can successfully connect to a server.
But after, it doesn't receive and send anything, RosterItems.Count = 0 and I cant see the user in the online list.

Also the OnXMLSent-Event never gets fired.

I don't know, wheres my mistake.
This is my relevant code:

 

        private void InitializeXMPPClient()
        {
            XMPPClient = new XMPPClient();

            XMPPClient.UserName = "berttester";
            XMPPClient.Password = "test";
            XMPPClient.Server = "jabber.ccc.de";
            XMPPClient.Domain = "jabber.ccc.de";
            XMPPClient.Resource = Guid.NewGuid().ToString();
            XMPPClient.Port = 5223;

            XMPPClient.OnServerDisconnect += new EventHandler(XMPPClient_OnServerDisconnect);
            XMPPClient.OnXMLSent +=new System.Net.XMPP.XMPPClient.DelegateString(XMPPClient_OnXMLSent);
            XMPPClient.OnXMLReceived += new System.Net.XMPP.XMPPClient.DelegateString(XMPPClient_OnXMLReceived);
            XMPPClient.JingleSessionManager.OnNewSession += new System.Net.XMPP.Jingle.JingleSessionManager.DelegateJingleSessionEventWithInfo(JingleSessionManager_OnNewSession);
            XMPPClient.OnStateChanged += new EventHandler(XMPPClient_OnStateChanged);
            XMPPClient.OnRetrievedRoster += new EventHandler(XMPPClient_OnRetrievedRoster);
           
            XMPPClient.UseOldStyleTLS = true;
            XMPPClient.UseTLS = true;

            XMPPClient.AutoAcceptPresenceSubscribe = false;
            XMPPClient.AutomaticallyDownloadAvatars = false;
            XMPPClient.RetrieveRoster = true;
            XMPPClient.AutoReconnect = true;
            
        }


        void XMPPClient_OnStateChanged(object sender, EventArgs e)
        {
            
            switch (XMPPClient.XMPPState)
            {
                case XMPPState.Ready:
                    XMPPClient.PresenceStatus.PresenceType = PresenceType.available;
                    XMPPClient.PresenceStatus.Status = "online";
                    XMPPClient.PresenceStatus.PresenceShow = PresenceShow.chat;
                    XMPPClient.UpdatePresence();
                    Dispatcher.BeginInvoke(delegate
                    {
                        this.ledState.Fill = cGreen;
                        this.button1.Content = "Trennen";
                    });
                    break;
                case XMPPState.Unknown:
                case XMPPState.AuthenticationFailed:
                    Dispatcher.BeginInvoke(delegate
                    {
                        this.ledState.Fill = cRed;
                        this.button1.Content = "Verbinden";
                    });
                    break;
                default:
                    Dispatcher.BeginInvoke(delegate
                    {
                        this.ledState.Fill = cYellow;
                    });
                    break;
           }
       }

        void XMPPClient_OnXMLReceived(XMPPClient client, string strXML)
        {
            Dispatcher.BeginInvoke(delegate
            {                
                this.tbReceived.Text = strXML;                
            });
        }



        void XMPPClient_OnXMLSent(XMPPClient client, string strXML)
        {
            Dispatcher.BeginInvoke(delegate
            {
                tbSent.Text = strXML;
            });
        }

 

 

 

Coordinator
Jun 7, 2012 at 7:07 AM

There were several bugs in the implementation, and we didn't have an ejabberd test server.  The latest code should fix the issues.  To summarize the problems:

  • The XMPP stream had to be reinitialized after SASL in addition to after TLS (new <stream..> stanza)
  • ejabberd sends a rspauth command in the digest flow that needed to be responded to.
  • ejabberd needed a "session" iq to be sent after the bind - other servers didn't need this.

 

After these changes I was able to log into an ejabberd server using TLS and port 5222.  Reinitializing the stream after SASL also fixed a problem on google talk where you had to connect to port 5223 old method in order to get it to work.  You can now connect to 5222 there.

The latest code is checked in, still need to perform a binary release. 

Thanks for the input, helped fix some major bugs in the implementation

Jun 7, 2012 at 8:46 AM

Hi, thanks a lot for your work and your answer. I can confirm, that it's working now.

A litte problem I had, because the ObservableCollectionEx (which implements a ToArray()-Method) is not compiled for Windows Phone, but Roster.cs need this Method.

My quick workarround was to implement a custom ToArray-Function for a normal ObservableCollection.

        private RosterItemPresenceInstance[] ToArray(ObservableCollection<RosterItemPresenceInstance> list) {
            RosterItemPresenceInstance[] array = new RosterItemPresenceInstance[list.Count];
            for (int i = 0; i < list.Count; i++)
            {
                array[i] = list[i];
            }
            return array;
        }

Maybe you did not compiled / tested it in a Windows Phone Environment?

But nevertheless it works absolutely perfect now. The Windows Phone Client of our school project is saved!
Thanks!

Coordinator
Jun 7, 2012 at 4:09 PM

Glad it's working, and thanks for the suggestion. 

I actually removed the ToArray() method and put the code back to enumerating the actual collection.  I had a lock issue before and that was an attempt to fix it, though the problem was found somewhere else.

 

Brian.

Aug 14, 2013 at 2:24 PM
HI,

Kindly help me to connection code for non ssl server on 5222 port. if it possible provide me xmpp library for windows phone .

Thanks in advance