Professional Documents
Culture Documents
Roll No:4238
ELECTIVE III:IOT LAB
ASSIGNMENT NO. 7
Problem Statement:
Install, configure XMPP server and deployed an application on Raspberry Pi/Beagle
board/Arduino. Write client applications to get services from the server application.
Hardware Requirements:
Raspberry-pi
Software Requirements:
Objectives:
Theory:
WHAT IS XMPP?
XMPP is an open protocol that chat clients and servers use to communicate to each other, the
equivalent of SMTP (the open protocol for email) but for instant messaging.
Like SMTP, it is based on a federated client-server model: anyone can run their own server,
clients communicate with the server and the servers pass messages to each other.
The actual data transfer for XMPP messages is achieved using XML (that's the plain text format
where everything is nested in loads of < and >).
4 </message>
Pros
Many free providers: you can choose to run your own XMPP server, which gives you total
control.
XMPP is Decentralised: unlike proprietary services like WhatsApp and Blackberry Messenger,
there isn't one single provider in control of the whole network. This ensures that XMPP
continues to serve the needs of its users, since providers cannot introduce anti-features without
users switching to another service.
Large selection Client and Server software: every platform I can think of has at least one
XMPP and there is a healthy selection of server software to choose from too. You really can
send messages from every device, without arbitrary restrictions imposed for non-technical
reasons (e.g. WhatsApp's decision not to allow installation on tablets).
Stability of service: XMPP has endured the boom and bust of many proprietary services, and is
likely to endure whatever the next decade throws at it. No company can decide to end XMPP, or
make it paid, or start including adverts in it. When Blackberries were popular, it seemed like
"everyone" used Blackberry Messenger, but then they went out of fashion and everyone switched
to a different platform, with new accounts etc... why bother with all this when you can use one
account that isn't tied to a particular platform or service?
Flexibility: due to its extensible nature, you can use the XEPs you want to add the features you
want.
Cons
Not all features are supported everywhere: this is the downside of having an extensible
protocol - for some features to work, your contact has to have a client/server that supports the
XEPs you are trying to use. This is most noticeable in photo sharing; there are many different
ways of sending images, as we will discuss later. However, the XMPP standards foundation does
publish some minimum requirements for compliance in an effort to ensure the most widely used
features are supported by most clients.
Ensuring message delivery is problematic: there is no mechanism for ensuring messages have
been delivered built in to XMPP. This is probably due in part to the fact that when it was
devised, people using it were on desktop computers with reasonably steady internet connections.
Either the person was online and you talked to them, or they were offline and you didn't. Now
that more and more clients are on smartphones, internet connectivity is less steady and it is easy
to miss messages if your signal comes and goes. Some proprietary IM services like Facebook
chat apparently echo every message back to the server to prove delivery (how wasteful!); XMPP
has solved the problem with various XEPs, but they are not part of the basic standard. The good
news here is that message delivery is mostly a client-server problem, so it can be dealt with in
your prosody configuration.
Not popular: it's unlikely that your friends already use XMPP or even know what it is. A good
rule of thumb is that the more someone knows about Free Software, the more likely they are to
use it. Whether you can persuade them to use it or not is down to you.
Volatile relationship with for-profit organisations: Google and Facebook both supported
XMPP, once upon a time, but they have since dropped (or are dropping) that support. In fact,
Google Hangouts and Facebook Messenger are both based on XMPP. Recommending XMPP
because "company X provides an XMPP gateway to their proprietary service" is a dangerous
game - it seems like this is only something that companies do when they are trying to attract
users. Once they have enough users, the financial incentive always favours the vendor-lockin
approach, and XMPP support is dumped or not updated.
Development can be slow: while proprietary messaging services have a strong incentive to
innovate and add new features to attract users, the inter-operability problem with XMPP clients
and servers means new features are added slowly, often only when a few popular projects get
organised and decide to support it together. The Android client Conversations is an exception
here, continually pushing the boundaries by supporting new XEPs that benefit mobile users -
more on that later.
Installing Prosody:
There are a few different branches of prosody. The current stable branch is 0.9 and the
development branch is 0.10. If you install straight from the repository in Raspbian or Ubuntu
you'll get 0.9, but some of the modules required to support newer XEPs that are important for
mobile require version 0.10.
So, the first thing we need to do is add the Prosody repository to get v0.10. The repository
contains packages for many different release codenames of Debian and Ubuntu. You can find out
which one you need by running:
Initial Testing
The default prosody configuration should "just work" - the server should be running, but we
haven't added any users yet. Verify it's running using systemctl:
Prosody also comes with its own utility for controlling the XMPP server,
called prosodyctl (similar to Apache's apachectl). You can also check the status of prosody
using this tool like so:
When I wrote this tutorial originally, I used prosodyctl to start, stop and restart prosody
throughout the tutorial. Thanks to some feedback and advice from Prosody developer Zash, I
have changed the tutorial to use the command service, which abstracts the relevant command for
whichever init system you are using (e.g. systemctl for systems running systemd). Apparently
mixing the two is a bad idea, because they control the service in different (and somewhat
incompatible) ways.
As mentioned previously, XMPP servers listen for client to server connections on port 5222 and
server to server connections on port 5269. If you used the mail server tutorial I wrote, you'll
remember we tested the server by sending commands using telnet. I found some useful XMPP
tests here.
Here's a simple connection request using XML, which requests a client-to-server (C2S)
connection for the hostname 'localhost':
<?xmlversion="1.0"?>
1
<stream:streamxmlns:stream="http://etherx.jabber.org/streams"version="1.0"xmlns="jabber:client"to="localhost"xml:lang="en"
2
xmlns:xml="http://www.w3.org/XML/1998/namespace">
<?xmlversion='1.0'?>
1
<stream:streamxmlns:stream='http://etherx.jabber.org/streams'xml:lang='en'from='localhost'id='9ea2578f-
2
c696-49fd-bc70-f51d05a2e444'version='1.0'xmlns='jabber:client'>
3
<stream:features>
4
<starttlsxmlns='urn:ietf:params:xml:ns:xmpp-tls'>
5
<required/>
6
</starttls>
7
</stream:features>
Here the server is declaring that all connections must use STARTTLS, a method of upgrading
plaintext connections to encrypted connections using SSL/TLS - more on that later!
The default prosody config file is set up to serve requests on the local server (localhost) only. If
you change the to="localhost" part of the data you send to something like to="foo.com", you will
get a different response from the server similar to this:
One of the things we will do in the course of this tutorial is to add a virtualhost (again,
terminology that will be familiar to apache users) to the prosody configuration, allowing it to
have multiple configurations for different domains.
VirtualHost "yourdomain.com"
enabled = true
There are a number of things we need to do before we can connect with a proper XMPP client.
Create a username for yourself, and possibly another username if you want to test sending
messages to yourself using two different clients:
$sudoprosodyctladduser you@yourdomain.com
In the prosody config file, find the admins block and change it so that your username is added as
an admin for the server e.g.:
admins = { "you@yourdomain.com" }
Being an administrator allows you to do certain things from a XMPP client like create new chat
rooms, set a message of the day etc, if your XMPP client supports this.
DNS records
The only record you really need for DNS to work is a DNS A record for whichever hostname
your Jabber ID is using (i.e. example.com for foo@example.com), which maps that domain
name to the WAN IP address of your server.
If you already have a DNS A record for example.com pointing to a server at a different IP
address, you can use SRV records (XMPP's equivalent of MX records for SMTP) to tell clients
and servers to use a subdomain for XMPP. SRV records can be created with your DNS provider.
You may want to create SRV records even if you have a very simple setup, because it's good
practice.
Here are some example SRV records that tell clients and servers wanting to connect to the
XMPP server responsible for @yourdomain.comaddresses to the
subdomain xmpp.yourdomain.com. In this case, the subdomain xmpp.yourdomain.com would
need its own DNS A record.
To test retrieving these records, we can use a commandline tool called dig, which is in
the dnsutils package. First, install dig:
dig yourdomain.com
If you want a more compact answer from dig that removes all of the extra information returned
in a query, then use:
The +noall option turns off all of the sections in the query result, and the +answer option turns
the answer back on.
So far, we have been connecting locally to test the server. Before youcan start connecting some
real client applications, you need to forward some ports on your router to make the server
accessible from the internet.
Navigate to your router's control panel (usually at 192.168.1.1 or 192.168.0.1). If you don't know
your router's IP address, use the route command:
$ route -n
The G in flags tells us that the first line is the gateway. Add the following port forwards to your
server:
Jabber Client
On other device install some Jabber client and try to connect to this account. Everything should
work. It is not common to use admin account for messaging, create another account, for example
via Pidgin.
If you choose to not allow registration of new acconts, you will have to create all accounts in
command line. use this commands, they are quite self-explanationary.
prosodyctladduser user@domain.com # adds a new user
prosodyctldeluser user@domain.com # deletes an existing account
prosodyctlpasswd user@domain.com # change password to existing account
Now you should be able to send messages to people from other domains, not only yours .
NOTE: If you are using standard ports for Jabber server you do not have to set this. If you
changed default ports, you will have to set SRV DNS records.
There are 3 records, first is port for server to server communication, second is for client to server
communication. Third is only for backwards compatibility, set there the same port as in server to
server statement.
NOTE2: In client to server communication is used asymetric certificate. Its keys are
automaticaly generated at installation, but you can also get validated certificates for your Jabber
server from StartSSL for free.
Prosody users
Admins - bnj@192.168.1.7 bnj@123
test test1234
Conclusion: