<?xml version="1.0"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">

<?rfc compact="no"?>
<?rfc toc="yes"?>

<rfc category="std" ipr="full3978"
     docName="draft-josefsson-password-auth-01rc">

<front>

<title>
A Password-based Authentication Protocol
</title>

<author initials="S." surname="Josefsson" fullname="Simon Josefsson">
	<organization></organization>
	<address>
		<email>simon@josefsson.org</email>
	</address>
</author>
	
<date month="December" year="2007"/>

<abstract>

  <t>There is a lack of a simple, standardized, secure and modern
    password-based mechanism for user authentication in application
    protocols.  This document specify a challenge/response protocol
    that provide password-based authentication services.  We describe
    how the protocol may be used as a GSS-API mechanism.  Via the GS2
    framework, it can also be used as a SASL mechanism.  The protocol
    supports HMAC-SHA-256 as the mandatory to implement algorithm, and
    it supports channel bindings.  The intended use is by application
    protocol that today use CRAM-MD5 or DIGEST-MD5 via SASL, or by
    GSS-API applications that needs a password based method.  The
    protocol is applicable to other environments, such as EAP, should
    the need arise.</t>

  <t>See &lt;http://josefsson.org/password/&gt; for more
    information.</t>

</abstract>

</front>
	
<middle>

<section title="Introduction">

  <t>Several application protocols, for example SMTP and IMAP, use
    the <xref target="RFC4422">Simple Authentication and Security
    Layer (SASL)</xref> for user authentication.  The SASL framework
    supports several authentication mechanisms based on different
    technologies.  Authentication based on a username and password may
    use the TLS+EXTERN, TLS+PLAIN, CRAM-MD5, DIGEST-MD5 or the
    Kerberos V5 mechanism.  Other mechanisms are (to my knowledge) not
    standardized nor widely deployed.</t>

  <t>A quick overview of some perceived disadvantages with the current
    options:</t>

  <t>TLS+EXTERN lack support for channel bindings, and TLS-SRP is not
    widely recognized thus leaving TLS without any password based
    authentication mechanism.</t>

  <t>TLS+PLAIN lack support for <xref target="RFC5056">channel
    bindings</xref>, and it transmits the password to the peer, which
    is considered sub-optimal from a security perspective.</t>

  <t>CRAM-MD5 lack support for channel bindings, authorization
    identities, and is based on the deprecated MD5 hash algorithm.</t>

  <t>DIGEST-MD5 is based on the deprecated MD5 hash algorithm, and
    does not use HMAC or a similar widely studied hash-based
    authentication mode.</t>

  <t>Kerberos V5 requires that there is a Kerberos V5 infrastructure
    in place, and needs out-of-band (from the application protocol's
    point of view) communication.</t>

  <t>The <xref target="RFC2743">Generic Security Service Application
      Program Interface (GSS-API)</xref> mechanism described in this
    document, when used with
    the <xref target="I-D.ietf-sasl-gs2">GS2</xref> SASL mechanism,
    provides channel bindings, authorization identity, hash agility
    with initial support for HMAC-SHA-256, and will not reveal the
    password to the peer.</t>

  <t>Finally, we note that the GSS-API framework currently do not have
    any password-based standard mechanism, and this document provides
    one.</t>
  
</section>

<section title="Conventions Used in this Document">

  <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>The term "big-endian" is used for brevity to refer to the
    most-significant-octet-first encoding of integers in binary
    structures.</t>

</section>

