PROPOSED STANDARD

Errata Exist

Internet Engineering Task Force (IETF) M. Thomson Request for Comments: 8188 Mozilla Category: Standards Track June 2017 ISSN: 2070-1721 Encrypted Content-Encoding for HTTP Abstract This memo introduces a content coding for HTTP that allows message payloads to be encrypted. Status of This Memo This is an Internet Standards Track document. This document is a product of the Internet Engineering Task Force (IETF). It represents the consensus of the IETF community. It has received public review and has been approved for publication by the Internet Engineering Steering Group (IESG). Further information on Internet Standards is available in Section 2 of RFC 7841. Information about the current status of this document, any errata, and how to provide feedback on it may be obtained at http://www.rfc-editor.org/info/rfc8188. Copyright Notice Copyright (c) 2017 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 (http://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. Thomson Standards Track [Page 1]

RFC 8188 HTTP Encryption Coding June 2017 RFC4880], [RFC5652], [RFC7516], and [XMLENC]. Those formats are not suited to stream processing, which is necessary for HTTP. The format described here follows more closely to the lower-level constructs described in [RFC5116]. To the extent that message-based encryption formats use the same primitives, the format can be considered to be a sequence of encrypted messages with a particular profile. For instance, Appendix A explains how the format is congruent with a sequence of JSON Web Encryption [RFC7516] values with a fixed header. This mechanism is likely only a small part of a larger design that uses content encryption. How clients and servers acquire and identify keys will depend on the use case. In particular, a key management system is not described. 1.1 . Requirements Language BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here. 2 . The "aes128gcm" HTTP Content Coding [RFC5116], Section 5.1. The AEAD_AES_128_GCM algorithm uses a 128-bit content- encryption key. Using this content coding requires knowledge of a key. How this key is acquired is not defined in this document. The "aes128gcm" content coding uses a single fixed set of encryption primitives. Cipher agility is achieved by defining a new content- coding scheme. This ensures that only the HTTP Accept-Encoding header field is necessary to negotiate the use of encryption. The "aes128gcm" content coding uses a fixed record size. The final encoding consists of a header (see Section 2.1) and zero or more fixed-size encrypted records; the final record can be smaller than the record size. Thomson Standards Track [Page 3]

RFC 8188 HTTP Encryption Coding June 2017 Section 2.1). +-----------+ content | data | any length up to rs-17 octets +-----------+ | v +-----------+-----+ add a delimiter octet (0x01 or 0x02) | data | pad | then 0x00-valued octets to rs-16 +-----------+-----+ (or less on the last record) | v +--------------------+ encrypt with AEAD_AES_128_GCM; | ciphertext | final size is rs; +--------------------+ the last record can be smaller AEAD_AES_128_GCM produces ciphertext 16 octets longer than its input plaintext. Therefore, the unencrypted content of each record is shorter than the record size by 16 octets. Valid records always contain at least a padding delimiter octet and a 16-octet authentication tag. Each record contains a single padding delimiter octet followed by any number of zero octets. The last record uses a padding delimiter octet set to the value 2, all other records have a padding delimiter octet value of 1. On decryption, the padding delimiter is the last non-zero-valued octet of the record. A decrypter MUST fail if the record contains no non-zero octet. A decrypter MUST fail if the last record contains a padding delimiter with a value other than 2 or if any record other than the last contains a padding delimiter with a value other than 1. The nonce for each record is a 96-bit value constructed from the record sequence number and the input-keying material. Nonce derivation is covered in Section 2.3. The additional data passed to each invocation of AEAD_AES_128_GCM is a zero-length octet sequence. A consequence of this record structure is that range requests [RFC7233] and random access to encrypted payload bodies are possible at the granularity of the record size. Partial records at the ends of a range cannot be decrypted. Thus, it is best if range requests start and end on record boundaries. However, note that random access Thomson Standards Track [Page 4]

RFC 8188 HTTP Encryption Coding June 2017 2.1 . Encryption Content-Coding Header RFC3629] string, particularly where the identifier might need to be rendered in a textual form. Thomson Standards Track [Page 5]

RFC 8188 HTTP Encryption Coding June 2017 2.2 . Content-Encryption Key Derivation RFC5869] using the SHA-256 hash algorithm [FIPS180-4]. The value of the "salt" parameter is the salt input to the HKDF. The keying material identified by the "keyid" parameter is the input- keying material (IKM) to HKDF. Input-keying material is expected to be provided to recipients separately. The extract phase of HKDF, therefore, produces a pseudorandom key (PRK) as follows: PRK = HMAC-SHA-256 (salt, IKM) The info parameter to HKDF is set to the ASCII-encoded string "Content-Encoding: aes128gcm" and a single zero octet: cek_info = "Content-Encoding: aes128gcm" || 0x00 Note(1): Concatenation of octet sequences is represented by the "||" operator. Note(2): The strings used here and in Section 2.3 do not include a terminating 0x00 octet, as is used in some programming languages. AEAD_AES_128_GCM requires a 16-octet (128-bit) content-encryption key (CEK), so the length (L) parameter to HKDF is 16. The second step of HKDF can, therefore, be simplified to the first 16 octets of a single HMAC: CEK = HMAC-SHA-256(PRK, cek_info || 0x01) 2.3 . Nonce Derivation Thomson Standards Track [Page 6]

