<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd" []>
<?xml-stylesheet type='text/xsl' href='http://xml.resource.org/authoring/rfc2629.xslt' ?>
<?rfc toc="yes"?>
<?rfc tocompact="yes"?>
<?rfc tocdepth="3"?>
<?rfc tocindent="yes"?>
<?rfc symrefs="no"?>
<?rfc sortrefs="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc strict="no"?>
<?rfc compact="no"?>
<?rfc subcompact="no"?>

<rfc category="std" ipr="trust200902"
docName="draft-ietf-oauth-pop-key-distribution-05">

  <front>
  <title abbrev="OAuth 2.0 PoP: AS-Client Key Distribution">OAuth 2.0 Proof-of-Possession: Authorization Server to Client Key Distribution</title>   

    <author fullname="John Bradley" initials="J." surname="Bradley">
      <organization abbrev="Ping Identity">Ping Identity</organization>
      <address>
	<email>ve7jtb@ve7jtb.com</email>
  <uri>http://www.thread-safe.com/</uri>
      </address>
    </author>

      <author fullname="Phil Hunt" initials="P." surname="Hunt">
      <organization>Oracle Corporation</organization>

      <address>
        <email>phil.hunt@yahoo.com</email>
        <uri>http://www.indepdentid.com</uri>
      </address>
    </author>
    
    
    <author fullname="Michael B. Jones" initials="M.B." surname="Jones">
      <organization abbrev="Microsoft">Microsoft</organization>

      <address>
        <email>mbj@microsoft.com</email>
        <uri>http://self-issued.info/</uri>
      </address>
    </author>


    <author initials="H." surname="Tschofenig" fullname="Hannes Tschofenig">
      <organization>Arm Ltd.</organization>
      <address>
        <postal>
          <street></street>
          <city>Absam</city>
          <code>6067</code>
          <country>Austria</country>
        </postal>
        <phone></phone>
        <email>Hannes.Tschofenig@gmx.net</email>
        <uri>http://www.tschofenig.priv.at</uri>
      </address>
    </author>

    <author initials="M.M." surname="Meszaros" fullname="Mihaly Meszaros">
      <organization>GITDA</organization>
      <address>
        <postal>
          <street></street>
          <city>Debrecen</city>
          <code>4033</code>
          <country>Hungary</country>
        </postal>
        <phone></phone>
        <email>bakfitty@gmail.com</email>
        <uri>https://github.com/misi</uri>
      </address>
    </author>


    <date year="2019"/>
    <keyword>Internet-Draft</keyword>
    <keyword>OAuth</keyword>
    <keyword>Security</keyword>
    <keyword>Authorization</keyword>
    <keyword>Key Distribution</keyword>
    <keyword>Proof-of-Possession</keyword>

    <abstract>

  <t>RFC 6750 specified the bearer token concept for securing access to protected resources. Bearer tokens need to be protected in transit as well as at rest. When a client requests access to a protected resource it hands-over the bearer token to the resource server.</t> 
  
  <t>The OAuth 2.0 Proof-of-Possession security concept extends bearer token security and requires the client to demonstrate possession of a key when accessing a protected resource.</t>
  
  <t>This document describes how the client requests and obtains a PoP access token from the authorization server for use with HTTPS-based transport. Alternative transports, for example using the Constrained Application Protocol (CoAP), have been specified in companion specifications.</t>

</abstract>

  </front>
  <middle>

<!-- ====================================================================== -->