<section title="Wire Protocol">

  <t>This section describes the format of the tokens which are
    exchanged between the client and the server.</t>

  <t>The protocol consists of one challenge packet, sent from the
    server to the client, and one response packet, send from the
    client to the server.</t>

  <t>For compatibility with the GSS-API framework, the challenge is
    prefixed with the mechanism-independent token format, as described
    by RFC 2743 section 3.1.  This description is self-contained and
    you need not implement GSS-API to support this protocol.</t>

  <t>The protocol does not specify control messages to signal
    (un)successful authentication to the peer.  It is anticipated that
    this protocol will be used in other authentication protocols or
    frameworks that has sufficient signalling capabilities.  This is
    true for GSS-API, SASL and EAP.  If a need arise to specify
    control messages, the protocol is flexible and allows this do be
    made inside a specific algorithm.</t>

  <section title="Challenge Token">

    <t>The challenge is sent from the server to the client, and its
      format is illustrated below.</t>

    <figure>
      <artwork>
                      1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |      0x60     |   length...                                   /
 /                      algorithm_identifier                     /
 /                     channel_binding_length                    |
 /                         channel_binding                       |
 /                            challenge                          |
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      </artwork>
    </figure>

    <t>The first byte is fixed to 0x60.</t>

    <t>The "length" field contains the sum of the lengths of the
      "algorithm_identifier" and "challenge" fields.  The length is
      encoded as a DER length values.</t>

    <t>For reference, DER length value encoding means that for lengths
      less than 128, it shall be represented in a single octet with
      bit 8 (high order) set to "0" and the remaining bits
      representing the value.  If the indicated value is 128 or more,
      it shall be represented in two or more octets, with bit 8 of the
      first octet set to "1" and the remaining bits of the first octet
      specifying the number of additional octets.  The subsequent
      octets carry the value, 8 bits per octet, most significant digit
      first.  The minimum number of octets shall be used to encode the
      length (i.e., no octets representing leading zeros shall be
      included within the length encoding).</t>

    <t>[XXX: Add example code to encode/decode DER lengths]</t>

    <t>The "algorithm_identifier" contains a fixed string that
      correspond to the algorithm which is used.  The strings will be
      DER encoded Object Identifiers (including the DER tag and
      length) but it is suggested that implementations compare the
      field against known supported algorithms.</t>

    <t>The "channel_binding_length" is a 4 byte integer encoded in
      big-endian order (i.e., most significant byte first) denoting
      the length of the "channel_binding" field.</t>

    <t>The "channel_binding" contains the channel binding data.  See
      <xref target="RFC5056"/> for more information.</t>

    <t>The "challenge" field contains the challenge data associated
      with the algorithm indicated by the "algorithm_identifier"
      field.</t>

  </section>
    
  <section title="Response">

    <t>The response is sent from the client to the server, and its
      format is illustrated below.</t>

    <figure>
      <artwork>
                      1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |                                                               /
 /                             response                          /
 /                                                               |
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      </artwork>
    </figure>

    <t>The "response" field contains the response for the given
      challenge.  Its format depends on the "algorithm_identifier"
      used.</t>

  </section>

</section>

<section title="Mandatory to implement algorithm: HMAC-SHA-256">

  <t>Implementations MUST support the HMAC-SHA-256 algorithm.  It is
    based on <xref target="RFC2104">HMAC</xref> and
    <xref target="FIPS.180-2.2002">SHA-256</xref>.  The
    "algorithm_identifier" value for it is:</t>

  <figure>
    <artwork>
         algorithm             algorithm_identifier (in HEX)
        ------------           -----------------------------
        HMAC-SHA-256               06092B06010401DA470401
    </artwork>
  </figure>

  <section title="HMAC-SHA-256 Challenge">

    <t>The "challenge" field MUST consist of 32 bytes of random
      data.</t>

  </section>

  <section title="HMAC-SHA-256 Response">

    <t>The "response" field is structured, illustrated as follows:</t>

    <figure>
      <artwork>
                      1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 |                                                               /
 /                  hmac_response (32 bytes)                     /
 /                                                               |
 |              authentication_identity_length                   |
 |                                                               /
 /                  authentication_identity                      /
 /                                                               /
 /                  [authorization_identity]                     /
 /                                                               |
 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      </artwork>
    </figure>

    <t>The "hmac_response" MUST consist of the output from the
      HMAC-SHA-256 algorithm using the "challenge" as input and the
      password as "key".  The size is always 32 bytes.</t>
      
    <t>The "authentication_identity_length" is a 4 byte integer
      encoded in big-endian order (i.e., most significant byte first)
      denoting the length of the "authentication_identity" field.</t>

    <t>The "authentication_identity" is a variable-length field (the
      length is in "authentication_identity_length") which contains an
      authentication identity.</t>

    <t>The "authorization_identity" is a variable-length field; its
      length can be deduced from "authentication_identity_length" and
      the size of the entire structure.  In particular, if there is
      data left in the structure after the "authentication_identity"
      field, the data constitutes the "authorization_identity".</t>

    <t>[XXX: Use PKCS#5 PBKDF2?  The username could be salt.  The
      problem is that we need to send the iteration length over the
      wire too, which complicate things.]</t>

    <t>[XXX: Support stored hashed password on the server.  For
      example, the "key" stored on the server wouldn't have to be the
      password straight, it could be a hashed value, possibly the
      PBKDF2 output, based on the authid and password. ]</t>

  </section>

</section>

