<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">
<?rfc toc="yes" ?>
<?rfc symrefs="yes" ?>
<?rfc sortrefs="yes"?>
<?rfc iprnotified="no" ?>
<?rfc strict="yes" ?>
<?rfc comments="yes" ?>
<?rfc inline="yes" ?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>

<rfc ipr="trust200902" category="std" docName='draft-melnikov-imap-sasl2-profile-00'>
  <front>
    <title abbrev="IMAP SASL2 Profile">
      IMAP SASL2 Profile
    </title>
<!--
    <author initials="I." surname="Somebody" fullname="Someone Somebody">
      <organization></organization>
      <address>
        <postal>
          <street></street>
          <city></city>
          <region></region>
          <code></code>
          <country></country>
        </postal>
        <email></email>
      </address>
    </author>
-->
    <author initials="A." surname="Melnikov" fullname="Alexey Melnikov">
      <organization>Isode Ltd</organization>
      <address>
        <postal>
          <street>14 Castle Mews</street>
          <city>Hampton</city>
          <region>Middlesex</region>
          <code>TW12 2NP</code>
          <country>UK</country>
        </postal>
        <email>alexey.melnikov@isode.com</email>
      </address>
    </author>
    <date year="2026"/>
    
    <!--One or more extra keywords which don't appear in the title-->
    <keyword>IMAP</keyword>
    <keyword>SASL</keyword>
    <keyword>SASL2</keyword>

    <abstract>

    <t>
      This document specifies an IMAP extension for SASL2 authentication,
      which extends IMAP SASL (RFC 4422) Profile.
    </t>
	
    </abstract>
    
  </front>
  <middle>

    <section title="Introduction">

        <t>
        This document specifies an IMAP <xref target="RFC9051"/> extension
        for Extensible Simple Authentication and Security Layer <xref target="SASL2"/> (also known as SASL2).

        SASL2 itself is based on Simple Authentication and Security Layer <xref target="RFC4422"/>.
        This document specified SASL2 protocol profile, i.e. it specifies how different SASL2
        commands, responses and capabilities are expressed as an IMAP extension.
        </t>

        <t>
        The IMAP CAPABILITY name for this extension is "SASL2". The extension includes
        CBINDING command and response, TASK command, REMEMBERME command, TOKEN response code,
        CONTINUE response code.
        </t>

        <t>
        [[Do we need to enable SASL2 with "ENABLE SASL2", so that the server can return CONTINUE response code
        and know that the client can handle it correctly?]]
        </t>

      
    </section>
    
    <section title="Conventions Used in This Document">
      
      <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 BCP
      14 <xref target="RFC2119"/> <xref target="RFC8174"/>
      when, and only when, they appear in all capitals, as shown here.
      </t>

    </section>


    <section title="Extended SASL Profile Definition">

      <t>
      This provides pointers <!--and/or clarifications to the Overview--> in the order
      and manner defined in <xref target="RFC4422"/>, section 4.
      </t>

      <section title="Service Name">
      
        <t>
        The service name SHALL be "imap", as defined in <xref target="RFC9051"/>.
        </t>

      </section>

      <section title="Mechanism negotiation">

        <t>
        Servers list available mechanisms in the CAPABILITY response or response code.
        Each mechanism name is prefix with "AUTH=".
        See <xref target="RFC9051"/>.
        </t>

      </section>

      <section title="Message Definitions for authentication">

        <t>
        Clients initiate authentication by issuing the AUTHENTICATE command <xref target="RFC9051"/>.
        </t>

        <t>
        Server Challenges and Client Responses are sent as described in <xref target="RFC9051"/>.
        </t>

        <t>
        Authentication may complete in one of three ways. It may fail by server returning
        tagged NO or BAD response, in which case the client is not authenticated and
        the session state remain entirely unchanged.
        It may complete successfully by returning a tagged OK response that
        either doesn't include any response code or includes a response code different from
        the CONTINUE response code (see <xref target="continue"/>); in which case the client is authenticated.
        Finally, it may have completed successfully, but further interaction is required
        - for example, a password change or second-factor authentication. In the latter case
        the server returns tagged OK response with CONTINUE response code.
        (Note that the CONTINUE response code is a new feature in this document,
        but otherwise the behaviour of AUTHENTICATE command is unchanged from <xref target="RFC9051"/>).
        </t>

      </section>

<!--Doesn't apply to IMAP?
      <section title="Non-Empty Authorization Strings">

