ACE Working Group G. Selander
Internet-Draft J. Mattsson
Intended status: Standards Track F. Palombini
Expires: March 22, 2019 Ericsson AB
September 18, 2018

Ephemeral Diffie-Hellman Over COSE (EDHOC)
draft-selander-ace-cose-ecdhe-10

Abstract

This document specifies Ephemeral Diffie-Hellman Over COSE (EDHOC), a very compact, and lightweight authenticated Diffie-Hellman key exchange with ephemeral keys that can be used over any layer. EDHOC provides mutual authentication, perfect forward secrecy, and identity protection. EDHOC uses CBOR and COSE, allowing reuse of existing libraries.

Status of This Memo

This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.

Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at https://datatracker.ietf.org/drafts/current/.

Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."

This Internet-Draft will expire on March 22, 2019.

Copyright Notice

Copyright (c) 2018 IETF Trust and the persons identified as the document authors. All rights reserved.

This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (https://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.


Table of Contents

1. Introduction

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 [I-D.hartke-core-e2e-security-reqs] or where the protocol needs to work on a variety of underlying protocols. IoT devices may be constrained in various ways, including memory, storage, processing capacity, and energy [RFC7228]. A method for protecting individual messages at the application layer suitable for constrained devices, is provided by CBOR Object Signing and Encryption (COSE) [RFC8152]), which builds on the Concise Binary Object Representation (CBOR) [I-D.ietf-cbor-7049bis].

In order for a communication session to provide forward secrecy, the communicating parties can run an Elliptic Curve Diffie-Hellman (ECDH) key exchange protocol with ephemeral keys, from which shared key material can be derived. This document specifies Ephemeral Diffie-Hellman Over COSE (EDHOC), a mutually authenticated key exchange protocol providing perfect forward secrecy and identity protection. EDHOC uses CBOR and COSE, allowing reuse of existing libraries. Authentication is based on credentials established out of band, e.g. from a trusted third party, such as an Authorization Server as specified by [I-D.ietf-ace-oauth-authz]. EDHOC supports authentication using pre-shared keys (PSK), raw public keys (RPK), and public key certificates. After successful completion of the EDHOC protocol, application keys and other application specific data can be derived using the EDHOC-Exporter interface. Note that this document focuses on authentication and key establishment: for integration with authorization of resource access, refer to [I-D.ietf-ace-oscore-profile].

EDHOC is designed to work in highly constrained scenarios making it especially suitable for network technologies such as Cellular IoT, 6TiSCH [I-D.ietf-6tisch-dtsecurity-zerotouch-join], and LoRaWAN [LoRa1][LoRa2]. Compared to the TLS 1.3 handshake with ECDH [RFC8446], the number of bytes in EDHOC is less than 1/3 when PSK authentication is used and less than 1/2 when RPK authentication is used, see Appendix E.

The ECDH exchange and the key derivation follow [SIGMA], NIST SP-800-56A [SP-800-56A], and HKDF [RFC5869]. CBOR [I-D.ietf-cbor-7049bis] and COSE [RFC8152] are used to implement these standards.

This paper is organized as follows: Section 2 describes how EDHOC builds on SIGMA-I, Section 3 specifies general properties of EDHOC, including message flow, formatting of the ephemeral public keys, and key derivation, Section 4 specifies EDHOC with asymmetric key authentication, Section 5 specifies EDHOC with symmetric key authentication, Section 6 specifies the EDHOC error message, and Appendix B provides a wealth of test vectors to ease implementation and ensure interoperability.

1.1. Terminology and Requirements Language

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 BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.

The word “encryption” without qualification always refers to authenticated encryption, in practice implemented with an Authenticated Encryption with Additional Data (AEAD) algorithm, see [RFC5116].

This document uses the Concise Data Definition Language (CDDL) [I-D.ietf-cbor-cddl] to express CBOR data structures [I-D.ietf-cbor-7049bis]. The use of the CDDL unwrap operator “~” is extended to unwrapping of byte strings. It is the inverse of “bstr .cbor” that wraps a data item in a bstr, i.e. ~ bstr .cbor T = T. Examples of CBOR and CDDL are provided in Appendix A.1.

2. Background

SIGMA (SIGn-and-MAc) is a family of theoretical protocols with a large number of variants [SIGMA]. Like IKEv2 and TLS 1.3, EDHOC is built on a variant of the SIGMA protocol which provide identity protection of the initiator (SIGMA-I), and like TLS 1.3, EDHOC implements the SIGMA-I variant as Sign-then-MAC. The SIGMA-I protocol using an authenticated encryption algorithm is shown in Figure 1.

Party U                                                 Party V
   |                          X_U                          |
   +------------------------------------------------------>|
   |                                                       |
   |  X_V, AE( K_2; ID_CRED_V, Sig(V; CRED_V, X_U, X_V) )  |
   |<------------------------------------------------------+
   |                                                       |
   |    AE( K_3; ID_CRED_U, Sig(U; CRED_U, X_V, X_U) )     |
   +------------------------------------------------------>|
   |                                                       |

Figure 1: Authenticated encryption variant of the SIGMA-I protocol.

The parties exchanging messages are called “U” and “V”. They exchange identities and ephemeral public keys, compute the shared secret, and derive symmetric application keys.

In order to create a “full-fledged” protocol some additional protocol elements are needed. EDHOC adds:

EDHOC is designed to encrypt and integrity protect as much information as possible, and all symmetric keys are derived using as much previous information as possible. EDHOC is furthermore designed to be as compact and lightweight as possible, in terms of message sizes, processing, and the ability to reuse already existing CBOR and COSE libraries. EDHOC does not put any requirement on the lower layers and can therefore also be used e.g. in environments without IP.

