<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='xep.xsl'?>
<xep xmlns="">
<header>
  <title>Bidirectional Server-to-Server Connections</title>
  <abstract>This specification defines a protocol for using server-to-server connections in a bidirectional way such that stanzas are sent and received on the same TCP connection.</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>0288</number>
  <status>Draft</status>
  <type>Standards Track</type>
  <sig>Standards</sig>
  <approver>Council</approver>
  <dependencies>
    <spec>XMPP Core</spec>
    <spec>XEP-0178</spec>
    <spec>XEP-0220</spec>
  </dependencies>
  <supersedes/>
  <supersededby/>
  <shortname>bidi</shortname>
  <schemaloc>
    <url>http://xmpp.org/schemas/bidi.xsd</url>
  </schemaloc>
  
  <author>
    <firstname>Philipp</firstname>
    <surname>Hancke</surname>
    <email>fippo@andyet.com</email>
    <jid>fippo@goodadvice.pages.de</jid>
  </author>

  
    <author>
      <firstname>Dave</firstname>
      <surname>Cridland</surname>
      <email>dave@hellopando.com</email>
      <jid>dwd@dave.cridland.net</jid>
    </author>

  <revision>
    <version>1.0.1</version>
    <date>2016-10-17</date>
    <initials>ssw</initials>
    <remark><p>Fix syntax highlighting and tweak example formatting.</p></remark>
  </revision>
  <revision>
    <version>1.0</version>
    <date>2013-09-26</date>
    <initials>psa</initials>
    <remark><p>Per a vote of the XMPP Council, advanced status to Draft.</p></remark>
  </revision>
  <revision>
    <version>0.5</version>
    <date>2012-08-21</date>
    <initials>ph/dwd</initials>
    <remark><p>Defined additional security considerations about the "unsolicited dialback" attack on bidirectional connections.</p></remark>
  </revision>
  <revision>
    <version>0.4</version>
    <date>2012-07-23</date>
    <initials>ph</initials>
    <remark><p>Added security note about dealing with unexpected &lt;db:result type='valid'/&gt; elements</p></remark>
  </revision>
  <revision>
    <version>0.3</version>
    <date>2012-03-07</date>
    <initials>ph</initials>
    <remark>
      <ul>
        <li>Fixed wrong from/to in example comment.</li><!-- Torje -->
        <li>Required support for dialback error handling if the connecting server uses bidi in combination with dialback</li>
      </ul>
    </remark>
  </revision>
  <revision>
    <version>0.2</version>
    <date>2011-12-12</date>
    <initials>ph</initials>
    <remark><p>Minor clarifications about the implications of bidi and dialback.</p></remark>
  </revision>
  <revision>
    <version>0.1</version>
    <date>2010-10-04</date>
    <initials>psa</initials>
    <remark><p>Initial published version.</p></remark>
  </revision>
  <revision>
    <version>0.0.2</version>
    <date>2010-09-13</date>
    <initials>dwd</initials>
    <remark>
      <p>belated run-over pre-publication</p>
      <p>Added notes on authentication</p>
    </remark>
  </revision>
  <revision>
    <version>0.0.1</version>
    <date>2010-04-12</date>
    <initials>ph</initials>
    <remark><p>initial version</p></remark>
  </revision>
</header>
<section1 topic="Introduction" anchor="intro">
  <p><span class="ref"><link url="http://tools.ietf.org/html/rfc3920">RFC 3920</link></span> <note>RFC 3920: Extensible Messaging and Presence Protocol (XMPP): Core &lt;<link url="http://tools.ietf.org/html/rfc3920">http://tools.ietf.org/html/rfc3920</link>&gt;.</note> restricted server-to-server communication in such a way that a server had to use one TCP connection for XML stanzas sent from the server to the peer, and another TCP connection (initiated by the peer) for stanzas from the peer to the server, for a total of two TCP connections. <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> allows two servers to send stanzas in a bidirectional way, but does not define methods for explicitly signalling the usage thereof. This is accomplished herein.</p>
  <p>While this may seem like a mere optimization that decreases the number of sockets used by an implementation or increases the performance of the server-to-server connection<note>In constrained environments, bidirectional server-to-server connections exhibit a reduced packet round trip time, see &lt;<link url="http://www.isode.com/whitepapers/xmpp-performance-constrained.html">http://www.isode.com/whitepapers/xmpp-performance-constrained.html</link>&gt;.</note>, it actually removes some of the practical barriers for the implementation of Multiplexing in <span class="ref"><link url="https://xmpp.org/extensions/xep-0220.html">Server Dialback (XEP-0220)</link></span> <note>XEP-0220: Server Dialback &lt;<link url="https://xmpp.org/extensions/xep-0220.html">https://xmpp.org/extensions/xep-0220.html</link>&gt;.</note>.</p>