If a Client specifies an authorization string which is non-empty, the identifier is normalized by treating it as a JID, and performing normalization as described in RFC 7622.

      </section>
-->

      <section title="Aborting">

        <t>
        Clients MAY abort unilaterally at any time before the authentication completed by sending
        an a line containing a single * character (i.e. * CR LF).
        <!--In XMPP: <abort> element MAY contain a <text/> element containing a textual representation of the reason
        as well as any other element defined in some future protocol.-->
        </t>

        <t>
        Servers MAY abort uniliterally by sending tagged NO or BAD response to AUTHENTICATE command.
        </t>

      </section>

      <section title="Security Layer Effect">

        <t>
        Security Layers take effect after the SASL mechanism itself (ie, the first negotiation)
        has completed successfully, after the final octet of the server's tagged OK response
        (with or without the CONTINUE response code).
        </t>

      </section>

      <section title="Security Layer Order">

        <t>
        Option (a) is used - any SASL Security Layer is applied first to data being sent, and TLS applied last.
        </t>

      </section>

      <section title="Multiple Authentications">

        <t>
        Unless changed by another IMAP extension, IMAP profile of SASL2 doesn't allow multiple authentications
        on the same TCP connection. Once a client is successfully authenticated on a connection
        (by server returning tagged OK response to AUTHENTICATE with or without CONTINUE response code),
        all subsequent authentication attempts MUST fail.
        </t>

        <t>
        Although the CONTINUE concept does use tasks analogous to multiple SASL authentication sequences,
        only the first SASL mechanism used is considered an authentication, and only the first can negotiate
        a security layer.
        </t>

      </section>

      <section title="Advertising list of Channel Bindings" anchor="cbinding-cmd">

        <t>
        List of channel bindings supported by the server can be retrieved
        by issuing CBINDING command. Available channel bindings are returned
        in the CBINDING response.
        </t>

        <t>
        The CBINDING command is available in all states.
        </t>

    <figure>
      <artwork>
<![CDATA[
  S: * OK ACME IMAP Server v1.23 is ready
  C: 22 CAPABILITY
  S: * CAPABILITY IMAP4rev1 IMAP4rev2 STARTTLS AUTH=REMEMBERME
   AUTH=SCRAM-SHA-256 TOKEN=JWT
  S: 22 CAPABILITY completed
  C: 23 STARTTLS
  S: 23 OK Completed
  C: 24 CBINDING
  S: * CBINDING tls-exporter tls-server-end-point
  S: 24 OK Completed
]]>
</artwork>
</figure>

      </section>

      <section title="Generating reauthentication tokens">

        <t>
        The REMEMBERME command <xref target="IMAP-REMEMBERME"/> is used for generating/retrieving
        quick reauthentication tokens. List of available tokens in returned in the CAPABILITY
        response/response code, prefixed with "TOKEN=".
        </t>
      
      </section>

      <section title="Task negotiation facility">

        <t>
        Available Tasks are listed in CONTINUE response code (see <xref target="continue"/>) in an OK response
        of an AUTHENTICATE or TASK command.
        It is not currently possible to list all available tasks before starting authentication.
        [[Do we need a mechanism similar to CAPABILITY response to allow for this??]]
        </t>

      </section>

      <section title="Messages necessary for executing Tasks">

        <t>
        Clients initiate execution of a task by issuing the TASK command <xref target="task-cmd"/>.
        </t>

        <t>
        Task related data sent by clients and servers as described in <xref target="task-cmd"/>.
        </t>

        <t>
        Task may complete in one of three ways. It may fail by server returning
        tagged NO or BAD response, in which case the client is not authenticated and
        the session state remain entirely unchanged (i.e. in half-authenticated state).
        It may complete successfully by returning a tagged OK response that
        either doesn't include any response code or includes a response code different from
        the CONTINUE response code (see <xref target="continue"/>); in which case the client is authenticated.
        Finally, it may have completed successfully, but further interaction is required
        - for example, a password change or second-factor authentication. In the latter case
        the server returns tagged OK response with CONTINUE response code.
        </t>

	    </section>

	  </section>


    <section title="CONTINUE - task required to complete authentication" anchor="continue">

      <t>
      If the server returns tagged OK with CONTINUE response code, this means that
      the user is in half-authenticated IMAP state. In this state the only allowed commands
      are commands allowed in all IMAP states (see Section 6.1 of <xref target="RFC9051"/>,
      as well as CBINDING command <xref target="cbinding-cmd"/>),
      plus the TASK command <xref target="task-cmd"/>.
      </t>

      <t>
      The most recent CONTINUE response code value lists possible choices for available tasks
      to complete. Once a task is completed successfully, it might advertise further possible
      tasks in the subsequent CONTINUE response code.
      </t>

      <t>
      Once there are no more tasks to complete, the server returns tagged OK response without
      a CONTINUE response code. The server MAY include a CAPABILITY response code in the tagged
      OK response of a successful TASK command in order to send capabilities automatically.
      It is unnecessary for a client to send a separate CAPABILITY command if it recognizes
      these automatic capabilities. The server MAY advertise different capabilities after
      a successful TASK command.
      </t>

    <figure>
      <artwork>
