COSE                                                       H. Tschofenig
Internet-Draft                                                     H-BRS
Intended status: Standards Track                              R. Housley
Expires: 23 April 2025                                    Vigil Security
                                                             K. Takayama
                                                         SECOM CO., LTD.
                                                         20 October 2024


     Encryption Key Derivation in the COSE using HKDF with SHA-256
                draft-tschofenig-cose-cek-hkdf-sha256-02

Abstract

   This document specifies the derivation of the content-encryption key
   in CBOR Object Signing and Encryption (COSE).  This mechanism
   protects against attacks where an attacker manipulates the content-
   encryption algorithm identifier.

About This Document

   This note is to be removed before publishing as an RFC.

   Status information for this document may be found at
   https://datatracker.ietf.org/doc/draft-tschofenig-cose-cek-hkdf-
   sha256/.

   Discussion of this document takes place on the COSE Working Group
   mailing list (mailto:cose@ietf.org), which is archived at
   https://datatracker.ietf.org/wg/cose/about/.  Subscribe at
   https://www.ietf.org/mailman/listinfo/cose/.

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 23 April 2025.



Tschofenig, et al.        Expires 23 April 2025                 [Page 1]

Internet-Draft      Encryption Key Derivation in COSE       October 2024


Copyright Notice

   Copyright (c) 2024 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 Revised BSD License text as
   described in Section 4.e of the Trust Legal Provisions and are
   provided without warranty as described in the Revised BSD License.

Table of Contents

   1.  Introduction  . . . . . . . . . . . . . . . . . . . . . . . .   2
   2.  Conventions and Definitions . . . . . . . . . . . . . . . . .   3
   3.  Updated Encryption Flow for each Content Key Distribution
           Method  . . . . . . . . . . . . . . . . . . . . . . . . .   3
   4.  Updated Decryption Flow for Each Content Key Distribution
           Method  . . . . . . . . . . . . . . . . . . . . . . . . .   6
   5.  Use of of HKDF with SHA-256 to Derive Encryption Keys . . . .   8
   6.  Security Considerations . . . . . . . . . . . . . . . . . . .   8
   7.  IANA Considerations . . . . . . . . . . . . . . . . . . . . .   9
   8.  References  . . . . . . . . . . . . . . . . . . . . . . . . .   9
     8.1.  Normative References  . . . . . . . . . . . . . . . . . .   9
     8.2.  Informative References  . . . . . . . . . . . . . . . . .  10
   Appendix A.  Acknowledgments  . . . . . . . . . . . . . . . . . .  10
   Authors' Addresses  . . . . . . . . . . . . . . . . . . . . . . .  10

1.  Introduction

   This document specifies the derivation of the content-encryption key
   for COSE.  The use of this mechanism provides protection against
   where the attacker manipulates the content-encryption algorithm
   identifier.  This attack has been demonstrated against CMS and the
   mitigation can be found in [I-D.ietf-lamps-cms-cek-hkdf-sha256].
   This attack is generic and can apply to other protocols with similar
   characteristics, such as COSE.  However, the attack requires several
   preconditions:

   1.  The attacker intercepts a COSE Encrypt payload an changes the
       algorithm identifier to use the same underlying cipher with a
       different encryption mode, such as AES-GCM to AES-CBC.

   2.  The attacker converts the intercepted content into a "garbage"
       COSE Encrypt payload composed of AES-CBC guess blocks.



Tschofenig, et al.        Expires 23 April 2025                 [Page 2]