</section1>
<!--
http://www.ietf.org/mail-archive/web/xmpp/current/msg00658.html
http://www.ietf.org/mail-archive/web/xmpp/current/msg00664.html
-->
<section1 topic="Protocol" anchor="protocol">
  <section2 topic="Stream Feature" anchor="feature">
    <p>If a server supports bidirectional server-to-server streams, it should inform the connecting entity when returning stream features during the stream negotiation process (both before and after TLS negotiation). This is done by including a &lt;bidi/&gt; element qualified by the 'urn:xmpp:features:bidi' namespace.</p>
    <example caption="Stream features"><![CDATA[
<stream:features>
  <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
  <bidi xmlns='urn:xmpp:features:bidi'/>
</stream:features>
]]></example>
    <p>If the initiating entity chooses to use TLS, STARTTLS negotiation MUST be completed before enabling bidirectionality.</p>
  </section2>
  <section2 topic="Negotiation" anchor="nego">
    <p>To enable bidirectional communication, the connecting server sends a &lt;bidi/&gt; element qualified by the 'urn:xmpp:bidi' namespace. This SHOULD be done before either SASL negotiation or Server Dialback.</p>
    <example caption="Connecting Server Requests Bidirectionality"><![CDATA[
<!-- Client -->
<bidi xmlns='urn:xmpp:bidi'/>
]]></example>
    <p>After enabling bidirectionality, the connecting server continues to authenticate via SASL or requests to send stanzas for a domain pair with Server Dialback. The receiving server MUST NOT send stanzas to the peer before it has authenticated via SASL, or the peer's identity has been verified via Server Dialback. Note that the receiving server MUST NOT attempt to verify a dialback key on the same connection where the corresponding request was issued.</p>
    <p>Also note that the receiving server MUST only send stanzas for which it has been authenticated - in the case of TLS/SASL based authentication, this is the value of the stream's 'to' attribute, whereas in the case of Server Dialback this is the inverse of any domain pair that has been used in a dialback request.</p>
    <p>Finally, once bidirectionality is enabled, the receiving server MAY initiate Server Dialback authentications for other domains it hosts to any domain authenticated to be hosted by the connecting server. In particular, it may initiate Target Piggybacking for any target domain that has successfully been used as a source domain by the connecting server. Note that this implies that a connecting server that uses bidi and dialback MUST support dialback error conditions as defined in XEP 0220<note>Ideally, support for dialback errors would be signalled by a proper extension mechanism such as &lt;stream:features/&gt;. However, these are currently only sent from the receiving server to the connecting server and can therefore not be used for signalling support for dialback errors in the other direction.</note>.</p>
  </section2>
