<?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-00" ipr="trust200902">
  <front>
    <title abbrev="oauth_tcse">OAuth Transient Client Secret Extension for
    Public Clients</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/>
      </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="28" month="July" year="2013"/>

    <area>Security</area>

    <workgroup>OAuth Working Group</workgroup>

    <abstract>
      <t>The OAuth 2.0 public client utilizing code flow 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.</t>

      <t>To mitigate this attack, this extension utilizes dynamically created
      client secret called transient client secret whose left hash is sent as
      a new authorization request parameter. The <spanx style="verb">code</spanx>
      obtained is then sent to the token endpoint with the transient client
      secret and the server compairs it with the previously received left hash
      of it so that it can perfom the proof of posession by the client.</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="transient client secret">
        <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="transient client secret hash">
        <t>base64url encoding of the left most 128bit of SHA256 hash of
        transient client secret</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 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="Client creates a transient client secret">
        <t>The client then creates a transient client secret, <spanx
        style="verb">tcs</spanx>, in the following manner.</t>

        <t> tcs = high entropy cryptographic random string</t>

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

      <section title="Client sends the salted left hash with the authorization request">
        <t>Then, the client calculates a transient client secret hash, <spanx
        style="verb">tcsh</spanx>, the salted left hash of the <spanx
        style="verb">tcs</spanx> as follows where L is a function that
        calcualtes the base64url encoded left-most 128 bits of the binary
        input, and H is a SHA256 function.</t>

        <t> tcsh = L (H ( tcs) )</t>

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

        <t><list style="hanging">
            <t hangText="tcsh">REQUIRED. transient client secret hash</t>
          </list></t>
      </section>

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

        <t>Typically, the <spanx style="verb">tcsh</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">tcsh</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>Unpon 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="tcs">REQUIRED. transient client secret</t>
          </list></t>
      </section>

      <section title="Server verifies tcs before returning the tokens">
        <t>Upon receipt of the request at the token endpoint, the server
        verifies it by calculating the transient client secret hash from
        <spanx style="verb">tcs</spanx> value and <spanx style="verb">tcsh</spanx>
        and comparing it with the previously associated <spanx style="verb">tcsh</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: tcs</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: tcsh</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 transient client
      secret is not being disclosed in the front channel. It is vitally
      important to adhear to this principle. As such, the transient client
      secret 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>
    </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>John Bradley, Ping Identity</t>

          <t>Brian Campbell, Ping Identity</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>Anthony Nadalin, Microsoft</t>

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

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

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

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

      <?rfc include='reference.RFC.4627'?>
    </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>