To simplify implementation, the use of CBOR and COSE in EDHOC is summarized in Appendix A.

3. EDHOC Overview

EDHOC consists of three messages (message_1, message_2, message_3) that maps directly to the three messages in SIGMA-I, plus an EDHOC error message. All EDHOC messages consists of a sequence of CBOR encoded data items, where the first data item is an int specifying the message type (MSG_TYPE). The messages may be viewed as a CBOR encoding of an indefinite-length array without the first and last byte, see Appendix A.1.

While EDHOC uses the COSE_Key, COSE_Sign1, and COSE_Encrypt0 structures, only a subset of the parameters are included in the EDHOC messages. After creating EDHOC message_3, Party U can derive symmetric application keys, and application protected data can therefore be sent in parallel with EDHOC message_3. The application may protect data using the negotiated algorithms (AEAD, HKDF, etc.) and the connection identifiers (C_U, C_V). EDHOC may be used with the media type application/edhoc defined in Section 7.

Party U                                                 Party V
   |                                                       |
   | ------------------ EDHOC message_1 -----------------> |
   |                                                       |
   | <----------------- EDHOC message_2 ------------------ |
   |                                                       |
   | ------------------ EDHOC message_3 -----------------> |
   |                                                       |
   | <----------- Application Protected Data ------------> |
   |                                                       |

Figure 2: EDHOC message flow

The EDHOC message exchange may be authenticated using pre-shared keys (PSK), raw public keys (RPK), or public key certificates. EDHOC assumes the existence of mechanisms (certification authority, manual distribution, etc.) for binding identities with authentication keys (public or pre-shared). When a public key infrastructure is used, the identity is included in the certificate and bound to the authentication key by trust in the certification authority. When the credential is manually distributed (PSK, RPK, self-signed certificate), the identity and authentication key is distributed out-of-band and bound together by trust in the distribution method. EDHOC with symmetric key authentication is very similar to EDHOC with asymmetric key authentication, the difference being that information is only MACed, not signed.

EDHOC allows opaque application data (UAD and PAD) to be sent in the EDHOC messages. Unprotected Application Data (UAD_1, UAD_2) may be sent in message_1 and message_2, while Protected Application Data (PAD_3) may be send in message_3.

3.1. Ephemeral Public Keys

The ECDH ephemeral public keys are formatted as a COSE_Key of type EC2 or OKP according to Sections 13.1 and 13.2 of [RFC8152], but only a subset of the parameters are included in the EDHOC messages. The curve X25519 is mandatory to implement. For Elliptic Curve Keys of type EC2, compact representation as per [RFC6090] MAY be used also in the COSE_Key. If the COSE implementation requires an y-coordinate, any of the possible values of the y-coordinate can be used, see Appendix C of [RFC6090]. COSE [RFC8152] always use compact output for Elliptic Curve Keys of type EC2.

3.2. Key Derivation

Key and IV derivation SHALL be performed as specified in Section 11 of [RFC8152] with the following input:

where exchange_hash, in non-CDDL notation, is:

exchange_hash = H( bstr .cborseq [ aad_3, CIPHERTEXT_3 ] )

where H() is the hash function in HKDF_V, which takes a CBOR byte string (bstr) as input and produces a CBOR byte string as output. The use of ‘.cborseq’ is exemplified in Appendix A.1.

We define EDHOC-Key-Derivation to be the function which produces the output as described in [RFC5869] and [RFC8152] depending on the variable input AlgorithmID, keyDataLength, and other:

output = EDHOC-Key-Derivation(AlgorithmID, keyDataLength, other)

For message_i the key, called K_i, SHALL be derived using other = aad_i, where i = 2 or 3. The key SHALL be derived using AlgorithmID set to the integer value of the negotiated AEAD (AEAD_V), and keyDataLength equal to the key length of AEAD_V.

If the AEAD algorithm uses an IV, then IV_i for message_i SHALL be derived using other = aad_i, where i = 2 or 3. The IV SHALL be derived using AlgorithmID = “IV-GENERATION” as specified in Section 12.1.2. of [RFC8152], and keyDataLength equal to the IV length of AEAD_V.

3.2.1. EDHOC-Exporter Interface

Application keys and other application specific data can be derived using the EDHOC-Exporter interface defined as:

EDHOC-Exporter(label, length) = EDHOC-Key-Derivation(label, 8 * length, exchange_hash)

The output of the EDHOC-Exporter function SHALL be derived using other = exchange_hash, AlgorithmID = label, and keyDataLength = 8 * length, where label is a tstr defined by the application and length is a uint defined by the application. The label SHALL be different for each different exporter value. An example use of the EDHOC-Exporter is given in Appendix D.2).

4. EDHOC Authenticated with Asymmetric Keys

4.1. Overview

EDHOC supports authentication with raw public keys (RPK) and public key certificates with the requirements that:

where ID_CRED_x, for x = U or V, is encoded in a COSE map, see Appendix A.2. In the following we give some examples of possible COSE map labels.

Raw public keys are most optimally stored as COSE_Key objects and identified with a ‘kid’ value (see [RFC8152]):

Public key certificates can be identified in different ways, for example (see [I-D.schaad-cose-x509]):

In the latter two examples, ID_CRED_U and ID_CRED_V contains the actual credential used for authentication. ID_CRED_U and ID_CRED_V do not need to uniquely identify the public authentication key, but doing so is recommended as the recipient may otherwise have to try several public keys. ID_CRED_U and ID_CRED_V are transported in the ciphertext, see Section 4.3.2 and Section 4.4.2.

