End-to-end encryption of traffic sent over the Extensible Messaging and Presence Protocol (XMPP) is a desirable goal. The Jabber/XMPP developer community has experimented with several such technologies, including OpenPGP (Current Jabber OpenPGP Usage (XEP-0027) ), S/MIME (RFC 3923 ), and encrypted sessions or "ESessions" (Bootstrapping Implementation of Encrypted Sessions (XEP-0218) ). For various reasons, these technologies have not been widely implemented and deployed. When the XMPP Standards Foundation (XSF)  asked various Internet security experts to complete a security review of encrypted sessions, it was recommended to explore the possibility of instead using the Transport Layer Security (TLS; see RFC 4346 ) as the base technology for end-to-end encryption XMPP traffic. That possibility is explored in this document.
TLS is the most widely implemented protocol for securing network traffic. In addition to applications in the email infrastructure, the World Wide Web (HTTP Over TLS; see RFC 2818 ), and datagram transport for multimedia session negotiation (DTLS; see RFC 4347 ), TLS is used in XMPP to secure TCP connections from client to server and from server to server, as specified in XMPP Core . Therefore TLS is already a familiar technology for many XMPP developers.
The basic idea behind XTLS is that two XMPP entities negotiate an encrypted "tunnel" between themselves over XMPP. The tunnel is negotiated using standard TLS handshake data, contained in XMPP <iq/> stanzas and encapsulated as Base64-encoded payloads of a <data/> element qualified by a dedicated namespace. The entities can then exchange TLS-encrypted XMPP stanzas over that tunnel.
XTLS is not limited to client-to-client encryption, since it can be used between two XMPP clients, between an XMPP client and a remote XMPP service (i.e., a service with which a client does not have a direct XML stream, such as a Multi-User Chat (XEP-0045)  chatroom), or between two remote XMPP services.
It is intended that this specification will address the requirements specified in Requirements for Encrypted Sessions (XEP-0210) , or some reasonable subset thereof (yet to be defined). However, there is no guarantee that this specification addresses those requirements in its current form. Detailed analysis will need to be performed in order to determine whether XTLS meets the full requirements for end-to-end encryption of XMPP traffic.
In XTLS, the initiator functions as a TLS client and the responder functions as a TLS server.
To start the use of XTLS, the initiator sends an IQ-set containing a <start/> element qualified by the 'urn:xmpp:tmp:xtls' namespace (see Protocol Namespaces regarding issuance of one or more permanent namespaces).
(Note: This is the functional equivalent of the <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/> command for direct XML streams as specified in RFC 3920.)
If the responder supports XTLS and agrees to start the use of XTLS, it returns an IQ-result containing a <proceed/> element qualified by the 'urn:xmpp:tmp:xtls' namespace (see Protocol Namespaces regarding issuance of one or more permanent namespaces).
(Note: This is the functional equivalent of the <proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/> command for direct XML streams as specified in RFC 3920.)
If the responder does not support XTLS, in accordance with core XMPP semantics it MUST return a <service-unavailable/> error.
If the responder supports XTLS but does not wish to proceed with the use of XTLS, it MUST return a <not-acceptable/> error.
It is possible that both parties will attempt to start the use of XTLS at the same time , in which case one party might receive an XTLS start stanza from the other party after it has sent such an XTLS start stanza but before receiving a response. In this case, one of the initiation requests shall be considered to have higher priority than the other, and the party that receives the lower priority initiation request shall return a <conflict/> stanza error in response to the lower priority request. The higher priority request MUST be considered the request that is generated by the party whose JID is sorted before the other party when the JIDs of both parties are sorted using "i;octet" collation as specified in Section 9.3 of RFC 4790 .
In this example, firstname.lastname@example.org/balcony is sorted before email@example.com/orchard and therefore her XTLS start stanza has a higher priority. Therefore she would return a conflict error to Romeo if they both send an XTLS start stanza at the same time.
C2C Authentication Using TLS (XEP-0250)  defines an IQ stanza to determine which TLS method shall be used for client-to-client STARTTLS as described in End-to-End XML Streams (XEP-0246) . The initiator MAY exchange the XEP-0250 offers first, but MAY instead include the offers in the XTLS <start/> stanza to save a round trip. A client supporting XTLS and XEP-0250 MUST support offer exchange in the XTLS <start/> stanza.
If the responder supports XTLS, agrees to start the use of XTLS, and can verify the X.509 fingerprint, it returns an IQ-result containing a <proceed/> element with its offer.
If the initiator detects that a TLS handshake will fail based on the received offers (e.g. the peer only supports X.509 certificates and the client is unable to verify the certificate), the initiator MUST close the tunnel immediately (see Closing the XTLS Tunnel).
Before sending encrypted data, the parties MUST perform a TLS handshake to establish the the XTLS tunnel. The TLS library sends the handshake and all encrypted data in-band as Base64-encoded payload of a <data> element qualified by the 'urn:xmpp:tmp:xtls' namespace (see Protocol Namespaces regarding issuance of one or more permanent namespaces). (This is similar to how data is sent in-band using In-Band Bytestreams (XEP-0047) , but in a dedicated namespace to work around the potential blockage of IBB exchanges by server administrators.) During the handshake, the responder (which functions as the TLS server) SHOULD send a CertificateRequest if X.509 certificates are used, since mutual authentication is desired. The first stanza MUST include a 'method' attribute defining the TLS method to be used. Possible values are 'x509', 'openpgp', and 'srp'. While this information is also included in the TLS handshake message itself, it can be useful for the recipient to know this before sending the data to the TLS library in use, e.g. when SRP is used the client might need to provide the password to the TLS library before decoding any data.
Note: It is possible that XTLS stanzas will not respect TLS message boundaries; therefore the number of IQ stanzas depends on the TLS implementation.
The responder then acknowledges the stanza and, if the stream contains the complete ClientHello message, it continues with the TLS handshake. Otherwise it will wait for more messages from the initiator.
After the TLS handshake has been completed, the parties exchange encrypted data over the tunnel. Because the routing information is already present in the IQ stanzas used by XTLS, it is OPTIONAL for the stanzas encapsulated in the XTLS stream to include routing information (i.e., the 'from' and 'to' attributes). In that case, the entity receiving the data MUST supply the 'from' and 'to' addresses of the IQ stanza that contains the encrypted data.
The sender's client would strip off the routing information.
This message is then encrypted and sent in one or more stanzas over the XTLS tunnel.
Either party can close the XTLS tunnel; this is done by sending an IQ-set containing an empty <close/> element qualified by the 'urn:xmpp:tmp:xtls' namespace (see Protocol Namespaces regarding issuance of one or more permanent namespaces). However, if the entities have a mutual presence subscription then it is RECOMMENDED for the entities to maintain the tunnel until one entity becomes unavailable. Keeping the XTLS tunnel open does not require significant resources and prevents the need for a new TLS handshake.
The other party then acknowledges that the tunnel is closed by sending an IQ-result containing an empty <closed/> element qualified by the 'urn:xmpp:tmp:xtls' namespace (see Protocol Namespaces regarding issuance of one or more permanent namespaces).
If the tunnel is unknown to the receiving party, it MUST return an <item-not-found/> error.
If an error is detected, the tunnel MUST be considered closed and invalid.
As mentioned, XTLS is intended to address the requirements specified in XEP-0210 (or a reasonable subset thereof). This section compares XTLS against the requirements and points out gaps that might need to be filled with changes to XTLS or to TLS itself.
If an entity wishes to request the use of XTLS, it SHOULD first determine whether the intended responder supports the protocol. This can be done directly via Service Discovery (XEP-0030)  or indirectly via Entity Capabilities (XEP-0115) .
If an entity supports XTLS, it MUST report that by including a service discovery feature of "urn:xmpp:tmp:xtls" in response to disco#info requests (see Protocol Namespaces regarding issuance of one or more permanent namespaces).
Both service discovery and entity capabilities information could be corrupted or intercepted; for details, see the Denial of Service section of this document.
This entire document addresses security. Particular security-related issues are discussed in the following sections.
An implementation MUST at a minimum support the TLS_RSA_WITH_3DES_EDE_CBC_SHA and TLS_DH_RSA_WITH_AES_256_CBC_SHA ciphers. An implementation MAY support other ciphers as well.
As noted, XTLS can be used between XMPP clients, between an XMPP client and a remote XMPP service (i.e., a service with which a client does not have a direct XML stream), or between remote XMPP services. Therefore, a party to an XTLS tunnel will present either a client certificate or a server certificate as appropriate. Such certificates MUST be generated and validated in accordance with the certificate guidelines guidelines provided in rfc3920bis .
A future version of this specification might provide additional guidelines regarding certificate validation in the context of client-to-client encryption.
The XTLS start stanzas and proceed stanzas are not encrypted or signed; the same is true of service discovery exchanges and entity capabilities data. Therefore it is possible for an attacker to intercept these stanzas and modify them (e.g., by spuriously returning a <service-unavailable/> error), thus convincing the initiator that the responder does not support XTLS and therefore denying the parties an opportunity to use XTLS.
A future version of this specification might address this problem.
This document requires no interaction with the Internet Assigned Numbers Authority (IANA) .
Until this proposal is accepted for publication by the XSF, its associated namespace shall be "urn:xmpp:tmp:xtls". Upon publication as a XEP, the XMPP Registrar  shall issue an initial namespace in accordance with the process defined in Section 4 of XMPP Registrar Function (XEP-0053) . The namespace "urn:xmpp:xtls:0" is requested and is thought to be unique per the XMPP Registrar's requirements.
The authors wish to thank Eric Rescorla for initial suggestions regarding the use of TLS for application-layer encryption in XMPP. Thanks also to Joe Hildebrand and Remko Tronçon for their comments and suggestions.
This document in other formats: XML PDF
This XMPP Extension Protocol is copyright © 1999 – 2018 by the XMPP Standards Foundation (XSF).
Permission is hereby granted, free of charge, to any person obtaining a copy of this specification (the "Specification"), to make use of the Specification without restriction, including without limitation the rights to implement the Specification in a software program, deploy the Specification in a network service, and copy, modify, merge, publish, translate, distribute, sublicense, or sell copies of the Specification, and to permit persons to whom the Specification is furnished to do so, subject to the condition that the foregoing copyright notice and this permission notice shall be included in all copies or substantial portions of the Specification. Unless separate permission is granted, modified works that are redistributed shall not contain misleading information regarding the authors, title, number, or publisher of the Specification, and shall not claim endorsement of the modified works by the authors, any organization or project to which the authors belong, or the XMPP Standards Foundation.
## NOTE WELL: This Specification is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. ##
In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall the XMPP Standards Foundation or any author of this Specification be liable for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising from, out of, or in connection with the Specification or the implementation, deployment, or other use of the Specification (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if the XMPP Standards Foundation or such author has been advised of the possibility of such damages.
This XMPP Extension Protocol has been contributed in full conformance with the XSF's Intellectual Property Rights Policy (a copy of which can be found at <https://xmpp.org/about/xsf/ipr-policy> or obtained by writing to XMPP Standards Foundation, P.O. Box 787, Parker, CO 80134 USA).
The Extensible Messaging and Presence Protocol (XMPP) is defined in the XMPP Core (RFC 6120) and XMPP IM (RFC 6121) specifications contributed by the XMPP Standards Foundation to the Internet Standards Process, which is managed by the Internet Engineering Task Force in accordance with RFC 2026. Any protocol defined in this document has been developed outside the Internet Standards Process and is to be understood as an extension to XMPP rather than as an evolution, development, or modification of XMPP itself.
The primary venue for discussion of XMPP Extension Protocols is the <firstname.lastname@example.org> discussion list.
Discussion on other xmpp.org discussion lists might also be appropriate; see <http://xmpp.org/about/discuss.shtml> for a complete list.
Given that this XMPP Extension Protocol normatively references IETF technologies, discussion on the <email@example.com> list might also be appropriate.
Errata can be sent to <firstname.lastname@example.org>.
The following requirements keywords as used in this document are to be interpreted as described in RFC 2119: "MUST", "SHALL", "REQUIRED"; "MUST NOT", "SHALL NOT"; "SHOULD", "RECOMMENDED"; "SHOULD NOT", "NOT RECOMMENDED"; "MAY", "OPTIONAL".
4. The XMPP Standards Foundation (XSF) is an independent, non-profit membership organization that develops open extensions to the IETF's Extensible Messaging and Presence Protocol (XMPP). For further information, see <https://xmpp.org/about/xmpp-standards-foundation>.
11. For example, the applications might automatically open an XTLS tunnel based on presence information.
18. RFC 3920: Extensible Messaging and Presence Protocol (XMPP): Core <http://tools.ietf.org/html/draft-ietf-saintandre-rfc3920bis>.
19. The Internet Assigned Numbers Authority (IANA) is the central coordinator for the assignment of unique parameter values for Internet protocols, such as port numbers and URI schemes. For further information, see <http://www.iana.org/>.
20. The XMPP Registrar maintains a list of reserved protocol namespaces as well as registries of parameters used in the context of XMPP extension protocols approved by the XMPP Standards Foundation. For further information, see <https://xmpp.org/registrar/>.
Note: Older versions of this specification might be available at http://xmpp.org/extensions/attic/
First draft, based on suggestions from Eric Rescorla.