<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">
<?rfc toc="yes"?>
<?rfc tocompact="yes"?>
<?rfc tocdepth="3"?>
<?rfc tocindent="yes"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<rfc category="std" docName="draft-sakimura-oauth-tcse-03" ipr="trust200902">
  <front>
    <title abbrev="oauth_spop">OAuth Symmetric Proof of Posession for Code
    Extension</title>

    <author fullname="Nat Sakimura" initials="N." role="editor"
            surname="Sakimura">
      <organization>Nomura Research Institute</organization>

      <address>
        <postal>
          <street/>

          <city/>

          <region/>

          <code/>

          <country/>
        </postal>

        <phone/>

        <facsimile/>

        <email>sakimura@gmail.com</email>

        <uri>http://nat.sakimura.org/</uri>
      </address>
    </author>

    <author fullname="John Bradley" initials="J." surname="Bradley">
      <organization>Ping Identity</organization>

      <address>
        <postal>
          <street/>

          <city/>

          <region/>

          <code/>

          <country/>
        </postal>

        <phone/>

        <facsimile/>

        <email>jbradley@pingidentity.com</email>

        <uri/>
      </address>
    </author>

    <author fullname="Naveen Agarwal" initials="N." surname="Agarwal">
      <organization>Google</organization>

      <address>
        <postal>
          <street/>

          <city/>

          <region/>

          <code/>

          <country/>
        </postal>

        <phone/>

        <facsimile/>

        <email>naa@google.com</email>

        <uri/>
      </address>
    </author>

    <date day="21" month="April" year="2014"/>

    <area>Security</area>

    <workgroup>OAuth Working Group</workgroup>

    <abstract>
      <t>The OAuth 2.0 public client utilizing authorization code grant is
      susceptible to the code interception attack. This specification describe
      a mechanism that acts as a control against this threat.</t>
    </abstract>

    <note title="Requirements Language">
      <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">RFC 2119</xref>.</t>
    </note>
  </front>

  <middle>
    <section title="Introduction">
      <t>Public clients in <xref target="RFC6749">OAuth 2.0 </xref> is
      suseptible to the <spanx style="verb">code</spanx> interception attack.
      The <spanx style="verb">code</spanx> interception attack is an attack
      that a malicious client intercepts the <spanx style="verb">code</spanx>
      returned from the authorization endpoint and uses it to obtain the
      access token. This is possible on a public client as there is no client
      secret associated for it to be sent to the token endpoint. This is
      especially true on some smartphone platform in which the <spanx
      style="verb">code</spanx> is returned to a redirect URI with a custom
      scheme as there can be multiple apps that can register the same
      scheme.Under this scenario, the mitigation strategy stated in section
      4.4.1 of <xref target="RFC6819"/> does not work as they rely on
      per-client instance secret or per client instance redirect uri.</t>

      <t>To mitigate this attack, this extension utilizes dynamically created
      cryptographically random key called 'code verifier'. The code verifier
      is created for every authorization request and its transformed value
      called code challenge is sent to the authorization server to obtain the
      authorization code. The <spanx style="verb">code</spanx> obtained is
      then sent to the token endpoint with the code verifier and the server
      compairs it with the previously received reqeust code so that it can
      perfom the proof of posession of the code verifier by the client. This
      works as the mitigation since the attacker would not know the one-time
      key.</t>
    </section>

    <section title="Terminology">
      <t>In addition to the terms defined in <xref target="RFC6749">OAuth
      2.0</xref>, this specification defines the following terms.</t>

      <section title="code verifier">
        <t>a cryptographically random string with big enough entropy that is
        used to correlate the authorization request to the token request</t>
      </section>

      <section title="code challenge">
        <t>either the code verifier itself or some transformation of it that
        is sent from the client to the server in the authorization request</t>

        <t>NOTE 1: The client and the server MAY use mutually agreed
        pre-negotiated algorithm such as base64url encoding of the left most
        128bit of SHA256 hash.</t>

        <t>NOTE 2: If no algorithm has been negotiated, it is treated as the
        code verifier itself.</t>
      </section>
    </section>

    <section title="Protocol">
      <t/>

      <section title="Client checks the server support">
        <t>Before starting the authorization process, the client MUST make
        sure that the server supports this specification. It may be obtained
        out-of-band or through some other mechanisms such as the discovery
        document in <xref target="OpenID.Discovery">OpenID Connect
        Discovery</xref>. The exact mechanism on how the client obtains this
        information is out of scope of this specification.</t>

        <t>The client that wishes to use this specification MUST stop
        proceeding if the server does not support this extension.</t>
      </section>

      <section title="(optional) Client registers its desired code challenge algorithm">
        <t>In this specification, the client sends the transformation of the
        code verifier to the authorization server in the front channel. The
        default transformation is not doing transformation at all. If the the
        server supports, the client MAY register its desired transformation
        algorithm to the server. If the algorithm is registered, the server
        MUST reject any request that does not conform to the algorithm.</t>

        <t>How does this client registers the algorithm is out of scope for
        this specification.</t>

        <t>Also, this specification does not define any transformation other
        than the default transformation.</t>
      </section>

      <section title="Client creates a code verifier">
        <t>The client then creates a code verifier, <spanx style="verb">code_verifier</spanx>,
        in the following manner.</t>

        <t>code_verifier = high entropy cryptographic random string of length
        less than 128 bytes</t>

        <t>NOTE: code verifier MUST have high enough entropy to make it
        inpractical to guess the value.</t>
      </section>

      <section title="Client sends the code challenge with the authorization request">
        <t>Then, the client creates a code challenge, <spanx style="verb">code_challenge</spanx>,
        by applying the pre-negotiated algorithm between the client and the
        server. The default behavior is no transofrmation, i.e., <spanx
        style="verb">code_challenge</spanx> == <spanx style="verb">code_verifier</spanx>.
        The authorization server MUST support this 'no transformation'
        algorithm.</t>

        <t>The client sends the code challenge with the following parameter
        with the <xref target="RFC6749">OAuth 2.0</xref> Authorization
        Request:</t>

        <t><list style="hanging">
            <t hangText="code_challenge">REQUIRED. code challenge.</t>
          </list></t>
      </section>

      <section title="Server returns the code">
        <t>When the server issues a <spanx style="verb">code</spanx>, it MUST
        associate the <spanx style="verb">code_challenge</spanx> value with
        the <spanx style="verb">code</spanx> so that it can be used later.</t>

        <t>Typically, the <spanx style="verb">code_challenge</spanx> value is
        stored in encrypted form in the <spanx style="verb">code</spanx>, but
        it could as well be just stored in the server in association with the
        code. The server MUST NOT include the <spanx style="verb">code_challenge</spanx>
        value in the form that any entity but itself can extract it.</t>
      </section>

      <section title="Client sends the code and the secret to the token endpoint">
        <t>Upon receipt of the <spanx style="verb">code</spanx>, the client
        sends the request to the token endpoint. In addition to the parameters
        defined in <xref target="RFC6749">OAuth 2.0</xref>, it sends the
        following parameter:</t>

        <t><list style="hanging">
            <t hangText="code_verifier">REQUIRED. code verifier</t>
          </list></t>
      </section>

      <section title="Server verifies code_verifier before returning the tokens">
        <t>Upon receipt of the request at the token endpoint, the server
        verifies it by calculating the code challenge from <spanx
        style="verb">code_verifier</spanx> value and comparing it with the
        previously associated <spanx style="verb">code_challenge</spanx>. If
        they are equal, then the successful response SHOULD be returned. If
        the values are not equal, an error response indicating <spanx
        style="verb">invalid_grant</spanx> as described in section 5.2 of
        <xref target="RFC6749">OAuth 2.0</xref> SHOULD be returned.</t>
      </section>
    </section>

    <section anchor="IANA" title="IANA Considerations">
      <t>This specification makes a registration request as follows:</t>

      <section title="OAuth Parameters Registry">
        <t>This specification registers the following parameters in the IANA
        OAuth Parameters registry defined in <xref target="RFC6749">OAuth
        2.0</xref>.</t>

        <t><list style="symbols">
            <t>Parameter name: code_verifier</t>

            <t>Parameter usage location: Access Token Request</t>

            <t>Change controller: OpenID Foundation Artifact Binding Working
            Group - openid-specs-ab@lists.openid.net</t>

            <t>Specification document(s): this document</t>

            <t>Related information: None</t>
          </list><list style="symbols">
            <t>Parameter name: code_challenge</t>

            <t>Parameter usage location: Authorization Request</t>

            <t>Change controller: OpenID Foundation Artifact Binding Working
            Group - openid-specs-ab@lists.openid.net</t>

            <t>Specification document(s): this document</t>

            <t>Related information: None</t>
          </list></t>
      </section>
    </section>

    <section anchor="Security" title="Security Considerations">
      <t>The security model relies on the fact that the code verifier is not
      learned or guessed by the attacker. It is vitally important to adhear to
      this principle. As such, the code verifier has to be created in such a
      manner that it is cryptographically random and has high entropy that it
      is not practical for the attacker to guess, and if it is to be returned
      inside <spanx style="verb">code</spanx>, it has to be encrypted in such
      a manner that only the server can decrypt and extract it.</t>

      <t>If the no transformation algorithm, which is the default algorithm,
      is used, the client MUST make sure that the request channel is
      adequately protected. On a platform that it is not possible, the client
      and the server SHOULD utilize a transformation algorithm that makes it
      reasonably hard to recalculate the code verifier from the code
      challenge.</t>

      <t>All the OAuth security analysis presented in <xref target="RFC6819"/>
      applies so readers SHOULD carefully follow it.</t>
    </section>

    <section anchor="Acknowledgements" title="Acknowledgements">
      <t>The initial draft of this specification was created by the OpenID
      AB/Connect Working Group of the OpenID Foundation, by most notably of
      the following people:</t>

      <t><list style="symbols">
          <t>Naveen Agarwal, Google</t>

          <t>Dirk Belfanz, Google</t>

          <t>Sergey Beryozkin</t>

          <t>John Bradley, Ping Identity</t>

          <t>Brian Campbell, Ping Identity</t>

          <t>Phill Hunt, Oracle</t>

          <t>Ryo Ito, mixi</t>

          <t>Michael B. Jones, Microsoft</t>

          <t>Torsten Lodderstadt, Deutsche Telekom</t>

          <t>Breno de Madeiros, Google</t>

          <t>Prateek Mishra, Oracle</t>

          <t>Anthony Nadalin, Microsoft</t>

          <t>Axel Nenker, Deutsche Telekom</t>

          <t>Nat Sakimura, Nomura Research Institute</t>
        </list></t>
    </section>

    <section title="Revision History">
      <t>-02</t>

      <t><list style="symbols">
          <t>Changed title.</t>

          <t>Changed parameter names.</t>

          <t>Changed the default transformation algorithm and added crypto
          agility.</t>

          <t>More text in the security consideration.</t>

          <t>Now references RFC 6819.</t>

          <t>Recorded more contributors.</t>
        </list>-01</t>

      <t><list style="symbols">
          <t>Minor editorial changes.</t>
        </list>-00</t>

      <t><list style="symbols">
          <t>Initial version.</t>
        </list></t>
    </section>
  </middle>

  <back>
    <references title="Normative References">
      <?rfc include="reference.RFC.2119"?>

      <?rfc include='reference.RFC.6749'?>

      <?rfc include='reference.RFC.6819'?>
    </references>

    <references title="Informative References">
      <?rfc include="http://xml.resource.org/public/rfc/bibxml/reference.RFC.4949"?>

      <reference anchor="OpenID.Discovery">
        <front>
          <title>OpenID Connect Discovery 1.0</title>

          <author fullname="Nat Sakimura" initials="N." surname="Sakimura">
            <organization abbrev="NRI">Nomura Research Institute,
            Ltd.</organization>
          </author>

          <author fullname="John Bradley" initials="J." surname="Bradley">
            <organization abbrev="Ping Identity">Ping Identity</organization>
          </author>

          <author fullname="Michael B. Jones" initials="M.B." surname="Jones">
            <organization abbrev="Microsoft">Microsoft</organization>
          </author>

          <author fullname="Edmund Jay" initials="E." surname="Jay">
            <organization abbrev="Illumila">Illumila</organization>
          </author>

          <date day="30" month="May" year="2013"/>
        </front>

        <format target="http://openid.net/specs/openid-connect-discovery-1_0-16.html"
                type="HTML"/>
      </reference>
    </references>
  </back>
</rfc>
