<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep xmlns="">
<header>
  <title>E2E Authentication in XMPP</title>
  <abstract>This specification describes how X.509 certificates can be used for end-to-end authentication in XMPP.</abstract>
  
<legal>
<copyright>This XMPP Extension Protocol is copyright © 1999 – 2024 by the <link url="https://xmpp.org/">XMPP Standards Foundation</link> (XSF).</copyright>
<permissions>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.</permissions>
<warranty>## 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. ##</warranty>
<liability>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.</liability>
<conformance>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 &lt;<link url="https://xmpp.org/about/xsf/ipr-policy">https://xmpp.org/about/xsf/ipr-policy</link>&gt; or obtained by writing to XMPP Standards Foundation, P.O. Box 787, Parker, CO 80134 USA).</conformance>
</legal>
  <number>0416</number>
  <status>Deferred</status>
  <type>Standards Track</type>
  <sig>Standards</sig>
  <approver>Council</approver>
  <dependencies>
    <spec>XMPP Core</spec>
    <spec>XEP-0001</spec>
  </dependencies>
  <supersedes/>
  <supersededby/>
  <shortname>NOT_YET_ASSIGNED</shortname>
  
  <author>
    <firstname>Evgeny</firstname>
    <surname>Khramtsov</surname>
    <email>ekhramtsov@process-one.net</email>
    <jid>xram@zinid.ru</jid>
  </author>

  <revision>
    <version>0.1.0</version>
    <date>2019-03-06</date>
    <initials>XEP Editor (jsc)</initials>
    <remark>Accepted by vote of Council on 2019-02-27.</remark>
  </revision>
  <revision>
    <version>0.0.1</version>
    <date>2019-02-08</date>
    <initials>evk</initials>
    <remark><p>First draft.</p></remark>
  </revision>
