<?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-liu-opentrustprotocol-cbor-00" ipr="trust200902">
  <front>
    <title abbrev="opentrustprotocol-CBOR"> Open Trust Protocol CBOR Encoding</title>

    <author fullname="Dapeng Liu" initials="D." surname="Liu">
      <organization>Alibaba Group</organization>

      <address>
        <postal>
          <street/>

          <city>Beijing</city>

          <code/>

          <region/>

          <country>Beijing</country>
        </postal>

        <phone>+86-1391788933</phone>

        <facsimile/>

        <email>maxpassion@gmail.com</email>
      </address>
    </author>
	
	<author fullname="Qiang Fang" initials="Q." surname="Fang">
      <organization>Alibaba Group</organization>

      <address>
        <postal>
          <street/>

          <city>Beijing</city>

          <code/>

          <region/>

          <country>Beijing</country>
        </postal>

        <phone>+86-15210569677</phone>

        <facsimile/>

        <email>qiangwu.fq@alibaba-inc.com</email>
      </address>
    </author>

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

    <area>Internet Area</area>

    <workgroup/>

    <abstract>
      <t>This document specifies the Open Trust Protocol (OTrP) using RFC 7049
	  Concise Binary Object Representation(CBOR).</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 uses CBOR to encode the operations in OTrP.
     The goal is to improve the efficiency of information transmission in bandwidth-constrained scenarios.
     This document will not change the OTrP entity and the trust model. </t>
	  <t>This document will re-use the TA remote security mechanism as defined in <xref target="draft-pei-opentrustprotocol"></xref>.</t>
		
	<t>This document uses CBOR to encode the contents of JSON data as defined in <xref target="draft-pei-opentrustprotocol"></xref>.</t>
	 <t><xref target="draft-pei-opentrustprotocol"></xref>uses JOSE for JSON content encryption, signatures and Message Authentication Code (MAC) operations.
         This document uses the CBOR Object Encryption and Signing (COSE) standard which does the similar thing for CBOR encoding format.</t>
	 <t>This document uses CDDL as defined in <xref target="draft-greevenbosch-appsawg-cbor-cddl"></xref>to describe the CBOR content defined in this document.</t>
	
	</section>
	<section title="Scenario of using CBOR">

	<t>
        In bandwidth constrained scenario, using JSON/JOSE to encode OTrP message may not efficient. Using CBOR as encoding scheme can improve the transmission efficiency.
        More use cases can be found in <xref target="draft-liu-opentrustprotocol-usecase"></xref>.
    </t>
    </section>

   <section title="OTrP Agent">
   
   <section title="API getTAInformation">
   <t>
      If a new Client Application in the device that hasn't had
      TEE SP AIK public key for the response verification, the
      application can contact TSM first to do GetDeviceState, and TSM
      will return TEE SP AIK public key to the app for this operation to
      proceed.
	  
   </t>
   	
<t>CBOR Message:</t>
 <t>
                <figure>
                  <artwork><![CDATA[
   TAInformationTBS={
   taid          :   tstr,         ;TA Identifier from the input
   tsmid         :   tstr,         ;TSM ID for the Security Domain where this TA resides
   signercert    :   tstr,         ;certificate data of the TA binary application's signer certificate
   signercacerts :   [*cacert],    ;CA certificate data of the TA binary application's signer certificate
   tsmcert       :   bstr,         ;certificate data of the TSM that manages this TA
   tsmcacerts    :   [*cacert]     ;CA certificate data of the TSM that manages this TA
   }
   
   cacert=(
   cacert : bstr
   )
				  
				  ]]></artwork>
                </figure>
  </t>

   
               <t>
                <figure>
                  <artwork><![CDATA[
98(
     [
       / protected / h'<signing algorithm>' /
   {
           "reserved":false,
           \ crit \ 2:[
             "reserved"
           ]
         } / ,
       / unprotected / {},
       / payload / 'the TAInformationTBS CBOR above.',
       / signatures / [
         [
           / protected / h'<signing algorithm>' / {
               \ alg \ 1:-7 \ ECDSA 256 \
             } / ,
           / unprotected / {
             / kid / 4:'11'
           },
           / signature / h'<signature contents signed by TEE SP AIK private key >'
         ]
       ]
     ]
   )

]]></artwork>
                </figure>
              </t>
   
   </section>
   
   
   
   <section title="OTrP Messages using CBOR Encoding">

	<t> When using CBOR as encoding method, the OTrP Protocol is composed of a set of standard CBOR messages
        created by TSM to deliver SD and TA management commands to a device and the device response messages created by
        TEE.
    </t>

       <section title="Request and Response Message Template">

	<t> An OTrP Request message uses the following format:(TBD)
	</t>
	             <t>
                <figure>
                  <artwork><![CDATA[
  {
       "<name>TBSRequest": {
         <request message content>
       }
     }

   A corresponding OTrP Response message will be as follows.

     {
       "<name>TBSResponse": {
         <response message content>
       }
     }

]]></artwork>
                </figure>
              </t>
  

   </section>
   
    <section title="Signed Request and Response Message Structure">
		<t>  A signed request message will generally include only one signature and uses the flattened COSE CBOR Serialization Syntax.
        </t>