<section title="Using the protocol with GSS-API">

  <t>The Challenge Token has the necessary format to serve as a
    mechanism-independent GSS-API Request Token.  The Response Token
    serve as the GSS-API Response Token.  The protocol consists only
    of one round-trip.  Calling GSS_Init_sec_context will return the
    Challenge Token with a GSS_S_CONTINUE_NEEDED status return.
    Passing the token to GSS_Accept_sec_context will either lead to a
    GSS_S_COMPLETE status return or a failure (thus, in particular, it
    will never lead to a GSS_S_CONTINUE_NEEDED status return).</t>

  <t>The HMAC-SHA-256 value is derived from the registered Object
    Identifier 1.3.6.1.4.1.11591.4.1.</t>

  <t>[XXX: Discuss GSS-API flags.]</t>

  <section title="How Applications Specify the Password">

    <t>The GSS-API framework does not deal with initial acquisation of
      credentials.  Thus, how application set the password that the
      GSS-CRAM implementation will use is outside of the scope of
      GSS-API.</t>
  
    <t>However, this particular GSS-API design choice seriously limits
      the usefulness of this mechanism, therefor it is considered
      whether to mandate, for use with GSS-CRAM, a specific method for
      applications to set the password.  One option here would be
      <xref target="gss-conv"/>. [XXX]</t>

  </section>

</section>

<section title="SASL GS2 Mechanism Name">

  <t>The <xref target="I-D.ietf-sasl-gs2">GS2</xref> framework can use
    the GSS-API mechanism based on this protocol directly.</t>

  <t>The OID is 1.3.6.1.4.1.11591.4.1. The ASN.1 DER encoding of the
    OID, including the tag and length, is (in hex) 06 09 2B 06 01 04
    01 DA 47 04 01.  The SHA-1 hash of the ASN.1 DER encoding is (in
    hex) 3e 0d 90 8a 97 7b 6c da 9e 48 29 2b ca 63 7b 8d 9d 6b 96 d1.
    Convert the first ten octets to binary, and re-group them in
    groups of 5, and convert them back to decimal, which results in
    these computations:</t>

  <figure>
    <artwork>
   hex:
   3E 0D 90 8A 97 7B 6C DA 9E 48

   binary:
   00111110 00001101 10010000 10001010 10010111
   01111011 01101100 11011010 10011110 01001000

   binary in groups of 5:
   00111 11000 00110 11001 00001 00010 10100 10111
   01111 01101 10110 01101 10101 00111 10010 01000

   decimal of each group:
   7 24 6 25 1 2 20 23 15 13 22 13 21 7 18 8

   base32 encoding:
   H Y G Z B C U X P N W N V H S I
    </artwork>
  </figure>

  <t>The last step translate each decimal value using table 3 in
    Base32 [6].  Thus the SASL mechanism name for the HMAC-SHA-256
    mechanism is "GS2-HYGZBCUXPNWNVHSI".</t>

</section>

<section title="IANA Considerations">

  <t>None</t>

</section>

<section title="Security Considerations">

  <t>TBA</t>

</section>

<section title="Copying conditions">

  <t>Regarding this entire document or any portion of it (including
    the pseudocode and C code), the author makes no guarantees and is
    not responsible for any damage resulting from its use.  The author
    grants irrevocable permission to anyone to use, modify, and
    distribute it in any way that does not diminish the rights of
    anyone else to use, modify, and distribute it, provided that
    redistributed derivative works do not contain misleading author or
    version information.  Derivative works need not be licensed under
    similar terms.</t>
  
</section>

</middle>

<back>

<references title="Normative References">

  <?rfc include="reference.RFC.2119.xml"?>
  <?rfc include="reference.RFC.2104.xml"?>
  <?rfc include="reference.FIPS.180-2.2002.xml"?>
  <?rfc include="reference.RFC.5056.xml"?>

</references>

<references title="Informative References">

  <?rfc include="reference.RFC.2743.xml"?>
  <?rfc include="reference.RFC.4422.xml"?>
  <?rfc include="reference.I-D.draft-ietf-sasl-gs2-06.xml"?>

  <reference anchor="gss-conv">
    <front>
      <title>GSS Conversation C-bindings Interface</title>
      <author initials="T." surname="Ts'o" fullname="T. Ts'o">
      </author>
    </front>
    <seriesInfo name="WWW"
		value="http://www3.ietf.org/proceedings/99nov/I-D/draft-ietf-cat-gss-conv-00.txt" />
  </reference>
  
</references>

</back>

</rfc>
