<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc sortrefs="yes"?>
<?rfc strict="yes"?>
<?rfc symrefs="yes"?>
<?rfc toc="yes"?>
<?rfc tocdepth="3"?>
<?rfc rfcedstyle="yes"?>

<rfc category='std' number='7247' ipr='trust200902'
submissionType="IETF" consensus="yes">

  <front>
    <title abbrev="SIP-XMPP Interworking: Core">Interworking between the Session Initiation Protocol (SIP) and the Extensible Messaging and Presence Protocol (XMPP): Architecture,&nbsp;Addresses, and Error Handling</title>

    <author initials="P." surname="Saint-Andre" fullname="Peter Saint-Andre">
      <organization>&amp;yet</organization>
      <address>
        <email>ietf@stpeter.im</email>
      </address>
    </author>
    <author initials="A." surname="Houri" fullname="Avshalom Houri">
      <organization>IBM</organization>
      <address>
        <postal>
          <street>Rorberg Building, Pekris 3</street>
          <city>Rehovot</city>
          <code>76123</code>
          <country>Israel</country>
        </postal>
        <email>avshalom@il.ibm.com</email>
      </address>
    </author>
    <author initials="J." surname="Hildebrand" fullname="Joe Hildebrand">
      <organization>Cisco Systems, Inc.</organization>
      <address>
        <postal>
          <street>1899 Wynkoop Street, Suite 600</street>
          <city>Denver</city>
          <region>CO</region>
          <code>80202</code>
          <country>USA</country>
        </postal>
        <email>jhildebr@cisco.com</email>
      </address>
    </author>

    <date month="May" year="2014"/>

    <area>RAI</area>
    <keyword>XMPP</keyword>
    <keyword>SIP</keyword>

    <abstract>
      <t>As a foundation for the definition of bidirectional protocol mappings
      between the Session Initiation Protocol (SIP) and the Extensible
      Messaging and Presence Protocol (XMPP), this document specifies the
      architectural assumptions underlying such mappings as well as the
      mapping of addresses and error conditions.</t>

    </abstract>
  </front>

  <middle>

    <section title="Introduction" anchor="intro">
      <t>The IETF has worked on two signaling technologies that can be used
      for multimedia session negotiation, instant messaging, presence,
      capabilities discovery, notifications, and other functions served by
      real-time communication applications:</t>

      <t>
        <list style='symbols'>
          <t>The Session Initiation Protocol <xref target="RFC3261"/>, along
          with various SIP extensions developed within the SIP for Instant
          Messaging and Presence Leveraging Extensions (SIMPLE) Working
          Group.</t>

          <t>The Extensible Messaging and Presence Protocol <xref
          target='RFC6120'/>, along with various XMPP extensions developed by
          the IETF as well as by the XMPP Standards Foundation (XSF).</t>

        </list>
      </t>
      <t>Because these technologies are widely deployed, it is important to
      clearly define mappings between them for the sake of interworking.  This
      document provides the basis for a series of SIP-XMPP interworking
      specifications by defining architectural assumptions, address
      translation methods, and error condition mappings.  Other documents in
      this series define mappings for presence, messaging, and media
      sessions.</t>

      <t>The guidelines in this series are based on implementation and
      deployment experience, and they describe techniques that have worked well in
      the field with existing systems.  In practice, interworking has been
      achieved through direct protocol mappings, not through mapping to an
      abstract model as described in, for example, <xref target='RFC3859'/>
      and <xref target='RFC3860'/>.  Therefore, this series describes the
      direct mapping approach in enough detail for developers of new
      implementations to achieve practical interworking between SIP systems
      and XMPP systems.</t>

    </section>

    <section title="Intended Audience" anchor="audience">
      <t>The documents in this series are intended for use by software
      developers who have an existing system based on one of these
      technologies (e.g., SIP) and would like to enable communication from
      that existing system to systems based on the other technology (e.g.,
      XMPP).  With regard to this document, we assume that readers are familiar
      with the core specifications for both SIP and XMPP; with regard to
      the other documents in this series, we assume that readers are familiar
      with this document as well as with the relevant SIP and XMPP extensions.
      </t>

    </section>

    <section title="Terminology" anchor="terms">
      <t>A number of terms used here are explained in <xref target='RFC3261'/>
      and <xref target='RFC6120'/>.</t>

      <t>Several examples use the "XML Notation" from the Internationalized
      Resource Identifier (IRI) specification <xref target='RFC3987'/>
      to represent Unicode characters outside the ASCII range
      (e.g., the string "&#xFC;" stands for the Unicode character
      <xref target='UNICODE'/> LATIN SMALL LETTER U WITH DIAERESIS,
      U+00FC).</t>

      <t>In architectural diagrams, SIP traffic is shown using arrows such as
      "***>", whereas XMPP traffic is shown using arrows such as "...>".</t>

      <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
      "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
      "OPTIONAL" in this document are to be interpreted as described in <xref
      target='RFC2119'/>.</t>

    </section>

    <section title="Architectural Assumptions" anchor="intro-arch">
      <t>Protocol translation between SIP and XMPP could occur in a number of
      different entities, depending on the architecture of real-time
      communication deployments.  For example, protocol translation could
      occur within a multiprotocol server (which uses protocol-specific
      connection managers to initiate traffic to and accept traffic from
      clients or other servers natively using SIP/SIMPLE, XMPP, etc.), within
      a multiprotocol client (which enables a user to establish connections
      natively with various servers using SIP/SIMPLE, XMPP, etc.), or within a
      gateway that acts as a dedicated protocol translator (which takes one
      protocol as input and provides another protocol as output).</t>

      <t>This document assumes that the protocol translation will occur within
      a gateway, specifically:</t>

      <t>
        <list style='symbols'>
          <t>When information needs to flow from an XMPP-based system to a
          SIP-based system, protocol translation will occur within an
          "XMPP-to-SIP gateway" that translates XMPP syntax and semantics on
          behalf of an "XMPP server" (together, these two logical functions
          comprise an "XMPP service").</t>

          <t>When information needs to flow from a SIP-based system to an
          XMPP-based system, protocol translation will occur within a
          "SIP-to-XMPP gateway" that translates SIP syntax and semantics on
          behalf of a "SIP server" (together, these two logical functions
          comprise a "SIP service").</t>

        </list>
      </t>
      <t>Naturally, these logical functions could occur in one and the same
      actual entity; we differentiate between them mainly for explanatory
      purposes (although, in practice, such gateways are indeed fairly
      common).</t>

      <t><list style='empty'><t>Note: This assumption is not meant to
      discourage protocol translation within multiprotocol clients or
      servers; instead, this assumption is followed mainly to clarify the
      discussion and examples so that the protocol translation principles can
      be more easily understood and can be applied by client and server
      implementors with appropriate modifications to the examples and
      terminology.</t></list></t>

      <t>This document assumes that a gateway will translate directly from one
      protocol to the other.  For the sake of the examples, we further assume
      that protocol translation will occur within a gateway in the source
      domain, so that information generated by the user of an XMPP system will
      be translated by a gateway within the trust domain of that XMPP system,
      and information generated by the user of a SIP system will be translated
      by a gateway within the trust domain of that SIP system.  However,
      nothing in this document ought to be taken as recommending against
      protocol translation at the destination domain.</t>

      <t>An architectural diagram for a possible gateway deployment is shown
      below, where the entities have the following significance and the "#"
      character is used to show the boundary of a trust domain:</t>

      <t>
        <list style='symbols'>
          <t>romeo@example.net -- a SIP user.</t>
          <t>example.net -- a SIP server with an associated gateway ("S2X GW")
          to XMPP.</t>

          <t>juliet@example.com -- an XMPP user.</t>
          <t>example.com -- an XMPP server with an associated gateway ("X2S
          GW") to SIP.</t>

        </list>
      </t>
      <figure anchor='figure-1' title='Possible Gateway Deployment Architecture'>
        <artwork><![CDATA[
   #########################################################
   #                                                       #
   #                 +-----+                               #
   #                 | S2X |                               #
   #   +-------------+ GW  |<...........>+-------------+   #
   #   | SIP Server  +-----+             | XMPP Server |   #
   #   | example.net |             +-----+ example.com |   #
   #   +-------------+<***********>| X2S +-------------+   #
   #         *                     | GW  |  :              #
   #         *                     +-----+  :              #
   #         *                              :              #
   #    romeo@example.net             juliet@example.com   #
   #                                                       #
   #########################################################

         Legend:
           XMPP = ... or :
            SIP = *
        ]]></artwork>
      </figure>
      <t>Note that bidirectional communication between the SIP server and the
      XMPP server can be established over either SIP or XMPP.  If the
      XMPP user initiates the interaction, then the XMPP server would invoke
      its XMPP-to-SIP gateway; thus, the communication would occur over SIP.
      If the SIP user initiates the interaction, then the SIP server would
      invoke its SIP-to-XMPP gateway; thus, the communication would occur
      over XMPP.</t>

    </section>

    <section title="Interdomain Federation" anchor="fed">
      <t>The architectural assumptions underlying this document imply that
      communication between a SIP system and an XMPP system will take place
      using interdomain federation: the SIP server invokes its associated
      SIP-to-XMPP gateway, which communicates with the XMPP server using
      native XMPP server-to-server methods; similarly, the XMPP server invokes
      its associated XMPP-to-SIP gateway, which communicates with the SIP
      server using native SIP server-to-server methods.</t>

      <t>When an XMPP server receives an XMPP stanza whose 'to' address
      specifies or includes a domain other than the domain of the XMPP server,
      it needs to determine whether the destination domain communicates via
      XMPP or SIP.  To do so, it performs one or more DNS SRV lookups <xref
      target="RFC2782"/> for "_xmpp-server" records as specified in <xref
      target="RFC6120"/>.  If the response returns a hostname, the XMPP server
      can attempt XMPP communication.  If not, it can determine the
      appropriate location for SIP communication at the target domain using
      the procedures specified in <xref target='RFC3263'/>.</t>

      <t>Similarly, when a SIP server receives a SIP message whose Request-URI
      or To header specifies or includes a domain other than the domain of the
      SIP server, it needs to determine whether the destination domain
      communicates via SIP or XMPP.  To do so, it uses the procedures
      specified in <xref target='RFC3263'/>.   If that response returns a
      hostname, the SIP server can attempt SIP communication.  If not, it
      can perform one or more DNS SRV lookups <xref target="RFC2782"/> for
      "_xmpp-server" records as specified in <xref target="RFC6120"/>.</t>

      <t>In both cases, the server in question might have previously
      determined that the foreign domain communicates via SIP or XMPP, in
      which case it would not need to perform the relevant DNS lookups.  The
      caching of such information is a matter of implementation and local
      service policy and is therefore out of scope for this document.</t>
      
      <t>Existing SIP and XMPP server implementations do not typically include
      the ability to communicate using the other technology (XMPP for SIP
      implementations, SIP for XMPP implementations).  One common
      architectural pattern is to associate a gateway with the core server
      implementation (e.g., in XMPP such a gateway might be called a
      "connection manager").  How exactly such a gateway interacts with the
      core server to complete tasks such as address lookups and communication
      with systems that use the other technology is a matter of implementation
      (e.g., the gateway might be an add-on module that is trusted by the core
      server to act as a fallback delivery mechanism if the remote domain does
      not support the server's native communication technology).</t>

      <t>Because <xref target='RFC6120'/> specifies a binding of XMPP to TCP,
      a gateway from SIP to XMPP will need to support TCP as the underlying
      transport protocol.  By contrast, as specified in <xref
      target='RFC3261'/>, either TCP or UDP can be used as the underlying
      transport for SIP messages, and a given SIP deployment might support
      only UDP; therefore, a gateway from XMPP to SIP might need to
      communicate with a SIP server using either TCP or UDP.</t>

    </section>

    <section title="Address Mapping" anchor="addr">
      <section title="Overview" anchor="addr-over">
        <t>The basic SIP address format is a 'sip' or 'sips' URI as specified
        in <xref target='RFC3261'/>.  When a SIP entity supports extensions
        for instant messaging it might be identified by an 'im' URI as
        specified in the Common Profile for Instant Messaging <xref
        target="RFC3860"/> (see <xref target="RFC3428"/>), and when a SIP
        entity supports extensions for presence it might be identified by a
        'pres' URI as specified in the Common Profile for Presence <xref
        target="RFC3859"/> (see <xref target="RFC3856"/>).  SIP entities
        typically also support the 'tel' URI scheme <xref target='RFC3966'/>
        and might support other URI schemes as well.</t>

        <t>The XMPP address format is specified in <xref target="RFC6122"/>
        (although note that XMPP URIs <xref target='RFC5122'/> are not used
        natively on the XMPP network); in addition, <xref target="RFC6121"/>
        encourages instant messaging and presence applications of XMPP to also
        support 'im' and 'pres' URIs as specified in <xref target="RFC3860"/>
        and <xref target="RFC3859"/>, respectively, although such support might
        simply involve leaving resolution of such addresses up to an XMPP
        server.</t>

        <t>In this document we primarily describe mappings for addresses of
        the form &lt;user@domain&gt;; however, we also provide guidelines for
        mapping the addresses of specific user agent instances, which take the
        form of Globally Routable User Agent URIs (GRUUs) in SIP and
        "resourceparts" in XMPP.  Mapping of protocol-specific identifiers
        (such as telephone numbers) is out of scope for this specification.
        In addition, we have ruled the mapping of domain names as out of scope
        for now, since that is a matter for the Domain Name System;
        specifically, the issue for interworking between SIP and XMPP relates
        to the translation of fully internationalized domain names (IDNs) into
        non-internationalized domain names (IDNs are not allowed in the SIP
        address format but are allowed in the XMPP address via
        Internationalized Domain Names in Applications; see <xref
        target="RFC6122"/> and <xref target='XMPP-ADDRESS-FORMAT'/>).
        Therefore, in the following sections we focus primarily on the local
        part of an address (these are called variously "usernames", "instant
        inboxes", "presentities", and "localparts" in the protocols at issue),
        secondarily on the instance-specific part of an address, and not at
        all on the domain-name part of an address.</t>

        <t>The 'sip'/'sips', 'im'/'pres', and XMPP address schemes allow
        different sets of characters (although all three allow alphanumeric
        characters and disallow both spaces and control characters).  In
        some cases, characters allowed in one scheme are disallowed in
        others; these characters need to be mapped appropriately in order to
        ensure interworking across systems.</t>

      </section>
      <section title="Local Part Mapping" anchor="addr-localpart">
        <t>The local part of a 'sip'/'sips' URI inherits from the "userinfo"
        rule in <xref target="RFC3986"/> with several changes; here we discuss
        the SIP "user" rule only (using ABNF as defined in
        <xref target="RFC5234"/>):</t>

        <figure>
          <artwork><![CDATA[
   user             =  1*( unreserved / escaped / user-unreserved )
   user-unreserved  =  "&" / "=" / "+" / "$" / "," / ";" / "?" / "/"
   unreserved       =  alphanum / mark
   mark             =  "-" / "_" / "." / "!" / "~" / "*" / "'"
                       / "(" / ")"
          ]]></artwork>
        </figure>
        <t>Here we make the simplifying assumption that the local part of an
        <vspace/>'im'/'pres' URI inherits from the "dot-atom-text" rule
        in <xref target="RFC5322"/> rather than the more complicated
        "local-part" rule:</t>

        <figure>
          <artwork><![CDATA[
   dot-atom-text =  1*atext *("." 1*atext)
   atext         =  ALPHA / DIGIT /    ; Any character except 
                    "!" / "#" / "$" /  ; controls, SP, and 
                    "%" / "&" / "'" /  ; specials.  Used for 
                    "*" / "+" / "-" /  ; atoms.
                    "/" / "=" / "?" /
                    "^" / "_" / "`" / 
                    "{" / "|" / "}" /
                    "~"
          ]]></artwork>
        </figure>
        <t>The local part of an XMPP address allows any ASCII character except
        space, controls, and the " &amp; ' / : &lt; &gt; @ characters.</t>

        <t>To summarize the foregoing information, the following table lists
        the allowed and disallowed characters in the local part of identifiers
        for each protocol (aside from the alphanumeric, space, and control
        characters), in order by hexadecimal character number (where each "A"
        row shows the allowed characters and each "D" row shows the disallowed
        characters).</t>

        <figure>
          <artwork><![CDATA[
              +---+----------------------------------+
              | SIP/SIPS CHARACTERS                  |
              +---+----------------------------------+
              | A | !  $ &'()*+,-./ ; = ?     _    ~ |
              | D |  "# %          : < > @[\]^ `{|}  |
              +---+----------------------------------+
              | IM/PRES CHARACTERS                   |
              +---+----------------------------------+
              | A | ! #$%&'  *+ - /   = ?    ^_`{|}~ |
              | D |  "     ()  , . :;< > @[\]        |
              +---+----------------------------------+
              | XMPP CHARACTERS                      |
              +---+----------------------------------+
              | A | ! #$%  ()*+,-.  ; = ? [\]^_`{|}~ |
              | D |  "   &'       /: < > @           |
              +---+----------------------------------+

             Table 1: Allowed and Disallowed Characters
          ]]></artwork>

        </figure>
        <t>When transforming the local part of an address from one address
        format to another, an application SHOULD proceed as follows:</t>

        <t>
          <list style='numbers'>
            <t>Unescape any escaped characters in the source address (e.g.,
            from SIP to XMPP unescape "%23" to "#" per <xref
            target='RFC3986'/>, and from XMPP to SIP unescape "\27" to "'" per
            <xref target='XEP-0106'/>).</t>

            <t>Leave unmodified any characters that are allowed in the
            destination scheme.</t>

            <t>Escape any characters that are allowed in the source scheme but
            reserved in the destination scheme, as escaping is defined for the
            destination scheme.  In particular:

              <list style='symbols'>
                <t>Where the destination scheme is a URI (i.e., an 'im',
                'pres', 'sip', or 'sips' URI), each reserved character MUST be
                percent-encoded to "%hexhex" as specified in Section 2.5 of
                <xref target='RFC3986'/> (e.g., when transforming from XMPP to
                SIP, encode "#" as "%23").</t>

                <t>Where the destination scheme is a native XMPP address, each
                reserved character MUST be encoded to "\hexhex" as specified
                in <xref target='XEP-0106'/> (e.g., when transforming from SIP
                to XMPP, encode "'" as "\27").</t>

              </list>
            </t>
          </list>
        </t>
      </section>
      <section title="Instance-Specific Mapping" anchor="addr-instance">
        <t>The meaning of a resourcepart in XMPP (i.e., the portion of a
        Jabber ID (JID) after the slash character, such as "foo" in
        "user@example.com/foo") matches that of a Globally Routable User Agent
        URI (GRUU) in SIP <xref target='RFC5627'/>.  In both cases, these
        constructs identify a particular device associated with the bare JID
        ("localpart@domainpart") of an XMPP entity or with the Address of
        Record (AOR) of a SIP entity. Therefore, it is reasonable to map the
        value of a "gr" URI parameter to an XMPP resourcepart and
        vice versa.</t>

        <t>The mapping described here does not apply to temporary GRUUs -- only
        to GRUUs associated with an Address of Record.</t>

        <t>The "gr" URI parameter in SIP can contain only characters from the
        ASCII range (although characters outside the ASCII range can be
        percent-encoded in accordance with <xref target='RFC3986'/>), whereas
        an XMPP resourcepart can contain nearly any Unicode character <xref
        target='UNICODE'/>.  Therefore, Unicode characters outside the ASCII
        range need to be mapped to characters in the ASCII range, as described
        below.</t>

      </section>
      <section title="SIP to XMPP" anchor="addr-sip">
        <t>The following is a high-level algorithm for mapping a 'sip', 'sips',
        'im', or 'pres' URI to an XMPP address:</t>

        <t>
          <list style='numbers'>
            <t>Remove URI scheme.</t>
            <t>Split at the first '@' character into local part and hostname
            (mapping the latter is out of scope).</t>

            <t>Translate any percent-encoded strings ("%hexhex") to
            percent-decoded octets.</t>

            <t>Treat result as a UTF-8 string.</t>
            <t>Translate "&amp;" to "\26", "'" to "\27", and "/" to "\2f",
            respectively in order to properly handle the characters disallowed
            in XMPP addresses but allowed in 'sip'/'sips' URIs and 'im'/'pres'
            URIs as shown in Table 1 above (this is consistent
            with <xref target="XEP-0106"/>).</t>

            <t>Apply Nodeprep profile of stringprep <xref target="RFC3454"/>
            or its replacement (see <xref target="RFC6122"/> and <xref
            target='XMPP-ADDRESS-FORMAT'/>) for canonicalization
            (OPTIONAL).</t>

            <t>Recombine local part with mapped hostname to form a bare JID
            ("localpart@domainpart").</t>

            <t>If the (SIP) address contained a "gr" URI parameter, append a
            slash character "/" and the "gr" value to the bare JID to form a
            full JID ("localpart@domainpart/resourcepart").</t>

          </list>
        </t>
        <t>Several examples follow, illustrating steps 3, 5, and 8 described
        above.</t>

        <figure>
          <artwork><![CDATA[
   +----------------------------+--------------------------+
   | SIP URI                    |  XMPP Address            |
   +----------------------------+--------------------------+
   | sip:f%C3%BC@sip.example    |  f&#xFC;@sip.example     |
   +----------------------------+--------------------------+
   | sip:o'malley@sip.example   |  o\27malley@sip.example  |
   +----------------------------+--------------------------+
   | sip:foo@sip.example;gr=bar |  foo@sip.example/bar     |
   +----------------------------+--------------------------+
          ]]></artwork>
        </figure>
        <t>In the first example, the string "%C3%BC" is a percent-encoded
        representation of the UTF-8-encoded Unicode character LATIN SMALL
        LETTER U WITH DIAERESIS (U+00FC), whereas the string "&amp;#xFC;" is
        the same character shown for documentation purposes using the XML
        Notation defined in <xref target='RFC3987'/> (in XMPP, it would be sent
        directly as a UTF-8-encoded Unicode character and not percent-encoded
        as in a SIP URI to comply with the URI syntax defined in <xref
        target='RFC3986'/>).</t>

      </section>
      <section title="XMPP to SIP" anchor="addr-xmpp">
        <t>The following is a high-level algorithm for mapping an XMPP address
        to a 'sip', 'sips', 'im', or 'pres' URI:</t>

        <t>
          <list style='numbers'>
            <t>Split XMPP address into localpart (mapping described in
            remaining steps), domainpart (hostname; mapping is out of scope),
            and resourcepart (specifier for particular device or connection,
            for which an OPTIONAL mapping is described below).</t>

            <t>Apply Nodeprep profile of stringprep <xref target="RFC3454"/>
            or its replacement (see <xref target="RFC6122"/> and <xref
            target='XMPP-ADDRESS-FORMAT'/>) for canonicalization of the XMPP
            localpart (OPTIONAL).</t>

            <t>Translate "\26" to "&amp;", "\27" to "'", and "\2f" to "/",
            respectively (this is consistent with <xref
            target="XEP-0106"/>).</t>

            <t>Determine if the foreign domain supports 'im' and 'pres' URIs
            (discovered via <xref target="RFC2782"/> lookup as specified in
            <xref target="RFC6121"/>), else assume that the foreign domain
            supports 'sip'/'sips' URIs.</t>

            <t>If converting into 'im' or 'pres' URI, for each byte, if the
            byte is in the set (),.;[\] or is a UTF-8 character outside the
            ASCII range, then percent-encode that byte to "%hexhex" format.  If
            converting into 'sip' or 'sips' URI, for each byte, if the byte is
            in the set #%[\]^`{|} or is a UTF-8 character outside the ASCII
            range, then percent-encode that byte to "%hexhex" format.</t>

            <t>Combine resulting local part with mapped hostname to form
            local@domain address.</t>

            <t>Prepend with the string 'im:' (for XMPP &lt;message/&gt;
            stanzas) or 'pres:' (for XMPP &lt;presence/&gt; stanzas) if foreign
            domain supports these, else prepend with the string 'sip:' or
            'sips:' according to local service policy.</t>

            <t>If the XMPP address included a resourcepart and the destination
            URI scheme is 'sip' or 'sips', optionally append the slash
            character '/' and then append the resourcepart (making sure to
            percent-encode any UTF-8 characters outside the ASCII range) as
            the "gr" URI parameter.</t>

          </list>
        </t>
        <t>Several examples follow, illustrating steps 3, 5, and 8 described
        above.</t>

        <figure>
          <artwork><![CDATA[
   +---------------------------+---------------------------------+
   | XMPP Address              |  SIP URI                        |
   +---------------------------+---------------------------------+
   | m\26m@xmpp.example        |  sip:m&m@xmpp.example           |
   | tsch&#xFC;ss@xmpp.example |  sip:tsch%C3%BCss@xmpp.example  |
   | baz@xmpp.example/qux      |  sip:baz@xmpp.example;gr=qux    |
   +---------------------------+---------------------------------+
          ]]></artwork>
        </figure>
        <t>As above, in the first example the string "&amp;#xFC;" is the
        Unicode character LATIN SMALL LETTER U WITH DIAERESIS (U+00FC) shown
        for documentation purposes using the XML Notation defined in <xref
        target='RFC3987'/> (in XMPP, it would be sent directly as a
        UTF-8-encoded Unicode character and not percent-encoded, whereas the
        string "%C3%BC" is a percent-encoded representation of the same
        character.</t>

      </section>
    </section>

    <section title='Error Mapping' anchor="errors">

      <t>Various differences between XMPP error conditions and SIP response
      codes make it hard to provide a comprehensive and consistent mapping
      between the protocols:</t>

      <t>
        <list style='symbols'>
          <t>Whereas the set of XMPP error conditions is fixed in the core
          XMPP specification (and supplemented where needed by
          application-specific extensions), the set of SIP response codes is
          more open to change, as evidenced by the IANA registry of SIP
          response codes.</t>

          <t>XMPP has defined fewer error conditions related to stanza
          handling (22 are defined in <xref target='RFC6120'/>) than SIP has
          defined response codes related to message handling (at the date of
          this writing, 71 SIP response codes are registered with IANA as
          defined in <xref target='RFC3261'/> and numerous SIP
          extensions).</t>

          <t>In many cases, the SIP response codes are more specific than the
          XMPP error conditions (e.g., from an XMPP perspective the SIP
          codes "413 Request Entity Too Large" and "414 Request-URI Too
          Long" are simply two different types of response to the same bad
          request, and the SIP codes "415 Unsupported Media Type" and
          "416 Unsupported URI Scheme" are two different responses to a
          request that is not acceptable).</t>

          <t>SIP differentiates between responses about a particular endpoint
          or resource (the 4xx series) and responses about a user, i.e., all
          of a user's endpoints or resources (the 6xx series).  There is no
          such distinction in XMPP, since the same error condition can be
          returned in relation to the "bare JID" (localpart@domainpart) of a
          user or the "full JID" (localpart@domainpart/resourcepart) of a
          particular endpoint or resource, depending on the 'to' address of
          the original request.</t>

        </list>
      </t>
      <t>As a result of these and other factors, the mapping of error
      conditions and response codes is more of an art than a science.  This
      document provides suggested mappings, but implementations are free to
      deviate from these mappings if needed.  Also, because no XMPP error
      conditions are equivalent to the provisional (1xx) and successful (2xx)
      response codes in SIP, this document suggests mappings only for the SIP
      redirection (3xx), request failure (4xx), server failure (5xx), and
      global failure (6xx) response code families.</t>

      <t>Supplementary information about SIP response codes can be expressed
      in the "Reason-Phrase" in the Status-Line header, and detailed
      information about XMPP error conditions can be expressed in the <vspace/>
      &lt;text/&gt; child of the &lt;error/&gt; element.  Although the
      semantics of these constructs are specified in a slightly different way,
      it is reasonable for a gateway to map these constructs to each other if
      they are found in a SIP response or XMPP error stanza.</t>


      <section title="XMPP to SIP" anchor="errors-xmpp">
        <t>The mapping of specific XMPP error conditions to SIP response codes
        SHOULD be as described in the following table.</t>

        <figure>
          <artwork><![CDATA[
      +------------------------------+---------------------+
      |  XMPP Error Condition        |  SIP Response Code  |
      +------------------------------+---------------------+
      |  <bad-request/>              | 400                 |
      +------------------------------+---------------------+
      |  <conflict/>                 | 400                 |
      +------------------------------+---------------------+
      |  <feature-not-implemented/>  | 405 or 501 (1)      |
      +------------------------------+---------------------+
      |  <forbidden/>                | 403 or 603 (2)      |
      +------------------------------+---------------------+
      |  <gone/>                     | 301 or 410 (3)      |
      +------------------------------+---------------------+
      |  <internal-server-error/>    | 500                 |
      +------------------------------+---------------------+
      |  <item-not-found/>           | 404 or 604 (2)      |
      +------------------------------+---------------------+
      |  <jid-malformed/>            | 400                 |
      +------------------------------+---------------------+
      |  <not-acceptable/>           | 406 or 606 (2)      |
      +------------------------------+---------------------+
      |  <not-allowed/>              | 403                 |
      +------------------------------+---------------------+
      |  <not-authorized/>           | 401                 |
      +------------------------------+---------------------+
      |  <policy-violation/>         | 403                 |
      +------------------------------+---------------------+
      |  <recipient-unavailable/>    | 480 or 600 (2)      |
      +------------------------------+---------------------+
      |  <redirect/>                 | 302                 |
      +------------------------------+---------------------+
      |  <registration-required/>    | 407                 |
      +------------------------------+---------------------+
      |  <remote-server-not-found/>  | 404 or 408 (4)      |
      +------------------------------+---------------------+
      |  <remote-server-timeout/>    | 408                 |
      +------------------------------+---------------------+
      |  <resource-constraint/>      | 500                 |
      +------------------------------+---------------------+
      |  <service-unavailable/>      | see note (5) below  |
      +------------------------------+---------------------+
      |  <subscription-required/>    | 400                 |
      +------------------------------+---------------------+
      |  <undefined-condition/>      | 400                 |
      +------------------------------+---------------------+
      |  <unexpected-request/>       | 491 or 400          |
      +------------------------------+---------------------+

  Table 2: Mapping of XMPP Error Conditions to SIP Response Codes
          ]]></artwork>
        </figure>
        <t>
          <list style='format (%d)'>
            <t>If the error relates to a "full JID"
            (localpart@domainpart/resourcepart), the SIP 405 response code is
            RECOMMENDED.  If the error relates to a "bare JID"
            (localpart@domainpart), the SIP 501 response code is
            RECOMMENDED.</t>

            <t>If the error relates to a "full JID"
            (localpart@domainpart/resourcepart), the SIP response code from
            the 4xx series is RECOMMENDED.  If the error relates to a "bare
            JID" (localpart@domainpart), the SIP response code from the 6xx
            series is RECOMMENDED.</t>

            <t>If the &lt;gone/&gt; element includes XML character data
            specifying the new address, the error MUST be mapped to SIP 301;
            if not, it MUST be mapped to SIP 410.</t>

            <t>The XMPP &lt;remote-server-not-found/&gt; error can mean that
            the remote server either (a) does not exist or (b) cannot be
            resolved.  SIP has two different response codes here: 404 to cover
            (a) and 408 to cover (b).</t>

            <t>The XMPP &lt;service-unavailable/&gt; error condition is widely
            used to inform the requesting entity that the intended recipient
            does not support the relevant feature, to signal that a server
            cannot perform the requested service either generally or in
            relation to a particular user, and to avoid disclosing whether a
            given account exists at all.  This is quite different from the
            semantics of the SIP 503 Service Unavailable response code, which
            is used to signal that communication with a server is impossible
            (e.g., even if the XMPP &lt;service-unavailable/&gt; error
            condition is returned in relation to a specific user, the SIP 503
            response code will be interpreted as applying to all future
            requests to this server, not just requests for the specific user).
            Therefore, mapping the XMPP &lt;service-unavailable/&gt; error
            condition to the SIP 503 Service Unavailable response code is NOT
            RECOMMENDED.  Although no precise mapping is available, the SIP
            403 Forbidden and 405 Method Not Allowed response codes are
            closest in meaning to the XMPP &lt;service-unavailable/&gt; error
            condition.</t>

          </list>
        </t>
      </section>
      <section title="SIP to XMPP" anchor="errors-sip">
        <t>The mapping of SIP response codes to XMPP error conditions SHOULD
        be as described in the following table.  If a gateway encounters a SIP
        response code that is not listed below, it SHOULD map a 3xx-series
        code to &lt;redirect/&gt;, a 4xx-series code to &lt;bad-request/&gt;,
        a 5xx-series code to &lt;internal-server-error&gt;, and a 6xx-series
        code to &lt;recipient-unavailable/&gt;.</t>

        <figure>
          <artwork><![CDATA[
     +---------------------+---------------------------------+
     |  SIP Response Code  |  XMPP Error Condition           |
     +---------------------+---------------------------------+
     |  3xx                |  <redirect/>                    |
     +---------------------+---------------------------------+
     |  300                |  <redirect/>                    |
     +---------------------+---------------------------------+
     |  301                |  <gone/> (1)                    |
     +---------------------+---------------------------------+
     |  302                |  <redirect/>                    |
     +---------------------+---------------------------------+
     |  305                |  <redirect/>                    |
     +---------------------+---------------------------------+
     |  380                |  <not-acceptable/>              |
     +---------------------+---------------------------------+
     |  4xx                |  <bad-request/>                 |
     +---------------------+---------------------------------+
     |  400                |  <bad-request/>                 |
     +---------------------+---------------------------------+
     |  401                |  <not-authorized/>              |
     +---------------------+---------------------------------+
     |  402                |  <bad-request/> (2)             |
     +---------------------+---------------------------------+
     |  403                |  <forbidden/> (3)               |
     +---------------------+---------------------------------+
     |  404                |  <item-not-found/> (4)          |
     +---------------------+---------------------------------+
     |  405                |  <feature-not-implemented/>     |
     +---------------------+---------------------------------+
     |  406                |  <not-acceptable/>              |
     +---------------------+---------------------------------+
     |  407                |  <registration-required/>       |
     +---------------------+---------------------------------+
     |  408                |  <remote-server-timeout/> (5)   |
     +---------------------+---------------------------------+
     |  410                |  <gone/> (1)                    |
     +---------------------+---------------------------------+
     |  413                |  <policy-violation/>            |
     +---------------------+---------------------------------+
     |  414                |  <policy-violation/>            |
     +---------------------+---------------------------------+
     |  415                |  <not-acceptable/>              |
     +---------------------+---------------------------------+
     |  416                |  <not-acceptable/>              |
     +---------------------+---------------------------------+
     |  420                |  <feature-not-implemented/>     |
     +---------------------+---------------------------------+
     |  421                |  <not-acceptable/>              |
     +---------------------+---------------------------------+
     |  423                |  <resource-constraint/>         |
     +---------------------+---------------------------------+
     |  430                |  <recipient-unavailable/> (6)   |
     +---------------------+---------------------------------+
     |  439                |  <feature-not-implemented/> (6) |
     +---------------------+---------------------------------+
     |  440                |  <policy-violation/> (7)        |
     +---------------------+---------------------------------+
     |  480                |  <recipient-unavailable/>       |
     +---------------------+---------------------------------+
     |  481                |  <item-not-found/>              |
     +---------------------+---------------------------------+
     |  482                |  <not-acceptable/>              |
     +---------------------+---------------------------------+
     |  483                |  <not-acceptable/>              |
     +---------------------+---------------------------------+
     |  484                |  <item-not-found/>              |
     +---------------------+---------------------------------+
     |  485                |  <item-not-found/>              |
     +---------------------+---------------------------------+
     |  486                |  <recipient-unavailable/>       |
     +---------------------+---------------------------------+
     |  487                |  <recipient-unavailable/>       |
     +---------------------+---------------------------------+
     |  488                |  <not-acceptable/>              |
     +---------------------+---------------------------------+
     |  489                |  <policy-violation/> (8)        |
     +---------------------+---------------------------------+
     |  491                |  <unexpected-request/>          |
     +---------------------+---------------------------------+
     |  493                |  <bad-request/>                 |
     +---------------------+---------------------------------+
     |  5xx                |  <internal-server-error/>       |
     +---------------------+---------------------------------+
     |  500                |  <internal-server-error/>       |
     +---------------------+---------------------------------+
     |  501                |  <feature-not-implemented/>     |
     +---------------------+---------------------------------+
     |  502                |  <remote-server-not-found/>     |
     +---------------------+---------------------------------+
     |  503                |  <internal-server-error/> (9)   |
     +---------------------+---------------------------------+
     |  504                |  <remote-server-timeout/>       |
     +---------------------+---------------------------------+
     |  505                |  <not-acceptable/>              |
     +---------------------+---------------------------------+
     |  513                |  <policy-violation/>            |
     +---------------------+---------------------------------+
     |  6xx                |  <recipient-unavailable/>       |
     +---------------------+---------------------------------+
     |  600                |  <recipient-unavailable/>       |
     +---------------------+---------------------------------+
     |  603                |  <recipient-unavailable/>       |
     +---------------------+---------------------------------+
     |  604                |  <item-not-found/>              |
     +---------------------+---------------------------------+
     |  606                |  <not-acceptable/>              |
     +---------------------+---------------------------------+

  Table 3: Mapping of SIP Response Codes to XMPP Error Conditions
          ]]></artwork>
        </figure>
        <t>
          <list style='format (%d)'>
            <t>When mapping SIP 301 to XMPP &lt;gone/&gt;, the &lt;gone/&gt;
            element MUST include XML character data specifying the new
            address.  When mapping SIP 410 to XMPP &lt;gone/&gt;, the
            &lt;gone/&gt; element MUST NOT include XML character data
            specifying a new address.</t>

            <t>The XMPP &lt;payment-required/&gt; error condition was removed
            in <xref target='RFC6120'/>.  Therefore, a mapping to XMPP
            &lt;bad-request/&gt; is suggested instead.</t>

            <t>Depending on the scenario, other possible translations for SIP
            403 are &lt;not-allowed/&gt; and &lt;policy-violation/&gt;.</t>

            <t>Depending on the scenario, another possible translation for SIP
            404 is &lt;remote-server-not-found/&gt;.</t>

            <t>Depending on the scenario, another possible translation for SIP
            408 is &lt;remote-server-not-found/&gt;.</t>

            <t>Codes 430 and 439 are defined in <xref target='RFC5626'/>.</t>
            <t>Code 440 is defined in <xref target='RFC5393'/>.</t>
            <t>Code 489 is defined in <xref target='RFC6665'/>.</t>
            <t>Regarding the semantic mismatch between XMPP <vspace/>
            &lt;service-unavailable/&gt; and SIP code 503, see note (5) in
            <xref target="errors-xmpp"/> of this document.</t>

          </list>
        </t>
      </section>
    </section>

    <section title='Security Considerations' anchor="sec">
      <t>Detailed security considerations for SIP and XMPP are given in <xref
      target="RFC3261"/> and <xref target="RFC6120"/>, respectively.</t>

      <t>To protect information sent between SIP and XMPP systems, deployed
      gateways SHOULD use Transport Layer Security (TLS) <xref
      target='RFC5246'/> when communicating over TCP and Datagram Transport
      Layer Security (DTLS) <xref target='RFC6347'/> when communicating over
      UDP.</t>

      <t>As specified in Section 26.4.4 of <xref target='RFC3261'/> and
      updated by <xref target='RFC5630'/>, a To header or a Request-URI
      containing a Session Initiation Protocol Secure (SIPS) URI
      is used to indicate that all hops in a communication path
      need to be protected using TLS.  Because XMPP lacks a
      way to signal that all hops need to be protected, if the To header or
      Request-URI of a SIP message is a SIPS URI then the SIP-to-XMPP gateway
      MUST NOT translate the SIP message into an XMPP stanza and MUST NOT
      route it to the destination XMPP server (there might be exceptions to
      such a policy, such as explicit agreement among two operators to enforce
      per-hop security, but currently they are quite rare).</t>

      <t>A gateway between SIP and XMPP (in either direction) effectively acts
      as a SIP back-to-back user agent ("B2BUA").  The amplification
      vulnerability described in <xref target='RFC5393'/> can manifest itself
      with B2BUAs (see also <xref target='B2BUA-LOOP-DETECT'/>), and a gateway
      SHOULD implement the loop-detection methods defined in that
      specification to help mitigate the possibility of amplification attacks.
      Note that although it would be possible to signal the Max-Forwards and
      Max-Breadth SIP headers over XMPP using the Stanza Headers and Internet
      Metadata (SHIM) extension <xref target='XEP-0131'/>, that extension is
      not widely implemented; therefore, defenses against excessive looping and
      amplification attacks when messages pass back and forth through SIP and
      XMPP networks are out of scope for this document.  However, it ought to
      be addressed in the future, and implementations are strongly encouraged
      to incorporate appropriate countermeasures wherever possible.</t>

      <t>The ability to use a wide range of Unicode characters <xref
      target='UNICODE'/> can lead to security issues, especially the
      possibility of user confusion over identifiers containing visually
      similar characters (also called "confusable characters" or
      "confusables").  The PRECIS framework specification <xref
      target='PRECIS'/> describes some of these security issues, and
      additional guidance can be found in <xref target='UTS39'/>.</t>

    </section>

  </middle>

  <back>

    <references title="Normative References">

<?rfc include="reference.RFC.2119"?>
<?rfc include="reference.RFC.3261"?>
<?rfc include="reference.RFC.3263"?>
<?rfc include="reference.RFC.3986"?>
<?rfc include="reference.RFC.3987"?>
<?rfc include="reference.RFC.5234"?>
<?rfc include="reference.RFC.5246"?>
<?rfc include="reference.RFC.5393"?>
<?rfc include="reference.RFC.5627"?>
<?rfc include="reference.RFC.5630"?>
<?rfc include="reference.RFC.6120"?>
<?rfc include="reference.RFC.6122"?>
<?rfc include="reference.RFC.6347"?>

<reference anchor="UNICODE" target="http://www.unicode.org/versions/Unicode6.3.0/">
  <front>
    <title>The Unicode Standard, Version 6.3</title>
    <author>
      <organization>The Unicode Consortium</organization>
    </author>
    <date year="2013" />
  </front>
</reference>

    </references>

    <references title="Informative References">

<!-- draft-ietf-precis-framework (App. Announcemt 2B sent) -->
<reference anchor='PRECIS'>
<front>
<title>PRECIS Framework: Preparation and Comparison of Internationalized Strings in Application Protocols</title>
<author initials='P' surname='Saint-Andre' fullname='Peter Saint-Andre'>
    <organization />
</author>
<author initials='M' surname='Blanchet' fullname='Marc Blanchet'>
    <organization />
</author>
<date month='April' year='2014' />
</front>
<seriesInfo name='Work in' value='Progress' />
</reference>

<!-- draft-ietf-straw-b2bua-loop-detection (App. Announcemt. 2B sent) -->
<reference anchor='B2BUA-LOOP-DETECT'>
<front>
<title>Loop Detection Mechanisms for Session Initiation Protocol (SIP) Back-to-Back User Agents (B2BUAs)</title>
<author initials='H' surname='Kaplan' fullname='Hadriel Kaplan'>
    <organization />
</author>
<author initials='V' surname='Pascual' fullname='Victor Pascual'>
    <organization />
</author>
<date month='February' year='2014' />
</front>
<seriesInfo name='Work in' value='Progress' />
</reference>

<!-- draft-ietf-xmpp-6122bis (I-D Exists) -->
<reference anchor='XMPP-ADDRESS-FORMAT'>
<front>
<title>Extensible Messaging and Presence Protocol (XMPP): Address Format</title>
<author initials='P' surname='Saint-Andre' fullname='Peter Saint-Andre'>
    <organization />
</author>
<date month='March' year='2014' />
</front>
<seriesInfo name='Work in' value='Progress' />
</reference>

<?rfc include="reference.RFC.2782"?>
<?rfc include="reference.RFC.3428"?>
<?rfc include="reference.RFC.3454"?>
<?rfc include="reference.RFC.3856"?>
<?rfc include="reference.RFC.3859"?>
<?rfc include="reference.RFC.3860"?>
<?rfc include="reference.RFC.3966"?>
<?rfc include="reference.RFC.5122"?>
<?rfc include="reference.RFC.5322"?>
<?rfc include="reference.RFC.5626"?>
<?rfc include="reference.RFC.6121"?>
<?rfc include="reference.RFC.6665"?>

<reference anchor="UTS39" target='http://unicode.org/reports/tr39/'>
  <front>
    <title>Unicode Technical Standard #39: Unicode Security Mechanisms</title>
    <author>
      <organization>The Unicode Consortium</organization>
    </author>
    <date month="November" year="2013" />
  </front>
</reference>

<reference anchor="XEP-0106" target="http://www.xmpp.org/extensions/xep-0106.html">
  <front>
    <title>JID Escaping</title>
    <author initials="J." surname="Hildebrand" fullname="Joe Hildebrand">
      <organization/>
      <address>
        <email>jhildebrand@jabber.com</email>
      </address>
    </author>
    <author initials="P." surname="Saint-Andre" fullname="Peter Saint-Andre">
      <organization/>
      <address>
        <email>stpeter@jabber.org</email>
      </address>
    </author>
    <date day="18" month="June" year="2007"/>
  </front>
  <seriesInfo name="XSF XEP" value="0106"/>
</reference>

<reference anchor="XEP-0131" target="http://xmpp.org/extensions/xep-0131.html">
  <front>
    <title>Stanza Headers and Internet Metadata</title>
    <author initials="P." surname="Saint-Andre" fullname="Peter Saint-Andre">
      <organization/>
      <address>
        <email>stpeter@jabber.org</email>
      </address>
    </author>
    <author initials="J." surname="Hildebrand" fullname="Joe Hildebrand">
      <organization/>
      <address>
        <email>jhildebr@cisco.com</email>
      </address>
    </author>
    <date day="12" month="July" year="2006"/>
  </front>
  <seriesInfo name="XSF XEP" value="0131"/>
</reference>

    </references>

    <section title="Acknowledgements" anchor="ack">
      <t>The authors wish to thank the following individuals for their
      feedback: Mary Barnes, Dave Cridland, Dave Crocker, Mike De Vries, Fabio
      Forno, Adrian Georgescu, Philipp Hancke, Saul Ibarra Corretge, Markus
      Isomaki, Olle Johansson, Paul Kyzivat, Salvatore Loreto,
      Daniel-Constantin Mierla, Tory Patnoe, and Robert Sparks.</t>

      <t>Dan Romascanu reviewed the document on behalf of the General Area
      Review Team.</t>

      <t>During IESG review, Stephen Farrell, Ted Lemon, Pete Resnick, and
      Sean Turner caught several issues that needed to be addressed.</t>

      <t>The authors gratefully acknowledge the assistance of Markus Isomaki
      and Yana Stamcheva as the working group chairs and Gonzalo Camarillo as
      the sponsoring Area Director.</t>

      <t>Peter Saint-Andre wishes to acknowledge Cisco Systems, Inc., for
      employing him during his work on earlier versions of this document.</t>

    </section>

  </back>

</rfc>