<t>
   The following example is a general COSE object:
</t>
	             <t>
                <figure>
                  <artwork><![CDATA[
      COSE_Sign = [
       Headers,
       payload : bstr / nil,
       signatures : [+ COSE_Signature]
   ]
   
      COSE_Signature =  [
       Headers,
       signature : bstr
   ]
   
   COSE_Encrypt = [
       Headers,
       ciphertext : bstr / nil,
       recipients : [+COSE_recipient]
   ]
   
   COSE_recipient = [
       Headers,
       ciphertext : bstr / nil,
       ? recipients : [+COSE_recipient]
   ]

]]></artwork>
                </figure>
              </t>
	
   </section>
    
      
   </section>
   
   <section title="Detailed Messages Specification-8">
     <t> For each message in the following sections all CBOR elements are mandatory if it isn't explicitly indicated as optional.</t>
   
   
   <section title="GetDeviceState-8.1">
		 <section title=" GetDeviceStateRequest message-8.1.1">
	    <t>  This is the first command that a TSM will query a device.
            This command is triggered when a SP's Client Application contacts its TSM to check whether the underlying device is ready for TA operations.
      </t>  
				 <t>
                <figure>
                  <artwork><![CDATA[
   GetDeviceStateTBSRequest={
         ver              :   tstr,     ;1.0
         rid              :   tstr,     ;Unique request ID
         tid              :   tstr,     ;transaction ID
         ocspdat          :   bstr,     ;OCSP stapling data of TSM certificate
         icaocspdat       :   bstr,     ;OCSP stapling data for TSM CA certificates
         supportedsigalgs :   bstr,     ;comma separated signing algorithms
   
   }
]]></artwork>
                </figure>
              </t>
	    <t>The request message consists of the following data elements: </t>
 <t>  ver -   version of the message format </t>
  <t>rid -   a unique request ID generated by the TSM </t>
 <t>  tid -   a unique transaction ID to trace request and response.  This can be from a prior transaction's tid field, and can be used in the subsequent message exchanges in this TSM session.  The combination of rid and tid should be made unique.</t>
 <t>ocspdat -   OCSP stapling data for the TSM certificate.  The TSM provides OCSP data such that a recipient TEE can validate the   validity of the TSM certificate without making its own external OCSP service call.  This is a mandate field.</t>
 <t> icaocspdat -   OCSP stapling data for the intermediate CA certificates of the TSM certificate up to the root.  A TEE side      can cache CA OCSP data such that this value isn't needed in each call.</t>
 <t>supportedsigalgs -   an optional property to list the signing algorithms that TSM is able to support.  A recipient TEE should  choose algorithm in this list to sign its response message if this property is present in a request.</t>
