<?xml version="1.0" encoding="us-ascii"?>
  <?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?>
  <!-- generated by https://github.com/cabo/kramdown-rfc2629 version 1.0.30 -->

<!DOCTYPE rfc SYSTEM "rfc2629.dtd" [
<!ENTITY I-D.ietf-cose-msg SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml3/reference.I-D.ietf-cose-msg.xml">
<!ENTITY RFC2119 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.2119.xml">
<!ENTITY I-D.hartke-core-e2e-security-reqs SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml3/reference.I-D.hartke-core-e2e-security-reqs.xml">
<!ENTITY I-D.ietf-ace-oauth-authz SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml3/reference.I-D.ietf-ace-oauth-authz.xml">
<!ENTITY RFC4492 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.4492.xml">
<!ENTITY RFC7228 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7228.xml">
<!ENTITY RFC7252 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.7252.xml">
<!ENTITY RFC5869 SYSTEM "http://xml2rfc.ietf.org/public/rfc/bibxml/reference.RFC.5869.xml">
]>

<?rfc toc="yes"?>
<?rfc sortrefs="yes"?>
<?rfc symrefs="yes"?>

<rfc ipr="trust200902" docName="draft-selander-ace-cose-ecdhe-02" category="std">

  <front>
    <title>Ephemeral Diffie-Hellman Over COSE (EDHOC)</title>

    <author initials="G." surname="Selander" fullname="Goeran Selander">
      <organization>Ericsson AB</organization>
      <address>
        <postal>
          <street>Farogatan 6</street>
          <city>Kista</city>
          <code>SE-16480 Stockholm</code>
          <country>Sweden</country>
        </postal>
        <email>goran.selander@ericsson.com</email>
      </address>
    </author>
    <author initials="J." surname="Mattsson" fullname="John Mattsson">
      <organization>Ericsson AB</organization>
      <address>
        <postal>
          <street>Farogatan 6</street>
          <city>Kista</city>
          <code>SE-16480 Stockholm</code>
          <country>Sweden</country>
        </postal>
        <email>john.mattsson@ericsson.com</email>
      </address>
    </author>
    <author initials="F." surname="Palombini" fullname="Francesca Palombini">
      <organization>Ericsson AB</organization>
      <address>
        <postal>
          <street>Farogatan 6</street>
          <city>Kista</city>
          <code>SE-16480 Stockholm</code>
          <country>Sweden</country>
        </postal>
        <email>francesca.palombini@ericsson.com</email>
      </address>
    </author>

    <date year="2016" month="July" day="07"/>

    <area>Applications</area>
    <workgroup>ACE Working Group</workgroup>
    <keyword>Internet-Draft</keyword>

    <abstract>


<t>This document specifies authenticated Diffie-Hellman key exchange with ephemeral keys, embedded in messages encoded with the CBOR Object Signing and Encryption (COSE) format.</t>



    </abstract>


  </front>

  <middle>


<section anchor="intro" title="Introduction">

<t>Security at the application layer provides an attractive option for protecting Internet of Things (IoT) deployments, for example where transport layer security is not sufficient <xref target="I-D.hartke-core-e2e-security-reqs"/>. IoT devices may be constrained in various ways, including memory, storage, processing capacity, and energy <xref target="RFC7228"/>. A method for protecting individual messages at application layer, suitable for constrained devices, is provided by COSE <xref target="I-D.ietf-cose-msg"/>).</t>

<t>In order for a communication session to provide forward secrecy, the communicating parties can run a Diffie-Hellman (DH) key exchange protocol with ephemeral keys, from which shared key material can be derived. This document specifies authenticated DH protocols using COSE objects for integrity protecting the transport of ephemeral public keys. The DH key exchange messages may be authenticated using either pre-shared keys, raw public keys or X.509 certificates. Authentication is based on credentials established out of band, or from a trusted third party, such as an Authorization Server as specified by <xref target="I-D.ietf-ace-oauth-authz"/>. This document also specifies the derivation of the shared key material.</t>

<t>The DH exchange and the key derivation follow <xref target="SP-800-56a"/> and HKDF <xref target="RFC5869"/>, and make use of the data structures of COSE which are aligned with these standards.</t>

<section anchor="terminology" title="Terminology">

<t>The key words &ldquo;MUST&rdquo;, &ldquo;MUST NOT&rdquo;, &ldquo;REQUIRED&rdquo;, &ldquo;SHALL&rdquo;, &ldquo;SHALL NOT&rdquo;,
&ldquo;SHOULD&rdquo;, &ldquo;SHOULD NOT&rdquo;, &ldquo;RECOMMENDED&rdquo;, &ldquo;MAY&rdquo;, and &ldquo;OPTIONAL&rdquo; in this
document are to be interpreted as described in <xref target="RFC2119"/>. These
words may also appear in this document in lowercase, absent their
normative meanings.</t>

<t>The parties exchanging messages are called &ldquo;party U&rdquo; and &ldquo;party V&rdquo;, and the ECDH ephemeral public keys of U and V are denoted &ldquo;E_U&rdquo; and &ldquo;E_V&rdquo;, respectively, see <xref target="mess-ex"/>. The messages in the authenticated message exchange are called &ldquo;message_1&rdquo; and &ldquo;message_2&rdquo;, see <xref target="mess-ex2"/>.</t>

<t>The keys used to authenticate the key exchange are either symmetric or asymmetric. In case of symmetric, the pre-shared key is denoted &ldquo;PSK&rdquo;. In case of asymmetric, the public keys of U and V are denoted &ldquo;S_U&rdquo; and &ldquo;S_V&rdquo;, respectively.</t>

<t>Most keys used in this document have an associated identifier. The identifiers used in the document are placeholders for values of the identifiers. The following key identifiers/value representations are used in the draft:</t>

<t><list style="symbols">
  <t>kid_eu and kid_ev represent the values of the key identifiers of the ephemeral public keys of U and V, respectively.
  <list style="symbols">
      <t>kid_eu is a sequence number used for replay protection of message_1.</t>
      <t>kid_ev is used to identify the resulting traffic key, as a means for party V to ensure that different U establishing traffic keys using this method have different identifiers.</t>
    </list></t>
  <t>kid_psk represents the value of the key identifier of the pre-shared key between U and V (<xref target="PSK"/>).</t>
  <t>kid_su and kid_sv represent the values of the key identifiers of the static public keys of U and V, respectively (<xref target="RPK"/>).</t>
</list></t>

<t>The key notation is summarized in <xref target="key-notation"/>.</t>

