<?xml version="1.0" encoding="UTF-8"?>
<!-- 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml' -->

<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
    <!ENTITY rfc2104 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2104.xml'>
    <!ENTITY rfc2119 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.2119.xml'>
    <!ENTITY rfc3629 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.3629.xml'>
    <!ENTITY rfc4422 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4422.xml'>
    <!ENTITY rfc4510 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4510.xml'>
    <!ENTITY rfc4616 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4616.xml'>
    <!ENTITY rfc4648 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4648.xml'>
    <!ENTITY rfc4949 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.4949.xml'>
    <!ENTITY rfc5056 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5056.xml'>
    <!ENTITY rfc5226 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5226.xml'>
    <!ENTITY rfc5234 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5234.xml'>
    <!ENTITY rfc5246 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5246.xml'>
    <!ENTITY rfc5802 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5802.xml'>
    <!ENTITY rfc5929 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.5929.xml'>
    <!ENTITY rfc6238 PUBLIC '' 'http://xml.resource.org/public/rfc/bibxml/reference.RFC.6238.xml'>
  ]>

  <?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>

<?rfc toc="yes" ?>
<?rfc tocindent="no" ?>
<?rfc autobreaks="no" ?>
<?rfc comments="yes" ?>
<?rfc inline="yes" ?>
<?rfc symrefs="yes" ?>
<?rfc sortrefs="yes"?>
<?rfc iprnotified="no" ?>
<?rfc strict="no" ?>
<?rfc compact="no"?>