<section anchor="introduction" title="Introduction">

   <t>The work on proof-of-possession tokens, an extended token security mechanisms for OAuth 2.0, is motivated in <xref target="I-D.ietf-oauth-pop-architecture"/>. This document defines the ability for the client request and to obtain PoP tokens from the authorization server. After successfully completing the exchange the client is in possession of a PoP token and the keying material bound to it. Clients that access protected resources then need to demonstrate knowledge of the secret key that is bound to the PoP token.</t>

  <t>To best describe the scope of this specification, the OAuth 2.0 protocol exchange sequence is shown in <xref target="oauth-flow"/>.
	  The extension defined in this document piggybacks on the message exchange marked with (C) and (D). To demonstrate possession of the private/secret key to the resource server protocol mechanisms outside the scope of this document are used.</t>
  
  	  <t>
        <figure anchor="oauth-flow" title="Augmented OAuth 2.0 Protocol Flow">
          <artwork><![CDATA[
+--------+                               +---------------+
|        |--(A)- Authorization Request ->|   Resource    |
|        |                               |     Owner     |
|        |<-(B)-- Authorization Grant ---|               |
|        |                               +---------------+
|        |
|        |                               +---------------+
|        |--(C)-- Authorization Grant -->|               |
| Client |        (aud, cnf)             | Authorization |
|        |                               |     Server    |
|        |<-(D)-- PoP Access Token ------|               |
|        |    (profile, cnf, rs_cnf,     +---------------+
|        |        token_type)
|        |                               +---------------+
|        |--(E)-- PoP Access Token ----->|               |
|        |   (with proof of private key) |    Resource   |
|        |                               |     Server    |
|        |<-(F)--- Protected Resource ---|               |
+--------+                               +---------------+
]]></artwork>
        </figure>
	  </t>
	  
	  
	  	  <t>In OAuth 2.0 <xref target="RFC6749"/> access tokens can be obtained via authorization grants and using refresh tokens. The core OAuth 
	  specification defines four authorization grants, see Section 1.3 of <xref target="RFC6749"/>, and 
	  <xref target="RFC7521"/> adds an assertion-based authorization grant to that list.
	  The token
   endpoint, which is described in Section 3.2 of <xref target="RFC6749"/>, is used with every authorization grant except for the implicit grant type. In the implicit grant type the access token is issued directly.</t>
   
   <t>This document extends the functionality of the token endpoint, i.e., the protocol exchange between the client and the authorization server, to allow keying material to be bound to an access token. Two types of keying material can be bound to an access token, namely symmetric keys and asymmetric keys. Conveying symmetric keys from the authorization server to the client is described in <xref target="symmetric"/> and the procedure for dealing with asymmetric keys is described in <xref target="asymmetric"/>. </t>
   	
</section> <!-- Introduction --> 

<!-- ************************************************************************************** --> 

<section title="Terminology">
   <t>The key words 'MUST', 'MUST NOT', 'REQUIRED', 'SHALL', 'SHALL NOT',
   'SHOULD', 'SHOULD NOT', 'RECOMMENDED', 'MAY', and 'OPTIONAL' in this
   specification are to be interpreted as described in <xref target="RFC2119"/>.</t>
   
  <t><list style="hanging">
		
		<t hangText="Session Key:"><vspace blankLines="1"/>
		In the context of this specification 'session key' refers to fresh and unique keying material established between the client and the resource server. This session key has a lifetime that corresponds to the lifetime of the access token, is generated by the authorization server and bound to the access token.</t> 
	</list>
   </t>
	  
	<t>This document uses the following abbreviations:</t>
	  
	<t>
	  <list style="hanging">
	    <t hangText="JWA:">JSON Web Algorithms<xref target="RFC7518"/></t>
	    <t hangText="JWT:">JSON Web Token<xref target="RFC7519"/></t>
	    <t hangText="JWS:">JSON Web Signature<xref target="RFC7515"/></t>	    
	    <t hangText="JWK:">JSON Web Key<xref target="RFC7517"/></t>
	    <t hangText="JWE:">JSON Web Encryption<xref target="RFC7516"/></t>
	    <t hangText="CWT:">CBOR Web Token<xref target="RFC8392"/></t>
		<t hangText="COSE:">CBOR Object Signing and Encryption<xref target="RFC8152"/></t>
	  </list> 	  
	</t>
	   
</section> <!-- Terminology --> 
	  
