<?xml version="1.0" encoding="US-ASCII"?>
<!DOCTYPE rfc SYSTEM "rfc2629.dtd">
<?xml-stylesheet type='text/xsl' href='rfc2629.xslt' ?>
<?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-jpop-03"
     ipr="trust200902">
  <front>
    <title abbrev="JPOP">The OAuth 2.0 Authorization Framework: JWT Pop Token Usage</title>

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

      <address>
        <postal>
          <street>Otemachi Financial City Grand Cube, 1-9-2 Otemachi</street>
          <city>Chiyoda-ku</city>
          <code>100-0004</code>
          <region>Tokyo</region>
          <country>Japan</country>
        </postal>
        <phone>+81-3-5533-2111</phone>
        <email>n-sakimura@nri.co.jp</email>
        <uri>https://nat.sakimura.org/</uri>
      </address>
    </author>
	
    <author fullname="Kepeng Li" initials="K." surname="Li">
      <organization>Alibaba Group</organization>

      <address>
        <email>kepeng.lkp@alibaba-inc.com</email>
      </address>
    </author>
    
    <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>


    <date day="27" month="March" year="2017"/>

    <area>Security Area</area>

    <workgroup>OAuth Working Group</workgroup>

    <keyword>JWT</keyword>
    <keyword>PoP</keyword>
    <keyword>HoK</keyword>
    <keyword>OAuth</keyword>
    <keyword>Draft</keyword>

    <abstract>
      <t>
      This specification describes how to use JWT POP (Jpop) tokens 
      that were obtained through <xref target="POPKD" />
      in HTTP requests to access OAuth 2.0 protected resources.  
      Only the party in possession of a corresponding 
      cryptographic key with the Jpop token can use it to get access to
      the associated resources unlike in the case of the bearer token 
      described in <xref target="RFC6750" /> where any party 
      in posession of the access token can access the resource. 
	  </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>This document specifies the method for the client to use a proof-of-possestion 
      token against a protected resource. The format of such token is 
      defined in section 3 of <xref target="RFC7800" />. 
	  </t>

      <section title="Notational Conventions" anchor="nconv">
        <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
        "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and
        "OPTIONAL" in this document are to be interpreted as described in RFC
        2119 [RFC2119]. </t>

        <t>Unless otherwise noted, all the protocol parameter names and values
        are case sensitive.</t>
      </section>
    </section>

    <section title="Terms and definitions" anchor="tnd">
      <t>For the purpose of this document, the terms defined in <xref
      target="RFC6749"/> and <xref target="RFC7800" /> 
      are used. </t>
    </section>
    
    <section title="JWT POP Token" anchor="Jpopt">
      <t>
      JWT PoP token is a JWS signed JWT whose payload is a JWT Claims Set. 
      The JWT claims set MUST include the following: 
      </t>
      <t><list style="hanging">
         <t hangText="iss">The issuer identifier of the auhtorization server. </t>
         <t hangText="aud">The identifier of the resource server.</t>
         <t hangText="iat">The issuance time of this token.</t>
         <t hangText="exp">The expiry time of this token.</t>
         <t hangText="cnf">The confirmation method. </t>
      </list></t>
      <t>
      Their semantics are defined in <xref target="RFC7519"/> and 
      <xref target="RFC7800"/>. 
      </t> 
        <figure anchor="eg_jpop_at" title="Example of JWT PoP Token.">
          <preamble>Following is an example of such. </preamble>

          <artwork><![CDATA[     {
      "iss": "https://server.example.com",
      "aud": "https://resource.example.org",
      "iat": "1360189224",
      "exp": "1361398868",
      "cnf":{...}
     }]]>      </artwork>

          <postamble></postamble>
        </figure>
     </section>
        
      <section title="Sender Constrained Token" anchor="sct">
        <t>There are several varieties of 
        sender constrained token. Namely: </t>
        <t><list style="numbers">
          <t>DN Constrained Token</t>
          <t>Client ID Constrained Token</t>
        </list></t>
        
        <section title="DN Constrained Token" anchor="dnct">
			<t>DN constrained token is typically used when 
			X.509 client certificate authentication 
			is used at the token endpoint. 
			In this case, the constraint is expressed 
			by including the following member at
			the top level of cnf claim. </t>

		    <t><list style="hanging">
			  <t hangText="dn">The Distinguished Name of the client certificate 
			  as a string that the client used in the authorization request. 
			   </t>
			</list></t>
			<t>
			The authorization server finds the relevant DN 
			from the X.509 client certificate authentication 
			that is performed at the token endpoint. 
			</t>
        
			<figure anchor="eg_cnf_dn" title="Example of DN Constrained JWT.">
			  <preamble> </preamble>

  <artwork><![CDATA[{
	"iss": "https://server.example.com",
	"sub": "joe@example.com",
	"aud": "https://resource.example.org",
	"exp": "1361398824",
	"nbf": "1360189224",
	"cnf":{
	  "dn": "cn=John Doe LLC,dc=client,dc=example,dc=com"
	}
}]]>      </artwork>

			  <postamble></postamble>
			</figure>
		</section>
		<section title="Client ID Constrained Token" anchor="cid_ct">
			<t>The constraint in the Client ID constrained token 
			is expressed by including the following member at
			the top level of cnf claim. 
			</t>
		    <t><list style="hanging">
				<t hangText="cid">The client_id of the client 
				that the client used in the authorization request. 
				The combination of the "iss" of the access token 
				and this value forms  
				a globally unique identifier for the client.
				</t>
			</list></t>
			<t>
			The authorization server finds the client ID 
			from the client ID used in the client authentication 
			at the token endpoint. 
			</t>
		</section>
      </section>
      
      <section title="Key Constrained Token" anchor="kct">
        <t>
        Methods to express key constraints 
        are extensively described in the section 3 of 
        <xref target="RFC7800" />. Such cnf claim is 
        used in the access token described in section 3 
        to form a key constrained token. 
        <xref target="RFC7800" /> defines 4 
        confirmation methods.
        </t>
        <t><list style="hanging">
        	<t hangText="jwk">JSON Web Key Representing a Public Key</t>
        	<t hangText="jwe">Encrypted JSON Web Key</t>
        	<t hangText="jwkt#s256"> <xref target="RFC7638" /> Thumbprint of a JWK using the SHA-256 hash function.</t>
        	<t hangText="x5t#s256"> <xref target="RFC7515" /> X.509 Certificate SHA-256 Thumbprint</t>
        	<t hangText="jku">JWK Set URL</t>
        </list></t>
		
		<t>The client provides the corresponding keys or the pointers 
		to the authorization server as a part of the client configuration. 
		It can be done through out-of-band methods (e.g., developper portal) 
		or through some form of dynamic registration, etc. </t>

        <t>Following is an example of a JWT payload containing a JWK with a raw key. </t>

        <figure anchor="eg_kct" title="Example of a JWK Key Constrained JWT.">
          <preamble> </preamble>

          <artwork><![CDATA[     {
      "iss": "https://server.example.com",
      "sub": "joe@example.com",
      "aud": "https://resource.example.org",
      "exp": "1361398824",
      "nbf": "1360189224",
      "cnf":{
        "jwk":{
          "kty": "EC",
          "use": "sig",
          "crv": "P-256",
          "x": "18wHLeIgW9wVN6VD1Txgpqy2LszYkMf6J8njVAibvhM",
          "y": "-V4dS4UaLMgP_4fY4j8ir7cl1TXlFdAgcx55o7TkcSA"
         }
       }
     }]]>      </artwork>

          <postamble></postamble>
        </figure>
        
        <t>Following is an example of a JWT payload containing a jku URI.</t>

        <figure anchor="jku" title="Example of a jku Constrained JWT.">
          <preamble> </preamble>

          <artwork><![CDATA[     {
      "iss": "https://server.example.com",
      "sub": "joe@example.com",
      "aud": "https://resource.example.org",
      "exp": "1361398824",
      "nbf": "1360189224",
      "cnf":{
        "jku": "https://client.example.com/keys/client123-jwks"
            }
       }]]>
	   </artwork>

          <postamble></postamble>
        </figure>
        
                <t>Following is an example of a JWT payload containing a x5t#s256 Certificate Thumbprint of a x509 certificate. .</t>

        <figure anchor="eg_x5ts256" title="Example of a x5t#s256 Certificate Thumbprint Constrained JWT.">
          <preamble> </preamble>

          <artwork><![CDATA[     {
      "iss": "https://server.example.com",
      "sub": "joe@example.com",
      "aud": "https://resource.example.org",
      "exp": "1361398824",
      "nbf": "1360189224",
      "cnf":{
        "x5t#s256": "w5cK0ebwmCZUYDB2Y5SlESsXE8o9yZg05O89jdNidgI"
            }
       }]]>
	   </artwork>

          <postamble></postamble>
        </figure>

    </section>

    <section title="Resource access method" anchor="resource_access_method">
      <t>The resource server that supports this specification MUST authenticate the
      Client by having it demonstrate that it is the holder of the key associated 
      with the access token being used. The confirmation method 
      can be broadly categorized in two forms. </t>
      
      <t><list style="hanging">
      	<t hangText="Mutual TLS method">A method leveraging on the X.509 client certificate authentication of the TLS connection.
      	cn, x5t#s256, and jku confirmation methods can be used with this access method.
      	 (The JWKS referenced by the jku MUST contain JWK with x5c certificate elements for 
      	 this access method)
      	</t>
      	
      	<t hangText="Signature method">A method leveraging the signature on the nonce. 
      	cid, jku, jwk, jwe, and, jwkt#S256 confirmation methods can be used with this access method.
      	</t>
      </list></t>
      
      <section title="Mutual TLS acess method"> 
      <t><list style="hanging">
      	<t hangText="DN cnf method">Under this method, X.509 client certificate authentication 
      	at the resource endpoint is being leveraged. 
      	The resource endpoint MUST obtain the DN of the client certificate 
      	used for the authentication and MUST verify that the value of the 
      	dn member in the cnf member matches with it. 
      	</t>
      	<t>If it does not match, 
      	the process stops here and the resource access MUST be denied.</t>

      	<t>If it is valid, then the resource server 
      	MUST verify the access token. If it is valid,
      	the resource SHOULD be returned as HTTP response.</t>
      	
      	<t hangText="x5t#s256 cnf method">Under this method, X.509 client certificate authentication 
      	at the resource endpoint is being leveraged. 
      	The resource endpoint MUST obtain the client certificate 
      	used for the authentication and MUST verify that the base64url-encoded SHA-256 thumprint
      	 of the DER encoded X.509 client certificate. 
      	The x5t#s256 member in the cnf member MUST exactly match the calculated thumbprint. 
      	</t>
      	<t>If it does not match, 
      	the process stops here and the resource access MUST be denied.</t>

      	<t>If it is valid, then the resource server 
      	MUST verify the access token. If it is valid,
      	the resource SHOULD be returned as HTTP response.</t>
      	
      	<t hangText="jku cnf method">Under this method, X.509 client certificate authentication 
      	at the resource endpoint is being leveraged. 
      	The resource endpoint MUST obtain the client certificate 
      	used for the authentication and MUST verify that the certificate matches one of the 
      	x5c elements retrieved from the <xref target="RFC7517" />JWKS. 
      	Each x5c element may contain a chain of base64-encoded certificates. The client 
      	certificate MUST only be compared with the last certificate in the chain.
      	</t>
      	<t>If it does not match, 
      	the process stops here and the resource access MUST be denied.</t>

      	<t>If it is valid, then the resource server 
      	MUST verify the access token. If it is valid,
      	the resource SHOULD be returned as HTTP response.</t>
      	</list></t>
      </section>
      
      <section title="Signature method" anchor="jwx_method">
		  <t>For this, the following steps are taken: </t>
		  
		  <t><list style="format STEP%d:" counter="my_count">
		  
			  <t>The client accesses the protected resource and gets an authorization 
			  error as in <xref target="Authz_error" />. With it, the client obtains a nonce.</t>
		  
	  
			  <t>The client prepares 
			  a client nonce, <spanx style="verb">cnonce</spanx>, 
			  and nounce count, <spanx style="verb">nc</spanx> 
			  as defined in section 3.2.2 of <xref target="RFC2617" />. 
			  </t>

			  <t>The client creates JWS compact serialization over the nonce.</t>
		  </list></t>
		  
		  <t>
		  To obtain it, first create a JSON with a name "nonce" and 
		  the value being what was received in the previous step. 
		  The JWS MUST contain a kid header element if the client has more than one signing key 
		  published via JWKS URI e.g., 
		  </t>
		  <figure>
			<artwork><![CDATA[
{
	"nonce":"dcd98b7102dd2f0e8b11d0f600bfb0c093", 
	"nc":"00000001",
	"cnonce":"0a4f113b"
} ]]></artwork>
		  </figure>
		  <t>
		  Then, 
		  <spanx style="verb">jws-on-nonce</spanx> is obtained by creating a 
		  compact serialization of JWS on this JSON. 
		  </t>
		  
		  <t><list style="format STEP%d:" counter="my_count">
			  <t>The client sends the request to the resource server, this time with
			  Authorization Request Header as defined in section 4.2 
			  of <xref target="RFC7235" /> with the credential as follows:
			  </t>
		  </list></t>

		  <figure>
			<artwork><![CDATA[
	credentials      =  "Jpop" jpop-response
	jpop-response    =  at-response "," s-response
	at-response      =  "at" "=" access-token (* As specified by [POPKD] *)
	s-response       =  "s" "=" jws-on-nonce (* Created in the STEP3. *)
	access-token     =  quoted-string
	jws-on-nonce     =  quoted-string
			]]></artwork>
		  </figure>
	  
		  <t>
		  In the following example, the access token and the jws-on-nonce 
		  are represented as access.token.jwt and jws.of.nonce for the sake 
		  of brevity. 
		  </t>
	  
		  <figure anchor="eg_resource_request" title="Example resouce request">
			<artwork><![CDATA[
	GET /resource/1234 HTTP/1.0
	Host: server.example.com
	Authorization: Jpop at="access.token.jwt", s="jws.of.nonce"]]></artwork>

			<postamble/>
		  </figure>

		  <t><list style="format STEP%d:" counter="my_count">
		  <t>The resource server finds the client's public key form the 
		  access token through the methods described in <xref target="RFC7800" />. </t>

		  <t>The resource server MUST verify 
		  the value of <spanx style="verb">s</spanx> of the Authorization
		  header. If it fails, the process stops here and the resource access MUST
		  be denied.</t>

		  <t>The resource server MUST verify the access token. If it is valid,
		  the resource SHOULD be returned as HTTP response.</t>
		  </list></t>
      </section>
    </section>
    
    <section anchor="Authz_error" title="Authorization Error">
          <t>If the client requests the resource without the proper authoization header, 
          the resource server returns a HTTP 401 response with <spanx style="verb">WWW-Authenticate</spanx>
      header as defined in section 4.1 of <xref target="RFC7235" /> with the challenge as follows: 
      </t>
      
      <figure>
        <artwork><![CDATA[
          challenge        =  "Jpop" jpop-challenge
          jpop-challenge   =  "nonce" "=" nonce-value
          nonce-value      =  quoted-string
        ]]></artwork>
      </figure>
      
      <t>Following example depicts what the response would look like. 
      </t>

      <figure anchor="eg_unauthorized" title="Example error response.">
        <artwork><![CDATA[HTTP/1.0 401 Unauthorized
Server: HTTPd/0.9
Date: Wed, 14 March 2017 09:26:53 GMT
WWW-Authenticate: Jpop nonce="dcd98b7102dd2f0e8b11d0f600bfb0c093"]]></artwork>
      </figure>


    </section>

    <section anchor="IANA" title="IANA Considerations">
      <section anchor="jpop_authentication_scheme" title="Jpop Authentication Scheme">
        <t>A new scheme has been registered in the HTTP Authentication Scheme 
        Registry as follows:
        </t>
        <t>Authentication Scheme Name: Jpop</t>
        <t>Reference: Section 3 of this specification</t>
        <t>Notes (optional): The Named Authentication scheme is 
        intended to be used only with OAuth Resource Access, 
        and thus does not support proxy authentication. 
        </t>
      </section>
      <section title="JWT Confirmation Methods" anchor="iana_jcm">
      <t><list style="symbols">
      	<t>Confirmation Method Value: "dn"</t>
      	<t>Confirmation Method Description: DN match with the TLS client auth. </t>
      	<t>Change Controller: IESG</t>
      	<t>Specification Document(s): This document. </t>
      </list></t>
        <t><list style="symbols">   	
      	<t>Confirmation Method Value: "cid"</t>
      	<t>Confirmation Method Description: Client ID Confirmation</t>
      	<t>Change Controller: IESG</t>
      	<t>Specification Document(s): This document. </t>
      </list></t>
      </section>
    </section>

    <section anchor="Security" title="Security Considerations">
    	<section anchor="sec.1" title="Certificate validation">
    		<t>The "dn" JWT confirmation method relies 
    		its security property on the X.509 client 
    		certificate authentication. In particular, 
    		the validity of the certificate needs to be 
    		verified properly. It involves the traversal of 
    		all the certificate chain and the certificate 
    		validation (e.g., with OCSP). </t>
    	</section>
    	<section anchor="sec.key" title="Key protection">
      		<t>The client's secret key must be kept securely. 
      		Otherwise, the notion of PoP breaks down. 
      		</t>
      		<t>It should be noted that JWE confirmation 
      		method is significantly weaker form of the 
      		PoP, as the resource server and the 
      		authorization server can masquerade 
      		as the client. 
      		</t>
      	</section>
      	<section anchor="aud" title="Audiance Restriction">
      		<t>When using the signature method the client must specify to the AS
      		the aud it intends to send the token to, so that it can be included in the AT. 
      		</t>
      		<t>A malicious RS could receive a AT with no aud or a logical audience and then 
      		replay the AT and jws-on-nonce to the actual server.
      		</t>
      		<t>NOTE another approach would be to include the resource in the jws-on-nonce</t>
      	</section>
      	<section anchor="client-registration" title="Dynamic client registration elements">
      		<t>When a AS uses dynamic client registration it may accept software statements 
      		supplied by a federation operator.  Those software statements can contain a 
      		JWKS-URI that is hosted by the federation operator or protected by a certificate 
      		provisioned from a trusted root.  These methods would allow the federation operator 
      		to administratively revoke the keys at the JWKS-URI without requiring the JWKS
      		to contain x5c elements with CA issued certificates and having to have the RS 
      		perform full certificate validation for each request.
      		</t>
      		
      	</section>
    </section>

    <section anchor="Acknowledgements" title="Acknowledgements">
      <t>The authors thank the following people for 
      providing valuable feedback to this document. 
      Nov Matake (YAuth). </t>
    </section>
  </middle>

  <back>
    <references title="Normative References">
      <?rfc include="reference.RFC.2119"?>
      <?rfc include='reference.RFC.2617'?>
      <?rfc include='reference.RFC.6749'?>
      <?rfc include='reference.RFC.6750'?>
      <?rfc include='reference.RFC.7519'?>
	  <?rfc include='reference.RFC.7515'?>
	  <?rfc include='reference.RFC.7517'?>
      <?rfc include='reference.RFC.7235'?>
      <?rfc include='reference.RFC.7800'?>
      <?rfc include='reference.RFC.7638'?>
      <reference anchor="POPKD" target="https://tools.ietf.org/html/draft-ietf-oauth-pop-key-distribution-03">
        <front>
		  <title>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 Limited</organization>
      <address>
        <postal>
          <street></street>
          <city></city>
          <code></code>
          <country>Austria</country>
        </postal>
        <phone></phone>
        <email>Hannes.Tschofenig@gmx.net</email>
        <uri>http://www.tschofenig.priv.at</uri>
      </address>
    </author>

          <date day="2" month="March" year="2017"/>
        </front>
      </reference>
    </references>

    <references title="Informative References">
      <reference anchor="POPA" target="https://tools.ietf.org/html/draft-ietf-oauth-pop-architecture-08">
        <front>
          <title>OAuth 2.0 Proof-of-Possession (PoP) Security
          Architecture</title>

          <author fullname="Phil Hunt et al." initials="P." role="editor"
                  surname="Hunt">
            <organization>Oralce Corporation</organization>
          </author>

          <date day="3" month="March" year="2015"/>
        </front>
      </reference>
      
      <reference anchor="PKCE">
        <front>
		  <title>Proof Key for Code Exchange by OAuth Public Clients</title>
          <author fullname="Nat Sakimura" initials="N." surname="Sakimura">
            <organization>Nomura Research Institute</organization>
          </author>

          <date day="10" month="July" year="2015"/>
        </front>
      </reference>
	  
      <reference anchor="TINTRO">
        <front>
		  <title>OAuth 2.0 Token Introspection</title>
          <author fullname="Justin Richer" initials="J." surname="Richer">
            <organization/>
          </author>

          <date day="3" month="July" year="2015"/>
        </front>
      </reference>
    </references>

    <section title="Document History">
      <t><list style="hanging">
		  <t hangText="-00">Initial Version.</t>

        </list> </t>
    </section>
  </back>
</rfc>