<t>The final request message is COSE signed message of the above raw CBOR data with TSM's certificate.</t>
				 <t>
                <figure>
                  <artwork><![CDATA[
    98(
     [
       / protected / h'',
       / unprotected / {},
       / payload / 'GetDeviceStateTBSRequest CBOR above.',
       / signatures / [
         [
           / protected / h'' / {
               \ alg \ 1:-7 \ ECDSA 256 \
             } / ,
           / unprotected / {
             / kid / 4:'11'
           },
           / signature / h'signature contents signed by TSM private key'
         ]
       ]
     ]
   )
   
]]></artwork>
                </figure>
              </t>
		
		
   </section>
			 <section title=" Request processing requirements at a TEE-8.1.2">
	 <t>  Upon receiving a request message GetDeviceStateRequest at a TEE, the TEE must validate the request: </t>
 <t>1.  Validate CBOR message signing </t>
 <t>2.  Validate that the request TSM certificate is chained to a trusted CA that the TEE embeds as its trust anchor. </t>
     <t> *  Cache the CA OCSP stapling data and certificate revocation check status for other subsequent requests. </t>
     <t> *  A TEE can use its own clock time for the OCSP stapling data validation.</t>
 <t>3. Collect Firmware signed data </t>
 <t> 4.  Collect SD information for the SD owned by this TSM </t>
 
   </section>

				 <section title=" Post Conditions-8.1.4">
		<t>The response message shall be encrypted where the encryption key shall be a symmetric key that is wrapped by TSM's public key.
            COSE_recipient holds the encrypted keys for recipients to encrypt the respond message .</t>
   </section>	
				 <section title=" GetDeviceStateResponse message-8.1.5">
	<t>The message has the following structure. </t>
				 <t>
                <figure>
                  <artwork><![CDATA[
       GetDeviceTEEStateTBSResponse={
         ver              :     1.0,
         status           :     pass/fail,
         rid              :     tstr,        ;the request ID from the request message
         tid              :     tstr,        ;transaction ID
         signerreq        :     true/false   ;whether TSM needs to send signer data again in subsequent messages
         edsi             :     bstr         ;Encrypted CBOR dsi information

   }	
   
]]></artwork>
                </figure>
              </t>
	<t>The Device State Information (DSI) message consists of the following.</t>
				 <t>
                <figure>
                  <artwork><![CDATA[
  dsi={
   tfwdata    :   tfwdata,
   tee        :   tee,
    }
   
   tfwdata={
   tbs     : tstr, ;TFW to be signed data is the tid       
   cert    : bstr, ;TFW certificate
   sigalg  : tstr, ;Signing method
   sig     : Tfw   ;signed data
   }
   
   tee ={
   name      :   tstr,   ; TEE name
   ver       :   tstr,   ;  TEE version
   cert      :   bstr,   ;encoded TEE cert
   cacert    :   bstr,   ;array value of CA certificates up to the root CA
   sdlist    :   sdlist,
   teeaiklist:   teeaiklist,
   }
   
   sdlist ={
   cnt: uint,   ;Number of SD owned by this TSM
   sd : sd
   }
   
   sd=[
   name   :  tstr,    ; SD name
   spid   :  tstr,    ;SP owner ID of this SD
   talist :  talist,
   ]
   
   talist=[
   taid   :  tstr, ;TA application 
   taname :  tstr, ;TA application friendly name optional
   ]
   
   teeaiklist=[*teeaiklist]
   
   teeaiklist=[
   spaik     :   bstr, ; SP AIK public key, BASE64 encoded
   spaiktype :   tstr, ; RSA/ECC
   spid      :   tstr, ; sp id
   ]	
   
]]></artwork>
                </figure>
              </t>	

<t>TBD</t>
		<!-- 
      <t>
	  don't know how to change jwe content to cose encrypted & recipient? jwe as follows:
	  
	  {
       "protected": "<BASE64URL encoding of encryption algorithm header
                      JSON data>",
       "recipients": [
           {
               "header": {
                   "alg": "RSA1_5"
               },
               "encrypted_key": "<encrypted value of CEK>"
           }
       ],
       "iv": "<BASE64URL encoded IV data>",
       "ciphertext": "<Encrypted data over the JSON object of dsi
                       (BASE64URL)>",
       "tag": "<JWE authentication tag (BASE64URL)>"
   }
	  
      </t>