<!-- ************************************************************************************** --> 

   <section title="Processing Instructions">

    <t><list style="empty">
	 
    <t>Step (0): As an initial step the client typically determines the resource server it wants to interact with. This may, for example, happen as part of a discovery procedure or via manual configuration.</t>
	 
    <t>Step (1): The client starts the OAuth 2.0 protocol interaction based on the selected grant type. </t>
	  
    <t>Step (2): When the client interacts with the token endpoint to obtain an access token it MUST follow the processing steps for the HTTPS-based transport described in Section 5.6.1 of <xref target="I-D.ietf-ace-oauth-authz"/>. This includes determining whether to use the 'aud' and the 'cnf' parameters. </t>
     
    <t>Step (3): The authorization server parses the request from the server and determines the suitable response based on the description in Section 5.6.2 of <xref target="I-D.ietf-ace-oauth-authz"/>. In case of an error the procedure in Section 5.6.3 of <xref target="I-D.ietf-ace-oauth-authz"/> is applicable. </t>
	       
   </list></t>
	 
    <t> Note that PoP access tokens may be encoded in a variety of ways. In case the access token is encoded using the JSON Web Token (JWT) format <xref target="RFC7519"/> it MUST be protected against modification by either using a digital signature or a keyed message digest, as described in <xref target="RFC7515"/>. The JWT may also be encrypted using <xref target="RFC7516"/>. <xref target="RFC8392"/> defines an alternative token format based on CBOR. The proof-of-possession token functionality is defined in <xref target="I-D.ietf-ace-cwt-proof-of-possession"/>. Finally, access tokens can also be passed by reference, which then requires the token introspection endpoint (or a similiar, proprietary protocol mechanism) to be used. This specification does not mandate a specific PoP token format.</t>

	 
	 <t>Subsequent steps for the interaction between the client and the resource server are beyond the scope of this document.</t> 
	
   </section> <!-- Processing Instructions -->
   
<!-- ************************************************************************************** --> 

   <section title="Examples"> 
  
<t>This section provides a number of examples.</t> 
  
   <section anchor="symmetric" title="Symmetric Key Transport"> 
   
   <section title="Client-to-AS Request">
  
  <t>The client starts with a request to the authorization server indicating that it is interested to obtain 
   a token for example-server.</t> 

   <t>
          <figure title="Example Request to the Authorization Server">
            <artwork>
              <![CDATA[
     POST /token HTTP/1.1
     Host: server.example.com
     Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
     Content-Type: application/x-www-form-urlencoded;charset=UTF-8

     grant_type=authorization_code
     &code=SplxlOBeZQQYbYS6WxSbIA
     &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb
     &aud=example-server
]]>
          </artwork>
        </figure>
      </t>
    
    </section>
    
    <section title="Client-to-AS Response"> 
    
      <t>If the access token request has been successfully verified by the authorization server and the client is authorized to obtain a PoP token for the indicated resource server, the
   authorization server issues an access token and optionally a refresh
   token.</t>

   <t><xref target="symmetric-response"/> shows a response containing a token and a "cnf" parameter
   with a symmetric proof-of-possession key. </t> 
   
        <t>
        <figure title="Example: Response from the Authorization Server (Symmetric Variant)" anchor="symmetric-response">
          <artwork>
            <![CDATA[
  HTTP/1.1 200 OK
  Content-Type: application/json
  Cache-Control: no-store

  {
    "access_token":"SlAV32hkKG ... 
     (remainder of JWT omitted for brevity;
     JWT contains JWK in the cnf claim)",
    "token_type":"pop",
    "expires_in":3600,
    "refresh_token":"8xLOxBtZp8",
    "cnf":{
       "keys" : {
         "kty" : "Symmetric",
         "kid" : b64'39Gqlw',
         "k" : b64'hJtXhkV8FJG+Onbc6mxCcQh'
       }
    }
  }
]]>
</artwork>
</figure>
</t>

<t>Note that the cnf payload in <xref target="symmetric-response"/> is not encrypted at the application layer since Transport Layer Security is used between the AS and the client and the content of the cnf payload is consumed by the client itself. Alternatively, a JWE could be used to encrypt the key distribution, as shown in <xref target="key-encryption"/>.
</t>
        <t>
        <figure title="Example: Encrypted Symmmetric Key" anchor="key-encryption">
          <artwork>
            <![CDATA[
  {
    "access_token":"SlAV32hkKG ... 
     (remainder of JWT omitted for brevity;
     JWT contains JWK in the cnf claim)",
    "token_type":"pop",
    "expires_in":3600,
    "refresh_token":"8xLOxBtZp8",
    "cnf":{
        "jwe":
          "eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhDQkMtSFMyNTYifQ.
          (remainder of JWE omitted for brevity)"
        }
    }
  }
]]>
</artwork>
</figure>
</t>

