Tuesday 19 June 2012

XMPP Plain Authentication

All of the communication between clientand server are done by passing XML. So it is important to getknowledge about XML first. Following are the links to get hands onXML.

For authenticating user to the xmppserver. Client needs to open a stream. XMPP works on stream base.

A stream is a sequence of data ofundetermined length. It's called a stream because it's like a streamof water that continues to flow. There's no definite end to it.

A better analogy might be a queue ofpeople waiting to get on a ride at an amusement park. As people areprocessed at the front (i.e. get on the roller coaster) more areadded at the back of the line. If it's a slow day the roller coastermay catch up with the end of the line and have to wait for people toboard. Other days there may always be people in line until the parkcloses. Each person is a discrete individual and must be put on theroller coaster or not put on the roller coaster. There are nohalf-people. There's always a definite number of people in linethough this number may change from moment to moment as people enterat the back of the line and exit from the front of the line. Althoughall the people are discrete, you'll sometimes have a family that mustbe put together in the same car. Thus although the individuals arediscrete, they aren't necessarily unrelated.

In Java a stream is composed ofdiscrete bytes. The bytes may represent chars or other kinds of data.They may come faster than you can handle them, or your thread mayblock while waiting for the next one to arrive. It often doesn'tmatter.

To open a stream in XMPP user needs tosend following XML to the server. Here because of you are using itwith client application it is necessary to ass jabber:client inxmlns.
<?xml version='1.0'?>

<stream:stream to='{server name}' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>
Server would open a stream for thatclient. Server must notify client with opened stream. If the streamhas been opened successfully. Server will also send starttls."starttls" is basically being used for securing thecommunication client-server.
      <xml encoding='UTF-8'version='1.0'></xml>

<stream:stream id='95360e39'from='{server name}' version='1.0' xml:lang='en' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'>

</stream:stream>

<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'>
</starttls>
Server will also send details aboutmethods of communication which is called stream-features. All of thestream features are explained in details athttp://xmpp.org/registrar/stream-features.html. Following are someexamples of the stream-features.
      <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
<mechanism>DIGEST-MD5</mechanism>
<mechanism>PLAIN</mechanism>
<mechanism>ANONYMOUS</mechanism>
<mechanism>CRAM-MD5</mechanism>
</mechanisms>

<compression xmlns='http://jabber.org/features/compress'>
<method>zlib</method>
</compression>

<auth xmlns='http://jabber.org/features/iq-auth'></auth>

<register xmlns='http://jabber.org/features/iq-register'></register>

<stream:features>

<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'></starttls>
<mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
<mechanism>DIGEST-MD5</mechanism>
<mechanism>PLAIN</mechanism>
<mechanism>ANONYMOUS</mechanism>
<mechanism>CRAM-MD5</mechanism>
</mechanisms>

<compression xmlns='http://jabber.org/features/compress'>
<method>zlib</method>
</compression>

<auth xmlns='http://jabber.org/features/iq-auth'></auth>

<register xmlns='http://jabber.org/features/iq-register'></register>

</stream:features>
In my case i have been using plainauthentication. For that you need to make sure that server is enabledto use plain authentication. This detail would have been given inmechanism XML in stream-features. Auth XML needs to have base64 valueof (username + password). As given below.
      <auth id='sasl2' xmlns="urn:ietf:params:xml:ns:xmpp-sasl"mechanism="PLAIN">"\0" + username + "\0"+ password</auth>
if user gets logged in successfully.Client will get a success XML in return. If authentication will befailed on server side. It will send back a failure XML. Examples aregiven below
 <success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'></success>  
<not-authorized></not-authorized>

<failure xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
<not-authorized></not-authorized>
</failure>

Wednesday 6 June 2012

Chat Application Protocol Suggestion


        Using XMPP is the easiest way toimplement chat application for any of the platform. There are manyoptions available in market which can be used to develop a chatapplication. There are many limitations and drawbacks of using someother protocol for chatting.

        Following are some of the benefits ofusing XMPP.

Decentralization

        The architecture of the XMPP network is similar to email; anyone canrun their own XMPP server and there is no central master server.
Open standards
        TheInternetEngineering Task Force hasformalized XMPP as an approved instant messaging and presencetechnology under the name of XMPP (the latest specifications are RFC6120 andRFC6121).No royalties are required to implement support of thesespecifications and their development is not tied to a single vendor.
History
        XMPP technologies have been in usesince 1999. Multiple implementations of the XMPP standards exist forclients, servers, components, and code libraries.
Security
        XMPPservers can be isolated from the public XMPP network (e.g., on acompany intranet), and strong security (via SASLandTLS)has been built into the core XMPP specifications.
Flexibility
        Custom functionality can be builton top of XMPP; to maintain interoperability, common extensions aremanaged by the XMPP Software Foundation. XMPP applications beyond IMinclude groupchat, network management, content syndication,collaboration tools, file sharing, gaming, remote systems control andmonitoring, geolocation, middleware and cloud computing, VoIP andIdentity services.
Integration
        Most of the chatting applicationprovider are exposing their service as XMPP. So it is easy tointegrate your application with others. As you are using standardprotocol, any customer who ask you for application. You can easilymarket it. As well you can provide specifications to them. That willcut off your cost of development also.

Following link contains list ofall XMPP server providers.
XMPPServer http://xmpp.org/xmpp-software/servers/

References have been taken from wikipedia.