The actual credentials CRED_U and CRED_V (e.g. a COSE_Key or a single X.509 certificate) are signed by party U and V, respectively, see Section 4.4.1 and Section 4.3.1. Party U and Party V MAY use different type of credentials, e.g. one uses RPK and the other uses certificate. Party U and Party V MAY use different signature algorithms.

EDHOC with asymmetric key authentication is illustrated in Figure 3.

Party U                                                          Party V
|                        C_U, X_U, ALG_1, UAD_1                        |
+--------------------------------------------------------------------->|
|                               message_1                              |
|                                                                      |
|C_U, C_V, X_V, ALG_2, AE(K_2; ID_CRED_V, Sig(V; CRED_V, aad_2), UAD_2)|
|<---------------------------------------------------------------------+
|                               message_2                              |
|                                                                      |
|         S_V, AE(K_3; ID_CRED_U, Sig(U; CRED_U, aad_3), PAD_3)        |
+--------------------------------------------------------------------->|
|                               message_3                              |

Figure 3: EDHOC with asymmetric key authentication.

4.1.1. Mandatory to Implement Algorithms

For EDHOC authenticated with asymmetric keys, the COSE algorithms ECDH-SS + HKDF-256, AES-CCM-64-64-128, and Ed25519 are mandatory to implement.

4.2. EDHOC Message 1

4.2.1. Formatting of Message 1

message_1 SHALL be a sequence of CBOR data items (see Appendix A.1) as defined below

message_1 = (
  MSG_TYPE : int,
  C_U : bstr,  
  ECDH-Curves_U : algs,
  ECDH-Curve_U : uint,
  X_U : bstr,
  HKDFs_U : algs,
  AEADs_U : algs,
  SIGs_V : algs,
  SIGs_U : algs,
  ? UAD_1 : bstr
)
alg : int / tstr
algs = alg / [ 2* alg ]

where:

4.2.2. Party U Processing of Message 1

Party U SHALL compose message_1 as follows:

4.2.3. Party V Processing of Message 1

Party V SHALL process message_1 as follows:

If any verification step fails, Party V MUST send an EDHOC error message back, formatted as defined in Section 6, and the protocol MUST be discontinued. If V does not support the curve ECDH-Curve_U, but supports another ECDH curves in ECDH-Curves_U, then ALGs_V MUST include the first supported ECDH curve in ECDH-Curves_U. If V does not support any of the algorithms of one kind (ECDH-Curves_U, HKDFs_U, AEADs_U, SIGs_V, or SIGs_U), then ALGs_V MUST include one or more supported algorithms of that kind.

4.3. EDHOC Message 2

4.3.1. Formatting of Message 2

message_2 SHALL be a sequence of CBOR data items (see Appendix A.1) as defined below

message_2 = (
  data_2,
  CIPHERTEXT_2 : bstr
)
data_2 = (
  MSG_TYPE : int,
  C_U : bstr / nil,
  C_V : bstr,
  X_V : bstr,
  HKDF_V : uint,
  AEAD_V : uint,
  SIG_V : uint,
  SIG_U : uint
)
aad_2 : bstr

where aad_2, in non-CDDL notation, is:

aad_2 = H( bstr .cborseq [ message_1, data_2 ] )

where:

4.3.2. Party V Processing of Message 2

Party V SHALL compose message_2 as follows:

4.3.3. Party U Processing of Message 2

Party U SHALL process message_2 as follows:

If any verification step fails, Party U MUST send an EDHOC error message back, formatted as defined in Section 6, and the protocol MUST be discontinued.

4.4. EDHOC Message 3

4.4.1. Formatting of Message 3

message_3 SHALL be a sequence of CBOR data items (see Appendix A.1) as defined below

message_3 = (
  data_3,
  CIPHERTEXT_3 : bstr
)
data_3 = (
  MSG_TYPE : int,
  C_V : bstr
)
aad_3 : bstr

where aad_3, in non-CDDL notation, is:

aad_3 = H( bstr .cborseq [ aad_2, CIPHERTEXT_2, data_3 ] )

where:

4.4.2. Party U Processing of Message 3

Party U SHALL compose message_3 as follows:

4.4.3. Party V Processing of Message 3

Party V SHALL process message_3 as follows:

If any verification step fails, Party V MUST send an EDHOC error message back, formatted as defined in Section 6, and the protocol MUST be discontinued.

5. EDHOC Authenticated with Symmetric Keys

5.1. Overview

EDHOC supports authentication with pre-shared keys. Party U and V are assumed to have a pre-shared key (PSK) with a good amount of randomness and the requirement that:

KID may optionally contain information about how to retrieve the PSK. KID does not need to uniquely identify the PSK, but doing so is recommended as the recipient may otherwise have to try several PSKs.

EDHOC with symmetric key authentication is illustrated in Figure 4. AEAD(K; P; A) denotes the output from an AEAD algorithm using key K on plaintext P and additional authenticated data A, see [RFC5116].

Party U                                                       Party V
|                    C_U, X_U, ALG_1, KID, UAD_1                    |
+------------------------------------------------------------------>|
|                             message_1                             |
|                                                                   |
|           C_U, C_V, X_V, ALG_2, AEAD(K_2; UAD_2; aad_2)           |
|<------------------------------------------------------------------+
|                             message_2                             |
|                                                                   |
|                    S_V, AEAD(K_3; PAD_3; aad_3)                   |
+------------------------------------------------------------------>|
|                             message_3                             |

Figure 4: EDHOC with symmetric key authentication.

5.1.1. Mandatory to Implement Algorithms