Internet-Draft      Encryption Key Derivation in COSE       October 2024


   3.  The attacker sends the "garbage" message to the victim, who then
       reveals the result of the decryption to the attacker.

   4.  If any of the transformed plaintext blocks match the guess for
       that block, then the attacker learns the plaintext for that
       block.

   With highly structured messages, one block can reveal the only
   sensitive part of the original message.

   This attack is thwarted if the encryption key depends upon the
   delivery of the unmodified algorithm identifier.

   The mitigation for this attack has two parts:

   *  Potential recipients include a new parameter, cek-hkdf, in the
      outermost protected header of the COSE_Encrypt payload to indicate
      support for this mitigation.  This parameter MUST use the value
      true.

   *  Perform encryption with a derived content-encryption key or
      content-authenticated-encryption key.  The new CEK' is the result
      of deriving a CEK.  This key derivation uses the alg parameter
      found in the outermost COSE_Encrypt header.

   CEK' = HKDF(CEK, COSE_Encrypt.alg)

2.  Conventions and Definitions

   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.

3.  Updated Encryption Flow for each Content Key Distribution Method

   This section describes the key distribution and encryption flows on
   sender side.  Only the payload encryption process will be changed
   with the mitigation.

   Some content key distribution methods generate encrypted CEK (eCEK)
   from randomly generated CEK.  Figure 1 shows that each procedure is
   NOT changed by the mitigation.







Tschofenig, et al.        Expires 23 April 2025                 [Page 3]

Internet-Draft      Encryption Key Derivation in COSE       October 2024


                   AES-KW                   ECDH+AES-KW     COSE-HPKE
                .---.  .---.               .---.  .---.    .---.  .---.
               | PSK || CEK |             | pkR || skS |  | pkR || skS |
                '-+-'  '-+-'               '-+-'  '-+-'    '-+-'  '-+-'
                  |      |                   v      v        v      v
                  |      |                +------------+   .----------.
                  |      |                |    ECDH    |  |  ContextS  |
                  |      |                +--+---------+   '-+--------'
                  |      |                   v               |
                  |      |                .-----.  .---.     |   .---.
                  |      |               | DH SS || CIS |    |  | aad |
                  |      |                '--+--'  '-+-'     |   '-+-'
                  |      |                   v       v       |  .-'
                  |      |                +------------+     | |
                  |      |                |    HKDF    |     | |
                  |      |                +--+---------+     | |
                  |      |                   |  .---.        | |  .---.
                  |      |                   | | CEK |       | | | CEK |
                  |      |                   |  '-+-'        | |  '-+-'
                  v      v                   v    v          v v    v
                +----------+              +----------+     +----------+
                |   Wrap   |              |   Wrap   |     |   open   |
                +----+-----+              +----+-----+     +----+-----+
                     v                         v                v
                   .----.                    .----.           .----.
                  | eCEK |                  | eCEK |         | eCEK |
                   '----'                    '----'           '----'

 PSK   : Pre Shared Key
 CEK   : Content Encryption Key
 pkR   : Recipient's Public Key
 skS   : (Static or Ephemeral) Sender's Private Key
 DH SS : DH-Shared Secret
 CIS   : COSE Context Information Structure
 eCEK  : Encrypted CEK into COSE message

    Figure 1: eCEK Generation Flow for each Content Key Distribution
                                 Method

   Figure 2 shows that the mitigation layer is inserted just before the
   encrypting the plaintext payload.  Note that Enc_structure is fed to
   encryption function (Encrypt) if the COSE_Encrypt.alg is an AEAD.









Tschofenig, et al.        Expires 23 April 2025                 [Page 4]