</section1>
<section1 topic="Examples" anchor="examples">
  <p>This section shows two complete examples of bidirectional streams, the first example uses SASL EXTERNAL, the second uses Server Dialback.</p>
  <example caption="Bidirectional Streams with SASL Authentication"><![CDATA[
<!-- Client -->
<stream:stream xmlns:stream='http://etherx.jabber.org/streams'
               xmlns='jabber:server' xmlns:db='jabber:server:dialback'
               to='montague.lit' from='capulet.lit'
               xml:lang='en' version='1.0'>
<!-- Server -->
<stream:stream xmlns='jabber:server' xmlns:db='jabber:server:dialback'
               xmlns:stream='http://etherx.jabber.org/streams' xml:lang='en'
               id='65b30434afd7646699d077f7affcb2c120c48e18'
               from='montague.lit' to='capulet.lit' version='1.0'>
<!-- Server -->
<stream:features>
  <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
  <bidi xmlns='urn:xmpp:features:bidi'/>
</stream:features>
<!-- Client -->
<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
<!-- Server -->
<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
<!-- Client -->
<stream:stream xmlns:stream='http://etherx.jabber.org/streams'
               xmlns='jabber:server' xmlns:db='jabber:server:dialback'
               to='montague.lit' from='capulet.lit'
               xml:lang='en' version='1.0'>
<!-- Server -->
<stream:stream xmlns='jabber:server' xmlns:db='jabber:server:dialback'
               xmlns:stream='http://etherx.jabber.org/streams' xml:lang='en'
               id='b5cd769b1dc292c6f6557fe76cabc4d112333f9a'
               from='montague.lit' to='capulet.lit' version='1.0'>
<stream:features>
  <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>
    <mechanism>EXTERNAL<mechanism>
  </mechanisms>
  <bidi xmlns='urn:xmpp:features:bidi'/>
</stream:features>
<!-- Client -->
<bidi xmlns='urn:xmpp:bidi'/>
<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='EXTERNAL'>
  Y2FwdWxldC5saXQ=
</auth>
<!-- Server -->
<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>
<!-- Client -->
<stream:stream xmlns:stream='http://etherx.jabber.org/streams'
               xmlns='jabber:server' xmlns:db='jabber:server:dialback'
               to='montague.lit' from='capulet.lit'
               xml:lang='en' version='1.0'>
<!-- Server -->
<stream:stream xmlns='jabber:server' xmlns:db='jabber:server:dialback'
               xmlns:stream='http://etherx.jabber.org/streams' xml:lang='en'
               id='b5cd769b1dc292c6f6557fe76cabc4d112333f9a'
               from='montague.lit' to='capulet.lit' version='1.0'>
<stream:features/>
<!-- At this point, S is allowed to send C stanzas from montague.lit to capulet.lit
     since that is the value of 'from' in the stream open sent by C above.
  -->
<!-- Client -->
<iq from='juliet@capulet.lit/balcony' to='montague.lit' type='get'
  id='8dfc70af'><query xmlns='urn:xmpp:ping'/></iq>
<!-- Server -->
<iq from='montague.lit' to='juliet@capulet.lit/balcony' type='result'
  id='8dfc70af'><query xmlns='urn:xmpp:ping'/></iq>
]]></example>
  <example caption="Bidirectional Streams with Server Dialback"><![CDATA[
<!-- Client -->
<stream:stream xmlns:stream='http://etherx.jabber.org/streams'
               xmlns='jabber:server' xmlns:db='jabber:server:dialback'
               to='montague.lit' from='capulet.lit'
               xml:lang='en' version='1.0'>
<!-- Server -->
<stream:stream xmlns='jabber:server' xmlns:db='jabber:server:dialback'
               xmlns:stream='http://etherx.jabber.org/streams' xml:lang='en'
               id='65b30434afd7646699d077f7affcb2c120c48e18'
               from='montague.lit' to='capulet.lit' version='1.0'>
<stream:features>
  <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
  <bidi xmlns='urn:xmpp:features:bidi'/>
</stream:features>
<!-- Client -->
<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
<!-- Server -->
<proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
<!-- Client -->
<stream:stream xmlns:stream='http://etherx.jabber.org/streams'
               xmlns='jabber:server' xmlns:db='jabber:server:dialback'
               to='montague.lit' from='capulet.lit'
               xml:lang='en' version='1.0'>
<!-- Server -->
<stream:stream xmlns='jabber:server' xmlns:db='jabber:server:dialback'
               xmlns:stream='http://etherx.jabber.org/streams' xml:lang='en'
               id='b5cd769b1dc292c6f6557fe76cabc4d112333f9a'
               from='montague.lit' to='capulet.lit' version='1.0'>
<stream:features>
  <mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'/>
  <bidi xmlns='urn:xmpp:features:bidi'/>
</stream:features>
]]></example>
  <example caption="Stream Setup before TLS"><![CDATA[
<!-- Client -->
<bidi xmlns='urn:xmpp:bidi'/>
<db:result from='capulet.lit' to='montague.lit'>
  e3f5cf21f12749ef2cf59269bc0118f35bc46b26</db:result>
<!-- Server -->
<db:result from='montague.lit' to='capulet.lit' type='valid'/>
<!-- At this point S may send from montague.lit to capulet.lit.-->
<!-- Client -->
<iq from='juliet@capulet.lit/balcony' to='montague.lit' type='get'
  id='8dfc70af'><query xmlns='urn:xmpp:ping'/></iq>
<!-- Server -->
<iq from='montague.lit' to='juliet@capulet.lit/balcony' type='result'
  id='8dfc70af'><query xmlns='urn:xmpp:ping'/></iq>
<db:result from='conference.montague.lit' to='capulet.lit'>
     1bac3ef56fed987cfe098c9785c654a5476ed765</db:result>
<!-- The above is also legal - S attempts to authenticate as
     a different domain as well, presumably a MUC domain.
     note that S can do this form of multiplexing regardless
     of the support for dialback errors since that was required by RFC 3920
  -->
<!-- Client -->
<db:result from='capulet.lit' to='conference.montague.lit' type='valid'/>
<!-- Now S can send as conference.m.l as well as C sending to that domain.
-->
]]></example>
</section1>
<section1 topic="Security Considerations" anchor="security">
  <p>This specification introduces no security considerations above and beyond those discussed in <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> or <span class="ref"><link url="https://xmpp.org/extensions/xep-0220.html">Server Dialback (XEP-0220)</link></span> <note>XEP-0220: Server Dialback &lt;<link url="https://xmpp.org/extensions/xep-0220.html">https://xmpp.org/extensions/xep-0220.html</link>&gt;.</note>.
  <!-- one might explain why not... http://mail.jabber.org/pipermail/xmppwg/2004-February/002026.html -->
  Note that the impact of the "unsolicited server dialback" attack described in <span class="ref"><link url="https://xmpp.org/extensions/xep-0220.html">Server Dialback (XEP-0220)</link></span> <note>XEP-0220: Server Dialback &lt;<link url="https://xmpp.org/extensions/xep-0220.html">https://xmpp.org/extensions/xep-0220.html</link>&gt;.</note> is considerably larger for bidirectional streams, e.g. a vulnerability which allows spoofing might also route messages to the wrong targets. Additionally, dialback elements with a "type" attribute also need to be handled in incoming connections.</p>
