You're reading from Linux Networking Cookbook
The Extensible Messaging and Presence Protocol (XMPP) is a widely implemented open protocol for passing XML messages. It was initially created as an instant messaging platform, but it has since been used by TiVo for communication between their set-top devices and their online scheduler, implemented by Google as Google Talk (since replaced by the non-XMPP Hangouts) and as an interface for Facebook's chat.
In this chapter, we'll learn to set up the ejabberd IM platform for use as your own IM service. We'll leverage XMPP's server-to-server federation to be able to exchange messages with other public XMPP systems and secure the traffic with TLS.
Currently there are a number of Open Source XMPP/Jabber server projects available with their own individual strengths and weaknesses. For this chapter, we're going to look at ejabberd, which is an extremely powerful and flexible option that has great online documentation. The code for ejabberd is written in Erlang, which is a language created for writing distributed, fault tolerant code. While we will not be taking advantage of the native clustering of ejabberd, it does exist for future expansion.
Install ejabberd through the following command:
sudo apt-get install ejabberd
Restrict access to the authentication script:
sudo chown root:ejabberd /usr/lib/ejabberd/priv/bin/epam sudo chmod 4750 /usr/lib/ejabberd/priv/bin/epam
Set up the
PAM
configuration:cat <<< '#%PAM-1.0 auth sufficient pam_unix.so likeauth nullok nodelay account sufficient pam_unix.so' > /etc/pam.d/ejabberd
Set up
/etc/ejabberd/ejabberd.cfg
:{loglevel, 3}. {hosts...
Much like an e-mail server, there are special DNS records which you can optionally add to your zone file in order to change how the XMPP service operates.
Add the c2s service to DNS:
_xmpp-client._tcp 28800 IN SRV 20 0 5222 xmpp.example.com.
Add the s2s service to DNS:
_xmpp-server._tcp 28800 IN SRV 20 0 5269 xmpp.example.com.
Similar to an e-mail, XMPP can use normal A records (or CNAMEs) for a given domain to handle message delivery if the messages are going to be defined to the IP for the root of the domain. In other words, if user@example.com
will be hosted on a server which example.com points to directly, then it will work fine.
Also similar to an e-mail, it often makes sense to have the traffic served by a different machine. Rather than MX records which are mail-specific, XMPP uses SRV records, which are a more general approach to looking up a service.
The SRV records are in the format of:
Service: The predefined service name that someone...
While using XMPP as an XML message passing system is becoming more and more common, the original use was using it for user-to-user chatting. With this use case, you'll want to use client software for accessing the service.
One common open source XMPP client is Pidgin. Pidgin was initially created as the GTK+ AIM client, or GAIM. Over time, gaim gained the ability to implement additional protocols via a plugin architecture. In 2007, gaim was renamed pidgin in response to the legal pressures from America Online, who owned a trademark on the name AIM.
Pidgin plugins can also implement other pieces of functionality including an implementation of the Off the Record (OTR) protocol, which allows for end-to-end encryption of chat messages layered over the underlying protocol.
In addition to making protocols available as plugins, Pidgin split its core chat functionality into a separate library called libpurple, which was then adopted by other client implementations as...