<t>
The content of the key parameter, which is a JWK in our example, is shown in <xref target="symmetric-JWK"/>.</t>

<t>
 <figure title="Example: Key Transport to Client via a JWK" anchor="symmetric-JWK">
 <artwork>
 <![CDATA[
  {
   "kty":"oct",
   "kid":"id123",
   "alg":"HS256",
   "k":"ZoRSOrFzN_FzUA5XKMYoVHyzff5oRJxl-IXRtztJ6uE"
  }
]]>
</artwork>
</figure>
</t>

<t>The content of the 'access_token' in JWT format contains 
  the 'cnf' (confirmation) claim, as shown in <xref target="symmetric-JWT"/>. The confirmation claim is defined in <xref target="RFC7800"/>. 
  The digital signature or the 
  keyed message digest offering integrity protection
  is not shown in this example but has to be present in a real deployment to mitigate a number of security threats.</t>

<t>The JWK in the key element of the response from the authorization server, as shown in <xref target="symmetric-response"/>, contains 
  the same session key as the JWK inside the access token, as shown in <xref target="symmetric-JWT"/>. It is, in this example, protected 
  by TLS and transmitted from the authorization server to the client (for processing by the client).</t>

 <t>
 <figure title="Example: Access Token in JWT Format" anchor="symmetric-JWT">
 <artwork>
 <![CDATA[
   {
      "iss": "https://server.example.com",
      "sub": "24400320",
      "aud": "s6BhdRkqt3",
      "nonce": "n-0S6_WzA2Mj",
      "exp": 1311281970,
      "iat": 1311280970,
      "cnf":{
        "jwk":
          "JDLUhTMjU2IiwiY3R5Ijoi ...
           (remainder of JWK protected by JWE omitted for brevity)"
        }
   }
]]>
</artwork>
</figure>
</t>

<t>Note: When the JWK inside the access token contains a symmetric key it 
  must be confidentiality protected using a JWE to maintain the security goals of 
  the PoP architecture, as described in <xref target="I-D.ietf-oauth-pop-architecture"/>
since content is meant for consumption by the selected resource server only.</t>
    
<t>Note: This document does not impose requirements on the encoding of the access token. 
The examples used in this document make use of the JWT structure but the CWT format is an equally appropriate format to use.</t>

<t>If the access token is only a reference then a look-up by 
  the resource server is needed, as described in the token introspection specification <xref target="RFC7662"/>. </t>

</section> 

   </section> 
   