<![CDATA[
  S: * OK ACME IMAP Server v1.23 is ready
  C: 22 CAPABILITY
  S: * CAPABILITY IMAP4rev1 IMAP4rev2 STARTTLS SASL2 AUTH=REMEMBERME
   AUTH=SCRAM-SHA-256 TOKEN=JWT
  S: 22 CAPABILITY completed
  C: 23 STARTTLS
  S: 23 OK Completed
  C: 24 AUTHENTICATE SCRAM-SHA-256
   <SCRAM-SHA-256 SASL exchange...>
  S: 24 OK [CONTINUE TOTP-EXAMPLE HOTP-EXAMPLE] Please complete
   an extra 2FA task
  C: 25 TASK TOTP-EXAMPLE SSd2ZSBydW4gb3V0IG9mIGlkZWFzIGhlcmUu
  S: + 94d27acffa2e99a42ba7786162a9e73e7ab17b9d
  C: OTRkMjdhY2ZmYTJlOTlhNDJiYTc3ODYxNjJhOWU3M2U3YWIxN2I5ZAo=
  S: SGFkIHlvdSBnb2luZywgdGhlcmUsIGRpZG4ndCBJPw==
  S: 25 OK [CAPABILITY IMAP4rev1 IMAP4rev2 CONDSTORE] Finally
   Authenticated
]]>
</artwork>
</figure>

    </section>

    <section title="TASK command" anchor="task-cmd">

   <t>
   <list style='hanging' hangIndent='12'>
   <t hangText='Arguments:'>Task mechanism name,
                            OPTIONAL initial response</t>

   <t hangText='Responses:'>continuation data can be requested</t>

   <t hangText='Result:'>OK - task completed, now in authenticated state<vspace/>
               NO - task failure: unsupported task mechanism, credentials rejected<vspace/>
               BAD - command unknown or arguments invalid,<vspace/>
                    invalid state, task exchange canceled</t>
   </list>
   </t>
            
      <t>
      This command is only valid in half-authenticated state.
      </t>

      <t>
      The TASK command indicates a task mechanism to the server. If the server supports
      the requested task mechanism, it performs a task protocol exchange to
      authenticate and identify the client. If the requested task mechanism is not supported,
      the server SHOULD reject the TASK command by sending a tagged NO response.
      </t>

      <t>
      The TASK command supports the optional "initial response" feature. The client MUST use it
      if the client sends data first for the specified task.
      </t>

      <t>
      The task protocol exchange consists of a series of task server challenges and task client responses
      that are specific to the task mechanism. A server challenge consists of a command continuation
      request response with the "+" token followed by a base64-encoded (see Section 4 of <xref target="RFC4648"/>")
      string. The client response consists of a single line consisting of a base64-encoded string.
      If the client wishes to cancel a task exchange, it issues a line consisting of a single "*".
      If the server receives such a response, or if it receives an invalid base64 string
      (e.g., characters outside the base64 alphabet or non-terminal "="), it MUST reject
      the TASK command by sending a tagged BAD response.
      </t>

      <t>
      As with any other client response, the initial response MUST be encoded as base64.
      It also MUST be transmitted outside of a quoted string or literal. To send a zero-length
      initial response, the client MUST send a single pad character ("=").
      This indicates that the response is present, but it is a zero-length string.
      </t>

      <t>
      When decoding the base64 data in the initial response, decoding errors MUST be treated
      as in any normal TASK client response, i.e., with a tagged BAD response.
      In particular, the server should check for any characters not explicitly allowed by
      the base64 alphabet, as well as any sequence of base64 characters that contains
      the pad character ('=') anywhere other than the end of the string (e.g., "=AAA"
      and "AAA=BBB" are not allowed).
      </t>

      <t>
      If the client uses an initial response with a task mechanism that does not support
      an initial response, the server MUST reject the command with a tagged BAD response.
      </t>

        <!--///Alexey:

        The following SASL2 requirement might need further elaboration:

          This message MUST allow for an optional field for carrying
          additional data with a successful outcome.  The specification MUST describe how
          messages with an empty additional data are distinguished from
          messages with no additional data.  This field MUST be capable
          of carrying arbitrary sequences of octets (including zero-
          length sequences and sequences containing zero-valued octets).
          -->


<!--
      <artwork name="" type="" align="left" alt="">
        <![CDATA[
  S: * OK ACME IMAP Server v1.23 is ready
  C: 22 CAPABILITY
  S: * CAPABILITY IMAP4rev1 IMAP4rev2 STARTTLS AUTH=PASSKEY AUTH=REMEMBERME
   AUTH=SCRAM-SHA-256 AUTH=REMEMBERME TOKEN=JWT TOKEN=RANDOM
  S: 22 CAPABILITY completed
  C: 23 STARTTLS
  S: 23 OK Completed
  C: 24 AUTHENTICATE ...
   <SASL exchange>
  S: 24 OK Completed
  C: 25 REMEMBERME JWT
  S: 26 OK [TOKEN <base64-encoded-token>] Completed
]]>

      </artwork>
-->

    </section>

    <section title="Formal Syntax">

      <t>The following syntax specification uses the Augmented Backus-Naur
      Form (ABNF) notation as specified in <xref target="ABNF"/>.
      ABNF productions not defined in this document are defined
      in IMAP4rev2 or <xref target="IMAP-REMEMBERME"/>.</t>

      <sourcecode type="abnf">
<![CDATA[
capability     =/ "SASL2"
                    ;; <capability> from [RFC9051]

resp-text-code =/ "CONTINUE" SP list-of-tasks

list-of-tasks  = task-name *(SP task-name)

task-name      = atom
                 ; Precise syntax specified in SASL2

c-binding-name = atom
]]>
      </sourcecode>



      <t>[[TBD: add ABNF for TASK and channel-binding advertisement]]</t>

    </section>
    
    
    <section title="IANA Considerations">

      <t>TBD. Register the new IMAP capability and new response codes.</t>

    </section>

    <section title="Security Considerations" anchor="seccons">

      <t>TBD.</t>

    </section>
    
  </middle>
  <back>
    <references title="Normative References">
      <?rfc include="reference.RFC.2119"?> <!-- Keywords, part 1 -->
      <?rfc include="reference.RFC.8174"?> <!-- Keywords, part 2 -->

      <reference anchor="ABNF">
        <front>
          <title>Augmented BNF for Syntax Specifications: ABNF</title>
          <author initials="D" surname="Crocker" fullname="Dave Crocker" role="editor">
            <organization />
          </author>
          <author initials="P" surname="Overell" fullname="Paul Overell" role="editor">
            <organization />
          </author>
          <date year="2008" month="January"/>
        </front>
        <seriesInfo name="RFC" value="5234" />
        <format type="TXT" target="https://www.rfc-editor.org/info/rfc5234" />
      </reference>

      <?rfc include="reference.RFC.3501"?> <!-- IMAP4rev1 -->
      <?rfc include="reference.RFC.9051"?> <!-- IMAP4rev2 -->
      <?rfc include="reference.RFC.4422"?> <!-- SASL -->

      <?rfc include="reference.RFC.4648"?> <!-- BASE64 -->

      <reference anchor="SASL2" target="https://www.ietf.org/archive/id/draft-melnikov-sasl2-03.txt">
      <front>
	<title abbrev="Extended SASL">Extensible Simple Authentication and Security Layer (SASL)</title>

	<author initials='D.' surname="Cridland" fullname="Dave Cridland">
	    <organization></organization>
	    <address>
		    <email>dave@cridland.net</email>
	    </address>
	</author>
  <author initials='T.' surname="Molitor" fullname="Thilo Molitor">
	    <organization></organization>
	    <address>
		    <email>thilo+xmpp@eightysoft.de</email>
	    </address>
	</author>
	<author initials='M.' surname="Wild" fullname="Matthew Wild">
	    <organization></organization>
	    <address>
		    <email>mwild1@gmail.com</email>
	    </address>
	</author>
	<author initials='A.' surname="Melnikov" fullname="Alexey Melnikov">
	    <organization>Isode Ltd</organization>
	    <address>
		    <email>Alexey.Melnikov@isode.com</email>
	    </address>
	</author>
        <date day="31" month="July" year="2026"/>
        <abstract>
          <t>
          This document specifies an IMAP extension for SASL2 authentication,
          which extends IMAP SASL (RFC 4422) Profile.
          </t>
        </abstract>
      </front>
      <seriesInfo name="Internet-Draft" value="draft-melnikov-sasl2-03"/>
      <format target="https://www.ietf.org/archive/id/draft-melnikov-sasl2-03.txt" type="TXT"/>
      </reference>


      <reference anchor="IMAP-REMEMBERME" target="https://www.ietf.org/archive/id/draft-melnikov-imap-rememberme-01.txt">
      <front>
	<title>IMAP REMEMBERME extension for quick reauthentication token generation</title>

	<author initials='A.' surname="Melnikov" fullname="Alexey Melnikov">
	    <organization>Isode Ltd</organization>
	    <address>
		    <email>Alexey.Melnikov@isode.com</email>
	    </address>
	</author>
        <date day="31" month="July" year="2026"/>
        <abstract>
          <t>
          This document specifies an IMAP extension for generating quick
          reauthentication tokens that allow clients to re-login without user
          interaction, once authentication using a strong SASL mechanism is
          completed.
          </t>
        </abstract>
      </front>
      <seriesInfo name="Internet-Draft" value="draft-melnikov-imap-rememberme-01"/>
      <format target="https://www.ietf.org/archive/id/draft-melnikov-imap-rememberme-01.txt" type="TXT"/>
      </reference>


    </references>

    <references title="Informative References">

      <?rfc include="reference.RFC.7519"?> <!-- JWT -->

      <reference anchor="draft-ietf-kitten-sasl-ht" target="https://www.ietf.org/archive/id/draft-ietf-kitten-sasl-ht-02.txt">
      <front>
        <title>The Hashed Token SASL Mechanism</title>
        <author fullname="Florian Schmaus" initials="F." surname="Schmaus">
          <organization>FAU Erlangen-Nürnberg</organization>
        </author>
        <author fullname="Thilo Molitor" initials="T." surname="Molitor">
          <organization>Chalmers University of Technology</organization>
        </author>
        <author fullname="Christoph Egger" initials="C." surname="Egger">
          <organization>Chalmers University of Technology</organization>
        </author>
        <date day="22" month="June" year="2026"/>
        <abstract>
          <t>This document specifies the family of Hashed Token SASL mechanisms which enable a proof-of-possession-based authentication scheme and are meant to be used for quick re-authentication of a previous session. The Hashed Token SASL mechanism's authentication sequence consists of only one round-trip. The usage of short-lived, exclusively ephemeral hashed tokens is achieving the single round- trip property. The SASL mechanism specified herin further provides hash agility, mutual authentication and support for channel binding.</t>
        </abstract>
      </front>
      <seriesInfo name="Internet-Draft" value="draft-ietf-kitten-sasl-ht-02"/>
      <format target="https://www.ietf.org/archive/id/draft-ietf-kitten-sasl-ht-02.txt" type="TXT"/>
      </reference>

      <reference anchor="draft-ietf-kitten-sasl-rememberme" target="https://www.ietf.org/archive/id/draft-ietf-kitten-sasl-rememberme-00.txt">
      <front>
        <title>SASL Remember Me</title>
        <author fullname="Ben Bucksch" initials="B." surname="Bucksch">
          <organization>Beonex</organization>
        </author>
        <author fullname="Stephen Farrell" initials="S." surname="Farrell">
          <organization>Trinity College Dublin</organization>
        </author>
        <date day="28" month="February" year="2025"/>
        <abstract>
          <t>Introduces a SASL mechanism that allows the application to stay
          logged in and re-login without user interaction, after completing a
          time-consuming SASL login mechanism that involves the user.
          </t>
        </abstract>
      </front>
      <seriesInfo name="Internet-Draft" value="draft-ietf-kitten-sasl-rememberme-00"/>
      <format target="https://www.ietf.org/archive/id/draft-ietf-kitten-sasl-rememberme-00.txt" type="TXT"/>
      </reference>

    </references>

<!--
    <section title="Acknowledgements">
	
      <t>Thank you to XSF community for suggestions, comments and corrections on this document.</t>
      
    </section>
-->    
    
  </back>
</rfc>