Internet-Draft      Encryption Key Derivation in COSE       October 2024


   Direct Direct+KDF AES-KW   Direct ECDH     ECDH+AES-KW     COSE-HPKE
    .---.    .--.    .---.   .---.  .---.        .---.          .---.
   | PSK |  | SS |  | CEK | | pkR || skS |      | CEK |        | CEK |
    '-+-'    '-+'    '-+-'   '-+-'  '-+-'        '-+-'          '-+-'
      |        |       |       v      v            |              |
      |        |       |    +------------+         |              |
      |        |       |    |    ECDH    |         |              |
      |        |       |    +--+---------+         |              |
      |     .-'        |       v                   |              |
      |    |  .---.    |    .-----.  .---.         |              |
      |    | | CIS |   |   | DH SS || CIS |        |              |
      |    |  '-+-'    |    '--+--'  '-+-'         |              |
      |    v    v      |       v       v           |              |
      |  +--------+    |    +------------+         |              |
      |  |  HKDF  |    |    |    HKDF    |         |              |
      |  +---+----+    |    +-----+------+         |              |
      v      v         v          v                v              v
   +-----------------------------------------------------------------+
   |          CEK' = HKDF(CEK, COSE_Encrypt.alg) [Proposal]          |
   +--------------------------------+--------------------------------+
                                    v
                               +---------+    .-----------------.
                               | Encrypt |<--+ Plaintext Payload |
                               +----+----+    '-----------------'
                                    v
                           .------------------.
                          | Encrypted Payload  |
                           '------------------'

   PSK   : Pre Shared Key
   SS    : Shared Secret
   CEK   : Content Encryption Key
   pkR   : (Static or Ephemeral) Recipient's Public Key
   skS   : Sender's Private Key
   DH SS : DH-Shared Secret
   CIS   : COSE Context Information Structure

           Figure 2: Payload Encryption Flow for each Content Key
                            Distribution Method

   Then the sender creates COSE_Encrypt0 or COSE_Encrypt structure using
   these parameters if necessary.

   *  layer 0: The content encryption layer

      -  protected or unprotected headers

         o  content encryption algorithm id



Tschofenig, et al.        Expires 23 April 2025                 [Page 5]

Internet-Draft      Encryption Key Derivation in COSE       October 2024


         o  its parameters such as IV

         o  cek-hkdf = true

      -  encrypted payload

   *  layer 1: The content key distribution layer

      -  protected or unprotected headers

         o  content key distribution method algorithm id

         o  its parameters such as ephemeral key

         o  kid

      -  eCEK

   TODO: provide an example binary (in appendix?)

4.  Updated Decryption Flow for Each Content Key Distribution Method

   This section describes the decryption flows on recipient side for
   each content key distribution method.

   Figure 3 shows that the mitigation layer is inserted between the
   content key distribution methods and content decryption if the cek-
   hkdf parameter with true value locates in outer header.  Note that
   Enc_structure is fed to decryption function (Decrypt) if the
   COSE_Encrypt.alg is an AEAD.





















Tschofenig, et al.        Expires 23 April 2025                 [Page 6]

Internet-Draft      Encryption Key Derivation in COSE       October 2024


 Direct Direct+KDF AES-KW   Direct ECDH     ECDH+AES-KW     COSE-HPKE
  .---.    .--.    .---.   .---.  .---.     .---.  .---.   .---.  .---.
 | PSK |  | SS |  | PSK | | pkS || skR |   | pkS || skR | | pkS || skR |
  '-+-'    '-+'    '-+-'   '-+-'  '-+-'     '-+-'  '-+-'   '-+-'  '-+-'
    |        |       |       v      v         v      v       v      v
    |        |       |    +------------+   +------------+  .----------.
    |        |       |    |    ECDH    |   |    ECDH    | |  ContextR  |
    |        |       |    +--+---------+   +--+---------+  '-+--------'
    |    .--'        |       v                v              |
    |   |  .---.     |    .-----.  .---.   .-----.  .---.    |   .---.
    |   | | CIS |    |   | DH SS || CIS | | DH SS || CIS |   |  | aad |
    |   |  '-+-'     |    '--+--'  '-+-'   '--+--'  '-+-'    |   '-+-'
    |   v    v       |       v       v        v       v      |  .-'
    | +--------+     |    +------------+   +------------+    | |
    | |  HKDF  |     |    |    HKDF    |   |    HKDF    |    | |
    | +----+---+  .-'     +-----+------+   +--+---------+    | |
    |      |     | .----.       |             |   .----.     | | .----.
    |      |     || eCEK |      |             |  | eCEK |    | || eCEK |
    |      |     | '--+-'       |             |   '--+-'     | | '--+-'
    |      |     v    v         |             v      v       v v    v
    |      |  +----------+      |           +----------+   +----------+
    |      |  |  Unwrap  |      |           |  Unwrap  |   |   open   |
    |      |  +----+-----+      |           +----+-----+   +----+-----+
    v      v       v            v                v              v
   .----------------------------------------------------------------.
  |                   Content Encryption Key (CEK)                   |
   '-------------------------------+--------------------------------'
                                   v
     +------------------------------------------------------------+
     | CEK' = HKDF(CEK, COSE_Encrypt.alg) if cek-hkdf [Proposal]  |
     +-----------------------------+------------------------------+
                                   v
                              +---------+    .-----------------.
                              | Decrypt |<--+ Encrypted Payload |
                              +----+----+    '-----------------'
                                   v
                          .------------------.
                         | Plaintext Payload  |
                          '------------------'

 PSK   : Pre Shared Key
 SS    : Shared Secret
 pkS   : (Static or Ephemeral) Sender's Public Key
 skR   : Recipient's Private Key
 CIS   : COSE Context Information Structure
 DH SS : DH-Shared Secret
 eCEK  : Encrypted CEK in COSE message