For EDHOC authenticated with symmetric keys, the COSE algorithms ECDH-SS + HKDF-256 and AES-CCM-64-64-128 are mandatory to implement.

5.2. EDHOC Message 1

5.2.1. Formatting of Message 1

message_1 SHALL be a sequence of CBOR data items (see Appendix A.1) as defined below

message_1 = (
  MSG_TYPE : int,
  C_U : bstr,
  ECDH-Curves_U : algs,
  ECDH-Curve_U : uint,
  X_U : bstr,
  HKDFs_U : algs,
  AEADs_U : algs,
  KID : bstr,
  ? UAD_1 : bstr
)
alg : int / tstr
algs = alg / [ 2* alg ]

where:

5.2.2. Party U Processing of Message 1

Party U SHALL compose message_1 as follows:

5.2.3. Party V Processing of Message 1

Party V SHALL process message_1 as follows:

If any verification step fails, Party V MUST send an EDHOC error message back, formatted as defined in Section 6, and the protocol MUST be discontinued. If V does not support the curve ECDH-Curve_U, but supports another ECDH curves in ECDH-Curves_U, then ALGs_V MUST include the first supported ECDH curve in ECDH-Curves_U. If V does not support any of the algorithms of one kind (ECDH-Curves_U, HKDFs_U, AEADs_U), then ALGs_V MUST include one or more supported algorithms of that kind.

5.3. EDHOC Message 2

5.3.1. Formatting of Message 2

message_2 SHALL be a sequence of CBOR data items (see Appendix A.1) as defined below

message_2 = (
  data_2,
  CIPHERTEXT_2 : bstr
)
data_2 = (
  MSG_TYPE : int,
  C_U : bstr / nil,  
  C_V : bstr,  
  X_V : bstr,
  HKDF_V : uint,
  AEAD_V : uint
)
aad_2 : bstr

where aad_2, in non-CDDL notation, is:

aad_2 = H( bstr .cborseq [ message_1, data_2 ] )

where:

5.3.2. Party V Processing of Message 2

Party V SHALL compose message_2 as follows:

5.3.3. Party U Processing of Message 2

Party U SHALL process message_2 as follows:

If any verification step fails, Party U MUST send an EDHOC error message back, formatted as defined in Section 6, and the protocol MUST be discontinued.

5.4. EDHOC Message 3

5.4.1. Formatting of Message 3

message_3 SHALL be a sequence of CBOR data items (see Appendix A.1) as defined below

message_3 = (
  data_3,
  CIPHERTEXT_3 : bstr
)
data_3 = (
  MSG_TYPE : int,
  C_V : bstr 
)
aad_3 : bstr

where aad_3, in non-CDDL notation, is:

aad_3 = H( bstr .cborseq [ aad_2, CIPHERTEXT_2, data_3 ] )

where:

5.4.2. Party U Processing of Message 3

Party U SHALL compose message_3 as follows:

5.4.3. Party V Processing of Message 3

Party V SHALL process message_3 as follows:

If any verification step fails, Party V MUST send an EDHOC error message back, formatted as defined in Section 6, and the protocol MUST be discontinued.

6. Error Handling

6.1. EDHOC Error Message

This section defines a message format for the EDHOC error message, used during the protocol. An EDHOC error message can be send by both parties as a response to any non-error EDHOC message. After sending an error message, the protocol MUST be discontinued. Errors at the EDHOC layer are sent as normal successful messages in the lower layers (e.g. POST and 2.04 Changed). An advantage of using such a construction is to avoid issues created by usage of cross protocol proxies (e.g. UDP to TCP).

error SHALL be a sequence of CBOR data items (see Appendix A.1) as defined below

error = (
  MSG_TYPE : int,
  ERR_MSG : tstr,
  ? ALGs_V: algs
)
alg : int / tstr
algs = alg / [ 2* alg ]

where:

7. IANA Considerations

7.1. The Well-Known URI Registry

IANA has added the well-known URI ‘edhoc’ to the Well-Known URIs registry.

7.2. Media Types Registry

IANA has added the media type ‘application/edhoc’ to the Media Types registry.

7.3. CoAP Content-Formats Registry

IANA has added the media type ‘application/edhoc’ to the CoAP Content-Formats registry.

8. Security Considerations

8.1. Security Properties

EDHOC inherits its security properties from the theoretical SIGMA-I protocol [SIGMA]. Using the terminology from [SIGMA], EDHOC provides perfect forward secrecy, mutual authentication with aliveness, consistency, peer awareness, and identity protection. As described in [SIGMA], peer awareness is provided to Party V, but not to Party U.

EDHOC with asymmetric authentication offers identity protection of Party U against active attacks and identity protection of Party V against passive attacks. The roles should be assigned to protect the most sensitive identity, typically the one that is not derivable from routing information in the lower layers.

Compared to [SIGMA], EDHOC adds an explicit message type and expands the message authentication coverage to additional elements such as algorithms, application data, and previous messages. This protects against an attacker replaying messages or injecting messages from another session.

EDHOC also adds negotiation of connection identifiers and downgrade protected negotiation of cryptographic parameters, i.e. an attacker cannot affect the negotiated parameters. A single session of EDHOC does not include negotiation of parameters related to the ephemeral key, but it enables Party V to verify that the ECDH curve used in the protocol is the most preferred curve by U which is supported by both U and V.

8.2. Cryptographic Considerations

The security of the SIGMA protocol requires the MAC to be bound to the identity of the signer. Hence the message authenticating functionality of the authenticated encryption in EDHOC is critical: authenticated encryption MUST NOT be replaced by plain encryption only, even if authentication is provided at another level or through a different mechanism. EDHOC implements SIGMA-I using the same Sign-then-MAC approach as TLS 1.3.