<!-- ====================================================================== -->

   <section anchor="asymmetric" title="Asymmetric Key Transport"> 
   
   
    <section title="Client-to-AS Request"> 
   <t>This example illustrates the case where an asymmetric key shall be bound to an access token. The client makes the following HTTPS request shown in <xref target="asymmetric-example"/>. Extra line breaks are for display purposes only.
   </t>
   
   <t>
   <figure anchor="asymmetric-example" title="Example Request to the Authorization Server (Asymmetric Key Variant)">
   <artwork>
   <![CDATA[
     POST /token HTTP/1.1
     Host: server.example.com
     Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
     Content-Type: application/x-www-form-urlencoded;charset=UTF-8

     grant_type=authorization_code
     &code=SplxlOBeZQQYbYS6WxSbIA
     &redirect_uri=https%3A%2F%2Fclient%2Eexample%2Ecom%2Fcb
     &token_type=pop
     &cnf=eyJhbGciOiJSU0ExXzUi ...
     (remainder of JWK omitted for brevity)
   ]]></artwork>
   </figure>
   </t>
 
   <t>As shown in <xref target="asymmetric-pk"/> the content of the 'cnf' parameter contains the ECC public key 
   the client would like to associate with the access token.</t>
   
   <t>
   <figure anchor="asymmetric-pk" title="Client Providing Public Key to Authorization Server">
   <artwork>
   <![CDATA[    
        "jwk":{
          "kty": "EC",
          "use": "sig",
          "crv": "P-256",
          "x": "18wHLeIgW9wVN6VD1Txgpqy2LszYkMf6J8njVAibvhM",
          "y": "-V4dS4UaLMgP_4fY4j8ir7cl1TXlFdAgcx55o7TkcSA"
         }
   ]]></artwork>
   </figure>
   </t>

   </section> 
   
   <section title="Client-to-AS Response"> 
          
   <t>If the access token request is valid and authorized, the
   authorization server issues an access token and optionally a refresh
   token. The authorization server also places information 
   about the public key used by the client into the access token to create the 
   binding between the two. The new token type "public_key" is placed into the 'token_type' parameter. </t>

   <t>An example of a successful response is shown in <xref target="asymmetric-response"/>.</t>
   
   <t>
   <figure title="Example: Response from the Authorization Server (Asymmetric Variant)" anchor="asymmetric-response">
   <artwork>
   <![CDATA[
     HTTP/1.1 200 OK
     Content-Type: application/json;charset=UTF-8
     Cache-Control: no-store
     Pragma: no-cache

     {
       "access_token":"2YotnFZFE....jr1zCsicMWpAA",
       "token_type":"pop",
       "expires_in":3600,
       "refresh_token":"tGzv3JOkF0XG5Qx2TlKWIA"
     }   
    ]]></artwork>
   </figure>
   </t>

   <t>The content of the 'access_token' field contains an encoded
    JWT, as shown in <xref target="asymmetric-access-token"/>. The digital 
    signature covering the access token offering authenticity and integrity protection
    is not shown below (but must be present).</t>

   <t>
   <figure title="Example: Access Token Structure (Asymmetric Variant)" anchor="asymmetric-access-token">
   <artwork>
   <![CDATA[   
    {
      "iss":"xas.example.com",
      "aud":"http://auth.example.com",
      "exp":"1361398824",
      "nbf":"1360189224",
      "cnf":{
         "jwk" : {
           "kty" : "EC",
           "kid" : h'11',
           "crv" : "P-256",
           "x" : b64'usWxHK2PmfnHKwXPS54m0kTcGJ90UiglWiGahtagnv8',
           "y" : b64'IBOL+C3BttVivg+lSreASjpkttcsz+1rb7btKLv8EX4'
         }
       }
     }
    ]]></artwork>
   </figure>
   </t>
     
   <t>Note: In this example there is no need for the authorization server
    to convey further keying material to the client since the client is 
    already in possession of the private key.</t>
   </section> 
   
  </section> 
	   
</section> 
	  
<!-- ====================================================================== -->