Tschofenig, et al.        Expires 23 April 2025                 [Page 7]

Internet-Draft      Encryption Key Derivation in COSE       October 2024


         Figure 3: Payload Decryption Flow for each Content Key
                          Distribution Method

5.  Use of of HKDF with SHA-256 to Derive Encryption Keys

   The mitigation uses the HMAC-based Extract-and-Expand Key Derivation
   Function (HKDF) [RFC5869] to derive output keying material (OKM) from
   input key material (IKM).  HKDF is used with the SHA-256 hash
   function [FIPS180].

   If an attacker were to change the originator-provided COSE_Encrypt
   algorithm identifier then the recipient will derive a different
   content-encryption key.

   The CEK_HKDF function uses the HKDF-Extract and HKDF- Expand
   functions to derive the OKM from the IKM:

   Inputs:
     IKM        Input keying material
     alg        COSE_Key algorithm identifier

   Output:
     OKM      output keying material (same size as IKM)

   The output OKM is calculated as follows:

     OKM_SIZE = len(IKM)
     IF OKM_SIZE > 8160 THEN raise error

     salt = "CBOR Object Signing and Encryption"
     PRK = HKDF-Extract(salt, IKM)

     OKM = HKDF-Expand(PRK, alg, OKM_SIZE)

6.  Security Considerations

   This mitigation always uses HKDF with SHA-256.  One KDF algorithm was
   selected to avoid the need for negotiation.  In the future, if a
   weakness is found in the KDF algorithm, a new attribute will need to
   be assigned for use with an alternative KDF algorithm.

   If the attacker removes the cek-hkdf header parameter from the
   COSE_Encrypt header prior to delivery to the recipient, then the
   recipient will not attempt to derive CEK', which will deny the
   recipient access to the content, but will not assist the attacker in
   recovering the plaintext content.





Tschofenig, et al.        Expires 23 April 2025                 [Page 8]

Internet-Draft      Encryption Key Derivation in COSE       October 2024


   If the attacker changes the value of the COSE_Encrypt alg parameter
   prior to delivery to the recipient, then the recipient will derive a
   different CEK', which will not assist the attacker in recovering the
   plaintext content.  Providing the algorithm identifer as an input to
   the key derivation function is sufficient to mitigate the attack
   described in [RS2023], but this mitigation includes both the object
   identifier and the parameters to protect against some yet-to-be-
   discovered attack that only manipulates the parameters.

   Implementations MUST protect the content-encryption keys, this
   includes the CEK and CEK'.  Compromise of a content-encryption key
   may result in disclosure of the associated encrypted content.
   Compromise of a content-authenticated-encryption key may result in
   disclosure of the associated encrypted content or allow modification
   of the authenticated content and the additional authenticated data
   (AAD).

   Implementations MUST randomly generate content-encryption keys and
   content-authenticated-encryption keys.  Content key distribution
   methods are described in Section 8.5 of [RFC9052] and in Section 6 of
   [RFC9053].  These algorithms define derivation and protection of
   content-encryption keys.