</section1>
<section1 topic="IANA Considerations" anchor="iana">
  <p>This document requires no interaction with the <span class="ref"><link url="http://www.iana.org/">Internet Assigned Numbers Authority (IANA)</link></span> <note>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 &lt;<link url="http://www.iana.org/">http://www.iana.org/</link>&gt;.</note>.</p>
</section1>
<section1 topic="XMPP Registrar Considerations" anchor="registrar">
  <section2 topic="Protocol Namespaces" anchor="registrar-ns">
    <p>The <span class="ref"><link url="https://xmpp.org/registrar/">XMPP Registrar</link></span> <note>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 &lt;<link url="https://xmpp.org/registrar/">https://xmpp.org/registrar/</link>&gt;.</note> includes 'urn:xmpp:bidi' in its registry of protocol namespaces (see &lt;<link url="https://xmpp.org/registrar/namespaces.html">https://xmpp.org/registrar/namespaces.html</link>&gt;).</p>
  </section2>
  <section2 topic="Stream Features" anchor="registrar-stream">
    <p>The XMPP Registrar includes 'urn:xmpp:features:bidi' in its registry of stream features (see &lt;<link url="https://xmpp.org/registrar/stream-features.html">https://xmpp.org/registrar/stream-features.html</link>&gt;).</p>
  </section2>
</section1>
<section1 topic="XML Schema" anchor="schema">
  <section2 topic="Bidi" anchor="schema-bidi">
    <code><![CDATA[
<?xml version='1.0' encoding='UTF-8'?>

<xs:schema
    xmlns:xs='http://www.w3.org/2001/XMLSchema'
    targetNamespace='urn:xmpp:bidi'
    xmlns='urn:xmpp:bidi'
    elementFormDefault='qualified'>

  <xs:annotation>
    <xs:documentation>
      The protocol documented by this schema is defined in
      XEP-0288: http://www.xmpp.org/extensions/xep-0288.html
    </xs:documentation>
  </xs:annotation>

  <xs:element name='bidi' type='empty'/>

  <xs:simpleType name='empty'>
    <xs:restriction base='xs:string'>
      <xs:enumeration value=''/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>
]]></code>
  </section2>
  <section2 topic="Stream Feature" anchor="schema-feature">
    <code><![CDATA[
<?xml version='1.0' encoding='UTF-8'?>

<xs:schema
    xmlns:xs='http://www.w3.org/2001/XMLSchema'
    targetNamespace='urn:xmpp:features:bidi'
    xmlns='urn:xmpp:features:bidi'
    elementFormDefault='qualified'>

  <xs:element name='bidi' type='empty'/>

  <xs:simpleType name='empty'>
    <xs:restriction base='xs:string'>
      <xs:enumeration value=''/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>
]]></code>
  </section2>
</section1>

<section1 topic="Acknowledgements" anchor="ack">
  <p>Thanks to Justin Karneges and Torje Henriksen.</p>
</section1>
</xep>