RFC 8188 HTTP Encryption Coding June 2017 3 . Examples RFC4648]. This includes the bodies of requests. Whitespace and line wrapping is added to fit formatting constraints. 3.1 . Encryption of a Response Thomson Standards Track [Page 7]

RFC 8188 HTTP Encryption Coding June 2017 3.2 . Encryption with Multiple Records 4 . Security Considerations Thomson Standards Track [Page 8]

RFC 8188 HTTP Encryption Coding June 2017 4.1 . Automatic Decryption 4.2 . Message Truncation 4.3 . Key and Nonce Reuse RFC5116]. The scheme defined here uses a fixed progression of nonce values. Thus, a new content- encryption key is needed for every application of the content coding. Since input-keying material can be reused, a unique "salt" parameter is needed to ensure that a content-encryption key is not reused. If a content-encryption key is reused -- that is, if input-keying material and "salt" parameter are reused -- this could expose the plaintext and the authentication key, nullifying the protection offered by encryption. Thus, if the same input-keying material is reused, then the "salt" parameter MUST be unique each time. This ensures that the content-encryption key is not reused. An implementation SHOULD generate a random "salt" parameter for every message. Thomson Standards Track [Page 9]

RFC 8188 HTTP Encryption Coding June 2017 4.4 . Data Encryption Limits Section 2.1), which ensures that the 2^36-31 limit for a single application of AEAD_AES_128_GCM is not reached [RFC5116]. In order to preserve a 2^-40 probability of indistinguishability under chosen plaintext attack (IND-CPA), the total amount of plaintext that can be enciphered with the key derived from the same input-keying material and salt MUST be less than 2^44.5 blocks of 16 octets [AEBounds]. If the record size is a multiple of 16 octets, this means that 398 terabytes can be encrypted safely, including padding and overhead. However, if the record size is not a multiple of 16 octets, the total amount of data that can be safely encrypted is reduced because partial AES blocks are encrypted. The worst case is a record size of 18 octets, for which at most 74 terabytes of plaintext can be encrypted, of which at least half is padding. 4.5 . Content Integrity 4.6 . Leaking Information in Header Fields Thomson Standards Track [Page 10]

RFC 8188 HTTP Encryption Coding June 2017 Section 8.3.2 of [RFC7230]), encrypting that as the payload of the "outer" message. 4.7 . Poisoning Storage RFC7235]). This is especially relevant when an HTTP PUT request is accepted by a server without decrypting the payload; if the request is unauthenticated, it becomes possible for a third party to deny service and/or poison the store. 4.8 . Sizing and Timing Attacks NETFLIX] or [CLINIC]. This risk can be mitigated through the use of the padding that this mechanism provides. Alternatively, splitting up content into segments and storing them separately might reduce exposure. HTTP/2 [RFC7540] combined with TLS [RFC5246] might be used to hide the size of individual messages. Thomson Standards Track [Page 11]

RFC 8188 HTTP Encryption Coding June 2017 Appendix A . JWE Mapping RFC7516] objects, each corresponding to a single fixed-size record that includes trailing padding. The following transformations are applied to a JWE object that might be expressed using the JWE Compact Serialization: o The JWE Protected Header is fixed to the value { "alg": "dir", "enc": "A128GCM" }, describing direct encryption using AES-GCM with a 128-bit content-encryption key. This header is not transmitted, it is instead implied by the value of the Content- Encoding header field. o The JWE Encrypted Key is empty, as stipulated by the direct encryption algorithm. o The JWE Initialization Vector ("iv") for each record is set to the exclusive-or of the 96-bit record sequence number, starting at zero, and a value derived from the input-keying material (see Section 2.3). This value is also not transmitted. o The final value is the concatenated header, JWE Ciphertext, and JWE Authentication Tag, all expressed without base64url encoding. The "." separator is omitted, since the length of these fields is known. Thus, the example in Section 3.1 can be rendered using the JWE Compact Serialization as: eyAiYWxnIjogImRpciIsICJlbmMiOiAiQTEyOEdDTSIgfQ..Bcs8gkIRKLI8GeI8. -NAVub2qFgBEuQKRapoZuw.4jGQi9rcwQHU8P6XLxOGOA Where the first line represents the fixed JWE Protected Header, an empty JWE Encrypted Key, and the algorithmically determined JWE Initialization Vector. The second line contains the encoded body, split into JWE Ciphertext and JWE Authentication Tag. Thomson Standards Track [Page 15]

RFC 8188 HTTP Encryption Coding June 2017