-->

			  
   </section>		
		
				 <section title=" TSM Processing Requirements-8.1.7">
	<t>TBD</t>	
   </section>	
		
	
   </section>
     
	 <section title=" Security Domain Management-8.2">
	 
	 <section title=" CreateSD-8.2.1">
	 <t>This command is typically preceded with GetDeviceState command that has acquired the device information of the target device by the TSM.TSM sends such a command to instruct a TEE to create a new Security Domain for a SP.</t>
		 <section title=" CreateSDRequest Message-8.2.1.1">
		  <t>The request message for CreateSD has the following CBOR format.</t>
		 <t>
                <figure>
                  <artwork><![CDATA[
    CreateSDRequest={
         ver              :     1.0,
         rid              :     tstr,         ;Unique request ID
         tid              :     tstr,         ;Transaction ID
         tee              :     tstr,         ; OCSP stapling data of TSM certificate
         nextdsi          :     true/false,     
         dsihash          :     bstr,         ;hash of DSI returned in the prior query
         content          :     content,      ;his piece of data will beencrypted
      }
   
    content ={
         spid             :     tstr,         ;SP ID value
         sdname           :     tstr,         ;SD name for the domain to be created
         spcert           :     tstr,         ;SP certificate
         tsmid            :     tstr,         ;An identifiable attribute of the TSM certificate
         did              :     bstr,         ;SHA256 hash of the TEE cert
   }
     
]]></artwork>
                </figure>
              </t>
	 <t>Following is the OTrP message template, the full request is signed message over the CreateSDTBSRequest as follows.</t>
		 <t>
                <figure>
                  <artwork><![CDATA[
    98(
     [
       / protected / h'',
       / unprotected / {},
       / payload / 'CreateSDTBSRequest CBOR above.',
       / signatures / [
         [
           / protected / h'a10126' / {
               \ alg \ 1:-7 \ ECDSA 256 \
             } / ,
           / unprotected / {
             / kid / 4:'11'
           },
           / signature / 'signature contents signed by TSM private key'
         ]
       ]
     ]
   )
				  
				  
     
]]></artwork>
                </figure>
              </t>	 

	
   </section>
		 <section title=" Request processing requirements at a TEE-8.2.1.2">
	
	
	
	<t> Upon receiving a request message CreateSDRequest at a TEE,the TEE must validate a request.
        The process of Validate the CBOR request message,Create action,Construct CreateSDResponse
        message,Deliver response message and TSM process are same as described in <xref target="draft-pei-opentrustprotocol"></xref> (8.2.1.2 Request processing requirements at a TEE)</t>

	
	
   </section>
		 <section title="CreateSDResponse Message-8.2.1.3">
	 <t>   The response message for a CreateSDRequest contains the following content.	</t>
	 <t>
                <figure>
                  <artwork><![CDATA[
    CreateSDTBSResponse={
         ver              :     1.0,         ;version
         status           :     bstr,        ;operation result
         rid              :     tstr,        ;Unique request ID
         tid              :     tstr,        ;Transaction ID
         content          :     content,     ;this piece of data will beencrypted
      }
   
    content ={
         reason           :     bstr,        ;failure reason detail
         did              :     bstr,        ;the device id received from the request
         sdname           :     tstr,        ;SD name for the domain to be created
         teespaik         :     bstr,        ;SP certificate
         dsi              :     bstr,        ;Updated TEE state, including all SD owned by this TSM
   }
   
]]></artwork>
                </figure>
              </t>	

		
   </section>  
   
   </section>
   	
	<section title=" UpdateSD-8.2.2">
 		 <section title="UpdateSDRequest Message-8.2.2.1">
             <t>TBD</t>
		
   </section> 	
 		 <section title="Request processing requirements at a TEE-8.2.2.1">
             <t>TBD</t>
		
   </section>
 		 <section title=" UpdateSDResponse Message-8.2.2.3">
             <t>TBD</t>
		
   </section>

   </section>
   
   	<section title="DeleteSD--8.2.3">
 		 <section title=" DeleteSDRequest Message-8.2.3.1">
             <t>TBD</t>
		
   </section>
 		 <section title=" Request processing requirements at a TEE-8.2.3.2">
             <t>TBD</t>
		
   </section>
 		 <section title=" DeleteSDResponse Message-8.2.3.3">
             <t>TBD</t>
		
   </section>

   
   </section>
 	
   </section>
 
     <section title=" Trusted Application Management-8.3">
	 <t>The following three TA management commands will be supported. </t>

   <t> o  InstallTA - provision a TA by TSM </t>

    <t>o  UpdateTA - update a TA by TSM </t>

   <t> o  DeleteTA - remove TA registration information with a SD, remove TA binary from TEE, remove all TA related data in TEE </t>
	 
	 <section title="InstallTA--8.3.1">
	
 		 <section title=" InstallTARequest Message-8.3.1.1">
		<t>The request message for InstallTA has the following format.</t>
			 <t>
                <figure>
                  <artwork><![CDATA[
    InstallTATBSRequest={
         ver              :     1.0,
         rid              :     tstr,         ;Unique request ID
         tid              :     tstr,         ;Transaction ID
         tee              :     tstr,         ; OCSP stapling data of TSM certificate
         nextdsi          :     true/false,     
         dsihash          :     bstr,         ;hash of DSI returned in the prior query
         content          :     content,      ;this piece of data will beencrypted
         encrypted_ta     :     encrypted_ta  ;encrypted_ta
      }
   
    content ={
         tsmid            :     tstr,         ;TSM ID previously assigned to the SD
         spid             :     tstr,         ;SPID value
         sdname           :     tstr,         ;SD name for the domain to install the TA
         spcert           :     bstr,         ;SP certificate
         taid             :     tstr,         ;TA identifier
   }
    
    encrypted_ta={
         key           :   bstr,    ;A 256-bit symmetric key encrypted by TEEspaik public key
         iv            :   bstr,    ;hex of 16 random bytes
         alg           :   tstr,    ;encryption algoritm. AESCBC by default.
         ciphertadata  :   bstr,    ;encrypted TA binary data
         cipherpdata   :   bstr,    ;encrypted TA personalization data
   }
   
]]></artwork>
                </figure>
              </t>

   </section>
 		 <section title="  InstallTAResponse Message-8.3.1.2">
			 <t>
                <figure>
                  <artwork><![CDATA[
    InstallTATBSResponse={
         ver              :     1.0,
         status           :     bstr,         ;operation result
         rid              :     tstr,         ;Unique request ID
         tid              :     tstr,         ;Transaction ID
         content          :     content,      ;this piece of data will be encrypted
      }
   
    content ={
         reason           :     bstr,         ;failure reason detail
         did              :     bstr,         ;the device id received from the request
         dsi              :     tstr,         ;the device id hash
   }
   
]]></artwork>
                </figure>
              </t>
	<t>The InstallTAResponse message: </t>
			 <t>
                <figure>
                  <artwork><![CDATA[
     TBD
				  
   
]]></artwork>
                </figure>
              </t>

			  
   </section>
	
   </section>
	
	   	<section title="UpdateTA--8.3.2">
 		 <section title=" UpdateTARequest Message-8.3.2.1">
             <t>TBD</t>
		
   </section>
 		 <section title=" UpdateTAResponse Message-8.3.2.2">
             <t>TBD</t>

   </section>
	
   </section>
   
   
      	<section title="DeleteTA--8.3.3">
 		 <section title=" DeleteTARequest Message-8.3.3.1">
             <t>TBD</t>
		
   </section>
 		 <section title=" Request processing requirements at a TEE-8.3.3.2">
             <t>TBD</t>

   </section>
 		 <section title=" DeleteTAResponse Message-8.3.3.3">
             <t>TBD</t>
		
   </section>
  
   </section>
  
   
   	   	<section title="UpdateTA--8.3.2">
	
   </section>
    </section>

   </section>
   </section>
   
   
   
 
   
	
  </middle>

  <back>
    <references title="Normative References">
      <?rfc include="reference.RFC.2119"?>
        <reference anchor="draft-pei-opentrustprotocol">
        <front>
          <title>The Open Trust Protocol (OTrP)</title>

          <author fullname="Mingliang Pei">
            <organization/>
          </author>

          <date day="5" month="January" year="2017"/>
        </front>
      </reference>
    </references>

      <references title="Informative References">
          <reference anchor="draft-greevenbosch-appsawg-cbor-cddl">
        <front>
          <title>CBOR data definition language (CDDL): a notational convention to express CBOR data structures</title>

          <author fullname="Christoph Vigano">
            <organization/>
          </author>

          <date day="21" month="September" year="2016"/>
        </front>
      </reference>

          <reference anchor="draft-liu-opentrustprotocol-usecase">
        <front>
          <title> Use case of Open Trust Protocol </title>

          <author fullname="Dapeng Liu">
            <organization/>
          </author>

          <date day="12" month="March" year="2016"/>
        </front>
      </reference>

      </references>
  </back>
</rfc>