<figure title="Notation of keys and key identifiers." anchor="key-notation"><artwork align="center"><![CDATA[
+------------+-----+---------------------------------------------+
|    Key     | Key |                       Use                   |
| Identifier |     |                                             |
+------------+-----+---------------------------------------------+
|   kid_eu   | E_U | ECDH ephemeral public key of U              |
|   kid_ev   | E_V | ECDH ephemeral public key of V              |
|   kid_psk  | PSK | Pre-shared static symmetric key (Section 3) |
|   kid_su   | S_U | Static public key of U (Section 4)          |
|   kid_sv   | S_V | Static public key of V (Section 4)          |
+------------+-----+---------------------------------------------+
]]></artwork></figure>

</section>
</section>
<section anchor="protocol" title="Protocol Overview">

<t>EDHOC is a 2-pass message exchange of COSE objects. This section gives an overview of the protocol, together with section <xref target="mess-proc"/>, which explains how the messages are processed, while section <xref target="mess-format"/> focuses on the detailed message formats embedded as COSE objects.</t>

<!-- TODO: check previous sentence [FP] -->

<t>The underlying scheme is the Elliptic Curve Cofactor Diffie-Hellman with two ephemeral keys as specified in Section 6.1.2.2 of <xref target="SP-800-56a"/>, see <xref target="mess-ex"/>. U and V exchange their ephemeral public keys E_U, E_V, computes the shared secret and derives the keying material as described in <xref target="SP-800-56a"/>.</t>

<figure title="Diffie-Hellman key exchange and key derivation" anchor="mess-ex"><artwork align="center"><![CDATA[
               Party U                 Party V
                 |                       | 
                 |          E_U          |  
                 +---------------------->|
                 |                       |          
                 |          E_V          |
                 |<----------------------+
                 |                       |
        Shared   |                       |  Shared
        Secret                              Secret
           |                                   |                                             
           | Key Derivation                    | Key Derivation       
           V                                   V     
 Derived Keying Material             Derived Keying Material
                                                     
]]></artwork></figure>

<t>EDHOC makes the following additions to this scheme (see <xref target="mess-ex2"/>):</t>

<t><list style="symbols">
  <t>Negotiation of hash function used with HKDF in the key derivation:
  <list style="symbols">
      <t>U proposes one or more hash functions (expressed as HKDF(s) with different hash algorithms).</t>
      <t>V decides and responds with one function (expressed as HKDF with a particular hash algorithm).</t>
    </list></t>
  <t>Optional nonces (N_U, N_V) contributing to the salt used in the extract phase of HKDF <xref target="RFC5869"/>.</t>
  <t>Negotiation of subsequent traffic crypto algorithm (TCA) to be used between party U and V:
  <list style="symbols">
      <t>U proposes one or more algorithms (TCA(s)).</t>
      <t>V decides and responds with one algorithm (TCA).</t>
    </list></t>
  <t>Authentication, integrity and replay protection of protocol messages
  <list style="symbols">
      <t>Authentication and integrity protection using the COSE format <xref target="I-D.ietf-cose-msg"/>.
      <list style="symbols">
          <t>The MAC/Signature is calculated over the message as defined by COSE.</t>
          <t>Information about keys, message protection algorithm and replay parameter is included in the COSE Header, as specified in the sections below.</t>
        </list></t>
      <t>Authentication may be based on pre-shared keys, raw public keys or X.509 certificates. In the latter case the message contains the public key certificate of the sending endpoints (Cert_U, Cert_V).</t>
    </list></t>
</list></t>

<t>The key exchange messages are called &ldquo;message_1&rdquo; and &ldquo;message_2&rdquo;, see <xref target="mess-ex2"/>.</t>

<figure title="EDHOC Overview. (Optionality indicated by '?'.)" anchor="mess-ex2"><artwork align="center"><![CDATA[
  Party U                                                    Party V
  |                                                                |
  |   Header, HKDF(s), ?N_U, TCA(s), E_U, MAC/Signature, ?Cert_U   |
  +--------------------------------------------------------------> |
  |                            message_1                           |
  |                                                                | 
  |      Header, HKDF, ?N_V, TCA, E_V, MAC/Signature, ?Cert_V      |
  | <--------------------------------------------------------------+
  |                            message_2                           |
  |                                                                |
  |   Shared                                               Shared  |
      Secret                                               Secret
         |                                                   |                                             
         | Key Derivation                    Key Derivation  |       
         V                                                   V     
  traffic_secret_0                                  traffic_secret_0

]]></artwork></figure>

<section anchor="auth" title="Authentication methods">

<t>The EDHOC protocol messages are authenticated based on credentials pre-established between U and V. The parties may have acquired such a credential from the other party out of band or from a trusted third party, such as an Authorization Server as specified in <xref target="I-D.ietf-ace-oauth-authz"/>. The pre-established credentials are either symmetric secret keys or public keys. The public keys may be raw public keys (RPK), or public keys of a Certificate Authority (CA) used as trust anchor for verification of received certificates.</t>

<t><list style="symbols">
  <t>Pre-shared symmetric key (PSK). Each message contains a MAC over the message generated by the sending party using PSK.</t>
  <t>Raw Public Keys (RPK). The pre-established credentials may be static raw public keys of the other party (S_U and S_V, of party U and V, respectively). Each message contain a signature over the message generated by the sending party.</t>
  <t>X.509 Certificates (Cert). The pre-established credentials may also be CA public keys, used to verify received public key certificates. Each message contain the signature over the message, excluding the certificate, generated by the sending party.</t>
</list></t>

</section>
</section>
<section anchor="mess-format" title="Message formatting using COSE">

<t>This section details the format for the objects used. Examples are provided for each object in <xref target="examples"/>.</t>

<section anchor="COSE_key" title="ECDH Public Keys using COSE_Key">

<t>This section defines the formatting of the ephemeral public keys E_U and E_V.</t>

<t>The ECDH ephemeral public key SHALL be formatted as a COSE_Key with the following fields and values (see <xref target="I-D.ietf-cose-msg"/>):</t>

<t><list style="symbols">
  <t>kty: The value SHALL be 2 (Elliptic Curve Keys)</t>
  <t>kid:</t>
  <t>crv: The value of the Curve used. The value 1 SHALL be supported by party V (NIST P-256 a.k.a. secp256r1 <xref target="RFC4492"/>)</t>
  <t>x:</t>
  <t>y: The value SHOULD be boolean.</t>
</list></t>

<t>TODO: Consider replacing P-256 with Curve25519 as mandatory</t>

