Internet-Draft Encryption Key Derivation in COSE October 2024
Tschofenig, et al. Expires 23 April 2025 [Page]
Workgroup:
COSE
Internet-Draft:
draft-tschofenig-cose-cek-hkdf-sha256-02
Published:
Intended Status:
Standards Track
Expires:
Authors:
H. Tschofenig
H-BRS
R. Housley
Vigil Security
K. Takayama
SECOM CO., LTD.

Encryption Key Derivation in the COSE using HKDF with SHA-256

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.

Table of Contents

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.

  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:

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.

AES-KW ECDH+AES-KW COSE-HPKE PSK CEK pkR skS pkR skS ECDH ContextS DH SS CIS aad HKDF CEK CEK Wrap Wrap open 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.

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

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.

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

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", , <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, , <https://www.rfc-editor.org/rfc/rfc2119>.
[RFC5869]
Krawczyk, H. and P. Eronen, "HMAC-based Extract-and-Expand Key Derivation Function (HKDF)", RFC 5869, DOI 10.17487/RFC5869, , <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, , <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, , <https://www.rfc-editor.org/rfc/rfc9052>.
[RFC9053]
Schaad, J., "CBOR Object Signing and Encryption (COSE): Initial Algorithms", RFC 9053, DOI 10.17487/RFC9053, , <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, , <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", , <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
Russ Housley
Vigil Security, LLC
Ken Takayama
SECOM CO., LTD.