To reduce message overhead EDHOC does not use explicit nonces and instead rely on the ephemeral public keys to provide randomness to each session. A good amount of randomness is important for the key generation, to provide aliveness, and to protect against interleaving attacks. For this reason, the ephemeral keys MUST NOT be reused, and both parties SHALL generate fresh random ephemeral key pairs.

The choice of key length used in the different algorithms needs to be harmonized, so that a sufficient security level is maintained for certificates, EDHOC, and the protection of application data. Party U and V should enforce a minimum security level.

The data rates in many IoT deployments are very limited. Given that the application keys are protected as well as the long-term authentication keys they can often be used for years or even decades before the cryptographic limits are reached. If the application keys established through EDHOC need to be renewed, the communicating parties can derive application keys with other labels or run EDHOC again.

8.3. Unprotected Data

Party U and V must make sure that unprotected data and metadata do not reveal any sensitive information. This also applies for encrypted data sent to an unauthenticated party. In particular, it applies to UAD_1, ID_CRED_V, UAD_2, and ERR_MSG in the asymmetric case, and KID, UAD_1, and ERR_MSG in the symmetric case. Using the same KID or UAD_1 in several EDHOC sessions allows passive eavesdroppers to correlate the different sessions. The communicating parties may therefore anonymize KID. Another consideration is that the list of supported algorithms may be used to identify the application.

Party U and V must also make sure that unauthenticated data does not trigger any harmful actions. In particular, this applies to UAD_1 and ERR_MSG in the asymmetric case, and KID, UAD_1, and ERR_MSG in the symmetric case.

8.4. Denial-of-Service

EDHOC itself does not provide countermeasures against Denial-of-Service attacks. By sending a number of new or replayed message_1 an attacker may cause Party V to allocate state, perform cryptographic operations, and amplify messages. To mitigate such attacks, an implementation SHOULD rely on lower layer mechanisms such as the Echo option in CoAP [I-D.ietf-core-echo-request-tag] that forces the initiator to demonstrate reachability at their apparent network address.

8.5. Implementation Considerations

The availability of a secure pseudorandom number generator and truly random seeds are essential for the security of EDHOC. If no true random number generator is available, a truly random seed must be provided from an external source. If ECDSA is supported, “deterministic ECDSA” as specified in RFC6979 is RECOMMENDED.