</section>
<section anchor="p1" title="Payload 1 formatting">

<t>This section defines the formatting of the payload in message_1.</t>

<t>payload_1 is a CBOR array object containing:</t>

<t><list style="symbols">
  <t>HKDFs: the set of proposed algorithms to indicate the key derivation</t>
  <t>N_U: optional nonce for use in salt with HKDF</t>
  <t>TCAs: the set of proposed algorithms to use with the derived secret</t>
  <t>E_U: the ephemeral public key (with &lsquo;kid&rsquo; = kid_eu, which is a sequence number)</t>
</list></t>

<figure><artwork><![CDATA[
   payload_1 = [
       HKDFs : AlgID / [ + AlgID ],
       N_U : nil / bstr,
       TCAs : AlgID / [ + AlgID ],
       E_U : COSE_Key
   ]

   AlgID : int / tstr
]]></artwork></figure>

</section>
<section anchor="p2" title="Payload 2 formatting">

<t>This section defines the formatting of the payload in message_2.</t>

<t>payload_2 is a CBOR array object containing:</t>

<t><list style="symbols">
  <t>HKDF: the agreed key derivation algorithm</t>
  <t>N_V: optional nonce for use in salt with HKDF</t>
  <t>TCA: the agreed traffic crypto algorithm</t>
  <t>E_V: the ephemeral public key (with &lsquo;kid&rsquo; = kid_ev)</t>
</list></t>

<figure><artwork><![CDATA[
   payload_2 = [
       HKDF : int / tstr,
       N_V : nil / bstr,
       TCA : int / tstr,
       E_V : COSE_Key
   ]
]]></artwork></figure>

</section>
<section anchor="PSK" title="Message Formatting with Symmetric Keys">

<t>Parties U and V are assumed to have a pre-shared key, PSK. The value of the key identifier kid_psk SHALL be unique for U and V.</t>

<section anchor="m1-PSK" title="Message 1 with PSK">

<t>In case of PSK, message_1 SHALL have the COSE_Mac0_Tagged structure <xref target="I-D.ietf-cose-msg"/> with the following fields and values:</t>

<t><list style="symbols">
  <t>Header
  <list style="symbols">
      <t>Protected
      <list style="symbols">
          <t>Alg: 4 (HMAC 256/64)</t>
          <t>Kid: kid_psk</t>
        </list></t>
      <t>Unprotected: Empty</t>
    </list></t>
  <t>Payload: payload_1 as defined in <xref target="p1"/></t>
  <t>MAC: As in section 6.3 of <xref target="I-D.ietf-cose-msg"/></t>
</list></t>

</section>
<section anchor="m2-PSK" title="Message 2 with PSK">

<t>In case of PSK, message_2 SHALL have the COSE_Mac0_Tagged structure <xref target="I-D.ietf-cose-msg"/> with the following fields and values:</t>

<t><list style="symbols">
  <t>Header
  <list style="symbols">
      <t>Protected
      <list style="symbols">
          <t>Alg: 4 (HMAC 256/64)</t>
          <t>Kid: kid_psk</t>
        </list></t>
      <t>Unprotected: empty</t>
    </list></t>
  <t>Payload: payload_2 as defined in <xref target="p2"/></t>
  <t>Tag: As in section 6.3 of <xref target="I-D.ietf-cose-msg"/>, including the external_aad in the MAC_structure.</t>
</list></t>

<t>The external authenticated data to use in the MAC_structure of Section 6.3 of <xref target="I-D.ietf-cose-msg"/> is the MAC of message_1.</t>

<t><list style="symbols">
  <t>external_aad: MAC</t>
</list></t>

</section>
<section anchor="kdf-context-with-symmetric-keys" title="KDF Context with Symmetric Keys">

<!---
The client and server SHALL derive "traffic_secret_0" from the information available through the key exchange, as described in this section. The key derivation is identical to Section 7 of I-D.ietf-tls-tls13, using the PSK + ECDHE operational mode and HKDF {{RFC5869}} with SHA-256:

* The Static Secret (SS) SHALL be the pre-shared key 
* The Ephemeral Secret (ES) SHALL be the ECDH shared secret, generated from the ephemeral keys, as specified in section 7.3.3. of I-D.ietf-tls-tls13
* The generic string "TLS 1.3, " in HkdfLabel (Section 7.1) SHALL be replaced by "EDHOC, "
* The handshake_hash is replaced by the exchange_hash = SHA-256(message_1 + message_2), where '+' denotes concatenation of octet strings

The procedure for deriving "traffic_secret_0" in Section 7 in I-D.ietf-tls-tls13 SHALL be followed. The "traffic_secret_0" SHALL be identified by the identifier of the server's ephemeral public key (kid_ev).

{{app-c}} provides an example of how to derive a security context from "traffic_secret_0".
-->
<t>The key derivation is specified in <xref target="key-der"/> using the following context information COSE_KDF_Context for symmetric keys:</t>

<figure><artwork><![CDATA[
COSE_KDF_Context = [
    AlgorithmID : int / tstr,      ; AlgID
    SuppPubInfo : [
        keyDataLength : uint,      ; length
        protected : bstr,          ; zero length bstr
        other : bstr               ; MAC message_1 || MAC message_2
    ],
]
]]></artwork></figure>

</section>
</section>
<section anchor="RPK" title="Message Formatting with Asymmetric Keys">

<t>Parties U and V are assumed to have access to each other&rsquo;s public key.</t>

<t><list style="symbols">
  <t>Party U&rsquo;s public key, S_U, SHALL be uniquely identified at V by kid_su.</t>
  <t>Party V&rsquo;s public key, S_V, SHALL be uniquely identified at U by kid_sv.</t>
</list></t>

<section anchor="m1-RPK" title="Message 1 with RPK">

<t>In case of RPK message_1 SHALL have the COSE_Sign1_Tagged structure <xref target="I-D.ietf-cose-msg"/>, with the following fields and values:</t>

