No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xep-0305.xml 23KB

  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <!DOCTYPE xep SYSTEM 'xep.dtd' [
  3. <!ENTITY % ents SYSTEM 'xep.ent'>
  4. %ents;
  5. ]>
  6. <?xml-stylesheet type='text/xsl' href='xep.xsl'?>
  7. <xep>
  8. <header>
  9. <title>XMPP Quickstart</title>
  10. <abstract>This document defines methods for speeding the process of connecting or reconnecting to an XMPP server.</abstract>
  12. <number>0305</number>
  13. <status>Deferred</status>
  14. <type>Standards Track</type>
  15. <sig>Standards</sig>
  16. <dependencies>
  17. <spec>RFC 5077</spec>
  18. <spec>RFC 6120</spec>
  19. <spec>XEP-0115</spec>
  20. <spec>XEP-0124</spec>
  21. <spec>XEP-0206</spec>
  22. <spec>XEP-0198</spec>
  23. </dependencies>
  24. <supersedes/>
  25. <supersededby/>
  26. <shortname>N/A</shortname>
  27. &stpeter;
  28. <revision>
  29. <version>0.3</version>
  30. <date>2013-03-01</date>
  31. <initials>psa</initials>
  32. <remark><p>Clarified the text in several places.</p></remark>
  33. </revision>
  34. <revision>
  35. <version>0.2</version>
  36. <date>2012-12-19</date>
  37. <initials>psa</initials>
  38. <remark><p>Cleaned up text and examples, and added material about the HTTP bindings (currently only BOSH, with WebSocket to be added in a future revision).</p></remark>
  39. </revision>
  40. <revision>
  41. <version>0.1</version>
  42. <date>2011-08-25</date>
  43. <initials>psa</initials>
  44. <remark><p>Initial published version, incorporating improvements based on list discussion and removing the concept of stream management tickets.</p></remark>
  45. </revision>
  46. <revision>
  47. <version>0.0.1</version>
  48. <date>2011-08-10</date>
  49. <initials>psa</initials>
  50. <remark><p>Rough draft.</p></remark>
  51. </revision>
  52. </header>
  53. <section1 topic='Introduction' anchor='intro'>
  54. <p>Establishing an XMPP session can require a fairly large number of round trips between the initiating entity and the receiving entity. However, in many deployment scenarios it would be helpful to reduce the number of round trips and therefore the time needed to establish a session. This document describes protocol optimizations and best practices to do just that.</p>
  55. </section1>
  56. <section1 topic='Preparing to Connect' anchor='prepare'>
  57. <p>In accordance with &rfc6120;, before attempting to establish a stream over TCP the initiating entity needs to determine the IP address and port at which to connect, usually by means of DNS lookups as described in Section 3.2 of <cite>RFC 6120</cite>. Implementations SHOULD cache the results of DNS lookups in order to avoid this step whenever possible. Similar considerations apply to connections established over one of the HTTP bindings, i.e., either BOSH (see &xep0124; and &xep0206;) or WebSocket (see &rfc6455; and &xmppoverwebsocket;).</p>
  58. <p>XMPP applications SHOULD cache whatever information they can about the peer, especially stream features data and &xep0030; information. To facilitate such caching, servers SHOULD include &xep0115; data in stream features as shown in Section 6.3 of <cite>XEP-0115</cite>. Note that for maximum benefit the server MUST include all of the stream features it supports in its replies to "disco#info" queries (i.e., not advertise such features only during stream establishment).</p>
  59. <p>XMPP clients SHOULD cache roster information, and servers SHOULD make such caching possible, using &xep0237; as subsequently included in Section 2.1.1 of &rfc6121;.</p>
  60. </section1>
  61. <section1 topic='Pipelining' anchor='pipelining'>
  62. <p>The primary method of speeding the connection process is pipelining of requests, along the lines of &rfc2920; and the QUICKSTART extension proposed for SMTP (&smtpquickstart;). The application of similar principles to XMPP was originally suggested by Tony Finch in February 2008 in a message to the discussion list &lt;<link url=''></link>&gt;.</p>
  63. <p>In essence, pipelining relies on two assumptions:</p>
  64. <ol>
  65. <li>The parties to a stream can proactively send multiple XMPP-related "commands" in a single TCP packet (as one simple example, the receiving entity can send both the response stream header and stream features in a single packet).</li>
  66. <li>The features that the receiving entity supports (e.g., stream features and SASL mechanisms) are stable over time, which means the initiating entity can assume support for certain features and send certain XMPP-related commands without discovering at the time of each connection attempt that the receiving entity supports them.</li>
  67. </ol>
  68. <p>Together, these assumptions enable the parties to reduce the number of round trips needed to complete the stream negotiation process by "pipelining" XMPP-related commands over the stream.</p>
  69. <p><em>Note well that pipelining at the XMPP layer is not to be confused with HTTP pipelining, which was added to HTTP in version 1.1 and which is not encouraged when using the HTTP bindings for XMPP.</em></p>
  70. </section1>
  71. <section1 topic='Discovery' anchor='discovery'>
  72. <p>If an XMPP server supports pipelining, it MUST advertise a stream feature of &lt;pipelining xmlns='urn:xmpp:features:pipelining'/&gt;.</p>
  73. <p>As noted, a server SHOULD also include its entity capabilities data in stream features as shown in Section 6.3 of <cite>XEP-0115</cite>.</p>
  74. </section1>
  75. <section1 topic='TCP Binding' anchor='tcp'>
  76. <p>If both parties support pipelining, they can proceed as follows over the TCP binding (the examples use the XML from Section 9.1 of <cite>RFC 6120</cite> for the client-server stream establishment, but the same principles apply to server-to-server streams).</p>
  77. <p>In the client-to-server half of the first exchange, the client assumes that the server supports the XMPP STARTTLS extension so it pipelines its initial stream header, the &lt;starttls/&gt; command, and the TLS ClientHello message.</p>
  78. <example caption='Client Initiation'><![CDATA[
  79. <stream:stream
  80. from=''
  81. to=''
  82. version='1.0'
  83. xml:lang='en'
  84. xmlns='jabber:client'
  85. xmlns:stream=''>
  86. <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
  87. TLS ClientHello
  88. ]]></example>
  89. <p>In the server-to-client half of the first exchange, the server pipelines its response stream header, stream features advertisement, STARTTLS &lt;proceed/&gt; response, and TLS ServerHello messages (which might include ServerHello, Certificate, ServerKeyExchange, CertificateRequest, and ServerHelloDone -- see &rfc5246; for details).</p>
  90. <example caption='Server Response to Initiation'><![CDATA[
  91. <stream:stream
  92. from=''
  93. id='t7AMCin9zjMNwQKDnplntZPIDEI='
  94. to=''
  95. version='1.0'
  96. xml:lang='en'
  97. xmlns='jabber:client'
  98. xmlns:stream=''>
  99. <stream:features>
  100. <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'>
  101. <required/>
  102. </starttls>
  103. <pipelining xmlns='urn:xmpp:features:pipelining'/>
  104. <c xmlns=''
  105. hash='sha-1'
  106. node=''
  107. ver='ItBTI0XLDFvVxZ72NQElAzKS9sU='/>
  108. </stream:features>
  109. <proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
  110. TLS ServerHello
  111. ]]></example>
  112. <p>Without pipelining, the foregoing exchange would require 3 round trips; with pipelining it requires 1 round trip.</p>
  113. <p>Now the parties complete the TLS negotiation (i.e., some combination of the TLS messages specified in RFC 5246); for our purposes we don't count these round trips because they are the same no matter whether we use pipelining or not.</p>
  114. <p>At the end of the TLS negotiation, the server knows that the client will need to restart the stream so it proactively attaches its response stream header and stream features in the same TCP packet at the TLS Finished message, thus starting the next exchange.</p>
  115. <example caption='Server Proactively Restarts Stream and Sends Stream Features'><![CDATA[
  116. TLS Finished
  117. <stream:stream
  118. from=''
  119. id='vgKi/bkYME8OAj4rlXMkpucAqe4='
  120. to=''
  121. version='1.0'
  122. xml:lang='en'
  123. xmlns='jabber:client'
  124. xmlns:stream=''>
  125. <stream:features>
  126. <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
  127. <mechanism>SCRAM-SHA-1-PLUS</mechanism>
  128. <mechanism>SCRAM-SHA-1</mechanism>
  129. <mechanism>PLAIN</mechanism>
  130. </mechanisms>
  131. <pipelining xmlns='urn:xmpp:features:pipelining'/>
  132. <c xmlns=''
  133. hash='sha-1'
  134. node=''
  135. ver='ItBTI0XLDFvVxZ72NQElAzKS9sU='/>
  136. </stream:features>
  137. ]]></example>
  138. <p>In response, the client pipelines its initial stream header with the command for initiating the SASL authentication process (including, if appropriate for the SASL mechanism used, the "initial response" data as explained in Section 6.3.10 of <cite>RFC 6120</cite>).</p>
  139. <example caption='Client Initiates SASL Authentication'><![CDATA[
  140. <stream:stream
  141. from=''
  142. to=''
  143. version='1.0'
  144. xml:lang='en'
  145. xmlns='jabber:client'
  146. xmlns:stream=''>
  147. <auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl"
  148. mechanism="SCRAM-SHA-1">
  150. </auth>
  151. ]]></example>
  152. <p>Without pipelining, the second exchange would require another 2 round trips; with pipelining it requires only 1.</p>
  153. <p>At this point the client and server might exchange multiple SASL-related messages, depending on the SASL mechanism in use. Because this specification does not attempt to reduce the number of round trips involved in the challenge-response sequence, we do not describe these exchanges here.</p>
  154. <p>When the client suspects that it is sending its final SASL response, with pipelining it appends an initial stream header and resource binding request.</p>
  155. <example caption='Client Sends Final SASL Response with Stream Header and Bind Request'><![CDATA[
  156. <response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
  159. RCa0gyRlhzMFdEWHZKWXc9
  160. </response>
  161. <stream:stream
  162. from=''
  163. to=''
  164. version='1.0'
  165. xml:lang='en'
  166. xmlns='jabber:client'
  167. xmlns:stream=''>
  168. <iq id='yhc13a95' type='set'>
  169. <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>
  170. <resource>balcony</resource>
  171. </bind>
  172. </iq>
  173. ]]></example>
  174. <p>The server then informs the client of SASL success (including "additional data with success" as explained in Section 6.3.10 of <cite>RFC 6120</cite>), sends a response stream header and stream features, and informs the client of successful resource binding.</p>
  175. <example caption='Server Accepts Bind Request'><![CDATA[
  176. <success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
  177. dj1wTk5ERlZFUXh1WHhDb1NFaVc4R0VaKzFSU289
  178. </success>
  179. <stream:stream
  180. from=''
  181. id='gPybzaOzBmaADgxKXu9UClbprp0='
  182. to=''
  183. version='1.0'
  184. xml:lang='en'
  185. xmlns='jabber:client'
  186. xmlns:stream=''>
  187. <stream:features>
  188. <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
  189. <sm xmlns='urn:xmpp:sm:3'/>
  190. <pipelining xmlns='urn:xmpp:features:pipelining'/>
  191. <c xmlns=''
  192. hash='sha-1'
  193. node=''
  194. ver='ItBTI0XLDFvVxZ72NQElAzKS9sU='/>
  195. </stream:features>
  196. <iq id='yhc13a95' type='result'>
  197. <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>
  198. <jid>
  200. </jid>
  201. </bind>
  202. </iq>
  203. ]]></example>
  204. <p>Without pipelining, this exchange would require another 3 round trips; with pipelining it requires only 1.</p>
  205. <p>Therefore, without pipelining the XMPP exchanges for stream establishment require at least 6 round trips (and perhaps more depending on the SASL mechanism used); with pipelining the minimum number of round trips is 3.</p>
  206. <p>Naturally, for typical client-to-server sessions, additional round trips are needed so that the client can gather service discovery information, retrieve the roster, etc. As noted, these steps can be reduced or eliminated by using entity capabilities and roster versioning.</p>
  207. </section1>
  208. <section1 topic='HTTP Bindings' anchor='http'>
  209. <p>In the HTTP bindings (BOSH and WebSocket) channel encryption occurs at the HTTP layer and therefore the first exchange shown above for the TCP binding is not used.</p>
  210. <p>For now, this section focuses on BOSH. A future version of this document will discuss WebSocket (once draft-moffitt-xmpp-over-websocket has been updated to include examples).</p>
  211. <p>When pipelining is used, a BOSH client can include its XMPP authentication (SASL) request in the BOSH session creation request, as shown in the following example.</p>
  212. <example caption="BOSH Session Request with Pipelined SASL Authentication Request"><![CDATA[
  213. POST /webclient HTTP/1.1
  214. Host:
  215. Accept-Encoding: gzip, deflate
  216. Content-Type: text/xml; charset=utf-8
  217. Content-Length: 104
  218. <body content='text/xml; charset=utf-8'
  219. from=''
  220. hold='1'
  221. rid='1573741820'
  222. to=''
  223. route=''
  224. secure='true'
  225. wait='60'
  226. xml:lang='en'
  227. xmpp:version='1.0'
  228. xmlns=''
  229. xmlns:xmpp='urn:xmpp:xbosh'>
  230. <auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl"
  231. mechanism="SCRAM-SHA-1">
  233. </auth>
  234. </body>
  235. ]]></example>
  236. <p>Note: If the client does not expect to receive a SASL challenge from the server but simply a success or failure notification (e.g., when using a simpler SASL mechanism such as PLAIN &rfc4616;), then it can also pipeline its XMPP resource binding request with the BOSH session creation request.</p>
  237. <p>The BOSH connection manager then returns a session creation response with a pipelined SASL authentication response.</p>
  238. <example caption="Session Creation Response with Pipelined SASL Authentication Response"><![CDATA[
  239. HTTP/1.1 200 OK
  240. Content-Type: text/xml; charset=utf-8
  241. Content-Length: 674
  242. <body wait='60'
  243. inactivity='30'
  244. polling='5'
  245. requests='2'
  246. hold='1'
  247. from=''
  248. accept='deflate,gzip'
  249. sid='SomeSID'
  250. secure='true'
  251. charsets='ISO_8859-1 ISO-2022-JP'
  252. xmpp:restartlogic='true'
  253. xmpp:version='1.0'
  254. authid='ServerStreamID'
  255. xmlns=''
  256. xmlns:xmpp='urn:xmpp:xbosh'
  257. xmlns:stream=''>
  258. <stream:features>
  259. <pipelining xmlns='urn:xmpp:features:pipelining'/>
  260. <c xmlns=''
  261. hash='sha-1'
  262. node=''
  263. ver='ItBTI0XLDFvVxZ72NQElAzKS9sU='/>
  264. <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
  265. <mechanism>SCRAM-SHA-1</mechanism>
  266. <mechanism>PLAIN</mechanism>
  267. </mechanisms>
  268. </stream:features>
  269. <challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
  272. AwTmpkbUxUa3hNbVV0TkRsbU5UTm1ORE5rTURNeixpPTQwOTY=
  273. </challenge>
  274. </body>
  275. ]]></example>
  276. <p>Without pipelining, this exchange would require 2 round trips; with pipelining, it requires only 1.</p>
  277. <p>If the SASL exchange involved a challenge, in its final SASL response the client includes an XMPP resource binding request (note that the BOSH &BODY; wrapper includes a restart='true' attribute, instead of sending this in a new empty &BODY; as shown in XEP-0206).</p>
  278. <example caption="SASL Response with Pipelined XMPP Resource Binding Request"><![CDATA[
  279. POST /webclient HTTP/1.1
  280. Host:
  281. Accept-Encoding: gzip, deflate
  282. Content-Type: text/xml; charset=utf-8
  283. Content-Length: 295
  284. <body rid='1573741822'
  285. sid='SomeSID'
  286. xmpp:restart='true'
  287. xmlns=''
  288. xmlns:xmpp='urn:xmpp:xbosh'>
  289. <response xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
  292. RCa0gyRlhzMFdEWHZKWXc9
  293. </response>
  294. <iq id='bind_1'
  295. type='set'
  296. xmlns='jabber:client'>
  297. <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>
  298. <resource>httpclient</resource>
  299. </bind>
  300. </iq>
  301. </body>
  302. ]]></example>
  303. <p>An XMPP stream restart is required by RFC 6120 at this point; however, the server can include the stream features element (if any) along with the SASL authentication success and XMPP resource binding success notifications, as shown in the following example.</p>
  304. <example caption="SASL Success with Pipelined Stream Features and XMPP Resource Binding Response"><![CDATA[
  305. HTTP/1.1 200 OK
  306. Content-Type: text/xml; charset=utf-8
  307. Content-Length: 149
  308. <body xmlns=''>
  309. <success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
  310. dj1wTk5ERlZFUXh1WHhDb1NFaVc4R0VaKzFSU289
  311. </success>
  312. <stream:features>
  313. <pipelining xmlns='urn:xmpp:features:pipelining'/>
  314. <c xmlns=''
  315. hash='sha-1'
  316. node=''
  317. ver='ItBTI0XLDFvVxZ72NQElAzKS9sU='/>
  318. <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
  319. </stream:features>
  320. <iq id='bind_1'
  321. type='result'
  322. xmlns='jabber:client'>
  323. <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>
  324. <jid></jid>
  325. </bind>
  326. </iq>
  327. </body>
  328. ]]></example>
  329. <p>Without pipelining, this second exchange would require 3 round trips; with pipelining, it requires only 1.</p>
  330. <p>Therefore, without pipelining the XMPP exchanges for stream establishment over BOSH require at least 5 round trips (if the SASL mechanism is not multi-stage, and perhaps more depending on the SASL mechanism used); with pipelining the minimum number of round trips is 1.</p>
  331. <p>Note: It might seem that with pipelining the minimum number of round trips is 2. However, consider the case of a session creation request that includes (a) a SASL authentication request for a SASL mechanism that is not multi-stage, such as PLAIN, (b) an XMPP resource binding request, and (c) a stream restart request; in the "happy path" the session creation response would include (a) stream features, (b) a SASL authentication success notification, and (c) an XMPP resource binding response. This flow is shown in the following example.</p>
  332. <example caption="BOSH Session Request with Pipelined SASL Authentication Request and XMPP Resource Binding Request, Including Stream Restart Request"><![CDATA[
  333. POST /webclient HTTP/1.1
  334. Host:
  335. Accept-Encoding: gzip, deflate
  336. Content-Type: text/xml; charset=utf-8
  337. Content-Length: 104
  338. <body content='text/xml; charset=utf-8'
  339. from=''
  340. hold='1'
  341. rid='1573741820'
  342. to=''
  343. route=''
  344. secure='true'
  345. wait='60'
  346. xml:lang='en'
  347. xmpp:restart='true'
  348. xmpp:version='1.0'
  349. xmlns=''
  350. xmlns:xmpp='urn:xmpp:xbosh'>
  351. <auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">
  352. [plain credentials here]
  353. </auth>
  354. <iq id='bind_2' type='set' xmlns='jabber:client'>
  355. <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'/>
  356. </iq>
  357. </body>
  358. ]]></example>
  359. <example caption="BOSH Session Response with Pipelined Stream Features, SASL Authentication Request, and XMPP Resource Binding Response"><![CDATA[
  360. HTTP/1.1 200 OK
  361. Content-Type: text/xml; charset=utf-8
  362. Content-Length: 674
  363. <body wait='60'
  364. inactivity='30'
  365. polling='5'
  366. requests='2'
  367. hold='1'
  368. from=''
  369. accept='deflate,gzip'
  370. sid='SomeSID'
  371. secure='true'
  372. charsets='ISO_8859-1 ISO-2022-JP'
  373. xmpp:restartlogic='true'
  374. xmpp:version='1.0'
  375. authid='ServerStreamID'
  376. xmlns=''
  377. xmlns:xmpp='urn:xmpp:xbosh'
  378. xmlns:stream=''>
  379. <stream:features>
  380. <pipelining xmlns='urn:xmpp:features:pipelining'/>
  381. <c xmlns=''
  382. hash='sha-1'
  383. node=''
  384. ver='ItBTI0XLDFvVxZ72NQElAzKS9sU='/>
  385. <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
  386. <mechanism>SCRAM-SHA-1</mechanism>
  387. <mechanism>PLAIN</mechanism>
  388. </mechanisms>
  389. </stream:features>
  390. <success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>
  391. <iq id='bind_2' type='result' xmlns='jabber:client'>
  392. <bind xmlns='urn:ietf:params:xml:ns:xmpp-bind'>
  393. <jid></jid>
  394. </bind>
  395. </iq>
  396. </body>
  397. ]]></example>
  398. </section1>
  399. <section1 topic='Reconnection' anchor='reconnection'>
  400. <p>The pain of multiple round trips is magnified if the initiating entity needs to reconnect frequently (e.g., because of intermittent network outages). Although XEP-0124 can be used to mitigate the pain, BOSH is not appropriate for all scenarios and is not currently used in others (e.g., server-to-server streams).</p>
  401. <p>To minimize the speed of reconnection, implementations are strongly encouraged to support TLS Session Resumption (&rfc5077;) in addition to the technologies already mentioned.</p>
  402. <p>Reconnection can be further enhanced by using the stream resumption feature defined in &xep0198;. <cite>XEP-0198</cite> does not legislate exactly when it is safe for the server to allow the client to send the &lt;resume/&gt; request. Clearly, sending it before the stream is encrypted would increase the possibility of replay attacks. However, sending it after TLS negotiation (Step 4 above) but before SASL authentication and resource binding (Steps 5 through 8) would enable the client to begin sending stanzas more quickly. It is a matter of server policy whether to advertise the SM feature after TLS negotiation or only after SASL negotiation.</p>
  403. </section1>
  404. <section1 topic='Security Considerations' anchor='security'>
  405. <p>Because pipelining does not skip any channel encryption or authentication steps, but merely packs them into a smaller number of TCP packets or HTTP request/response pairs, it is unlikely that the foregoing quickstart methods introduce security vulnerabilities. However, the server needs to be careful not to send stream features that it would not otherwise send before a security context is established.</p>
  406. </section1>
  407. <section1 topic='IANA Considerations' anchor='iana'>
  408. <p>This document requires no interaction with &IANA;.</p>
  409. </section1>
  410. <section1 topic='XMPP Registrar Considerations' anchor='registrar'>
  411. <p>This specification defines the following XML namespace:</p>
  412. <ul>
  413. <li>urn:xmpp:features:pipelining</li>
  414. </ul>
  415. <p>Upon advancement of this specification from a status of Experimental to a status of Draft, the &REGISTRAR; shall add the foregoing namespace to the registry located at &STREAMFEATURES;, as described in Section 4 of &xep0053;.</p>
  416. </section1>
  417. <section1 topic='Acknowledgements' anchor='ack'>
  418. <p>Special thanks to Tony Finch for suggesting this work and for providing the initial outline of how pipelining would work. Thanks also to Waqas Hussain, Jehan Pagès, and Kevin Smith for their feedback.</p>
  419. </section1>
  420. </xep>