</header>
<section1 topic="Introduction" anchor="intro">
  <p>X.509 version 3 certificates can be used to provide a strong cryptographic identity of an XMPP entity, i.e. an association of an XMPP address (<span class="ref"><link url="http://tools.ietf.org/html/rfc7622">RFC 7622</link></span> <note>RFC 7622: Extensible Messaging and Presence Protocol (XMPP): Address Format &lt;<link url="http://tools.ietf.org/html/rfc7622">http://tools.ietf.org/html/rfc7622</link>&gt;.</note>) with its cryptographic key (formally defined under Section 13.7.1.4 of <span class="ref"><link url="http://tools.ietf.org/html/rfc6120">RFC 6120</link></span> <note>RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core &lt;<link url="http://tools.ietf.org/html/rfc6120">http://tools.ietf.org/html/rfc6120</link>&gt;.</note>). They were initially intended for the use in SASL EXTERNAL for c2s and mutual s2s authentication (see <span class="ref"><link url="https://xmpp.org/extensions/xep-0178.html">Best Practices for Use of SASL EXTERNAL (XEP-0178)</link></span> <note>XEP-0178: Best Practices for Use of SASL EXTERNAL &lt;<link url="https://xmpp.org/extensions/xep-0178.html">https://xmpp.org/extensions/xep-0178.html</link>&gt;.</note>). This document extends their usage for end-to-end (e2e) authentication of any entities attached to the XMPP network. A separate document also defines how Certificate Signing Request (CSR) of an XMPP account can be issued and signed using the XMPP protocol (XEP-EAX-SIGN).</p>
  <p>Example usages:</p>
  <dl>
    <di><dt>E2E encryption</dt><dd>For end-to-end encryption, XMPP clients may use certificates to mutually identify each other, i.e. check that the cryptographic key belongs to this exact XMPP address.</dd></di>
    <di><dt>External services</dt><dd>An XMPP server may authenticate users of other servers at its local services, such as an HTTP Upload component (<span class="ref"><link url="https://xmpp.org/extensions/xep-0363.html">HTTP File Upload (XEP-0363)</link></span> <note>XEP-0363: HTTP File Upload &lt;<link url="https://xmpp.org/extensions/xep-0363.html">https://xmpp.org/extensions/xep-0363.html</link>&gt;.</note>), e.g. for granting file uploads, or a TURN server (<span class="ref"><link url="http://tools.ietf.org/html/rfc5766">RFC 5766</link></span> <note>RFC 5766: Traversal Using Relays around NAT (TURN): Relay Extensions to Session Traversal Utilities for NAT (STUN) &lt;<link url="http://tools.ietf.org/html/rfc5766">http://tools.ietf.org/html/rfc5766</link>&gt;.</note>).</dd></di>
    <di><dt>XMPP Usage of RELOAD</dt><dd>XMPP entities attached to the XOR overlay (XEP-0415) are supposed to use certificates for mutual authentication.</dd></di>
    <di><dt>SPAM protection</dt><dd>Since certificate authorities are required to be Sybil resistant (XEP-EAX-CAR), a spammer is limited in ability to create accounts massively. Thus it is expected that SPAM dissemination will fall to negligible levels.</dd></di>
    <di><dt>Registration delegation</dt><dd>XMPP accounts registration typically creates a huge burden for operators of public servers. An operator may want to delegate a registration of accounts of its own server to a trusted CA. The CA will validate the users' identities and will issue certificates for them. The users can use these certificates in c2s SASL EXTERNAL authentication at the operator's server as well as for e2e authentication with other entities.</dd></di>
  </dl>
  <p>Note that an XMPP client may use the same certificate for different kinds of e2e authentication.</p>
  <p>Conceptually, the idea is to build PKIX trees where in each tree a node corresponds to a certificate of a CA signing certificates of its successors. A leaf in the tree represents a certificate assigned to an XMPP account, a "leaf certificate". The leaf certificates are supposed to be used for (but not limited to) e2e authentication.</p>
  <example><![CDATA[
          Tree 1                  Tree 2                      Tree N
  +--------------------+  +---------------------+     +-----------------------+
  |     Root CA 1      |  |       Root CA 2     | ... |       Root CA N       |
  +--------------------+  +---------------------+     +-----------------------+
            |                        |                           |
            |                        |                           |
  +--------------------+  +---------------------+     +-----------------------+
  | juliet@capulet.lit |  | Intermediate CA 2.1 |     | CA of shakespeare.lit |
  +--------------------+  +---------------------+     +-----------------------+
                                     |                           |
                                     |                           |
                          +---------------------+     +-----------------------+
                          | romeo@montague.lit  |     | bard@shakespeare.lit  |
                          +---------------------+     +-----------------------+
]]></example>
  <p>In the example above, XMPP servers of domains "capulet.lit" and "montague.lit" do not have associated certificate authorities, so Root CA 1 and Intermediate CA 2.1 sign certificates of "juliet@capulet.lit" and "romeo@montague.lit" directly. An XMPP server of domain "shakespeare.lit" has an associated CA (whose certificate is signed by Root CA N) and thus is able to sign certificates for users of "shakespeare.lit" (and only for them). As long as all root CAs are trusted by all parties, "juliet@capulet.lit", "romeo@montague.lit" and "bard@shakespeare.lit" may mutually authenticate each other using their certificates (for sharing resources, exchanging messages, etc).</p>
</section1>
<section1 topic="Glossary" anchor="glossary">
  <dl>
    <di><dt>CA</dt><dd>Certificate authority - an entity that issues X.509 certificates.</dd></di>
    <di><dt>CSR</dt><dd>Certificate signing request - a message sent from an applicant to a certificate authority in order to apply for an X.509 certificate.</dd></di>
    <di><dt>Leaf certificate</dt><dd>A certificate assigned to an XMPP account.</dd></di>
    <di><dt>Domain-associated certificate</dt><dd>An intermediate certificate assigned for a particular XMPP domain. Such certificates can be used to sign leaf certificates associated with the same XMPP domain only.</dd></di>
    <di><dt>Intermediate certificate</dt><dd>A non-root certificate used for signing any other certificates.</dd></di>
    <di><dt>Root certificate</dt><dd>A self-signed certificate used for signing any other certificates.</dd></di>
  </dl>
</section1>
<section1 topic="Requirements" anchor="reqs">
  <section2 topic="General Requirements" anchor="gen-req">
    <ol>
      <li>The leaf certificate MUST be compliant with c2s SASL EXTERNAL authentication (<span class="ref"><link url="http://tools.ietf.org/html/rfc6120">RFC 6120</link></span> <note>RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core &lt;<link url="http://tools.ietf.org/html/rfc6120">http://tools.ietf.org/html/rfc6120</link>&gt;.</note>, <span class="ref"><link url="https://xmpp.org/extensions/xep-0178.html">Best Practices for Use of SASL EXTERNAL (XEP-0178)</link></span> <note>XEP-0178: Best Practices for Use of SASL EXTERNAL &lt;<link url="https://xmpp.org/extensions/xep-0178.html">https://xmpp.org/extensions/xep-0178.html</link>&gt;.</note>).</li>
      <li>The leaf certificate MUST be compliant with RELOAD authentication (<span class="ref"><link url="http://tools.ietf.org/html/rfc6940">RFC 6940</link></span> <note>RFC 6940: REsource LOcation And Discovery (RELOAD) Base Protocol &lt;<link url="http://tools.ietf.org/html/rfc6940">http://tools.ietf.org/html/rfc6940</link>&gt;.</note>).</li>
    </ol>
  </section2>
  <section2 topic="Certificate Requirements" anchor="cert-req">
    <p>The following rules apply to any certificate:</p>
    <ol>
      <li>The certificate MUST conform to <span class="ref"><link url="http://tools.ietf.org/html/rfc5280">RFC 5280</link></span> <note>RFC 5280: Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile &lt;<link url="http://tools.ietf.org/html/rfc5280">http://tools.ietf.org/html/rfc5280</link>&gt;.</note>.</li>
      <li>The subject field MUST NOT be null.</li>
      <li>The certificate MUST contain a keyUsage extension with the digitalSignature bit set.</li>
      <li>The certificate SHOULD use Elliptic Curve Cryptography. FIXME: correctly define this statement.</li>
    </ol>
    <p>The following rules apply to leaf certificates:</p>
    <ol>
      <li>The certificate MUST NOT contain a basicConstraints extension with the cA boolean set to TRUE.</li>
      <li>The certificate MUST include a CRL Distribution Points extension that specifies an URI of a Certificate Revocation List.</li>
      <li>The certificate MUST possess a single XMPP address represented as an XmppAddr as specified under Section 13.7.1.4 of <span class="ref"><link url="http://tools.ietf.org/html/rfc6120">RFC 6120</link></span> <note>RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core &lt;<link url="http://tools.ietf.org/html/rfc6120">http://tools.ietf.org/html/rfc6120</link>&gt;.</note>.</li>
      <li>The SubjectAltName field in the certificate MUST contain a single RELOAD URI as specified under Section 14.15 of <span class="ref"><link url="http://tools.ietf.org/html/rfc6940">RFC 6940</link></span> <note>RFC 6940: REsource LOcation And Discovery (RELOAD) Base Protocol &lt;<link url="http://tools.ietf.org/html/rfc6940">http://tools.ietf.org/html/rfc6940</link>&gt;.</note> encoded as uniformResourceIdentifier type. The "destination" part of the URI MUST be a RELOAD Node-ID. The Node-ID MAY be hexadecimal-encoded. The "overlay" part of the URI MUST be "xmpp.org". The "specifier" part of the URI MUST be empty.</li>
      <li>If the XMPP address doesn't contain non-ASCII characters, it MUST be encoded in the SubjectAltName field as rfc822Name type.</li>
    </ol>
    <p>Note that the rules for leaf certificates comply with the rules defined for client certificates under Sections 13.7.1.1 and 13.7.1.4 of <span class="ref"><link url="http://tools.ietf.org/html/rfc6120">RFC 6120</link></span> <note>RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core &lt;<link url="http://tools.ietf.org/html/rfc6120">http://tools.ietf.org/html/rfc6120</link>&gt;.</note>. Thus they can be used for c2s SASL EXTERNAL authentication.</p>
    <p>The requirement to possess a RELOAD URI and an rfc822Name address makes it possible to use the certificate for RELOAD authentication. Even if XOR extension (XEP-0415) is unused, the RELOAD URI uniquely identifies a user device: a user MAY have several certificates assigned to their XMPP address but with different RELOAD URIs.</p>
    <p>The following rules apply to domain-associated certificates:</p>
    <ol>
      <li>The certificate MUST contain a keyUsage extension with the keyCertSign bit set.</li>
      <li>The certificate MUST contain a basicConstraints extension with the cA boolean set to TRUE and pathLenConstraint set to 0 (zero).</li>
      <li>The certificate MUST include a CRL Distribution Points extension that specifies an URI of a Certificate Revocation List.</li>
      <li>The certificate MUST possess the associated domain name encoded as DNS-ID identifier type. The domain name MUST NOT contain the wildcard character '*'.</li>
    </ol>
    <p>The following rules apply to intermediate certificates, excluding domain-associated certificates:</p>
    <ol>
      <li>The certificate MUST contain a keyUsage extension with the keyCertSign bit set.</li>
      <li>The certificate MUST contain a basicConstraints extension with the cA boolean set to TRUE.</li>
      <li>The certificate MUST include a CRL Distribution Points extension that specifies an URI of a Certificate Revocation List.</li>
    </ol>
    <p>The following rules apply to root certificates:</p>
    <ol>
      <li>The certificate MUST contain a keyUsage extension with the keyCertSign bit set.</li>
      <li>The certificate MUST contain a basicConstraints extension with the cA boolean set to TRUE.</li>
    </ol>
  </section2>
  <section2 topic="CA Requirements" anchor="ca-req">
    <p>CA Requirements are outlined in XEP-EAX-CAR.</p>
  </section2>
</section1>
<section1 topic="Certificate Validation" anchor="cert-valid">
  <p>The certificate is considered valid if it follows the rules specified in <link url="#cert-req">Certificate Requirements</link> and, in the case when it is signed by a domain-associated certificate, it is a leaf certificate and the domain from the domain-associated certificate matches the domain part of the XmppAddr of the certificate. Otherwise, the certificate MUST be considered invalid.</p>
  <p>In the case of a certificate chain, the rules for certification path validation are applied (<span class="ref"><link url="http://tools.ietf.org/html/rfc5280">RFC 5280</link></span> <note>RFC 5280: Internet X.509 Public Key Infrastructure Certificate and Certificate Revocation List (CRL) Profile &lt;<link url="http://tools.ietf.org/html/rfc5280">http://tools.ietf.org/html/rfc5280</link>&gt;.</note>).</p>
</section1>
<section1 topic="Root Certificates Discovery" anchor="root-cert-disco">
  <p>An XMPP entity MAY maintain its own list of root certificates. However, in practice it's convenient to retrieve this list from a trusted source. For example, several organizations in the Internet maintain and provide such lists for certificates verification in the Web. This section specifies how the list of root certificates can be retrieved for the purpose of e2e authentication in XMPP.</p>
  <p>Since the authentication is intended to be compliant with RELOAD and creating new document formats or DNS TXT records without exigency are in general discouraged, the Overlay Configuration document is reused to provide the list of root certificates (see Section 11.1 of <span class="ref"><link url="http://tools.ietf.org/html/rfc6940">RFC 6940</link></span> <note>RFC 6940: REsource LOcation And Discovery (RELOAD) Base Protocol &lt;<link url="http://tools.ietf.org/html/rfc6940">http://tools.ietf.org/html/rfc6940</link>&gt;.</note>). The root certificates are PEM-encoded (<span class="ref"><link url="http://tools.ietf.org/html/rfc7468">RFC 7468</link></span> <note>RFC 7468: Textual Encodings of PKIX, PKCS, and CMS Structures &lt;<link url="http://tools.ietf.org/html/rfc7468">http://tools.ietf.org/html/rfc7468</link>&gt;.</note>) with encapsulation boundaries removed and are included in &lt;root-cert/&gt; elements of the Overlay Configuration.</p>
  <p>In order to retrieve the Overlay Configuration, an HTTP GET request is performed to "https://xmpp.org/.well-known/reload-config". The requesting UA MUST be prepared to process HTTP redirects. In the case of a failure, the UA MAY repeat the request. In this case exponential backoff MUST be applied. Since the list of root certifcates is not a subject for frequent updates, under normal conditions, the UA SHOULD NOT request the Overlay Configuration more often than once per day. Usage of 'If-Modified-Since' is RECOMMENDED (<span class="ref"><link url="http://tools.ietf.org/html/rfc7232">RFC 7232</link></span> <note>RFC 7232: Hypertext Transfer Protocol (HTTP/1.1): Conditional Requests &lt;<link url="http://tools.ietf.org/html/rfc7232">http://tools.ietf.org/html/rfc7232</link>&gt;.</note>).</p>
  <p>Further versions of this specification MAY extend the Overlay Configuration with new XML elements.</p>
</section1>
<section1 topic="Leaf Certificates Discovery" anchor="leaf-cert-disco">
  <p>An XMPP entity MAY want to publish its certificate so other XMPP entities MAY retrieve it. The method to accomplish this depends on the usage:</p>
  <ul>
    <li>In the case of an ordinary XMPP usage (<span class="ref"><link url="http://tools.ietf.org/html/rfc6120">RFC 6120</link></span> <note>RFC 6120: Extensible Messaging and Presence Protocol (XMPP): Core &lt;<link url="http://tools.ietf.org/html/rfc6120">http://tools.ietf.org/html/rfc6120</link>&gt;.</note>) a special PEP node (<span class="ref"><link url="https://xmpp.org/extensions/xep-0163.html">Personal Eventing Protocol (XEP-0163)</link></span> <note>XEP-0163: Personal Eventing Protocol &lt;<link url="https://xmpp.org/extensions/xep-0163.html">https://xmpp.org/extensions/xep-0163.html</link>&gt;.</note>) is used as specified in XEP-EAX-SIGN.</li>
    <li>In the case of XMPP Usage of RELOAD (XEP-0415) a peer is REQUIRED to store its certificate in the RELOAD overlay (see Section 8 of <span class="ref"><link url="http://tools.ietf.org/html/rfc6940">RFC 6940</link></span> <note>RFC 6940: REsource LOcation And Discovery (RELOAD) Base Protocol &lt;<link url="http://tools.ietf.org/html/rfc6940">http://tools.ietf.org/html/rfc6940</link>&gt;.</note>).</li>
  </ul>
</section1>
<section1 topic="Accessibility Considerations" anchor="access">
  <p>None required.</p>
</section1>
<section1 topic="Internationalization Considerations" anchor="i18n">
  <p>None required.</p>
</section1>
<section1 topic="Security Considerations" anchor="security">
  <p>TBD.</p>
</section1>
<section1 topic="IANA Considerations" anchor="iana">
  <p>None required.</p>
</section1>
<section1 topic="XMPP Registrar Considerations" anchor="registrar">
  <p>None required.</p>
</section1>
<section1 topic="XML Schema" anchor="schema">
  <p>None required.</p>
</section1>
</xep>