7.  IANA Considerations

   IANA is requested to add a new header parameter to the "COSE Common
   Header Parameters" established with [RFC9052].

   +-----------+-------+--------------+-------------+------------------+
   | Name      | Label | Value Type   | Value       | Description      |
   |           |       |              | Registry    |                  |
   +-----------+-------+--------------+-------------+------------------+
   | cek-hkdf  | TBD   | bool         | N/A         | CEK-HKDF-SHA256  |
   +-----------+-------+--------------+-------------+------------------+

8.  References

8.1.  Normative References

   [FIPS180]  National Institute of Standards and Technology (NIST),
              "Secure Hash Standard (SHS), FIPS PUB 180-4", August 2015,
              <https://csrc.nist.gov/pubs/fips/180-4/upd1/final>.

   [RFC2119]  Bradner, S., "Key words for use in RFCs to Indicate
              Requirement Levels", BCP 14, RFC 2119,
              DOI 10.17487/RFC2119, March 1997,
              <https://www.rfc-editor.org/rfc/rfc2119>.




Tschofenig, et al.        Expires 23 April 2025                 [Page 9]

Internet-Draft      Encryption Key Derivation in COSE       October 2024


   [RFC5869]  Krawczyk, H. and P. Eronen, "HMAC-based Extract-and-Expand
              Key Derivation Function (HKDF)", RFC 5869,
              DOI 10.17487/RFC5869, May 2010,
              <https://www.rfc-editor.org/rfc/rfc5869>.

   [RFC8174]  Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC
              2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174,
              May 2017, <https://www.rfc-editor.org/rfc/rfc8174>.

   [RFC9052]  Schaad, J., "CBOR Object Signing and Encryption (COSE):
              Structures and Process", STD 96, RFC 9052,
              DOI 10.17487/RFC9052, August 2022,
              <https://www.rfc-editor.org/rfc/rfc9052>.

   [RFC9053]  Schaad, J., "CBOR Object Signing and Encryption (COSE):
              Initial Algorithms", RFC 9053, DOI 10.17487/RFC9053,
              August 2022, <https://www.rfc-editor.org/rfc/rfc9053>.

8.2.  Informative References

   [I-D.ietf-lamps-cms-cek-hkdf-sha256]
              Housley, R., "Encryption Key Derivation in the
              Cryptographic Message Syntax (CMS) using HKDF with SHA-
              256", Work in Progress, Internet-Draft, draft-ietf-lamps-
              cms-cek-hkdf-sha256-05, 19 September 2024,
              <https://datatracker.ietf.org/doc/html/draft-ietf-lamps-
              cms-cek-hkdf-sha256-05>.

   [RS2023]   Strenzke, F. and J. Roth, "AEAD-to-CBC Downgrade Attacks
              on CMS", November 2023,
              <https://datatracker.ietf.org/meeting/118/materials/
              slides-118-lamps-attack-against-aead-in-cms>.

Appendix A.  Acknowledgments

   Add your name here.

Authors' Addresses

   Hannes Tschofenig
   University of Applied Sciences Bonn-Rhein-Sieg
   Email: Hannes.Tschofenig@gmx.net


   Russ Housley
   Vigil Security, LLC
   Email: housley@vigilsec.com




Tschofenig, et al.        Expires 23 April 2025                [Page 10]

Internet-Draft      Encryption Key Derivation in COSE       October 2024


   Ken Takayama
   SECOM CO., LTD.
   Email: ken.takayama.ietf@gmail.com
















































Tschofenig, et al.        Expires 23 April 2025                [Page 11]