<rfc ipr="trust200902" category="std" docName="draft-melnikov-scram-2fa-03">
    <front>
	<title abbrev="SCRAM 2FA extensions">Extensions to Salted Challenge Response (SCRAM) for 2 factor authentication</title>
	<author initials='A.' surname="Melnikov" fullname="Alexey Melnikov">
	    <organization>Isode Ltd</organization>
	    <address>
		<email>Alexey.Melnikov@isode.com</email>
	    </address>
	</author>
      
  <date year="2021"/>
	<area>Security</area>
	<keyword>SASL</keyword>
	<keyword>SCRAM</keyword>
	<keyword>KITTEN</keyword>
	<keyword>2FA</keyword>
	<abstract>

    <t>
    This specification describes an extension to family of Simple Authentication and
    Security Layer (SASL; RFC 4422) authentication mechanisms called the
    Salted Challenge Response Authentication Mechanism (SCRAM), which
    provides support for 2 factor authentication.
    </t>

    <t>
    This specification also gives an example of how TOTP (RFC 6238) can be used
    as the second factor.
    </t>

  </abstract>
    </front>

    <middle>

	<section title="Introduction">

    <t>
    SCRAM <xref target='RFC5802'/> is a password based SASL <xref target="RFC4422"/>
    authentication mechanism that provides (among other things) mutual authentication
    and binding to an external security layer such as TLS.
    </t>
    
    <t>
    Two-factor authentication (2FA) is a way to add additional security to an authentication
    exchange. The first "factor" is a password. The second "factor" is a verification code
    retrieved from an application on a mobile device or computer.
    2FA is conceptually similar to a security token device that banks in some countries
    require for online banking. Other names for 2FA systems include OTP (one-time password)
    and TOTP (Time-based One-time Password algorithm, such as <xref target="RFC6238"/>).
    </t>

    <t>This specification describes an extension to SCRAM to provide 2 factor authentication.
    SCRAM already relies on passwords for authentication. This document specifies
    how second "factors" can be incorporated into SCRAM authentication.
    </t>
  
	</section>

	<section anchor="conv" title="Conventions Used in This Document">

	<!--///Need to update to match the latest wording-->
	    <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL",
		"SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED",
		"MAY", and "OPTIONAL" in this document are to be
		interpreted as described in <xref
		    target='RFC2119'/>.</t>

	    <t>Formal syntax is defined by <xref target='RFC5234'/>
		including the core rules defined in Appendix B of <xref
		    target='RFC5234'/>.
      </t>

	    <t>Example lines prefaced by "C:" are sent by the client and
		ones prefaced by "S:" by the server. If a single "C:" or
		"S:" label applies to multiple lines, then the line
		breaks between those lines are for editorial clarity
		only, and are not part of the actual protocol
		exchange.</t>

	    <section title="Terminology">

		<t>This document uses several terms defined in <xref
			target='RFC4949'/> ("Internet Security
		    Glossary") including the following: authentication,
		    authentication exchange, authentication information,
		    brute force, challenge-response, cryptographic hash
		    function, dictionary attack, eavesdropping, hash
		    result, keyed hash, man-in-the-middle, nonce,
		    one-way encryption function, password, replay attack
		    and salt. Readers not familiar with these terms
		    should use that glossary as a reference.
            Other terms defined in <xref target='RFC5802'/> are
            also used in this document.</t>

	    </section>

	    <section title="Notation">

	<!--///If this document ends up not using +=, + or ||, this section can be deleted!-->
		    <t>This document reuses notation defined in SCRAM.</t>

	    </section>

	</section>

	<section title="SCRAM Extension for 2FA" anchor='overview'>

	    <t>This extension doesn't add any extra roundtrips to
        SCRAM authentication. SCRAM was designed to be extensible,
        so it allows for optional and mandatory attributes, which
        covered by MAC codes. Second "factors" are conveyed
        in the second message ("client-final-message-without-proof"
        ABNF production) sent from the client to the server.
        </t>

		<t>
        This extension doesn't change how the client authenticates
        the server.
        </t>

     <!--///I am using ABNF production references below. How to make it clearer?-->
	    <t>The server authenticates the client after receiving
        the second message as described in Section 3 of <xref target='RFC5802'/>
        If the client included "type" and "second-factor" attributes defined in this document
        (see <xref target="attrs"/>) and the server supports the specified
        second factor type, the server verifies content of the "second-factor"
        according to the "type". If the second factor verification fails,
        the server MUST fail authentication and SHOULD return either "replayed-second-factor"
        or "invalid-second-factor" error in the "e" attribute.

        [[It would be possible to make the extra attributes mandatory by using SCRAM's "m=",
        but the text above doesn't do that.]]
      </t>

	</section>

	<section anchor='attrs' title="Formal Syntax">

	  <t>This document defines the following new SCRAM attributes:

		<list style='symbols'>

		  <t>t: This attribute specifies the type of second factor.
		  [[Create IANA registry for these?]] This document defines one
      type: "totp".
		  If this attribute is specified, the "f" attribute MUST also be specified.</t>

		  <t>f: This attribute specifies the value of the second factor.
		  For "t=totp" it is 6 digit decimal number. [[Use 8 digits per Rick van Rein?]]
		  This attribute MUST be ignored unless the "t" attribute is also specified.</t>

		</list>

	  </t>

      <t>The following syntax specification uses the Augmented
      Backus-Naur Form (ABNF) notation as specified in <xref
		    target='RFC5234'/>.</t>
    
<figure><artwork type='abnf'>
<![CDATA[
   type            = "t=" type-value
                 ; Complies with "attr-val" syntax.
   type-value      = "totp" / value
                 ; Type of second factor.
                 ; Should be registered with IANA.
   second-factor   = "f=" second-factor-value
                 ; Complies with "attr-val" syntax.
   second-factor-value = 6DIGIT / value
                 ; 6DIGIT when "t=totp"
   server-error-value-ext =
           "replayed-second-factor" /
           "invalid-second-factor" /
           "second-factor-value-missing"

   value = <as defined in RFC 5802>
]]>
			</artwork>
			</figure>

	</section>
      
      
	<section anchor='totp' title="Use of TOTP with SCRAM">

	  <t>When TOTP is used with SCRAM, the following values for "t" and "f" attributes
    (see <xref target="attrs"/> for their generic syntax) are used:

		<list style='symbols'>

		  <t>t: This attribute specifies the type of second factor. For TOTP the value is "totp".
		  If this attribute is specified, the "f" attribute MUST also be specified.</t>

		  <t>f: This attribute specifies the value of the second factor.
		  For "t=totp" it is 6 digit decimal number.
		  This attribute MUST be ignored unless the "t" attribute is also specified.</t>

		</list>

	  </t>

    <!--///Alexey: Might need to explain why the following URI definition is needed?-->
    <t>A TOTP URI is specified with the following ABNF:</t>
    
<figure><artwork type='abnf'>
<![CDATA[
totp-uri = "otpauth" "://" "totp/" label "?secret=" secret
           "&issuer=" issuer
label = issuer (":" / "%3A") identity
identity = 1*CHAR ; URI-encoded SASL identity
secret = 40 * HEXCHAR ; Base32 (hex) encoded secret with no padding.
issuer = 1*CHAR ; Issuer name.
]]>
			</artwork>
			</figure>

	</section>  
      

	<section title="Example">

	  <t>The following example extends the example from Section 5 of <xref target='RFC5802'/> to demonstrate use of TOTP:</t>

      <figure>
        <artwork>
<![CDATA[
   C: n,,n=user,r=fyko+d2lbbFgONRv9qkxdawL
   S: r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,s=QSXCR+Q6sek8bf92,
      i=4096
   C: c=biws,r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,
      t=totp,f=776804,p=v0X8v3Bz2T0CJGbJQyF0X+HI4Ts=
   S: v=lz59pqV8S7suAoZWja4dJRkFsKQ=
]]>
        </artwork>
      </figure>

      <t>Please note that TOTP extension described in this document works in the same way
      with SCRAM-SHA-256/SCRAM-SHA-256-PLUS and SCRAM-SHA-512/SCRAM-SHA-512-PLUS variants of SCRAM.</t>

	</section>

	<section title="Open Issues">

	  <t>Simon Josefsson: should this be a new SASL mechanism name, e.g. CROTP-SHA-256?</t>
    
	  <t>Simon Josefsson: cookie option for fast reauthentication?
      Alexey: can do or just used CLIENT-KEY (draft-cridland-kitten-clientkey)?</t>

	  <t>Rick van Rein: specify a HOTP variant as well?</t>

	  <t>Rick van Rein: use TOTP with 6 or 8 digits? Register both variants?</t>

  </section>
      
	<section title="Security Considerations">

    <t>
    Unless an external security layer (such as TLS) is also used,
    the OTP value is sent in unencrypted/unhashed form from the client to the
    server, which allows an attacker to read the OTP value and perform a
    race with the server to validate the OTP.
    <!-- "For that reason TLS should always be used." -->
    </t>

	  <t>TBD</t>

  </section>

	<section anchor='iana' title="IANA Considerations">

    <!--///Alexey: the following will have to change, if something like CROTP-* is used-->
    <t>IANA is requested to update the definition of the SASL family SCRAM
    in the SASL Mechanism registry established by <xref target="RFC4422"/>
    to also point to this document.</t>

    <t>
    IANA is also requested to create a new subregistry of "SASL mechanism"
    for registering second factor schemes used in the "t" attribute as specified in this document.
    </t>

	  <t>The registration template is as follows:</t>

    <figure>
      <artwork>
        <![CDATA[
SCRAM Second Factor Scheme Name:
Pointer to specification text:
Notes (optional):
		    ]]>
      </artwork>
    </figure>

    <t>The registration procedure for the above subregistry is Expert Review.</t>

    <t>IANA is requested to register a new value in the subregistry defined above:</t>
    <figure>
      <artwork>
        <![CDATA[
SCRAM Second Factor Scheme Name: TOTP
Pointer to specification text: [[ this document ]]
Notes (optional): (none)
		    ]]>
      </artwork>
    </figure>

  </section>

	<section title="Acknowledgements">
		
    <t>Thank you to Stephen Farrell for motivating creation of this document and
    to Dave Cridland for describing how TOTP can be used with XMPP in XEP-400.
    Thank you to Rick van Rein and Simon Josefsson for comments and corrections,
    but all final errors in this document remain mine.</t>
    
	</section>


<!--
	<section title="Internet-Draft Change History">

	    <t>(RFC Editor: Please delete this section and all subsections.)</t>

	    <t>Changes since -00

		<list style='symbols'>

		    <t></t>

		</list>

	    </t>

	</section>
-->

    </middle>

    <back>
      
	<references title="Normative References">
    
      &rfc2119;
      &rfc4422;
      &rfc4949;
<!--
      &rfc5056;
      &rfc5929;
-->
	    &rfc5234;
	    &rfc5802;
      &rfc6238;

  </references>

<!--
  <references title="Informative References">
  </references>
-->
      
    </back>

</rfc>
