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-0200.xml 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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>Stanza Encryption</title>
  10. <abstract>This document specifies an XMPP protocol extension for session-based stanza encryption.</abstract>
  11. &LEGALNOTICE;
  12. <number>0200</number>
  13. <status>Deferred</status>
  14. <type>Standards Track</type>
  15. <sig>Standards</sig>
  16. <dependencies>
  17. <spec>XMPP Core</spec>
  18. <spec>XMPP IM</spec>
  19. <spec>RFC 2104</spec>
  20. <spec>RFC 3548</spec>
  21. </dependencies>
  22. <supersedes/>
  23. <supersededby/>
  24. <shortname>TO BE ASSIGNED</shortname>
  25. &ianpaterson;
  26. <revision>
  27. <version>0.2</version>
  28. <date>2007-05-30</date>
  29. <initials>ip</initials>
  30. <remark><p>Added reference to Simplified Encrypted Session Negotiation; modified namespaces to reflect XMPP Registrar procedures regarding URN issuance.</p></remark>
  31. </revision>
  32. <revision>
  33. <version>0.1</version>
  34. <date>2006-11-23</date>
  35. <initials>ip</initials>
  36. <remark><p>Initial version (extracted from XEP-0116 version 0.12); clarified Re-Key Exchange section; removed canonicalization requirement; employed HMAC instead of hash; added new sections; changed element name and namespace</p></remark>
  37. </revision>
  38. </header>
  39. <section1 topic='Introduction' anchor='intro'>
  40. <p>End-to-end encryption is a desirable feature for any communication technology. Ideally, such a technology would design encryption in from the beginning and would forbid unencrypted communications. Realistically, most communication technologies have not been designed in that manner, and Jabber/XMPP technologies are no exception. In particular, the original Jabber technologies developed in 1999 did not include end-to-end encryption by default. PGP-based encryption of message bodies and signing of presence information was added as an extension to the core protocols in the year 2000; this extension is documented in &xep0027;. When the core protocols were formalized within the Internet Standards Process by the IETF's XMPP Working Group in 2003 (see &rfc3920; and &rfc3921;), a different extension was defined using S/MIME-based signing and encryption of CPIM-formatted messages (see &rfc3862;) and PIDF-formatted presence information (see &rfc3863;); this extension is specified in &rfc3923;.</p>
  41. <p>For reasons described in &xep0210;, the foregoing proposals (and others not mentioned) have not been widely implemented and deployed. This is unfortunate, since an open communication protocol needs to enable end-to-end encryption in order to be seriously considered for deployment by a broad range of users.</p>
  42. <p>This document describes a different session-based approach to the end-to-end encryption of the full content of XMPP stanzas sent between two entities. The protocol assumes that the encrypted session parameters (initial keys, counters and algorithms etc.) have already been agreed, typically through a negotiation protocol such as &xep0116;, &xep0217; or &xep0187;. The session approach when combined with short-lived keys offers many important advantages over the existing "Object Encryption" proposals, including Perfect Forward Secrecy and Identity Protection.</p>
  43. </section1>
  44. <section1 topic="Requirements" anchor='require'>
  45. <p>The requirements and the consequent cryptographic design that underpin this protocol and its associated protocols are described in &xep0210; and <cite>Cryptographic Design of Encrypted Sessions</cite>. The specific objectives of this protocol include:</p>
  46. <ul>
  47. <li><p>Encryption of the full stanza content (except that which is required for stanza routing)</p></li>
  48. <li><p>Minimise the Perfect Forward Secrecy window by enabling light-weight renegotiation of the short-term keys without requiring a full session renegotiation.</p></li>
  49. <li><p>Minimise bandwidth overhead</p></li>
  50. <li><p>No dependence on XML canonicalization</p></li>
  51. </ul>
  52. </section1>
  53. <section1 topic="Dramatis Personae" anchor='personae'>
  54. <p>This document introduces two characters to help the reader follow the necessary exchanges:</p>
  55. <ol start='1'>
  56. <li>"Alice" is the name of the entity sending the encrypted stanza or initiating a re-key. Within the scope of this document, we stipulate that her fully-qualified JID is: &lt;alice@example.org/pda&gt;.</li>
  57. <li>"Bob" is the name of the entity receiving the encrypted stanza or accepting a re-key. Within the scope of this document, his fully-qualified JID is: &lt;bob@example.com/laptop&gt;.</li>
  58. </ol>
  59. <p>While Alice and Bob are introduced as "end users", they are simply meant to be examples of XMPP entities. Any directly addressable XMPP entity may send or receive encrypted stanzas within an encrypted session or initiate a re-key.</p>
  60. <p>Here we assume that Alice and Bob have already established an encrypted session. Either Alice or Bob MAY send encrypted stanzas within the encrypted session or initiate a re-key. The following sections describe the process where Alice sends Bob an encrypted stanza and initiates a re-key.</p>
  61. </section1>
  62. <section1 topic="Assumptions" anchor='assume'>
  63. <p>The following sections assume that the parameters in the tables below have already been agreed. For more details refer to an encrypted session negotiation protocol such as <cite>Encrypted Session Negotiation</cite>.</p>
  64. <table caption='Encryption Parameters'>
  65. <tr>
  66. <th>Parameter</th>
  67. <th>Description</th>
  68. </tr>
  69. <tr>
  70. <td>&CsubA;, &CsubB;</td>
  71. <td>The initial block cipher counter value for blocks sent by Alice and Bob</td>
  72. </tr>
  73. <tr>
  74. <td>&KCsubA;, &KCsubB;</td>
  75. <td>The initial secret cipher keys that Alice and Bob use to encrypt</td>
  76. </tr>
  77. <tr>
  78. <td>&KMsubA;, &KMsubB;</td>
  79. <td>The initial secret MAC keys that Alice and Bob use to protect the integrity of encrypted data</td>
  80. </tr>
  81. <tr>
  82. <td>HASH</td>
  83. <td>Agreed hash algorithm</td>
  84. </tr>
  85. <tr>
  86. <td>CIPHER, DECIPHER</td>
  87. <td>Agreed CTR-mode block cipher algorithm</td>
  88. </tr>
  89. <tr>
  90. <td>COMPRESS, DECOMPRESS</td>
  91. <td>Agreed compression algorithm</td>
  92. </tr>
  93. </table>
  94. <table caption='Re-Key Parameters'>
  95. <tr>
  96. <th>Parameter</th>
  97. <th>Description</th>
  98. </tr>
  99. <tr>
  100. <td>g</td>
  101. <td>Diffie-Hellman generator</td>
  102. </tr>
  103. <tr>
  104. <td>p</td>
  105. <td>Diffie-Hellman prime</td>
  106. </tr>
  107. <tr>
  108. <td>e, d</td>
  109. <td>Alice and Bob's initial public Diffie-Hellman keys</td>
  110. </tr>
  111. <tr>
  112. <td>x, y</td>
  113. <td>*Alice and Bob's initial private Diffie-Hellman keys</td>
  114. </tr>
  115. </table>
  116. <p>* x and y MUST be known only to Alice and Bob respectively, all other parameters MUST be known by both parties</p>
  117. <p>All parameters except the algorithms are multi-precision integers, so implementations will need a Big Integer Math library to perform the necessary modular arithmetic. Note: A simple HMAC function and a cryptographic-strength pseudo-random number generator are also required, but no other cryptographic code is necessary.</p>
  118. </section1>
  119. <section1 topic="Encryptable Content" anchor='content'>
  120. <p>Alice MAY use this protocol to encrypt only that part of the <em>content</em> of one-to-one &MESSAGE;, &PRESENCE; and &IQ; stanzas that would normally be ignored by the intermediate servers. She MUST NOT encrypt:</p>
  121. <ul>
  122. <li><p>Stanza wrapper element tags (only stanza content)</p></li>
  123. <li><p>&lt;error/&gt; elements <note>RFC 6120 requires that stanzas of type 'error' contain an &lt;error/&gt; child element.</note></p></li>
  124. <li><p>&lt;defined-condition xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/&gt; child elements of &lt;error/&gt; elements. <note>RFC 6120 requires that &lt;error/&gt; elements contain a &lt;defined-condition/&gt; child element.</note></p></li>
  125. <li><p>&THREAD; elements <note>Applications typically use &THREAD; elements internally to route stanzas to the process handling a session. The content of thread elements MUST be opaque with no semantic meaning and only exact comparisons MAY be made against it.</note></p></li>
  126. <li><p>&lt;amp/&gt; elements (see &xep0079;)</p></li>
  127. </ul>
  128. <p>A stanza MUST NOT contain more than one &lt;c xmlns='http://www.xmpp.org/extensions/xep-0200.html#ns'/&gt; element, and it MUST be an immediate child of the stanza wrapper element. There is only one exception to those two rules, if the stanza is type 'error' then its &lt;error/&gt; child element MAY also contain a &lt;c xmlns='http://www.xmpp.org/extensions/xep-0200.html#ns'/&gt; element.</p>
  129. <example caption='Plain Message Stanza'><![CDATA[
  130. <message from='alice@example.org/pda'
  131. to='bob@example.com/laptop'
  132. type='chat'>
  133. <thread>ffd7076498744578d10edabfe7f4a866</thread>
  134. <body>Hello, Bob!</body>
  135. <amp xmlns='http://jabber.org/protocol/amp'>
  136. <rule action='error' condition='match-resource' value='exact'/>
  137. </amp>
  138. <active xmlns='http://jabber.org/protocol/chatstates'/>
  139. </message>
  140. ]]></example>
  141. <example caption='Message Content to be Encrypted'><![CDATA[
  142. <body>Hello, Bob!</body>
  143. <active xmlns='http://jabber.org/protocol/chatstates'/>
  144. ]]></example>
  145. <example caption='Plain Presence Stanza'><![CDATA[
  146. <presence from='alice@example.org/pda'
  147. to='bob@example.com/laptop'>
  148. <show>dnd</show>
  149. <status>Working</status>
  150. <c xmlns='http://jabber.org/protocol/caps'
  151. node='http://exodus.jabberstudio.org/caps'
  152. ver='0.9'
  153. ext='jingle ftrans xhtml'/>
  154. <geoloc xmlns='http://jabber.org/protocol/geoloc'>
  155. <alt>1609</alt>
  156. <description>Jabber, Inc.</description>
  157. <error>10</error>
  158. <lat>39.75477</lat>
  159. <lon>-104.99768</lon>
  160. <timestamp>2004-02-19T21:12Z</timestamp>
  161. </geoloc>
  162. </presence>
  163. ]]></example>
  164. <example caption='Presence with Encrypted Content'><![CDATA[
  165. <presence from='alice@example.org/pda'
  166. to='bob@example.com/laptop'>
  167. <c xmlns='http://www.xmpp.org/extensions/xep-0200.html#ns'>
  168. <data> ** Base64 encoded m_final ** </data>
  169. <mac> ** Base64 encoded a_mac ** </mac>
  170. </c>
  171. </presence>
  172. ]]></example>
  173. <example caption='Plain IQ Error Stanza'><![CDATA[
  174. <iq from='alice@example.org/pda'
  175. to='bob@example.com/laptop'
  176. id='publish1'
  177. type='error'>
  178. <pubsub xmlns='http://jabber.org/protocol/pubsub'>
  179. <publish node='princely_musings'>
  180. <item id='ae890ac52d0df67ed7cfdf51b644e901'>
  181. ...
  182. </item>
  183. </publish>
  184. </pubsub>
  185. <error type='modify'>
  186. <not-acceptable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  187. <payload-too-big xmlns='http://jabber.org/protocol/pubsub#errors'/>
  188. </error>
  189. </iq>
  190. ]]></example>
  191. <example caption='Encrypted IQ Error Stanza'><![CDATA[
  192. <iq from='alice@example.org/pda'
  193. to='bob@example.com/laptop'
  194. id='publish1'
  195. type='error'>
  196. <c xmlns='http://www.xmpp.org/extensions/xep-0200.html#ns'>
  197. <data> ** Base64 encoded m_final ** </data>
  198. <mac> ** Base64 encoded a_mac ** </mac>
  199. </c>
  200. <error type='modify'>
  201. <not-acceptable xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>
  202. <c xmlns='http://www.xmpp.org/extensions/xep-0200.html#ns'>
  203. <data> ** Base64 encoded m_final ** </data>
  204. <mac> ** Base64 encoded a_mac ** </mac>
  205. </c>
  206. </error>
  207. </iq>
  208. ]]></example>
  209. </section1>
  210. <section1 topic="Encrypting a Stanza" anchor='encrypt'>
  211. <p>Alice MUST perform the following steps to encrypt the XML content. Note: if there is no XML content to be encrypted (e.g. if this is an empty <link url='#rekey'>Re-Key Exchange</link> stanza), then &CsubA; MUST be incremented by 1 (see below), and only the last two steps (normalization and MAC calculation) should be performed.</p>
  212. <ol start='1'>
  213. <li><p>Serialize the XML content she wishes to send into an array of UTF-8 bytes, m. <note>Although counter mode encryption requires no padding, implementations MAY still disguise the length of m by appending a random number of white-space characters.</note></p></li>
  214. <li>
  215. <p>Compress m using the negotiated algorithm. If a compression algorithm other than 'none' was agreed, the compression context is typically initialized after key exchange and passed from one stanza to the next, with only a partial flush at the end of each stanza. <note>If Bob were to receive a stanza out-of-order, then he would fail to decrypt the stanza and be forced to terminate the encrypted session.</note></p>
  216. <code>m_compressed = COMPRESS(m)</code>
  217. </li>
  218. <li>
  219. <p>Encrypt the data with the agreed algorithm in counter mode, using the encryption key &KCsubA;. Note: &CsubA; MUST be incremented by 1 for each encrypted block or partial block (i.e. &CsubA; = (&CsubA; + 1) mod 2<span class='super'>n</span>, where n is the number of bits per cipher block for the agreed block cipher algorithm). Note: if the block cipher algorithm 'none' was agreed then encryption MUST NOT be performed and &CsubA; MUST be incremented by 1 (for replay protection).</p>
  220. <code>m_final = CIPHER(&KCsubA;, &CsubA;, m_compressed)</code>
  221. </li>
  222. <li>
  223. <p>Generate the whole serialized <em>content</em> of the &lt;c/&gt; element:</p>
  224. <p>If there is encrypted XML content, the XML MUST include the Base64 encoded (even if the block cipher algorithm 'none' was agreed <note>The content is encoded even if no encryption is used to avoid triggering namespace errors when entities parse the XML.</note>, in accordance with Section 4 of &rfc4648;) value of m_final wrapped in a &lt;data/&gt; element.</p>
  225. <p>Only if Alice has received stanzas containing a &lt;key/&gt; element (see <link url='#rekey'>Re-Key Exchange</link>) from Bob since she sent her last stanza then the XML MUST include the (positive, non-zero) number of such stanzas she has received (since she sent her last stanza) wrapped in a &lt;new/&gt; element.</p>
  226. <p>The content may also contain one &lt;key/&gt; element (see <link url='#rekey'>Re-Key Exchange</link>) and one or more &lt;old/&gt; elements (see <link url='#publish'>Publishing Old MAC Values</link>).</p>
  227. <p>Alice MUST normalize the content by removing any whitespace from the serialized content (i.e. remove all character data from <em>between</em> all elements). Note: &lt;c/&gt; elements are so simple that there should <em>never</em> be a need to convert the XML to canonical form.</p>
  228. <p>For example:</p>
  229. <code>m_content = '&lt;data&gt; ** Base64 encoded m_final ** &lt;/data&gt;&lt;new&gt;1&lt;/new&gt;'</code>
  230. </li>
  231. <li>
  232. <p>Process the XML content, concatenated with the value of Alice's block cipher counter &CsubA;&#160;<em>before</em> the data was encrypted, through the HMAC algorithm (as defined in Section 2 of &rfc2104;), along with the agreed hash algorithm ("HASH") and the integrity key &KMsubA;.</p>
  233. <code>a_mac = <em>HMAC</em>(HASH, &KMsubA;, m_content | &CsubA;)</code>
  234. </li>
  235. </ol>
  236. </section1>
  237. <section1 topic="Sending an Encrypted Stanza" anchor='send'>
  238. <p>Before sending the stanza to Bob, Alice MUST wrap the (unnormalized) content and the Base64 encoded value of a_mac (wrapped in a &lt;mac/&gt; element) inside an &lt;c/&gt; element and insert it into the stanza in place of the original content.</p>
  239. <example caption='Message Stanza with Encrypted Content'><![CDATA[
  240. <message from='alice@example.org/pda'
  241. to='bob@example.com/laptop'
  242. type='chat'>
  243. <thread>ffd7076498744578d10edabfe7f4a866</thread>
  244. <c xmlns='http://www.xmpp.org/extensions/xep-0200.html#ns'>
  245. <data> ** Base64 encoded m_final ** </data>
  246. <new>1</new>
  247. <mac> ** Base64 encoded a_mac ** </mac>
  248. </c>
  249. <amp xmlns='http://jabber.org/protocol/amp' per-hop='true'>
  250. <rule action='error' condition='match-resource' value='exact'/>
  251. </amp>
  252. </message>
  253. ]]></example>
  254. </section1>
  255. <section1 topic="Decrypting a Stanza" anchor='decrypt'>
  256. <p>When Bob receives the stanza from Alice, he MUST extract and Base64 decode the values of m_final and a_mac from the content and perform the following steps.</p>
  257. <ol start='1'>
  258. <li>
  259. <p>Use any &lt;new/&gt; element the stanza may (or may not) contain to determine which of his &lt;key/&gt; elements (see <link url='#rekey-init'>Re-Key Initiation</link>) Alice had received before she sent him the stanza. He MUST use this information to determine which of his stored sets of values &setB; he should use to decrypt and verify the stanza. Bob MUST then securely destroy any of his sets of values that are older than the selected set.</p>
  260. </li>
  261. <li>
  262. <p>Remove the &lt;mac/&gt; element from the serialized content of the &lt;c/&gt; element, and normalize the remaining content by removing all whitespace. Calculate the Message Authentication Code (MAC) for the <em>content</em> concatenated with Alice's block cipher counter using the agreed hash algorithm ("HASH") and the integrity key &KMsubA;.</p>
  263. <code>b_mac = <em>HMAC</em>(HASH, &KMsubA;, m_content | &CsubA;)</code>
  264. </li>
  265. <li>
  266. <p>Verify that b_mac and a_mac match. If they are not identical, the content has been tampered with and Bob MUST terminate the encrypted session, he MAY send a &notacceptable; error to Alice. <note>If Bob were to receive a stanza out-of-order, then the MACs would not match because the values of &CsubA; would not be synchronized.</note></p>
  267. </li>
  268. <li>
  269. <p>Decrypt m_final using the agreed algorithm, &KCsubA; and &CsubA;. Note: &CsubA; MUST be incremented by 1 for each decrypted block (see <link url='#encrypt'>Encrypting a Stanza</link>). Note: if the block cipher algorithm 'none' was agreed decryption MUST NOT be performed and &CsubA; MUST be incremented by 1.</p>
  270. <code>m_compressed = DECIPHER(&KCsubA;, &CsubA;, m_final)</code>
  271. </li>
  272. <li>
  273. <p>Decompress m_compressed using the negotiated algorithm (usually 'none').</p>
  274. <code>m = DECOMPRESS(m_compressed)</code>
  275. </li>
  276. <li>
  277. <p>Replace the &lt;c/&gt; element in the serialized XML stanza with m and feed the stanza into an XML parser. If the parser returns an XML format error then Bob MUST terminate the encrypted session, he MAY send a &notacceptable; error to Alice. <note>Bob MUST NOT send a stream error to his server since intermediate entities are not responsible for encoded content.</note></p>
  278. </li>
  279. </ol>
  280. </section1>
  281. <section1 topic='Re-Key Exchange' anchor='rekey'>
  282. <section2 topic='Introduction' anchor='rekey-intro'>
  283. <p>Once an attacker has discovered an encryption key it could be used to decrypt all stanzas within a session, including stanzas that were intercepted <em>before</em> the key was discovered. To reduce the window of vulnerability, both Alice and Bob SHOULD use the Diffie-Hellman key exchange described below to agree a new encryption key as regularly as possible. They MUST also destroy all copies of keys as soon as they are no longer needed.</p>
  284. <p>Note: Although most entities are capable of exchanging new keys after every stanza, clients running in constrained runtime environments may require a few seconds of full-load CPU time in order to re-key. During encrypted session negotiation (when using <cite>Encrypted Session Negotiation</cite> for example) these clients MAY negotiate the minimum number of stanzas to be exchanged between re-keys at the cost of a larger window of vulnerability. Entities MUST NOT initiate key re-exchanges more frequently than the agreed limit.</p>
  285. <p>Either Alice or Bob MAY initiate a key re-exchange. Here we describe the process initiated by Alice.</p>
  286. </section2>
  287. <section2 topic='Re-Key Initiation' anchor='rekey-init'>
  288. <p>First Alice MUST calculate new values for the encryption parameters:</p>
  289. <ol start='1'>
  290. <li><p>Generate: a secret random number x (where &twosup2n; &lt; x &lt; p - 1, where n is the number of bits per cipher block for CIPHER)</p></li>
  291. <li><p>Calculate: e = &gsupx; mod p</p></li>
  292. <li><p>Calculate: K = &dsupx; mod p (the new shared secret)</p></li>
  293. <li><p>Alice's Encryption key: &KCsubA; = HMAC(HASH, K, "Rekey Initiator Crypt")</p></li>
  294. <li><p>Bob's Encryption key: &KCsubB; = HMAC(HASH, K, "Rekey Acceptor Crypt")</p></li>
  295. <li><p>Alice's Integrity key: &KMsubA; = HMAC(HASH, K, "Rekey Initiator MAC")</p></li>
  296. <li><p>Bob's Integrity key: &KMsubB; = HMAC(HASH, K, "Rekey Acceptor MAC")</p></li>
  297. </ol>
  298. <p>Note: Once &KCsubA;, &KMsubA;, &KCsubB; and &KMsubB; have been calculated the value of K MUST be securely destroyed. When calculating those keys, as many bits of key data as are needed for each key MUST be taken from the <em>least</em> significant bits of the output of HMAC. For algorithms with variable-length keys the maximum length (up to the output length of HMAC) SHOULD be used.</p>
  299. <p>The new value of e SHOULD be wrapped in a &lt;key/&gt; element and sent to Bob. To avoid unnecessary network traffic, it SHOULD be sent together with encrypted content (see <link url='#encrypt'>Encrypting a Stanza</link>). Alice MUST use her <em>old</em>&#160;&KCsubA; and &KMsubA; to encrypt and calculate the MAC of this stanza, after which she MUST securely destroy all copies of the old value of &KCsubA;. She MUST use her <em>new</em>&#160;&KCsubA; and &KMsubA; when sending <em>subsequent</em> stanzas.</p>
  300. <p>Note: There is no need for Alice to provide a signature because the calculation of the MAC includes the new value of e (see <link url='#encrypt'>Encrypting a Stanza</link>).</p>
  301. <example caption='Alice Sends Re-Key Stanza'><![CDATA[
  302. <message from='alice@example.org/pda' to='bob@example.com/laptop'>
  303. <thread>ffd7076498744578d10edabfe7f4a866</thread>
  304. <c xmlns='http://www.xmpp.org/extensions/xep-0200.html#ns'>
  305. <data> ** Base64 encoded m_final ** </data>
  306. <key> ** Base64 encoded value of new e ** </key>
  307. <mac> ** Base64 encoded a_mac ** </mac>
  308. </c>
  309. </message>
  310. ]]></example>
  311. <p>Note: Bob may send one of more stanzas before he receives Alice's &lt;key/&gt; element (i.e. the stanzas may be in transit at the same time). So, before destroying her old values of &KCsubB; and &KMsubB;, Alice MUST wait until either she receives a stanza encrypted with her new key, or a reasonable time has passed (60 seconds should cover a network round-trip and calculations by a constrained client). Similarly she MUST wait before destroying her old value of x, in case Bob sends one or more stanzas including a &lt;key/&gt; element before he receives Alice's new key. Consequently, if Alice sends several &lt;key/&gt; elements to Bob within a reasonable time without receiving a stanza from him, then she MUST remember several "sets" of the three values: &setA;.</p>
  312. <p>Note: Alice never remembers more than one copy of &KCsubA; and &KMsubA;.</p>
  313. </section2>
  314. <section2 topic='Re-Key Acceptance' anchor='rekey-accept'>
  315. <p>After receiving and <link url='#decrypt'>decrypting a stanza</link> that contains a &lt;key/&gt; element Bob MUST extract the new value of e and confirm that it is greater than one. Then he MUST calculate K using the new value of e and the value of y from his oldest stored set of values &setB; (i.e. the set that also contains the value of &KCsubA; used to decrypt the stanza):</p>
  316. <code>K = &esupy; mod p</code>
  317. <p>Bob MUST replace the values of &KCsubA; and &KMsubA; in <em>all</em> his stored sets of values &setB; with values that are derived from K in exactly the same way as Alice did (see <link url='#rekey-init'>Re-Key Initiation</link>).</p>
  318. <p>Only if Bob is storing exactly one set of values &setB; then he MUST also replace his values of &KCsubB; and &KMsubB; with values that are derived from K in exactly the same way as Alice did.</p>
  319. </section2>
  320. </section1>
  321. <section1 topic='Publishing Old MAC Values' anchor='publish'>
  322. <p>Once the expired MAC keys have been published, anyone could create valid arbitrary stanzas with them. This prevents anyone being able to prove the authenticity of a transcript of the encrypted session in the future.</p>
  323. <p>Either entity MAY publish old values of &KMsubA; and/or &KMsubB; within any encrypted stanza as long as it knows that all the stanzas that MAY use the old values have been received and validated. Note: A 'man-in-the-middle' could delay the delivery of stanzas indefinitely. So, before Alice publishes &KMsubA; (and &KMsubB;), she MUST wait until she has <em>both</em> sent a re-key to Bob <em>and</em> received a stanza from Bob encrypted with her new key. (She MAY also publish &KMsubB; after she has received a re-key from Bob.)</p>
  324. <example caption='Publishing Expired MAC Keys'><![CDATA[
  325. <message from='alice@example.org/pda' to='bob@example.com/laptop'>
  326. <thread>ffd7076498744578d10edabfe7f4a866</thread>
  327. <c xmlns='http://www.xmpp.org/extensions/xep-0200.html#ns'>
  328. <data> ** Base64 encoded m_final ** </data>
  329. <old> ** Base64 encoded old MAC key ** </old>
  330. <old> ** Base64 encoded old MAC key ** </old>
  331. <mac> ** Base64 encoded a_mac ** </mac>
  332. </c>
  333. </message>
  334. ]]></example>
  335. <p>Entities SHOULD ignore any &lt;old/&gt; elements they receive.</p>
  336. </section1>
  337. <section1 topic='Security Considerations' anchor='sec'>
  338. <section2 topic='Random Numbers' anchor='sec-prng'>
  339. <p>Weak pseudo-random number generators (PRNG) enable successful attacks. Implementors MUST use a cryptographically strong PRNG to generate all random numbers (see &rfc1750;).</p>
  340. </section2>
  341. <section2 topic='Storage' anchor='sec-storage'>
  342. <p>If either entity stores a (re-encrypted) transcript of an encrypted session for future consultation then the Perfect Forward Secrecy offered by this protocol is lost. If the negotiated value of the 'otr' <cite>Stanza Session Negotiation</cite> field is 'true' the entities MUST NOT store any part of the encrypted session content (not even in encrypted form).</p>
  343. </section2>
  344. <section2 topic='Replay Attacks' anchor='sec-replay'>
  345. <p>The block cipher counters maintained implicitly by Alice and Bob (&CsubA; and &CsubB;) prevent stanzas being replayed within any encrypted session. They ensure that the MAC will be different for all stanzas, even if the HMAC key and the content of the stanza are identical.</p>
  346. <p>Alice and Bob MUST ensure that every value of x and y (and therefore e and d) they generate is unique. This prevents complete online encrypted sessions being replayed.</p>
  347. </section2>
  348. <section2 topic='Maximum Key Life' anchor='sec-life'>
  349. <p>After each key exchange an entity MUST NOT exchange a total of &twosup32; encrypted <em>blocks</em> (not stanzas) before it initiates a key re-exchange (see &rfc4344;). Note: This limitation also ensures the same key and counter values are never used to encrypt two different blocks using counter mode (thus preventing simple attacks).</p>
  350. <p>In order to reduce the Perfect Forward Secrecy window of vulnerability, after an extended period of inactivity entities SHOULD re-key (or terminate the encrypted session).</p>
  351. </section2>
  352. <section2 topic='Extra Responsabilities of Implementors' anchor='sec-general'>
  353. <p>Cryptography plays only a small part in an entity's security. Even if it implements this protocol perfectly it may still be vulnerable to other attacks. For examples, an implementation might store encrypted session keys on swap space or save private keys to a file in cleartext! Implementors MUST take very great care when developing applications with secure technologies.</p>
  354. </section2>
  355. </section1>
  356. <section1 topic='IANA Considerations' anchor='iana'>
  357. <p>This document requires no interaction with &IANA;. </p>
  358. </section1>
  359. <section1 topic='XMPP Registrar Considerations' anchor='registrar'>
  360. <section2 topic='Protocol Namespaces' anchor='ns'>
  361. <p>Until this specification advances to a status of Draft, its associated namespace shall be "http://www.xmpp.org/extensions/xep-0200.html#ns"; upon advancement of this specification, the &REGISTRAR; shall issue a permanent namespace in accordance with the process defined in Section 4 of &xep0053;.</p>
  362. </section2>
  363. </section1>
  364. <section1 topic='XML Schemas' anchor='schema'>
  365. <code><![CDATA[
  366. <?xml version='1.0' encoding='UTF-8'?>
  367. <xs:schema
  368. xmlns:xs='http://www.w3.org/2001/XMLSchema'
  369. targetNamespace='http://www.xmpp.org/extensions/xep-0200.html#ns'
  370. xmlns='http://www.xmpp.org/extensions/xep-0200.html#ns'
  371. elementFormDefault='qualified'>
  372. <xs:element name='data' type='xs:string'/>
  373. <xs:element name='c'>
  374. <xs:complexType>
  375. <xs:sequence>
  376. <xs:element ref='data' minOccurs='0' maxOccurs='1'/>
  377. <xs:element ref='key' minOccurs='0' maxOccurs='1'/>
  378. <xs:element ref='mac' minOccurs='0' maxOccurs='1'/>
  379. <xs:element ref='new' minOccurs='0' maxOccurs='1'/>
  380. <xs:element ref='old' minOccurs='0' maxOccurs='unbounded'/>
  381. </xs:sequence>
  382. </xs:complexType>
  383. </xs:element>
  384. <xs:element name='key' type='xs:string'/>
  385. <xs:element name='mac' type='xs:string'/>
  386. <xs:element name='new' type='xs:positiveInteger'/>
  387. <xs:element name='old' type='xs:string'/>
  388. </xs:schema>
  389. ]]></code>
  390. </section1>
  391. </xep>