The referenced processing instructions in [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. The ECDH shared secret, keys (K_2, K_3), and IVs (IV_2, IV_3) MUST be secret. Implementations should provide countermeasures to side-channel attacks such as timing attacks.

Party U and V are responsible for verifying the integrity of certificates. The selection of trusted CAs should be done very carefully and certificate revocation should be supported. The private authentication keys MUST be kept secret.

Party U and V are allowed to select the connection identifiers C_U and C_V, respectively, for the other party to use in the ongoing EDHOC protocol as well as in a subsequent application protocol (e.g. OSCORE [I-D.ietf-core-object-security]). The choice of connection identifier is not security critical in EDHOC but intended to simplify the retrieval of the right security context in combination with using short identifiers. If the wrong connection identifier of the other party is used in a protocol message it will result in the receiving party not being able to retrieve a security context (which will terminate the protocol) or retrieve the wrong security context (which also terminates the protocol as the message cannot be verified).

8.6. Other Documents Referencing EDHOC

EDHOC has been analyzed in several other documents. An analysis of EDHOC for certificate enrollment was done in [CertEnr], the use of EDHOC in LoRaWAN is analyzed in [LoRa1] and [LoRa2], and the use of EDHOC in 6TiSCH is described in [I-D.ietf-6tisch-dtsecurity-zerotouch-join].

9. References

9.1. Normative References

[I-D.ietf-cbor-7049bis] Bormann, C. and P. Hoffman, "Concise Binary Object Representation (CBOR)", Internet-Draft draft-ietf-cbor-7049bis-02, March 2018.
[I-D.ietf-cbor-cddl] Birkholz, H., Vigano, C. and C. Bormann, "Concise data definition language (CDDL): a notational convention to express CBOR and JSON data structures", Internet-Draft draft-ietf-cbor-cddl-05, August 2018.
[I-D.ietf-core-echo-request-tag] Amsuess, C., Mattsson, J. and G. Selander, "Echo and Request-Tag", Internet-Draft draft-ietf-core-echo-request-tag-02, June 2018.
[I-D.ietf-core-object-security] Selander, G., Mattsson, J., Palombini, F. and L. Seitz, "Object Security for Constrained RESTful Environments (OSCORE)", Internet-Draft draft-ietf-core-object-security-15, August 2018.
[I-D.schaad-cose-x509] Schaad, J., "CBOR Object Signing and Encryption (COSE): Headers for carrying and referencing X.509 certificates", Internet-Draft draft-schaad-cose-x509-02, July 2018.
[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997.
[RFC5116] McGrew, D., "An Interface and Algorithms for Authenticated Encryption", RFC 5116, DOI 10.17487/RFC5116, January 2008.
[RFC5869] Krawczyk, H. and P. Eronen, "HMAC-based Extract-and-Expand Key Derivation Function (HKDF)", RFC 5869, DOI 10.17487/RFC5869, May 2010.
[RFC6090] McGrew, D., Igoe, K. and M. Salter, "Fundamental Elliptic Curve Cryptography Algorithms", RFC 6090, DOI 10.17487/RFC6090, February 2011.
[RFC7252] Shelby, Z., Hartke, K. and C. Bormann, "The Constrained Application Protocol (CoAP)", RFC 7252, DOI 10.17487/RFC7252, June 2014.
[RFC8152] Schaad, J., "CBOR Object Signing and Encryption (COSE)", RFC 8152, DOI 10.17487/RFC8152, July 2017.
[RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, May 2017.
[SIGMA] Krawczyk, H., "SIGMA - The 'SIGn-and-MAc' Approach to Authenticated Diffie-Hellman and Its Use in the IKE-Protocols (Long version)", June 2003.
[SP-800-56A] Barker, E., Chen, L., Roginsky, A., Vassilev, A. and R. Davis, "Recommendation for Pair-Wise Key-Establishment Schemes Using Discrete Logarithm Cryptography", NIST Special Publication 800-56A Revision 3, April 2018.

9.2. Informative References

[CborMe] Bormann, C., "CBOR Playground", May 2018.
[CertEnr] Krontiris, A., "Evaluation of Certificate Enrollment over Application Layer Security", May 2018.
[I-D.hartke-core-e2e-security-reqs] Selander, G., Palombini, F. and K. Hartke, "Requirements for CoAP End-To-End Security", Internet-Draft draft-hartke-core-e2e-security-reqs-03, July 2017.
[I-D.ietf-6tisch-dtsecurity-zerotouch-join] Richardson, M. and B. Damm, "6tisch Zero-Touch Secure Join protocol", Internet-Draft draft-ietf-6tisch-dtsecurity-zerotouch-join-02, April 2018.
[I-D.ietf-ace-oauth-authz] Seitz, L., Selander, G., Wahlstroem, E., Erdtman, S. and H. Tschofenig, "Authentication and Authorization for Constrained Environments (ACE) using the OAuth 2.0 Framework (ACE-OAuth)", Internet-Draft draft-ietf-ace-oauth-authz-13, July 2018.
[I-D.ietf-ace-oscore-profile] Seitz, L., Palombini, F., Gunnarsson, M. and G. Selander, "OSCORE profile of the Authentication and Authorization for Constrained Environments Framework", Internet-Draft draft-ietf-ace-oscore-profile-02, June 2018.
[I-D.ietf-core-resource-directory] Shelby, Z., Koster, M., Bormann, C., Stok, P. and C. Amsuess, "CoRE Resource Directory", Internet-Draft draft-ietf-core-resource-directory-14, July 2018.
[LoRa1] Sanchez-Iborra, R., Sánchez-Gómez, J., Pérez, S., Fernández, P., Santa, J., Hernández-Ramos, J. and A. Skarmeta, "Enhancing LoRaWAN Security through a Lightweight and Authenticated Key Management Approach", June 2018.
[LoRa2] Sanchez-Iborra, R., Sánchez-Gómez, J., Pérez, S., Fernández, P., Santa, J., Hernández-Ramos, J. and A. Skarmeta, "Internet Access for LoRaWAN Devices Considering Security Issues", June 2018.
[RFC7228] Bormann, C., Ersue, M. and A. Keranen, "Terminology for Constrained-Node Networks", RFC 7228, DOI 10.17487/RFC7228, May 2014.
[RFC8446] Rescorla, E., "The Transport Layer Security (TLS) Protocol Version 1.3", RFC 8446, DOI 10.17487/RFC8446, August 2018.

Appendix A. Use of CBOR, CDDL and COSE in EDHOC

This Appendix is intended to simplify for implementors not familiar with CBOR [I-D.ietf-cbor-7049bis], CDDL [I-D.ietf-cbor-cddl], COSE [RFC8152], and HKDF [RFC5869].

A.1. CBOR and CDDL

The Concise Binary Object Representation (CBOR) [I-D.ietf-cbor-7049bis] is a data format designed for small code size and small message size. CBOR builds on the JSON data model but extends it by e.g. encoding binary data directly without base64 conversion. In addition to the binary CBOR encoding, CBOR also has a diagnostic notation that is readable and editable by humans. The Concise Data Definition Language (CDDL) [I-D.ietf-cbor-cddl] provides a way to express structures for protocol messages and APIs that use CBOR. [I-D.ietf-cbor-cddl] also extends the diagnostic notation.

CBOR data items are encoded to or decoded from byte strings using a type-length-value encoding scheme, where the three highest order bits of the initial byte contain information about the major type. CBOR supports several different types of data items, in addition to integers (int, uint), simple values (e.g. null), byte strings (bstr), and text strings (tstr), CBOR also supports arrays [] of data items and maps {} of pairs of data items. Some examples are given below. For a complete specification and more examples, see [I-D.ietf-cbor-7049bis] and [I-D.ietf-cbor-cddl]. We recommend implementors to get used to CBOR by using the CBOR playground [CborMe].

Diagnostic          Encoded              Type
------------------------------------------------------------------
1                   0x01                 unsigned integer    
24                  0x1818               unsigned integer
-24                 0x37                 negative integer
-25                 0x3818               negative integer 
null                0xf6                 simple value 
h'12cd'             0x4212cd             byte string
'12cd'              0x4431326364         byte string
"12cd"              0x6431326364         text string
<< 1, 2, null >>    0x430102f6           byte string
[ 1, 2, null ]      0x830102f6           array      
[_ 1, 2, null ]     0x9f0102f6ff         array (indefinite-length)
( 1, 2, null )      0x0102f6             group
{ 4: h'cd' }        0xa10441cd           map                 
------------------------------------------------------------------

All EDHOC messages consist of a sequence of CBOR encoded data items. While an EDHOC message in itself is not a CBOR data item, it may be viewed as the CBOR encoding of an indefinite-length array [_ message_i ] without the first byte (0x9f) and the last byte (0xff), for i = 1, 2 and 3. The same applies to the EDHOC error message.

The message format specification uses the constructs ‘.cbor’, ‘.cborseq’ and ‘~’ enabling conversion between different CDDL types matching different CBOR items with different encodings. Some examples are given below.

An type (e.g. an uint) may be wrapped in a byte string (bstr), and back again:

CDDL Type                       Diagnostic                Encoded
------------------------------------------------------------------
uint                            24                        0x1818
bstr .cbor uint                 << 24 >>                  0x421818
~ bstr .cbor uint               24                        0x1818
------------------------------------------------------------------

A array, say of an uint and a byte string, may be converted into a byte string (bstr):

CDDL Type                       Diagnostic              Encoded
--------------------------------------------------------------------
bstr                            h'cd'                   0x41cd
[ uint, bstr ]                  [ 24, h'cd' ]           0x82181841cd
bstr .cborseq [ uint, bstr ]    << 24, h'cd' >>         0x44181841cd
--------------------------------------------------------------------

A.2. COSE

CBOR Object Signing and Encryption (COSE) [RFC8152] describes how to create and process signatures, message authentication codes, and encryption using CBOR. COSE builds on JOSE, but is adapted to allow more efficient processing in constrained devices. EDHOC makes use of COSE_Key, COSE_Encrypt0, COSE_Sign1, and COSE_KDF_Context objects.

A.2.1. Encryption and Decryption

The COSE parameters used in COSE_Encrypt0 (see Section 5.2 of [RFC8152]) are constructed as described below. Note that “i” in “K_i”, “IV_i” and “aad_i” is a variable with value i = 2 or 3, depending on whether the calculation is made over message_2 or message_3.

COSE constructs the input to the AEAD [RFC5116] as follows:

   [ "Encrypt0", h'', aad_i ]

A.2.2. Signing and Verification

The COSE parameters used in COSE_Sign1 (see Section 4.2 of [RFC8152]) are constructed as described below. Note that “i” in “aad_i” is a variable with values i = 2 or 3, depending on whether the calculation is made over message_2 or message_3. Note also that “x” in “ID_CRED_x” and “CRED_x” is a variable with values x = U or V, depending on whether it is the credential of U or of V that is used in the relevant protocol message.

COSE constructs the input to the Signature Algorithm as follows:

   [ "Signature1", << { abc : ID_CRED_x } >>, aad_i, CRED_x ]

A.2.3. Key Derivation

Assuming use of the mandatory-to-implement algorithms HKDF SHA-256 and AES-CCM-16-64-128, the extract phase of HKDF produces a pseudorandom key (PRK) as follows:

PRK = HMAC-SHA-256( salt, ECDH shared secret )

where salt = 0x in the asymmetric case and salt = PSK in the symmetric case. As the output length L is smaller than the hash function output size, the expand phase of HKDF consists of a single HMAC invocation, and K_i and IV_i are therefore the first 16 and 13 bytes, respectively, of

output parameter = HMAC-SHA-256( PRK, info || 0x01 )

where | | means byte string concatenation, and info is the CBOR encoding of

COSE_KDF_Context = [
  AlgorithmID,
  [ null, null, null ],
  [ null, null, null ],
  [ keyDataLength, h'', aad_i ]
]

If AES-CCM-16-64-128 then AlgorithmID = 10 and keyDataLength = 128 for K_i, and AlgorithmID = “IV-GENERATION” (CBOR encoding 0x6d49562d47454e45524154494f4e) and keyDataLength = 104 for IV_i. Hence, if aad_2 = h’aaaa’ then

K_2  = HMAC-SHA-256( PRK, 0x840a83f6f6f683f6f6f68318804042aaaa01 )
IV_2 = HMAC-SHA-256( PRK, 0x846d49562d47454e45524154494f4e
                                83f6f6f683f6f6f68318804042aaaa01 ) 

Appendix B. Test Vectors

This appendix provides a wealth of test vectors to ease implementation and ensure interoperability.

TODO: This section needs to be updated.

Appendix C. EDHOC PSK Chaining

An application using EDHOC may want to derive new PSKs to use for authentication in future EDHOC sessions. In this case, the new PSK and KID SHOULD be derived as follows where length is the key length (in bytes) of AEAD_V.

PSK = EDHOC-Exporter("EDHOC Chaining PSK", length)
KID = EDHOC-Exporter("EDHOC Chaining KID", 4)

Appendix D. EDHOC with CoAP and OSCORE

D.1. Transferring EDHOC in CoAP

EDHOC can be transferred as an exchange of CoAP [RFC7252] messages. By default, the CoAP client is Party U and the CoAP server is Party V, but the roles SHOULD be chosen to protect the most sensitive identity, see Section 8. By default, EDHOC is transferred in POST requests and 2.04 (Changed) responses to the Uri-Path: “/.well-known/edhoc”, but an application may define its own path that can be discovered e.g. using resource directory [I-D.ietf-core-resource-directory].

By default, the message flow is as follows: EDHOC message_1 is sent in the payload of a POST request from the client to the server’s resource for EDHOC. EDHOC message_2 or the EDHOC error message is sent from the server to the client in the payload of a 2.04 (Changed) response. EDHOC message_3 or the EDHOC error message is sent from the client to the server’s resource in the payload of a POST request. If needed, an EDHOC error message is sent from the server to the client in the payload of a 2.04 (Changed) response.

An example of a successful EDHOC exchange using CoAP is shown in Figure 5.

Client    Server
  |          |
  +--------->| Header: POST (Code=0.02)
  |   POST   | Uri-Path: "/.well-known/edhoc"
  |          | Content-Format: application/edhoc
  |          | Payload: EDHOC message_1
  |          |
  |<---------+ Header: 2.04 Changed
  |   2.04   | Content-Format: application/edhoc
  |          | Payload: EDHOC message_2
  |          |
  +--------->| Header: POST (Code=0.02)
  |   POST   | Uri-Path: "/.well-known/edhoc"
  |          | Content-Format: application/edhoc
  |          | Payload: EDHOC message_3
  |          |
  |<---------+ Header: 2.04 Changed
  |   2.04   | 
  |          |

Figure 5: Example of transferring EDHOC in CoAP

D.2. Deriving an OSCORE context from EDHOC

When EDHOC is used to derive parameters for OSCORE [I-D.ietf-core-object-security], the parties must make sure that the EDHOC connection identifiers are unique, i.e. C_V MUST NOT be equal to C_U. In case that the CoAP client is party U and the CoAP server is party V:

   Master Secret = EDHOC-Exporter("OSCORE Master Secret", length)
   Master Salt   = EDHOC-Exporter("OSCORE Master Salt", 8)

Appendix E. Message Sizes

This appendix gives an estimate of the message sizes of EDHOC with different authentication methods. Note that the examples in this appendix are not test vectors, the cryptographic parts are just replaced with byte strings of the same length. All examples are given in CBOR diagnostic notation and hexadecimal.

E.1. Message Sizes RPK

E.1.1. message_1

message_1 = (
  1,
  h'c3',
  4,
  0,
  h'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d
    1e1f',
  -27,
  10,
  -8,
  -8
)
message_1 (44 bytes):
01 41 C3 04 00 58 20 00 01 02 03 04 05 06 07 08 09 0A 0B 0C
0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
38 1A 0A 27 27

E.1.2. message_2

plaintext = <<
  { 4 : 'acdc' },
  h'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d
    1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b
    3c3d3e3f'
>>

The protected header map is 7 bytes. The length of plaintext is 73 bytes so assuming a 64-bit MAC value the length of ciphertext is 81 bytes.

message_2 = (
  2,
  null,
  h'c4',
  h'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d
    1e1f',
  0,
  0,
  0,
  0,
  h'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d
    1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b
    3c3d3e3f404142434445464748494a4b4c4d4e4f50'
)
message_2 (125 bytes):
02 F6 41 C4 58 20 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D
0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 00 00
00 00 58 51 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23
24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37
38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A 4B
4C 4D 4E 4F 50

E.1.3. message_3

The plaintext and ciphertext in message_3 are assumed to be of equal sizes as in message_2.

message_3 = (
  3,
  h'c3',
  h'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d
    1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b
    3c3d3e3f404142434445464748494a4b4c4d4e4f50'
)
message_3 (86 bytes):
03 41 C3 58 51 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E
0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22
23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36
37 38 39 3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49 4A
4B 4C 4D 4E 4F 50

E.2. Message Sizes Certificates

When the certificates are distributed out-of-band and identified with the x5t header and a SHA256/64 hash value, the protected header map will be 13 bytes instead of 7 bytes (assuming labels in the range -24…23).

protected = << { TDB1 : [ TDB6, h'0001020304050607' ] } >>

When the certificates are identified with the x5chain header, the message sizes depends on the size of the (truncated) certificate chains. The protected header map will be 3 bytes + the size of the certificate chain (assuming a label in the range -24…23).

protected = << { TDB3 : h'0001020304050607...' } >>

E.3. Message Sizes PSK

E.3.1. message_1

message_1 = (
  4,
  h'c3',
  4,
  0,
  h'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d
    1e1f',
  -27,
  10,
  'abba'
)
message_1 (47 bytes):
04 41 C3 04 00 58 20 00 01 02 03 04 05 06 07 08 09 0A 0B 0C
0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
38 1A 0A 44 61 63 64 63

E.3.2. message_2

Assuming a 0 byte plaintext and a 64-bit MAC value the ciphertext is 8 bytes

message_2 = (
  5,
  null,
  h'c4',
  h'000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d
    1e1f',
  0,
  0,
  h'0001020304050607'
)
message_2 (49 bytes):
05 F6 41 C4 58 20 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D
0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 00 00
48 61 62 63 64 65 66 67 68

E.3.3. message_3

The plaintext and ciphertext in message_3 are assumed to be of equal sizes as in message_2.

message_3 = (
  6,
  h'c3',
  h'0001020304050607'
)
message_3 (12 bytes):
06 41 C3 48 00 01 02 03 04 05 06 07

E.4. Summary

              PSK       RPK       x5t     x5chain                  
--------------------------------------------------------------------
message_1      47        44        44        44                     
message_2      49       125       131       121 + Certificate chain 
message_3      12        86        92        82 + Certificate chain 
--------------------------------------------------------------------
Total         108       255       267       247 + Certificate chains

Figure 6: Typical message sizes in bytes

Acknowledgments

The authors want to thank Dan Harkins, Ilari Liusvaara, Jim Schaad, and Ludwig Seitz for reviewing intermediate versions of the draft and contributing concrete proposals incorporated in this version. We are especially indebted to Jim Schaad for his continuous reviewing and implementation of different versions of the draft.

We are also grateful to Theis Grønbech Petersen, Thorvald Sahl Jørgensen, Alessandro Bruni, and Carsten Schürmann for their work on formal analysis of EDHOC.

Authors' Addresses

Göran Selander Ericsson AB EMail: goran.selander@ericsson.com
John Mattsson Ericsson AB EMail: john.mattsson@ericsson.com
Francesca Palombini Ericsson AB EMail: francesca.palombini@ericsson.com