<section anchor="SecurityConsiderations" title="Security Considerations">
  
  <t><xref target="I-D.ietf-oauth-pop-architecture"/> describes the architecture for the OAuth 2.0 proof-of-possession security architecture, including use cases, threats, and requirements.
  This requirements describes one solution component of that architecture, namely the mechanism for the client to interact with the authorization server to either obtain a symmetric key from the authorization server, to obtain an asymmetric key pair, or to offer a public key to the authorization. In any case, these keys are then bound to the access token by the authorization server. 
  </t>

   <t>To summarize the main security recommendations: A large range of threats can be mitigated by protecting the contents
   of the access token by using a digital signature or a keyed message digest. 
   Consequently, the token integrity protection MUST be applied 
   to prevent the token from being modified, particularly since it contains a reference to the symmetric key or the asymmetric key.
   If the access token contains the symmetric key (see Section 2.2 of <xref target="RFC7800"/> for a description about how symmetric keys can be securely conveyed within the access token) this symmetric key MUST be encrypted by the authorization server with a long-term key shared with the resource server. </t>

   <t>To deal with token redirect, it is important for the authorization
   server to include the identity of the intended recipient (the
   audience), typically a single resource server (or a list of resource
   servers), in the token. Using a single shared secret with multiple authorization server to simplify key management is 
   NOT RECOMMENDED since the benefit from using the proof-of-possession concept is significantly reduced. </t>

   <t>Token replay is also not possible since an eavesdropper will also have to obtain 
   the corresponding private key or shared secret that is bound to the access token. 
   Nevertheless, it is good practice to limit the lifetime of the access token and therefore the lifetime 
   of associated key.
   </t>
   
   <t>The authorization server MUST offer confidentiality protection for any interactions with the client. 
   This step is extremely important since the client will obtain the session key from the authorization server for use with a specific 
   access token. Not using confidentiality protection exposes this secret (and the access token) to an eavesdropper thereby making the OAuth 2.0 proof-of-possession security model completely insecure. 
   OAuth 2.0 <xref target="RFC6749"/> relies on TLS to offer confidentiality protection and additional protection can be applied using the JWK <xref target="RFC7517"/> offered security mechanism, which would add an additional layer of protection on top of TLS for cases where the keying material is conveyed, for example, to a hardware security module. Which version(s) of TLS ought
   to be implemented will vary over time, and depend on the widespread
   deployment and known security vulnerabilities at the time of
   implementation.  At the time of this writing, TLS version 1.2
   <xref target="RFC5246"/> is the most recent version. The
   client MUST validate the TLS certificate chain when making requests
   to protected resources, including checking the validity of the certificate. 
   </t> 
  
   <t>Similarly to the security recommendations for the bearer token specification <xref target="RFC6750"/> developers MUST ensure that the ephemeral 
   credentials (i.e., the private key or the session key) is not leaked to third parties. An adversary in possession of the ephemeral credentials bound to the access token will be able to impersonate the client. Be aware that this is a real risk with many smart phone app and Web development environments.</t>


 <t>Clients can at any time request a new proof-of-possession capable access token. Using a refresh token to regularly request new access tokens that are bound to fresh and unique keys is important. Keeping the lifetime of the access token short allows the authorization server to use shorter key sizes, which translate to a performance benefit for the client and for the resource server. Shorter keys also lead to shorter messages (particularly with asymmetric keying material).</t> 
   
   <t>When authorization servers bind symmetric keys to access tokens then they SHOULD scope these access tokens to a specific permissions.</t> 

</section> 

<section anchor="iana" title="IANA Considerations">

<t>This document does not require any actions by IANA.</t> 

</section> 

<!-- ====================================================================== -->

    
<section anchor="acks" title="Acknowledgements">
  <t>We would like to thank Chuck Mortimore for his review comments. </t>
</section>


  </middle>

<!-- ====================================================================== -->
  <back>

    <references title="Normative References"> 
      <?rfc include="reference.RFC.2119"?>
      <?rfc include="reference.RFC.6749"?>
      <?rfc include="reference.RFC.3986"?>
      <?rfc include="reference.RFC.5246"?>
      <?rfc include="reference.RFC.7517"?>
      <?rfc include="reference.RFC.7515"?>
      <?rfc include="reference.RFC.7518"?>
      <?rfc include="reference.RFC.7516"?>
      <?rfc include="reference.RFC.7519"?>
      <?rfc include="reference.RFC.7800"?>
      <?rfc include="reference.RFC.7638"?>
      <?rfc include="reference.I-D.ietf-ace-oauth-authz"?>
      <?rfc include="reference.I-D.ietf-ace-cwt-proof-of-possession"?>
      <?rfc include="reference.RFC.8392"?>
      <?rfc include="reference.RFC.8152"?>
	  
    </references> 

    <references title="Informative References"> 
      <?rfc include="reference.RFC.6750"?>
      <?rfc include="reference.RFC.5234"?>
      <?rfc include="reference.RFC.7521"?>
      <?rfc include="reference.RFC.7636"?>
      <?rfc include="reference.RFC.7591"?>
      <?rfc include="reference.I-D.ietf-oauth-pop-architecture"?>
      <?rfc include="reference.RFC.7662"?>
     	  
	  
		<reference anchor="IANA-JWT-CLAIMS">
                <front>
                    <title>JSON Web Token Claims</title>
                    <author>
                        <organization>IANA</organization>
                    </author>

                    <date month="March" day="11" year="2019"/>
                </front>

                <format type="HTML" target="https://www.iana.org/assignments/jwt/jwt.xhtml"/>
        </reference>

	</references>
  
  </back>

</rfc>
