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