<t><list style="symbols">
  <t>Header
  <list style="symbols">
      <t>protected:
      <list style="symbols">
          <t>alg: -7 (ECDSA 256)</t>
          <t>kid: kid_su</t>
        </list></t>
      <t>unprotected: empty</t>
    </list></t>
  <t>payload: payload_1 as defined in <xref target="p1"/></t>
  <t>signature: computed as in Section 4.4 of {{I-D.ietf-cose-msg}</t>
</list></t>

<!---
  FIXME for version -02: check thread [COSE] FW: New Version Notification for draft-selander-ace-cose-ecdhe-00.txt from 31-03
GS: There may be multiple server RS_V, I think we need an explicit field for kid_sv.
-->

</section>
<section anchor="m2-RPK" title="Message 2 with RPK">

<t>In case of RPK, message_2 SHALL have the COSE_Sign1_Tagged structure <xref target="I-D.ietf-cose-msg"/> with the following fields and values:</t>

<t><list style="symbols">
  <t>Header
  <list style="symbols">
      <t>Protected
      <list style="symbols">
          <t>Alg: -7 (ECDSA 256)</t>
          <t>Kid: kid_sv</t>
        </list></t>
      <t>Unprotected: empty</t>
    </list></t>
  <t>payload: payload_2 as defined in <xref target="p2"/></t>
  <t>signature: computed as in Section 4.4 of {{I-D.ietf-cose-msg}, including the external_aad in the Sig_structure.</t>
</list></t>

<t>The external authenticated data to use in the Sig_structure of Section 4.4 of <xref target="I-D.ietf-cose-msg"/> is the signature in message_1.</t>

<t><list style="symbols">
  <t>external_aad: signature</t>
</list></t>

</section>
<section anchor="m1-Cert" title="Message 1 with Cert">

<t>The case of Certificates is similar to RPK. message_1 SHALL have the COSE_Sign1_Tagged structure <xref target="I-D.ietf-cose-msg"/>, with the same fields and values as <xref target="m1-RPK"/> with the addition of the unprotected header field &ldquo;x5c&rdquo; containing the X.509 certificate of S_U as a byte string.</t>

<t><list style="symbols">
  <t>Header
  <list style="symbols">
      <t>protected:
      <list style="symbols">
          <t>alg: -7 (ECDSA 256)</t>
          <t>kid: kid_su</t>
        </list></t>
      <t>unprotected:
      <list style="symbols">
          <t>x5c: bstr</t>
        </list></t>
    </list></t>
  <t>payload: payload_1 as defined in <xref target="p1"/></t>
  <t>signature: computed as in Section 4.4 of {{I-D.ietf-cose-msg}</t>
</list></t>

</section>
<section anchor="m2-Cert" title="Message 2 with Cert">

<t>message_2 is analogous to message_1. message_2 SHALL have the COSE_Sign1_Tagged structure <xref target="I-D.ietf-cose-msg"/>, with the same fields and values as <xref target="m2-RPK"/> and with the addition of the unprotected header field &ldquo;x5c&rdquo; containing the X.509 certificate of S_V as a byte string.</t>

<t><list style="symbols">
  <t>Header
  <list style="symbols">
      <t>Protected
      <list style="symbols">
          <t>Alg: -7 (ECDSA 256)</t>
          <t>Kid: kid_sv</t>
        </list></t>
      <t>Unprotected:
      <list style="symbols">
          <t>x5c: bstr</t>
        </list></t>
    </list></t>
  <t>payload: payload_2 as defined in <xref target="p2"/></t>
  <t>signature: computed as in Section 4.4 of {{I-D.ietf-cose-msg}, including the external_aad in the Sig_structure.</t>
</list></t>

<t>The external authenticated data to use in the Sig_structure of Section 4.4 of <xref target="I-D.ietf-cose-msg"/> is the signature in message_1.</t>

<t><list style="symbols">
  <t>external_aad: signature</t>
</list></t>

</section>
<section anchor="kdf-context-with-asymmetric-keys" title="KDF Context with Asymmetric Keys">

<!---
The client and server SHALL derive "traffic_secret_0" from the information available through the key exchange, as described in this section. The key derivation is identical to Section 7 of {{I-D.ietf-tls-tls13}}, using the ECDHE operational mode and HKDF {{RFC5869}} with SHA-256:

* The Static Secret (SS) and the Ephemeral Secret (ES) SHALL be the ECDH shared secret, generated from the ephemeral keys, as specified in section 7.3.3. of {{I-D.ietf-tls-tls13}}
* The generic string "TLS 1.3, " in HkdfLabel (Section 7.1) SHALL be replaced by "EDHOC, "
* The handshake_hash is replaced by the exchange_hash = SHA-256(message_1 + message_2), where '+' denotes concatenation of octet strings

The procedure for deriving "traffic_secret_0" in Section 7 in {{I-D.ietf-tls-tls13}} SHALL be followed. The "traffic_secret_0" SHALL be identified with the value of the 'kid' field of the server's ephemeral public key (kid_ev).

{{app-c}} provides an example of how to derive a security context from "traffic_secret_0".
-->

<t>The key derivation is specified in <xref target="key-der"/> using the following context information COSE_KDF_Context for asymmetric keys:</t>

<figure><artwork><![CDATA[
   COSE_KDF_Context = [
       AlgorithmID : int / tstr,      ; AlgID
       SuppPubInfo : [
           keyDataLength : uint,      ; length
           protected : bstr,          ; zero length bstr
           other : bstr               ; signature of message_1 || 
                                        signature of message_2
       ]
   ]
]]></artwork></figure>

</section>
</section>
</section>
<section anchor="mess-proc" title="Message Processing">

<t>Party U and V are assumed to have pre-established credentials as described in <xref target="auth"/>.</t>

<section anchor="u-message1" title="U -&gt; message_1">

<t>Party U processes message_1 for party V as follows:</t>

<t><list style="symbols">
  <t>Party U SHALL generate a fresh ephemeral ECDH key pair as specified in Section 5 of <xref target="SP-800-56a"/> using ECC domain parameters of a curve complying with security policies for communicating with party V.</t>
  <t>The ephemeral public key, E_U, SHALL be formatted as a COSE_key as specified in <xref target="COSE_key"/>.</t>
  <t>The key identifier kid_eu of the ephemeral public key E_U SHALL be a sequence number initiated to 1 and increased by 1 for each message_1 associated to a particular party V.</t>
  <t>Party U SHALL define the parameters and format payload_1 as specified in <xref target="p1"/> complying with the security policies for communicating with party V.</t>
  <t>message_1 SHALL be formatted as a COSE message according to <xref target="I-D.ietf-cose-msg"/> with parameters specified in <xref target="m1-PSK"/> (PSK) , <xref target="m1-RPK"/> (RPK) or <xref target="m1-Cert"/> (Cert). Party U SHALL cache the MAC/Signature value of the request.</t>
  <t>Party U sends message_1 to party V.</t>
</list></t>

</section>
<section anchor="message1-v" title="message_1 -&gt; V">

<t>Party V processes the received message_1 as follows:</t>

<t><list style="symbols">
  <t>If the message contains a certificate, party V SHALL verify the certificate using the pre-established trust anchor and the revocation verification policies relevant for party U. If the verification fails the message is discarded.</t>
  <t>Party V SHALL verify that kid_eu is greater than a counter tracking latest message associated with party U, identified with the sending party key. (The counter is initialized to 0 at first contact with party U.) If kid_eu is less than or equal than the counter, the message is discarded.</t>
  <t>Party V SHALL verify the COSE message as specified in <xref target="I-D.ietf-cose-msg"/> using the key associated to party U, identified by the key identifier kid_psk/kid_su in the message header, or in the verified received certificate. If the MAC/Signature of the received request can be verified, then the counter associated to party U is updated with kid-eu, else the message is discarded.</t>
  <t>Party V SHALL verify that the ECDH curve is compliant with its security policy for communicating with U, or else respond with an error.</t>
  <t>V SHALL select a preferred pair of (HKDF, TCA) out of those proposed by U, compliant with the security policy relevant for party U. If such a pair does not exist, V SHALL stop processing the message and MAY respond with an error, indicating that no common algorithm could be found.</t>
</list></t>

</section>
<section anchor="message2-v" title="message_2 &lt;- V">

<t>Party V composes message_2 for party U as follows:</t>

<t><list style="symbols">
  <t>Party V SHALL generate a fresh ephemeral ECDH key pair as specified in Section 5 of <xref target="SP-800-56a"/> using same curve/ECC domain parameters as used by party U.</t>
  <t>The ephemeral public key, E_V, SHALL be formatted as a COSE_key as specified in <xref target="COSE_key"/>. The key identifier kid_ev SHALL be unique among key identifiers used for traffic keys by party V.</t>
  <t>Party SHALL define the parameters and format payload_2 as specified in <xref target="p2"/> complying with the security policies for communicating with party V.</t>
  <t>message_2 SHALL be formatted as a COSE message according to <xref target="I-D.ietf-cose-msg"/> with parameters specified in <xref target="m2-PSK"/> (PSK) , <xref target="m2-RPK"/> (RPK) or <xref target="m2-Cert"/> (Cert) using the same authentication scheme as in message_1. Note that the MAC/Signature value of the request is included as additional authenticated data of the response.</t>
</list></t>

<t>Party V sends message_2 to party U. Then party V derives the traffic_secret_0 key as specified <xref target="key-der"/>, and labels it with kid_ev.</t>

</section>
<section anchor="u-message2" title="U &lt;- message_2">

<t>Party U processes the received message_2 as follows:</t>

<t><list style="symbols">
  <t>If the message contains a certificate, party V SHALL verify the certificate using the pre-established trust anchor and the revocation verification policies relevant for party U. If the verification fails the message is discarded.</t>
  <t>Party U SHALL verify the received COSE message as defined in <xref target="I-D.ietf-cose-msg"/> using the key associated to the key identifier (kid_psk/kid_su) in the message header, or in the verified received certificate. Note the use of the cached MAC/Signature of the request. If the COSE message cannot be verified, the message is discarded.</t>
  <t>U SHALL verify that the received pair (HKDF, TCA) is one element of those proposed in the request, else stop processing the message.</t>
  <t>If the response is verified, U derives the traffic_secret_0 as specified <xref target="key-der"/>.</t>
</list></t>

</section>
</section>
<section anchor="key-der" title="Key Derivation">

<t>The key derivation is identical to Section 11 of <xref target="I-D.ietf-cose-msg"/>, using HKDF <xref target="RFC5869"/> agreed during the message exchange.</t>

<t><list style="symbols">
  <t>the secret SHALL be the ECDH shared secret as defined in Section 12.4.1 of <xref target="I-D.ietf-cose-msg"/>, where the computed secret is specified in section 5.7.1.2 of <xref target="SP-800-56a"/></t>
  <t>the salt SHALL be B1 XOR B2, where
  <list style="symbols">
      <t>B1 = N_U || 00 .. 0, i.e. the nonce N_U, if present, appended with padded zeros to the size of the hash function; or else just an octet string of zeros</t>
      <t>B2 = 00&hellip; 0 || N_V, i.e. the nonce N_V, if present, prepended with padded zeros to the size of the hash function; or else just an octet string of zeros</t>
      <t>This corresponds to salt = N_U || N_V in the case of each party contributing a nonce of half the size of the salt, but also accommodates for nonces of different sizes.</t>
    </list></t>
  <t>the length SHALL be the length of the key in TCA.</t>
  <t>the context information SHALL be the serialized COSE_KDF_Context defined in the next paragraph.</t>
  <t>the PRF SHALL be the one indicated in HKDF using the Table 18 of <xref target="I-D.ietf-cose-msg"/> (in our examples, -27 corresponds to HMAC with SHA-256)</t>
</list></t>

<t>The context information COSE_KDF_Context is defined as follows:</t>

<t><list style="symbols">
  <t>AlgorithmID SHALL be the algorithm for which the key material will be derived. It&rsquo;s value is AlgID</t>
  <t>PartyUInfo SHALL be empty</t>
  <t>PartyVInfo SHALL be empty</t>
  <t>SuppPubInfo SHALL contain:
  <list style="symbols">
      <t>KeyDataLength SHALL be equal to &lsquo;length&rsquo;</t>
      <t>protected SHALL be a zero length bstr</t>
      <t>other SHALL be the concatenation of the MAC/Signature of message_1 and the MAC/Signature of message_2</t>
    </list></t>
  <t>SuppPrivInfo SHALL be empty</t>
</list></t>

<t>The tags are either MACs (PSK) or the Signatures (RPK, Cert) of the COSE messages.</t>

<figure><artwork><![CDATA[
COSE\_KDF\_Context = [
    AlgorithmID : int / tstr,      ; HKDF
    SuppPubInfo : [
        keyDataLength : uint,      ; length
        protected : bstr,          ; zero length bstr
        other : bstr               ; MAC/Signature message_1 
                                     || MAC/Signature message_2
    ],
]
]]></artwork></figure>

<t>The output from the key derivation is denoted &ldquo;traffic_secret_0&rdquo;.</t>

</section>
<section anchor="sec-cons" title="Security Considerations">

<t>For unauthenticated Diffie-Hellman it is recommended that public information about parties U and V, such as their identifiers, is included in the context information used in the key derivation. In the present case the assumption is that the parties authenticate each other with pre-established credentials, and the tag (MAC/Signature) created with the pre-established credentials is included in the key derivation context.</t>

<t>The referenced processing instructions in <xref target="SP-800-56a"/> must be complied with, including deleting the intermediate computed values along with any ephemeral ECDH secrets after the key derivation is completed.</t>

<t>The choice of key length used in the different algorithms needs to be harmonized, so that right security level is maintained throughout the calculations.</t>

<t>The identifier of the ephemeral key of party U is used for replay protection of U&rsquo;s requests.</t>

<t>With the current protocol, key confirmation of the Diffie-Hellman shared secret/traffic keys is performed when the keys are successfully used. The addition of key confirmation to the protocol is for further study.</t>

<t>TODO: Expand on the security considerations in a future version of the draft</t>

</section>
<section anchor="privacy-considerations" title="Privacy Considerations">

<t>TODO</t>

</section>
<section anchor="iana" title="IANA Considerations">

</section>
<section anchor="acknowledgments" title="Acknowledgments">

<t>The authors wants to thank Ilari Liusvaara, Jim Schaad and Ludwig Seitz for timely review and helpful comments.</t>

</section>


  </middle>

  <back>

    <references title='Normative References'>

&I-D.ietf-cose-msg;
&RFC2119;
<reference anchor="SP-800-56a" target="http://dx.doi.org/10.6028/NIST.SP.800-56Ar2">
  <front>
    <title>Recommendation for Pair-Wise Key Establishment Schemes Using Discrete Logarithm Cryptography</title>
    <author initials="E." surname="Barker" fullname="Elaine Barker">
      <organization></organization>
    </author>
    <author initials="L." surname="Chen" fullname="Lily Chen">
      <organization></organization>
    </author>
    <author initials="A." surname="Roginsky" fullname="Allen Roginsky">
      <organization></organization>
    </author>
    <author initials="M." surname="Smid" fullname="Miles Smid">
      <organization></organization>
    </author>
    <date year="2013" month="May"/>
  </front>
  <seriesInfo name="NIST" value="Special Publication 800-56A"/>
  <format type="PDF" target="http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-56Ar2.pdf"/>
</reference>


    </references>

    <references title='Informative References'>

&I-D.hartke-core-e2e-security-reqs;
&I-D.ietf-ace-oauth-authz;
&RFC4492;
&RFC7228;
&RFC7252;
&RFC5869;


    </references>


<section anchor="examples" title="Examples">

<section anchor="ecdh-public-key" title="ECDH Public Key">

<t>An example of COSE_Key structure, representing an ECDH public key, is given in <xref target="ex-cose-key"/>, using CBOR&rsquo;s diagnostic
notation. In this example, the ephemeral key is identified by a 4 bytes &lsquo;kid&rsquo;.</t>

<figure title="Example of an ECDH public key formatted as a COSE_Key" anchor="ex-cose-key"><artwork><![CDATA[
   / ephemeral / -1:{
               / kty / 1:2,
               / kid / 2:h'78f67901',
               / crv / -1:1,
               / x / -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590b
               bfbf054e1c7b4d91d6280',
               / y / -3:true
             }
]]></artwork></figure>

<t>The equivalent CBOR encoding is:
h&rsquo;a120a50102024478f67901200121582098f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91d628022f5&rsquo;,
which has a size of 51 bytes.</t>

</section>
<section anchor="ex-p1" title="Payload 1">

<t>An example of COSE encoding for payload_1 is given in <xref target="payload1"/>, using CBOR&rsquo;s diagnostic notation. In this example, the size of the identifier of U&rsquo;s ephemeral key, kid_eu, is 1 byte.</t>

<t>The payload_1 is:</t>

<figure title="Example of payload of message_1" anchor="payload1"><artwork><![CDATA[
[
  -27, / HKDFs /
  null, / N_U /
  12, / TCAs /
  h'a120a50102024103200121582098f50a4ff6c05861c8860d13a638ea56c3f5a
  d7590bbfbf054e1c7b4d91d628022f5' / COSE_Key E_U { /
    / ephemeral -1:{ /
    / kty 1:2, /
    / kid 2:h'03', kid_eu /
    / crv -1:1, /
    / x -2:h'98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfb /
    / f054e1c7b4d91d6280', /
    / y -3:true /
    / } /
  / } / 
]
]]></artwork></figure>

<t>The equivalent CBOR encoding of the payload is:
h&rsquo;84381af60c582fa120a50102024103200121582098f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91d628022f5&rsquo;,
which has a size of 54 bytes.</t>

</section>
<section anchor="ex-p2" title="Payload 2">

<t>An example of COSE encoding for message_2 is given in <xref target="payload2"/> using CBOR&rsquo;s diagnostic notation. In this example, kid_ev, the identifier of V&rsquo;s ephemeral public key, is 4 bytes.</t>

<t>The payload is:</t>

<figure title="Example of payload of message_2" anchor="payload2"><artwork><![CDATA[
[
  -27, / HKDF /
  null, / N_V /
  12, / TCA /
  h'a120a5010202442edb61f92001215820acbee6672a28340affce41c721901eb
  d7868231bd1d86e41888a07822214050022f5' / COSE_Key E_V { /
    / ephemeral -1:{ /
    / kty 1:2, /
    / kid 2:h'2edb61f9', kid_ev /
    / crv -1:1, /
    / x -2:h'acbee6672a28340affce41c721901ebd7868231bd1d /
    / 86e41888a078222140500', /
    / y -3:true /
    / } /
  / } / 
]
]]></artwork></figure>

<t>The equivalent CBOR encoding of the payload is:
h&rsquo;84381af60c5832a120a5010202442edb61f92001215820acbee6672a28340affce41c721901ebd7868231bd1d86e41888a07822214050022f5&rsquo;,
which has a size of 57 bytes.</t>

</section>
<section anchor="message-1-with-psk" title="Message 1 with PSK">

<t>An example of COSE encoding for message_1 is given in <xref target="mess1-psk"/> using CBOR&rsquo;s diagnostic notation. In this example, kid_psk, the identifier of PSK is 4 bytes, and the payload is as in <xref target="ex-p1"/>.</t>

<t>The message_1 is:</t>

<figure title="Example of message_1 authenticated with PSK" anchor="mess1-psk"><artwork><![CDATA[
996(
  [
    / protected / h'a201040444e19648b5' / { /
        / alg 1:4, HMAC 256//64 /
        / kid 4:h'e19648b5' kid_psk /
    / } / ,
    / unprotected / {},
    / payload / h'84381af60c582fa120a501020241032001215820
    98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4
    d91d628022f5', / payload_1 /
    / tag / h'e77fe81c66c3b5c0'
  ]
)
]]></artwork></figure>

<t>The equivalent CBOR encoding is:
h&rsquo;d903e48449a201040444e19648b5a0583684381af60c582fa120a50102024103200121582098f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91d628022f548e77fe81c66c3b5c0&rsquo;,
which has a size of 80 bytes.</t>

</section>
<section anchor="message-2-with-psk" title="Message 2 with PSK">

<t>An example of COSE encoding for message_2 is given in <xref target="mess2-psk"/> using CBOR&rsquo;s diagnostic notation. In this example, kid_psk, the identifier of PSK, is 4 bytes, and the payload is as in <xref target="ex-p2"/>.</t>

<t>The message_2 is:</t>

<figure title="Example of message_2 authenticated with PSK" anchor="mess2-psk"><artwork><![CDATA[
996(
  [
    / protected / h'a201040444e19648b5' / { /
        / alg 1:4, HMAC 256//64 /
        / kid 4:h'e19648b5' kid_psk /
      / } / ,
    / unprotected / {},
    / payload / h'84381af60c5832a120a5010202442edb61f92001215820
    acbee6672a28340affce41c721901ebd7868231bd1d86e41888a07822214
    050022f5', / payload_2 /
    / tag / h'6113268ad246f2c9'
  ]
)
]]></artwork></figure>

<t>The equivalent CBOR encoding is:
h&rsquo;d903e48449a201040444e19648b5a0583984381af60c5832a120a5010202442edb61f92001215820acbee6672a28340affce41c721901ebd7868231bd1d86e41888a07822214050022f5486113268ad246f2c9&rsquo;,
which has a size of 83 bytes.</t>

</section>
<section anchor="ex-m1-RPK" title="Message 1 with RPK">

<t>An example of COSE encoding for message_1 is given in <xref target="mess1-rpk"/>, using CBOR&rsquo;s diagnostic notation. In this example, the size of the identifier of the static public key of U, kid_su, is 4 bytes, and the payload is as in <xref target="ex-p1"/>.</t>

<t>The message_1 is:</t>

<figure title="Example of message_1 authenticated with RPK" anchor="mess1-rpk"><artwork><![CDATA[
997(
  [
    / protected / h'a201260444c150d41c' / { /
      / alg  1:-7,  ECDSA 256 /
      / kid  4:h'c150d41c',  kid_c /
      / } / ,
    / unprotected / {},
    / payload / h'84381af60c582fa120a501020241032001215820
    98f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4
    d91d628022f5', / payload_1 /
    / signature / h'eae868ecc1276883766c5dc5ba5b8dca25dab3c2e56a
    51ce5705b793914348e14eea4aee6e0c9f09db4ef3ddeca8f3506cd1a98a8fb64
    327be470355c9657ce0'
  ]
)

]]></artwork></figure>

<t>The equivalent CBOR encoding is:
h&rsquo;d903e58449a201260444c150d41ca0583684381af60c582fa120a50102024103200121582098f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91d628022f55840eae868ecc1276883766c5dc5ba5b8dca25dab3c2e56a51ce5705b793914348e14eea4aee6e0c9f09db4ef3ddeca8f3506cd1a98a8fb64327be470355c9657ce0&rsquo;,
which has a size of 137 bytes.</t>

</section>
<section anchor="ex-m2-RPK" title="Message 2 with RPK">

<t>An example of COSE encoding for Message 2 is given in <xref target="mess2-rpk"/>, using CBOR&rsquo;s diagnostic notation. In this example, the size of the identifier of the public key of V, kid_sv, is 4 bytes, and the payload is as in <xref target="ex-p2"/>.</t>

<t>The external_aad is the signature of message_1:</t>

<figure title="Example of external additional authenticated data" anchor="extaad1-rpk"><artwork><![CDATA[
  / external\_aad / h'eae868ecc1276883766c5dc5ba5b8dca25dab3c2e56a
 51ce5705b793914348e14eea4aee6e0c9f09db4ef3ddeca8f3506cd1a98a8fb64327
 be470355c9657ce0'
]]></artwork></figure>

<t>The message_2 is:</t>

<figure title="Example of message_2 authenticated with RPK." anchor="mess2-rpk"><artwork><![CDATA[
997(
  [
    / protected / h'a2012604447a2af164' / { /
      / alg 1:-7, ECDSA 256 /
      / kid 4:h'7a2af164', kid_sv /
    / } / ,
    / unprotected / {},
    / payload, / h'84381af60c5832a120a5010202442edb61f92001215820acb
    ee6672a28340affce41c721901ebd7868231bd1d86e41888a078222140
    50022f5', / payload_2 /
    / signature / h'2374e27a3d9eeb4f66c5dc5ba5b8dca25dab3c2e56a551ce
    5705b793914348e14eea4aee6e0c9f09db4ef3ddeca8f3506cd1a98a8fb64327
    be470355c9657ce0'
  ]
)
]]></artwork></figure>

<t>The equivalent CBOR encoding is:
h&rsquo;d903e58449a2012604447a2af164a0583984381af60c5832a120a5010202442edb61f92001215820acbee6672a28340affce41c721901ebd7868231bd1d86e41888a07822214050022f558402374e27a3d9eeb4f66c5dc5ba5b8dca25dab3c2e56a551ce5705b793914348e14eea4aee6e0c9f09db4ef3ddeca8f3506cd1a98a8fb64327be470355c9657ce0&rsquo;,
which has a size of 140 bytes.</t>

</section>
<section anchor="ex-m1-Cert" title="Message 1 with Cert">

<t>An example of COSE encoding for message_1 is given in <xref target="mess1-cert"/>, using CBOR&rsquo;s diagnostic notation. In this example, the size of the identifier of the static public key of U, kid_su, is 4 bytes, and the payload is as in <xref target="ex-p1"/>.</t>

<t>The message_1 is:</t>

<figure title="Example of message_1 authenticated with Certificate" anchor="mess1-cert"><artwork><![CDATA[
997(
  [
    / protected / h'a201260444c150d41c' / { /
      / alg 1:-7, ECDSA 256 /
      / kid 4:h'c150d41c', kid_su /
      / } / ,
    / unprotected / {"x5c": certificate-chain},
    / payload / h'84381af60c582fa120a50102024103200121582098f
    50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d9
    1d628022f5', / payload_1 / 
    / signature / h'eae868ecc1276883766c5dc5ba5b8dca25dab3c2e56a       
    51ce5705b793914348e14eea4aee6e0c9f09db4ef3ddeca8f3506cd1a98a8fb64
    327be470355c9657ce0'
  ]
)
]]></artwork></figure>

<t>The equivalent CBOR encoding is:
h&rsquo;d903e58449a201260444c150d41ca163783563 40&hellip; 583684381af60c582fa120a50102024103200121582098f50a4ff6c05861c8860d13a638ea56c3f5ad7590bbfbf054e1c7b4d91d628022f55840eae868ecc1276883766c5dc5ba5b8dca25dab3c2e56a51ce5705b793914348e14eea4aee6e0c9f09db4ef3ddeca8f3506cd1a98a8fb64327be470355c9657ce0&rsquo;,</t>

<t>which has a size of 142 bytes plus the size of the certificate.</t>

</section>
<section anchor="ex-m2-Cert" title="Message 2 with Cert">

<t>An example of COSE encoding for message_2 is given in <xref target="mess2-cert"/>, using CBOR&rsquo;s diagnostic notation. In this example, the size of the identifier of the static public key of U, kid_su, is 4 bytes, and the payload is as in <xref target="ex-p2"/>.</t>

<t>The message_2 is:</t>

<figure title="Example of message_2 authenticated with Certificate." anchor="mess2-cert"><artwork><![CDATA[
997(
  [
    / protected / h'a2012604447a2af164' / { /
      / alg 1:-7, ECDSA 256 /
      / kid 4:h'7a2af164', kid_sv /
    / } / ,
    / unprotected / {"x5c": certificate-chain},
    / payload / h'84381af60c5832a120a5010202442edb61f92001215820
    acbee6672a28340affce41c721901ebd7868231bd1d86e41888a07822214
    050022f5', / payload_2 / 
    / signature / h'2374e27a3d9eeb4f66c5dc5ba5b8dca25dab3c2e56a551ce
    5705b793914348e14eea4aee6e0c9f09db4ef3ddeca8f3506cd1a98a8fb64327
    be470355c9657ce0'
  ]
)
]]></artwork></figure>

<t>The equivalent CBOR encoding is:
h&rsquo;d903e58449a2012604447a2af164a163783563 40&hellip; 583984381af60c5832a120a5010202442edb61f92001215820acbee6672a28340affce41c721901ebd7868231bd1d86e41888a07822214050022f558402374e27a3d9eeb4f66c5dc5ba5b8dca25dab3c2e56a551ce5705b793914348e14eea4aee6e0c9f09db4ef3ddeca8f3506cd1a98a8fb64327be470355c9657ce0&rsquo;,</t>

<t>which has a size of 145 bytes plus the size of the certificate.</t>

</section>
</section>
<section anchor="app-a" title="Implementing EDHOC with CoAP">

<t>The DH key exchange specified in this document can be implemented as a CoAP <xref target="RFC7252"/> message exchange with the CoAP client as party U and the CoAP server as party V. A strawman is sketched here.</t>

<t>The CoAP client makes the following request:</t>

<t><list style="symbols">
  <t>The request method is POST</t>
  <t>Content-Format is &ldquo;application/cose+cbor&rdquo;</t>
  <t>The Uri-Path is &ldquo;edhoc&rdquo;</t>
  <t>The Payload is message_1</t>
</list></t>

<t>The CoAP server performs the verifications of the COSE object as specified in <xref target="I-D.ietf-cose-msg"/>. If successful, then the server provides the following response:</t>

<t><list style="symbols">
  <t>The response Code is 2.04 (Changed)</t>
  <t>The Payload is message_2</t>
</list></t>

<!--

# Integrating EDHOC with ACE # {#app-b}

TODO: Move to ACE-OSCOAP (done)

A pre-requisite for using the DH key exchange protocols in {{PSK}} and {{RPK}} of this document is that some keys are pre-established in client and server. The ACE framework {{I-D.ietf-ace-oauth-authz}} specifies how an authorization server (AS) supports the establishment of keys in client and (resource) server, either a shared secret key or each others' public keys, which is exactly what is required in {{PSK}} and {{RPK}}, respectively. 

The ACE protocol specifies a client making a 'token request' to the AS to retrieve an access token (JWT {{RFC7519}}, or CWT {{I-D.wahlstroem-ace-cbor-web-token}}) containing authorization information about the client regarding a certain resource on a certain server. The client can then transfer the access token to the server in the CoAP payload of the following request:

POST /authz-info

The access token may also contain a shared secret key or the public key of the client, for use by the server. 

In case of symmetric keys, the AS generates this key and protects it for the client and server, after which the protocol in {{PSK}} can start.

In case of asymmetric keys, the ACE framework allows the client to include its public key in the 'token request', which results in the key being included in the access token reaching the server. The server's public key can be assumed to be known to the AS, which can therefore provide also this information to the client in the response to the token request.

The transfer of the access token as defined in {{I-D.ietf-ace-oauth-authz}} can be combined with the execution of EDHOC, for example, by including the access token in the Unprotected of Header of message_1. A dedicated resource could be defined for this combined message exchange, for example: 

POST /authz-info-edhoc

The strawman in {{app-a}} applies also to this case.


# Deriving Security Context for OSCOAP # {#app-c}

TODO: Moved to OSCOAP (done)

In this section we show how to establish security context for OSCOAP {{I-D.selander-ace-object-security}}, using the method specified in this document. 

We assume that "traffic_secret_0" has been established, e.g. as described in {{app-b}} using a DH key exchange specified in this document. OSCOAP requires traffic keying material Client/Server Write Key/IV to be established at client and server, see section 3 of {{I-D.selander-ace-object-security}}. The computation of keying material mimics the traffic key calculation of Section 7.3 in TLS 1.3 I-D.ietf-tls-tls13 using HKDF with SHA-256 and the following parameters:

* Secret = traffic_secret_0
* phase = "application data key expansion"
* purpose = "client write key" / "server write key" / "client write IV" / "server write IV" 
* handshake_context = message_1 + message_2, the concatenation of the exchanged messages
* key_length for key and IV is algorithm specific. 

The first three bullets are identical to TLS 1.3.

With the mandatory OSCOAP algorithm AES-CCM-64-64-128 (see Section 10.2 in {{I-D.ietf-cose-msg}}), key_length for the keys is 128 bits and key_length for the static IVs is 56 bits.

The Context Identifier (Cid) is set to the key identifier of traffic_secret_0 (i.e. kid_ev, using the terminology of {{PSK}} and {{RPK}}).
-->

</section>


  </back>
</rfc>

