package ae is obsolete, use lmodern instead
[skm-ma-ws1314.git] / sec-xmpp.tex
1 \subsection{XMPP}
3 The \term{Extensible Messaging and Presence Protocol (XMPP)} is a distributed,
4 XML-based protocol for real-time communication. Its core functionalities are
5 specified in RFC~6120~\cite{rfc6120} and RFC~6122~\cite{rfc6121}, while protocol
6 extensions are usually defined by the XMPP community in \term{XMPP Extension
7 Proposals (XEPs)}.
9 \subsubsection{Addressing}
10 \enlargethispage{2\baselineskip}
12 Every user account in XMPP is addressed by a globally unique identifier, called
13 the \term{Jabber ID (JID)}~\cite{rfc6122}. It has the form
14 \code{localpart@domain/resource}, where \code{domain} is the DNS name of an XMPP
15 server, and \code{localpart} is the name of a user account on that server. Since
16 a user can be logged in from multiple clients at the same time, the
17 \code{resource} part is a string chosen by the user to distinguish those
18 clients. Only the part \code{localpart@domain} (the \term{bare JID}) is
19 needed to identify a user, the resource is only needed for routing between
20 client and server.
22 \subsubsection{Architecture}
23 \begin{wrapfigure}{r}{0.5\textwidth}
24 \tikzstyle{iconlabel}=[text width=3cm, align=center, font=\footnotesize]
25 \tikzstyle{label}=[font=\footnotesize]
26 \begin{tikzpicture}[node distance=0pt,scale=1.5,>=stealth,thick]
27 \def\nodelist{
28 juliet/{(-1,-1)}/XMPP client \code{}/below/computer,
29 examplenet/{(-1,1)}/XMPP server \code{}/above/server,
30 imexampleorg/{(1,1)}/XMPP server \code{}/above/server,
31 romeo/{(1,-1)}/XMPP client \code{}/below/computer%
32 }
33 \foreach \name/\pos/\text/\tpos/\icon in \nodelist {
34 \node (\name) at \pos { \includegraphics[width=1cm]{icon-\icon.pdf} };
35 \node[\tpos=of \name,iconlabel] (\name text) { \text };
36 }
37 \draw[<->,dashed] (juliet) -- node[anchor=east,label]{s2c} (examplenet);
38 \draw[<->] (examplenet) -- node[anchor=south,label]{s2s} (imexampleorg);
39 \draw[<->,dashed] (imexampleorg) -- node[anchor=west,label]{s2c} (romeo);
40 \end{tikzpicture}
41 \centering
42 \caption{XMPP architecture, showing server-to-server (s2s) and
43 server-to-client (s2c) connections}
44 \label{fig:xmpparch}
45 \end{wrapfigure}
47 The original architecture underlying XMPP strongly leans on the established
48 design of Internet Mail, and an example is depicted in Fig.~\ref{fig:xmpparch}.
49 The distributed network is formed by \term{XMPP servers} on one hand, which make
50 up the always-on backbone of the network used for message routing, and which
51 manage user accounts and statuses. On the other hand, \term{XMPP clients}
52 represent a single logged-in user and make up the interface for communication
53 with other users.
55 Every client communicates only with the server that manages the respective user
56 account which is configured in the client, as given in the user's JID. The
57 server then routes the messages to their recipients, using the JID to determine
58 the correct server for a message to be sent to. Finally, the receiving server
59 sends the message to a client where the receiving JID is logged in. If the user
60 is not logged in at the time the message is sent, the server can store it for
61 the user and deliver it on the next login.
63 XMPP strongly relies on DNS Service Discovery (see Section~\ref{sec:dnssd}) to
64 determine the server being in charge of a domain. For example, the server who
65 manages the users for the domain \code{} is given by the SRV record
66 \code{\_xmpp-server.\}.
68 \subsubsection{Communication primitives}
70 All communication over XMPP is based on XML. To minimize communication overhead,
71 only fragments of XML, called \term{stanzas}, are sent between hosts. A stanza
72 is always well-formed as a whole; it consists of a root element, which in most
73 cases also includes routing attributes (\code{to} and \code{from}), and its
74 optional child elements.
76 On top of that, living connections between hosts are represented by \term{XML
77 streams}. The client initiates a connection by sending an XML declaration
78 followed by an opening \code{<stream>} tag. The server then responds also with
79 an opening \code{<stream>} tag. The client then performs SASL authentication and
80 binds its stream to a resource for proper addressing. If this process succeeded,
81 both client and server can send an unlimited number of stanzas, until the
82 connection is closed by one side by sending a closing \code{</stream>} tag. The
83 other side then has the chance to send all outstanding stanzas and then likewise
84 closes its stream. If both streams are closed, the underlying TCP connection is
85 terminated.
87 \subsubsection{Publish/Subscribe and Presence}
89 Typically, a user wants to chat with a more or less fixed set of other users,
90 whose JIDs she needs to know, so she needs some kind of ``address book'' that
91 remembers the JIDs for her. In XMPP, this address book is called
92 \term{roster}, and it also shows the users' willingness to chat (``presence'').
93 In order to see their chat status (which can be one of ``online'', ``offline'',
94 and several ``away'' or ``do not disturb'' states), a user needs to subscribe to
95 the other user's status. The mechanism behind this is called
96 \term{Publish-Subscribe} and is specified in XEP-0060~\cite{xep0060}. It can
97 be used to notify interested users about changes in personal information, and
98 implements the well-known Observer pattern~\cite{GOF95}.
100 A user publishes information by creating a \term{node} on the XMPP server, which
101 acts as a handle for the data. Interested users can then query the server for
102 nodes, and request subscription to them. When the owner of the node confirms the
103 subscription request, subscribers get notified whenever the owner updates the
104 respective node.
106 All communication takes place between the client and the server over \code{<iq>}
107 (``information query'') stanzas.
109 \subsubsection{Multi-User Chats}
111 Besides one-to-one messaging, XMPP also allows users to create multi-user chat
112 rooms, which is specified in XEP-0045~\cite{xep0045}. Each chat room is given a
113 unique JID on the server managing the room to which the users send their
114 messages to. Each incoming message is then dispatched to all users which have
115 joined the room.
117 To join a room, the user sends a \code{<presence>} stanza to the room JID, where
118 the resource part of the room JID specifies the desired nick name.
120 \subsubsection{XMPP Serverless Messaging}\label{sec:xsm}
122 To overcome the need for a central server and authentication, XMPP Serverless
123 Messaging~\cite{xep0174} allows XMPP clients on a network to build a
124 peer-to-peer mesh network and chat directly with each other. This feature was
125 first introduced by Apple as part of their \term{Bonjour} project, and nowadays
126 it is also available in many other XMPP clients.
128 %\begin{wrapfigure}{R}{0.4\textwidth}
129 %\tikzstyle{iconlabel}=[text width=2cm, align=center, font=\footnotesize]
130 %\tikzstyle{label}=[font=\footnotesize]
131 %\begin{tikzpicture}[node distance=0pt,scale=1.2,>=stealth,thick]
132 %\def\nodelist{
133 %juliet/{(-1,-1)}/\code{juliet@\ balcony.local}/below/computer,
134 %tybalt/{(-1,1)}/\code{tybalt@\ montague.local}/above/computer,
135 %mercutio/{(1,1)}/\code{mercutio@\ capulet.local}/above/computer,
136 %romeo/{(1,-1)}/\code{romeo@\ romeo.local}/below/computer%
137 %}
138 %\foreach \name/\pos/\text/\tpos/\icon in \nodelist {
139 %\node (\name) at \pos { \includegraphics[width=1cm]{icon-\icon.pdf} };
140 %\node[\tpos=of \name,iconlabel] (\name text) { \text };
141 %}
142 %\draw[<->,dashed] (juliet) -- (tybalt);
143 %\draw[<->,dashed] (juliet) -- (romeo);
144 %\draw[<->,dashed] (juliet) -- (mercutio);
145 %\draw[<->,dashed] (romeo) -- (mercutio);
146 %\draw[<->,dashed] (romeo) -- (tybalt);
147 %\draw[<->,dashed] (mercutio) -- (tybalt);
148 %\end{tikzpicture}
149 %\centering
150 %\caption{XMPP architecture with Serverless Messaging}
151 %\label{fig:xmpparch2}
152 %\end{wrapfigure}
154 With XMPP Serverless Messaging, XMPP clients simply open a port on their host,
155 and then rely on mDNS and DNS-SD (see Section~\ref{sec:dns}) to publish instance
156 names in the domain \code{\_presence.\_tcp.local}. For example, if Juliet uses
157 her machine (named \code{capulet}) with serverless messaging, her client would
158 publish the following four mDNS records:
160 \begin{itemize}
161 \item an A record \code{capulet.local}, specifying her IP address,
162 \item an SRV record \code{juliet@capulet.\_presence.\_tcp.local}, specifying
163 the port on which her XMPP client listens, and referring to
164 \code{capulet.local} as the host name
165 \item a PTR record \code{\_presence.\_tcp.local} for service discovery,
166 pointing to \code{juliet@capulet.\_presence.\_tcp.local}
167 \item and a TXT record \code{juliet@capulet.\_presence.\_tcp.local} specifying
168 more information about her (e.~g. her online status, contact data, etc.) in
169 standardized key-value pairs.
170 \end{itemize}
172 When other clients in the same network enumerate the available services by
173 querying \code{\_presence.\_tcp.local}, they notice Juliet's presence and add
174 her to the roster automatically. In that way, XMPP users can see who is
175 currently available for communication. To start a chat session, clients initiate
176 a TCP connection over the advertised ports, open their XML streams, and send
177 message or IQ stanzas like they would to an XMPP server. Presence is managed
178 over the corresponding TXT record in the mDNS. To go offline, a client
179 announces the deletion of its mDNS records.
181 % vim: set ft=tex et ts=2 sw=2 :
This page took 0.071393 seconds and 5 git commands to generate.